{"name":"stampit","version":"5.0.0","keywords":["object","prototype","object oriented","browser","inheritance","oop","node","factory","class","stamp","mixin"],"license":"MIT","_id":"stampit@5.0.0","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":"ba312d1d66c0cad4cd190ff74820acacce294814","tarball":"http://registry-npm.ywwl.com/stampit/download/stampit-5.0.0.tgz","fileCount":5,"integrity":"sha512-SZ7R+uHzo3efFKps1au4bEpLfp44rX6UW4NmbBKHdTejn9KlgVqUX5B3cwsgKOXnDnn/tk2sZiW3lt0ygrpqkg==","signatures":[{"sig":"MEQCIBVqgqivcGFbFRkV9DqewgBUqUDo1F4xuedWbJWurmWrAiB558JZajMgmXffLK086LZpSLBeb+tjm/Jo1NdfV8OrNA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":36793,"size":9540,"noattachment":false,"key":"/stampit/-/stampit-5.0.0.tgz"},"type":"module","types":"stampit.d.ts","authors":[{"url":"https://ericelliottjs.com","name":"Eric Elliott"},{"url":"https://vasyl.boroviak.name","name":"Vasyl Boroviak"}],"exports":{".":"./stampit.js"},"gitHead":"eb1c51e3ad677d1e0d316f102ecd6440bdef4a9f","scripts":{"ci":"node --run test && node --run lint && node --run test:benchmark","cov":"c8 --reporter html node --run test && open ./coverage/index.html","lint":"oxlint --ignore-pattern='*.ts'","size":"uglifyjs ./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 ./stampit.min.js && echo 'min.js -> min.js.gz:' && gzip-size --raw --include-original ./stampit.min.js && rm ./stampit.min.js","test":"node --test \"test/*.test.js\" && node --run size","test:benchmark":"node --test \"test/benchmark/*.test.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.3","description":"Create objects from reusable, composable behaviors.","directories":{},"_nodeVersion":"22.19.0","_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","oxlint":"^1.19.0","prettier":"^3.3.3","benchmark":"^2.1.4","uglify-js":"^3.13.3","check-compose":"^5.1.0","gzip-size-cli":"^5.1.0"},"_npmOperationalInternal":{"tmp":"tmp/stampit_5.0.0_1759667412139_0.9453133928486694","host":"s3://npm-registry-packages-npm-production"},"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":1759667412343,"_cnpm_publish_time":1759667412343,"dist-tags":{"latest":"5.1.0","next":"5.0.5-next","rc":"3.0.0-rc.11"}}