
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
faker-factory
Advanced tools
A small utility for creating fake models using a factory function. This factory is inspired by Laravel's factory function and assumes a class model similar to Eloquent.
Register a factory by providing label
, class
and callback
arguments. The callback function provides an instance of
Faker.js and should return an object of attributes for your model.
const factory = require('factory')
const User = require('../models/user')
factory.register('user', User, faker => {
return {
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
email: faker.internet.email(),
}
})
Once you've registered your factory bindings, you can make as many models as you like, each with unique data. You can also replace the default attributes with your own.
let users = factory('user', 10)->make() // array of fake users
let adminUsers = factory('user', 10)->make({ isAdmin: true }) // array of fake admin users
The factory assumes two things about your model class. The first assumption is that the constructor of your model takes an object of attributes as it's only argument.
class User {
constructor (attributes = {}) {
this.attributes = attributes
}
}
The second assumption is that your class has a method called create() which will persist your model to your storage engine.
class User {
async create () {
return await firebase.database().location('users').push(this.attributes)
}
}
With these two assumptions, you should be able to create fake models in no time. This is a tiny package, so please feel free to comment or send me a Pull Request.
FAQs
A factory for making fake objects with faker.js
We found that faker-factory 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.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.