{"_id":"kindof","_rev":"13-076d0dc2dfc5035d1988d0cd23a253a4","name":"kindof","description":"A proper typeof that works with primitives, built-in value objects and those from other execution contexts.","dist-tags":{"latest":"2.0.0"},"versions":{"0.1.337":{"name":"kindof","version":"0.1.337","description":"A proper and semantic typeof function that works with literal primitives, boxed objects or those from another execution context.","keywords":["tostring","type","typeof"],"homepage":"https://github.com/moll/js-kindof","bugs":{"url":"https://github.com/moll/js-kindof/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-kindof.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-kindof/blob/master/LICENSE"}],"main":"index.js","scripts":{"test":"make test"},"devDependencies":{"mocha":">= 1.12.0 < 2"},"_id":"kindof@0.1.337","dist":{"shasum":"dff5c637f579b2d8f0cbfb4b3bf24868ef77b5d9","tarball":"https://registry.npmjs.org/kindof/-/kindof-0.1.337.tgz","integrity":"sha512-KFNVOaB5DTfEjGcTZp6ngdp4cN4yYC+PrixkNjSk1MN6GPth5FhYFa+Ha3P3UwSbyjMrHh2MLkAA14ATjgk/AQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCv6s+MEcUbPdp+gZLmfMEL6th3h4RAESJ1Lvam61sgTwIhAOzLh71+2ku/ohWNjWQitDknqwftdxui2xQjyC5aaaY7"}]},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}],"directories":{}},"1.0.0":{"name":"kindof","version":"1.0.0","description":"A proper and semantic typeof function that works with literal primitives, boxed objects and those from another execution context.","keywords":["tostring","type","typeof"],"homepage":"https://github.com/moll/js-kindof","bugs":{"url":"https://github.com/moll/js-kindof/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-kindof.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-kindof/blob/master/LICENSE"}],"main":"kindof.js","scripts":{"test":"make test"},"devDependencies":{"mocha":">= 1.12.0 < 2"},"_id":"kindof@1.0.0","dist":{"shasum":"131899a8527537a94da2edcd5cc49fc609606560","tarball":"https://registry.npmjs.org/kindof/-/kindof-1.0.0.tgz","integrity":"sha512-c196X8+lYRqWpw5D0MFJGamh+ZQFmNGFqayjPUPVzMB9AGwbuwWLqr6YvQzRtkfcDqk4pv5T0e44HJWfXo2orQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC8U0ry7k/hC9c9ow5J57v8hz6F8QrV5hBLEFnKrTpGOgIgbE1C5u5w2XyK9wtVbSa5gLx3T1BfNbj83aWUoOs6GRc="}]},"_from":".","_npmVersion":"1.3.8","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}]},"2.0.0":{"name":"kindof","version":"2.0.0","description":"A proper typeof that works with primitives, built-in value objects and those from other execution contexts.","keywords":["kind","tostring","type","typeof"],"homepage":"https://github.com/moll/js-kindof","bugs":{"url":"https://github.com/moll/js-kindof/issues"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-kindof.git"},"licenses":[{"type":"LAGPL","url":"https://github.com/moll/js-kindof/blob/master/LICENSE"}],"main":"kindof.js","scripts":{},"devDependencies":{"mocha":">= 1.12.0 < 2"},"gitHead":"2303c9bc3edb650f92e435bdee274e4345d7df74","_id":"kindof@2.0.0","_shasum":"c335baf603a77cc37f8b406b73b6463fdbdf1abe","_from":".","_npmVersion":"2.7.6","_nodeVersion":"0.12.2","_npmUser":{"name":"moll","email":"andri@dot.ee"},"maintainers":[{"name":"moll","email":"andri@dot.ee"}],"dist":{"shasum":"c335baf603a77cc37f8b406b73b6463fdbdf1abe","tarball":"https://registry.npmjs.org/kindof/-/kindof-2.0.0.tgz","integrity":"sha512-ZjkyNRo87FUdtxtpx/MLmePxaLoAhipw0CSTNgX50S1BQhPnsjkgZ/Vso0tR9pbfrzzQiAn+MSFooZAr/GfUNw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+0DsL1vaKnVLjUXCsN5NEq9eKbzW8xjRpQaTL1076HwIhAOv55cGL+GdrM3dfzwa95SVOyoun16o/2GLVSr2QDODP"}]}}},"readme":"Kindof.js\n=========\n[![NPM version][npm-badge]](https://www.npmjs.com/package/kindof)\n[![Build status][travis-badge]](https://travis-ci.org/moll/js-kindof)\n\nKindof.js **provides a single `kindof` function** that does what you'd expect\nfrom `typeof` — gives you the proper semantic type regardless if the variable\nwas a **primitive** (`\"Hello\"`), a **built-in [value object][value-object]**\nlike (`new Date(2000, 5, 18)` or `/.*/`) or came from **another execution\ncontext** (e.g. an array from another `<iframe>`).\n\n### Tour\nWhen and why should you use `kindof` over `typeof`?\n\n- When you need a type check that returns `\"null\"` given the `null` value.  \n  You might remember, JavaScript's `typeof` says `null` is an object.\n- When you need to **differentiate** between **plain objects** (`{name:\n  \"John\"}`) and **built-in value objects** (`new Date(2000, 5, 18)`).  \n  A single `kindof(obj) == \"date\"` check makes that easy.  \n- When there's a chance you might get an object from **another execution\n  context**.  \n  In the browser that might mean an object from another `<frame>`.  \n  Different execution contexts have different built-in class instances, so you\n  can't do `obj instanceof Date` safely.\n- Kindof.js does not consider boxed objects (instances of `Boolean`, `Number`\n  and `String`) to of the same type as their primitive counterparts. See below\n  for why boxed objects are very error prone and should be avoided.\n\nKindof.js supports all ECMAScript **built-in types and primitives**:\n`undefined`, `null`, `Boolean`, `Number`, `String`, `Symbol`, `RegExp`, `Date`,\n`Array`, `Function` and plain old `Object`. Others, e.g. `Math` and `JSON`, are\nconsidered just objects.  In general, objects that behave like **value objects**\n(dates, regular expressions etc.) or proper arrays have a kind other than\n`object`.\n\nPlease see the table below for the full list of kinds.\n\n### Primitives and Boxed Objects\nYou might know, JavaScript has both primitive types and boxed object types for\nbooleans, numbers and strings. Primitives are what you get from code literals\n(`true`, `42`, `\"Hello\"`) and from `JSON.parse`. Boxed objects tend to only\nappear when someone explicitly calls their constructor (`new Boolean(false)`).\n\nBoxed objects wouldn't be so bad, except JavaScript's equivalence operator\n(`==`), for all its type coercions, doesn't handle them transparently. While you\ncan't compare other value types like dates and regular expressions with `==`\neither, you won't make that mistake that easily. The following is a small\nexample of problems with boxed objects:\n\n```javascript\nnew String(\"a\") == new String(\"a\") // => false\nnew Boolean(true) == new Boolean(true) // => false\nBoolean(new Boolean(false)) // => true\n!!(new Boolean(false)) // => true\n```\n\nIf you still wish Kindof to consider boxed Boolean, Number and String types like\nprimitives (returning `\"boolean\"`, `\"number\"` and `\"string\"` respectively), feel\nfree to use [Kindof.js's v1 branch][v1] with `npm install kindof@1`.\n\n[value-object]: https://en.wikipedia.org/wiki/Value_object\n[v1]: https://github.com/moll/js-kindof/tree/v1\n[npm-badge]: https://img.shields.io/npm/v/kindof.svg\n[travis-badge]: https://travis-ci.org/moll/js-kindof.png?branch=master\n\n\nInstalling\n----------\n**Note**: Kindof.js follows [semantic versioning](http://semver.org/).\n\n### Installing for the browser\nTake the `kindof.js` file and source it at will.\n\n### Installing on Node.js\nInstall with `npm install kindof`.  \nAnd require with `var kindof = require(\"kindof\")`.\n\n\nUsing\n-----\nPass any object to `kindof` and compare its output to what you expect:\n```javascript\nkindof(\"Hello\") // => \"string\"\nkindof(new Date(2000, 5, 18)) // => \"date\"\n```\n\nA switch statement might help:\n```javascript\nswitch (kindof(obj)) {\n  case \"null\":   this.name = \"Alfred\"; break\n  case \"string\": this.name = obj; break\n  case \"date\": this.birthdate = obj; break\n  default: throw new TypeError(\"Pardon, sir, came upon an unexpected type.\")\n}\n```\n\n\nKinds\n-----\nThe pattern is simple and follows `typeof`: besides primitives, built-in objects\nthat are **value objects** (dates, regular expressions etc.) or **real arrays**\nare of a kind other than `object`. The `arguments` object, for example, is not\na proper array and is therefore an `object`.\n\nValue                 | Kindof\n----------------------|----------\n`undefined           `| undefined\n`null                `| null\n`true                `| boolean\n`false               `| boolean\n`42                  `| number\n`NaN                 `| number\n`Infinity            `| number\n`\"Hello\"             `| string\n`Symbol()            `| symbol\n`Symbol(\"forEach\")   `| symbol\n`Symbol.iterator     `| symbol\n`/.*/                `| regexp\n`new RegExp(\".*\")    `| regexp\n`new Date            `| date\n`[42, 69]            `| array\n`function() {}       `| function\n`{}                  `| object\n`arguments           `| object\n`new Boolean(true)   `| object\n`new Number(42)      `| object\n`new String(\"Hello\") `| object\n`new MyClass         `| object\n`new Error           `| object\n`Math                `| object\n`JSON                `| object\n\n**Subclassed objects**, such as subclassed arrays, are considered to be `object`\nunless their internal `[[Class]]` property remains that of the original. For\nways to subclass properly, please see further reading below.\n\n\nFurther Reading\n---------------\n- The [`typeof` operator in ECMAScript 5.1][typeof-ecma].\n- The [`typeof` operator as implemented by Firefox][typeof-firefox].\n- Article on [subclassing `Array`][subclass] by [Juriy Zaytsev][juriy].\n\n[typeof-ecma]: http://www.ecma-international.org/ecma-262/5.1/#sec-11.4.3\n[typeof-firefox]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof\n[subclass]: http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/\n[juriy]: http://perfectionkills.com\n\n\nLicense\n-------\nKindof.js is released under a *Lesser GNU Affero General Public License*, which\nin summary means:\n\n- You **can** use this program for **no cost**.\n- You **can** use this program for **both personal and commercial reasons**.\n- You **do not have to share your own program's code** which uses this program.\n- You **have to share modifications** (e.g bug-fixes) you've made to this\n  program.\n\nFor more convoluted language, see the `LICENSE` file.\n\n\nAbout\n-----\n**[Andri Möll](http://themoll.com)** typed this and the code.  \n[Monday Calendar](https://mondayapp.com) supported the engineering work.\n\nIf you find Kindof.js needs improving, please don't hesitate to type to me now\nat [andri@dot.ee][email] or [create an issue online][issues].\n\n[email]: mailto:andri@dot.ee\n[issues]: https://github.com/moll/js-kindof/issues\n","maintainers":[{"name":"moll","email":"andri@dot.ee"}],"time":{"modified":"2022-06-19T08:46:21.417Z","created":"2013-09-14T13:08:12.106Z","0.1.337":"2013-09-14T13:08:15.606Z","1.0.0":"2013-09-14T14:17:43.605Z","2.0.0":"2015-05-25T10:23:16.486Z"},"author":{"name":"Andri Möll","email":"andri@dot.ee","url":"http://themoll.com"},"repository":{"type":"git","url":"git://github.com/moll/js-kindof.git"},"users":{"moll":true},"homepage":"https://github.com/moll/js-kindof","keywords":["kind","tostring","type","typeof"],"bugs":{"url":"https://github.com/moll/js-kindof/issues"},"readmeFilename":"README.md"}