@ts-fns/stdlib 0.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/LICENSE +7 -0
- package/README.md +132 -0
- package/dist/array/index.cjs +551 -0
- package/dist/array/index.cjs.map +1 -0
- package/dist/array/index.d.cts +334 -0
- package/dist/array/index.d.cts.map +1 -0
- package/dist/array/index.d.mts +334 -0
- package/dist/array/index.d.mts.map +1 -0
- package/dist/array/index.mjs +498 -0
- package/dist/array/index.mjs.map +1 -0
- package/dist/errors-CJsLpYo9.d.cts +25 -0
- package/dist/errors-CJsLpYo9.d.cts.map +1 -0
- package/dist/errors-CJsLpYo9.d.mts +25 -0
- package/dist/errors-CJsLpYo9.d.mts.map +1 -0
- package/dist/errors-Dw1kitu_.mjs +39 -0
- package/dist/errors-Dw1kitu_.mjs.map +1 -0
- package/dist/errors-O-d_Vemi.cjs +74 -0
- package/dist/errors-O-d_Vemi.cjs.map +1 -0
- package/dist/function/index.cjs +15 -0
- package/dist/function/index.d.cts +107 -0
- package/dist/function/index.d.cts.map +1 -0
- package/dist/function/index.d.mts +107 -0
- package/dist/function/index.d.mts.map +1 -0
- package/dist/function/index.mjs +3 -0
- package/dist/function-CB82a2GS.cjs +186 -0
- package/dist/function-CB82a2GS.cjs.map +1 -0
- package/dist/function-DnI2v0p3.mjs +121 -0
- package/dist/function-DnI2v0p3.mjs.map +1 -0
- package/dist/get-CWL_cu6G.mjs +27 -0
- package/dist/get-CWL_cu6G.mjs.map +1 -0
- package/dist/get-yrs1Kqho.cjs +38 -0
- package/dist/get-yrs1Kqho.cjs.map +1 -0
- package/dist/guard/index.cjs +43 -0
- package/dist/guard/index.cjs.map +1 -0
- package/dist/guard/index.d.cts +52 -0
- package/dist/guard/index.d.cts.map +1 -0
- package/dist/guard/index.d.mts +52 -0
- package/dist/guard/index.d.mts.map +1 -0
- package/dist/guard/index.mjs +40 -0
- package/dist/guard/index.mjs.map +1 -0
- package/dist/index-BJlKyBJH.d.cts +18 -0
- package/dist/index-BJlKyBJH.d.cts.map +1 -0
- package/dist/index-DGrnGMDt.d.mts +18 -0
- package/dist/index-DGrnGMDt.d.mts.map +1 -0
- package/dist/isNotNil-DrF-ohem.cjs +28 -0
- package/dist/isNotNil-DrF-ohem.cjs.map +1 -0
- package/dist/isNotNil-R5f1hC53.mjs +23 -0
- package/dist/isNotNil-R5f1hC53.mjs.map +1 -0
- package/dist/iterator/index.cjs +160 -0
- package/dist/iterator/index.cjs.map +1 -0
- package/dist/iterator/index.d.cts +71 -0
- package/dist/iterator/index.d.cts.map +1 -0
- package/dist/iterator/index.d.mts +71 -0
- package/dist/iterator/index.d.mts.map +1 -0
- package/dist/iterator/index.mjs +148 -0
- package/dist/iterator/index.mjs.map +1 -0
- package/dist/lens/index.cjs +199 -0
- package/dist/lens/index.cjs.map +1 -0
- package/dist/lens/index.d.cts +109 -0
- package/dist/lens/index.d.cts.map +1 -0
- package/dist/lens/index.d.mts +109 -0
- package/dist/lens/index.d.mts.map +1 -0
- package/dist/lens/index.mjs +187 -0
- package/dist/lens/index.mjs.map +1 -0
- package/dist/map/index.cjs +86 -0
- package/dist/map/index.cjs.map +1 -0
- package/dist/map/index.d.cts +41 -0
- package/dist/map/index.d.cts.map +1 -0
- package/dist/map/index.d.mts +41 -0
- package/dist/map/index.d.mts.map +1 -0
- package/dist/map/index.mjs +75 -0
- package/dist/map/index.mjs.map +1 -0
- package/dist/number/index.cjs +179 -0
- package/dist/number/index.cjs.map +1 -0
- package/dist/number/index.d.cts +112 -0
- package/dist/number/index.d.cts.map +1 -0
- package/dist/number/index.d.mts +112 -0
- package/dist/number/index.d.mts.map +1 -0
- package/dist/number/index.mjs +159 -0
- package/dist/number/index.mjs.map +1 -0
- package/dist/object/index.cjs +190 -0
- package/dist/object/index.cjs.map +1 -0
- package/dist/object/index.d.cts +118 -0
- package/dist/object/index.d.cts.map +1 -0
- package/dist/object/index.d.mts +118 -0
- package/dist/object/index.d.mts.map +1 -0
- package/dist/object/index.mjs +169 -0
- package/dist/object/index.mjs.map +1 -0
- package/dist/orThrow-V91Jw2lF.mjs +15 -0
- package/dist/orThrow-V91Jw2lF.mjs.map +1 -0
- package/dist/orThrow-ejzcQYAI.cjs +20 -0
- package/dist/orThrow-ejzcQYAI.cjs.map +1 -0
- package/dist/order/index.cjs +50 -0
- package/dist/order/index.cjs.map +1 -0
- package/dist/order/index.d.cts +3 -0
- package/dist/order/index.d.mts +3 -0
- package/dist/order/index.mjs +42 -0
- package/dist/order/index.mjs.map +1 -0
- package/dist/order.constants-BWSCg3C7.d.cts +11 -0
- package/dist/order.constants-BWSCg3C7.d.cts.map +1 -0
- package/dist/order.constants-BWSCg3C7.d.mts +11 -0
- package/dist/order.constants-BWSCg3C7.d.mts.map +1 -0
- package/dist/purry-B2_0DGLV.cjs +28 -0
- package/dist/purry-B2_0DGLV.cjs.map +1 -0
- package/dist/purry-BOWmqwDB.mjs +23 -0
- package/dist/purry-BOWmqwDB.mjs.map +1 -0
- package/dist/set/index.cjs +131 -0
- package/dist/set/index.cjs.map +1 -0
- package/dist/set/index.d.cts +61 -0
- package/dist/set/index.d.cts.map +1 -0
- package/dist/set/index.d.mts +61 -0
- package/dist/set/index.d.mts.map +1 -0
- package/dist/set/index.mjs +115 -0
- package/dist/set/index.mjs.map +1 -0
- package/dist/string/index.cjs +288 -0
- package/dist/string/index.cjs.map +1 -0
- package/dist/string/index.d.cts +144 -0
- package/dist/string/index.d.cts.map +1 -0
- package/dist/string/index.d.mts +144 -0
- package/dist/string/index.d.mts.map +1 -0
- package/dist/string/index.mjs +254 -0
- package/dist/string/index.mjs.map +1 -0
- package/dist/tuple/index.cjs +135 -0
- package/dist/tuple/index.cjs.map +1 -0
- package/dist/tuple/index.d.cts +207 -0
- package/dist/tuple/index.d.cts.map +1 -0
- package/dist/tuple/index.d.mts +207 -0
- package/dist/tuple/index.d.mts.map +1 -0
- package/dist/tuple/index.mjs +122 -0
- package/dist/tuple/index.mjs.map +1 -0
- package/dist/types-D8f67ZCe.d.cts +54 -0
- package/dist/types-D8f67ZCe.d.cts.map +1 -0
- package/dist/types-D8f67ZCe.d.mts +54 -0
- package/dist/types-D8f67ZCe.d.mts.map +1 -0
- package/package.json +177 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { t as purry } from "../purry-BOWmqwDB.mjs";
|
|
2
|
+
//#region src/tuple/at.ts
|
|
3
|
+
function at2Implementation(tuple, index) {
|
|
4
|
+
if (index < 0) throw new RangeError(`Tuple.at() :: ${index} must be a positive integer`);
|
|
5
|
+
if (index >= tuple.length) throw new RangeError(`Tuple.at() :: ${index} is out of bounds`);
|
|
6
|
+
return tuple[index];
|
|
7
|
+
}
|
|
8
|
+
function at(...args) {
|
|
9
|
+
return purry(at2Implementation, args);
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/tuple/fanOut.ts
|
|
13
|
+
function fanOutImplementation(value, fn1, fn2) {
|
|
14
|
+
return [fn1(value), fn2(value)];
|
|
15
|
+
}
|
|
16
|
+
function fanOut(...args) {
|
|
17
|
+
return purry(fanOutImplementation, args);
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/tuple/first.ts
|
|
21
|
+
/**
|
|
22
|
+
* Returns the first element of a tuple with at least one element.
|
|
23
|
+
*
|
|
24
|
+
* @param tuple - A non-empty tuple.
|
|
25
|
+
* @returns The element at index `0`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* first([1, 2]); // 1
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @throws {RangeError} When the tuple has fewer than one element.
|
|
33
|
+
*/
|
|
34
|
+
function first(tuple) {
|
|
35
|
+
if (tuple.length < 1) throw new RangeError("Tuple.first() :: received a tuple with less than 1 element");
|
|
36
|
+
return tuple[0];
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/tuple/insert.ts
|
|
40
|
+
function updateImplementation(tuple, index, value) {
|
|
41
|
+
return tuple.with(index, value);
|
|
42
|
+
}
|
|
43
|
+
function insert(...args) {
|
|
44
|
+
return purry(updateImplementation, args);
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/tuple/mapBoth.ts
|
|
48
|
+
/**
|
|
49
|
+
* Maps both elements of a homogeneous pair with the same function.
|
|
50
|
+
*/
|
|
51
|
+
function mapBothImplementation(tuple, fn) {
|
|
52
|
+
return [fn(tuple[0]), fn(tuple[1])];
|
|
53
|
+
}
|
|
54
|
+
function mapBoth(...args) {
|
|
55
|
+
return purry(mapBothImplementation, args);
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/tuple/mapEach.ts
|
|
59
|
+
function mapEachImplementation(tuple, fnA, fnB) {
|
|
60
|
+
return [fnA(tuple[0]), fnB(tuple[1])];
|
|
61
|
+
}
|
|
62
|
+
function mapEach(...args) {
|
|
63
|
+
return purry(mapEachImplementation, args);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/tuple/mapFirst.ts
|
|
67
|
+
/**
|
|
68
|
+
* Maps the first element of a pair; leaves the second unchanged.
|
|
69
|
+
*/
|
|
70
|
+
function mapFirstImplementation(tuple, fn) {
|
|
71
|
+
return [fn(tuple[0]), tuple[1]];
|
|
72
|
+
}
|
|
73
|
+
function mapFirst(...args) {
|
|
74
|
+
return purry(mapFirstImplementation, args);
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/tuple/mapSecond.ts
|
|
78
|
+
function mapSecondImplementation(tuple, fn) {
|
|
79
|
+
return [tuple[0], fn(tuple[1])];
|
|
80
|
+
}
|
|
81
|
+
function mapSecond(...args) {
|
|
82
|
+
return purry(mapSecondImplementation, args);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/tuple/second.ts
|
|
86
|
+
/**
|
|
87
|
+
* Returns the second element of a tuple with at least two elements.
|
|
88
|
+
*
|
|
89
|
+
* @param tuple - A tuple with at least two elements.
|
|
90
|
+
* @returns The element at index `1`.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* second([1, 2]); // 2
|
|
95
|
+
* ```
|
|
96
|
+
*
|
|
97
|
+
* @throws {RangeError} When the tuple has fewer than two elements.
|
|
98
|
+
*/
|
|
99
|
+
function second(tuple) {
|
|
100
|
+
if (tuple.length < 2) throw new RangeError("Tuple.second() :: received a tuple with less than 2 elements");
|
|
101
|
+
return tuple[1];
|
|
102
|
+
}
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/tuple/swap.ts
|
|
105
|
+
/**
|
|
106
|
+
* Swaps the two elements of a pair.
|
|
107
|
+
*
|
|
108
|
+
* @param data - A two-element tuple.
|
|
109
|
+
* @returns The tuple with elements reversed.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* swap([1, 'a']); // ['a', 1]
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
function swap(data) {
|
|
117
|
+
return [data[1], data[0]];
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
export { at, fanOut, fanOutImplementation, first, insert, mapBoth, mapBothImplementation, mapEach, mapFirst, mapFirstImplementation, mapSecond, second, swap };
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/tuple/at.ts","../../src/tuple/fanOut.ts","../../src/tuple/first.ts","../../src/tuple/insert.ts","../../src/tuple/mapBoth.ts","../../src/tuple/mapEach.ts","../../src/tuple/mapFirst.ts","../../src/tuple/mapSecond.ts","../../src/tuple/second.ts","../../src/tuple/swap.ts"],"sourcesContent":["import { purry } from '../function/purry';\n\nfunction at2Implementation<T>(tuple: T[], index: number): T {\n if (index < 0) {\n throw new RangeError(`Tuple.at() :: ${index} must be a positive integer`);\n }\n if (index >= tuple.length) {\n throw new RangeError(`Tuple.at() :: ${index} is out of bounds`);\n }\n\n return tuple[index]!;\n}\n\n/**\n * Get an element from a tuple by index.\n *\n * @param tuple - The tuple to get the element from.\n * @param index - The index of the element to get.\n *\n * @example\n * ```ts\n * at(0, [1, 2, 3]) // 1\n * at(1, [1, 2, 3]) // 2\n * at([1, 2, 3], 0) // 1\n * at([1, 2, 3], 1) // 2\n * ```\n *\n * @throws {RangeError}\n */\nexport function at<T>(index: 0): (tuple: [T, ...unknown[]]) => T;\nexport function at<T>(index: 1): (tuple: [unknown, T, ...unknown[]]) => T;\nexport function at<T>(index: 2): (tuple: [unknown, unknown, T, ...unknown[]]) => T;\nexport function at<T>(index: 3): (tuple: [unknown, unknown, unknown, T, ...unknown[]]) => T;\nexport function at<T>(index: 4): (tuple: [unknown, unknown, unknown, unknown, T, ...unknown[]]) => T;\nexport function at<T>(index: 5): (tuple: [unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]) => T;\nexport function at<T>(index: 6): (tuple: [unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]) => T;\nexport function at<T>(tuple: [T, ...unknown[]], index: 0): T;\nexport function at<T>(tuple: [unknown, T, ...unknown[]], index: 1): T;\nexport function at<T>(tuple: [unknown, unknown, T, ...unknown[]], index: 2): T;\nexport function at<T>(tuple: [unknown, unknown, unknown, T, ...unknown[]], index: 3): T;\nexport function at<T>(tuple: [unknown, unknown, unknown, unknown, T, ...unknown[]], index: 4): T;\nexport function at<T>(tuple: [unknown, unknown, unknown, unknown, unknown, T, ...unknown[]], index: 5): T;\nexport function at<T>(tuple: [unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]], index: 6): T;\nexport function at(...args: readonly unknown[]): unknown {\n return purry(at2Implementation, args);\n}\n","import { purry } from '../function/purry';\n\nexport function fanOutImplementation<A, C, D>(value: A, fn1: (value: A) => C, fn2: (value: A) => D): [C, D] {\n return [fn1(value), fn2(value)];\n}\n\n/**\n * Takes a value and two functions and returns a tuple of the results of the functions.\n *\n * @public\n * @category Tuple\n * @param value - The value to apply the functions to.\n * @param fn1 - The first function to apply to the value.\n * @param fn2 - The second function to apply to the value.\n *\n * @example\n * ```ts\n * fanOut((x) => x * 2, (x) => x + 1, 2); // [4, 3]\n * ```\n */\nexport function fanOut<A, C, D>(fn1: (value: A) => C, fn2: (value: A) => D): (value: A) => [C, D];\nexport function fanOut<A, C, D>(value: A, fn1: (value: A) => C, fn2: (value: A) => D): [C, D];\nexport function fanOut(...args: readonly unknown[]): unknown {\n return purry(fanOutImplementation, args);\n}\n","/**\n * Returns the first element of a tuple with at least one element.\n *\n * @param tuple - A non-empty tuple.\n * @returns The element at index `0`.\n *\n * @example\n * ```ts\n * first([1, 2]); // 1\n * ```\n *\n * @throws {RangeError} When the tuple has fewer than one element.\n */\nexport function first<T>(tuple: [T, ...unknown[]]): T {\n if (tuple.length < 1) {\n throw new RangeError('Tuple.first() :: received a tuple with less than 1 element');\n }\n return tuple[0];\n}\n","/* eslint-disable @typescript-eslint/unified-signatures */\nimport { purry } from '../function/purry';\n\nfunction updateImplementation<T>(tuple: T[], index: number, value: T): T[] {\n return tuple.with(index, value);\n}\n\n/**\n * Returns a new tuple with the element at `index` replaced by `value`.\n *\n * @param index - Zero-based index of the element to replace.\n * @param value - Replacement value.\n * @param tuple - The source tuple.\n *\n * @example\n * ```ts\n * insert([1, 2, 3], 1, 99); // [1, 99, 3]\n * insert(1, 99)([1, 2, 3]); // [1, 99, 3]\n * ```\n *\n * @throws {RangeError} When `index` is negative or out of bounds (from the underlying `with` call).\n */\nexport function insert<T>(index: 0, value: T): <U extends readonly [T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(index: 1, value: T): <U extends readonly [unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(index: 2, value: T): <U extends readonly [unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 3,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 4,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 5,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 6,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 7,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(tuple: U) => U;\nexport function insert<T>(\n index: 8,\n value: T,\n): <U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(\n tuple: U,\n) => U;\nexport function insert<T, U extends readonly [T, ...unknown[]]>(tuple: U, index: 0, value: T): U;\nexport function insert<T, U extends readonly [unknown, T, ...unknown[]]>(tuple: U, index: 1, value: T): U;\nexport function insert<T, U extends readonly [unknown, unknown, T, ...unknown[]]>(tuple: U, index: 2, value: T): U;\nexport function insert<T, U extends readonly [unknown, unknown, unknown, T, ...unknown[]]>(\n tuple: U,\n index: 3,\n value: T,\n): U;\nexport function insert<T, U extends readonly [unknown, unknown, unknown, unknown, T, ...unknown[]]>(\n tuple: U,\n index: 4,\n value: T,\n): U;\nexport function insert<T, U extends readonly [unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(\n tuple: U,\n index: 5,\n value: T,\n): U;\nexport function insert<T, U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]]>(\n tuple: U,\n index: 6,\n value: T,\n): U;\nexport function insert<\n T,\n U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]],\n>(tuple: U, index: 7, value: T): U;\nexport function insert<\n T,\n U extends readonly [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, T, ...unknown[]],\n>(tuple: U, index: 8, value: T): U;\nexport function insert(...args: readonly unknown[]): unknown {\n return purry(updateImplementation, args);\n}\n","import { purry } from '../function/purry';\n\n/**\n * Maps both elements of a homogeneous pair with the same function.\n */\nexport function mapBothImplementation<T, U>(tuple: [T, T], fn: (value: T) => U): [U, U] {\n return [fn(tuple[0]), fn(tuple[1])];\n}\n\n/**\n * Maps both elements of a homogeneous pair with the same function.\n *\n * @param fn - Function applied to each element\n * @param tuple - A two-element tuple of the same type\n *\n * @example\n * ```ts\n * mapBoth([1, 2], (n) => n * 2); // [2, 4]\n * mapBoth((n) => n * 2)([1, 2]); // [2, 4]\n * ```\n */\nexport function mapBoth<T, U>(fn: (value: T) => U): (tuple: [T, T]) => [U, U];\nexport function mapBoth<T, U>(tuple: [T, T], fn: (value: T) => U): [U, U];\nexport function mapBoth(...args: readonly unknown[]): unknown {\n return purry(mapBothImplementation, args);\n}\n","import { purry } from '../function/purry';\n\nfunction mapEachImplementation<A, B, X, Y>(tuple: [A, B], fnA: (value: A) => X, fnB: (value: B) => Y): [X, Y] {\n return [fnA(tuple[0]), fnB(tuple[1])];\n}\n\n/**\n * Maps the first and second elements of a pair with two functions.\n *\n * @param fnA - Function applied to the first element\n * @param fnB - Function applied to the second element\n * @param tuple - A two-element tuple\n *\n * @example\n * ```ts\n * mapEach([1, 'a'], String, (s) => s.toUpperCase()); // ['1', 'A']\n * mapEach(String, (s) => s.toUpperCase())([1, 'a']); // ['1', 'A']\n * ```\n */\nexport function mapEach<A, B, X, Y>(fnA: (value: A) => X, fnB: (value: B) => Y): (tuple: [A, B]) => [X, Y];\nexport function mapEach<A, B, X, Y>(tuple: [A, B], fnA: (value: A) => X, fnB: (value: B) => Y): [X, Y];\nexport function mapEach(...args: readonly unknown[]): unknown {\n return purry(mapEachImplementation, args);\n}\n","import { purry } from '../function/purry';\n\n/**\n * Maps the first element of a pair; leaves the second unchanged.\n */\nexport function mapFirstImplementation<A, B, X>(tuple: [A, B], fn: (value: A) => X): [X, B] {\n return [fn(tuple[0]), tuple[1]];\n}\n\n/**\n * Maps the first element of a pair; leaves the second unchanged.\n *\n * @param fn - Function applied to the first element\n * @param tuple - A two-element tuple\n *\n * @example\n * ```ts\n * mapFirst([1, 'a'], (n) => n + 1); // [2, 'a']\n * mapFirst((n) => n + 1)([1, 'a']); // [2, 'a']\n * ```\n */\nexport function mapFirst<A, B, X>(fn: (value: A) => X): (tuple: [A, B]) => [X, B];\nexport function mapFirst<A, B, X>(tuple: [A, B], fn: (value: A) => X): [X, B];\nexport function mapFirst(...args: readonly unknown[]): unknown {\n return purry(mapFirstImplementation, args);\n}\n","import { purry } from '../function/purry';\n\nfunction mapSecondImplementation<A, B, Y>(tuple: [A, B], fn: (value: B) => Y): [A, Y] {\n return [tuple[0], fn(tuple[1])];\n}\n\n/**\n * Maps the second element of a pair; leaves the first unchanged.\n *\n * @param fn - Function applied to the second element\n * @param tuple - A two-element tuple (data-first overload).\n *\n * @example\n * ```ts\n * mapSecond([1, 'a'], (s) => s.toUpperCase()); // [1, 'A']\n * mapSecond((s) => s.toUpperCase())([1, 'a']); // [1, 'A']\n * ```\n */\nexport function mapSecond<A, B, Y>(fn: (value: B) => Y): (tuple: [A, B]) => [A, Y];\nexport function mapSecond<A, B, Y>(tuple: [A, B], fn: (value: B) => Y): [A, Y];\nexport function mapSecond(...args: readonly unknown[]): unknown {\n return purry(mapSecondImplementation, args);\n}\n","/**\n * Returns the second element of a tuple with at least two elements.\n *\n * @param tuple - A tuple with at least two elements.\n * @returns The element at index `1`.\n *\n * @example\n * ```ts\n * second([1, 2]); // 2\n * ```\n *\n * @throws {RangeError} When the tuple has fewer than two elements.\n */\nexport function second<T>(tuple: [unknown, T, ...unknown[]]): T {\n if (tuple.length < 2) {\n throw new RangeError('Tuple.second() :: received a tuple with less than 2 elements');\n }\n return tuple[1];\n}\n","/**\n * Swaps the two elements of a pair.\n *\n * @param data - A two-element tuple.\n * @returns The tuple with elements reversed.\n *\n * @example\n * ```ts\n * swap([1, 'a']); // ['a', 1]\n * ```\n */\nexport function swap<A, B>(data: [A, B]): [B, A] {\n return [data[1], data[0]];\n}\n"],"mappings":";;AAEA,SAAS,kBAAqB,OAAY,OAAkB;CAC1D,IAAI,QAAQ,GACV,MAAM,IAAI,WAAW,iBAAiB,MAAM,4BAA4B;CAE1E,IAAI,SAAS,MAAM,QACjB,MAAM,IAAI,WAAW,iBAAiB,MAAM,kBAAkB;CAGhE,OAAO,MAAM;AACf;AAgCA,SAAgB,GAAG,GAAG,MAAmC;CACvD,OAAO,MAAM,mBAAmB,IAAI;AACtC;;;AC3CA,SAAgB,qBAA8B,OAAU,KAAsB,KAA8B;CAC1G,OAAO,CAAC,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC;AAChC;AAkBA,SAAgB,OAAO,GAAG,MAAmC;CAC3D,OAAO,MAAM,sBAAsB,IAAI;AACzC;;;;;;;;;;;;;;;;ACXA,SAAgB,MAAS,OAA6B;CACpD,IAAI,MAAM,SAAS,GACjB,MAAM,IAAI,WAAW,4DAA4D;CAEnF,OAAO,MAAM;AACf;;;ACfA,SAAS,qBAAwB,OAAY,OAAe,OAAe;CACzE,OAAO,MAAM,KAAK,OAAO,KAAK;AAChC;AA6EA,SAAgB,OAAO,GAAG,MAAmC;CAC3D,OAAO,MAAM,sBAAsB,IAAI;AACzC;;;;;;AC/EA,SAAgB,sBAA4B,OAAe,IAA6B;CACtF,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,GAAG,MAAM,EAAE,CAAC;AACpC;AAgBA,SAAgB,QAAQ,GAAG,MAAmC;CAC5D,OAAO,MAAM,uBAAuB,IAAI;AAC1C;;;ACvBA,SAAS,sBAAkC,OAAe,KAAsB,KAA8B;CAC5G,OAAO,CAAC,IAAI,MAAM,EAAE,GAAG,IAAI,MAAM,EAAE,CAAC;AACtC;AAiBA,SAAgB,QAAQ,GAAG,MAAmC;CAC5D,OAAO,MAAM,uBAAuB,IAAI;AAC1C;;;;;;AClBA,SAAgB,uBAAgC,OAAe,IAA6B;CAC1F,OAAO,CAAC,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;AAChC;AAgBA,SAAgB,SAAS,GAAG,MAAmC;CAC7D,OAAO,MAAM,wBAAwB,IAAI;AAC3C;;;ACvBA,SAAS,wBAAiC,OAAe,IAA6B;CACpF,OAAO,CAAC,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC;AAChC;AAgBA,SAAgB,UAAU,GAAG,MAAmC;CAC9D,OAAO,MAAM,yBAAyB,IAAI;AAC5C;;;;;;;;;;;;;;;;ACTA,SAAgB,OAAU,OAAsC;CAC9D,IAAI,MAAM,SAAS,GACjB,MAAM,IAAI,WAAW,8DAA8D;CAErF,OAAO,MAAM;AACf;;;;;;;;;;;;;;ACPA,SAAgB,KAAW,MAAsB;CAC/C,OAAO,CAAC,KAAK,IAAI,KAAK,EAAE;AAC1B"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Global configuration types.
|
|
4
|
+
*/
|
|
5
|
+
interface Config {
|
|
6
|
+
noUncheckedIndexedAccess: true;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the `noUncheckedIndexedAccess` value from the provided configuration type.
|
|
10
|
+
* Defaults to `false` if not specified.
|
|
11
|
+
*/
|
|
12
|
+
type NoUncheckedIndexedAccess<TConfig = Config> = TConfig extends {
|
|
13
|
+
noUncheckedIndexedAccess: infer TValue;
|
|
14
|
+
} ? TValue : false;
|
|
15
|
+
/**
|
|
16
|
+
* Returns `T | undefined` if `noUncheckedIndexedAccess` is enabled, otherwise returns `T`.
|
|
17
|
+
* Simulates TypeScript's `noUncheckedIndexedAccess` compiler option.
|
|
18
|
+
*/
|
|
19
|
+
type Accessed<T> = NoUncheckedIndexedAccess extends true ? T | undefined : T;
|
|
20
|
+
/**
|
|
21
|
+
* Represents an array containing at least one element.
|
|
22
|
+
*/
|
|
23
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
24
|
+
/**
|
|
25
|
+
* Represents a readonly array containing at least one element.
|
|
26
|
+
*/
|
|
27
|
+
type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
|
|
28
|
+
/**
|
|
29
|
+
* Helper type to prevent type inference on `T`.
|
|
30
|
+
*/
|
|
31
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
32
|
+
/**
|
|
33
|
+
* Evaluates to `true` if type `T` is `any`, otherwise `false`.
|
|
34
|
+
*/
|
|
35
|
+
type IsAny<T> = 0 extends NoInfer<T> & 1 ? true : false;
|
|
36
|
+
/**
|
|
37
|
+
* Narrows type `T` to base type `Base`. Reverts to `Base` if `T` is `any` or incompatible.
|
|
38
|
+
*/
|
|
39
|
+
type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
|
|
40
|
+
/**
|
|
41
|
+
* Extracts the success type from a union type containing `Error`.
|
|
42
|
+
*/
|
|
43
|
+
type Ok<T> = Exclude<T, Error>;
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the `Error` type from a union type.
|
|
46
|
+
*/
|
|
47
|
+
type Err<T> = Extract<T, Error>;
|
|
48
|
+
/**
|
|
49
|
+
* Represents a function taking a single input of type `I` and returning type `O`.
|
|
50
|
+
*/
|
|
51
|
+
type Fn<I, O> = (input: I) => O;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { NonEmptyArray as a, NarrowedTo as i, Err as n, Ok as o, Fn as r, ReadonlyNonEmptyArray as s, Accessed as t };
|
|
54
|
+
//# sourceMappingURL=types-D8f67ZCe.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-D8f67ZCe.d.cts","names":[],"sources":["../src/types.ts"],"mappings":";;AAGA;;UAAiB,MAAA;EACf,wBAAwB;AAAA;AAO1B;;;;AAAA,KAAY,wBAAA,WAAmC,MAAA,IAAU,OAAO;EAC9D,wBAAA;AAAA,IAEE,MAAA;;;;;KAOQ,QAAA,MAAc,wBAAA,gBAAwC,CAAA,eAAgB,CAAA;;;;KAqBtE,aAAA,OAAoB,CAAA,KAAM,CAAC;AAAvC;;;AAAA,KAKY,qBAAA,gBAAqC,CAAA,KAAM,CAAC;;;;KAKnD,OAAA,MAAa,CAAC,mBAAmB,CAAA;AAVC;AAKvC;;AALuC,KAe3B,KAAA,gBAAqB,OAAO,CAAC,CAAA;;;;KAK7B,UAAA,YACV,OAAA,CAAQ,CAAA,EAAG,IAAA,kBAAsB,IAAA,GAAO,KAAA,CAAM,CAAA,iBAAkB,IAAA,GAAO,OAAA,CAAQ,CAAA,EAAG,IAAA;;AAX7C;AAKvC;KA+BY,EAAA,MAAQ,OAAA,CAAQ,CAAA,EAAG,KAAA;;;;KAKnB,GAAA,MAAS,OAAA,CAAQ,CAAA,EAAG,KAAA;;;AApCU;KAyC9B,EAAA,UAAY,KAAA,EAAO,CAAA,KAAM,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Global configuration types.
|
|
4
|
+
*/
|
|
5
|
+
interface Config {
|
|
6
|
+
noUncheckedIndexedAccess: true;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Extracts the `noUncheckedIndexedAccess` value from the provided configuration type.
|
|
10
|
+
* Defaults to `false` if not specified.
|
|
11
|
+
*/
|
|
12
|
+
type NoUncheckedIndexedAccess<TConfig = Config> = TConfig extends {
|
|
13
|
+
noUncheckedIndexedAccess: infer TValue;
|
|
14
|
+
} ? TValue : false;
|
|
15
|
+
/**
|
|
16
|
+
* Returns `T | undefined` if `noUncheckedIndexedAccess` is enabled, otherwise returns `T`.
|
|
17
|
+
* Simulates TypeScript's `noUncheckedIndexedAccess` compiler option.
|
|
18
|
+
*/
|
|
19
|
+
type Accessed<T> = NoUncheckedIndexedAccess extends true ? T | undefined : T;
|
|
20
|
+
/**
|
|
21
|
+
* Represents an array containing at least one element.
|
|
22
|
+
*/
|
|
23
|
+
type NonEmptyArray<T> = [T, ...T[]];
|
|
24
|
+
/**
|
|
25
|
+
* Represents a readonly array containing at least one element.
|
|
26
|
+
*/
|
|
27
|
+
type ReadonlyNonEmptyArray<T> = readonly [T, ...T[]];
|
|
28
|
+
/**
|
|
29
|
+
* Helper type to prevent type inference on `T`.
|
|
30
|
+
*/
|
|
31
|
+
type NoInfer<T> = T extends infer U ? U : never;
|
|
32
|
+
/**
|
|
33
|
+
* Evaluates to `true` if type `T` is `any`, otherwise `false`.
|
|
34
|
+
*/
|
|
35
|
+
type IsAny<T> = 0 extends NoInfer<T> & 1 ? true : false;
|
|
36
|
+
/**
|
|
37
|
+
* Narrows type `T` to base type `Base`. Reverts to `Base` if `T` is `any` or incompatible.
|
|
38
|
+
*/
|
|
39
|
+
type NarrowedTo<T, Base> = Extract<T, Base> extends never ? Base : IsAny<T> extends true ? Base : Extract<T, Base>;
|
|
40
|
+
/**
|
|
41
|
+
* Extracts the success type from a union type containing `Error`.
|
|
42
|
+
*/
|
|
43
|
+
type Ok<T> = Exclude<T, Error>;
|
|
44
|
+
/**
|
|
45
|
+
* Extracts the `Error` type from a union type.
|
|
46
|
+
*/
|
|
47
|
+
type Err<T> = Extract<T, Error>;
|
|
48
|
+
/**
|
|
49
|
+
* Represents a function taking a single input of type `I` and returning type `O`.
|
|
50
|
+
*/
|
|
51
|
+
type Fn<I, O> = (input: I) => O;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { NonEmptyArray as a, NarrowedTo as i, Err as n, Ok as o, Fn as r, ReadonlyNonEmptyArray as s, Accessed as t };
|
|
54
|
+
//# sourceMappingURL=types-D8f67ZCe.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-D8f67ZCe.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;AAGA;;UAAiB,MAAA;EACf,wBAAwB;AAAA;AAO1B;;;;AAAA,KAAY,wBAAA,WAAmC,MAAA,IAAU,OAAO;EAC9D,wBAAA;AAAA,IAEE,MAAA;;;;;KAOQ,QAAA,MAAc,wBAAA,gBAAwC,CAAA,eAAgB,CAAA;;;;KAqBtE,aAAA,OAAoB,CAAA,KAAM,CAAC;AAAvC;;;AAAA,KAKY,qBAAA,gBAAqC,CAAA,KAAM,CAAC;;;;KAKnD,OAAA,MAAa,CAAC,mBAAmB,CAAA;AAVC;AAKvC;;AALuC,KAe3B,KAAA,gBAAqB,OAAO,CAAC,CAAA;;;;KAK7B,UAAA,YACV,OAAA,CAAQ,CAAA,EAAG,IAAA,kBAAsB,IAAA,GAAO,KAAA,CAAM,CAAA,iBAAkB,IAAA,GAAO,OAAA,CAAQ,CAAA,EAAG,IAAA;;AAX7C;AAKvC;KA+BY,EAAA,MAAQ,OAAA,CAAQ,CAAA,EAAG,KAAA;;;;KAKnB,GAAA,MAAS,OAAA,CAAQ,CAAA,EAAG,KAAA;;;AApCU;KAyC9B,EAAA,UAAY,KAAA,EAAO,CAAA,KAAM,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ts-fns/stdlib",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"author": "Harris Miller <harrismillerconsulting@gmail.com>",
|
|
6
|
+
"packageManager": "pnpm@10.29.3",
|
|
7
|
+
"description": "A Functional Programming Standard Library for Typescript",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/Harris-Miller/fp-utils.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"fp",
|
|
15
|
+
"stdlib",
|
|
16
|
+
"typescript",
|
|
17
|
+
"functional",
|
|
18
|
+
"result",
|
|
19
|
+
"adt",
|
|
20
|
+
"lens",
|
|
21
|
+
"lenses"
|
|
22
|
+
],
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"clean": "rimraf dist public",
|
|
29
|
+
"docs": "typedoc",
|
|
30
|
+
"docs:dev": "vitepress dev docs",
|
|
31
|
+
"docs:build": "vitepress build docs",
|
|
32
|
+
"docs:preview": "vitepress preview docs",
|
|
33
|
+
"lint": "eslint .",
|
|
34
|
+
"local-ci": "run-s typecheck lint test test-d",
|
|
35
|
+
"test": "vitest --passWithNoTests",
|
|
36
|
+
"test-d": "vitest --typecheck.only --typecheck.ignoreSourceErrors",
|
|
37
|
+
"typecheck": "tsgo --noEmit"
|
|
38
|
+
},
|
|
39
|
+
"exports": {
|
|
40
|
+
"array": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./dist/array/index.d.mts",
|
|
43
|
+
"default": "./dist/array/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/array/index.d.cts",
|
|
47
|
+
"default": "./dist/array/index.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"function": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./dist/function/index.d.mts",
|
|
53
|
+
"default": "./dist/function/index.mjs"
|
|
54
|
+
},
|
|
55
|
+
"require": {
|
|
56
|
+
"types": "./dist/function/index.d.cts",
|
|
57
|
+
"default": "./dist/function/index.cjs"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"guard": {
|
|
61
|
+
"import": {
|
|
62
|
+
"types": "./dist/guard/index.d.mts",
|
|
63
|
+
"default": "./dist/guard/index.mjs"
|
|
64
|
+
},
|
|
65
|
+
"require": {
|
|
66
|
+
"types": "./dist/guard/index.d.cts",
|
|
67
|
+
"default": "./dist/guard/index.cjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"iterator": {
|
|
71
|
+
"import": {
|
|
72
|
+
"types": "./dist/iterator/index.d.mts",
|
|
73
|
+
"default": "./dist/iterator/index.mjs"
|
|
74
|
+
},
|
|
75
|
+
"require": {
|
|
76
|
+
"types": "./dist/iterator/index.d.cts",
|
|
77
|
+
"default": "./dist/iterator/index.cjs"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"lens": {
|
|
81
|
+
"import": {
|
|
82
|
+
"types": "./dist/lens/index.d.mts",
|
|
83
|
+
"default": "./dist/lens/index.mjs"
|
|
84
|
+
},
|
|
85
|
+
"require": {
|
|
86
|
+
"types": "./dist/lens/index.d.cts",
|
|
87
|
+
"default": "./dist/lens/index.cjs"
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
"map": {
|
|
91
|
+
"import": {
|
|
92
|
+
"types": "./dist/map/index.d.mts",
|
|
93
|
+
"default": "./dist/map/index.mjs"
|
|
94
|
+
},
|
|
95
|
+
"require": {
|
|
96
|
+
"types": "./dist/map/index.d.cts",
|
|
97
|
+
"default": "./dist/map/index.cjs"
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
"number": {
|
|
101
|
+
"import": {
|
|
102
|
+
"types": "./dist/number/index.d.mts",
|
|
103
|
+
"default": "./dist/number/index.mjs"
|
|
104
|
+
},
|
|
105
|
+
"require": {
|
|
106
|
+
"types": "./dist/number/index.d.cts",
|
|
107
|
+
"default": "./dist/number/index.cjs"
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"object": {
|
|
111
|
+
"import": {
|
|
112
|
+
"types": "./dist/object/index.d.mts",
|
|
113
|
+
"default": "./dist/object/index.mjs"
|
|
114
|
+
},
|
|
115
|
+
"require": {
|
|
116
|
+
"types": "./dist/object/index.d.cts",
|
|
117
|
+
"default": "./dist/object/index.cjs"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"order": {
|
|
121
|
+
"import": {
|
|
122
|
+
"types": "./dist/order/index.d.mts",
|
|
123
|
+
"default": "./dist/order/index.mjs"
|
|
124
|
+
},
|
|
125
|
+
"require": {
|
|
126
|
+
"types": "./dist/order/index.d.cts",
|
|
127
|
+
"default": "./dist/order/index.cjs"
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
"set": {
|
|
131
|
+
"import": {
|
|
132
|
+
"types": "./dist/set/index.d.mts",
|
|
133
|
+
"default": "./dist/set/index.mjs"
|
|
134
|
+
},
|
|
135
|
+
"require": {
|
|
136
|
+
"types": "./dist/set/index.d.cts",
|
|
137
|
+
"default": "./dist/set/index.cjs"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"string": {
|
|
141
|
+
"import": {
|
|
142
|
+
"types": "./dist/string/index.d.mts",
|
|
143
|
+
"default": "./dist/string/index.mjs"
|
|
144
|
+
},
|
|
145
|
+
"require": {
|
|
146
|
+
"types": "./dist/string/index.d.cts",
|
|
147
|
+
"default": "./dist/string/index.cjs"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"tuple": {
|
|
151
|
+
"import": {
|
|
152
|
+
"types": "./dist/tuple/index.d.mts",
|
|
153
|
+
"default": "./dist/tuple/index.mjs"
|
|
154
|
+
},
|
|
155
|
+
"require": {
|
|
156
|
+
"types": "./dist/tuple/index.d.cts",
|
|
157
|
+
"default": "./dist/tuple/index.cjs"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"dependencies": {
|
|
162
|
+
"type-fest": "^5.7.0"
|
|
163
|
+
},
|
|
164
|
+
"devDependencies": {
|
|
165
|
+
"@types/node": "^22.19.19",
|
|
166
|
+
"@typescript/native-preview": "7.0.0-dev.20260527.2",
|
|
167
|
+
"eslint": "^9.39.4",
|
|
168
|
+
"eslint-config-harris": "5.1.2",
|
|
169
|
+
"npm-run-all2": "^9.0.1",
|
|
170
|
+
"rimraf": "^6.1.3",
|
|
171
|
+
"tsdown": "^0.22.1",
|
|
172
|
+
"typedoc": "^0.28.19",
|
|
173
|
+
"typescript": "^6.0.3",
|
|
174
|
+
"vitepress": "2.0.0-alpha.17",
|
|
175
|
+
"vitest": "^4.1.7"
|
|
176
|
+
}
|
|
177
|
+
}
|