{"_id":"interface","_rev":"21-ec5623245b1ef29c0cb77efa8e379476","name":"interface","description":"Enforce an interface on classes","dist-tags":{"latest":"1.2.1"},"versions":{"0.0.1":{"name":"interface","author":{"name":"Bradley Meck","email":"bradley.meck@gmail.com"},"description":"System for development. Middleware for libraries and applications.","version":"0.0.1","main":"./lib/interface","_id":"interface@0.0.1","engines":{"node":"*"},"_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/interface/-/interface-0.0.1.tgz","shasum":"d2ac5c2a3f50d2b9cfa340b2b83ce8870bfc0c4f","integrity":"sha512-fGo8WxOuxn5otVy5RPdbO0JCkrqKRa9LPT0EEZjJuHAilLhxNlPt1ot1L+oKSFkkJvfc6tLy+HA3kRUCLvmOLg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG3zKo4joCNS/Vu01GogciZpLpUMKpRRVEIVyv6ELFD5AiEAr0ODJL4O+2p1Bl6UkhI6MYcbGOBtD8qfAJA9wjMWPU0="}]}},"0.1.0":{"name":"interface","author":{"name":"Bradley Meck","email":"bradley.meck@gmail.com"},"description":"System for development. Middleware for libraries and applications.","version":"0.1.0","main":"./lib/interface","_id":"interface@0.1.0","engines":{"node":"*"},"_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/interface/-/interface-0.1.0.tgz","shasum":"7bcb9a17356250a17066e0b26df966f4d21f3c8e","integrity":"sha512-T/iWs2vOHClVlPuBpj74eMhe0DkJfg3cU3zqajGoB056IRnYi/KMZygC2Oqc6NRn55nNJRwAkDv1+FwlbE2V5A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIEHaEbgPBzhkuv7x4WTV8R6sfa1mAM6jRx0A7JVvso7yAiEAuE5S5lCDmw82tB9GQvjfigYuWXP67Je+7oTKpPrd07A="}]}},"0.1.1":{"name":"interface","author":{"name":"Bradley Meck","email":"bradley.meck@gmail.com"},"description":"System for development. Middleware for libraries and applications.","version":"0.1.1","main":"./lib/interface","_id":"interface@0.1.1","engines":{"node":"*"},"_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/interface/-/interface-0.1.1.tgz","shasum":"ad7ed2fc82058cd4a452a6546ceb93df5a1d70d7","integrity":"sha512-0+RJpDvlAIQOM6SPQCH8SxDdHz4HTrx3xTnyWbjBsUUxSwWOc8oRpEUp2/Pb5jnXTnFsqtwbPaTyb7CGbGUbvQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDsJN/RoekOzMSNTslsC2SWibse0yXhCZxA/5RWKbE4aAIgP8zEJMoEXEcWcgd7w5vKOCNH1Ex+Xqlc4YgYq2ohdtM="}]}},"1.0.0":{"name":"interface","version":"1.0.0","description":"Enforce an interface on classes","main":"index.js","dependencies":{},"devDependencies":{"chai":"^3.5.0","eslint":"^3.15.0","eslint-config-standard":"^6.2.1","eslint-plugin-promise":"^3.4.2","eslint-plugin-standard":"^2.0.1","mocha":"^3.2.0","nyc":"^10.1.2"},"scripts":{"test":"nyc mocha","lint":"eslint ."},"author":{"name":"Charlie Duong"},"license":"MIT","directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"keywords":["interface"],"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"homepage":"https://github.com/charlieduong94/interface-js#readme","gitHead":"b0fbc3ad3d4662a995c1f1384aa21f232f5b0323","_id":"interface@1.0.0","_shasum":"9a4757d8a15f9c9c1ce4ce33f428dcca8b5c8b25","_from":".","_npmVersion":"2.15.11","_nodeVersion":"6.9.1","_npmUser":{"name":"charlieduong94","email":"charlieduong94@gmail.com"},"dist":{"shasum":"9a4757d8a15f9c9c1ce4ce33f428dcca8b5c8b25","tarball":"https://registry.npmjs.org/interface/-/interface-1.0.0.tgz","integrity":"sha512-e4R4VMpLIroJrWiAtQSXJderkE8BDkLFFJ1oXjztZ5eRLNe+LgQspZmj8suI8YqvMSf52g6Aq5KhDzVCKJ22dw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD60Hpv0mojBCHpPm+KeK0dYIyLvweK+/1YevbuyVPiKQIhAJmjrwSQivIHOn7BJEHODqay4ZF3GlUqUDFkGQ4+FOja"}]},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/interface-1.0.0.tgz_1487965980279_0.09212903422303498"}},"1.1.0":{"name":"interface","version":"1.1.0","description":"Enforce an interface on classes","main":"index.js","dependencies":{},"devDependencies":{"chai":"^3.5.0","coveralls":"^2.11.16","eslint":"^3.15.0","eslint-config-standard":"^6.2.1","eslint-plugin-promise":"^3.4.2","eslint-plugin-standard":"^2.0.1","mocha":"^3.2.0","nyc":"^10.1.2"},"scripts":{"test":"nyc --reporter=lcov mocha","lint":"eslint .","coveralls":"cat ./coverage/lcov.info | coveralls"},"author":{"name":"Charlie Duong"},"license":"MIT","directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"keywords":["interface"],"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"homepage":"https://github.com/charlieduong94/interface-js#readme","gitHead":"b020e56fe225378ab9da90e7bd0edc62395ef37f","_id":"interface@1.1.0","_shasum":"7e08b31801901fc4d559d5e1b09eb937373bddfe","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"charlieduong94","email":"charlieduong94@gmail.com"},"dist":{"shasum":"7e08b31801901fc4d559d5e1b09eb937373bddfe","tarball":"https://registry.npmjs.org/interface/-/interface-1.1.0.tgz","integrity":"sha512-jSgh5O9GALVwUxTKn8nqsJQ+uerVL8PryddtaKftg2dtMzGFDkbxRauZ+BiC3WxyumsVj6y+idfdxGTYkLSjIA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIASThSOTRw85YTldQm+OCzU3rIhSCvCO22JaQbXyBnerAiEAtHKkOCnouXU4QI8bg4kFDDu60pHDOvZKL60p/LF3v0Y="}]},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/interface-1.1.0.tgz_1488058732581_0.2806674875319004"}},"1.1.1":{"name":"interface","version":"1.1.1","description":"Enforce an interface on classes","main":"index.js","dependencies":{},"devDependencies":{"chai":"^3.5.0","coveralls":"^2.11.16","eslint":"^3.15.0","eslint-config-standard":"^6.2.1","eslint-plugin-promise":"^3.4.2","eslint-plugin-standard":"^2.0.1","mocha":"^3.2.0","nyc":"^10.1.2"},"scripts":{"test":"nyc --reporter=lcov mocha","lint":"eslint .","coveralls":"cat ./coverage/lcov.info | coveralls"},"author":{"name":"Charlie Duong"},"license":"MIT","directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"keywords":["interface"],"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"homepage":"https://github.com/charlieduong94/interface-js#readme","gitHead":"5870427ff0152bb97934b1c45f4443d65cf7980d","_id":"interface@1.1.1","_shasum":"546e67e940cb524ec4e1db4bdcc779f39b5545ac","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.4.0","_npmUser":{"name":"charlieduong94","email":"charlieduong94@gmail.com"},"dist":{"shasum":"546e67e940cb524ec4e1db4bdcc779f39b5545ac","tarball":"https://registry.npmjs.org/interface/-/interface-1.1.1.tgz","integrity":"sha512-TD4HMynxPs2s1PQ/M+0Q5L8h3+PJcRF45LWzK8i6h6kdNYHtzeTZDbnSM7bqlXtpbtLQbXQ5VTT8X7yQMs2nyw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCsGxHpdBIMIeExXzDEeNQjCI7Rwb8u0HwP5tIZ5e6qjwIhALgZRlPQ//wA/xTPkejBgd3h+9234Tj2iuY36KbFCoLU"}]},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/interface-1.1.1.tgz_1488078769380_0.8995967051014304"}},"1.2.0":{"name":"interface","version":"1.2.0","description":"Enforce an interface on classes","main":"index.js","dependencies":{},"devDependencies":{"chai":"^3.5.0","coveralls":"^2.11.16","eslint":"^4.3.0","eslint-config-standard":"^6.2.1","eslint-plugin-promise":"^3.4.2","eslint-plugin-standard":"^2.0.1","mocha":"^3.2.0","nyc":"^10.1.2"},"scripts":{"pretest":"npm run lint","test":"nyc --reporter=lcov mocha","lint":"eslint .","coveralls":"cat ./coverage/lcov.info | coveralls"},"author":{"name":"Charlie Duong"},"license":"MIT","directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"keywords":["interface"],"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"homepage":"https://github.com/charlieduong94/interface-js#readme","gitHead":"16622ab0c25c84398a3001bffbd880730f546400","_id":"interface@1.2.0","_npmVersion":"5.0.3","_nodeVersion":"8.1.4","_npmUser":{"name":"charlieduong94","email":"charlieduong94@gmail.com"},"dist":{"integrity":"sha512-mn5OZr4kH6wO3sfWJKccF60UX64IxuYSmUYpGjL9apOcbtssQgRz1p8wCwXji/Gnuftocj5Jjy2tmr272S3+Ng==","shasum":"e10821fc254bc5c6ea1223a6ff1b2b98e51d4a27","tarball":"https://registry.npmjs.org/interface/-/interface-1.2.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIF+okUPHw61vvwjCl5lhdp9VWiEUHQHxXMEprVspHio4AiANTXLV0fIWWPjc12ILy3PstxYixO7gn/cLO4+8TiLFug=="}]},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/interface-1.2.0.tgz_1501074992611_0.20582576002925634"}},"1.2.1":{"name":"interface","version":"1.2.1","description":"Enforce an interface on classes","main":"index.js","dependencies":{},"devDependencies":{"chai":"^3.5.0","coveralls":"^2.11.16","eslint":"^4.3.0","eslint-config-standard":"^6.2.1","eslint-plugin-promise":"^3.4.2","eslint-plugin-standard":"^2.0.1","mocha":"^3.2.0","nyc":"^10.1.2"},"scripts":{"pretest":"npm run lint","test":"nyc --reporter=lcov mocha","lint":"eslint .","coveralls":"cat ./coverage/lcov.info | coveralls"},"author":{"name":"Charlie Duong"},"license":"MIT","directories":{"test":"test"},"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"keywords":["interface"],"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"homepage":"https://github.com/charlieduong94/interface-js#readme","gitHead":"f29d1edb221ed0527b274eabbc8f27cbf95ce6a9","_id":"interface@1.2.1","_npmVersion":"5.0.3","_nodeVersion":"8.1.4","_npmUser":{"name":"charlieduong94","email":"charlieduong94@gmail.com"},"dist":{"integrity":"sha512-qMf+X2WyPxlGKE/lyBxQ7Ju3RNe8buQUxRBVPlmrmqMyMvQtPUShz7a/281njPjGnUMJ7hJ8+3Wx8Y7H6L5ixw==","shasum":"ba9ec974a56fc576e497278348dd59b3fc9a7c44","tarball":"https://registry.npmjs.org/interface/-/interface-1.2.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIADlu5DkNWIGv2eCD2fg2aLp6PUr/AtXZda+aDG952fiAiBw+2ui24SFnvXFWWETgNr/36QU3qxadz3jM43XHosCQA=="}]},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/interface-1.2.1.tgz_1501720546911_0.47906701965257525"}}},"maintainers":[{"name":"bradleymeck","email":"bradley.meck@gmail.com"},{"name":"charlieduong94","email":"charlieduong94@gmail.com"}],"author":{"name":"Charlie Duong"},"readme":"# Interface-js\n[![Build Status](https://travis-ci.org/charlieduong94/interface-js.svg?branch=master)](https://travis-ci.org/charlieduong94/interface-js)\n[![Coverage Status](https://coveralls.io/repos/github/charlieduong94/interface-js/badge.svg)](https://coveralls.io/github/charlieduong94/interface-js)\n\nExposes a way to enforce an interface on classes.\n\n### Installation\n\n```bash\nnpm install --save interface\n```\n\n### Usage\n\nTo enforce an interface, first create a new `Interface` and pass it the function names that you want to enforce.\n\n```js\nconst MyInterface = Interface.create('myMethodA', 'myMethodB')\n```\n\nor alternatively\n\n```js\nconst MyInterface = new Interface('myMethodA', 'myMethodB')\n```\n\nNext, just make your class extend from the interface. Make sure you call `super()` within your class's constructor.\n\n```js\nclass MyClass extends MyInterface {\n  constructor () {\n    super()\n  }\n\n  myMethodA () {\n    // ...implementation goes here\n  }\n}\n```\n\nNow, whenever you try to instantiate `MyClass`, the interface will be enforced.\n\n```js\nconst instance = new MyClass()\n// throws a new error with the message:\n// 'The following function(s) need to be implemented for class MyClass: myMethodB'\n```\n\nOf course, the interface is enforced on all subclasses as well.\n\n```js\nclass MySubClass extends MyClass {\n  constructor () {\n    super()\n  }\n\n  myMethodA () {\n    // override 'myMethodA'\n  }\n}\n\nconst instance = new MySubClass()\n// still throws an error with the message:\n// 'The following function(s) need to be implemented for class MyClass: myMethodB'\n```\n\nInterfaces can be enforced for classes defined the old way too.\n\n```js\nconst inherits = require('util').inherits\n\nconst MyInterface = new Interface('myMethodA', 'myMethodB', 'myMethodC')\n\nfunction MyClass () {\n  MyInterface.call(this)\n}\n\ninherits(MyClass, MyInterface)\n\nMyClass.prototype.myMethodA = function () {\n  // implementation\n}\n\nfunction MySubClass () {\n  MyClass.call(this)\n}\n\n// inherit prototype of parent class\ninherits(MySubClass, MyClass)\n\nMySubClass.prototype.myMethodB = function () {\n  // implementation\n}\n\nvar instance = new MySubClass()\n// throws an error with the message:\n// 'The following function(s) need to be implemented for class MyClass: myMethodC'\n```\n\nYou can also enforce that arbitrary objects match an interface by using\nthe `isImplementedBy` method.\n\n```js\nconst MyInterface = new Interface('myMethod')\n\nclass MyClass {\n  myMethod () {\n    // some implementation\n  }\n}\n\nclass MyOtherClass {\n  myOtherMethod () {\n    // some implementation\n  }\n}\n\nconst instanceA = new MyClass()\nconst instanceB = new MyOtherClass()\n\nMyInterface.isImplementedBy(instanceA) // returns true\nMyInterface.isImplementedBy(instanceB) // returns false\n```\n","readmeFilename":"README.md","time":{"modified":"2022-06-19T01:44:41.146Z","created":"2017-02-24T19:27:28.649Z","0.0.1":"2017-02-24T19:27:28.649Z","0.1.0":"2017-02-24T19:27:28.649Z","0.1.1":"2017-02-24T19:27:28.649Z","1.0.0":"2017-02-24T19:53:00.869Z","1.1.0":"2017-02-25T21:38:53.274Z","1.1.1":"2017-02-26T03:12:51.235Z","1.2.0":"2017-07-26T13:16:33.673Z","1.2.1":"2017-08-03T00:35:47.964Z"},"homepage":"https://github.com/charlieduong94/interface-js#readme","keywords":["interface"],"repository":{"type":"git","url":"git+https://github.com/charlieduong94/interface-js.git"},"bugs":{"url":"https://github.com/charlieduong94/interface-js/issues"},"license":"MIT"}