Installations
npm install stampit
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
12.16.1
NPM Version
6.14.8
Score
99.6
Supply Chain
100
Quality
86.1
Maintenance
100
Vulnerability
100
License
Releases
55 bytes or 4% smaller bundle if Gzipped
Published on 30 Mar 2021
Minor but important - improved TypeScript support
Published on 04 Dec 2019
Getters and Setters built in support
Published on 15 Sept 2019
name: "MyStampName" in stampit arguments
Published on 15 Sept 2019
Added stampit.version
Published on 08 Mar 2018
Not so breaking release
Published on 09 Nov 2017
Contributors
Unable to fetch Contributors
Languages
JavaScript (90.22%)
TypeScript (9.68%)
HTML (0.11%)
Developer
Download Statistics
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
GitHub Statistics
3,017 Stars
689 Commits
103 Forks
73 Watching
2 Branches
32 Contributors
Package Meta Information
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
Publised On
30 Mar 2021
Total Downloads
Cumulative downloads
Total Downloads
0
Last day
0%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Stampit
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.
Example
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] }
Status
- v1.
npm i stampit@1
- v2.
npm i stampit@2
Breaking changes - v3.
npm i stampit@3
Breaking changes. Compatible with the stamp specification <= 1.4 - v4.
npm i stampit
Breaking changes. Compatible with the stamp specification v1.5 - next.
npm i @stamp/it
The new ecosystem of useful stamps like collision control, etc.
Install
Compatibility
Stampit should run fine in any ES5 browser or any node.js.
API
What's the Point?
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.
Development
Unit tests
npm t
Unit and benchmark tests
env CI=1 npm t
Unit tests in a browser
To run unit tests in a default browser:
npm run browsertest
To run tests in a different browser:
- Open the
./test/index.html
in your browser, and - open developer's console. The logs should indicate success.
Publishing to NPM registry
1npx 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
23 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: MIT License: LICENSE.md:0
Reason
SAST tool detected but not run on all commits
Details
- Info: SAST configuration detected: CodeQL
- Warn: 8 commits out of 13 are checked with a SAST tool
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:42: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/codeql-analysis.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/stampit-org/stampit/codeql-analysis.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:21
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
Found 0/19 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
4.7
/10
Last Scanned on 2024-12-16
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