@stryke/helpers 0.1.4 â 0.2.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.
- package/README.md +41 -1
- package/dist/deep-clone.cjs +4 -3
- package/dist/deep-clone.d.ts +22 -19
- package/dist/deep-clone.mjs +1 -1
- package/dist/deep-copy.cjs +83 -0
- package/dist/deep-copy.d.ts +69 -0
- package/dist/deep-copy.mjs +1 -0
- package/dist/index.cjs +11 -22
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +1 -1
- package/package.json +16 -30
- package/dist/is-production.cjs +0 -12
- package/dist/is-production.d.ts +0 -30
- package/dist/is-production.mjs +0 -1
- package/dist/is-runtime-server.cjs +0 -10
- package/dist/is-runtime-server.d.ts +0 -11
- package/dist/is-runtime-server.mjs +0 -1
package/README.md
CHANGED
|
@@ -47,7 +47,8 @@ This package is part of Storm Software's **đŠī¸ Stryke** monorepo. Stryke pac
|
|
|
47
47
|
# Stryke - Helper Functions
|
|
48
48
|
|
|
49
49
|
A package containing miscellaneous helper functions that are used across many
|
|
50
|
-
different Storm Software projects. This package is not meant to depend on any
|
|
50
|
+
different Storm Software projects. This package is not meant to depend on any
|
|
51
|
+
other Stryke projects.
|
|
51
52
|
|
|
52
53
|
<!-- START doctoc -->
|
|
53
54
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
@@ -56,6 +57,7 @@ different Storm Software projects. This package is not meant to depend on any ot
|
|
|
56
57
|
|
|
57
58
|
- [Stryke - Helper Functions](#stryke---helper-functions)
|
|
58
59
|
- [Table of Contents](#table-of-contents)
|
|
60
|
+
- [Quick Features](#quick-features)
|
|
59
61
|
- [Installing](#installing)
|
|
60
62
|
- [Reduced Package Size](#reduced-package-size)
|
|
61
63
|
- [Development](#development)
|
|
@@ -72,6 +74,44 @@ different Storm Software projects. This package is not meant to depend on any ot
|
|
|
72
74
|
|
|
73
75
|
<!-- END doctoc -->
|
|
74
76
|
|
|
77
|
+
## Quick Features
|
|
78
|
+
|
|
79
|
+
The following modules are available in this package:
|
|
80
|
+
|
|
81
|
+
- **arg-identity**: Provides a function that returns its argument.
|
|
82
|
+
- **debounce**: Provides a function to debounce another function, delaying its
|
|
83
|
+
execution.
|
|
84
|
+
- **deep-clone**: Provides a function to create a deep clone of an object.
|
|
85
|
+
- **deep-copy**: Provides a function to create a deep copy of an object.
|
|
86
|
+
- **deep-merge**: Provides a function to deeply merge two objects.
|
|
87
|
+
- **delay**: Provides a function to delay execution for a specified amount of
|
|
88
|
+
time.
|
|
89
|
+
- **flatten-object**: Provides a function to flatten a nested object into a
|
|
90
|
+
single level object.
|
|
91
|
+
- **get-field**: Provides a function to get the value of a field from an object.
|
|
92
|
+
- **get-ordered-by**: Provides a function to order an array of objects by a
|
|
93
|
+
specified field.
|
|
94
|
+
- **get-unique**: Provides a function to get unique values from an array.
|
|
95
|
+
- **identity**: Provides a function that returns its argument.
|
|
96
|
+
- **is-equal**: Provides a function to check if two values are deeply equal.
|
|
97
|
+
- **match-sorter**: Provides a function to sort an array based on a search
|
|
98
|
+
query.
|
|
99
|
+
- **noop**: Provides a no-operation function.
|
|
100
|
+
- **remove-accents**: Provides a function to remove accents from a string.
|
|
101
|
+
- **remove-empty-items**: Provides a function to remove empty items from an
|
|
102
|
+
array.
|
|
103
|
+
- **set-field**: Provides a function to set the value of a field in an object.
|
|
104
|
+
- **throttle**: Provides a function to throttle another function, limiting its
|
|
105
|
+
execution rate.
|
|
106
|
+
- **timeout**: Provides a function to execute another function with a timeout.
|
|
107
|
+
- **to-deep-key**: Provides a function to convert a path to a deep key.
|
|
108
|
+
- **to-path**: Provides a function to convert a deep key to a path.
|
|
109
|
+
- **unflatten-object**: Provides a function to unflatten a single level object
|
|
110
|
+
into a nested object.
|
|
111
|
+
- **union**: Provides a function to create a union of two arrays.
|
|
112
|
+
- **with-timeout**: Provides a function to execute another function with a
|
|
113
|
+
timeout.
|
|
114
|
+
|
|
75
115
|
## Installing
|
|
76
116
|
|
|
77
117
|
Using [pnpm](http://pnpm.io):
|
package/dist/deep-clone.cjs
CHANGED
|
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deepClone = deepClone;
|
|
7
|
-
var
|
|
7
|
+
var _isPrimitive = require("@stryke/types/type-checks/is-primitive");
|
|
8
|
+
var _isTypedArray = require("@stryke/types/type-checks/is-typed-array");
|
|
8
9
|
function deepClone(e) {
|
|
9
|
-
if ((0,
|
|
10
|
+
if ((0, _isPrimitive.isPrimitive)(e)) return e;
|
|
10
11
|
if (Array.isArray(e)) return e.map(n => deepClone(n));
|
|
11
12
|
if (e instanceof Date) return new Date(e.getTime());
|
|
12
13
|
if (e instanceof RegExp) return new RegExp(e.source, e.flags);
|
|
@@ -20,7 +21,7 @@ function deepClone(e) {
|
|
|
20
21
|
for (const t of e.values()) n.add(deepClone(t));
|
|
21
22
|
return n;
|
|
22
23
|
}
|
|
23
|
-
if ((0,
|
|
24
|
+
if ((0, _isTypedArray.isTypedArray)(e)) {
|
|
24
25
|
const n = new (Object.getPrototypeOf(e).constructor)(e.length);
|
|
25
26
|
for (const [t, s] of e.entries()) n[t] = deepClone(s);
|
|
26
27
|
return n;
|
package/dist/deep-clone.d.ts
CHANGED
|
@@ -1,8 +1,25 @@
|
|
|
1
|
+
export type Resolved<T> = Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
|
|
2
|
+
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
3
|
+
type ResolvedMain<T> = T extends [never] ? never : ValueOf<T> extends boolean | number | bigint | string ? ValueOf<T> : T extends (...args: any[]) => any ? never : T extends object ? ResolvedObject<T> : ValueOf<T>;
|
|
4
|
+
type ResolvedObject<T extends object> = T extends (infer U)[] ? IsTuple<T> extends true ? ResolvedTuple<T> : ResolvedMain<U>[] : T extends Set<infer U> ? Set<ResolvedMain<U>> : T extends Map<infer K, infer V> ? Map<ResolvedMain<K>, ResolvedMain<V>> : T extends WeakSet<any> | WeakMap<any, any> ? never : T extends Date | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView | Blob | File ? T : {
|
|
5
|
+
[P in keyof T]: ResolvedMain<T[P]>;
|
|
6
|
+
};
|
|
7
|
+
type ResolvedTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [ResolvedMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>, ...ResolvedTuple<Rest>] : T extends [(infer F)?] ? [ResolvedMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>?, ...ResolvedTuple<Rest>] : [];
|
|
8
|
+
type IsTuple<T extends readonly any[] | {
|
|
9
|
+
length: number;
|
|
10
|
+
}> = [T] extends [
|
|
11
|
+
never
|
|
12
|
+
] ? false : T extends readonly any[] ? number extends T["length"] ? false : true : false;
|
|
13
|
+
type ValueOf<Instance> = IsValueOf<Instance, boolean> extends true ? boolean : IsValueOf<Instance, number> extends true ? number : IsValueOf<Instance, string> extends true ? string : Instance;
|
|
14
|
+
type IsValueOf<Instance, O extends IValueOf<any>> = Instance extends O ? O extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
|
|
15
|
+
interface IValueOf<T> {
|
|
16
|
+
valueOf(): T;
|
|
17
|
+
}
|
|
1
18
|
/**
|
|
2
19
|
* Creates a deep clone of the given object.
|
|
3
20
|
*
|
|
4
|
-
* @
|
|
5
|
-
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This function creates a deep clone of the given object, including nested objects and arrays. The resulting output will be of type `Resolved<T>`, which is a type that resolves to the most specific type possible for the given input type `T`. **If you are just looking for a way to copy an object deeply, use {@link deepCopy} instead.**
|
|
6
23
|
*
|
|
7
24
|
* @example
|
|
8
25
|
* ```typescript
|
|
@@ -41,23 +58,9 @@
|
|
|
41
58
|
* console.log(clonedObj); // { a: 1, b: { c: 1 } }
|
|
42
59
|
* console.log(clonedObj === obj); // false
|
|
43
60
|
* ```
|
|
61
|
+
*
|
|
62
|
+
* @param obj - The object to clone.
|
|
63
|
+
* @returns A deep clone of the given object.
|
|
44
64
|
*/
|
|
45
65
|
export declare function deepClone<T>(obj: T): Resolved<T>;
|
|
46
|
-
export type Resolved<T> = Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
|
|
47
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
48
|
-
type ResolvedMain<T> = T extends [never] ? never : ValueOf<T> extends boolean | number | bigint | string ? ValueOf<T> : T extends (...args: any[]) => any ? never : T extends object ? ResolvedObject<T> : ValueOf<T>;
|
|
49
|
-
type ResolvedObject<T extends object> = T extends (infer U)[] ? IsTuple<T> extends true ? ResolvedTuple<T> : ResolvedMain<U>[] : T extends Set<infer U> ? Set<ResolvedMain<U>> : T extends Map<infer K, infer V> ? Map<ResolvedMain<K>, ResolvedMain<V>> : T extends WeakSet<any> | WeakMap<any, any> ? never : T extends Date | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | BigUint64Array | Int8Array | Int16Array | Int32Array | BigInt64Array | Float32Array | Float64Array | ArrayBuffer | SharedArrayBuffer | DataView | Blob | File ? T : {
|
|
50
|
-
[P in keyof T]: ResolvedMain<T[P]>;
|
|
51
|
-
};
|
|
52
|
-
type ResolvedTuple<T extends readonly any[]> = T extends [] ? [] : T extends [infer F] ? [ResolvedMain<F>] : T extends [infer F, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>, ...ResolvedTuple<Rest>] : T extends [(infer F)?] ? [ResolvedMain<F>?] : T extends [(infer F)?, ...infer Rest extends readonly any[]] ? [ResolvedMain<F>?, ...ResolvedTuple<Rest>] : [];
|
|
53
|
-
type IsTuple<T extends readonly any[] | {
|
|
54
|
-
length: number;
|
|
55
|
-
}> = [T] extends [
|
|
56
|
-
never
|
|
57
|
-
] ? false : T extends readonly any[] ? number extends T["length"] ? false : true : false;
|
|
58
|
-
type ValueOf<Instance> = IsValueOf<Instance, boolean> extends true ? boolean : IsValueOf<Instance, number> extends true ? number : IsValueOf<Instance, string> extends true ? string : Instance;
|
|
59
|
-
type IsValueOf<Instance, O extends IValueOf<any>> = Instance extends O ? O extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
|
|
60
|
-
interface IValueOf<T> {
|
|
61
|
-
valueOf(): T;
|
|
62
|
-
}
|
|
63
66
|
export {};
|
package/dist/deep-clone.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPrimitive as l
|
|
1
|
+
import{isPrimitive as l}from"@stryke/types/type-checks/is-primitive";import{isTypedArray as i}from"@stryke/types/type-checks/is-typed-array";export function deepClone(e){if(l(e))return e;if(Array.isArray(e))return e.map(n=>deepClone(n));if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const n=new Map;for(const[t,s]of e.entries())n.set(t,deepClone(s));return n}if(e instanceof Set){const n=new Set;for(const t of e.values())n.add(deepClone(t));return n}if(i(e)){const n=new(Object.getPrototypeOf(e)).constructor(e.length);for(const[t,s]of e.entries())n[t]=deepClone(s);return n}if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer)return[...e];if(e instanceof DataView){const n=new DataView([...e.buffer]);return r(e,n),n}if(typeof File<"u"&&e instanceof File){const n=new File([e],e.name,{type:e.type});return r(e,n),n}if(e instanceof Blob){const n=new Blob([e],{type:e.type});return r(e,n),n}if(e instanceof Error){const n=new e.constructor;return n.message=e.message,n.name=e.name,n.stack=e.stack,n.cause=e.cause,r(e,n),n}if(typeof e=="object"&&e!==null){const n={};return r(e,n),n}return e}function r(e,n){const t=Object.keys(e);for(const s of t){const a=Object.getOwnPropertyDescriptor(e,s);(a?.writable||a?.set)&&(n[s]=deepClone(e[s]))}}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cloneRegExp = cloneRegExp;
|
|
7
|
+
exports.deepCopy = deepCopy;
|
|
8
|
+
function a(r) {
|
|
9
|
+
const t = new ArrayBuffer(r.byteLength);
|
|
10
|
+
return new Uint8Array(t).set(new Uint8Array(r)), t;
|
|
11
|
+
}
|
|
12
|
+
function A(r) {
|
|
13
|
+
const t = a(r.buffer);
|
|
14
|
+
return new DataView(t, r.byteOffset, r.byteLength);
|
|
15
|
+
}
|
|
16
|
+
function i(r) {
|
|
17
|
+
return new Date(r.getTime());
|
|
18
|
+
}
|
|
19
|
+
function s(r) {
|
|
20
|
+
const t = new Map();
|
|
21
|
+
for (const [n, o] of r.entries()) t.set(deepCopy(n), deepCopy(o));
|
|
22
|
+
return t;
|
|
23
|
+
}
|
|
24
|
+
const y = {
|
|
25
|
+
"[object Float32Array]": Float32Array,
|
|
26
|
+
"[object Float64Array]": Float64Array,
|
|
27
|
+
"[object Int8Array]": Int8Array,
|
|
28
|
+
"[object Int16Array]": Int16Array,
|
|
29
|
+
"[object Int32Array]": Int32Array,
|
|
30
|
+
"[object Uint8Array]": Uint8Array,
|
|
31
|
+
"[object Uint16Array]": Uint16Array,
|
|
32
|
+
"[object Uint32Array]": Uint32Array,
|
|
33
|
+
"[object Uint8ClampedArray]": Uint8ClampedArray
|
|
34
|
+
},
|
|
35
|
+
c = {
|
|
36
|
+
"[object Date]": i,
|
|
37
|
+
"[object ArrayBuffer]": a,
|
|
38
|
+
"[object DataView]": A,
|
|
39
|
+
"[object Float32Array]": e,
|
|
40
|
+
"[object Float64Array]": e,
|
|
41
|
+
"[object Int8Array]": e,
|
|
42
|
+
"[object Int16Array]": e,
|
|
43
|
+
"[object Int32Array]": e,
|
|
44
|
+
"[object Uint8Array]": e,
|
|
45
|
+
"[object Uint8ClampedArray]": e,
|
|
46
|
+
"[object Uint16Array]": e,
|
|
47
|
+
"[object Uint32Array]": e,
|
|
48
|
+
"[object BigInt64Array]": e,
|
|
49
|
+
"[object BigUint64Array]": e,
|
|
50
|
+
"[object RegExp]": cloneRegExp,
|
|
51
|
+
"[object Map]": s
|
|
52
|
+
};
|
|
53
|
+
function e(r) {
|
|
54
|
+
try {
|
|
55
|
+
y["[object BigInt64Array]"] = BigInt64Array, y["[object BigUint64Array]"] = BigUint64Array;
|
|
56
|
+
} catch {}
|
|
57
|
+
const t = a(r.buffer),
|
|
58
|
+
n = y[Object.prototype.toString.call(r)];
|
|
59
|
+
if (!n) throw new Error("Unsupported typed array type in `cloneTypedArray`.");
|
|
60
|
+
return new n(t).subarray(r.byteOffset, r.byteOffset + r.length);
|
|
61
|
+
}
|
|
62
|
+
function cloneRegExp(r) {
|
|
63
|
+
const t = new RegExp(r.source, r.flags);
|
|
64
|
+
return t.lastIndex = r.lastIndex, t;
|
|
65
|
+
}
|
|
66
|
+
function deepCopy(r) {
|
|
67
|
+
const t = Object.prototype.toString.call(r);
|
|
68
|
+
if (c[t]) return c[t](r);
|
|
69
|
+
if (r === null) return r;
|
|
70
|
+
if (Array.isArray(r)) {
|
|
71
|
+
const n = [];
|
|
72
|
+
for (const o of r) n.push(o);
|
|
73
|
+
return n.map(o => deepCopy(o));
|
|
74
|
+
}
|
|
75
|
+
if (typeof r == "object") {
|
|
76
|
+
const n = {
|
|
77
|
+
...r
|
|
78
|
+
};
|
|
79
|
+
for (const o of Object.keys(n)) n[o] = deepCopy(n[o]);
|
|
80
|
+
return n;
|
|
81
|
+
}
|
|
82
|
+
return r;
|
|
83
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a clone of `regexp`.
|
|
3
|
+
*
|
|
4
|
+
* @param targetRegexp - The regexp to clone.
|
|
5
|
+
* @returns Returns the cloned regexp.
|
|
6
|
+
*/
|
|
7
|
+
export declare function cloneRegExp(targetRegexp: RegExp): RegExp;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a deep copy of `target`.
|
|
10
|
+
*
|
|
11
|
+
* @see Original source: ts-deepcopy https://github.com/ykdr2017/ts-deepcopy
|
|
12
|
+
* @see Code pen https://codepen.io/erikvullings/pen/ejyBYg
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* **Use this method instead of {@link ./deep-clone#deepClone} if you want to deep copy a value and retain its type (not cloning into a plain object).**
|
|
16
|
+
*
|
|
17
|
+
* This method is a deep copy of the given value. It supports the following types:
|
|
18
|
+
* - `ArrayBuffer`
|
|
19
|
+
* - `DataView`
|
|
20
|
+
* - `Date`
|
|
21
|
+
* - `Map`
|
|
22
|
+
* - `RegExp`
|
|
23
|
+
* - `Set`
|
|
24
|
+
* - `TypedArray`
|
|
25
|
+
* - `WeakMap`
|
|
26
|
+
* - `WeakSet`
|
|
27
|
+
* - `Array`
|
|
28
|
+
* - `Object`
|
|
29
|
+
* - `null`
|
|
30
|
+
* - `undefined`
|
|
31
|
+
* - `string`
|
|
32
|
+
* - `number`
|
|
33
|
+
* - `boolean`
|
|
34
|
+
* - `symbol`
|
|
35
|
+
* - `bigint`
|
|
36
|
+
* - `function`
|
|
37
|
+
* - `Error`
|
|
38
|
+
* - `Promise`
|
|
39
|
+
* - `MapIterator`
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const original = { a: 1, b: { c: 2 } };
|
|
44
|
+
* const copy = deepCopy(original);
|
|
45
|
+
* console.log(copy); // { a: 1, b: { c: 2 } }
|
|
46
|
+
* console.log(copy !== original); // true
|
|
47
|
+
* console.log(copy.b !== original.b); // true
|
|
48
|
+
*
|
|
49
|
+
* const date = new Date();
|
|
50
|
+
* const dateCopy = deepCopy(date);
|
|
51
|
+
* console.log(dateCopy); // Same date value as `date`
|
|
52
|
+
* console.log(dateCopy !== date); // true
|
|
53
|
+
*
|
|
54
|
+
* const map = new Map([['key', 'value']]);
|
|
55
|
+
* const mapCopy = deepCopy(map);
|
|
56
|
+
* console.log(mapCopy.get('key')); // 'value'
|
|
57
|
+
* console.log(mapCopy !== map); // true
|
|
58
|
+
*
|
|
59
|
+
* const arrayBuffer = new ArrayBuffer(8);
|
|
60
|
+
* const arrayBufferCopy = deepCopy(arrayBuffer);
|
|
61
|
+
* console.log(arrayBufferCopy.byteLength); // 8
|
|
62
|
+
* console.log(arrayBufferCopy !== arrayBuffer); // true
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @param T - Generic type of target/copied value.
|
|
66
|
+
* @param target - Target value to be copied.
|
|
67
|
+
* @returns Returns the copied value.
|
|
68
|
+
*/
|
|
69
|
+
export declare function deepCopy<T>(target: T): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function a(r){const t=new ArrayBuffer(r.byteLength);return new Uint8Array(t).set(new Uint8Array(r)),t}function A(r){const t=a(r.buffer);return new DataView(t,r.byteOffset,r.byteLength)}function i(r){return new Date(r.getTime())}function s(r){const t=new Map;for(const[n,o]of r.entries())t.set(deepCopy(n),deepCopy(o));return t}const y={"[object Float32Array]":Float32Array,"[object Float64Array]":Float64Array,"[object Int8Array]":Int8Array,"[object Int16Array]":Int16Array,"[object Int32Array]":Int32Array,"[object Uint8Array]":Uint8Array,"[object Uint16Array]":Uint16Array,"[object Uint32Array]":Uint32Array,"[object Uint8ClampedArray]":Uint8ClampedArray},c={"[object Date]":i,"[object ArrayBuffer]":a,"[object DataView]":A,"[object Float32Array]":e,"[object Float64Array]":e,"[object Int8Array]":e,"[object Int16Array]":e,"[object Int32Array]":e,"[object Uint8Array]":e,"[object Uint8ClampedArray]":e,"[object Uint16Array]":e,"[object Uint32Array]":e,"[object BigInt64Array]":e,"[object BigUint64Array]":e,"[object RegExp]":cloneRegExp,"[object Map]":s};function e(r){try{y["[object BigInt64Array]"]=BigInt64Array,y["[object BigUint64Array]"]=BigUint64Array}catch{}const t=a(r.buffer),n=y[Object.prototype.toString.call(r)];if(!n)throw new Error("Unsupported typed array type in `cloneTypedArray`.");return new n(t).subarray(r.byteOffset,r.byteOffset+r.length)}export function cloneRegExp(r){const t=new RegExp(r.source,r.flags);return t.lastIndex=r.lastIndex,t}export function deepCopy(r){const t=Object.prototype.toString.call(r);if(c[t])return c[t](r);if(r===null)return r;if(Array.isArray(r)){const n=[];for(const o of r)n.push(o);return n.map(o=>deepCopy(o))}if(typeof r=="object"){const n={...r};for(const o of Object.keys(n))n[o]=deepCopy(n[o]);return n}return r}
|
package/dist/index.cjs
CHANGED
|
@@ -36,6 +36,17 @@ Object.keys(_deepClone).forEach(function (key) {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
});
|
|
39
|
+
var _deepCopy = require("./deep-copy.cjs");
|
|
40
|
+
Object.keys(_deepCopy).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _deepCopy[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _deepCopy[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
39
50
|
var _deepMerge = require("./deep-merge.cjs");
|
|
40
51
|
Object.keys(_deepMerge).forEach(function (key) {
|
|
41
52
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -124,28 +135,6 @@ Object.keys(_isEqual).forEach(function (key) {
|
|
|
124
135
|
}
|
|
125
136
|
});
|
|
126
137
|
});
|
|
127
|
-
var _isProduction = require("./is-production.cjs");
|
|
128
|
-
Object.keys(_isProduction).forEach(function (key) {
|
|
129
|
-
if (key === "default" || key === "__esModule") return;
|
|
130
|
-
if (key in exports && exports[key] === _isProduction[key]) return;
|
|
131
|
-
Object.defineProperty(exports, key, {
|
|
132
|
-
enumerable: true,
|
|
133
|
-
get: function () {
|
|
134
|
-
return _isProduction[key];
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
var _isRuntimeServer = require("./is-runtime-server.cjs");
|
|
139
|
-
Object.keys(_isRuntimeServer).forEach(function (key) {
|
|
140
|
-
if (key === "default" || key === "__esModule") return;
|
|
141
|
-
if (key in exports && exports[key] === _isRuntimeServer[key]) return;
|
|
142
|
-
Object.defineProperty(exports, key, {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function () {
|
|
145
|
-
return _isRuntimeServer[key];
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
138
|
var _matchSorter = require("./match-sorter.cjs");
|
|
150
139
|
Object.keys(_matchSorter).forEach(function (key) {
|
|
151
140
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./arg-identity";
|
|
2
2
|
export * from "./debounce";
|
|
3
3
|
export * from "./deep-clone";
|
|
4
|
+
export * from "./deep-copy";
|
|
4
5
|
export * from "./deep-merge";
|
|
5
6
|
export * from "./delay";
|
|
6
7
|
export * from "./flatten-object";
|
|
@@ -9,8 +10,6 @@ export * from "./get-ordered-by";
|
|
|
9
10
|
export * from "./get-unique";
|
|
10
11
|
export * from "./identity";
|
|
11
12
|
export * from "./is-equal";
|
|
12
|
-
export * from "./is-production";
|
|
13
|
-
export * from "./is-runtime-server";
|
|
14
13
|
export * from "./match-sorter";
|
|
15
14
|
export * from "./noop";
|
|
16
15
|
export * from "./remove-accents";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-merge";export*from"./delay";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./
|
|
1
|
+
export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-copy";export*from"./deep-merge";export*from"./delay";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./match-sorter";export*from"./noop";export*from"./remove-accents";export*from"./remove-empty-items";export*from"./set-field";export*from"./throttle";export*from"./timeout";export*from"./to-deep-key";export*from"./to-path";export*from"./unflatten-object";export*from"./union";export*from"./with-timeout";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/helpers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing miscellaneous helper functions that are used across many different Storm Software projects.",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
12
|
"publishConfig": { "access": "public" },
|
|
13
|
-
"dependencies": { "@stryke/types": ">=0.1.
|
|
13
|
+
"dependencies": { "@stryke/types": ">=0.1.2" },
|
|
14
14
|
"devDependencies": {},
|
|
15
15
|
"sideEffects": false,
|
|
16
16
|
"files": ["dist/**/*"],
|
|
@@ -209,34 +209,6 @@
|
|
|
209
209
|
"default": "./dist/match-sorter.mjs"
|
|
210
210
|
}
|
|
211
211
|
},
|
|
212
|
-
"./is-runtime-server": {
|
|
213
|
-
"import": {
|
|
214
|
-
"types": "./dist/is-runtime-server.d.ts",
|
|
215
|
-
"default": "./dist/is-runtime-server.mjs"
|
|
216
|
-
},
|
|
217
|
-
"require": {
|
|
218
|
-
"types": "./dist/is-runtime-server.d.ts",
|
|
219
|
-
"default": "./dist/is-runtime-server.cjs"
|
|
220
|
-
},
|
|
221
|
-
"default": {
|
|
222
|
-
"types": "./dist/is-runtime-server.d.ts",
|
|
223
|
-
"default": "./dist/is-runtime-server.mjs"
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
"./is-production": {
|
|
227
|
-
"import": {
|
|
228
|
-
"types": "./dist/is-production.d.ts",
|
|
229
|
-
"default": "./dist/is-production.mjs"
|
|
230
|
-
},
|
|
231
|
-
"require": {
|
|
232
|
-
"types": "./dist/is-production.d.ts",
|
|
233
|
-
"default": "./dist/is-production.cjs"
|
|
234
|
-
},
|
|
235
|
-
"default": {
|
|
236
|
-
"types": "./dist/is-production.d.ts",
|
|
237
|
-
"default": "./dist/is-production.mjs"
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
212
|
"./is-equal": {
|
|
241
213
|
"import": {
|
|
242
214
|
"types": "./dist/is-equal.d.ts",
|
|
@@ -365,6 +337,20 @@
|
|
|
365
337
|
"default": "./dist/deep-merge.mjs"
|
|
366
338
|
}
|
|
367
339
|
},
|
|
340
|
+
"./deep-copy": {
|
|
341
|
+
"import": {
|
|
342
|
+
"types": "./dist/deep-copy.d.ts",
|
|
343
|
+
"default": "./dist/deep-copy.mjs"
|
|
344
|
+
},
|
|
345
|
+
"require": {
|
|
346
|
+
"types": "./dist/deep-copy.d.ts",
|
|
347
|
+
"default": "./dist/deep-copy.cjs"
|
|
348
|
+
},
|
|
349
|
+
"default": {
|
|
350
|
+
"types": "./dist/deep-copy.d.ts",
|
|
351
|
+
"default": "./dist/deep-copy.mjs"
|
|
352
|
+
}
|
|
353
|
+
},
|
|
368
354
|
"./deep-clone": {
|
|
369
355
|
"import": {
|
|
370
356
|
"types": "./dist/deep-clone.d.ts",
|
package/dist/is-production.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isProduction = exports.isMode = exports.isDevelopment = void 0;
|
|
7
|
-
const isMode = (o, t) => t?.toLowerCase() === o,
|
|
8
|
-
isProduction = o => isMode("production", o),
|
|
9
|
-
isDevelopment = o => !isProduction(o);
|
|
10
|
-
exports.isDevelopment = isDevelopment;
|
|
11
|
-
exports.isProduction = isProduction;
|
|
12
|
-
exports.isMode = isMode;
|
package/dist/is-production.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Check the current runtime mode of the process
|
|
3
|
-
*
|
|
4
|
-
* @param mode - The mode to check the current process's mode against
|
|
5
|
-
* @param env - An optional environment name to check the current process's mode against
|
|
6
|
-
* @returns An indicator specifying if the current runtime matches the `mode` parameter
|
|
7
|
-
*/
|
|
8
|
-
export declare const isMode: (mode: string, env: string) => boolean;
|
|
9
|
-
/**
|
|
10
|
-
* The function checks if the code is running in production.
|
|
11
|
-
*
|
|
12
|
-
* @param env - An environment name to check the current process's mode against
|
|
13
|
-
* @returns A boolean indicating if the code is running in production.
|
|
14
|
-
*/
|
|
15
|
-
export declare const isProduction: (env: string) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
* The function checks if the code is **NOT** running in production.
|
|
18
|
-
*
|
|
19
|
-
* @remarks
|
|
20
|
-
* **Please note:** This function does **not** check if the mode equals 'development' specifically.
|
|
21
|
-
*
|
|
22
|
-
* To check for the 'development' mode specifically, run:
|
|
23
|
-
*
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const isDevelopmentSpecifically = isMode("development");
|
|
26
|
-
* ```
|
|
27
|
-
* @param env - An environment name to check the current process's mode against
|
|
28
|
-
* @returns A boolean indicating if the code is **NOT** running in production.
|
|
29
|
-
*/
|
|
30
|
-
export declare const isDevelopment: (env: string) => boolean;
|
package/dist/is-production.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isMode=(o,t)=>t?.toLowerCase()===o,isProduction=o=>isMode("production",o),isDevelopment=o=>!isProduction(o);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isRuntimeServer = exports.isRuntimeClient = void 0;
|
|
7
|
-
const isRuntimeServer = () => typeof globalThis > "u" || "Deno" in globalThis,
|
|
8
|
-
isRuntimeClient = () => !isRuntimeServer();
|
|
9
|
-
exports.isRuntimeClient = isRuntimeClient;
|
|
10
|
-
exports.isRuntimeServer = isRuntimeServer;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The function checks if the code is running on the server-side
|
|
3
|
-
*
|
|
4
|
-
* @returns An indicator specifying if the code is running on the server-side
|
|
5
|
-
*/
|
|
6
|
-
export declare const isRuntimeServer: () => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* The function checks if the code is running in
|
|
9
|
-
* the browser (and not on the server).
|
|
10
|
-
*/
|
|
11
|
-
export declare const isRuntimeClient: () => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isRuntimeServer=()=>typeof globalThis>"u"||"Deno"in globalThis,isRuntimeClient=()=>!isRuntimeServer();
|