@klyper/utils 0.2.2 → 0.2.3
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.
- package/dist/index.cjs +66 -10
- package/dist/index.d.ts +83 -4
- package/dist/index.js +47 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,77 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @klyper/utils v0.2.
|
|
2
|
+
* @klyper/utils v0.2.3
|
|
3
3
|
* Utility helpers for the Klyper ecosystem.
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
return value === null || value === undefined;
|
|
11
|
-
}
|
|
9
|
+
const types$1 = {};
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
const type = (test) => test == null ? "null" : types$1[types$1.toString.call(test)] || "object";
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
return value;
|
|
17
|
-
}
|
|
13
|
+
["Array", "AsyncFunction", "Boolean", "Date", "Function", "Map", "Number", "Object", "RegExp", "Set", "String"].forEach((type) => types$1["[object " + type + "]"] = type.toLowerCase());
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
const isArray = (test) => type(test) == "array";
|
|
16
|
+
|
|
17
|
+
const isBoolean = (test) => type(test) == "boolean";
|
|
18
|
+
|
|
19
|
+
const isFunction = (test) => typeof test == "function";
|
|
20
|
+
|
|
21
|
+
const isConstructor = (test) => isFunction(test) && !!test.prototype && test.prototype.constructor === test;
|
|
22
|
+
|
|
23
|
+
const isDate = (test) => type(test) == "date";
|
|
24
|
+
|
|
25
|
+
const isDef = (test) => type(test) != "null";
|
|
26
|
+
|
|
27
|
+
const isNumber = (test) => type(test) == "number";
|
|
28
|
+
|
|
29
|
+
const isFloat = (test) => isNumber(test) && !!(test % 1);
|
|
30
|
+
|
|
31
|
+
const isInteger = (test) => isNumber(test) && !(test % 1);
|
|
32
|
+
|
|
33
|
+
const isMap = (test) => type(test) == "map";
|
|
34
|
+
|
|
35
|
+
const isNil = (test) => test === null || test === undefined;
|
|
36
|
+
|
|
37
|
+
const isNull = (test) => test === null;
|
|
38
|
+
|
|
39
|
+
const isObject = (test) => type(test) == "object";
|
|
40
|
+
|
|
41
|
+
const isPlainObject = (test) => isObject(test) && test.constructor === Object;
|
|
42
|
+
|
|
43
|
+
const isRegExp = (test) => type(test) == "regexp";
|
|
44
|
+
|
|
45
|
+
const types = ["boolean", "number", "string"];
|
|
46
|
+
|
|
47
|
+
const isScalar = (test) => types.indexOf(type(test)) != -1;
|
|
48
|
+
|
|
49
|
+
const isSet = (test) => type(test) == "set";
|
|
50
|
+
|
|
51
|
+
const isString = (test) => typeof test == "string";
|
|
52
|
+
|
|
53
|
+
const isSymbol = (test) => typeof test == "symbol";
|
|
54
|
+
|
|
55
|
+
const isUndefined = (test) => test === undefined;
|
|
56
|
+
|
|
57
|
+
exports.isArray = isArray;
|
|
58
|
+
exports.isBoolean = isBoolean;
|
|
59
|
+
exports.isConstructor = isConstructor;
|
|
60
|
+
exports.isDate = isDate;
|
|
61
|
+
exports.isDef = isDef;
|
|
62
|
+
exports.isFloat = isFloat;
|
|
63
|
+
exports.isFunction = isFunction;
|
|
64
|
+
exports.isInteger = isInteger;
|
|
65
|
+
exports.isMap = isMap;
|
|
20
66
|
exports.isNil = isNil;
|
|
21
|
-
exports.
|
|
67
|
+
exports.isNull = isNull;
|
|
68
|
+
exports.isNumber = isNumber;
|
|
69
|
+
exports.isObject = isObject;
|
|
70
|
+
exports.isPlainObject = isPlainObject;
|
|
71
|
+
exports.isRegExp = isRegExp;
|
|
72
|
+
exports.isScalar = isScalar;
|
|
73
|
+
exports.isSet = isSet;
|
|
74
|
+
exports.isString = isString;
|
|
75
|
+
exports.isSymbol = isSymbol;
|
|
76
|
+
exports.isUndefined = isUndefined;
|
|
77
|
+
exports.type = type;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,88 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @klyper/utils v0.2.
|
|
2
|
+
* @klyper/utils v0.2.3
|
|
3
3
|
* Utility helpers for the Klyper ecosystem.
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
declare const isArray: (test: unknown) => test is Array<any>;
|
|
8
|
+
|
|
9
|
+
declare const isBoolean: (test: unknown) => test is boolean;
|
|
10
|
+
|
|
11
|
+
type TypeAnyConstructor<T = any> = new (...args: Array<any>) => T;
|
|
12
|
+
type TypeAnyFunction<T = any> = (...args: Array<any>) => T;
|
|
13
|
+
type TypeArray<T> = Array<T>;
|
|
14
|
+
type TypeAnyArray = TypeArray<any>;
|
|
15
|
+
type TypeStringArray = TypeArray<string>;
|
|
16
|
+
type TypeNumberArray = TypeArray<number>;
|
|
17
|
+
type TypeFunctionArray = TypeArray<TypeAnyFunction>;
|
|
18
|
+
type TypeKey = number | string | symbol;
|
|
19
|
+
type TypeOptional<T> = T | null | undefined;
|
|
20
|
+
type TypeScalar = boolean | number | string;
|
|
21
|
+
type Nullable<T> = T | null;
|
|
22
|
+
type Maybe<T> = TypeOptional<T>;
|
|
23
|
+
type EntityId = string;
|
|
24
|
+
type TypeObject<T, K extends keyof any = string> = Record<K, T>;
|
|
25
|
+
type TypeAnyObject = TypeObject<any>;
|
|
26
|
+
type TypeBooleanObject = TypeObject<boolean>;
|
|
27
|
+
type TypeFunctionObject = TypeObject<TypeAnyFunction>;
|
|
28
|
+
type TypeNumberObject = TypeObject<number>;
|
|
29
|
+
type TypeStringObject = TypeObject<string>;
|
|
30
|
+
type TypeObjectOptional<T, K extends keyof T = keyof T> = {
|
|
31
|
+
[P in keyof T as P extends K ? never : P]: T[P];
|
|
32
|
+
} & {
|
|
33
|
+
[P in keyof T as P extends K ? P : never]?: T[P];
|
|
34
|
+
};
|
|
35
|
+
type TypeObjectRequired<T, K extends keyof T> = {
|
|
36
|
+
[P in K]-?: T[P];
|
|
37
|
+
} & {
|
|
38
|
+
[P in Exclude<keyof T, K>]: T[P];
|
|
39
|
+
};
|
|
40
|
+
type TypeObjectKeys<T, F = any> = {
|
|
41
|
+
[K in keyof T]: T[K] extends F ? K : never;
|
|
42
|
+
}[keyof T];
|
|
43
|
+
type TypeObjectKeysFunction<T> = TypeObjectKeys<T, TypeAnyFunction>;
|
|
44
|
+
type TypeCallback<T, K, O, R> = (value: T, key: K, object: O) => R;
|
|
45
|
+
type TypeCallbackArray<T> = TypeCallback<T, number, TypeArray<T>, any>;
|
|
46
|
+
type TypeCallbackMap<T> = TypeCallback<T, number, TypeArray<T>, T>;
|
|
47
|
+
type TypeCallbackObject<T> = TypeCallback<T, string, TypeObject<T>, any>;
|
|
48
|
+
|
|
49
|
+
declare const isConstructor: (test: unknown) => test is TypeAnyConstructor;
|
|
50
|
+
|
|
51
|
+
declare const isDate: (test: unknown) => test is Date;
|
|
52
|
+
|
|
53
|
+
declare const isDef: <T = any>(test: unknown) => test is T;
|
|
54
|
+
|
|
55
|
+
declare const isFloat: (test: unknown) => test is number;
|
|
56
|
+
|
|
57
|
+
declare const isFunction: (test: unknown) => test is TypeAnyFunction;
|
|
58
|
+
|
|
59
|
+
declare const isInteger: (test: unknown) => test is number;
|
|
60
|
+
|
|
61
|
+
declare const isMap: <K = any, V = any>(test: unknown) => test is Map<K, V>;
|
|
62
|
+
|
|
63
|
+
declare const isNil: (test: unknown) => test is null | undefined;
|
|
64
|
+
|
|
65
|
+
declare const isNull: (test: unknown) => test is null;
|
|
66
|
+
|
|
67
|
+
declare const isNumber: (test: unknown) => test is number;
|
|
68
|
+
|
|
69
|
+
declare const isObject: (test: unknown) => test is TypeAnyObject;
|
|
70
|
+
|
|
71
|
+
declare const isPlainObject: (test: unknown) => test is TypeAnyObject;
|
|
72
|
+
|
|
73
|
+
declare const isRegExp: (test: unknown) => test is RegExp;
|
|
74
|
+
|
|
75
|
+
declare const isScalar: (test: unknown) => test is TypeScalar;
|
|
76
|
+
|
|
77
|
+
declare const isSet: <T = any>(test: unknown) => test is Set<T>;
|
|
78
|
+
|
|
79
|
+
declare const isString: (test: unknown) => test is string;
|
|
80
|
+
|
|
81
|
+
declare const isSymbol: (test: unknown) => test is symbol;
|
|
82
|
+
|
|
83
|
+
declare const isUndefined: (test: unknown) => test is undefined;
|
|
84
|
+
|
|
85
|
+
declare const type: (test: unknown) => string;
|
|
86
|
+
|
|
87
|
+
export { isArray, isBoolean, isConstructor, isDate, isDef, isFloat, isFunction, isInteger, isMap, isNil, isNull, isNumber, isObject, isPlainObject, isRegExp, isScalar, isSet, isString, isSymbol, isUndefined, type };
|
|
88
|
+
export type { EntityId, Maybe, Nullable, TypeAnyArray, TypeAnyConstructor, TypeAnyFunction, TypeAnyObject, TypeArray, TypeBooleanObject, TypeCallback, TypeCallbackArray, TypeCallbackMap, TypeCallbackObject, TypeFunctionArray, TypeFunctionObject, TypeKey, TypeNumberArray, TypeNumberObject, TypeObject, TypeObjectKeys, TypeObjectKeysFunction, TypeObjectOptional, TypeObjectRequired, TypeOptional, TypeScalar, TypeStringArray, TypeStringObject };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,55 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @klyper/utils v0.2.
|
|
2
|
+
* @klyper/utils v0.2.3
|
|
3
3
|
* Utility helpers for the Klyper ecosystem.
|
|
4
4
|
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
return value === null || value === undefined;
|
|
9
|
-
}
|
|
7
|
+
const types$1 = {};
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
const type = (test) => test == null ? "null" : types$1[types$1.toString.call(test)] || "object";
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
return value;
|
|
15
|
-
}
|
|
11
|
+
["Array", "AsyncFunction", "Boolean", "Date", "Function", "Map", "Number", "Object", "RegExp", "Set", "String"].forEach((type) => types$1["[object " + type + "]"] = type.toLowerCase());
|
|
16
12
|
|
|
17
|
-
|
|
13
|
+
const isArray = (test) => type(test) == "array";
|
|
14
|
+
|
|
15
|
+
const isBoolean = (test) => type(test) == "boolean";
|
|
16
|
+
|
|
17
|
+
const isFunction = (test) => typeof test == "function";
|
|
18
|
+
|
|
19
|
+
const isConstructor = (test) => isFunction(test) && !!test.prototype && test.prototype.constructor === test;
|
|
20
|
+
|
|
21
|
+
const isDate = (test) => type(test) == "date";
|
|
22
|
+
|
|
23
|
+
const isDef = (test) => type(test) != "null";
|
|
24
|
+
|
|
25
|
+
const isNumber = (test) => type(test) == "number";
|
|
26
|
+
|
|
27
|
+
const isFloat = (test) => isNumber(test) && !!(test % 1);
|
|
28
|
+
|
|
29
|
+
const isInteger = (test) => isNumber(test) && !(test % 1);
|
|
30
|
+
|
|
31
|
+
const isMap = (test) => type(test) == "map";
|
|
32
|
+
|
|
33
|
+
const isNil = (test) => test === null || test === undefined;
|
|
34
|
+
|
|
35
|
+
const isNull = (test) => test === null;
|
|
36
|
+
|
|
37
|
+
const isObject = (test) => type(test) == "object";
|
|
38
|
+
|
|
39
|
+
const isPlainObject = (test) => isObject(test) && test.constructor === Object;
|
|
40
|
+
|
|
41
|
+
const isRegExp = (test) => type(test) == "regexp";
|
|
42
|
+
|
|
43
|
+
const types = ["boolean", "number", "string"];
|
|
44
|
+
|
|
45
|
+
const isScalar = (test) => types.indexOf(type(test)) != -1;
|
|
46
|
+
|
|
47
|
+
const isSet = (test) => type(test) == "set";
|
|
48
|
+
|
|
49
|
+
const isString = (test) => typeof test == "string";
|
|
50
|
+
|
|
51
|
+
const isSymbol = (test) => typeof test == "symbol";
|
|
52
|
+
|
|
53
|
+
const isUndefined = (test) => test === undefined;
|
|
54
|
+
|
|
55
|
+
export { isArray, isBoolean, isConstructor, isDate, isDef, isFloat, isFunction, isInteger, isMap, isNil, isNull, isNumber, isObject, isPlainObject, isRegExp, isScalar, isSet, isString, isSymbol, isUndefined, type };
|