{"name":"stampit","version":"5.0.0-next","keywords":["object","prototype","object oriented","browser","inheritance","oop","node","factory","class","stamp"],"author":{"url":"https://ericelliottjs.com","name":"Eric Elliott"},"license":"MIT","_id":"stampit@5.0.0-next","maintainers":[{"name":"ericelliott","email":"nospam@paralleldrive.com"},{"name":"koresar","email":"kore.sar@gmail.com"}],"homepage":"https://stampit.js.org","bugs":{"url":"https://github.com/stampit-org/stampit/issues"},"dist":{"shasum":"42e12268c245039cc2c4bc4a61d9a66a174bbfe9","tarball":"http://registry-npm.ywwl.com/stampit/download/stampit-5.0.0-next.tgz","fileCount":5,"integrity":"sha512-bpkLOuFdCl2y88SIzR5UQLxnRPxbjkEcwnxgYaHPs/bwejbSPNMFiukGwHM1TJhWVzKKT+LavAIyF2nGt/Z01A==","signatures":[{"sig":"MEUCIGtNwBrPGbqa+NbPcVQDYixi/fYm1UAEuZNVtevdmhJjAiEA9upzMghkcrg/B5c0DagPjDr8TG4kO+Cm/VkgbaeqS2M=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":28018,"size":9192,"noattachment":false,"key":"/stampit/-/stampit-5.0.0-next.tgz"},"main":"dist/stampit.min.js","types":"./types/index.d.ts","gitHead":"32b1b1c90a67a63eb099a060575b07d1aedcba21","scripts":{"ci":"npm run test","cov":"nyc npm run test","lint":"eslint ./src/ ./test/","test":"node test","build":"npm run minify","check":"npm run test && npm run lint","minify":"mkdirp ./dist/ && uglifyjs src/stampit.js -c collapse_vars,evaluate=false,unsafe,loops=false,keep_fargs=false,pure_getters,unused,dead_code,keep_fnames=[\"'stampit','Stamp'\"] -m reserved=['stampit','Stamp'] -o dist/stampit.min.js","pretest":"npm run build","posttest":"node test/benchmark","prebuild":"rm -rf ./dist/*","postminify":"ls -l dist/ && echo GZIP size: && gzip-size --raw dist/stampit.min.js","preversion":"npm run check","browsertest":"mkdirp ./dist/ && browserify ./test/index.js > dist/test_bundle.js && cp ./test/index.html ./dist/ && open ./dist/index.html","postversion":"replace-in-file VERSION $npm_package_version dist/stampit.min.js"},"_npmUser":{"name":"koresar","email":"kore.sar@gmail.com"},"repository":{"url":"git+ssh://git@github.com/stampit-org/stampit.git","type":"git"},"_npmVersion":"10.9.0","description":"Create objects from reusable, composable behaviors.","directories":{},"_nodeVersion":"22.11.0","eslintConfig":{"env":{"es6":true,"node":true,"browser":true,"commonjs":true},"rules":{"no-prototype-builtins":0},"extends":"eslint:recommended","parserOptions":{"ecmaVersion":2023}},"minified:main":"dist/stampit.min.js","_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"nyc":"^17.1.0","tape":"^4.11.0","eslint":"^8.57.1","lodash":"^4.17.21","mkdirp":"^3.0.1","prettier":"^3.3.3","benchmark":"^2.1.4","uglify-js":"^3.13.3","browserify":"^17.0.1","typescript":"^3.6.4","require-all":"^3.0.0","check-compose":"^5.0.0","gzip-size-cli":"^5.1.0","replace-in-file":"^8.2.0"},"_npmOperationalInternal":{"tmp":"tmp/stampit_5.0.0-next_1732077383051_0.5969765199514181","host":"s3://npm-registry-packages"},"readme":"<p align=\"center\">\n<img src=\"https://raw.githubusercontent.com/stampit-org/stampit-logo/master/stampit-logo.png\" alt=\"stampit\" width=\"160\" />\n</p>\n\n# Stampit [![npm](https://img.shields.io/npm/dm/stampit.svg)](https://www.npmjs.com/package/stampit)\n\n**Create objects from reusable, composable behaviors**\n\nStampit is a **1.3KB** gzipped (or 4.8K 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.\n\nStamps are [standardised](https://github.com/stampit-org/stamp-specification) composable factory functions. **Stampit** is a handy implementation of the specification featuring friendly API.\n\nFind many more examples in [this series of mini blog posts](https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0) or on the [official website](https://stampit.js.org/api/quick-start).\n\n## Example\n\n```js\nimport stampit from \"stampit\";\n\nconst Character = stampit({\n  props: {\n    name: null,\n    health: 100,\n  },\n  init({ name = this.name }) {\n    this.name = name;\n  },\n});\n\nconst Fighter = Character.compose({\n  // inheriting\n  props: {\n    stamina: 100,\n  },\n  init({ stamina = this.stamina }) {\n    this.stamina = stamina;\n  },\n  methods: {\n    fight() {\n      console.log(`${this.name} takes a mighty swing!`);\n      this.stamina--;\n    },\n  },\n});\n\nconst Mage = Character.compose({\n  // inheriting\n  props: {\n    mana: 100,\n  },\n  init({ mana = this.mana }) {\n    this.mana = mana;\n  },\n  methods: {\n    cast() {\n      console.log(`${this.name} casts a fireball!`);\n      this.mana--;\n    },\n  },\n});\n\nconst Paladin = stampit(Mage, Fighter); // as simple as that!\n\nconst fighter = Fighter({ name: \"Thumper\" });\nfighter.fight();\nconst mage = Mage({ name: \"Zapper\" });\nmage.cast();\nconst paladin = Paladin({ name: \"Roland\", stamina: 50, mana: 50 });\npaladin.fight();\npaladin.cast();\n\nconsole.log(Paladin.compose.properties); // { name: null, health: 100, stamina: 100, mana: 100 }\nconsole.log(Paladin.compose.methods); // { fight: [Function: fight], cast: [Function: cast] }\n```\n\n## Status\n\n- **v1**. `npm i stampit@1`\n- **v2**. `npm i stampit@2` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/2.0)\n- **v3**. `npm i stampit@3` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v3.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) <= 1.4\n- **v4**. `npm i stampit@4` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v4.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) v1.5\n- **v5**. `npm i stampit` [Breaking changes](https://github.com/stampit-org/stampit/releases/tag/v5.0.0). Compatible with the [stamp specification](https://github.com/stampit-org/stamp-specification) v1.5\n\n## Install\n\n[![NPM](https://nodei.co/npm/stampit.png?compact=true)](https://www.npmjs.com/package/stampit)\n\n## API\n\nSee https://stampit.js.org\n\n# What's the Point?\n\nPrototypal OO is great, and JavaScript's capabilities give us some really powerful tools to explore it, but it could be easier to use.\n\nBasic questions like \"how do I inherit privileged methods and private data?\" and\n\"what are some good alternatives to inheritance hierarchies?\" are stumpers for many JavaScript users.\n\nLet's answer both of these questions at the same time.\n\n```js\n// Some privileged methods with some private data.\nconst Availability = stampit({\n  init() {\n    let isOpen = false; // private\n\n    this.open = function open() {\n      isOpen = true;\n      return this;\n    };\n    this.close = function close() {\n      isOpen = false;\n      return this;\n    };\n    this.isOpen = function isOpenMethod() {\n      return isOpen;\n    };\n  },\n});\n\n// Here's a stamp with public methods, and some state:\nconst Membership = stampit({\n  props: {\n    members: {},\n  },\n  methods: {\n    add(member) {\n      this.members[member.name] = member;\n      return this;\n    },\n    getMember(name) {\n      return this.members[name];\n    },\n  },\n});\n\n// Let's set some defaults:\nconst Defaults = stampit({\n  props: {\n    name: \"The Saloon\",\n    specials: \"Whisky, Gin, Tequila\",\n  },\n  init({ name, specials }) {\n    this.name = name || this.name;\n    this.specials = specials || this.specials;\n  },\n});\n\n// Classical inheritance has nothing on this.\n// No parent/child coupling. No deep inheritance hierarchies.\n// Just good, clean code reusability.\nconst Bar = stampit(Defaults, Availability, Membership);\n\n// Create an object instance\nconst myBar = Bar({ name: \"Moe's\" });\n\n// Silly, but proves that everything is as it should be.\nmyBar.add({ name: \"Homer\" }).open().getMember(\"Homer\");\n```\n\nFor more examples see the [API](https://stampit.js.org) or the [Fun With Stamps](https://medium.com/@koresar/fun-with-stamps-episode-1-stamp-basics-e0627d81efe0) mini-blog series.\n\n# Development\n\n### Unit tests\n\n```\nnpm t\n```\n\n### Benchmark tests\n\n```\nnpm run test:benchmark\n```\n","publish_time":1732077383214,"_cnpm_publish_time":1732077383214,"dist-tags":{"latest":"5.1.0","next":"5.0.5-next","rc":"3.0.0-rc.11"}}