deverything 0.42.2 → 0.44.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 +12 -6
- package/dist/index.d.ts +79 -41
- package/dist/index.global.js +135 -127
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +135 -127
- 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
|
@@ -18,12 +18,14 @@ Contributions always welcome!
|
|
|
18
18
|
- `isArray()`
|
|
19
19
|
- `isBoolean()`
|
|
20
20
|
- `isBrowser()` to detect if you are on the browser
|
|
21
|
+
- `isBuffer()`
|
|
21
22
|
- `isClient()` to detect if you are ont the browser/client
|
|
22
23
|
- `isEmail()` this is a relaxed check, use your own validation if you need to be strict
|
|
23
24
|
- ⭐ `isEmpty()` to check for empty object, empty array, empty string, null or undefined
|
|
24
25
|
- `isEmptyString()` trims the string and checks if something is left
|
|
25
26
|
- `isEmptyArray()`
|
|
26
27
|
- `isEmptyObject()`
|
|
28
|
+
- `isFile()`
|
|
27
29
|
- `isFunction()`
|
|
28
30
|
- `isJsDate()` if it's a **valid** javascript's Date
|
|
29
31
|
- `isFutureDate()`
|
|
@@ -98,6 +100,7 @@ Contributions always welcome!
|
|
|
98
100
|
|
|
99
101
|
### Formatters
|
|
100
102
|
|
|
103
|
+
- `formatCamelCase()`
|
|
101
104
|
- `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
|
|
102
105
|
- `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
|
|
103
106
|
- `stringToCSSUnicode()` "hello" => "\000068\000065\00006c\00006c\00006f" use this for CSS
|
|
@@ -127,6 +130,7 @@ These functions are optimized for low entropy random data generation useful for
|
|
|
127
130
|
- `randomEnumValue()` enum FRUIT { APPLE = 1, PEAR = 3 } => 3
|
|
128
131
|
- `randomFile()`
|
|
129
132
|
- `randomFloat()`
|
|
133
|
+
- `randomObject()`
|
|
130
134
|
- `randomHandle()` useful for social identifiers, or slugs
|
|
131
135
|
- `randomHexColor()`
|
|
132
136
|
- `randomHexValue()`
|
|
@@ -149,6 +153,7 @@ These functions are optimized for low entropy random data generation useful for
|
|
|
149
153
|
- `randomPhoneNumber()`
|
|
150
154
|
- `randomString()`
|
|
151
155
|
- `randomUUID()` lightweight uuid generation, passing UUID validation
|
|
156
|
+
- `randomValue()`
|
|
152
157
|
- `randomWord()`
|
|
153
158
|
|
|
154
159
|
### Checks
|
|
@@ -167,20 +172,21 @@ Checks are functions that throw an error, if the validation fails
|
|
|
167
172
|
- `MaybePromiseOrValue<>`
|
|
168
173
|
- `MaybePromiseOrValueArray<>`
|
|
169
174
|
- `NonUndefined`
|
|
175
|
+
- `Key`
|
|
170
176
|
- `ObjectKey<>`
|
|
171
177
|
- `ObjectKeys<>`
|
|
172
178
|
- `ObjectValue<>`
|
|
173
179
|
- `ObjectValues<>`
|
|
180
|
+
- `ObjectEntry<>`
|
|
174
181
|
- `ObjectEntries<>`
|
|
175
182
|
- ⭐ `PlainObject` use this instead of `Record<,>` or `extends object`, also makes sure it's not an array
|
|
176
183
|
- `Point`
|
|
177
|
-
- `PrismaSelect<>`
|
|
178
184
|
- `HashMap<>`
|
|
179
|
-
- `
|
|
180
|
-
- `NumberMap`
|
|
181
|
-
- `StringMap`
|
|
182
|
-
- `
|
|
183
|
-
- `
|
|
185
|
+
- `BoolMap`
|
|
186
|
+
- `NumberMap`
|
|
187
|
+
- `StringMap`
|
|
188
|
+
- `TrueMap`
|
|
189
|
+
- `VoidFn`
|
|
184
190
|
|
|
185
191
|
## Development
|
|
186
192
|
|
package/dist/index.d.ts
CHANGED
|
@@ -38,6 +38,25 @@ type Config = {
|
|
|
38
38
|
*/
|
|
39
39
|
declare const checkEnvVars: (envVarsMap: Record<string, SimpleValidationRule | EnvValidation | WithEnvValidation>, config?: Config) => void;
|
|
40
40
|
|
|
41
|
+
declare const formatCamelCase: (str: string) => string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @example formatNumber(1000, { compact: true }) // 1K
|
|
46
|
+
* @example formatNumber(1111, { maxDigits: 2 }) // 1,100
|
|
47
|
+
* @example formatNumber(111111.123123123) // 111,111.123
|
|
48
|
+
* @example formatNumber(0.12345, { percentage: true, maxDigits: 2 }) // '12.35%' (rounding)
|
|
49
|
+
*/
|
|
50
|
+
declare const formatNumber: (value: number, { compact, maxDigits, percentage, }?: {
|
|
51
|
+
compact?: boolean | undefined;
|
|
52
|
+
maxDigits?: number | undefined;
|
|
53
|
+
percentage?: boolean | undefined;
|
|
54
|
+
}) => string;
|
|
55
|
+
|
|
56
|
+
declare const stringToCSSUnicode: (text: string) => string;
|
|
57
|
+
|
|
58
|
+
declare const stringToUnicode: (text: string) => string;
|
|
59
|
+
|
|
41
60
|
declare const array: <U extends (...args: any) => any>(length: number, mapFn?: U) => ReturnType<U>[];
|
|
42
61
|
|
|
43
62
|
declare const arrayDiff: (arr1: any[], arr2: any[]) => any[];
|
|
@@ -54,18 +73,25 @@ declare const clamp: ({ number, min, max, }: {
|
|
|
54
73
|
|
|
55
74
|
declare const cleanSpaces: (str: string) => string;
|
|
56
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @returns element from array at index, if index is greater than array length, it will loop back to the start of the array
|
|
78
|
+
*/
|
|
79
|
+
declare const cyclicalItem: <T>(array: T[], index: number) => T;
|
|
80
|
+
|
|
57
81
|
/**
|
|
58
82
|
* Print or log helper that does not break on circular references, and expands nested objects.
|
|
59
83
|
*/
|
|
60
84
|
declare const dir: (arg: any, depth?: number) => void;
|
|
61
85
|
|
|
86
|
+
type Key = string | number | symbol;
|
|
62
87
|
type ObjectKey<T> = keyof T;
|
|
63
88
|
type ObjectKeys<T> = ObjectKey<T>[];
|
|
64
89
|
type ObjectValue<T> = T[keyof T];
|
|
65
90
|
type ObjectValues<T> = ObjectValue<T>[];
|
|
66
|
-
type
|
|
91
|
+
type ObjectEntry<T> = {
|
|
67
92
|
[K in keyof T]: [K, T[K]];
|
|
68
|
-
}[keyof T]
|
|
93
|
+
}[keyof T];
|
|
94
|
+
type ObjectEntries<T> = ObjectEntry<T>[];
|
|
69
95
|
|
|
70
96
|
declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
|
|
71
97
|
|
|
@@ -90,12 +116,11 @@ type Dimensions = {
|
|
|
90
116
|
height: number;
|
|
91
117
|
};
|
|
92
118
|
|
|
93
|
-
type
|
|
94
|
-
type
|
|
95
|
-
type
|
|
96
|
-
type
|
|
97
|
-
type
|
|
98
|
-
type TrueMap = Record<HashMapKey, true>;
|
|
119
|
+
type HashMap<T> = Record<Key, T>;
|
|
120
|
+
type NumberMap = Record<Key, number>;
|
|
121
|
+
type StringMap = Record<Key, string>;
|
|
122
|
+
type BoolMap = Record<Key, boolean>;
|
|
123
|
+
type TrueMap = Record<Key, true>;
|
|
99
124
|
|
|
100
125
|
type Matrix<T> = T[][];
|
|
101
126
|
|
|
@@ -106,7 +131,11 @@ type MaybePromiseOrValueArray<T> = MaybePromiseOrValue<T>[];
|
|
|
106
131
|
|
|
107
132
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
108
133
|
|
|
109
|
-
|
|
134
|
+
/**
|
|
135
|
+
* A plain object is an object that is not an array, does not have a length property, and is not a function.
|
|
136
|
+
* Would have been nice to call it just Object, but that's already taken by the built-in type.
|
|
137
|
+
*/
|
|
138
|
+
type PlainObject<T = any> = Record<Key, T> & {
|
|
110
139
|
length?: never;
|
|
111
140
|
};
|
|
112
141
|
|
|
@@ -117,12 +146,16 @@ type Point = {
|
|
|
117
146
|
|
|
118
147
|
type PrismaSelect<T> = Record<keyof T, true>;
|
|
119
148
|
|
|
120
|
-
declare const firstKey: (arg:
|
|
149
|
+
declare const firstKey: <T extends PlainObject<any>>(arg: T) => keyof T;
|
|
121
150
|
|
|
122
|
-
declare const firstValue: (arg:
|
|
151
|
+
declare const firstValue: <T extends PlainObject<any>>(arg: T) => ObjectValue<T>;
|
|
123
152
|
|
|
124
|
-
|
|
125
|
-
|
|
153
|
+
/**
|
|
154
|
+
* TODO: rename to allKeys
|
|
155
|
+
* @deprecated use Object.keys instead unless you need to include symbols, but the function will be renamed to allKeys
|
|
156
|
+
*/
|
|
157
|
+
declare const getKeys: <T extends PlainObject<any>>(obj: T) => (string | symbol)[];
|
|
158
|
+
declare const getEnumerableOwnPropertySymbols: (obj: object) => symbol[];
|
|
126
159
|
|
|
127
160
|
declare const getUrlSearchParam: (urlString: Maybe<string>, param: string) => string | undefined;
|
|
128
161
|
|
|
@@ -130,7 +163,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
|
|
|
130
163
|
|
|
131
164
|
declare const incrementalId: () => number;
|
|
132
165
|
|
|
133
|
-
declare const keysLength: <T extends PlainObject
|
|
166
|
+
declare const keysLength: <T extends PlainObject<any>>(obj: T) => number;
|
|
134
167
|
|
|
135
168
|
declare const last: <T>(arr: T[]) => T;
|
|
136
169
|
|
|
@@ -140,7 +173,13 @@ declare const lastIndex: (array: any[]) => number;
|
|
|
140
173
|
* @description Simple merge function that merges two objects, arrays get overwritten, no options
|
|
141
174
|
*
|
|
142
175
|
*/
|
|
143
|
-
declare const merge: (target: PlainObject, source: PlainObject) => PlainObject
|
|
176
|
+
declare const merge: (target: PlainObject, source: PlainObject) => PlainObject<any>;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @description Merge two arrays, unique values, no options
|
|
180
|
+
* @example mergeArrays([1,2,3], [2,3,4]) => [1,2,3,4]
|
|
181
|
+
*/
|
|
182
|
+
declare const mergeArrays: (arrayA: any[], arrayB: any[]) => any[];
|
|
144
183
|
|
|
145
184
|
declare const moveToFirst: <T>(items: T[], condition: (item: T, i: number, items: T[]) => boolean) => T[];
|
|
146
185
|
|
|
@@ -152,15 +191,15 @@ declare const normalizeNumber: ({ value, max, min, }: {
|
|
|
152
191
|
min: number;
|
|
153
192
|
}) => number;
|
|
154
193
|
|
|
155
|
-
declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject
|
|
194
|
+
declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject<any>;
|
|
156
195
|
|
|
157
|
-
declare const omit: <T extends PlainObject
|
|
196
|
+
declare const omit: <T extends PlainObject<any>>(obj: T, keys: (keyof T)[]) => Partial<T>;
|
|
158
197
|
|
|
159
198
|
declare const parseDate: (arg?: Maybe<DateLike>) => Date | undefined;
|
|
160
199
|
|
|
161
|
-
declare const pickObjectKeys: <T extends PlainObject
|
|
200
|
+
declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
|
|
162
201
|
|
|
163
|
-
declare const pickObjectValues: <T extends PlainObject
|
|
202
|
+
declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
|
|
164
203
|
|
|
165
204
|
declare const pretty: (arg?: any) => string;
|
|
166
205
|
|
|
@@ -169,13 +208,13 @@ declare const promiseWithTimeout: <T>(promise: () => Promise<T>, timeoutMs: numb
|
|
|
169
208
|
declare const scrambleText: (str: string) => string;
|
|
170
209
|
|
|
171
210
|
/**
|
|
172
|
-
* Serialize
|
|
211
|
+
* Serialize shallow object to a deterministic string,
|
|
173
212
|
* for nested objects use [json-stable-stringify](https://www.npmjs.com/package/json-stable-stringify)
|
|
174
213
|
*
|
|
175
214
|
* @example
|
|
176
215
|
* serialize({ b: 1, a: 2 }) // '{"a":1,"b":2}'
|
|
177
216
|
*/
|
|
178
|
-
declare const serialize: <T extends PlainObject
|
|
217
|
+
declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
|
|
179
218
|
|
|
180
219
|
/**
|
|
181
220
|
*
|
|
@@ -223,8 +262,18 @@ declare const min: (values: number[]) => number;
|
|
|
223
262
|
|
|
224
263
|
declare const multiply: (numbers: number[]) => number;
|
|
225
264
|
|
|
265
|
+
declare const percentageChange: ({ previous, current, }: {
|
|
266
|
+
previous: number;
|
|
267
|
+
current: number;
|
|
268
|
+
}) => number;
|
|
269
|
+
|
|
226
270
|
declare const sum: (numbers: number[]) => number;
|
|
227
271
|
|
|
272
|
+
declare const prismaDateRange: ({ startDate, endDate }: DateRange) => {
|
|
273
|
+
gte: Date;
|
|
274
|
+
lt: Date;
|
|
275
|
+
};
|
|
276
|
+
|
|
228
277
|
type RandomAddress = {
|
|
229
278
|
city: string;
|
|
230
279
|
country: string;
|
|
@@ -415,6 +464,8 @@ declare const randomWord: () => string;
|
|
|
415
464
|
declare const randomNoun: () => string;
|
|
416
465
|
declare const randomVerb: () => string;
|
|
417
466
|
|
|
467
|
+
declare const formatTrpcInputQueryString: (input: PlainObject) => URLSearchParams;
|
|
468
|
+
|
|
418
469
|
declare const isArray: <T>(arg?: any) => arg is T[];
|
|
419
470
|
|
|
420
471
|
declare const isArrayIncluded: <T>(arr1: T[], arr2: T[]) => boolean;
|
|
@@ -423,6 +474,8 @@ declare const isBoolean: (arg: any) => arg is boolean;
|
|
|
423
474
|
|
|
424
475
|
declare const isBrowser: () => boolean;
|
|
425
476
|
|
|
477
|
+
declare const isBuffer: (val?: any) => boolean;
|
|
478
|
+
|
|
426
479
|
declare const isClient: () => boolean;
|
|
427
480
|
|
|
428
481
|
declare const isEmail: (arg: string) => boolean;
|
|
@@ -432,13 +485,15 @@ declare const isEmptyString: (arg: string) => boolean;
|
|
|
432
485
|
declare const isEmptyArray: (arg: any[]) => boolean;
|
|
433
486
|
declare const isEmptyObject: (arg: PlainObject) => boolean;
|
|
434
487
|
|
|
488
|
+
declare const isFile: (arg?: any) => arg is File;
|
|
489
|
+
|
|
435
490
|
declare const isFunction: (arg: any) => arg is Function;
|
|
436
491
|
|
|
437
492
|
declare const isFutureDate: (arg: DateLike) => boolean;
|
|
438
493
|
|
|
439
494
|
declare const isJsDate: (arg: Date) => arg is Date;
|
|
440
495
|
|
|
441
|
-
declare const isKey: <T extends object>(key:
|
|
496
|
+
declare const isKey: <T extends object>(key: Key, obj: T) => key is keyof T;
|
|
442
497
|
|
|
443
498
|
declare const isLastIndex: (index: number, array: any[]) => boolean;
|
|
444
499
|
|
|
@@ -463,7 +518,7 @@ declare const isNumeric: (arg: number | string) => boolean;
|
|
|
463
518
|
|
|
464
519
|
declare const isNumericId: (id: string) => boolean;
|
|
465
520
|
|
|
466
|
-
declare const isObject: <T>(arg?: any) => arg is
|
|
521
|
+
declare const isObject: <T>(arg?: any) => arg is PlainObject<T>;
|
|
467
522
|
|
|
468
523
|
declare const isPastDate: (arg: DateLike) => boolean;
|
|
469
524
|
|
|
@@ -491,21 +546,4 @@ declare const isUUID: (arg: string) => boolean;
|
|
|
491
546
|
|
|
492
547
|
declare const isValue: (arg?: Maybe<any>) => boolean;
|
|
493
548
|
|
|
494
|
-
|
|
495
|
-
*
|
|
496
|
-
* @example formatNumber(1000, { compact: true }) // 1K
|
|
497
|
-
* @example formatNumber(1111, { maxDigits: 2 }) // 1,100
|
|
498
|
-
* @example formatNumber(111111.123123123) // 111,111.123
|
|
499
|
-
* @example formatNumber(0.12345, { percentage: true, maxDigits: 2 }) // '12.35%' (rounding)
|
|
500
|
-
*/
|
|
501
|
-
declare const formatNumber: (value: number, { compact, maxDigits, percentage, }?: {
|
|
502
|
-
compact?: boolean | undefined;
|
|
503
|
-
maxDigits?: number | undefined;
|
|
504
|
-
percentage?: boolean | undefined;
|
|
505
|
-
}) => string;
|
|
506
|
-
|
|
507
|
-
declare const stringToUnicode: (text: string) => string;
|
|
508
|
-
|
|
509
|
-
declare const stringToCSSUnicode: (text: string) => string;
|
|
510
|
-
|
|
511
|
-
export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, HashMapKey, JS_MAX_DIGITS, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PlainObject, Point, PrismaSelect, StringMap, TrueMap, array, arrayDiff, arrayIntersection, average, capitalize, checkEnvVars, clamp, cleanSpaces, dir, enumKeys, enumValues, first, firstKey, firstValue, formatNumber, getEnumerableOwnPropertySymbols, getKeys, getUrlSearchParam, getUrlSearchParams, incrementalId, isArray, isArrayIncluded, isBoolean, isBrowser, isClient, isEmail, isEmpty, isEmptyArray, isEmptyObject, isEmptyString, isEven, isFunction, isFutureDate, isInt, isJsDate, isKey, isLastIndex, isNegative, isNegativeInt, isNotEmptyString, isNumber, isNumeric, isNumericId, isObject, isOdd, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, max, merge, min, moveToFirst, moveToLast, multiply, normalizeNumber, objectDiff, omit, parseDate, pickObjectKeys, pickObjectValues, pretty, promiseWithTimeout, randomAddress, randomAlphaNumericCode, randomArrayItem, randomBankAccount, 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, randomNumericId, randomParagraph, randomPassword, randomPastDate, randomPath, randomPercentage, randomPhoneNumber, randomPositiveInt, randomPositivePercentage, randomString, randomUUID, randomVerb, randomWord, scrambleText, serialize, seriesAll, setUrlSearchParams, shuffle, sleep, stringToCSSUnicode, stringToUnicode, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
|
|
549
|
+
export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PlainObject, Point, PrismaSelect, StringMap, TrueMap, array, arrayDiff, arrayIntersection, average, capitalize, checkEnvVars, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, first, firstKey, firstValue, formatCamelCase, formatNumber, formatTrpcInputQueryString, getEnumerableOwnPropertySymbols, getKeys, getUrlSearchParam, getUrlSearchParams, incrementalId, isArray, isArrayIncluded, 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, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, max, merge, mergeArrays, min, moveToFirst, moveToLast, multiply, normalizeNumber, objectDiff, omit, parseDate, percentageChange, pickObjectKeys, pickObjectValues, pretty, prismaDateRange, promiseWithTimeout, randomAddress, randomAlphaNumericCode, randomArrayItem, randomBankAccount, 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, randomNumericId, randomParagraph, randomPassword, randomPastDate, randomPath, randomPercentage, randomPhoneNumber, randomPositiveInt, randomPositivePercentage, randomString, randomUUID, randomVerb, randomWord, scrambleText, serialize, seriesAll, setUrlSearchParams, shuffle, sleep, stringToCSSUnicode, stringToUnicode, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
|