You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* 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.
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
+
exportconst parseArray = (
11
+
str:string,
12
+
options?: { separator?:string }
13
+
): string[] => {
14
+
// ...
15
+
};
16
+
```
17
+
18
+
**Avoid**
19
+
20
+
```ts
21
+
exportfunction 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
+
exportconst 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)
- ⭐ `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
132
141
-`pickObjectKeys()` pick specific keys from object
133
142
-`pickObjectValues()` pick specific values from object
134
143
-`pluck()` make array of value from object keys
144
+
-`prismaDateRange()``{ gte, lt }` window from a start/end range for Prisma filters
135
145
-`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.
136
146
-`removeUndefinedValues()` remove undefined values from object
137
147
-`scrambleText()` replace alpha chars with random chars
138
148
-`serialize()` serialize object to string
139
149
-`seriesAsync()` executes promises in series, and returns all results
140
150
-`setObjectPath()` set a value in an object by path
141
151
-`setUrlSearchParams()` set URL search params
152
+
-`formatTrpcInputQueryString()` serialize a tRPC procedure input to `URLSearchParams`
142
153
-`shuffle()` shuffles elements in an array
154
+
-`singleton()` lazily-initialized singleton from a factory (sync or async)
143
155
-`sleep()` promise-based sleep
144
156
-`stringify()` stringify anything, without breaking on circular dependencies
0 commit comments