Gathering detailed insights and metrics for stampit
Gathering detailed insights and metrics for stampit
Gathering detailed insights and metrics for stampit
Gathering detailed insights and metrics for stampit
OOP is better with stamps: Composable object factories.
npm install stampit
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
100
Quality
81.3
Maintenance
100
Vulnerability
100
License
55 bytes or 4% smaller bundle if Gzipped
Updated on Mar 30, 2021
Minor but important - improved TypeScript support
Updated on Dec 04, 2019
Getters and Setters built in support
Updated on Sep 15, 2019
name: "MyStampName" in stampit arguments
Updated on Sep 15, 2019
Added stampit.version
Updated on Mar 08, 2018
Not so breaking release
Updated on Nov 09, 2017
JavaScript (90.22%)
TypeScript (9.68%)
HTML (0.11%)
Total Downloads
33,107,636
Last Day
33,918
Last Week
192,650
Last Month
906,084
Last Year
12,097,312
MIT License
3,013 Stars
689 Commits
104 Forks
71 Watchers
2 Branches
32 Contributors
Updated on May 07, 2025
Minified
Minified + Gzipped
Latest Version
4.3.2
Package Id
stampit@4.3.2
Size
9.04 kB
NPM Version
6.14.8
Node Version
12.16.1
Published on
Mar 30, 2021
Cumulative downloads
Total Downloads
Last Day
7.4%
33,918
Compared to previous day
Last Week
-8.9%
192,650
Compared to previous week
Last Month
-17.1%
906,084
Compared to previous month
Last Year
0.7%
12,097,312
Compared to previous year
Create objects from reusable, composable behaviors
Stampit is a 1.4KB gzipped (or 3K minified) JavaScript module which supports three different kinds of prototypal inheritance (delegation, concatenation, and functional) to let you inherit behavior in a way that is much more powerful and flexible than any other Object Oriented Programming model.
Stamps are standardised composable factory functions. Stampit is a handy implementation of the specification featuring friendly API.
Find many more examples in this series of mini blog posts or on the official website.
1import stampit from 'stampit' 2 3const Character = stampit({ 4 props: { 5 name: null, 6 health: 100 7 }, 8 init({ name = this.name }) { 9 this.name = name 10 } 11}) 12 13const Fighter = Character.compose({ // inheriting 14 props: { 15 stamina: 100 16 }, 17 init({ stamina = this.stamina }) { 18 this.stamina = stamina; 19 }, 20 methods: { 21 fight() { 22 console.log(`${this.name} takes a mighty swing!`) 23 this.stamina-- 24 } 25 } 26}) 27 28const Mage = Character.compose({ // inheriting 29 props: { 30 mana: 100 31 }, 32 init({ mana = this.mana }) { 33 this.mana = mana; 34 }, 35 methods: { 36 cast() { 37 console.log(`${this.name} casts a fireball!`) 38 this.mana-- 39 } 40 } 41}) 42 43const Paladin = stampit(Mage, Fighter) // as simple as that! 44 45const fighter = Fighter({ name: 'Thumper' }) 46fighter.fight() 47const mage = Mage({ name: 'Zapper' }) 48mage.cast() 49const paladin = Paladin({ name: 'Roland', stamina: 50, mana: 50 }) 50paladin.fight() 51paladin.cast() 52 53console.log(Paladin.compose.properties) // { name: null, health: 100, stamina: 100, mana: 100 } 54console.log(Paladin.compose.methods) // { fight: [Function: fight], cast: [Function: cast] }
npm i stampit@1
npm i stampit@2
Breaking changesnpm i stampit@3
Breaking changes. Compatible with the stamp specification <= 1.4npm i stampit
Breaking changes. Compatible with the stamp specification v1.5npm i @stamp/it
The new ecosystem of useful stamps like collision control, etc.Stampit should run fine in any ES5 browser or any node.js.
Prototypal OO is great, and JavaScript's capabilities give us some really powerful tools to explore it, but it could be easier to use.
Basic questions like "how do I inherit privileged methods and private data?" and "what are some good alternatives to inheritance hierarchies?" are stumpers for many JavaScript users.
Let's answer both of these questions at the same time.
1// Some privileged methods with some private data. 2const Availability = stampit({ 3 init() { 4 let isOpen = false; // private 5 6 this.open = function open() { 7 isOpen = true; 8 return this; 9 }; 10 this.close = function close() { 11 isOpen = false; 12 return this; 13 }; 14 this.isOpen = function isOpenMethod() { 15 return isOpen; 16 } 17 } 18}); 19 20// Here's a stamp with public methods, and some state: 21const Membership = stampit({ 22 props: { 23 members: {} 24 }, 25 methods: { 26 add(member) { 27 this.members[member.name] = member; 28 return this; 29 }, 30 getMember(name) { 31 return this.members[name]; 32 } 33 } 34}); 35 36// Let's set some defaults: 37const Defaults = stampit({ 38 props: { 39 name: "The Saloon", 40 specials: "Whisky, Gin, Tequila" 41 }, 42 init({ name, specials }) { 43 this.name = name || this.name; 44 this.specials = specials || this.specials; 45 } 46}); 47 48// Classical inheritance has nothing on this. 49// No parent/child coupling. No deep inheritance hierarchies. 50// Just good, clean code reusability. 51const Bar = stampit(Defaults, Availability, Membership); 52 53// Create an object instance 54const myBar = Bar({ name: "Moe's" }); 55 56// Silly, but proves that everything is as it should be. 57myBar.add({ name: "Homer" }).open().getMember("Homer");
For more examples see the API or the Fun With Stamps mini-blog series.
npm t
env CI=1 npm t
To run unit tests in a default browser:
npm run browsertest
To run tests in a different browser:
./test/index.html
in your browser, and1npx cut-release
It will run the cut-release
utility which would ask you if you're publishing patch, minor, or major version. Then it will execute npm version
, git push
and npm publish
with proper arguments for you.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
5 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-04-28
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More