{"name":"class-is","version":"0.2.1","description":"Enhances a JavaScript class by adding an is<Class> property to compare types between realms.","keywords":["withis","with-is","isclass","is-class","symbols","realms","instanceof","instance-of"],"author":{"name":"Diogo Silva","email":"fsdiogo@gmail.com"},"homepage":"https://github.com/moxystudio/js-class-is","repository":{"type":"git","url":"git+ssh://git@github.com/moxystudio/js-class-is.git"},"license":"MIT","main":"lib/index.js","module":"es/index.js","files":["lib","es"],"scripts":{"build:commonjs":"BABEL_ENV=commonjs babel src -d lib","build:es":"BABEL_ENV=es babel src -d es","build":"npm run build:commonjs && npm run build:es","lint":"eslint .","test":"jest --env node --coverage","prerelease":"npm t && npm run lint && npm run build","release":"standard-version","precommit":"lint-staged","commitmsg":"commitlint -e $GIT_PARAMS"},"standard-version":{"scripts":{"posttag":"git push --follow-tags origin master && npm publish"}},"lint-staged":{"*.js":["eslint --fix","git add"]},"commitlint":{"extends":["@commitlint/config-conventional"]},"devDependencies":{"@commitlint/cli":"^6.1.3","@commitlint/config-conventional":"^6.1.3","babel-cli":"^6.26.0","babel-preset-moxy":"^2.3.2","eslint":"^4.19.1","eslint-config-moxy":"^5.2.1","husky":"^0.14.3","jest":"^22.4.3","lint-staged":"^7.0.0","standard-version":"^4.3.0"},"dependencies":{},"gitHead":"8741227d57dab1f087e438e4d35fbd81763853e8","bugs":{"url":"https://github.com/moxystudio/js-class-is/issues"},"_id":"class-is@0.2.1","_npmVersion":"5.7.1","_nodeVersion":"9.5.0","_npmUser":{"name":"fsdiogo","email":"fsdiogo@gmail.com"},"dist":{"integrity":"sha512-gl+wWgc+7/Htb8fMyWEaHSy6p7BcSrFD+7pE5VysODLNoPlwk2jBUirw2FQw7Sq2hHGGT9LkWui8ETD/CrD7og==","shasum":"a491974cca3fe3e6e18d41d4e4432a52e84d3961","tarball":"http://registry-npm.ywwl.com/class-is/download/class-is-0.2.1.tgz","fileCount":6,"unpackedSize":10615,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD17buVpPz1ksb74bkICmnIfkJ3Hal3OqRuIJWcwRDfFgIhAMBkRx+x9xowdCOWbCvLYLN9CDLPKNY9qTNfuLBMJjG3"}],"size":3733,"noattachment":false,"key":"/class-is/-/class-is-0.2.1.tgz"},"maintainers":[{"email":"andreclima.pt@gmail.com","name":"acostalima"},{"email":"a.reis_05@hotmail.com","name":"afonsovreis"},{"email":"andregoncalves20007@gmail.com","name":"andregoncalvesdev"},{"email":"andre.neves@moxy.studio","name":"andreneves"},{"email":"antonio.c.capelo@gmail.com","name":"capelo"},{"email":"filipediasferreira@me.com","name":"filipediasf"},{"email":"fsdiogo@gmail.com","name":"fsdiogo"},{"email":"mail@hugodias.me","name":"hugomrdias"},{"email":"ivolimasilva@outlook.com","name":"ivolimasilva"},{"email":"jonnybel91@gmail.com","name":"jonnybel"},{"email":"marcooliveira@me.com","name":"marcooliveira"},{"email":"hello@moxy.studio","name":"moxyhq"},{"email":"nelsonfonseca.18@gmail.com","name":"nlfonseca"},{"email":"paulobmarcos@outlook.com","name":"paulobmarcos"},{"email":"ricardo.silva@moxy.studio","name":"ricardo-silva91"},{"email":"ruimpmonteiro12345@gmail.com","name":"ruimonteiro"},{"email":"rui.neves@moxy.studio","name":"ruipneves"},{"email":"andremiguelcruz@msn.com","name":"satazor"},{"email":"santos.vasco10@gmail.com","name":"vascosantos"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/class-is_0.2.1_1521807304457_0.4081498134888595"},"_hasShrinkwrap":false,"readme":"# class-is\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]\n\n[npm-url]:https://npmjs.org/package/class-is\n[downloads-image]:http://img.shields.io/npm/dm/class-is.svg\n[npm-image]:http://img.shields.io/npm/v/class-is.svg\n[travis-url]:https://travis-ci.org/moxystudio/js-class-is\n[travis-image]:http://img.shields.io/travis/moxystudio/js-class-is/master.svg\n[codecov-url]:https://codecov.io/gh/moxystudio/js-class-is\n[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/js-class-is/master.svg\n[david-dm-url]:https://david-dm.org/moxystudio/js-class-is\n[david-dm-image]:https://img.shields.io/david/moxystudio/js-class-is.svg\n[david-dm-dev-url]:https://david-dm.org/moxystudio/js-class-is?type=dev\n[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/js-class-is.svg\n[greenkeeper-image]:https://badges.greenkeeper.io/moxystudio/js-class-is.svg\n[greenkeeper-url]:https://greenkeeper.io/\n\nEnhances a JavaScript class by adding an `is<Class>` property to compare types between realms.\n\n\n## Motivation\n\nChecking if a value is an instance of a class in JavaScript is not an easy task.\n\nYou can use `instanceof`, but that doesn't work between different realms or different versions. Comparing with `constructor.name` could be a solution but if you need to Uglify the module it doesn't work, as it creates different names for the same module.\n\n[Symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) to the rescue!\n\n\n## Installation\n\n`$ npm install class-is`\n\nIf you want to use this module in the browser you have to compile it yourself to your desired target.\n\n\n## Usage\n\n### ES6 classes:\n\n```js\n// Package X\nconst withIs = require('class-is');\n\nclass Person {\n    constructor(name, city) {\n        this.name = name;\n        this.city = city;\n    }\n}\n\nmodule.exports = withIs(Person, {\n    className: 'Person',\n    symbolName: '@org/package-x/Person',\n});\n```\n\n```js\n// Package Y\nconst withIs = require('class-is');\n\nclass Animal {\n    constructor(species) {\n        this.species = species;\n    }\n}\n\nmodule.exports = withIs(Animal, {\n    className: 'Animal',\n    symbolName: '@org/package-y/Animal',\n});\n```\n\n```js\nconst Person = require('package-x');\nconst Animal = require('package-y');\n\nconst diogo = new Person('Diogo', 'Porto');\nconst wolf = new Animal('Gray Wolf');\n\nconsole.log(Person.isPerson(diogo));\nconsole.log(Person.isPerson(wolf));\n```\n\nRunning the example above will print:\n\n```\ntrue\nfalse\n```\n\n### ES5 and below classes:\n\nIn ES5 it's not unusual to see constructors like the one below, so you can call it without using the `new` keyword.\n\n```js\nfunction Circle(radius) {\n    if (!(this instanceof Circle)) {\n        return new Circle();\n    }\n\n    this.radius = radius;\n}\n```\n\nIn such cases you can use the `withIs.proto` method:\n\n```js\nconst withIs = require('class-is');\n\nconst Circle = withIs.proto(function (radius) {\n    if (!(this instanceof Circle)) {\n        return new Circle();\n    }\n\n    this.radius = radius;\n}, {\n    className: 'Circle',\n    symbolName: '@org/package/Circle',\n});\n```\n\n...or even better:\n\n```js\nconst withIs = require('class-is');\n\nfunction Circle(radius) {\n    this.radius = radius;\n}\n\nmodule.exports = withIs.proto(Circle, {\n    className: 'Circle',\n    symbolName: '@org/package/Circle',\n    withoutNew: true,\n});\n```\n\n\n## API\n\n### withIs(Class, { className, symbolName })\n\n###### class\n\nType: `class`\n\nThe class to be enhanced.\n\n###### className\n\nType: `String`\n\nThe name of the class your passing.\n\n###### symbolName\n\nType: `String`\n\nUnique *id* for the class. This should be namespaced so different classes from different modules do not collide and give false positives.\n\nExample: `@organization/package/Class`\n\n### withIs.proto(Class, { className, symbolName, withoutNew })\n\nThe `className` and `symbolName` parameters are the same as above.\n\n###### withoutNew\n\nType: `Boolean`   \nDefault: `false`\n\nAllow creating an instance without the `new` operator.\n\n\n## Tests\n\n`$ npm test`   \n`$ npm test -- --watch` during development\n\n\n## License\n\n[MIT](http://www.opensource.org/licenses/mit-license.php)\n","publish_time":1521807304535,"_cnpm_publish_time":1521807304535,"dist-tags":{"latest":"1.1.0"}}