New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rosie

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rosie

factory for building JavaScript objects, mostly useful for setting up test data. Inspired by factory_girl

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
599K
decreased by-0.01%
Maintainers
2
Weekly downloads
 
Created

What is rosie?

Rosie is a factory for building JavaScript objects, useful for setting up test data or creating objects with default values.

What are rosie's main functionalities?

Defining a Factory

This feature allows you to define a factory with attributes. In this example, a user factory is created with an 'id' attribute that generates a random number and a 'name' attribute with a default value of 'John Doe'.

const Factory = require('rosie').Factory;
const userFactory = new Factory()
  .attr('id', () => Math.floor(Math.random() * 1000))
  .attr('name', 'John Doe');

Building an Object

This feature allows you to build an object using the defined factory. The 'build' method generates an object with the specified attributes. In this example, it creates a user object with a random 'id' and the name 'John Doe'.

const user = userFactory.build();
console.log(user);

Overriding Attributes

This feature allows you to override default attributes when building an object. In this example, the 'name' attribute is overridden to 'Jane Doe' while the 'id' attribute remains randomly generated.

const customUser = userFactory.build({ name: 'Jane Doe' });
console.log(customUser);

Defining Sequences

This feature allows you to define sequences for attributes. In this example, the 'id' attribute is a sequence that increments with each build, while the 'name' attribute remains 'Sequence User'.

const sequenceFactory = new Factory()
  .sequence('id')
  .attr('name', 'Sequence User');
const user1 = sequenceFactory.build();
const user2 = sequenceFactory.build();
console.log(user1, user2);

Other packages similar to rosie

Keywords

FAQs

Package last updated on 11 Nov 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc