Skip to content

Instantly share code, notes, and snippets.

@ko1ebayev
Created January 13, 2024 18:44
Show Gist options
  • Save ko1ebayev/74d7828f02537da2c89ad9df08af4586 to your computer and use it in GitHub Desktop.
Save ko1ebayev/74d7828f02537da2c89ad9df08af4586 to your computer and use it in GitHub Desktop.
Idea: ts identity npm package
export default class Identity {
static isNumber(v: unknown): v is number {
return typeof v === 'number';
}
static isString(v: unknown): v is string {
return typeof v === 'string' || v instanceof String;
}
static isNil(v: unknown): boolean {
return v === null || v === undefined;
}
static isNull(v: unknown): v is null {
return v === null;
}
static isUndefined(v: unknown): v is undefined {
return v === undefined;
}
static isBoolean(v: unknown): boolean {
return typeof v === 'boolean';
}
static isObject(v: unknown): v is object {
return typeof v === 'object' && v !== null;
}
static isArray(v: unknown): boolean {
return Array.isArray(v);
}
static isBigInt(v: unknown): v is bigint {
return typeof v === 'bigint';
}
static isDate(v: unknown): v is Date {
return v instanceof Date;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment