deverything 2.2.0 → 3.1.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 +47 -12
- package/dist/index.global.js +162 -162
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +162 -162
- 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
|
@@ -139,8 +139,19 @@ type Serialized<T> = T extends Date ? string : T extends Array<infer R> ? Array<
|
|
|
139
139
|
[K in keyof T]: Serialized<T[K]>;
|
|
140
140
|
} : T;
|
|
141
141
|
|
|
142
|
+
/**
|
|
143
|
+
*
|
|
144
|
+
* @deprecated use getDateRangeSeries instead
|
|
145
|
+
*/
|
|
142
146
|
declare const getDateSeries: (startDate: Date, endDate: Date, unit: "days" | "hours" | "minutes" | "seconds") => ISODate[];
|
|
143
147
|
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @description Generate a series of dates between the start and end dates
|
|
151
|
+
* NOTE: it does NOT include the end date
|
|
152
|
+
*/
|
|
153
|
+
declare const getDateRangeSeries: (dateRange: DateRange, unit: "days" | "hours" | "minutes" | "seconds") => ISODate[];
|
|
154
|
+
|
|
144
155
|
declare const isOver18: (birthDate: DateLike) => boolean;
|
|
145
156
|
|
|
146
157
|
declare const startOfDay: (day: Date) => Date;
|
|
@@ -303,12 +314,10 @@ declare const firstValue: <T extends PlainObject<any>>(arg: T) => ObjectValue<T>
|
|
|
303
314
|
*/
|
|
304
315
|
declare const getCookieByName: (name: string) => string | undefined;
|
|
305
316
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
declare const getKeys: <T extends PlainObject<any>>(obj: T) => (string | symbol)[];
|
|
311
|
-
declare const getEnumerableOwnPropertySymbols: (obj: object) => symbol[];
|
|
317
|
+
declare const getKeys: {
|
|
318
|
+
(o: object): string[];
|
|
319
|
+
(o: {}): string[];
|
|
320
|
+
};
|
|
312
321
|
|
|
313
322
|
declare const getUrlSearchParam: (urlString: Maybe<string>, param: string) => string | undefined;
|
|
314
323
|
|
|
@@ -327,7 +336,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
|
|
|
327
336
|
* { externalId: 2, value: 100 },
|
|
328
337
|
* { mis_spelled_externalId: 2, value: 90 }, // not included in any group
|
|
329
338
|
* ];
|
|
330
|
-
* const ordersByInstrument =
|
|
339
|
+
* const ordersByInstrument = groupByKey(items, "externalId");
|
|
331
340
|
* // {
|
|
332
341
|
* // 1: [
|
|
333
342
|
* // { externalId: 1, value: 100 },
|
|
@@ -339,7 +348,7 @@ declare const getUrlSearchParams: (urlString: Maybe<string>) => Record<string, s
|
|
|
339
348
|
* // ],
|
|
340
349
|
* // }
|
|
341
350
|
*/
|
|
342
|
-
declare const
|
|
351
|
+
declare const groupByKey: <T, K extends keyof T>(items: T[], key: K) => Record<keyof T, T[]>;
|
|
343
352
|
|
|
344
353
|
declare const incrementalId: () => number;
|
|
345
354
|
|
|
@@ -349,6 +358,17 @@ declare const last: <T>(arr: T[]) => T;
|
|
|
349
358
|
|
|
350
359
|
declare const lastIndex: (array: any[]) => number;
|
|
351
360
|
|
|
361
|
+
/**
|
|
362
|
+
*
|
|
363
|
+
* @description Given an array of objects, returns a record where the key is the value of the object's key
|
|
364
|
+
* NOTE: if two objects have the same key, the last one will be the one kept.
|
|
365
|
+
* Useful for quick lookups by key.
|
|
366
|
+
* @example
|
|
367
|
+
* const items = [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }];
|
|
368
|
+
* const itemsById = mapByKey(items, "id");
|
|
369
|
+
* itemsById[1]; // { id: 1, name: "Alice" }
|
|
370
|
+
* itemsById[2]; // { id: 2, name: "Bob" }
|
|
371
|
+
*/
|
|
352
372
|
declare const mapByKey: <T extends PlainObject<any>>(items: T[], key: keyof T) => Record<keyof T, T>;
|
|
353
373
|
|
|
354
374
|
/**
|
|
@@ -387,8 +407,22 @@ declare const parseDate: (arg?: Maybe<DateLike>, options?: {
|
|
|
387
407
|
asUTC?: boolean;
|
|
388
408
|
}) => Date | undefined;
|
|
389
409
|
|
|
410
|
+
/**
|
|
411
|
+
*
|
|
412
|
+
* @description Given an object, returns a new object with only the keys that are in the `keys` array.
|
|
413
|
+
* @example
|
|
414
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
415
|
+
* pickObjectKeys(obj, ["a", "c"]); // { a: 1, c: 3 }
|
|
416
|
+
*/
|
|
390
417
|
declare const pickObjectKeys: <T extends PlainObject<any>>(obj: T, keys: ObjectKeys<T>) => Partial<T>;
|
|
391
418
|
|
|
419
|
+
/**
|
|
420
|
+
*
|
|
421
|
+
* @description Given an object, returns a new object with only the keys that have the values in the `values` array.
|
|
422
|
+
* @example
|
|
423
|
+
* const obj = { a: 1, b: 2, c: 3 };
|
|
424
|
+
* pickObjectValues(obj, [1, 3]); // { a: 1, c: 3 }
|
|
425
|
+
*/
|
|
392
426
|
declare const pickObjectValues: <T extends PlainObject<any>>(obj: T, values: ObjectValues<T>) => Partial<T>;
|
|
393
427
|
|
|
394
428
|
declare const pluck: <T extends PlainObject<any>>(items: T[], key: keyof T) => Exclude<T[keyof T], null | undefined>[];
|
|
@@ -410,8 +444,9 @@ declare const scrambleText: (str: string) => string;
|
|
|
410
444
|
*/
|
|
411
445
|
declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
|
|
412
446
|
|
|
413
|
-
type
|
|
414
|
-
|
|
447
|
+
type AsyncFunction<T = any> = () => Promise<T>;
|
|
448
|
+
type SeriesResult<T extends readonly AsyncFunction[]> = {
|
|
449
|
+
[K in keyof T]: T[K] extends AsyncFunction<infer U> ? Awaited<U> : never;
|
|
415
450
|
};
|
|
416
451
|
/**
|
|
417
452
|
*
|
|
@@ -424,7 +459,7 @@ type SeriesResult<T extends readonly unknown[]> = {
|
|
|
424
459
|
* async () => 4,
|
|
425
460
|
* ]); => [1, 2, 3, 4]
|
|
426
461
|
*/
|
|
427
|
-
declare const seriesAsync: <T extends readonly
|
|
462
|
+
declare const seriesAsync: <T extends readonly AsyncFunction<any>[]>(series: readonly [...T]) => Promise<SeriesResult<T>>;
|
|
428
463
|
|
|
429
464
|
/**
|
|
430
465
|
* Sets a value in an object using a dot-separated path.
|
|
@@ -813,4 +848,4 @@ declare const isUUID: (arg: string) => boolean;
|
|
|
813
848
|
|
|
814
849
|
declare const isValue: <T>(arg?: Maybe<T>) => arg is T;
|
|
815
850
|
|
|
816
|
-
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,
|
|
851
|
+
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, getDateRangeSeries, 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 };
|