@spinajs/util 2.0.180 → 2.0.181

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.
@@ -0,0 +1,11 @@
1
+ type ArrayItemType<T> = T extends (infer U)[] ? U : T;
2
+ /**
3
+ * Makes array from single value. If passed value is already array
4
+ * return value
5
+ *
6
+ * @param val val to convert
7
+ * @returns val if array, or [val]
8
+ */
9
+ export declare const toArray: <T>(val: ArrayItemType<T> | ArrayItemType<T>[]) => ArrayItemType<T>[];
10
+ export {};
11
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,uEAEnB,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toArray = void 0;
4
+ /**
5
+ * Makes array from single value. If passed value is already array
6
+ * return value
7
+ *
8
+ * @param val val to convert
9
+ * @returns val if array, or [val]
10
+ */
11
+ const toArray = (val) => {
12
+ return global.Array.isArray(val) ? val : [val];
13
+ };
14
+ exports.toArray = toArray;
15
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":";;;AAEA;;;;;;GAMG;AACI,MAAM,OAAO,GAAG,CAAI,GAA0C,EAAsB,EAAE;IAC3F,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC,CAAC;AAFW,QAAA,OAAO,WAElB"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Tries to get value from hashmap, if missing calls onMissing callback and
3
+ * sets result to hashmap
4
+ *
5
+ * @param hash hash map object
6
+ * @param key key to find / set
7
+ * @param onMissing fallback called when key is missing in hash. returned value is inserted into hash
8
+ * @returns hash value at given key
9
+ */
10
+ export declare const tryGetHash: <T, V>(hash: Map<T, V>, key: T, onMissing: () => Promise<V>) => Promise<V>;
11
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,4EAMtB,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tryGetHash = void 0;
4
+ /**
5
+ * Tries to get value from hashmap, if missing calls onMissing callback and
6
+ * sets result to hashmap
7
+ *
8
+ * @param hash hash map object
9
+ * @param key key to find / set
10
+ * @param onMissing fallback called when key is missing in hash. returned value is inserted into hash
11
+ * @returns hash value at given key
12
+ */
13
+ const tryGetHash = async (hash, key, onMissing) => {
14
+ if (!hash.has(key)) {
15
+ hash.set(key, await onMissing());
16
+ }
17
+ return hash.get(key);
18
+ };
19
+ exports.tryGetHash = tryGetHash;
20
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACI,MAAM,UAAU,GAAG,KAAK,EAAQ,IAAe,EAAE,GAAM,EAAE,SAA2B,EAAE,EAAE;IAC7F,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,SAAS,EAAE,CAAC,CAAC;KAClC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC;AANW,QAAA,UAAU,cAMrB"}
@@ -1,2 +1,5 @@
1
- export * from './json.js';
1
+ export * from "./array.js";
2
+ export * from "./hash.js";
3
+ export * from "./json.js";
4
+ export * from "./thread.js";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/lib/cjs/index.js CHANGED
@@ -1,18 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./json.js"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./array.js"), exports);
18
+ __exportStar(require("./hash.js"), exports);
19
+ __exportStar(require("./json.js"), exports);
20
+ __exportStar(require("./thread.js"), exports);
18
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,4CAA0B;AAC1B,4CAA0B;AAC1B,8CAA4B"}
package/lib/cjs/json.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export interface ICustomDataType {
2
- dataType: string;
3
- value: any;
4
- }
5
- export declare function replacer(_: string, value: unknown): unknown;
6
- export declare function reviver(_: string, value: ICustomDataType): ICustomDataType | Map<unknown, unknown>;
1
+ export interface ICustomDataType {
2
+ dataType: string;
3
+ value: any;
4
+ }
5
+ export declare function replacer(_: string, value: unknown): unknown;
6
+ export declare function reviver(_: string, value: ICustomDataType): ICustomDataType | Map<unknown, unknown>;
7
7
  //# sourceMappingURL=json.d.ts.map
package/lib/cjs/json.js CHANGED
@@ -1,25 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reviver = exports.replacer = void 0;
4
- function replacer(_, value) {
5
- if (value instanceof Map) {
6
- return {
7
- dataType: 'Map',
8
- value: Array.from(value.entries()), // or with spread: value: [...value]
9
- };
10
- }
11
- else {
12
- return value;
13
- }
14
- }
15
- exports.replacer = replacer;
16
- function reviver(_, value) {
17
- if (typeof value === 'object' && value !== null) {
18
- if (value.dataType === 'Map') {
19
- return new Map(value.value);
20
- }
21
- }
22
- return value;
23
- }
24
- exports.reviver = reviver;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reviver = exports.replacer = void 0;
4
+ function replacer(_, value) {
5
+ if (value instanceof Map) {
6
+ return {
7
+ dataType: 'Map',
8
+ value: Array.from(value.entries()), // or with spread: value: [...value]
9
+ };
10
+ }
11
+ else {
12
+ return value;
13
+ }
14
+ }
15
+ exports.replacer = replacer;
16
+ function reviver(_, value) {
17
+ if (typeof value === 'object' && value !== null) {
18
+ if (value.dataType === 'Map') {
19
+ return new Map(value.value);
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+ exports.reviver = reviver;
25
25
  //# sourceMappingURL=json.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * Sleep for a given duration in ms
4
+ *
5
+ * @param duration sleep duration in ms
6
+ * @returns
7
+ */
8
+ export declare const sleep: (duration: number) => Promise<void>;
9
+ //# sourceMappingURL=thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,aAAc,MAAM,kBAMrC,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sleep = void 0;
4
+ /**
5
+ *
6
+ * Sleep for a given duration in ms
7
+ *
8
+ * @param duration sleep duration in ms
9
+ * @returns
10
+ */
11
+ const sleep = (duration) => {
12
+ return new Promise((resolve) => {
13
+ setTimeout(() => {
14
+ resolve();
15
+ }, duration);
16
+ });
17
+ };
18
+ exports.sleep = sleep;
19
+ //# sourceMappingURL=thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":";;;AACA;;;;;;GAMG;AACI,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE,EAAE;IACxC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AANW,QAAA,KAAK,SAMhB"}
@@ -0,0 +1,11 @@
1
+ type ArrayItemType<T> = T extends (infer U)[] ? U : T;
2
+ /**
3
+ * Makes array from single value. If passed value is already array
4
+ * return value
5
+ *
6
+ * @param val val to convert
7
+ * @returns val if array, or [val]
8
+ */
9
+ export declare const toArray: <T>(val: ArrayItemType<T> | ArrayItemType<T>[]) => ArrayItemType<T>[];
10
+ export {};
11
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.d.ts","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":"AAAA,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,uEAEnB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Makes array from single value. If passed value is already array
3
+ * return value
4
+ *
5
+ * @param val val to convert
6
+ * @returns val if array, or [val]
7
+ */
8
+ export const toArray = (val) => {
9
+ return global.Array.isArray(val) ? val : [val];
10
+ };
11
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/array.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAI,GAA0C,EAAsB,EAAE;IAC3F,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACjD,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Tries to get value from hashmap, if missing calls onMissing callback and
3
+ * sets result to hashmap
4
+ *
5
+ * @param hash hash map object
6
+ * @param key key to find / set
7
+ * @param onMissing fallback called when key is missing in hash. returned value is inserted into hash
8
+ * @returns hash value at given key
9
+ */
10
+ export declare const tryGetHash: <T, V>(hash: Map<T, V>, key: T, onMissing: () => Promise<V>) => Promise<V>;
11
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,4EAMtB,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Tries to get value from hashmap, if missing calls onMissing callback and
3
+ * sets result to hashmap
4
+ *
5
+ * @param hash hash map object
6
+ * @param key key to find / set
7
+ * @param onMissing fallback called when key is missing in hash. returned value is inserted into hash
8
+ * @returns hash value at given key
9
+ */
10
+ export const tryGetHash = async (hash, key, onMissing) => {
11
+ if (!hash.has(key)) {
12
+ hash.set(key, await onMissing());
13
+ }
14
+ return hash.get(key);
15
+ };
16
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../../src/hash.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAAQ,IAAe,EAAE,GAAM,EAAE,SAA2B,EAAE,EAAE;IAC7F,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,SAAS,EAAE,CAAC,CAAC;KAClC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC,CAAC"}
@@ -1,2 +1,5 @@
1
- export * from './json.js';
1
+ export * from "./array.js";
2
+ export * from "./hash.js";
3
+ export * from "./json.js";
4
+ export * from "./thread.js";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/lib/mjs/index.js CHANGED
@@ -1,2 +1,5 @@
1
- export * from './json.js';
1
+ export * from "./array.js";
2
+ export * from "./hash.js";
3
+ export * from "./json.js";
4
+ export * from "./thread.js";
2
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/lib/mjs/json.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export interface ICustomDataType {
2
- dataType: string;
3
- value: any;
4
- }
5
- export declare function replacer(_: string, value: unknown): unknown;
6
- export declare function reviver(_: string, value: ICustomDataType): ICustomDataType | Map<unknown, unknown>;
1
+ export interface ICustomDataType {
2
+ dataType: string;
3
+ value: any;
4
+ }
5
+ export declare function replacer(_: string, value: unknown): unknown;
6
+ export declare function reviver(_: string, value: ICustomDataType): ICustomDataType | Map<unknown, unknown>;
7
7
  //# sourceMappingURL=json.d.ts.map
package/lib/mjs/json.js CHANGED
@@ -1,20 +1,20 @@
1
- export function replacer(_, value) {
2
- if (value instanceof Map) {
3
- return {
4
- dataType: 'Map',
5
- value: Array.from(value.entries()), // or with spread: value: [...value]
6
- };
7
- }
8
- else {
9
- return value;
10
- }
11
- }
12
- export function reviver(_, value) {
13
- if (typeof value === 'object' && value !== null) {
14
- if (value.dataType === 'Map') {
15
- return new Map(value.value);
16
- }
17
- }
18
- return value;
19
- }
1
+ export function replacer(_, value) {
2
+ if (value instanceof Map) {
3
+ return {
4
+ dataType: 'Map',
5
+ value: Array.from(value.entries()), // or with spread: value: [...value]
6
+ };
7
+ }
8
+ else {
9
+ return value;
10
+ }
11
+ }
12
+ export function reviver(_, value) {
13
+ if (typeof value === 'object' && value !== null) {
14
+ if (value.dataType === 'Map') {
15
+ return new Map(value.value);
16
+ }
17
+ }
18
+ return value;
19
+ }
20
20
  //# sourceMappingURL=json.js.map
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * Sleep for a given duration in ms
4
+ *
5
+ * @param duration sleep duration in ms
6
+ * @returns
7
+ */
8
+ export declare const sleep: (duration: number) => Promise<void>;
9
+ //# sourceMappingURL=thread.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,aAAc,MAAM,kBAMrC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ *
3
+ * Sleep for a given duration in ms
4
+ *
5
+ * @param duration sleep duration in ms
6
+ * @returns
7
+ */
8
+ export const sleep = (duration) => {
9
+ return new Promise((resolve) => {
10
+ setTimeout(() => {
11
+ resolve();
12
+ }, duration);
13
+ });
14
+ };
15
+ //# sourceMappingURL=thread.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread.js","sourceRoot":"","sources":["../../src/thread.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,QAAgB,EAAE,EAAE;IACxC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,UAAU,CAAC,GAAG,EAAE;YACd,OAAO,EAAE,CAAC;QACZ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}