Registry / testing / schema-pop

schema-pop

JSON →
library0.1.42jsnpmunverified

schema-pop is a JavaScript library for populating data structures based on a schema definition. Current stable version is 0.1.42, with active development and frequent minor releases. It differentiates from similar tools by focusing on schema-driven data generation for testing and prototyping, offering a simple API and support for nested objects and arrays. This library is lightweight, has no external runtime dependencies, and is published as both ESM and CommonJS modules, with TypeScript type definitions included.

npm install schema-pop
INSTALL
IMPORT
SIG · SCHEMA-POP
S
schema-pop
testingjavascriptv0.1.42
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

populate
✓ import { populate } from 'schema-pop'
✗ const populate = require('schema-pop')
Default export not available; use named import. In CommonJS, use const { populate } = require('schema-pop').
SchemaPop
✓ import { SchemaPop } from 'schema-pop'
✗ const SchemaPop = require('schema-pop').SchemaPop
This is a named export for the class. ESM-only symbols require named import syntax.
types
✓ import type { Schema } from 'schema-pop'
✗ const { Schema } = require('schema-pop')
TypeScript users should import types with 'import type' to avoid runtime bundling issues. In CommonJS, you cannot import types directly.

Demonstrates basic usage of populate() with a schema including strings, numbers, nested objects, and arrays. Overrides specific fields with provided values.

import { populate } from 'schema-pop'; const schema = { name: 'string', age: 'number', address: { street: 'string', city: 'string' }, tags: ['string'] }; const data = populate(schema, { name: 'John' }); console.log(data); // Example output: // { // name: 'John', // age: 27, // address: { street: 'abc', city: 'xyz' }, // tags: ['abc', 'def'] // }
Debug
Known issues
breakingIn version 0.1.0, the output order of array elements is not guaranteed to be stable. Do not rely on array ordering.
fix
If you need stable order, sort the array after population or upgrade to version 0.2.0+
affects: <0.2.0
gotchaWhen using TypeScript, type inference may not work correctly with complex nested schemas. Use explicit type annotations.
fix
Define a type for your schema and cast the result: const data = populate<MyType>(schema);
affects: >=0.1.0
deprecatedThe method `generate` is deprecated in favor of `populate` since version 0.1.20.
fix
Replace `generate(schema)` with `populate(schema)`.
affects: >=0.1.20 <0.2.0
gotchaPopulate generates random data each time. For reproducible tests, you cannot rely on constant output.
fix
Seed the random number generator if supported, or use your own deterministic generation.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: populate is not a function
Using default import instead of named import: import populate from 'schema-pop'
fix
Use named import: import { populate } from 'schema-pop'
Cannot find module 'schema-pop'
Package not installed or module resolution issue
fix
Install package: npm install schema-pop
Schema must be an object or array
Passing an invalid schema (e.g., string or number) to populate
fix
Ensure schema is a plain object or array describing types
Upgrade
Version history
0.1.42latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
schema-pop — npm install schema-pop · libregistry