is-what 4.1.16 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +6 -6
  2. package/dist/getType.d.ts +2 -0
  3. package/dist/getType.js +4 -0
  4. package/dist/index.d.ts +41 -380
  5. package/dist/index.js +37 -171
  6. package/dist/isAnyObject.d.ts +6 -0
  7. package/dist/isAnyObject.js +8 -0
  8. package/dist/isArray.d.ts +2 -0
  9. package/dist/isArray.js +5 -0
  10. package/dist/isBlob.d.ts +2 -0
  11. package/dist/isBlob.js +5 -0
  12. package/dist/isBoolean.d.ts +2 -0
  13. package/dist/isBoolean.js +5 -0
  14. package/dist/isDate.d.ts +2 -0
  15. package/dist/isDate.js +5 -0
  16. package/dist/isEmptyArray.d.ts +2 -0
  17. package/dist/isEmptyArray.js +5 -0
  18. package/dist/isEmptyObject.d.ts +7 -0
  19. package/dist/isEmptyObject.js +8 -0
  20. package/dist/isEmptyString.d.ts +2 -0
  21. package/dist/isEmptyString.js +4 -0
  22. package/dist/isError.d.ts +2 -0
  23. package/dist/isError.js +5 -0
  24. package/dist/isFile.d.ts +2 -0
  25. package/dist/isFile.js +5 -0
  26. package/dist/isFullArray.d.ts +2 -0
  27. package/dist/isFullArray.js +5 -0
  28. package/dist/isFullObject.d.ts +6 -0
  29. package/dist/isFullObject.js +8 -0
  30. package/dist/isFullString.d.ts +2 -0
  31. package/dist/isFullString.js +5 -0
  32. package/dist/isFunction.d.ts +3 -0
  33. package/dist/isFunction.js +4 -0
  34. package/dist/isInstanceOf.d.ts +23 -0
  35. package/dist/isInstanceOf.js +20 -0
  36. package/dist/isMap.d.ts +2 -0
  37. package/dist/isMap.js +5 -0
  38. package/dist/isNaNValue.d.ts +2 -0
  39. package/dist/isNaNValue.js +5 -0
  40. package/dist/isNegativeNumber.d.ts +2 -0
  41. package/dist/isNegativeNumber.js +5 -0
  42. package/dist/isNull.d.ts +2 -0
  43. package/dist/isNull.js +5 -0
  44. package/dist/isNullOrUndefined.d.ts +2 -0
  45. package/dist/isNullOrUndefined.js +5 -0
  46. package/dist/isNumber.d.ts +6 -0
  47. package/dist/isNumber.js +9 -0
  48. package/dist/isObject.d.ts +6 -0
  49. package/dist/isObject.js +8 -0
  50. package/dist/isObjectLike.d.ts +9 -0
  51. package/dist/isObjectLike.js +11 -0
  52. package/dist/isOneOf.d.ts +54 -0
  53. package/dist/isOneOf.js +15 -0
  54. package/dist/isPlainObject.d.ts +6 -0
  55. package/dist/isPlainObject.js +11 -0
  56. package/dist/isPositiveNumber.d.ts +2 -0
  57. package/dist/isPositiveNumber.js +5 -0
  58. package/dist/isPrimitive.d.ts +6 -0
  59. package/dist/isPrimitive.js +19 -0
  60. package/dist/isPromise.d.ts +2 -0
  61. package/dist/isPromise.js +5 -0
  62. package/dist/isRegExp.d.ts +2 -0
  63. package/dist/isRegExp.js +5 -0
  64. package/dist/isSet.d.ts +2 -0
  65. package/dist/isSet.js +5 -0
  66. package/dist/isString.d.ts +2 -0
  67. package/dist/isString.js +5 -0
  68. package/dist/isSymbol.d.ts +2 -0
  69. package/dist/isSymbol.js +5 -0
  70. package/dist/isType.d.ts +10 -0
  71. package/dist/isType.js +19 -0
  72. package/dist/isUndefined.d.ts +2 -0
  73. package/dist/isUndefined.js +5 -0
  74. package/dist/isWeakMap.d.ts +2 -0
  75. package/dist/isWeakMap.js +5 -0
  76. package/dist/isWeakSet.d.ts +2 -0
  77. package/dist/isWeakSet.js +5 -0
  78. package/package.json +12 -74
  79. package/dist/cjs/index.cjs +0 -209
  80. package/dist/cjs/index.d.cts +0 -380
@@ -0,0 +1,6 @@
1
+ import { PlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is an any kind of object (including special classes or objects with
4
+ * different prototypes)
5
+ */
6
+ export declare function isAnyObject(payload: unknown): payload is PlainObject;
@@ -0,0 +1,8 @@
1
+ import { getType } from './getType.js';
2
+ /**
3
+ * Returns whether the payload is an any kind of object (including special classes or objects with
4
+ * different prototypes)
5
+ */
6
+ export function isAnyObject(payload) {
7
+ return getType(payload) === 'Object';
8
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is an array */
2
+ export declare function isArray(payload: unknown): payload is unknown[];
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is an array */
3
+ export function isArray(payload) {
4
+ return getType(payload) === 'Array';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Blob */
2
+ export declare function isBlob(payload: unknown): payload is Blob;
package/dist/isBlob.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Blob */
3
+ export function isBlob(payload) {
4
+ return getType(payload) === 'Blob';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a boolean */
2
+ export declare function isBoolean(payload: unknown): payload is boolean;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a boolean */
3
+ export function isBoolean(payload) {
4
+ return getType(payload) === 'Boolean';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Date, and that the date is valid */
2
+ export declare function isDate(payload: unknown): payload is Date;
package/dist/isDate.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Date, and that the date is valid */
3
+ export function isDate(payload) {
4
+ return getType(payload) === 'Date' && !isNaN(payload);
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a an empty array */
2
+ export declare function isEmptyArray(payload: unknown): payload is [];
@@ -0,0 +1,5 @@
1
+ import { isArray } from './isArray.js';
2
+ /** Returns whether the payload is a an empty array */
3
+ export function isEmptyArray(payload) {
4
+ return isArray(payload) && payload.length === 0;
5
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns whether the payload is a an empty object (excluding special classes or objects with other
3
+ * prototypes)
4
+ */
5
+ export declare function isEmptyObject(payload: unknown): payload is {
6
+ [K in string | symbol | number]: never;
7
+ };
@@ -0,0 +1,8 @@
1
+ import { isPlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is a an empty object (excluding special classes or objects with other
4
+ * prototypes)
5
+ */
6
+ export function isEmptyObject(payload) {
7
+ return isPlainObject(payload) && Object.keys(payload).length === 0;
8
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is '' */
2
+ export declare function isEmptyString(payload: unknown): payload is string;
@@ -0,0 +1,4 @@
1
+ /** Returns whether the payload is '' */
2
+ export function isEmptyString(payload) {
3
+ return payload === '';
4
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is an Error */
2
+ export declare function isError(payload: unknown): payload is Error;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is an Error */
3
+ export function isError(payload) {
4
+ return getType(payload) === 'Error' || payload instanceof Error;
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a File */
2
+ export declare function isFile(payload: unknown): payload is File;
package/dist/isFile.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a File */
3
+ export function isFile(payload) {
4
+ return getType(payload) === 'File';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a an array with at least 1 item */
2
+ export declare function isFullArray(payload: unknown): payload is unknown[];
@@ -0,0 +1,5 @@
1
+ import { isArray } from './isArray.js';
2
+ /** Returns whether the payload is a an array with at least 1 item */
3
+ export function isFullArray(payload) {
4
+ return isArray(payload) && payload.length > 0;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { PlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is a an empty object (excluding special classes or objects with other
4
+ * prototypes)
5
+ */
6
+ export declare function isFullObject(payload: unknown): payload is PlainObject;
@@ -0,0 +1,8 @@
1
+ import { isPlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is a an empty object (excluding special classes or objects with other
4
+ * prototypes)
5
+ */
6
+ export function isFullObject(payload) {
7
+ return isPlainObject(payload) && Object.keys(payload).length > 0;
8
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a string, BUT returns false for '' */
2
+ export declare function isFullString(payload: unknown): payload is string;
@@ -0,0 +1,5 @@
1
+ import { isString } from './isString.js';
2
+ /** Returns whether the payload is a string, BUT returns false for '' */
3
+ export function isFullString(payload) {
4
+ return isString(payload) && payload !== '';
5
+ }
@@ -0,0 +1,3 @@
1
+ export type AnyFunction = (...args: unknown[]) => unknown;
2
+ /** Returns whether the payload is a function (regular or async) */
3
+ export declare function isFunction(payload: unknown): payload is AnyFunction;
@@ -0,0 +1,4 @@
1
+ /** Returns whether the payload is a function (regular or async) */
2
+ export function isFunction(payload) {
3
+ return typeof payload === 'function';
4
+ }
@@ -0,0 +1,23 @@
1
+ import { AnyClass } from './isType.js';
2
+ type GlobalClassName = {
3
+ [K in keyof typeof globalThis]: (typeof globalThis)[K] extends AnyClass ? K : never;
4
+ }[keyof typeof globalThis];
5
+ /**
6
+ * Checks if a value is an instance of a class or a class name. Useful when you want to check if a
7
+ * value is an instance of a class that may not be defined in the current scope. For example, if you
8
+ * want to check if a value is an `OffscreenCanvas` instance, you might not want to do the song and
9
+ * dance of using `typeof OffscreenCanvas !== 'undefined'` and then shimming `OffscreenCanvas` if
10
+ * the types aren't around.
11
+ *
12
+ * @example
13
+ * if (isInstanceOf(value, 'OffscreenCanvas')) {
14
+ * // value is an OffscreenCanvas
15
+ * }
16
+ *
17
+ * @param value The value to recursively check
18
+ * @param class_ A string or class that the value should be an instance of
19
+ */
20
+ export declare function isInstanceOf<T extends AnyClass>(value: unknown, class_: T): value is T;
21
+ export declare function isInstanceOf<K extends GlobalClassName>(value: unknown, className: K): value is (typeof globalThis)[K];
22
+ export declare function isInstanceOf(value: unknown, className: string): value is object;
23
+ export {};
@@ -0,0 +1,20 @@
1
+ import { getType } from './getType.js';
2
+ import { isType } from './isType.js';
3
+ export function isInstanceOf(value, classOrClassName) {
4
+ if (typeof classOrClassName === 'function') {
5
+ for (let p = value; p; p = Object.getPrototypeOf(p)) {
6
+ if (isType(p, classOrClassName)) {
7
+ return true;
8
+ }
9
+ }
10
+ return false;
11
+ }
12
+ else {
13
+ for (let p = value; p; p = Object.getPrototypeOf(p)) {
14
+ if (getType(p) === classOrClassName) {
15
+ return true;
16
+ }
17
+ }
18
+ return false;
19
+ }
20
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Map */
2
+ export declare function isMap(payload: unknown): payload is Map<unknown, unknown>;
package/dist/isMap.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Map */
3
+ export function isMap(payload) {
4
+ return getType(payload) === 'Map';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) */
2
+ export declare function isNaNValue(payload: unknown): payload is typeof NaN;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is literally the value `NaN` (it's `NaN` and also a `number`) */
3
+ export function isNaNValue(payload) {
4
+ return getType(payload) === 'Number' && isNaN(payload);
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a negative number (but not 0) */
2
+ export declare function isNegativeNumber(payload: unknown): payload is number;
@@ -0,0 +1,5 @@
1
+ import { isNumber } from './isNumber.js';
2
+ /** Returns whether the payload is a negative number (but not 0) */
3
+ export function isNegativeNumber(payload) {
4
+ return isNumber(payload) && payload < 0;
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is null */
2
+ export declare function isNull(payload: unknown): payload is null;
package/dist/isNull.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is null */
3
+ export function isNull(payload) {
4
+ return getType(payload) === 'Null';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns true whether the payload is null or undefined */
2
+ export declare const isNullOrUndefined: (payload: unknown) => payload is null | undefined;
@@ -0,0 +1,5 @@
1
+ import { isNull } from './isNull.js';
2
+ import { /* tree-shaking no-side-effects-when-called */ isOneOf } from './isOneOf.js';
3
+ import { isUndefined } from './isUndefined.js';
4
+ /** Returns true whether the payload is null or undefined */
5
+ export const isNullOrUndefined = isOneOf(isNull, isUndefined);
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns whether the payload is a number (but not NaN)
3
+ *
4
+ * This will return `false` for `NaN`!!
5
+ */
6
+ export declare function isNumber(payload: unknown): payload is number;
@@ -0,0 +1,9 @@
1
+ import { getType } from './getType.js';
2
+ /**
3
+ * Returns whether the payload is a number (but not NaN)
4
+ *
5
+ * This will return `false` for `NaN`!!
6
+ */
7
+ export function isNumber(payload) {
8
+ return getType(payload) === 'Number' && !isNaN(payload);
9
+ }
@@ -0,0 +1,6 @@
1
+ import { PlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects
4
+ * with other prototypes)
5
+ */
6
+ export declare function isObject(payload: unknown): payload is PlainObject;
@@ -0,0 +1,8 @@
1
+ import { isPlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects
4
+ * with other prototypes)
5
+ */
6
+ export function isObject(payload) {
7
+ return isPlainObject(payload);
8
+ }
@@ -0,0 +1,9 @@
1
+ import { PlainObject } from './isPlainObject.js';
2
+ /**
3
+ * Returns whether the payload is an object like a type passed in < >
4
+ *
5
+ * Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
6
+ *
7
+ * @template T This must be passed in < >
8
+ */
9
+ export declare function isObjectLike<T extends PlainObject>(payload: unknown): payload is T;
@@ -0,0 +1,11 @@
1
+ import { isAnyObject } from './isAnyObject.js';
2
+ /**
3
+ * Returns whether the payload is an object like a type passed in < >
4
+ *
5
+ * Usage: isObjectLike<{id: any}>(payload) // will make sure it's an object and has an `id` prop.
6
+ *
7
+ * @template T This must be passed in < >
8
+ */
9
+ export function isObjectLike(payload) {
10
+ return isAnyObject(payload);
11
+ }
@@ -0,0 +1,54 @@
1
+ type TypeGuard<A, B extends A> = (payload: A) => payload is B;
2
+ /**
3
+ * A factory function that creates a function to check if the payload is one of the given types.
4
+ *
5
+ * @example
6
+ * import { isOneOf, isNull, isUndefined } from 'is-what'
7
+ *
8
+ * const isNullOrUndefined = isOneOf(isNull, isUndefined)
9
+ *
10
+ * isNullOrUndefined(null) // true
11
+ * isNullOrUndefined(undefined) // true
12
+ * isNullOrUndefined(123) // false
13
+ */
14
+ export declare function isOneOf<A, B extends A, C extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>): TypeGuard<A, B | C>;
15
+ /**
16
+ * A factory function that creates a function to check if the payload is one of the given types.
17
+ *
18
+ * @example
19
+ * import { isOneOf, isNull, isUndefined } from 'is-what'
20
+ *
21
+ * const isNullOrUndefined = isOneOf(isNull, isUndefined)
22
+ *
23
+ * isNullOrUndefined(null) // true
24
+ * isNullOrUndefined(undefined) // true
25
+ * isNullOrUndefined(123) // false
26
+ */
27
+ export declare function isOneOf<A, B extends A, C extends A, D extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>): TypeGuard<A, B | C | D>;
28
+ /**
29
+ * A factory function that creates a function to check if the payload is one of the given types.
30
+ *
31
+ * @example
32
+ * import { isOneOf, isNull, isUndefined } from 'is-what'
33
+ *
34
+ * const isNullOrUndefined = isOneOf(isNull, isUndefined)
35
+ *
36
+ * isNullOrUndefined(null) // true
37
+ * isNullOrUndefined(undefined) // true
38
+ * isNullOrUndefined(123) // false
39
+ */
40
+ export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>): TypeGuard<A, B | C | D | E>;
41
+ /**
42
+ * A factory function that creates a function to check if the payload is one of the given types.
43
+ *
44
+ * @example
45
+ * import { isOneOf, isNull, isUndefined } from 'is-what'
46
+ *
47
+ * const isNullOrUndefined = isOneOf(isNull, isUndefined)
48
+ *
49
+ * isNullOrUndefined(null) // true
50
+ * isNullOrUndefined(undefined) // true
51
+ * isNullOrUndefined(123) // false
52
+ */
53
+ export declare function isOneOf<A, B extends A, C extends A, D extends A, E extends A, F extends A>(a: TypeGuard<A, B>, b: TypeGuard<A, C>, c: TypeGuard<A, D>, d: TypeGuard<A, E>, e: TypeGuard<A, F>): TypeGuard<A, B | C | D | E | F>;
54
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A factory function that creates a function to check if the payload is one of the given types.
3
+ *
4
+ * @example
5
+ * import { isOneOf, isNull, isUndefined } from 'is-what'
6
+ *
7
+ * const isNullOrUndefined = isOneOf(isNull, isUndefined)
8
+ *
9
+ * isNullOrUndefined(null) // true
10
+ * isNullOrUndefined(undefined) // true
11
+ * isNullOrUndefined(123) // false
12
+ */
13
+ export function isOneOf(a, b, c, d, e) {
14
+ return (value) => a(value) || b(value) || (!!c && c(value)) || (!!d && d(value)) || (!!e && e(value));
15
+ }
@@ -0,0 +1,6 @@
1
+ export type PlainObject = Record<string | number | symbol, unknown>;
2
+ /**
3
+ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects
4
+ * with other prototypes)
5
+ */
6
+ export declare function isPlainObject(payload: unknown): payload is PlainObject;
@@ -0,0 +1,11 @@
1
+ import { getType } from './getType.js';
2
+ /**
3
+ * Returns whether the payload is a plain JavaScript object (excluding special classes or objects
4
+ * with other prototypes)
5
+ */
6
+ export function isPlainObject(payload) {
7
+ if (getType(payload) !== 'Object')
8
+ return false;
9
+ const prototype = Object.getPrototypeOf(payload);
10
+ return !!prototype && prototype.constructor === Object && prototype === Object.prototype;
11
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a positive number (but not 0) */
2
+ export declare function isPositiveNumber(payload: unknown): payload is number;
@@ -0,0 +1,5 @@
1
+ import { isNumber } from './isNumber.js';
2
+ /** Returns whether the payload is a positive number (but not 0) */
3
+ export function isPositiveNumber(payload) {
4
+ return isNumber(payload) && payload > 0;
5
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String
3
+ *
4
+ * | Symbol)
5
+ */
6
+ export declare function isPrimitive(payload: unknown): payload is boolean | null | undefined | number | string | symbol;
@@ -0,0 +1,19 @@
1
+ import { isBoolean } from './isBoolean.js';
2
+ import { isNull } from './isNull.js';
3
+ import { isNumber } from './isNumber.js';
4
+ import { isString } from './isString.js';
5
+ import { isSymbol } from './isSymbol.js';
6
+ import { isUndefined } from './isUndefined.js';
7
+ /**
8
+ * Returns whether the payload is a primitive type (eg. Boolean | Null | Undefined | Number | String
9
+ *
10
+ * | Symbol)
11
+ */
12
+ export function isPrimitive(payload) {
13
+ return (isBoolean(payload) ||
14
+ isNull(payload) ||
15
+ isUndefined(payload) ||
16
+ isNumber(payload) ||
17
+ isString(payload) ||
18
+ isSymbol(payload));
19
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Promise */
2
+ export declare function isPromise(payload: unknown): payload is Promise<unknown>;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Promise */
3
+ export function isPromise(payload) {
4
+ return getType(payload) === 'Promise';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a regular expression (RegExp) */
2
+ export declare function isRegExp(payload: unknown): payload is RegExp;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a regular expression (RegExp) */
3
+ export function isRegExp(payload) {
4
+ return getType(payload) === 'RegExp';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Set */
2
+ export declare function isSet(payload: unknown): payload is Set<unknown>;
package/dist/isSet.js ADDED
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Set */
3
+ export function isSet(payload) {
4
+ return getType(payload) === 'Set';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a string */
2
+ export declare function isString(payload: unknown): payload is string;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a string */
3
+ export function isString(payload) {
4
+ return getType(payload) === 'String';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a Symbol */
2
+ export declare function isSymbol(payload: unknown): payload is symbol;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a Symbol */
3
+ export function isSymbol(payload) {
4
+ return getType(payload) === 'Symbol';
5
+ }
@@ -0,0 +1,10 @@
1
+ import { AnyFunction } from './isFunction.js';
2
+ export type AnyClass = new (...args: unknown[]) => unknown;
3
+ /**
4
+ * Does a generic check to check that the given payload is of a given type. In cases like Number, it
5
+ * will return true for NaN as NaN is a Number (thanks javascript!); It will, however, differentiate
6
+ * between object and null
7
+ *
8
+ * @throws {TypeError} Will throw type error if type is an invalid type
9
+ */
10
+ export declare function isType<T extends AnyFunction | AnyClass>(payload: unknown, type: T): payload is T;
package/dist/isType.js ADDED
@@ -0,0 +1,19 @@
1
+ import { getType } from './getType.js';
2
+ /**
3
+ * Does a generic check to check that the given payload is of a given type. In cases like Number, it
4
+ * will return true for NaN as NaN is a Number (thanks javascript!); It will, however, differentiate
5
+ * between object and null
6
+ *
7
+ * @throws {TypeError} Will throw type error if type is an invalid type
8
+ */
9
+ export function isType(payload, type) {
10
+ if (!(type instanceof Function)) {
11
+ throw new TypeError('Type must be a function');
12
+ }
13
+ if (!Object.prototype.hasOwnProperty.call(type, 'prototype')) {
14
+ throw new TypeError('Type is not a class');
15
+ }
16
+ // Classes usually have names (as functions usually have names)
17
+ const name = type.name;
18
+ return getType(payload) === name || Boolean(payload && payload.constructor === type);
19
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is undefined */
2
+ export declare function isUndefined(payload: unknown): payload is undefined;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is undefined */
3
+ export function isUndefined(payload) {
4
+ return getType(payload) === 'Undefined';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a WeakMap */
2
+ export declare function isWeakMap(payload: unknown): payload is WeakMap<WeakKey, unknown>;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a WeakMap */
3
+ export function isWeakMap(payload) {
4
+ return getType(payload) === 'WeakMap';
5
+ }
@@ -0,0 +1,2 @@
1
+ /** Returns whether the payload is a WeakSet */
2
+ export declare function isWeakSet(payload: unknown): payload is WeakSet<WeakKey>;
@@ -0,0 +1,5 @@
1
+ import { getType } from './getType.js';
2
+ /** Returns whether the payload is a WeakSet */
3
+ export function isWeakSet(payload) {
4
+ return getType(payload) === 'WeakSet';
5
+ }