Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
object-factory
Advanced tools
Create and distribute test fixtures/factories.
All examples assume you have required object-factory like this:
var Factory = require('object-factory');
function Event(props) {
this.title = props.title;
this.location = props.location;
}
var EventFactory = new Factory({
object: Event
properties: {
// define defaults
title: 'Amazing Event',
location: 'Bahamas'
}
});
// create an object with the attributes of the factory but not an
// instance of the Event class
var event = EventFactory.build({
title: 'xxx'
});
// Create an instance of the event class
var event = EventFactory.create({
title: 'xxx'
});
When creating factories there are various options that can be passed.
.properties
new Factory({
properties: {
key: 'default value
'
}
});
The .properties
property (sorry) specify the default values for a
given factory.
.object
var MyThing = new Factory({
object: ThingWithConstructorThatAcceptsObjects
});
As the fictional object might suggest object is the object that the factories properties are passed into...
// This operation
MyThing.create({ xfoo: true });
// Translates to this
new ThingWithConstructorThatAcceptsObjects({ xfoo: true })
.onbuild
The onbuild
property will be called if given before the generated
properties are passed to the constructor .object
.
var BuildMe = new Factory({
onbuild: function(builtObject) {
// use this to customize the output of your factory for dynamic
// values, etc...
}
})
.oncreate
The oncreate
property will be called if given after the generated
properties are passed to the constructor .object
.
var BuildMe = new Factory({
object: Xfoo
oncreate: function(object) {
// (object instanceof Xfoo) === true
}
})
You can't create abritrarty depth in a factory. Each factory must be one object deep but multiple factories can be referenced as properties to create this nesting.
var Person = new Factory({
properties: {
name: 'James Lal'
}
});
var Event = new Factory({
properties: {
// define defaults
title: 'Amazing Event',
location: 'Bahamas',
person: Person
}
});
Factories can inherit from other factories:
var Developer = Person.extend({
properties: {
OCD: true
}
});
object factory ships with a object-factory-viewer
binary which will
pretty print the output of your factory given a module.
// xfoo.js
module.exports = new Factory({
properties: { xfoo: 'foo' }
});
./node_modules/.bin/object-factory-viewer xfoo.js
# will output the pretty printed (util.inspect) version of the factory.
If your not using .onbuild or .oncreate then this is a great way to test the output of your factories. This serves as a good sanity check (and could be used as documentation too).
FAQs
Build/share/create reusable factories
The npm package object-factory receives a total of 687 weekly downloads. As such, object-factory popularity was classified as not popular.
We found that object-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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.