radashi 13.0.4 → 13.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 +10 -1
- package/dist/radashi.cjs +50 -40
- package/dist/radashi.d.cts +21 -10
- package/dist/radashi.d.ts +21 -10
- package/dist/radashi.js +50 -40
- package/package.json +3 -2
- package/skills/radashi/SKILL.md +32 -0
- package/skills/radashi/agents/openai.yaml +4 -0
package/README.md
CHANGED
|
@@ -96,6 +96,16 @@ jsr add @radashi-org/radashi
|
|
|
96
96
|
deno add jsr:@radashi-org/radashi
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
### Agent skills
|
|
100
|
+
|
|
101
|
+
Radashi includes an agent skill for AI coding assistants in `skills/radashi/SKILL.md`.
|
|
102
|
+
|
|
103
|
+
Package managers supporting dependency-provided agent skills (such as [pnpm](https://pnpm.io/agent-skills) v12.11+) can discover and link the skill into your project's agent directories upon approval:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
pnpm approve
|
|
107
|
+
```
|
|
108
|
+
|
|
99
109
|
<img src="https://github.com/radashi-org/radashi/raw/main/.github/img/rule.png" width="100%" />
|
|
100
110
|
|
|
101
111
|
## FAQ
|
|
@@ -127,7 +137,6 @@ deno add jsr:@radashi-org/radashi
|
|
|
127
137
|
|
|
128
138
|
- **Automatic releases**
|
|
129
139
|
To ensure contributions are quickly rolled out, we have the following automatic processes:
|
|
130
|
-
|
|
131
140
|
- **Patch releases**
|
|
132
141
|
Whenever the `main` branch receives a `^fix:` commit, a patch release is immediately published to NPM.
|
|
133
142
|
|
package/dist/radashi.cjs
CHANGED
|
@@ -496,16 +496,22 @@ function queueByKey(asyncFn, keyFn) {
|
|
|
496
496
|
|
|
497
497
|
// src/async/reduce.ts
|
|
498
498
|
async function reduce(array, reducer, initialValue) {
|
|
499
|
+
const length = array.length;
|
|
499
500
|
let index = 0;
|
|
500
501
|
let acc = initialValue;
|
|
501
502
|
if (acc === void 0 && arguments.length < 3) {
|
|
502
|
-
|
|
503
|
+
while (index < length && !(index in array)) {
|
|
504
|
+
index++;
|
|
505
|
+
}
|
|
506
|
+
if (index === length) {
|
|
503
507
|
throw new TypeError("Reduce of empty array with no initial value");
|
|
504
508
|
}
|
|
505
509
|
acc = array[index++];
|
|
506
510
|
}
|
|
507
|
-
|
|
508
|
-
|
|
511
|
+
for (; index < length; index++) {
|
|
512
|
+
if (index in array) {
|
|
513
|
+
acc = await reducer(acc, array[index], index);
|
|
514
|
+
}
|
|
509
515
|
}
|
|
510
516
|
return acc;
|
|
511
517
|
}
|
|
@@ -548,12 +554,15 @@ function sleep(milliseconds) {
|
|
|
548
554
|
|
|
549
555
|
// src/async/timeout.ts
|
|
550
556
|
function timeout(ms, error) {
|
|
551
|
-
return new Promise(
|
|
552
|
-
(
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
+
return new Promise((_, reject) => {
|
|
558
|
+
setTimeout(() => {
|
|
559
|
+
try {
|
|
560
|
+
reject(isFunction(error) ? error() : new TimeoutError(error));
|
|
561
|
+
} catch (cause) {
|
|
562
|
+
reject(cause);
|
|
563
|
+
}
|
|
564
|
+
}, ms);
|
|
565
|
+
});
|
|
557
566
|
}
|
|
558
567
|
|
|
559
568
|
// src/async/toResult.ts
|
|
@@ -915,6 +924,9 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
915
924
|
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
|
|
916
925
|
const start = end !== void 0 ? startOrLength : 0;
|
|
917
926
|
const final = end ?? startOrLength;
|
|
927
|
+
if (start <= final && step <= 0) {
|
|
928
|
+
throw new RangeError("Range step must be greater than zero");
|
|
929
|
+
}
|
|
918
930
|
for (let i = start; i <= final; i += step) {
|
|
919
931
|
yield mapper(i);
|
|
920
932
|
}
|
|
@@ -1178,7 +1190,9 @@ function mapEntries(obj, toEntry) {
|
|
|
1178
1190
|
|
|
1179
1191
|
// src/object/mapKeys.ts
|
|
1180
1192
|
function mapKeys(obj, mapFunc) {
|
|
1181
|
-
const keys2 =
|
|
1193
|
+
const keys2 = Reflect.ownKeys(obj).filter(
|
|
1194
|
+
(key) => Object.prototype.propertyIsEnumerable.call(obj, key)
|
|
1195
|
+
);
|
|
1182
1196
|
return keys2.reduce(
|
|
1183
1197
|
(acc, key) => {
|
|
1184
1198
|
acc[mapFunc(key, obj[key])] = obj[key];
|
|
@@ -1255,7 +1269,7 @@ function set(initial, path, value) {
|
|
|
1255
1269
|
value = recurse(object[key], keys2, index + 1);
|
|
1256
1270
|
}
|
|
1257
1271
|
if (!Object.is(object[key], value)) {
|
|
1258
|
-
object = clone(object);
|
|
1272
|
+
object = typeof object !== "object" && typeof object !== "function" ? isIntString(key) ? [] : {} : clone(object);
|
|
1259
1273
|
object[key] = value;
|
|
1260
1274
|
}
|
|
1261
1275
|
return object;
|
|
@@ -1430,7 +1444,7 @@ var QuantityParser = class {
|
|
|
1430
1444
|
let unit = match[2];
|
|
1431
1445
|
unit = this.short?.[unit] || unit;
|
|
1432
1446
|
const count = Number.parseFloat(match[1]);
|
|
1433
|
-
if (
|
|
1447
|
+
if (!this.units[unit] && unit.endsWith("s")) {
|
|
1434
1448
|
unit = unit.substring(0, unit.length - 1);
|
|
1435
1449
|
}
|
|
1436
1450
|
if (!this.units[unit]) {
|
|
@@ -1708,7 +1722,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1708
1722
|
function camel(str) {
|
|
1709
1723
|
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1710
1724
|
return parts.reduce((acc, part) => {
|
|
1711
|
-
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}
|
|
1725
|
+
return acc ? `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}` : part;
|
|
1712
1726
|
});
|
|
1713
1727
|
}
|
|
1714
1728
|
|
|
@@ -1820,7 +1834,7 @@ function pascal(str) {
|
|
|
1820
1834
|
return firstCharacter.toUpperCase();
|
|
1821
1835
|
}
|
|
1822
1836
|
);
|
|
1823
|
-
return result
|
|
1837
|
+
return result.charAt(0).toUpperCase() + result.substring(1);
|
|
1824
1838
|
}
|
|
1825
1839
|
|
|
1826
1840
|
// src/string/similarity.ts
|
|
@@ -1846,29 +1860,28 @@ function similarity(str1, str2) {
|
|
|
1846
1860
|
if (length2 === 0) {
|
|
1847
1861
|
return length1;
|
|
1848
1862
|
}
|
|
1849
|
-
const
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
const i = y * numColumns + x;
|
|
1861
|
-
distances[i] = Math.min(
|
|
1863
|
+
const row = new Uint32Array(length1 + 1);
|
|
1864
|
+
for (let y = 1; y <= length1; y++) {
|
|
1865
|
+
row[y] = y;
|
|
1866
|
+
}
|
|
1867
|
+
for (let x = 1; x <= length2; x++) {
|
|
1868
|
+
let diagonal = row[0];
|
|
1869
|
+
row[0] = x;
|
|
1870
|
+
const char2 = str2[start + x - 1];
|
|
1871
|
+
for (let y = 1; y <= length1; y++) {
|
|
1872
|
+
const above = row[y];
|
|
1873
|
+
row[y] = Math.min(
|
|
1862
1874
|
// Cost of a deletion.
|
|
1863
|
-
|
|
1875
|
+
row[y - 1] + 1,
|
|
1864
1876
|
// Cost of an insertion.
|
|
1865
|
-
|
|
1877
|
+
above + 1,
|
|
1866
1878
|
// Cost of a substitution.
|
|
1867
|
-
|
|
1879
|
+
diagonal + (str1[start + y - 1] === char2 ? 0 : 1)
|
|
1868
1880
|
);
|
|
1881
|
+
diagonal = above;
|
|
1869
1882
|
}
|
|
1870
1883
|
}
|
|
1871
|
-
return
|
|
1884
|
+
return row[length1];
|
|
1872
1885
|
}
|
|
1873
1886
|
|
|
1874
1887
|
// src/string/snake.ts
|
|
@@ -1882,14 +1895,10 @@ function snake(str, options) {
|
|
|
1882
1895
|
|
|
1883
1896
|
// src/string/template.ts
|
|
1884
1897
|
function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
result += str.slice(from, match.index) + data[match[1]];
|
|
1890
|
-
from = regex.lastIndex;
|
|
1891
|
-
}
|
|
1892
|
-
return result + str.slice(from);
|
|
1898
|
+
return str.replace(regex, (_match, ...args) => {
|
|
1899
|
+
const key = args.length > 2 ? args[0] : void 0;
|
|
1900
|
+
return data[key];
|
|
1901
|
+
});
|
|
1893
1902
|
}
|
|
1894
1903
|
|
|
1895
1904
|
// src/string/title.ts
|
|
@@ -2044,7 +2053,8 @@ function isMapEqual(x, y) {
|
|
|
2044
2053
|
return false;
|
|
2045
2054
|
}
|
|
2046
2055
|
for (const [key, value] of x) {
|
|
2047
|
-
|
|
2056
|
+
const otherValue = y.get(key);
|
|
2057
|
+
if (!isEqual(value, otherValue) || otherValue === void 0 && !y.has(key)) {
|
|
2048
2058
|
return false;
|
|
2049
2059
|
}
|
|
2050
2060
|
}
|
package/dist/radashi.d.cts
CHANGED
|
@@ -297,6 +297,7 @@ declare function last<const TArray extends readonly any[], const TDefault = unde
|
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
299
|
* Creates a list of given start, end, value, and step parameters.
|
|
300
|
+
* For nonempty ranges, zero and negative steps throw a RangeError.
|
|
300
301
|
*
|
|
301
302
|
* @see https://radashi.js.org/reference/array/list
|
|
302
303
|
* @example
|
|
@@ -2493,9 +2494,11 @@ declare function parseQuantity<TUnit extends string, TShortUnit extends string =
|
|
|
2493
2494
|
|
|
2494
2495
|
/**
|
|
2495
2496
|
* Creates a generator that will produce an iteration through the
|
|
2496
|
-
* range of
|
|
2497
|
+
* range of numbers as requested. For nonempty ranges, the step must
|
|
2498
|
+
* be greater than zero. Zero and negative steps throw a RangeError
|
|
2499
|
+
* when iteration begins.
|
|
2497
2500
|
*
|
|
2498
|
-
* @see https://radashi.js.org/reference/
|
|
2501
|
+
* @see https://radashi.js.org/reference/number/range
|
|
2499
2502
|
* @example
|
|
2500
2503
|
* ```ts
|
|
2501
2504
|
* range(3) // yields 0, 1, 2, 3
|
|
@@ -2519,6 +2522,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
|
|
|
2519
2522
|
* The `precision` argument is limited to be within the range of -323
|
|
2520
2523
|
* to +292. Without this limit, precision values outside this range
|
|
2521
2524
|
* can result in NaN.
|
|
2525
|
+
* With nonzero precision, negative zero may be returned as positive zero.
|
|
2522
2526
|
*
|
|
2523
2527
|
* @see https://radashi.js.org/reference/number/round
|
|
2524
2528
|
* @example
|
|
@@ -2624,13 +2628,12 @@ declare function assign<TInitial extends Record<keyof any, any>, TOverride exten
|
|
|
2624
2628
|
*
|
|
2625
2629
|
* @see https://radashi.js.org/reference/object/assign
|
|
2626
2630
|
*/
|
|
2627
|
-
type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> &
|
|
2628
|
-
|
|
2631
|
+
type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> & AssignShared<TInitial, TOverride>> : never : never;
|
|
2632
|
+
type AssignShared<TInitial extends object, TOverride extends object, Shared extends keyof TInitial & keyof TOverride = keyof TInitial & keyof TOverride, RequiredInitial = RequiredKeys<Pick<TInitial, Shared>>, RequiredOverride = RequiredKeys<Pick<TOverride, Shared>>> = {
|
|
2633
|
+
[K in Shared & (RequiredInitial | RequiredOverride)]: AssignDeep<TInitial[K], TOverride[K], K extends RequiredOverride ? false : true>;
|
|
2629
2634
|
} & {
|
|
2630
|
-
[K in
|
|
2631
|
-
}
|
|
2632
|
-
[K in OptionalKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]?: AssignDeep<TConflictInitial[K], TConflictOverride[K], true>;
|
|
2633
|
-
} : unknown : unknown)> : never : never;
|
|
2635
|
+
[K in Exclude<Shared, RequiredInitial | RequiredOverride>]?: AssignDeep<TInitial[K], TOverride[K], true>;
|
|
2636
|
+
};
|
|
2634
2637
|
/**
|
|
2635
2638
|
* Mimic the `Simplify` type and also remove `readonly` modifiers.
|
|
2636
2639
|
*/
|
|
@@ -2969,7 +2972,8 @@ declare function lowerize<T extends Record<string, any>>(obj: T): LowercaseKeys<
|
|
|
2969
2972
|
declare function mapEntries<TKey extends string | number | symbol, TValue, TNewKey extends string | number | symbol, TNewValue>(obj: Record<TKey, TValue>, toEntry: (key: TKey, value: TValue) => [TNewKey, TNewValue]): Record<TNewKey, TNewValue>;
|
|
2970
2973
|
|
|
2971
2974
|
/**
|
|
2972
|
-
* Map over
|
|
2975
|
+
* Map over the own enumerable string and symbol keys of an object
|
|
2976
|
+
* to return a new object.
|
|
2973
2977
|
*
|
|
2974
2978
|
* @see https://radashi.js.org/reference/object/mapKeys
|
|
2975
2979
|
* @example
|
|
@@ -3095,6 +3099,8 @@ declare function pick<T extends object, F extends KeyFilter<T, keyof T>>(obj: T,
|
|
|
3095
3099
|
/**
|
|
3096
3100
|
* Opposite of get, dynamically set a nested value into an object
|
|
3097
3101
|
* using a key path. Does not modify the given initial object.
|
|
3102
|
+
* Primitive intermediates are replaced with objects or arrays when
|
|
3103
|
+
* a property needs to change.
|
|
3098
3104
|
*
|
|
3099
3105
|
* @see https://radashi.js.org/reference/object/set
|
|
3100
3106
|
* @example
|
|
@@ -4007,13 +4013,18 @@ declare function isEqual<TType>(x: TType, y: TType): boolean;
|
|
|
4007
4013
|
declare function isError(value: unknown): value is Error;
|
|
4008
4014
|
|
|
4009
4015
|
/**
|
|
4010
|
-
* Return true if the given value is a number
|
|
4016
|
+
* Return true if the given value is a non-integer number, including
|
|
4017
|
+
* Infinity and -Infinity. Return false for integers, NaN, and
|
|
4018
|
+
* non-number values.
|
|
4011
4019
|
*
|
|
4012
4020
|
* @see https://radashi.js.org/reference/typed/isFloat
|
|
4013
4021
|
* @example
|
|
4014
4022
|
* ```ts
|
|
4015
4023
|
* isFloat(0) // => false
|
|
4016
4024
|
* isFloat(0.1) // => true
|
|
4025
|
+
* isFloat(Infinity) // => true
|
|
4026
|
+
* isFloat(-Infinity) // => true
|
|
4027
|
+
* isFloat(NaN) // => false
|
|
4017
4028
|
* ```
|
|
4018
4029
|
* @version 12.1.0
|
|
4019
4030
|
*/
|
package/dist/radashi.d.ts
CHANGED
|
@@ -297,6 +297,7 @@ declare function last<const TArray extends readonly any[], const TDefault = unde
|
|
|
297
297
|
|
|
298
298
|
/**
|
|
299
299
|
* Creates a list of given start, end, value, and step parameters.
|
|
300
|
+
* For nonempty ranges, zero and negative steps throw a RangeError.
|
|
300
301
|
*
|
|
301
302
|
* @see https://radashi.js.org/reference/array/list
|
|
302
303
|
* @example
|
|
@@ -2493,9 +2494,11 @@ declare function parseQuantity<TUnit extends string, TShortUnit extends string =
|
|
|
2493
2494
|
|
|
2494
2495
|
/**
|
|
2495
2496
|
* Creates a generator that will produce an iteration through the
|
|
2496
|
-
* range of
|
|
2497
|
+
* range of numbers as requested. For nonempty ranges, the step must
|
|
2498
|
+
* be greater than zero. Zero and negative steps throw a RangeError
|
|
2499
|
+
* when iteration begins.
|
|
2497
2500
|
*
|
|
2498
|
-
* @see https://radashi.js.org/reference/
|
|
2501
|
+
* @see https://radashi.js.org/reference/number/range
|
|
2499
2502
|
* @example
|
|
2500
2503
|
* ```ts
|
|
2501
2504
|
* range(3) // yields 0, 1, 2, 3
|
|
@@ -2519,6 +2522,7 @@ declare function range<T = number>(startOrLength: number, end?: number, valueOrM
|
|
|
2519
2522
|
* The `precision` argument is limited to be within the range of -323
|
|
2520
2523
|
* to +292. Without this limit, precision values outside this range
|
|
2521
2524
|
* can result in NaN.
|
|
2525
|
+
* With nonzero precision, negative zero may be returned as positive zero.
|
|
2522
2526
|
*
|
|
2523
2527
|
* @see https://radashi.js.org/reference/number/round
|
|
2524
2528
|
* @example
|
|
@@ -2624,13 +2628,12 @@ declare function assign<TInitial extends Record<keyof any, any>, TOverride exten
|
|
|
2624
2628
|
*
|
|
2625
2629
|
* @see https://radashi.js.org/reference/object/assign
|
|
2626
2630
|
*/
|
|
2627
|
-
type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> &
|
|
2628
|
-
|
|
2631
|
+
type Assign<TInitial extends object, TOverride extends object> = TInitial extends any ? TOverride extends any ? SimplifyMutable<Omit<TInitial, keyof TOverride> & Omit<TOverride, keyof TInitial> & AssignShared<TInitial, TOverride>> : never : never;
|
|
2632
|
+
type AssignShared<TInitial extends object, TOverride extends object, Shared extends keyof TInitial & keyof TOverride = keyof TInitial & keyof TOverride, RequiredInitial = RequiredKeys<Pick<TInitial, Shared>>, RequiredOverride = RequiredKeys<Pick<TOverride, Shared>>> = {
|
|
2633
|
+
[K in Shared & (RequiredInitial | RequiredOverride)]: AssignDeep<TInitial[K], TOverride[K], K extends RequiredOverride ? false : true>;
|
|
2629
2634
|
} & {
|
|
2630
|
-
[K in
|
|
2631
|
-
}
|
|
2632
|
-
[K in OptionalKeys<TConflictInitial> & OptionalKeys<TConflictOverride>]?: AssignDeep<TConflictInitial[K], TConflictOverride[K], true>;
|
|
2633
|
-
} : unknown : unknown)> : never : never;
|
|
2635
|
+
[K in Exclude<Shared, RequiredInitial | RequiredOverride>]?: AssignDeep<TInitial[K], TOverride[K], true>;
|
|
2636
|
+
};
|
|
2634
2637
|
/**
|
|
2635
2638
|
* Mimic the `Simplify` type and also remove `readonly` modifiers.
|
|
2636
2639
|
*/
|
|
@@ -2969,7 +2972,8 @@ declare function lowerize<T extends Record<string, any>>(obj: T): LowercaseKeys<
|
|
|
2969
2972
|
declare function mapEntries<TKey extends string | number | symbol, TValue, TNewKey extends string | number | symbol, TNewValue>(obj: Record<TKey, TValue>, toEntry: (key: TKey, value: TValue) => [TNewKey, TNewValue]): Record<TNewKey, TNewValue>;
|
|
2970
2973
|
|
|
2971
2974
|
/**
|
|
2972
|
-
* Map over
|
|
2975
|
+
* Map over the own enumerable string and symbol keys of an object
|
|
2976
|
+
* to return a new object.
|
|
2973
2977
|
*
|
|
2974
2978
|
* @see https://radashi.js.org/reference/object/mapKeys
|
|
2975
2979
|
* @example
|
|
@@ -3095,6 +3099,8 @@ declare function pick<T extends object, F extends KeyFilter<T, keyof T>>(obj: T,
|
|
|
3095
3099
|
/**
|
|
3096
3100
|
* Opposite of get, dynamically set a nested value into an object
|
|
3097
3101
|
* using a key path. Does not modify the given initial object.
|
|
3102
|
+
* Primitive intermediates are replaced with objects or arrays when
|
|
3103
|
+
* a property needs to change.
|
|
3098
3104
|
*
|
|
3099
3105
|
* @see https://radashi.js.org/reference/object/set
|
|
3100
3106
|
* @example
|
|
@@ -4007,13 +4013,18 @@ declare function isEqual<TType>(x: TType, y: TType): boolean;
|
|
|
4007
4013
|
declare function isError(value: unknown): value is Error;
|
|
4008
4014
|
|
|
4009
4015
|
/**
|
|
4010
|
-
* Return true if the given value is a number
|
|
4016
|
+
* Return true if the given value is a non-integer number, including
|
|
4017
|
+
* Infinity and -Infinity. Return false for integers, NaN, and
|
|
4018
|
+
* non-number values.
|
|
4011
4019
|
*
|
|
4012
4020
|
* @see https://radashi.js.org/reference/typed/isFloat
|
|
4013
4021
|
* @example
|
|
4014
4022
|
* ```ts
|
|
4015
4023
|
* isFloat(0) // => false
|
|
4016
4024
|
* isFloat(0.1) // => true
|
|
4025
|
+
* isFloat(Infinity) // => true
|
|
4026
|
+
* isFloat(-Infinity) // => true
|
|
4027
|
+
* isFloat(NaN) // => false
|
|
4017
4028
|
* ```
|
|
4018
4029
|
* @version 12.1.0
|
|
4019
4030
|
*/
|
package/dist/radashi.js
CHANGED
|
@@ -494,16 +494,22 @@ function queueByKey(asyncFn, keyFn) {
|
|
|
494
494
|
|
|
495
495
|
// src/async/reduce.ts
|
|
496
496
|
async function reduce(array, reducer, initialValue) {
|
|
497
|
+
const length = array.length;
|
|
497
498
|
let index = 0;
|
|
498
499
|
let acc = initialValue;
|
|
499
500
|
if (acc === void 0 && arguments.length < 3) {
|
|
500
|
-
|
|
501
|
+
while (index < length && !(index in array)) {
|
|
502
|
+
index++;
|
|
503
|
+
}
|
|
504
|
+
if (index === length) {
|
|
501
505
|
throw new TypeError("Reduce of empty array with no initial value");
|
|
502
506
|
}
|
|
503
507
|
acc = array[index++];
|
|
504
508
|
}
|
|
505
|
-
|
|
506
|
-
|
|
509
|
+
for (; index < length; index++) {
|
|
510
|
+
if (index in array) {
|
|
511
|
+
acc = await reducer(acc, array[index], index);
|
|
512
|
+
}
|
|
507
513
|
}
|
|
508
514
|
return acc;
|
|
509
515
|
}
|
|
@@ -546,12 +552,15 @@ function sleep(milliseconds) {
|
|
|
546
552
|
|
|
547
553
|
// src/async/timeout.ts
|
|
548
554
|
function timeout(ms, error) {
|
|
549
|
-
return new Promise(
|
|
550
|
-
(
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
+
return new Promise((_, reject) => {
|
|
556
|
+
setTimeout(() => {
|
|
557
|
+
try {
|
|
558
|
+
reject(isFunction(error) ? error() : new TimeoutError(error));
|
|
559
|
+
} catch (cause) {
|
|
560
|
+
reject(cause);
|
|
561
|
+
}
|
|
562
|
+
}, ms);
|
|
563
|
+
});
|
|
555
564
|
}
|
|
556
565
|
|
|
557
566
|
// src/async/toResult.ts
|
|
@@ -913,6 +922,9 @@ function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
|
|
|
913
922
|
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
|
|
914
923
|
const start = end !== void 0 ? startOrLength : 0;
|
|
915
924
|
const final = end ?? startOrLength;
|
|
925
|
+
if (start <= final && step <= 0) {
|
|
926
|
+
throw new RangeError("Range step must be greater than zero");
|
|
927
|
+
}
|
|
916
928
|
for (let i = start; i <= final; i += step) {
|
|
917
929
|
yield mapper(i);
|
|
918
930
|
}
|
|
@@ -1176,7 +1188,9 @@ function mapEntries(obj, toEntry) {
|
|
|
1176
1188
|
|
|
1177
1189
|
// src/object/mapKeys.ts
|
|
1178
1190
|
function mapKeys(obj, mapFunc) {
|
|
1179
|
-
const keys2 =
|
|
1191
|
+
const keys2 = Reflect.ownKeys(obj).filter(
|
|
1192
|
+
(key) => Object.prototype.propertyIsEnumerable.call(obj, key)
|
|
1193
|
+
);
|
|
1180
1194
|
return keys2.reduce(
|
|
1181
1195
|
(acc, key) => {
|
|
1182
1196
|
acc[mapFunc(key, obj[key])] = obj[key];
|
|
@@ -1253,7 +1267,7 @@ function set(initial, path, value) {
|
|
|
1253
1267
|
value = recurse(object[key], keys2, index + 1);
|
|
1254
1268
|
}
|
|
1255
1269
|
if (!Object.is(object[key], value)) {
|
|
1256
|
-
object = clone(object);
|
|
1270
|
+
object = typeof object !== "object" && typeof object !== "function" ? isIntString(key) ? [] : {} : clone(object);
|
|
1257
1271
|
object[key] = value;
|
|
1258
1272
|
}
|
|
1259
1273
|
return object;
|
|
@@ -1428,7 +1442,7 @@ var QuantityParser = class {
|
|
|
1428
1442
|
let unit = match[2];
|
|
1429
1443
|
unit = this.short?.[unit] || unit;
|
|
1430
1444
|
const count = Number.parseFloat(match[1]);
|
|
1431
|
-
if (
|
|
1445
|
+
if (!this.units[unit] && unit.endsWith("s")) {
|
|
1432
1446
|
unit = unit.substring(0, unit.length - 1);
|
|
1433
1447
|
}
|
|
1434
1448
|
if (!this.units[unit]) {
|
|
@@ -1706,7 +1720,7 @@ var series = (items, toKey = (item) => `${item}`) => {
|
|
|
1706
1720
|
function camel(str) {
|
|
1707
1721
|
const parts = str.replace(/([A-Z])+/g, capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x) => x.toLowerCase());
|
|
1708
1722
|
return parts.reduce((acc, part) => {
|
|
1709
|
-
return `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}
|
|
1723
|
+
return acc ? `${acc}${part.charAt(0).toUpperCase()}${part.slice(1)}` : part;
|
|
1710
1724
|
});
|
|
1711
1725
|
}
|
|
1712
1726
|
|
|
@@ -1818,7 +1832,7 @@ function pascal(str) {
|
|
|
1818
1832
|
return firstCharacter.toUpperCase();
|
|
1819
1833
|
}
|
|
1820
1834
|
);
|
|
1821
|
-
return result
|
|
1835
|
+
return result.charAt(0).toUpperCase() + result.substring(1);
|
|
1822
1836
|
}
|
|
1823
1837
|
|
|
1824
1838
|
// src/string/similarity.ts
|
|
@@ -1844,29 +1858,28 @@ function similarity(str1, str2) {
|
|
|
1844
1858
|
if (length2 === 0) {
|
|
1845
1859
|
return length1;
|
|
1846
1860
|
}
|
|
1847
|
-
const
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
const i = y * numColumns + x;
|
|
1859
|
-
distances[i] = Math.min(
|
|
1861
|
+
const row = new Uint32Array(length1 + 1);
|
|
1862
|
+
for (let y = 1; y <= length1; y++) {
|
|
1863
|
+
row[y] = y;
|
|
1864
|
+
}
|
|
1865
|
+
for (let x = 1; x <= length2; x++) {
|
|
1866
|
+
let diagonal = row[0];
|
|
1867
|
+
row[0] = x;
|
|
1868
|
+
const char2 = str2[start + x - 1];
|
|
1869
|
+
for (let y = 1; y <= length1; y++) {
|
|
1870
|
+
const above = row[y];
|
|
1871
|
+
row[y] = Math.min(
|
|
1860
1872
|
// Cost of a deletion.
|
|
1861
|
-
|
|
1873
|
+
row[y - 1] + 1,
|
|
1862
1874
|
// Cost of an insertion.
|
|
1863
|
-
|
|
1875
|
+
above + 1,
|
|
1864
1876
|
// Cost of a substitution.
|
|
1865
|
-
|
|
1877
|
+
diagonal + (str1[start + y - 1] === char2 ? 0 : 1)
|
|
1866
1878
|
);
|
|
1879
|
+
diagonal = above;
|
|
1867
1880
|
}
|
|
1868
1881
|
}
|
|
1869
|
-
return
|
|
1882
|
+
return row[length1];
|
|
1870
1883
|
}
|
|
1871
1884
|
|
|
1872
1885
|
// src/string/snake.ts
|
|
@@ -1880,14 +1893,10 @@ function snake(str, options) {
|
|
|
1880
1893
|
|
|
1881
1894
|
// src/string/template.ts
|
|
1882
1895
|
function template(str, data, regex = /\{\{(.+?)\}\}/g) {
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
result += str.slice(from, match.index) + data[match[1]];
|
|
1888
|
-
from = regex.lastIndex;
|
|
1889
|
-
}
|
|
1890
|
-
return result + str.slice(from);
|
|
1896
|
+
return str.replace(regex, (_match, ...args) => {
|
|
1897
|
+
const key = args.length > 2 ? args[0] : void 0;
|
|
1898
|
+
return data[key];
|
|
1899
|
+
});
|
|
1891
1900
|
}
|
|
1892
1901
|
|
|
1893
1902
|
// src/string/title.ts
|
|
@@ -2042,7 +2051,8 @@ function isMapEqual(x, y) {
|
|
|
2042
2051
|
return false;
|
|
2043
2052
|
}
|
|
2044
2053
|
for (const [key, value] of x) {
|
|
2045
|
-
|
|
2054
|
+
const otherValue = y.get(key);
|
|
2055
|
+
if (!isEqual(value, otherValue) || otherValue === void 0 && !y.has(key)) {
|
|
2046
2056
|
return false;
|
|
2047
2057
|
}
|
|
2048
2058
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radashi",
|
|
3
|
-
"version": "13.0
|
|
3
|
+
"version": "13.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The modern, community-first TypeScript toolkit with all of the fast, readable, and minimal utility functions you need. Type-safe, dependency-free, tree-shakeable, fully tested.",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": "dist/radashi.d.cts",
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
31
|
+
"dist",
|
|
32
|
+
"skills"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
34
35
|
"add-function": "radashi fn create",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: radashi
|
|
3
|
+
description: Use this skill when writing TypeScript or JavaScript code.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Radashi LLM essentials
|
|
7
|
+
|
|
8
|
+
Import these functions from `radashi`. Use only these Radashi functions by default; use other Radashi functions only to match nearby code.
|
|
9
|
+
|
|
10
|
+
assert — assert a condition and narrow types; throws if false.
|
|
11
|
+
castArray — normalize a value-or-array into an array; `null` becomes `[null]` and `undefined` becomes `[undefined]`.
|
|
12
|
+
clamp — constrain a number between min and max.
|
|
13
|
+
concat — combine arrays/items; drops `null`/`undefined` and flattens one array level.
|
|
14
|
+
dedent — write readable multiline template strings.
|
|
15
|
+
escapeHTML — escape HTML text characters; not a sanitizer.
|
|
16
|
+
getErrorMessage — convert an unknown caught error to a message string.
|
|
17
|
+
group — group array items by a key.
|
|
18
|
+
isDate — test for `Date` values.
|
|
19
|
+
isError — test for `Error` values.
|
|
20
|
+
isNullish — test for `null` or `undefined`.
|
|
21
|
+
isObject — test for object-like values.
|
|
22
|
+
isPlainObject — test for ordinary JSON-style objects.
|
|
23
|
+
mapValues — transform object values while preserving keys.
|
|
24
|
+
objectify — convert an array to an object by key; duplicate keys overwrite earlier values.
|
|
25
|
+
omit — return an object without explicit keys.
|
|
26
|
+
pick — return an object with only explicit keys; prefer key arrays.
|
|
27
|
+
range — create an inclusive numeric generator.
|
|
28
|
+
shake — remove `undefined` object properties only.
|
|
29
|
+
sleep — delay async code by milliseconds.
|
|
30
|
+
sort — return a sorted copy of an array by numeric getter.
|
|
31
|
+
sum — sum numbers or numeric fields.
|
|
32
|
+
unique — remove duplicates, optionally by key.
|