deverything 0.51.1 → 1.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 CHANGED
@@ -70,6 +70,8 @@ Contributions always welcome!
70
70
  - `max()`
71
71
  - `min()`
72
72
  - `multiply()`
73
+ - `normaliseArray()`
74
+ - `normaliseNumber()`
73
75
  - `percentageChange()`
74
76
  - `sum()`
75
77
 
@@ -79,10 +81,11 @@ Contributions always welcome!
79
81
  - `arrayDiff()` get the difference of two arrays
80
82
  - `arrayIntersection()` get the intersection of two arrays
81
83
  - `capitalize()` word => Word
82
- - `cleanSpaces()` trims and turns double spaces into single space
83
84
  - `clamp()` clamp number in a range
85
+ - `cleanSpaces()` trims and turns double spaces into single space
84
86
  - `enumKeys()` enum FRUIT { APPLE, PEAR } => ["APPLE", "PEAR"]
85
87
  - `enumValues()` enum FRUIT { APPLE = 1, PEAR = 3 } => [1, 3]
88
+ - `filterAlphanumeric()` remove non-alphanumeric characters
86
89
  - `first()` get the first element of an array
87
90
  - `firstKey()` get the first key of an object
88
91
  - `firstValue()` get the first value of an object
@@ -114,6 +117,7 @@ Contributions always welcome!
114
117
  ### Formatters
115
118
 
116
119
  - `formatCamelCase()`
120
+ - `formatCookies()` { cookie1: "1", cookie2: "2" } => "cookie1=1; cookie2=2"
117
121
  - `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
118
122
  - `formatPercentage()` 0.11 => "11%"
119
123
  - `formatProgress()` => "[2/10]"
@@ -171,12 +175,6 @@ These functions are optimized for low entropy random data generation useful for
171
175
  - `randomValue()`
172
176
  - `randomWord()`
173
177
 
174
- ### Checks
175
-
176
- Checks are functions that throw an error, if the validation fails
177
-
178
- - ⭐ `checkEnvVars()` Make sure env vars are set per-environment
179
-
180
178
  ### TypeScript Helpers & Generics
181
179
 
182
180
  - `Coords`
package/dist/index.d.ts CHANGED
@@ -1,43 +1,3 @@
1
- type Keyword = "should" | "shouldNot" | "always" | "never";
2
- type SimpleValidationRule = Keyword | boolean;
3
- type EnvValidation = string[];
4
- type AdvancedValidation = {
5
- oneOf?: string[];
6
- endsWith?: string;
7
- startsWith?: string;
8
- };
9
- type WithEnvValidation = AdvancedValidation | {
10
- [env: string]: AdvancedValidation | SimpleValidationRule;
11
- };
12
- type Config = {
13
- processEnvKey?: string;
14
- };
15
- /**
16
- * @param envVarsMap
17
- * @param config
18
- * @example
19
- * checkEnvVars({
20
- * NEW_API_KEY: true,
21
- * OLD_API: false,
22
- * ONLY_NON_PROD: ["test", "dev"],
23
- * ONLY_PROD: {
24
- * prod: true,
25
- * },
26
- * APP_ENV: {
27
- * oneOf: ["test", "dev", "prod"],
28
- * },
29
- * STRIPE_KEY: {
30
- * prod: {
31
- * startsWith: "live_key_",
32
- * endsWith: "_end",
33
- * },
34
- * },
35
- * }, {
36
- * processEnvKey: "APP_ENV" // default is "NODE_ENV"
37
- * })
38
- */
39
- declare const checkEnvVars: (envVarsMap: Record<string, SimpleValidationRule | EnvValidation | WithEnvValidation>, config?: Config) => void;
40
-
41
1
  type Coords = {
42
2
  lat: number;
43
3
  lng: number;
@@ -45,7 +5,18 @@ type Coords = {
45
5
 
46
6
  type DateLike = Date | string | number;
47
7
  type Datey = Date | string;
8
+ /**
9
+ * @example "2021-01-01T00:00:00.000Z"
10
+ */
48
11
  type ISODate = string;
12
+ /**
13
+ * @example "2021-01-01"
14
+ */
15
+ type ISODay = string;
16
+ /**
17
+ * @example "America/New_York"
18
+ */
19
+ type Timezone = string;
49
20
  type DateRange = {
50
21
  startDate: DateLike;
51
22
  endDate: DateLike;
@@ -120,6 +91,13 @@ declare const startOfTomorrow: () => Date;
120
91
 
121
92
  declare const formatCamelCase: (str: string) => string;
122
93
 
94
+ /**
95
+ *
96
+ * @example formatCookies({}) => ""
97
+ * @example formatCookies({ session: "123", _ga: 123 }) => "session=123; _ga=123"
98
+ */
99
+ declare const formatCookies: (object: PlainObject) => string;
100
+
123
101
  /**
124
102
  *
125
103
  * @example formatNumber(1000, { compact: true }) // 1K
@@ -200,6 +178,12 @@ declare const enumKeys: <T extends object>(arg: T) => ObjectKeys<T>;
200
178
 
201
179
  declare const enumValues: <T extends object>(enumObject: T) => ObjectValues<T>;
202
180
 
181
+ /**
182
+ * @returns a string with only alphanumeric characters
183
+ * @example filterAlphanumeric("!abc()") // returns "abc"
184
+ */
185
+ declare const filterAlphanumeric: (string: string) => string;
186
+
203
187
  declare const first: <T>(arr?: T[] | undefined) => T | undefined;
204
188
 
205
189
  declare const firstKey: <T extends PlainObject<any>>(arg: T) => keyof T;
@@ -284,12 +268,13 @@ declare const serialize: <T extends PlainObject<any>>(obj: T) => string;
284
268
  * @description Run a series of (async) functions in order and return the results
285
269
  * @example
286
270
  * const results = await seriesAll([
287
- * () => Promise.resolve(1),
288
- * () => sleep(100).then(() => 2),
271
+ * Promise.resolve(1),
272
+ * sleep(100).then(() => 2),
289
273
  * () => Promise.resolve(3),
290
- * ]); => [1, 2, 3]
274
+ * async () => 4,
275
+ * ]); => [1, 2, 3, 4]
291
276
  */
292
- declare const seriesAll: <T>(series: Function[]) => Promise<T[]>;
277
+ declare const seriesAll: <T>(series: (Promise<T> | (() => Promise<T>))[]) => Promise<T[]>;
293
278
 
294
279
  /**
295
280
  * Sets a value in an object using a dot-separated path.
@@ -342,10 +327,25 @@ declare const min: (values: number[]) => number;
342
327
 
343
328
  declare const multiply: (numbers: number[]) => number;
344
329
 
345
- declare const percentageChange: ({ previous, current, }: {
346
- previous: number;
347
- current: number;
348
- }) => number;
330
+ /**
331
+ * Normalises an array of numbers
332
+ * @example normaliseArray([1, 2, 3]) => [0, 0.5, 1]
333
+ */
334
+ declare const normaliseArray: (values: number[]) => number[];
335
+
336
+ /**
337
+ *
338
+ * @example normaliseNumber(50, 0, 100) => 0.5
339
+ */
340
+ declare const normaliseNumber: (value: number, minValue: number, maxValue: number) => number;
341
+
342
+ /**
343
+ *
344
+ * @param previous Positive percentage i.e. 0.1 for 10%
345
+ * @param current Positive percentage i.e. 0.2 for 20%
346
+ * @returns
347
+ */
348
+ declare const percentageChange: (previous: number, current: number) => number;
349
349
 
350
350
  declare const sum: (numbers: number[]) => number;
351
351
 
@@ -418,8 +418,8 @@ declare const randomCoords: () => Coords;
418
418
  declare const randomLat: () => number;
419
419
  declare const randomLng: () => number;
420
420
 
421
- declare const randomDate: (startDate?: DateLike, endDate?: DateLike) => Date;
422
- declare const randomMaxDate: (start?: Date, end?: Date) => Date;
421
+ declare const randomDate: ({ startDate, endDate }?: Partial<DateRange>) => Date;
422
+ declare const randomMaxDate: ({ startDate, endDate }: Partial<DateRange>) => Date;
423
423
  declare const randomFutureDate: ({ startDate, endDate, }?: Partial<DateRange>) => Date;
424
424
  declare const randomPastDate: ({ startDate, endDate, }?: Partial<DateRange>) => Date;
425
425
  declare const randomDateRange: () => {
@@ -463,19 +463,20 @@ declare const randomHtmlColorName: () => string;
463
463
 
464
464
  declare const randomIBAN: () => string;
465
465
 
466
- declare const randomInt: (min?: number, max?: number) => number;
467
- declare const randomPositiveInt: (max?: number) => number;
468
- declare const randomNegativeInt: (min?: number) => number;
469
- declare const randomMaxSafeInt: () => number;
470
- declare const randomMaxInt: () => number;
471
- declare const randomPercentage: ({ min, max, }?: {
466
+ declare const randomInt: ({ min, max, }?: {
467
+ min?: number | undefined;
468
+ max?: number | undefined;
469
+ }) => number;
470
+ declare const randomPositiveInt: ({ min, max, }?: {
472
471
  min?: number | undefined;
473
472
  max?: number | undefined;
474
473
  }) => number;
475
- declare const randomPositivePercentage: ({ min, max, }?: {
474
+ declare const randomNegativeInt: ({ min, max, }?: {
476
475
  min?: number | undefined;
477
476
  max?: number | undefined;
478
477
  }) => number;
478
+ declare const randomMaxSafeInt: () => number;
479
+ declare const randomMaxInt: () => number;
479
480
  declare const randomFormattedPercentage: () => string;
480
481
 
481
482
  declare const randomIP: () => string;
@@ -567,6 +568,9 @@ declare const isEmptyObject: (arg: PlainObject) => boolean;
567
568
 
568
569
  declare const isFile: (arg?: any) => arg is File;
569
570
 
571
+ /**
572
+ * @returns true if the argument can be called like a function -> fn() or await fn()
573
+ */
570
574
  declare const isFunction: (arg: any) => arg is Function;
571
575
 
572
576
  declare const isFutureDate: (arg: DateLike) => boolean;
@@ -633,4 +637,4 @@ declare const isUUID: (arg: string) => boolean;
633
637
 
634
638
  declare const isValue: (arg?: Maybe<any>) => boolean;
635
639
 
636
- export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, ISODate, 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, isOver18, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isStrictlyBetween, 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, startOfDay, startOfNextMonth, startOfNextWeek, startOfThisWeek, startOfToday, startOfTomorrow, stringToCSSUnicode, stringToUnicode, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };
640
+ export { BoolMap, Coords, DateLike, DateRange, Datey, Dimensions, HashMap, ISODate, ISODay, JS_MAX_DIGITS, Key, Matrix, Maybe, MaybePromise, MaybePromiseOrValue, MaybePromiseOrValueArray, NonUndefined, NumberMap, ObjectEntries, ObjectEntry, ObjectKey, ObjectKeys, ObjectValue, ObjectValues, PlainKey, PlainObject, Point, PrismaSelect, Serialized, StringMap, Timezone, TrueMap, WithDatey, array, arrayDiff, arrayIntersection, average, capitalize, chunkArray, chunkedAll, chunkedAsync, clamp, cleanSpaces, cyclicalItem, dir, enumKeys, enumValues, filterAlphanumeric, first, firstKey, firstValue, formatCamelCase, formatCookies, 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, isOver18, isPWA, isPastDate, isPositive, isPositiveInt, isPromise, isReactElement, isRegExp, isSame, isServer, isSpacedString, isStrictlyBetween, isString, isStringDate, isURL, isUUID, isValue, keysLength, last, lastIndex, max, merge, mergeArrays, min, moveToFirst, moveToLast, multiply, normaliseArray, normaliseNumber, 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, randomPhoneNumber, randomPositiveInt, randomString, randomUUID, randomVerb, randomWord, scrambleText, serialize, seriesAll, setObjectPath, setUrlSearchParams, shuffle, sleep, startOfDay, startOfNextMonth, startOfNextWeek, startOfThisWeek, startOfToday, startOfTomorrow, stringToCSSUnicode, stringToUnicode, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };