-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
210 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import is from './index'; | ||
|
||
export const isArray = is.array; | ||
export const isArrayOf = is.arrayOf; | ||
export const isAsyncGeneratorFunction = is.asyncGeneratorFunction; | ||
export const isAsyncFunction = is.asyncFunction; | ||
export const isBigInt = is.bigint; | ||
export const isBoolean = is.boolean; | ||
export const isDate = is.date; | ||
export const isDefined = is.defined; | ||
export const isDomElement = is.domElement; | ||
export const isEmpty = is.empty; | ||
export const isError = is.error; | ||
export const isFunction = is.function; | ||
export const isGenerator = is.generator; | ||
export const isGeneratorFunction = is.generatorFunction; | ||
export const isInstanceOf = is.instanceOf; | ||
export const isIterable = is.iterable; | ||
export const isMap = is.map; | ||
export const isNan = is.nan; | ||
export const isNull = is.null; | ||
export const isNullOrUndefined = is.nullOrUndefined; | ||
export const isNumber = is.number; | ||
export const isNumericString = is.numericString; | ||
export const isObject = is.object; | ||
export const isOneOf = is.oneOf; | ||
export const isPlainFunction = is.plainFunction; | ||
export const isPlainObject = is.plainObject; | ||
export const isPrimitive = is.primitive; | ||
export const isPromise = is.promise; | ||
export const isPropertyOf = is.propertyOf; | ||
export const isRegexp = is.regexp; | ||
export const isSet = is.set; | ||
export const isString = is.string; | ||
export const isSymbol = is.symbol; | ||
export const isUndefined = is.undefined; | ||
export const isWeakMap = is.weakMap; | ||
export const isWeakSet = is.weakSet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
import type { ObjectTypes, Primitive, PrimitiveTypes } from './types'; | ||
|
||
export const objectTypes = [ | ||
'Array', | ||
'ArrayBuffer', | ||
'AsyncFunction', | ||
'AsyncGenerator', | ||
'AsyncGeneratorFunction', | ||
'Date', | ||
'Error', | ||
'Function', | ||
'Generator', | ||
'GeneratorFunction', | ||
'HTMLElement', | ||
'Map', | ||
'Object', | ||
'Promise', | ||
'RegExp', | ||
'Set', | ||
'WeakMap', | ||
'WeakSet', | ||
] as const; | ||
|
||
export const primitiveTypes = [ | ||
'bigint', | ||
'boolean', | ||
'null', | ||
'number', | ||
'string', | ||
'symbol', | ||
'undefined', | ||
] as const; | ||
|
||
export function getObjectType(value: unknown): ObjectTypes | undefined { | ||
const objectTypeName = Object.prototype.toString.call(value).slice(8, -1); | ||
|
||
if (/HTML\w+Element/.test(objectTypeName)) { | ||
return 'HTMLElement'; | ||
} | ||
|
||
if (isObjectType(objectTypeName)) { | ||
return objectTypeName; | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
export function isObjectOfType<T>(type: string) { | ||
return (value: unknown): value is T => getObjectType(value) === type; | ||
} | ||
|
||
export function isObjectType(name: unknown): name is ObjectTypes { | ||
return objectTypes.includes(name as ObjectTypes); | ||
} | ||
|
||
export function isOfType<T extends Primitive | Function>(type: string) { | ||
// eslint-disable-next-line valid-typeof | ||
return (value: unknown): value is T => typeof value === type; | ||
} | ||
|
||
export function isPrimitiveType(name: unknown): name is PrimitiveTypes { | ||
return primitiveTypes.includes(name as PrimitiveTypes); | ||
} |
Oops, something went wrong.