|
1 |
| -## New Functions |
2 |
| - |
3 |
| -### Add `isClass` function [→ PR #239](https://github.com/radashi-org/radashi/pull/239) |
4 |
| - |
5 |
| -The `isClass` function determines if a value was declared using ES6 `class` syntax, distinguishing modern class declarations from traditional constructor functions or other types. |
6 |
| - |
7 |
| -- Only returns `true` for values created with the `class` keyword |
8 |
| -- Old-style constructor functions will return `false` |
9 |
| -- Built-in native class constructors (like `Error`) return `false` |
10 |
| -- Works with type narrowing for TypeScript |
11 |
| - |
12 |
| -```typescript |
13 |
| -import * as _ from 'radashi' |
14 |
| - |
15 |
| -class MyClass { |
16 |
| - x = 1 |
17 |
| -} |
18 |
| - |
19 |
| -function OldConstructor() { |
20 |
| - this.x = 1 |
21 |
| -} |
22 |
| - |
23 |
| -// Examples |
24 |
| -_.isClass(MyClass) // true |
25 |
| -_.isClass(OldConstructor) // false |
26 |
| -_.isClass('string') // false |
27 |
| -_.isClass(Error) // false |
28 |
| -``` |
29 |
| - |
30 |
| -Thanks to [Marlon Passos](https://github.com/MarlonPassos-git) and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
31 |
| - |
32 |
| -🔗 [Docs](https://radashi.js.org/reference/typed/isClass) / [Source](https://github.com/radashi-org/radashi/blob/main/src/typed/isClass.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/typed/isClass.test.ts) |
33 |
| - |
34 |
| -### Add `isNullish` function [→ PR #277](https://github.com/radashi-org/radashi/pull/277) |
35 |
| - |
36 |
| -The `isNullish` function is a type-checking utility that determines whether a given value is either `null` or `undefined`. It helps you avoid the typos that an `x == null` check is prone to, and it's shorter to write than `x === undefined || x === null`. |
37 |
| - |
38 |
| -```ts |
39 |
| -import * as _ from 'radashi' |
40 |
| - |
41 |
| -// Basic usage examples |
42 |
| -_.isNullish(null) // true |
43 |
| -_.isNullish(undefined) // true |
44 |
| -_.isNullish('') // false |
45 |
| -_.isNullish([]) // false |
46 |
| -_.isNullish(0) // false |
47 |
| -``` |
48 |
| - |
49 |
| -Thanks to [Wei Xiaopeng](https://github.com/ilxqx) for their work on this feature! |
50 |
| - |
51 |
| -🔗 [Docs](https://radashi.js.org/reference/typed/isNullish) / [Source](https://github.com/radashi-org/radashi/blob/main/src/typed/isNullish.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/typed/isNullish.test.ts) |
52 |
| - |
53 |
| -### Add `cartesianProduct` function [→ PR #241](https://github.com/radashi-org/radashi/pull/241) |
54 |
| - |
55 |
| -The `cartesianProduct` function generates all possible combinations of elements from multiple input arrays, creating a new array containing every unique permutation of elements from those arrays. |
56 |
| - |
57 |
| -- Works with any number of input arrays |
58 |
| -- Returns an array of arrays representing all combinations |
59 |
| -- Preserves the order of input arrays in the resulting combinations |
60 |
| -- Can handle arrays of different types |
61 |
| - |
62 |
| -```typescript |
63 |
| -import * as _ from 'radashi' |
64 |
| - |
65 |
| -const colors = ['red', 'blue'] |
66 |
| -const numbers = [1, 2, 3] |
67 |
| -const booleans = [true, false] |
68 |
| - |
69 |
| -// Generate all combinations of colors, numbers, and booleans |
70 |
| -const combinations = _.cartesianProduct(colors, numbers, booleans) |
71 |
| -``` |
72 |
| - |
73 |
| -Thanks to [Yam Borodetsky](https://github.com/yamcodes), [Marlon Passos](https://github.com/MarlonPassos-git), and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
74 |
| - |
75 |
| -🔗 [Docs](https://radashi.js.org/reference/array/cartesianProduct) / [Source](https://github.com/radashi-org/radashi/blob/main/src/array/cartesianProduct.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/array/cartesianProduct.test.ts) |
76 |
| - |
77 |
| -### Add `isUndefined` function [→ PR #305](https://github.com/radashi-org/radashi/pull/305) |
78 |
| - |
79 |
| -The `isUndefined` function is a type guard that checks whether a given value is specifically `undefined`. It provides a simple and type-safe way to determine if a value has been left unassigned or is explicitly set to `undefined`. |
80 |
| - |
81 |
| -- Strictly checks for `undefined` using the `typeof` operator |
82 |
| -- Can be used for type narrowing in TypeScript |
83 |
| - |
84 |
| -```typescript |
85 |
| -import * as _ from 'radashi' |
86 |
| - |
87 |
| -// Basic usage examples |
88 |
| -const result1 = _.isUndefined(undefined) // true |
89 |
| -const result2 = _.isUndefined(null) // false |
90 |
| -const result3 = _.isUndefined(42) // false |
91 |
| -``` |
92 |
| - |
93 |
| -Thanks to [RobinBobin](https://github.com/RobinBobin) for their work on this feature! |
94 |
| - |
95 |
| -🔗 [Docs](https://radashi.js.org/reference/typed/isUndefined) / [Source](https://github.com/radashi-org/radashi/blob/main/src/typed/isUndefined.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/typed/isUndefined.test.ts) |
96 |
| - |
97 |
| -### Add `timeout` function [→ PR #250](https://github.com/radashi-org/radashi/pull/250) |
98 |
| - |
99 |
| -The `timeout` function creates a promise that rejects after a specified delay, providing a way to set timeouts for asynchronous operations. It allows customizing the error message or type of error thrown when the timeout occurs. |
100 |
| - |
101 |
| -- Can be used with a default `TimeoutError` or a custom error message/function |
102 |
| -- Primarily useful with `Promise.race` to add timeout functionality to async tasks |
| 1 | +If you open a PR that introduces a new function, add it to the "New Functions" section. If you're extending an existing function, add it to the "New Features" section. |
103 | 2 |
|
104 |
| -```typescript |
105 |
| -import * as _ from 'radashi' |
| 3 | +The `####` headline should be short and descriptive of the new functionality. In the body of the section, include a link to the PR. You don't need to include a description of the change itself, as we will extract that from the documentation. |
106 | 4 |
|
107 |
| -// Basic usage: reject after 1 second with default TimeoutError |
108 |
| -const basicTimeout = _.timeout(1000) |
109 |
| - |
110 |
| -// With custom message |
111 |
| -const customMessageTimeout = _.timeout(1000, 'Operation took too long') |
112 |
| - |
113 |
| -// With Promise.race to limit async task duration |
114 |
| -const someAsyncTask = async () => { |
115 |
| - await _.sleep(5000) // Simulate a long-running task |
116 |
| - return 'Task completed' |
117 |
| -} |
118 |
| - |
119 |
| -// Will reject after 1 second if task doesn't complete |
120 |
| -const racedTask = await Promise.race([ |
121 |
| - someAsyncTask(), |
122 |
| - _.timeout(1000, 'Task exceeded time limit'), |
123 |
| -]) |
124 |
| -``` |
125 |
| - |
126 |
| -Thanks to [Marlon Passos](https://github.com/MarlonPassos-git) and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
127 |
| - |
128 |
| -🔗 [Docs](https://radashi.js.org/reference/async/TimeoutError) / [Source](https://github.com/radashi-org/radashi/blob/main/src/async/TimeoutError.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/async/TimeoutError.test.ts) |
129 |
| - |
130 |
| -### Add `dedent` function [→ PR #120](https://github.com/radashi-org/radashi/pull/120) |
131 |
| - |
132 |
| -The `dedent` function removes indentation from a multi-line string, making it easy to format and clean up text templates while preserving the relative indentation of embedded content. |
133 |
| - |
134 |
| -- Supports both explicit and auto-detected indentation |
135 |
| -- Works with tagged template strings |
136 |
| -- Automatically handles multi-line embedded strings |
137 |
| -- Removes the first leading and first trailing empty line |
138 |
| -- Preserves relative indentation of content |
139 |
| - |
140 |
| -```typescript |
141 |
| -import * as _ from 'radashi' |
142 |
| - |
143 |
| -// Remove auto-detected indentation |
144 |
| -const message = _.dedent` |
145 |
| - Hello, world! |
146 |
| - This is a dedented message. |
147 |
| -` |
148 |
| -// => 'Hello, world!\nThis is a dedented message.' |
149 |
| - |
150 |
| -// Remove specific indentation |
151 |
| -const customMessage = _.dedent('\n Hello\n World!\n\n', ' ') |
152 |
| -// => ' Hello\n World!\n' |
153 |
| -``` |
154 |
| - |
155 |
| -Thanks to [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
| 5 | +## New Functions |
156 | 6 |
|
157 |
| -🔗 [Docs](https://radashi.js.org/reference/string/dedent) / [Source](https://github.com/radashi-org/radashi/blob/main/src/string/dedent.ts) / [Tests](https://github.com/radashi-org/radashi/blob/main/tests/string/dedent.test.ts) |
| 7 | +#### |
158 | 8 |
|
159 | 9 | ## New Features
|
160 | 10 |
|
161 |
| -### Add `signal` option to `retry` [→ PR #262](https://github.com/radashi-org/radashi/pull/262) |
162 |
| - |
163 |
| -The new feature introduces an optional `signal` parameter to both the `retry` function, allowing for manual interruption of async operations using `AbortController`. |
164 |
| - |
165 |
| -- The `signal` option accepts an `AbortController.signal` |
166 |
| -- When the signal is aborted, no more calls to the callback will be made |
167 |
| -- Aborting will throw a `DOMException` with the message "This operation was aborted" |
168 |
| -- Works consistently across Node.js and browser environments |
169 |
| - |
170 |
| -```typescript |
171 |
| -import * as _ from 'radashi' |
172 |
| - |
173 |
| -const abortController = new AbortController() |
174 |
| -const signal = abortController.signal |
175 |
| - |
176 |
| -const promise = _.retry( |
177 |
| - { times: 3, delay: 1000, signal }, |
178 |
| - async () => await fetchSomeData(), |
179 |
| -) |
180 |
| - |
181 |
| -// To abort the operation: |
182 |
| -abortController.abort() |
183 |
| -``` |
184 |
| - |
185 |
| -Thanks to [ts-saidbe.abdiganiev](https://github.com/SaidbekAbdiganiev) and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
186 |
| - |
187 |
| -### Add `signal` option to `parallel` [→ PR #262](https://github.com/radashi-org/radashi/pull/262) |
188 |
| - |
189 |
| -The latest update adds an optional `signal` option to the `parallel` function, allowing you to interrupt parallel processing with an `AbortController`. |
190 |
| - |
191 |
| -- The `signal` option works with an `AbortController.signal` |
192 |
| -- When aborted, it will throw a `DOMException` with an `"AbortError"` name |
193 |
| -- Interruption only stops future iterations, not in-progress async calls |
194 |
| -- Signals are compatible with both browser and Node.js environments |
195 |
| - |
196 |
| -```typescript |
197 |
| -import * as _ from 'radashi' |
198 |
| - |
199 |
| -// Abort a parallel operation |
200 |
| -const abortController = new AbortController() |
201 |
| -const signal = abortController.signal |
202 |
| - |
203 |
| -const pizzas = await _.parallel( |
204 |
| - { limit: 2, signal }, |
205 |
| - ['pepperoni', 'cheese', 'mushroom'], |
206 |
| - async topping => { |
207 |
| - return await bakePizzaInWoodFiredOven(topping) |
208 |
| - }, |
209 |
| -) |
210 |
| - |
211 |
| -// Abort the operation if needed |
212 |
| -abortController.abort() |
213 |
| -``` |
214 |
| - |
215 |
| -Thanks to [ts-saidbe.abdiganiev](https://github.com/SaidbekAbdiganiev) and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
216 |
| - |
217 |
| -### Tolerate out-of-range `parallel` limit [→ PR #238](https://github.com/radashi-org/radashi/pull/238) |
218 |
| - |
219 |
| -The `parallel` function now automatically clamps the concurrency limit between 1 and the input array's length, ensuring more predictable and safe parallel processing. |
220 |
| - |
221 |
| -- Previously, passing a limit larger than the array length or less than 1 could cause unexpected behavior |
222 |
| -- The limit is now automatically adjusted to be within the valid range |
223 |
| - |
224 |
| -```typescript |
225 |
| -import * as _ from 'radashi' |
226 |
| - |
227 |
| -// Limit will be adjusted to 3 (array length) |
228 |
| -const results = await _.parallel( |
229 |
| - 10, |
230 |
| - ['item1', 'item2', 'item3'], |
231 |
| - async item => { |
232 |
| - // Process each item |
233 |
| - return item.toUpperCase() |
234 |
| - }, |
235 |
| -) |
236 |
| -``` |
237 |
| - |
238 |
| -Thanks to [Marlon Passos](https://github.com/MarlonPassos-git) and [Alec Larson](https://github.com/aleclarson) for their work on this feature! |
| 11 | +#### |
0 commit comments