https://github.com/grjan7/get-dtype-of
An utility npm package to return data type.
https://github.com/grjan7/get-dtype-of
array datatypes javascript nodejs npm npm-package objects string typeof
Last synced: about 2 months ago
JSON representation
An utility npm package to return data type.
- Host: GitHub
- URL: https://github.com/grjan7/get-dtype-of
- Owner: grjan7
- License: gpl-3.0
- Created: 2022-09-25T17:25:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-08T19:09:14.000Z (over 3 years ago)
- Last Synced: 2025-02-27T11:45:45.801Z (over 1 year ago)
- Topics: array, datatypes, javascript, nodejs, npm, npm-package, objects, string, typeof
- Language: JavaScript
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# get-dtype-of
[](https://www.npmjs.com/package/get-dtype-of)
[](https://www.npmjs.com/package/get-dtype-of)
[](https://snyk.io/test/github/grjan7/get-dtype-of)
## Description
This package returns the type of `input`. By default, the returned data type can be a `string | number | boolean | array | object | null | undefined | function`. Setting `refineObject` to `true` returns the refined type of `object` (e.g., Date, Map, Set, Buffer, EventEmitter).
## Installation
```sh
npm i get-dtype-of
```
### Usage
#### `getTypeOf(input, refineObject)`
- **input** | any
- **refineObject** | boolean | default: false
#### Examples
```js
const getTypeOf = require('get-dtype-of');
```
| Without Option | Returns | With Option (refineObject: true) | Returns |
| :-----------------------------|:----------|:--------------------------------------|:----------|
| | | | |
| getTypeOf(`"Hello"`) | string | getTypeOf(`"Hello"`, `true`) | string |
| | | | |
| getTypeOf(`412`) | number | getTypeOf(`412`, `true`) | number |
| | | | |
| getTypeOf(`true`) | boolean | getTypeOf(`true`, `true`) | boolean |
| | | | |
| getTypeOf(`undefined`) | undefined | getTypeOf(`undefined`, `true`) | undefined |
| | | | |
| getTypeOf(`["a", "b"]`) | array | getTypeOf(`["a", "b"]`, `true`) | array |
| | | | |
| getTypeOf(`null`) | null | getTypeOf(`null`, `true`) | null |
| | | | |
| getTypeOf(`stream`) | function | getTypeOf(`stream`, `true`) | function |
| | | | |
| getTypeOf(`{ name: "John" }`) | object | getTypeOf(`{ name: "John" }`, `true`) | object |
| | | | |
| getTypeOf(`/[a-z]/`) | object | getTypeOf(`/[a-z]/`, `true`) | RegExp |
| | | | |
| getTypeOf(`new Date()`) | object | getTypeOf(`new Date()`, `true`) | Date |
| | | | |
| getTypeOf(`new Set()`) | object | getTypeOf(`new Set()`, `true`) | Set |
| | | | |