@media-quest/engine 0.0.25 → 0.0.26

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.
@@ -1,116 +1,116 @@
1
- // export type RandomObjectId = string & { randomObjectId: true };
2
- export namespace DUtil {
3
- export const randomString = (length: number): string => {
4
- const letters = "abcdefghijklmnopqrstuvxyz";
5
- const uppercase = letters.toUpperCase();
6
- const all = letters + uppercase;
7
- const abs = Math.abs(length);
8
- let result = "";
9
-
10
- for (let i = 0; i < abs; i++) {
11
- const char = all.charAt(Math.floor(Math.random() * all.length));
12
- result += char;
13
- }
14
- return result;
15
- };
16
-
17
- export const randomObjectId = () => randomString(32);
18
-
19
- export const deleteProp = <Obj, Key extends keyof Obj>(obj: Obj, key: Key): Omit<Obj, Key> => {
20
- delete obj[key];
21
- return obj;
22
- };
23
-
24
- export const isInRange = (min: number, max: number) => {
25
- return (value: number) => value >= min && value <= max;
26
- };
27
- export const isInfinity = (number: number) => {
28
- return (
29
- number === Number.POSITIVE_INFINITY ||
30
- number === Number.NEGATIVE_INFINITY ||
31
- number === Infinity
32
- );
33
- };
34
- export type NonEmptyArray<T> = [T, ...T[]];
35
- export const isNonEmptyArray = <T>(array: Array<T>): array is NonEmptyArray<T> => {
36
- return array.length > 0;
37
- };
38
-
39
- export const neverCheck = (args: never) => {
40
- console.log("OOPS: This value slipped through the never-check", args);
41
- };
42
-
43
- export const isString = (str: unknown): str is string => typeof str === "string";
44
-
45
- export const hasKey = <T extends string>(
46
- obj: unknown,
47
- key: T,
48
- ): obj is Record<typeof key, unknown> => {
49
- if (!isRecord(obj)) {
50
- return false;
51
- }
52
- return Object.prototype.hasOwnProperty.call(obj, key);
53
- };
54
-
55
- export const isRecord = (obj: unknown): obj is Record<string, unknown> => {
56
- if (!obj) {
57
- return false;
58
- }
59
-
60
- if (Array.isArray(obj)) {
61
- return false;
62
- }
63
-
64
- if (typeof obj !== "object") {
65
- return false;
66
- }
67
-
68
- if (obj === null) {
69
- return false;
70
- }
71
- return true;
72
- };
73
-
74
- export const isBool = (obj?: boolean): obj is boolean => typeof obj === "boolean";
75
-
76
- export const isTrue = (bool?: boolean): bool is true => bool === true;
77
-
78
- export const isFalse = (bool?: boolean): bool is false => bool === false;
79
-
80
- export const isDefined = (obj: unknown): boolean => {
81
- const notNull = obj !== null;
82
- const notUndefined = obj !== undefined;
83
- return notNull && notUndefined;
84
- };
85
-
86
- export const hasKind = (obj: unknown): obj is { readonly kind: string } => {
87
- if (!hasKey(obj, "kind")) {
88
- return false;
89
- }
90
- if (typeof obj.kind !== "string") {
91
- return false;
92
- }
93
- return obj.kind.length > 0;
94
- };
95
-
96
- export const hasValue = (obj: unknown): obj is { value: unknown } => {
97
- return hasKey(obj, "value");
98
- };
99
- export const isNumber = (value?: number): value is number => {
100
- const isNumber = typeof value === "number";
101
- const notNaN = !Number.isNaN(value);
102
- return isNumber && notNaN;
103
- };
104
-
105
- export const maxFn = (upperLimit: number) => {
106
- return (value: number) => {
107
- return Math.min(value, upperLimit);
108
- };
109
- };
110
-
111
- export const minFn = (lowerLimit: number) => {
112
- return (value: number) => {
113
- return Math.min(value, lowerLimit);
114
- };
115
- };
116
- }
1
+ // export type RandomObjectId = string & { randomObjectId: true };
2
+ export namespace DUtil {
3
+ export const randomString = (length: number): string => {
4
+ const letters = "abcdefghijklmnopqrstuvxyz";
5
+ const uppercase = letters.toUpperCase();
6
+ const all = letters + uppercase;
7
+ const abs = Math.abs(length);
8
+ let result = "";
9
+
10
+ for (let i = 0; i < abs; i++) {
11
+ const char = all.charAt(Math.floor(Math.random() * all.length));
12
+ result += char;
13
+ }
14
+ return result;
15
+ };
16
+
17
+ export const randomObjectId = () => randomString(32);
18
+
19
+ export const deleteProp = <Obj, Key extends keyof Obj>(obj: Obj, key: Key): Omit<Obj, Key> => {
20
+ delete obj[key];
21
+ return obj;
22
+ };
23
+
24
+ export const isInRange = (min: number, max: number) => {
25
+ return (value: number) => value >= min && value <= max;
26
+ };
27
+ export const isInfinity = (number: number) => {
28
+ return (
29
+ number === Number.POSITIVE_INFINITY ||
30
+ number === Number.NEGATIVE_INFINITY ||
31
+ number === Infinity
32
+ );
33
+ };
34
+ export type NonEmptyArray<T> = [T, ...T[]];
35
+ export const isNonEmptyArray = <T>(array: Array<T>): array is NonEmptyArray<T> => {
36
+ return array.length > 0;
37
+ };
38
+
39
+ export const neverCheck = (args: never) => {
40
+ console.log("OOPS: This value slipped through the never-check", args);
41
+ };
42
+
43
+ export const isString = (str: unknown): str is string => typeof str === "string";
44
+
45
+ export const hasKey = <T extends string>(
46
+ obj: unknown,
47
+ key: T,
48
+ ): obj is Record<typeof key, unknown> => {
49
+ if (!isRecord(obj)) {
50
+ return false;
51
+ }
52
+ return Object.prototype.hasOwnProperty.call(obj, key);
53
+ };
54
+
55
+ export const isRecord = (obj: unknown): obj is Record<string, unknown> => {
56
+ if (!obj) {
57
+ return false;
58
+ }
59
+
60
+ if (Array.isArray(obj)) {
61
+ return false;
62
+ }
63
+
64
+ if (typeof obj !== "object") {
65
+ return false;
66
+ }
67
+
68
+ if (obj === null) {
69
+ return false;
70
+ }
71
+ return true;
72
+ };
73
+
74
+ export const isBool = (obj?: boolean): obj is boolean => typeof obj === "boolean";
75
+
76
+ export const isTrue = (bool?: boolean): bool is true => bool === true;
77
+
78
+ export const isFalse = (bool?: boolean): bool is false => bool === false;
79
+
80
+ export const isDefined = (obj: unknown): boolean => {
81
+ const notNull = obj !== null;
82
+ const notUndefined = obj !== undefined;
83
+ return notNull && notUndefined;
84
+ };
85
+
86
+ export const hasKind = (obj: unknown): obj is { readonly kind: string } => {
87
+ if (!hasKey(obj, "kind")) {
88
+ return false;
89
+ }
90
+ if (typeof obj.kind !== "string") {
91
+ return false;
92
+ }
93
+ return obj.kind.length > 0;
94
+ };
95
+
96
+ export const hasValue = (obj: unknown): obj is { value: unknown } => {
97
+ return hasKey(obj, "value");
98
+ };
99
+ export const isNumber = (value?: number): value is number => {
100
+ const isNumber = typeof value === "number";
101
+ const notNaN = !Number.isNaN(value);
102
+ return isNumber && notNaN;
103
+ };
104
+
105
+ export const maxFn = (upperLimit: number) => {
106
+ return (value: number) => {
107
+ return Math.min(value, upperLimit);
108
+ };
109
+ };
110
+
111
+ export const minFn = (lowerLimit: number) => {
112
+ return (value: number) => {
113
+ return Math.min(value, lowerLimit);
114
+ };
115
+ };
116
+ }