deverything 0.43.0 → 0.45.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 CHANGED
@@ -4,11 +4,11 @@
4
4
 
5
5
  The promise:
6
6
 
7
- - **✅ 1 package**: say goodbye to lodash, faker, this and that and the other package.
7
+ - **✅ 1 package**: say goodbye to lodash, faker, and the other package you don't recall the name of.
8
8
  - **⭕ 0 dependencies**: keep it simple and lightweight.
9
- - **🏆 Pick the best**: the code is minimal and uses the best current practices and is optimized for max performance.
9
+ - **🏆 Pick the best**: the code is minimal and uses the best practices for max performance.
10
10
  - **👪🏼 Typescript**: use it, support it and export it.
11
- - **🌊 Intuitive**: favour always the most intuitive API and common usage, _never_ throw errors unless asked.
11
+ - **🌊 Intuitive**: favour always the most intuitive API and common usage, _never_ throw error unless asked to.
12
12
  - **🙈 Semantic**: use simple function names that are easy to remember, no complicated options.
13
13
 
14
14
  Contributions always welcome!
@@ -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
- - `isClient()` to detect if you are ont the browser/client
21
+ - `isBuffer()`
22
+ - `isClient()` same as isBrowser
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()`
@@ -38,7 +40,7 @@ Contributions always welcome!
38
40
  - `isOdd()`
39
41
  - `isPositiveInt()`
40
42
  - `isNegativeInt()`
41
- - `isNumeric()`
43
+ - `isNumeric()` if string is representing a number
42
44
  - ⭐ `isObject()` if it's a js plain Object
43
45
  - `isPromise()`
44
46
  - `isPWA()`
@@ -52,11 +54,12 @@ Contributions always welcome!
52
54
 
53
55
  ### Math
54
56
 
55
- - `average()` numbers of an array
56
- - `max()` numbers of an array
57
- - `min()` numbers of an array
58
- - `multiply()` numbers of an array
59
- - `sum()` numbers an array
57
+ - `average()`
58
+ - `max()`
59
+ - `min()`
60
+ - `multiply()`
61
+ - `percentageChange()`
62
+ - `sum()`
60
63
 
61
64
  ### Helpers
62
65
 
@@ -71,7 +74,6 @@ Contributions always welcome!
71
74
  - `first()` get the first element of an array
72
75
  - `firstKey()`
73
76
  - `firstValue()`
74
- - `getKeys()` get the keys of an object, includes symbols
75
77
  - `getUrlSearchParam()`
76
78
  - `getUrlSearchParams()`
77
79
  - `incrementalId()` autoincremental SQL-like, process-unique numeric id
@@ -98,9 +100,12 @@ 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
- - `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
105
+ - `formatPercentage()` 0.11 => "11%"
106
+ - `formatProgress()` => "[2/10]"
103
107
  - `stringToCSSUnicode()` "hello" => "\000068\000065\00006c\00006c\00006f" use this for CSS
108
+ - `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
104
109
 
105
110
  ### Random data generators
106
111
 
@@ -127,6 +132,7 @@ These functions are optimized for low entropy random data generation useful for
127
132
  - `randomEnumValue()` enum FRUIT { APPLE = 1, PEAR = 3 } => 3
128
133
  - `randomFile()`
129
134
  - `randomFloat()`
135
+ - `randomObject()`
130
136
  - `randomHandle()` useful for social identifiers, or slugs
131
137
  - `randomHexColor()`
132
138
  - `randomHexValue()`
@@ -149,6 +155,7 @@ These functions are optimized for low entropy random data generation useful for
149
155
  - `randomPhoneNumber()`
150
156
  - `randomString()`
151
157
  - `randomUUID()` lightweight uuid generation, passing UUID validation
158
+ - `randomValue()`
152
159
  - `randomWord()`
153
160
 
154
161
  ### Checks
@@ -167,20 +174,21 @@ Checks are functions that throw an error, if the validation fails
167
174
  - `MaybePromiseOrValue<>`
168
175
  - `MaybePromiseOrValueArray<>`
169
176
  - `NonUndefined`
177
+ - `Key`
170
178
  - `ObjectKey<>`
171
179
  - `ObjectKeys<>`
172
180
  - `ObjectValue<>`
173
181
  - `ObjectValues<>`
182
+ - `ObjectEntry<>`
174
183
  - `ObjectEntries<>`
175
184
  - ⭐ `PlainObject` use this instead of `Record<,>` or `extends object`, also makes sure it's not an array
176
185
  - `Point`
177
- - `PrismaSelect<>`
178
186
  - `HashMap<>`
179
- - `HashMapKey`
180
- - `NumberMap`
181
- - `StringMap`
182
- - `BoolMap`
183
- - `TrueMap`
187
+ - `BoolMap`
188
+ - `NumberMap`
189
+ - `StringMap`
190
+ - `TrueMap`
191
+ - `VoidFn`
184
192
 
185
193
  ## Development
186
194
 
package/dist/index.d.ts CHANGED
@@ -38,6 +38,8 @@ 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
+
41
43
  /**
42
44
  *
43
45
  * @example formatNumber(1000, { compact: true }) // 1K
@@ -51,10 +53,30 @@ declare const formatNumber: (value: number, { compact, maxDigits, percentage, }?
51
53
  percentage?: boolean | undefined;
52
54
  }) => string;
53
55
 
54
- declare const stringToUnicode: (text: string) => string;
56
+ /**
57
+ *
58
+ * @example formatPercentage(1) => 100%
59
+ * @example formatPercentage(0, { digits: 2 }) => 0.00%
60
+ */
61
+ declare const formatPercentage: (value: number, { digits, }?: {
62
+ digits?: number | undefined;
63
+ }) => string;
64
+
65
+ /**
66
+ *
67
+ * @example formatProgress({ index: -1, total: 10 }) => [1/10] capped
68
+ * @example formatProgress({ index: 1, total: 10 }) => [2/10]
69
+ * @example formatProgress({ index: 11, total: 10 }) => [10/10] capped
70
+ */
71
+ declare const formatProgress: ({ index, total, }: {
72
+ index: number;
73
+ total: number;
74
+ }) => string;
55
75
 
56
76
  declare const stringToCSSUnicode: (text: string) => string;
57
77
 
78
+ declare const stringToUnicode: (text: string) => string;
79
+
58
80
  declare const array: <U extends (...args: any) => any>(length: number, mapFn?: U) => ReturnType<U>[];
59
81
 
60
82
  declare const arrayDiff: (arr1: any[], arr2: any[]) => any[];
@@ -63,6 +85,19 @@ declare const arrayIntersection: <T>(arr1: T[], arr2: T[]) => T[];
63
85
 
64
86
  declare const capitalize: (string: string) => string;
65
87
 
88
+ declare const chunkArray: <T>(array: T[], size: number) => T[][];
89
+
90
+ declare const chunkedAll: <T>(array: T[], chunkSize: number, fn: (chunk: T[]) => Promise<any>) => Promise<any[]>;
91
+
92
+ /**
93
+ * @description Run a series of (async) functions in order and return the results
94
+ * @param array
95
+ * @param chunkSize
96
+ * @param fn
97
+ *
98
+ */
99
+ declare const chunkedAsync: <T>(array: T[], chunkSize: number, fn: (chunk: T[]) => Promise<any>) => Promise<any[]>;
100
+
66
101
  declare const clamp: ({ number, min, max, }: {
67
102
  number: number;
68
103
  min: number;
@@ -81,13 +116,15 @@ declare const cyclicalItem: <T>(array: T[], index: number) => T;
81
116
  */
82
117
  declare const dir: (arg: any, depth?: number) => void;
83
118
 
119
+ type Key = string | number | symbol;
84
120
  type ObjectKey<T> = keyof T;
85
121
  type ObjectKeys<T> = ObjectKey<T>[];
86
122
  type ObjectValue<T> = T[keyof T];
87
123
  type ObjectValues<T> = ObjectValue<T>[];
88
- type ObjectEntries<T> = {
124
+ type ObjectEntry<T> = {
89
125
  [K in keyof T]: [K, T[K]];
90
- }[keyof T][];
126
+ }[keyof T];
127
+ type ObjectEntries<T> = ObjectEntry<T>[];
91
128
 
92
129
  declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
93
130
 
@@ -112,12 +149,11 @@ type Dimensions = {
112
149
  height: number;
113
150
  };
114
151
 
115
- type HashMapKey = string | number | symbol;
116
- type HashMap<T> = Record<HashMapKey, T>;
117
- type NumberMap = Record<HashMapKey, number>;
118
- type StringMap = Record<HashMapKey, string>;
119
- type BoolMap = Record<HashMapKey, boolean>;
120
- type TrueMap = Record<HashMapKey, true>;
152
+ type HashMap<T> = Record<Key, T>;
153
+ type NumberMap = Record<Key, number>;
154
+ type StringMap = Record<Key, string>;
155
+ type BoolMap = Record<Key, boolean>;
156
+ type TrueMap = Record<Key, true>;
121
157
 
122
158
  type Matrix<T> = T[][];
123
159
 
@@ -128,7 +164,11 @@ type MaybePromiseOrValueArray<T> = MaybePromiseOrValue<T>[];
128
164
 
129
165
  type NonUndefined<T> = T extends undefined ? never : T;
130
166
 
131
- type PlainObject = Record<string | symbol, any> & {
167
+ /**
168
+ * A plain object is an object that is not an array, does not have a length property, and is not a function.
169
+ * Would have been nice to call it just Object, but that's already taken by the built-in type.
170
+ */
171
+ type PlainObject<T = any> = Record<Key, T> & {
132
172
  length?: never;
133
173
  };
134
174
 
@@ -139,12 +179,16 @@ type Point = {
139
179
 
140
180
  type PrismaSelect<T> = Record<keyof T, true>;
141
181
 
142
- declare const firstKey: <T extends PlainObject>(arg: T) => keyof T;
182
+ declare const firstKey: <T extends PlainObject<any>>(arg: T) => keyof T;
143
183
 
144
- declare const firstValue: <T extends PlainObject>(arg: T) => ObjectValue<T>;
184
+ declare const firstValue: <T extends PlainObject<any>>(arg: T) => ObjectValue<T>;
145
185
 
146
- declare const getKeys: <T extends PlainObject>(obj: T) => ObjectKeys<T>;
147
- declare const getEnumerableOwnPropertySymbols: (obj: object) => any[];
186
+ /**
187
+ * TODO: rename to allKeys
188
+ * @deprecated use Object.keys instead unless you need to include symbols, but the function will be renamed to allKeys
189
+ */
190
+ declare const getKeys: <T extends PlainObject<any>>(obj: T) => (string | symbol)[];
191
+ declare const getEnumerableOwnPropertySymbols: (obj: object) => symbol[];
148
192
 
149
193
  declare const getUrlSearchParam: (urlString: Maybe<string>, param: string) => string | undefined;
150
194
 
@@ -152,7 +196,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
152
196
 
153
197
  declare const incrementalId: () => number;
154
198
 
155
- declare const keysLength: <T extends PlainObject>(obj: T) => number;
199
+ declare const keysLength: <T extends PlainObject<any>>(obj: T) => number;
156
200
 
157
201
  declare const last: <T>(arr: T[]) => T;
158
202
 
@@ -162,7 +206,7 @@ declare const lastIndex: (array: any[]) => number;
162
206
  * @description Simple merge function that merges two objects, arrays get overwritten, no options
163
207
  *
164
208
  */
165
- declare const merge: (target: PlainObject, source: PlainObject) => PlainObject;
209
+ declare const merge: (target: PlainObject, source: PlainObject) => PlainObject<any>;
166
210
 
167
211
  /**
168
212
  * @description Merge two arrays, unique values, no options
@@ -180,15 +224,15 @@ declare const normalizeNumber: ({ value, max, min, }: {
180
224
  min: number;
181
225
  }) => number;
182
226
 
183
- declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject;
227
+ declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject<any>;
184
228
 
185
- declare const omit: <T extends PlainObject>(obj: T, keys: (keyof T)[]) => Partial<T>;
229
+ declare const omit: <T extends PlainObject<any>>(obj: T, keys: (keyof T)[]) => Partial<T>;
186
230
 
187
231
  declare const parseDate: (arg?: Maybe<DateLike>) => Date | undefined;
188
232
 
189
- declare const pickObjectKeys: <T extends PlainObject>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
233
+ declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
190
234
 
191
- declare const pickObjectValues: <T extends PlainObject>(obj: T, values: ObjectValues<T>) => Partial<T>;
235
+ declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
192
236
 
193
237
  declare const pretty: (arg?: any) => string;
194
238
 
@@ -197,13 +241,13 @@ declare const promiseWithTimeout: <T>(promise: () => Promise<T>, timeoutMs: numb
197
241
  declare const scrambleText: (str: string) => string;
198
242
 
199
243
  /**
200
- * Serialize plain object to a deterministic string,
244
+ * Serialize shallow object to a deterministic string,
201
245
  * for nested objects use [json-stable-stringify](https://www.npmjs.com/package/json-stable-stringify)
202
246
  *
203
247
  * @example
204
248
  * serialize({ b: 1, a: 2 }) // '{"a":1,"b":2}'
205
249
  */
206
- declare const serialize: <T extends PlainObject>(obj: T) => string;
250
+ declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
207
251
 
208
252
  /**
209
253
  *
@@ -213,8 +257,7 @@ declare const serialize: <T extends PlainObject>(obj: T) => string;
213
257
  * () => Promise.resolve(1),
214
258
  * () => sleep(100).then(() => 2),
215
259
  * () => Promise.resolve(3),
216
- * ]);
217
- * @returns [1, 2, 3]
260
+ * ]); => [1, 2, 3]
218
261
  */
219
262
  declare const seriesAll: <T>(series: Function[]) => Promise<T[]>;
220
263
 
@@ -463,6 +506,8 @@ declare const isBoolean: (arg: any) => arg is boolean;
463
506
 
464
507
  declare const isBrowser: () => boolean;
465
508
 
509
+ declare const isBuffer: (val?: any) => boolean;
510
+
466
511
  declare const isClient: () => boolean;
467
512
 
468
513
  declare const isEmail: (arg: string) => boolean;
@@ -472,13 +517,15 @@ declare const isEmptyString: (arg: string) => boolean;
472
517
  declare const isEmptyArray: (arg: any[]) => boolean;
473
518
  declare const isEmptyObject: (arg: PlainObject) => boolean;
474
519
 
520
+ declare const isFile: (arg?: any) => arg is File;
521
+
475
522
  declare const isFunction: (arg: any) => arg is Function;
476
523
 
477
524
  declare const isFutureDate: (arg: DateLike) => boolean;
478
525
 
479
526
  declare const isJsDate: (arg: Date) => arg is Date;
480
527
 
481
- declare const isKey: <T extends object>(key: string | number | symbol, obj: T) => key is keyof T;
528
+ declare const isKey: <T extends object>(key: Key, obj: T) => key is keyof T;
482
529
 
483
530
  declare const isLastIndex: (index: number, array: any[]) => boolean;
484
531
 
@@ -499,11 +546,18 @@ declare const isNegative: (arg: any) => boolean;
499
546
  declare const isNegativeInt: (arg: any) => boolean;
500
547
  declare const isNumber: (arg: any) => arg is number;
501
548
 
549
+ /**
550
+ *
551
+ * @example isNumeric(1) => true
552
+ * @example isNumeric('1') => true
553
+ * @example isNumeric('1.1') => true
554
+ * @example isNumeric('1.1.1') => false
555
+ */
502
556
  declare const isNumeric: (arg: number | string) => boolean;
503
557
 
504
558
  declare const isNumericId: (id: string) => boolean;
505
559
 
506
- declare const isObject: <T>(arg?: any) => arg is Record<string, T>;
560
+ declare const isObject: <T>(arg?: any) => arg is PlainObject<T>;
507
561
 
508
562
  declare const isPastDate: (arg: DateLike) => boolean;
509
563
 
@@ -531,4 +585,4 @@ declare const isUUID: (arg: string) => boolean;
531
585
 
532
586
  declare const isValue: (arg?: Maybe<any>) => boolean;
533
587
 
534
- 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, cyclicalItem, dir, enumKeys, enumValues, first, firstKey, firstValue, formatNumber, formatTrpcInputQueryString, 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, 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 };
588
+ 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, chunkArray, chunkedAll, chunkedAsync, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, first, firstKey, firstValue, formatCamelCase, formatNumber, formatPercentage, formatProgress, 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 };