@jarenjs/core 0.9.2 → 0.34.2

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.
Files changed (121) hide show
  1. package/ARCHITECTURE.md +229 -26
  2. package/README.md +64 -10
  3. package/dist/types/array.d.ts +13 -0
  4. package/dist/types/cache.d.ts +166 -0
  5. package/dist/types/chunk.d.ts +102 -0
  6. package/dist/types/color.d.ts +64 -0
  7. package/dist/types/convert/convert.d.ts +33 -0
  8. package/dist/types/convert/currency.d.ts +47 -0
  9. package/dist/types/convert/index.d.ts +9 -0
  10. package/dist/types/convert/registry.d.ts +55 -0
  11. package/dist/types/dates/civil.d.ts +146 -0
  12. package/dist/types/dates/duration.d.ts +83 -0
  13. package/dist/types/dates/format.d.ts +59 -0
  14. package/dist/types/dates/index.d.ts +4 -0
  15. package/dist/types/{dates.d.ts → dates/rfc3339.d.ts} +57 -3
  16. package/dist/types/errors.d.ts +77 -0
  17. package/dist/types/finance/amortization.d.ts +51 -0
  18. package/dist/types/finance/bond.d.ts +45 -0
  19. package/dist/types/finance/cashflow.d.ts +44 -0
  20. package/dist/types/finance/depreciation.d.ts +26 -0
  21. package/dist/types/finance/index.d.ts +16 -0
  22. package/dist/types/finance/indicators.d.ts +76 -0
  23. package/dist/types/finance/interest.d.ts +44 -0
  24. package/dist/types/finance/returns.d.ts +43 -0
  25. package/dist/types/finance/tvm.d.ts +50 -0
  26. package/dist/types/geo/angle.d.ts +4 -0
  27. package/dist/types/geo/bbox.d.ts +32 -0
  28. package/dist/types/geo/distance.d.ts +67 -0
  29. package/dist/types/geo/geohash.d.ts +63 -0
  30. package/dist/types/geo/geojson.d.ts +108 -0
  31. package/dist/types/geo/index-tree.d.ts +52 -0
  32. package/dist/types/geo/index.d.ts +11 -0
  33. package/dist/types/geo/mercator.d.ts +57 -0
  34. package/dist/types/geo/predicates.d.ts +44 -0
  35. package/dist/types/geo/ring.d.ts +80 -0
  36. package/dist/types/geo/simplify.d.ts +31 -0
  37. package/dist/types/geo/valid.d.ts +24 -0
  38. package/dist/types/geo/wkt.d.ts +16 -0
  39. package/dist/types/math/float64.d.ts +126 -3
  40. package/dist/types/math/format.d.ts +58 -0
  41. package/dist/types/math/index.d.ts +5 -0
  42. package/dist/types/math/mat4.d.ts +60 -0
  43. package/dist/types/math/project.d.ts +54 -0
  44. package/dist/types/math/solve.d.ts +67 -0
  45. package/dist/types/math/word.d.ts +82 -0
  46. package/dist/types/message.d.ts +52 -0
  47. package/dist/types/object.d.ts +151 -0
  48. package/dist/types/scan.d.ts +30 -0
  49. package/dist/types/schema.d.ts +24 -0
  50. package/dist/types/string.d.ts +96 -0
  51. package/dist/types/text/base64.d.ts +6 -4
  52. package/dist/types/text/email.d.ts +0 -1
  53. package/dist/types/text/host.d.ts +39 -8
  54. package/dist/types/text/i18n.d.ts +13 -1
  55. package/dist/types/text/index.d.ts +1 -0
  56. package/dist/types/text/misc.d.ts +15 -1
  57. package/dist/types/text/punycode.d.ts +45 -85
  58. package/docs/CONVERT.md +45 -0
  59. package/docs/DATES.md +78 -0
  60. package/docs/FINANCE.md +59 -0
  61. package/docs/GEO.md +114 -0
  62. package/docs/MATH.md +75 -0
  63. package/package.json +57 -4
  64. package/src/array.js +16 -0
  65. package/src/cache.js +206 -0
  66. package/src/chunk.js +159 -0
  67. package/src/color.js +125 -0
  68. package/src/convert/convert.js +59 -0
  69. package/src/convert/currency.js +74 -0
  70. package/src/convert/index.js +11 -0
  71. package/src/convert/registry.js +213 -0
  72. package/src/dates/civil.js +360 -0
  73. package/src/dates/duration.js +225 -0
  74. package/src/dates/format.js +238 -0
  75. package/src/dates/index.js +30 -0
  76. package/src/dates/rfc3339.js +621 -0
  77. package/src/errors.js +102 -0
  78. package/src/finance/amortization.js +50 -0
  79. package/src/finance/bond.js +100 -0
  80. package/src/finance/cashflow.js +122 -0
  81. package/src/finance/depreciation.js +54 -0
  82. package/src/finance/index.js +27 -0
  83. package/src/finance/indicators.js +207 -0
  84. package/src/finance/interest.js +63 -0
  85. package/src/finance/returns.js +90 -0
  86. package/src/finance/tvm.js +94 -0
  87. package/src/function.js +0 -2
  88. package/src/geo/angle.js +12 -0
  89. package/src/geo/bbox.js +80 -0
  90. package/src/geo/distance.js +155 -0
  91. package/src/geo/geohash.js +224 -0
  92. package/src/geo/geojson.js +361 -0
  93. package/src/geo/index-tree.js +294 -0
  94. package/src/geo/index.js +52 -0
  95. package/src/geo/mercator.js +124 -0
  96. package/src/geo/predicates.js +313 -0
  97. package/src/geo/ring.js +182 -0
  98. package/src/geo/simplify.js +130 -0
  99. package/src/geo/valid.js +142 -0
  100. package/src/geo/wkt.js +262 -0
  101. package/src/math/float64.js +228 -11
  102. package/src/math/format.js +157 -0
  103. package/src/math/index.js +5 -0
  104. package/src/math/mat4.js +131 -0
  105. package/src/math/project.js +49 -0
  106. package/src/math/solve.js +112 -0
  107. package/src/math/word.js +177 -0
  108. package/src/message.js +119 -0
  109. package/src/object.js +329 -0
  110. package/src/scan.js +42 -0
  111. package/src/schema.js +37 -0
  112. package/src/string.js +189 -0
  113. package/src/text/base64.js +15 -52
  114. package/src/text/email.js +0 -5
  115. package/src/text/host.js +515 -140
  116. package/src/text/i18n.js +13 -6
  117. package/src/text/identifiers.js +1 -1
  118. package/src/text/index.js +1 -0
  119. package/src/text/misc.js +81 -5
  120. package/src/text/punycode.js +235 -323
  121. package/src/dates.js +0 -371
@@ -5,6 +5,20 @@ export declare const mathf64_sin: (x: number) => number;
5
5
  export declare const mathf64_cos: (x: number) => number;
6
6
  export declare const mathf64_atan2: (y: number, x: number) => number;
7
7
  export declare const mathf64_asin: (x: number) => number;
8
+ export declare const mathf64_tan: (x: number) => number;
9
+ export declare const mathf64_acos: (x: number) => number;
10
+ export declare const mathf64_atan: (x: number) => number;
11
+ export declare const mathf64_sinh: (x: number) => number;
12
+ export declare const mathf64_cosh: (x: number) => number;
13
+ export declare const mathf64_tanh: (x: number) => number;
14
+ export declare const mathf64_cbrt: (x: number) => number;
15
+ export declare const mathf64_log: (x: number) => number;
16
+ export declare const mathf64_log2: (x: number) => number;
17
+ export declare const mathf64_log10: (x: number) => number;
18
+ export declare const mathf64_exp: (x: number) => number;
19
+ export declare const mathf64_expm1: (x: number) => number;
20
+ export declare const mathf64_hypot: (...values: number[]) => number;
21
+ export declare const mathf64_sign: (x: number) => number;
8
22
  export declare const mathf64_ceil: (x: number) => number;
9
23
  export declare const mathf64_floor: (x: number) => number;
10
24
  export declare const mathf64_round: (x: number) => number;
@@ -13,6 +27,10 @@ export declare const mathf64_max: (...values: number[]) => number;
13
27
  export declare const mathf64_random: () => number;
14
28
  export declare const mathf64_EPSILON = 0.000001;
15
29
  export declare const mathf64_SQRTFIVE: number;
30
+ export declare const mathf64_E: number;
31
+ export declare const mathf64_LN2: number;
32
+ export declare const mathf64_LN10: number;
33
+ export declare const mathf64_PHI: number;
16
34
  export declare const mathf64_PI: number;
17
35
  export declare const mathf64_PI2: number;
18
36
  export declare const mathf64_PI1H: number;
@@ -79,8 +97,6 @@ export declare class Float64 {
79
97
  static fib(n?: number): number;
80
98
  static fib2(value?: number): number;
81
99
  static norm(value?: number, min?: number, max?: number): number;
82
- static lerp(norm?: number, min?: number, max?: number): number;
83
- static map(value?: number, smin?: number, smax?: number, dmin?: number, dmax?: number): number;
84
100
  /**
85
101
  * Clamps a value between a checked boundary.
86
102
  * and can therefor handle swapped min/max arguments
@@ -111,11 +127,118 @@ export declare class Float64 {
111
127
  static sinLpEx(r?: number): number;
112
128
  static sinLp(r?: number): number;
113
129
  static cosLp(r?: number): number;
114
- static cosHp(r?: number): void;
130
+ static cosHp(r?: number): number;
115
131
  static sinMpEx(r?: number): number;
116
132
  static sinMp(r?: number): number;
117
133
  static cosMp(r?: number): number;
118
134
  static theta(x?: number, y?: number): number;
119
135
  static angle(x?: number, y?: number): number;
120
136
  static phi(y?: number, len?: number): number;
137
+ /**
138
+ * The base-e logarithm of `x` in an arbitrary base.
139
+ * @param {number} base
140
+ * @param {number} x
141
+ * @returns {number}
142
+ */
143
+ static logBase(base?: number, x?: number): number;
144
+ /**
145
+ * The sign of `x` (-1, 0 or +1); preserves ±0 and NaN like `Math.sign`.
146
+ * @param {number} x
147
+ * @returns {number}
148
+ */
149
+ static sign(x?: number): number;
150
+ /**
151
+ * The Euclidean length of any number of components, overflow-safe.
152
+ * @param {...number} args
153
+ * @returns {number}
154
+ */
155
+ static hypot(...args: number[]): number;
156
+ /**
157
+ * The real `n`-th root of `x` (odd roots of negatives handled).
158
+ * @param {number} x
159
+ * @param {number} n
160
+ * @returns {number}
161
+ */
162
+ static nthroot(x?: number, n?: number): number;
163
+ /**
164
+ * Round `value` to `digits` decimal places (banker-free, half-up).
165
+ * @param {number} value
166
+ * @param {number} [digits]
167
+ * @returns {number}
168
+ */
169
+ static roundTo(value?: number, digits?: number): number;
170
+ /**
171
+ * Round `value` to `digits` significant figures (1–100) — the numeric
172
+ * value of `Number.prototype.toPrecision`, without its exponential
173
+ * string formatting.
174
+ * @param {number} value
175
+ * @param {number} [digits]
176
+ * @returns {number}
177
+ */
178
+ static roundToPrecision(value?: number, digits?: number): number;
179
+ /**
180
+ * The Lanczos approximation of the Gamma function, valid for the whole
181
+ * real line (poles at non-positive integers return ±Infinity/NaN).
182
+ * @param {number} x
183
+ * @returns {number}
184
+ */
185
+ static gamma(x?: number): number;
186
+ /**
187
+ * The factorial `n!`. Integer `n` uses an exact product; non-integers
188
+ * are lifted to `gamma(n + 1)`. Negative integers return NaN.
189
+ * @param {number} n
190
+ * @returns {number}
191
+ */
192
+ static factorial(n?: number): number;
121
193
  }
194
+ /**
195
+ * Linear remap of `v` from the source range `[smin, smax]` to the destination
196
+ * range `[dmin, dmax]`: `dmin + t·(dmax - dmin)` with
197
+ * `t = (v - smin)/(smax - smin)`. A degenerate source range collapses to
198
+ * `dmin` rather than dividing by zero, so a constant-valued axis still maps to
199
+ * a drawable coordinate. Inverted destination ranges are supported, which is
200
+ * what screen-space y-flips need.
201
+ *
202
+ * @param {number} v
203
+ * @param {number} smin
204
+ * @param {number} smax
205
+ * @param {number} dmin
206
+ * @param {number} dmax
207
+ * @returns {number}
208
+ */
209
+ export declare function remap(v: number, smin: number, smax: number, dmin: number, dmax: number): number;
210
+ /**
211
+ * The "nice" axis step — 1, 2 or 5 times a power of ten — that covers `span`
212
+ * in roughly `count` steps, so a tick sequence reads as 0/2/4/6 rather than
213
+ * 0/1.7/3.4. `count` is floored at 1; pass a pre-divided per-step span and
214
+ * leave it at its default to get the ladder alone.
215
+ *
216
+ * The ladder is pure arithmetic with no domain guard: it is the caller who
217
+ * knows what a non-positive or non-finite `span` means for its axis, and
218
+ * different axes answer that differently.
219
+ *
220
+ * @param {number} span the domain span to cover
221
+ * @param {number} [count] desired number of steps (floored at 1)
222
+ * @returns {number}
223
+ */
224
+ export declare function niceStep(span: number, count?: number): number;
225
+ /**
226
+ * Clamp a value into the unit interval `[0, 1]` — the fraction every
227
+ * unit-space geometry stage emits. `NaN` passes through as `NaN` rather
228
+ * than collapsing to a boundary, so a non-finite input stays visible to
229
+ * the caller instead of silently rendering at an edge; callers that want a
230
+ * drawable coordinate regardless guard with `Number.isFinite` first.
231
+ *
232
+ * @param {number} v
233
+ * @returns {number}
234
+ */
235
+ export declare function clamp01(v: number): number;
236
+ /**
237
+ * Geometric mean — the honest average of ratios (a 10× and a 0.1×
238
+ * average to parity, where an arithmetic mean would claim 5×).
239
+ * Non-finite and non-positive entries are skipped; `null` when nothing
240
+ * usable remains.
241
+ * @param {number[]} values
242
+ * @returns {number|null}
243
+ */
244
+ export declare function geoMean(values: number[]): number | null;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * @file Number formatting and parsing. The
3
+ * one place the suite formats a number for display: notation control
4
+ * (auto/fixed/sci/eng), thousands grouping and radix output, plus a
5
+ * radix-aware `parseNumber`. Radix I/O delegates to `math/word.js` so
6
+ * base conversion is never re-implemented.
7
+ */
8
+ export type FormatOptions = {
9
+ /**
10
+ * default 'auto'
11
+ */
12
+ notation?: 'auto' | 'fixed' | 'sci' | 'eng';
13
+ /**
14
+ * significant/decimal digits (notation-dependent)
15
+ */
16
+ precision?: number;
17
+ /**
18
+ * thousands separator: true → ',', or a custom string
19
+ */
20
+ group?: boolean | string;
21
+ /**
22
+ * 2..36; when not 10, `value` is formatted as an integer word
23
+ */
24
+ radix?: number;
25
+ /**
26
+ * decimal mark, default '.'
27
+ */
28
+ decimal?: string;
29
+ };
30
+ /**
31
+ * Format a number for display.
32
+ *
33
+ * `notation: 'auto'` (the default) is NOT a drop-in for a fixed-unit
34
+ * readout: the auto branch escapes to exponential once
35
+ * `abs(value) >= 1e21` or `abs(value) < 1e-6`, so
36
+ * `formatNumber(v, { precision: 3 })` is not interchangeable with a
37
+ * plain `Number(v.toPrecision(3))`. A caller that appends its own unit
38
+ * - `"0.0509 ms"` - wants the value never to become `5.09e-5`, and must
39
+ * either pass `notation: 'fixed'` or keep its own rounder. See
40
+ * packages/core/docs/MATH.md.
41
+ * @param {number} value
42
+ * @param {FormatOptions} [opts]
43
+ * @returns {string}
44
+ */
45
+ export declare function formatNumber(value: number, opts?: FormatOptions): string;
46
+ /**
47
+ * Parse a numeric string, radix-aware. Recognizes `0x`/`0o`/`0b`
48
+ * prefixes, an explicit `radix` option, grouping separators (`,`/`_`/
49
+ * space) and base-10 scientific notation. Returns `NaN` on failure
50
+ * rather than throwing.
51
+ *
52
+ * @param {string} str
53
+ * @param {{ radix?: number }} [opts]
54
+ * @returns {number}
55
+ */
56
+ export declare function parseNumber(str: string, opts?: {
57
+ radix?: number;
58
+ }): number;
@@ -3,3 +3,8 @@ export * from './vec2i32.js';
3
3
  export * from './float64.js';
4
4
  export * from './vec2f64.js';
5
5
  export * from './vec3f64.js';
6
+ export * from './word.js';
7
+ export * from './solve.js';
8
+ export * from './mat4.js';
9
+ export * from './project.js';
10
+ export * from './format.js';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @file A minimal 4×4 matrix kernel for the x·y·z plotter and
3
+ * any future 3D consumer (Mermaid 3D is a candidate — see ROADMAP).
4
+ *
5
+ * Matrices are `Float64Array(16)` in **column-major** order (the WebGL /
6
+ * glMatrix convention): element `m[col * 4 + row]`. Every factory returns
7
+ * a fresh array; `multiply` composes right-to-left like linear algebra
8
+ * (`multiply(a, b)` applies `b` then `a` to a column vector).
9
+ */
10
+ export type Mat4Array = Float64Array;
11
+ /** @typedef {Float64Array} Mat4Array */
12
+ export declare class Mat4 {
13
+ /** @returns {Mat4Array} the 4×4 identity. */
14
+ static identity(): Mat4Array;
15
+ /**
16
+ * `a · b` (column-major). Neither operand is mutated.
17
+ * @param {Mat4Array} a @param {Mat4Array} b
18
+ * @returns {Mat4Array}
19
+ */
20
+ static multiply(a: Mat4Array, b: Mat4Array): Mat4Array;
21
+ /** @param {number} rad @returns {Mat4Array} */
22
+ static rotationX(rad: number): Mat4Array;
23
+ /** @param {number} rad @returns {Mat4Array} */
24
+ static rotationY(rad: number): Mat4Array;
25
+ /** @param {number} rad @returns {Mat4Array} */
26
+ static rotationZ(rad: number): Mat4Array;
27
+ /** @param {number} tx @param {number} ty @param {number} tz @returns {Mat4Array} */
28
+ static translation(tx: number, ty: number, tz: number): Mat4Array;
29
+ /** @param {number} sx @param {number} sy @param {number} sz @returns {Mat4Array} */
30
+ static scaling(sx: number, sy: number, sz: number): Mat4Array;
31
+ /**
32
+ * Orthographic projection.
33
+ * @param {number} l @param {number} r @param {number} b @param {number} t
34
+ * @param {number} n @param {number} f
35
+ * @returns {Mat4Array}
36
+ */
37
+ static ortho(l: number, r: number, b: number, t: number, n: number, f: number): Mat4Array;
38
+ /**
39
+ * Perspective projection (right-handed, clip space z in [-1, 1]).
40
+ * @param {number} fovy vertical field of view, radians
41
+ * @param {number} aspect width / height
42
+ * @param {number} n near plane (> 0)
43
+ * @param {number} f far plane
44
+ * @returns {Mat4Array}
45
+ */
46
+ static perspective(fovy: number, aspect: number, n: number, f: number): Mat4Array;
47
+ /**
48
+ * Transform a 3D point (implicit w = 1) by `m`, returning the
49
+ * perspective-divided `{ x, y, z, w }` (w is the pre-divide clip w, so
50
+ * callers can reject points behind the camera).
51
+ * @param {Mat4Array} m @param {number} x @param {number} y @param {number} z
52
+ * @returns {{ x: number, y: number, z: number, w: number }}
53
+ */
54
+ static transformPoint(m: Mat4Array, x: number, y: number, z: number): {
55
+ x: number;
56
+ y: number;
57
+ z: number;
58
+ w: number;
59
+ };
60
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @file 3D → 2D projection helpers, built on `Mat4` and the
3
+ * existing `Vec3f64`. Used by the x·y·z plotter to turn a rotated grid
4
+ * of surface points into screen coordinates and to shade faces.
5
+ */
6
+ export type Viewport = {
7
+ /**
8
+ * left edge in pixels
9
+ */
10
+ x: number;
11
+ /**
12
+ * top edge in pixels
13
+ */
14
+ y: number;
15
+ width: number;
16
+ height: number;
17
+ };
18
+ /**
19
+ * @typedef {object} Viewport
20
+ * @property {number} x left edge in pixels
21
+ * @property {number} y top edge in pixels
22
+ * @property {number} width
23
+ * @property {number} height
24
+ */
25
+ /**
26
+ * Project a 3D point through `mat` (model·view·projection) and map the
27
+ * resulting normalized device coordinates into `viewport` pixels. The Y
28
+ * axis is flipped so that +Y is up in world space but down in screen
29
+ * space, as SVG expects.
30
+ *
31
+ * @param {{ x: number, y: number, z: number } | import('./vec3f64.js').Vec3f64} point3
32
+ * @param {import('./mat4.js').Mat4Array} mat
33
+ * @param {Viewport} viewport
34
+ * @returns {{ x: number, y: number, z: number, w: number }}
35
+ */
36
+ export declare function project3dTo2d(point3: {
37
+ x: number;
38
+ y: number;
39
+ z: number;
40
+ } | import('./vec3f64.js').Vec3f64, mat: import('./mat4.js').Mat4Array, viewport: Viewport): {
41
+ x: number;
42
+ y: number;
43
+ z: number;
44
+ w: number;
45
+ };
46
+ /**
47
+ * The (un-normalized) surface normal of triangle `a→b→c`, right-hand
48
+ * winding. Returns a `Vec3f64`.
49
+ * @param {import('./vec3f64.js').Vec3f64} a
50
+ * @param {import('./vec3f64.js').Vec3f64} b
51
+ * @param {import('./vec3f64.js').Vec3f64} c
52
+ * @returns {import('./vec3f64.js').Vec3f64}
53
+ */
54
+ export declare function surfaceNormal(a: import('./vec3f64.js').Vec3f64, b: import('./vec3f64.js').Vec3f64, c: import('./vec3f64.js').Vec3f64): import('./vec3f64.js').Vec3f64;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @file Generic, domain-free numeric root finders. No finance
3
+ * or geometry lives here; `@jarenjs/core/finance` builds NPV/IRR/rate on
4
+ * top of these, the calculator's equation helpers on top of them too.
5
+ *
6
+ * Each solver returns a `{ root, iterations, converged }` record instead
7
+ * of throwing on non-convergence — callers decide how to react (finance
8
+ * falls back from Newton to bisection, for example).
9
+ */
10
+ export type SolveResult = {
11
+ /**
12
+ * the best estimate found
13
+ */
14
+ root: number;
15
+ /**
16
+ * iterations actually run
17
+ */
18
+ iterations: number;
19
+ /**
20
+ * whether `tol` was reached
21
+ */
22
+ converged: boolean;
23
+ };
24
+ /**
25
+ * Newton–Raphson using an explicit derivative. Falls back to reporting
26
+ * non-convergence (rather than diverging silently) when the derivative
27
+ * vanishes or the step explodes.
28
+ *
29
+ * @param {(x: number) => number} f
30
+ * @param {(x: number) => number} df
31
+ * @param {number} x0
32
+ * @param {{ tol?: number, maxIter?: number }} [opts]
33
+ * @returns {SolveResult}
34
+ */
35
+ export declare function newtonRaphson(f: (x: number) => number, df: (x: number) => number, x0: number, opts?: {
36
+ tol?: number;
37
+ maxIter?: number;
38
+ }): SolveResult;
39
+ /**
40
+ * Bisection on a sign-changing bracket `[a, b]`. Guaranteed to converge
41
+ * when `f(a)` and `f(b)` straddle a root; returns `converged: false` if
42
+ * the bracket does not (rather than throwing).
43
+ *
44
+ * @param {(x: number) => number} f
45
+ * @param {number} a
46
+ * @param {number} b
47
+ * @param {{ tol?: number, maxIter?: number }} [opts]
48
+ * @returns {SolveResult}
49
+ */
50
+ export declare function bisect(f: (x: number) => number, a: number, b: number, opts?: {
51
+ tol?: number;
52
+ maxIter?: number;
53
+ }): SolveResult;
54
+ /**
55
+ * The secant method (Newton without an explicit derivative). Needs two
56
+ * starting points.
57
+ *
58
+ * @param {(x: number) => number} f
59
+ * @param {number} x0
60
+ * @param {number} x1
61
+ * @param {{ tol?: number, maxIter?: number }} [opts]
62
+ * @returns {SolveResult}
63
+ */
64
+ export declare function secant(f: (x: number) => number, x0: number, x1: number, opts?: {
65
+ tol?: number;
66
+ maxIter?: number;
67
+ }): SolveResult;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * @file BigInt fixed-width word math. The programmer-calculator
3
+ * kernel: two's-complement integers of a fixed bit width (8/16/32/64),
4
+ * signed or unsigned, with the bitwise/shift/rotate operators and
5
+ * radix-string I/O a HEX/DEC/OCT/BIN calculator needs.
6
+ *
7
+ * Everything is native `BigInt` — zero dependencies, exact at any width.
8
+ * Values crossing the module boundary are plain `BigInt`s already reduced
9
+ * to the requested word (mask + sign-extend), so operators compose
10
+ * without re-normalizing.
11
+ */
12
+ /** Supported word sizes, in bits. */
13
+ export declare const WORD_BITS: readonly number[];
14
+ /**
15
+ * The unsigned mask for a word of `bits` bits: `2**bits - 1`.
16
+ * @param {number} bits
17
+ * @returns {bigint}
18
+ */
19
+ export declare function wordMask(bits: number): bigint;
20
+ /**
21
+ * Reduce any integer to a fixed-width word. Unsigned words wrap into
22
+ * `[0, 2**bits)`; signed words are the two's-complement interpretation,
23
+ * so the high bit becomes the sign and the result lands in
24
+ * `[-2**(bits-1), 2**(bits-1))`.
25
+ *
26
+ * @param {bigint|number|string} value
27
+ * @param {number} [bits]
28
+ * @param {boolean} [signed]
29
+ * @returns {bigint}
30
+ */
31
+ export declare function toWord(value: bigint | number | string, bits?: number, signed?: boolean): bigint;
32
+ /** @param {bigint} a @param {bigint} b @param {number} [bits] @param {boolean} [signed] */
33
+ export declare function wAnd(a: bigint, b: bigint, bits?: number, signed?: boolean): bigint;
34
+ /** @param {bigint} a @param {bigint} b @param {number} [bits] @param {boolean} [signed] */
35
+ export declare function wOr(a: bigint, b: bigint, bits?: number, signed?: boolean): bigint;
36
+ /** @param {bigint} a @param {bigint} b @param {number} [bits] @param {boolean} [signed] */
37
+ export declare function wXor(a: bigint, b: bigint, bits?: number, signed?: boolean): bigint;
38
+ /** @param {bigint} a @param {number} [bits] @param {boolean} [signed] */
39
+ export declare function wNot(a: bigint, bits?: number, signed?: boolean): bigint;
40
+ /** @param {bigint} a @param {bigint} n @param {number} [bits] @param {boolean} [signed] */
41
+ export declare function wShl(a: bigint, n: bigint, bits?: number, signed?: boolean): bigint;
42
+ /**
43
+ * Logical right shift (zero fill) over the unsigned representation, then
44
+ * reinterpreted per `signed`.
45
+ * @param {bigint} a @param {bigint} n @param {number} [bits] @param {boolean} [signed]
46
+ */
47
+ export declare function wShr(a: bigint, n: bigint, bits?: number, signed?: boolean): bigint;
48
+ /** Rotate left. @param {bigint} a @param {bigint} n @param {number} [bits] @param {boolean} [signed] */
49
+ export declare function wRol(a: bigint, n: bigint, bits?: number, signed?: boolean): bigint;
50
+ /** Rotate right. @param {bigint} a @param {bigint} n @param {number} [bits] @param {boolean} [signed] */
51
+ export declare function wRor(a: bigint, n: bigint, bits?: number, signed?: boolean): bigint;
52
+ /**
53
+ * Euclidean-flavoured modulo that follows the sign of the divisor,
54
+ * reduced back into the word.
55
+ * @param {bigint} a @param {bigint} b @param {number} [bits] @param {boolean} [signed]
56
+ */
57
+ export declare function wMod(a: bigint, b: bigint, bits?: number, signed?: boolean): bigint;
58
+ /**
59
+ * Format an integer as a radix string (no prefix). Groups digits with an
60
+ * optional separator and left-pads to `pad` digits.
61
+ *
62
+ * @param {bigint|number} int
63
+ * @param {number} [radix] 2..36
64
+ * @param {{ group?: number, sep?: string, pad?: number, upper?: boolean }} [opts]
65
+ * @returns {string}
66
+ */
67
+ export declare function toBase(int: bigint | number, radix?: number, opts?: {
68
+ group?: number;
69
+ sep?: string;
70
+ pad?: number;
71
+ upper?: boolean;
72
+ }): string;
73
+ /**
74
+ * Parse a radix string back to a BigInt. Tolerates group separators
75
+ * (space/underscore), a leading sign, and an optional `0x`/`0o`/`0b`
76
+ * prefix (which must agree with `radix` when both are given).
77
+ *
78
+ * @param {string} str
79
+ * @param {number} [radix] 2..36
80
+ * @returns {bigint}
81
+ */
82
+ export declare function fromBase(str: string, radix?: number): bigint;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Human-message templating: the shared half of every message catalog in
3
+ * the suite.
4
+ *
5
+ * A catalog is a plain flat object keyed by a stable message id, whose
6
+ * entries are either render closures or template strings. Compiling one
7
+ * turns every template string into a closure, so the consumer only ever
8
+ * calls `catalog[msgid](params)` — the two-stage house rule applied to
9
+ * messages: parse the template once, render many times.
10
+ *
11
+ * This lives in `@jarenjs/core` so that packages which must not depend on
12
+ * each other can still speak the identical catalog contract. That is what
13
+ * lets one locale pack service both the validator's document voice ("must
14
+ * have required property 'x'") and the form layer's field voice ("This
15
+ * field is required") without either package importing the other.
16
+ */
17
+ /**
18
+ * Render one interpolated parameter: `String(v)` for primitives,
19
+ * `JSON.stringify(v)` for objects and arrays.
20
+ *
21
+ * @param {unknown} value - The parameter value
22
+ * @returns {string} The rendered value
23
+ */
24
+ export declare function formatTemplateParam(value: unknown): string;
25
+ /**
26
+ * Render a JSON value for quotation inside a message: strings keep their
27
+ * quotes so an empty or space-padded value is visible, everything else is
28
+ * JSON.
29
+ *
30
+ * @param {unknown} value - The value to render
31
+ * @returns {string}
32
+ */
33
+ export declare function formatMessageValue(value: unknown): string;
34
+ /**
35
+ * Compile a message template into a render closure. Template syntax:
36
+ * `{name}` substitutes the params member `name`; an unknown name leaves
37
+ * the placeholder literally (so a catalog typo shows up in the output
38
+ * instead of rendering as `undefined`); `{{` escapes a literal `{`.
39
+ *
40
+ * @param {string} template - The template text
41
+ * @returns {(params: object, error?: object) => string} The compiled render closure
42
+ */
43
+ export declare function compileMessageTemplate(template: string): (params: object, error?: object) => string;
44
+ /**
45
+ * Compile a catalog-like object into a functions-only frozen catalog.
46
+ * Entries may be render closures (kept as-is) or template strings
47
+ * (compiled through {@link compileMessageTemplate}).
48
+ *
49
+ * @param {Record<string, string | ((params: object, error?: object) => string)>} catalogLike - The catalog to compile
50
+ * @returns {Readonly<Record<string, (params: object, error?: object) => string>>} The compiled catalog
51
+ */
52
+ export declare function compileMessageCatalog(catalogLike: Record<string, string | ((params: object, error?: object) => string)>): Readonly<Record<string, (params: object, error?: object) => string>>;