{"id":19439361,"url":"https://github.com/codevendor/type_of","last_synced_at":"2026-04-20T14:06:03.700Z","repository":{"id":58365096,"uuid":"531327145","full_name":"Codevendor/type_of","owner":"Codevendor","description":"An importable TypeScript method to fix the JavaScript 'typeof' operator. This code is written as a module for the deno runtime.","archived":false,"fork":false,"pushed_at":"2023-03-27T03:16:25.000Z","size":241,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T21:37:55.510Z","etag":null,"topics":["check","javascript","operator","type","typecheck","typechecking","typeof","types","typescript"],"latest_commit_sha":null,"homepage":"https://codevendor.com","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/Codevendor.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-01T02:00:10.000Z","updated_at":"2023-03-25T21:56:37.000Z","dependencies_parsed_at":"2024-11-10T15:27:57.776Z","dependency_job_id":null,"html_url":"https://github.com/Codevendor/type_of","commit_stats":{"total_commits":30,"total_committers":1,"mean_commits":30.0,"dds":0.0,"last_synced_commit":"a059af4af14315efcfd75511f83b9613c31fea54"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codevendor%2Ftype_of","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codevendor%2Ftype_of/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codevendor%2Ftype_of/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Codevendor%2Ftype_of/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Codevendor","download_url":"https://codeload.github.com/Codevendor/type_of/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240619812,"owners_count":19830270,"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":["check","javascript","operator","type","typecheck","typechecking","typeof","types","typescript"],"created_at":"2024-11-10T15:22:42.323Z","updated_at":"2026-04-20T14:06:03.657Z","avatar_url":"https://github.com/Codevendor.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# type_of\n\u003e An importable TypeScript / JavaScript method to fix the JavaScript **typeof** operator. This code is written as a module for the **deno** runtime. If you are using JavaScript with node.js there is also an included [type_of.mjs](./src/type_of.mjs) file you can download. If you would like to visit the deno.land module page for **type_of()** [type_of deno module](https://deno.land/x/type_of).\n\n## Table of Contents\n* [General Info](#general-info)\n* [Features](#features)\n* [Tech](#tech)\n* [Screenshots](#screenshots)\n* [Setup](#setup)\n* [Usage](#usage)\n* [Examples](#examples)\n* [Versions](#versions)\n* [Acknowledgements](#acknowledgements)\n* [Contact](#contact)\n* [License](#license)\n\n\n## General Info\nWhile programming many years with _JavaScript_, I've ran into many bugs using the **typeof** operator to check data types. \nThe bugs have carried over to using _TypeScript_ as well. I decided to research all the bugs and build an alternative typeof as a method named **type_of ()**. This module is created to work on the deno runtime.\n\n\n## Features\nBelow are the current features of the **type_of ()** module.\n- Proper **undefined** check\n- Proper **null** check\n- Can type check all common **JavaScript primitive types**.\n- Can type check **complex types** like **object** and seperate it into **exact types**.\n- Can type check all methods including **anonymous** arrow functions.\n- Can type check **arrays**.\n- Using **extended** option can return **class names**.\n- Can type check new JavaScript types like **bigint** and **symbol**.\n- Can type check internal JavaScript functions like **eval**, **JSON**, **NaN**, etc.\n- JavaScript **Errors** can return **proper type** and **name**.\n- In extended mode can seperate numbers into number types, integer, float, nan, infinity, bigint.\n- In extended mode can seperate strings into **'string'** for literal, and **'string Object'** for **new String('foo')**; \n\n## Tech\n- **Deno** - version 1.25.0\n- **TypeScript** - version 4.7.4\n- **V8** - version 10.4.132.20\n- **Visual Studio Code** - 1.70+\n\n\n## Screenshots\n![Visual Studio Code](./assets/visual-studio.jpg)\n\n\n## Setup\nThings you will need to get this module running. You will need to install **Deno** runtime for _Javascript / TypeScript_.\n\n- [Deno Installation](https://deno.land/manual@v1.25.0/getting_started/installation)\n- [Visual Studio Code Installation](https://code.visualstudio.com/Docs/setup/setup-overview)\n- [Deno Plugin Install for VSC](https://deno.land/manual@v1.25.0/vscode_deno)\n\n\n### Installing code from github\n```bash\n    # git clone git@github.com:Codevendor/type_of.git\n```\n\n### Installing code from deno.land with import statement. [type_of deno module](https://deno.land/x/type_of)\nThe deno url can be changed to whatever version you would like to use https://deno.land/x/type_of@v*.*.*/mod.ts. Just change (*) to the version number. i.e: **2.1.0**\n```js\n    // Snake case version - type_of();\n   import { type_of } from \"https://deno.land/x/type_of@v2.1.0/mod.ts\";\n   \n   // Or\n   \n   // Camel case alias - typeOf()\n   import { typeOf } from \"https://deno.land/x/type_of@v2.1.0/mod.ts\";\n```\n\n\n## Usage\nThe method **type_of ()** was built to mimic the JavaScript **typeof** operator. The purpose is to keep the familiarity of the functionality while correcting the known bugs with the operator code. I have also extended the method with a second optional boolean parameter for returning names of functions, classes, errors, etc.\n\n### Method - **type_of** ( **src**: _unknown_, **extended**: _boolean = false_ )\nListed below are the method **signature(s)**.\n\n| Method Signature                        |\n| :---------------------------------------- |\n| **type_of** ( **src:** _unknown_ )  |\n| **type_of** ( **src:** _unknown_, **extended:** _boolean = false_ )  |\n| _alias_ **typeOf** ( **src:** _unknown_ ) |\n| _alias_ **typeOf** ( **src:** _unknown_, **extended:** _boolean = false_ ) |\n\nListed below are the **parameter(s)** for the method.\n\n| Param Name        | Type          | Description                                                                        |\n| :----------------- | :------------- | :------------------------------------------------------------------------------ |\n| **src**           | _unknown_         | The source to test for type.                                             |\n| **extended**      | _boolean_       | Extends the return type string to include name. i.e _'function foo'_. Defaults to _false_.                 |\n\nBelow is the **return type** for the method.\n\n| Return Type      | Description                                                                                       |\n| :----------------- | :------------------------------------------------------------------------------------------------- |\n| **string**        | A _string_ representing the correct type of the src. If ( _extended = true_ ) then string will return with name. i.e _'function foo'_                              |\n\n\n### Javascript Primitive Types:\n- **null**\n- **undefined**\n- **boolean**\n- **number**\n- **string**\n- **symbol** --- (Available from **ES2015**)\n- **bigint** --- (Available from **ES2020**)\n- **array** --- (Added with **type_of()** module)\n\n### Javascript Complex Type:\n- **object**\n\n### Extended types in type_of() module with ( _extended = true_ )\n- **anonymous functions** --- ('function anonymous')\n- **function names** --- ('function foo')\n- **class names** --- ('function classname')\n- **internal javascript function names** --- ('function eval')\n- **error names** --- ('error RangeError', 'function RangeError')\n- **number names** --- ('number integer', 'number float', 'number nan', 'number infinity', 'number bigint')\n- **string literal vs string Object** --- ('string') for literal, ('string Object') for new String('foo')\n\n## Examples\nExamples will be shown below, but can also be found as assertion tests in the [mod_test.ts](./tests/mod_test.ts) file.\n\n#### Type: unknown\nWhile **type_of()** cant check for _unknown types_ that spit out **ReferenceErrors**, you can always be safe by starting your check like so. \n```js\nwindow.foo \u0026\u0026 type_of(foo);\n```\n\n#### Type Response List\nBelow is a string response list for using the **type_of()** method. \n\n| Example | Response |\n| :------ | :------- |\n| **type_of** ( _unknown_ ) | \"unknown\" |\n| **type_of** ( _undefined_ ) | \"undefined\" |\n| **type_of** ( _void 0_ )    | \"undefined\" |\n| **type_of** ( _null_ )      | \"null\"      |\n| **type_of** ( _true_ )      | \"boolean\"   |\n| **type_of** ( _12345_ )     | \"number\"    |\n| **type_of** ( _\"foo\"_ )     | \"string\"    |\n| **type_of** ( _Symbol()_ )      | \"symbol\"   |\n| **type_of** ( _BigInt('9007199254740995')_ )      | \"bigint\"   |\n| **type_of** ( _[]_ )      | \"array\"   |\n| **type_of** ( _{}_ )      | \"object\"   |\n| **type_of** ( _JSON_ )      | \"json\"   |\n| **type_of** ( _Math_ )      | \"math\"   |\n| **type_of** ( _/a-z/_ )      | \"regexp\"   |\n| **type_of** ( _function foo() { }_ )      | \"function\"   |\n| **type_of** ( _() =\u003e { }_ )      | \"function\"   |\n| **type_of** ( _class foo { }_ )      | \"function\"   |\n| **type_of** ( _NaN_ )      | \"number\"   |\n| **type_of** ( _Infinity_ )      | \"number\"   |\n| **type_of** ( _window_ )      | \"window\"   |\n| **type_of**( _globalThis_ )      | \"window\"   |\n| **type_of** ( _eval_ )      | \"function\"   |\n| **type_of** ( _Date_ )      | \"function\"   |\n| **type_of** ( _Error_ )      | \"function\"   |\n| **type_of** ( _new Error()_ )      | \"error\"   |\n| **type_of** ( _new RangeError()_ )      | \"error\"   |\n\n#### Type Response List with ( _extended = true_ )\nBelow is an extended response list for **type_of** (src, true) \n\n| Example | Response |\n| :------ | :------- |\n| **type_of** ( _\"foo\", true_ ) | \"string\" |\n| **type_of** ( _{}, true_ ) | \"object Object\" |\n| **type_of** ( _Date, true_ ) | \"function Date\" |\n| **type_of** ( _eval, true_ ) | \"function eval\" |\n| **type_of** ( _function foo(){}, true_ ) | \"function foo\" |\n| **type_of** ( _() =\u003e {}, true_ ) | \"function anonymous\" |\n| **type_of** ( _class foo {}, true_ ) | \"function foo\" |\n| **type_of** ( _new class foo {}, true_ ) | \"object foo\" |\n| **type_of** ( _Error, true_ ) | \"function Error\" |\n| **type_of** ( _new Error(), true_ ) | \"error Error\" |\n| **type_of** ( _RangeError, true_ ) | \"function RangeError\" |\n| **type_of** ( _new RangeError(), true_ ) | \"error RangeError\" |\n| **type_of** ( _0, true_ ) | \"number\" |\n| **type_of** ( _12345, true_ ) | \"number integer\" |\n| **type_of** ( _-12345, true_ ) | \"number integer\" |\n| **type_of** ( _12345.67, true_ ) | \"number float\" |\n| **type_of** ( _-12345.67, true_ ) | \"number float\" |\n| **type_of** ( _NaN, true_ ) | \"number nan\" |\n| **type_of** ( _Infinity, true_ ) | \"number infinity\" |\n| **type_of** ( _BigInt('9007199254740995'), true_ ) | \"number bigint\" |\n| **type_of** ( _1.0, true_ ) | \"number integer\" \u003c-- Internal js error |\n| **type_of** ( _new String('foo'), true_ ) | \"string Object\" |\n\n#### Unsolved Number Types\nThere is an internal issue with _JavaScript_ where **floats** starting or ending with zero get truncated off. So _1.0_ reports as _1_ and _1.01_ reports as _1.01_. I would love to fix this issue, but it's internal _JavaScript_. Only way to keep this precision is by keeping everything string.\n\n```js\ntype_of( 1.0, true ) === 'number integer'        // \u003c--- This is an error, because it should be a float.\n\n// Should return this:\ntype_of ( 1.0, true ) === 'number float'        \n```\n\n## Versions\n- **v2.1.0** --- Added new features for number and string.\n1. Added in extended support for number. Now **type_of ()** can return (_'number integer'_, _'number float'_, _'number nan'_, _'number infinity'_, _'number bigint'_)\n2. Added in extended support for _string literal_ vs _string Object_. Now **type_of ()** can return (_'string'_, _'string Object'_)\n3. Added in a .mjs module file written in javascript. \n- **v2.0.0** --- Importable Method **type_of ()** or _alias_ **typeOf ()** with only one return type of (**string**) \n- **v1.0.0** --- Global method **type_of ()** with extended return type of (**string | type_of_value**)\n\n## Acknowledgements\n- This project was based on [this tutorial](https://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/).\n- Thanks to [Angus croll](https://github.com/angus-c)\n\n## Contact\nCreated by _Adam Smith_ [@Codevendor](https://codevendor.com/) - feel free to contact me!\n\n\n## License\nThis project is open source and available under the [... MIT License](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodevendor%2Ftype_of","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodevendor%2Ftype_of","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodevendor%2Ftype_of/lists"}