{"id":18873549,"url":"https://github.com/bartekleon/param-type","last_synced_at":"2025-08-05T18:13:11.350Z","repository":{"id":48314423,"uuid":"147855610","full_name":"bartekleon/param-type","owner":"bartekleon","description":"Get the type of every parameter","archived":false,"fork":false,"pushed_at":"2021-08-02T05:19:35.000Z","size":97,"stargazers_count":2,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T00:42:35.194Z","etag":null,"topics":["array","boolean","javascript","number","object","regexp","string","type","type-of","typeof","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/bartekleon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-07T17:37:43.000Z","updated_at":"2020-08-07T14:27:19.000Z","dependencies_parsed_at":"2022-09-21T10:13:42.463Z","dependency_job_id":null,"html_url":"https://github.com/bartekleon/param-type","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartekleon%2Fparam-type","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartekleon%2Fparam-type/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartekleon%2Fparam-type/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bartekleon%2Fparam-type/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bartekleon","download_url":"https://codeload.github.com/bartekleon/param-type/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239825010,"owners_count":19703199,"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":["array","boolean","javascript","number","object","regexp","string","type","type-of","typeof","typescript"],"created_at":"2024-11-08T05:35:14.576Z","updated_at":"2025-02-20T11:15:59.927Z","avatar_url":"https://github.com/bartekleon.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# param-type [![NPM version](https://img.shields.io/npm/v/param-type.svg?style=flat)](https://www.npmjs.com/package/param-type)\n\nSpeed and accuracy - that is what param-type offers. Thanks to multiple benchmarks it is **as fast as it is possible**!\nUnit tests make sure that **each case** is checked and works as intended.\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save param-type\n```\n\n## Why use this instead of kind-of?\n\n1. [it's faster](#benchmarks)\n2. [even better type checking](#better-type-checking)\n\n```js\nimport paramType from 'param-type';\nor\nconst paramType = require('param-type').default;\n\nparamType(undefined); //=\u003e 'undefined'\n\nparamType(null); //=\u003e 'null'\n\nparamType(true); //=\u003e 'boolean'\n\nparamType(false); //=\u003e 'boolean'\n\nparamType(new Buffer('')); //=\u003e 'buffer'\n\nparamType(42); //=\u003e 'number'\n\nparamType('str'); //=\u003e 'string'\n\nparamType(arguments); //=\u003e 'arguments'\n\nparamType({}); //=\u003e 'object'\n\nparamType(Object.create(null)); //=\u003e 'object'\n\nparamType(new Test()); //=\u003e 'object'\n\nparamType(class Test {}); //=\u003e 'class'\n\nparamType(new Date()); //=\u003e 'date'\n\nparamType([1, 2, 3]); //=\u003e 'array'\n\nparamType(/foo/); //=\u003e 'regexp'\n\nparamType(new RegExp('foo')); //=\u003e 'regexp'\n\nparamType(new Error('error')); //=\u003e 'error'\n\nparamType(new TypeError('error')); //=\u003e 'TypeError'\n\nparamType(function () {}); //=\u003e 'function'\n\nparamType(function * () {}); //=\u003e 'generatorfunction'\n\nparamType(Symbol('str')); //=\u003e 'symbol'\n\nparamType(new Map()); //=\u003e 'map'\n\nparamType(new WeakMap()); //=\u003e 'weakmap'\n\nparamType(new Set()); //=\u003e 'set'\n\nparamType(new WeakSet()); //=\u003e 'weakset'\n\nparamType(new Int8Array()); //=\u003e 'int8array'\n\nparamType(new Uint8Array()); //=\u003e 'uint8array'\n\nparamType(new Uint8ClampedArray()); //=\u003e 'uint8clampedarray'\n\nparamType(new Int16Array()); //=\u003e 'int16array'\n\nparamType(new Uint16Array()); //=\u003e 'uint16array'\n\nparamType(new Int32Array()); //=\u003e 'int32array'\n\nparamType(new Uint32Array()); //=\u003e 'uint32array'\n\nparamType(new Float32Array()); //=\u003e 'float32array'\n\nparamType(new Float64Array()); //=\u003e 'float64array'\n\n```\n\n## Benchmarks\n\n```bash\n\n1 of 54; paramType: undefined, kindOf: undefined; undefined\nparamType x 232,529,580 ops/sec ±0.25% (96 runs sampled)\nkindOf x 232,828,210 ops/sec ±0.22% (95 runs sampled)\n\n2 of 54; paramType: null, kindOf: null; null\nparamType x 861,366,755 ops/sec ±0.08% (94 runs sampled)\nkindOf x 860,534,655 ops/sec ±0.09% (90 runs sampled)\n\n3 of 54; paramType: boolean, kindOf: boolean; true\nparamType x 859,796,084 ops/sec ±0.08% (96 runs sampled)\nkindOf x 859,137,398 ops/sec ±0.12% (93 runs sampled)\n\n4 of 54; paramType: boolean, kindOf: boolean; [Boolean: false]\nparamType x 11,456,708 ops/sec ±2.08% (92 runs sampled)\nkindOf x 7,743,944 ops/sec ±0.35% (91 runs sampled)\n\n5 of 54; paramType: number, kindOf: number; 42\nparamType x 854,180,837 ops/sec ±0.32% (92 runs sampled)\nkindOf x 844,934,313 ops/sec ±0.43% (92 runs sampled)\n\n6 of 54; paramType: number, kindOf: number; [Number: 42]\nparamType x 11,825,460 ops/sec ±0.49% (93 runs sampled)\nkindOf x 7,782,055 ops/sec ±0.94% (94 runs sampled)\n\n7 of 54; paramType: string, kindOf: string; str\nparamType x 856,236,138 ops/sec ±0.08% (96 runs sampled)\nkindOf x 850,086,443 ops/sec ±0.15% (93 runs sampled)\n\n8 of 54; paramType: string, kindOf: string; [String: 'str']\nparamType x 11,176,581 ops/sec ±2.26% (90 runs sampled)\nkindOf x 7,201,272 ops/sec ±0.61% (93 runs sampled)\n\n9 of 54; paramType: buffer, kindOf: buffer; \u003cBuffer \u003e\nparamType x 843,157,940 ops/sec ±1.37% (94 runs sampled)\nkindOf x 845,896,308 ops/sec ±0.08% (96 runs sampled)\n\n10 of 54; paramType: object, kindOf: object; Test {}\nparamType x 10,311,092 ops/sec ±0.78% (92 runs sampled)\nkindOf x 16,222,608 ops/sec ±0.41% (95 runs sampled)\n\n11 of 54; paramType: object, kindOf: object; {}\nparamType x 9,502,126 ops/sec ±1.86% (91 runs sampled)\nkindOf x 6,589,771 ops/sec ±0.35% (90 runs sampled)\n\n12 of 54; paramType: object, kindOf: object; {}\nparamType x 58,496,946 ops/sec ±0.62% (93 runs sampled)\nkindOf x 7,072,641 ops/sec ±0.37% (93 runs sampled)\n\n13 of 54; paramType: object, kindOf: object; {}\nparamType x 11,931,658 ops/sec ±0.40% (94 runs sampled)\nkindOf x 9,396,057 ops/sec ±1.02% (93 runs sampled)\n\n14 of 54; paramType: date, kindOf: date; 2018-08-30T14:06:11.084Z\nparamType x 854,501,424 ops/sec ±0.07% (96 runs sampled)\nkindOf x 835,282,391 ops/sec ±0.13% (94 runs sampled)\n\n15 of 54; paramType: array, kindOf: array; []\nparamType x 855,124,500 ops/sec ±0.12% (96 runs sampled)\nkindOf x 851,350,257 ops/sec ±0.08% (96 runs sampled)\n\n16 of 54; paramType: array, kindOf: array; [ 1, 2, 3 ]\nparamType x 855,533,418 ops/sec ±0.08% (95 runs sampled)\nkindOf x 851,269,708 ops/sec ±0.09% (94 runs sampled)\n\n17 of 54; paramType: array, kindOf: array; []\nparamType x 855,693,176 ops/sec ±0.08% (93 runs sampled)\nkindOf x 844,913,453 ops/sec ±1.42% (90 runs sampled)\n\n18 of 54; paramType: regexp, kindOf: regexp; /./\nparamType x 854,200,203 ops/sec ±0.04% (96 runs sampled)\nkindOf x 827,346,536 ops/sec ±0.11% (95 runs sampled)\n\n19 of 54; paramType: regexp, kindOf: regexp; /^foo$/\nparamType x 852,697,504 ops/sec ±0.09% (97 runs sampled)\nkindOf x 827,161,399 ops/sec ±0.17% (92 runs sampled)\n\n20 of 54; paramType: function, kindOf: function; () =\u003e { }\nparamType x 44,005,853 ops/sec ±0.27% (94 runs sampled)\nkindOf x 23,147,781 ops/sec ±0.30% (95 runs sampled)\n\n21 of 54; paramType: function, kindOf: function; function anonymous() { }\nparamType x 44,012,200 ops/sec ±0.15% (96 runs sampled)\nkindOf x 23,131,852 ops/sec ±0.33% (94 runs sampled)\n\n22 of 54; paramType: error, kindOf: error; Error\nparamType x 854,936,723 ops/sec ±0.21% (95 runs sampled)\nkindOf x 826,491,491 ops/sec ±0.10% (95 runs sampled)\n\n23 of 54; paramType: typeerror, kindOf: error; TypeError\nparamType x 848,079,116 ops/sec ±0.29% (94 runs sampled)\nkindOf x 823,982,705 ops/sec ±0.08% (94 runs sampled)\n\n24 of 54; paramType: syntaxerror, kindOf: error; SyntaxError\nparamType x 848,539,406 ops/sec ±0.22% (96 runs sampled)\nkindOf x 787,520,028 ops/sec ±2.13% (93 runs sampled)\n\n25 of 54; paramType: referenceerror, kindOf: error; ReferenceError\nparamType x 849,306,191 ops/sec ±0.15% (94 runs sampled)\nkindOf x 822,882,350 ops/sec ±0.09% (98 runs sampled)\n\n26 of 54; paramType: rangeerror, kindOf: error; RangeError\nparamType x 848,792,554 ops/sec ±0.17% (96 runs sampled)\nkindOf x 822,489,308 ops/sec ±0.09% (95 runs sampled)\n\n27 of 54; paramType: promise, kindOf: promise; Promise { 123 }\nparamType x 38,624,211 ops/sec ±0.38% (93 runs sampled)\nkindOf x 30,413,884 ops/sec ±1.48% (93 runs sampled)\n\n28 of 54; paramType: promise, kindOf: promise; Promise { \u003cpending\u003e }\nparamType x 38,842,016 ops/sec ±0.14% (96 runs sampled)\nkindOf x 30,605,588 ops/sec ±0.34% (96 runs sampled)\n\n29 of 54; paramType: generatorfunction, kindOf: generatorfunction; function* named() { return true; }\nparamType x 42,513,717 ops/sec ±1.31% (96 runs sampled)\nkindOf x 39,970,558 ops/sec ±0.27% (95 runs sampled)\n\n30 of 54; paramType: map, kindOf: map; Map {}\nparamType x 20,892,524 ops/sec ±0.36% (97 runs sampled)\nkindOf x 6,675,789 ops/sec ±0.65% (92 runs sampled)\n\n31 of 54; paramType: function, kindOf: function; function set() { [native code] }\nparamType x 42,471,400 ops/sec ±0.27% (98 runs sampled)\nkindOf x 23,045,797 ops/sec ±0.46% (94 runs sampled)\n\n32 of 54; paramType: function, kindOf: function; function get() { [native code] }\nparamType x 41,915,516 ops/sec ±1.34% (94 runs sampled)\nkindOf x 22,035,007 ops/sec ±1.98% (92 runs sampled)\n\n33 of 54; paramType: weakmap, kindOf: weakmap; WeakMap { [items unknown] }\nparamType x 38,271,040 ops/sec ±0.82% (93 runs sampled)\nkindOf x 26,519,721 ops/sec ±0.42% (94 runs sampled)\n\n34 of 54; paramType: function, kindOf: function; function set() { [native code] }\nparamType x 42,474,601 ops/sec ±0.49% (97 runs sampled)\nkindOf x 23,089,446 ops/sec ±0.39% (92 runs sampled)\n\n35 of 54; paramType: function, kindOf: function; function get() { [native code] }\nparamType x 42,493,569 ops/sec ±0.29% (95 runs sampled)\nkindOf x 22,965,640 ops/sec ±0.66% (95 runs sampled)\n\n36 of 54; paramType: set, kindOf: set; Set {}\nparamType x 37,147,866 ops/sec ±0.29% (94 runs sampled)\nkindOf x 20,203,494 ops/sec ±0.41% (93 runs sampled)\n\n37 of 54; paramType: function, kindOf: function; function add() { [native code] }\nparamType x 42,542,313 ops/sec ±0.18% (93 runs sampled)\nkindOf x 23,099,553 ops/sec ±0.30% (95 runs sampled)\n\n38 of 54; paramType: weakset, kindOf: weakset; WeakSet { [items unknown] }\nparamType x 38,111,152 ops/sec ±0.92% (95 runs sampled)\nkindOf x 23,624,576 ops/sec ±0.58% (94 runs sampled)\n\n39 of 54; paramType: function, kindOf: function; function add() { [native code] }\nparamType x 42,512,212 ops/sec ±0.33% (97 runs sampled)\nkindOf x 23,121,852 ops/sec ±0.34% (94 runs sampled)\n\n40 of 54; paramType: setiterator, kindOf: setiterator; [Set Iterator] {  }\nparamType x 3,119,704 ops/sec ±0.34% (92 runs sampled)\nkindOf x 2,374,588 ops/sec ±2.74% (96 runs sampled)\n\n41 of 54; paramType: mapiterator, kindOf: mapiterator; [Map Iterator] {  }\nparamType x 3,549,362 ops/sec ±0.25% (94 runs sampled)\nkindOf x 3,590,369 ops/sec ±1.46% (93 runs sampled)\n\n42 of 54; paramType: arrayiterator, kindOf: arrayiterator; Object [Array Iterator] {}\nparamType x 3,106,207 ops/sec ±0.29% (96 runs sampled)\nkindOf x 3,530,001 ops/sec ±0.29% (94 runs sampled)\n\n43 of 54; paramType: stringiterator, kindOf: stringiterator; Object [String Iterator] {}\nparamType x 3,033,089 ops/sec ±1.72% (96 runs sampled)\nkindOf x 3,596,716 ops/sec ±0.36% (94 runs sampled)\n\n44 of 54; paramType: symbol, kindOf: symbol; Symbol(foo)\nparamType x 854,952,179 ops/sec ±0.10% (97 runs sampled)\nkindOf x 851,428,920 ops/sec ±0.07% (92 runs sampled)\n\n45 of 54; paramType: symbol, kindOf: symbol; Symbol {}\nparamType x 38,830,190 ops/sec ±0.19% (96 runs sampled)\nkindOf x 34,718,953 ops/sec ±0.52% (92 runs sampled)\n\n46 of 54; paramType: int8array, kindOf: int8array; Int8Array [  ]\nparamType x 37,600,628 ops/sec ±0.31% (93 runs sampled)\nkindOf x 18,568,330 ops/sec ±2.19% (91 runs sampled)\n\n47 of 54; paramType: uint8array, kindOf: uint8array; Uint8Array [  ]\nparamType x 17,607,559 ops/sec ±2.58% (88 runs sampled)\nkindOf x 5,571,822 ops/sec ±1.41% (88 runs sampled)\n\n48 of 54; paramType: uint8clampedarray, kindOf: uint8clampedarray; Uint8ClampedArray [  ]\nparamType x 35,503,774 ops/sec ±2.23% (90 runs sampled)\nkindOf x 16,473,845 ops/sec ±0.44% (94 runs sampled)\n\n49 of 54; paramType: int16array, kindOf: int16array; Int16Array [  ]\nparamType x 35,284,544 ops/sec ±0.30% (94 runs sampled)\nkindOf x 14,742,312 ops/sec ±1.64% (93 runs sampled)\n\n50 of 54; paramType: uint16array, kindOf: uint16array; Uint16Array [  ]\nparamType x 36,774,376 ops/sec ±0.17% (95 runs sampled)\nkindOf x 14,369,110 ops/sec ±0.61% (93 runs sampled)\n\n51 of 54; paramType: int32array, kindOf: int32array; Int32Array [  ]\nparamType x 36,343,115 ops/sec ±0.34% (91 runs sampled)\nkindOf x 13,334,695 ops/sec ±0.36% (91 runs sampled)\n\n52 of 54; paramType: uint32array, kindOf: uint32array; Uint32Array [  ]\nparamType x 36,202,306 ops/sec ±1.00% (94 runs sampled)\nkindOf x 12,709,154 ops/sec ±0.39% (93 runs sampled)\n\n53 of 54; paramType: float32array, kindOf: float32array; Float32Array [  ]\nparamType x 35,642,803 ops/sec ±0.55% (94 runs sampled)\nkindOf x 12,137,500 ops/sec ±0.43% (92 runs sampled)\n\n54 of 54; paramType: float64array, kindOf: float64array; Float64Array [  ]\nparamType x 35,708,504 ops/sec ±0.30% (94 runs sampled)\nkindOf x 11,517,890 ops/sec ±0.39% (96 runs sampled)\n```\n\n## Better type checking\n\nReturns specific `Error` (TypeError, ReferenceError) type instead of `error`\n\n## Test\n\n- Unit tests:\n```sh\n$ npm install \u0026\u0026 npm test\n```\n- Benchmarking:\nImport your favourite type checking library in `benchmark.ts` and add it to test\n```javascript\ntargets.forEach((target, index) =\u003e {\n  console.log(`\\n${index + 1} of ${targets.length};`, `paramType: ${paramType(target)}`, target);\n  new Suite()\n    .add(\"typeOf\", () =\u003e {\n      paramType(target);\n    })\n    .add(Your library name, () =\u003e {\n      Your_library(target);\n    })\n    .on(\"cycle\", (event: Event) =\u003e {\n      console.log(`${String(event.target)}`);\n    })\n    .run();\n});\n```\n\n### Author\n\n**kmdrGroch**\n\n### License\nCopyright © 2018, [kmdrGroch](https://github.com/kmdrgroch).\nReleased under the [MIT License](LICENSE).\n\n### Note\nThe code will work for node \u003e= 8, although there is a possibility that development tools won't work for some versions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartekleon%2Fparam-type","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbartekleon%2Fparam-type","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbartekleon%2Fparam-type/lists"}