deverything 2.1.2 → 3.0.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 +3 -0
- package/dist/index.d.ts +48 -13
- package/dist/index.global.js +175 -174
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +175 -174
- 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
|
@@ -92,10 +92,12 @@ Contributions always welcome!
|
|
|
92
92
|
- `firstValue()` get the first value of an object
|
|
93
93
|
- `getUrlSearchParam()` get URL search param
|
|
94
94
|
- `getUrlSearchParams()` get URL search params
|
|
95
|
+
- `groupByKey()`
|
|
95
96
|
- `incrementalId()` autoincremental SQL-like, process-unique numeric id
|
|
96
97
|
- `keysLength()` get the length of keys in an object
|
|
97
98
|
- `last()` get the last element of an array
|
|
98
99
|
- `lastIndex()` get the last index of an array
|
|
100
|
+
- `mapByKey()`
|
|
99
101
|
- ⭐ `merge()` deep merge objects
|
|
100
102
|
- `moveToFirst()` move array element to first
|
|
101
103
|
- `moveToIndex()` move array element to desired index
|
|
@@ -103,6 +105,7 @@ Contributions always welcome!
|
|
|
103
105
|
- `normalizeNumber()` normalizes between 0 and 1
|
|
104
106
|
- `objectDiff()` get the difference between two objects
|
|
105
107
|
- ⭐ `parseDate()` pass anything Date-Like, and get a JS Date back
|
|
108
|
+
- `pluck()` make array of value from object keys
|
|
106
109
|
- `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.
|
|
107
110
|
- `scrambleText()` replace alpha chars with random chars
|
|
108
111
|
- `seriesAsync()` executes promises in series, and returns all results
|
package/dist/index.d.ts
CHANGED
|
@@ -211,10 +211,17 @@ declare const stringToUnicode: (text: string) => string;
|
|
|
211
211
|
declare const array: <U extends (...args: any) => any>(length: number, mapFn?: U) => ReturnType<U>[];
|
|
212
212
|
|
|
213
213
|
/**
|
|
214
|
-
* Given 2 arrays, returns the elements that belong to each but not both at the same time.
|
|
214
|
+
* Given 2 arrays, returns the (unique) elements that belong to each but not both at the same time.
|
|
215
|
+
* @example
|
|
216
|
+
* arrayDiff([1, 2, 3], [2, 3, 4]); // [1, 4]
|
|
215
217
|
*/
|
|
216
218
|
declare const arrayDiff: (arr1: any[], arr2: any[]) => any[];
|
|
217
219
|
|
|
220
|
+
/**
|
|
221
|
+
* @description Given 2 arrays, returns the (unique) elements that belong to both arrays.
|
|
222
|
+
* @example
|
|
223
|
+
* arrayIntersection([1, 2, 3], [2, 3, 4]); // [2, 3]
|
|
224
|
+
*/
|
|
218
225
|
declare const arrayIntersection: <T>(arr1: T[], arr2: T[]) => T[];
|
|
219
226
|
|
|
220
227
|
declare const capitalize: (string: string) => string;
|
|
@@ -296,12 +303,10 @@ declare const firstValue: <T extends PlainObject<any>>(arg: T) => ObjectValue<T>
|
|
|
296
303
|
*/
|
|
297
304
|
declare const getCookieByName: (name: string) => string | undefined;
|
|
298
305
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
declare const getKeys: <T extends PlainObject<any>>(obj: T) => (string | symbol)[];
|
|
304
|
-
declare const getEnumerableOwnPropertySymbols: (obj: object) => symbol[];
|
|
306
|
+
declare const getKeys: {
|
|
307
|
+
(o: object): string[];
|
|
308
|
+
(o: {}): string[];
|
|
309
|
+
};
|
|
305
310
|
|
|
306
311
|
declare const getUrlSearchParam: (urlString: Maybe<string>, param: string) => string | undefined;
|
|
307
312
|
|
|
@@ -320,7 +325,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
|
|
|
320
325
|
* { externalId: 2, value: 100 },
|
|
321
326
|
* { mis_spelled_externalId: 2, value: 90 }, // not included in any group
|
|
322
327
|
* ];
|
|
323
|
-
* const ordersByInstrument =
|
|
328
|
+
* const ordersByInstrument = groupByKey(items, "externalId");
|
|
324
329
|
* // {
|
|
325
330
|
* // 1: [
|
|
326
331
|
* // { externalId: 1, value: 100 },
|
|
@@ -332,7 +337,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
|
|
|
332
337
|
* // ],
|
|
333
338
|
* // }
|
|
334
339
|
*/
|
|
335
|
-
declare const
|
|
340
|
+
declare const groupByKey: <T, K extends keyof T>(items: T[], key: K) => Record<keyof T, T[]>;
|
|
336
341
|
|
|
337
342
|
declare const incrementalId: () => number;
|
|
338
343
|
|
|
@@ -342,6 +347,19 @@ declare const last: <T>(arr: T[]) => T;
|
|
|
342
347
|
|
|
343
348
|
declare const lastIndex: (array: any[]) => number;
|
|
344
349
|
|
|
350
|
+
/**
|
|
351
|
+
*
|
|
352
|
+
* @description Given an array of objects, returns a record where the key is the value of the object's key
|
|
353
|
+
* NOTE: if two objects have the same key, the last one will be the one kept.
|
|
354
|
+
* Useful for quick lookups by key.
|
|
355
|
+
* @example
|
|
356
|
+
* const items = [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }];
|
|
357
|
+
* const itemsById = mapByKey(items, "id");
|
|
358
|
+
* itemsById[1]; // { id: 1, name: "Alice" }
|
|
359
|
+
* itemsById[2]; // { id: 2, name: "Bob" }
|
|
360
|
+
*/
|
|
361
|
+
declare const mapByKey: <T extends PlainObject<any>>(items: T[], key: keyof T) => Record<keyof T, T>;
|
|
362
|
+
|
|
345
363
|
/**
|
|
346
364
|
* @description Simple merge function that merges two objects, arrays get overwritten, no options
|
|
347
365
|
*
|
|
@@ -378,10 +396,26 @@ declare const parseDate: (arg?: Maybe<DateLike>, options?: {
|
|
|
378
396
|
asUTC?: boolean;
|
|
379
397
|
}) => Date | undefined;
|
|
380
398
|
|
|
399
|
+
/**
|
|
400
|
+
*
|
|
401
|
+
* @description Given an object, returns a new object with only the keys that are in the `keys` array.
|
|
402
|
+
* @example
|
|
403
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
404
|
+
* pickObjectKeys(obj, ["a", "c"]); // { a: 1, c: 3 }
|
|
405
|
+
*/
|
|
381
406
|
declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
|
|
382
407
|
|
|
408
|
+
/**
|
|
409
|
+
*
|
|
410
|
+
* @description Given an object, returns a new object with only the keys that have the values in the `values` array.
|
|
411
|
+
* @example
|
|
412
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
413
|
+
* pickObjectValues(obj, [1, 3]); // { a: 1, c: 3 }
|
|
414
|
+
*/
|
|
383
415
|
declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
|
|
384
416
|
|
|
417
|
+
declare const pluck: <T extends PlainObject<any>>(items: T[], key: keyof T) => Exclude<T[keyof T], null | undefined>[];
|
|
418
|
+
|
|
385
419
|
declare const promiseWithTimeout: <T>(promise: () => Promise<T>, timeoutMs: number, error?: Error) => Promise<T>;
|
|
386
420
|
|
|
387
421
|
declare const removeUndefinedValues: (obj: PlainObject) => {
|
|
@@ -399,8 +433,9 @@ declare const scrambleText: (str: string) => string;
|
|
|
399
433
|
*/
|
|
400
434
|
declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
|
|
401
435
|
|
|
402
|
-
type
|
|
403
|
-
|
|
436
|
+
type AsyncFunction<T = any> = () => Promise<T>;
|
|
437
|
+
type SeriesResult<T extends readonly AsyncFunction[]> = {
|
|
438
|
+
[K in keyof T]: T[K] extends AsyncFunction<infer U> ? Awaited<U> : never;
|
|
404
439
|
};
|
|
405
440
|
/**
|
|
406
441
|
*
|
|
@@ -413,7 +448,7 @@ type SeriesResult<T extends readonly unknown[]> = {
|
|
|
413
448
|
* async () => 4,
|
|
414
449
|
* ]); => [1, 2, 3, 4]
|
|
415
450
|
*/
|
|
416
|
-
declare const seriesAsync: <T extends readonly
|
|
451
|
+
declare const seriesAsync: <T extends readonly AsyncFunction<any>[]>(series: readonly [...T]) => Promise<SeriesResult<T>>;
|
|
417
452
|
|
|
418
453
|
/**
|
|
419
454
|
* Sets a value in an object using a dot-separated path.
|
|
@@ -802,4 +837,4 @@ declare const isUUID: (arg: string) => boolean;
|
|
|
802
837
|
|
|
803
838
|
declare const isValue: <T>(arg?: Maybe<T>) => arg is T;
|
|
804
839
|
|
|
805
|
-
export { BoolMap, Coords, DateLike, DateRange, Datey, Defined, Dimensions, HashMap, ISODate, ISODay, ISOMonth, ISOYear, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PickDefined, PickRequired, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, Timezone, TrueMap, VoidFn, array, arrayDiff, arrayIntersection, average, capitalize, chunkArray, chunkedAll, chunkedAsync, chunkedDynamic, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, filterAlphanumeric, first, firstKey, firstValue, formatCamelCase, formatCookies, formatIndexProgress, formatNumber, formatPercentage, formatProgress, formatTrpcInputQueryString, getCookieByName, getDateSeries,
|
|
840
|
+
export { BoolMap, Coords, DateLike, DateRange, Datey, Defined, Dimensions, HashMap, ISODate, ISODay, ISOMonth, ISOYear, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PickDefined, PickRequired, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, Timezone, TrueMap, VoidFn, array, arrayDiff, arrayIntersection, average, capitalize, chunkArray, chunkedAll, chunkedAsync, chunkedDynamic, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, filterAlphanumeric, first, firstKey, firstValue, formatCamelCase, formatCookies, formatIndexProgress, formatNumber, formatPercentage, formatProgress, formatTrpcInputQueryString, getCookieByName, getDateSeries, getKeys, getUrlSearchParam, getUrlSearchParams, groupByKey, incrementalId, isArray, isArrayIncluded, isBetween, isBigInt, isBigIntString, 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, isOutsideInt4, isOver18, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isSequence, isServer, isSpacedString, isStrictlyBetween, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, mapByKey, max, merge, mergeArrays, min, moveToFirst, moveToLast, multiply, noop, normaliseArray, normaliseNumber, normalizeNumber, objectDiff, omit, parseDate, percentageChange, pickObjectKeys, pickObjectValues, pluck, prismaDateRange, promiseWithTimeout, randomAddress, randomAlphaNumericCode, randomArray, randomArrayItem, randomBankAccount, randomBigInt, randomBool, randomChar, randomCompany, randomCoords, randomDate, randomDateRange, randomEmail, randomEmoji, randomEmptyValue, 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, removeUndefinedValues, scrambleText, serialize, seriesAsync, setObjectPath, setUrlSearchParams, shuffle, sleep, startOfDay, startOfNextMonth, startOfNextWeek, startOfThisWeek, startOfToday, startOfTomorrow, startOfUTCDay, stringToCSSUnicode, stringToUnicode, stringify, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
|