0.0.5 β’ Published 7 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.00Documents provide type detection:
isStringstrings,StringobjectsisNumbernumber,NumberobjectisBooleanboolean,Booleanobject constructedisNullnullisUndefinedundefinedisNaNNaN(NaNis a special valueNaN !== NaNeven iftypeof NaNreturnsnumber)isFunctionfunctionisArrayarray,ArrayobjectisSymbolsymbolisBigIntis a large integerisPlainObjectobject (normal object, not other built-in object types)isPromisePromiseisAsyncFunctionis an asynchronous functionisDatetimeisMapMapisSetSetisWeakMapWeakMapisWeakSetWeakSetisGeneratorgeneratorisGeneratorFunctiongenerator functionisBigInt64ArrayBigInt64ArrayisBigUint64ArrayBigUint64ArrayisDataViewDataViewisArrayBufferArrayBufferisRegExpregex,RegExpobject-built regexisSharedArrayBufferSharedArrayBufferisUint8ClampedArrayUint8ClampedArrayisInt8ArrayInt8ArrayisUint8ArrayUint8ArrayisTypedArrayTypedArrayisInt16ArrayInt16ArrayisUint16ArrayUint16ArrayisInt32ArrayInt32ArrayisUint32ArrayUint32ArrayisFloat32ArrayFloat32ArrayisFloat64ArrayFloat64ArrayisIntlCollatorIntl.CollatorisIntlDateTimeFormatIntl.DateTimeFormatisIntlDisplayNamesIntl.DisplayNamesisIntlListFormatIntl.ListFormatisIntlLocaleIntl.LocaleisIntlNumberFormatIntl.NumberFormatisErrorerrorisEvalErroreval errorisRangeErrorrange errorisReferenceErrorreference errorisSyntaxErrorsyntax errorisTypeErrortype errorisURIErroruri errorisAggregateErroraggregate error