{"id":16049103,"url":"https://github.com/alexindigo/precise-typeof","last_synced_at":"2025-03-18T04:31:06.951Z","repository":{"id":57329634,"uuid":"49860771","full_name":"alexindigo/precise-typeof","owner":"alexindigo","description":"Detects precise type of objects like `Array()`, `new Number(1)`, `new Boolean(true)`, etc","archived":false,"fork":false,"pushed_at":"2019-01-19T10:03:49.000Z","size":74,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-26T18:22:49.825Z","etag":null,"topics":["array","instance","instanceof","kind","kindof","object","plain-object","pojo","precise","type","typeof"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/precise-typeof","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/alexindigo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-18T07:55:10.000Z","updated_at":"2022-03-02T10:24:01.000Z","dependencies_parsed_at":"2022-09-06T20:30:47.496Z","dependency_job_id":null,"html_url":"https://github.com/alexindigo/precise-typeof","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexindigo%2Fprecise-typeof","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexindigo%2Fprecise-typeof/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexindigo%2Fprecise-typeof/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexindigo%2Fprecise-typeof/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexindigo","download_url":"https://codeload.github.com/alexindigo/precise-typeof/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244156628,"owners_count":20407541,"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","instance","instanceof","kind","kindof","object","plain-object","pojo","precise","type","typeof"],"created_at":"2024-10-09T00:13:36.634Z","updated_at":"2025-03-18T04:31:06.389Z","avatar_url":"https://github.com/alexindigo.png","language":"JavaScript","readme":"# precise-typeof [![NPM Module](https://img.shields.io/npm/v/precise-typeof.svg?style=flat)](https://www.npmjs.com/package/precise-typeof)\n\nBetter `typeof`. Detects real type of the objects like `Array()`, `new Number(1)`, `new Boolean(true)`, etc.\n\n[![PhantomJS Build](https://img.shields.io/travis/alexindigo/precise-typeof/master.svg?label=browser\u0026style=flat)](https://travis-ci.org/alexindigo/precise-typeof)\n[![Linux Build](https://img.shields.io/travis/alexindigo/precise-typeof/master.svg?label=linux:6.x-10.x\u0026style=flat)](https://travis-ci.org/alexindigo/precise-typeof)\n[![MacOS Build](https://img.shields.io/travis/alexindigo/precise-typeof/master.svg?label=macos:6.x-10.x\u0026style=flat)](https://travis-ci.org/alexindigo/precise-typeof)\n[![Windows Build](https://img.shields.io/appveyor/ci/alexindigo/precise-typeof/master.svg?label=windows:6.x-10.x\u0026style=flat)](https://ci.appveyor.com/project/alexindigo/precise-typeof)\n\n[![Coverage Status](https://img.shields.io/coveralls/alexindigo/precise-typeof/master.svg?label=code+coverage\u0026style=flat)](https://coveralls.io/github/alexindigo/precise-typeof?branch=master)\n[![Dependency Status](https://img.shields.io/david/alexindigo/precise-typeof.svg?style=flat)](https://david-dm.org/alexindigo/precise-typeof)\n[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://opensource.org/licenses/MIT)\n\n\u003c!-- Not yet ![Readme](https://img.shields.io/badge/readme-tested-brightgreen.svg?style=flat)\nToo many false positives [![Codacy Badge](https://img.shields.io/codacy/5f1289b78b7346498797f9f3cd674408.svg)](https://www.codacy.com/app/alexindigo/precise-typeof) --\u003e\n\n| compression              |    size |\n| :----------------------- | ------: |\n| precise-typeof.js        | 1.69 kB |\n| precise-typeof.min.js    |   809 B |\n| precise-typeof.min.js.gz |   391 B |\n\n\n## Install\n\n```sh\n$ yarn add precise-typeof\n```\n\nor\n\n```sh\n$ npm install --save precise-typeof\n```\n\n## Examples\n\n```javascript\nvar typeOf = require('precise-typeof');\n\ntypeOf({});               // -\u003e 'object'\ntypeOf(new function(){}); // -\u003e 'object'\ntypeOf([]);               // -\u003e 'array'\ntypeOf(25);               // -\u003e 'number'\ntypeOf(Infinity);         // -\u003e 'number'\ntypeOf('ABC');            // -\u003e 'string'\ntypeOf(function(){});     // -\u003e 'function'\ntypeOf(Math.sin);         // -\u003e 'function'\ntypeOf(undefined);        // -\u003e 'undefined'\ntypeOf(true);             // -\u003e 'boolean'\ntypeOf(null);             // -\u003e 'null'\ntypeOf(NaN);              // -\u003e 'nan'\n\n// object values\ntypeOf(new Object());                           // -\u003e 'object'\ntypeOf(new Array());                            // -\u003e 'array'\ntypeOf(new Number(5));                          // -\u003e 'number'\ntypeOf(new Number(Infinity));                   // -\u003e 'number'\ntypeOf(new String('ABC'));                      // -\u003e 'string'\ntypeOf(new Function('a', 'b', 'return a + b')); // -\u003e 'function'\ntypeOf(new Boolean());                          // -\u003e 'boolean'\ntypeOf(new Number('blabla'));                   // -\u003e 'nan'\n\n// instances\ntypeOf(new function Moment(){});                // -\u003e 'object'\n\n// special objects\ntypeOf(/s/);         // -\u003e 'regexp'\ntypeOf(new Date());  // -\u003e 'date'\ntypeOf(Math);        // -\u003e 'math'\ntypeOf(new Error()); // -\u003e 'error'\ntypeOf(arguments);   // -\u003e 'arguments'\n\n// node\ntypeOf(global);               // -\u003e 'global'\ntypeOf(process);              // -\u003e 'process'\ntypeOf(Buffer('B'));          // -\u003e 'buffer'\ntypeOf(new Buffer(2));        // -\u003e 'buffer'\ntypeOf(Buffer([62, 64, 66])); // -\u003e 'buffer'\n\n// es6\ntypeOf(Symbol('A')); // -\u003e 'symbol'\n\n// browser\ntypeOf(window);                                   // -\u003e 'global'\ntypeOf(document);                                 // -\u003e 'html'\ntypeOf(document.body);                            // -\u003e 'html'\ntypeOf(document.getElementsByTagName('html')[0]); // -\u003e 'html'\ntypeOf(document.getElementsByTagName('div'));     // -\u003e 'html'\ntypeOf(document.createElement('a'));              // -\u003e 'html'\ntypeOf(document.createTextNode('Abcd'));          // -\u003e 'text'\ntypeOf(document.createComment('abcd'));           // -\u003e 'comment'\ntypeOf(document.createEvent('Event'));            // -\u003e 'event'\ntypeOf(document.createEvent('UIEvents'));         // -\u003e 'event'\ntypeOf(document.createEvent('HTMLEvents'));       // -\u003e 'event'\ntypeOf(document.createEvent('MouseEvents'));      // -\u003e 'event'\n```\n\n### `{ pojoOnly: true }`\n\nWith `pojoOnly` flag it only reports Plain-Old Javascript Objects as `object`,\nand reports \"instances\" by their constructor names (e.g. `Moment` for `moment` instance).\nIn case if object was created from the nameless function, it will be reported as `unknown`.\n\n```javascript\nvar typeOf = require('precise-typeof');\n\n// reported differently with `{pojoOnly: true}`\ntypeOf(new function Moment(){}, {pojoOnly: true}); // -\u003e 'Moment'\ntypeOf(new function ABC(){}, {pojoOnly: true});    // -\u003e 'ABC'\ntypeOf(new function(){}, {pojoOnly: true});        // -\u003e 'unknown'\n\n// same with or without `{pojoOnly: true}`\ntypeOf({}, {pojoOnly: true});                      // -\u003e 'object'\ntypeOf([], {pojoOnly: true});                      // -\u003e 'array'\ntypeOf(25, {pojoOnly: true});                      // -\u003e 'number'\ntypeOf(Infinity, {pojoOnly: true});                // -\u003e 'number'\ntypeOf('ABC', {pojoOnly: true});                   // -\u003e 'string'\ntypeOf(function(){}, {pojoOnly: true});            // -\u003e 'function'\ntypeOf(Math.sin, {pojoOnly: true});                // -\u003e 'function'\ntypeOf(undefined, {pojoOnly: true});               // -\u003e 'undefined'\ntypeOf(true, {pojoOnly: true});                    // -\u003e 'boolean'\ntypeOf(null, {pojoOnly: true});                    // -\u003e 'null'\ntypeOf(NaN, {pojoOnly: true});                     // -\u003e 'nan'\n\ntypeOf(new Object(), {pojoOnly: true});            // -\u003e 'object'\ntypeOf(new Array(), {pojoOnly: true});             // -\u003e 'array'\ntypeOf(new Number(5), {pojoOnly: true});           // -\u003e 'number'\ntypeOf(new Number(Infinity), {pojoOnly: true});    // -\u003e 'number'\ntypeOf(new String('ABC'), {pojoOnly: true});       // -\u003e 'string'\ntypeOf(new Function(), {pojoOnly: true});          // -\u003e 'function'\ntypeOf(new Boolean(), {pojoOnly: true});           // -\u003e 'boolean'\ntypeOf(new Number('blabla'), {pojoOnly: true});    // -\u003e 'nan'\n```\n\n## License\n\nPrecise-TypeOf is released under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexindigo%2Fprecise-typeof","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexindigo%2Fprecise-typeof","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexindigo%2Fprecise-typeof/lists"}