
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
data-generator-light
Advanced tools
A simple utility for quickly generating mock data. An example use case would be, in conjunction with [json-server](https://github.com/typicode/json-server), mocking out an API.
A simple utility for quickly generating mock data. An example use case would be, in conjunction with json-server, mocking out an API.
npm install --save-dev data-generator-light
The generator creates N number of collections with N members.
The members each:
The generator takes an array of object literals as its input. The object literals correspond to IJobDefinition and consist of two parts : parameters that are unique to this package, and a specification used by json-schema-faker.
export interface IJobDefinition {
/**
* Custom parameters used by the generator
*/
parameters: IParameters;
/**
* Specification used by json-schema-faker. See https://github.com/json-schema-faker/json-schema-faker.
*/
specification: any;
}
export interface IParameters {
/**
* The name associated with the collection. For example, a collection of user objects may be referred to as 'users.'
*/
collectionName: string;
/**
* The number of objects to create.
*/
numberToCreate: number;
/**
* The field associated with the objects primary key. Defaults to 'id' if not specified.
* Note: If a non-numeric primary key is needed, generate it using the specification rather than here.
*/
primaryKey?: string;
/**
* If a collection has any foreign keys. For example, an address object might be associated with a specific user.
*/
foreignKeys?: IForeignKey[];
}
export interface IForeignKey {
/**
* The foreign key. For example, an account object might be associated with a specific user. It might refer
* to that user by a field called 'userId'.
*/
foreignKey: string
/**
* The collection it refers to. For example, an account object might be associated with 'users.'
*/
forCollection: string
}
The job definition below would create:
const accountsDefinition: IJobDefinition = {
"parameters": {
"collectionName": "account",
"numberToCreate": 30,
"primaryKey": "accountId",
"foreignKeys": [
{"foreignKey": "uid", "forCollection": "users"}
]
},
"specification": {
"type": "object",
"properties": {
"balance": {
"type": "string",
"faker": {
"finance.amount": [100, 10000, 2, "$"]
}
},
"userName": {
"type": 'string',
"faker": 'name.findName'
}
},
"required": [
"userName", "balance"
]
}
};
This example script takes all .json files in a directory and plugs them into the generator. It outputs the generated data to standard out.
const jsf = require('json-schema-faker');
const jobDefinitionsDir = __dirname + "/../job-definitions/";
let jobDefinitions: IJobDefinition[] = [];
readdirSync(jobDefinitionsDir).forEach((file) => {
if (file.indexOf(".json") > -1) {
const jobDefinition: IJobDefinition = require(jobDefinitionsDir + file);
const { collectionName, numberToCreate, primaryKey, foreignKeys } = jobDefinition.parameters;
jobDefinitions.push({
parameters: {
collectionName,
numberToCreate,
primaryKey,
foreignKeys
},
specification: jobDefinition.specification
});
jobDefinitions.push(require(jobDefinitionsDir + file));
}
});
const generator = new Generator(jsf);
const data = generator.generate(jobDefinitions);
process.stdout.write(JSON.stringify(data));
This data generator is a lightweight utility that's intended to simulate the types of data I receive from my own API's. I might be making different assumptions from those that inform your own API's. This utility is not intended to be comprehensive, nor is this utility intended to generate fixtures for mock data that you might use to populate a database.
Refer to json-schema-faker for information on how to populate the specifications.
FAQs
A simple utility for quickly generating mock data. An example use case would be, in conjunction with [json-server](https://github.com/typicode/json-server), mocking out an API.
We found that data-generator-light demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.