0.0.5 β’ Published 5 months ago
a-type-of-js v0.0.5
a-type-of-js
A simple type determination tool
use
import { typeOf } from 'a-type-of-js';
const num = 1;
if (typeOf(num) === 'number') {
console.log('num is number');
} else {
console.log('num is not number');
}
Use the is type judgment in 'ts' for type-safe contraction
import { isString, isNumber } from 'a-type-of-js';
function doSomething(value: string | number) {
if (isString(value)) {
value.toLocaleUpperCase();
} else if (isNumber(value)) {
value.toFixed(2);
}
}
doSomething('hello'); // HELLO
doSomething(1); // 1.00
Documents provide type detection:
isString
strings,String
objectsisNumber
number,Number
objectisBoolean
boolean,Boolean
object constructedisNull
nullisUndefined
undefinedisNaN
NaN
(NaN
is a special valueNaN !== NaN
even iftypeof NaN
returnsnumber
)isFunction
functionisArray
array,Array
objectisSymbol
symbolisBigInt
is a large integerisPlainObject
object (normal object, not other built-in object types)isPromise
PromiseisAsyncFunction
is an asynchronous functionisDate
timeisMap
MapisSet
SetisWeakMap
WeakMapisWeakSet
WeakSetisGenerator
generatorisGeneratorFunction
generator functionisBigInt64Array
BigInt64ArrayisBigUint64Array
BigUint64ArrayisDataView
DataViewisArrayBuffer
ArrayBufferisRegExp
regex,RegExp
object-built regexisSharedArrayBuffer
SharedArrayBufferisUint8ClampedArray
Uint8ClampedArrayisInt8Array
Int8ArrayisUint8Array
Uint8ArrayisTypedArray
TypedArrayisInt16Array
Int16ArrayisUint16Array
Uint16ArrayisInt32Array
Int32ArrayisUint32Array
Uint32ArrayisFloat32Array
Float32ArrayisFloat64Array
Float64ArrayisIntlCollator
Intl.CollatorisIntlDateTimeFormat
Intl.DateTimeFormatisIntlDisplayNames
Intl.DisplayNamesisIntlListFormat
Intl.ListFormatisIntlLocale
Intl.LocaleisIntlNumberFormat
Intl.NumberFormatisError
errorisEvalError
eval errorisRangeError
range errorisReferenceError
reference errorisSyntaxError
syntax errorisTypeError
type errorisURIError
uri errorisAggregateError
aggregate error