deverything 0.43.0 → 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 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
- - `HashMapKey`
180
- - `NumberMap`
181
- - `StringMap`
182
- - `BoolMap`
183
- - `TrueMap`
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,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,10 @@ 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;
55
-
56
56
  declare const stringToCSSUnicode: (text: string) => string;
57
57
 
58
+ declare const stringToUnicode: (text: string) => string;
59
+
58
60
  declare const array: <U extends (...args: any) => any>(length: number, mapFn?: U) => ReturnType<U>[];
59
61
 
60
62
  declare const arrayDiff: (arr1: any[], arr2: any[]) => any[];
@@ -81,13 +83,15 @@ declare const cyclicalItem: <T>(array: T[], index: number) => T;
81
83
  */
82
84
  declare const dir: (arg: any, depth?: number) => void;
83
85
 
86
+ type Key = string | number | symbol;
84
87
  type ObjectKey<T> = keyof T;
85
88
  type ObjectKeys<T> = ObjectKey<T>[];
86
89
  type ObjectValue<T> = T[keyof T];
87
90
  type ObjectValues<T> = ObjectValue<T>[];
88
- type ObjectEntries<T> = {
91
+ type ObjectEntry<T> = {
89
92
  [K in keyof T]: [K, T[K]];
90
- }[keyof T][];
93
+ }[keyof T];
94
+ type ObjectEntries<T> = ObjectEntry<T>[];
91
95
 
92
96
  declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
93
97
 
@@ -112,12 +116,11 @@ type Dimensions = {
112
116
  height: number;
113
117
  };
114
118
 
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>;
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>;
121
124
 
122
125
  type Matrix<T> = T[][];
123
126
 
@@ -128,7 +131,11 @@ type MaybePromiseOrValueArray<T> = MaybePromiseOrValue<T>[];
128
131
 
129
132
  type NonUndefined<T> = T extends undefined ? never : T;
130
133
 
131
- type PlainObject = Record<string | symbol, any> & {
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> & {
132
139
  length?: never;
133
140
  };
134
141
 
@@ -139,12 +146,16 @@ type Point = {
139
146
 
140
147
  type PrismaSelect<T> = Record<keyof T, true>;
141
148
 
142
- declare const firstKey: <T extends PlainObject>(arg: T) => keyof T;
149
+ declare const firstKey: <T extends PlainObject<any>>(arg: T) => keyof T;
143
150
 
144
- declare const firstValue: <T extends PlainObject>(arg: T) => ObjectValue<T>;
151
+ declare const firstValue: <T extends PlainObject<any>>(arg: T) => ObjectValue<T>;
145
152
 
146
- declare const getKeys: <T extends PlainObject>(obj: T) => ObjectKeys<T>;
147
- declare const getEnumerableOwnPropertySymbols: (obj: object) => any[];
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[];
148
159
 
149
160
  declare const getUrlSearchParam: (urlString: Maybe<string>, param: string) => string | undefined;
150
161
 
@@ -152,7 +163,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
152
163
 
153
164
  declare const incrementalId: () => number;
154
165
 
155
- declare const keysLength: <T extends PlainObject>(obj: T) => number;
166
+ declare const keysLength: <T extends PlainObject<any>>(obj: T) => number;
156
167
 
157
168
  declare const last: <T>(arr: T[]) => T;
158
169
 
@@ -162,7 +173,7 @@ declare const lastIndex: (array: any[]) => number;
162
173
  * @description Simple merge function that merges two objects, arrays get overwritten, no options
163
174
  *
164
175
  */
165
- declare const merge: (target: PlainObject, source: PlainObject) => PlainObject;
176
+ declare const merge: (target: PlainObject, source: PlainObject) => PlainObject<any>;
166
177
 
167
178
  /**
168
179
  * @description Merge two arrays, unique values, no options
@@ -180,15 +191,15 @@ declare const normalizeNumber: ({ value, max, min, }: {
180
191
  min: number;
181
192
  }) => number;
182
193
 
183
- declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject;
194
+ declare const objectDiff: (leftObject: PlainObject, rightObject: PlainObject) => PlainObject<any>;
184
195
 
185
- declare const omit: <T extends PlainObject>(obj: T, keys: (keyof T)[]) => Partial<T>;
196
+ declare const omit: <T extends PlainObject<any>>(obj: T, keys: (keyof T)[]) => Partial<T>;
186
197
 
187
198
  declare const parseDate: (arg?: Maybe<DateLike>) => Date | undefined;
188
199
 
189
- declare const pickObjectKeys: <T extends PlainObject>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
200
+ declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
190
201
 
191
- declare const pickObjectValues: <T extends PlainObject>(obj: T, values: ObjectValues<T>) => Partial<T>;
202
+ declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
192
203
 
193
204
  declare const pretty: (arg?: any) => string;
194
205
 
@@ -197,13 +208,13 @@ declare const promiseWithTimeout: <T>(promise: () => Promise<T>, timeoutMs: numb
197
208
  declare const scrambleText: (str: string) => string;
198
209
 
199
210
  /**
200
- * Serialize plain object to a deterministic string,
211
+ * Serialize shallow object to a deterministic string,
201
212
  * for nested objects use [json-stable-stringify](https://www.npmjs.com/package/json-stable-stringify)
202
213
  *
203
214
  * @example
204
215
  * serialize({ b: 1, a: 2 }) // '{"a":1,"b":2}'
205
216
  */
206
- declare const serialize: <T extends PlainObject>(obj: T) => string;
217
+ declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
207
218
 
208
219
  /**
209
220
  *
@@ -463,6 +474,8 @@ declare const isBoolean: (arg: any) => arg is boolean;
463
474
 
464
475
  declare const isBrowser: () => boolean;
465
476
 
477
+ declare const isBuffer: (val?: any) => boolean;
478
+
466
479
  declare const isClient: () => boolean;
467
480
 
468
481
  declare const isEmail: (arg: string) => boolean;
@@ -472,13 +485,15 @@ declare const isEmptyString: (arg: string) => boolean;
472
485
  declare const isEmptyArray: (arg: any[]) => boolean;
473
486
  declare const isEmptyObject: (arg: PlainObject) => boolean;
474
487
 
488
+ declare const isFile: (arg?: any) => arg is File;
489
+
475
490
  declare const isFunction: (arg: any) => arg is Function;
476
491
 
477
492
  declare const isFutureDate: (arg: DateLike) => boolean;
478
493
 
479
494
  declare const isJsDate: (arg: Date) => arg is Date;
480
495
 
481
- declare const isKey: <T extends object>(key: string | number | symbol, obj: T) => key is keyof T;
496
+ declare const isKey: <T extends object>(key: Key, obj: T) => key is keyof T;
482
497
 
483
498
  declare const isLastIndex: (index: number, array: any[]) => boolean;
484
499
 
@@ -503,7 +518,7 @@ declare const isNumeric: (arg: number | string) => boolean;
503
518
 
504
519
  declare const isNumericId: (id: string) => boolean;
505
520
 
506
- declare const isObject: <T>(arg?: any) => arg is Record<string, T>;
521
+ declare const isObject: <T>(arg?: any) => arg is PlainObject<T>;
507
522
 
508
523
  declare const isPastDate: (arg: DateLike) => boolean;
509
524
 
@@ -531,4 +546,4 @@ declare const isUUID: (arg: string) => boolean;
531
546
 
532
547
  declare const isValue: (arg?: Maybe<any>) => boolean;
533
548
 
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 };
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 };