@bytebury/toolkit 1.6.0 → 1.7.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/esm/src/core.d.ts +9 -10
- package/esm/src/core.d.ts.map +1 -1
- package/esm/src/core.js +35 -0
- package/package.json +1 -1
- package/script/src/core.d.ts +9 -10
- package/script/src/core.d.ts.map +1 -1
- package/script/src/core.js +35 -0
package/esm/src/core.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NonEmptyList } from "./utility_types.js";
|
|
2
1
|
/**
|
|
3
2
|
* Clone an object using structuredClone.
|
|
4
3
|
*/
|
|
@@ -23,31 +22,33 @@ export declare function isEqual(thing1: unknown, thing2: unknown): boolean;
|
|
|
23
22
|
* is a string, then it will return the first character.
|
|
24
23
|
*
|
|
25
24
|
* @remarks
|
|
26
|
-
* If an empty list is passed then this will return undefined.
|
|
25
|
+
* If an empty list or string is passed then this will return undefined.
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```ts
|
|
30
29
|
* first("hello"); // "h"
|
|
31
30
|
* first([1, 2, 3]); // 1
|
|
31
|
+
* first([]); // undefined
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function first
|
|
35
|
-
export declare function first(
|
|
34
|
+
export declare function first(value: string): string | undefined;
|
|
35
|
+
export declare function first<T>(list: T[]): T | undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Returns the last thing in a list. If the value
|
|
38
38
|
* is a string, then it will return the last character.
|
|
39
39
|
*
|
|
40
40
|
* @remarks
|
|
41
|
-
* If an empty list is passed then this will return undefined.
|
|
41
|
+
* If an empty list or string is passed then this will return undefined.
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
45
|
* last("hello"); // "o"
|
|
46
46
|
* last([1, 2, 3]); // 3
|
|
47
|
+
* last([]); // undefined
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
export declare function last
|
|
50
|
-
export declare function last(
|
|
50
|
+
export declare function last(value: string): string | undefined;
|
|
51
|
+
export declare function last<T>(list: T[]): T | undefined;
|
|
51
52
|
/**
|
|
52
53
|
* Compares two things by turning them into strings,
|
|
53
54
|
* and comparing them by their string value.
|
|
@@ -161,7 +162,6 @@ export declare function reverse<T>(thing: Set<T>): Set<T>;
|
|
|
161
162
|
* isEmpty(new Map()); // true
|
|
162
163
|
* ```
|
|
163
164
|
*/
|
|
164
|
-
export declare function isEmpty(thing: unknown[]): boolean;
|
|
165
165
|
export declare function isEmpty(thing: unknown): boolean;
|
|
166
166
|
/**
|
|
167
167
|
* Determines if the given thing is not empty.
|
|
@@ -179,7 +179,6 @@ export declare function isEmpty(thing: unknown): boolean;
|
|
|
179
179
|
* isNotEmpty(new Map()); // false
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
export declare function isNotEmpty(thing: unknown[]): boolean;
|
|
183
182
|
export declare function isNotEmpty(thing: unknown): boolean;
|
|
184
183
|
/**
|
|
185
184
|
* Returns the distinct values from a list.
|
|
@@ -220,7 +219,7 @@ export declare function distinct<T>(list: T[]): T[];
|
|
|
220
219
|
* console.log(sample([])); // undefined
|
|
221
220
|
* ```
|
|
222
221
|
*/
|
|
223
|
-
export declare function sample<T>(list:
|
|
222
|
+
export declare function sample<T>(list: T[]): T | undefined;
|
|
224
223
|
/**
|
|
225
224
|
* Gives a random number in the given range. The first parameter is inclusive
|
|
226
225
|
* and the second one is exclusive. Therefore, it will work with lists out of
|
package/esm/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,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H,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAExE;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAQtD;AAED;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAE7C;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAQlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAOpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAC3B,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAC3B,OAAO,CAGT"}
|
package/esm/src/core.js
CHANGED
|
@@ -128,6 +128,25 @@ export function reverse(thing) {
|
|
|
128
128
|
return new Set([...thing].reverse());
|
|
129
129
|
return thing.reverse();
|
|
130
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Determines if the given thing is empty.
|
|
133
|
+
*
|
|
134
|
+
* Things are empty when:
|
|
135
|
+
* * They are `None`
|
|
136
|
+
* * They are empty strings
|
|
137
|
+
* * They have no length or size
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* isEmpty([]); // true
|
|
142
|
+
* isEmpty([0]); // false
|
|
143
|
+
* isEmpty(""); // true
|
|
144
|
+
* isEmpty(" "); // false
|
|
145
|
+
* isEmpty(new Set()); // true
|
|
146
|
+
* isEmpty({}); // true
|
|
147
|
+
* isEmpty(new Map()); // true
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
131
150
|
export function isEmpty(thing) {
|
|
132
151
|
if (isNone(thing))
|
|
133
152
|
return true;
|
|
@@ -141,6 +160,22 @@ export function isEmpty(thing) {
|
|
|
141
160
|
return Object.keys(thing).length === 0;
|
|
142
161
|
return false;
|
|
143
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Determines if the given thing is not empty.
|
|
165
|
+
*
|
|
166
|
+
* @remarks this is the inverse of `isEmpty`.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* isNotEmpty([]); // false
|
|
171
|
+
* isNotEmpty([0]); // true
|
|
172
|
+
* isNotEmpty(""); // false
|
|
173
|
+
* isNotEmpty(" "); // true
|
|
174
|
+
* isNotEmpty(new Set()); // false
|
|
175
|
+
* isNotEmpty({}); // false
|
|
176
|
+
* isNotEmpty(new Map()); // false
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
144
179
|
export function isNotEmpty(thing) {
|
|
145
180
|
return !isEmpty(thing);
|
|
146
181
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytebury/toolkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "TypeScript utility library to help energize your projects with useful functions for any size project. Save yourself some time and focus on shipping features.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
package/script/src/core.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { NonEmptyList } from "./utility_types.js";
|
|
2
1
|
/**
|
|
3
2
|
* Clone an object using structuredClone.
|
|
4
3
|
*/
|
|
@@ -23,31 +22,33 @@ export declare function isEqual(thing1: unknown, thing2: unknown): boolean;
|
|
|
23
22
|
* is a string, then it will return the first character.
|
|
24
23
|
*
|
|
25
24
|
* @remarks
|
|
26
|
-
* If an empty list is passed then this will return undefined.
|
|
25
|
+
* If an empty list or string is passed then this will return undefined.
|
|
27
26
|
*
|
|
28
27
|
* @example
|
|
29
28
|
* ```ts
|
|
30
29
|
* first("hello"); // "h"
|
|
31
30
|
* first([1, 2, 3]); // 1
|
|
31
|
+
* first([]); // undefined
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
export declare function first
|
|
35
|
-
export declare function first(
|
|
34
|
+
export declare function first(value: string): string | undefined;
|
|
35
|
+
export declare function first<T>(list: T[]): T | undefined;
|
|
36
36
|
/**
|
|
37
37
|
* Returns the last thing in a list. If the value
|
|
38
38
|
* is a string, then it will return the last character.
|
|
39
39
|
*
|
|
40
40
|
* @remarks
|
|
41
|
-
* If an empty list is passed then this will return undefined.
|
|
41
|
+
* If an empty list or string is passed then this will return undefined.
|
|
42
42
|
*
|
|
43
43
|
* @example
|
|
44
44
|
* ```ts
|
|
45
45
|
* last("hello"); // "o"
|
|
46
46
|
* last([1, 2, 3]); // 3
|
|
47
|
+
* last([]); // undefined
|
|
47
48
|
* ```
|
|
48
49
|
*/
|
|
49
|
-
export declare function last
|
|
50
|
-
export declare function last(
|
|
50
|
+
export declare function last(value: string): string | undefined;
|
|
51
|
+
export declare function last<T>(list: T[]): T | undefined;
|
|
51
52
|
/**
|
|
52
53
|
* Compares two things by turning them into strings,
|
|
53
54
|
* and comparing them by their string value.
|
|
@@ -161,7 +162,6 @@ export declare function reverse<T>(thing: Set<T>): Set<T>;
|
|
|
161
162
|
* isEmpty(new Map()); // true
|
|
162
163
|
* ```
|
|
163
164
|
*/
|
|
164
|
-
export declare function isEmpty(thing: unknown[]): boolean;
|
|
165
165
|
export declare function isEmpty(thing: unknown): boolean;
|
|
166
166
|
/**
|
|
167
167
|
* Determines if the given thing is not empty.
|
|
@@ -179,7 +179,6 @@ export declare function isEmpty(thing: unknown): boolean;
|
|
|
179
179
|
* isNotEmpty(new Map()); // false
|
|
180
180
|
* ```
|
|
181
181
|
*/
|
|
182
|
-
export declare function isNotEmpty(thing: unknown[]): boolean;
|
|
183
182
|
export declare function isNotEmpty(thing: unknown): boolean;
|
|
184
183
|
/**
|
|
185
184
|
* Returns the distinct values from a list.
|
|
@@ -220,7 +219,7 @@ export declare function distinct<T>(list: T[]): T[];
|
|
|
220
219
|
* console.log(sample([])); // undefined
|
|
221
220
|
* ```
|
|
222
221
|
*/
|
|
223
|
-
export declare function sample<T>(list:
|
|
222
|
+
export declare function sample<T>(list: T[]): T | undefined;
|
|
224
223
|
/**
|
|
225
224
|
* Gives a random number in the given range. The first parameter is inclusive
|
|
226
225
|
* and the second one is exclusive. Therefore, it will work with lists out of
|
package/script/src/core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/src/core.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAElC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAEjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AACzD,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;AAKnD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MA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QG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAQlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,CAOpD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAC3B,OAAO,CAGT;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAC3B,OAAO,CAGT"}
|
package/script/src/core.js
CHANGED
|
@@ -159,6 +159,25 @@ function reverse(thing) {
|
|
|
159
159
|
return new Set([...thing].reverse());
|
|
160
160
|
return thing.reverse();
|
|
161
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Determines if the given thing is empty.
|
|
164
|
+
*
|
|
165
|
+
* Things are empty when:
|
|
166
|
+
* * They are `None`
|
|
167
|
+
* * They are empty strings
|
|
168
|
+
* * They have no length or size
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* isEmpty([]); // true
|
|
173
|
+
* isEmpty([0]); // false
|
|
174
|
+
* isEmpty(""); // true
|
|
175
|
+
* isEmpty(" "); // false
|
|
176
|
+
* isEmpty(new Set()); // true
|
|
177
|
+
* isEmpty({}); // true
|
|
178
|
+
* isEmpty(new Map()); // true
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
162
181
|
function isEmpty(thing) {
|
|
163
182
|
if (isNone(thing))
|
|
164
183
|
return true;
|
|
@@ -172,6 +191,22 @@ function isEmpty(thing) {
|
|
|
172
191
|
return Object.keys(thing).length === 0;
|
|
173
192
|
return false;
|
|
174
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Determines if the given thing is not empty.
|
|
196
|
+
*
|
|
197
|
+
* @remarks this is the inverse of `isEmpty`.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* isNotEmpty([]); // false
|
|
202
|
+
* isNotEmpty([0]); // true
|
|
203
|
+
* isNotEmpty(""); // false
|
|
204
|
+
* isNotEmpty(" "); // true
|
|
205
|
+
* isNotEmpty(new Set()); // false
|
|
206
|
+
* isNotEmpty({}); // false
|
|
207
|
+
* isNotEmpty(new Map()); // false
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
175
210
|
function isNotEmpty(thing) {
|
|
176
211
|
return !isEmpty(thing);
|
|
177
212
|
}
|