2.14.79 • Published 10 months ago

@erboladaiorg/maiores-dolor-fugiat v2.14.79

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

What is Type-Detect?

Type Detect is a module which you can use to detect the type of a given object. It returns a string representation of the object's type, either using typeof or @@toStringTag. It also normalizes some object names for consistency among browsers.

Why?

The typeof operator will only specify primitive values; everything else is "object" (including null, arrays, regexps, etc). Many developers use Object.prototype.toString() - which is a fine alternative and returns many more types (null returns [object Null], Arrays as [object Array], regexps as [object RegExp] etc).

Sadly, Object.prototype.toString is slow, and buggy. By slow - we mean it is slower than typeof. By buggy - we mean that some values (like Promises, the global object, iterators, dataviews, a bunch of HTML elements) all report different things in different browsers.

@erboladaiorg/maiores-dolor-fugiat fixes all of the shortcomings with Object.prototype.toString. We have extra code to speed up checks of JS and DOM objects, as much as 20-30x faster for some values. @erboladaiorg/maiores-dolor-fugiat also fixes any consistencies with these objects.

Installation

Node.js

@erboladaiorg/maiores-dolor-fugiat is available on npm. To install it, type:

$ npm install @erboladaiorg/maiores-dolor-fugiat

Deno

@erboladaiorg/maiores-dolor-fugiat can be imported with the following line:

import type from 'https://deno.land/x/type_detect@v4.1.0/index.ts'

Browsers

You can also use it within the browser; install via npm and use the @erboladaiorg/maiores-dolor-fugiat.js file found within the download. For example:

<script src="./node_modules/@erboladaiorg/maiores-dolor-fugiat/@erboladaiorg/maiores-dolor-fugiat.js"></script>

Usage

The primary export of @erboladaiorg/maiores-dolor-fugiat is function that can serve as a replacement for typeof. The results of this function will be more specific than that of native typeof.

var type = require('@erboladaiorg/maiores-dolor-fugiat');

Or, in the browser use case, after the tag,

var type = typeDetect;

array

assert(type([]) === 'Array');
assert(type(new Array()) === 'Array');

regexp

assert(type(/a-z/gi) === 'RegExp');
assert(type(new RegExp('a-z')) === 'RegExp');

function

assert(type(function () {}) === 'function');

arguments

(function () {
  assert(type(arguments) === 'Arguments');
})();

date

assert(type(new Date) === 'Date');

number

assert(type(1) === 'number');
assert(type(1.234) === 'number');
assert(type(-1) === 'number');
assert(type(-1.234) === 'number');
assert(type(Infinity) === 'number');
assert(type(NaN) === 'number');
assert(type(new Number(1)) === 'Number'); // note - the object version has a capital N

string

assert(type('hello world') === 'string');
assert(type(new String('hello')) === 'String'); // note - the object version has a capital S

null

assert(type(null) === 'null');
assert(type(undefined) !== 'null');

undefined

assert(type(undefined) === 'undefined');
assert(type(null) !== 'undefined');

object

var Noop = function () {};
assert(type({}) === 'Object');
assert(type(Noop) !== 'Object');
assert(type(new Noop) === 'Object');
assert(type(new Object) === 'Object');

ECMA6 Types

All new ECMAScript 2015 objects are also supported, such as Promises and Symbols:

assert(type(new Map() === 'Map');
assert(type(new WeakMap()) === 'WeakMap');
assert(type(new Set()) === 'Set');
assert(type(new WeakSet()) === 'WeakSet');
assert(type(Symbol()) === 'symbol');
assert(type(new Promise(callback) === 'Promise');
assert(type(new Int8Array()) === 'Int8Array');
assert(type(new Uint8Array()) === 'Uint8Array');
assert(type(new UInt8ClampedArray()) === 'Uint8ClampedArray');
assert(type(new Int16Array()) === 'Int16Array');
assert(type(new Uint16Array()) === 'Uint16Array');
assert(type(new Int32Array()) === 'Int32Array');
assert(type(new UInt32Array()) === 'Uint32Array');
assert(type(new Float32Array()) === 'Float32Array');
assert(type(new Float64Array()) === 'Float64Array');
assert(type(new ArrayBuffer()) === 'ArrayBuffer');
assert(type(new DataView(arrayBuffer)) === 'DataView');

Also, if you use Symbol.toStringTag to change an Objects return value of the toString() Method, type() will return this value, e.g:

var myObject = {};
myObject[Symbol.toStringTag] = 'myCustomType';
assert(type(myObject) === 'myCustomType');
2.14.79

10 months ago

2.14.78

10 months ago

2.14.77

11 months ago

2.14.76

11 months ago

2.14.75

11 months ago

2.14.74

11 months ago

2.13.74

11 months ago

2.13.73

11 months ago

2.13.72

11 months ago

2.13.71

11 months ago

1.13.71

11 months ago

1.13.70

11 months ago

1.13.69

11 months ago

1.13.68

11 months ago

1.13.67

11 months ago

1.13.66

11 months ago

1.13.65

11 months ago

1.13.64

11 months ago

1.13.63

11 months ago

1.13.62

11 months ago

1.13.61

11 months ago

1.13.60

11 months ago

1.13.59

11 months ago

1.13.58

11 months ago

1.13.57

11 months ago

1.13.56

11 months ago

1.13.55

11 months ago

1.12.55

11 months ago

1.12.54

11 months ago

1.11.54

11 months ago

1.11.53

11 months ago

1.10.53

11 months ago

1.10.52

12 months ago

1.10.51

12 months ago

1.10.50

12 months ago

1.10.49

12 months ago

1.10.48

12 months ago

1.10.47

12 months ago

1.10.46

12 months ago

1.10.45

12 months ago

1.10.44

12 months ago

1.10.43

12 months ago

1.10.42

12 months ago

1.10.41

12 months ago

1.10.40

12 months ago

1.10.39

12 months ago

1.10.38

12 months ago

1.10.37

12 months ago

1.10.36

12 months ago

1.10.35

12 months ago

1.10.34

12 months ago

1.10.33

12 months ago

1.10.32

1 year ago

1.9.32

1 year ago

1.9.31

1 year ago

1.8.31

1 year ago

1.7.31

1 year ago

1.6.31

1 year ago

1.6.30

1 year ago

1.6.29

1 year ago

1.6.28

1 year ago

1.6.27

1 year ago

1.6.26

1 year ago

1.5.26

1 year ago

1.4.26

1 year ago

1.3.26

1 year ago

1.3.25

1 year ago

1.3.24

1 year ago

1.3.23

1 year ago

1.3.22

1 year ago

1.3.21

1 year ago

1.3.20

1 year ago

1.2.20

1 year ago

1.2.19

1 year ago

1.2.18

1 year ago

1.2.17

1 year ago

1.2.16

1 year ago

1.2.15

1 year ago

1.2.14

1 year ago

1.2.13

1 year ago

1.2.12

1 year ago

1.2.11

1 year ago

1.2.10

1 year ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago