deverything 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/dist/index.d.ts +49 -12
- package/dist/index.global.js +169 -163
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +169 -163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -81,10 +81,11 @@ Contributions always welcome!
|
|
|
81
81
|
- `arrayDiff()` get the difference of two arrays
|
|
82
82
|
- `arrayIntersection()` get the intersection of two arrays
|
|
83
83
|
- `capitalize()` word => Word
|
|
84
|
-
- `cleanSpaces()` trims and turns double spaces into single space
|
|
85
84
|
- `clamp()` clamp number in a range
|
|
85
|
+
- `cleanSpaces()` trims and turns double spaces into single space
|
|
86
86
|
- `enumKeys()` enum FRUIT { APPLE, PEAR } => ["APPLE", "PEAR"]
|
|
87
87
|
- `enumValues()` enum FRUIT { APPLE = 1, PEAR = 3 } => [1, 3]
|
|
88
|
+
- `filterAlphanumeric()` remove non-alphanumeric characters
|
|
88
89
|
- `first()` get the first element of an array
|
|
89
90
|
- `firstKey()` get the first key of an object
|
|
90
91
|
- `firstValue()` get the first value of an object
|
|
@@ -101,7 +102,6 @@ Contributions always welcome!
|
|
|
101
102
|
- `normalizeNumber()` normalizes between 0 and 1
|
|
102
103
|
- `objectDiff()` get the difference between two objects
|
|
103
104
|
- ⭐ `parseDate()` pass anything Date-Like, and get a JS Date back
|
|
104
|
-
- `pretty()` stringify anything, without breaking on circular dependencies
|
|
105
105
|
- `promiseWithTimeout()` takes a promise, a timeoutMs, and an option error as arguments. Returns a new Promise that either resolves with the value of the input promise or rejects with the provided error or a default error message if the input promise does not resolve or reject within the specified timeoutMs.
|
|
106
106
|
- `scrambleText()` replace alpha chars with random chars
|
|
107
107
|
- `seriesAll()` executes promises in series, and returns all results
|
|
@@ -109,6 +109,7 @@ Contributions always welcome!
|
|
|
109
109
|
- `setUrlSearchParams()` set URL search params
|
|
110
110
|
- `shuffle()` shuffles elements in an array
|
|
111
111
|
- `sleep()` promise-based sleep
|
|
112
|
+
- `stringify()` stringify anything, without breaking on circular dependencies
|
|
112
113
|
- `toggleArrayValue()` remove/add value in array
|
|
113
114
|
- `truncate()` truncate text, does not break emojis
|
|
114
115
|
- `uniqueValues()` gets unique values in an array
|
|
@@ -116,6 +117,7 @@ Contributions always welcome!
|
|
|
116
117
|
### Formatters
|
|
117
118
|
|
|
118
119
|
- `formatCamelCase()`
|
|
120
|
+
- `formatCookies()` { cookie1: "1", cookie2: "2" } => "cookie1=1; cookie2=2"
|
|
119
121
|
- `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
|
|
120
122
|
- `formatPercentage()` 0.11 => "11%"
|
|
121
123
|
- `formatProgress()` => "[2/10]"
|
|
@@ -128,6 +130,7 @@ These functions are optimized for low entropy random data generation useful for
|
|
|
128
130
|
|
|
129
131
|
- `randomAddress()`
|
|
130
132
|
- `randomAlphaNumericCode()`
|
|
133
|
+
- `randomArray()`
|
|
131
134
|
- ⭐ `randomArrayItem()` now supporting non-uniform distribution
|
|
132
135
|
- `randomBankAccount()`
|
|
133
136
|
- `randomBool()`
|
|
@@ -154,31 +157,28 @@ These functions are optimized for low entropy random data generation useful for
|
|
|
154
157
|
- `randomHtmlColorName()`
|
|
155
158
|
- `randomIBAN()`
|
|
156
159
|
- `randomInt()`
|
|
157
|
-
- `
|
|
158
|
-
- `randomNegativeInt()` < 0
|
|
159
|
-
- `randomMaxSafeInt()` Range of very BIG integers, which are still safe to use tho
|
|
160
|
+
- `randomBigInt()`
|
|
160
161
|
- `randomMaxInt()` Range within the Maximum integer supported by js
|
|
162
|
+
- `randomMaxSafeInt()` Range of very BIG integers, which are still safe to use tho
|
|
163
|
+
- `randomNegativeInt()` < 0
|
|
164
|
+
- `randomPositiveInt()` > 0
|
|
161
165
|
- `randomIP()`
|
|
162
166
|
- `randomName()`
|
|
163
167
|
- `randomFirstName()`
|
|
164
168
|
- `randomLastName()`
|
|
165
169
|
- `randomFullName()`
|
|
166
170
|
- `randomNumericCode()`
|
|
171
|
+
- `randomObject()`
|
|
167
172
|
- `randomParagraph()`
|
|
168
173
|
- `randomPassword()`
|
|
169
174
|
- `randomPath()` /path/to/something
|
|
170
175
|
- `randomPhoneNumber()`
|
|
171
176
|
- `randomString()`
|
|
177
|
+
- `randomSymbol()`
|
|
172
178
|
- `randomUUID()` lightweight uuid generation, passing UUID validation
|
|
173
179
|
- `randomValue()`
|
|
174
180
|
- `randomWord()`
|
|
175
181
|
|
|
176
|
-
### Checks
|
|
177
|
-
|
|
178
|
-
Checks are functions that throw an error, if the validation fails
|
|
179
|
-
|
|
180
|
-
- ⭐ `checkEnvVars()` Make sure env vars are set per-environment
|
|
181
|
-
|
|
182
182
|
### TypeScript Helpers & Generics
|
|
183
183
|
|
|
184
184
|
- `Coords`
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,18 @@ type Coords = {
|
|
|
5
5
|
|
|
6
6
|
type DateLike = Date | string | number;
|
|
7
7
|
type Datey = Date | string;
|
|
8
|
+
/**
|
|
9
|
+
* @example "2021-01-01T00:00:00.000Z"
|
|
10
|
+
*/
|
|
8
11
|
type ISODate = string;
|
|
12
|
+
/**
|
|
13
|
+
* @example "2021-01-01"
|
|
14
|
+
*/
|
|
15
|
+
type ISODay = string;
|
|
16
|
+
/**
|
|
17
|
+
* @example "America/New_York"
|
|
18
|
+
*/
|
|
19
|
+
type Timezone = string;
|
|
9
20
|
type DateRange = {
|
|
10
21
|
startDate: DateLike;
|
|
11
22
|
endDate: DateLike;
|
|
@@ -80,6 +91,13 @@ declare const startOfTomorrow: () => Date;
|
|
|
80
91
|
|
|
81
92
|
declare const formatCamelCase: (str: string) => string;
|
|
82
93
|
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @example formatCookies({}) => ""
|
|
97
|
+
* @example formatCookies({ session: "123", _ga: 123 }) => "session=123; _ga=123"
|
|
98
|
+
*/
|
|
99
|
+
declare const formatCookies: (object: PlainObject) => string;
|
|
100
|
+
|
|
83
101
|
/**
|
|
84
102
|
*
|
|
85
103
|
* @example formatNumber(1000, { compact: true }) // 1K
|
|
@@ -154,12 +172,20 @@ declare const cyclicalItem: <T>(array: T[], index: number) => T;
|
|
|
154
172
|
/**
|
|
155
173
|
* Print or log helper that does not break on circular references, and expands nested objects.
|
|
156
174
|
*/
|
|
157
|
-
declare const dir: (arg: any,
|
|
175
|
+
declare const dir: (arg: any, { maxDepth }?: {
|
|
176
|
+
maxDepth?: number | undefined;
|
|
177
|
+
}) => void;
|
|
158
178
|
|
|
159
179
|
declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
|
|
160
180
|
|
|
161
181
|
declare const enumValues: <T extends object>(enumObject: T) => ObjectValues<T>;
|
|
162
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @returns a string with only alphanumeric characters
|
|
185
|
+
* @example filterAlphanumeric("!abc()") // returns "abc"
|
|
186
|
+
*/
|
|
187
|
+
declare const filterAlphanumeric: (string: string) => string;
|
|
188
|
+
|
|
163
189
|
declare const first: <T>(arr?: T[] | undefined) => T | undefined;
|
|
164
190
|
|
|
165
191
|
declare const firstKey: <T extends PlainObject<any>>(arg: T) => keyof T;
|
|
@@ -224,8 +250,6 @@ declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectK
|
|
|
224
250
|
|
|
225
251
|
declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
|
|
226
252
|
|
|
227
|
-
declare const pretty: (arg?: any) => string;
|
|
228
|
-
|
|
229
253
|
declare const promiseWithTimeout: <T>(promise: () => Promise<T>, timeoutMs: number, error?: Error) => Promise<T>;
|
|
230
254
|
|
|
231
255
|
declare const scrambleText: (str: string) => string;
|
|
@@ -244,12 +268,13 @@ declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
|
|
|
244
268
|
* @description Run a series of (async) functions in order and return the results
|
|
245
269
|
* @example
|
|
246
270
|
* const results = await seriesAll([
|
|
247
|
-
*
|
|
248
|
-
*
|
|
271
|
+
* Promise.resolve(1),
|
|
272
|
+
* sleep(100).then(() => 2),
|
|
249
273
|
* () => Promise.resolve(3),
|
|
250
|
-
*
|
|
274
|
+
* async () => 4,
|
|
275
|
+
* ]); => [1, 2, 3, 4]
|
|
251
276
|
*/
|
|
252
|
-
declare const seriesAll: <T>(series:
|
|
277
|
+
declare const seriesAll: <T>(series: (Promise<T> | (() => Promise<T>))[]) => Promise<T[]>;
|
|
253
278
|
|
|
254
279
|
/**
|
|
255
280
|
* Sets a value in an object using a dot-separated path.
|
|
@@ -266,6 +291,8 @@ declare const shuffle: <T>(array: T[]) => T[];
|
|
|
266
291
|
|
|
267
292
|
declare const sleep: (timeMs: number) => Promise<void>;
|
|
268
293
|
|
|
294
|
+
declare const stringify: (arg?: any) => string;
|
|
295
|
+
|
|
269
296
|
declare const toggleArrayValue: <T>(array: T[], value: T) => T[];
|
|
270
297
|
/**
|
|
271
298
|
* @deprecated Use toggleArrayValue instead
|
|
@@ -354,6 +381,8 @@ declare const randomAlphaNumericCode: ({ length, }?: {
|
|
|
354
381
|
length?: number | undefined;
|
|
355
382
|
}) => string;
|
|
356
383
|
|
|
384
|
+
declare const randomArray: () => (string | number | boolean | symbol | Date | BigInt | null | undefined)[];
|
|
385
|
+
|
|
357
386
|
declare const randomArrayItem: <T>(array: T[], { weights }?: {
|
|
358
387
|
weights?: number[] | undefined;
|
|
359
388
|
}) => T;
|
|
@@ -442,6 +471,7 @@ declare const randomInt: ({ min, max, }?: {
|
|
|
442
471
|
min?: number | undefined;
|
|
443
472
|
max?: number | undefined;
|
|
444
473
|
}) => number;
|
|
474
|
+
declare const randomBigInt: () => BigInt;
|
|
445
475
|
declare const randomPositiveInt: ({ min, max, }?: {
|
|
446
476
|
min?: number | undefined;
|
|
447
477
|
max?: number | undefined;
|
|
@@ -475,10 +505,10 @@ declare const randomNumericCode: ({ length }?: {
|
|
|
475
505
|
length?: number | undefined;
|
|
476
506
|
}) => string;
|
|
477
507
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
508
|
+
declare const randomObject: ({ maxDepth, circular, }?: {
|
|
509
|
+
maxDepth?: number | undefined;
|
|
510
|
+
circular?: boolean | undefined;
|
|
511
|
+
}) => PlainObject<any>;
|
|
482
512
|
|
|
483
513
|
/**
|
|
484
514
|
* Generates a random paragraph of text.
|
|
@@ -507,6 +537,8 @@ declare const randomString: ({ length, }?: {
|
|
|
507
537
|
length?: number | undefined;
|
|
508
538
|
}) => string;
|
|
509
539
|
|
|
540
|
+
declare const randomSymbol: () => symbol;
|
|
541
|
+
|
|
510
542
|
/**
|
|
511
543
|
* This is a light-weight version of the `generateUuid` function
|
|
512
544
|
* To be used only for test purposed and NOT for production
|
|
@@ -516,6 +548,8 @@ declare const randomString: ({ length, }?: {
|
|
|
516
548
|
*/
|
|
517
549
|
declare const randomUUID: () => string;
|
|
518
550
|
|
|
551
|
+
declare const randomValue: () => string | number | boolean | symbol | Date | BigInt | null | undefined;
|
|
552
|
+
|
|
519
553
|
declare const randomWord: () => string;
|
|
520
554
|
declare const randomNoun: () => string;
|
|
521
555
|
declare const randomVerb: () => string;
|
|
@@ -543,6 +577,9 @@ declare const isEmptyObject: (arg: PlainObject) => boolean;
|
|
|
543
577
|
|
|
544
578
|
declare const isFile: (arg?: any) => arg is File;
|
|
545
579
|
|
|
580
|
+
/**
|
|
581
|
+
* @returns true if the argument can be called like a function -> fn() or await fn()
|
|
582
|
+
*/
|
|
546
583
|
declare const isFunction: (arg: any) => arg is Function;
|
|
547
584
|
|
|
548
585
|
declare const isFutureDate: (arg: DateLike) => boolean;
|
|
@@ -609,4 +646,4 @@ declare const isUUID: (arg: string) => boolean;
|
|
|
609
646
|
|
|
610
647
|
declare const isValue: (arg?: Maybe<any>) => boolean;
|
|
611
648
|
|
|
612
|
-
export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, ISODate, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, TrueMap, WithDatey, array, arrayDiff, arrayIntersection, average, capitalize, chunkArray, chunkedAll, chunkedAsync, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, first, firstKey, firstValue, formatCamelCase, formatNumber, formatPercentage, formatProgress, formatTrpcInputQueryString, getCookieByName, getEnumerableOwnPropertySymbols, getKeys, getUrlSearchParam, getUrlSearchParams, incrementalId, isArray, isArrayIncluded, isBetween, isBoolean, isBrowser, isBuffer, isClient, isEmail, isEmpty, isEmptyArray, isEmptyObject, isEmptyString, isEven, isFile, isFunction, isFutureDate, isInt, isJsDate, isKey, isLastIndex, isNegative, isNegativeInt, isNotEmptyString, isNumber, isNumeric, isNumericId, isObject, isOdd, isOutside, isOver18, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isStrictlyBetween, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, max, merge, mergeArrays, min, moveToFirst, moveToLast, multiply, normaliseArray, normaliseNumber, normalizeNumber, objectDiff, omit, parseDate, percentageChange, pickObjectKeys, pickObjectValues,
|
|
649
|
+
export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, ISODate, ISODay, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, Timezone, TrueMap, WithDatey, array, arrayDiff, arrayIntersection, average, capitalize, chunkArray, chunkedAll, chunkedAsync, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, filterAlphanumeric, first, firstKey, firstValue, formatCamelCase, formatCookies, formatNumber, formatPercentage, formatProgress, formatTrpcInputQueryString, getCookieByName, getEnumerableOwnPropertySymbols, getKeys, getUrlSearchParam, getUrlSearchParams, incrementalId, isArray, isArrayIncluded, isBetween, isBoolean, isBrowser, isBuffer, isClient, isEmail, isEmpty, isEmptyArray, isEmptyObject, isEmptyString, isEven, isFile, isFunction, isFutureDate, isInt, isJsDate, isKey, isLastIndex, isNegative, isNegativeInt, isNotEmptyString, isNumber, isNumeric, isNumericId, isObject, isOdd, isOutside, isOver18, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isStrictlyBetween, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, max, merge, mergeArrays, min, moveToFirst, moveToLast, multiply, normaliseArray, normaliseNumber, normalizeNumber, objectDiff, omit, parseDate, percentageChange, pickObjectKeys, pickObjectValues, prismaDateRange, promiseWithTimeout, randomAddress, randomAlphaNumericCode, randomArray, randomArrayItem, randomBankAccount, randomBigInt, randomBool, randomChar, randomCompany, randomCoords, randomDate, randomDateRange, randomEmail, randomEmoji, randomEnumKey, randomEnumValue, randomFile, randomFirstName, randomFloat, randomFormattedPercentage, randomFullName, randomFutureDate, randomHandle, randomHexColor, randomHexValue, randomHtmlColorName, randomIBAN, randomIP, randomInt, randomLastName, randomLat, randomLng, randomMaxDate, randomMaxInt, randomMaxSafeInt, randomName, randomNegativeInt, randomNoun, randomNumericCode, randomObject, randomParagraph, randomPassword, randomPastDate, randomPath, randomPhoneNumber, randomPositiveInt, randomString, randomSymbol, randomUUID, randomValue, randomVerb, randomWord, scrambleText, serialize, seriesAll, setObjectPath, setUrlSearchParams, shuffle, sleep, startOfDay, startOfNextMonth, startOfNextWeek, startOfThisWeek, startOfToday, startOfTomorrow, stringToCSSUnicode, stringToUnicode, stringify, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
|