{"id":21074801,"url":"https://github.com/dawsbot/to-type","last_synced_at":"2025-05-16T06:31:35.283Z","repository":{"id":57377433,"uuid":"53637610","full_name":"dawsbot/to-type","owner":"dawsbot","description":"The way typeof should be","archived":false,"fork":false,"pushed_at":"2022-04-06T18:17:38.000Z","size":18,"stargazers_count":16,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-11T01:52:39.560Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dawsbot.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":".github/contributing.md","funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-11T03:47:10.000Z","updated_at":"2023-07-06T10:04:49.000Z","dependencies_parsed_at":"2022-09-26T16:41:48.506Z","dependency_job_id":null,"html_url":"https://github.com/dawsbot/to-type","commit_stats":null,"previous_names":["dawsonbotsford/to-type"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Fto-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Fto-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Fto-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dawsbot%2Fto-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dawsbot","download_url":"https://codeload.github.com/dawsbot/to-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225411493,"owners_count":17470246,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T19:18:04.336Z","updated_at":"2024-11-19T19:18:05.103Z","avatar_url":"https://github.com/dawsbot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# to-type\n\n\u003e The way typeof should be\n\n\u003cbr\u003e\n\n[![npm version](https://img.shields.io/npm/v/to-type.svg)](https://www.npmjs.com/package/to-type)\n[![npm download count](http://img.shields.io/npm/dm/to-type.svg?style=flat)](http://npmjs.org/to-type)\n[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/sindresorhus/xo)\n\n  \u003ctable\u003e\n    \u003cthead\u003e\n      \u003ctr\u003e\n        \u003cth\u003eLinux \u0026 OSX\u003c/th\u003e\n        \u003cth\u003eWindows\u003c/th\u003e\n      \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n      \u003ctr\u003e\n        \u003ctd align='center'\u003e\n          \u003ca href='https://travis-ci.org/dawsbot/to-type'\u003e\u003cimg src='https://api.travis-ci.org/dawsbot/to-type.svg?branch=master'\u003e\u003c/a\u003e\n        \u003c/td\u003e\n        \u003ctd align='center'\u003e\n          \u003ca href='https://ci.appveyor.com/project/dawsonbotsford/to-type'\u003e\u003cimg src='https://ci.appveyor.com/api/projects/status/xnen769jka939d6t/branch/master?svg=true'\u003e\u003c/a\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n    \u003c/tbody\u003e\n  \u003c/table\u003e\n\n\u003cbr\u003e\n\nA JavaScript implementation of [angus-c](https://github.com/angus-c)'s [Fixing the JavaScript typeof operator](https://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/).\n\n\u003cbr\u003e\n\n## Install\n\n#### Node\n\n```\nnpm install --save to-type\n```\n\u003cbr\u003e\n\n#### Web\n\n```html\n\u003cscript src=\"https://rawgit.com/dawsonbotsford/to-type/master/bundle.js\"\u003e\u003c/script\u003e\n```\n\n\u003cbr\u003e\n\nAlternatively, you can install the npm module and reference the bundle within `node_modules`\n\n```html\n\u003cscript src=\"\u003cpath to node_modules\u003e/to-type/bundle.js\"\u003e\u003c/script\u003e\n```\n\n\u003cbr\u003e\n\n## Usage\n\n```js\n// Remove this require line if you're using the web bundle (it's already bundled as \"to-type\")\nconst to-type = require('to-type');\n\ntoType([1, 2, 3]);\n//=\u003e 'array'\n\ntoType(/a-z/);\n//=\u003e 'regexp'\n\ntoType(new Number(4));\n//=\u003e 'number'\n\ntoType(new String('abc'));\n//=\u003e 'string'\n```\n\n\u003cbr\u003e\n\n## About\nJavaScript's `typeof` function sucks. It has returned vague values since [1997](http://www.ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%201st%20edition,%20June%201997.pdf#sec-11.4.3) and always will be due to backwards compatibility. It seems like nearly every call returns `object`. Don't believe me?\n\n\u003cbr\u003e\n\n```js\ntypeof {a: 4};\n//=\u003e 'object'\n\ntypeof [1, 2, 3];\n//=\u003e 'object'\n\ntypeof new ReferenceError;\n//=\u003e 'object'\n\ntypeof new Date;\n//=\u003e 'object'\n\ntypeof /a-z/;\n//=\u003e 'object'\n\ntypeof JSON;\n//=\u003e 'object'\n\ntypeof new Number(4);\n//=\u003e 'object'\n\ntypeof new String('abc');\n//=\u003e 'object'\n```\n\n\u003cbr\u003e\n\nDid I hear you say that was not enough proof?\n\n```js\ntypeof new Boolean(true);\n//=\u003e 'object'\n```\n\n\u003cbr\u003e\n\nWait, you're still not convinced?\n\n```js\ntypeof Math;\n//=\u003e 'object'\n```\n\n\u003cbr\u003e\n\n`to-type` fixes these vague outputs by returning the types you expect to see.\n\n\u003cbr\u003e\n\n## API\n\n### toType(target)\n\n\u003cbr\u003e\n\n#### target\n\n**Type**: `all types`\n\n\u003cbr\u003e\n\n#### returns\n\n**Type**: `string`\n\n**Description**: The return value is always **lowercased**.\n\n\u003cbr\u003e\n\n## More Examples\n```js\ntoType({a: 4});\n//=\u003e 'object'\n\ntoType(new Date());\n//=\u003e 'date'\n\ntoType(Math);\n//=\u003e'math'\n\ntoType(JSON);\n//=\u003e 'json'\n\ntoType(new Number(4));\n//=\u003e 'number'\n\ntoType(new String('abc'));\n//=\u003e 'string'\n\ntoType(new Boolean(true));\n//=\u003e 'boolean'\n\ntoType(new ReferenceError());\n//=\u003e 'error'\n\n\n//es2015 and newer\ntoType(Promise);\n//=\u003e 'function'\n\ntoType(Symbol());\n//=\u003e 'symbol'\n```\n\n\u003cbr\u003e\n\n## License\n\nMIT © [Dawson Botsford](http://dawsonbotsford.com)\n\n\u003cbr\u003e\n\n---\nIf you like this, star it. If you want to follow me, follow me.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawsbot%2Fto-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdawsbot%2Fto-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdawsbot%2Fto-type/lists"}