https://github.com/nicolaeiotu/xtypeof
xtypeof is extended typeof
https://github.com/nicolaeiotu/xtypeof
typeof types xtypeof xtypes
Last synced: 3 months ago
JSON representation
xtypeof is extended typeof
- Host: GitHub
- URL: https://github.com/nicolaeiotu/xtypeof
- Owner: NicolaeIotu
- License: isc
- Created: 2020-11-02T07:26:08.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-05T13:19:40.000Z (6 months ago)
- Last Synced: 2025-01-05T15:22:32.726Z (5 months ago)
- Topics: typeof, types, xtypeof, xtypes
- Language: JavaScript
- Homepage:
- Size: 512 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

# xtypeof
**xtypeof** is extended typeof.
This simple single function lightweight module has zero dependencies and runs in all environments.
**xtypeof** function takes a single parameter which can be anything and returns a lowercase string representing
the extended type of object passed including builtins and all other types available
in the environment.By value returns include "undefined", "null", "boolean", "number", "bigint", "string", "symbol", "function", "object",
"array", "map", "set", "date", "regexp", "weakmap", "weakset", "promise", "arraybuffer", "sharedarraybuffer",
"dataview", "int8array", "uint8array", "uint8clampedarray", "int16array", "uint16array", "int32array", "uint32array",
"float32array", "float64array", "bigint64array", "biguint64array", "error" and all other environment specific extended
lowercase types such as "htmldivelement" a.m.o.```
import xtypeof from 'xtypeof'console.log(xtypeof([])) // 'array'
console.log(xtypeof('a')) // 'string'
console.log(xtypeof(null)) // 'null'
console.log(xtypeof(BigInt(123))) // 'bigint'
console.log(xtypeof(Buffer.alloc(5))) // 'uint8array'
console.log(xtypeof(new Error('err'))) // 'error'
console.log(xtypeof(new RangeError('oor'))) // 'error'
```Inspired by [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#Examples](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#Examples)
There is an exception with Proxy which is not a regular type and will be recognized as 'object'. This is done for
efficiency.