superjs-core 0.2.0 → 0.3.1
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/dist/async/index.js.map +1 -1
- package/dist/collection/index.js.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/crypto/index.js.map +1 -1
- package/dist/date/index.js.map +1 -1
- package/dist/dep-exray/analyzer/index.d.ts +7 -0
- package/dist/dep-exray/analyzer/index.js +68 -0
- package/dist/dep-exray/analyzer/index.js.map +1 -0
- package/dist/dep-exray/cli.d.ts +1 -0
- package/dist/dep-exray/cli.js +389 -0
- package/dist/dep-exray/cli.js.map +1 -0
- package/dist/dep-exray/index.d.ts +5 -0
- package/dist/dep-exray/index.js +440 -0
- package/dist/dep-exray/index.js.map +1 -0
- package/dist/dep-exray/known-mappings.d.ts +17 -0
- package/dist/dep-exray/known-mappings.js +122 -0
- package/dist/dep-exray/known-mappings.js.map +1 -0
- package/dist/dep-exray/reporter/index.d.ts +5 -0
- package/dist/dep-exray/reporter/index.js +75 -0
- package/dist/dep-exray/reporter/index.js.map +1 -0
- package/dist/dep-exray/scanner/index.d.ts +5 -0
- package/dist/dep-exray/scanner/index.js +299 -0
- package/dist/dep-exray/scanner/index.js.map +1 -0
- package/dist/dep-exray/types.d.ts +38 -0
- package/dist/dep-exray/types.js +1 -0
- package/dist/dep-exray/types.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +439 -814
- package/dist/index.js.map +1 -1
- package/dist/io/index.js.map +1 -1
- package/dist/math/index.d.ts +1 -664
- package/dist/math/index.js +1 -822
- package/dist/math/index.js.map +1 -1
- package/dist/path/index.js.map +1 -1
- package/dist/string/index.js.map +1 -1
- package/dist/type/index.js.map +1 -1
- package/package.json +44 -5
package/dist/io/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/io/index.ts"],"sourcesContent":["/**\n * Options for CSV parsing.\n */\nexport interface CsvOptions {\n delimiter?: string\n header?: boolean\n skipEmptyLines?: boolean\n}\n\n/**\n * Parses a CSV string into an array of records (objects).\n *\n * @param input - CSV string\n * @param options - Optional parsing options\n */\nexport function parseCsv(input: string, options?: CsvOptions): Record<string, string>[] {\n const { delimiter = ',', header = true, skipEmptyLines = true } = options ?? {}\n\n const lines = input.split(/\\r?\\n/)\n const rows: string[][] = []\n\n for (const line of lines) {\n const trimmed = line.trim()\n if (skipEmptyLines && trimmed.length === 0) continue\n const values = parseCsvLine(trimmed, delimiter)\n rows.push(values)\n }\n\n if (rows.length === 0) return []\n\n if (header) {\n const [head, ...body] = rows\n if (head === undefined) return []\n return body.map(row => {\n const record: Record<string, string> = {}\n for (let i = 0; i < head.length; i++) {\n record[head[i]!] = row[i] ?? ''\n }\n return record\n })\n }\n\n return rows.map(row => {\n const record: Record<string, string> = {}\n for (let i = 0; i < row.length; i++) {\n record[String(i)] = row[i]!\n }\n return record\n })\n}\n\nfunction parseCsvLine(line: string, delimiter: string): string[] {\n const result: string[] = []\n let current = ''\n let inQuotes = false\n\n for (let i = 0; i < line.length; i++) {\n const ch = line[i]!\n if (inQuotes) {\n if (ch === '\"') {\n if (line[i + 1] === '\"') {\n current += '\"'\n i++\n } else {\n inQuotes = false\n }\n } else {\n current += ch\n }\n } else {\n if (ch === '\"') {\n inQuotes = true\n } else if (ch === delimiter) {\n result.push(current)\n current = ''\n } else {\n current += ch\n }\n }\n }\n result.push(current)\n return result\n}\n\n/**\n * Converts an array of records to a CSV string.\n */\nexport function stringifyCsv(data: Record<string, unknown>[], options?: { delimiter?: string }): string {\n const { delimiter = ',' } = options ?? {}\n if (data.length === 0) return ''\n\n const headers = Object.keys(data[0]!)\n const lines: string[] = [headers.map(v => escapeCsvField(v, delimiter)).join(delimiter)]\n\n for (const record of data) {\n const row = headers.map(h => escapeCsvField(String(record[h] ?? ''), delimiter))\n lines.push(row.join(delimiter))\n }\n\n return lines.join('\\n')\n}\n\nfunction escapeCsvField(value: string, delimiter: string): string {\n if (value.includes('\"') || value.includes(delimiter) || value.includes('\\n') || value.includes('\\r')) {\n return '\"' + value.replace(/\"/g, '\"\"') + '\"'\n }\n return value\n}\n\n/**\n * Safely parses a JSON string, returning the default value or null on failure.\n */\nexport function safeJsonParse<T>(input: string, default_?: T): T | null {\n try {\n return JSON.parse(input) as T\n } catch {\n return default_ ?? null\n }\n}\n\n/**\n * Reads an environment variable with optional default.\n */\nexport function env(name: string, default_?: string): string {\n const value = process.env[name]\n return value ?? default_ ?? ''\n}\n\n/**\n * Reads an environment variable as an integer.\n */\nexport function envInt(name: string, default_?: number): number {\n const value = process.env[name]\n if (value === undefined || value === '') return default_ ?? 0\n const parsed = Number.parseInt(value, 10)\n return Number.isNaN(parsed) ? (default_ ?? 0) : parsed\n}\n\n/**\n * Reads an environment variable as a boolean.\n */\nexport function envBool(name: string, default_?: boolean): boolean {\n const value = process.env[name]\n if (value === undefined || value === '') return default_ ?? false\n return value === 'true' || value === '1' || value === 'yes'\n}\n"],"mappings":";AAeO,SAAS,SAAS,OAAe,SAAgD;AACtF,QAAM,EAAE,YAAY,KAAK,SAAS,MAAM,iBAAiB,KAAK,IAAI,WAAW,CAAC;AAE9E,QAAM,QAAQ,MAAM,MAAM,OAAO;AACjC,QAAM,OAAmB,CAAC;AAE1B,aAAW,QAAQ,OAAO;AACxB,UAAM,UAAU,KAAK,KAAK;AAC1B,QAAI,kBAAkB,QAAQ,WAAW,EAAG;AAC5C,UAAM,SAAS,aAAa,SAAS,SAAS;AAC9C,SAAK,KAAK,MAAM;AAAA,EAClB;AAEA,MAAI,KAAK,WAAW,EAAG,QAAO,CAAC;AAE/B,MAAI,QAAQ;AACV,UAAM,CAAC,MAAM,GAAG,IAAI,IAAI;AACxB,QAAI,SAAS,OAAW,QAAO,CAAC;AAChC,WAAO,KAAK,IAAI,SAAO;AACrB,YAAM,SAAiC,CAAC;AACxC,eAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,eAAO,KAAK,CAAC,CAAE,IAAI,IAAI,CAAC,KAAK;AAAA,MAC/B;AACA,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,SAAO,KAAK,IAAI,SAAO;AACrB,UAAM,SAAiC,CAAC;AACxC,aAAS,IAAI,GAAG,IAAI,IAAI,QAAQ,KAAK;AACnC,aAAO,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,SAAS,aAAa,MAAc,WAA6B;AAC/D,QAAM,SAAmB,CAAC;AAC1B,MAAI,UAAU;AACd,MAAI,WAAW;AAEf,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,KAAK,KAAK,CAAC;AACjB,QAAI,UAAU;AACZ,UAAI,OAAO,KAAK;AACd,YAAI,KAAK,IAAI,CAAC,MAAM,KAAK;AACvB,qBAAW;AACX;AAAA,QACF,OAAO;AACL,qBAAW;AAAA,QACb;AAAA,MACF,OAAO;AACL,mBAAW;AAAA,MACb;AAAA,IACF,OAAO;AACL,UAAI,OAAO,KAAK;AACd,mBAAW;AAAA,MACb,WAAW,OAAO,WAAW;AAC3B,eAAO,KAAK,OAAO;AACnB,kBAAU;AAAA,MACZ,OAAO;AACL,mBAAW;AAAA,MACb;AAAA,IACF;AAAA,EACF;AACA,SAAO,KAAK,OAAO;AACnB,SAAO;AACT;AAKO,SAAS,aAAa,MAAiC,SAA0C;AACtG,QAAM,EAAE,YAAY,IAAI,IAAI,WAAW,CAAC;AACxC,MAAI,KAAK,WAAW,EAAG,QAAO;AAE9B,QAAM,UAAU,OAAO,KAAK,KAAK,CAAC,CAAE;AACpC,QAAM,QAAkB,CAAC,QAAQ,IAAI,OAAK,eAAe,GAAG,SAAS,CAAC,EAAE,KAAK,SAAS,CAAC;AAEvF,aAAW,UAAU,MAAM;AACzB,UAAM,MAAM,QAAQ,IAAI,OAAK,eAAe,OAAO,OAAO,CAAC,KAAK,EAAE,GAAG,SAAS,CAAC;AAC/E,UAAM,KAAK,IAAI,KAAK,SAAS,CAAC;AAAA,EAChC;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;AAEA,SAAS,eAAe,OAAe,WAA2B;AAChE,MAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,SAAS,KAAK,MAAM,SAAS,IAAI,KAAK,MAAM,SAAS,IAAI,GAAG;AACpG,WAAO,MAAM,MAAM,QAAQ,MAAM,IAAI,IAAI;AAAA,EAC3C;AACA,SAAO;AACT;AAKO,SAAS,cAAiB,OAAe,UAAwB;AACtE,MAAI;AACF,WAAO,KAAK,MAAM,KAAK;AAAA,EACzB,QAAQ;AACN,WAAO,YAAY;AAAA,EACrB;AACF;AAKO,SAAS,IAAI,MAAc,UAA2B;AAC3D,QAAM,QAAQ,QAAQ,IAAI,IAAI;AAC9B,SAAO,SAAS,YAAY;AAC9B;AAKO,SAAS,OAAO,MAAc,UAA2B;AAC9D,QAAM,QAAQ,QAAQ,IAAI,IAAI;AAC9B,MAAI,UAAU,UAAa,UAAU,GAAI,QAAO,YAAY;AAC5D,QAAM,SAAS,OAAO,SAAS,OAAO,EAAE;AACxC,SAAO,OAAO,MAAM,MAAM,IAAK,YAAY,IAAK;AAClD;AAKO,SAAS,QAAQ,MAAc,UAA6B;AACjE,QAAM,QAAQ,QAAQ,IAAI,IAAI;AAC9B,MAAI,UAAU,UAAa,UAAU,GAAI,QAAO,YAAY;AAC5D,SAAO,UAAU,UAAU,UAAU,OAAO,UAAU;AACxD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/io/index.ts"],"sourcesContent":["/**\r\n * Options for CSV parsing.\r\n */\r\nexport interface CsvOptions {\r\n delimiter?: string\r\n header?: boolean\r\n skipEmptyLines?: boolean\r\n}\r\n\r\n/**\r\n * Parses a CSV string into an array of records (objects).\r\n *\r\n * @param input - CSV string\r\n * @param options - Optional parsing options\r\n */\r\nexport function parseCsv(input: string, options?: CsvOptions): Record<string, string>[] {\r\n const { delimiter = ',', header = true, skipEmptyLines = true } = options ?? {}\r\n\r\n const lines = input.split(/\\r?\\n/)\r\n const rows: string[][] = []\r\n\r\n for (const line of lines) {\r\n const trimmed = line.trim()\r\n if (skipEmptyLines && trimmed.length === 0) continue\r\n const values = parseCsvLine(trimmed, delimiter)\r\n rows.push(values)\r\n }\r\n\r\n if (rows.length === 0) return []\r\n\r\n if (header) {\r\n const [head, ...body] = rows\r\n if (head === undefined) return []\r\n return body.map(row => {\r\n const record: Record<string, string> = {}\r\n for (let i = 0; i < head.length; i++) {\r\n record[head[i]!] = row[i] ?? ''\r\n }\r\n return record\r\n })\r\n }\r\n\r\n return rows.map(row => {\r\n const record: Record<string, string> = {}\r\n for (let i = 0; i < row.length; i++) {\r\n record[String(i)] = row[i]!\r\n }\r\n return record\r\n })\r\n}\r\n\r\nfunction parseCsvLine(line: string, delimiter: string): string[] {\r\n const result: string[] = []\r\n let current = ''\r\n let inQuotes = false\r\n\r\n for (let i = 0; i < line.length; i++) {\r\n const ch = line[i]!\r\n if (inQuotes) {\r\n if (ch === '\"') {\r\n if (line[i + 1] === '\"') {\r\n current += '\"'\r\n i++\r\n } else {\r\n inQuotes = false\r\n }\r\n } else {\r\n current += ch\r\n }\r\n } else {\r\n if (ch === '\"') {\r\n inQuotes = true\r\n } else if (ch === delimiter) {\r\n result.push(current)\r\n current = ''\r\n } else {\r\n current += ch\r\n }\r\n }\r\n }\r\n result.push(current)\r\n return result\r\n}\r\n\r\n/**\r\n * Converts an array of records to a CSV string.\r\n */\r\nexport function stringifyCsv(data: Record<string, unknown>[], options?: { delimiter?: string }): string {\r\n const { delimiter = ',' } = options ?? {}\r\n if (data.length === 0) return ''\r\n\r\n const headers = Object.keys(data[0]!)\r\n const lines: string[] = [headers.map(v => escapeCsvField(v, delimiter)).join(delimiter)]\r\n\r\n for (const record of data) {\r\n const row = headers.map(h => escapeCsvField(String(record[h] ?? ''), delimiter))\r\n lines.push(row.join(delimiter))\r\n }\r\n\r\n return lines.join('\\n')\r\n}\r\n\r\nfunction escapeCsvField(value: string, delimiter: string): string {\r\n if (value.includes('\"') || value.includes(delimiter) || value.includes('\\n') || value.includes('\\r')) {\r\n return '\"' + value.replace(/\"/g, '\"\"') + '\"'\r\n }\r\n return value\r\n}\r\n\r\n/**\r\n * Safely parses a JSON string, returning the default value or null on failure.\r\n */\r\nexport function safeJsonParse<T>(input: string, default_?: T): T | null {\r\n try {\r\n return JSON.parse(input) as T\r\n } catch {\r\n return default_ ?? null\r\n }\r\n}\r\n\r\n/**\r\n * Reads an environment variable with optional default.\r\n */\r\nexport function env(name: string, default_?: string): string {\r\n const value = process.env[name]\r\n return value ?? default_ ?? ''\r\n}\r\n\r\n/**\r\n * Reads an environment variable as an integer.\r\n */\r\nexport function envInt(name: string, default_?: number): number {\r\n const value = process.env[name]\r\n if (value === undefined || value === '') return default_ ?? 0\r\n const parsed = Number.parseInt(value, 10)\r\n return Number.isNaN(parsed) ? (default_ ?? 0) : parsed\r\n}\r\n\r\n/**\r\n * Reads an environment variable as a boolean.\r\n */\r\nexport function envBool(name: string, default_?: boolean): boolean {\r\n const value = process.env[name]\r\n if (value === undefined || value === '') return default_ ?? false\r\n return value === 'true' || value === '1' || value === 'yes'\r\n}\r\n"],"mappings":"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","names":[]}
|
package/dist/math/index.d.ts
CHANGED
|
@@ -113,668 +113,5 @@ declare function randomInt(min: number, max: number): number;
|
|
|
113
113
|
* @returns Whether the value is in range.
|
|
114
114
|
*/
|
|
115
115
|
declare function inRange(value: number, min: number, max: number): boolean;
|
|
116
|
-
/**
|
|
117
|
-
* Converts radians to degrees.
|
|
118
|
-
*
|
|
119
|
-
* @param radians - Angle in radians.
|
|
120
|
-
* @returns Angle in degrees.
|
|
121
|
-
*/
|
|
122
|
-
declare function toDegrees(radians: number): number;
|
|
123
|
-
/**
|
|
124
|
-
* Converts degrees to radians.
|
|
125
|
-
*
|
|
126
|
-
* @param degrees - Angle in degrees.
|
|
127
|
-
* @returns Angle in radians.
|
|
128
|
-
*/
|
|
129
|
-
declare function toRadians(degrees: number): number;
|
|
130
|
-
/**
|
|
131
|
-
* Computes the sine of an angle.
|
|
132
|
-
*
|
|
133
|
-
* @param angle - The angle.
|
|
134
|
-
* @param unit - Unit of the angle: `'rad'` (default) or `'deg'`.
|
|
135
|
-
* @returns The sine value.
|
|
136
|
-
*/
|
|
137
|
-
declare function sin(angle: number, unit?: 'rad' | 'deg'): number;
|
|
138
|
-
/**
|
|
139
|
-
* Computes the cosine of an angle.
|
|
140
|
-
*
|
|
141
|
-
* @param angle - The angle.
|
|
142
|
-
* @param unit - Unit of the angle: `'rad'` (default) or `'deg'`.
|
|
143
|
-
* @returns The cosine value.
|
|
144
|
-
*/
|
|
145
|
-
declare function cos(angle: number, unit?: 'rad' | 'deg'): number;
|
|
146
|
-
/**
|
|
147
|
-
* Computes the tangent of an angle.
|
|
148
|
-
*
|
|
149
|
-
* @param angle - The angle.
|
|
150
|
-
* @param unit - Unit of the angle: `'rad'` (default) or `'deg'`.
|
|
151
|
-
* @returns The tangent value.
|
|
152
|
-
*/
|
|
153
|
-
declare function tan(angle: number, unit?: 'rad' | 'deg'): number;
|
|
154
|
-
/**
|
|
155
|
-
* Computes the arcsine (inverse sine) of a value.
|
|
156
|
-
*
|
|
157
|
-
* @param value - A number between -1 and 1.
|
|
158
|
-
* @returns The angle in radians.
|
|
159
|
-
* @throws {RangeError} If value is outside [-1, 1].
|
|
160
|
-
*/
|
|
161
|
-
declare function asin(value: number): number;
|
|
162
|
-
/**
|
|
163
|
-
* Computes the arccosine (inverse cosine) of a value.
|
|
164
|
-
*
|
|
165
|
-
* @param value - A number between -1 and 1.
|
|
166
|
-
* @returns The angle in radians.
|
|
167
|
-
* @throws {RangeError} If value is outside [-1, 1].
|
|
168
|
-
*/
|
|
169
|
-
declare function acos(value: number): number;
|
|
170
|
-
/**
|
|
171
|
-
* Computes the arctangent (inverse tangent) of a value.
|
|
172
|
-
*
|
|
173
|
-
* @param value - Any real number.
|
|
174
|
-
* @returns The angle in radians.
|
|
175
|
-
*/
|
|
176
|
-
declare function atan(value: number): number;
|
|
177
|
-
/**
|
|
178
|
-
* Computes the angle whose tangent is the quotient of two numbers.
|
|
179
|
-
*
|
|
180
|
-
* @param y - The y-coordinate.
|
|
181
|
-
* @param x - The x-coordinate.
|
|
182
|
-
* @returns The angle in radians from the positive x-axis.
|
|
183
|
-
*/
|
|
184
|
-
declare function atan2(y: number, x: number): number;
|
|
185
|
-
/**
|
|
186
|
-
* Computes the square root of the sum of squares of the arguments (hypotenuse).
|
|
187
|
-
*
|
|
188
|
-
* @param values - Variable number of values.
|
|
189
|
-
* @returns The hypotenuse.
|
|
190
|
-
*/
|
|
191
|
-
declare function hypot(...values: number[]): number;
|
|
192
|
-
/**
|
|
193
|
-
* Computes the median of a numeric array.
|
|
194
|
-
*
|
|
195
|
-
* @param values - Array of numbers.
|
|
196
|
-
* @returns The median value.
|
|
197
|
-
* @throws {RangeError} If the array is empty.
|
|
198
|
-
*/
|
|
199
|
-
declare function median(values: number[]): number;
|
|
200
|
-
/**
|
|
201
|
-
* Computes the mode(s) of a numeric array.
|
|
202
|
-
*
|
|
203
|
-
* @param values - Array of numbers.
|
|
204
|
-
* @returns Array of mode values (may be multiple).
|
|
205
|
-
* @throws {RangeError} If the array is empty.
|
|
206
|
-
*/
|
|
207
|
-
declare function mode(values: number[]): number[];
|
|
208
|
-
/**
|
|
209
|
-
* Computes the p-th percentile of a numeric array.
|
|
210
|
-
*
|
|
211
|
-
* @param values - Array of numbers.
|
|
212
|
-
* @param p - Percentile between 0 and 100.
|
|
213
|
-
* @returns The percentile value.
|
|
214
|
-
* @throws {RangeError} If array is empty or p is out of range.
|
|
215
|
-
*/
|
|
216
|
-
declare function percentile(values: number[], p: number): number;
|
|
217
|
-
/**
|
|
218
|
-
* Computes the quartiles (Q1, Q2, Q3) of a numeric array.
|
|
219
|
-
*
|
|
220
|
-
* @param values - Array of numbers.
|
|
221
|
-
* @returns An object with q1, q2, q3.
|
|
222
|
-
* @throws {RangeError} If the array is empty.
|
|
223
|
-
*/
|
|
224
|
-
declare function quartiles(values: number[]): {
|
|
225
|
-
q1: number;
|
|
226
|
-
q2: number;
|
|
227
|
-
q3: number;
|
|
228
|
-
};
|
|
229
|
-
/**
|
|
230
|
-
* Computes the variance of a numeric array.
|
|
231
|
-
*
|
|
232
|
-
* @param values - Array of numbers.
|
|
233
|
-
* @param sample - If true, use sample variance (n-1). Default false.
|
|
234
|
-
* @returns The variance.
|
|
235
|
-
* @throws {RangeError} If array has fewer than 2 elements for sample variance.
|
|
236
|
-
*/
|
|
237
|
-
declare function variance(values: number[], sample?: boolean): number;
|
|
238
|
-
/**
|
|
239
|
-
* Computes the standard deviation of a numeric array.
|
|
240
|
-
*
|
|
241
|
-
* @param values - Array of numbers.
|
|
242
|
-
* @param sample - If true, use sample standard deviation (n-1). Default false.
|
|
243
|
-
* @returns The standard deviation.
|
|
244
|
-
*/
|
|
245
|
-
declare function stddev(values: number[], sample?: boolean): number;
|
|
246
|
-
/**
|
|
247
|
-
* Computes the covariance between two numeric arrays.
|
|
248
|
-
*
|
|
249
|
-
* @param x - First array.
|
|
250
|
-
* @param y - Second array.
|
|
251
|
-
* @returns The covariance.
|
|
252
|
-
* @throws {RangeError} If arrays have different lengths or fewer than 2 elements.
|
|
253
|
-
*/
|
|
254
|
-
declare function covariance(x: number[], y: number[]): number;
|
|
255
|
-
/**
|
|
256
|
-
* Computes the Pearson correlation coefficient between two arrays.
|
|
257
|
-
*
|
|
258
|
-
* @param x - First array.
|
|
259
|
-
* @param y - Second array.
|
|
260
|
-
* @returns The correlation coefficient between -1 and 1.
|
|
261
|
-
*/
|
|
262
|
-
declare function correlation(x: number[], y: number[]): number;
|
|
263
|
-
/**
|
|
264
|
-
* Computes the sample skewness of a numeric array.
|
|
265
|
-
*
|
|
266
|
-
* @param values - Array of numbers.
|
|
267
|
-
* @returns The skewness.
|
|
268
|
-
*/
|
|
269
|
-
declare function skewness(values: number[]): number;
|
|
270
|
-
/**
|
|
271
|
-
* Computes the excess kurtosis of a numeric array.
|
|
272
|
-
*
|
|
273
|
-
* @param values - Array of numbers.
|
|
274
|
-
* @returns The excess kurtosis (kurtosis - 3).
|
|
275
|
-
*/
|
|
276
|
-
declare function kurtosis(values: number[]): number;
|
|
277
|
-
/**
|
|
278
|
-
* Computes the weighted mean of values with given weights.
|
|
279
|
-
*
|
|
280
|
-
* @param values - Array of numbers.
|
|
281
|
-
* @param weights - Array of weights.
|
|
282
|
-
* @returns The weighted mean.
|
|
283
|
-
* @throws {RangeError} If arrays differ in length or weights sum to zero.
|
|
284
|
-
*/
|
|
285
|
-
declare function weightedMean(values: number[], weights: number[]): number;
|
|
286
|
-
/**
|
|
287
|
-
* Computes the geometric mean of a numeric array.
|
|
288
|
-
*
|
|
289
|
-
* @param values - Array of positive numbers.
|
|
290
|
-
* @returns The geometric mean.
|
|
291
|
-
* @throws {RangeError} If array is empty or contains non-positive values.
|
|
292
|
-
*/
|
|
293
|
-
declare function geometricMean(values: number[]): number;
|
|
294
|
-
/**
|
|
295
|
-
* Computes the harmonic mean of a numeric array.
|
|
296
|
-
*
|
|
297
|
-
* @param values - Array of positive numbers.
|
|
298
|
-
* @returns The harmonic mean.
|
|
299
|
-
* @throws {RangeError} If array is empty or contains non-positive values.
|
|
300
|
-
*/
|
|
301
|
-
declare function harmonicMean(values: number[]): number;
|
|
302
|
-
/**
|
|
303
|
-
* Computes the z-score of a value relative to a distribution.
|
|
304
|
-
*
|
|
305
|
-
* @param value - The value to standardize.
|
|
306
|
-
* @param mean - The mean of the distribution.
|
|
307
|
-
* @param stddev - The standard deviation of the distribution.
|
|
308
|
-
* @returns The z-score.
|
|
309
|
-
*/
|
|
310
|
-
declare function zScore(value: number, mean: number, stddev: number): number;
|
|
311
|
-
/**
|
|
312
|
-
* Normalizes an array to [0, 1] range using min-max scaling.
|
|
313
|
-
*
|
|
314
|
-
* @param values - Array of numbers.
|
|
315
|
-
* @returns The normalized array.
|
|
316
|
-
*/
|
|
317
|
-
declare function normalize(values: number[]): number[];
|
|
318
|
-
/**
|
|
319
|
-
* Standardizes an array to have mean 0 and standard deviation 1 (z-scores).
|
|
320
|
-
*
|
|
321
|
-
* @param values - Array of numbers.
|
|
322
|
-
* @returns The standardized array.
|
|
323
|
-
*/
|
|
324
|
-
declare function standardize(values: number[]): number[];
|
|
325
|
-
/**
|
|
326
|
-
* Computes the factorial of a non-negative integer.
|
|
327
|
-
*
|
|
328
|
-
* @param n - Non-negative integer.
|
|
329
|
-
* @returns n!.
|
|
330
|
-
* @throws {RangeError} If n is negative or not an integer.
|
|
331
|
-
*/
|
|
332
|
-
declare function factorial(n: number): number;
|
|
333
|
-
/**
|
|
334
|
-
* Computes the binomial coefficient "n choose k".
|
|
335
|
-
*
|
|
336
|
-
* @param n - Total number of items.
|
|
337
|
-
* @param k - Number of items to choose.
|
|
338
|
-
* @returns The binomial coefficient.
|
|
339
|
-
* @throws {RangeError} If n < k or arguments are not non-negative integers.
|
|
340
|
-
*/
|
|
341
|
-
declare function binomial(n: number, k: number): number;
|
|
342
|
-
/**
|
|
343
|
-
* Computes the number of permutations "n P k".
|
|
344
|
-
*
|
|
345
|
-
* @param n - Total number of items.
|
|
346
|
-
* @param k - Number of items to arrange.
|
|
347
|
-
* @returns The number of permutations.
|
|
348
|
-
* @throws {RangeError} If n < k or arguments are not non-negative integers.
|
|
349
|
-
*/
|
|
350
|
-
declare function permutation(n: number, k: number): number;
|
|
351
|
-
/**
|
|
352
|
-
* Computes the greatest common divisor of two or more numbers.
|
|
353
|
-
*
|
|
354
|
-
* @param values - Two or more integers.
|
|
355
|
-
* @returns The GCD.
|
|
356
|
-
* @throws {RangeError} If fewer than 2 values are provided.
|
|
357
|
-
*/
|
|
358
|
-
declare function gcd(...values: number[]): number;
|
|
359
|
-
/**
|
|
360
|
-
* Computes the least common multiple of two or more numbers.
|
|
361
|
-
*
|
|
362
|
-
* @param values - Two or more integers.
|
|
363
|
-
* @returns The LCM.
|
|
364
|
-
* @throws {RangeError} If fewer than 2 values are provided.
|
|
365
|
-
*/
|
|
366
|
-
declare function lcm(...values: number[]): number;
|
|
367
|
-
/**
|
|
368
|
-
* Checks if a number is prime.
|
|
369
|
-
*
|
|
370
|
-
* @param n - Integer to check.
|
|
371
|
-
* @returns True if prime.
|
|
372
|
-
*/
|
|
373
|
-
declare function isPrime(n: number): boolean;
|
|
374
|
-
/**
|
|
375
|
-
* Computes the prime factors of a number.
|
|
376
|
-
*
|
|
377
|
-
* @param n - Integer greater than 1.
|
|
378
|
-
* @returns Array of prime factors.
|
|
379
|
-
* @throws {RangeError} If n is less than 2.
|
|
380
|
-
*/
|
|
381
|
-
declare function primeFactors(n: number): number[];
|
|
382
|
-
/**
|
|
383
|
-
* Computes the n-th Fibonacci number.
|
|
384
|
-
*
|
|
385
|
-
* @param n - Non-negative integer (0-indexed: F(0)=0, F(1)=1).
|
|
386
|
-
* @returns The n-th Fibonacci number.
|
|
387
|
-
* @throws {RangeError} If n is negative or not an integer.
|
|
388
|
-
*/
|
|
389
|
-
declare function fibonacci(n: number): number;
|
|
390
|
-
/**
|
|
391
|
-
* Checks if a number is even.
|
|
392
|
-
*
|
|
393
|
-
* @param n - The number to check.
|
|
394
|
-
* @returns True if even.
|
|
395
|
-
*/
|
|
396
|
-
declare function isEven(n: number): boolean;
|
|
397
|
-
/**
|
|
398
|
-
* Checks if a number is odd.
|
|
399
|
-
*
|
|
400
|
-
* @param n - The number to check.
|
|
401
|
-
* @returns True if odd.
|
|
402
|
-
*/
|
|
403
|
-
declare function isOdd(n: number): boolean;
|
|
404
|
-
/**
|
|
405
|
-
* Returns the sign of a number.
|
|
406
|
-
*
|
|
407
|
-
* @param n - The number.
|
|
408
|
-
* @returns -1 if negative, 1 if positive, 0 if zero.
|
|
409
|
-
*/
|
|
410
|
-
declare function sign(n: number): number;
|
|
411
|
-
/**
|
|
412
|
-
* Represents a 2D matrix.
|
|
413
|
-
*/
|
|
414
|
-
type Matrix = number[][];
|
|
415
|
-
/**
|
|
416
|
-
* Adds two matrices element-wise.
|
|
417
|
-
*
|
|
418
|
-
* @param a - First matrix.
|
|
419
|
-
* @param b - Second matrix.
|
|
420
|
-
* @returns The sum matrix.
|
|
421
|
-
*/
|
|
422
|
-
declare function matrixAdd(a: Matrix, b: Matrix): Matrix;
|
|
423
|
-
/**
|
|
424
|
-
* Subtracts two matrices element-wise.
|
|
425
|
-
*
|
|
426
|
-
* @param a - First matrix.
|
|
427
|
-
* @param b - Second matrix.
|
|
428
|
-
* @returns The difference matrix.
|
|
429
|
-
*/
|
|
430
|
-
declare function matrixSub(a: Matrix, b: Matrix): Matrix;
|
|
431
|
-
/**
|
|
432
|
-
* Multiplies two matrices element-wise (Hadamard product).
|
|
433
|
-
*
|
|
434
|
-
* @param a - First matrix.
|
|
435
|
-
* @param b - Second matrix.
|
|
436
|
-
* @returns The element-wise product matrix.
|
|
437
|
-
*/
|
|
438
|
-
declare function matrixMul(a: Matrix, b: Matrix): Matrix;
|
|
439
|
-
/**
|
|
440
|
-
* Multiplies a matrix by a scalar.
|
|
441
|
-
*
|
|
442
|
-
* @param a - The matrix.
|
|
443
|
-
* @param scalar - The scalar value.
|
|
444
|
-
* @returns The scaled matrix.
|
|
445
|
-
*/
|
|
446
|
-
declare function matrixScale(a: Matrix, scalar: number): Matrix;
|
|
447
|
-
/**
|
|
448
|
-
* Transposes a matrix (rows become columns).
|
|
449
|
-
*
|
|
450
|
-
* @param a - The matrix.
|
|
451
|
-
* @returns The transposed matrix.
|
|
452
|
-
*/
|
|
453
|
-
declare function matrixTranspose(a: Matrix): Matrix;
|
|
454
|
-
/**
|
|
455
|
-
* Computes the determinant of a square matrix (max 3x3).
|
|
456
|
-
*
|
|
457
|
-
* @param a - The square matrix.
|
|
458
|
-
* @returns The determinant.
|
|
459
|
-
*/
|
|
460
|
-
declare function matrixDeterminant(a: Matrix): number;
|
|
461
|
-
/**
|
|
462
|
-
* Computes the inverse of a square matrix (max 3x3).
|
|
463
|
-
*
|
|
464
|
-
* @param a - The square matrix.
|
|
465
|
-
* @returns The inverse matrix.
|
|
466
|
-
*/
|
|
467
|
-
declare function matrixInverse(a: Matrix): Matrix;
|
|
468
|
-
/**
|
|
469
|
-
* Creates an n x n identity matrix.
|
|
470
|
-
*
|
|
471
|
-
* @param n - The size of the matrix.
|
|
472
|
-
* @returns The identity matrix.
|
|
473
|
-
*/
|
|
474
|
-
declare function matrixIdentity(n: number): Matrix;
|
|
475
|
-
/**
|
|
476
|
-
* Multiplies two matrices using standard matrix multiplication (dot product).
|
|
477
|
-
*
|
|
478
|
-
* @param a - First matrix.
|
|
479
|
-
* @param b - Second matrix.
|
|
480
|
-
* @returns The product matrix.
|
|
481
|
-
*/
|
|
482
|
-
declare function matrixMultiply(a: Matrix, b: Matrix): Matrix;
|
|
483
|
-
/**
|
|
484
|
-
* Computes the trace of a square matrix.
|
|
485
|
-
*
|
|
486
|
-
* @param a - The square matrix.
|
|
487
|
-
* @returns The trace (sum of diagonal elements).
|
|
488
|
-
*/
|
|
489
|
-
declare function matrixTrace(a: Matrix): number;
|
|
490
|
-
/**
|
|
491
|
-
* Represents a complex number with real and imaginary parts.
|
|
492
|
-
*/
|
|
493
|
-
declare class Complex {
|
|
494
|
-
/** The real part. */
|
|
495
|
-
re: number;
|
|
496
|
-
/** The imaginary part. */
|
|
497
|
-
im: number;
|
|
498
|
-
constructor(
|
|
499
|
-
/** The real part. */
|
|
500
|
-
re: number,
|
|
501
|
-
/** The imaginary part. */
|
|
502
|
-
im?: number);
|
|
503
|
-
/**
|
|
504
|
-
* Adds another complex number.
|
|
505
|
-
*
|
|
506
|
-
* @param other - The complex number to add.
|
|
507
|
-
* @returns A new Complex instance.
|
|
508
|
-
*/
|
|
509
|
-
add(other: Complex): Complex;
|
|
510
|
-
/**
|
|
511
|
-
* Subtracts another complex number.
|
|
512
|
-
*
|
|
513
|
-
* @param other - The complex number to subtract.
|
|
514
|
-
* @returns A new Complex instance.
|
|
515
|
-
*/
|
|
516
|
-
sub(other: Complex): Complex;
|
|
517
|
-
/**
|
|
518
|
-
* Multiplies by another complex number.
|
|
519
|
-
*
|
|
520
|
-
* @param other - The complex number to multiply by.
|
|
521
|
-
* @returns A new Complex instance.
|
|
522
|
-
*/
|
|
523
|
-
mul(other: Complex): Complex;
|
|
524
|
-
/**
|
|
525
|
-
* Divides by another complex number.
|
|
526
|
-
*
|
|
527
|
-
* @param other - The complex number to divide by.
|
|
528
|
-
* @returns A new Complex instance.
|
|
529
|
-
* @throws {DivisionByZeroError} If the divisor is zero.
|
|
530
|
-
*/
|
|
531
|
-
div(other: Complex): Complex;
|
|
532
|
-
/**
|
|
533
|
-
* Computes the magnitude (absolute value) of the complex number.
|
|
534
|
-
*
|
|
535
|
-
* @returns The magnitude.
|
|
536
|
-
*/
|
|
537
|
-
abs(): number;
|
|
538
|
-
/**
|
|
539
|
-
* Computes the complex conjugate.
|
|
540
|
-
*
|
|
541
|
-
* @returns A new Complex instance with negated imaginary part.
|
|
542
|
-
*/
|
|
543
|
-
conj(): Complex;
|
|
544
|
-
/**
|
|
545
|
-
* Computes the argument (phase angle) in radians.
|
|
546
|
-
*
|
|
547
|
-
* @returns The phase angle.
|
|
548
|
-
*/
|
|
549
|
-
arg(): number;
|
|
550
|
-
/**
|
|
551
|
-
* Raises the complex number to a real power.
|
|
552
|
-
*
|
|
553
|
-
* @param n - The exponent.
|
|
554
|
-
* @returns A new Complex instance.
|
|
555
|
-
*/
|
|
556
|
-
pow(n: number): Complex;
|
|
557
|
-
/**
|
|
558
|
-
* Computes the square root of the complex number.
|
|
559
|
-
*
|
|
560
|
-
* @returns A new Complex instance.
|
|
561
|
-
*/
|
|
562
|
-
sqrt(): Complex;
|
|
563
|
-
/**
|
|
564
|
-
* Computes e raised to this complex number.
|
|
565
|
-
*
|
|
566
|
-
* @returns A new Complex instance.
|
|
567
|
-
*/
|
|
568
|
-
exp(): Complex;
|
|
569
|
-
/**
|
|
570
|
-
* Computes the natural logarithm of the complex number.
|
|
571
|
-
*
|
|
572
|
-
* @returns A new Complex instance.
|
|
573
|
-
*/
|
|
574
|
-
log(): Complex;
|
|
575
|
-
/**
|
|
576
|
-
* Computes the sine of the complex number.
|
|
577
|
-
*
|
|
578
|
-
* @returns A new Complex instance.
|
|
579
|
-
*/
|
|
580
|
-
sin(): Complex;
|
|
581
|
-
/**
|
|
582
|
-
* Computes the cosine of the complex number.
|
|
583
|
-
*
|
|
584
|
-
* @returns A new Complex instance.
|
|
585
|
-
*/
|
|
586
|
-
cos(): Complex;
|
|
587
|
-
/**
|
|
588
|
-
* Returns a string representation of the complex number.
|
|
589
|
-
*
|
|
590
|
-
* @returns String like "a + bi".
|
|
591
|
-
*/
|
|
592
|
-
toString(): string;
|
|
593
|
-
/**
|
|
594
|
-
* Creates a complex number from polar coordinates.
|
|
595
|
-
*
|
|
596
|
-
* @param r - The magnitude.
|
|
597
|
-
* @param theta - The angle in radians.
|
|
598
|
-
* @returns A new Complex instance.
|
|
599
|
-
*/
|
|
600
|
-
static fromPolar(r: number, theta: number): Complex;
|
|
601
|
-
/** The real part. */
|
|
602
|
-
get real(): number;
|
|
603
|
-
/** The imaginary part. */
|
|
604
|
-
get imag(): number;
|
|
605
|
-
}
|
|
606
|
-
/**
|
|
607
|
-
* Computes compound interest.
|
|
608
|
-
*
|
|
609
|
-
* @param principal - Initial amount.
|
|
610
|
-
* @param rate - Annual interest rate (decimal, e.g. 0.05 for 5%).
|
|
611
|
-
* @param time - Time in years.
|
|
612
|
-
* @param n - Number of compounding periods per year (default 12).
|
|
613
|
-
* @returns The future value including interest.
|
|
614
|
-
*/
|
|
615
|
-
declare function compoundInterest(principal: number, rate: number, time: number, n?: number): number;
|
|
616
|
-
/**
|
|
617
|
-
* Computes the future value of a present sum.
|
|
618
|
-
*
|
|
619
|
-
* @param pv - Present value.
|
|
620
|
-
* @param rate - Periodic interest rate.
|
|
621
|
-
* @param nper - Number of periods.
|
|
622
|
-
* @returns Future value.
|
|
623
|
-
*/
|
|
624
|
-
declare function futureValue(pv: number, rate: number, nper: number): number;
|
|
625
|
-
/**
|
|
626
|
-
* Computes the present value of a future sum.
|
|
627
|
-
*
|
|
628
|
-
* @param fv - Future value.
|
|
629
|
-
* @param rate - Periodic interest rate.
|
|
630
|
-
* @param nper - Number of periods.
|
|
631
|
-
* @returns Present value.
|
|
632
|
-
*/
|
|
633
|
-
declare function presentValue(fv: number, rate: number, nper: number): number;
|
|
634
|
-
/**
|
|
635
|
-
* Computes the periodic payment for a loan (PMT).
|
|
636
|
-
*
|
|
637
|
-
* @param rate - Periodic interest rate.
|
|
638
|
-
* @param nper - Total number of payments.
|
|
639
|
-
* @param pv - Present value (loan amount).
|
|
640
|
-
* @param fv - Future value (default 0).
|
|
641
|
-
* @returns The periodic payment amount.
|
|
642
|
-
*/
|
|
643
|
-
declare function pmt(rate: number, nper: number, pv: number, fv?: number): number;
|
|
644
|
-
/**
|
|
645
|
-
* Computes the net present value (NPV) of cashflows.
|
|
646
|
-
*
|
|
647
|
-
* @param rate - Discount rate per period.
|
|
648
|
-
* @param cashflows - Array of cashflow values (negative for outflows).
|
|
649
|
-
* @returns The net present value.
|
|
650
|
-
*/
|
|
651
|
-
declare function npv(rate: number, cashflows: number[]): number;
|
|
652
|
-
/**
|
|
653
|
-
* Computes the internal rate of return (IRR) of cashflows using Newton's method.
|
|
654
|
-
*
|
|
655
|
-
* @param cashflows - Array of cashflow values.
|
|
656
|
-
* @returns The IRR as a decimal.
|
|
657
|
-
*/
|
|
658
|
-
declare function irr(cashflows: number[]): number;
|
|
659
|
-
/**
|
|
660
|
-
* Computes the return on investment (ROI).
|
|
661
|
-
*
|
|
662
|
-
* @param gain - The gain from the investment.
|
|
663
|
-
* @param cost - The cost of the investment.
|
|
664
|
-
* @returns The ROI as a decimal.
|
|
665
|
-
*/
|
|
666
|
-
declare function roi(gain: number, cost: number): number;
|
|
667
|
-
/**
|
|
668
|
-
* Generates an amortization schedule for a loan.
|
|
669
|
-
*
|
|
670
|
-
* @param principal - Loan amount.
|
|
671
|
-
* @param rate - Periodic interest rate.
|
|
672
|
-
* @param nper - Total number of payments.
|
|
673
|
-
* @returns Array of period details.
|
|
674
|
-
*/
|
|
675
|
-
declare function amortizationSchedule(principal: number, rate: number, nper: number): {
|
|
676
|
-
period: number;
|
|
677
|
-
payment: number;
|
|
678
|
-
interest: number;
|
|
679
|
-
principal: number;
|
|
680
|
-
balance: number;
|
|
681
|
-
}[];
|
|
682
|
-
/**
|
|
683
|
-
* Generates a random number from a normal (Gaussian) distribution.
|
|
684
|
-
*
|
|
685
|
-
* @param mean - The mean (default 0).
|
|
686
|
-
* @param stddev - The standard deviation (default 1).
|
|
687
|
-
* @returns A normally distributed random number.
|
|
688
|
-
*/
|
|
689
|
-
declare function randomNormal(mean?: number, stddev?: number): number;
|
|
690
|
-
/**
|
|
691
|
-
* Generates a random number from a Poisson distribution.
|
|
692
|
-
*
|
|
693
|
-
* @param lambda - The rate parameter (mean).
|
|
694
|
-
* @returns A Poisson-distributed random integer.
|
|
695
|
-
*/
|
|
696
|
-
declare function randomPoisson(lambda: number): number;
|
|
697
|
-
/**
|
|
698
|
-
* Generates a random number from a binomial distribution.
|
|
699
|
-
*
|
|
700
|
-
* @param n - Number of trials.
|
|
701
|
-
* @param p - Probability of success per trial.
|
|
702
|
-
* @returns Number of successes.
|
|
703
|
-
*/
|
|
704
|
-
declare function randomBinomial(n: number, p: number): number;
|
|
705
|
-
/**
|
|
706
|
-
* Generates a random number from an exponential distribution.
|
|
707
|
-
*
|
|
708
|
-
* @param lambda - The rate parameter.
|
|
709
|
-
* @returns An exponentially distributed random number.
|
|
710
|
-
*/
|
|
711
|
-
declare function randomExponential(lambda: number): number;
|
|
712
|
-
/**
|
|
713
|
-
* Generates a random number from a uniform distribution.
|
|
714
|
-
*
|
|
715
|
-
* @param min - Lower bound (default 0).
|
|
716
|
-
* @param max - Upper bound (default 1).
|
|
717
|
-
* @returns A uniformly distributed random number.
|
|
718
|
-
*/
|
|
719
|
-
declare function randomUniform(min?: number, max?: number): number;
|
|
720
|
-
/**
|
|
721
|
-
* Computes the numerical derivative of a function at a point.
|
|
722
|
-
*
|
|
723
|
-
* @param f - The function.
|
|
724
|
-
* @param x - The point to evaluate at.
|
|
725
|
-
* @param h - Step size (default 1e-10).
|
|
726
|
-
* @returns The derivative value.
|
|
727
|
-
*/
|
|
728
|
-
declare function derivative(f: (x: number) => number, x: number, h?: number): number;
|
|
729
|
-
/**
|
|
730
|
-
* Computes the definite integral of a function using Simpson's rule.
|
|
731
|
-
*
|
|
732
|
-
* @param f - The function to integrate.
|
|
733
|
-
* @param a - Lower bound.
|
|
734
|
-
* @param b - Upper bound.
|
|
735
|
-
* @param n - Number of subintervals (must be even, default 100).
|
|
736
|
-
* @returns The approximate integral value.
|
|
737
|
-
*/
|
|
738
|
-
declare function integral(f: (x: number) => number, a: number, b: number, n?: number): number;
|
|
739
|
-
/**
|
|
740
|
-
* Computes the definite integral using the trapezoidal rule.
|
|
741
|
-
*
|
|
742
|
-
* @param f - The function to integrate.
|
|
743
|
-
* @param a - Lower bound.
|
|
744
|
-
* @param b - Upper bound.
|
|
745
|
-
* @param n - Number of subintervals (default 100).
|
|
746
|
-
* @returns The approximate integral value.
|
|
747
|
-
*/
|
|
748
|
-
declare function trapezoidal(f: (x: number) => number, a: number, b: number, n?: number): number;
|
|
749
|
-
/**
|
|
750
|
-
* Finds a root of a function using Newton's method.
|
|
751
|
-
*
|
|
752
|
-
* @param f - The function.
|
|
753
|
-
* @param guess - Initial guess.
|
|
754
|
-
* @param tolerance - Convergence tolerance (default 1e-7).
|
|
755
|
-
* @param maxIter - Maximum iterations (default 100).
|
|
756
|
-
* @returns The root value, or NaN if not converged.
|
|
757
|
-
*/
|
|
758
|
-
declare function newtonRoot(f: (x: number) => number, guess: number, tolerance?: number, maxIter?: number): number;
|
|
759
|
-
/**
|
|
760
|
-
* Linearly interpolates between two values.
|
|
761
|
-
*
|
|
762
|
-
* @param a - Start value.
|
|
763
|
-
* @param b - End value.
|
|
764
|
-
* @param t - Interpolation factor (0 to 1).
|
|
765
|
-
* @returns The interpolated value.
|
|
766
|
-
*/
|
|
767
|
-
declare function lerp(a: number, b: number, t: number): number;
|
|
768
|
-
/**
|
|
769
|
-
* Maps a value from one range to another.
|
|
770
|
-
*
|
|
771
|
-
* @param value - The input value.
|
|
772
|
-
* @param inMin - Input range minimum.
|
|
773
|
-
* @param inMax - Input range maximum.
|
|
774
|
-
* @param outMin - Output range minimum.
|
|
775
|
-
* @param outMax - Output range maximum.
|
|
776
|
-
* @returns The mapped value.
|
|
777
|
-
*/
|
|
778
|
-
declare function mapRange(value: number, inMin: number, inMax: number, outMin: number, outMax: number): number;
|
|
779
116
|
|
|
780
|
-
export {
|
|
117
|
+
export { DivisionByZeroError, add, approxEqual, average, ceil, clamp, div, floor, inRange, mul, randomInt, round, sub, sum };
|