Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Half-Faked is a tool for generating fake data for a given schema definition. It was originally apart of the Restfool library as the fixture()
function, but has since been isolated into its own module. This tool can be used for creating more accurate and varied test cases, modeling data architecture, or even setting up mock services that deliver data for your front-end team(s) to develop against.
Half-Faked helps you get something close to what your final data will look like, without being your final data!
Install via npm
:
Note: We recommend installing the awesome faker library to use in conjunction with half-faked.
npm install --save-dev half-faked
Then, require
it in your project like so...
const createFactory = require('half-faked');
This library exposes a single function that accepts either an object literal or function that provides the desired output schema. Any functional values found will be called and their results can will also be checked for functional values to invoke.
type createFactory = (Object|Func schema) -> Factory
The return value of this function is a "factory" function that will be used for generating n
number of copies.
type Factory = (Integer count [, Object|Func modifier]) -> Array
Note: As previously mentioned, we're using the faker library below to quickly generate some fake data.
const createFactory = require('half-faked');
const faker = require('faker');
// object literal
const makeAddress = createFactory({
street: faker.address.streetAddress,
city: faker.address.city,
state: faker.address.usState,
country: 'usa',
zipcode: faker.address.zipCode
});
// function
const makeUser = createFactory(function () {
return {
name: faker.name.firstName() + ' '+ faker.name.lastName(),
email: faker.internet.email,
password: faker.random.uuid,
addresses: makeAddress(5)
};
});
Now that you've created a factory for your data, you can start creating rows using the returned factory function. You can create a single item by providing no first argument, or you can create a collection of items by specifying a count of 1
or greater.
var one = makeUser();
// => { name: 'Nick Glenn', email: ... }
var oneInArray = makeUser(1);
// => [ { name: 'Nick Glenn', email: ... } ]
var many = makeUser(5);
// => [ {...}, {...}, {...}, {...}, {...} ]
You can override the results of custom values by passing an object or function in as a second argument. This is called a modifier.
Using an object as a second argument will simply merge the given object with the data of each row in the collection, overriding the value of any existing matched keys.
var active = makeUser(2, { active: true });
// => [ {name: '...', active: true}, {name: '...', active: true} ]
Providing a function will give you a greater level of control. The generated object will be passed to the function and whatever is returned will take its place.
var users = makeUser(10, function (user) {
if (user.email === 'admin@example.com') {
user.password = '123456789';
}
return user;
});
FAQs
A simple tool for generating fake data using schemas.
We found that half-faked 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.