deverything 3.1.1 → 3.3.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
@@ -7,6 +7,7 @@ The promise:
7
7
  - **✅ 1 package**: say goodbye to lodash, faker, and the other package you don't recall the name of.
8
8
  - **⭕ 0 dependencies**: keep it simple and lightweight.
9
9
  - **🏆 Pick the best**: the code is minimal and uses the best practices for max performance.
10
+ - **🤖 AI**: Functions are reviewed by AI to make sure all corner cases are covered.
10
11
  - **👪🏼 Typescript**: use it, support it and export it.
11
12
  - **🌊 Intuitive**: favour always the most intuitive API and common usage, _never_ throw error unless asked to.
12
13
  - **🙈 Semantic**: use simple function names that are easy to remember, no complicated options.
@@ -16,6 +17,7 @@ Contributions always welcome!
16
17
  ### Validators
17
18
 
18
19
  - `isArray()`
20
+ - `isArrayIncluded()`
19
21
  - `isBoolean()`
20
22
  - `isBrowser()` to detect if you are on the browser
21
23
  - `isBuffer()` if it's a buffer
@@ -41,6 +43,7 @@ Contributions always welcome!
41
43
  - `isPositiveInt()`
42
44
  - `isNegativeInt()`
43
45
  - `isNumeric()` if string is representing a number
46
+ - `isNumericId()` if it's a valid numeric ID
44
47
  - ⭐ `isObject()` if it's a js plain Object
45
48
  - `isPromise()` if it's a promise
46
49
  - `isPWA()` to detect if you are on a PWA
@@ -49,18 +52,24 @@ Contributions always welcome!
49
52
  - ⭐ `isSame()` Compare if dates, functions, arrays, objects or anything else are the same
50
53
  - `isSequence()` if the array is a perfect sequence
51
54
  - `isServer()` if you are on the server
55
+ - `isSpacedString()` if string contains spaces
52
56
  - `isString()`
53
57
  - `isURL()`
54
58
  - `isUUID()` if it's a valid UUID
59
+ - `isValue()` if it's a defined value (not null, undefined, or empty string)
55
60
 
56
61
  ### Dates
57
62
 
63
+ - `getDateRangeSeries()` generate a series of dates within a range
58
64
  - `isOver18()`
65
+ - `startOfDay()` get the start of a specific day
59
66
  - `startOfNextMonth()`
60
67
  - `startOfNextWeek()`
61
68
  - `startOfThisWeek()`
62
69
  - `startOfToday()`
63
70
  - `startOfTomorrow()`
71
+ - `startOfUTCDay()` get the start of a specific day in UTC
72
+ - `startOfUTCTomorrow()` get the start of tomorrow in UTC
64
73
 
65
74
  ### Math
66
75
 
@@ -82,14 +91,22 @@ Contributions always welcome!
82
91
  - `arrayDiff()` get the difference of two arrays
83
92
  - `arrayIntersection()` get the intersection of two arrays
84
93
  - `capitalize()` word => Word
94
+ - `chunkArray()` split array into chunks
95
+ - `chunkedAll()` process all items in chunks
96
+ - `chunkedAsync()` process async operations in chunks
97
+ - `chunkedDynamic()` process with dynamic chunk sizes
85
98
  - `clamp()` clamp number in a range
86
99
  - `cleanSpaces()` trims and turns double spaces into single space
100
+ - `cyclicalItem()` get item from array with cyclical indexing
101
+ - `dir()` get directory listing
87
102
  - `enumKeys()` enum FRUIT { APPLE, PEAR } => ["APPLE", "PEAR"]
88
103
  - `enumValues()` enum FRUIT { APPLE = 1, PEAR = 3 } => [1, 3]
89
104
  - `filterAlphanumeric()` remove non-alphanumeric characters
90
105
  - `first()` get the first element of an array
91
106
  - `firstKey()` get the first key of an object
92
107
  - `firstValue()` get the first value of an object
108
+ - `getCookieByName()` get cookie value by name
109
+ - `getKeys()` get all keys from an object
93
110
  - `getUrlSearchParam()` get URL search param
94
111
  - `getUrlSearchParams()` get URL search params
95
112
  - `groupByKey()`
@@ -99,15 +116,21 @@ Contributions always welcome!
99
116
  - `lastIndex()` get the last index of an array
100
117
  - `mapByKey()`
101
118
  - ⭐ `merge()` deep merge objects
119
+ - `mergeArrays()` merge multiple arrays
102
120
  - `moveToFirst()` move array element to first
103
121
  - `moveToIndex()` move array element to desired index
104
122
  - `moveToLast()` move array element to last
105
123
  - `normalizeNumber()` normalizes between 0 and 1
106
124
  - `objectDiff()` get the difference between two objects
125
+ - `omit()` omit properties from object
107
126
  - ⭐ `parseDate()` pass anything Date-Like, and get a JS Date back
127
+ - `pickObjectKeys()` pick specific keys from object
128
+ - `pickObjectValues()` pick specific values from object
108
129
  - `pluck()` make array of value from object keys
109
130
  - `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.
131
+ - `removeUndefinedValues()` remove undefined values from object
110
132
  - `scrambleText()` replace alpha chars with random chars
133
+ - `serialize()` serialize object to string
111
134
  - `seriesAsync()` executes promises in series, and returns all results
112
135
  - `setObjectPath()` set a value in an object by path
113
136
  - `setUrlSearchParams()` set URL search params
@@ -125,6 +148,7 @@ Contributions always welcome!
125
148
  - `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
126
149
  - `formatPercentage()` 0.11 => "11%"
127
150
  - `formatIndexProgress()` => "[2/10]"
151
+ - `formatProgress()` format progress as percentage
128
152
  - `stringToCSSUnicode()` "hello" => "\000068\000065\00006c\00006c\00006f" use this for CSS
129
153
  - `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
130
154
 
@@ -150,6 +174,7 @@ These functions are optimized for low entropy random data generation useful for
150
174
  - `randomDateRange()` => { startDate, endDate }
151
175
  - `randomEmail()`
152
176
  - `randomEmoji()`
177
+ - `randomEmptyValue()` random empty value (null, undefined, empty string)
153
178
  - `randomEnumKey()` enum FRUIT { APPLE, PEAR } => APPLE
154
179
  - `randomEnumValue()` enum FRUIT { APPLE = 1, PEAR = 3 } => 3
155
180
  - `randomFile()`
@@ -189,29 +214,27 @@ These functions are optimized for low entropy random data generation useful for
189
214
  - `DateLike`
190
215
  - `Defined<T>`
191
216
  - `Dimensions`
217
+ - `Function`
192
218
  - `HashMap<>`
193
219
  - `BoolMap`
194
220
  - `NumberMap`
195
221
  - `StringMap`
196
222
  - `TrueMap`
197
223
  - `Key`
224
+ - `Matrix`
198
225
  - `Maybe<>`
199
226
  - `MaybePromise<>`
200
227
  - `MaybePromiseOrValue<>`
201
228
  - `MaybePromiseOrValueArray<>`
202
229
  - `NonUndefined`
203
- - `ObjectEntries<>`
204
- - `ObjectEntry<>`
205
- - `ObjectKey<>`
206
- - `ObjectKeys<>`
207
- - `ObjectValue<>`
208
- - `ObjectValues<>`
209
- - ⭐ `PlainObject` use this instead of `Record<,>` or `extends object`, also makes sure it's not an array
230
+ - `Object`
210
231
  - `PickDefined<T, K>`
211
232
  - `PickRequired<T, K>`
212
233
  - `PlainKey`
213
234
  - `Point`
214
- - `VoidFn`
235
+ - `PrismaSelect`
236
+ - `Serialized`
237
+ - `Tuple`
215
238
 
216
239
  ## Development
217
240
 
package/dist/index.d.ts CHANGED
@@ -25,10 +25,11 @@ type ISOYear = string;
25
25
  * @example "America/New_York"
26
26
  */
27
27
  type Timezone = string;
28
- type DateRange = {
29
- startDate: DateLike;
30
- endDate: DateLike;
28
+ type DateRange<T extends DateLike = DateLike> = {
29
+ startDate: T;
30
+ endDate: T;
31
31
  };
32
+ type DateSeries<T extends DateLike = DateLike> = T[];
32
33
 
33
34
  /**
34
35
  * Makes all keys required and removes undefined and null from the value types.
@@ -144,7 +145,7 @@ type Serialized<T> = T extends Date ? string : T extends Array<infer R> ? Array<
144
145
  * @description Generate a series of dates between the start and end dates
145
146
  * NOTE: it does NOT include the end date
146
147
  */
147
- declare const getDateRangeSeries: (dateRange: DateRange, unit: "days" | "hours" | "minutes" | "seconds") => ISODate[];
148
+ declare const getDateRangeSeries: (dateRange: DateRange, unit: "day" | "hour" | "minute" | "second" | "calendarMonth") => ISODate[];
148
149
 
149
150
  /**
150
151
  *
@@ -152,8 +153,22 @@ declare const getDateRangeSeries: (dateRange: DateRange, unit: "days" | "hours"
152
153
  */
153
154
  declare const getDateSeries: (startDate: Date, endDate: Date, unit: "days" | "hours" | "minutes" | "seconds") => ISODate[];
154
155
 
156
+ /**
157
+ * @description Returns the smallest and biggest dates from an array of dates in DateRange format
158
+ * @param dates - Array of dates to find the range for
159
+ * @returns DateRange object with startDate (smallest) and endDate (biggest)
160
+ * @throws Error if the array is empty or contains invalid dates
161
+ */
162
+ declare const getDateSeriesRange: (dateSeries: DateSeries<DateLike>) => DateRange;
163
+
155
164
  declare const isOver18: (birthDate: DateLike) => boolean;
156
165
 
166
+ /**
167
+ * Note: This function does not use defaults, use startOfToday instead.
168
+ *
169
+ * @param day - The date to get the start of the day for.
170
+ * @returns A new Date object set to the start of the day.
171
+ */
157
172
  declare const startOfDay: (day: Date) => Date;
158
173
 
159
174
  declare const startOfNextMonth: () => Date;
@@ -168,6 +183,14 @@ declare const startOfTomorrow: () => Date;
168
183
 
169
184
  declare const startOfUTCDay: (date: Date) => Date;
170
185
 
186
+ /**
187
+ * Returns the start of tomorrow (00:00:00.000) in UTC time.
188
+ *
189
+ * @param date - The date to calculate tomorrow from. Defaults to current date if not provided.
190
+ * @returns A new Date object set to the start of tomorrow in UTC time.
191
+ */
192
+ declare const startOfUTCTomorrow: () => Date;
193
+
171
194
  declare const formatCamelCase: (str: string) => string;
172
195
 
173
196
  /**
@@ -848,4 +871,4 @@ declare const isUUID: (arg: string) => boolean;
848
871
 
849
872
  declare const isValue: <T>(arg?: Maybe<T>) => arg is T;
850
873
 
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 };
874
+ export { BoolMap, Coords, DateLike, DateRange, DateSeries, 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, getDateSeriesRange, 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, startOfUTCTomorrow, stringToCSSUnicode, stringToUnicode, stringify, sum, toggleArray, toggleArrayValue, truncate, uniqueValues };