@valkyriestudios/utils 12.19.0 → 12.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 +384 -161
- package/array/dedupe.d.ts +0 -2
- package/array/groupBy.d.ts +0 -1
- package/array/is.d.ts +1 -3
- package/array/isNotEmpty.d.ts +1 -3
- package/array/join.d.ts +0 -2
- package/array/join.js +3 -2
- package/array/mapFn.js +1 -1
- package/array/mapPrimitive.d.ts +0 -2
- package/array/sort.d.ts +0 -2
- package/array/split.d.ts +0 -2
- package/boolean/is.d.ts +1 -3
- package/date/addUTC.d.ts +5 -6
- package/date/diff.d.ts +5 -6
- package/date/endOfUTC.d.ts +4 -5
- package/date/format.d.ts +16 -2
- package/date/format.js +175 -73
- package/date/index.d.ts +3 -1
- package/date/index.js +6 -1
- package/date/is.d.ts +1 -3
- package/date/isFormat.d.ts +11 -0
- package/date/isFormat.js +110 -0
- package/date/isLeap.d.ts +7 -0
- package/date/isLeap.js +11 -0
- package/date/nowUnix.d.ts +0 -2
- package/date/nowUnixMs.d.ts +0 -2
- package/date/setTimeUTC.d.ts +1 -2
- package/date/startOfUTC.d.ts +4 -5
- package/date/toUTC.d.ts +1 -3
- package/date/toUnix.d.ts +1 -3
- package/deep/freeze.d.ts +1 -3
- package/deep/get.d.ts +5 -7
- package/deep/seal.d.ts +1 -3
- package/deep/set.d.ts +0 -1
- package/equal.d.ts +2 -4
- package/formdata/index.d.ts +2 -1
- package/formdata/index.js +3 -1
- package/formdata/is.d.ts +1 -3
- package/formdata/toObject.d.ts +16 -0
- package/formdata/toObject.js +23 -0
- package/function/is.d.ts +1 -3
- package/function/isAsync.d.ts +1 -3
- package/function/noop.d.ts +0 -2
- package/function/noop.js +1 -2
- package/function/noopresolve.d.ts +0 -2
- package/function/noopreturn.d.ts +0 -2
- package/function/sleep.d.ts +1 -3
- package/hash/fnv1A.d.ts +2 -4
- package/hash/fnv1A.js +2 -2
- package/hash/guid.d.ts +0 -2
- package/index.d.ts +41 -10
- package/number/is.d.ts +1 -3
- package/number/isAbove.d.ts +2 -4
- package/number/isAboveOrEqual.d.ts +2 -4
- package/number/isBelow.d.ts +2 -4
- package/number/isBelowOrEqual.d.ts +2 -4
- package/number/isBetween.d.ts +3 -5
- package/number/isBetween.js +4 -6
- package/number/isInteger.d.ts +1 -3
- package/number/isIntegerAbove.d.ts +2 -4
- package/number/isIntegerAboveOrEqual.d.ts +2 -4
- package/number/isIntegerBelow.d.ts +2 -4
- package/number/isIntegerBelowOrEqual.d.ts +2 -4
- package/number/isIntegerBetween.d.ts +3 -5
- package/number/isIntegerBetween.js +4 -6
- package/number/isNumericalNaN.d.ts +1 -3
- package/number/randomBetween.d.ts +2 -4
- package/number/randomIntBetween.d.ts +2 -4
- package/number/round.d.ts +2 -4
- package/number/round.js +5 -3
- package/number/toPercentage.d.ts +4 -6
- package/object/define.d.ts +0 -2
- package/object/is.d.ts +1 -3
- package/object/isNotEmpty.d.ts +2 -6
- package/object/merge.d.ts +2 -4
- package/object/merge.js +2 -3
- package/object/pick.d.ts +0 -2
- package/object/pick.js +2 -3
- package/package.json +1 -1
- package/regexp/is.d.ts +1 -3
- package/regexp/sanitize.d.ts +1 -3
- package/regexp/sanitize.js +2 -1
- package/string/humanizeBytes.d.ts +1 -3
- package/string/humanizeBytes.js +5 -11
- package/string/humanizeNumber.d.ts +2 -4
- package/string/humanizeNumber.js +13 -15
- package/string/is.d.ts +1 -3
- package/string/isBetween.d.ts +4 -6
- package/string/isNotEmpty.d.ts +2 -4
- package/string/shorten.d.ts +0 -2
- package/string/shorten.js +1 -4
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# @valkyriestudios/utils
|
|
2
2
|
|
|
3
|
-
[](https://codecov.io/gh/ValkyrieStudios/utils)
|
|
4
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/test.yml)
|
|
5
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/lint.yml)
|
|
6
|
+
[](https://github.com/ValkyrieStudios/utils/actions/workflows/github-code-scanning/codeql)
|
|
7
7
|
[](https://www.npmjs.com/package/@valkyriestudios/utils)
|
|
8
8
|
[](https://www.npmjs.com/package/@valkyriestudios/utils)
|
|
9
9
|
|
|
@@ -13,26 +13,27 @@ Zero-dependency collection of single-function utilities for common tasks
|
|
|
13
13
|
`npm install @valkyriestudios/utils`
|
|
14
14
|
|
|
15
15
|
## Available Functions
|
|
16
|
-
|
|
17
|
-
### array
|
|
18
|
-
- **isArray(val:any)**
|
|
16
|
+
### array/is(val:unknown)
|
|
19
17
|
Check if a variable is of type Array
|
|
20
18
|
```typescript
|
|
19
|
+
import is from '@valkyriestudios/utils/array/is';
|
|
21
20
|
isArray({a:1}); // FALSE
|
|
22
21
|
isArray([]); // TRUE
|
|
23
22
|
```
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
### array/isNotEmpty(val:unknown)
|
|
26
25
|
Check if a variable a non-empty array
|
|
27
26
|
```typescript
|
|
27
|
+
import isNotEmptyArray from '@valkyriestudios/utils/array/isNotEmpty';
|
|
28
28
|
isNotEmptyArray({a:1}); // FALSE
|
|
29
29
|
isNotEmptyArray([]); // FALSE
|
|
30
30
|
isNotEmptyArray([0, 1, 2]); // TRUE
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
### array/mapKey(val:Record[], key:string, opts:object={})
|
|
34
34
|
Map a non-primitive object array into an object map by key
|
|
35
35
|
```typescript
|
|
36
|
+
import mapKey from '@valkyriestudios/utils/array/mapKey';
|
|
36
37
|
mapKey([
|
|
37
38
|
{uid: 12, name: 'Peter'},
|
|
38
39
|
{uid: 15, name: 'Jonas'},
|
|
@@ -50,6 +51,7 @@ output:
|
|
|
50
51
|
|
|
51
52
|
Autofilters anything not meeting the spec:
|
|
52
53
|
```typescript
|
|
54
|
+
import mapKey from '@valkyriestudios/utils/array/mapKey';
|
|
53
55
|
mapKey([
|
|
54
56
|
0,
|
|
55
57
|
{uid: 12, name: 'Peter'},
|
|
@@ -74,6 +76,7 @@ output:
|
|
|
74
76
|
|
|
75
77
|
allows merging objects onto existing keys:
|
|
76
78
|
```typescript
|
|
79
|
+
import mapKey from '@valkyriestudios/utils/array/mapKey';
|
|
77
80
|
mapKey([
|
|
78
81
|
0,
|
|
79
82
|
{uid: 12, name: 'Peter'},
|
|
@@ -99,10 +102,11 @@ output:
|
|
|
99
102
|
}
|
|
100
103
|
```
|
|
101
104
|
|
|
102
|
-
|
|
105
|
+
### array/mapFn(val:Record[], key:Function, opts:object={})
|
|
103
106
|
Same behavior as mapKey but instead of a key, a function is passed to generate your own key. Eg:
|
|
104
107
|
|
|
105
108
|
```typescript
|
|
109
|
+
import mapFn from '@valkyriestudios/utils/array/mapFn';
|
|
106
110
|
mapFn([
|
|
107
111
|
{uid: 12, name: 'Peter'},
|
|
108
112
|
{uid: 15, name: 'Jonas'},
|
|
@@ -120,19 +124,21 @@ output:
|
|
|
120
124
|
|
|
121
125
|
options are the same as the mapKey function
|
|
122
126
|
|
|
123
|
-
|
|
127
|
+
### array/mapPrimitive(val:any[], opts:object={valtrim:false,keyround:false,valround:false})
|
|
124
128
|
Map an array of primitives (number/string)
|
|
125
129
|
```typescript
|
|
130
|
+
import mapPrimitive from '@valkyriestudios/utils/array/mapPrimitive';
|
|
126
131
|
mapPrimitive([1,2,3]); // {1: 1, 2: 2, 3: 3}
|
|
127
132
|
mapPrimitive(['hello', 'hello', 'foo', 'bar']); // {hello: 'hello', foo: 'foo', bar: 'bar'}
|
|
128
133
|
mapPrimitive(['hello', ' hello', 'foo', ' foo'], {valtrim: true}); // {hello: 'hello', foo: 'foo'}
|
|
129
134
|
```
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
### array/groupBy(val:Record[], handler:Function|string)
|
|
132
137
|
Return a grouped object from an array. This function **will automatically filter out any non/empty objects**.
|
|
133
138
|
|
|
134
139
|
Example usage when using a **function** as the handler
|
|
135
140
|
```typescript
|
|
141
|
+
import groupBy from '@valkyriestudios/utils/array/groupBy';
|
|
136
142
|
/* The output of the function will be what the key is on the map */
|
|
137
143
|
const group = groupBy([
|
|
138
144
|
{tally: 20, name: 'Peter'},
|
|
@@ -163,9 +169,9 @@ const group = groupBy([
|
|
|
163
169
|
```
|
|
164
170
|
**Take note**: If the function returns an undefined or empty string the object will be added to a fallback group called '_'
|
|
165
171
|
|
|
166
|
-
|
|
167
172
|
Example usage when using a **string** as the handler to denote a grouping by a certain property name
|
|
168
173
|
```typescript
|
|
174
|
+
import groupBy from '@valkyriestudios/utils/array/groupBy';
|
|
169
175
|
const group = groupBy([
|
|
170
176
|
{role: 'user', name: 'Peter'},
|
|
171
177
|
{role: 'user', name: 'Jake'},
|
|
@@ -184,9 +190,10 @@ const group = groupBy([
|
|
|
184
190
|
**Take note**: any object without the key will be added to a fallback group called '_'
|
|
185
191
|
|
|
186
192
|
|
|
187
|
-
|
|
193
|
+
### array/dedupe(val:Array, opts?:{filter_fn})
|
|
188
194
|
Remove all duplicates from an array, behind the scenes it uses the fnv 1A hash algorithm to performantly do comparisons.
|
|
189
195
|
```typescript
|
|
196
|
+
import dedupe from '@valkyriestudios/utils/array/dedupe';
|
|
190
197
|
dedupe(['a','a','b','c','c']); // ['a', 'b', 'c']
|
|
191
198
|
dedupe(['1',1,'2',2]); // ['1','2']
|
|
192
199
|
dedupe([new RegExp(/ab+c/, 'i'), new RegExp(/ab+c/, 'i')]); // [new RegExp(/ab+c/, 'i')]
|
|
@@ -197,10 +204,11 @@ dedupe(['hello', 'hello', 'world', false, 'world'], {filter_fn: el => isNotEmpty
|
|
|
197
204
|
|
|
198
205
|
Take Note: The filtering is applied while deduping, ensuring O(n) performance, as such this is faster than dedupe(arr.filter(...))
|
|
199
206
|
|
|
200
|
-
|
|
207
|
+
### array/join(val:Array, opts:object={delim:' ',trim:true,valtrim:true,innertrim:true,valround:false})
|
|
201
208
|
Concatenate the values within an array into a string, behind the scenes this will automatically filter out any value that is not a string or numerical value. For strings it will automatically trim (and remove if empty after trimming) before joining.
|
|
202
209
|
|
|
203
210
|
```typescript
|
|
211
|
+
import join from '@valkyriestudios/utils/array/join';
|
|
204
212
|
join(['Valkyrie', 'Studios']); // 'Valkyrie Studios'
|
|
205
213
|
join([5.1, ' years ', 'ago'], {valround: 0}); // '5 years ago'
|
|
206
214
|
join(['peter ', ' valkyrie '], {delim: '@'}); // 'peter@valkyrie'
|
|
@@ -209,19 +217,21 @@ join([' a', 1], {delim: '', valtrim: false, trim: false}); // ' a1'
|
|
|
209
217
|
join([' hello world ', 'this is peter '], {valtrim:true, innertrim: true, delim: ' '}); // 'hello world this is peter'
|
|
210
218
|
```
|
|
211
219
|
|
|
212
|
-
|
|
220
|
+
### array/shuffle(val:Array)
|
|
213
221
|
Shuffle an array (Fisher-Yates) in O(n), take note this changes the passed value
|
|
214
222
|
|
|
215
223
|
```typescript
|
|
224
|
+
import shuffle from '@valkyriestudios/utils/array/shuffle';
|
|
216
225
|
const arr = [1, 2, 3, 4, 5, 6];
|
|
217
226
|
shuffle(arr);
|
|
218
227
|
// [4, 6, 3, 2, 5, 1]
|
|
219
228
|
```
|
|
220
229
|
|
|
221
|
-
|
|
230
|
+
### array/sort(val:Array[object], by:string|Function, dir:Enum(asc,desc), options:Object)
|
|
222
231
|
Sort an array of objects, uses an implementation of [Tony Hoare's quicksort](https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html)
|
|
223
232
|
|
|
224
233
|
```typescript
|
|
234
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
225
235
|
const out = sort([
|
|
226
236
|
{test: 'Peter'},
|
|
227
237
|
{test: 'Jack'},
|
|
@@ -235,6 +245,7 @@ const out = sort([
|
|
|
235
245
|
```
|
|
236
246
|
|
|
237
247
|
```typescript
|
|
248
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
238
249
|
const out = sort([
|
|
239
250
|
{test: 'Peter'},
|
|
240
251
|
{test: 'Jack'},
|
|
@@ -250,6 +261,7 @@ const out = sort([
|
|
|
250
261
|
allows passing a function to determine the key to sort by
|
|
251
262
|
|
|
252
263
|
```typescript
|
|
264
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
253
265
|
const out = sort([
|
|
254
266
|
{test: 'Peter'},
|
|
255
267
|
{test: 'Jack'},
|
|
@@ -265,6 +277,7 @@ const out = sort([
|
|
|
265
277
|
auto-cleans input to only contains non-empty objects
|
|
266
278
|
|
|
267
279
|
```typescript
|
|
280
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
268
281
|
const out = sort([
|
|
269
282
|
{test: 'Peter'},
|
|
270
283
|
{},
|
|
@@ -284,6 +297,7 @@ allows passing custom filter function to clean input
|
|
|
284
297
|
Take note: Sort will still verify that the object is not an empty object, even when passing a custom filter function.
|
|
285
298
|
|
|
286
299
|
```typescript
|
|
300
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
287
301
|
const out = sort([
|
|
288
302
|
{test: 'Peter'},
|
|
289
303
|
{},
|
|
@@ -304,6 +318,7 @@ const out = sort([
|
|
|
304
318
|
allows passing custom options to position elements without a proper key (nokey_atend, defaults to true), or hide them (nokey_hide, defaults to false)
|
|
305
319
|
|
|
306
320
|
```typescript
|
|
321
|
+
import sort from '@valkyriestudios/utils/array/sort';
|
|
307
322
|
const arr = [{test: 'Peter'}, {test: undefined}, {test: 'Jack'}, {test: 'Pony'}, {uid: 100}, {test: 'JOHn'}];
|
|
308
323
|
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: false});
|
|
309
324
|
// [{test: undefined}, {uid: 100}, {test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}]
|
|
@@ -315,29 +330,31 @@ const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_hide: true});
|
|
|
315
330
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}]
|
|
316
331
|
```
|
|
317
332
|
|
|
318
|
-
|
|
333
|
+
### array/split(val:any[], size:number, opts?:{filter_fn})
|
|
319
334
|
Splits an array into subarray of provided size with optional filter
|
|
320
335
|
```typescript
|
|
336
|
+
import split from '@valkyriestudios/utils/array/split';
|
|
321
337
|
split([1,2,3,4,5], 2); // [[1,2],[3,4],[5]]
|
|
322
338
|
split([1, 2, false, 4, 5], 2, {filter_fn: isInteger}); // [[1,2],[4,5]]
|
|
323
339
|
```
|
|
324
340
|
|
|
325
341
|
Take Note: The filtering is applied while splitting, ensuring O(n) performance, as such this is faster than split(arr.filter(...), ...)
|
|
326
342
|
|
|
327
|
-
### boolean
|
|
328
|
-
- **isBoolean(val:any)**
|
|
343
|
+
### boolean/is(val:any)
|
|
329
344
|
Check if a variable is of type Boolean
|
|
330
345
|
```typescript
|
|
346
|
+
import isBoolean from '@valkyriestudios/utils/boolean/is';
|
|
331
347
|
isBoolean(null); // FALSE
|
|
332
348
|
isBoolean(false); // TRUE
|
|
333
349
|
isBoolean(true); // TRUE
|
|
334
350
|
```
|
|
335
351
|
|
|
336
|
-
### caching
|
|
337
|
-
- **memoize(fn:Function, resolver:Function=false, memoize_for:number|false)**
|
|
352
|
+
### caching/memoize(fn:Function, resolver:Function=false, memoize_for:number|false)
|
|
338
353
|
memoize the output of a function. An optional resolver function can be passed which allows custom cache key generation.
|
|
339
354
|
|
|
340
355
|
```typescript
|
|
356
|
+
import memoize from '@valkyriestudios/utils/caching/memoize';
|
|
357
|
+
|
|
341
358
|
const memoized_function = memoize((a) => {
|
|
342
359
|
return fnv1A(a);
|
|
343
360
|
});
|
|
@@ -345,6 +362,8 @@ const memoized_function = memoize((a) => {
|
|
|
345
362
|
|
|
346
363
|
Take Note: Also supports async functions and cache busting, eg:
|
|
347
364
|
```typescript
|
|
365
|
+
import memoize from '@valkyriestudios/utils/caching/memoize';
|
|
366
|
+
|
|
348
367
|
async function retrieveUser (userId:string) {
|
|
349
368
|
...
|
|
350
369
|
}
|
|
@@ -364,19 +383,60 @@ await memoized('123456'); /* Original function will not be called and memoized c
|
|
|
364
383
|
await memoized('123456'); /* Original function will be called and re-cached */
|
|
365
384
|
```
|
|
366
385
|
|
|
367
|
-
### date
|
|
368
|
-
|
|
369
|
-
Check if a variable is of type Date
|
|
386
|
+
### date/is(val:unknown)
|
|
387
|
+
Check if a variable is of type Date and valid
|
|
370
388
|
```typescript
|
|
389
|
+
import isDate from '@valkyriestudios/utils/date/is';
|
|
371
390
|
isDate(new Date('December 17, 1995 03:24:00')); // TRUE
|
|
372
391
|
isDate('December 17, 1995 03:24:00'); // FALSE
|
|
373
392
|
```
|
|
374
393
|
|
|
375
|
-
|
|
394
|
+
### date/isLeap(val:Date)
|
|
395
|
+
Check if a date is in a leap year or not
|
|
396
|
+
```typescript
|
|
397
|
+
import isLeap from '@valkyriestudios/utils/date/isLeap';
|
|
398
|
+
isLeap(new Date("2022-02-07T14:30:59.000Z")); // false
|
|
399
|
+
isLeap(new Date("2024-02-07T14:30:59.000Z")); // true
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### date/isFormat(val:unknown, spec:string)
|
|
403
|
+
Check if a variable is a string in a particular date format
|
|
404
|
+
```typescript
|
|
405
|
+
import isFormat from '@valkyriestudios/utils/date/isFormat';
|
|
406
|
+
isFormat('2024-02-07', 'YYYY-MM-DD'); // TRUE
|
|
407
|
+
isFormat('2024-2-07', 'YYYY-MM-DD'); // FALSE
|
|
408
|
+
isFormat('12:30 AM', 'HH:mm A'); // TRUE
|
|
409
|
+
isFormat('2024-Q4', 'YYYY-[Q]Q'); // TRUE
|
|
410
|
+
isFormat('2024-Q5', 'YYYY-[Q]Q'); // FALSE (there is no such thing as a fifth quarter)
|
|
411
|
+
isFormat('2024-02-29T12:30:00.000Z', 'ISO'); // TRUE
|
|
412
|
+
isFormat('2023-02-29T12:30:00.000Z', 'ISO'); // FALSE (leap year)
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Available tokens for usage in spec:
|
|
416
|
+
| Token | Description | Example |
|
|
417
|
+
|:---------|:--------------------------|:---------------|
|
|
418
|
+
| `YYYY` | Full Year | 2021 |
|
|
419
|
+
| `Q` | Quarters of the year | 1 2 3 4 |
|
|
420
|
+
| `MM` | Month as 2 char | 01 02 .. 11 12 |
|
|
421
|
+
| `DD` | Day of month as 2 char | 01 02 .. 30 31 |
|
|
422
|
+
| `HH` | Hours as 2-char | 00 01 .. 22 23 |
|
|
423
|
+
| `mm` | Minutes as 2-char | 00 01 .. 58 59 |
|
|
424
|
+
| `ss` | Seconds as 2-char | 00 01 .. 58 59 |
|
|
425
|
+
| `SSS` | Milliseconds as 3-digit | 000 001 ... 998 999 |
|
|
426
|
+
| `A` | Uppercase AM/PM | AM ... PM |
|
|
427
|
+
| `a` | Lowercase AM/PM | am ... pm |
|
|
428
|
+
| `Z` | Zone, does not allow full zone names, only Z or offsets | `Z` `+02:00` |
|
|
429
|
+
| `ISO` | Check for full iso date format, take note this enforces milliseconds as a requirement | 2024-02-03T10:28:30.000Z |
|
|
430
|
+
|
|
431
|
+
Note: The `ISO` token is a shorthand for `YYYY-MM-DDTHH:mm:ss.SSSZ`
|
|
432
|
+
Note: You can escape characters by surrounding them with `[...]` in your spec, eg: `YYYY-[Q]Q` would check for example `2024-Q1`
|
|
433
|
+
|
|
434
|
+
### date/diff(val_a:Date, val_b:Date, key:string)
|
|
376
435
|
Take two incoming dates and return the difference between them in a certain unit. Possible key options(week,day,hour,minute,second,millisecond).
|
|
377
436
|
|
|
378
437
|
Note: Does not touch the passed date objects, if no key is passed will default to millisecond
|
|
379
438
|
```typescript
|
|
439
|
+
import diff from '@valkyriestudios/utils/date/diff';
|
|
380
440
|
diff(new Date("2022-10-05T13:12:11+02:00"), new Date("2022-11-05T13:12:11+06:00"), 'week'); // -4.404761904761905
|
|
381
441
|
diff(new Date("2022-11-05T13:12:11+06:00"), new Date("2022-10-05T13:12:11+02:00"), 'day'); // 30.83333333333333332
|
|
382
442
|
diff(new Date("2022-11-05T13:12:11+06:00"), new Date("2022-10-05T13:12:11+02:00"), 'hour'); // 740
|
|
@@ -385,14 +445,18 @@ diff(new Date("2022-10-05T13:12:11+02:00"), new Date("2022-10-05T17:43:09.344+06
|
|
|
385
445
|
diff(new Date("2022-10-05T13:12:11+02:00"), new Date("2022-10-05T17:43:09.344+06:00"), 'millisecond'); // -1858344
|
|
386
446
|
diff(new Date("2022-11-05T13:12:11+06:00"), new Date("2022-10-05T13:25:43.898+02:00")); // 2663187102
|
|
387
447
|
```
|
|
388
|
-
- **format(val:Date, spec:string, locale?:string, zone?:string):string**
|
|
389
|
-
Format a date according to a spec/locale and zone
|
|
390
448
|
|
|
391
|
-
|
|
449
|
+
### date/format(val:Date, spec:string, locale?:string, zone?:string, startOfWeek?:'mon'|'sun'|'sat'):string
|
|
450
|
+
Format a date according to a spec/locale and zone
|
|
392
451
|
|
|
393
|
-
Note
|
|
452
|
+
**Take Note**:
|
|
453
|
+
- The locale is by default set to `en-US`
|
|
454
|
+
- The zone is by default detected as the time zone of the client
|
|
455
|
+
- If we fail to detect the time zone we default to `UTC`
|
|
456
|
+
- The start of week is by default set to `mon`, the supported values are `mon`, `sun`, `sat`
|
|
457
|
+
- You can escape characters by surrounding them with `[...]` in your spec, eg: `YYYY-[Q]Q` would for example become `2024-Q1`
|
|
394
458
|
|
|
395
|
-
Available
|
|
459
|
+
**Available Tokens**:
|
|
396
460
|
| Token | Description | Example |
|
|
397
461
|
|:---------|:--------------------------|:---------------|
|
|
398
462
|
| `YYYY` | Full Year | 2021 |
|
|
@@ -401,6 +465,8 @@ Available tokens for usage in spec:
|
|
|
401
465
|
| `MMM` | Month as 3 char | Jan Feb ... Nov Dec |
|
|
402
466
|
| `MM` | Month as 2 char | 01 02 .. 11 12 |
|
|
403
467
|
| `M` | Month as pure digit | 1 2 .. 11 12 |
|
|
468
|
+
| `WW` | Week Number as 2 char | 01 02 .. 52 53 |
|
|
469
|
+
| `W` | Week Number as pure digit | 1 2 .. 52 53 |
|
|
404
470
|
| `DD` | Day of month as 2 char | 01 02 .. 30 31 |
|
|
405
471
|
| `D` | Day of month as 1 char | 1 2 .. 30 31 |
|
|
406
472
|
| `dddd` | Day of week as 3 char | Sun Mon ... Fri Sat |
|
|
@@ -421,7 +487,22 @@ Available tokens for usage in spec:
|
|
|
421
487
|
| `t` | Locale-specific short time | 10:28 AM |
|
|
422
488
|
| `T` | Locale-specific time with seconds | 10:28:30 AM |
|
|
423
489
|
|
|
490
|
+
**Additional**:
|
|
491
|
+
Format has several additional functions defined which help usage inside of an ecosystem (eg: webapp) by **overriding the global defaults** used by format.
|
|
492
|
+
| Function | Description | Example |
|
|
493
|
+
|:---------|:--------------------------|:---------------|
|
|
494
|
+
| setZone | Sets the global timezone used by format | `format.setZone("Europe/Brussels")` |
|
|
495
|
+
| getZone | Returns the global timezone used by format ||
|
|
496
|
+
| setLocale | Sets the global locale used by format | `format.setLocale("nl-BE")` |
|
|
497
|
+
| getLocale | Returns the global locale used by format ||
|
|
498
|
+
| setStartOfWeek | Sets the global start of week used by format | `format.setStartOfWeek("sun")` |
|
|
499
|
+
| getStartOfWeek | Returns the global start of week used by format ||
|
|
500
|
+
|
|
501
|
+
**Usage**:
|
|
502
|
+
|
|
424
503
|
```typescript
|
|
504
|
+
import format from '@valkyriestudios/utils/date/format';
|
|
505
|
+
|
|
425
506
|
format(new Date('2023-01-10T14:30:00Z'), '[Today is] dddd, MMMM D, YYYY [at] h:mm A', 'en', 'Europe/Brussels');
|
|
426
507
|
// 'Today is Tuesday, January 10, 2023 at 2:30 PM'
|
|
427
508
|
|
|
@@ -433,25 +514,38 @@ format(new Date('2022-07-14T16:40:30Z'), 'YYYY-MM-DD', 'fr', 'Asia/Singapore');
|
|
|
433
514
|
|
|
434
515
|
format(new Date('2022-07-14T16:40:30Z'), 'YYYY-MM-DD', 'fr', 'Europe/Brussels');
|
|
435
516
|
// 2022-07-14
|
|
517
|
+
|
|
518
|
+
// ... (somewhere else in your code)
|
|
519
|
+
|
|
520
|
+
format.setLocale('fr');
|
|
521
|
+
format.setZone('Asia/Singapore');
|
|
522
|
+
|
|
523
|
+
// ... (somewhere else in your code)
|
|
524
|
+
|
|
525
|
+
format(new Date('2022-07-14T16:40:30Z'), 'dddd, [Year] Q Q M D [à] hh:mm A [string]');
|
|
526
|
+
// 'vendredi, Year 3 3 7 15 à 12:40 AM string'
|
|
527
|
+
format(new Date('2022-07-14T19:40:30Z'), 'dddd, YYYY-MM-DD');
|
|
528
|
+
// 'vendredi, 2022-07-15'
|
|
436
529
|
```
|
|
437
530
|
|
|
438
|
-
|
|
531
|
+
### date/toUTC(val:Date)
|
|
439
532
|
Takes the passed date object and returns a new date object set for utc
|
|
440
533
|
|
|
441
|
-
|
|
534
|
+
### date/toUnix(val:Date)
|
|
442
535
|
Takes the passed date object and returns its unix timestamp in seconds
|
|
443
536
|
|
|
444
|
-
|
|
537
|
+
### date/nowUnix()
|
|
445
538
|
Returns the current unix timestamp in seconds
|
|
446
539
|
|
|
447
|
-
|
|
540
|
+
### date/nowUnixMs()
|
|
448
541
|
Returns the current unix timestamp in milliseconds
|
|
449
542
|
|
|
450
|
-
|
|
543
|
+
### date/setTimeUTC(val:Date, props:{hour?:number;minute?:number;second?:number;millisecond?:number})
|
|
451
544
|
Take the incoming date and return a date where the time portion is set to the values in the provided props
|
|
452
545
|
|
|
453
546
|
Note: Does not touch the date object passed
|
|
454
547
|
```typescript
|
|
548
|
+
import setTimeUTC from '@valkyriestudios/utils/date/setTimeUTC';
|
|
455
549
|
setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5}); // new Date("2023-05-04T05:04:27.432Z")
|
|
456
550
|
setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5, minute: 30}); // new Date("2023-05-04T05:30:27.432Z")
|
|
457
551
|
setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {hour: 5, minute: 30, second: 0}); // new Date("2023-05-04T05:30:00.432Z")
|
|
@@ -460,11 +554,12 @@ setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {minute: 30, second: 0, millise
|
|
|
460
554
|
setTimeUTC(new Date("2023-05-04T12:04:27.432Z"), {second: 9, millisecond: 0}); // new Date("2023-05-04T12:04:09.000Z")
|
|
461
555
|
```
|
|
462
556
|
|
|
463
|
-
|
|
557
|
+
### date/startOfUTC(val:Date, key:string)
|
|
464
558
|
Take the incoming date and return a date set to the start of passed key. Possible key options(year,quarter,month,week,week_sun,week_mon,week_tue,week_wed,week_thu,week_fri,week_sat,day,hour,minute,second).
|
|
465
559
|
|
|
466
560
|
Note: Does not touch the date object passed
|
|
467
561
|
```typescript
|
|
562
|
+
import startOfUTC from '@valkyriestudios/utils/date/startOfUTC';
|
|
468
563
|
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-01-01T00:00:00.000Z")
|
|
469
564
|
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-04-01T00:00:00.000Z")
|
|
470
565
|
startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-01T00:00:00.000Z")
|
|
@@ -480,11 +575,12 @@ startOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'minute'); // new Date("2023-0
|
|
|
480
575
|
startOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023-05-04T10:04:27.000Z")
|
|
481
576
|
```
|
|
482
577
|
|
|
483
|
-
|
|
578
|
+
### date/endOfUTC(val:Date, key:string)
|
|
484
579
|
Take the incoming date and return a date set to the end of passed key. Possible key options(year,quarter,month,week,week_sun,week_mon,week_tue,week_wed,week_thu,week_fri,week_sat,day,hour,minute,second).
|
|
485
580
|
|
|
486
581
|
Note: Does not touch the date object passed
|
|
487
582
|
```typescript
|
|
583
|
+
import endOfUTC from '@valkyriestudios/utils/date/endOfUTC';
|
|
488
584
|
endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'year'); // new Date("2023-12-31T23:59:59.999Z")
|
|
489
585
|
endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'quarter'); // new Date("2023-06-30T23:59:59.999Z")
|
|
490
586
|
endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'month'); // new Date("2023-05-31T23:59:59.999Z")
|
|
@@ -504,11 +600,12 @@ endOfUTC(new Date("2023-05-04T12:04:27+02:00"), 'minute'); // new Date("2023-05-
|
|
|
504
600
|
endOfUTC(new Date("2023-05-04T12:04:27.043+02:00"), 'second'); // new Date("2023-05-04T10:04:27.999Z")
|
|
505
601
|
```
|
|
506
602
|
|
|
507
|
-
|
|
603
|
+
### date/addUTC(val:Date, amount:integer, key:string)
|
|
508
604
|
Take the incoming date and add a certain amount of the passed key. Possible key options(year,years,month,months,day,days,hour,hours,minute,minutes,second,seconds,millisecond,milliseconds).
|
|
509
605
|
|
|
510
606
|
Note: Does not touch the date object passed
|
|
511
607
|
```typescript
|
|
608
|
+
import addUTC from '@valkyriestudios/utils/date/addUTC';
|
|
512
609
|
addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'year'); // new Date("2032-10-05T11:12:11.000Z")
|
|
513
610
|
addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'year'); // new Date("2012-10-05T11:12:11.000Z")
|
|
514
611
|
addUTC(new Date("2022-10-05T13:12:11+02:00"), 10, 'month'); // new Date("2023-08-05T11:12:11.000Z")
|
|
@@ -527,35 +624,36 @@ addUTC(new Date("2022-10-05T13:12:11+02:00"), 336000 * 60, 'second'); // new Dat
|
|
|
527
624
|
addUTC(new Date("2022-10-05T13:12:11+02:00"), -10, 'second'); // new Date("2022-10-05T11:12:01.000Z")
|
|
528
625
|
```
|
|
529
626
|
|
|
530
|
-
### deep
|
|
531
|
-
- **deepFreeze(val:Object)**
|
|
627
|
+
### deep/freeze(val:Object)
|
|
532
628
|
Recursively freezes all properties of an object
|
|
533
629
|
```typescript
|
|
630
|
+
import deepFreeze from '@valkyriestudios/utils/deep/freeze';
|
|
534
631
|
const myObj = deepFreeze({
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
632
|
+
a: 2,
|
|
633
|
+
b: {
|
|
634
|
+
c: 3,
|
|
635
|
+
d: {
|
|
636
|
+
e: 'hello',
|
|
637
|
+
}
|
|
638
|
+
}
|
|
542
639
|
});
|
|
543
640
|
Object.isFrozen(myObj); // TRUE
|
|
544
641
|
Object.isFrozen(myObj.b); // TRUE
|
|
545
642
|
Object.isFrozen(myObj.b.d); // TRUE
|
|
546
643
|
```
|
|
547
644
|
|
|
548
|
-
|
|
645
|
+
### deep/seal(val:Object)
|
|
549
646
|
Recursively freezes all properties of an object
|
|
550
647
|
```typescript
|
|
648
|
+
import deepSeal from '@valkyriestudios/utils/deep/seal';
|
|
551
649
|
const myObj = deepSeal({
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
650
|
+
a: 2,
|
|
651
|
+
b: {
|
|
652
|
+
c: 3,
|
|
653
|
+
d: {
|
|
654
|
+
e: 'hello',
|
|
655
|
+
}
|
|
656
|
+
}
|
|
559
657
|
});
|
|
560
658
|
Object.isSealed(myObj); // TRUE
|
|
561
659
|
Object.isSealed(myObj.b); // TRUE
|
|
@@ -563,66 +661,62 @@ Object.isSealed(myObj.b.d); // TRUE
|
|
|
563
661
|
Object.isFrozen(myObj.b.d); // FALSE
|
|
564
662
|
```
|
|
565
663
|
|
|
566
|
-
|
|
664
|
+
### deep/set(obj:Object, path:string, value:any=null, define:boolean=false)
|
|
567
665
|
Sets a property and its value deep in the structure of an object
|
|
568
666
|
```typescript
|
|
667
|
+
import deepSet from '@valkyriestudios/utils/deep/set';
|
|
569
668
|
const myObj = {
|
|
570
|
-
|
|
669
|
+
a: 2,
|
|
571
670
|
};
|
|
572
671
|
deepSet(myObj, 'b.c.d.e', 4);
|
|
573
672
|
myObj.b.c.d.e; // 4
|
|
574
|
-
```
|
|
575
673
|
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
],
|
|
674
|
+
const myObj2 = {
|
|
675
|
+
a: 2,
|
|
676
|
+
b: [
|
|
677
|
+
{ price : 2 },
|
|
678
|
+
{ price : 4 },
|
|
679
|
+
],
|
|
583
680
|
};
|
|
584
|
-
deepSet(
|
|
585
|
-
deepSet(
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
```
|
|
681
|
+
deepSet(myObj2, 'b[0].price', 100);
|
|
682
|
+
deepSet(myObj2, 'b[1].price', 500);
|
|
683
|
+
myObj2.b[0].price; // 100
|
|
684
|
+
myObj2.b[1].price; // 500
|
|
589
685
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
a: 2,
|
|
686
|
+
const myObj3 = {
|
|
687
|
+
a: 2,
|
|
593
688
|
};
|
|
594
|
-
deepSet(
|
|
595
|
-
|
|
689
|
+
deepSet(myObj3, 'b.c', { value: function () => {...} }, true);
|
|
690
|
+
myObj3.b.c; // Function
|
|
596
691
|
```
|
|
597
692
|
|
|
598
|
-
|
|
693
|
+
### deep/get(obj:Object, path:string, get_parent:boolean=false)
|
|
599
694
|
Retrieves a value based on a path in a deeply nested object
|
|
600
695
|
```typescript
|
|
696
|
+
import deepGet from '@valkyriestudios/utils/deep/get';
|
|
601
697
|
const myObj = {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
698
|
+
a: 2,
|
|
699
|
+
b: [
|
|
700
|
+
{ price : 2 },
|
|
701
|
+
{ price : 4 },
|
|
702
|
+
],
|
|
607
703
|
};
|
|
608
704
|
deepGet(myObj, 'b[0].price', true); // [{price: 2}, {price: 4}]
|
|
609
|
-
```
|
|
610
705
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
],
|
|
706
|
+
const myObj2 = {
|
|
707
|
+
a: 2,
|
|
708
|
+
b: [
|
|
709
|
+
{ price : 2 },
|
|
710
|
+
{ price : 4 },
|
|
711
|
+
],
|
|
618
712
|
};
|
|
619
|
-
deepGet(
|
|
713
|
+
deepGet(myObj2, 'b[0].price'); // 2
|
|
620
714
|
```
|
|
621
715
|
|
|
622
|
-
### equal
|
|
623
|
-
- **equal(a:any, b:any)**
|
|
716
|
+
### equal(a:any, b:any)
|
|
624
717
|
Check if a variable is equal to another one
|
|
625
718
|
```typescript
|
|
719
|
+
import equal from '@valkyriestudios/utils/equal';
|
|
626
720
|
equal(5, 6); // FALSE
|
|
627
721
|
equal(1, 1); // TRUE
|
|
628
722
|
equal([0, 1, 2], [1, 2]); // FALSE
|
|
@@ -632,47 +726,91 @@ equal(new Date('2012-20-09'), '2012-20-09'); // TRUE ( check is being done on un
|
|
|
632
726
|
equal(new RegExp(/ab+c/, 'i'), /ab+c/i); // TRUE
|
|
633
727
|
```
|
|
634
728
|
|
|
635
|
-
### function
|
|
636
|
-
- **debounce(val:Fn, wait:number)**
|
|
729
|
+
### function/debounce(val:Fn, wait:number)
|
|
637
730
|
Wrap a function in a debounce proxy that waits for X uninterrupted milliseconds before running callback function
|
|
731
|
+
```typescript
|
|
732
|
+
const log = (message: string) => console.log(message);
|
|
733
|
+
const debouncedLog = debounce(log, 2000);
|
|
734
|
+
debouncedLog("Hello, World!"); // 2 seconds later we see log
|
|
735
|
+
|
|
736
|
+
debouncedLog("Hello, World!");
|
|
737
|
+
debouncedLog.cancel(); // No log as we cancelled
|
|
738
|
+
|
|
739
|
+
debouncedLog("Hello, World!");
|
|
740
|
+
debouncedLog.flush(); // Immediate log no 2 second debounce
|
|
638
741
|
|
|
639
|
-
|
|
742
|
+
debouncedLog("Hello, World!");
|
|
743
|
+
debouncedLog.cancel();
|
|
744
|
+
debouncedLog.flush(); // Nothing happens as timeout was killed through cancel
|
|
745
|
+
````
|
|
746
|
+
|
|
747
|
+
### function/is(val:unknown)
|
|
640
748
|
Check if a variable is a Function
|
|
749
|
+
```typescript
|
|
750
|
+
import isFunction from '@valkyriestudios/utils/function/is';
|
|
751
|
+
isFunction(() => console.log('Hello')); // TRUE
|
|
752
|
+
isFunction('December 17, 1995 03:24:00'); // FALSE
|
|
753
|
+
```
|
|
641
754
|
|
|
642
|
-
|
|
755
|
+
### function/isAsync(val:unknown):boolean
|
|
643
756
|
Check if a variable is an async function
|
|
757
|
+
```typescript
|
|
758
|
+
import isAsync from '@valkyriestudios/utils/function/isAsync';
|
|
759
|
+
isAsync(() => console.log('Hello')); // FALSE
|
|
760
|
+
isAsync(async () => {
|
|
761
|
+
await sleep(1000);
|
|
762
|
+
console.log('Hello');
|
|
763
|
+
}); // TRUE
|
|
764
|
+
```
|
|
644
765
|
|
|
645
|
-
|
|
766
|
+
### function/noop()
|
|
646
767
|
An empty function that can be used in (for example) piping
|
|
647
768
|
|
|
648
|
-
|
|
769
|
+
### function/noopreturn(val:any)
|
|
649
770
|
An empty function that will pass back the variable that it was passed
|
|
650
771
|
|
|
651
|
-
|
|
772
|
+
### function/noopresolve(val:any)
|
|
652
773
|
An empty function that returns a promise that will immediately resolve itself and pass back any variable that was passed to it
|
|
653
774
|
|
|
654
|
-
|
|
775
|
+
### function/sleep(val:int)
|
|
655
776
|
An empty function that returns a promise that will resolve after X milliseconds, default is set to 1000ms.
|
|
656
|
-
|
|
777
|
+
```typescript
|
|
778
|
+
import sleep from '@valkyriestudios/utils/function/sleep';
|
|
779
|
+
await sleep(1000); // sleeps for 1 second
|
|
780
|
+
````
|
|
657
781
|
|
|
658
|
-
### formdata
|
|
659
|
-
- **isFormData(val:any)**
|
|
782
|
+
### formdata/is(val:any)
|
|
660
783
|
Check if a variable is of type FormData
|
|
661
784
|
```typescript
|
|
785
|
+
import isFormData from '@valkyriestudios/utils/formdata/is';
|
|
662
786
|
isFormData(new FormData()); // TRUE
|
|
663
787
|
isFormData({hi: 'there'}); // FALSE
|
|
664
788
|
```
|
|
665
789
|
|
|
666
|
-
###
|
|
667
|
-
|
|
790
|
+
### formdata/toObject(val:FormData)
|
|
791
|
+
Converts an instance of FormData to an object
|
|
792
|
+
```typescript
|
|
793
|
+
import toObject from '@valkyriestudios/utils/formdata/toObject';
|
|
794
|
+
const form = new FormData();
|
|
795
|
+
form.append('name', 'Alice');
|
|
796
|
+
form.append('hobbies', 'reading');
|
|
797
|
+
form.append('hobbies', 'writing');
|
|
798
|
+
form.append('emptyField', '');
|
|
799
|
+
|
|
800
|
+
toObject(form); // {name: 'Alice', hobbies: ['reading', 'writing'], emptyField: ''}
|
|
801
|
+
```
|
|
802
|
+
|
|
803
|
+
### hash/guid()
|
|
668
804
|
Generate a unique identifier (guid) according to RFC4122
|
|
669
805
|
```typescript
|
|
806
|
+
import guid from '@valkyriestudios/utils/hash/guid';
|
|
670
807
|
guid(); // 245caf1a-86af-11e7-bb31-be2e44b06b34
|
|
671
808
|
```
|
|
672
809
|
|
|
673
|
-
|
|
810
|
+
### hash/fnv1A(val:unknown)
|
|
674
811
|
Generate a fnv1A hash from an object, using a 32-bit prime/offset
|
|
675
812
|
```typescript
|
|
813
|
+
import fnv1A from '@valkyriestudios/utils/hash/fnv1A';
|
|
676
814
|
fnv1A('hello world'); // -2023343616
|
|
677
815
|
fnv1A({a:1,b:2}); // 361168128
|
|
678
816
|
fnv1A(4); // 1630425728
|
|
@@ -680,54 +818,114 @@ fnv1A(new RegExp(/ab+c/, 'i')); // 2131692544
|
|
|
680
818
|
fnv1A(new Date('2012-02-02')); // 1655579136
|
|
681
819
|
```
|
|
682
820
|
|
|
683
|
-
###
|
|
684
|
-
|
|
821
|
+
### Is
|
|
822
|
+
The utility found at `@valkyriestudios/utils/is` combines and exposes a barrel export of several other functions found within the library. This does not extend those utils but simply acts as an easy single import for many utils all at once.
|
|
823
|
+
|
|
824
|
+
These functions are the following:
|
|
825
|
+
- **Is.Array**
|
|
826
|
+
- **Is.NeArray**
|
|
827
|
+
- **Is.NotEmptyArray**
|
|
828
|
+
- **Is.Boolean**
|
|
829
|
+
- **Is.Date**
|
|
830
|
+
- **Is.Formdata**
|
|
831
|
+
- **Is.Function**
|
|
832
|
+
- **Is.AsyncFunction**
|
|
833
|
+
- **Is.Num**
|
|
834
|
+
- **Is.NumBetween**
|
|
835
|
+
- **Is.NumAbove**
|
|
836
|
+
- **Is.NumAboveOrEqual**
|
|
837
|
+
- **Is.NumBelow**
|
|
838
|
+
- **Is.NumBelowOrEqual**
|
|
839
|
+
- **Is.NumGt**
|
|
840
|
+
- **Is.NumGte**
|
|
841
|
+
- **Is.NumLt**
|
|
842
|
+
- **Is.NumLte**
|
|
843
|
+
- **Is.Number**
|
|
844
|
+
- **Is.NumberBetween**
|
|
845
|
+
- **Is.NumberAbove**
|
|
846
|
+
- **Is.NumberAboveOrEqual**
|
|
847
|
+
- **Is.NumberBelow**
|
|
848
|
+
- **Is.NumberBelowOrEqual**
|
|
849
|
+
- **Is.Int**
|
|
850
|
+
- **Is.IntBetween**
|
|
851
|
+
- **Is.IntAbove**
|
|
852
|
+
- **Is.IntAboveOrEqual**
|
|
853
|
+
- **Is.IntBelow**
|
|
854
|
+
- **Is.IntBelowOrEqual**
|
|
855
|
+
- **Is.IntGt**
|
|
856
|
+
- **Is.IntGte**
|
|
857
|
+
- **Is.IntLt**
|
|
858
|
+
- **Is.IntLte**
|
|
859
|
+
- **Is.Integer**
|
|
860
|
+
- **Is.IntegerBetween**
|
|
861
|
+
- **Is.IntegerBelow**
|
|
862
|
+
- **Is.IntegerBelowOrEqual**
|
|
863
|
+
- **Is.IntegerAbove**
|
|
864
|
+
- **Is.IntegerAboveOrEqual**
|
|
865
|
+
- **Is.RegExp**
|
|
866
|
+
- **Is.Object**
|
|
867
|
+
- **Is.NeObject**
|
|
868
|
+
- **Is.NotEmptyObject**
|
|
869
|
+
- **Is.String**
|
|
870
|
+
- **Is.StringBetween**
|
|
871
|
+
- **Is.NeString**
|
|
872
|
+
- **Is.NotEmptyString**
|
|
873
|
+
- **Is.Equal**
|
|
874
|
+
- **Is.Eq**
|
|
875
|
+
|
|
876
|
+
### number/is(val:unknown)
|
|
685
877
|
Check if a variable is a number
|
|
686
878
|
```typescript
|
|
879
|
+
import isNumber from '@valkyriestudios/utils/number/is';
|
|
687
880
|
isNumber('foo'); // FALSE
|
|
688
881
|
isNumber(4); // TRUE
|
|
689
882
|
isNumber(0.5); // TRUE
|
|
690
883
|
```
|
|
691
884
|
|
|
692
|
-
|
|
885
|
+
### number/isAbove(val:number, comp:number)
|
|
693
886
|
Check if a variable is a number above a certain bound
|
|
694
887
|
```typescript
|
|
888
|
+
import isNumberAbove from '@valkyriestudios/utils/number/isAbove';
|
|
695
889
|
isNumberAbove(5, 0); // TRUE
|
|
696
890
|
isNumberAbove(.1, 0); // TRUE
|
|
697
891
|
isNumberAbove(-1, -1); // FALSE
|
|
698
892
|
isNumberAbove(-10, -9); // FALSE
|
|
699
893
|
```
|
|
700
894
|
|
|
701
|
-
|
|
895
|
+
### number/isAboveOrEqual(val:number, comp:number)
|
|
702
896
|
Check if a variable is a number above or equal to a certain bound
|
|
703
897
|
```typescript
|
|
898
|
+
import isNumberAboveOrEqual from '@valkyriestudios/utils/number/isAboveOrEqual';
|
|
704
899
|
isNumberAboveOrEqual(5, 0); // TRUE
|
|
705
900
|
isNumberAboveOrEqual(.1, 0); // TRUE
|
|
706
901
|
isNumberAboveOrEqual(-1, -1); // TRUE
|
|
707
902
|
isNumberAboveOrEqual(-10, -9); // FALSE
|
|
708
903
|
```
|
|
709
904
|
|
|
710
|
-
|
|
905
|
+
### number/isBelow(val:number, comp:number)
|
|
711
906
|
Check if a variable is a number below a certain bound
|
|
712
907
|
```typescript
|
|
908
|
+
import isNumberBelow from '@valkyriestudios/utils/number/isBelow';
|
|
713
909
|
isNumberBelow(0, 5); // TRUE
|
|
714
910
|
isNumberBelow(0, .1); // TRUE
|
|
715
911
|
isNumberBelow(-1, -1); // FALSE
|
|
716
912
|
isNumberBelow(-9, -10); // FALSE
|
|
717
913
|
```
|
|
718
914
|
|
|
719
|
-
|
|
915
|
+
### number/isBelowOrEqual(val:number, comp:number)
|
|
720
916
|
Check if a variable is a number below or equal a certain bound
|
|
721
917
|
```typescript
|
|
918
|
+
import isNumberBelowOrEqual from '@valkyriestudios/utils/number/isBelowOrEqual';
|
|
722
919
|
isNumberBelowOrEqual(0, 5); // TRUE
|
|
723
920
|
isNumberBelowOrEqual(0, .1); // TRUE
|
|
724
921
|
isNumberBelowOrEqual(-1, -1); // TRUE
|
|
725
922
|
isNumberBelowOrEqual(-9, -10); // FALSE
|
|
726
923
|
```
|
|
727
924
|
|
|
728
|
-
|
|
925
|
+
### number/isBetween(val:number, min:number, max:number)
|
|
729
926
|
Check if a variable is a number between a range of numbers
|
|
730
927
|
```typescript
|
|
928
|
+
import isNumberBetween from '@valkyriestudios/utils/number/isBetween';
|
|
731
929
|
isNumberBetween(5, 0, 10); // TRUE
|
|
732
930
|
isNumberBetween(.1, 0, 1); // TRUE
|
|
733
931
|
isNumberBetween(-.1, -1, 0); // TRUE
|
|
@@ -735,35 +933,39 @@ isNumberBetween(0, 0, 1); // TRUE
|
|
|
735
933
|
isNumberBetween(-1, 0, 1); // FALSE
|
|
736
934
|
```
|
|
737
935
|
|
|
738
|
-
|
|
936
|
+
### number/isInteger(val:unknown)
|
|
739
937
|
Check if a variable is an integer
|
|
740
938
|
```typescript
|
|
939
|
+
import isInteger from '@valkyriestudios/utils/number/isInteger';
|
|
741
940
|
isInteger('foo'); // FALSE
|
|
742
941
|
isInteger(4); // TRUE
|
|
743
942
|
isInteger(0.5); // FALSE
|
|
744
943
|
```
|
|
745
944
|
|
|
746
|
-
|
|
945
|
+
### number/isIntegerAbove(val:number, comp:number)
|
|
747
946
|
Check if a variable is an integer above a certain bound
|
|
748
947
|
```typescript
|
|
948
|
+
import isIntegerAbove from '@valkyriestudios/utils/number/isIntegerAbove';
|
|
749
949
|
isIntegerAbove(5, 0); // TRUE
|
|
750
950
|
isIntegerAbove(.1, 0); // FALSE
|
|
751
951
|
isIntegerAbove(-1, -1); // FALSE
|
|
752
952
|
isIntegerAbove(-10, -9); // FALSE
|
|
753
953
|
```
|
|
754
954
|
|
|
755
|
-
|
|
955
|
+
### number/isIntegerAboveOrEqual(val:number, comp:number)
|
|
756
956
|
Check if a variable is an integer above or equal to a certain bound
|
|
757
957
|
```typescript
|
|
958
|
+
import isIntegerAboveOrEqual from '@valkyriestudios/utils/number/isIntegerAboveOrEqual';
|
|
758
959
|
isIntegerAboveOrEqual(5, 0); // TRUE
|
|
759
960
|
isIntegerAboveOrEqual(.1, 0); // FALSE
|
|
760
961
|
isIntegerAboveOrEqual(-1, -1); // TRUE
|
|
761
962
|
isIntegerAboveOrEqual(-10, -9); // FALSE
|
|
762
963
|
```
|
|
763
964
|
|
|
764
|
-
|
|
965
|
+
### number/isIntegerBelow(val:number, comp:number)
|
|
765
966
|
Check if a variable is an integer below a certain bound
|
|
766
967
|
```typescript
|
|
968
|
+
import isIntegerBelow from '@valkyriestudios/utils/number/isIntegerBelow';
|
|
767
969
|
isIntegerBelow(0, 5); // TRUE
|
|
768
970
|
isIntegerBelow(0, .1); // TRUE
|
|
769
971
|
isIntegerBelow(.4, 5); // FALSE
|
|
@@ -771,9 +973,10 @@ isIntegerBelow(-1, -1); // FALSE
|
|
|
771
973
|
isIntegerBelow(-9, -10); // FALSE
|
|
772
974
|
```
|
|
773
975
|
|
|
774
|
-
|
|
976
|
+
### number/isIntegerBelowOrEqual(val:number, comp:number)
|
|
775
977
|
Check if a variable is an integer below or equal to a certain bound
|
|
776
978
|
```typescript
|
|
979
|
+
import isIntegerBelowOrEqual from '@valkyriestudios/utils/number/isIntegerBelowOrEqual';
|
|
777
980
|
isIntegerBelowOrEqual(0, 5); // TRUE
|
|
778
981
|
isIntegerBelowOrEqual(0, .1); // TRUE
|
|
779
982
|
isIntegerBelowOrEqual(.4, 5); // FALSE
|
|
@@ -781,9 +984,10 @@ isIntegerBelowOrEqual(-1, -1); // TRUE
|
|
|
781
984
|
isIntegerBelowOrEqual(-9, -10); // FALSE
|
|
782
985
|
```
|
|
783
986
|
|
|
784
|
-
|
|
987
|
+
### number/isIntegerBetween(val:number, min:number, max:number)
|
|
785
988
|
Check if a variable is an integer between a range of numbers
|
|
786
989
|
```typescript
|
|
990
|
+
import isIntegerBetween from '@valkyriestudios/utils/number/isIntegerBetween';
|
|
787
991
|
isIntegerBetween(5, 0, 10); // TRUE
|
|
788
992
|
isIntegerBetween(.1, 0, 1); // FALSE
|
|
789
993
|
isIntegerBetween(-.1, -1, 0); // FALSE
|
|
@@ -791,69 +995,77 @@ isIntegerBetween(0, 0, 1); // TRUE
|
|
|
791
995
|
isIntegerBetween(-1, 0, 1); // FALSE
|
|
792
996
|
```
|
|
793
997
|
|
|
794
|
-
|
|
998
|
+
### number/isNumericalNaN(val:unknown)
|
|
795
999
|
Check if a variable is a numerical nan ( a number that is a NaN, this distinguishment is made since both a string or a number can be NaN)
|
|
796
1000
|
```typescript
|
|
1001
|
+
import isNumericalNaN from '@valkyriestudios/utils/number/isNumericalNaN';
|
|
797
1002
|
isNumericalNaN('foo'); // FALSE
|
|
798
1003
|
isNumericalNaN(NaN); // TRUE
|
|
799
1004
|
```
|
|
800
1005
|
|
|
801
|
-
|
|
1006
|
+
### number/toPercentage(val:Number,precision:Number=0,min:Number=0,max:Number=1)
|
|
802
1007
|
Calculate the percentage of a specific value in a range
|
|
803
1008
|
```typescript
|
|
1009
|
+
import toPercentage from '@valkyriestudios/utils/number/toPercentage';
|
|
804
1010
|
toPercentage(0.50106579, 5); // 50.11658
|
|
805
1011
|
toPercentage(-356, 0, -1000, 1000); // 32
|
|
806
1012
|
toPercentage(0.5); // 50
|
|
807
1013
|
```
|
|
808
1014
|
|
|
809
|
-
|
|
1015
|
+
### number/round(val:Number,precision:Number=0)
|
|
810
1016
|
Round a numeric value to a specific amount of decimals
|
|
811
1017
|
```typescript
|
|
1018
|
+
import round from '@valkyriestudios/utils/number/round';
|
|
812
1019
|
round(5.123456789, 0); // 5
|
|
813
1020
|
round(5.123456789, 2); // 5.12
|
|
814
1021
|
round(5.123456789, 5); // 5.12346
|
|
815
1022
|
```
|
|
816
1023
|
|
|
817
|
-
|
|
1024
|
+
### number/randomBetween(min:Number=0,max:Number=10)
|
|
818
1025
|
Generate a random numeric value between a min and max range
|
|
819
1026
|
```typescript
|
|
1027
|
+
import randomBetween from '@valkyriestudios/utils/number/randomBetween';
|
|
820
1028
|
randomBetween(); // Will generate a random between 0 and 10
|
|
821
1029
|
randomBetween(25, 100); // Will generate a random between 25 and 100
|
|
822
1030
|
```
|
|
823
1031
|
|
|
824
|
-
|
|
1032
|
+
### number/randomIntBetween(min:Number=0,max:Number=10)
|
|
825
1033
|
Generate a random numeric value between a min and max range (max not inclusive)
|
|
826
1034
|
```typescript
|
|
1035
|
+
import randomIntBetween from '@valkyriestudios/utils/number/randomIntBetween';
|
|
827
1036
|
randomIntBetween(); // Will generate a random between 0 and 10 (10 not inclusive)
|
|
828
1037
|
randomIntBetween(25, 100); // Will generate a random between 25 and 100 (100 not inclusive)
|
|
829
1038
|
```
|
|
830
1039
|
|
|
831
|
-
### object
|
|
832
|
-
- **isObject(val:any)**
|
|
1040
|
+
### object/is(val:unknown)
|
|
833
1041
|
Check if a variable is of type Object
|
|
834
1042
|
```typescript
|
|
1043
|
+
import isObject from '@valkyriestudios/utils/object/is';
|
|
835
1044
|
isObject({a: 1}); // TRUE
|
|
836
1045
|
isObject(1); // FALSE
|
|
837
1046
|
```
|
|
838
1047
|
|
|
839
|
-
|
|
1048
|
+
### object/isNotEmpty(val:unknown)
|
|
840
1049
|
Check if a variable a non-empty object
|
|
841
1050
|
```typescript
|
|
1051
|
+
import isNotEmptyObject from '@valkyriestudios/utils/object/isNotEmpty';
|
|
842
1052
|
isNotEmptyObject({a:1}); // TRUE
|
|
843
1053
|
isNotEmptyObject({}); // FALSE
|
|
844
1054
|
isNotEmptyObject('Hi'); // FALSE
|
|
845
1055
|
```
|
|
846
1056
|
|
|
847
|
-
|
|
1057
|
+
### object/pick(obj:Object={}, keys:Array[string]=[])
|
|
848
1058
|
Copies the keys passed in the 'keys' array from the passed object to a new object and returns that object.**
|
|
849
1059
|
<small>If a key wasn't found it will be set as undefined</small>
|
|
850
1060
|
```typescript
|
|
1061
|
+
import pick from '@valkyriestudios/utils/object/pick';
|
|
851
1062
|
pick({a: 1, b: 2, c: 3}, ['a','b']); // {a: 1, b: 2}
|
|
852
1063
|
```
|
|
853
1064
|
|
|
854
|
-
|
|
1065
|
+
### object/merge(target:Object={},obj:Object|Object[]={}, opts?:{union?:boolean})
|
|
855
1066
|
Merges two objects together, with the preference over the second object.
|
|
856
1067
|
```typescript
|
|
1068
|
+
import merge from '@valkyriestudios/utils/object/merge';
|
|
857
1069
|
merge({a: 1, b: false}, {a: 900, c: 50}, {union: true}); // {a: 900, b: false, c: 50}
|
|
858
1070
|
merge({a: 1, b: false}, {a: 900, c: 50}, {union: false}); // {a: 900, b: false}
|
|
859
1071
|
merge({a: 1, c: {bar: 'foo'}}, [{b: 2}, {c: {foo: 'bar'}}], {union: true}); // {a: 1, b: 2, c: {bar: 'foo', foo: 'bar'}}
|
|
@@ -862,68 +1074,73 @@ merge({a: 1, c: {bar: 'foo'}}, [{b: 2}, {c: {foo: 'bar'}}], {union: true}); // {
|
|
|
862
1074
|
Take Note: The default behavior is to not have union, this means that ONLY the keys in the target object
|
|
863
1075
|
are going to be available in the response of this function.
|
|
864
1076
|
|
|
865
|
-
|
|
1077
|
+
### object/define(props:Object, obj:Object={})
|
|
866
1078
|
Creates an object with the passed accessors set on it
|
|
867
1079
|
```typescript
|
|
1080
|
+
import define from '@valkyriestudios/utils/object/define';
|
|
868
1081
|
define(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
1082
|
+
{
|
|
1083
|
+
a: {
|
|
1084
|
+
enumerable: false,
|
|
1085
|
+
value : function () { ... }
|
|
1086
|
+
}
|
|
1087
|
+
},
|
|
1088
|
+
{ b: 2 }
|
|
876
1089
|
);
|
|
877
1090
|
// { a : () => ..., b: 2 }
|
|
878
1091
|
```
|
|
879
1092
|
|
|
880
1093
|
```typescript
|
|
1094
|
+
import define from '@valkyriestudios/utils/object/define';
|
|
881
1095
|
define({
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
1096
|
+
a : {
|
|
1097
|
+
enumerable: false,
|
|
1098
|
+
value : function () { ... }
|
|
1099
|
+
}
|
|
886
1100
|
}); // { a : () => ... }
|
|
887
1101
|
```
|
|
888
1102
|
|
|
889
|
-
### regexp
|
|
890
|
-
- **isRegExp(val:any)**
|
|
1103
|
+
### regexp/is(val:unknown)
|
|
891
1104
|
Check if a variable is an instance of RegExp
|
|
892
1105
|
```typescript
|
|
1106
|
+
import isRegExp from '@valkyriestudios/utils/regexp/is';
|
|
893
1107
|
isRegExp('foo'); // FALSE
|
|
894
1108
|
isRegExp(new RegExp('ab+c', 'i')); // TRUE
|
|
895
1109
|
isRegExp(new RegExp(/ab+c/, 'i')); // TRUE
|
|
896
1110
|
isRegExp(/ab+c/i); // FALSE
|
|
897
1111
|
```
|
|
898
1112
|
|
|
899
|
-
|
|
1113
|
+
### regexp/sanitize(val:string)
|
|
900
1114
|
Escapes special characters in a string and returns a sanitized version safe for usage in RegExp instances
|
|
901
1115
|
```typescript
|
|
902
|
-
|
|
1116
|
+
import sanitize from '@valkyriestudios/utils/regexp/sanitize';
|
|
1117
|
+
sanitize('contact@valkyriestudios.be'); // contact@valkyriestudios\\.be
|
|
903
1118
|
```
|
|
904
1119
|
|
|
905
|
-
### string
|
|
906
|
-
- **isString(val:any)**
|
|
1120
|
+
### string/is(val:unknown)
|
|
907
1121
|
Check if a variable is a string
|
|
908
1122
|
```typescript
|
|
1123
|
+
import isString from '@valkyriestudios/utils/string/is';
|
|
909
1124
|
isString('foo'); // TRUE
|
|
910
1125
|
isString(4); // FALSE
|
|
911
1126
|
```
|
|
912
1127
|
|
|
913
|
-
|
|
1128
|
+
### string/isBetween(val:string, min:number, max:number, trimmed:boolean=true)
|
|
914
1129
|
Check if a variable is between a range of numbers
|
|
915
1130
|
```typescript
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1131
|
+
import isBetween from '@valkyriestudios/utils/string/isBetween';
|
|
1132
|
+
isBetween('Peter', 4, 10); // TRUE
|
|
1133
|
+
isBetween('Jeff', 4, 10); // TRUE
|
|
1134
|
+
isBetween('Moe', 4, 10); // FALSE
|
|
1135
|
+
isBetween('Hello', 6, 1); // FALSE
|
|
1136
|
+
isBetween(' Joe', 1, 3); // TRUE
|
|
1137
|
+
isBetween(' Joe', 1, 3, false); // FALSE
|
|
922
1138
|
```
|
|
923
1139
|
|
|
924
|
-
|
|
1140
|
+
### string/isNotEmpty(val:unknown, trimmed:boolean=true)
|
|
925
1141
|
Check if a variable a non-empty string
|
|
926
1142
|
```typescript
|
|
1143
|
+
import isNotEmptyString from '@valkyriestudios/utils/string/isNotEmpty';
|
|
927
1144
|
isNotEmptyString({a:1}); // FALSE
|
|
928
1145
|
isNotEmptyString(''); // FALSE
|
|
929
1146
|
isNotEmptyString(' '); // FALSE
|
|
@@ -931,9 +1148,10 @@ isNotEmptyString(' ', false); // TRUE
|
|
|
931
1148
|
isNotEmptyString('Hi'); // TRUE
|
|
932
1149
|
```
|
|
933
1150
|
|
|
934
|
-
|
|
1151
|
+
### string/shorten(val:string, length:integer, postfix:string=..., truncate_words=true)
|
|
935
1152
|
Shorten a string and add a postfix if string went over length
|
|
936
1153
|
```typescript
|
|
1154
|
+
import shorten from '@valkyriestudios/utils/string/shorten';
|
|
937
1155
|
shorten('To the moon and beyond', 11, '..'); // 'To the moon..'
|
|
938
1156
|
shorten('Hi', 250); // 'Hi'
|
|
939
1157
|
shorten('To the moon and beyond'); // 'To the moon...'
|
|
@@ -943,21 +1161,26 @@ shorten('To the moon and beyond', 11, ' '); // 'To the moon '
|
|
|
943
1161
|
shorten('To the moon and beyond', 11, '...', false);
|
|
944
1162
|
```
|
|
945
1163
|
|
|
946
|
-
|
|
1164
|
+
### string/humanizeBytes(val:number|string)
|
|
947
1165
|
Humanize an amount of bytes
|
|
1166
|
+
|
|
1167
|
+
allows passing options to control the output, following options are possible:
|
|
948
1168
|
-- option:delim (default:','): Override the delimiter used, eg: `20000 -> 20,000`
|
|
949
1169
|
-- option:separator (default:'.'): Override the separator used for floats, eg: '20.034' -> '20,034'
|
|
950
1170
|
-- option:precision (default:2): Override decimal precision for floats: eg: '20.0344233' with precision 2 -> '20.03'
|
|
951
1171
|
-- option:units (default:[' byes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB']): Override units used, eg: `4893290423489 with units [' Jedi', ' Darth', ' Vader', ' Force'] and precision of 0` -> `'4,893 Force'`
|
|
952
1172
|
```typescript
|
|
1173
|
+
import humanizeBytes from '@valkyriestudios/utils/string/humanizeBytes';
|
|
953
1174
|
humanizeBytes(1504230); // '1.4 MB'
|
|
954
1175
|
humanizeBytes(23); // '23 bytes'
|
|
955
1176
|
humanizeBytes(-374237489237); // '-348.5 GB'
|
|
956
1177
|
humanizeBytes('-1504230'); // '-1.4 MB'
|
|
957
1178
|
```
|
|
958
1179
|
|
|
959
|
-
|
|
1180
|
+
### string/humanizeNumber(val:number|string, options:Object)
|
|
960
1181
|
Humanize a number
|
|
1182
|
+
|
|
1183
|
+
allows passing options to control the output, following options are possible:
|
|
961
1184
|
-- option:delim (default:','): Override the delimiter used, eg: `20000 -> 20,000`
|
|
962
1185
|
-- option:separator (default:'.'): Override the separator used for floats, eg: '20.034' -> '20,034'
|
|
963
1186
|
-- option:precision (default:2): Override decimal precision for floats: eg: '20.0344233' with precision 2 -> '20.03'
|
|
@@ -966,6 +1189,7 @@ Humanize a number
|
|
|
966
1189
|
-- option:divider (default:1000): Override default divider used for units (used internally for humanizeBytes with 1024 as divider)
|
|
967
1190
|
|
|
968
1191
|
```typescript
|
|
1192
|
+
import humanizeBytes from '@valkyriestudios/utils/string/humanizeBytes';
|
|
969
1193
|
humanizeNumber(4327963279469432); // '4.33q'
|
|
970
1194
|
humanizeNumber(1504230); // '1.5m'
|
|
971
1195
|
humanizeNumber(-432443); // '-432.44k'
|
|
@@ -973,7 +1197,6 @@ humanizeNumber('-1500'); // '-1.5k'
|
|
|
973
1197
|
humanizeNumber(47328748923747923479); // '47,328.75q'
|
|
974
1198
|
```
|
|
975
1199
|
|
|
976
|
-
allows passing options to control the output, following options are possible:
|
|
977
|
-
|
|
978
1200
|
## Contributors
|
|
979
1201
|
- [Peter Vermeulen](https://www.linkedin.com/in/petervermeulen1/)
|
|
1202
|
+
- [Xander Berkein](https://github.com/xanderberkein)
|