Skip to content

Commit c220183

Browse files
authored
A bunch of new helpers (#38)
* A bunch of new helpers * Enhance parsePrimitive function to support boolean coercion and add corresponding tests. Updated function signature to accept options for boolean mapping and expanded test cases for various input scenarios. * Implement unique value filtering in parseArray function and add corresponding tests. Updated function signature to accept an options object for separator and uniqueValues. Enhanced filtering logic to support duplicate removal based on the uniqueValues option. * Remove deprecated bucketSortedDates function and its tests. Update README.md to include new utility functions and enhancements for date and string formatting, as well as random data generation. * Reintroduce startOfYesterday export in dates module * Update version to 5.0.0 and modify CHANGELOG.md to reflect major changes, including the removal of `bucketSortedDates` and `objectDiff`, and the addition of `parseArray` and `parsePrimitive` functions.
1 parent 99761af commit c220183

17 files changed

Lines changed: 318 additions & 443 deletions

AGENTS.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Agent guidance — deverything
2+
3+
## Prefer `const` over `function`
4+
5+
Define exported helpers with **`const` and an arrow function** (or `const` + function expression) rather than a `function` declaration. Keeps style consistent and avoids hoisting surprises.
6+
7+
**Good**
8+
9+
```ts
10+
export const parseArray = (
11+
str: string,
12+
options?: { separator?: string }
13+
): string[] => {
14+
// ...
15+
};
16+
```
17+
18+
**Avoid**
19+
20+
```ts
21+
export function parseArray(
22+
str: string,
23+
options?: { separator?: string }
24+
): string[] {
25+
// ...
26+
}
27+
```
28+
29+
## Function parameters: options as objects
30+
31+
For helpers that accept configuration beyond the primary input (or where more knobs may be added later), use a single **options object** as the last argument instead of extra positional parameters.
32+
33+
- Defaults belong on that object (e.g. `separator` defaulting to `","`).
34+
- Document option keys in JSDoc on the `options` parameter or per-field.
35+
36+
**Good**
37+
38+
```ts
39+
export const parseArray = (
40+
str: string,
41+
options?: { separator?: string }
42+
): string[] => {
43+
const { separator = "," } = options ?? {};
44+
// ...
45+
};
46+
```
47+
48+
**Avoid** (positional config — harder to extend and to call with partial overrides)
49+
50+
```ts
51+
export const parseArray = (str: string, separator = ","): string[] => {
52+
// ...
53+
};
54+
```
55+
56+
The primary value (`str`, `id`, etc.) stays the first argument; everything else goes in `options`.

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# deverything
22

3+
## 5.0.0
4+
5+
### Major Changes
6+
7+
- dropped and added, so major version
8+
- `bucketSortedDates` REMOVED
9+
- `objectDiff` REMOVED
10+
- parseArray and parsePrimitive added
11+
312
## 4.10.2
413

514
### Patch Changes

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ Contributions always welcome!
3131
- `isFunction()`
3232
- `isJsDate()` if it's a **valid** javascript's Date
3333
- `isBetweenDates()` check if date falls between two other dates (left inclusive: includes start, excludes end)
34+
- `isInDateRange()` alias of `isBetweenDates()`
3435
- `isFutureDate()` check if date is in the future, optionally against a reference date
3536
- `isPastDate()` check if date is in the past, optionally against a reference date
37+
- `isSameUTCDay()` same calendar day in UTC
3638
- `isStringDate()` also checks if the string passed is a **valid** date
3739
- `isKey()` is a real key of an object
3840
- `isLastIndex()` is the index is the last item of array
@@ -43,6 +45,9 @@ Contributions always welcome!
4345
- `isOdd()`
4446
- `isPositiveInt()`
4547
- `isNegativeInt()`
48+
- `isBigInt()` if the arg is a bigint
49+
- `isBigIntString()` if the string is a valid bigint literal
50+
- `isOutsideInt4()` if a number is outside PostgreSQL `int4` range
4651
- `isNumeric()` if string is representing a number
4752
- `isNumericId()` if it's a valid numeric ID
4853
-`isObject()` if it's a js plain Object
@@ -71,6 +76,7 @@ Contributions always welcome!
7176
- `startOfThisWeek()`
7277
- `startOfToday()`
7378
- `startOfTomorrow()`
79+
- `startOfYesterday()`
7480
- `startOfUTCDay()` get the start of a specific day in UTC
7581
- `startOfUTCTomorrow()` get the start of tomorrow in UTC
7682

@@ -126,20 +132,26 @@ Contributions always welcome!
126132
- `moveToIndex()` move array element to desired index
127133
- `moveToLast()` move array element to last
128134
- `normalizeNumber()` normalizes between 0 and 1
129-
- `objectDiff()` get the difference between two objects
135+
- `normalizeString()` trim, strip diacritics (Unicode NFD), lowercase
136+
- `noop()` no-op function
130137
- `omit()` omit properties from object
131138
-`parseDate()` pass anything Date-Like, and get a JS Date back
139+
- `parseArray()` split a string into parsed primitives (comma-separated by default)
140+
- `parsePrimitive()` coerce a string to boolean, number, null, undefined, or trimmed string
132141
- `pickObjectKeys()` pick specific keys from object
133142
- `pickObjectValues()` pick specific values from object
134143
- `pluck()` make array of value from object keys
144+
- `prismaDateRange()` `{ gte, lt }` window from a start/end range for Prisma filters
135145
- `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.
136146
- `removeUndefinedValues()` remove undefined values from object
137147
- `scrambleText()` replace alpha chars with random chars
138148
- `serialize()` serialize object to string
139149
- `seriesAsync()` executes promises in series, and returns all results
140150
- `setObjectPath()` set a value in an object by path
141151
- `setUrlSearchParams()` set URL search params
152+
- `formatTrpcInputQueryString()` serialize a tRPC procedure input to `URLSearchParams`
142153
- `shuffle()` shuffles elements in an array
154+
- `singleton()` lazily-initialized singleton from a factory (sync or async)
143155
- `sleep()` promise-based sleep
144156
- `stringify()` stringify anything, without breaking on circular dependencies
145157
- `toggleArrayValue()` remove/add value in array
@@ -153,9 +165,11 @@ Contributions always welcome!
153165
- `formatCount()` "#items: 3, #users: 5"
154166
- `formatDateRange()` "2026-02-09T00:00... ⮕ 2026-02-10T00:00..."
155167
- `formatIndexProgress()` => "[2/10]"
168+
- `formatProgress()` progress string with optional id prefix
156169
- `formatNumber()` 1000 => "1,000" or "1K" or 0.112 => "11.2%"
157170
- `formatPascalCase()` "hello-world" => "HelloWorld"
158171
- `formatPercentage()` 0.11 => "11%"
172+
- `formatPercentageNumber()` numeric percentage (e.g. 0.123 => 12.35) before formatting as string
159173
- `stringToCSSUnicode()` "hello" => "\000068\000065\00006c\00006c\00006f" use this for CSS
160174
- `stringToUnicode()` "hello" => "\u0068\u0065\u006c\u006c\u006f"
161175

@@ -186,6 +200,7 @@ These functions are optimized for low entropy random data generation useful for
186200
- `randomEnumValue()` enum FRUIT { APPLE = 1, PEAR = 3 } => 3
187201
- `randomFile()`
188202
- `randomFloat()`
203+
- `randomFormattedPercentage()` random percentage string for tests
189204
- `randomObject()`
190205
- `randomObjectKey()` get a random key from an object
191206
- `randomObjectValue()` get a random value from an object
@@ -216,6 +231,8 @@ These functions are optimized for low entropy random data generation useful for
216231
- `randomUUID()` lightweight uuid generation, passing UUID validation
217232
- `randomValue()`
218233
- `randomWord()`
234+
- `randomNoun()`
235+
- `randomVerb()`
219236

220237
### TypeScript Helpers & Generics
221238

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "deverything",
3-
"version": "4.10.2",
3+
"version": "5.0.0",
44
"description": "Everything you need for Dev",
55
"main": "./dist/index.js",
66
"module": "./dist/index.mjs",

0 commit comments

Comments
 (0)