Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stampit

Package Overview
Dependencies
Maintainers
2
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stampit

Create objects from reusable, composable behaviors.

  • 4.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
230K
increased by3.41%
Maintainers
2
Weekly downloads
 
Created

What is stampit?

The stampit package is a powerful library for creating composable, reusable, and flexible object factories in JavaScript. It leverages the concept of stamps, which are composable factory functions that produce objects. This approach allows for a more modular and maintainable codebase, especially in large applications.

What are stampit's main functionalities?

Creating Stamps

This feature allows you to create a stamp with default properties. The resulting stamp can be used to create new objects with those properties.

const stampit = require('stampit');

const MyStamp = stampit().props({
  name: 'defaultName',
  age: 0
});

const instance = MyStamp();
console.log(instance); // { name: 'defaultName', age: 0 }

Composing Stamps

This feature allows you to compose multiple stamps into a single stamp. The resulting stamp inherits properties from all composed stamps.

const stampit = require('stampit');

const StampA = stampit().props({
  name: 'StampA'
});

const StampB = stampit().props({
  age: 30
});

const ComposedStamp = stampit.compose(StampA, StampB);
const instance = ComposedStamp();
console.log(instance); // { name: 'StampA', age: 30 }

Adding Methods

This feature allows you to add methods to the stamp. The methods will be available on all objects created by the stamp.

const stampit = require('stampit');

const MyStamp = stampit().methods({
  sayHello() {
    console.log(`Hello, my name is ${this.name}`);
  }
}).props({
  name: 'John'
});

const instance = MyStamp();
instance.sayHello(); // Hello, my name is John

Initializers

This feature allows you to add initializers to the stamp. Initializers are functions that run when a new object is created by the stamp.

const stampit = require('stampit');

const MyStamp = stampit().init(function() {
  this.initialized = true;
});

const instance = MyStamp();
console.log(instance.initialized); // true

Other packages similar to stampit

Keywords

FAQs

Package last updated on 30 Mar 2021

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