@ztimson/utils 0.20.12 → 0.21.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 +91 -91
- package/dist/array.d.ts +0 -7
- package/dist/aset.d.ts +6 -6
- package/dist/cache.d.ts +5 -17
- package/dist/emitter.d.ts +5 -5
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +466 -504
- package/dist/index.mjs.map +1 -1
- package/dist/logger.d.ts +7 -6
- package/dist/makeArray.ts +7 -0
- package/dist/misc.d.ts +0 -11
- package/dist/time.d.ts +2 -2
- package/package.json +1 -1
- package/dist/path-events.d.ts +0 -137
package/dist/time.d.ts
CHANGED
|
@@ -24,14 +24,14 @@ export declare function sleep(ms: number): Promise<void>;
|
|
|
24
24
|
* ```js
|
|
25
25
|
* let loading = true;
|
|
26
26
|
* setTimeout(() => wait = false, 1000);
|
|
27
|
-
* await
|
|
27
|
+
* await sleepUntil(() => loading); // Won't continue until loading flag is false
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* @param {() => boolean | Promise<boolean>} fn Return true to continue
|
|
31
31
|
* @param {number} checkInterval Run function ever x milliseconds
|
|
32
32
|
* @return {Promise<void>} Callback when sleep is over
|
|
33
33
|
*/
|
|
34
|
-
export declare function
|
|
34
|
+
export declare function sleepUntil(fn: () => boolean | Promise<boolean>, checkInterval?: number): Promise<void>;
|
|
35
35
|
/**
|
|
36
36
|
* Calculate the number of milliseconds until date/time
|
|
37
37
|
*
|
package/package.json
CHANGED
package/dist/path-events.d.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Available methods:
|
|
3
|
-
* * - All/Wildcard
|
|
4
|
-
* n - None
|
|
5
|
-
* c - Create
|
|
6
|
-
* r - Read
|
|
7
|
-
* u - Update
|
|
8
|
-
* d - Delete
|
|
9
|
-
* x - Execute
|
|
10
|
-
*/
|
|
11
|
-
export type Method = '*' | 'n' | 'c' | 'r' | 'u' | 'd' | 'x';
|
|
12
|
-
/**
|
|
13
|
-
* Shorthand for creating Event from a string
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const event: Event = PE`users/system:*`;
|
|
18
|
-
* ```
|
|
19
|
-
*
|
|
20
|
-
* @param {TemplateStringsArray} str String that will be parsed into Event
|
|
21
|
-
* @param {string} args
|
|
22
|
-
* @return {PathEvent} Event object
|
|
23
|
-
*/
|
|
24
|
-
export declare function PE(str: TemplateStringsArray, ...args: string[]): PathEvent;
|
|
25
|
-
/**
|
|
26
|
-
* Shorthand for creating Event strings, ensures paths are correct
|
|
27
|
-
*
|
|
28
|
-
* @param {TemplateStringsArray} str
|
|
29
|
-
* @param {string} args
|
|
30
|
-
* @return {string}
|
|
31
|
-
* @constructor
|
|
32
|
-
*/
|
|
33
|
-
export declare function PES(str: TemplateStringsArray, ...args: any[]): string;
|
|
34
|
-
export declare class PathError extends Error {
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A event broken down into its core components for easy processing
|
|
38
|
-
* Event Structure: `module/path/name:property:method`
|
|
39
|
-
* Example: `users/system:crud` or `storage/some/path/file.txt:r`
|
|
40
|
-
*/
|
|
41
|
-
export declare class PathEvent {
|
|
42
|
-
/** First directory in path */
|
|
43
|
-
module: string;
|
|
44
|
-
/** Entire path, including the module & name */
|
|
45
|
-
fullPath: string;
|
|
46
|
-
/** Path including the name, excluding the module */
|
|
47
|
-
path: string;
|
|
48
|
-
/** Last sagment of path */
|
|
49
|
-
name: string;
|
|
50
|
-
/** List of methods */
|
|
51
|
-
methods: Method[];
|
|
52
|
-
/** All/Wildcard specified */
|
|
53
|
-
all: boolean;
|
|
54
|
-
/** None specified */
|
|
55
|
-
none: boolean;
|
|
56
|
-
/** Create method specified */
|
|
57
|
-
create: boolean;
|
|
58
|
-
/** Read method specified */
|
|
59
|
-
read: boolean;
|
|
60
|
-
/** Update method specified */
|
|
61
|
-
update: boolean;
|
|
62
|
-
/** Delete method specified */
|
|
63
|
-
delete: boolean;
|
|
64
|
-
constructor(Event: string | PathEvent);
|
|
65
|
-
/**
|
|
66
|
-
* Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
67
|
-
* combined until a "none" is reached
|
|
68
|
-
*
|
|
69
|
-
* @param {string | PathEvent} paths Events as strings or pre-parsed
|
|
70
|
-
* @return {PathEvent} Final combined permission
|
|
71
|
-
*/
|
|
72
|
-
static combine(paths: (string | PathEvent)[]): PathEvent;
|
|
73
|
-
/**
|
|
74
|
-
* Squash 2 sets of paths & return true if any overlap is found
|
|
75
|
-
*
|
|
76
|
-
* @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
|
|
77
|
-
* @param has Target must have at least one of these path
|
|
78
|
-
* @return {boolean} Whether there is any overlap
|
|
79
|
-
*/
|
|
80
|
-
static has(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Squash 2 sets of paths & return true if the target has all paths
|
|
83
|
-
*
|
|
84
|
-
* @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
|
|
85
|
-
* @param has Target must have all these paths
|
|
86
|
-
* @return {boolean} Whether there is any overlap
|
|
87
|
-
*/
|
|
88
|
-
static hasAll(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): boolean;
|
|
89
|
-
/**
|
|
90
|
-
* Same as `has` but raises an error if there is no overlap
|
|
91
|
-
*
|
|
92
|
-
* @param {string | string[]} target Array of Events as strings or pre-parsed
|
|
93
|
-
* @param has Target must have at least one of these path
|
|
94
|
-
*/
|
|
95
|
-
static hasFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void;
|
|
96
|
-
/**
|
|
97
|
-
* Same as `hasAll` but raises an error if the target is missing any paths
|
|
98
|
-
*
|
|
99
|
-
* @param {string | string[]} target Array of Events as strings or pre-parsed
|
|
100
|
-
* @param has Target must have all these paths
|
|
101
|
-
*/
|
|
102
|
-
static hasAllFatal(target: string | PathEvent | (string | PathEvent)[], ...has: (string | PathEvent)[]): void;
|
|
103
|
-
/**
|
|
104
|
-
* Create event string from its components
|
|
105
|
-
*
|
|
106
|
-
* @param {string | string[]} path Event path
|
|
107
|
-
* @param {Method} methods Event method
|
|
108
|
-
* @return {string} String representation of Event
|
|
109
|
-
*/
|
|
110
|
-
static toString(path: string | string[], methods: Method | Method[]): string;
|
|
111
|
-
/**
|
|
112
|
-
* Create event string from its components
|
|
113
|
-
*
|
|
114
|
-
* @return {string} String representation of Event
|
|
115
|
-
*/
|
|
116
|
-
toString(): string;
|
|
117
|
-
}
|
|
118
|
-
export type PathListener = (event: PathEvent, ...args: any[]) => any;
|
|
119
|
-
export type PathUnsubscribe = () => void;
|
|
120
|
-
export interface IPathEventEmitter {
|
|
121
|
-
emit(event: string, ...args: any[]): void;
|
|
122
|
-
off(listener: PathListener): void;
|
|
123
|
-
on(event: string, listener: PathListener): PathUnsubscribe;
|
|
124
|
-
once(event: string, listener?: PathListener): Promise<any>;
|
|
125
|
-
relayEvents(emitter: PathEventEmitter): void;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Event emitter that uses paths allowing listeners to listen to different combinations of modules, paths & methods
|
|
129
|
-
*/
|
|
130
|
-
export declare class PathEventEmitter implements IPathEventEmitter {
|
|
131
|
-
private listeners;
|
|
132
|
-
emit(event: string | PathEvent, ...args: any[]): void;
|
|
133
|
-
off(listener: PathListener): void;
|
|
134
|
-
on(event: string | string[], listener: PathListener): PathUnsubscribe;
|
|
135
|
-
once(event: string | string[], listener?: PathListener): Promise<any>;
|
|
136
|
-
relayEvents(emitter: IPathEventEmitter): void;
|
|
137
|
-
}
|