New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

ts-type-detector

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-type-detector

Takes any JavaScript data type or object as an input and returns a string describing the type of the input.

latest
Source
npmnpm
Version
2.7.0
Version published
Maintainers
1
Created
Source

ts-type-detector

Workflow Codecov NPM Monthly Downloads Install Size Known Vulnerabilities

Takes any JavaScript data type or object as an input and returns a string describing the type of the input.

Intro

The ts-type-detector library is help to identify the data type of the input provided to it. This document outlines how to use the API, including the available methods, request parameters, and response formats.

Usage

import whoami from 'ts-type-detector';

Overview

Method: whoami(input)

Description

The whoami function takes any JavaScript data type or object as an input and returns a string describing the type of the input.

Parameters

  • input (any): The input parameter whose type needs to be identified.

Returns

  • (string): A string describing the type of the input. Possible return values include:
    • 'undefined'
    • 'null'
    • 'boolean'
    • 'number'
    • 'string'
    • 'array'
    • 'object'
    • 'buffer'
    • 'date'
    • 'regexp'
    • 'function'
    • 'error'
    • 'promise'
    • 'generatorfunction'
    • 'generator'
    • 'map'
    • 'weakmap'
    • 'set'
    • 'weakset'
    • 'setiterator'
    • 'mapiterator'
    • 'arrayiterator'
    • 'stringiterator'
    • 'symbol'
    • 'int8array'
    • 'uint8array'
    • 'uint8clampedarray'
    • 'int16array'
    • 'uint16array'
    • 'int32array'
    • 'uint32array'
    • 'float32array'
    • 'float64array'

Examples

const result = whoami(undefined);
//=> 'undefined'

const result = whoami(null);
//=> 'null'

const result = whoami(true);
//=> 'boolean'

const result = whoami(false);
//=> 'boolean'

const result = whoami(new Buffer(''));
//=> 'buffer'

const result = whoami(42);
//=> 'number'

const result = whoami('str');
//=> 'string'

const result = whoami(arguments);
//=> 'arguments'

const result = whoami({});
//=> 'object'

const result = whoami(Object.create(null));
//=> 'object'

const result = whoami(new Test());
//=> 'object'

const result = whoami(new Date());
//=> 'date'

const result = whoami([1, 2, 3]);
//=> 'array'

const result = whoami(/foo/);
//=> 'regexp'

const result = whoami(new RegExp('foo'));
//=> 'regexp'

const result = whoami(new Error('error'));
//=> 'error'

const result = whoami(function () {});
//=> 'function'

const result = whoami(function* () {});
//=> 'generatorfunction'

const result = whoami(Symbol('str'));
//=> 'symbol'

const result = whoami(new Map());
//=> 'map'

const result = whoami(new WeakMap());
//=> 'weakmap'

const result = whoami(new Set());
//=> 'set'

const result = whoami(new WeakSet());
//=> 'weakset'

const result = whoami(new Int8Array());
//=> 'int8array'

const result = whoami(new Uint8Array());
//=> 'uint8array'

const result = whoami(new Uint8ClampedArray());
//=> 'uint8clampedarray'

const result = whoami(new Int16Array());
//=> 'int16array'

const result = whoami(new Uint16Array());
//=> 'uint16array'

const result = whoami(new Int32Array());
//=> 'int32array'

const result = whoami(new Uint32Array());
//=> 'uint32array'

const result = whoami(new Float32Array());
//=> 'float32array'

const result = whoami(new Float64Array());
//=> 'float64array'

Error Handling

If an unsupported data type or object is passed, it may return 'unknown' or throw an error.

Keywords

arguments

FAQs

Package last updated on 16 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts