deverything 0.47.2 → 0.48.1
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 +32 -30
- package/dist/index.d.ts +28 -15
- package/dist/index.global.js +134 -131
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +134 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -15,42 +15,42 @@ Contributions always welcome!
|
|
|
15
15
|
|
|
16
16
|
### Validators
|
|
17
17
|
|
|
18
|
-
- `isArray()`
|
|
19
|
-
- `isBoolean()`
|
|
18
|
+
- `isArray()`
|
|
19
|
+
- `isBoolean()`
|
|
20
20
|
- `isBrowser()` to detect if you are on the browser
|
|
21
|
-
- `isBuffer()`
|
|
21
|
+
- `isBuffer()` if it's a buffer
|
|
22
22
|
- `isClient()` same as isBrowser
|
|
23
23
|
- `isEmail()` this is a relaxed check, use your own validation if you need to be strict
|
|
24
24
|
- ⭐ `isEmpty()` to check for empty object, empty array, empty string, null or undefined
|
|
25
25
|
- `isEmptyString()` trims the string and checks if something is left
|
|
26
|
-
- `isEmptyArray()`
|
|
27
|
-
- `isEmptyObject()`
|
|
28
|
-
- `isFile()`
|
|
29
|
-
- `isFunction()`
|
|
26
|
+
- `isEmptyArray()` checks if the array has no items
|
|
27
|
+
- `isEmptyObject()` checks if the object has no keys
|
|
28
|
+
- `isFile()` if it's a file
|
|
29
|
+
- `isFunction()`
|
|
30
30
|
- `isJsDate()` if it's a **valid** javascript's Date
|
|
31
|
-
- `isFutureDate()`
|
|
32
|
-
- `isPastDate()`
|
|
31
|
+
- `isFutureDate()`
|
|
32
|
+
- `isPastDate()`
|
|
33
33
|
- `isStringDate()` also checks if the string passed is a **valid** date
|
|
34
34
|
- `isKey()` is a real key of an object
|
|
35
35
|
- `isLastIndex()` is the index is the last item of array
|
|
36
36
|
- `isNotEmptyString()` must have some text, checks for spaces-only
|
|
37
37
|
- `isNumber()` if the arg is number, and also usable (no infinity)
|
|
38
|
-
- `isInt()`
|
|
39
|
-
- `isEven()`
|
|
40
|
-
- `isOdd()`
|
|
41
|
-
- `isPositiveInt()`
|
|
42
|
-
- `isNegativeInt()`
|
|
38
|
+
- `isInt()` if it's an integer
|
|
39
|
+
- `isEven()`
|
|
40
|
+
- `isOdd()`
|
|
41
|
+
- `isPositiveInt()`
|
|
42
|
+
- `isNegativeInt()`
|
|
43
43
|
- `isNumeric()` if string is representing a number
|
|
44
44
|
- ⭐ `isObject()` if it's a js plain Object
|
|
45
|
-
- `isPromise()`
|
|
46
|
-
- `isPWA()`
|
|
47
|
-
- `isReactElement()`
|
|
48
|
-
- `isRegExp()`
|
|
45
|
+
- `isPromise()` if it's a promise
|
|
46
|
+
- `isPWA()` to detect if you are on a PWA
|
|
47
|
+
- `isReactElement()` if it's a valid React Element
|
|
48
|
+
- `isRegExp()` if it's a valid RegExp
|
|
49
49
|
- ⭐ `isSame()` Compare if dates, functions, arrays, objects or anything else are the same
|
|
50
50
|
- `isServer()` if you are on the server
|
|
51
51
|
- `isString()`
|
|
52
|
-
- `isURL()`
|
|
53
|
-
- `isUUID()`
|
|
52
|
+
- `isURL()`
|
|
53
|
+
- `isUUID()` if it's a valid UUID
|
|
54
54
|
|
|
55
55
|
### Math
|
|
56
56
|
|
|
@@ -64,20 +64,20 @@ Contributions always welcome!
|
|
|
64
64
|
### Helpers
|
|
65
65
|
|
|
66
66
|
- `array()` create an arbitrary array based on a function
|
|
67
|
-
- `arrayDiff()`
|
|
68
|
-
- `arrayIntersection()`
|
|
67
|
+
- `arrayDiff()` get the difference of two arrays
|
|
68
|
+
- `arrayIntersection()` get the intersection of two arrays
|
|
69
69
|
- `capitalize()` word => Word
|
|
70
70
|
- `cleanSpaces()` trims and turns double spaces into single space
|
|
71
71
|
- `clamp()` clamp number in a range
|
|
72
72
|
- `enumKeys()` enum FRUIT { APPLE, PEAR } => ["APPLE", "PEAR"]
|
|
73
73
|
- `enumValues()` enum FRUIT { APPLE = 1, PEAR = 3 } => [1, 3]
|
|
74
74
|
- `first()` get the first element of an array
|
|
75
|
-
- `firstKey()`
|
|
76
|
-
- `firstValue()`
|
|
77
|
-
- `getUrlSearchParam()`
|
|
78
|
-
- `getUrlSearchParams()`
|
|
75
|
+
- `firstKey()` get the first key of an object
|
|
76
|
+
- `firstValue()` get the first value of an object
|
|
77
|
+
- `getUrlSearchParam()` get URL search param
|
|
78
|
+
- `getUrlSearchParams()` get URL search params
|
|
79
79
|
- `incrementalId()` autoincremental SQL-like, process-unique numeric id
|
|
80
|
-
- `keysLength()`
|
|
80
|
+
- `keysLength()` get the length of keys in an object
|
|
81
81
|
- `last()` get the last element of an array
|
|
82
82
|
- `lastIndex()` get the last index of an array
|
|
83
83
|
- ⭐ `merge()` deep merge objects
|
|
@@ -85,13 +85,14 @@ Contributions always welcome!
|
|
|
85
85
|
- `moveToIndex()` move array element to desired index
|
|
86
86
|
- `moveToLast()` move array element to last
|
|
87
87
|
- `normalizeNumber()` normalizes between 0 and 1
|
|
88
|
-
- `objectDiff()`
|
|
88
|
+
- `objectDiff()` get the difference between two objects
|
|
89
89
|
- ⭐ `parseDate()` pass anything Date-Like, and get a JS Date back
|
|
90
90
|
- `pretty()` stringify anything, without breaking on circular dependencies
|
|
91
91
|
- `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.
|
|
92
92
|
- `scrambleText()` replace alpha chars with random chars
|
|
93
93
|
- `seriesAll()` executes promises in series, and returns all results
|
|
94
|
-
- `
|
|
94
|
+
- `setObjectPath()` set a value in an object by path
|
|
95
|
+
- `setUrlSearchParams()` set URL search params
|
|
95
96
|
- `shuffle()` shuffles elements in an array
|
|
96
97
|
- `sleep()` promise-based sleep
|
|
97
98
|
- `toggleArrayValue()` remove/add value in array
|
|
@@ -111,7 +112,7 @@ Contributions always welcome!
|
|
|
111
112
|
|
|
112
113
|
These functions are optimized for low entropy random data generation useful for Unit Testing, Storybook, Pass real validations, Reverse hacking, Penetration testing...
|
|
113
114
|
|
|
114
|
-
- `randomAddress()`
|
|
115
|
+
- `randomAddress()`
|
|
115
116
|
- `randomAlphaNumericCode()`
|
|
116
117
|
- ⭐ `randomArrayItem()` now supporting non-uniform distribution
|
|
117
118
|
- `randomBankAccount()`
|
|
@@ -182,6 +183,7 @@ Checks are functions that throw an error, if the validation fails
|
|
|
182
183
|
- `ObjectEntry<>`
|
|
183
184
|
- `ObjectEntries<>`
|
|
184
185
|
- ⭐ `PlainObject` use this instead of `Record<,>` or `extends object`, also makes sure it's not an array
|
|
186
|
+
- `PlainKey`
|
|
185
187
|
- `Point`
|
|
186
188
|
- `HashMap<>`
|
|
187
189
|
- `BoolMap`
|
package/dist/index.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ declare const cyclicalItem: <T>(array: T[], index: number) => T;
|
|
|
117
117
|
declare const dir: (arg: any, depth?: number) => void;
|
|
118
118
|
|
|
119
119
|
type Key = string | number | symbol;
|
|
120
|
+
type PlainKey = string | number;
|
|
120
121
|
type ObjectKey<T> = keyof T;
|
|
121
122
|
type ObjectKeys<T> = ObjectKey<T>[];
|
|
122
123
|
type ObjectValue<T> = T[keyof T];
|
|
@@ -125,6 +126,13 @@ type ObjectEntry<T> = {
|
|
|
125
126
|
[K in keyof T]: [K, T[K]];
|
|
126
127
|
}[keyof T];
|
|
127
128
|
type ObjectEntries<T> = ObjectEntry<T>[];
|
|
129
|
+
/**
|
|
130
|
+
* A plain object is an object that is not an array, does not have a length property, and is not a function.
|
|
131
|
+
* Would have been nice to call it just Object, but that's already taken by the built-in type.
|
|
132
|
+
*/
|
|
133
|
+
type PlainObject<T = any> = Record<PlainKey, T> & {
|
|
134
|
+
length?: never;
|
|
135
|
+
};
|
|
128
136
|
|
|
129
137
|
declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
|
|
130
138
|
|
|
@@ -149,11 +157,11 @@ type Dimensions = {
|
|
|
149
157
|
height: number;
|
|
150
158
|
};
|
|
151
159
|
|
|
152
|
-
type HashMap<T> = Record<
|
|
153
|
-
type NumberMap = Record<
|
|
154
|
-
type StringMap = Record<
|
|
155
|
-
type BoolMap = Record<
|
|
156
|
-
type TrueMap = Record<
|
|
160
|
+
type HashMap<T> = Record<PlainKey, T>;
|
|
161
|
+
type NumberMap = Record<PlainKey, number>;
|
|
162
|
+
type StringMap = Record<PlainKey, string>;
|
|
163
|
+
type BoolMap = Record<PlainKey, boolean>;
|
|
164
|
+
type TrueMap = Record<PlainKey, true>;
|
|
157
165
|
|
|
158
166
|
type Matrix<T> = T[][];
|
|
159
167
|
|
|
@@ -164,14 +172,6 @@ type MaybePromiseOrValueArray<T> = MaybePromiseOrValue<T>[];
|
|
|
164
172
|
|
|
165
173
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
166
174
|
|
|
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> & {
|
|
172
|
-
length?: never;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
175
|
type Point = {
|
|
176
176
|
x: number;
|
|
177
177
|
y: number;
|
|
@@ -276,6 +276,15 @@ declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
|
|
|
276
276
|
*/
|
|
277
277
|
declare const seriesAll: <T>(series: Function[]) => Promise<T[]>;
|
|
278
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Sets a value in an object using a dot-separated path.
|
|
281
|
+
*
|
|
282
|
+
* @param obj The object to set the value in.
|
|
283
|
+
* @param path The path to the key to set, separated by dots.
|
|
284
|
+
* @param value The value to set.
|
|
285
|
+
*/
|
|
286
|
+
declare const setObjectPath: (obj: PlainObject, path: string, value: any) => void;
|
|
287
|
+
|
|
279
288
|
declare const setUrlSearchParams: (currentURL: string, searchParams?: Record<string, string | number | boolean>) => string;
|
|
280
289
|
|
|
281
290
|
declare const shuffle: <T>(array: T[]) => T[];
|
|
@@ -306,12 +315,16 @@ declare const uniqueValues: (arr: any[]) => any[];
|
|
|
306
315
|
*/
|
|
307
316
|
declare const average: (numbers: number[]) => number;
|
|
308
317
|
|
|
318
|
+
declare const isBetween: (value: number, min: number, max: number) => boolean;
|
|
319
|
+
|
|
309
320
|
declare const max: (values: number[]) => number;
|
|
310
321
|
|
|
311
322
|
declare const min: (values: number[]) => number;
|
|
312
323
|
|
|
313
324
|
declare const multiply: (numbers: number[]) => number;
|
|
314
325
|
|
|
326
|
+
declare const isOutside: (value: number, min: number, max: number) => boolean;
|
|
327
|
+
|
|
315
328
|
declare const percentageChange: ({ previous, current, }: {
|
|
316
329
|
previous: number;
|
|
317
330
|
current: number;
|
|
@@ -543,7 +556,7 @@ declare const isFutureDate: (arg: DateLike) => boolean;
|
|
|
543
556
|
|
|
544
557
|
declare const isJsDate: (arg: Date) => arg is Date;
|
|
545
558
|
|
|
546
|
-
declare const isKey: <T extends
|
|
559
|
+
declare const isKey: <T extends PlainObject<any>>(key: Key, obj: T) => key is keyof T;
|
|
547
560
|
|
|
548
561
|
declare const isLastIndex: (index: number, array: any[]) => boolean;
|
|
549
562
|
|
|
@@ -603,4 +616,4 @@ declare const isUUID: (arg: string) => boolean;
|
|
|
603
616
|
|
|
604
617
|
declare const isValue: (arg?: Maybe<any>) => boolean;
|
|
605
618
|
|
|
606
|
-
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, Serialized, StringMap, TrueMap, WithDatey, array, arrayDiff, arrayIntersection, average, capitalize, checkEnvVars, 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, 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 };
|
|
619
|
+
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, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, TrueMap, WithDatey, array, arrayDiff, arrayIntersection, average, capitalize, checkEnvVars, 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, 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, setObjectPath, setUrlSearchParams, shuffle, sleep, stringToCSSUnicode, stringToUnicode, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
|