modern-ts 0.8.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 +201 -0
- package/README.md +223 -0
- package/README.zh-CN.md +223 -0
- package/dist/chunks/Errors-BWEYu-AB.cjs +2 -0
- package/dist/chunks/Errors-BWEYu-AB.cjs.map +1 -0
- package/dist/chunks/Errors-DwUAvFIF.mjs +63 -0
- package/dist/chunks/Errors-DwUAvFIF.mjs.map +1 -0
- package/dist/chunks/Math-CGEH1ClN.mjs +68 -0
- package/dist/chunks/Math-CGEH1ClN.mjs.map +1 -0
- package/dist/chunks/Math-CWZVxSF-.cjs +2 -0
- package/dist/chunks/Math-CWZVxSF-.cjs.map +1 -0
- package/dist/chunks/base-B9k8Lqvf.mjs +56 -0
- package/dist/chunks/base-B9k8Lqvf.mjs.map +1 -0
- package/dist/chunks/base-BTXL1y_I.cjs +2 -0
- package/dist/chunks/base-BTXL1y_I.cjs.map +1 -0
- package/dist/chunks/base-BpECeKwU.mjs +19 -0
- package/dist/chunks/base-BpECeKwU.mjs.map +1 -0
- package/dist/chunks/base-BvHqpP_s.cjs +2 -0
- package/dist/chunks/base-BvHqpP_s.cjs.map +1 -0
- package/dist/chunks/base-K-RHLZ-S.mjs +46 -0
- package/dist/chunks/base-K-RHLZ-S.mjs.map +1 -0
- package/dist/chunks/base-r6kn0B0D.cjs +2 -0
- package/dist/chunks/base-r6kn0B0D.cjs.map +1 -0
- package/dist/chunks/combine-async-DcG-3p8i.cjs +2 -0
- package/dist/chunks/combine-async-DcG-3p8i.cjs.map +1 -0
- package/dist/chunks/combine-async-Dcg4ya1R.mjs +236 -0
- package/dist/chunks/combine-async-Dcg4ya1R.mjs.map +1 -0
- package/dist/chunks/delay-CG3cD7bk.cjs +2 -0
- package/dist/chunks/delay-CG3cD7bk.cjs.map +1 -0
- package/dist/chunks/delay-CKIXpP71.mjs +32 -0
- package/dist/chunks/delay-CKIXpP71.mjs.map +1 -0
- package/dist/chunks/helper-BVabbpmX.mjs +165 -0
- package/dist/chunks/helper-BVabbpmX.mjs.map +1 -0
- package/dist/chunks/helper-tsqZMRHW.cjs +3 -0
- package/dist/chunks/helper-tsqZMRHW.cjs.map +1 -0
- package/dist/chunks/local-8JVtLN0O.mjs +10 -0
- package/dist/chunks/local-8JVtLN0O.mjs.map +1 -0
- package/dist/chunks/local-Da4yU-nE.cjs +2 -0
- package/dist/chunks/local-Da4yU-nE.cjs.map +1 -0
- package/dist/chunks/types-B7X_LBjM.cjs +2 -0
- package/dist/chunks/types-B7X_LBjM.cjs.map +1 -0
- package/dist/chunks/types-DE2SnSbz.mjs +5 -0
- package/dist/chunks/types-DE2SnSbz.mjs.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.mjs +759 -0
- package/dist/index.mjs.map +1 -0
- package/dist/subpath/Arr.cjs +2 -0
- package/dist/subpath/Arr.cjs.map +1 -0
- package/dist/subpath/Arr.mjs +539 -0
- package/dist/subpath/Arr.mjs.map +1 -0
- package/dist/subpath/Concurrent.cjs +15 -0
- package/dist/subpath/Concurrent.cjs.map +1 -0
- package/dist/subpath/Concurrent.mjs +4044 -0
- package/dist/subpath/Concurrent.mjs.map +1 -0
- package/dist/subpath/FetchQ.cjs +2 -0
- package/dist/subpath/FetchQ.cjs.map +1 -0
- package/dist/subpath/FetchQ.mjs +519 -0
- package/dist/subpath/FetchQ.mjs.map +1 -0
- package/dist/subpath/Fit.cjs +2 -0
- package/dist/subpath/Fit.cjs.map +1 -0
- package/dist/subpath/Fit.mjs +914 -0
- package/dist/subpath/Fit.mjs.map +1 -0
- package/dist/subpath/Lazy.cjs +2 -0
- package/dist/subpath/Lazy.cjs.map +1 -0
- package/dist/subpath/Lazy.mjs +72 -0
- package/dist/subpath/Lazy.mjs.map +1 -0
- package/dist/subpath/Maps.cjs +2 -0
- package/dist/subpath/Maps.cjs.map +1 -0
- package/dist/subpath/Maps.mjs +123 -0
- package/dist/subpath/Maps.mjs.map +1 -0
- package/dist/subpath/Maybe.cjs +2 -0
- package/dist/subpath/Maybe.cjs.map +1 -0
- package/dist/subpath/Maybe.mjs +329 -0
- package/dist/subpath/Maybe.mjs.map +1 -0
- package/dist/subpath/Reactive.cjs +2 -0
- package/dist/subpath/Reactive.cjs.map +1 -0
- package/dist/subpath/Reactive.mjs +1204 -0
- package/dist/subpath/Reactive.mjs.map +1 -0
- package/dist/subpath/Reader.cjs +2 -0
- package/dist/subpath/Reader.cjs.map +1 -0
- package/dist/subpath/Reader.mjs +75 -0
- package/dist/subpath/Reader.mjs.map +1 -0
- package/dist/subpath/ReaderT.cjs +2 -0
- package/dist/subpath/ReaderT.cjs.map +1 -0
- package/dist/subpath/ReaderT.mjs +148 -0
- package/dist/subpath/ReaderT.mjs.map +1 -0
- package/dist/subpath/Resource.cjs +2 -0
- package/dist/subpath/Resource.cjs.map +1 -0
- package/dist/subpath/Resource.mjs +150 -0
- package/dist/subpath/Resource.mjs.map +1 -0
- package/dist/subpath/Result.cjs +2 -0
- package/dist/subpath/Result.cjs.map +1 -0
- package/dist/subpath/Result.mjs +337 -0
- package/dist/subpath/Result.mjs.map +1 -0
- package/dist/subpath/Sets.cjs +2 -0
- package/dist/subpath/Sets.cjs.map +1 -0
- package/dist/subpath/Sets.mjs +92 -0
- package/dist/subpath/Sets.mjs.map +1 -0
- package/dist/subpath/Str.cjs +2 -0
- package/dist/subpath/Str.cjs.map +1 -0
- package/dist/subpath/Str.mjs +114 -0
- package/dist/subpath/Str.mjs.map +1 -0
- package/dist/subpath/TxScope.cjs +2 -0
- package/dist/subpath/TxScope.cjs.map +1 -0
- package/dist/subpath/TxScope.mjs +138 -0
- package/dist/subpath/TxScope.mjs.map +1 -0
- package/dist/subpath/TypeTool.cjs +2 -0
- package/dist/subpath/TypeTool.cjs.map +1 -0
- package/dist/subpath/TypeTool.mjs +9 -0
- package/dist/subpath/TypeTool.mjs.map +1 -0
- package/dist/subpath/Utils.cjs +2 -0
- package/dist/subpath/Utils.cjs.map +1 -0
- package/dist/subpath/Utils.mjs +835 -0
- package/dist/subpath/Utils.mjs.map +1 -0
- package/dist/subpath/VirtualTime.cjs +2 -0
- package/dist/subpath/VirtualTime.cjs.map +1 -0
- package/dist/subpath/VirtualTime.mjs +1186 -0
- package/dist/subpath/VirtualTime.mjs.map +1 -0
- package/dist/types/Arr.d.ts +2 -0
- package/dist/types/Concurrent/Lock/condition_variable.d.ts +138 -0
- package/dist/types/Concurrent/Lock/mutex.d.ts +185 -0
- package/dist/types/Concurrent/Lock/rwlock.d.ts +253 -0
- package/dist/types/Concurrent/Lock/semaphore.d.ts +208 -0
- package/dist/types/Concurrent/Valve/__export__.d.ts +5 -0
- package/dist/types/Concurrent/Valve/circuit-breaker.d.ts +146 -0
- package/dist/types/Concurrent/Valve/leaky-bucket.d.ts +115 -0
- package/dist/types/Concurrent/Valve/sliding-window.d.ts +91 -0
- package/dist/types/Concurrent/Valve/token-bucket.d.ts +68 -0
- package/dist/types/Concurrent/__export__.d.ts +15 -0
- package/dist/types/Concurrent/barrier.d.ts +255 -0
- package/dist/types/Concurrent/channel.d.ts +239 -0
- package/dist/types/Concurrent/delay.d.ts +42 -0
- package/dist/types/Concurrent/ext/map.d.ts +82 -0
- package/dist/types/Concurrent/ext/other.d.ts +113 -0
- package/dist/types/Concurrent/ext/race.d.ts +31 -0
- package/dist/types/Concurrent/ext/some.d.ts +64 -0
- package/dist/types/Concurrent/limiter.d.ts +131 -0
- package/dist/types/Concurrent/scheduler.d.ts +171 -0
- package/dist/types/Concurrent/task-scope.d.ts +282 -0
- package/dist/types/Concurrent.d.ts +2 -0
- package/dist/types/Errors.d.ts +66 -0
- package/dist/types/FetchQ.d.ts +2 -0
- package/dist/types/Fit/__export__.d.ts +5 -0
- package/dist/types/Fit/base.d.ts +325 -0
- package/dist/types/Fit/parser.d.ts +110 -0
- package/dist/types/Fit/standard-schema.d.ts +127 -0
- package/dist/types/Fit/sugar.d.ts +274 -0
- package/dist/types/Fit/tool.d.ts +585 -0
- package/dist/types/Fit.d.ts +2 -0
- package/dist/types/Lazy.d.ts +2 -0
- package/dist/types/Maps.d.ts +2 -0
- package/dist/types/Maybe/__export__.d.ts +6 -0
- package/dist/types/Maybe/base.d.ts +62 -0
- package/dist/types/Maybe/consumers-async.d.ts +58 -0
- package/dist/types/Maybe/consumers.d.ts +63 -0
- package/dist/types/Maybe/operators-async.d.ts +145 -0
- package/dist/types/Maybe/operators.d.ts +177 -0
- package/dist/types/Maybe/types.d.ts +12 -0
- package/dist/types/Maybe.d.ts +2 -0
- package/dist/types/MockClock/Timeline.d.ts +392 -0
- package/dist/types/MockClock/TimerHandle.d.ts +159 -0
- package/dist/types/MockClock/TimerHeap.d.ts +21 -0
- package/dist/types/MockClock/VirtualTimeManager.d.ts +23 -0
- package/dist/types/MockClock/__export__.d.ts +104 -0
- package/dist/types/MockClock/hooks/__export__.d.ts +9 -0
- package/dist/types/MockClock/hooks/hookAbortSignal.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookDate.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookIntl.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookMessageChannel.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookMicrotasks.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookOs.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookPerformance.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookProcess.d.ts +3 -0
- package/dist/types/MockClock/hooks/hookTimers.d.ts +3 -0
- package/dist/types/MockClock/types.d.ts +103 -0
- package/dist/types/Other/FetchQ.d.ts +320 -0
- package/dist/types/Other/deque.d.ts +59 -0
- package/dist/types/Other/disjointSet.d.ts +53 -0
- package/dist/types/Other/heap.d.ts +41 -0
- package/dist/types/Other/lazy.d.ts +127 -0
- package/dist/types/Other/queue.d.ts +42 -0
- package/dist/types/Other/secret.d.ts +111 -0
- package/dist/types/Other/stack.d.ts +40 -0
- package/dist/types/Reactive/__export__.d.ts +4 -0
- package/dist/types/Reactive/event_emitter.d.ts +195 -0
- package/dist/types/Reactive/flow-combination.d.ts +74 -0
- package/dist/types/Reactive/flow.d.ts +180 -0
- package/dist/types/Reactive/pace.d.ts +80 -0
- package/dist/types/Reactive.d.ts +2 -0
- package/dist/types/Reader/__export-readerT__.d.ts +4 -0
- package/dist/types/Reader/__export-reader__.d.ts +4 -0
- package/dist/types/Reader/local.d.ts +39 -0
- package/dist/types/Reader/reader-async.d.ts +84 -0
- package/dist/types/Reader/reader.d.ts +96 -0
- package/dist/types/Reader/readerT-async.d.ts +186 -0
- package/dist/types/Reader/readerT.d.ts +178 -0
- package/dist/types/Reader/types.d.ts +37 -0
- package/dist/types/Reader.d.ts +2 -0
- package/dist/types/ReaderT.d.ts +2 -0
- package/dist/types/Resource/TxScope-async.d.ts +86 -0
- package/dist/types/Resource/TxScope.d.ts +85 -0
- package/dist/types/Resource/__export-TxScope__.d.ts +2 -0
- package/dist/types/Resource/__export-resource__.d.ts +2 -0
- package/dist/types/Resource/resource-async.d.ts +79 -0
- package/dist/types/Resource/resource.d.ts +78 -0
- package/dist/types/Resource/types.d.ts +79 -0
- package/dist/types/Resource.d.ts +2 -0
- package/dist/types/Result/Consumers/branch-async.d.ts +77 -0
- package/dist/types/Result/Consumers/branch.d.ts +70 -0
- package/dist/types/Result/Consumers/inspect.d.ts +66 -0
- package/dist/types/Result/Operators/Async/combine-async.d.ts +69 -0
- package/dist/types/Result/Operators/Async/partition-async.d.ts +29 -0
- package/dist/types/Result/Operators/Async/reduce-async.d.ts +15 -0
- package/dist/types/Result/Operators/Async/transform-async.d.ts +90 -0
- package/dist/types/Result/Operators/combine.d.ts +60 -0
- package/dist/types/Result/Operators/flatten.d.ts +26 -0
- package/dist/types/Result/Operators/partition.d.ts +25 -0
- package/dist/types/Result/Operators/reduce.d.ts +12 -0
- package/dist/types/Result/Operators/transform.d.ts +70 -0
- package/dist/types/Result/__export__.d.ts +14 -0
- package/dist/types/Result/base.d.ts +115 -0
- package/dist/types/Result/types.d.ts +34 -0
- package/dist/types/Result.d.ts +2 -0
- package/dist/types/Sets.d.ts +2 -0
- package/dist/types/Str.d.ts +2 -0
- package/dist/types/TxScope.d.ts +2 -0
- package/dist/types/TypeTool.d.ts +2 -0
- package/dist/types/Utils/Array/__export__.d.ts +10 -0
- package/dist/types/Utils/Array/filtering.d.ts +89 -0
- package/dist/types/Utils/Array/flatten.d.ts +45 -0
- package/dist/types/Utils/Array/grouping.d.ts +44 -0
- package/dist/types/Utils/Array/iteration.d.ts +86 -0
- package/dist/types/Utils/Array/operators.d.ts +62 -0
- package/dist/types/Utils/Array/randomization.d.ts +76 -0
- package/dist/types/Utils/Array/set.d.ts +108 -0
- package/dist/types/Utils/Array/slice.d.ts +189 -0
- package/dist/types/Utils/Array/sorting.d.ts +55 -0
- package/dist/types/Utils/Array/zip.d.ts +93 -0
- package/dist/types/Utils/Functions/__export__.d.ts +5 -0
- package/dist/types/Utils/Functions/base.d.ts +157 -0
- package/dist/types/Utils/Functions/curry.d.ts +73 -0
- package/dist/types/Utils/Functions/debounce.d.ts +240 -0
- package/dist/types/Utils/Functions/defer.d.ts +43 -0
- package/dist/types/Utils/Functions/pipe.d.ts +205 -0
- package/dist/types/Utils/Map.d.ts +284 -0
- package/dist/types/Utils/Math.d.ts +225 -0
- package/dist/types/Utils/Object/__export__.d.ts +2 -0
- package/dist/types/Utils/Object/base.d.ts +131 -0
- package/dist/types/Utils/Object/clone.d.ts +81 -0
- package/dist/types/Utils/Predicates.d.ts +361 -0
- package/dist/types/Utils/Set.d.ts +105 -0
- package/dist/types/Utils/String.d.ts +217 -0
- package/dist/types/Utils/__export__.d.ts +9 -0
- package/dist/types/Utils/type-tool.d.ts +168 -0
- package/dist/types/Utils.d.ts +2 -0
- package/dist/types/VirtualTime.d.ts +2 -0
- package/dist/types/helper.d.ts +71 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/unknown-error.d.ts +98 -0
- package/package.json +179 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clamps a number between a minimum and maximum value.
|
|
3
|
+
* @param n The number to clamp.
|
|
4
|
+
* @param min The minimum allowed value.
|
|
5
|
+
* @param max The maximum allowed value.
|
|
6
|
+
* @returns The clamped number.
|
|
7
|
+
*/
|
|
8
|
+
export declare const clamp: (n: number, min: number, max: number) => number;
|
|
9
|
+
/**
|
|
10
|
+
* Rounds a number to a specified number of decimal places.
|
|
11
|
+
* @param n The number to round.
|
|
12
|
+
* @param precision The number of decimal places (default: 0).
|
|
13
|
+
* @returns The rounded number.
|
|
14
|
+
*/
|
|
15
|
+
export declare const round: (n: number, precision?: number) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes a value from a given range to [0, 1].
|
|
18
|
+
* @param n The value to normalize.
|
|
19
|
+
* @param min The minimum of the original range.
|
|
20
|
+
* @param max The maximum of the original range.
|
|
21
|
+
* @returns The normalized value in [0, 1].
|
|
22
|
+
*/
|
|
23
|
+
export declare const normalize: (n: number, min: number, max: number) => number;
|
|
24
|
+
/**
|
|
25
|
+
* Computes the greatest common divisor (GCD) of two numbers.
|
|
26
|
+
* @param a First number
|
|
27
|
+
* @param b Second number
|
|
28
|
+
* @returns The GCD (always non-negative)
|
|
29
|
+
*/
|
|
30
|
+
export declare const gcd: (a: number, b: number) => number;
|
|
31
|
+
/**
|
|
32
|
+
* Computes the least common multiple (LCM) of two numbers.
|
|
33
|
+
* Uses safe calculation to prevent integer overflow.
|
|
34
|
+
* @param a First number
|
|
35
|
+
* @param b Second number
|
|
36
|
+
* @returns The LCM (always non-negative), 0 if either input is 0
|
|
37
|
+
*/
|
|
38
|
+
export declare const lcm: (a: number, b: number) => number;
|
|
39
|
+
/**
|
|
40
|
+
* Checks if a number is within a specified range [min, max).
|
|
41
|
+
* @param n The number to check.
|
|
42
|
+
* @param min The inclusive lower bound.
|
|
43
|
+
* @param max The exclusive upper bound.
|
|
44
|
+
* @returns `true` if the number is in range.
|
|
45
|
+
*/
|
|
46
|
+
export declare const inRange: (n: number, min: number, max: number) => boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Generates an array of numbers from `start` to `end` (exclusive), incremented by `step`.
|
|
49
|
+
* @param start The start of the range.
|
|
50
|
+
* @param end The end of the range (exclusive).
|
|
51
|
+
* @param step The increment between numbers (default: 1).
|
|
52
|
+
* @returns An array of numbers.
|
|
53
|
+
*/
|
|
54
|
+
export declare const range: (start: number, end: number, step?: number) => number[];
|
|
55
|
+
/**
|
|
56
|
+
* Like `range`, but returns numbers in reverse order.
|
|
57
|
+
* @param start The start of the range.
|
|
58
|
+
* @param end The end of the range (exclusive).
|
|
59
|
+
* @param step The increment between numbers (default: 1).
|
|
60
|
+
* @returns A reversed array of numbers.
|
|
61
|
+
*/
|
|
62
|
+
export declare const rangeRight: (start: number, end: number, step?: number) => number[];
|
|
63
|
+
/**
|
|
64
|
+
* Maps a number from one range to another linearly.
|
|
65
|
+
* @param n The input value.
|
|
66
|
+
* @param inMin Minimum of the input range.
|
|
67
|
+
* @param inMax Maximum of the input range.
|
|
68
|
+
* @param outMin Minimum of the output range.
|
|
69
|
+
* @param outMax Maximum of the output range.
|
|
70
|
+
* @returns The mapped value.
|
|
71
|
+
*/
|
|
72
|
+
export declare const mapRange: (n: number, inMin: number, inMax: number, outMin: number, outMax: number) => number;
|
|
73
|
+
/**
|
|
74
|
+
* Generates a random floating-point number between `min` (inclusive) and `max` (exclusive).
|
|
75
|
+
* @param min The minimum value (inclusive).
|
|
76
|
+
* @param max The maximum value (exclusive).
|
|
77
|
+
* @returns A random number in [min, max).
|
|
78
|
+
*/
|
|
79
|
+
export declare const random: (min: number, max: number) => number;
|
|
80
|
+
/**
|
|
81
|
+
* Generates a random integer between `min` and `max` (both inclusive).
|
|
82
|
+
* @param min The minimum integer (inclusive).
|
|
83
|
+
* @param max The maximum integer (inclusive).
|
|
84
|
+
* @returns A random integer in [min, max].
|
|
85
|
+
*/
|
|
86
|
+
export declare const randomInt: (min: number, max: number) => number;
|
|
87
|
+
/**
|
|
88
|
+
* Computes the sum of an array of numbers.
|
|
89
|
+
* @param nums Array of numbers.
|
|
90
|
+
* @returns The sum.
|
|
91
|
+
*/
|
|
92
|
+
export declare const sum: (nums: number[]) => number;
|
|
93
|
+
/**
|
|
94
|
+
* Computes the sum of values extracted from an array using a selector function.
|
|
95
|
+
* @param arr The input array.
|
|
96
|
+
* @param getValue A function to extract numeric values from items.
|
|
97
|
+
* @returns The sum of extracted values.
|
|
98
|
+
*/
|
|
99
|
+
export declare const sumBy: <T>(arr: T[], getValue: (item: T) => number) => number;
|
|
100
|
+
/**
|
|
101
|
+
* Computes the arithmetic mean (average) of an array of numbers.
|
|
102
|
+
* @param nums Array of numbers.
|
|
103
|
+
* @returns The mean, or 0 if the array is empty.
|
|
104
|
+
*/
|
|
105
|
+
export declare const mean: (nums: number[]) => number;
|
|
106
|
+
/**
|
|
107
|
+
* Computes the arithmetic mean of values extracted from an array.
|
|
108
|
+
* @param arr The input array.
|
|
109
|
+
* @param getValue A function to extract numeric values from items.
|
|
110
|
+
* @returns The mean of extracted values, or 0 if empty.
|
|
111
|
+
*/
|
|
112
|
+
export declare const meanBy: <T>(arr: T[], getValue: (item: T) => number) => number;
|
|
113
|
+
/**
|
|
114
|
+
* Computes the median of an array of numbers.
|
|
115
|
+
* @param nums Array of numbers.
|
|
116
|
+
* @returns The median value.
|
|
117
|
+
*/
|
|
118
|
+
export declare const median: (nums: number[]) => number;
|
|
119
|
+
/**
|
|
120
|
+
* Computes the median of values extracted from an array.
|
|
121
|
+
* @param arr The input array.
|
|
122
|
+
* @param getValue A function to extract numeric values from items.
|
|
123
|
+
* @returns The median of extracted values.
|
|
124
|
+
*/
|
|
125
|
+
export declare const medianBy: <T>(arr: T[], getValue: (item: T) => number) => number;
|
|
126
|
+
/**
|
|
127
|
+
* Computes the standard deviation of an array of numbers.
|
|
128
|
+
* @param nums Array of numbers.
|
|
129
|
+
* @param isSample If `true`, computes sample standard deviation (Bessel's correction).
|
|
130
|
+
* @returns The standard deviation.
|
|
131
|
+
*/
|
|
132
|
+
export declare const stdDev: (nums: number[], isSample?: boolean) => number;
|
|
133
|
+
/**
|
|
134
|
+
* Checks if two numbers are approximately equal within a tolerance.
|
|
135
|
+
* @param n1 First number.
|
|
136
|
+
* @param n2 Second number.
|
|
137
|
+
* @param epsilon Tolerance (default: 1e-10).
|
|
138
|
+
* @returns `true` if |n1 - n2| < epsilon.
|
|
139
|
+
*/
|
|
140
|
+
export declare const approxEqual: (n1: number, n2: number, epsilon?: number) => boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Checks if a number is even.
|
|
143
|
+
* @param n The number to check.
|
|
144
|
+
* @returns `true` if even.
|
|
145
|
+
*/
|
|
146
|
+
export declare const isEven: (n: number) => boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Checks if a number is odd.
|
|
149
|
+
* @param n The number to check.
|
|
150
|
+
* @returns `true` if odd.
|
|
151
|
+
*/
|
|
152
|
+
export declare const isOdd: (n: number) => boolean;
|
|
153
|
+
/**
|
|
154
|
+
* Converts degrees to radians.
|
|
155
|
+
* @param deg Angle in degrees.
|
|
156
|
+
* @returns Angle in radians.
|
|
157
|
+
*/
|
|
158
|
+
export declare const toRadians: (deg: number) => number;
|
|
159
|
+
/**
|
|
160
|
+
* Converts radians to degrees.
|
|
161
|
+
* @param rad Angle in radians.
|
|
162
|
+
* @returns Angle in degrees.
|
|
163
|
+
*/
|
|
164
|
+
export declare const toDegrees: (rad: number) => number;
|
|
165
|
+
/**
|
|
166
|
+
* Wraps an angle in degrees to [0, 360).
|
|
167
|
+
* @param deg Input angle in degrees.
|
|
168
|
+
* @returns Wrapped angle in [0, 360).
|
|
169
|
+
*/
|
|
170
|
+
export declare const wrapAngle: (deg: number) => number;
|
|
171
|
+
/**
|
|
172
|
+
* Computes the smallest signed difference between two angles (in degrees).
|
|
173
|
+
* Result is in [-180, 180].
|
|
174
|
+
* @param a First angle in degrees.
|
|
175
|
+
* @param b Second angle in degrees.
|
|
176
|
+
* @returns The angular difference.
|
|
177
|
+
*/
|
|
178
|
+
export declare const angleDist: (a: number, b: number) => number;
|
|
179
|
+
/**
|
|
180
|
+
* Computes the Euclidean distance between two 2D points.
|
|
181
|
+
* @param x1 X-coordinate of the first point.
|
|
182
|
+
* @param y1 Y-coordinate of the first point.
|
|
183
|
+
* @param x2 X-coordinate of the second point.
|
|
184
|
+
* @param y2 Y-coordinate of the second point.
|
|
185
|
+
* @returns The distance.
|
|
186
|
+
*/
|
|
187
|
+
export declare const getDistance: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
188
|
+
/**
|
|
189
|
+
* Computes the squared Euclidean distance between two 2D points (faster, no sqrt).
|
|
190
|
+
* @param x1 X-coordinate of the first point.
|
|
191
|
+
* @param y1 Y-coordinate of the first point.
|
|
192
|
+
* @param x2 X-coordinate of the second point.
|
|
193
|
+
* @param y2 Y-coordinate of the second point.
|
|
194
|
+
* @returns The squared distance.
|
|
195
|
+
*/
|
|
196
|
+
export declare const getDistanceSq: (x1: number, y1: number, x2: number, y2: number) => number;
|
|
197
|
+
/**
|
|
198
|
+
* Linearly interpolates between `start` and `end` by factor `t`.
|
|
199
|
+
* @param start Start value.
|
|
200
|
+
* @param end End value.
|
|
201
|
+
* @param t Interpolation factor (0 = start, 1 = end).
|
|
202
|
+
* @returns The interpolated value.
|
|
203
|
+
*/
|
|
204
|
+
export declare const lerp: (start: number, end: number, t: number) => number;
|
|
205
|
+
/**
|
|
206
|
+
* Computes a point on a quadratic Bezier curve.
|
|
207
|
+
* @param p0 Start point {x, y}
|
|
208
|
+
* @param p1 Control point {x, y}
|
|
209
|
+
* @param p2 End point {x, y}
|
|
210
|
+
* @param t Interpolation factor [0, 1]
|
|
211
|
+
* @returns The interpolated point {x, y}
|
|
212
|
+
*/
|
|
213
|
+
export declare const bezier2: (p0: {
|
|
214
|
+
x: number;
|
|
215
|
+
y: number;
|
|
216
|
+
}, p1: {
|
|
217
|
+
x: number;
|
|
218
|
+
y: number;
|
|
219
|
+
}, p2: {
|
|
220
|
+
x: number;
|
|
221
|
+
y: number;
|
|
222
|
+
}, t: number) => {
|
|
223
|
+
x: number;
|
|
224
|
+
y: number;
|
|
225
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transforms object keys using a mapper function.
|
|
3
|
+
* @template T - Object type
|
|
4
|
+
* @param obj - Source object
|
|
5
|
+
* @param fn - Function that receives (value, key) and returns new key name
|
|
6
|
+
* @returns New object with transformed keys (original values preserved)
|
|
7
|
+
* @remarks If fn returns duplicate keys, later entries will overwrite earlier ones
|
|
8
|
+
*/
|
|
9
|
+
export declare const mapKeys: <T extends Record<string, unknown>>(obj: T, fn: (value: T[keyof T], key: keyof T) => string) => Record<string, T[keyof T]>;
|
|
10
|
+
/**
|
|
11
|
+
* Transforms object values while preserving keys.
|
|
12
|
+
* @template T - Source object type
|
|
13
|
+
* @template V - Transformed value type
|
|
14
|
+
* @param obj - Source object
|
|
15
|
+
* @param fn - Function that receives (value, key) and returns new value
|
|
16
|
+
* @returns New object with same keys but transformed values
|
|
17
|
+
*/
|
|
18
|
+
export declare const mapValues: <T extends Record<string, unknown>, V>(obj: T, fn: (value: T[keyof T], key: keyof T) => V) => Record<keyof T, V>;
|
|
19
|
+
/**
|
|
20
|
+
* Swaps object keys and values.
|
|
21
|
+
* @template T - Object with string/number values
|
|
22
|
+
* @param obj - Source object (values must be string or number)
|
|
23
|
+
* @returns New object with keys and values swapped
|
|
24
|
+
* @remarks Duplicate values in source will cause later keys to overwrite earlier ones
|
|
25
|
+
*/
|
|
26
|
+
export declare const invert: <T extends Record<string, string | number>>(obj: T) => Record<string, keyof T>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates new object with only specified keys.
|
|
29
|
+
* @template T - Source object type
|
|
30
|
+
* @template K - Selected keys
|
|
31
|
+
* @param obj - Source object
|
|
32
|
+
* @param keys - Array of keys to include
|
|
33
|
+
* @returns New object containing only specified keys
|
|
34
|
+
* @remarks Keys not present in source object are silently ignored
|
|
35
|
+
*/
|
|
36
|
+
export declare const pick: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates new object with keys satisfying predicate.
|
|
39
|
+
* @template T - Source object type
|
|
40
|
+
* @param obj - Source object
|
|
41
|
+
* @param predicate - Function that receives (value, key) and returns boolean
|
|
42
|
+
* @returns Partial object containing only entries where predicate returns true
|
|
43
|
+
*/
|
|
44
|
+
export declare const pickBy: <T extends Record<PropertyKey, unknown>>(obj: T, predicate: (value: T[keyof T], key: keyof T) => boolean) => Partial<T>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates new object excluding specified keys.
|
|
47
|
+
* @template T - Source object type
|
|
48
|
+
* @template K - Keys to exclude
|
|
49
|
+
* @param obj - Source object
|
|
50
|
+
* @param keys - Array of keys to exclude
|
|
51
|
+
* @returns New object without specified keys
|
|
52
|
+
* @remarks Non-enumerable properties are not included in result
|
|
53
|
+
*/
|
|
54
|
+
export declare const omit: <T extends object, K extends keyof T>(obj: T, keys: K[]) => Omit<T, K>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates new object excluding keys where predicate returns true.
|
|
57
|
+
* @template T - Source object type
|
|
58
|
+
* @param obj - Source object
|
|
59
|
+
* @param predicate - Function that receives (value, key) and returns boolean
|
|
60
|
+
* @returns Partial object excluding entries where predicate returns true
|
|
61
|
+
*/
|
|
62
|
+
export declare const omitBy: <T extends Record<PropertyKey, unknown>>(obj: T, predicate: (value: T[keyof T], key: keyof T) => boolean) => Partial<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Finds first key where predicate returns true.
|
|
65
|
+
* @template T - Source object type
|
|
66
|
+
* @param obj - Source object
|
|
67
|
+
* @param fn - Function that receives (value, key) and returns boolean
|
|
68
|
+
* @returns First matching key, or undefined if none found
|
|
69
|
+
* @remarks Only checks own enumerable properties
|
|
70
|
+
*/
|
|
71
|
+
export declare const findKey: <T extends object>(obj: T, fn: (value: T[keyof T], key: keyof T) => boolean) => keyof T | undefined;
|
|
72
|
+
/** Symbol indicating merge should skip current property */
|
|
73
|
+
export declare const MERGE_SKIP: unique symbol;
|
|
74
|
+
/** Symbol indicating merge should use default logic for current property */
|
|
75
|
+
export declare const MERGE_DEFAULT: unique symbol;
|
|
76
|
+
/**
|
|
77
|
+
* Customizer function type for mergeWith.
|
|
78
|
+
* @returns New value, MERGE_SKIP to skip, or MERGE_DEFAULT for default logic
|
|
79
|
+
*/
|
|
80
|
+
type MergeCustomizer = (target_value: unknown, source_value: unknown, key: string, target: unknown, source: unknown) => unknown;
|
|
81
|
+
/**
|
|
82
|
+
* Internal merge implementation.
|
|
83
|
+
* @template T - Target object type
|
|
84
|
+
* @param target - Target object (will be mutated)
|
|
85
|
+
* @param customizer - Optional customizer function
|
|
86
|
+
* @param sources - Source objects to merge
|
|
87
|
+
* @returns Mutated target object
|
|
88
|
+
* @remarks Performs deep merge for plain objects, overwrites other values
|
|
89
|
+
*/
|
|
90
|
+
export declare const internalMerge: <T extends Record<string, unknown>>(target: T, customizer: MergeCustomizer | undefined, ...sources: Record<string, unknown>[]) => T;
|
|
91
|
+
/**
|
|
92
|
+
* Deep merges source objects into target.
|
|
93
|
+
* @template T - Target object type
|
|
94
|
+
* @param target - Target object (will be cloned)
|
|
95
|
+
* @param sources - Source objects to merge
|
|
96
|
+
* @returns New deeply merged object (target is not mutated)
|
|
97
|
+
* @remarks Uses structuredClone for deep cloning target
|
|
98
|
+
*/
|
|
99
|
+
export declare const merge: <T extends Record<string, unknown>>(target: T, ...sources: Record<string, unknown>[]) => T;
|
|
100
|
+
/**
|
|
101
|
+
* Deep merges with customizer function.
|
|
102
|
+
* @template T - Target object type
|
|
103
|
+
* @param target - Target object (will be cloned)
|
|
104
|
+
* @param customizer - Customizer function for control over merging
|
|
105
|
+
* @param sources - Source objects to merge
|
|
106
|
+
* @returns New deeply merged object (target is not mutated)
|
|
107
|
+
*/
|
|
108
|
+
export declare const mergeWith: <T extends Record<string, unknown>>(target: T, customizer: MergeCustomizer, ...sources: Record<string, unknown>[]) => T;
|
|
109
|
+
/**
|
|
110
|
+
* Flattens nested object to single level.
|
|
111
|
+
* @param obj - Object to flatten
|
|
112
|
+
* @param separator - Separator for nested keys (default: '.')
|
|
113
|
+
* @returns New flattened object
|
|
114
|
+
* @remarks Empty objects are preserved as objects (not flattened)
|
|
115
|
+
*/
|
|
116
|
+
export declare const flattenObject: (obj: Record<string, unknown>, separator?: string) => Record<string, unknown>;
|
|
117
|
+
/**
|
|
118
|
+
* Recursively converts object keys to camelCase.
|
|
119
|
+
* @template T - Desired return type
|
|
120
|
+
* @param obj - Input value
|
|
121
|
+
* @returns Value with keys transformed to camelCase
|
|
122
|
+
*/
|
|
123
|
+
export declare const toCamelCaseKeys: <T = unknown>(obj: unknown) => T;
|
|
124
|
+
/**
|
|
125
|
+
* Recursively converts object keys to snake_case.
|
|
126
|
+
* @template T - Desired return type
|
|
127
|
+
* @param obj - Input value
|
|
128
|
+
* @returns Value with keys transformed to snake_case
|
|
129
|
+
*/
|
|
130
|
+
export declare const toSnakeCaseKeys: <T = unknown>(obj: unknown) => T;
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Special symbol indicating that a value should be skipped during cloning.
|
|
3
|
+
* When returned by a customizer or encountered as a cloned value, the property will be omitted.
|
|
4
|
+
* @example
|
|
5
|
+
* const obj = { a: 1, b: 2 };
|
|
6
|
+
* const cloned = cloneDeepWith(obj, (value) => value === 1 ? CLONE_FILTER : CLONE_DEFAULT);
|
|
7
|
+
* // Result: { b: 2 }
|
|
8
|
+
*/
|
|
9
|
+
export declare const CLONE_FILTER: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* Special symbol indicating that the default cloning logic should be used.
|
|
12
|
+
* When returned by a customizer, the cloner will continue with its standard cloning procedure.
|
|
13
|
+
*/
|
|
14
|
+
export declare const CLONE_DEFAULT: unique symbol;
|
|
15
|
+
/**
|
|
16
|
+
* Special symbol indicating that an empty slot should be created.
|
|
17
|
+
* When returned by a customizer for array elements, the position will be kept as an empty slot.
|
|
18
|
+
* @example
|
|
19
|
+
* const arr = [1, 2, 3];
|
|
20
|
+
* const cloned = cloneDeepWith(arr, (value, index) => {
|
|
21
|
+
* if (index === 1) return CLONE_HOLE; // Keep index 1 as empty slot
|
|
22
|
+
* return CLONE_DEFAULT;
|
|
23
|
+
* });
|
|
24
|
+
* // Result: [1, empty, 3] (sparse array, length: 3)
|
|
25
|
+
* // cloned[1] === undefined, but 1 in cloned === false
|
|
26
|
+
*/
|
|
27
|
+
export declare const CLONE_HOLE: unique symbol;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a shallow copy of a value.
|
|
30
|
+
* @template T - Type of value to clone
|
|
31
|
+
* @param value - Value to clone
|
|
32
|
+
* @returns Shallow clone of the value
|
|
33
|
+
* @remarks
|
|
34
|
+
* - For primitive values (null, undefined, strings, numbers, booleans, symbols, bigints):
|
|
35
|
+
* Returns the value directly (no actual cloning needed)
|
|
36
|
+
* - For arrays: Creates a new array with the same elements (reference copy)
|
|
37
|
+
* - For plain objects: Creates a new object with the same enumerable properties (reference copy)
|
|
38
|
+
* - For other object types (Dates, RegExps, etc.): Returns a shallow copy using spread operator
|
|
39
|
+
* which may not preserve special behaviors
|
|
40
|
+
* @example
|
|
41
|
+
* const arr = [1, 2, { a: 3 }];
|
|
42
|
+
* const clonedArr = clone(arr);
|
|
43
|
+
* clonedArr[2].a = 99; // Also modifies original array's object
|
|
44
|
+
*/
|
|
45
|
+
export declare const clone: <T>(value: T) => T;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if the given key is a valid array index.
|
|
48
|
+
* @param k - The key to check (must be a string or number)
|
|
49
|
+
* @param n - Optional maximum index (defaults to 0, meaning no upper bound)
|
|
50
|
+
* @returns True if the key is a valid array index, false otherwise
|
|
51
|
+
*/
|
|
52
|
+
export declare const isArrayIndex: (k: PropertyKey, n?: number) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Customizer function for controlling cloning behavior.
|
|
55
|
+
* @param value - Current value being cloned
|
|
56
|
+
* @param key - Property key of the value (undefined for root)
|
|
57
|
+
* @param object - Parent object containing the value (undefined for root)
|
|
58
|
+
* @param stack - WeakMap tracking already visited objects for circular reference detection
|
|
59
|
+
* @returns
|
|
60
|
+
* - `CLONE_FILTER`: Skip this property (omit from result)
|
|
61
|
+
* - `CLONE_DEFAULT`: Use default cloning logic
|
|
62
|
+
* - Any other value: Use as the cloned result
|
|
63
|
+
*/
|
|
64
|
+
export type CloneCustomizer = (value: unknown, key: PropertyKey | undefined, object: object | undefined, stack: WeakMap<object, unknown>) => unknown;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a deep clone of a value.
|
|
67
|
+
* @template T - Type of value to clone
|
|
68
|
+
* @param value - Value to clone
|
|
69
|
+
* @param depth - Maximum cloning depth (default: Infinity)
|
|
70
|
+
* @returns Deep clone of the value
|
|
71
|
+
*/
|
|
72
|
+
export declare const cloneDeep: <T>(value: T, depth?: number) => T;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a deep clone of a value with custom transformation logic.
|
|
75
|
+
* @template T - Type of value to clone
|
|
76
|
+
* @param value - Value to clone
|
|
77
|
+
* @param customizer - Customizer function for controlling cloning behavior
|
|
78
|
+
* @param depth - Maximum cloning depth (default: Infinity)
|
|
79
|
+
* @returns Deep clone of the value with custom transformations
|
|
80
|
+
*/
|
|
81
|
+
export declare const cloneDeepWith: <T>(value: T, customizer: CloneCustomizer, depth?: number) => T;
|