@danielsimonjr/mathts-core 0.3.1 → 0.4.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/chunk-ZPGSJR5L.js +6258 -0
- package/dist/index-DpOizJsa.d.ts +337 -0
- package/dist/index.d.ts +212 -186
- package/dist/index.js +140 -2746
- package/dist/internal.d.ts +510 -0
- package/dist/internal.js +144 -0
- package/package.json +7 -3
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
interface BigNumber {
|
|
2
|
+
isBigNumber: boolean;
|
|
3
|
+
constructor: {
|
|
4
|
+
prototype: {
|
|
5
|
+
isBigNumber: boolean;
|
|
6
|
+
};
|
|
7
|
+
isDecimal?: (x: unknown) => boolean;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface Complex {
|
|
11
|
+
re: number;
|
|
12
|
+
im: number;
|
|
13
|
+
}
|
|
14
|
+
interface Fraction {
|
|
15
|
+
n: number;
|
|
16
|
+
d: number;
|
|
17
|
+
}
|
|
18
|
+
interface Unit$1 {
|
|
19
|
+
constructor: {
|
|
20
|
+
prototype: {
|
|
21
|
+
isUnit: boolean;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface Matrix {
|
|
26
|
+
isMatrix?: boolean;
|
|
27
|
+
_size?: number[];
|
|
28
|
+
constructor: {
|
|
29
|
+
prototype: {
|
|
30
|
+
isMatrix: boolean;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
interface DenseMatrix extends Matrix {
|
|
35
|
+
isDenseMatrix: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface SparseMatrix extends Matrix {
|
|
38
|
+
isSparseMatrix: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface Range {
|
|
41
|
+
start: number;
|
|
42
|
+
end: number;
|
|
43
|
+
step: number;
|
|
44
|
+
constructor: {
|
|
45
|
+
prototype: {
|
|
46
|
+
isRange: boolean;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
interface IndexDimension {
|
|
51
|
+
_data?: unknown[];
|
|
52
|
+
_size: number[];
|
|
53
|
+
isRange?: boolean;
|
|
54
|
+
start?: number;
|
|
55
|
+
end?: number;
|
|
56
|
+
}
|
|
57
|
+
interface Index {
|
|
58
|
+
_dimensions: (IndexDimension | string)[];
|
|
59
|
+
_sourceSize?: (number | null)[];
|
|
60
|
+
constructor: {
|
|
61
|
+
prototype: {
|
|
62
|
+
isIndex: boolean;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
declare function isNumber(x: unknown): x is number;
|
|
67
|
+
declare function isBigNumber(x: unknown): x is BigNumber;
|
|
68
|
+
declare function isBigInt(x: unknown): x is bigint;
|
|
69
|
+
declare function isComplex(x: unknown): x is Complex;
|
|
70
|
+
declare function isFraction(x: unknown): x is Fraction;
|
|
71
|
+
declare function isUnit(x: unknown): x is Unit$1;
|
|
72
|
+
declare function isString(x: unknown): x is string;
|
|
73
|
+
declare const isArray: (arg: any) => arg is any[];
|
|
74
|
+
declare function isMatrix(x: unknown): x is Matrix;
|
|
75
|
+
/**
|
|
76
|
+
* Test whether a value is a collection: an Array or Matrix
|
|
77
|
+
* @param {*} x
|
|
78
|
+
* @returns {boolean} isCollection
|
|
79
|
+
*/
|
|
80
|
+
declare function isCollection(x: unknown): x is unknown[] | Matrix;
|
|
81
|
+
declare function isDenseMatrix(x: unknown): x is DenseMatrix;
|
|
82
|
+
declare function isSparseMatrix(x: unknown): x is SparseMatrix;
|
|
83
|
+
declare function isRange(x: unknown): x is Range;
|
|
84
|
+
declare function isIndex(x: unknown): x is Index;
|
|
85
|
+
declare function isBoolean(x: unknown): x is boolean;
|
|
86
|
+
declare function isFunction(x: unknown): x is (...args: unknown[]) => unknown;
|
|
87
|
+
declare function isDate(x: unknown): x is Date;
|
|
88
|
+
declare function isRegExp(x: unknown): x is RegExp;
|
|
89
|
+
declare function isObject(x: unknown): x is Record<string, unknown>;
|
|
90
|
+
/**
|
|
91
|
+
* Returns `true` if the passed object appears to be a Map (i.e. duck typing).
|
|
92
|
+
*
|
|
93
|
+
* Methods looked for are `get`, `set`, `keys` and `has`.
|
|
94
|
+
*
|
|
95
|
+
* @param {Map | object} object
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
declare function isMap(object: unknown): object is Map<unknown, unknown>;
|
|
99
|
+
declare function isNull(x: unknown): x is null;
|
|
100
|
+
declare function isUndefined(x: unknown): x is undefined;
|
|
101
|
+
declare function typeOf(x: unknown): string;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Shared TypeScript interfaces for the Unit factory (`Unit.ts`).
|
|
105
|
+
*
|
|
106
|
+
* The Unit type is a "function-as-class" (a constructor function whose
|
|
107
|
+
* prototype is built up imperatively) ported from mathjs. These interfaces
|
|
108
|
+
* describe the runtime shapes precisely so `Unit.ts` can be fully type-checked
|
|
109
|
+
* under strict mode without suppression directives or escape-hatch typing.
|
|
110
|
+
*
|
|
111
|
+
* @module @danielsimonjr/mathts-core/types/unit/unit-types
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
/** A complex number value (re/im pair), as produced by the `Complex` type. */
|
|
115
|
+
type ComplexValue = Complex;
|
|
116
|
+
/**
|
|
117
|
+
* Minimal structural view of a BigNumber value: only the instance methods that
|
|
118
|
+
* the Unit factory actually calls when computing angle constants.
|
|
119
|
+
*/
|
|
120
|
+
interface BigNumberValue {
|
|
121
|
+
div(other: BigNumberValue | number | string): BigNumberValue;
|
|
122
|
+
times(other: BigNumberValue | number | string): BigNumberValue;
|
|
123
|
+
}
|
|
124
|
+
/** Structural view of a Fraction value (numerator/denominator/sign). */
|
|
125
|
+
interface FractionValue {
|
|
126
|
+
n: number;
|
|
127
|
+
d: number;
|
|
128
|
+
s: number;
|
|
129
|
+
isFraction?: boolean;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Any numeric value a Unit can carry. Mirrors what `isNumeric`/`isComplex`
|
|
133
|
+
* accept at the constructor boundary (number, bigint, boolean, BigNumber,
|
|
134
|
+
* Fraction, Complex). Boolean/bigint flow through unchanged for valueless
|
|
135
|
+
* units and are coerced by the scalar operations otherwise.
|
|
136
|
+
*/
|
|
137
|
+
type Numeric = number | bigint | boolean | BigNumberValue | FractionValue | ComplexValue;
|
|
138
|
+
/** A prefix definition such as `{ name: 'k', value: 1e3, scientific: true }`. */
|
|
139
|
+
interface PrefixDef {
|
|
140
|
+
name: string;
|
|
141
|
+
value: number;
|
|
142
|
+
scientific: boolean;
|
|
143
|
+
}
|
|
144
|
+
/** A named table of prefixes (e.g. PREFIXES.SHORT), keyed by prefix name. */
|
|
145
|
+
type PrefixTable = Record<string, PrefixDef>;
|
|
146
|
+
/** A base dimension definition (the 9-element exponent vector + its key). */
|
|
147
|
+
interface BaseUnitDef {
|
|
148
|
+
dimensions: number[];
|
|
149
|
+
key?: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* A unit definition entry in the UNITS table. `dimensions` and `base.key` are
|
|
153
|
+
* populated after the literal is created (see the module-init loops), hence
|
|
154
|
+
* optional; `value` is `null` for angle units until `calculateAngleValues`
|
|
155
|
+
* runs at module init, before any unit is parsed.
|
|
156
|
+
*/
|
|
157
|
+
interface UnitDef {
|
|
158
|
+
name: string;
|
|
159
|
+
base?: BaseUnitDef;
|
|
160
|
+
prefixes?: PrefixTable;
|
|
161
|
+
value: Numeric | null;
|
|
162
|
+
offset: number;
|
|
163
|
+
dimensions?: number[];
|
|
164
|
+
reciprocal?: boolean;
|
|
165
|
+
}
|
|
166
|
+
/** A single component of a Unit's unit list (e.g. the `m` in `m/s^2`). */
|
|
167
|
+
interface UnitComponent {
|
|
168
|
+
unit: UnitDef;
|
|
169
|
+
prefix: PrefixDef;
|
|
170
|
+
power: number;
|
|
171
|
+
}
|
|
172
|
+
/** An entry in a unit system, pairing a unit with a default prefix. */
|
|
173
|
+
interface UnitSystemEntry {
|
|
174
|
+
unit: UnitDef;
|
|
175
|
+
prefix: PrefixDef;
|
|
176
|
+
}
|
|
177
|
+
/** A unit system (e.g. `si`, `cgs`, `us`, `auto`), keyed by base-dimension. */
|
|
178
|
+
type UnitSystem = Record<string, UnitSystemEntry>;
|
|
179
|
+
/** JSON serialization shape produced by `Unit#toJSON`. */
|
|
180
|
+
interface UnitJSON {
|
|
181
|
+
mathjs: 'Unit';
|
|
182
|
+
value: Numeric | null;
|
|
183
|
+
unit: string | null;
|
|
184
|
+
fixPrefix: boolean;
|
|
185
|
+
skipSimp: boolean;
|
|
186
|
+
}
|
|
187
|
+
/** A numeric-type converter (number → BigNumber/Fraction/Complex/number). */
|
|
188
|
+
type ConverterFn = (x: Numeric) => Numeric;
|
|
189
|
+
/** The table of numeric-type converters exposed on `Unit.typeConverters`. */
|
|
190
|
+
interface TypeConverters {
|
|
191
|
+
BigNumber: ConverterFn;
|
|
192
|
+
Fraction: ConverterFn;
|
|
193
|
+
Complex: ConverterFn;
|
|
194
|
+
number: ConverterFn;
|
|
195
|
+
[key: string]: ConverterFn;
|
|
196
|
+
}
|
|
197
|
+
/** Options accepted by `Unit.parse`. */
|
|
198
|
+
interface ParseOptions {
|
|
199
|
+
allowNoUnits?: boolean;
|
|
200
|
+
}
|
|
201
|
+
/** Formatting options accepted by `Unit#format` / `Unit#toBest`. */
|
|
202
|
+
interface UnitFormatOptions {
|
|
203
|
+
offset?: number;
|
|
204
|
+
[key: string]: unknown;
|
|
205
|
+
}
|
|
206
|
+
/** Options accepted by `Unit.createUnit`. */
|
|
207
|
+
interface CreateUnitOptions {
|
|
208
|
+
override?: boolean;
|
|
209
|
+
}
|
|
210
|
+
/** Object form of a `createUnit` / `createUnitSingle` definition. */
|
|
211
|
+
interface CreateUnitDefObject {
|
|
212
|
+
definition?: string | UnitInstance;
|
|
213
|
+
prefixes?: string;
|
|
214
|
+
offset?: number;
|
|
215
|
+
baseName?: string;
|
|
216
|
+
aliases?: string[];
|
|
217
|
+
}
|
|
218
|
+
/** Config object the Unit factory reads (`config` dep + `on('config')`). */
|
|
219
|
+
interface UnitConfig {
|
|
220
|
+
number: string;
|
|
221
|
+
predictable?: boolean;
|
|
222
|
+
}
|
|
223
|
+
/** Constructor (with static `.I`) for Complex values. */
|
|
224
|
+
interface ComplexConstructor {
|
|
225
|
+
readonly I: ComplexValue;
|
|
226
|
+
}
|
|
227
|
+
/** Constructor for BigNumber values. */
|
|
228
|
+
interface BigNumberConstructor {
|
|
229
|
+
new (value: number | string): BigNumberValue;
|
|
230
|
+
}
|
|
231
|
+
/** Constructor for Fraction values. */
|
|
232
|
+
interface FractionConstructor {
|
|
233
|
+
new (value: Numeric | string, denominator?: number): FractionValue;
|
|
234
|
+
}
|
|
235
|
+
/** `subtractScalar` is polymorphic: it also subtracts two Units (in splitUnit). */
|
|
236
|
+
interface SubtractScalar {
|
|
237
|
+
(a: UnitInstance, b: UnitInstance): UnitInstance;
|
|
238
|
+
(a: Numeric, b: Numeric): Numeric;
|
|
239
|
+
}
|
|
240
|
+
/** A binary scalar operation (add/multiply/divide/pow). */
|
|
241
|
+
type ScalarBinaryOp = (a: Numeric, b: Numeric) => Numeric;
|
|
242
|
+
/** A unary scalar operation (abs/fix/round). */
|
|
243
|
+
type ScalarUnaryOp = (x: Numeric) => Numeric;
|
|
244
|
+
/**
|
|
245
|
+
* The dependency object injected into the Unit factory by the factory system.
|
|
246
|
+
* `on` is optional (`?on` in the dependency list). The index signature reflects that
|
|
247
|
+
* this is a factory *scope* (a string-keyed dependency record that may also carry
|
|
248
|
+
* deps beyond the ones the Unit itself reads), and lets it satisfy the `factory`
|
|
249
|
+
* helper's `Record<string, unknown>` constraint.
|
|
250
|
+
*/
|
|
251
|
+
interface UnitDependencies {
|
|
252
|
+
[key: string]: unknown;
|
|
253
|
+
on?: (event: string, callback: (curr: UnitConfig, prev: UnitConfig) => void) => void;
|
|
254
|
+
config: UnitConfig;
|
|
255
|
+
addScalar: ScalarBinaryOp;
|
|
256
|
+
subtractScalar: SubtractScalar;
|
|
257
|
+
multiplyScalar: ScalarBinaryOp;
|
|
258
|
+
divideScalar: ScalarBinaryOp;
|
|
259
|
+
pow: ScalarBinaryOp;
|
|
260
|
+
abs: ScalarUnaryOp;
|
|
261
|
+
fix: ScalarUnaryOp;
|
|
262
|
+
round: ScalarUnaryOp;
|
|
263
|
+
equal: (a: unknown, b: unknown) => boolean;
|
|
264
|
+
isNumeric: (x: unknown) => boolean;
|
|
265
|
+
format: (value: unknown, options?: unknown) => string;
|
|
266
|
+
number: (x: unknown) => number;
|
|
267
|
+
Complex: ComplexConstructor;
|
|
268
|
+
BigNumber: BigNumberConstructor;
|
|
269
|
+
Fraction: FractionConstructor;
|
|
270
|
+
}
|
|
271
|
+
/** An instance of Unit (the prototype methods + per-instance fields). */
|
|
272
|
+
interface UnitInstance {
|
|
273
|
+
value: Numeric | null;
|
|
274
|
+
units: UnitComponent[];
|
|
275
|
+
dimensions: number[];
|
|
276
|
+
fixPrefix: boolean;
|
|
277
|
+
skipAutomaticSimplification: boolean;
|
|
278
|
+
type: 'Unit';
|
|
279
|
+
isUnit: boolean;
|
|
280
|
+
constructor: UnitConstructor;
|
|
281
|
+
clone(): UnitInstance;
|
|
282
|
+
valueType(): string;
|
|
283
|
+
_isDerived(): boolean;
|
|
284
|
+
_normalize(value: Numeric | null | undefined): Numeric | null;
|
|
285
|
+
_denormalize(value: Numeric | null, prefixValue?: Numeric): Numeric | null;
|
|
286
|
+
hasBase(base: BaseUnitDef | string | undefined): boolean;
|
|
287
|
+
equalBase(other: {
|
|
288
|
+
dimensions: number[];
|
|
289
|
+
}): boolean;
|
|
290
|
+
equals(other: UnitInstance): boolean;
|
|
291
|
+
multiply(other: UnitInstance | Numeric): UnitInstance | Numeric;
|
|
292
|
+
divideInto(numerator: Numeric): UnitInstance | Numeric;
|
|
293
|
+
divide(other: UnitInstance | Numeric): UnitInstance | Numeric;
|
|
294
|
+
pow(p: number): UnitInstance | Numeric;
|
|
295
|
+
abs(): UnitInstance;
|
|
296
|
+
to(valuelessUnit: string | UnitInstance): UnitInstance;
|
|
297
|
+
toNumber(valuelessUnit?: string | UnitInstance): number;
|
|
298
|
+
toNumeric(valuelessUnit?: string | UnitInstance): Numeric | null;
|
|
299
|
+
toString(): string;
|
|
300
|
+
toJSON(): UnitJSON;
|
|
301
|
+
valueOf(): string;
|
|
302
|
+
simplify(): UnitInstance;
|
|
303
|
+
toSI(): UnitInstance;
|
|
304
|
+
formatUnits(): string;
|
|
305
|
+
toBest(unitList?: Array<string | UnitInstance>, options?: UnitFormatOptions): UnitInstance;
|
|
306
|
+
format(options?: UnitFormatOptions): string;
|
|
307
|
+
_bestPrefix(offset?: number): PrefixDef;
|
|
308
|
+
splitUnit(parts: Array<string | UnitInstance>): UnitInstance[];
|
|
309
|
+
_numberConverter(): ConverterFn;
|
|
310
|
+
}
|
|
311
|
+
/** The Unit constructor function together with its static members. */
|
|
312
|
+
interface UnitConstructor {
|
|
313
|
+
new (value?: Numeric | null, valuelessUnit?: string | UnitInstance): UnitInstance;
|
|
314
|
+
prototype: UnitInstance;
|
|
315
|
+
name: string;
|
|
316
|
+
parse(str: string, options?: ParseOptions): UnitInstance;
|
|
317
|
+
isValuelessUnit(name: string): boolean;
|
|
318
|
+
isValidAlpha(c: string): boolean;
|
|
319
|
+
fromJSON(json: UnitJSON): UnitInstance;
|
|
320
|
+
setUnitSystem(name: string): void;
|
|
321
|
+
getUnitSystem(): string | undefined;
|
|
322
|
+
createUnit(obj: Record<string, unknown>, options?: CreateUnitOptions): UnitInstance | undefined;
|
|
323
|
+
createUnitSingle(name: string, obj?: unknown): UnitInstance;
|
|
324
|
+
deleteUnit(name: string): void;
|
|
325
|
+
_getNumberConverter(type: string): ConverterFn;
|
|
326
|
+
typeConverters: TypeConverters;
|
|
327
|
+
PREFIXES: Record<string, PrefixTable>;
|
|
328
|
+
BASE_DIMENSIONS: string[];
|
|
329
|
+
BASE_UNITS: Record<string, BaseUnitDef>;
|
|
330
|
+
UNIT_SYSTEMS: Record<string, UnitSystem>;
|
|
331
|
+
UNITS: Record<string, UnitDef>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** The core `Unit` class, pre-wired to core's numeric primitives. */
|
|
335
|
+
declare const Unit: UnitConstructor;
|
|
336
|
+
|
|
337
|
+
export { isNull as $, type UnitSystem as A, type BaseUnitDef as B, type Complex as C, type DenseMatrix as D, type UnitSystemEntry as E, type Fraction as F, isArray as G, isBigInt as H, type Index as I, isBigNumber as J, isBoolean as K, isCollection as L, type Matrix as M, type Numeric as N, isComplex as O, type ParseOptions as P, isDate as Q, type Range as R, type ScalarBinaryOp as S, type TypeConverters as T, Unit as U, isDenseMatrix as V, isFraction as W, isFunction as X, isIndex as Y, isMap as Z, isMatrix as _, type UnitInstance as a, isNumber as a0, isObject as a1, isRange as a2, isRegExp as a3, isSparseMatrix as a4, isString as a5, isUndefined as a6, typeOf as a7, type UnitConstructor as b, type UnitDependencies as c, type BigNumber as d, type BigNumberConstructor as e, type BigNumberValue as f, type ComplexConstructor as g, type ComplexValue as h, isUnit as i, type ConverterFn as j, type CreateUnitDefObject as k, type CreateUnitOptions as l, type FractionConstructor as m, type FractionValue as n, type IndexDimension as o, type PrefixDef as p, type PrefixTable as q, type ScalarUnaryOp as r, type SparseMatrix as s, type SubtractScalar as t, type Unit$1 as u, type UnitComponent as v, type UnitConfig as w, type UnitDef as x, type UnitFormatOptions as y, type UnitJSON as z };
|