Amitkumar001 commited on
Commit
dc4ddea
·
verified ·
1 Parent(s): f119c28

Upload folder using huggingface_hub (part 7)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. web/node_modules/fastq/README.md +310 -0
  3. web/node_modules/fastq/SECURITY.md +15 -0
  4. web/node_modules/fastq/queue.js +346 -0
  5. web/node_modules/fastq/test/example.ts +83 -0
  6. web/node_modules/fastq/test/promise.js +325 -0
  7. web/node_modules/fastq/test/test.js +733 -0
  8. web/node_modules/fastq/test/tsconfig.json +11 -0
  9. web/node_modules/fdir/LICENSE +7 -0
  10. web/node_modules/fdir/README.md +91 -0
  11. web/node_modules/fdir/dist/index.cjs +588 -0
  12. web/node_modules/fdir/dist/index.d.cts +155 -0
  13. web/node_modules/fdir/dist/index.d.mts +155 -0
  14. web/node_modules/fdir/dist/index.mjs +570 -0
  15. web/node_modules/fdir/package.json +103 -0
  16. web/node_modules/fill-range/LICENSE +21 -0
  17. web/node_modules/fill-range/README.md +237 -0
  18. web/node_modules/fill-range/index.js +248 -0
  19. web/node_modules/fill-range/package.json +74 -0
  20. web/node_modules/fraction.js/CHANGELOG.md +38 -0
  21. web/node_modules/fraction.js/LICENSE +21 -0
  22. web/node_modules/fraction.js/README.md +520 -0
  23. web/node_modules/fraction.js/dist/fraction.js +1045 -0
  24. web/node_modules/fraction.js/dist/fraction.min.js +21 -0
  25. web/node_modules/fraction.js/dist/fraction.mjs +1043 -0
  26. web/node_modules/fraction.js/examples/angles.js +26 -0
  27. web/node_modules/fraction.js/examples/approx.js +54 -0
  28. web/node_modules/fraction.js/examples/egyptian.js +24 -0
  29. web/node_modules/fraction.js/examples/hesse-convergence.js +111 -0
  30. web/node_modules/fraction.js/examples/integrate.js +67 -0
  31. web/node_modules/fraction.js/examples/ratio-chain.js +24 -0
  32. web/node_modules/fraction.js/examples/rational-pow.js +29 -0
  33. web/node_modules/fraction.js/examples/tape-measure.js +16 -0
  34. web/node_modules/fraction.js/examples/toFraction.js +35 -0
  35. web/node_modules/fraction.js/examples/valueOfPi.js +42 -0
  36. web/node_modules/fraction.js/fraction.d.mts +79 -0
  37. web/node_modules/fraction.js/fraction.d.ts +79 -0
  38. web/node_modules/fraction.js/package.json +81 -0
  39. web/node_modules/fraction.js/src/fraction.js +1046 -0
  40. web/node_modules/fraction.js/tests/fraction.test.js +1806 -0
  41. web/node_modules/function-bind/.eslintrc +21 -0
  42. web/node_modules/function-bind/.github/FUNDING.yml +12 -0
  43. web/node_modules/function-bind/.github/SECURITY.md +3 -0
  44. web/node_modules/function-bind/.nycrc +13 -0
  45. web/node_modules/function-bind/CHANGELOG.md +136 -0
  46. web/node_modules/function-bind/LICENSE +20 -0
  47. web/node_modules/function-bind/README.md +46 -0
  48. web/node_modules/function-bind/implementation.js +84 -0
  49. web/node_modules/function-bind/index.js +5 -0
  50. web/node_modules/function-bind/package.json +87 -0
.gitattributes CHANGED
@@ -37,3 +37,4 @@ web/node_modules/@oxlint/binding-win32-x64-msvc/oxlint.win32-x64-msvc.node filte
37
  web/node_modules/@rolldown/binding-win32-x64-msvc/rolldown-binding.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
38
  web/node_modules/@tailwindcss/node/node_modules/lightningcss-win32-x64-msvc/lightningcss.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
39
  web/node_modules/@tailwindcss/oxide-win32-x64-msvc/tailwindcss-oxide.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
 
 
37
  web/node_modules/@rolldown/binding-win32-x64-msvc/rolldown-binding.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
38
  web/node_modules/@tailwindcss/node/node_modules/lightningcss-win32-x64-msvc/lightningcss.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
39
  web/node_modules/@tailwindcss/oxide-win32-x64-msvc/tailwindcss-oxide.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
40
+ web/node_modules/lightningcss-win32-x64-msvc/lightningcss.win32-x64-msvc.node filter=lfs diff=lfs merge=lfs -text
web/node_modules/fastq/README.md ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # fastq
2
+
3
+ ![ci][ci-url]
4
+ [![npm version][npm-badge]][npm-url]
5
+
6
+ Fast, in memory work queue.
7
+
8
+ Benchmarks (1 million tasks):
9
+
10
+ * setImmediate: 812ms
11
+ * fastq: 854ms
12
+ * async.queue: 1298ms
13
+ * neoAsync.queue: 1249ms
14
+
15
+ Obtained on node 12.16.1, on a dedicated server.
16
+
17
+ If you need zero-overhead series function call, check out
18
+ [fastseries](http://npm.im/fastseries). For zero-overhead parallel
19
+ function call, check out [fastparallel](http://npm.im/fastparallel).
20
+
21
+ * <a href="#install">Installation</a>
22
+ * <a href="#usage">Usage</a>
23
+ * <a href="#api">API</a>
24
+ * <a href="#license">Licence &amp; copyright</a>
25
+
26
+ ## Install
27
+
28
+ `npm i fastq --save`
29
+
30
+ ## Usage (callback API)
31
+
32
+ ```js
33
+ 'use strict'
34
+
35
+ const queue = require('fastq')(worker, 1)
36
+
37
+ queue.push(42, function (err, result) {
38
+ if (err) { throw err }
39
+ console.log('the result is', result)
40
+ })
41
+
42
+ function worker (arg, cb) {
43
+ cb(null, arg * 2)
44
+ }
45
+ ```
46
+
47
+ ## Usage (promise API)
48
+
49
+ ```js
50
+ const queue = require('fastq').promise(worker, 1)
51
+
52
+ async function worker (arg) {
53
+ return arg * 2
54
+ }
55
+
56
+ async function run () {
57
+ const result = await queue.push(42)
58
+ console.log('the result is', result)
59
+ }
60
+
61
+ run()
62
+ ```
63
+
64
+ ### Setting "this"
65
+
66
+ ```js
67
+ 'use strict'
68
+
69
+ const that = { hello: 'world' }
70
+ const queue = require('fastq')(that, worker, 1)
71
+
72
+ queue.push(42, function (err, result) {
73
+ if (err) { throw err }
74
+ console.log(this)
75
+ console.log('the result is', result)
76
+ })
77
+
78
+ function worker (arg, cb) {
79
+ console.log(this)
80
+ cb(null, arg * 2)
81
+ }
82
+ ```
83
+
84
+ ### Using with TypeScript (callback API)
85
+
86
+ ```ts
87
+ 'use strict'
88
+
89
+ import * as fastq from "fastq";
90
+ import type { queue, done } from "fastq";
91
+
92
+ type Task = {
93
+ id: number
94
+ }
95
+
96
+ const q: queue<Task> = fastq(worker, 1)
97
+
98
+ q.push({ id: 42})
99
+
100
+ function worker (arg: Task, cb: done) {
101
+ console.log(arg.id)
102
+ cb(null)
103
+ }
104
+ ```
105
+
106
+ ### Using with TypeScript (promise API)
107
+
108
+ ```ts
109
+ 'use strict'
110
+
111
+ import * as fastq from "fastq";
112
+ import type { queueAsPromised } from "fastq";
113
+
114
+ type Task = {
115
+ id: number
116
+ }
117
+
118
+ const q: queueAsPromised<Task> = fastq.promise(asyncWorker, 1)
119
+
120
+ q.push({ id: 42}).catch((err) => console.error(err))
121
+
122
+ async function asyncWorker (arg: Task): Promise<void> {
123
+ // No need for a try-catch block, fastq handles errors automatically
124
+ console.log(arg.id)
125
+ }
126
+ ```
127
+
128
+ ## API
129
+
130
+ * <a href="#fastqueue"><code>fastqueue()</code></a>
131
+ * <a href="#push"><code>queue#<b>push()</b></code></a>
132
+ * <a href="#unshift"><code>queue#<b>unshift()</b></code></a>
133
+ * <a href="#pause"><code>queue#<b>pause()</b></code></a>
134
+ * <a href="#resume"><code>queue#<b>resume()</b></code></a>
135
+ * <a href="#idle"><code>queue#<b>idle()</b></code></a>
136
+ * <a href="#length"><code>queue#<b>length()</b></code></a>
137
+ * <a href="#getQueue"><code>queue#<b>getQueue()</b></code></a>
138
+ * <a href="#kill"><code>queue#<b>kill()</b></code></a>
139
+ * <a href="#killAndDrain"><code>queue#<b>killAndDrain()</b></code></a>
140
+ * <a href="#error"><code>queue#<b>error()</b></code></a>
141
+ * <a href="#concurrency"><code>queue#<b>concurrency</b></code></a>
142
+ * <a href="#drain"><code>queue#<b>drain</b></code></a>
143
+ * <a href="#empty"><code>queue#<b>empty</b></code></a>
144
+ * <a href="#saturated"><code>queue#<b>saturated</b></code></a>
145
+ * <a href="#promise"><code>fastqueue.promise()</code></a>
146
+
147
+ -------------------------------------------------------
148
+ <a name="fastqueue"></a>
149
+ ### fastqueue([that], worker, concurrency)
150
+
151
+ Creates a new queue.
152
+
153
+ Arguments:
154
+
155
+ * `that`, optional context of the `worker` function.
156
+ * `worker`, worker function, it would be called with `that` as `this`,
157
+ if that is specified.
158
+ * `concurrency`, number of concurrent tasks that could be executed in
159
+ parallel.
160
+
161
+ -------------------------------------------------------
162
+ <a name="push"></a>
163
+ ### queue.push(task, done)
164
+
165
+ Add a task at the end of the queue. `done(err, result)` will be called
166
+ when the task was processed.
167
+
168
+ -------------------------------------------------------
169
+ <a name="unshift"></a>
170
+ ### queue.unshift(task, done)
171
+
172
+ Add a task at the beginning of the queue. `done(err, result)` will be called
173
+ when the task was processed.
174
+
175
+ -------------------------------------------------------
176
+ <a name="pause"></a>
177
+ ### queue.pause()
178
+
179
+ Pause the processing of tasks. Currently worked tasks are not
180
+ stopped.
181
+
182
+ -------------------------------------------------------
183
+ <a name="resume"></a>
184
+ ### queue.resume()
185
+
186
+ Resume the processing of tasks.
187
+
188
+ -------------------------------------------------------
189
+ <a name="idle"></a>
190
+ ### queue.idle()
191
+
192
+ Returns `false` if there are tasks being processed or waiting to be processed.
193
+ `true` otherwise.
194
+
195
+ -------------------------------------------------------
196
+ <a name="length"></a>
197
+ ### queue.length()
198
+
199
+ Returns the number of tasks waiting to be processed (in the queue).
200
+
201
+ -------------------------------------------------------
202
+ <a name="getQueue"></a>
203
+ ### queue.getQueue()
204
+
205
+ Returns all the tasks be processed (in the queue). Returns empty array when there are no tasks
206
+
207
+ -------------------------------------------------------
208
+ <a name="kill"></a>
209
+ ### queue.kill()
210
+
211
+ Removes all tasks waiting to be processed, and reset `drain` to an empty
212
+ function.
213
+
214
+ -------------------------------------------------------
215
+ <a name="killAndDrain"></a>
216
+ ### queue.killAndDrain()
217
+
218
+ Same than `kill` but the `drain` function will be called before reset to empty.
219
+
220
+ -------------------------------------------------------
221
+ <a name="error"></a>
222
+ ### queue.error(handler)
223
+
224
+ Set a global error handler. `handler(err, task)` will be called
225
+ each time a task is completed, `err` will be not null if the task has thrown an error.
226
+
227
+ -------------------------------------------------------
228
+ <a name="concurrency"></a>
229
+ ### queue.concurrency
230
+
231
+ Property that returns the number of concurrent tasks that could be executed in
232
+ parallel. It can be altered at runtime.
233
+
234
+ -------------------------------------------------------
235
+ <a name="paused"></a>
236
+ ### queue.paused
237
+
238
+ Property (Read-Only) that returns `true` when the queue is in a paused state.
239
+
240
+ -------------------------------------------------------
241
+ <a name="drain"></a>
242
+ ### queue.drain
243
+
244
+ Function that will be called when the last
245
+ item from the queue has been processed by a worker.
246
+ It can be altered at runtime.
247
+
248
+ -------------------------------------------------------
249
+ <a name="empty"></a>
250
+ ### queue.empty
251
+
252
+ Function that will be called when the last
253
+ item from the queue has been assigned to a worker.
254
+ It can be altered at runtime.
255
+
256
+ -------------------------------------------------------
257
+ <a name="saturated"></a>
258
+ ### queue.saturated
259
+
260
+ Function that will be called when the queue hits the concurrency
261
+ limit.
262
+ It can be altered at runtime.
263
+
264
+ -------------------------------------------------------
265
+ <a name="promise"></a>
266
+ ### fastqueue.promise([that], worker(arg), concurrency)
267
+
268
+ Creates a new queue with `Promise` apis. It also offers all the methods
269
+ and properties of the object returned by [`fastqueue`](#fastqueue) with the modified
270
+ [`push`](#pushPromise) and [`unshift`](#unshiftPromise) methods.
271
+
272
+ Node v10+ is required to use the promisified version.
273
+
274
+ Arguments:
275
+ * `that`, optional context of the `worker` function.
276
+ * `worker`, worker function, it would be called with `that` as `this`,
277
+ if that is specified. It MUST return a `Promise`.
278
+ * `concurrency`, number of concurrent tasks that could be executed in
279
+ parallel.
280
+
281
+ <a name="pushPromise"></a>
282
+ #### queue.push(task) => Promise
283
+
284
+ Add a task at the end of the queue. The returned `Promise` will be fulfilled (rejected)
285
+ when the task is completed successfully (unsuccessfully).
286
+
287
+ This promise could be ignored as it will not lead to a `'unhandledRejection'`.
288
+
289
+ <a name="unshiftPromise"></a>
290
+ #### queue.unshift(task) => Promise
291
+
292
+ Add a task at the beginning of the queue. The returned `Promise` will be fulfilled (rejected)
293
+ when the task is completed successfully (unsuccessfully).
294
+
295
+ This promise could be ignored as it will not lead to a `'unhandledRejection'`.
296
+
297
+ <a name="drained"></a>
298
+ #### queue.drained() => Promise
299
+
300
+ Wait for the queue to be drained. The returned `Promise` will be resolved when all tasks in the queue have been processed by a worker.
301
+
302
+ This promise could be ignored as it will not lead to a `'unhandledRejection'`.
303
+
304
+ ## License
305
+
306
+ ISC
307
+
308
+ [ci-url]: https://github.com/mcollina/fastq/workflows/ci/badge.svg
309
+ [npm-badge]: https://badge.fury.io/js/fastq.svg
310
+ [npm-url]: https://badge.fury.io/js/fastq
web/node_modules/fastq/SECURITY.md ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Security Policy
2
+
3
+ ## Supported Versions
4
+
5
+ Use this section to tell people about which versions of your project are
6
+ currently being supported with security updates.
7
+
8
+ | Version | Supported |
9
+ | ------- | ------------------ |
10
+ | 1.x | :white_check_mark: |
11
+ | < 1.0 | :x: |
12
+
13
+ ## Reporting a Vulnerability
14
+
15
+ Please report all vulnerabilities at [https://github.com/mcollina/fastq/security](https://github.com/mcollina/fastq/security).
web/node_modules/fastq/queue.js ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ /* eslint-disable no-var */
4
+
5
+ var reusify = require('reusify')
6
+
7
+ function fastqueue (context, worker, _concurrency) {
8
+ if (typeof context === 'function') {
9
+ _concurrency = worker
10
+ worker = context
11
+ context = null
12
+ }
13
+
14
+ if (!(_concurrency >= 1)) {
15
+ throw new Error('fastqueue concurrency must be equal to or greater than 1')
16
+ }
17
+
18
+ var cache = reusify(Task)
19
+ var queueHead = null
20
+ var queueTail = null
21
+ var _running = 0
22
+ var errorHandler = null
23
+
24
+ var self = {
25
+ push: push,
26
+ drain: noop,
27
+ saturated: noop,
28
+ pause: pause,
29
+ paused: false,
30
+
31
+ get concurrency () {
32
+ return _concurrency
33
+ },
34
+ set concurrency (value) {
35
+ if (!(value >= 1)) {
36
+ throw new Error('fastqueue concurrency must be equal to or greater than 1')
37
+ }
38
+ _concurrency = value
39
+
40
+ if (self.paused) return
41
+ for (; queueHead && _running < _concurrency;) {
42
+ _running++
43
+ release()
44
+ }
45
+ },
46
+
47
+ running: running,
48
+ resume: resume,
49
+ idle: idle,
50
+ length: length,
51
+ getQueue: getQueue,
52
+ unshift: unshift,
53
+ empty: noop,
54
+ kill: kill,
55
+ killAndDrain: killAndDrain,
56
+ error: error,
57
+ abort: abort
58
+ }
59
+
60
+ return self
61
+
62
+ function running () {
63
+ return _running
64
+ }
65
+
66
+ function pause () {
67
+ self.paused = true
68
+ }
69
+
70
+ function length () {
71
+ var current = queueHead
72
+ var counter = 0
73
+
74
+ while (current) {
75
+ current = current.next
76
+ counter++
77
+ }
78
+
79
+ return counter
80
+ }
81
+
82
+ function getQueue () {
83
+ var current = queueHead
84
+ var tasks = []
85
+
86
+ while (current) {
87
+ tasks.push(current.value)
88
+ current = current.next
89
+ }
90
+
91
+ return tasks
92
+ }
93
+
94
+ function resume () {
95
+ if (!self.paused) return
96
+ self.paused = false
97
+ if (queueHead === null) {
98
+ _running++
99
+ release()
100
+ return
101
+ }
102
+ for (; queueHead && _running < _concurrency;) {
103
+ _running++
104
+ release()
105
+ }
106
+ }
107
+
108
+ function idle () {
109
+ return _running === 0 && self.length() === 0
110
+ }
111
+
112
+ function push (value, done) {
113
+ var current = cache.get()
114
+
115
+ current.context = context
116
+ current.release = release
117
+ current.value = value
118
+ current.callback = done || noop
119
+ current.errorHandler = errorHandler
120
+
121
+ if (_running >= _concurrency || self.paused) {
122
+ if (queueTail) {
123
+ queueTail.next = current
124
+ queueTail = current
125
+ } else {
126
+ queueHead = current
127
+ queueTail = current
128
+ self.saturated()
129
+ }
130
+ } else {
131
+ _running++
132
+ worker.call(context, current.value, current.worked)
133
+ }
134
+ }
135
+
136
+ function unshift (value, done) {
137
+ var current = cache.get()
138
+
139
+ current.context = context
140
+ current.release = release
141
+ current.value = value
142
+ current.callback = done || noop
143
+ current.errorHandler = errorHandler
144
+
145
+ if (_running >= _concurrency || self.paused) {
146
+ if (queueHead) {
147
+ current.next = queueHead
148
+ queueHead = current
149
+ } else {
150
+ queueHead = current
151
+ queueTail = current
152
+ self.saturated()
153
+ }
154
+ } else {
155
+ _running++
156
+ worker.call(context, current.value, current.worked)
157
+ }
158
+ }
159
+
160
+ function release (holder) {
161
+ if (holder) {
162
+ cache.release(holder)
163
+ }
164
+ var next = queueHead
165
+ if (next && _running <= _concurrency) {
166
+ if (!self.paused) {
167
+ if (queueTail === queueHead) {
168
+ queueTail = null
169
+ }
170
+ queueHead = next.next
171
+ next.next = null
172
+ worker.call(context, next.value, next.worked)
173
+ if (queueTail === null) {
174
+ self.empty()
175
+ }
176
+ } else {
177
+ _running--
178
+ }
179
+ } else if (--_running === 0) {
180
+ self.drain()
181
+ }
182
+ }
183
+
184
+ function kill () {
185
+ queueHead = null
186
+ queueTail = null
187
+ self.drain = noop
188
+ }
189
+
190
+ function killAndDrain () {
191
+ queueHead = null
192
+ queueTail = null
193
+ self.drain()
194
+ self.drain = noop
195
+ }
196
+
197
+ function abort () {
198
+ var current = queueHead
199
+ queueHead = null
200
+ queueTail = null
201
+
202
+ while (current) {
203
+ var next = current.next
204
+ var callback = current.callback
205
+ var errorHandler = current.errorHandler
206
+ var val = current.value
207
+ var context = current.context
208
+
209
+ // Reset the task state
210
+ current.value = null
211
+ current.callback = noop
212
+ current.errorHandler = null
213
+
214
+ // Call error handler if present
215
+ if (errorHandler) {
216
+ errorHandler(new Error('abort'), val)
217
+ }
218
+
219
+ // Call callback with error
220
+ callback.call(context, new Error('abort'))
221
+
222
+ // Release the task back to the pool
223
+ current.release(current)
224
+
225
+ current = next
226
+ }
227
+
228
+ self.drain = noop
229
+ }
230
+
231
+ function error (handler) {
232
+ errorHandler = handler
233
+ }
234
+ }
235
+
236
+ function noop () {}
237
+
238
+ function Task () {
239
+ this.value = null
240
+ this.callback = noop
241
+ this.next = null
242
+ this.release = noop
243
+ this.context = null
244
+ this.errorHandler = null
245
+
246
+ var self = this
247
+
248
+ this.worked = function worked (err, result) {
249
+ var callback = self.callback
250
+ var errorHandler = self.errorHandler
251
+ var val = self.value
252
+ self.value = null
253
+ self.callback = noop
254
+ if (self.errorHandler) {
255
+ errorHandler(err, val)
256
+ }
257
+ callback.call(self.context, err, result)
258
+ self.release(self)
259
+ }
260
+ }
261
+
262
+ function queueAsPromised (context, worker, _concurrency) {
263
+ if (typeof context === 'function') {
264
+ _concurrency = worker
265
+ worker = context
266
+ context = null
267
+ }
268
+
269
+ function asyncWrapper (arg, cb) {
270
+ worker.call(this, arg)
271
+ .then(function (res) {
272
+ cb(null, res)
273
+ }, cb)
274
+ }
275
+
276
+ var queue = fastqueue(context, asyncWrapper, _concurrency)
277
+
278
+ var pushCb = queue.push
279
+ var unshiftCb = queue.unshift
280
+
281
+ queue.push = push
282
+ queue.unshift = unshift
283
+ queue.drained = drained
284
+
285
+ return queue
286
+
287
+ function push (value) {
288
+ var p = new Promise(function (resolve, reject) {
289
+ pushCb(value, function (err, result) {
290
+ if (err) {
291
+ reject(err)
292
+ return
293
+ }
294
+ resolve(result)
295
+ })
296
+ })
297
+
298
+ // Let's fork the promise chain to
299
+ // make the error bubble up to the user but
300
+ // not lead to a unhandledRejection
301
+ p.catch(noop)
302
+
303
+ return p
304
+ }
305
+
306
+ function unshift (value) {
307
+ var p = new Promise(function (resolve, reject) {
308
+ unshiftCb(value, function (err, result) {
309
+ if (err) {
310
+ reject(err)
311
+ return
312
+ }
313
+ resolve(result)
314
+ })
315
+ })
316
+
317
+ // Let's fork the promise chain to
318
+ // make the error bubble up to the user but
319
+ // not lead to a unhandledRejection
320
+ p.catch(noop)
321
+
322
+ return p
323
+ }
324
+
325
+ function drained () {
326
+ var p = new Promise(function (resolve) {
327
+ process.nextTick(function () {
328
+ if (queue.idle()) {
329
+ resolve()
330
+ } else {
331
+ var previousDrain = queue.drain
332
+ queue.drain = function () {
333
+ if (typeof previousDrain === 'function') previousDrain()
334
+ resolve()
335
+ queue.drain = previousDrain
336
+ }
337
+ }
338
+ })
339
+ })
340
+
341
+ return p
342
+ }
343
+ }
344
+
345
+ module.exports = fastqueue
346
+ module.exports.promise = queueAsPromised
web/node_modules/fastq/test/example.ts ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import * as fastq from '../'
2
+ import { promise as queueAsPromised } from '../'
3
+
4
+ // Basic example
5
+
6
+ const queue = fastq(worker, 1)
7
+
8
+ queue.push('world', (err, result) => {
9
+ if (err) throw err
10
+ console.log('the result is', result)
11
+ })
12
+
13
+ queue.push('push without cb')
14
+
15
+ queue.concurrency
16
+
17
+ queue.drain()
18
+
19
+ queue.empty = () => undefined
20
+
21
+ console.log('the queue tasks are', queue.getQueue())
22
+
23
+ queue.idle()
24
+
25
+ queue.kill()
26
+
27
+ queue.killAndDrain()
28
+
29
+ queue.length
30
+
31
+ queue.pause()
32
+
33
+ queue.resume()
34
+
35
+ queue.running()
36
+
37
+ queue.saturated = () => undefined
38
+
39
+ queue.unshift('world', (err, result) => {
40
+ if (err) throw err
41
+ console.log('the result is', result)
42
+ })
43
+
44
+ queue.unshift('unshift without cb')
45
+
46
+ function worker(task: any, cb: fastq.done) {
47
+ cb(null, 'hello ' + task)
48
+ }
49
+
50
+ // Generics example
51
+
52
+ interface GenericsContext {
53
+ base: number;
54
+ }
55
+
56
+ const genericsQueue = fastq<GenericsContext, number, string>({ base: 6 }, genericsWorker, 1)
57
+
58
+ genericsQueue.push(7, (err, done) => {
59
+ if (err) throw err
60
+ console.log('the result is', done)
61
+ })
62
+
63
+ genericsQueue.unshift(7, (err, done) => {
64
+ if (err) throw err
65
+ console.log('the result is', done)
66
+ })
67
+
68
+ function genericsWorker(this: GenericsContext, task: number, cb: fastq.done<string>) {
69
+ cb(null, 'the meaning of life is ' + (this.base * task))
70
+ }
71
+
72
+ const queue2 = queueAsPromised(asyncWorker, 1)
73
+
74
+ async function asyncWorker(task: any) {
75
+ return 'hello ' + task
76
+ }
77
+
78
+ async function run () {
79
+ await queue.push(42)
80
+ await queue.unshift(42)
81
+ }
82
+
83
+ run()
web/node_modules/fastq/test/promise.js ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ const test = require('tape')
4
+ const buildQueue = require('../').promise
5
+ const { promisify } = require('util')
6
+ const sleep = promisify(setTimeout)
7
+ const immediate = promisify(setImmediate)
8
+
9
+ test('concurrency', function (t) {
10
+ t.plan(2)
11
+ t.throws(buildQueue.bind(null, worker, 0))
12
+ t.doesNotThrow(buildQueue.bind(null, worker, 1))
13
+
14
+ async function worker (arg) {
15
+ return true
16
+ }
17
+ })
18
+
19
+ test('worker execution', async function (t) {
20
+ const queue = buildQueue(worker, 1)
21
+
22
+ const result = await queue.push(42)
23
+
24
+ t.equal(result, true, 'result matches')
25
+
26
+ async function worker (arg) {
27
+ t.equal(arg, 42)
28
+ return true
29
+ }
30
+ })
31
+
32
+ test('limit', async function (t) {
33
+ const queue = buildQueue(worker, 1)
34
+
35
+ const [res1, res2] = await Promise.all([queue.push(10), queue.push(0)])
36
+ t.equal(res1, 10, 'the result matches')
37
+ t.equal(res2, 0, 'the result matches')
38
+
39
+ async function worker (arg) {
40
+ await sleep(arg)
41
+ return arg
42
+ }
43
+ })
44
+
45
+ test('multiple executions', async function (t) {
46
+ const queue = buildQueue(worker, 1)
47
+ const toExec = [1, 2, 3, 4, 5]
48
+ const expected = ['a', 'b', 'c', 'd', 'e']
49
+ let count = 0
50
+
51
+ await Promise.all(toExec.map(async function (task, i) {
52
+ const result = await queue.push(task)
53
+ t.equal(result, expected[i], 'the result matches')
54
+ }))
55
+
56
+ async function worker (arg) {
57
+ t.equal(arg, toExec[count], 'arg matches')
58
+ return expected[count++]
59
+ }
60
+ })
61
+
62
+ test('drained', async function (t) {
63
+ const queue = buildQueue(worker, 2)
64
+
65
+ const toExec = new Array(10).fill(10)
66
+ let count = 0
67
+
68
+ async function worker (arg) {
69
+ await sleep(arg)
70
+ count++
71
+ }
72
+
73
+ toExec.forEach(function (i) {
74
+ queue.push(i)
75
+ })
76
+
77
+ await queue.drained()
78
+
79
+ t.equal(count, toExec.length)
80
+
81
+ toExec.forEach(function (i) {
82
+ queue.push(i)
83
+ })
84
+
85
+ await queue.drained()
86
+
87
+ t.equal(count, toExec.length * 2)
88
+ })
89
+
90
+ test('drained with exception should not throw', async function (t) {
91
+ const queue = buildQueue(worker, 2)
92
+
93
+ const toExec = new Array(10).fill(10)
94
+
95
+ async function worker () {
96
+ throw new Error('foo')
97
+ }
98
+
99
+ toExec.forEach(function (i) {
100
+ queue.push(i)
101
+ })
102
+
103
+ await queue.drained()
104
+ })
105
+
106
+ test('drained with drain function', async function (t) {
107
+ let drainCalled = false
108
+ const queue = buildQueue(worker, 2)
109
+
110
+ queue.drain = function () {
111
+ drainCalled = true
112
+ }
113
+
114
+ const toExec = new Array(10).fill(10)
115
+ let count = 0
116
+
117
+ async function worker (arg) {
118
+ await sleep(arg)
119
+ count++
120
+ }
121
+
122
+ toExec.forEach(function () {
123
+ queue.push()
124
+ })
125
+
126
+ await queue.drained()
127
+
128
+ t.equal(count, toExec.length)
129
+ t.equal(drainCalled, true)
130
+ })
131
+
132
+ test('drained while idle should resolve', async function (t) {
133
+ const queue = buildQueue(worker, 2)
134
+
135
+ async function worker (arg) {
136
+ await sleep(arg)
137
+ }
138
+
139
+ await queue.drained()
140
+ })
141
+
142
+ test('drained while idle should not call the drain function', async function (t) {
143
+ let drainCalled = false
144
+ const queue = buildQueue(worker, 2)
145
+
146
+ queue.drain = function () {
147
+ drainCalled = true
148
+ }
149
+
150
+ async function worker (arg) {
151
+ await sleep(arg)
152
+ }
153
+
154
+ await queue.drained()
155
+
156
+ t.equal(drainCalled, false)
157
+ })
158
+
159
+ test('set this', async function (t) {
160
+ t.plan(1)
161
+ const that = {}
162
+ const queue = buildQueue(that, worker, 1)
163
+
164
+ await queue.push(42)
165
+
166
+ async function worker (arg) {
167
+ t.equal(this, that, 'this matches')
168
+ }
169
+ })
170
+
171
+ test('unshift', async function (t) {
172
+ const queue = buildQueue(worker, 1)
173
+ const expected = [1, 2, 3, 4]
174
+
175
+ await Promise.all([
176
+ queue.push(1),
177
+ queue.push(4),
178
+ queue.unshift(3),
179
+ queue.unshift(2)
180
+ ])
181
+
182
+ t.is(expected.length, 0)
183
+
184
+ async function worker (arg) {
185
+ t.equal(expected.shift(), arg, 'tasks come in order')
186
+ }
187
+ })
188
+
189
+ test('push with worker throwing error', async function (t) {
190
+ t.plan(5)
191
+ const q = buildQueue(async function (task, cb) {
192
+ throw new Error('test error')
193
+ }, 1)
194
+ q.error(function (err, task) {
195
+ t.ok(err instanceof Error, 'global error handler should catch the error')
196
+ t.match(err.message, /test error/, 'error message should be "test error"')
197
+ t.equal(task, 42, 'The task executed should be passed')
198
+ })
199
+ try {
200
+ await q.push(42)
201
+ } catch (err) {
202
+ t.ok(err instanceof Error, 'push callback should catch the error')
203
+ t.match(err.message, /test error/, 'error message should be "test error"')
204
+ }
205
+ })
206
+
207
+ test('unshift with worker throwing error', async function (t) {
208
+ t.plan(2)
209
+ const q = buildQueue(async function (task, cb) {
210
+ throw new Error('test error')
211
+ }, 1)
212
+ try {
213
+ await q.unshift(42)
214
+ } catch (err) {
215
+ t.ok(err instanceof Error, 'push callback should catch the error')
216
+ t.match(err.message, /test error/, 'error message should be "test error"')
217
+ }
218
+ })
219
+
220
+ test('no unhandledRejection (push)', async function (t) {
221
+ function handleRejection () {
222
+ t.fail('unhandledRejection')
223
+ }
224
+ process.once('unhandledRejection', handleRejection)
225
+ const q = buildQueue(async function (task, cb) {
226
+ throw new Error('test error')
227
+ }, 1)
228
+
229
+ q.push(42)
230
+
231
+ await immediate()
232
+ process.removeListener('unhandledRejection', handleRejection)
233
+ })
234
+
235
+ test('no unhandledRejection (unshift)', async function (t) {
236
+ function handleRejection () {
237
+ t.fail('unhandledRejection')
238
+ }
239
+ process.once('unhandledRejection', handleRejection)
240
+ const q = buildQueue(async function (task, cb) {
241
+ throw new Error('test error')
242
+ }, 1)
243
+
244
+ q.unshift(42)
245
+
246
+ await immediate()
247
+ process.removeListener('unhandledRejection', handleRejection)
248
+ })
249
+
250
+ test('drained should resolve after async tasks complete', async function (t) {
251
+ const logs = []
252
+
253
+ async function processTask () {
254
+ await new Promise(resolve => setTimeout(resolve, 0))
255
+ logs.push('processed')
256
+ }
257
+
258
+ const queue = buildQueue(processTask, 1)
259
+ queue.drain = () => logs.push('called drain')
260
+
261
+ queue.drained().then(() => logs.push('drained promise resolved'))
262
+
263
+ await Promise.all([
264
+ queue.push(),
265
+ queue.push(),
266
+ queue.push()
267
+ ])
268
+
269
+ t.deepEqual(logs, [
270
+ 'processed',
271
+ 'processed',
272
+ 'processed',
273
+ 'called drain',
274
+ 'drained promise resolved'
275
+ ], 'events happened in correct order')
276
+ })
277
+
278
+ test('drained should handle undefined drain function', async function (t) {
279
+ const queue = buildQueue(worker, 1)
280
+
281
+ async function worker (arg) {
282
+ await sleep(10)
283
+ return arg
284
+ }
285
+
286
+ queue.drain = undefined
287
+ queue.push(1)
288
+ await queue.drained()
289
+
290
+ t.pass('drained resolved successfully with undefined drain')
291
+ })
292
+
293
+ test('abort rejects all pending promises', async function (t) {
294
+ const queue = buildQueue(worker, 1)
295
+ const promises = []
296
+ let rejectedCount = 0
297
+
298
+ // Pause queue to prevent tasks from starting
299
+ queue.pause()
300
+
301
+ for (let i = 0; i < 10; i++) {
302
+ promises.push(queue.push(i))
303
+ }
304
+
305
+ queue.abort()
306
+
307
+ // All promises should be rejected
308
+ for (const promise of promises) {
309
+ try {
310
+ await promise
311
+ t.fail('promise should have been rejected')
312
+ } catch (err) {
313
+ t.equal(err.message, 'abort', 'error message is abort')
314
+ rejectedCount++
315
+ }
316
+ }
317
+
318
+ t.equal(rejectedCount, 10, 'all promises were rejected')
319
+ t.equal(queue.length(), 0, 'queue is empty')
320
+
321
+ async function worker (arg) {
322
+ await sleep(500)
323
+ return arg
324
+ }
325
+ })
web/node_modules/fastq/test/test.js ADDED
@@ -0,0 +1,733 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict'
2
+
3
+ /* eslint-disable no-var */
4
+
5
+ var test = require('tape')
6
+ var buildQueue = require('../')
7
+
8
+ test('concurrency', function (t) {
9
+ t.plan(6)
10
+ t.throws(buildQueue.bind(null, worker, 0))
11
+ t.throws(buildQueue.bind(null, worker, NaN))
12
+ t.doesNotThrow(buildQueue.bind(null, worker, 1))
13
+
14
+ var queue = buildQueue(worker, 1)
15
+ t.throws(function () {
16
+ queue.concurrency = 0
17
+ })
18
+ t.throws(function () {
19
+ queue.concurrency = NaN
20
+ })
21
+ t.doesNotThrow(function () {
22
+ queue.concurrency = 2
23
+ })
24
+
25
+ function worker (arg, cb) {
26
+ cb(null, true)
27
+ }
28
+ })
29
+
30
+ test('worker execution', function (t) {
31
+ t.plan(3)
32
+
33
+ var queue = buildQueue(worker, 1)
34
+
35
+ queue.push(42, function (err, result) {
36
+ t.error(err, 'no error')
37
+ t.equal(result, true, 'result matches')
38
+ })
39
+
40
+ function worker (arg, cb) {
41
+ t.equal(arg, 42)
42
+ cb(null, true)
43
+ }
44
+ })
45
+
46
+ test('limit', function (t) {
47
+ t.plan(4)
48
+
49
+ var expected = [10, 0]
50
+ var queue = buildQueue(worker, 1)
51
+
52
+ queue.push(10, result)
53
+ queue.push(0, result)
54
+
55
+ function result (err, arg) {
56
+ t.error(err, 'no error')
57
+ t.equal(arg, expected.shift(), 'the result matches')
58
+ }
59
+
60
+ function worker (arg, cb) {
61
+ setTimeout(cb, arg, null, arg)
62
+ }
63
+ })
64
+
65
+ test('multiple executions', function (t) {
66
+ t.plan(15)
67
+
68
+ var queue = buildQueue(worker, 1)
69
+ var toExec = [1, 2, 3, 4, 5]
70
+ var count = 0
71
+
72
+ toExec.forEach(function (task) {
73
+ queue.push(task, done)
74
+ })
75
+
76
+ function done (err, result) {
77
+ t.error(err, 'no error')
78
+ t.equal(result, toExec[count - 1], 'the result matches')
79
+ }
80
+
81
+ function worker (arg, cb) {
82
+ t.equal(arg, toExec[count], 'arg matches')
83
+ count++
84
+ setImmediate(cb, null, arg)
85
+ }
86
+ })
87
+
88
+ test('multiple executions, one after another', function (t) {
89
+ t.plan(15)
90
+
91
+ var queue = buildQueue(worker, 1)
92
+ var toExec = [1, 2, 3, 4, 5]
93
+ var count = 0
94
+
95
+ queue.push(toExec[0], done)
96
+
97
+ function done (err, result) {
98
+ t.error(err, 'no error')
99
+ t.equal(result, toExec[count - 1], 'the result matches')
100
+ if (count < toExec.length) {
101
+ queue.push(toExec[count], done)
102
+ }
103
+ }
104
+
105
+ function worker (arg, cb) {
106
+ t.equal(arg, toExec[count], 'arg matches')
107
+ count++
108
+ setImmediate(cb, null, arg)
109
+ }
110
+ })
111
+
112
+ test('set this', function (t) {
113
+ t.plan(3)
114
+
115
+ var that = {}
116
+ var queue = buildQueue(that, worker, 1)
117
+
118
+ queue.push(42, function (err, result) {
119
+ t.error(err, 'no error')
120
+ t.equal(this, that, 'this matches')
121
+ })
122
+
123
+ function worker (arg, cb) {
124
+ t.equal(this, that, 'this matches')
125
+ cb(null, true)
126
+ }
127
+ })
128
+
129
+ test('drain', function (t) {
130
+ t.plan(4)
131
+
132
+ var queue = buildQueue(worker, 1)
133
+ var worked = false
134
+
135
+ queue.push(42, function (err, result) {
136
+ t.error(err, 'no error')
137
+ t.equal(result, true, 'result matches')
138
+ })
139
+
140
+ queue.drain = function () {
141
+ t.equal(true, worked, 'drained')
142
+ }
143
+
144
+ function worker (arg, cb) {
145
+ t.equal(arg, 42)
146
+ worked = true
147
+ setImmediate(cb, null, true)
148
+ }
149
+ })
150
+
151
+ test('pause && resume', function (t) {
152
+ t.plan(13)
153
+
154
+ var queue = buildQueue(worker, 1)
155
+ var worked = false
156
+ var expected = [42, 24]
157
+
158
+ t.notOk(queue.paused, 'it should not be paused')
159
+
160
+ queue.pause()
161
+
162
+ queue.push(42, function (err, result) {
163
+ t.error(err, 'no error')
164
+ t.equal(result, true, 'result matches')
165
+ })
166
+
167
+ queue.push(24, function (err, result) {
168
+ t.error(err, 'no error')
169
+ t.equal(result, true, 'result matches')
170
+ })
171
+
172
+ t.notOk(worked, 'it should be paused')
173
+ t.ok(queue.paused, 'it should be paused')
174
+
175
+ queue.resume()
176
+ queue.pause()
177
+ queue.resume()
178
+ queue.resume() // second resume is a no-op
179
+
180
+ function worker (arg, cb) {
181
+ t.notOk(queue.paused, 'it should not be paused')
182
+ t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
183
+ t.equal(arg, expected.shift())
184
+ worked = true
185
+ process.nextTick(function () { cb(null, true) })
186
+ }
187
+ })
188
+
189
+ test('pause in flight && resume', function (t) {
190
+ t.plan(16)
191
+
192
+ var queue = buildQueue(worker, 1)
193
+ var expected = [42, 24, 12]
194
+
195
+ t.notOk(queue.paused, 'it should not be paused')
196
+
197
+ queue.push(42, function (err, result) {
198
+ t.error(err, 'no error')
199
+ t.equal(result, true, 'result matches')
200
+ t.ok(queue.paused, 'it should be paused')
201
+ process.nextTick(function () {
202
+ queue.resume()
203
+ queue.pause()
204
+ queue.resume()
205
+ })
206
+ })
207
+
208
+ queue.push(24, function (err, result) {
209
+ t.error(err, 'no error')
210
+ t.equal(result, true, 'result matches')
211
+ t.notOk(queue.paused, 'it should not be paused')
212
+ })
213
+
214
+ queue.push(12, function (err, result) {
215
+ t.error(err, 'no error')
216
+ t.equal(result, true, 'result matches')
217
+ t.notOk(queue.paused, 'it should not be paused')
218
+ })
219
+
220
+ queue.pause()
221
+
222
+ function worker (arg, cb) {
223
+ t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
224
+ t.equal(arg, expected.shift())
225
+ process.nextTick(function () { cb(null, true) })
226
+ }
227
+ })
228
+
229
+ test('altering concurrency', function (t) {
230
+ t.plan(24)
231
+
232
+ var queue = buildQueue(worker, 1)
233
+
234
+ queue.push(24, workDone)
235
+ queue.push(24, workDone)
236
+ queue.push(24, workDone)
237
+
238
+ queue.pause()
239
+
240
+ queue.concurrency = 3 // concurrency changes are ignored while paused
241
+ queue.concurrency = 2
242
+
243
+ queue.resume()
244
+
245
+ t.equal(queue.running(), 2, '2 jobs running')
246
+
247
+ queue.concurrency = 3
248
+
249
+ t.equal(queue.running(), 3, '3 jobs running')
250
+
251
+ queue.concurrency = 1
252
+
253
+ t.equal(queue.running(), 3, '3 jobs running') // running jobs can't be killed
254
+
255
+ queue.push(24, workDone)
256
+ queue.push(24, workDone)
257
+ queue.push(24, workDone)
258
+ queue.push(24, workDone)
259
+
260
+ function workDone (err, result) {
261
+ t.error(err, 'no error')
262
+ t.equal(result, true, 'result matches')
263
+ }
264
+
265
+ function worker (arg, cb) {
266
+ t.ok(queue.running() <= queue.concurrency, 'should respect the concurrency')
267
+ setImmediate(function () {
268
+ cb(null, true)
269
+ })
270
+ }
271
+ })
272
+
273
+ test('idle()', function (t) {
274
+ t.plan(12)
275
+
276
+ var queue = buildQueue(worker, 1)
277
+
278
+ t.ok(queue.idle(), 'queue is idle')
279
+
280
+ queue.push(42, function (err, result) {
281
+ t.error(err, 'no error')
282
+ t.equal(result, true, 'result matches')
283
+ t.notOk(queue.idle(), 'queue is not idle')
284
+ })
285
+
286
+ queue.push(42, function (err, result) {
287
+ t.error(err, 'no error')
288
+ t.equal(result, true, 'result matches')
289
+ // it will go idle after executing this function
290
+ setImmediate(function () {
291
+ t.ok(queue.idle(), 'queue is now idle')
292
+ })
293
+ })
294
+
295
+ t.notOk(queue.idle(), 'queue is not idle')
296
+
297
+ function worker (arg, cb) {
298
+ t.notOk(queue.idle(), 'queue is not idle')
299
+ t.equal(arg, 42)
300
+ setImmediate(cb, null, true)
301
+ }
302
+ })
303
+
304
+ test('saturated', function (t) {
305
+ t.plan(9)
306
+
307
+ var queue = buildQueue(worker, 1)
308
+ var preworked = 0
309
+ var worked = 0
310
+
311
+ queue.saturated = function () {
312
+ t.pass('saturated')
313
+ t.equal(preworked, 1, 'started 1 task')
314
+ t.equal(worked, 0, 'worked zero task')
315
+ }
316
+
317
+ queue.push(42, done)
318
+ queue.push(42, done)
319
+
320
+ function done (err, result) {
321
+ t.error(err, 'no error')
322
+ t.equal(result, true, 'result matches')
323
+ }
324
+
325
+ function worker (arg, cb) {
326
+ t.equal(arg, 42)
327
+ preworked++
328
+ setImmediate(function () {
329
+ worked++
330
+ cb(null, true)
331
+ })
332
+ }
333
+ })
334
+
335
+ test('length', function (t) {
336
+ t.plan(7)
337
+
338
+ var queue = buildQueue(worker, 1)
339
+
340
+ t.equal(queue.length(), 0, 'nothing waiting')
341
+ queue.push(42, done)
342
+ t.equal(queue.length(), 0, 'nothing waiting')
343
+ queue.push(42, done)
344
+ t.equal(queue.length(), 1, 'one task waiting')
345
+ queue.push(42, done)
346
+ t.equal(queue.length(), 2, 'two tasks waiting')
347
+
348
+ function done (err, result) {
349
+ t.error(err, 'no error')
350
+ }
351
+
352
+ function worker (arg, cb) {
353
+ setImmediate(function () {
354
+ cb(null, true)
355
+ })
356
+ }
357
+ })
358
+
359
+ test('getQueue', function (t) {
360
+ t.plan(10)
361
+
362
+ var queue = buildQueue(worker, 1)
363
+
364
+ t.equal(queue.getQueue().length, 0, 'nothing waiting')
365
+ queue.push(42, done)
366
+ t.equal(queue.getQueue().length, 0, 'nothing waiting')
367
+ queue.push(42, done)
368
+ t.equal(queue.getQueue().length, 1, 'one task waiting')
369
+ t.equal(queue.getQueue()[0], 42, 'should be equal')
370
+ queue.push(43, done)
371
+ t.equal(queue.getQueue().length, 2, 'two tasks waiting')
372
+ t.equal(queue.getQueue()[0], 42, 'should be equal')
373
+ t.equal(queue.getQueue()[1], 43, 'should be equal')
374
+
375
+ function done (err, result) {
376
+ t.error(err, 'no error')
377
+ }
378
+
379
+ function worker (arg, cb) {
380
+ setImmediate(function () {
381
+ cb(null, true)
382
+ })
383
+ }
384
+ })
385
+
386
+ test('unshift', function (t) {
387
+ t.plan(8)
388
+
389
+ var queue = buildQueue(worker, 1)
390
+ var expected = [1, 2, 3, 4]
391
+
392
+ queue.push(1, done)
393
+ queue.push(4, done)
394
+ queue.unshift(3, done)
395
+ queue.unshift(2, done)
396
+
397
+ function done (err, result) {
398
+ t.error(err, 'no error')
399
+ }
400
+
401
+ function worker (arg, cb) {
402
+ t.equal(expected.shift(), arg, 'tasks come in order')
403
+ setImmediate(function () {
404
+ cb(null, true)
405
+ })
406
+ }
407
+ })
408
+
409
+ test('unshift && empty', function (t) {
410
+ t.plan(2)
411
+
412
+ var queue = buildQueue(worker, 1)
413
+ var completed = false
414
+
415
+ queue.pause()
416
+
417
+ queue.empty = function () {
418
+ t.notOk(completed, 'the task has not completed yet')
419
+ }
420
+
421
+ queue.unshift(1, done)
422
+
423
+ queue.resume()
424
+
425
+ function done (err, result) {
426
+ completed = true
427
+ t.error(err, 'no error')
428
+ }
429
+
430
+ function worker (arg, cb) {
431
+ setImmediate(function () {
432
+ cb(null, true)
433
+ })
434
+ }
435
+ })
436
+
437
+ test('push && empty', function (t) {
438
+ t.plan(2)
439
+
440
+ var queue = buildQueue(worker, 1)
441
+ var completed = false
442
+
443
+ queue.pause()
444
+
445
+ queue.empty = function () {
446
+ t.notOk(completed, 'the task has not completed yet')
447
+ }
448
+
449
+ queue.push(1, done)
450
+
451
+ queue.resume()
452
+
453
+ function done (err, result) {
454
+ completed = true
455
+ t.error(err, 'no error')
456
+ }
457
+
458
+ function worker (arg, cb) {
459
+ setImmediate(function () {
460
+ cb(null, true)
461
+ })
462
+ }
463
+ })
464
+
465
+ test('kill', function (t) {
466
+ t.plan(5)
467
+
468
+ var queue = buildQueue(worker, 1)
469
+ var expected = [1]
470
+
471
+ var predrain = queue.drain
472
+
473
+ queue.drain = function drain () {
474
+ t.fail('drain should never be called')
475
+ }
476
+
477
+ queue.push(1, done)
478
+ queue.push(4, done)
479
+ queue.unshift(3, done)
480
+ queue.unshift(2, done)
481
+ queue.kill()
482
+
483
+ function done (err, result) {
484
+ t.error(err, 'no error')
485
+ setImmediate(function () {
486
+ t.equal(queue.length(), 0, 'no queued tasks')
487
+ t.equal(queue.running(), 0, 'no running tasks')
488
+ t.equal(queue.drain, predrain, 'drain is back to default')
489
+ })
490
+ }
491
+
492
+ function worker (arg, cb) {
493
+ t.equal(expected.shift(), arg, 'tasks come in order')
494
+ setImmediate(function () {
495
+ cb(null, true)
496
+ })
497
+ }
498
+ })
499
+
500
+ test('killAndDrain', function (t) {
501
+ t.plan(6)
502
+
503
+ var queue = buildQueue(worker, 1)
504
+ var expected = [1]
505
+
506
+ var predrain = queue.drain
507
+
508
+ queue.drain = function drain () {
509
+ t.pass('drain has been called')
510
+ }
511
+
512
+ queue.push(1, done)
513
+ queue.push(4, done)
514
+ queue.unshift(3, done)
515
+ queue.unshift(2, done)
516
+ queue.killAndDrain()
517
+
518
+ function done (err, result) {
519
+ t.error(err, 'no error')
520
+ setImmediate(function () {
521
+ t.equal(queue.length(), 0, 'no queued tasks')
522
+ t.equal(queue.running(), 0, 'no running tasks')
523
+ t.equal(queue.drain, predrain, 'drain is back to default')
524
+ })
525
+ }
526
+
527
+ function worker (arg, cb) {
528
+ t.equal(expected.shift(), arg, 'tasks come in order')
529
+ setImmediate(function () {
530
+ cb(null, true)
531
+ })
532
+ }
533
+ })
534
+
535
+ test('pause && idle', function (t) {
536
+ t.plan(11)
537
+
538
+ var queue = buildQueue(worker, 1)
539
+ var worked = false
540
+
541
+ t.notOk(queue.paused, 'it should not be paused')
542
+ t.ok(queue.idle(), 'should be idle')
543
+
544
+ queue.pause()
545
+
546
+ queue.push(42, function (err, result) {
547
+ t.error(err, 'no error')
548
+ t.equal(result, true, 'result matches')
549
+ })
550
+
551
+ t.notOk(worked, 'it should be paused')
552
+ t.ok(queue.paused, 'it should be paused')
553
+ t.notOk(queue.idle(), 'should not be idle')
554
+
555
+ queue.resume()
556
+
557
+ t.notOk(queue.paused, 'it should not be paused')
558
+ t.notOk(queue.idle(), 'it should not be idle')
559
+
560
+ function worker (arg, cb) {
561
+ t.equal(arg, 42)
562
+ worked = true
563
+ process.nextTick(cb.bind(null, null, true))
564
+ process.nextTick(function () {
565
+ t.ok(queue.idle(), 'is should be idle')
566
+ })
567
+ }
568
+ })
569
+
570
+ test('push without cb', function (t) {
571
+ t.plan(1)
572
+
573
+ var queue = buildQueue(worker, 1)
574
+
575
+ queue.push(42)
576
+
577
+ function worker (arg, cb) {
578
+ t.equal(arg, 42)
579
+ cb()
580
+ }
581
+ })
582
+
583
+ test('unshift without cb', function (t) {
584
+ t.plan(1)
585
+
586
+ var queue = buildQueue(worker, 1)
587
+
588
+ queue.unshift(42)
589
+
590
+ function worker (arg, cb) {
591
+ t.equal(arg, 42)
592
+ cb()
593
+ }
594
+ })
595
+
596
+ test('push with worker throwing error', function (t) {
597
+ t.plan(5)
598
+ var q = buildQueue(function (task, cb) {
599
+ cb(new Error('test error'), null)
600
+ }, 1)
601
+ q.error(function (err, task) {
602
+ t.ok(err instanceof Error, 'global error handler should catch the error')
603
+ t.match(err.message, /test error/, 'error message should be "test error"')
604
+ t.equal(task, 42, 'The task executed should be passed')
605
+ })
606
+ q.push(42, function (err) {
607
+ t.ok(err instanceof Error, 'push callback should catch the error')
608
+ t.match(err.message, /test error/, 'error message should be "test error"')
609
+ })
610
+ })
611
+
612
+ test('unshift with worker throwing error', function (t) {
613
+ t.plan(5)
614
+ var q = buildQueue(function (task, cb) {
615
+ cb(new Error('test error'), null)
616
+ }, 1)
617
+ q.error(function (err, task) {
618
+ t.ok(err instanceof Error, 'global error handler should catch the error')
619
+ t.match(err.message, /test error/, 'error message should be "test error"')
620
+ t.equal(task, 42, 'The task executed should be passed')
621
+ })
622
+ q.unshift(42, function (err) {
623
+ t.ok(err instanceof Error, 'unshift callback should catch the error')
624
+ t.match(err.message, /test error/, 'error message should be "test error"')
625
+ })
626
+ })
627
+
628
+ test('pause/resume should trigger drain event', function (t) {
629
+ t.plan(1)
630
+
631
+ var queue = buildQueue(worker, 1)
632
+ queue.pause()
633
+ queue.drain = function () {
634
+ t.pass('drain should be called')
635
+ }
636
+
637
+ function worker (arg, cb) {
638
+ cb(null, true)
639
+ }
640
+
641
+ queue.resume()
642
+ })
643
+
644
+ test('paused flag', function (t) {
645
+ t.plan(2)
646
+
647
+ var queue = buildQueue(function (arg, cb) {
648
+ cb(null)
649
+ }, 1)
650
+ t.equal(queue.paused, false)
651
+ queue.pause()
652
+ t.equal(queue.paused, true)
653
+ })
654
+
655
+ test('abort', function (t) {
656
+ t.plan(11)
657
+
658
+ var queue = buildQueue(worker, 1)
659
+ var abortedTasks = 0
660
+
661
+ var predrain = queue.drain
662
+
663
+ queue.drain = function drain () {
664
+ t.fail('drain should never be called')
665
+ }
666
+
667
+ // Pause queue to prevent tasks from starting
668
+ queue.pause()
669
+ queue.push(1, doneAborted)
670
+ queue.push(4, doneAborted)
671
+ queue.unshift(3, doneAborted)
672
+ queue.unshift(2, doneAborted)
673
+
674
+ // Abort all queued tasks
675
+ queue.abort()
676
+
677
+ // Verify state after abort
678
+ t.equal(queue.length(), 0, 'no queued tasks after abort')
679
+ t.equal(queue.drain, predrain, 'drain is back to default')
680
+
681
+ setImmediate(function () {
682
+ t.equal(abortedTasks, 4, 'all queued tasks were aborted')
683
+ })
684
+
685
+ function doneAborted (err) {
686
+ t.ok(err, 'error is present')
687
+ t.equal(err.message, 'abort', 'error message is abort')
688
+ abortedTasks++
689
+ }
690
+
691
+ function worker (arg, cb) {
692
+ t.fail('worker should not be called')
693
+ setImmediate(function () {
694
+ cb(null, true)
695
+ })
696
+ }
697
+ })
698
+
699
+ test('abort with error handler', function (t) {
700
+ t.plan(7)
701
+
702
+ var queue = buildQueue(worker, 1)
703
+ var errorHandlerCalled = 0
704
+
705
+ queue.error(function (err, task) {
706
+ t.equal(err.message, 'abort', 'error handler receives abort error')
707
+ t.ok(task !== null, 'error handler receives task value')
708
+ errorHandlerCalled++
709
+ })
710
+
711
+ // Pause queue to prevent tasks from starting
712
+ queue.pause()
713
+ queue.push(1, doneAborted)
714
+ queue.push(2, doneAborted)
715
+
716
+ // Abort all queued tasks
717
+ queue.abort()
718
+
719
+ setImmediate(function () {
720
+ t.equal(errorHandlerCalled, 2, 'error handler called for all aborted tasks')
721
+ })
722
+
723
+ function doneAborted (err) {
724
+ t.ok(err, 'callback receives error')
725
+ }
726
+
727
+ function worker (arg, cb) {
728
+ t.fail('worker should not be called')
729
+ setImmediate(function () {
730
+ cb(null, true)
731
+ })
732
+ }
733
+ })
web/node_modules/fastq/test/tsconfig.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6",
4
+ "module": "commonjs",
5
+ "noEmit": true,
6
+ "strict": true
7
+ },
8
+ "files": [
9
+ "./example.ts"
10
+ ]
11
+ }
web/node_modules/fdir/LICENSE ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ Copyright 2023 Abdullah Atta
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
web/node_modules/fdir/README.md ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <img src="https://github.com/thecodrr/fdir/raw/master/assets/fdir.gif" width="75%"/>
3
+
4
+ <h1 align="center">The Fastest Directory Crawler & Globber for NodeJS</h1>
5
+ <p align="center">
6
+ <a href="https://www.npmjs.com/package/fdir"><img src="https://img.shields.io/npm/v/fdir?style=for-the-badge"/></a>
7
+ <a href="https://www.npmjs.com/package/fdir"><img src="https://img.shields.io/npm/dw/fdir?style=for-the-badge"/></a>
8
+ <a href="https://codeclimate.com/github/thecodrr/fdir/maintainability"><img src="https://img.shields.io/codeclimate/maintainability-percentage/thecodrr/fdir?style=for-the-badge"/></a>
9
+ <a href="https://coveralls.io/github/thecodrr/fdir?branch=master"><img src="https://img.shields.io/coveralls/github/thecodrr/fdir?style=for-the-badge"/></a>
10
+ <a href="https://www.npmjs.com/package/fdir"><img src="https://img.shields.io/bundlephobia/minzip/fdir?style=for-the-badge"/></a>
11
+ <a href="https://www.producthunt.com/posts/fdir-every-millisecond-matters"><img src="https://img.shields.io/badge/ProductHunt-Upvote-red?style=for-the-badge&logo=product-hunt"/></a>
12
+ <a href="https://dev.to/thecodrr/how-i-wrote-the-fastest-directory-crawler-ever-3p9c"><img src="https://img.shields.io/badge/dev.to-Read%20Blog-black?style=for-the-badge&logo=dev.to"/></a>
13
+ <a href="./LICENSE"><img src="https://img.shields.io/github/license/thecodrr/fdir?style=for-the-badge"/></a>
14
+ </p>
15
+ </p>
16
+
17
+ ⚡ **The Fastest:** Nothing similar (in the NodeJS world) beats `fdir` in speed. It can easily crawl a directory containing **1 million files in < 1 second.**
18
+
19
+ 💡 **Stupidly Easy:** `fdir` uses expressive Builder pattern to build the crawler increasing code readability.
20
+
21
+ 🤖 **Zero Dependencies\*:** `fdir` only uses NodeJS `fs` & `path` modules.
22
+
23
+ 🕺 **Astonishingly Small:** < 2KB in size gzipped & minified.
24
+
25
+ 🖮 **Hackable:** Extending `fdir` is extremely simple now that the new Builder API is here. Feel free to experiment around.
26
+
27
+ _\* `picomatch` must be installed manually by the user to support globbing._
28
+
29
+ ## 🚄 Quickstart
30
+
31
+ ### Installation
32
+
33
+ You can install using `npm`:
34
+
35
+ ```sh
36
+ $ npm i fdir
37
+ ```
38
+
39
+ or Yarn:
40
+
41
+ ```sh
42
+ $ yarn add fdir
43
+ ```
44
+
45
+ ### Usage
46
+
47
+ ```ts
48
+ import { fdir } from "fdir";
49
+
50
+ // create the builder
51
+ const api = new fdir().withFullPaths().crawl("path/to/dir");
52
+
53
+ // get all files in a directory synchronously
54
+ const files = api.sync();
55
+
56
+ // or asynchronously
57
+ api.withPromise().then((files) => {
58
+ // do something with the result here.
59
+ });
60
+ ```
61
+
62
+ ## Documentation:
63
+
64
+ Documentation for all methods is available [here](/documentation.md).
65
+
66
+ ## 📊 Benchmarks:
67
+
68
+ Please check the benchmark against the latest version [here](/BENCHMARKS.md).
69
+
70
+ ## 🙏Used by:
71
+
72
+ `fdir` is downloaded over 200k+ times a week by projects around the world. Here's a list of some notable projects using `fdir` in production:
73
+
74
+ > Note: if you think your project should be here, feel free to open an issue. Notable is anything with a considerable amount of GitHub stars.
75
+
76
+ 1. [rollup/plugins](https://github.com/rollup/plugins)
77
+ 2. [SuperchupuDev/tinyglobby](https://github.com/SuperchupuDev/tinyglobby)
78
+ 3. [pulumi/pulumi](https://github.com/pulumi/pulumi)
79
+ 4. [dotenvx/dotenvx](https://github.com/dotenvx/dotenvx)
80
+ 5. [mdn/yari](https://github.com/mdn/yari)
81
+ 6. [streetwriters/notesnook](https://github.com/streetwriters/notesnook)
82
+ 7. [imba/imba](https://github.com/imba/imba)
83
+ 8. [moroshko/react-scanner](https://github.com/moroshko/react-scanner)
84
+ 9. [netlify/build](https://github.com/netlify/build)
85
+ 10. [yassinedoghri/astro-i18next](https://github.com/yassinedoghri/astro-i18next)
86
+ 11. [selfrefactor/rambda](https://github.com/selfrefactor/rambda)
87
+ 12. [whyboris/Video-Hub-App](https://github.com/whyboris/Video-Hub-App)
88
+
89
+ ## 🦮 LICENSE
90
+
91
+ Copyright &copy; 2024 Abdullah Atta under MIT. [Read full text here.](https://github.com/thecodrr/fdir/raw/master/LICENSE)
web/node_modules/fdir/dist/index.cjs ADDED
@@ -0,0 +1,588 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+ const path = __toESM(require("path"));
25
+ const fs = __toESM(require("fs"));
26
+
27
+ //#region src/utils.ts
28
+ function cleanPath(path$1) {
29
+ let normalized = (0, path.normalize)(path$1);
30
+ if (normalized.length > 1 && normalized[normalized.length - 1] === path.sep) normalized = normalized.substring(0, normalized.length - 1);
31
+ return normalized;
32
+ }
33
+ const SLASHES_REGEX = /[\\/]/g;
34
+ function convertSlashes(path$1, separator) {
35
+ return path$1.replace(SLASHES_REGEX, separator);
36
+ }
37
+ const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
38
+ function isRootDirectory(path$1) {
39
+ return path$1 === "/" || WINDOWS_ROOT_DIR_REGEX.test(path$1);
40
+ }
41
+ function normalizePath(path$1, options) {
42
+ const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
43
+ const pathNeedsCleaning = process.platform === "win32" && path$1.includes("/") || path$1.startsWith(".");
44
+ if (resolvePaths) path$1 = (0, path.resolve)(path$1);
45
+ if (normalizePath$1 || pathNeedsCleaning) path$1 = cleanPath(path$1);
46
+ if (path$1 === ".") return "";
47
+ const needsSeperator = path$1[path$1.length - 1] !== pathSeparator;
48
+ return convertSlashes(needsSeperator ? path$1 + pathSeparator : path$1, pathSeparator);
49
+ }
50
+
51
+ //#endregion
52
+ //#region src/api/functions/join-path.ts
53
+ function joinPathWithBasePath(filename, directoryPath) {
54
+ return directoryPath + filename;
55
+ }
56
+ function joinPathWithRelativePath(root, options) {
57
+ return function(filename, directoryPath) {
58
+ const sameRoot = directoryPath.startsWith(root);
59
+ if (sameRoot) return directoryPath.slice(root.length) + filename;
60
+ else return convertSlashes((0, path.relative)(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
61
+ };
62
+ }
63
+ function joinPath(filename) {
64
+ return filename;
65
+ }
66
+ function joinDirectoryPath(filename, directoryPath, separator) {
67
+ return directoryPath + filename + separator;
68
+ }
69
+ function build$7(root, options) {
70
+ const { relativePaths, includeBasePath } = options;
71
+ return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
72
+ }
73
+
74
+ //#endregion
75
+ //#region src/api/functions/push-directory.ts
76
+ function pushDirectoryWithRelativePath(root) {
77
+ return function(directoryPath, paths) {
78
+ paths.push(directoryPath.substring(root.length) || ".");
79
+ };
80
+ }
81
+ function pushDirectoryFilterWithRelativePath(root) {
82
+ return function(directoryPath, paths, filters) {
83
+ const relativePath = directoryPath.substring(root.length) || ".";
84
+ if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
85
+ };
86
+ }
87
+ const pushDirectory = (directoryPath, paths) => {
88
+ paths.push(directoryPath || ".");
89
+ };
90
+ const pushDirectoryFilter = (directoryPath, paths, filters) => {
91
+ const path$1 = directoryPath || ".";
92
+ if (filters.every((filter) => filter(path$1, true))) paths.push(path$1);
93
+ };
94
+ const empty$2 = () => {};
95
+ function build$6(root, options) {
96
+ const { includeDirs, filters, relativePaths } = options;
97
+ if (!includeDirs) return empty$2;
98
+ if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
99
+ return filters && filters.length ? pushDirectoryFilter : pushDirectory;
100
+ }
101
+
102
+ //#endregion
103
+ //#region src/api/functions/push-file.ts
104
+ const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
105
+ if (filters.every((filter) => filter(filename, false))) counts.files++;
106
+ };
107
+ const pushFileFilter = (filename, paths, _counts, filters) => {
108
+ if (filters.every((filter) => filter(filename, false))) paths.push(filename);
109
+ };
110
+ const pushFileCount = (_filename, _paths, counts, _filters) => {
111
+ counts.files++;
112
+ };
113
+ const pushFile = (filename, paths) => {
114
+ paths.push(filename);
115
+ };
116
+ const empty$1 = () => {};
117
+ function build$5(options) {
118
+ const { excludeFiles, filters, onlyCounts } = options;
119
+ if (excludeFiles) return empty$1;
120
+ if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
121
+ else if (onlyCounts) return pushFileCount;
122
+ else return pushFile;
123
+ }
124
+
125
+ //#endregion
126
+ //#region src/api/functions/get-array.ts
127
+ const getArray = (paths) => {
128
+ return paths;
129
+ };
130
+ const getArrayGroup = () => {
131
+ return [""].slice(0, 0);
132
+ };
133
+ function build$4(options) {
134
+ return options.group ? getArrayGroup : getArray;
135
+ }
136
+
137
+ //#endregion
138
+ //#region src/api/functions/group-files.ts
139
+ const groupFiles = (groups, directory, files) => {
140
+ groups.push({
141
+ directory,
142
+ files,
143
+ dir: directory
144
+ });
145
+ };
146
+ const empty = () => {};
147
+ function build$3(options) {
148
+ return options.group ? groupFiles : empty;
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/api/functions/resolve-symlink.ts
153
+ const resolveSymlinksAsync = function(path$1, state, callback$1) {
154
+ const { queue, fs: fs$1, options: { suppressErrors } } = state;
155
+ queue.enqueue();
156
+ fs$1.realpath(path$1, (error, resolvedPath) => {
157
+ if (error) return queue.dequeue(suppressErrors ? null : error, state);
158
+ fs$1.stat(resolvedPath, (error$1, stat) => {
159
+ if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
160
+ if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return queue.dequeue(null, state);
161
+ callback$1(stat, resolvedPath);
162
+ queue.dequeue(null, state);
163
+ });
164
+ });
165
+ };
166
+ const resolveSymlinks = function(path$1, state, callback$1) {
167
+ const { queue, fs: fs$1, options: { suppressErrors } } = state;
168
+ queue.enqueue();
169
+ try {
170
+ const resolvedPath = fs$1.realpathSync(path$1);
171
+ const stat = fs$1.statSync(resolvedPath);
172
+ if (stat.isDirectory() && isRecursive(path$1, resolvedPath, state)) return;
173
+ callback$1(stat, resolvedPath);
174
+ } catch (e) {
175
+ if (!suppressErrors) throw e;
176
+ }
177
+ };
178
+ function build$2(options, isSynchronous) {
179
+ if (!options.resolveSymlinks || options.excludeSymlinks) return null;
180
+ return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
181
+ }
182
+ function isRecursive(path$1, resolved, state) {
183
+ if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
184
+ let parent = (0, path.dirname)(path$1);
185
+ let depth = 1;
186
+ while (parent !== state.root && depth < 2) {
187
+ const resolvedPath = state.symlinks.get(parent);
188
+ const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
189
+ if (isSameRoot) depth++;
190
+ else parent = (0, path.dirname)(parent);
191
+ }
192
+ state.symlinks.set(path$1, resolved);
193
+ return depth > 1;
194
+ }
195
+ function isRecursiveUsingRealPaths(resolved, state) {
196
+ return state.visited.includes(resolved + state.options.pathSeparator);
197
+ }
198
+
199
+ //#endregion
200
+ //#region src/api/functions/invoke-callback.ts
201
+ const onlyCountsSync = (state) => {
202
+ return state.counts;
203
+ };
204
+ const groupsSync = (state) => {
205
+ return state.groups;
206
+ };
207
+ const defaultSync = (state) => {
208
+ return state.paths;
209
+ };
210
+ const limitFilesSync = (state) => {
211
+ return state.paths.slice(0, state.options.maxFiles);
212
+ };
213
+ const onlyCountsAsync = (state, error, callback$1) => {
214
+ report(error, callback$1, state.counts, state.options.suppressErrors);
215
+ return null;
216
+ };
217
+ const defaultAsync = (state, error, callback$1) => {
218
+ report(error, callback$1, state.paths, state.options.suppressErrors);
219
+ return null;
220
+ };
221
+ const limitFilesAsync = (state, error, callback$1) => {
222
+ report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
223
+ return null;
224
+ };
225
+ const groupsAsync = (state, error, callback$1) => {
226
+ report(error, callback$1, state.groups, state.options.suppressErrors);
227
+ return null;
228
+ };
229
+ function report(error, callback$1, output, suppressErrors) {
230
+ if (error && !suppressErrors) callback$1(error, output);
231
+ else callback$1(null, output);
232
+ }
233
+ function build$1(options, isSynchronous) {
234
+ const { onlyCounts, group, maxFiles } = options;
235
+ if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
236
+ else if (group) return isSynchronous ? groupsSync : groupsAsync;
237
+ else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
238
+ else return isSynchronous ? defaultSync : defaultAsync;
239
+ }
240
+
241
+ //#endregion
242
+ //#region src/api/functions/walk-directory.ts
243
+ const readdirOpts = { withFileTypes: true };
244
+ const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
245
+ state.queue.enqueue();
246
+ if (currentDepth < 0) return state.queue.dequeue(null, state);
247
+ const { fs: fs$1 } = state;
248
+ state.visited.push(crawlPath);
249
+ state.counts.directories++;
250
+ fs$1.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
251
+ callback$1(entries, directoryPath, currentDepth);
252
+ state.queue.dequeue(state.options.suppressErrors ? null : error, state);
253
+ });
254
+ };
255
+ const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
256
+ const { fs: fs$1 } = state;
257
+ if (currentDepth < 0) return;
258
+ state.visited.push(crawlPath);
259
+ state.counts.directories++;
260
+ let entries = [];
261
+ try {
262
+ entries = fs$1.readdirSync(crawlPath || ".", readdirOpts);
263
+ } catch (e) {
264
+ if (!state.options.suppressErrors) throw e;
265
+ }
266
+ callback$1(entries, directoryPath, currentDepth);
267
+ };
268
+ function build(isSynchronous) {
269
+ return isSynchronous ? walkSync : walkAsync;
270
+ }
271
+
272
+ //#endregion
273
+ //#region src/api/queue.ts
274
+ /**
275
+ * This is a custom stateless queue to track concurrent async fs calls.
276
+ * It increments a counter whenever a call is queued and decrements it
277
+ * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
278
+ */
279
+ var Queue = class {
280
+ count = 0;
281
+ constructor(onQueueEmpty) {
282
+ this.onQueueEmpty = onQueueEmpty;
283
+ }
284
+ enqueue() {
285
+ this.count++;
286
+ return this.count;
287
+ }
288
+ dequeue(error, output) {
289
+ if (this.onQueueEmpty && (--this.count <= 0 || error)) {
290
+ this.onQueueEmpty(error, output);
291
+ if (error) {
292
+ output.controller.abort();
293
+ this.onQueueEmpty = void 0;
294
+ }
295
+ }
296
+ }
297
+ };
298
+
299
+ //#endregion
300
+ //#region src/api/counter.ts
301
+ var Counter = class {
302
+ _files = 0;
303
+ _directories = 0;
304
+ set files(num) {
305
+ this._files = num;
306
+ }
307
+ get files() {
308
+ return this._files;
309
+ }
310
+ set directories(num) {
311
+ this._directories = num;
312
+ }
313
+ get directories() {
314
+ return this._directories;
315
+ }
316
+ /**
317
+ * @deprecated use `directories` instead
318
+ */
319
+ /* c8 ignore next 3 */
320
+ get dirs() {
321
+ return this._directories;
322
+ }
323
+ };
324
+
325
+ //#endregion
326
+ //#region src/api/aborter.ts
327
+ /**
328
+ * AbortController is not supported on Node 14 so we use this until we can drop
329
+ * support for Node 14.
330
+ */
331
+ var Aborter = class {
332
+ aborted = false;
333
+ abort() {
334
+ this.aborted = true;
335
+ }
336
+ };
337
+
338
+ //#endregion
339
+ //#region src/api/walker.ts
340
+ var Walker = class {
341
+ root;
342
+ isSynchronous;
343
+ state;
344
+ joinPath;
345
+ pushDirectory;
346
+ pushFile;
347
+ getArray;
348
+ groupFiles;
349
+ resolveSymlink;
350
+ walkDirectory;
351
+ callbackInvoker;
352
+ constructor(root, options, callback$1) {
353
+ this.isSynchronous = !callback$1;
354
+ this.callbackInvoker = build$1(options, this.isSynchronous);
355
+ this.root = normalizePath(root, options);
356
+ this.state = {
357
+ root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
358
+ paths: [""].slice(0, 0),
359
+ groups: [],
360
+ counts: new Counter(),
361
+ options,
362
+ queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
363
+ symlinks: /* @__PURE__ */ new Map(),
364
+ visited: [""].slice(0, 0),
365
+ controller: new Aborter(),
366
+ fs: options.fs || fs
367
+ };
368
+ this.joinPath = build$7(this.root, options);
369
+ this.pushDirectory = build$6(this.root, options);
370
+ this.pushFile = build$5(options);
371
+ this.getArray = build$4(options);
372
+ this.groupFiles = build$3(options);
373
+ this.resolveSymlink = build$2(options, this.isSynchronous);
374
+ this.walkDirectory = build(this.isSynchronous);
375
+ }
376
+ start() {
377
+ this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
378
+ this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
379
+ return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
380
+ }
381
+ walk = (entries, directoryPath, depth) => {
382
+ const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
383
+ if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
384
+ const files = this.getArray(this.state.paths);
385
+ for (let i = 0; i < entries.length; ++i) {
386
+ const entry = entries[i];
387
+ if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
388
+ const filename = this.joinPath(entry.name, directoryPath);
389
+ this.pushFile(filename, files, this.state.counts, filters);
390
+ } else if (entry.isDirectory()) {
391
+ let path$1 = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
392
+ if (exclude && exclude(entry.name, path$1)) continue;
393
+ this.pushDirectory(path$1, paths, filters);
394
+ this.walkDirectory(this.state, path$1, path$1, depth - 1, this.walk);
395
+ } else if (this.resolveSymlink && entry.isSymbolicLink()) {
396
+ let path$1 = joinPathWithBasePath(entry.name, directoryPath);
397
+ this.resolveSymlink(path$1, this.state, (stat, resolvedPath) => {
398
+ if (stat.isDirectory()) {
399
+ resolvedPath = normalizePath(resolvedPath, this.state.options);
400
+ if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path$1 + pathSeparator)) return;
401
+ this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path$1 + pathSeparator, depth - 1, this.walk);
402
+ } else {
403
+ resolvedPath = useRealPaths ? resolvedPath : path$1;
404
+ const filename = (0, path.basename)(resolvedPath);
405
+ const directoryPath$1 = normalizePath((0, path.dirname)(resolvedPath), this.state.options);
406
+ resolvedPath = this.joinPath(filename, directoryPath$1);
407
+ this.pushFile(resolvedPath, files, this.state.counts, filters);
408
+ }
409
+ });
410
+ }
411
+ }
412
+ this.groupFiles(this.state.groups, directoryPath, files);
413
+ };
414
+ };
415
+
416
+ //#endregion
417
+ //#region src/api/async.ts
418
+ function promise(root, options) {
419
+ return new Promise((resolve$1, reject) => {
420
+ callback(root, options, (err, output) => {
421
+ if (err) return reject(err);
422
+ resolve$1(output);
423
+ });
424
+ });
425
+ }
426
+ function callback(root, options, callback$1) {
427
+ let walker = new Walker(root, options, callback$1);
428
+ walker.start();
429
+ }
430
+
431
+ //#endregion
432
+ //#region src/api/sync.ts
433
+ function sync(root, options) {
434
+ const walker = new Walker(root, options);
435
+ return walker.start();
436
+ }
437
+
438
+ //#endregion
439
+ //#region src/builder/api-builder.ts
440
+ var APIBuilder = class {
441
+ constructor(root, options) {
442
+ this.root = root;
443
+ this.options = options;
444
+ }
445
+ withPromise() {
446
+ return promise(this.root, this.options);
447
+ }
448
+ withCallback(cb) {
449
+ callback(this.root, this.options, cb);
450
+ }
451
+ sync() {
452
+ return sync(this.root, this.options);
453
+ }
454
+ };
455
+
456
+ //#endregion
457
+ //#region src/builder/index.ts
458
+ let pm = null;
459
+ /* c8 ignore next 6 */
460
+ try {
461
+ require.resolve("picomatch");
462
+ pm = require("picomatch");
463
+ } catch {}
464
+ var Builder = class {
465
+ globCache = {};
466
+ options = {
467
+ maxDepth: Infinity,
468
+ suppressErrors: true,
469
+ pathSeparator: path.sep,
470
+ filters: []
471
+ };
472
+ globFunction;
473
+ constructor(options) {
474
+ this.options = {
475
+ ...this.options,
476
+ ...options
477
+ };
478
+ this.globFunction = this.options.globFunction;
479
+ }
480
+ group() {
481
+ this.options.group = true;
482
+ return this;
483
+ }
484
+ withPathSeparator(separator) {
485
+ this.options.pathSeparator = separator;
486
+ return this;
487
+ }
488
+ withBasePath() {
489
+ this.options.includeBasePath = true;
490
+ return this;
491
+ }
492
+ withRelativePaths() {
493
+ this.options.relativePaths = true;
494
+ return this;
495
+ }
496
+ withDirs() {
497
+ this.options.includeDirs = true;
498
+ return this;
499
+ }
500
+ withMaxDepth(depth) {
501
+ this.options.maxDepth = depth;
502
+ return this;
503
+ }
504
+ withMaxFiles(limit) {
505
+ this.options.maxFiles = limit;
506
+ return this;
507
+ }
508
+ withFullPaths() {
509
+ this.options.resolvePaths = true;
510
+ this.options.includeBasePath = true;
511
+ return this;
512
+ }
513
+ withErrors() {
514
+ this.options.suppressErrors = false;
515
+ return this;
516
+ }
517
+ withSymlinks({ resolvePaths = true } = {}) {
518
+ this.options.resolveSymlinks = true;
519
+ this.options.useRealPaths = resolvePaths;
520
+ return this.withFullPaths();
521
+ }
522
+ withAbortSignal(signal) {
523
+ this.options.signal = signal;
524
+ return this;
525
+ }
526
+ normalize() {
527
+ this.options.normalizePath = true;
528
+ return this;
529
+ }
530
+ filter(predicate) {
531
+ this.options.filters.push(predicate);
532
+ return this;
533
+ }
534
+ onlyDirs() {
535
+ this.options.excludeFiles = true;
536
+ this.options.includeDirs = true;
537
+ return this;
538
+ }
539
+ exclude(predicate) {
540
+ this.options.exclude = predicate;
541
+ return this;
542
+ }
543
+ onlyCounts() {
544
+ this.options.onlyCounts = true;
545
+ return this;
546
+ }
547
+ crawl(root) {
548
+ return new APIBuilder(root || ".", this.options);
549
+ }
550
+ withGlobFunction(fn) {
551
+ this.globFunction = fn;
552
+ return this;
553
+ }
554
+ /**
555
+ * @deprecated Pass options using the constructor instead:
556
+ * ```ts
557
+ * new fdir(options).crawl("/path/to/root");
558
+ * ```
559
+ * This method will be removed in v7.0
560
+ */
561
+ /* c8 ignore next 4 */
562
+ crawlWithOptions(root, options) {
563
+ this.options = {
564
+ ...this.options,
565
+ ...options
566
+ };
567
+ return new APIBuilder(root || ".", this.options);
568
+ }
569
+ glob(...patterns) {
570
+ if (this.globFunction) return this.globWithOptions(patterns);
571
+ return this.globWithOptions(patterns, ...[{ dot: true }]);
572
+ }
573
+ globWithOptions(patterns, ...options) {
574
+ const globFn = this.globFunction || pm;
575
+ /* c8 ignore next 5 */
576
+ if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
577
+ var isMatch = this.globCache[patterns.join("\0")];
578
+ if (!isMatch) {
579
+ isMatch = globFn(patterns, ...options);
580
+ this.globCache[patterns.join("\0")] = isMatch;
581
+ }
582
+ this.options.filters.push((path$1) => isMatch(path$1));
583
+ return this;
584
+ }
585
+ };
586
+
587
+ //#endregion
588
+ exports.fdir = Builder;
web/node_modules/fdir/dist/index.d.cts ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+ import * as nativeFs from "fs";
3
+ import picomatch from "picomatch";
4
+
5
+ //#region src/api/aborter.d.ts
6
+ /**
7
+ * AbortController is not supported on Node 14 so we use this until we can drop
8
+ * support for Node 14.
9
+ */
10
+ declare class Aborter {
11
+ aborted: boolean;
12
+ abort(): void;
13
+ }
14
+ //#endregion
15
+ //#region src/api/queue.d.ts
16
+ type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
17
+ /**
18
+ * This is a custom stateless queue to track concurrent async fs calls.
19
+ * It increments a counter whenever a call is queued and decrements it
20
+ * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
21
+ */
22
+ declare class Queue {
23
+ private onQueueEmpty?;
24
+ count: number;
25
+ constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
26
+ enqueue(): number;
27
+ dequeue(error: Error | null, output: WalkerState): void;
28
+ }
29
+ //#endregion
30
+ //#region src/types.d.ts
31
+ type Counts = {
32
+ files: number;
33
+ directories: number;
34
+ /**
35
+ * @deprecated use `directories` instead. Will be removed in v7.0.
36
+ */
37
+ dirs: number;
38
+ };
39
+ type Group = {
40
+ directory: string;
41
+ files: string[];
42
+ /**
43
+ * @deprecated use `directory` instead. Will be removed in v7.0.
44
+ */
45
+ dir: string;
46
+ };
47
+ type GroupOutput = Group[];
48
+ type OnlyCountsOutput = Counts;
49
+ type PathsOutput = string[];
50
+ type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
51
+ type FSLike = {
52
+ readdir: typeof nativeFs.readdir;
53
+ readdirSync: typeof nativeFs.readdirSync;
54
+ realpath: typeof nativeFs.realpath;
55
+ realpathSync: typeof nativeFs.realpathSync;
56
+ stat: typeof nativeFs.stat;
57
+ statSync: typeof nativeFs.statSync;
58
+ };
59
+ type WalkerState = {
60
+ root: string;
61
+ paths: string[];
62
+ groups: Group[];
63
+ counts: Counts;
64
+ options: Options;
65
+ queue: Queue;
66
+ controller: Aborter;
67
+ fs: FSLike;
68
+ symlinks: Map<string, string>;
69
+ visited: string[];
70
+ };
71
+ type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
72
+ type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
73
+ type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
74
+ type PathSeparator = "/" | "\\";
75
+ type Options<TGlobFunction = unknown> = {
76
+ includeBasePath?: boolean;
77
+ includeDirs?: boolean;
78
+ normalizePath?: boolean;
79
+ maxDepth: number;
80
+ maxFiles?: number;
81
+ resolvePaths?: boolean;
82
+ suppressErrors: boolean;
83
+ group?: boolean;
84
+ onlyCounts?: boolean;
85
+ filters: FilterPredicate[];
86
+ resolveSymlinks?: boolean;
87
+ useRealPaths?: boolean;
88
+ excludeFiles?: boolean;
89
+ excludeSymlinks?: boolean;
90
+ exclude?: ExcludePredicate;
91
+ relativePaths?: boolean;
92
+ pathSeparator: PathSeparator;
93
+ signal?: AbortSignal;
94
+ globFunction?: TGlobFunction;
95
+ fs?: FSLike;
96
+ };
97
+ type GlobMatcher = (test: string) => boolean;
98
+ type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
99
+ type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
100
+ //#endregion
101
+ //#region src/builder/api-builder.d.ts
102
+ declare class APIBuilder<TReturnType extends Output> {
103
+ private readonly root;
104
+ private readonly options;
105
+ constructor(root: string, options: Options);
106
+ withPromise(): Promise<TReturnType>;
107
+ withCallback(cb: ResultCallback<TReturnType>): void;
108
+ sync(): TReturnType;
109
+ }
110
+ //#endregion
111
+ //#region src/builder/index.d.ts
112
+ declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
113
+ private readonly globCache;
114
+ private options;
115
+ private globFunction?;
116
+ constructor(options?: Partial<Options<TGlobFunction>>);
117
+ group(): Builder<GroupOutput, TGlobFunction>;
118
+ withPathSeparator(separator: "/" | "\\"): this;
119
+ withBasePath(): this;
120
+ withRelativePaths(): this;
121
+ withDirs(): this;
122
+ withMaxDepth(depth: number): this;
123
+ withMaxFiles(limit: number): this;
124
+ withFullPaths(): this;
125
+ withErrors(): this;
126
+ withSymlinks({
127
+ resolvePaths
128
+ }?: {
129
+ resolvePaths?: boolean | undefined;
130
+ }): this;
131
+ withAbortSignal(signal: AbortSignal): this;
132
+ normalize(): this;
133
+ filter(predicate: FilterPredicate): this;
134
+ onlyDirs(): this;
135
+ exclude(predicate: ExcludePredicate): this;
136
+ onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
137
+ crawl(root?: string): APIBuilder<TReturnType>;
138
+ withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
139
+ /**
140
+ * @deprecated Pass options using the constructor instead:
141
+ * ```ts
142
+ * new fdir(options).crawl("/path/to/root");
143
+ * ```
144
+ * This method will be removed in v7.0
145
+ */
146
+ crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
147
+ glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
148
+ globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
149
+ globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
150
+ }
151
+ //#endregion
152
+ //#region src/index.d.ts
153
+ type Fdir = typeof Builder;
154
+ //#endregion
155
+ export { Counts, ExcludePredicate, FSLike, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
web/node_modules/fdir/dist/index.d.mts ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /// <reference types="node" />
2
+ import * as nativeFs from "fs";
3
+ import picomatch from "picomatch";
4
+
5
+ //#region src/api/aborter.d.ts
6
+ /**
7
+ * AbortController is not supported on Node 14 so we use this until we can drop
8
+ * support for Node 14.
9
+ */
10
+ declare class Aborter {
11
+ aborted: boolean;
12
+ abort(): void;
13
+ }
14
+ //#endregion
15
+ //#region src/api/queue.d.ts
16
+ type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
17
+ /**
18
+ * This is a custom stateless queue to track concurrent async fs calls.
19
+ * It increments a counter whenever a call is queued and decrements it
20
+ * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
21
+ */
22
+ declare class Queue {
23
+ private onQueueEmpty?;
24
+ count: number;
25
+ constructor(onQueueEmpty?: OnQueueEmptyCallback | undefined);
26
+ enqueue(): number;
27
+ dequeue(error: Error | null, output: WalkerState): void;
28
+ }
29
+ //#endregion
30
+ //#region src/types.d.ts
31
+ type Counts = {
32
+ files: number;
33
+ directories: number;
34
+ /**
35
+ * @deprecated use `directories` instead. Will be removed in v7.0.
36
+ */
37
+ dirs: number;
38
+ };
39
+ type Group = {
40
+ directory: string;
41
+ files: string[];
42
+ /**
43
+ * @deprecated use `directory` instead. Will be removed in v7.0.
44
+ */
45
+ dir: string;
46
+ };
47
+ type GroupOutput = Group[];
48
+ type OnlyCountsOutput = Counts;
49
+ type PathsOutput = string[];
50
+ type Output = OnlyCountsOutput | PathsOutput | GroupOutput;
51
+ type FSLike = {
52
+ readdir: typeof nativeFs.readdir;
53
+ readdirSync: typeof nativeFs.readdirSync;
54
+ realpath: typeof nativeFs.realpath;
55
+ realpathSync: typeof nativeFs.realpathSync;
56
+ stat: typeof nativeFs.stat;
57
+ statSync: typeof nativeFs.statSync;
58
+ };
59
+ type WalkerState = {
60
+ root: string;
61
+ paths: string[];
62
+ groups: Group[];
63
+ counts: Counts;
64
+ options: Options;
65
+ queue: Queue;
66
+ controller: Aborter;
67
+ fs: FSLike;
68
+ symlinks: Map<string, string>;
69
+ visited: string[];
70
+ };
71
+ type ResultCallback<TOutput extends Output> = (error: Error | null, output: TOutput) => void;
72
+ type FilterPredicate = (path: string, isDirectory: boolean) => boolean;
73
+ type ExcludePredicate = (dirName: string, dirPath: string) => boolean;
74
+ type PathSeparator = "/" | "\\";
75
+ type Options<TGlobFunction = unknown> = {
76
+ includeBasePath?: boolean;
77
+ includeDirs?: boolean;
78
+ normalizePath?: boolean;
79
+ maxDepth: number;
80
+ maxFiles?: number;
81
+ resolvePaths?: boolean;
82
+ suppressErrors: boolean;
83
+ group?: boolean;
84
+ onlyCounts?: boolean;
85
+ filters: FilterPredicate[];
86
+ resolveSymlinks?: boolean;
87
+ useRealPaths?: boolean;
88
+ excludeFiles?: boolean;
89
+ excludeSymlinks?: boolean;
90
+ exclude?: ExcludePredicate;
91
+ relativePaths?: boolean;
92
+ pathSeparator: PathSeparator;
93
+ signal?: AbortSignal;
94
+ globFunction?: TGlobFunction;
95
+ fs?: FSLike;
96
+ };
97
+ type GlobMatcher = (test: string) => boolean;
98
+ type GlobFunction = (glob: string | string[], ...params: unknown[]) => GlobMatcher;
99
+ type GlobParams<T> = T extends ((globs: string | string[], ...params: infer TParams extends unknown[]) => GlobMatcher) ? TParams : [];
100
+ //#endregion
101
+ //#region src/builder/api-builder.d.ts
102
+ declare class APIBuilder<TReturnType extends Output> {
103
+ private readonly root;
104
+ private readonly options;
105
+ constructor(root: string, options: Options);
106
+ withPromise(): Promise<TReturnType>;
107
+ withCallback(cb: ResultCallback<TReturnType>): void;
108
+ sync(): TReturnType;
109
+ }
110
+ //#endregion
111
+ //#region src/builder/index.d.ts
112
+ declare class Builder<TReturnType extends Output = PathsOutput, TGlobFunction = typeof picomatch> {
113
+ private readonly globCache;
114
+ private options;
115
+ private globFunction?;
116
+ constructor(options?: Partial<Options<TGlobFunction>>);
117
+ group(): Builder<GroupOutput, TGlobFunction>;
118
+ withPathSeparator(separator: "/" | "\\"): this;
119
+ withBasePath(): this;
120
+ withRelativePaths(): this;
121
+ withDirs(): this;
122
+ withMaxDepth(depth: number): this;
123
+ withMaxFiles(limit: number): this;
124
+ withFullPaths(): this;
125
+ withErrors(): this;
126
+ withSymlinks({
127
+ resolvePaths
128
+ }?: {
129
+ resolvePaths?: boolean | undefined;
130
+ }): this;
131
+ withAbortSignal(signal: AbortSignal): this;
132
+ normalize(): this;
133
+ filter(predicate: FilterPredicate): this;
134
+ onlyDirs(): this;
135
+ exclude(predicate: ExcludePredicate): this;
136
+ onlyCounts(): Builder<OnlyCountsOutput, TGlobFunction>;
137
+ crawl(root?: string): APIBuilder<TReturnType>;
138
+ withGlobFunction<TFunc>(fn: TFunc): Builder<TReturnType, TFunc>;
139
+ /**
140
+ * @deprecated Pass options using the constructor instead:
141
+ * ```ts
142
+ * new fdir(options).crawl("/path/to/root");
143
+ * ```
144
+ * This method will be removed in v7.0
145
+ */
146
+ crawlWithOptions(root: string, options: Partial<Options<TGlobFunction>>): APIBuilder<TReturnType>;
147
+ glob(...patterns: string[]): Builder<TReturnType, TGlobFunction>;
148
+ globWithOptions(patterns: string[]): Builder<TReturnType, TGlobFunction>;
149
+ globWithOptions(patterns: string[], ...options: GlobParams<TGlobFunction>): Builder<TReturnType, TGlobFunction>;
150
+ }
151
+ //#endregion
152
+ //#region src/index.d.ts
153
+ type Fdir = typeof Builder;
154
+ //#endregion
155
+ export { Counts, ExcludePredicate, FSLike, Fdir, FilterPredicate, GlobFunction, GlobMatcher, GlobParams, Group, GroupOutput, OnlyCountsOutput, Options, Output, PathSeparator, PathsOutput, ResultCallback, WalkerState, Builder as fdir };
web/node_modules/fdir/dist/index.mjs ADDED
@@ -0,0 +1,570 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createRequire } from "module";
2
+ import { basename, dirname, normalize, relative, resolve, sep } from "path";
3
+ import * as nativeFs from "fs";
4
+
5
+ //#region rolldown:runtime
6
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
7
+
8
+ //#endregion
9
+ //#region src/utils.ts
10
+ function cleanPath(path) {
11
+ let normalized = normalize(path);
12
+ if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
13
+ return normalized;
14
+ }
15
+ const SLASHES_REGEX = /[\\/]/g;
16
+ function convertSlashes(path, separator) {
17
+ return path.replace(SLASHES_REGEX, separator);
18
+ }
19
+ const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
20
+ function isRootDirectory(path) {
21
+ return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
22
+ }
23
+ function normalizePath(path, options) {
24
+ const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
25
+ const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
26
+ if (resolvePaths) path = resolve(path);
27
+ if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
28
+ if (path === ".") return "";
29
+ const needsSeperator = path[path.length - 1] !== pathSeparator;
30
+ return convertSlashes(needsSeperator ? path + pathSeparator : path, pathSeparator);
31
+ }
32
+
33
+ //#endregion
34
+ //#region src/api/functions/join-path.ts
35
+ function joinPathWithBasePath(filename, directoryPath) {
36
+ return directoryPath + filename;
37
+ }
38
+ function joinPathWithRelativePath(root, options) {
39
+ return function(filename, directoryPath) {
40
+ const sameRoot = directoryPath.startsWith(root);
41
+ if (sameRoot) return directoryPath.slice(root.length) + filename;
42
+ else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
43
+ };
44
+ }
45
+ function joinPath(filename) {
46
+ return filename;
47
+ }
48
+ function joinDirectoryPath(filename, directoryPath, separator) {
49
+ return directoryPath + filename + separator;
50
+ }
51
+ function build$7(root, options) {
52
+ const { relativePaths, includeBasePath } = options;
53
+ return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
54
+ }
55
+
56
+ //#endregion
57
+ //#region src/api/functions/push-directory.ts
58
+ function pushDirectoryWithRelativePath(root) {
59
+ return function(directoryPath, paths) {
60
+ paths.push(directoryPath.substring(root.length) || ".");
61
+ };
62
+ }
63
+ function pushDirectoryFilterWithRelativePath(root) {
64
+ return function(directoryPath, paths, filters) {
65
+ const relativePath = directoryPath.substring(root.length) || ".";
66
+ if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
67
+ };
68
+ }
69
+ const pushDirectory = (directoryPath, paths) => {
70
+ paths.push(directoryPath || ".");
71
+ };
72
+ const pushDirectoryFilter = (directoryPath, paths, filters) => {
73
+ const path = directoryPath || ".";
74
+ if (filters.every((filter) => filter(path, true))) paths.push(path);
75
+ };
76
+ const empty$2 = () => {};
77
+ function build$6(root, options) {
78
+ const { includeDirs, filters, relativePaths } = options;
79
+ if (!includeDirs) return empty$2;
80
+ if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
81
+ return filters && filters.length ? pushDirectoryFilter : pushDirectory;
82
+ }
83
+
84
+ //#endregion
85
+ //#region src/api/functions/push-file.ts
86
+ const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
87
+ if (filters.every((filter) => filter(filename, false))) counts.files++;
88
+ };
89
+ const pushFileFilter = (filename, paths, _counts, filters) => {
90
+ if (filters.every((filter) => filter(filename, false))) paths.push(filename);
91
+ };
92
+ const pushFileCount = (_filename, _paths, counts, _filters) => {
93
+ counts.files++;
94
+ };
95
+ const pushFile = (filename, paths) => {
96
+ paths.push(filename);
97
+ };
98
+ const empty$1 = () => {};
99
+ function build$5(options) {
100
+ const { excludeFiles, filters, onlyCounts } = options;
101
+ if (excludeFiles) return empty$1;
102
+ if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
103
+ else if (onlyCounts) return pushFileCount;
104
+ else return pushFile;
105
+ }
106
+
107
+ //#endregion
108
+ //#region src/api/functions/get-array.ts
109
+ const getArray = (paths) => {
110
+ return paths;
111
+ };
112
+ const getArrayGroup = () => {
113
+ return [""].slice(0, 0);
114
+ };
115
+ function build$4(options) {
116
+ return options.group ? getArrayGroup : getArray;
117
+ }
118
+
119
+ //#endregion
120
+ //#region src/api/functions/group-files.ts
121
+ const groupFiles = (groups, directory, files) => {
122
+ groups.push({
123
+ directory,
124
+ files,
125
+ dir: directory
126
+ });
127
+ };
128
+ const empty = () => {};
129
+ function build$3(options) {
130
+ return options.group ? groupFiles : empty;
131
+ }
132
+
133
+ //#endregion
134
+ //#region src/api/functions/resolve-symlink.ts
135
+ const resolveSymlinksAsync = function(path, state, callback$1) {
136
+ const { queue, fs, options: { suppressErrors } } = state;
137
+ queue.enqueue();
138
+ fs.realpath(path, (error, resolvedPath) => {
139
+ if (error) return queue.dequeue(suppressErrors ? null : error, state);
140
+ fs.stat(resolvedPath, (error$1, stat) => {
141
+ if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
142
+ if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
143
+ callback$1(stat, resolvedPath);
144
+ queue.dequeue(null, state);
145
+ });
146
+ });
147
+ };
148
+ const resolveSymlinks = function(path, state, callback$1) {
149
+ const { queue, fs, options: { suppressErrors } } = state;
150
+ queue.enqueue();
151
+ try {
152
+ const resolvedPath = fs.realpathSync(path);
153
+ const stat = fs.statSync(resolvedPath);
154
+ if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
155
+ callback$1(stat, resolvedPath);
156
+ } catch (e) {
157
+ if (!suppressErrors) throw e;
158
+ }
159
+ };
160
+ function build$2(options, isSynchronous) {
161
+ if (!options.resolveSymlinks || options.excludeSymlinks) return null;
162
+ return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
163
+ }
164
+ function isRecursive(path, resolved, state) {
165
+ if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
166
+ let parent = dirname(path);
167
+ let depth = 1;
168
+ while (parent !== state.root && depth < 2) {
169
+ const resolvedPath = state.symlinks.get(parent);
170
+ const isSameRoot = !!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath));
171
+ if (isSameRoot) depth++;
172
+ else parent = dirname(parent);
173
+ }
174
+ state.symlinks.set(path, resolved);
175
+ return depth > 1;
176
+ }
177
+ function isRecursiveUsingRealPaths(resolved, state) {
178
+ return state.visited.includes(resolved + state.options.pathSeparator);
179
+ }
180
+
181
+ //#endregion
182
+ //#region src/api/functions/invoke-callback.ts
183
+ const onlyCountsSync = (state) => {
184
+ return state.counts;
185
+ };
186
+ const groupsSync = (state) => {
187
+ return state.groups;
188
+ };
189
+ const defaultSync = (state) => {
190
+ return state.paths;
191
+ };
192
+ const limitFilesSync = (state) => {
193
+ return state.paths.slice(0, state.options.maxFiles);
194
+ };
195
+ const onlyCountsAsync = (state, error, callback$1) => {
196
+ report(error, callback$1, state.counts, state.options.suppressErrors);
197
+ return null;
198
+ };
199
+ const defaultAsync = (state, error, callback$1) => {
200
+ report(error, callback$1, state.paths, state.options.suppressErrors);
201
+ return null;
202
+ };
203
+ const limitFilesAsync = (state, error, callback$1) => {
204
+ report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
205
+ return null;
206
+ };
207
+ const groupsAsync = (state, error, callback$1) => {
208
+ report(error, callback$1, state.groups, state.options.suppressErrors);
209
+ return null;
210
+ };
211
+ function report(error, callback$1, output, suppressErrors) {
212
+ if (error && !suppressErrors) callback$1(error, output);
213
+ else callback$1(null, output);
214
+ }
215
+ function build$1(options, isSynchronous) {
216
+ const { onlyCounts, group, maxFiles } = options;
217
+ if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
218
+ else if (group) return isSynchronous ? groupsSync : groupsAsync;
219
+ else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
220
+ else return isSynchronous ? defaultSync : defaultAsync;
221
+ }
222
+
223
+ //#endregion
224
+ //#region src/api/functions/walk-directory.ts
225
+ const readdirOpts = { withFileTypes: true };
226
+ const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
227
+ state.queue.enqueue();
228
+ if (currentDepth < 0) return state.queue.dequeue(null, state);
229
+ const { fs } = state;
230
+ state.visited.push(crawlPath);
231
+ state.counts.directories++;
232
+ fs.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
233
+ callback$1(entries, directoryPath, currentDepth);
234
+ state.queue.dequeue(state.options.suppressErrors ? null : error, state);
235
+ });
236
+ };
237
+ const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
238
+ const { fs } = state;
239
+ if (currentDepth < 0) return;
240
+ state.visited.push(crawlPath);
241
+ state.counts.directories++;
242
+ let entries = [];
243
+ try {
244
+ entries = fs.readdirSync(crawlPath || ".", readdirOpts);
245
+ } catch (e) {
246
+ if (!state.options.suppressErrors) throw e;
247
+ }
248
+ callback$1(entries, directoryPath, currentDepth);
249
+ };
250
+ function build(isSynchronous) {
251
+ return isSynchronous ? walkSync : walkAsync;
252
+ }
253
+
254
+ //#endregion
255
+ //#region src/api/queue.ts
256
+ /**
257
+ * This is a custom stateless queue to track concurrent async fs calls.
258
+ * It increments a counter whenever a call is queued and decrements it
259
+ * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
260
+ */
261
+ var Queue = class {
262
+ count = 0;
263
+ constructor(onQueueEmpty) {
264
+ this.onQueueEmpty = onQueueEmpty;
265
+ }
266
+ enqueue() {
267
+ this.count++;
268
+ return this.count;
269
+ }
270
+ dequeue(error, output) {
271
+ if (this.onQueueEmpty && (--this.count <= 0 || error)) {
272
+ this.onQueueEmpty(error, output);
273
+ if (error) {
274
+ output.controller.abort();
275
+ this.onQueueEmpty = void 0;
276
+ }
277
+ }
278
+ }
279
+ };
280
+
281
+ //#endregion
282
+ //#region src/api/counter.ts
283
+ var Counter = class {
284
+ _files = 0;
285
+ _directories = 0;
286
+ set files(num) {
287
+ this._files = num;
288
+ }
289
+ get files() {
290
+ return this._files;
291
+ }
292
+ set directories(num) {
293
+ this._directories = num;
294
+ }
295
+ get directories() {
296
+ return this._directories;
297
+ }
298
+ /**
299
+ * @deprecated use `directories` instead
300
+ */
301
+ /* c8 ignore next 3 */
302
+ get dirs() {
303
+ return this._directories;
304
+ }
305
+ };
306
+
307
+ //#endregion
308
+ //#region src/api/aborter.ts
309
+ /**
310
+ * AbortController is not supported on Node 14 so we use this until we can drop
311
+ * support for Node 14.
312
+ */
313
+ var Aborter = class {
314
+ aborted = false;
315
+ abort() {
316
+ this.aborted = true;
317
+ }
318
+ };
319
+
320
+ //#endregion
321
+ //#region src/api/walker.ts
322
+ var Walker = class {
323
+ root;
324
+ isSynchronous;
325
+ state;
326
+ joinPath;
327
+ pushDirectory;
328
+ pushFile;
329
+ getArray;
330
+ groupFiles;
331
+ resolveSymlink;
332
+ walkDirectory;
333
+ callbackInvoker;
334
+ constructor(root, options, callback$1) {
335
+ this.isSynchronous = !callback$1;
336
+ this.callbackInvoker = build$1(options, this.isSynchronous);
337
+ this.root = normalizePath(root, options);
338
+ this.state = {
339
+ root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
340
+ paths: [""].slice(0, 0),
341
+ groups: [],
342
+ counts: new Counter(),
343
+ options,
344
+ queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
345
+ symlinks: /* @__PURE__ */ new Map(),
346
+ visited: [""].slice(0, 0),
347
+ controller: new Aborter(),
348
+ fs: options.fs || nativeFs
349
+ };
350
+ this.joinPath = build$7(this.root, options);
351
+ this.pushDirectory = build$6(this.root, options);
352
+ this.pushFile = build$5(options);
353
+ this.getArray = build$4(options);
354
+ this.groupFiles = build$3(options);
355
+ this.resolveSymlink = build$2(options, this.isSynchronous);
356
+ this.walkDirectory = build(this.isSynchronous);
357
+ }
358
+ start() {
359
+ this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
360
+ this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
361
+ return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
362
+ }
363
+ walk = (entries, directoryPath, depth) => {
364
+ const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
365
+ if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
366
+ const files = this.getArray(this.state.paths);
367
+ for (let i = 0; i < entries.length; ++i) {
368
+ const entry = entries[i];
369
+ if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
370
+ const filename = this.joinPath(entry.name, directoryPath);
371
+ this.pushFile(filename, files, this.state.counts, filters);
372
+ } else if (entry.isDirectory()) {
373
+ let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
374
+ if (exclude && exclude(entry.name, path)) continue;
375
+ this.pushDirectory(path, paths, filters);
376
+ this.walkDirectory(this.state, path, path, depth - 1, this.walk);
377
+ } else if (this.resolveSymlink && entry.isSymbolicLink()) {
378
+ let path = joinPathWithBasePath(entry.name, directoryPath);
379
+ this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
380
+ if (stat.isDirectory()) {
381
+ resolvedPath = normalizePath(resolvedPath, this.state.options);
382
+ if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
383
+ this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
384
+ } else {
385
+ resolvedPath = useRealPaths ? resolvedPath : path;
386
+ const filename = basename(resolvedPath);
387
+ const directoryPath$1 = normalizePath(dirname(resolvedPath), this.state.options);
388
+ resolvedPath = this.joinPath(filename, directoryPath$1);
389
+ this.pushFile(resolvedPath, files, this.state.counts, filters);
390
+ }
391
+ });
392
+ }
393
+ }
394
+ this.groupFiles(this.state.groups, directoryPath, files);
395
+ };
396
+ };
397
+
398
+ //#endregion
399
+ //#region src/api/async.ts
400
+ function promise(root, options) {
401
+ return new Promise((resolve$1, reject) => {
402
+ callback(root, options, (err, output) => {
403
+ if (err) return reject(err);
404
+ resolve$1(output);
405
+ });
406
+ });
407
+ }
408
+ function callback(root, options, callback$1) {
409
+ let walker = new Walker(root, options, callback$1);
410
+ walker.start();
411
+ }
412
+
413
+ //#endregion
414
+ //#region src/api/sync.ts
415
+ function sync(root, options) {
416
+ const walker = new Walker(root, options);
417
+ return walker.start();
418
+ }
419
+
420
+ //#endregion
421
+ //#region src/builder/api-builder.ts
422
+ var APIBuilder = class {
423
+ constructor(root, options) {
424
+ this.root = root;
425
+ this.options = options;
426
+ }
427
+ withPromise() {
428
+ return promise(this.root, this.options);
429
+ }
430
+ withCallback(cb) {
431
+ callback(this.root, this.options, cb);
432
+ }
433
+ sync() {
434
+ return sync(this.root, this.options);
435
+ }
436
+ };
437
+
438
+ //#endregion
439
+ //#region src/builder/index.ts
440
+ let pm = null;
441
+ /* c8 ignore next 6 */
442
+ try {
443
+ __require.resolve("picomatch");
444
+ pm = __require("picomatch");
445
+ } catch {}
446
+ var Builder = class {
447
+ globCache = {};
448
+ options = {
449
+ maxDepth: Infinity,
450
+ suppressErrors: true,
451
+ pathSeparator: sep,
452
+ filters: []
453
+ };
454
+ globFunction;
455
+ constructor(options) {
456
+ this.options = {
457
+ ...this.options,
458
+ ...options
459
+ };
460
+ this.globFunction = this.options.globFunction;
461
+ }
462
+ group() {
463
+ this.options.group = true;
464
+ return this;
465
+ }
466
+ withPathSeparator(separator) {
467
+ this.options.pathSeparator = separator;
468
+ return this;
469
+ }
470
+ withBasePath() {
471
+ this.options.includeBasePath = true;
472
+ return this;
473
+ }
474
+ withRelativePaths() {
475
+ this.options.relativePaths = true;
476
+ return this;
477
+ }
478
+ withDirs() {
479
+ this.options.includeDirs = true;
480
+ return this;
481
+ }
482
+ withMaxDepth(depth) {
483
+ this.options.maxDepth = depth;
484
+ return this;
485
+ }
486
+ withMaxFiles(limit) {
487
+ this.options.maxFiles = limit;
488
+ return this;
489
+ }
490
+ withFullPaths() {
491
+ this.options.resolvePaths = true;
492
+ this.options.includeBasePath = true;
493
+ return this;
494
+ }
495
+ withErrors() {
496
+ this.options.suppressErrors = false;
497
+ return this;
498
+ }
499
+ withSymlinks({ resolvePaths = true } = {}) {
500
+ this.options.resolveSymlinks = true;
501
+ this.options.useRealPaths = resolvePaths;
502
+ return this.withFullPaths();
503
+ }
504
+ withAbortSignal(signal) {
505
+ this.options.signal = signal;
506
+ return this;
507
+ }
508
+ normalize() {
509
+ this.options.normalizePath = true;
510
+ return this;
511
+ }
512
+ filter(predicate) {
513
+ this.options.filters.push(predicate);
514
+ return this;
515
+ }
516
+ onlyDirs() {
517
+ this.options.excludeFiles = true;
518
+ this.options.includeDirs = true;
519
+ return this;
520
+ }
521
+ exclude(predicate) {
522
+ this.options.exclude = predicate;
523
+ return this;
524
+ }
525
+ onlyCounts() {
526
+ this.options.onlyCounts = true;
527
+ return this;
528
+ }
529
+ crawl(root) {
530
+ return new APIBuilder(root || ".", this.options);
531
+ }
532
+ withGlobFunction(fn) {
533
+ this.globFunction = fn;
534
+ return this;
535
+ }
536
+ /**
537
+ * @deprecated Pass options using the constructor instead:
538
+ * ```ts
539
+ * new fdir(options).crawl("/path/to/root");
540
+ * ```
541
+ * This method will be removed in v7.0
542
+ */
543
+ /* c8 ignore next 4 */
544
+ crawlWithOptions(root, options) {
545
+ this.options = {
546
+ ...this.options,
547
+ ...options
548
+ };
549
+ return new APIBuilder(root || ".", this.options);
550
+ }
551
+ glob(...patterns) {
552
+ if (this.globFunction) return this.globWithOptions(patterns);
553
+ return this.globWithOptions(patterns, ...[{ dot: true }]);
554
+ }
555
+ globWithOptions(patterns, ...options) {
556
+ const globFn = this.globFunction || pm;
557
+ /* c8 ignore next 5 */
558
+ if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
559
+ var isMatch = this.globCache[patterns.join("\0")];
560
+ if (!isMatch) {
561
+ isMatch = globFn(patterns, ...options);
562
+ this.globCache[patterns.join("\0")] = isMatch;
563
+ }
564
+ this.options.filters.push((path) => isMatch(path));
565
+ return this;
566
+ }
567
+ };
568
+
569
+ //#endregion
570
+ export { Builder as fdir };
web/node_modules/fdir/package.json ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "fdir",
3
+ "version": "6.5.0",
4
+ "description": "The fastest directory crawler & globbing alternative to glob, fast-glob, & tiny-glob. Crawls 1m files in < 1s",
5
+ "main": "./dist/index.cjs",
6
+ "types": "./dist/index.d.cts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "prepublishOnly": "npm run test && npm run build",
10
+ "build": "tsdown",
11
+ "format": "prettier --write src __tests__ benchmarks",
12
+ "test": "vitest run __tests__/",
13
+ "test:coverage": "vitest run --coverage __tests__/",
14
+ "test:watch": "vitest __tests__/",
15
+ "bench": "ts-node benchmarks/benchmark.js",
16
+ "bench:glob": "ts-node benchmarks/glob-benchmark.ts",
17
+ "bench:fdir": "ts-node benchmarks/fdir-benchmark.ts",
18
+ "release": "./scripts/release.sh"
19
+ },
20
+ "engines": {
21
+ "node": ">=12.0.0"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/thecodrr/fdir.git"
26
+ },
27
+ "keywords": [
28
+ "util",
29
+ "os",
30
+ "sys",
31
+ "fs",
32
+ "walk",
33
+ "crawler",
34
+ "directory",
35
+ "files",
36
+ "io",
37
+ "tiny-glob",
38
+ "glob",
39
+ "fast-glob",
40
+ "speed",
41
+ "javascript",
42
+ "nodejs"
43
+ ],
44
+ "author": "thecodrr <thecodrr@protonmail.com>",
45
+ "license": "MIT",
46
+ "bugs": {
47
+ "url": "https://github.com/thecodrr/fdir/issues"
48
+ },
49
+ "homepage": "https://github.com/thecodrr/fdir#readme",
50
+ "devDependencies": {
51
+ "@types/glob": "^8.1.0",
52
+ "@types/mock-fs": "^4.13.4",
53
+ "@types/node": "^20.9.4",
54
+ "@types/picomatch": "^4.0.0",
55
+ "@types/tap": "^15.0.11",
56
+ "@vitest/coverage-v8": "^0.34.6",
57
+ "all-files-in-tree": "^1.1.2",
58
+ "benny": "^3.7.1",
59
+ "csv-to-markdown-table": "^1.3.1",
60
+ "expect": "^29.7.0",
61
+ "fast-glob": "^3.3.2",
62
+ "fdir1": "npm:fdir@1.2.0",
63
+ "fdir2": "npm:fdir@2.1.0",
64
+ "fdir3": "npm:fdir@3.4.2",
65
+ "fdir4": "npm:fdir@4.1.0",
66
+ "fdir5": "npm:fdir@5.0.0",
67
+ "fs-readdir-recursive": "^1.1.0",
68
+ "get-all-files": "^4.1.0",
69
+ "glob": "^10.3.10",
70
+ "klaw-sync": "^6.0.0",
71
+ "mock-fs": "^5.2.0",
72
+ "picomatch": "^4.0.2",
73
+ "prettier": "^3.5.3",
74
+ "recur-readdir": "0.0.1",
75
+ "recursive-files": "^1.0.2",
76
+ "recursive-fs": "^2.1.0",
77
+ "recursive-readdir": "^2.2.3",
78
+ "rrdir": "^12.1.0",
79
+ "systeminformation": "^5.21.17",
80
+ "tiny-glob": "^0.2.9",
81
+ "ts-node": "^10.9.1",
82
+ "tsdown": "^0.12.5",
83
+ "typescript": "^5.3.2",
84
+ "vitest": "^0.34.6",
85
+ "walk-sync": "^3.0.0"
86
+ },
87
+ "peerDependencies": {
88
+ "picomatch": "^3 || ^4"
89
+ },
90
+ "peerDependenciesMeta": {
91
+ "picomatch": {
92
+ "optional": true
93
+ }
94
+ },
95
+ "module": "./dist/index.mjs",
96
+ "exports": {
97
+ ".": {
98
+ "import": "./dist/index.mjs",
99
+ "require": "./dist/index.cjs"
100
+ },
101
+ "./package.json": "./package.json"
102
+ }
103
+ }
web/node_modules/fill-range/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014-present, Jon Schlinkert.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
web/node_modules/fill-range/README.md ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # fill-range [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![NPM total downloads](https://img.shields.io/npm/dt/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/fill-range)
2
+
3
+ > Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`
4
+
5
+ Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6
+
7
+ ## Install
8
+
9
+ Install with [npm](https://www.npmjs.com/):
10
+
11
+ ```sh
12
+ $ npm install --save fill-range
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_.
18
+
19
+ ```js
20
+ const fill = require('fill-range');
21
+ // fill(from, to[, step, options]);
22
+
23
+ console.log(fill('1', '10')); //=> ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
24
+ console.log(fill('1', '10', { toRegex: true })); //=> [1-9]|10
25
+ ```
26
+
27
+ **Params**
28
+
29
+ * `from`: **{String|Number}** the number or letter to start with
30
+ * `to`: **{String|Number}** the number or letter to end with
31
+ * `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use.
32
+ * `options`: **{Object|Function}**: See all available [options](#options)
33
+
34
+ ## Examples
35
+
36
+ By default, an array of values is returned.
37
+
38
+ **Alphabetical ranges**
39
+
40
+ ```js
41
+ console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
42
+ console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
43
+ ```
44
+
45
+ **Numerical ranges**
46
+
47
+ Numbers can be defined as actual numbers or strings.
48
+
49
+ ```js
50
+ console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
51
+ console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
52
+ ```
53
+
54
+ **Negative ranges**
55
+
56
+ Numbers can be defined as actual numbers or strings.
57
+
58
+ ```js
59
+ console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
60
+ console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
61
+ ```
62
+
63
+ **Steps (increments)**
64
+
65
+ ```js
66
+ // numerical ranges with increments
67
+ console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
68
+ console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
69
+ console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]
70
+
71
+ // alphabetical ranges with increments
72
+ console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
73
+ console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
74
+ console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
75
+ ```
76
+
77
+ ## Options
78
+
79
+ ### options.step
80
+
81
+ **Type**: `number` (formatted as a string or number)
82
+
83
+ **Default**: `undefined`
84
+
85
+ **Description**: The increment to use for the range. Can be used with letters or numbers.
86
+
87
+ **Example(s)**
88
+
89
+ ```js
90
+ // numbers
91
+ console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
92
+ console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
93
+ console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]
94
+
95
+ // letters
96
+ console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
97
+ console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
98
+ console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
99
+ ```
100
+
101
+ ### options.strictRanges
102
+
103
+ **Type**: `boolean`
104
+
105
+ **Default**: `false`
106
+
107
+ **Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
108
+
109
+ **Example(s)**
110
+
111
+ The following are all invalid:
112
+
113
+ ```js
114
+ fill('1.1', '2'); // decimals not supported in ranges
115
+ fill('a', '2'); // incompatible range values
116
+ fill(1, 10, 'foo'); // invalid "step" argument
117
+ ```
118
+
119
+ ### options.stringify
120
+
121
+ **Type**: `boolean`
122
+
123
+ **Default**: `undefined`
124
+
125
+ **Description**: Cast all returned values to strings. By default, integers are returned as numbers.
126
+
127
+ **Example(s)**
128
+
129
+ ```js
130
+ console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
131
+ console.log(fill(1, 5, { stringify: true })); //=> [ '1', '2', '3', '4', '5' ]
132
+ ```
133
+
134
+ ### options.toRegex
135
+
136
+ **Type**: `boolean`
137
+
138
+ **Default**: `undefined`
139
+
140
+ **Description**: Create a regex-compatible source string, instead of expanding values to an array.
141
+
142
+ **Example(s)**
143
+
144
+ ```js
145
+ // alphabetical range
146
+ console.log(fill('a', 'e', { toRegex: true })); //=> '[a-e]'
147
+ // alphabetical with step
148
+ console.log(fill('a', 'z', 3, { toRegex: true })); //=> 'a|d|g|j|m|p|s|v|y'
149
+ // numerical range
150
+ console.log(fill('1', '100', { toRegex: true })); //=> '[1-9]|[1-9][0-9]|100'
151
+ // numerical range with zero padding
152
+ console.log(fill('000001', '100000', { toRegex: true }));
153
+ //=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
154
+ ```
155
+
156
+ ### options.transform
157
+
158
+ **Type**: `function`
159
+
160
+ **Default**: `undefined`
161
+
162
+ **Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
163
+
164
+ **Example(s)**
165
+
166
+ ```js
167
+ // add zero padding
168
+ console.log(fill(1, 5, value => String(value).padStart(4, '0')));
169
+ //=> ['0001', '0002', '0003', '0004', '0005']
170
+ ```
171
+
172
+ ## About
173
+
174
+ <details>
175
+ <summary><strong>Contributing</strong></summary>
176
+
177
+ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
178
+
179
+ </details>
180
+
181
+ <details>
182
+ <summary><strong>Running Tests</strong></summary>
183
+
184
+ Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
185
+
186
+ ```sh
187
+ $ npm install && npm test
188
+ ```
189
+
190
+ </details>
191
+
192
+ <details>
193
+ <summary><strong>Building docs</strong></summary>
194
+
195
+ _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
196
+
197
+ To generate the readme, run the following command:
198
+
199
+ ```sh
200
+ $ npm install -g verbose/verb#dev verb-generate-readme && verb
201
+ ```
202
+
203
+ </details>
204
+
205
+ ### Contributors
206
+
207
+ | **Commits** | **Contributor** |
208
+ | --- | --- |
209
+ | 116 | [jonschlinkert](https://github.com/jonschlinkert) |
210
+ | 4 | [paulmillr](https://github.com/paulmillr) |
211
+ | 2 | [realityking](https://github.com/realityking) |
212
+ | 2 | [bluelovers](https://github.com/bluelovers) |
213
+ | 1 | [edorivai](https://github.com/edorivai) |
214
+ | 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
215
+
216
+ ### Author
217
+
218
+ **Jon Schlinkert**
219
+
220
+ * [GitHub Profile](https://github.com/jonschlinkert)
221
+ * [Twitter Profile](https://twitter.com/jonschlinkert)
222
+ * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
223
+
224
+ Please consider supporting me on Patreon, or [start your own Patreon page](https://patreon.com/invite/bxpbvm)!
225
+
226
+ <a href="https://www.patreon.com/jonschlinkert">
227
+ <img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" height="50">
228
+ </a>
229
+
230
+ ### License
231
+
232
+ Copyright © 2019, [Jon Schlinkert](https://github.com/jonschlinkert).
233
+ Released under the [MIT License](LICENSE).
234
+
235
+ ***
236
+
237
+ _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on April 08, 2019._
web/node_modules/fill-range/index.js ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * fill-range <https://github.com/jonschlinkert/fill-range>
3
+ *
4
+ * Copyright (c) 2014-present, Jon Schlinkert.
5
+ * Licensed under the MIT License.
6
+ */
7
+
8
+ 'use strict';
9
+
10
+ const util = require('util');
11
+ const toRegexRange = require('to-regex-range');
12
+
13
+ const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
14
+
15
+ const transform = toNumber => {
16
+ return value => toNumber === true ? Number(value) : String(value);
17
+ };
18
+
19
+ const isValidValue = value => {
20
+ return typeof value === 'number' || (typeof value === 'string' && value !== '');
21
+ };
22
+
23
+ const isNumber = num => Number.isInteger(+num);
24
+
25
+ const zeros = input => {
26
+ let value = `${input}`;
27
+ let index = -1;
28
+ if (value[0] === '-') value = value.slice(1);
29
+ if (value === '0') return false;
30
+ while (value[++index] === '0');
31
+ return index > 0;
32
+ };
33
+
34
+ const stringify = (start, end, options) => {
35
+ if (typeof start === 'string' || typeof end === 'string') {
36
+ return true;
37
+ }
38
+ return options.stringify === true;
39
+ };
40
+
41
+ const pad = (input, maxLength, toNumber) => {
42
+ if (maxLength > 0) {
43
+ let dash = input[0] === '-' ? '-' : '';
44
+ if (dash) input = input.slice(1);
45
+ input = (dash + input.padStart(dash ? maxLength - 1 : maxLength, '0'));
46
+ }
47
+ if (toNumber === false) {
48
+ return String(input);
49
+ }
50
+ return input;
51
+ };
52
+
53
+ const toMaxLen = (input, maxLength) => {
54
+ let negative = input[0] === '-' ? '-' : '';
55
+ if (negative) {
56
+ input = input.slice(1);
57
+ maxLength--;
58
+ }
59
+ while (input.length < maxLength) input = '0' + input;
60
+ return negative ? ('-' + input) : input;
61
+ };
62
+
63
+ const toSequence = (parts, options, maxLen) => {
64
+ parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
65
+ parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
66
+
67
+ let prefix = options.capture ? '' : '?:';
68
+ let positives = '';
69
+ let negatives = '';
70
+ let result;
71
+
72
+ if (parts.positives.length) {
73
+ positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
74
+ }
75
+
76
+ if (parts.negatives.length) {
77
+ negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
78
+ }
79
+
80
+ if (positives && negatives) {
81
+ result = `${positives}|${negatives}`;
82
+ } else {
83
+ result = positives || negatives;
84
+ }
85
+
86
+ if (options.wrap) {
87
+ return `(${prefix}${result})`;
88
+ }
89
+
90
+ return result;
91
+ };
92
+
93
+ const toRange = (a, b, isNumbers, options) => {
94
+ if (isNumbers) {
95
+ return toRegexRange(a, b, { wrap: false, ...options });
96
+ }
97
+
98
+ let start = String.fromCharCode(a);
99
+ if (a === b) return start;
100
+
101
+ let stop = String.fromCharCode(b);
102
+ return `[${start}-${stop}]`;
103
+ };
104
+
105
+ const toRegex = (start, end, options) => {
106
+ if (Array.isArray(start)) {
107
+ let wrap = options.wrap === true;
108
+ let prefix = options.capture ? '' : '?:';
109
+ return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
110
+ }
111
+ return toRegexRange(start, end, options);
112
+ };
113
+
114
+ const rangeError = (...args) => {
115
+ return new RangeError('Invalid range arguments: ' + util.inspect(...args));
116
+ };
117
+
118
+ const invalidRange = (start, end, options) => {
119
+ if (options.strictRanges === true) throw rangeError([start, end]);
120
+ return [];
121
+ };
122
+
123
+ const invalidStep = (step, options) => {
124
+ if (options.strictRanges === true) {
125
+ throw new TypeError(`Expected step "${step}" to be a number`);
126
+ }
127
+ return [];
128
+ };
129
+
130
+ const fillNumbers = (start, end, step = 1, options = {}) => {
131
+ let a = Number(start);
132
+ let b = Number(end);
133
+
134
+ if (!Number.isInteger(a) || !Number.isInteger(b)) {
135
+ if (options.strictRanges === true) throw rangeError([start, end]);
136
+ return [];
137
+ }
138
+
139
+ // fix negative zero
140
+ if (a === 0) a = 0;
141
+ if (b === 0) b = 0;
142
+
143
+ let descending = a > b;
144
+ let startString = String(start);
145
+ let endString = String(end);
146
+ let stepString = String(step);
147
+ step = Math.max(Math.abs(step), 1);
148
+
149
+ let padded = zeros(startString) || zeros(endString) || zeros(stepString);
150
+ let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
151
+ let toNumber = padded === false && stringify(start, end, options) === false;
152
+ let format = options.transform || transform(toNumber);
153
+
154
+ if (options.toRegex && step === 1) {
155
+ return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
156
+ }
157
+
158
+ let parts = { negatives: [], positives: [] };
159
+ let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
160
+ let range = [];
161
+ let index = 0;
162
+
163
+ while (descending ? a >= b : a <= b) {
164
+ if (options.toRegex === true && step > 1) {
165
+ push(a);
166
+ } else {
167
+ range.push(pad(format(a, index), maxLen, toNumber));
168
+ }
169
+ a = descending ? a - step : a + step;
170
+ index++;
171
+ }
172
+
173
+ if (options.toRegex === true) {
174
+ return step > 1
175
+ ? toSequence(parts, options, maxLen)
176
+ : toRegex(range, null, { wrap: false, ...options });
177
+ }
178
+
179
+ return range;
180
+ };
181
+
182
+ const fillLetters = (start, end, step = 1, options = {}) => {
183
+ if ((!isNumber(start) && start.length > 1) || (!isNumber(end) && end.length > 1)) {
184
+ return invalidRange(start, end, options);
185
+ }
186
+
187
+ let format = options.transform || (val => String.fromCharCode(val));
188
+ let a = `${start}`.charCodeAt(0);
189
+ let b = `${end}`.charCodeAt(0);
190
+
191
+ let descending = a > b;
192
+ let min = Math.min(a, b);
193
+ let max = Math.max(a, b);
194
+
195
+ if (options.toRegex && step === 1) {
196
+ return toRange(min, max, false, options);
197
+ }
198
+
199
+ let range = [];
200
+ let index = 0;
201
+
202
+ while (descending ? a >= b : a <= b) {
203
+ range.push(format(a, index));
204
+ a = descending ? a - step : a + step;
205
+ index++;
206
+ }
207
+
208
+ if (options.toRegex === true) {
209
+ return toRegex(range, null, { wrap: false, options });
210
+ }
211
+
212
+ return range;
213
+ };
214
+
215
+ const fill = (start, end, step, options = {}) => {
216
+ if (end == null && isValidValue(start)) {
217
+ return [start];
218
+ }
219
+
220
+ if (!isValidValue(start) || !isValidValue(end)) {
221
+ return invalidRange(start, end, options);
222
+ }
223
+
224
+ if (typeof step === 'function') {
225
+ return fill(start, end, 1, { transform: step });
226
+ }
227
+
228
+ if (isObject(step)) {
229
+ return fill(start, end, 0, step);
230
+ }
231
+
232
+ let opts = { ...options };
233
+ if (opts.capture === true) opts.wrap = true;
234
+ step = step || opts.step || 1;
235
+
236
+ if (!isNumber(step)) {
237
+ if (step != null && !isObject(step)) return invalidStep(step, opts);
238
+ return fill(start, end, 1, step);
239
+ }
240
+
241
+ if (isNumber(start) && isNumber(end)) {
242
+ return fillNumbers(start, end, step, opts);
243
+ }
244
+
245
+ return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
246
+ };
247
+
248
+ module.exports = fill;
web/node_modules/fill-range/package.json ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "fill-range",
3
+ "description": "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`",
4
+ "version": "7.1.1",
5
+ "homepage": "https://github.com/jonschlinkert/fill-range",
6
+ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7
+ "contributors": [
8
+ "Edo Rivai (edo.rivai.nl)",
9
+ "Jon Schlinkert (http://twitter.com/jonschlinkert)",
10
+ "Paul Miller (paulmillr.com)",
11
+ "Rouven Weßling (www.rouvenwessling.de)",
12
+ "(https://github.com/wtgtybhertgeghgtwtg)"
13
+ ],
14
+ "repository": "jonschlinkert/fill-range",
15
+ "bugs": {
16
+ "url": "https://github.com/jonschlinkert/fill-range/issues"
17
+ },
18
+ "license": "MIT",
19
+ "files": [
20
+ "index.js"
21
+ ],
22
+ "main": "index.js",
23
+ "engines": {
24
+ "node": ">=8"
25
+ },
26
+ "scripts": {
27
+ "lint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ignore-path .gitignore .",
28
+ "mocha": "mocha --reporter dot",
29
+ "test": "npm run lint && npm run mocha",
30
+ "test:ci": "npm run test:cover",
31
+ "test:cover": "nyc npm run mocha"
32
+ },
33
+ "dependencies": {
34
+ "to-regex-range": "^5.0.1"
35
+ },
36
+ "devDependencies": {
37
+ "gulp-format-md": "^2.0.0",
38
+ "mocha": "^6.1.1",
39
+ "nyc": "^15.1.0"
40
+ },
41
+ "keywords": [
42
+ "alpha",
43
+ "alphabetical",
44
+ "array",
45
+ "bash",
46
+ "brace",
47
+ "expand",
48
+ "expansion",
49
+ "fill",
50
+ "glob",
51
+ "match",
52
+ "matches",
53
+ "matching",
54
+ "number",
55
+ "numerical",
56
+ "range",
57
+ "ranges",
58
+ "regex",
59
+ "sh"
60
+ ],
61
+ "verb": {
62
+ "toc": false,
63
+ "layout": "default",
64
+ "tasks": [
65
+ "readme"
66
+ ],
67
+ "plugins": [
68
+ "gulp-format-md"
69
+ ],
70
+ "lint": {
71
+ "reflinks": true
72
+ }
73
+ }
74
+ }
web/node_modules/fraction.js/CHANGELOG.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CHANGELOG
2
+
3
+ v5.2.2
4
+ - Improved documentation and removed unecessary check
5
+
6
+ v5.2.1:
7
+ - 2bb7b05: Added negative sign check
8
+
9
+ v5.2:
10
+ - 6f9d124: Implemented log and improved simplify
11
+ - b773e7a: Added named export to TS definition
12
+ - 70304f9: Fixed merge conflict
13
+ - 3b940d3: Implemented other comparing functions
14
+ - 10acdfc: Update README.md
15
+ - ba41d00: Update README.md
16
+ - 73ded97: Update README.md
17
+ - acabc39: Fixed param parsing
18
+
19
+ v5.0.5:
20
+ - 2c9d4c2: Improved roundTo() and param parser
21
+
22
+ v5.0.4:
23
+ - 39e61e7: Fixed bignum param passing
24
+
25
+ v5.0.3:
26
+ - 7d9a3ec: Upgraded bundler for code quality
27
+
28
+ v5.0.2:
29
+ - c64b1d6: fixed esm export
30
+
31
+ v5.0.1:
32
+ - e440f9c: Fixed CJS export
33
+ - 9bbdd29: Fixed CJS export
34
+
35
+ v5.0.0:
36
+ - ac7cd06: Fixed readme
37
+ - 33cc9e5: Added crude build
38
+ - 1adcc76: Release breaking v5.0. Fraction.js now builds on BigInt. The API stays the same as v4, except that the object attributes `n`, `d`, and `s`, are not Number but BigInt and may break code that directly accesses these attributes.
web/node_modules/fraction.js/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Robert Eisele
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
web/node_modules/fraction.js/README.md ADDED
@@ -0,0 +1,520 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fraction.js - ℚ in JavaScript
2
+
3
+ [![NPM Package](https://img.shields.io/npm/v/fraction.js.svg?style=flat)](https://npmjs.org/package/fraction.js "View this project on npm")
4
+ [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
5
+
6
+ Do you find the limitations of floating-point arithmetic frustrating, especially when rational and irrational numbers like π or √2 are stored within the same finite precision? This can lead to avoidable inaccuracies such as:
7
+
8
+ ```javascript
9
+ 1 / 98 * 98 // Results in 0.9999999999999999
10
+ ```
11
+
12
+ For applications requiring higher precision or where working with fractions is preferable, consider incorporating *Fraction.js* into your project.
13
+
14
+ The library effectively addresses precision issues, as demonstrated below:
15
+
16
+ ```javascript
17
+ Fraction(1).div(98).mul(98) // Returns 1
18
+ ```
19
+
20
+ *Fraction.js* uses a `BigInt` representation for both the numerator and denominator, ensuring minimal performance overhead while maximizing accuracy. Its design is optimized for precision, making it an ideal choice as a foundational library for other math tools, such as [Polynomial.js](https://github.com/rawify/Polynomial.js) and [Math.js](https://github.com/josdejong/mathjs).
21
+
22
+ ## Convert Decimal to Fraction
23
+
24
+ One of the core features of *Fraction.js* is its ability to seamlessly convert decimal numbers into fractions.
25
+
26
+ ```javascript
27
+ let x = new Fraction(1.88);
28
+ let res = x.toFraction(true); // Returns "1 22/25" as a string
29
+ ```
30
+
31
+ This is particularly useful when you need precise fraction representations instead of dealing with the limitations of floating-point arithmetic. What if you allow some error tolerance?
32
+
33
+ ```javascript
34
+ let x = new Fraction(0.33333);
35
+ let res = x.simplify(0.001) // Error < 0.001
36
+ .toFraction(); // Returns "1/3" as a string
37
+ ```
38
+
39
+ ## Precision
40
+
41
+ As native `BigInt` support in JavaScript becomes more common, libraries like *Fraction.js* use it to handle calculations with higher precision. This improves the speed and accuracy of math operations with large numbers, providing a better solution for tasks that need more precision than floating-point numbers can offer.
42
+
43
+ ## Examples / Motivation
44
+
45
+ A simple example of using *Fraction.js* might look like this:
46
+
47
+ ```javascript
48
+ var f = new Fraction("9.4'31'"); // 9.4313131313131...
49
+ f.mul([-4, 3]).mod("4.'8'"); // 4.88888888888888...
50
+ ```
51
+
52
+ The result can then be displayed as:
53
+
54
+ ```javascript
55
+ console.log(f.toFraction()); // -4154 / 1485
56
+ ```
57
+
58
+ Additionally, you can access the internal attributes of the fraction, such as the sign (s), numerator (n), and denominator (d). Keep in mind that these values are stored as `BigInt`:
59
+
60
+ ```javascript
61
+ Number(f.s) * Number(f.n) / Number(f.d) = -1 * 4154 / 1485 = -2.797306...
62
+ ```
63
+
64
+ If you attempted to calculate this manually using floating-point arithmetic, you'd get something like:
65
+
66
+ ```javascript
67
+ (9.4313131 * (-4 / 3)) % 4.888888 = -2.797308133...
68
+ ```
69
+
70
+ While the result is reasonably close, it’s not as accurate as the fraction-based approach that *Fraction.js* provides, especially when dealing with repeating decimals or complex operations. This highlights the value of precision that the library brings.
71
+
72
+ ### Laplace Probability
73
+
74
+ Here's a straightforward example of using *Fraction.js* to calculate probabilities. Let's determine the probability of rolling a specific outcome on a fair die:
75
+
76
+ - **P({3})**: The probability of rolling a 3.
77
+ - **P({1, 4})**: The probability of rolling either 1 or 4.
78
+ - **P({2, 4, 6})**: The probability of rolling 2, 4, or 6.
79
+
80
+ #### P({3}):
81
+
82
+ ```javascript
83
+ var p = new Fraction([3].length, 6).toString(); // "0.1(6)"
84
+ ```
85
+
86
+ #### P({1, 4}):
87
+
88
+ ```javascript
89
+ var p = new Fraction([1, 4].length, 6).toString(); // "0.(3)"
90
+ ```
91
+
92
+ #### P({2, 4, 6}):
93
+
94
+ ```javascript
95
+ var p = new Fraction([2, 4, 6].length, 6).toString(); // "0.5"
96
+ ```
97
+
98
+ ### Convert degrees/minutes/seconds to precise rational representation:
99
+
100
+ 57+45/60+17/3600
101
+
102
+ ```javascript
103
+ var deg = 57; // 57°
104
+ var min = 45; // 45 Minutes
105
+ var sec = 17; // 17 Seconds
106
+
107
+ new Fraction(deg).add(min, 60).add(sec, 3600).toString() // -> 57.7547(2)
108
+ ```
109
+
110
+
111
+ ### Rational approximation of irrational numbers
112
+
113
+ To approximate a number like *sqrt(5) - 2* with a numerator and denominator, you can reformat the equation as follows: *pow(n / d + 2, 2) = 5*.
114
+
115
+ Then the following algorithm will generate the rational number besides the binary representation.
116
+
117
+ ```javascript
118
+ var x = "/", s = "";
119
+
120
+ var a = new Fraction(0),
121
+ b = new Fraction(1);
122
+ for (var n = 0; n <= 10; n++) {
123
+
124
+ var c = a.add(b).div(2);
125
+
126
+ console.log(n + "\t" + a + "\t" + b + "\t" + c + "\t" + x);
127
+
128
+ if (c.add(2).pow(2).valueOf() < 5) {
129
+ a = c;
130
+ x = "1";
131
+ } else {
132
+ b = c;
133
+ x = "0";
134
+ }
135
+ s+= x;
136
+ }
137
+ console.log(s)
138
+ ```
139
+
140
+ The result is
141
+
142
+ ```
143
+ n a[n] b[n] c[n] x[n]
144
+ 0 0/1 1/1 1/2 /
145
+ 1 0/1 1/2 1/4 0
146
+ 2 0/1 1/4 1/8 0
147
+ 3 1/8 1/4 3/16 1
148
+ 4 3/16 1/4 7/32 1
149
+ 5 7/32 1/4 15/64 1
150
+ 6 15/64 1/4 31/128 1
151
+ 7 15/64 31/128 61/256 0
152
+ 8 15/64 61/256 121/512 0
153
+ 9 15/64 121/512 241/1024 0
154
+ 10 241/1024 121/512 483/2048 1
155
+ ```
156
+
157
+ Thus the approximation after 11 iterations of the bisection method is *483 / 2048* and the binary representation is 0.00111100011 (see [WolframAlpha](http://www.wolframalpha.com/input/?i=sqrt%285%29-2+binary))
158
+
159
+ I published another example on how to approximate PI with fraction.js on my [blog](https://raw.org/article/rational-numbers-in-javascript/) (Still not the best idea to approximate irrational numbers, but it illustrates the capabilities of Fraction.js perfectly).
160
+
161
+
162
+ ### Get the exact fractional part of a number
163
+
164
+ ```javascript
165
+ var f = new Fraction("-6.(3416)");
166
+ console.log(f.mod(1).abs().toFraction()); // = 3416/9999
167
+ ```
168
+
169
+ ### Mathematical correct modulo
170
+
171
+ The behaviour on negative congruences is different to most modulo implementations in computer science. Even the *mod()* function of Fraction.js behaves in the typical way. To solve the problem of having the mathematical correct modulo with Fraction.js you could come up with this:
172
+
173
+ ```javascript
174
+ var a = -1;
175
+ var b = 10.99;
176
+
177
+ console.log(new Fraction(a)
178
+ .mod(b)); // Not correct, usual Modulo
179
+
180
+ console.log(new Fraction(a)
181
+ .mod(b).add(b).mod(b)); // Correct! Mathematical Modulo
182
+ ```
183
+
184
+ fmod() imprecision circumvented
185
+ ---
186
+ It turns out that Fraction.js outperforms almost any fmod() implementation, including JavaScript itself, [php.js](http://phpjs.org/functions/fmod/), C++, Python, Java and even Wolframalpha due to the fact that numbers like 0.05, 0.1, ... are infinite decimal in base 2.
187
+
188
+ The equation *fmod(4.55, 0.05)* gives *0.04999999999999957*, wolframalpha says *1/20*. The correct answer should be **zero**, as 0.05 divides 4.55 without any remainder.
189
+
190
+
191
+ ## Parser
192
+
193
+ Any function (see below) as well as the constructor of the *Fraction* class parses its input and reduce it to the smallest term.
194
+
195
+ You can pass either Arrays, Objects, Integers, Doubles or Strings.
196
+
197
+ ### Arrays / Objects
198
+
199
+ ```javascript
200
+ new Fraction(numerator, denominator);
201
+ new Fraction([numerator, denominator]);
202
+ new Fraction({n: numerator, d: denominator});
203
+ ```
204
+
205
+ ### Integers
206
+
207
+ ```javascript
208
+ new Fraction(123);
209
+ ```
210
+
211
+ ### Doubles
212
+
213
+ ```javascript
214
+ new Fraction(55.4);
215
+ ```
216
+
217
+ **Note:** If you pass a double as it is, Fraction.js will perform a number analysis based on Farey Sequences. If you concern performance, cache Fraction.js objects and pass arrays/objects.
218
+
219
+ The method is really precise, but too large exact numbers, like 1234567.9991829 will result in a wrong approximation. If you want to keep the number as it is, convert it to a string, as the string parser will not perform any further observations. If you have problems with the approximation, in the file `examples/approx.js` is a different approximation algorithm, which might work better in some more specific use-cases.
220
+
221
+
222
+ ### Strings
223
+
224
+ ```javascript
225
+ new Fraction("123.45");
226
+ new Fraction("123/45"); // A rational number represented as two decimals, separated by a slash
227
+ new Fraction("123:45"); // A rational number represented as two decimals, separated by a colon
228
+ new Fraction("4 123/45"); // A rational number represented as a whole number and a fraction
229
+ new Fraction("123.'456'"); // Note the quotes, see below!
230
+ new Fraction("123.(456)"); // Note the brackets, see below!
231
+ new Fraction("123.45'6'"); // Note the quotes, see below!
232
+ new Fraction("123.45(6)"); // Note the brackets, see below!
233
+ ```
234
+
235
+ ### Two arguments
236
+
237
+ ```javascript
238
+ new Fraction(3, 2); // 3/2 = 1.5
239
+ ```
240
+
241
+ ### Repeating decimal places
242
+
243
+ *Fraction.js* can easily handle repeating decimal places. For example *1/3* is *0.3333...*. There is only one repeating digit. As you can see in the examples above, you can pass a number like *1/3* as "0.'3'" or "0.(3)", which are synonym. There are no tests to parse something like 0.166666666 to 1/6! If you really want to handle this number, wrap around brackets on your own with the function below for example: 0.1(66666666)
244
+
245
+ Assume you want to divide 123.32 / 33.6(567). [WolframAlpha](http://www.wolframalpha.com/input/?i=123.32+%2F+%2812453%2F370%29) states that you'll get a period of 1776 digits. *Fraction.js* comes to the same result. Give it a try:
246
+
247
+ ```javascript
248
+ var f = new Fraction("123.32");
249
+ console.log("Bam: " + f.div("33.6(567)"));
250
+ ```
251
+
252
+ To automatically make a number like "0.123123123" to something more Fraction.js friendly like "0.(123)", I hacked this little brute force algorithm in a 10 minutes. Improvements are welcome...
253
+
254
+ ```javascript
255
+ function formatDecimal(str) {
256
+
257
+ var comma, pre, offset, pad, times, repeat;
258
+
259
+ if (-1 === (comma = str.indexOf(".")))
260
+ return str;
261
+
262
+ pre = str.substr(0, comma + 1);
263
+ str = str.substr(comma + 1);
264
+
265
+ for (var i = 0; i < str.length; i++) {
266
+
267
+ offset = str.substr(0, i);
268
+
269
+ for (var j = 0; j < 5; j++) {
270
+
271
+ pad = str.substr(i, j + 1);
272
+
273
+ times = Math.ceil((str.length - offset.length) / pad.length);
274
+
275
+ repeat = new Array(times + 1).join(pad); // Silly String.repeat hack
276
+
277
+ if (0 === (offset + repeat).indexOf(str)) {
278
+ return pre + offset + "(" + pad + ")";
279
+ }
280
+ }
281
+ }
282
+ return null;
283
+ }
284
+
285
+ var f, x = formatDecimal("13.0123123123"); // = 13.0(123)
286
+ if (x !== null) {
287
+ f = new Fraction(x);
288
+ }
289
+ ```
290
+
291
+ ## Attributes
292
+
293
+
294
+ The Fraction object allows direct access to the numerator, denominator and sign attributes. It is ensured that only the sign-attribute holds sign information so that a sign comparison is only necessary against this attribute.
295
+
296
+ ```javascript
297
+ var f = new Fraction('-1/2');
298
+ console.log(f.n); // Numerator: 1
299
+ console.log(f.d); // Denominator: 2
300
+ console.log(f.s); // Sign: -1
301
+ ```
302
+
303
+
304
+ ## Functions
305
+
306
+ ### Fraction abs()
307
+
308
+ Returns the actual number without any sign information
309
+
310
+ ### Fraction neg()
311
+
312
+ Returns the actual number with flipped sign in order to get the additive inverse
313
+
314
+ ### Fraction add(n)
315
+
316
+ Returns the sum of the actual number and the parameter n
317
+
318
+ ### Fraction sub(n)
319
+
320
+ Returns the difference of the actual number and the parameter n
321
+
322
+ ### Fraction mul(n)
323
+
324
+ Returns the product of the actual number and the parameter n
325
+
326
+ ### Fraction div(n)
327
+
328
+ Returns the quotient of the actual number and the parameter n
329
+
330
+ ### Fraction pow(exp)
331
+
332
+ Returns the power of the actual number, raised to an possible rational exponent. If the result becomes non-rational the function returns `null`.
333
+
334
+ ### Fraction log(base)
335
+
336
+ Returns the logarithm of the actual number to a given rational base. If the result becomes non-rational the function returns `null`.
337
+
338
+ ### Fraction mod(n)
339
+
340
+ Returns the modulus (rest of the division) of the actual object and n (this % n). It's a much more precise [fmod()](#fmod-impreciseness-circumvented) if you like. Please note that *mod()* is just like the modulo operator of most programming languages. If you want a mathematical correct modulo, see [here](#mathematical-correct-modulo).
341
+
342
+ ### Fraction mod()
343
+
344
+ Returns the modulus (rest of the division) of the actual object (numerator mod denominator)
345
+
346
+ ### Fraction gcd(n)
347
+
348
+ Returns the fractional greatest common divisor
349
+
350
+ ### Fraction lcm(n)
351
+
352
+ Returns the fractional least common multiple
353
+
354
+ ### Fraction ceil([places=0-16])
355
+
356
+ Returns the ceiling of a rational number with Math.ceil
357
+
358
+ ### Fraction floor([places=0-16])
359
+
360
+ Returns the floor of a rational number with Math.floor
361
+
362
+ ### Fraction round([places=0-16])
363
+
364
+ Returns the rational number rounded with Math.round
365
+
366
+ ### Fraction roundTo(multiple)
367
+
368
+ Rounds a fraction to the closest multiple of another fraction.
369
+
370
+ ### Fraction inverse()
371
+
372
+ Returns the multiplicative inverse of the actual number (n / d becomes d / n) in order to get the reciprocal
373
+
374
+ ### Fraction simplify([eps=0.001])
375
+
376
+ Simplifies the rational number under a certain error threshold. Ex. `0.333` will be `1/3` with `eps=0.001`
377
+
378
+ ### boolean equals(n)
379
+
380
+ Check if two rational numbers are equal
381
+
382
+ ### boolean lt(n)
383
+
384
+ Check if this rational number is less than another
385
+
386
+ ### boolean lte(n)
387
+
388
+ Check if this rational number is less than or equal another
389
+
390
+ ### boolean gt(n)
391
+
392
+ Check if this rational number is greater than another
393
+
394
+ ### boolean gte(n)
395
+
396
+ Check if this rational number is greater than or equal another
397
+
398
+ ### int compare(n)
399
+
400
+ Compare two numbers.
401
+ ```
402
+ result < 0: n is greater than actual number
403
+ result > 0: n is smaller than actual number
404
+ result = 0: n is equal to the actual number
405
+ ```
406
+
407
+ ### boolean divisible(n)
408
+
409
+ Check if two numbers are divisible (n divides this)
410
+
411
+ ### double valueOf()
412
+
413
+ Returns a decimal representation of the fraction
414
+
415
+ ### String toString([decimalPlaces=15])
416
+
417
+ Generates an exact string representation of the given object. For repeating decimal places, digits within repeating cycles are enclosed in parentheses, e.g., `1/3 = "0.(3)"`. For other numbers, the string will include up to the specified `decimalPlaces` significant digits, including any trailing zeros if truncation occurs. For example, `1/2` will be represented as `"0.5"`, without additional trailing zeros.
418
+
419
+ **Note:** Since both `valueOf()` and `toString()` are provided, `toString()` will only be invoked implicitly when the object is used in a string context. For instance, when using the plus operator like `"123" + new Fraction`, `valueOf()` will be called first, as JavaScript attempts to combine primitives before concatenating them, with the string type taking precedence. However, `alert(new Fraction)` or `String(new Fraction)` will behave as expected. To ensure specific behavior, explicitly call either `toString()` or `valueOf()`.
420
+
421
+ ### String toLatex(showMixed=false)
422
+
423
+ Generates an exact LaTeX representation of the actual object. You can see a [live demo](https://raw.org/article/rational-numbers-in-javascript/) on my blog.
424
+
425
+ The optional boolean parameter indicates if you want to show the a mixed fraction. "1 1/3" instead of "4/3"
426
+
427
+ ### String toFraction(showMixed=false)
428
+
429
+ Gets a string representation of the fraction
430
+
431
+ The optional boolean parameter indicates if you want to showa mixed fraction. "1 1/3" instead of "4/3"
432
+
433
+ ### Array toContinued()
434
+
435
+ Gets an array of the fraction represented as a continued fraction. The first element always contains the whole part.
436
+
437
+ ```javascript
438
+ var f = new Fraction('88/33');
439
+ var c = f.toContinued(); // [2, 1, 2]
440
+ ```
441
+
442
+ ### Fraction clone()
443
+
444
+ Creates a copy of the actual Fraction object
445
+
446
+
447
+ ## Exceptions
448
+
449
+ If a really hard error occurs (parsing error, division by zero), *Fraction.js* throws exceptions! Please make sure you handle them correctly.
450
+
451
+
452
+ ## Installation
453
+
454
+ You can install `Fraction.js` via npm:
455
+
456
+ ```bash
457
+ npm install fraction.js
458
+ ```
459
+
460
+ Or with yarn:
461
+
462
+ ```bash
463
+ yarn add fraction.js
464
+ ```
465
+
466
+ Alternatively, download or clone the repository:
467
+
468
+ ```bash
469
+ git clone https://github.com/rawify/Fraction.js
470
+ ```
471
+
472
+ ## Usage
473
+
474
+ Include the `fraction.min.js` file in your project:
475
+
476
+ ```html
477
+ <script src="path/to/fraction.min.js"></script>
478
+ <script>
479
+ var x = new Fraction("13/4");
480
+ </script>
481
+ ```
482
+
483
+ Or in a Node.js project:
484
+
485
+ ```javascript
486
+ const Fraction = require('fraction.js');
487
+ ```
488
+
489
+ or
490
+
491
+ ```javascript
492
+ import Fraction from 'fraction.js';
493
+ ```
494
+
495
+
496
+ ## Coding Style
497
+
498
+ As every library I publish, Fraction.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
499
+
500
+ ## Building the library
501
+
502
+ After cloning the Git repository run:
503
+
504
+ ```bash
505
+ npm install
506
+ npm run build
507
+ ```
508
+
509
+ ## Run a test
510
+
511
+ Testing the source against the shipped test suite is as easy as
512
+
513
+ ```bash
514
+ npm run test
515
+ ```
516
+
517
+ ## Copyright and Licensing
518
+
519
+ Copyright (c) 2025, [Robert Eisele](https://raw.org/)
520
+ Licensed under the MIT license.
web/node_modules/fraction.js/dist/fraction.js ADDED
@@ -0,0 +1,1045 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /**
4
+ *
5
+ * This class offers the possibility to calculate fractions.
6
+ * You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
7
+ *
8
+ * Array/Object form
9
+ * [ 0 => <numerator>, 1 => <denominator> ]
10
+ * { n => <numerator>, d => <denominator> }
11
+ *
12
+ * Integer form
13
+ * - Single integer value as BigInt or Number
14
+ *
15
+ * Double form
16
+ * - Single double value as Number
17
+ *
18
+ * String form
19
+ * 123.456 - a simple double
20
+ * 123/456 - a string fraction
21
+ * 123.'456' - a double with repeating decimal places
22
+ * 123.(456) - synonym
23
+ * 123.45'6' - a double with repeating last place
24
+ * 123.45(6) - synonym
25
+ *
26
+ * Example:
27
+ * let f = new Fraction("9.4'31'");
28
+ * f.mul([-4, 3]).div(4.9);
29
+ *
30
+ */
31
+
32
+ // Set Identity function to downgrade BigInt to Number if needed
33
+ if (typeof BigInt === 'undefined') BigInt = function (n) { if (isNaN(n)) throw new Error(""); return n; };
34
+
35
+ const C_ZERO = BigInt(0);
36
+ const C_ONE = BigInt(1);
37
+ const C_TWO = BigInt(2);
38
+ const C_THREE = BigInt(3);
39
+ const C_FIVE = BigInt(5);
40
+ const C_TEN = BigInt(10);
41
+ const MAX_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
42
+
43
+ // Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
44
+ // Example: 1/7 = 0.(142857) has 6 repeating decimal places.
45
+ // If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
46
+ const MAX_CYCLE_LEN = 2000;
47
+
48
+ // Parsed data to avoid calling "new" all the time
49
+ const P = {
50
+ "s": C_ONE,
51
+ "n": C_ZERO,
52
+ "d": C_ONE
53
+ };
54
+
55
+ function assign(n, s) {
56
+
57
+ try {
58
+ n = BigInt(n);
59
+ } catch (e) {
60
+ throw InvalidParameter();
61
+ }
62
+ return n * s;
63
+ }
64
+
65
+ function ifloor(x) {
66
+ return typeof x === 'bigint' ? x : Math.floor(x);
67
+ }
68
+
69
+ // Creates a new Fraction internally without the need of the bulky constructor
70
+ function newFraction(n, d) {
71
+
72
+ if (d === C_ZERO) {
73
+ throw DivisionByZero();
74
+ }
75
+
76
+ const f = Object.create(Fraction.prototype);
77
+ f["s"] = n < C_ZERO ? -C_ONE : C_ONE;
78
+
79
+ n = n < C_ZERO ? -n : n;
80
+
81
+ const a = gcd(n, d);
82
+
83
+ f["n"] = n / a;
84
+ f["d"] = d / a;
85
+ return f;
86
+ }
87
+
88
+ const FACTORSTEPS = [C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO * C_THREE, C_TWO, C_TWO * C_THREE]; // repeats
89
+ function factorize(n) {
90
+
91
+ const factors = Object.create(null);
92
+ if (n <= C_ONE) {
93
+ factors[n] = C_ONE;
94
+ return factors;
95
+ }
96
+
97
+ const add = (p) => { factors[p] = (factors[p] || C_ZERO) + C_ONE; };
98
+
99
+ while (n % C_TWO === C_ZERO) { add(C_TWO); n /= C_TWO; }
100
+ while (n % C_THREE === C_ZERO) { add(C_THREE); n /= C_THREE; }
101
+ while (n % C_FIVE === C_ZERO) { add(C_FIVE); n /= C_FIVE; }
102
+
103
+ // 30-wheel trial division: test only residues coprime to 2*3*5
104
+ // Residue step pattern after 5: 7,11,13,17,19,23,29,31, ...
105
+ for (let si = 0, p = C_TWO + C_FIVE; p * p <= n;) {
106
+ while (n % p === C_ZERO) { add(p); n /= p; }
107
+ p += FACTORSTEPS[si];
108
+ si = (si + 1) & 7; // fast modulo 8
109
+ }
110
+ if (n > C_ONE) add(n);
111
+ return factors;
112
+ }
113
+
114
+ const parse = function (p1, p2) {
115
+
116
+ let n = C_ZERO, d = C_ONE, s = C_ONE;
117
+
118
+ if (p1 === undefined || p1 === null) { // No argument
119
+ /* void */
120
+ } else if (p2 !== undefined) { // Two arguments
121
+
122
+ if (typeof p1 === "bigint") {
123
+ n = p1;
124
+ } else if (isNaN(p1)) {
125
+ throw InvalidParameter();
126
+ } else if (p1 % 1 !== 0) {
127
+ throw NonIntegerParameter();
128
+ } else {
129
+ n = BigInt(p1);
130
+ }
131
+
132
+ if (typeof p2 === "bigint") {
133
+ d = p2;
134
+ } else if (isNaN(p2)) {
135
+ throw InvalidParameter();
136
+ } else if (p2 % 1 !== 0) {
137
+ throw NonIntegerParameter();
138
+ } else {
139
+ d = BigInt(p2);
140
+ }
141
+
142
+ s = n * d;
143
+
144
+ } else if (typeof p1 === "object") {
145
+ if ("d" in p1 && "n" in p1) {
146
+ n = BigInt(p1["n"]);
147
+ d = BigInt(p1["d"]);
148
+ if ("s" in p1)
149
+ n *= BigInt(p1["s"]);
150
+ } else if (0 in p1) {
151
+ n = BigInt(p1[0]);
152
+ if (1 in p1)
153
+ d = BigInt(p1[1]);
154
+ } else if (typeof p1 === "bigint") {
155
+ n = p1;
156
+ } else {
157
+ throw InvalidParameter();
158
+ }
159
+ s = n * d;
160
+ } else if (typeof p1 === "number") {
161
+
162
+ if (isNaN(p1)) {
163
+ throw InvalidParameter();
164
+ }
165
+
166
+ if (p1 < 0) {
167
+ s = -C_ONE;
168
+ p1 = -p1;
169
+ }
170
+
171
+ if (p1 % 1 === 0) {
172
+ n = BigInt(p1);
173
+ } else {
174
+
175
+ let z = 1;
176
+
177
+ let A = 0, B = 1;
178
+ let C = 1, D = 1;
179
+
180
+ let N = 10000000;
181
+
182
+ if (p1 >= 1) {
183
+ z = 10 ** Math.floor(1 + Math.log10(p1));
184
+ p1 /= z;
185
+ }
186
+
187
+ // Using Farey Sequences
188
+
189
+ while (B <= N && D <= N) {
190
+ let M = (A + C) / (B + D);
191
+
192
+ if (p1 === M) {
193
+ if (B + D <= N) {
194
+ n = A + C;
195
+ d = B + D;
196
+ } else if (D > B) {
197
+ n = C;
198
+ d = D;
199
+ } else {
200
+ n = A;
201
+ d = B;
202
+ }
203
+ break;
204
+
205
+ } else {
206
+
207
+ if (p1 > M) {
208
+ A += C;
209
+ B += D;
210
+ } else {
211
+ C += A;
212
+ D += B;
213
+ }
214
+
215
+ if (B > N) {
216
+ n = C;
217
+ d = D;
218
+ } else {
219
+ n = A;
220
+ d = B;
221
+ }
222
+ }
223
+ }
224
+ n = BigInt(n) * BigInt(z);
225
+ d = BigInt(d);
226
+ }
227
+
228
+ } else if (typeof p1 === "string") {
229
+
230
+ let ndx = 0;
231
+
232
+ let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;
233
+
234
+ let match = p1.replace(/_/g, '').match(/\d+|./g);
235
+
236
+ if (match === null)
237
+ throw InvalidParameter();
238
+
239
+ if (match[ndx] === '-') {// Check for minus sign at the beginning
240
+ s = -C_ONE;
241
+ ndx++;
242
+ } else if (match[ndx] === '+') {// Check for plus sign at the beginning
243
+ ndx++;
244
+ }
245
+
246
+ if (match.length === ndx + 1) { // Check if it's just a simple number "1234"
247
+ w = assign(match[ndx++], s);
248
+ } else if (match[ndx + 1] === '.' || match[ndx] === '.') { // Check if it's a decimal number
249
+
250
+ if (match[ndx] !== '.') { // Handle 0.5 and .5
251
+ v = assign(match[ndx++], s);
252
+ }
253
+ ndx++;
254
+
255
+ // Check for decimal places
256
+ if (ndx + 1 === match.length || match[ndx + 1] === '(' && match[ndx + 3] === ')' || match[ndx + 1] === "'" && match[ndx + 3] === "'") {
257
+ w = assign(match[ndx], s);
258
+ y = C_TEN ** BigInt(match[ndx].length);
259
+ ndx++;
260
+ }
261
+
262
+ // Check for repeating places
263
+ if (match[ndx] === '(' && match[ndx + 2] === ')' || match[ndx] === "'" && match[ndx + 2] === "'") {
264
+ x = assign(match[ndx + 1], s);
265
+ z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;
266
+ ndx += 3;
267
+ }
268
+
269
+ } else if (match[ndx + 1] === '/' || match[ndx + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
270
+ w = assign(match[ndx], s);
271
+ y = assign(match[ndx + 2], C_ONE);
272
+ ndx += 3;
273
+ } else if (match[ndx + 3] === '/' && match[ndx + 1] === ' ') { // Check for a complex fraction "123 1/2"
274
+ v = assign(match[ndx], s);
275
+ w = assign(match[ndx + 2], s);
276
+ y = assign(match[ndx + 4], C_ONE);
277
+ ndx += 5;
278
+ }
279
+
280
+ if (match.length <= ndx) { // Check for more tokens on the stack
281
+ d = y * z;
282
+ s = /* void */
283
+ n = x + d * v + z * w;
284
+ } else {
285
+ throw InvalidParameter();
286
+ }
287
+
288
+ } else if (typeof p1 === "bigint") {
289
+ n = p1;
290
+ s = p1;
291
+ d = C_ONE;
292
+ } else {
293
+ throw InvalidParameter();
294
+ }
295
+
296
+ if (d === C_ZERO) {
297
+ throw DivisionByZero();
298
+ }
299
+
300
+ P["s"] = s < C_ZERO ? -C_ONE : C_ONE;
301
+ P["n"] = n < C_ZERO ? -n : n;
302
+ P["d"] = d < C_ZERO ? -d : d;
303
+ };
304
+
305
+ function modpow(b, e, m) {
306
+
307
+ let r = C_ONE;
308
+ for (; e > C_ZERO; b = (b * b) % m, e >>= C_ONE) {
309
+
310
+ if (e & C_ONE) {
311
+ r = (r * b) % m;
312
+ }
313
+ }
314
+ return r;
315
+ }
316
+
317
+ function cycleLen(n, d) {
318
+
319
+ for (; d % C_TWO === C_ZERO;
320
+ d /= C_TWO) {
321
+ }
322
+
323
+ for (; d % C_FIVE === C_ZERO;
324
+ d /= C_FIVE) {
325
+ }
326
+
327
+ if (d === C_ONE) // Catch non-cyclic numbers
328
+ return C_ZERO;
329
+
330
+ // If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
331
+ // 10^(d-1) % d == 1
332
+ // However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
333
+ // as we want to translate the numbers to strings.
334
+
335
+ let rem = C_TEN % d;
336
+ let t = 1;
337
+
338
+ for (; rem !== C_ONE; t++) {
339
+ rem = rem * C_TEN % d;
340
+
341
+ if (t > MAX_CYCLE_LEN)
342
+ return C_ZERO; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
343
+ }
344
+ return BigInt(t);
345
+ }
346
+
347
+ function cycleStart(n, d, len) {
348
+
349
+ let rem1 = C_ONE;
350
+ let rem2 = modpow(C_TEN, len, d);
351
+
352
+ for (let t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
353
+ // Solve 10^s == 10^(s+t) (mod d)
354
+
355
+ if (rem1 === rem2)
356
+ return BigInt(t);
357
+
358
+ rem1 = rem1 * C_TEN % d;
359
+ rem2 = rem2 * C_TEN % d;
360
+ }
361
+ return 0;
362
+ }
363
+
364
+ function gcd(a, b) {
365
+
366
+ if (!a)
367
+ return b;
368
+ if (!b)
369
+ return a;
370
+
371
+ while (1) {
372
+ a %= b;
373
+ if (!a)
374
+ return b;
375
+ b %= a;
376
+ if (!b)
377
+ return a;
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Module constructor
383
+ *
384
+ * @constructor
385
+ * @param {number|Fraction=} a
386
+ * @param {number=} b
387
+ */
388
+ function Fraction(a, b) {
389
+
390
+ parse(a, b);
391
+
392
+ if (this instanceof Fraction) {
393
+ a = gcd(P["d"], P["n"]); // Abuse a
394
+ this["s"] = P["s"];
395
+ this["n"] = P["n"] / a;
396
+ this["d"] = P["d"] / a;
397
+ } else {
398
+ return newFraction(P['s'] * P['n'], P['d']);
399
+ }
400
+ }
401
+
402
+ const DivisionByZero = function () { return new Error("Division by Zero"); };
403
+ const InvalidParameter = function () { return new Error("Invalid argument"); };
404
+ const NonIntegerParameter = function () { return new Error("Parameters must be integer"); };
405
+
406
+ Fraction.prototype = {
407
+
408
+ "s": C_ONE,
409
+ "n": C_ZERO,
410
+ "d": C_ONE,
411
+
412
+ /**
413
+ * Calculates the absolute value
414
+ *
415
+ * Ex: new Fraction(-4).abs() => 4
416
+ **/
417
+ "abs": function () {
418
+
419
+ return newFraction(this["n"], this["d"]);
420
+ },
421
+
422
+ /**
423
+ * Inverts the sign of the current fraction
424
+ *
425
+ * Ex: new Fraction(-4).neg() => 4
426
+ **/
427
+ "neg": function () {
428
+
429
+ return newFraction(-this["s"] * this["n"], this["d"]);
430
+ },
431
+
432
+ /**
433
+ * Adds two rational numbers
434
+ *
435
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
436
+ **/
437
+ "add": function (a, b) {
438
+
439
+ parse(a, b);
440
+ return newFraction(
441
+ this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
442
+ this["d"] * P["d"]
443
+ );
444
+ },
445
+
446
+ /**
447
+ * Subtracts two rational numbers
448
+ *
449
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
450
+ **/
451
+ "sub": function (a, b) {
452
+
453
+ parse(a, b);
454
+ return newFraction(
455
+ this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
456
+ this["d"] * P["d"]
457
+ );
458
+ },
459
+
460
+ /**
461
+ * Multiplies two rational numbers
462
+ *
463
+ * Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
464
+ **/
465
+ "mul": function (a, b) {
466
+
467
+ parse(a, b);
468
+ return newFraction(
469
+ this["s"] * P["s"] * this["n"] * P["n"],
470
+ this["d"] * P["d"]
471
+ );
472
+ },
473
+
474
+ /**
475
+ * Divides two rational numbers
476
+ *
477
+ * Ex: new Fraction("-17.(345)").inverse().div(3)
478
+ **/
479
+ "div": function (a, b) {
480
+
481
+ parse(a, b);
482
+ return newFraction(
483
+ this["s"] * P["s"] * this["n"] * P["d"],
484
+ this["d"] * P["n"]
485
+ );
486
+ },
487
+
488
+ /**
489
+ * Clones the actual object
490
+ *
491
+ * Ex: new Fraction("-17.(345)").clone()
492
+ **/
493
+ "clone": function () {
494
+ return newFraction(this['s'] * this['n'], this['d']);
495
+ },
496
+
497
+ /**
498
+ * Calculates the modulo of two rational numbers - a more precise fmod
499
+ *
500
+ * Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
501
+ * Ex: new Fraction(20, 10).mod().equals(0) ? "is Integer"
502
+ **/
503
+ "mod": function (a, b) {
504
+
505
+ if (a === undefined) {
506
+ return newFraction(this["s"] * this["n"] % this["d"], C_ONE);
507
+ }
508
+
509
+ parse(a, b);
510
+ if (C_ZERO === P["n"] * this["d"]) {
511
+ throw DivisionByZero();
512
+ }
513
+
514
+ /**
515
+ * I derived the rational modulo similar to the modulo for integers
516
+ *
517
+ * https://raw.org/book/analysis/rational-numbers/
518
+ *
519
+ * n1/d1 = (n2/d2) * q + r, where 0 ≤ r < n2/d2
520
+ * => d2 * n1 = n2 * d1 * q + d1 * d2 * r
521
+ * => r = (d2 * n1 - n2 * d1 * q) / (d1 * d2)
522
+ * = (d2 * n1 - n2 * d1 * floor((d2 * n1) / (n2 * d1))) / (d1 * d2)
523
+ * = ((d2 * n1) % (n2 * d1)) / (d1 * d2)
524
+ */
525
+ return newFraction(
526
+ this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
527
+ P["d"] * this["d"]);
528
+ },
529
+
530
+ /**
531
+ * Calculates the fractional gcd of two rational numbers
532
+ *
533
+ * Ex: new Fraction(5,8).gcd(3,7) => 1/56
534
+ */
535
+ "gcd": function (a, b) {
536
+
537
+ parse(a, b);
538
+
539
+ // https://raw.org/book/analysis/rational-numbers/
540
+ // gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
541
+
542
+ return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
543
+ },
544
+
545
+ /**
546
+ * Calculates the fractional lcm of two rational numbers
547
+ *
548
+ * Ex: new Fraction(5,8).lcm(3,7) => 15
549
+ */
550
+ "lcm": function (a, b) {
551
+
552
+ parse(a, b);
553
+
554
+ // https://raw.org/book/analysis/rational-numbers/
555
+ // lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
556
+
557
+ if (P["n"] === C_ZERO && this["n"] === C_ZERO) {
558
+ return newFraction(C_ZERO, C_ONE);
559
+ }
560
+ return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
561
+ },
562
+
563
+ /**
564
+ * Gets the inverse of the fraction, means numerator and denominator are exchanged
565
+ *
566
+ * Ex: new Fraction([-3, 4]).inverse() => -4 / 3
567
+ **/
568
+ "inverse": function () {
569
+ return newFraction(this["s"] * this["d"], this["n"]);
570
+ },
571
+
572
+ /**
573
+ * Calculates the fraction to some integer exponent
574
+ *
575
+ * Ex: new Fraction(-1,2).pow(-3) => -8
576
+ */
577
+ "pow": function (a, b) {
578
+
579
+ parse(a, b);
580
+
581
+ // Trivial case when exp is an integer
582
+
583
+ if (P['d'] === C_ONE) {
584
+
585
+ if (P['s'] < C_ZERO) {
586
+ return newFraction((this['s'] * this["d"]) ** P['n'], this["n"] ** P['n']);
587
+ } else {
588
+ return newFraction((this['s'] * this["n"]) ** P['n'], this["d"] ** P['n']);
589
+ }
590
+ }
591
+
592
+ // Negative roots become complex
593
+ // (-a/b)^(c/d) = x
594
+ // ⇔ (-1)^(c/d) * (a/b)^(c/d) = x
595
+ // ⇔ (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x
596
+ // ⇔ (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula
597
+ // From which follows that only for c=0 the root is non-complex
598
+ if (this['s'] < C_ZERO) return null;
599
+
600
+ // Now prime factor n and d
601
+ let N = factorize(this['n']);
602
+ let D = factorize(this['d']);
603
+
604
+ // Exponentiate and take root for n and d individually
605
+ let n = C_ONE;
606
+ let d = C_ONE;
607
+ for (let k in N) {
608
+ if (k === '1') continue;
609
+ if (k === '0') {
610
+ n = C_ZERO;
611
+ break;
612
+ }
613
+ N[k] *= P['n'];
614
+
615
+ if (N[k] % P['d'] === C_ZERO) {
616
+ N[k] /= P['d'];
617
+ } else return null;
618
+ n *= BigInt(k) ** N[k];
619
+ }
620
+
621
+ for (let k in D) {
622
+ if (k === '1') continue;
623
+ D[k] *= P['n'];
624
+
625
+ if (D[k] % P['d'] === C_ZERO) {
626
+ D[k] /= P['d'];
627
+ } else return null;
628
+ d *= BigInt(k) ** D[k];
629
+ }
630
+
631
+ if (P['s'] < C_ZERO) {
632
+ return newFraction(d, n);
633
+ }
634
+ return newFraction(n, d);
635
+ },
636
+
637
+ /**
638
+ * Calculates the logarithm of a fraction to a given rational base
639
+ *
640
+ * Ex: new Fraction(27, 8).log(9, 4) => 3/2
641
+ */
642
+ "log": function (a, b) {
643
+
644
+ parse(a, b);
645
+
646
+ if (this['s'] <= C_ZERO || P['s'] <= C_ZERO) return null;
647
+
648
+ const allPrimes = Object.create(null);
649
+
650
+ const baseFactors = factorize(P['n']);
651
+ const T1 = factorize(P['d']);
652
+
653
+ const numberFactors = factorize(this['n']);
654
+ const T2 = factorize(this['d']);
655
+
656
+ for (const prime in T1) {
657
+ baseFactors[prime] = (baseFactors[prime] || C_ZERO) - T1[prime];
658
+ }
659
+ for (const prime in T2) {
660
+ numberFactors[prime] = (numberFactors[prime] || C_ZERO) - T2[prime];
661
+ }
662
+
663
+ for (const prime in baseFactors) {
664
+ if (prime === '1') continue;
665
+ allPrimes[prime] = true;
666
+ }
667
+ for (const prime in numberFactors) {
668
+ if (prime === '1') continue;
669
+ allPrimes[prime] = true;
670
+ }
671
+
672
+ let retN = null;
673
+ let retD = null;
674
+
675
+ // Iterate over all unique primes to determine if a consistent ratio exists
676
+ for (const prime in allPrimes) {
677
+
678
+ const baseExponent = baseFactors[prime] || C_ZERO;
679
+ const numberExponent = numberFactors[prime] || C_ZERO;
680
+
681
+ if (baseExponent === C_ZERO) {
682
+ if (numberExponent !== C_ZERO) {
683
+ return null; // Logarithm cannot be expressed as a rational number
684
+ }
685
+ continue; // Skip this prime since both exponents are zero
686
+ }
687
+
688
+ // Calculate the ratio of exponents for this prime
689
+ let curN = numberExponent;
690
+ let curD = baseExponent;
691
+
692
+ // Simplify the current ratio
693
+ const gcdValue = gcd(curN, curD);
694
+ curN /= gcdValue;
695
+ curD /= gcdValue;
696
+
697
+ // Check if this is the first ratio; otherwise, ensure ratios are consistent
698
+ if (retN === null && retD === null) {
699
+ retN = curN;
700
+ retD = curD;
701
+ } else if (curN * retD !== retN * curD) {
702
+ return null; // Ratios do not match, logarithm cannot be rational
703
+ }
704
+ }
705
+
706
+ return retN !== null && retD !== null
707
+ ? newFraction(retN, retD)
708
+ : null;
709
+ },
710
+
711
+ /**
712
+ * Check if two rational numbers are the same
713
+ *
714
+ * Ex: new Fraction(19.6).equals([98, 5]);
715
+ **/
716
+ "equals": function (a, b) {
717
+
718
+ parse(a, b);
719
+ return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"];
720
+ },
721
+
722
+ /**
723
+ * Check if this rational number is less than another
724
+ *
725
+ * Ex: new Fraction(19.6).lt([98, 5]);
726
+ **/
727
+ "lt": function (a, b) {
728
+
729
+ parse(a, b);
730
+ return this["s"] * this["n"] * P["d"] < P["s"] * P["n"] * this["d"];
731
+ },
732
+
733
+ /**
734
+ * Check if this rational number is less than or equal another
735
+ *
736
+ * Ex: new Fraction(19.6).lt([98, 5]);
737
+ **/
738
+ "lte": function (a, b) {
739
+
740
+ parse(a, b);
741
+ return this["s"] * this["n"] * P["d"] <= P["s"] * P["n"] * this["d"];
742
+ },
743
+
744
+ /**
745
+ * Check if this rational number is greater than another
746
+ *
747
+ * Ex: new Fraction(19.6).lt([98, 5]);
748
+ **/
749
+ "gt": function (a, b) {
750
+
751
+ parse(a, b);
752
+ return this["s"] * this["n"] * P["d"] > P["s"] * P["n"] * this["d"];
753
+ },
754
+
755
+ /**
756
+ * Check if this rational number is greater than or equal another
757
+ *
758
+ * Ex: new Fraction(19.6).lt([98, 5]);
759
+ **/
760
+ "gte": function (a, b) {
761
+
762
+ parse(a, b);
763
+ return this["s"] * this["n"] * P["d"] >= P["s"] * P["n"] * this["d"];
764
+ },
765
+
766
+ /**
767
+ * Compare two rational numbers
768
+ * < 0 iff this < that
769
+ * > 0 iff this > that
770
+ * = 0 iff this = that
771
+ *
772
+ * Ex: new Fraction(19.6).compare([98, 5]);
773
+ **/
774
+ "compare": function (a, b) {
775
+
776
+ parse(a, b);
777
+ let t = this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"];
778
+
779
+ return (C_ZERO < t) - (t < C_ZERO);
780
+ },
781
+
782
+ /**
783
+ * Calculates the ceil of a rational number
784
+ *
785
+ * Ex: new Fraction('4.(3)').ceil() => (5 / 1)
786
+ **/
787
+ "ceil": function (places) {
788
+
789
+ places = C_TEN ** BigInt(places || 0);
790
+
791
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
792
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
793
+ places);
794
+ },
795
+
796
+ /**
797
+ * Calculates the floor of a rational number
798
+ *
799
+ * Ex: new Fraction('4.(3)').floor() => (4 / 1)
800
+ **/
801
+ "floor": function (places) {
802
+
803
+ places = C_TEN ** BigInt(places || 0);
804
+
805
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) -
806
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
807
+ places);
808
+ },
809
+
810
+ /**
811
+ * Rounds a rational numbers
812
+ *
813
+ * Ex: new Fraction('4.(3)').round() => (4 / 1)
814
+ **/
815
+ "round": function (places) {
816
+
817
+ places = C_TEN ** BigInt(places || 0);
818
+
819
+ /* Derivation:
820
+
821
+ s >= 0:
822
+ round(n / d) = ifloor(n / d) + (n % d) / d >= 0.5 ? 1 : 0
823
+ = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
824
+ s < 0:
825
+ round(n / d) =-ifloor(n / d) - (n % d) / d > 0.5 ? 1 : 0
826
+ =-ifloor(n / d) - 2(n % d) > d ? 1 : 0
827
+
828
+ =>:
829
+
830
+ round(s * n / d) = s * ifloor(n / d) + s * (C + 2(n % d) > d ? 1 : 0)
831
+ where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.
832
+ */
833
+
834
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
835
+ this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
836
+ places);
837
+ },
838
+
839
+ /**
840
+ * Rounds a rational number to a multiple of another rational number
841
+ *
842
+ * Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
843
+ **/
844
+ "roundTo": function (a, b) {
845
+
846
+ /*
847
+ k * x/y ≤ a/b < (k+1) * x/y
848
+ ⇔ k ≤ a/b / (x/y) < (k+1)
849
+ ⇔ k = floor(a/b * y/x)
850
+ ⇔ k = floor((a * y) / (b * x))
851
+ */
852
+
853
+ parse(a, b);
854
+
855
+ const n = this['n'] * P['d'];
856
+ const d = this['d'] * P['n'];
857
+ const r = n % d;
858
+
859
+ // round(n / d) = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
860
+ let k = ifloor(n / d);
861
+ if (r + r >= d) {
862
+ k++;
863
+ }
864
+ return newFraction(this['s'] * k * P['n'], P['d']);
865
+ },
866
+
867
+ /**
868
+ * Check if two rational numbers are divisible
869
+ *
870
+ * Ex: new Fraction(19.6).divisible(1.5);
871
+ */
872
+ "divisible": function (a, b) {
873
+
874
+ parse(a, b);
875
+ if (P['n'] === C_ZERO) return false;
876
+ return (this['n'] * P['d']) % (P['n'] * this['d']) === C_ZERO;
877
+ },
878
+
879
+ /**
880
+ * Returns a decimal representation of the fraction
881
+ *
882
+ * Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
883
+ **/
884
+ 'valueOf': function () {
885
+ //if (this['n'] <= MAX_INTEGER && this['d'] <= MAX_INTEGER) {
886
+ return Number(this['s'] * this['n']) / Number(this['d']);
887
+ //}
888
+ },
889
+
890
+ /**
891
+ * Creates a string representation of a fraction with all digits
892
+ *
893
+ * Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
894
+ **/
895
+ 'toString': function (dec = 15) {
896
+
897
+ let N = this["n"];
898
+ let D = this["d"];
899
+
900
+ let cycLen = cycleLen(N, D); // Cycle length
901
+ let cycOff = cycleStart(N, D, cycLen); // Cycle start
902
+
903
+ let str = this['s'] < C_ZERO ? "-" : "";
904
+
905
+ // Append integer part
906
+ str += ifloor(N / D);
907
+
908
+ N %= D;
909
+ N *= C_TEN;
910
+
911
+ if (N)
912
+ str += ".";
913
+
914
+ if (cycLen) {
915
+
916
+ for (let i = cycOff; i--;) {
917
+ str += ifloor(N / D);
918
+ N %= D;
919
+ N *= C_TEN;
920
+ }
921
+ str += "(";
922
+ for (let i = cycLen; i--;) {
923
+ str += ifloor(N / D);
924
+ N %= D;
925
+ N *= C_TEN;
926
+ }
927
+ str += ")";
928
+ } else {
929
+ for (let i = dec; N && i--;) {
930
+ str += ifloor(N / D);
931
+ N %= D;
932
+ N *= C_TEN;
933
+ }
934
+ }
935
+ return str;
936
+ },
937
+
938
+ /**
939
+ * Returns a string-fraction representation of a Fraction object
940
+ *
941
+ * Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
942
+ **/
943
+ 'toFraction': function (showMixed = false) {
944
+
945
+ let n = this["n"];
946
+ let d = this["d"];
947
+ let str = this['s'] < C_ZERO ? "-" : "";
948
+
949
+ if (d === C_ONE) {
950
+ str += n;
951
+ } else {
952
+ const whole = ifloor(n / d);
953
+ if (showMixed && whole > C_ZERO) {
954
+ str += whole;
955
+ str += " ";
956
+ n %= d;
957
+ }
958
+
959
+ str += n;
960
+ str += '/';
961
+ str += d;
962
+ }
963
+ return str;
964
+ },
965
+
966
+ /**
967
+ * Returns a latex representation of a Fraction object
968
+ *
969
+ * Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
970
+ **/
971
+ 'toLatex': function (showMixed = false) {
972
+
973
+ let n = this["n"];
974
+ let d = this["d"];
975
+ let str = this['s'] < C_ZERO ? "-" : "";
976
+
977
+ if (d === C_ONE) {
978
+ str += n;
979
+ } else {
980
+ const whole = ifloor(n / d);
981
+ if (showMixed && whole > C_ZERO) {
982
+ str += whole;
983
+ n %= d;
984
+ }
985
+
986
+ str += "\\frac{";
987
+ str += n;
988
+ str += '}{';
989
+ str += d;
990
+ str += '}';
991
+ }
992
+ return str;
993
+ },
994
+
995
+ /**
996
+ * Returns an array of continued fraction elements
997
+ *
998
+ * Ex: new Fraction("7/8").toContinued() => [0,1,7]
999
+ */
1000
+ 'toContinued': function () {
1001
+
1002
+ let a = this['n'];
1003
+ let b = this['d'];
1004
+ const res = [];
1005
+
1006
+ while (b) {
1007
+ res.push(ifloor(a / b));
1008
+ const t = a % b;
1009
+ a = b;
1010
+ b = t;
1011
+ }
1012
+ return res;
1013
+ },
1014
+
1015
+ "simplify": function (eps = 1e-3) {
1016
+
1017
+ // Continued fractions give best approximations for a max denominator,
1018
+ // generally outperforming mediants in denominator–accuracy trade-offs.
1019
+ // Semiconvergents can further reduce the denominator within tolerance.
1020
+
1021
+ const ieps = BigInt(Math.ceil(1 / eps));
1022
+
1023
+ const thisABS = this['abs']();
1024
+ const cont = thisABS['toContinued']();
1025
+
1026
+ for (let i = 1; i < cont.length; i++) {
1027
+
1028
+ let s = newFraction(cont[i - 1], C_ONE);
1029
+ for (let k = i - 2; k >= 0; k--) {
1030
+ s = s['inverse']()['add'](cont[k]);
1031
+ }
1032
+
1033
+ let t = s['sub'](thisABS);
1034
+ if (t['n'] * ieps < t['d']) { // More robust than Math.abs(t.valueOf()) < eps
1035
+ return s['mul'](this['s']);
1036
+ }
1037
+ }
1038
+ return this;
1039
+ }
1040
+ };
1041
+
1042
+ Object.defineProperty(Fraction, "__esModule", { 'value': true });
1043
+ Fraction['default'] = Fraction;
1044
+ Fraction['Fraction'] = Fraction;
1045
+ module['exports'] = Fraction;
web/node_modules/fraction.js/dist/fraction.min.js ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.3.4 8/22/2025
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2025, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ 'use strict';(function(F){function D(){return Error("Parameters must be integer")}function x(){return Error("Invalid argument")}function C(){return Error("Division by Zero")}function q(a,b){var d=g,c=h;let f=h;if(void 0!==a&&null!==a)if(void 0!==b){if("bigint"===typeof a)d=a;else{if(isNaN(a))throw x();if(0!==a%1)throw D();d=BigInt(a)}if("bigint"===typeof b)c=b;else{if(isNaN(b))throw x();if(0!==b%1)throw D();c=BigInt(b)}f=d*c}else if("object"===typeof a){if("d"in a&&"n"in a)d=BigInt(a.n),c=BigInt(a.d),
9
+ "s"in a&&(d*=BigInt(a.s));else if(0 in a)d=BigInt(a[0]),1 in a&&(c=BigInt(a[1]));else if("bigint"===typeof a)d=a;else throw x();f=d*c}else if("number"===typeof a){if(isNaN(a))throw x();0>a&&(f=-h,a=-a);if(0===a%1)d=BigInt(a);else{b=1;var k=0,l=1,m=1;let r=1;1<=a&&(b=10**Math.floor(1+Math.log10(a)),a/=b);for(;1E7>=l&&1E7>=r;)if(c=(k+m)/(l+r),a===c){1E7>=l+r?(d=k+m,c=l+r):r>l?(d=m,c=r):(d=k,c=l);break}else a>c?(k+=m,l+=r):(m+=k,r+=l),1E7<l?(d=m,c=r):(d=k,c=l);d=BigInt(d)*BigInt(b);c=BigInt(c)}}else if("string"===
10
+ typeof a){c=0;k=b=d=g;l=m=h;a=a.replace(/_/g,"").match(/\d+|./g);if(null===a)throw x();"-"===a[c]?(f=-h,c++):"+"===a[c]&&c++;if(a.length===c+1)b=w(a[c++],f);else if("."===a[c+1]||"."===a[c]){"."!==a[c]&&(d=w(a[c++],f));c++;if(c+1===a.length||"("===a[c+1]&&")"===a[c+3]||"'"===a[c+1]&&"'"===a[c+3])b=w(a[c],f),m=t**BigInt(a[c].length),c++;if("("===a[c]&&")"===a[c+2]||"'"===a[c]&&"'"===a[c+2])k=w(a[c+1],f),l=t**BigInt(a[c+1].length)-h,c+=3}else"/"===a[c+1]||":"===a[c+1]?(b=w(a[c],f),m=w(a[c+2],h),c+=
11
+ 3):"/"===a[c+3]&&" "===a[c+1]&&(d=w(a[c],f),b=w(a[c+2],f),m=w(a[c+4],h),c+=5);if(a.length<=c)c=m*l,f=d=k+c*d+l*b;else throw x();}else if("bigint"===typeof a)f=d=a,c=h;else throw x();if(c===g)throw C();e.s=f<g?-h:h;e.n=d<g?-d:d;e.d=c<g?-c:c}function w(a,b){try{a=BigInt(a)}catch(d){throw x();}return a*b}function u(a){return"bigint"===typeof a?a:Math.floor(a)}function n(a,b){if(b===g)throw C();const d=Object.create(v.prototype);d.s=a<g?-h:h;a=a<g?-a:a;const c=y(a,b);d.n=a/c;d.d=b/c;return d}function A(a){const b=
12
+ Object.create(null);if(a<=h)return b[a]=h,b;for(;a%p===g;)b[p]=(b[p]||g)+h,a/=p;for(;a%B===g;)b[B]=(b[B]||g)+h,a/=B;for(;a%z===g;)b[z]=(b[z]||g)+h,a/=z;for(let d=0,c=p+z;c*c<=a;){for(;a%c===g;)b[c]=(b[c]||g)+h,a/=c;c+=G[d];d=d+1&7}a>h&&(b[a]=(b[a]||g)+h);return b}function y(a,b){if(!a)return b;if(!b)return a;for(;;){a%=b;if(!a)return b;b%=a;if(!b)return a}}function v(a,b){q(a,b);if(this instanceof v)a=y(e.d,e.n),this.s=e.s,this.n=e.n/a,this.d=e.d/a;else return n(e.s*e.n,e.d)}"undefined"===typeof BigInt&&
13
+ (BigInt=function(a){if(isNaN(a))throw Error("");return a});const g=BigInt(0),h=BigInt(1),p=BigInt(2),B=BigInt(3),z=BigInt(5),t=BigInt(10),e={s:h,n:g,d:h},G=[p*p,p,p*p,p,p*p,p*B,p,p*B];v.prototype={s:h,n:g,d:h,abs:function(){return n(this.n,this.d)},neg:function(){return n(-this.s*this.n,this.d)},add:function(a,b){q(a,b);return n(this.s*this.n*e.d+e.s*this.d*e.n,this.d*e.d)},sub:function(a,b){q(a,b);return n(this.s*this.n*e.d-e.s*this.d*e.n,this.d*e.d)},mul:function(a,b){q(a,b);return n(this.s*e.s*
14
+ this.n*e.n,this.d*e.d)},div:function(a,b){q(a,b);return n(this.s*e.s*this.n*e.d,this.d*e.n)},clone:function(){return n(this.s*this.n,this.d)},mod:function(a,b){if(void 0===a)return n(this.s*this.n%this.d,h);q(a,b);if(g===e.n*this.d)throw C();return n(this.s*e.d*this.n%(e.n*this.d),e.d*this.d)},gcd:function(a,b){q(a,b);return n(y(e.n,this.n)*y(e.d,this.d),e.d*this.d)},lcm:function(a,b){q(a,b);return e.n===g&&this.n===g?n(g,h):n(e.n*this.n,y(e.n,this.n)*y(e.d,this.d))},inverse:function(){return n(this.s*
15
+ this.d,this.n)},pow:function(a,b){q(a,b);if(e.d===h)return e.s<g?n((this.s*this.d)**e.n,this.n**e.n):n((this.s*this.n)**e.n,this.d**e.n);if(this.s<g)return null;a=A(this.n);b=A(this.d);let d=h,c=h;for(let f in a)if("1"!==f){if("0"===f){d=g;break}a[f]*=e.n;if(a[f]%e.d===g)a[f]/=e.d;else return null;d*=BigInt(f)**a[f]}for(let f in b)if("1"!==f){b[f]*=e.n;if(b[f]%e.d===g)b[f]/=e.d;else return null;c*=BigInt(f)**b[f]}return e.s<g?n(c,d):n(d,c)},log:function(a,b){q(a,b);if(this.s<=g||e.s<=g)return null;
16
+ var d=Object.create(null);a=A(e.n);const c=A(e.d);b=A(this.n);const f=A(this.d);for(var k in c)a[k]=(a[k]||g)-c[k];for(var l in f)b[l]=(b[l]||g)-f[l];for(var m in a)"1"!==m&&(d[m]=!0);for(var r in b)"1"!==r&&(d[r]=!0);l=k=null;for(const E in d)if(m=a[E]||g,d=b[E]||g,m===g){if(d!==g)return null}else if(r=y(d,m),d/=r,m/=r,null===k&&null===l)k=d,l=m;else if(d*l!==k*m)return null;return null!==k&&null!==l?n(k,l):null},equals:function(a,b){q(a,b);return this.s*this.n*e.d===e.s*e.n*this.d},lt:function(a,
17
+ b){q(a,b);return this.s*this.n*e.d<e.s*e.n*this.d},lte:function(a,b){q(a,b);return this.s*this.n*e.d<=e.s*e.n*this.d},gt:function(a,b){q(a,b);return this.s*this.n*e.d>e.s*e.n*this.d},gte:function(a,b){q(a,b);return this.s*this.n*e.d>=e.s*e.n*this.d},compare:function(a,b){q(a,b);a=this.s*this.n*e.d-e.s*e.n*this.d;return(g<a)-(a<g)},ceil:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/this.d)+(a*this.n%this.d>g&&this.s>=g?h:g),a)},floor:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/
18
+ this.d)-(a*this.n%this.d>g&&this.s<g?h:g),a)},round:function(a){a=t**BigInt(a||0);return n(u(this.s*a*this.n/this.d)+this.s*((this.s>=g?h:g)+a*this.n%this.d*p>this.d?h:g),a)},roundTo:function(a,b){q(a,b);var d=this.n*e.d;a=this.d*e.n;b=d%a;d=u(d/a);b+b>=a&&d++;return n(this.s*d*e.n,e.d)},divisible:function(a,b){q(a,b);return e.n===g?!1:this.n*e.d%(e.n*this.d)===g},valueOf:function(){return Number(this.s*this.n)/Number(this.d)},toString:function(a=15){let b=this.n,d=this.d;var c;a:{for(c=d;c%p===g;c/=
19
+ p);for(;c%z===g;c/=z);if(c===h)c=g;else{for(var f=t%c,k=1;f!==h;k++)if(f=f*t%c,2E3<k){c=g;break a}c=BigInt(k)}}a:{f=h;k=t;var l=c;let m=h;for(;l>g;k=k*k%d,l>>=h)l&h&&(m=m*k%d);k=m;for(l=0;300>l;l++){if(f===k){f=BigInt(l);break a}f=f*t%d;k=k*t%d}f=0}k=f;f=this.s<g?"-":"";f+=u(b/d);(b=b%d*t)&&(f+=".");if(c){for(a=k;a--;)f+=u(b/d),b%=d,b*=t;f+="(";for(a=c;a--;)f+=u(b/d),b%=d,b*=t;f+=")"}else for(;b&&a--;)f+=u(b/d),b%=d,b*=t;return f},toFraction:function(a=!1){let b=this.n,d=this.d,c=this.s<g?"-":"";
20
+ if(d===h)c+=b;else{const f=u(b/d);a&&f>g&&(c+=f,c+=" ",b%=d);c=c+b+"/"+d}return c},toLatex:function(a=!1){let b=this.n,d=this.d,c=this.s<g?"-":"";if(d===h)c+=b;else{const f=u(b/d);a&&f>g&&(c+=f,b%=d);c=c+"\\frac{"+b+"}{"+d;c+="}"}return c},toContinued:function(){let a=this.n,b=this.d;const d=[];for(;b;){d.push(u(a/b));const c=a%b;a=b;b=c}return d},simplify:function(a=.001){a=BigInt(Math.ceil(1/a));const b=this.abs(),d=b.toContinued();for(let f=1;f<d.length;f++){let k=n(d[f-1],h);for(var c=f-2;0<=
21
+ c;c--)k=k.inverse().add(d[c]);c=k.sub(b);if(c.n*a<c.d)return k.mul(this.s)}return this}};"function"===typeof define&&define.amd?define([],function(){return v}):"object"===typeof exports?(Object.defineProperty(v,"__esModule",{value:!0}),v["default"]=v,v.Fraction=v,module.exports=v):F.Fraction=v})(this);
web/node_modules/fraction.js/dist/fraction.mjs ADDED
@@ -0,0 +1,1043 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /**
4
+ *
5
+ * This class offers the possibility to calculate fractions.
6
+ * You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
7
+ *
8
+ * Array/Object form
9
+ * [ 0 => <numerator>, 1 => <denominator> ]
10
+ * { n => <numerator>, d => <denominator> }
11
+ *
12
+ * Integer form
13
+ * - Single integer value as BigInt or Number
14
+ *
15
+ * Double form
16
+ * - Single double value as Number
17
+ *
18
+ * String form
19
+ * 123.456 - a simple double
20
+ * 123/456 - a string fraction
21
+ * 123.'456' - a double with repeating decimal places
22
+ * 123.(456) - synonym
23
+ * 123.45'6' - a double with repeating last place
24
+ * 123.45(6) - synonym
25
+ *
26
+ * Example:
27
+ * let f = new Fraction("9.4'31'");
28
+ * f.mul([-4, 3]).div(4.9);
29
+ *
30
+ */
31
+
32
+ // Set Identity function to downgrade BigInt to Number if needed
33
+ if (typeof BigInt === 'undefined') BigInt = function (n) { if (isNaN(n)) throw new Error(""); return n; };
34
+
35
+ const C_ZERO = BigInt(0);
36
+ const C_ONE = BigInt(1);
37
+ const C_TWO = BigInt(2);
38
+ const C_THREE = BigInt(3);
39
+ const C_FIVE = BigInt(5);
40
+ const C_TEN = BigInt(10);
41
+ const MAX_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
42
+
43
+ // Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
44
+ // Example: 1/7 = 0.(142857) has 6 repeating decimal places.
45
+ // If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
46
+ const MAX_CYCLE_LEN = 2000;
47
+
48
+ // Parsed data to avoid calling "new" all the time
49
+ const P = {
50
+ "s": C_ONE,
51
+ "n": C_ZERO,
52
+ "d": C_ONE
53
+ };
54
+
55
+ function assign(n, s) {
56
+
57
+ try {
58
+ n = BigInt(n);
59
+ } catch (e) {
60
+ throw InvalidParameter();
61
+ }
62
+ return n * s;
63
+ }
64
+
65
+ function ifloor(x) {
66
+ return typeof x === 'bigint' ? x : Math.floor(x);
67
+ }
68
+
69
+ // Creates a new Fraction internally without the need of the bulky constructor
70
+ function newFraction(n, d) {
71
+
72
+ if (d === C_ZERO) {
73
+ throw DivisionByZero();
74
+ }
75
+
76
+ const f = Object.create(Fraction.prototype);
77
+ f["s"] = n < C_ZERO ? -C_ONE : C_ONE;
78
+
79
+ n = n < C_ZERO ? -n : n;
80
+
81
+ const a = gcd(n, d);
82
+
83
+ f["n"] = n / a;
84
+ f["d"] = d / a;
85
+ return f;
86
+ }
87
+
88
+ const FACTORSTEPS = [C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO * C_THREE, C_TWO, C_TWO * C_THREE]; // repeats
89
+ function factorize(n) {
90
+
91
+ const factors = Object.create(null);
92
+ if (n <= C_ONE) {
93
+ factors[n] = C_ONE;
94
+ return factors;
95
+ }
96
+
97
+ const add = (p) => { factors[p] = (factors[p] || C_ZERO) + C_ONE; };
98
+
99
+ while (n % C_TWO === C_ZERO) { add(C_TWO); n /= C_TWO; }
100
+ while (n % C_THREE === C_ZERO) { add(C_THREE); n /= C_THREE; }
101
+ while (n % C_FIVE === C_ZERO) { add(C_FIVE); n /= C_FIVE; }
102
+
103
+ // 30-wheel trial division: test only residues coprime to 2*3*5
104
+ // Residue step pattern after 5: 7,11,13,17,19,23,29,31, ...
105
+ for (let si = 0, p = C_TWO + C_FIVE; p * p <= n;) {
106
+ while (n % p === C_ZERO) { add(p); n /= p; }
107
+ p += FACTORSTEPS[si];
108
+ si = (si + 1) & 7; // fast modulo 8
109
+ }
110
+ if (n > C_ONE) add(n);
111
+ return factors;
112
+ }
113
+
114
+ const parse = function (p1, p2) {
115
+
116
+ let n = C_ZERO, d = C_ONE, s = C_ONE;
117
+
118
+ if (p1 === undefined || p1 === null) { // No argument
119
+ /* void */
120
+ } else if (p2 !== undefined) { // Two arguments
121
+
122
+ if (typeof p1 === "bigint") {
123
+ n = p1;
124
+ } else if (isNaN(p1)) {
125
+ throw InvalidParameter();
126
+ } else if (p1 % 1 !== 0) {
127
+ throw NonIntegerParameter();
128
+ } else {
129
+ n = BigInt(p1);
130
+ }
131
+
132
+ if (typeof p2 === "bigint") {
133
+ d = p2;
134
+ } else if (isNaN(p2)) {
135
+ throw InvalidParameter();
136
+ } else if (p2 % 1 !== 0) {
137
+ throw NonIntegerParameter();
138
+ } else {
139
+ d = BigInt(p2);
140
+ }
141
+
142
+ s = n * d;
143
+
144
+ } else if (typeof p1 === "object") {
145
+ if ("d" in p1 && "n" in p1) {
146
+ n = BigInt(p1["n"]);
147
+ d = BigInt(p1["d"]);
148
+ if ("s" in p1)
149
+ n *= BigInt(p1["s"]);
150
+ } else if (0 in p1) {
151
+ n = BigInt(p1[0]);
152
+ if (1 in p1)
153
+ d = BigInt(p1[1]);
154
+ } else if (typeof p1 === "bigint") {
155
+ n = p1;
156
+ } else {
157
+ throw InvalidParameter();
158
+ }
159
+ s = n * d;
160
+ } else if (typeof p1 === "number") {
161
+
162
+ if (isNaN(p1)) {
163
+ throw InvalidParameter();
164
+ }
165
+
166
+ if (p1 < 0) {
167
+ s = -C_ONE;
168
+ p1 = -p1;
169
+ }
170
+
171
+ if (p1 % 1 === 0) {
172
+ n = BigInt(p1);
173
+ } else {
174
+
175
+ let z = 1;
176
+
177
+ let A = 0, B = 1;
178
+ let C = 1, D = 1;
179
+
180
+ let N = 10000000;
181
+
182
+ if (p1 >= 1) {
183
+ z = 10 ** Math.floor(1 + Math.log10(p1));
184
+ p1 /= z;
185
+ }
186
+
187
+ // Using Farey Sequences
188
+
189
+ while (B <= N && D <= N) {
190
+ let M = (A + C) / (B + D);
191
+
192
+ if (p1 === M) {
193
+ if (B + D <= N) {
194
+ n = A + C;
195
+ d = B + D;
196
+ } else if (D > B) {
197
+ n = C;
198
+ d = D;
199
+ } else {
200
+ n = A;
201
+ d = B;
202
+ }
203
+ break;
204
+
205
+ } else {
206
+
207
+ if (p1 > M) {
208
+ A += C;
209
+ B += D;
210
+ } else {
211
+ C += A;
212
+ D += B;
213
+ }
214
+
215
+ if (B > N) {
216
+ n = C;
217
+ d = D;
218
+ } else {
219
+ n = A;
220
+ d = B;
221
+ }
222
+ }
223
+ }
224
+ n = BigInt(n) * BigInt(z);
225
+ d = BigInt(d);
226
+ }
227
+
228
+ } else if (typeof p1 === "string") {
229
+
230
+ let ndx = 0;
231
+
232
+ let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;
233
+
234
+ let match = p1.replace(/_/g, '').match(/\d+|./g);
235
+
236
+ if (match === null)
237
+ throw InvalidParameter();
238
+
239
+ if (match[ndx] === '-') {// Check for minus sign at the beginning
240
+ s = -C_ONE;
241
+ ndx++;
242
+ } else if (match[ndx] === '+') {// Check for plus sign at the beginning
243
+ ndx++;
244
+ }
245
+
246
+ if (match.length === ndx + 1) { // Check if it's just a simple number "1234"
247
+ w = assign(match[ndx++], s);
248
+ } else if (match[ndx + 1] === '.' || match[ndx] === '.') { // Check if it's a decimal number
249
+
250
+ if (match[ndx] !== '.') { // Handle 0.5 and .5
251
+ v = assign(match[ndx++], s);
252
+ }
253
+ ndx++;
254
+
255
+ // Check for decimal places
256
+ if (ndx + 1 === match.length || match[ndx + 1] === '(' && match[ndx + 3] === ')' || match[ndx + 1] === "'" && match[ndx + 3] === "'") {
257
+ w = assign(match[ndx], s);
258
+ y = C_TEN ** BigInt(match[ndx].length);
259
+ ndx++;
260
+ }
261
+
262
+ // Check for repeating places
263
+ if (match[ndx] === '(' && match[ndx + 2] === ')' || match[ndx] === "'" && match[ndx + 2] === "'") {
264
+ x = assign(match[ndx + 1], s);
265
+ z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;
266
+ ndx += 3;
267
+ }
268
+
269
+ } else if (match[ndx + 1] === '/' || match[ndx + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
270
+ w = assign(match[ndx], s);
271
+ y = assign(match[ndx + 2], C_ONE);
272
+ ndx += 3;
273
+ } else if (match[ndx + 3] === '/' && match[ndx + 1] === ' ') { // Check for a complex fraction "123 1/2"
274
+ v = assign(match[ndx], s);
275
+ w = assign(match[ndx + 2], s);
276
+ y = assign(match[ndx + 4], C_ONE);
277
+ ndx += 5;
278
+ }
279
+
280
+ if (match.length <= ndx) { // Check for more tokens on the stack
281
+ d = y * z;
282
+ s = /* void */
283
+ n = x + d * v + z * w;
284
+ } else {
285
+ throw InvalidParameter();
286
+ }
287
+
288
+ } else if (typeof p1 === "bigint") {
289
+ n = p1;
290
+ s = p1;
291
+ d = C_ONE;
292
+ } else {
293
+ throw InvalidParameter();
294
+ }
295
+
296
+ if (d === C_ZERO) {
297
+ throw DivisionByZero();
298
+ }
299
+
300
+ P["s"] = s < C_ZERO ? -C_ONE : C_ONE;
301
+ P["n"] = n < C_ZERO ? -n : n;
302
+ P["d"] = d < C_ZERO ? -d : d;
303
+ };
304
+
305
+ function modpow(b, e, m) {
306
+
307
+ let r = C_ONE;
308
+ for (; e > C_ZERO; b = (b * b) % m, e >>= C_ONE) {
309
+
310
+ if (e & C_ONE) {
311
+ r = (r * b) % m;
312
+ }
313
+ }
314
+ return r;
315
+ }
316
+
317
+ function cycleLen(n, d) {
318
+
319
+ for (; d % C_TWO === C_ZERO;
320
+ d /= C_TWO) {
321
+ }
322
+
323
+ for (; d % C_FIVE === C_ZERO;
324
+ d /= C_FIVE) {
325
+ }
326
+
327
+ if (d === C_ONE) // Catch non-cyclic numbers
328
+ return C_ZERO;
329
+
330
+ // If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
331
+ // 10^(d-1) % d == 1
332
+ // However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
333
+ // as we want to translate the numbers to strings.
334
+
335
+ let rem = C_TEN % d;
336
+ let t = 1;
337
+
338
+ for (; rem !== C_ONE; t++) {
339
+ rem = rem * C_TEN % d;
340
+
341
+ if (t > MAX_CYCLE_LEN)
342
+ return C_ZERO; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
343
+ }
344
+ return BigInt(t);
345
+ }
346
+
347
+ function cycleStart(n, d, len) {
348
+
349
+ let rem1 = C_ONE;
350
+ let rem2 = modpow(C_TEN, len, d);
351
+
352
+ for (let t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
353
+ // Solve 10^s == 10^(s+t) (mod d)
354
+
355
+ if (rem1 === rem2)
356
+ return BigInt(t);
357
+
358
+ rem1 = rem1 * C_TEN % d;
359
+ rem2 = rem2 * C_TEN % d;
360
+ }
361
+ return 0;
362
+ }
363
+
364
+ function gcd(a, b) {
365
+
366
+ if (!a)
367
+ return b;
368
+ if (!b)
369
+ return a;
370
+
371
+ while (1) {
372
+ a %= b;
373
+ if (!a)
374
+ return b;
375
+ b %= a;
376
+ if (!b)
377
+ return a;
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Module constructor
383
+ *
384
+ * @constructor
385
+ * @param {number|Fraction=} a
386
+ * @param {number=} b
387
+ */
388
+ function Fraction(a, b) {
389
+
390
+ parse(a, b);
391
+
392
+ if (this instanceof Fraction) {
393
+ a = gcd(P["d"], P["n"]); // Abuse a
394
+ this["s"] = P["s"];
395
+ this["n"] = P["n"] / a;
396
+ this["d"] = P["d"] / a;
397
+ } else {
398
+ return newFraction(P['s'] * P['n'], P['d']);
399
+ }
400
+ }
401
+
402
+ const DivisionByZero = function () { return new Error("Division by Zero"); };
403
+ const InvalidParameter = function () { return new Error("Invalid argument"); };
404
+ const NonIntegerParameter = function () { return new Error("Parameters must be integer"); };
405
+
406
+ Fraction.prototype = {
407
+
408
+ "s": C_ONE,
409
+ "n": C_ZERO,
410
+ "d": C_ONE,
411
+
412
+ /**
413
+ * Calculates the absolute value
414
+ *
415
+ * Ex: new Fraction(-4).abs() => 4
416
+ **/
417
+ "abs": function () {
418
+
419
+ return newFraction(this["n"], this["d"]);
420
+ },
421
+
422
+ /**
423
+ * Inverts the sign of the current fraction
424
+ *
425
+ * Ex: new Fraction(-4).neg() => 4
426
+ **/
427
+ "neg": function () {
428
+
429
+ return newFraction(-this["s"] * this["n"], this["d"]);
430
+ },
431
+
432
+ /**
433
+ * Adds two rational numbers
434
+ *
435
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
436
+ **/
437
+ "add": function (a, b) {
438
+
439
+ parse(a, b);
440
+ return newFraction(
441
+ this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
442
+ this["d"] * P["d"]
443
+ );
444
+ },
445
+
446
+ /**
447
+ * Subtracts two rational numbers
448
+ *
449
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
450
+ **/
451
+ "sub": function (a, b) {
452
+
453
+ parse(a, b);
454
+ return newFraction(
455
+ this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
456
+ this["d"] * P["d"]
457
+ );
458
+ },
459
+
460
+ /**
461
+ * Multiplies two rational numbers
462
+ *
463
+ * Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
464
+ **/
465
+ "mul": function (a, b) {
466
+
467
+ parse(a, b);
468
+ return newFraction(
469
+ this["s"] * P["s"] * this["n"] * P["n"],
470
+ this["d"] * P["d"]
471
+ );
472
+ },
473
+
474
+ /**
475
+ * Divides two rational numbers
476
+ *
477
+ * Ex: new Fraction("-17.(345)").inverse().div(3)
478
+ **/
479
+ "div": function (a, b) {
480
+
481
+ parse(a, b);
482
+ return newFraction(
483
+ this["s"] * P["s"] * this["n"] * P["d"],
484
+ this["d"] * P["n"]
485
+ );
486
+ },
487
+
488
+ /**
489
+ * Clones the actual object
490
+ *
491
+ * Ex: new Fraction("-17.(345)").clone()
492
+ **/
493
+ "clone": function () {
494
+ return newFraction(this['s'] * this['n'], this['d']);
495
+ },
496
+
497
+ /**
498
+ * Calculates the modulo of two rational numbers - a more precise fmod
499
+ *
500
+ * Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
501
+ * Ex: new Fraction(20, 10).mod().equals(0) ? "is Integer"
502
+ **/
503
+ "mod": function (a, b) {
504
+
505
+ if (a === undefined) {
506
+ return newFraction(this["s"] * this["n"] % this["d"], C_ONE);
507
+ }
508
+
509
+ parse(a, b);
510
+ if (C_ZERO === P["n"] * this["d"]) {
511
+ throw DivisionByZero();
512
+ }
513
+
514
+ /**
515
+ * I derived the rational modulo similar to the modulo for integers
516
+ *
517
+ * https://raw.org/book/analysis/rational-numbers/
518
+ *
519
+ * n1/d1 = (n2/d2) * q + r, where 0 ≤ r < n2/d2
520
+ * => d2 * n1 = n2 * d1 * q + d1 * d2 * r
521
+ * => r = (d2 * n1 - n2 * d1 * q) / (d1 * d2)
522
+ * = (d2 * n1 - n2 * d1 * floor((d2 * n1) / (n2 * d1))) / (d1 * d2)
523
+ * = ((d2 * n1) % (n2 * d1)) / (d1 * d2)
524
+ */
525
+ return newFraction(
526
+ this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
527
+ P["d"] * this["d"]);
528
+ },
529
+
530
+ /**
531
+ * Calculates the fractional gcd of two rational numbers
532
+ *
533
+ * Ex: new Fraction(5,8).gcd(3,7) => 1/56
534
+ */
535
+ "gcd": function (a, b) {
536
+
537
+ parse(a, b);
538
+
539
+ // https://raw.org/book/analysis/rational-numbers/
540
+ // gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
541
+
542
+ return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
543
+ },
544
+
545
+ /**
546
+ * Calculates the fractional lcm of two rational numbers
547
+ *
548
+ * Ex: new Fraction(5,8).lcm(3,7) => 15
549
+ */
550
+ "lcm": function (a, b) {
551
+
552
+ parse(a, b);
553
+
554
+ // https://raw.org/book/analysis/rational-numbers/
555
+ // lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
556
+
557
+ if (P["n"] === C_ZERO && this["n"] === C_ZERO) {
558
+ return newFraction(C_ZERO, C_ONE);
559
+ }
560
+ return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
561
+ },
562
+
563
+ /**
564
+ * Gets the inverse of the fraction, means numerator and denominator are exchanged
565
+ *
566
+ * Ex: new Fraction([-3, 4]).inverse() => -4 / 3
567
+ **/
568
+ "inverse": function () {
569
+ return newFraction(this["s"] * this["d"], this["n"]);
570
+ },
571
+
572
+ /**
573
+ * Calculates the fraction to some integer exponent
574
+ *
575
+ * Ex: new Fraction(-1,2).pow(-3) => -8
576
+ */
577
+ "pow": function (a, b) {
578
+
579
+ parse(a, b);
580
+
581
+ // Trivial case when exp is an integer
582
+
583
+ if (P['d'] === C_ONE) {
584
+
585
+ if (P['s'] < C_ZERO) {
586
+ return newFraction((this['s'] * this["d"]) ** P['n'], this["n"] ** P['n']);
587
+ } else {
588
+ return newFraction((this['s'] * this["n"]) ** P['n'], this["d"] ** P['n']);
589
+ }
590
+ }
591
+
592
+ // Negative roots become complex
593
+ // (-a/b)^(c/d) = x
594
+ // ⇔ (-1)^(c/d) * (a/b)^(c/d) = x
595
+ // ⇔ (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x
596
+ // ⇔ (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula
597
+ // From which follows that only for c=0 the root is non-complex
598
+ if (this['s'] < C_ZERO) return null;
599
+
600
+ // Now prime factor n and d
601
+ let N = factorize(this['n']);
602
+ let D = factorize(this['d']);
603
+
604
+ // Exponentiate and take root for n and d individually
605
+ let n = C_ONE;
606
+ let d = C_ONE;
607
+ for (let k in N) {
608
+ if (k === '1') continue;
609
+ if (k === '0') {
610
+ n = C_ZERO;
611
+ break;
612
+ }
613
+ N[k] *= P['n'];
614
+
615
+ if (N[k] % P['d'] === C_ZERO) {
616
+ N[k] /= P['d'];
617
+ } else return null;
618
+ n *= BigInt(k) ** N[k];
619
+ }
620
+
621
+ for (let k in D) {
622
+ if (k === '1') continue;
623
+ D[k] *= P['n'];
624
+
625
+ if (D[k] % P['d'] === C_ZERO) {
626
+ D[k] /= P['d'];
627
+ } else return null;
628
+ d *= BigInt(k) ** D[k];
629
+ }
630
+
631
+ if (P['s'] < C_ZERO) {
632
+ return newFraction(d, n);
633
+ }
634
+ return newFraction(n, d);
635
+ },
636
+
637
+ /**
638
+ * Calculates the logarithm of a fraction to a given rational base
639
+ *
640
+ * Ex: new Fraction(27, 8).log(9, 4) => 3/2
641
+ */
642
+ "log": function (a, b) {
643
+
644
+ parse(a, b);
645
+
646
+ if (this['s'] <= C_ZERO || P['s'] <= C_ZERO) return null;
647
+
648
+ const allPrimes = Object.create(null);
649
+
650
+ const baseFactors = factorize(P['n']);
651
+ const T1 = factorize(P['d']);
652
+
653
+ const numberFactors = factorize(this['n']);
654
+ const T2 = factorize(this['d']);
655
+
656
+ for (const prime in T1) {
657
+ baseFactors[prime] = (baseFactors[prime] || C_ZERO) - T1[prime];
658
+ }
659
+ for (const prime in T2) {
660
+ numberFactors[prime] = (numberFactors[prime] || C_ZERO) - T2[prime];
661
+ }
662
+
663
+ for (const prime in baseFactors) {
664
+ if (prime === '1') continue;
665
+ allPrimes[prime] = true;
666
+ }
667
+ for (const prime in numberFactors) {
668
+ if (prime === '1') continue;
669
+ allPrimes[prime] = true;
670
+ }
671
+
672
+ let retN = null;
673
+ let retD = null;
674
+
675
+ // Iterate over all unique primes to determine if a consistent ratio exists
676
+ for (const prime in allPrimes) {
677
+
678
+ const baseExponent = baseFactors[prime] || C_ZERO;
679
+ const numberExponent = numberFactors[prime] || C_ZERO;
680
+
681
+ if (baseExponent === C_ZERO) {
682
+ if (numberExponent !== C_ZERO) {
683
+ return null; // Logarithm cannot be expressed as a rational number
684
+ }
685
+ continue; // Skip this prime since both exponents are zero
686
+ }
687
+
688
+ // Calculate the ratio of exponents for this prime
689
+ let curN = numberExponent;
690
+ let curD = baseExponent;
691
+
692
+ // Simplify the current ratio
693
+ const gcdValue = gcd(curN, curD);
694
+ curN /= gcdValue;
695
+ curD /= gcdValue;
696
+
697
+ // Check if this is the first ratio; otherwise, ensure ratios are consistent
698
+ if (retN === null && retD === null) {
699
+ retN = curN;
700
+ retD = curD;
701
+ } else if (curN * retD !== retN * curD) {
702
+ return null; // Ratios do not match, logarithm cannot be rational
703
+ }
704
+ }
705
+
706
+ return retN !== null && retD !== null
707
+ ? newFraction(retN, retD)
708
+ : null;
709
+ },
710
+
711
+ /**
712
+ * Check if two rational numbers are the same
713
+ *
714
+ * Ex: new Fraction(19.6).equals([98, 5]);
715
+ **/
716
+ "equals": function (a, b) {
717
+
718
+ parse(a, b);
719
+ return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"];
720
+ },
721
+
722
+ /**
723
+ * Check if this rational number is less than another
724
+ *
725
+ * Ex: new Fraction(19.6).lt([98, 5]);
726
+ **/
727
+ "lt": function (a, b) {
728
+
729
+ parse(a, b);
730
+ return this["s"] * this["n"] * P["d"] < P["s"] * P["n"] * this["d"];
731
+ },
732
+
733
+ /**
734
+ * Check if this rational number is less than or equal another
735
+ *
736
+ * Ex: new Fraction(19.6).lt([98, 5]);
737
+ **/
738
+ "lte": function (a, b) {
739
+
740
+ parse(a, b);
741
+ return this["s"] * this["n"] * P["d"] <= P["s"] * P["n"] * this["d"];
742
+ },
743
+
744
+ /**
745
+ * Check if this rational number is greater than another
746
+ *
747
+ * Ex: new Fraction(19.6).lt([98, 5]);
748
+ **/
749
+ "gt": function (a, b) {
750
+
751
+ parse(a, b);
752
+ return this["s"] * this["n"] * P["d"] > P["s"] * P["n"] * this["d"];
753
+ },
754
+
755
+ /**
756
+ * Check if this rational number is greater than or equal another
757
+ *
758
+ * Ex: new Fraction(19.6).lt([98, 5]);
759
+ **/
760
+ "gte": function (a, b) {
761
+
762
+ parse(a, b);
763
+ return this["s"] * this["n"] * P["d"] >= P["s"] * P["n"] * this["d"];
764
+ },
765
+
766
+ /**
767
+ * Compare two rational numbers
768
+ * < 0 iff this < that
769
+ * > 0 iff this > that
770
+ * = 0 iff this = that
771
+ *
772
+ * Ex: new Fraction(19.6).compare([98, 5]);
773
+ **/
774
+ "compare": function (a, b) {
775
+
776
+ parse(a, b);
777
+ let t = this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"];
778
+
779
+ return (C_ZERO < t) - (t < C_ZERO);
780
+ },
781
+
782
+ /**
783
+ * Calculates the ceil of a rational number
784
+ *
785
+ * Ex: new Fraction('4.(3)').ceil() => (5 / 1)
786
+ **/
787
+ "ceil": function (places) {
788
+
789
+ places = C_TEN ** BigInt(places || 0);
790
+
791
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
792
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
793
+ places);
794
+ },
795
+
796
+ /**
797
+ * Calculates the floor of a rational number
798
+ *
799
+ * Ex: new Fraction('4.(3)').floor() => (4 / 1)
800
+ **/
801
+ "floor": function (places) {
802
+
803
+ places = C_TEN ** BigInt(places || 0);
804
+
805
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) -
806
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
807
+ places);
808
+ },
809
+
810
+ /**
811
+ * Rounds a rational numbers
812
+ *
813
+ * Ex: new Fraction('4.(3)').round() => (4 / 1)
814
+ **/
815
+ "round": function (places) {
816
+
817
+ places = C_TEN ** BigInt(places || 0);
818
+
819
+ /* Derivation:
820
+
821
+ s >= 0:
822
+ round(n / d) = ifloor(n / d) + (n % d) / d >= 0.5 ? 1 : 0
823
+ = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
824
+ s < 0:
825
+ round(n / d) =-ifloor(n / d) - (n % d) / d > 0.5 ? 1 : 0
826
+ =-ifloor(n / d) - 2(n % d) > d ? 1 : 0
827
+
828
+ =>:
829
+
830
+ round(s * n / d) = s * ifloor(n / d) + s * (C + 2(n % d) > d ? 1 : 0)
831
+ where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.
832
+ */
833
+
834
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
835
+ this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
836
+ places);
837
+ },
838
+
839
+ /**
840
+ * Rounds a rational number to a multiple of another rational number
841
+ *
842
+ * Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
843
+ **/
844
+ "roundTo": function (a, b) {
845
+
846
+ /*
847
+ k * x/y ≤ a/b < (k+1) * x/y
848
+ ⇔ k ≤ a/b / (x/y) < (k+1)
849
+ ⇔ k = floor(a/b * y/x)
850
+ ⇔ k = floor((a * y) / (b * x))
851
+ */
852
+
853
+ parse(a, b);
854
+
855
+ const n = this['n'] * P['d'];
856
+ const d = this['d'] * P['n'];
857
+ const r = n % d;
858
+
859
+ // round(n / d) = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
860
+ let k = ifloor(n / d);
861
+ if (r + r >= d) {
862
+ k++;
863
+ }
864
+ return newFraction(this['s'] * k * P['n'], P['d']);
865
+ },
866
+
867
+ /**
868
+ * Check if two rational numbers are divisible
869
+ *
870
+ * Ex: new Fraction(19.6).divisible(1.5);
871
+ */
872
+ "divisible": function (a, b) {
873
+
874
+ parse(a, b);
875
+ if (P['n'] === C_ZERO) return false;
876
+ return (this['n'] * P['d']) % (P['n'] * this['d']) === C_ZERO;
877
+ },
878
+
879
+ /**
880
+ * Returns a decimal representation of the fraction
881
+ *
882
+ * Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
883
+ **/
884
+ 'valueOf': function () {
885
+ //if (this['n'] <= MAX_INTEGER && this['d'] <= MAX_INTEGER) {
886
+ return Number(this['s'] * this['n']) / Number(this['d']);
887
+ //}
888
+ },
889
+
890
+ /**
891
+ * Creates a string representation of a fraction with all digits
892
+ *
893
+ * Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
894
+ **/
895
+ 'toString': function (dec = 15) {
896
+
897
+ let N = this["n"];
898
+ let D = this["d"];
899
+
900
+ let cycLen = cycleLen(N, D); // Cycle length
901
+ let cycOff = cycleStart(N, D, cycLen); // Cycle start
902
+
903
+ let str = this['s'] < C_ZERO ? "-" : "";
904
+
905
+ // Append integer part
906
+ str += ifloor(N / D);
907
+
908
+ N %= D;
909
+ N *= C_TEN;
910
+
911
+ if (N)
912
+ str += ".";
913
+
914
+ if (cycLen) {
915
+
916
+ for (let i = cycOff; i--;) {
917
+ str += ifloor(N / D);
918
+ N %= D;
919
+ N *= C_TEN;
920
+ }
921
+ str += "(";
922
+ for (let i = cycLen; i--;) {
923
+ str += ifloor(N / D);
924
+ N %= D;
925
+ N *= C_TEN;
926
+ }
927
+ str += ")";
928
+ } else {
929
+ for (let i = dec; N && i--;) {
930
+ str += ifloor(N / D);
931
+ N %= D;
932
+ N *= C_TEN;
933
+ }
934
+ }
935
+ return str;
936
+ },
937
+
938
+ /**
939
+ * Returns a string-fraction representation of a Fraction object
940
+ *
941
+ * Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
942
+ **/
943
+ 'toFraction': function (showMixed = false) {
944
+
945
+ let n = this["n"];
946
+ let d = this["d"];
947
+ let str = this['s'] < C_ZERO ? "-" : "";
948
+
949
+ if (d === C_ONE) {
950
+ str += n;
951
+ } else {
952
+ const whole = ifloor(n / d);
953
+ if (showMixed && whole > C_ZERO) {
954
+ str += whole;
955
+ str += " ";
956
+ n %= d;
957
+ }
958
+
959
+ str += n;
960
+ str += '/';
961
+ str += d;
962
+ }
963
+ return str;
964
+ },
965
+
966
+ /**
967
+ * Returns a latex representation of a Fraction object
968
+ *
969
+ * Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
970
+ **/
971
+ 'toLatex': function (showMixed = false) {
972
+
973
+ let n = this["n"];
974
+ let d = this["d"];
975
+ let str = this['s'] < C_ZERO ? "-" : "";
976
+
977
+ if (d === C_ONE) {
978
+ str += n;
979
+ } else {
980
+ const whole = ifloor(n / d);
981
+ if (showMixed && whole > C_ZERO) {
982
+ str += whole;
983
+ n %= d;
984
+ }
985
+
986
+ str += "\\frac{";
987
+ str += n;
988
+ str += '}{';
989
+ str += d;
990
+ str += '}';
991
+ }
992
+ return str;
993
+ },
994
+
995
+ /**
996
+ * Returns an array of continued fraction elements
997
+ *
998
+ * Ex: new Fraction("7/8").toContinued() => [0,1,7]
999
+ */
1000
+ 'toContinued': function () {
1001
+
1002
+ let a = this['n'];
1003
+ let b = this['d'];
1004
+ const res = [];
1005
+
1006
+ while (b) {
1007
+ res.push(ifloor(a / b));
1008
+ const t = a % b;
1009
+ a = b;
1010
+ b = t;
1011
+ }
1012
+ return res;
1013
+ },
1014
+
1015
+ "simplify": function (eps = 1e-3) {
1016
+
1017
+ // Continued fractions give best approximations for a max denominator,
1018
+ // generally outperforming mediants in denominator–accuracy trade-offs.
1019
+ // Semiconvergents can further reduce the denominator within tolerance.
1020
+
1021
+ const ieps = BigInt(Math.ceil(1 / eps));
1022
+
1023
+ const thisABS = this['abs']();
1024
+ const cont = thisABS['toContinued']();
1025
+
1026
+ for (let i = 1; i < cont.length; i++) {
1027
+
1028
+ let s = newFraction(cont[i - 1], C_ONE);
1029
+ for (let k = i - 2; k >= 0; k--) {
1030
+ s = s['inverse']()['add'](cont[k]);
1031
+ }
1032
+
1033
+ let t = s['sub'](thisABS);
1034
+ if (t['n'] * ieps < t['d']) { // More robust than Math.abs(t.valueOf()) < eps
1035
+ return s['mul'](this['s']);
1036
+ }
1037
+ }
1038
+ return this;
1039
+ }
1040
+ };
1041
+ export {
1042
+ Fraction as default, Fraction
1043
+ };
web/node_modules/fraction.js/examples/angles.js ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+
9
+ // This example generates a list of angles with human readable radians
10
+
11
+ var Fraction = require('fraction.js');
12
+
13
+ var tab = [];
14
+ for (var d = 1; d <= 360; d++) {
15
+
16
+ var pi = Fraction(2, 360).mul(d);
17
+ var tau = Fraction(1, 360).mul(d);
18
+
19
+ if (pi.d <= 6n && pi.d != 5n)
20
+ tab.push([
21
+ d,
22
+ pi.toFraction() + "pi",
23
+ tau.toFraction() + "tau"]);
24
+ }
25
+
26
+ console.table(tab);
web/node_modules/fraction.js/examples/approx.js ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ // Another rational approximation, not using Farey Sequences but Binary Search using the mediant
11
+ function approximate(p, precision) {
12
+
13
+ var num1 = Math.floor(p);
14
+ var den1 = 1;
15
+
16
+ var num2 = num1 + 1;
17
+ var den2 = 1;
18
+
19
+ if (p !== num1) {
20
+
21
+ while (den1 <= precision && den2 <= precision) {
22
+
23
+ var m = (num1 + num2) / (den1 + den2);
24
+
25
+ if (p === m) {
26
+
27
+ if (den1 + den2 <= precision) {
28
+ den1 += den2;
29
+ num1 += num2;
30
+ den2 = precision + 1;
31
+ } else if (den1 > den2) {
32
+ den2 = precision + 1;
33
+ } else {
34
+ den1 = precision + 1;
35
+ }
36
+ break;
37
+
38
+ } else if (p < m) {
39
+ num2 += num1;
40
+ den2 += den1;
41
+ } else {
42
+ num1 += num2;
43
+ den1 += den2;
44
+ }
45
+ }
46
+ }
47
+
48
+ if (den1 > precision) {
49
+ den1 = den2;
50
+ num1 = num2;
51
+ }
52
+ return new Fraction(num1, den1);
53
+ }
54
+
web/node_modules/fraction.js/examples/egyptian.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ // Based on http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fractions/egyptian.html
11
+ function egyptian(a, b) {
12
+
13
+ var res = [];
14
+
15
+ do {
16
+ var t = Math.ceil(b / a);
17
+ var x = new Fraction(a, b).sub(1, t);
18
+ res.push(t);
19
+ a = Number(x.n);
20
+ b = Number(x.d);
21
+ } while (a !== 0n);
22
+ return res;
23
+ }
24
+ console.log("1 / " + egyptian(521, 1050).join(" + 1 / "));
web/node_modules/fraction.js/examples/hesse-convergence.js ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ /*
11
+ We have the polynom f(x) = 1/3x_1^2 + x_2^2 + x_1 * x_2 + 3
12
+
13
+ The gradient of f(x):
14
+
15
+ grad(x) = | x_1^2+x_2 |
16
+ | 2x_2+x_1 |
17
+
18
+ And thus the Hesse-Matrix H:
19
+ | 2x_1 1 |
20
+ | 1 2 |
21
+
22
+ The inverse Hesse-Matrix H^-1 is
23
+ | -2 / (1-4x_1) 1 / (1 - 4x_1) |
24
+ | 1 / (1 - 4x_1) -2x_1 / (1 - 4x_1) |
25
+
26
+ We now want to find lim ->oo x[n], with the starting element of (3 2)^T
27
+
28
+ */
29
+
30
+ // Get the Hesse Matrix
31
+ function H(x) {
32
+
33
+ var z = Fraction(1).sub(Fraction(4).mul(x[0]));
34
+
35
+ return [
36
+ Fraction(-2).div(z),
37
+ Fraction(1).div(z),
38
+ Fraction(1).div(z),
39
+ Fraction(-2).mul(x[0]).div(z),
40
+ ];
41
+ }
42
+
43
+ // Get the gradient of f(x)
44
+ function grad(x) {
45
+
46
+ return [
47
+ Fraction(x[0]).mul(x[0]).add(x[1]),
48
+ Fraction(2).mul(x[1]).add(x[0])
49
+ ];
50
+ }
51
+
52
+ // A simple matrix multiplication helper
53
+ function matrMult(m, v) {
54
+
55
+ return [
56
+ Fraction(m[0]).mul(v[0]).add(Fraction(m[1]).mul(v[1])),
57
+ Fraction(m[2]).mul(v[0]).add(Fraction(m[3]).mul(v[1]))
58
+ ];
59
+ }
60
+
61
+ // A simple vector subtraction helper
62
+ function vecSub(a, b) {
63
+
64
+ return [
65
+ Fraction(a[0]).sub(b[0]),
66
+ Fraction(a[1]).sub(b[1])
67
+ ];
68
+ }
69
+
70
+ // Main function, gets a vector and the actual index
71
+ function run(V, j) {
72
+
73
+ var t = H(V);
74
+ //console.log("H(X)");
75
+ for (var i in t) {
76
+
77
+ // console.log(t[i].toFraction());
78
+ }
79
+
80
+ var s = grad(V);
81
+ //console.log("vf(X)");
82
+ for (var i in s) {
83
+
84
+ // console.log(s[i].toFraction());
85
+ }
86
+
87
+ //console.log("multiplication");
88
+ var r = matrMult(t, s);
89
+ for (var i in r) {
90
+
91
+ // console.log(r[i].toFraction());
92
+ }
93
+
94
+ var R = (vecSub(V, r));
95
+
96
+ console.log("X" + j);
97
+ console.log(R[0].toFraction(), "= " + R[0].valueOf());
98
+ console.log(R[1].toFraction(), "= " + R[1].valueOf());
99
+ console.log("\n");
100
+
101
+ return R;
102
+ }
103
+
104
+
105
+ // Set the starting vector
106
+ var v = [3, 2];
107
+
108
+ for (var i = 0; i < 15; i++) {
109
+
110
+ v = run(v, i);
111
+ }
web/node_modules/fraction.js/examples/integrate.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ // NOTE: This is a nice example, but a stable version of this is served with Polynomial.js:
11
+ // https://github.com/rawify/Polynomial.js
12
+
13
+ function integrate(poly) {
14
+
15
+ poly = poly.replace(/\s+/g, "");
16
+
17
+ var regex = /(\([+-]?[0-9/]+\)|[+-]?[0-9/]+)x(?:\^(\([+-]?[0-9/]+\)|[+-]?[0-9]+))?/g;
18
+ var arr;
19
+ var res = {};
20
+ while (null !== (arr = regex.exec(poly))) {
21
+
22
+ var a = (arr[1] || "1").replace("(", "").replace(")", "").split("/");
23
+ var b = (arr[2] || "1").replace("(", "").replace(")", "").split("/");
24
+
25
+ var exp = new Fraction(b).add(1);
26
+ var key = "" + exp;
27
+
28
+ if (res[key] !== undefined) {
29
+ res[key] = { x: new Fraction(a).div(exp).add(res[key].x), e: exp };
30
+ } else {
31
+ res[key] = { x: new Fraction(a).div(exp), e: exp };
32
+ }
33
+ }
34
+
35
+ var str = "";
36
+ var c = 0;
37
+ for (var i in res) {
38
+ if (res[i].x.s !== -1n && c > 0) {
39
+ str += "+";
40
+ } else if (res[i].x.s === -1n) {
41
+ str += "-";
42
+ }
43
+ if (res[i].x.n !== res[i].x.d) {
44
+ if (res[i].x.d !== 1n) {
45
+ str += res[i].x.n + "/" + res[i].x.d;
46
+ } else {
47
+ str += res[i].x.n;
48
+ }
49
+ }
50
+ str += "x";
51
+ if (res[i].e.n !== res[i].e.d) {
52
+ str += "^";
53
+ if (res[i].e.d !== 1n) {
54
+ str += "(" + res[i].e.n + "/" + res[i].e.d + ")";
55
+ } else {
56
+ str += res[i].e.n;
57
+ }
58
+ }
59
+ c++;
60
+ }
61
+ return str;
62
+ }
63
+
64
+ var poly = "-2/3x^3-2x^2+3x+8x^3-1/3x^(4/8)";
65
+
66
+ console.log("f(x): " + poly);
67
+ console.log("F(x): " + integrate(poly));
web/node_modules/fraction.js/examples/ratio-chain.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Given the ratio a : b : c = 2 : 3 : 4
3
+ What is c, given a = 40?
4
+
5
+ A general ratio chain is a_1 : a_2 : a_3 : ... : a_n = r_1 : r2 : r_3 : ... : r_n.
6
+ Now each term can be expressed as a_i = r_i * x for some unknown proportional constant x.
7
+ If a_k is known it follows that x = a_k / r_k. Substituting x into the first equation yields
8
+ a_i = r_i / r_k * a_k.
9
+
10
+ Given an array r and a given value a_k, the following function calculates all a_i:
11
+ */
12
+
13
+ function calculateRatios(r, a_k, k) {
14
+ const x = Fraction(a_k).div(r[k]);
15
+ return r.map(r_i => x.mul(r_i));
16
+ }
17
+
18
+ // Example usage:
19
+ const r = [2, 3, 4]; // Ratio array representing a : b : c = 2 : 3 : 4
20
+ const a_k = 40; // Given value of a (corresponding to r[0])
21
+ const k = 0; // Index of the known value (a corresponds to r[0])
22
+
23
+ const result = calculateRatios(r, a_k, k);
24
+ console.log(result); // Output: [40, 60, 80]
web/node_modules/fraction.js/examples/rational-pow.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ // Calculates (a/b)^(c/d) if result is rational
11
+ // Derivation: https://raw.org/book/analysis/rational-numbers/
12
+ function root(a, b, c, d) {
13
+
14
+ // Initial estimate
15
+ let x = Fraction(100 * (Math.floor(Math.pow(a / b, c / d)) || 1), 100);
16
+ const abc = Fraction(a, b).pow(c);
17
+
18
+ for (let i = 0; i < 30; i++) {
19
+ const n = abc.mul(x.pow(1 - d)).sub(x).div(d).add(x)
20
+
21
+ if (x.n === n.n && x.d === n.d) {
22
+ return n;
23
+ }
24
+ x = n;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ root(18, 2, 1, 2); // 3/1
web/node_modules/fraction.js/examples/tape-measure.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+ const Fraction = require('fraction.js');
9
+
10
+ function closestTapeMeasure(frac) {
11
+
12
+ // A tape measure is usually divided in parts of 1/16
13
+
14
+ return Fraction(frac).roundTo("1/16");
15
+ }
16
+ console.log(closestTapeMeasure("1/3")); // 5/16
web/node_modules/fraction.js/examples/toFraction.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+
9
+ const Fraction = require('fraction.js');
10
+
11
+ function toFraction(frac) {
12
+
13
+ var map = {
14
+ '1:4': "¼",
15
+ '1:2': "½",
16
+ '3:4': "¾",
17
+ '1:7': "⅐",
18
+ '1:9': "⅑",
19
+ '1:10': "⅒",
20
+ '1:3': "⅓",
21
+ '2:3': "⅔",
22
+ '1:5': "⅕",
23
+ '2:5': "⅖",
24
+ '3:5': "⅗",
25
+ '4:5': "⅘",
26
+ '1:6': "⅙",
27
+ '5:6': "⅚",
28
+ '1:8': "⅛",
29
+ '3:8': "⅜",
30
+ '5:8': "⅝",
31
+ '7:8': "⅞"
32
+ };
33
+ return map[frac.n + ":" + frac.d] || frac.toFraction(false);
34
+ }
35
+ console.log(toFraction(Fraction(0.25))); // ¼
web/node_modules/fraction.js/examples/valueOfPi.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Fraction.js v5.0.0 10/1/2024
3
+ https://raw.org/article/rational-numbers-in-javascript/
4
+
5
+ Copyright (c) 2024, Robert Eisele (https://raw.org/)
6
+ Licensed under the MIT license.
7
+ */
8
+
9
+ var Fraction = require("fraction.js")
10
+
11
+ function valueOfPi(val) {
12
+
13
+ let minLen = Infinity, minI = 0, min = null;
14
+ const choose = [val, val * Math.PI, val / Math.PI];
15
+ for (let i = 0; i < choose.length; i++) {
16
+ let el = new Fraction(choose[i]).simplify(1e-13);
17
+ let len = Math.log(Number(el.n) + 1) + Math.log(Number(el.d));
18
+ if (len < minLen) {
19
+ minLen = len;
20
+ minI = i;
21
+ min = el;
22
+ }
23
+ }
24
+
25
+ if (minI == 2) {
26
+ return min.toFraction().replace(/(\d+)(\/\d+)?/, (_, p, q) =>
27
+ (p == "1" ? "" : p) + "π" + (q || ""));
28
+ }
29
+
30
+ if (minI == 1) {
31
+ return min.toFraction().replace(/(\d+)(\/\d+)?/, (_, p, q) =>
32
+ p + (!q ? "/π" : "/(" + q.slice(1) + "π)"));
33
+ }
34
+ return min.toFraction();
35
+ }
36
+
37
+ console.log(valueOfPi(-3)); // -3
38
+ console.log(valueOfPi(4 * Math.PI)); // 4π
39
+ console.log(valueOfPi(3.14)); // 157/50
40
+ console.log(valueOfPi(3 / 2 * Math.PI)); // 3π/2
41
+ console.log(valueOfPi(Math.PI / 2)); // π/2
42
+ console.log(valueOfPi(-1 / (2 * Math.PI))); // -1/(2π)
web/node_modules/fraction.js/fraction.d.mts ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Interface representing a fraction with numerator and denominator.
3
+ */
4
+ export interface NumeratorDenominator {
5
+ n: number | bigint;
6
+ d: number | bigint;
7
+ }
8
+
9
+ /**
10
+ * Type for handling multiple types of input for Fraction operations.
11
+ */
12
+ export type FractionInput =
13
+ | Fraction
14
+ | number
15
+ | bigint
16
+ | string
17
+ | [number | bigint | string, number | bigint | string]
18
+ | NumeratorDenominator;
19
+
20
+ /**
21
+ * Function signature for Fraction operations like add, sub, mul, etc.
22
+ */
23
+ export type FractionParam = {
24
+ (numerator: number | bigint, denominator: number | bigint): Fraction;
25
+ (num: FractionInput): Fraction;
26
+ };
27
+
28
+ /**
29
+ * Fraction class representing a rational number with numerator and denominator.
30
+ */
31
+ declare class Fraction {
32
+ constructor();
33
+ constructor(num: FractionInput);
34
+ constructor(numerator: number | bigint, denominator: number | bigint);
35
+
36
+ s: bigint;
37
+ n: bigint;
38
+ d: bigint;
39
+
40
+ abs(): Fraction;
41
+ neg(): Fraction;
42
+
43
+ add: FractionParam;
44
+ sub: FractionParam;
45
+ mul: FractionParam;
46
+ div: FractionParam;
47
+ pow: FractionParam;
48
+ log: FractionParam;
49
+ gcd: FractionParam;
50
+ lcm: FractionParam;
51
+
52
+ mod(): Fraction;
53
+ mod(num: FractionInput): Fraction;
54
+
55
+ ceil(places?: number): Fraction;
56
+ floor(places?: number): Fraction;
57
+ round(places?: number): Fraction;
58
+ roundTo: FractionParam;
59
+
60
+ inverse(): Fraction;
61
+ simplify(eps?: number): Fraction;
62
+
63
+ equals(num: FractionInput): boolean;
64
+ lt(num: FractionInput): boolean;
65
+ lte(num: FractionInput): boolean;
66
+ gt(num: FractionInput): boolean;
67
+ gte(num: FractionInput): boolean;
68
+ compare(num: FractionInput): number;
69
+ divisible(num: FractionInput): boolean;
70
+
71
+ valueOf(): number;
72
+ toString(decimalPlaces?: number): string;
73
+ toLatex(showMixed?: boolean): string;
74
+ toFraction(showMixed?: boolean): string;
75
+ toContinued(): bigint[];
76
+ clone(): Fraction;
77
+ }
78
+
79
+ export { Fraction as default, Fraction };
web/node_modules/fraction.js/fraction.d.ts ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ declare class Fraction {
2
+ constructor();
3
+ constructor(num: Fraction.FractionInput);
4
+ constructor(numerator: number | bigint, denominator: number | bigint);
5
+
6
+ s: bigint;
7
+ n: bigint;
8
+ d: bigint;
9
+
10
+ abs(): Fraction;
11
+ neg(): Fraction;
12
+
13
+ add: Fraction.FractionParam;
14
+ sub: Fraction.FractionParam;
15
+ mul: Fraction.FractionParam;
16
+ div: Fraction.FractionParam;
17
+ pow: Fraction.FractionParam;
18
+ log: Fraction.FractionParam;
19
+ gcd: Fraction.FractionParam;
20
+ lcm: Fraction.FractionParam;
21
+
22
+ mod(): Fraction;
23
+ mod(num: Fraction.FractionInput): Fraction;
24
+
25
+ ceil(places?: number): Fraction;
26
+ floor(places?: number): Fraction;
27
+ round(places?: number): Fraction;
28
+ roundTo: Fraction.FractionParam;
29
+
30
+ inverse(): Fraction;
31
+ simplify(eps?: number): Fraction;
32
+
33
+ equals(num: Fraction.FractionInput): boolean;
34
+ lt(num: Fraction.FractionInput): boolean;
35
+ lte(num: Fraction.FractionInput): boolean;
36
+ gt(num: Fraction.FractionInput): boolean;
37
+ gte(num: Fraction.FractionInput): boolean;
38
+ compare(num: Fraction.FractionInput): number;
39
+ divisible(num: Fraction.FractionInput): boolean;
40
+
41
+ valueOf(): number;
42
+ toString(decimalPlaces?: number): string;
43
+ toLatex(showMixed?: boolean): string;
44
+ toFraction(showMixed?: boolean): string;
45
+ toContinued(): bigint[];
46
+ clone(): Fraction;
47
+
48
+ static default: typeof Fraction;
49
+ static Fraction: typeof Fraction;
50
+ }
51
+
52
+ declare namespace Fraction {
53
+ interface NumeratorDenominator { n: number | bigint; d: number | bigint; }
54
+ type FractionInput =
55
+ | Fraction
56
+ | number
57
+ | bigint
58
+ | string
59
+ | [number | bigint | string, number | bigint | string]
60
+ | NumeratorDenominator;
61
+
62
+ type FractionParam = {
63
+ (numerator: number | bigint, denominator: number | bigint): Fraction;
64
+ (num: FractionInput): Fraction;
65
+ };
66
+ }
67
+
68
+ /**
69
+ * Export matches CJS runtime:
70
+ * module.exports = Fraction;
71
+ * module.exports.default = Fraction;
72
+ * module.exports.Fraction = Fraction;
73
+ */
74
+ declare const FractionExport: typeof Fraction & {
75
+ default: typeof Fraction;
76
+ Fraction: typeof Fraction;
77
+ };
78
+
79
+ export = FractionExport;
web/node_modules/fraction.js/package.json ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "fraction.js",
3
+ "title": "Fraction.js",
4
+ "version": "5.3.4",
5
+ "description": "The RAW rational numbers library",
6
+ "homepage": "https://raw.org/article/rational-numbers-in-javascript/",
7
+ "bugs": "https://github.com/rawify/Fraction.js/issues",
8
+ "keywords": [
9
+ "math",
10
+ "numbers",
11
+ "parser",
12
+ "ratio",
13
+ "fraction",
14
+ "fractions",
15
+ "rational",
16
+ "rationals",
17
+ "rational numbers",
18
+ "bigint",
19
+ "arbitrary precision",
20
+ "mixed numbers",
21
+ "decimal",
22
+ "numerator",
23
+ "denominator",
24
+ "simplification"
25
+ ],
26
+ "private": false,
27
+ "main": "./dist/fraction.js",
28
+ "module": "./dist/fraction.mjs",
29
+ "browser": "./dist/fraction.min.js",
30
+ "unpkg": "./dist/fraction.min.js",
31
+ "types": "./fraction.d.mts",
32
+ "exports": {
33
+ ".": {
34
+ "types": {
35
+ "import": "./fraction.d.mts",
36
+ "require": "./fraction.d.ts"
37
+ },
38
+ "import": "./dist/fraction.mjs",
39
+ "require": "./dist/fraction.js",
40
+ "browser": "./dist/fraction.min.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "typesVersions": {
45
+ "<4.7": {
46
+ "*": [
47
+ "fraction.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "sideEffects": false,
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+ssh://git@github.com/rawify/Fraction.js.git"
55
+ },
56
+ "funding": {
57
+ "type": "github",
58
+ "url": "https://github.com/sponsors/rawify"
59
+ },
60
+ "author": {
61
+ "name": "Robert Eisele",
62
+ "email": "robert@raw.org",
63
+ "url": "https://raw.org/"
64
+ },
65
+ "license": "MIT",
66
+ "engines": {
67
+ "node": "*"
68
+ },
69
+ "directories": {
70
+ "example": "examples",
71
+ "test": "tests"
72
+ },
73
+ "scripts": {
74
+ "build": "crude-build Fraction",
75
+ "test": "mocha tests/*.js"
76
+ },
77
+ "devDependencies": {
78
+ "crude-build": "^0.1.2",
79
+ "mocha": "*"
80
+ }
81
+ }
web/node_modules/fraction.js/src/fraction.js ADDED
@@ -0,0 +1,1046 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license Fraction.js v5.3.4 8/22/2025
3
+ * https://raw.org/article/rational-numbers-in-javascript/
4
+ *
5
+ * Copyright (c) 2025, Robert Eisele (https://raw.org/)
6
+ * Licensed under the MIT license.
7
+ **/
8
+
9
+ /**
10
+ *
11
+ * This class offers the possibility to calculate fractions.
12
+ * You can pass a fraction in different formats. Either as array, as double, as string or as an integer.
13
+ *
14
+ * Array/Object form
15
+ * [ 0 => <numerator>, 1 => <denominator> ]
16
+ * { n => <numerator>, d => <denominator> }
17
+ *
18
+ * Integer form
19
+ * - Single integer value as BigInt or Number
20
+ *
21
+ * Double form
22
+ * - Single double value as Number
23
+ *
24
+ * String form
25
+ * 123.456 - a simple double
26
+ * 123/456 - a string fraction
27
+ * 123.'456' - a double with repeating decimal places
28
+ * 123.(456) - synonym
29
+ * 123.45'6' - a double with repeating last place
30
+ * 123.45(6) - synonym
31
+ *
32
+ * Example:
33
+ * let f = new Fraction("9.4'31'");
34
+ * f.mul([-4, 3]).div(4.9);
35
+ *
36
+ */
37
+
38
+ // Set Identity function to downgrade BigInt to Number if needed
39
+ if (typeof BigInt === 'undefined') BigInt = function (n) { if (isNaN(n)) throw new Error(""); return n; };
40
+
41
+ const C_ZERO = BigInt(0);
42
+ const C_ONE = BigInt(1);
43
+ const C_TWO = BigInt(2);
44
+ const C_THREE = BigInt(3);
45
+ const C_FIVE = BigInt(5);
46
+ const C_TEN = BigInt(10);
47
+ const MAX_INTEGER = BigInt(Number.MAX_SAFE_INTEGER);
48
+
49
+ // Maximum search depth for cyclic rational numbers. 2000 should be more than enough.
50
+ // Example: 1/7 = 0.(142857) has 6 repeating decimal places.
51
+ // If MAX_CYCLE_LEN gets reduced, long cycles will not be detected and toString() only gets the first 10 digits
52
+ const MAX_CYCLE_LEN = 2000;
53
+
54
+ // Parsed data to avoid calling "new" all the time
55
+ const P = {
56
+ "s": C_ONE,
57
+ "n": C_ZERO,
58
+ "d": C_ONE
59
+ };
60
+
61
+ function assign(n, s) {
62
+
63
+ try {
64
+ n = BigInt(n);
65
+ } catch (e) {
66
+ throw InvalidParameter();
67
+ }
68
+ return n * s;
69
+ }
70
+
71
+ function ifloor(x) {
72
+ return typeof x === 'bigint' ? x : Math.floor(x);
73
+ }
74
+
75
+ // Creates a new Fraction internally without the need of the bulky constructor
76
+ function newFraction(n, d) {
77
+
78
+ if (d === C_ZERO) {
79
+ throw DivisionByZero();
80
+ }
81
+
82
+ const f = Object.create(Fraction.prototype);
83
+ f["s"] = n < C_ZERO ? -C_ONE : C_ONE;
84
+
85
+ n = n < C_ZERO ? -n : n;
86
+
87
+ const a = gcd(n, d);
88
+
89
+ f["n"] = n / a;
90
+ f["d"] = d / a;
91
+ return f;
92
+ }
93
+
94
+ const FACTORSTEPS = [C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO, C_TWO * C_TWO, C_TWO * C_THREE, C_TWO, C_TWO * C_THREE]; // repeats
95
+ function factorize(n) {
96
+
97
+ const factors = Object.create(null);
98
+ if (n <= C_ONE) {
99
+ factors[n] = C_ONE;
100
+ return factors;
101
+ }
102
+
103
+ const add = (p) => { factors[p] = (factors[p] || C_ZERO) + C_ONE; };
104
+
105
+ while (n % C_TWO === C_ZERO) { add(C_TWO); n /= C_TWO; }
106
+ while (n % C_THREE === C_ZERO) { add(C_THREE); n /= C_THREE; }
107
+ while (n % C_FIVE === C_ZERO) { add(C_FIVE); n /= C_FIVE; }
108
+
109
+ // 30-wheel trial division: test only residues coprime to 2*3*5
110
+ // Residue step pattern after 5: 7,11,13,17,19,23,29,31, ...
111
+ for (let si = 0, p = C_TWO + C_FIVE; p * p <= n;) {
112
+ while (n % p === C_ZERO) { add(p); n /= p; }
113
+ p += FACTORSTEPS[si];
114
+ si = (si + 1) & 7; // fast modulo 8
115
+ }
116
+ if (n > C_ONE) add(n);
117
+ return factors;
118
+ }
119
+
120
+ const parse = function (p1, p2) {
121
+
122
+ let n = C_ZERO, d = C_ONE, s = C_ONE;
123
+
124
+ if (p1 === undefined || p1 === null) { // No argument
125
+ /* void */
126
+ } else if (p2 !== undefined) { // Two arguments
127
+
128
+ if (typeof p1 === "bigint") {
129
+ n = p1;
130
+ } else if (isNaN(p1)) {
131
+ throw InvalidParameter();
132
+ } else if (p1 % 1 !== 0) {
133
+ throw NonIntegerParameter();
134
+ } else {
135
+ n = BigInt(p1);
136
+ }
137
+
138
+ if (typeof p2 === "bigint") {
139
+ d = p2;
140
+ } else if (isNaN(p2)) {
141
+ throw InvalidParameter();
142
+ } else if (p2 % 1 !== 0) {
143
+ throw NonIntegerParameter();
144
+ } else {
145
+ d = BigInt(p2);
146
+ }
147
+
148
+ s = n * d;
149
+
150
+ } else if (typeof p1 === "object") {
151
+ if ("d" in p1 && "n" in p1) {
152
+ n = BigInt(p1["n"]);
153
+ d = BigInt(p1["d"]);
154
+ if ("s" in p1)
155
+ n *= BigInt(p1["s"]);
156
+ } else if (0 in p1) {
157
+ n = BigInt(p1[0]);
158
+ if (1 in p1)
159
+ d = BigInt(p1[1]);
160
+ } else if (typeof p1 === "bigint") {
161
+ n = p1;
162
+ } else {
163
+ throw InvalidParameter();
164
+ }
165
+ s = n * d;
166
+ } else if (typeof p1 === "number") {
167
+
168
+ if (isNaN(p1)) {
169
+ throw InvalidParameter();
170
+ }
171
+
172
+ if (p1 < 0) {
173
+ s = -C_ONE;
174
+ p1 = -p1;
175
+ }
176
+
177
+ if (p1 % 1 === 0) {
178
+ n = BigInt(p1);
179
+ } else {
180
+
181
+ let z = 1;
182
+
183
+ let A = 0, B = 1;
184
+ let C = 1, D = 1;
185
+
186
+ let N = 10000000;
187
+
188
+ if (p1 >= 1) {
189
+ z = 10 ** Math.floor(1 + Math.log10(p1));
190
+ p1 /= z;
191
+ }
192
+
193
+ // Using Farey Sequences
194
+
195
+ while (B <= N && D <= N) {
196
+ let M = (A + C) / (B + D);
197
+
198
+ if (p1 === M) {
199
+ if (B + D <= N) {
200
+ n = A + C;
201
+ d = B + D;
202
+ } else if (D > B) {
203
+ n = C;
204
+ d = D;
205
+ } else {
206
+ n = A;
207
+ d = B;
208
+ }
209
+ break;
210
+
211
+ } else {
212
+
213
+ if (p1 > M) {
214
+ A += C;
215
+ B += D;
216
+ } else {
217
+ C += A;
218
+ D += B;
219
+ }
220
+
221
+ if (B > N) {
222
+ n = C;
223
+ d = D;
224
+ } else {
225
+ n = A;
226
+ d = B;
227
+ }
228
+ }
229
+ }
230
+ n = BigInt(n) * BigInt(z);
231
+ d = BigInt(d);
232
+ }
233
+
234
+ } else if (typeof p1 === "string") {
235
+
236
+ let ndx = 0;
237
+
238
+ let v = C_ZERO, w = C_ZERO, x = C_ZERO, y = C_ONE, z = C_ONE;
239
+
240
+ let match = p1.replace(/_/g, '').match(/\d+|./g);
241
+
242
+ if (match === null)
243
+ throw InvalidParameter();
244
+
245
+ if (match[ndx] === '-') {// Check for minus sign at the beginning
246
+ s = -C_ONE;
247
+ ndx++;
248
+ } else if (match[ndx] === '+') {// Check for plus sign at the beginning
249
+ ndx++;
250
+ }
251
+
252
+ if (match.length === ndx + 1) { // Check if it's just a simple number "1234"
253
+ w = assign(match[ndx++], s);
254
+ } else if (match[ndx + 1] === '.' || match[ndx] === '.') { // Check if it's a decimal number
255
+
256
+ if (match[ndx] !== '.') { // Handle 0.5 and .5
257
+ v = assign(match[ndx++], s);
258
+ }
259
+ ndx++;
260
+
261
+ // Check for decimal places
262
+ if (ndx + 1 === match.length || match[ndx + 1] === '(' && match[ndx + 3] === ')' || match[ndx + 1] === "'" && match[ndx + 3] === "'") {
263
+ w = assign(match[ndx], s);
264
+ y = C_TEN ** BigInt(match[ndx].length);
265
+ ndx++;
266
+ }
267
+
268
+ // Check for repeating places
269
+ if (match[ndx] === '(' && match[ndx + 2] === ')' || match[ndx] === "'" && match[ndx + 2] === "'") {
270
+ x = assign(match[ndx + 1], s);
271
+ z = C_TEN ** BigInt(match[ndx + 1].length) - C_ONE;
272
+ ndx += 3;
273
+ }
274
+
275
+ } else if (match[ndx + 1] === '/' || match[ndx + 1] === ':') { // Check for a simple fraction "123/456" or "123:456"
276
+ w = assign(match[ndx], s);
277
+ y = assign(match[ndx + 2], C_ONE);
278
+ ndx += 3;
279
+ } else if (match[ndx + 3] === '/' && match[ndx + 1] === ' ') { // Check for a complex fraction "123 1/2"
280
+ v = assign(match[ndx], s);
281
+ w = assign(match[ndx + 2], s);
282
+ y = assign(match[ndx + 4], C_ONE);
283
+ ndx += 5;
284
+ }
285
+
286
+ if (match.length <= ndx) { // Check for more tokens on the stack
287
+ d = y * z;
288
+ s = /* void */
289
+ n = x + d * v + z * w;
290
+ } else {
291
+ throw InvalidParameter();
292
+ }
293
+
294
+ } else if (typeof p1 === "bigint") {
295
+ n = p1;
296
+ s = p1;
297
+ d = C_ONE;
298
+ } else {
299
+ throw InvalidParameter();
300
+ }
301
+
302
+ if (d === C_ZERO) {
303
+ throw DivisionByZero();
304
+ }
305
+
306
+ P["s"] = s < C_ZERO ? -C_ONE : C_ONE;
307
+ P["n"] = n < C_ZERO ? -n : n;
308
+ P["d"] = d < C_ZERO ? -d : d;
309
+ };
310
+
311
+ function modpow(b, e, m) {
312
+
313
+ let r = C_ONE;
314
+ for (; e > C_ZERO; b = (b * b) % m, e >>= C_ONE) {
315
+
316
+ if (e & C_ONE) {
317
+ r = (r * b) % m;
318
+ }
319
+ }
320
+ return r;
321
+ }
322
+
323
+ function cycleLen(n, d) {
324
+
325
+ for (; d % C_TWO === C_ZERO;
326
+ d /= C_TWO) {
327
+ }
328
+
329
+ for (; d % C_FIVE === C_ZERO;
330
+ d /= C_FIVE) {
331
+ }
332
+
333
+ if (d === C_ONE) // Catch non-cyclic numbers
334
+ return C_ZERO;
335
+
336
+ // If we would like to compute really large numbers quicker, we could make use of Fermat's little theorem:
337
+ // 10^(d-1) % d == 1
338
+ // However, we don't need such large numbers and MAX_CYCLE_LEN should be the capstone,
339
+ // as we want to translate the numbers to strings.
340
+
341
+ let rem = C_TEN % d;
342
+ let t = 1;
343
+
344
+ for (; rem !== C_ONE; t++) {
345
+ rem = rem * C_TEN % d;
346
+
347
+ if (t > MAX_CYCLE_LEN)
348
+ return C_ZERO; // Returning 0 here means that we don't print it as a cyclic number. It's likely that the answer is `d-1`
349
+ }
350
+ return BigInt(t);
351
+ }
352
+
353
+ function cycleStart(n, d, len) {
354
+
355
+ let rem1 = C_ONE;
356
+ let rem2 = modpow(C_TEN, len, d);
357
+
358
+ for (let t = 0; t < 300; t++) { // s < ~log10(Number.MAX_VALUE)
359
+ // Solve 10^s == 10^(s+t) (mod d)
360
+
361
+ if (rem1 === rem2)
362
+ return BigInt(t);
363
+
364
+ rem1 = rem1 * C_TEN % d;
365
+ rem2 = rem2 * C_TEN % d;
366
+ }
367
+ return 0;
368
+ }
369
+
370
+ function gcd(a, b) {
371
+
372
+ if (!a)
373
+ return b;
374
+ if (!b)
375
+ return a;
376
+
377
+ while (1) {
378
+ a %= b;
379
+ if (!a)
380
+ return b;
381
+ b %= a;
382
+ if (!b)
383
+ return a;
384
+ }
385
+ }
386
+
387
+ /**
388
+ * Module constructor
389
+ *
390
+ * @constructor
391
+ * @param {number|Fraction=} a
392
+ * @param {number=} b
393
+ */
394
+ function Fraction(a, b) {
395
+
396
+ parse(a, b);
397
+
398
+ if (this instanceof Fraction) {
399
+ a = gcd(P["d"], P["n"]); // Abuse a
400
+ this["s"] = P["s"];
401
+ this["n"] = P["n"] / a;
402
+ this["d"] = P["d"] / a;
403
+ } else {
404
+ return newFraction(P['s'] * P['n'], P['d']);
405
+ }
406
+ }
407
+
408
+ const DivisionByZero = function () { return new Error("Division by Zero"); };
409
+ const InvalidParameter = function () { return new Error("Invalid argument"); };
410
+ const NonIntegerParameter = function () { return new Error("Parameters must be integer"); };
411
+
412
+ Fraction.prototype = {
413
+
414
+ "s": C_ONE,
415
+ "n": C_ZERO,
416
+ "d": C_ONE,
417
+
418
+ /**
419
+ * Calculates the absolute value
420
+ *
421
+ * Ex: new Fraction(-4).abs() => 4
422
+ **/
423
+ "abs": function () {
424
+
425
+ return newFraction(this["n"], this["d"]);
426
+ },
427
+
428
+ /**
429
+ * Inverts the sign of the current fraction
430
+ *
431
+ * Ex: new Fraction(-4).neg() => 4
432
+ **/
433
+ "neg": function () {
434
+
435
+ return newFraction(-this["s"] * this["n"], this["d"]);
436
+ },
437
+
438
+ /**
439
+ * Adds two rational numbers
440
+ *
441
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => 467 / 30
442
+ **/
443
+ "add": function (a, b) {
444
+
445
+ parse(a, b);
446
+ return newFraction(
447
+ this["s"] * this["n"] * P["d"] + P["s"] * this["d"] * P["n"],
448
+ this["d"] * P["d"]
449
+ );
450
+ },
451
+
452
+ /**
453
+ * Subtracts two rational numbers
454
+ *
455
+ * Ex: new Fraction({n: 2, d: 3}).add("14.9") => -427 / 30
456
+ **/
457
+ "sub": function (a, b) {
458
+
459
+ parse(a, b);
460
+ return newFraction(
461
+ this["s"] * this["n"] * P["d"] - P["s"] * this["d"] * P["n"],
462
+ this["d"] * P["d"]
463
+ );
464
+ },
465
+
466
+ /**
467
+ * Multiplies two rational numbers
468
+ *
469
+ * Ex: new Fraction("-17.(345)").mul(3) => 5776 / 111
470
+ **/
471
+ "mul": function (a, b) {
472
+
473
+ parse(a, b);
474
+ return newFraction(
475
+ this["s"] * P["s"] * this["n"] * P["n"],
476
+ this["d"] * P["d"]
477
+ );
478
+ },
479
+
480
+ /**
481
+ * Divides two rational numbers
482
+ *
483
+ * Ex: new Fraction("-17.(345)").inverse().div(3)
484
+ **/
485
+ "div": function (a, b) {
486
+
487
+ parse(a, b);
488
+ return newFraction(
489
+ this["s"] * P["s"] * this["n"] * P["d"],
490
+ this["d"] * P["n"]
491
+ );
492
+ },
493
+
494
+ /**
495
+ * Clones the actual object
496
+ *
497
+ * Ex: new Fraction("-17.(345)").clone()
498
+ **/
499
+ "clone": function () {
500
+ return newFraction(this['s'] * this['n'], this['d']);
501
+ },
502
+
503
+ /**
504
+ * Calculates the modulo of two rational numbers - a more precise fmod
505
+ *
506
+ * Ex: new Fraction('4.(3)').mod([7, 8]) => (13/3) % (7/8) = (5/6)
507
+ * Ex: new Fraction(20, 10).mod().equals(0) ? "is Integer"
508
+ **/
509
+ "mod": function (a, b) {
510
+
511
+ if (a === undefined) {
512
+ return newFraction(this["s"] * this["n"] % this["d"], C_ONE);
513
+ }
514
+
515
+ parse(a, b);
516
+ if (C_ZERO === P["n"] * this["d"]) {
517
+ throw DivisionByZero();
518
+ }
519
+
520
+ /**
521
+ * I derived the rational modulo similar to the modulo for integers
522
+ *
523
+ * https://raw.org/book/analysis/rational-numbers/
524
+ *
525
+ * n1/d1 = (n2/d2) * q + r, where 0 ≤ r < n2/d2
526
+ * => d2 * n1 = n2 * d1 * q + d1 * d2 * r
527
+ * => r = (d2 * n1 - n2 * d1 * q) / (d1 * d2)
528
+ * = (d2 * n1 - n2 * d1 * floor((d2 * n1) / (n2 * d1))) / (d1 * d2)
529
+ * = ((d2 * n1) % (n2 * d1)) / (d1 * d2)
530
+ */
531
+ return newFraction(
532
+ this["s"] * (P["d"] * this["n"]) % (P["n"] * this["d"]),
533
+ P["d"] * this["d"]);
534
+ },
535
+
536
+ /**
537
+ * Calculates the fractional gcd of two rational numbers
538
+ *
539
+ * Ex: new Fraction(5,8).gcd(3,7) => 1/56
540
+ */
541
+ "gcd": function (a, b) {
542
+
543
+ parse(a, b);
544
+
545
+ // https://raw.org/book/analysis/rational-numbers/
546
+ // gcd(a / b, c / d) = gcd(a, c) / lcm(b, d)
547
+
548
+ return newFraction(gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]), P["d"] * this["d"]);
549
+ },
550
+
551
+ /**
552
+ * Calculates the fractional lcm of two rational numbers
553
+ *
554
+ * Ex: new Fraction(5,8).lcm(3,7) => 15
555
+ */
556
+ "lcm": function (a, b) {
557
+
558
+ parse(a, b);
559
+
560
+ // https://raw.org/book/analysis/rational-numbers/
561
+ // lcm(a / b, c / d) = lcm(a, c) / gcd(b, d)
562
+
563
+ if (P["n"] === C_ZERO && this["n"] === C_ZERO) {
564
+ return newFraction(C_ZERO, C_ONE);
565
+ }
566
+ return newFraction(P["n"] * this["n"], gcd(P["n"], this["n"]) * gcd(P["d"], this["d"]));
567
+ },
568
+
569
+ /**
570
+ * Gets the inverse of the fraction, means numerator and denominator are exchanged
571
+ *
572
+ * Ex: new Fraction([-3, 4]).inverse() => -4 / 3
573
+ **/
574
+ "inverse": function () {
575
+ return newFraction(this["s"] * this["d"], this["n"]);
576
+ },
577
+
578
+ /**
579
+ * Calculates the fraction to some integer exponent
580
+ *
581
+ * Ex: new Fraction(-1,2).pow(-3) => -8
582
+ */
583
+ "pow": function (a, b) {
584
+
585
+ parse(a, b);
586
+
587
+ // Trivial case when exp is an integer
588
+
589
+ if (P['d'] === C_ONE) {
590
+
591
+ if (P['s'] < C_ZERO) {
592
+ return newFraction((this['s'] * this["d"]) ** P['n'], this["n"] ** P['n']);
593
+ } else {
594
+ return newFraction((this['s'] * this["n"]) ** P['n'], this["d"] ** P['n']);
595
+ }
596
+ }
597
+
598
+ // Negative roots become complex
599
+ // (-a/b)^(c/d) = x
600
+ // ⇔ (-1)^(c/d) * (a/b)^(c/d) = x
601
+ // ⇔ (cos(pi) + i*sin(pi))^(c/d) * (a/b)^(c/d) = x
602
+ // ⇔ (cos(c*pi/d) + i*sin(c*pi/d)) * (a/b)^(c/d) = x # DeMoivre's formula
603
+ // From which follows that only for c=0 the root is non-complex
604
+ if (this['s'] < C_ZERO) return null;
605
+
606
+ // Now prime factor n and d
607
+ let N = factorize(this['n']);
608
+ let D = factorize(this['d']);
609
+
610
+ // Exponentiate and take root for n and d individually
611
+ let n = C_ONE;
612
+ let d = C_ONE;
613
+ for (let k in N) {
614
+ if (k === '1') continue;
615
+ if (k === '0') {
616
+ n = C_ZERO;
617
+ break;
618
+ }
619
+ N[k] *= P['n'];
620
+
621
+ if (N[k] % P['d'] === C_ZERO) {
622
+ N[k] /= P['d'];
623
+ } else return null;
624
+ n *= BigInt(k) ** N[k];
625
+ }
626
+
627
+ for (let k in D) {
628
+ if (k === '1') continue;
629
+ D[k] *= P['n'];
630
+
631
+ if (D[k] % P['d'] === C_ZERO) {
632
+ D[k] /= P['d'];
633
+ } else return null;
634
+ d *= BigInt(k) ** D[k];
635
+ }
636
+
637
+ if (P['s'] < C_ZERO) {
638
+ return newFraction(d, n);
639
+ }
640
+ return newFraction(n, d);
641
+ },
642
+
643
+ /**
644
+ * Calculates the logarithm of a fraction to a given rational base
645
+ *
646
+ * Ex: new Fraction(27, 8).log(9, 4) => 3/2
647
+ */
648
+ "log": function (a, b) {
649
+
650
+ parse(a, b);
651
+
652
+ if (this['s'] <= C_ZERO || P['s'] <= C_ZERO) return null;
653
+
654
+ const allPrimes = Object.create(null);
655
+
656
+ const baseFactors = factorize(P['n']);
657
+ const T1 = factorize(P['d']);
658
+
659
+ const numberFactors = factorize(this['n']);
660
+ const T2 = factorize(this['d']);
661
+
662
+ for (const prime in T1) {
663
+ baseFactors[prime] = (baseFactors[prime] || C_ZERO) - T1[prime];
664
+ }
665
+ for (const prime in T2) {
666
+ numberFactors[prime] = (numberFactors[prime] || C_ZERO) - T2[prime];
667
+ }
668
+
669
+ for (const prime in baseFactors) {
670
+ if (prime === '1') continue;
671
+ allPrimes[prime] = true;
672
+ }
673
+ for (const prime in numberFactors) {
674
+ if (prime === '1') continue;
675
+ allPrimes[prime] = true;
676
+ }
677
+
678
+ let retN = null;
679
+ let retD = null;
680
+
681
+ // Iterate over all unique primes to determine if a consistent ratio exists
682
+ for (const prime in allPrimes) {
683
+
684
+ const baseExponent = baseFactors[prime] || C_ZERO;
685
+ const numberExponent = numberFactors[prime] || C_ZERO;
686
+
687
+ if (baseExponent === C_ZERO) {
688
+ if (numberExponent !== C_ZERO) {
689
+ return null; // Logarithm cannot be expressed as a rational number
690
+ }
691
+ continue; // Skip this prime since both exponents are zero
692
+ }
693
+
694
+ // Calculate the ratio of exponents for this prime
695
+ let curN = numberExponent;
696
+ let curD = baseExponent;
697
+
698
+ // Simplify the current ratio
699
+ const gcdValue = gcd(curN, curD);
700
+ curN /= gcdValue;
701
+ curD /= gcdValue;
702
+
703
+ // Check if this is the first ratio; otherwise, ensure ratios are consistent
704
+ if (retN === null && retD === null) {
705
+ retN = curN;
706
+ retD = curD;
707
+ } else if (curN * retD !== retN * curD) {
708
+ return null; // Ratios do not match, logarithm cannot be rational
709
+ }
710
+ }
711
+
712
+ return retN !== null && retD !== null
713
+ ? newFraction(retN, retD)
714
+ : null;
715
+ },
716
+
717
+ /**
718
+ * Check if two rational numbers are the same
719
+ *
720
+ * Ex: new Fraction(19.6).equals([98, 5]);
721
+ **/
722
+ "equals": function (a, b) {
723
+
724
+ parse(a, b);
725
+ return this["s"] * this["n"] * P["d"] === P["s"] * P["n"] * this["d"];
726
+ },
727
+
728
+ /**
729
+ * Check if this rational number is less than another
730
+ *
731
+ * Ex: new Fraction(19.6).lt([98, 5]);
732
+ **/
733
+ "lt": function (a, b) {
734
+
735
+ parse(a, b);
736
+ return this["s"] * this["n"] * P["d"] < P["s"] * P["n"] * this["d"];
737
+ },
738
+
739
+ /**
740
+ * Check if this rational number is less than or equal another
741
+ *
742
+ * Ex: new Fraction(19.6).lt([98, 5]);
743
+ **/
744
+ "lte": function (a, b) {
745
+
746
+ parse(a, b);
747
+ return this["s"] * this["n"] * P["d"] <= P["s"] * P["n"] * this["d"];
748
+ },
749
+
750
+ /**
751
+ * Check if this rational number is greater than another
752
+ *
753
+ * Ex: new Fraction(19.6).lt([98, 5]);
754
+ **/
755
+ "gt": function (a, b) {
756
+
757
+ parse(a, b);
758
+ return this["s"] * this["n"] * P["d"] > P["s"] * P["n"] * this["d"];
759
+ },
760
+
761
+ /**
762
+ * Check if this rational number is greater than or equal another
763
+ *
764
+ * Ex: new Fraction(19.6).lt([98, 5]);
765
+ **/
766
+ "gte": function (a, b) {
767
+
768
+ parse(a, b);
769
+ return this["s"] * this["n"] * P["d"] >= P["s"] * P["n"] * this["d"];
770
+ },
771
+
772
+ /**
773
+ * Compare two rational numbers
774
+ * < 0 iff this < that
775
+ * > 0 iff this > that
776
+ * = 0 iff this = that
777
+ *
778
+ * Ex: new Fraction(19.6).compare([98, 5]);
779
+ **/
780
+ "compare": function (a, b) {
781
+
782
+ parse(a, b);
783
+ let t = this["s"] * this["n"] * P["d"] - P["s"] * P["n"] * this["d"];
784
+
785
+ return (C_ZERO < t) - (t < C_ZERO);
786
+ },
787
+
788
+ /**
789
+ * Calculates the ceil of a rational number
790
+ *
791
+ * Ex: new Fraction('4.(3)').ceil() => (5 / 1)
792
+ **/
793
+ "ceil": function (places) {
794
+
795
+ places = C_TEN ** BigInt(places || 0);
796
+
797
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
798
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] >= C_ZERO ? C_ONE : C_ZERO),
799
+ places);
800
+ },
801
+
802
+ /**
803
+ * Calculates the floor of a rational number
804
+ *
805
+ * Ex: new Fraction('4.(3)').floor() => (4 / 1)
806
+ **/
807
+ "floor": function (places) {
808
+
809
+ places = C_TEN ** BigInt(places || 0);
810
+
811
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) -
812
+ (places * this["n"] % this["d"] > C_ZERO && this["s"] < C_ZERO ? C_ONE : C_ZERO),
813
+ places);
814
+ },
815
+
816
+ /**
817
+ * Rounds a rational numbers
818
+ *
819
+ * Ex: new Fraction('4.(3)').round() => (4 / 1)
820
+ **/
821
+ "round": function (places) {
822
+
823
+ places = C_TEN ** BigInt(places || 0);
824
+
825
+ /* Derivation:
826
+
827
+ s >= 0:
828
+ round(n / d) = ifloor(n / d) + (n % d) / d >= 0.5 ? 1 : 0
829
+ = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
830
+ s < 0:
831
+ round(n / d) =-ifloor(n / d) - (n % d) / d > 0.5 ? 1 : 0
832
+ =-ifloor(n / d) - 2(n % d) > d ? 1 : 0
833
+
834
+ =>:
835
+
836
+ round(s * n / d) = s * ifloor(n / d) + s * (C + 2(n % d) > d ? 1 : 0)
837
+ where C = s >= 0 ? 1 : 0, to fix the >= for the positve case.
838
+ */
839
+
840
+ return newFraction(ifloor(this["s"] * places * this["n"] / this["d"]) +
841
+ this["s"] * ((this["s"] >= C_ZERO ? C_ONE : C_ZERO) + C_TWO * (places * this["n"] % this["d"]) > this["d"] ? C_ONE : C_ZERO),
842
+ places);
843
+ },
844
+
845
+ /**
846
+ * Rounds a rational number to a multiple of another rational number
847
+ *
848
+ * Ex: new Fraction('0.9').roundTo("1/8") => 7 / 8
849
+ **/
850
+ "roundTo": function (a, b) {
851
+
852
+ /*
853
+ k * x/y ≤ a/b < (k+1) * x/y
854
+ ⇔ k ≤ a/b / (x/y) < (k+1)
855
+ ⇔ k = floor(a/b * y/x)
856
+ ⇔ k = floor((a * y) / (b * x))
857
+ */
858
+
859
+ parse(a, b);
860
+
861
+ const n = this['n'] * P['d'];
862
+ const d = this['d'] * P['n'];
863
+ const r = n % d;
864
+
865
+ // round(n / d) = ifloor(n / d) + 2(n % d) >= d ? 1 : 0
866
+ let k = ifloor(n / d);
867
+ if (r + r >= d) {
868
+ k++;
869
+ }
870
+ return newFraction(this['s'] * k * P['n'], P['d']);
871
+ },
872
+
873
+ /**
874
+ * Check if two rational numbers are divisible
875
+ *
876
+ * Ex: new Fraction(19.6).divisible(1.5);
877
+ */
878
+ "divisible": function (a, b) {
879
+
880
+ parse(a, b);
881
+ if (P['n'] === C_ZERO) return false;
882
+ return (this['n'] * P['d']) % (P['n'] * this['d']) === C_ZERO;
883
+ },
884
+
885
+ /**
886
+ * Returns a decimal representation of the fraction
887
+ *
888
+ * Ex: new Fraction("100.'91823'").valueOf() => 100.91823918239183
889
+ **/
890
+ 'valueOf': function () {
891
+ //if (this['n'] <= MAX_INTEGER && this['d'] <= MAX_INTEGER) {
892
+ return Number(this['s'] * this['n']) / Number(this['d']);
893
+ //}
894
+ },
895
+
896
+ /**
897
+ * Creates a string representation of a fraction with all digits
898
+ *
899
+ * Ex: new Fraction("100.'91823'").toString() => "100.(91823)"
900
+ **/
901
+ 'toString': function (dec = 15) {
902
+
903
+ let N = this["n"];
904
+ let D = this["d"];
905
+
906
+ let cycLen = cycleLen(N, D); // Cycle length
907
+ let cycOff = cycleStart(N, D, cycLen); // Cycle start
908
+
909
+ let str = this['s'] < C_ZERO ? "-" : "";
910
+
911
+ // Append integer part
912
+ str += ifloor(N / D);
913
+
914
+ N %= D;
915
+ N *= C_TEN;
916
+
917
+ if (N)
918
+ str += ".";
919
+
920
+ if (cycLen) {
921
+
922
+ for (let i = cycOff; i--;) {
923
+ str += ifloor(N / D);
924
+ N %= D;
925
+ N *= C_TEN;
926
+ }
927
+ str += "(";
928
+ for (let i = cycLen; i--;) {
929
+ str += ifloor(N / D);
930
+ N %= D;
931
+ N *= C_TEN;
932
+ }
933
+ str += ")";
934
+ } else {
935
+ for (let i = dec; N && i--;) {
936
+ str += ifloor(N / D);
937
+ N %= D;
938
+ N *= C_TEN;
939
+ }
940
+ }
941
+ return str;
942
+ },
943
+
944
+ /**
945
+ * Returns a string-fraction representation of a Fraction object
946
+ *
947
+ * Ex: new Fraction("1.'3'").toFraction() => "4 1/3"
948
+ **/
949
+ 'toFraction': function (showMixed = false) {
950
+
951
+ let n = this["n"];
952
+ let d = this["d"];
953
+ let str = this['s'] < C_ZERO ? "-" : "";
954
+
955
+ if (d === C_ONE) {
956
+ str += n;
957
+ } else {
958
+ const whole = ifloor(n / d);
959
+ if (showMixed && whole > C_ZERO) {
960
+ str += whole;
961
+ str += " ";
962
+ n %= d;
963
+ }
964
+
965
+ str += n;
966
+ str += '/';
967
+ str += d;
968
+ }
969
+ return str;
970
+ },
971
+
972
+ /**
973
+ * Returns a latex representation of a Fraction object
974
+ *
975
+ * Ex: new Fraction("1.'3'").toLatex() => "\frac{4}{3}"
976
+ **/
977
+ 'toLatex': function (showMixed = false) {
978
+
979
+ let n = this["n"];
980
+ let d = this["d"];
981
+ let str = this['s'] < C_ZERO ? "-" : "";
982
+
983
+ if (d === C_ONE) {
984
+ str += n;
985
+ } else {
986
+ const whole = ifloor(n / d);
987
+ if (showMixed && whole > C_ZERO) {
988
+ str += whole;
989
+ n %= d;
990
+ }
991
+
992
+ str += "\\frac{";
993
+ str += n;
994
+ str += '}{';
995
+ str += d;
996
+ str += '}';
997
+ }
998
+ return str;
999
+ },
1000
+
1001
+ /**
1002
+ * Returns an array of continued fraction elements
1003
+ *
1004
+ * Ex: new Fraction("7/8").toContinued() => [0,1,7]
1005
+ */
1006
+ 'toContinued': function () {
1007
+
1008
+ let a = this['n'];
1009
+ let b = this['d'];
1010
+ const res = [];
1011
+
1012
+ while (b) {
1013
+ res.push(ifloor(a / b));
1014
+ const t = a % b;
1015
+ a = b;
1016
+ b = t;
1017
+ }
1018
+ return res;
1019
+ },
1020
+
1021
+ "simplify": function (eps = 1e-3) {
1022
+
1023
+ // Continued fractions give best approximations for a max denominator,
1024
+ // generally outperforming mediants in denominator–accuracy trade-offs.
1025
+ // Semiconvergents can further reduce the denominator within tolerance.
1026
+
1027
+ const ieps = BigInt(Math.ceil(1 / eps));
1028
+
1029
+ const thisABS = this['abs']();
1030
+ const cont = thisABS['toContinued']();
1031
+
1032
+ for (let i = 1; i < cont.length; i++) {
1033
+
1034
+ let s = newFraction(cont[i - 1], C_ONE);
1035
+ for (let k = i - 2; k >= 0; k--) {
1036
+ s = s['inverse']()['add'](cont[k]);
1037
+ }
1038
+
1039
+ let t = s['sub'](thisABS);
1040
+ if (t['n'] * ieps < t['d']) { // More robust than Math.abs(t.valueOf()) < eps
1041
+ return s['mul'](this['s']);
1042
+ }
1043
+ }
1044
+ return this;
1045
+ }
1046
+ };
web/node_modules/fraction.js/tests/fraction.test.js ADDED
@@ -0,0 +1,1806 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const Fraction = require('fraction.js');
2
+ const assert = require('assert');
3
+
4
+ var DivisionByZero = function () { return new Error("Division by Zero"); };
5
+ var InvalidParameter = function () { return new Error("Invalid argument"); };
6
+ var NonIntegerParameter = function () { return new Error("Parameters must be integer"); };
7
+
8
+ var tests = [{
9
+ set: "",
10
+ expectError: InvalidParameter()
11
+ }, {
12
+ set: "foo",
13
+ expectError: InvalidParameter()
14
+ }, {
15
+ set: " 123",
16
+ expectError: InvalidParameter()
17
+ }, {
18
+ set: 0,
19
+ expect: 0
20
+ }, {
21
+ set: .2,
22
+ expect: "0.2"
23
+ }, {
24
+ set: .333,
25
+ expect: "0.333"
26
+ }, {
27
+ set: 1.1,
28
+ expect: "1.1"
29
+ }, {
30
+ set: 1.2,
31
+ expect: "1.2"
32
+ }, {
33
+ set: 1.3,
34
+ expect: "1.3"
35
+ }, {
36
+ set: 1.4,
37
+ expect: "1.4"
38
+ }, {
39
+ set: 1.5,
40
+ expect: "1.5"
41
+ }, {
42
+ set: 2.555,
43
+ expect: "2.555"
44
+ }, {
45
+ set: 1e12,
46
+ expect: "1000000000000"
47
+ }, {
48
+ set: " - ",
49
+ expectError: InvalidParameter()
50
+ }, {
51
+ set: ".5",
52
+ expect: "0.5"
53
+ }, {
54
+ set: "2_000_000",
55
+ expect: "2000000"
56
+ }, {
57
+ set: "-.5",
58
+ expect: "-0.5"
59
+ }, {
60
+ set: "123",
61
+ expect: "123"
62
+ }, {
63
+ set: "-123",
64
+ expect: "-123"
65
+ }, {
66
+ set: "123.4",
67
+ expect: "123.4"
68
+ }, {
69
+ set: "-123.4",
70
+ expect: "-123.4"
71
+ }, {
72
+ set: "123.",
73
+ expect: "123"
74
+ }, {
75
+ set: "-123.",
76
+ expect: "-123"
77
+ }, {
78
+ set: "123.4(56)",
79
+ expect: "123.4(56)"
80
+ }, {
81
+ set: "-123.4(56)",
82
+ expect: "-123.4(56)"
83
+ }, {
84
+ set: "123.(4)",
85
+ expect: "123.(4)"
86
+ }, {
87
+ set: "-123.(4)",
88
+ expect: "-123.(4)"
89
+ }, {
90
+ set: "0/0",
91
+ expectError: DivisionByZero()
92
+ }, {
93
+ set: "9/0",
94
+ expectError: DivisionByZero()
95
+ }, {
96
+ label: "0/1+0/1",
97
+ set: "0/1",
98
+ param: "0/1",
99
+ expect: "0"
100
+ }, {
101
+ label: "1/9+0/1",
102
+ set: "1/9",
103
+ param: "0/1",
104
+ expect: "0.(1)"
105
+ }, {
106
+ set: "123/456",
107
+ expect: "0.269(736842105263157894)"
108
+ }, {
109
+ set: "-123/456",
110
+ expect: "-0.269(736842105263157894)"
111
+ }, {
112
+ set: "19 123/456",
113
+ expect: "19.269(736842105263157894)"
114
+ }, {
115
+ set: "-19 123/456",
116
+ expect: "-19.269(736842105263157894)"
117
+ }, {
118
+ set: "123.(22)123",
119
+ expectError: InvalidParameter()
120
+ }, {
121
+ set: "+33.3(3)",
122
+ expect: "33.(3)"
123
+ }, {
124
+ set: "3.'09009'",
125
+ expect: "3.(09009)"
126
+ }, {
127
+ set: "123.(((",
128
+ expectError: InvalidParameter()
129
+ }, {
130
+ set: "123.((",
131
+ expectError: InvalidParameter()
132
+ }, {
133
+ set: "123.()",
134
+ expectError: InvalidParameter()
135
+ }, {
136
+ set: null,
137
+ expect: "0" // I would say it's just fine
138
+ }, {
139
+ set: [22, 7],
140
+ expect: '3.(142857)' // We got Pi! - almost ;o
141
+ }, {
142
+ set: "355/113",
143
+ expect: "3.(1415929203539823008849557522123893805309734513274336283185840707964601769911504424778761061946902654867256637168)" // Yay, a better PI
144
+ }, {
145
+ set: "3 1/7",
146
+ expect: '3.(142857)'
147
+ }, {
148
+ set: [36, -36],
149
+ expect: "-1"
150
+ }, {
151
+ set: [1n, 3n],
152
+ expect: "0.(3)"
153
+ }, {
154
+ set: 1n,
155
+ set2: 3n,
156
+ expect: "0.(3)"
157
+ }, {
158
+ set: { n: 1n, d: 3n },
159
+ expect: "0.(3)"
160
+ }, {
161
+ set: { n: 1n, d: 3n },
162
+ expect: "0.(3)"
163
+ }, {
164
+ set: [1n, 3n],
165
+ expect: "0.(3)"
166
+ }, {
167
+ set: "9/12",
168
+ expect: "0.75"
169
+ }, {
170
+ set: "0.09(33)",
171
+ expect: "0.09(3)"
172
+ }, {
173
+ set: 1 / 2,
174
+ expect: "0.5"
175
+ }, {
176
+ set: 1 / 3,
177
+ expect: "0.(3)"
178
+ }, {
179
+ set: "0.'3'",
180
+ expect: "0.(3)"
181
+ }, {
182
+ set: "0.00002",
183
+ expect: "0.00002"
184
+ }, {
185
+ set: 7 / 8,
186
+ expect: "0.875"
187
+ }, {
188
+ set: 0.003,
189
+ expect: "0.003"
190
+ }, {
191
+ set: 4,
192
+ expect: "4"
193
+ }, {
194
+ set: -99,
195
+ expect: "-99"
196
+ }, {
197
+ set: "-92332.1192",
198
+ expect: "-92332.1192"
199
+ }, {
200
+ set: '88.92933(12111)',
201
+ expect: "88.92933(12111)"
202
+ }, {
203
+ set: '-192322.823(123)',
204
+ expect: "-192322.8(231)"
205
+ }, {
206
+ label: "-99.12 % 0.09(34)",
207
+ set: '-99.12',
208
+ fn: "mod",
209
+ param: "0.09(34)",
210
+ expect: "-0.07(95)"
211
+ }, {
212
+ label: "0.4 / 0.1",
213
+ set: .4,
214
+ fn: "div",
215
+ param: ".1",
216
+ expect: "4"
217
+ }, {
218
+ label: "1 / -.1",
219
+ set: 1,
220
+ fn: "div",
221
+ param: "-.1",
222
+ expect: "-10"
223
+ }, {
224
+ label: "1 - (-1)",
225
+ set: 1,
226
+ fn: "sub",
227
+ param: "-1",
228
+ expect: "2"
229
+ }, {
230
+ label: "1 + (-1)",
231
+ set: 1,
232
+ fn: "add",
233
+ param: "-1",
234
+ expect: "0"
235
+ }, {
236
+ label: "-187 % 12",
237
+ set: '-187',
238
+ fn: "mod",
239
+ param: "12",
240
+ expect: "-7"
241
+ }, {
242
+ label: "Negate by 99 * -1",
243
+ set: '99',
244
+ fn: "mul",
245
+ param: "-1",
246
+ expect: "-99"
247
+ }, {
248
+ label: "0.5050000000000000000000000",
249
+ set: "0.5050000000000000000000000",
250
+ expect: "101/200",
251
+ fn: "toFraction",
252
+ param: true
253
+ }, {
254
+ label: "0.505000000(0000000000)",
255
+ set: "0.505000000(0000000000)",
256
+ expect: "101/200",
257
+ fn: "toFraction",
258
+ param: true
259
+ }, {
260
+ set: [20, -5],
261
+ expect: "-4",
262
+ fn: "toFraction",
263
+ param: true
264
+ }, {
265
+ set: [-10, -7],
266
+ expect: "1 3/7",
267
+ fn: "toFraction",
268
+ param: true
269
+ }, {
270
+ set: [21, -6],
271
+ expect: "-3 1/2",
272
+ fn: "toFraction",
273
+ param: true
274
+ }, {
275
+ set: "10/78",
276
+ expect: "5/39",
277
+ fn: "toFraction",
278
+ param: true
279
+ }, {
280
+ set: "0/91",
281
+ expect: "0",
282
+ fn: "toFraction",
283
+ param: true
284
+ }, {
285
+ set: "-0/287",
286
+ expect: "0",
287
+ fn: "toFraction",
288
+ param: true
289
+ }, {
290
+ set: "-5/20",
291
+ expect: "-1/4",
292
+ fn: "toFraction",
293
+ param: true
294
+ }, {
295
+ set: "42/9",
296
+ expect: "4 2/3",
297
+ fn: "toFraction",
298
+ param: true
299
+ }, {
300
+ set: "71/23",
301
+ expect: "3 2/23",
302
+ fn: "toFraction",
303
+ param: true
304
+ }, {
305
+ set: "6/3",
306
+ expect: "2",
307
+ fn: "toFraction",
308
+ param: true
309
+ }, {
310
+ set: "28/4",
311
+ expect: "7",
312
+ fn: "toFraction",
313
+ param: true
314
+ }, {
315
+ set: "105/35",
316
+ expect: "3",
317
+ fn: "toFraction",
318
+ param: true
319
+ }, {
320
+ set: "4/6",
321
+ expect: "2/3",
322
+ fn: "toFraction",
323
+ param: true
324
+ }, {
325
+ label: "99.(9) + 66",
326
+ set: '99.(999999)',
327
+ fn: "add",
328
+ param: "66",
329
+ expect: "166"
330
+ }, {
331
+ label: "123.32 / 33.'9821'",
332
+ set: '123.32',
333
+ fn: "div",
334
+ param: "33.'9821'",
335
+ expect: "3.628958880242975"
336
+ }, {
337
+ label: "-82.124 / 66.(3)",
338
+ set: '-82.124',
339
+ fn: "div",
340
+ param: "66.(3)",
341
+ expect: "-1.238(050251256281407035175879396984924623115577889447236180904522613065326633165829145728643216080402010)"
342
+ }, {
343
+ label: "100 - .91",
344
+ set: '100',
345
+ fn: "sub",
346
+ param: ".91",
347
+ expect: "99.09"
348
+ }, {
349
+ label: "381.(33411) % 11.119(356)",
350
+ set: '381.(33411)',
351
+ fn: "mod",
352
+ param: "11.119(356)",
353
+ expect: "3.275(997225017295217)"
354
+ }, {
355
+ label: "13/26 mod 1",
356
+ set: '13/26',
357
+ fn: "mod",
358
+ param: "1.000",
359
+ expect: "0.5"
360
+ }, {
361
+ label: "381.(33411) % 1", // Extract fraction part of a number
362
+ set: '381.(33411)',
363
+ fn: "mod",
364
+ param: "1",
365
+ expect: "0.(33411)"
366
+ }, {
367
+ label: "-222/3",
368
+ set: {
369
+ n: 3,
370
+ d: 222,
371
+ s: -1
372
+ },
373
+ fn: "inverse",
374
+ param: null,
375
+ expect: "-74"
376
+ }, {
377
+ label: "inverse",
378
+ set: 1 / 2,
379
+ fn: "inverse",
380
+ param: null,
381
+ expect: "2"
382
+ }, {
383
+ label: "abs(-222/3)",
384
+ set: {
385
+ n: -222,
386
+ d: 3
387
+ },
388
+ fn: "abs",
389
+ param: null,
390
+ expect: "74"
391
+ }, {
392
+ label: "9 % -2",
393
+ set: 9,
394
+ fn: "mod",
395
+ param: "-2",
396
+ expect: "1"
397
+ }, {
398
+ label: "-9 % 2",
399
+ set: '-9',
400
+ fn: "mod",
401
+ param: "-2",
402
+ expect: "-1"
403
+ }, {
404
+ label: "1 / 195312500",
405
+ set: '1',
406
+ fn: "div",
407
+ param: "195312500",
408
+ expect: "0.00000000512"
409
+ }, {
410
+ label: "10 / 0",
411
+ set: 10,
412
+ fn: "div",
413
+ param: 0,
414
+ expectError: DivisionByZero()
415
+ }, {
416
+ label: "-3 / 4",
417
+ set: [-3, 4],
418
+ fn: "inverse",
419
+ param: null,
420
+ expect: "-1.(3)"
421
+ }, {
422
+ label: "-19.6",
423
+ set: [-98, 5],
424
+ fn: "equals",
425
+ param: '-19.6',
426
+ expect: "true" // actually, we get a real bool but we call toString() in the test below
427
+ }, {
428
+ label: "-19.6",
429
+ set: [98, -5],
430
+ fn: "equals",
431
+ param: '-19.6',
432
+ expect: "true"
433
+ }, {
434
+ label: "99/88",
435
+ set: [99, 88],
436
+ fn: "equals",
437
+ param: [88, 99],
438
+ expect: "false"
439
+ }, {
440
+ label: "99/88",
441
+ set: [99, -88],
442
+ fn: "equals",
443
+ param: [9, 8],
444
+ expect: "false"
445
+ }, {
446
+ label: "12.5",
447
+ set: 12.5,
448
+ fn: "add",
449
+ param: 0,
450
+ expect: "12.5"
451
+ }, {
452
+ label: "0/1 -> 1/0",
453
+ set: 0,
454
+ fn: "inverse",
455
+ param: null,
456
+ expectError: DivisionByZero()
457
+ }, {
458
+ label: "abs(-100.25)",
459
+ set: -100.25,
460
+ fn: "abs",
461
+ param: null,
462
+ expect: "100.25"
463
+ }, {
464
+ label: "0.022222222",
465
+ set: '0.0(22222222)',
466
+ fn: "abs",
467
+ param: null,
468
+ expect: "0.0(2)"
469
+ }, {
470
+ label: "1.5 | 100.5",
471
+ set: 100.5,
472
+ fn: "divisible",
473
+ param: '1.5',
474
+ expect: "true"
475
+ }, {
476
+ label: "1.5 | 100.6",
477
+ set: 100.6,
478
+ fn: "divisible",
479
+ param: 1.6,
480
+ expect: "false"
481
+ }, {
482
+ label: "(1/6) | (2/3)", // == 4
483
+ set: [2, 3],
484
+ fn: "divisible",
485
+ param: [1, 6],
486
+ expect: "true"
487
+ }, {
488
+ label: "(1/6) | (2/5)",
489
+ set: [2, 5],
490
+ fn: "divisible",
491
+ param: [1, 6],
492
+ expect: "false"
493
+ }, {
494
+ label: "0 | (2/5)",
495
+ set: [2, 5],
496
+ fn: "divisible",
497
+ param: 0,
498
+ expect: "false"
499
+ }, {
500
+ label: "6 | 0",
501
+ set: 0,
502
+ fn: "divisible",
503
+ param: 6,
504
+ expect: "true"
505
+ }, {
506
+ label: "fmod(4.55, 0.05)", // http://phpjs.org/functions/fmod/ (comment section)
507
+ set: 4.55,
508
+ fn: "mod",
509
+ param: 0.05,
510
+ expect: "0"
511
+ }, {
512
+ label: "fmod(99.12, 0.4)",
513
+ set: 99.12,
514
+ fn: "mod",
515
+ param: "0.4",
516
+ expect: "0.32"
517
+ }, {
518
+ label: "fmod(fmod(1.0,0.1))", // http://stackoverflow.com/questions/4218961/why-fmod1-0-0-1-1
519
+ set: 1.0,
520
+ fn: "mod",
521
+ param: 0.1,
522
+ expect: "0"
523
+ }, {
524
+ label: "bignum",
525
+ set: [5385020324, 1673196525],
526
+ fn: "add",
527
+ param: 0,
528
+ expect: "3.21(840276592733181776121606516006839065124164060763872313206005492988936251824931324190982287630557922656455433410609073551596098372245902196097377144624418820138297860736950789447760776337973807350574075570710380240599651018280712721418065340531352107607323652551812465663589637206543923464101146157950573080469432602963360804254598843372567965379918536467197121390148715495330113717514444395585868193217769203770011415724163065662594535928766646225254382476081224230369471990147720394052336440275597631903998844367669243157195775313960803259497565595290726533154854597848271290188102679689703515252041298615534717298077104242133182771222884293284077911887845930112722413166618308629346454087334421161315763550250022184333666363549254920906556389124702491239037207539024741878423396797336762338781453063321417070239253574830368476888869943116813489676593728283053898883754853602746993512910863832926021645903191198654921901657666901979730085800889408373591978384009612977172541043856160291750546158945674358246709841810124486123947693472528578195558946669459524487119048971249805817042322628538808374587079661786890216019304725725509141850506771761314768448972244907094819599867385572056456428511886850828834945135927771544947477105237234460548500123140047759781236696030073335228807028510891749551057667897081007863078128255137273847732859712937785356684266362554153643129279150277938809369688357439064129062782986595074359241811119587401724970711375341877428295519559485099934689381452068220139292962014728066686607540019843156200674036183526020650801913421377683054893985032630879985)"
529
+ }, {
530
+ label: "ceil(0.4)",
531
+ set: 0.4,
532
+ fn: "ceil",
533
+ param: null,
534
+ expect: "1"
535
+ },
536
+
537
+
538
+ {
539
+ label: "1 < 2",
540
+ set: 1,
541
+ fn: "lt",
542
+ param: 2,
543
+ expect: "true"
544
+ }, {
545
+ label: "2 < 2",
546
+ set: 2,
547
+ fn: "lt",
548
+ param: 2,
549
+ expect: "false"
550
+ }, {
551
+ label: "3 > 2",
552
+ set: 3,
553
+ fn: "gt",
554
+ param: 2,
555
+ expect: "true"
556
+ }, {
557
+ label: "2 > 2",
558
+ set: 2,
559
+ fn: "gt",
560
+ param: 2,
561
+ expect: "false"
562
+ }, {
563
+ label: "1 <= 2",
564
+ set: 1,
565
+ fn: "lte",
566
+ param: 2,
567
+ expect: "true"
568
+ }, {
569
+ label: "2 <= 2",
570
+ set: 2,
571
+ fn: "lte",
572
+ param: 2,
573
+ expect: "true"
574
+ }, {
575
+ label: "3 <= 2",
576
+ set: 3,
577
+ fn: "lte",
578
+ param: 2,
579
+ expect: "false"
580
+ }, {
581
+ label: "3 >= 2",
582
+ set: 3,
583
+ fn: "gte",
584
+ param: 2,
585
+ expect: "true"
586
+ }, {
587
+ label: "2 >= 2",
588
+ set: 2,
589
+ fn: "gte",
590
+ param: 2,
591
+ expect: "true"
592
+ }, {
593
+ label: "ceil(0.5)",
594
+ set: 0.5,
595
+ fn: "ceil",
596
+ param: null,
597
+ expect: "1"
598
+ }, {
599
+ label: "ceil(0.23, 2)",
600
+ set: 0.23,
601
+ fn: "ceil",
602
+ param: 2,
603
+ expect: "0.23"
604
+ }, {
605
+ label: "ceil(0.6)",
606
+ set: 0.6,
607
+ fn: "ceil",
608
+ param: null,
609
+ expect: "1"
610
+ }, {
611
+ label: "ceil(-0.4)",
612
+ set: -0.4,
613
+ fn: "ceil",
614
+ param: null,
615
+ expect: "0"
616
+ }, {
617
+ label: "ceil(-0.5)",
618
+ set: -0.5,
619
+ fn: "ceil",
620
+ param: null,
621
+ expect: "0"
622
+ }, {
623
+ label: "ceil(-0.6)",
624
+ set: -0.6,
625
+ fn: "ceil",
626
+ param: null,
627
+ expect: "0"
628
+ }, {
629
+ label: "floor(0.4)",
630
+ set: 0.4,
631
+ fn: "floor",
632
+ param: null,
633
+ expect: "0"
634
+ }, {
635
+ label: "floor(0.4, 1)",
636
+ set: 0.4,
637
+ fn: "floor",
638
+ param: 1,
639
+ expect: "0.4"
640
+ }, {
641
+ label: "floor(0.5)",
642
+ set: 0.5,
643
+ fn: "floor",
644
+ param: null,
645
+ expect: "0"
646
+ }, {
647
+ label: "floor(0.6)",
648
+ set: 0.6,
649
+ fn: "floor",
650
+ param: null,
651
+ expect: "0"
652
+ }, {
653
+ label: "floor(-0.4)",
654
+ set: -0.4,
655
+ fn: "floor",
656
+ param: null,
657
+ expect: "-1"
658
+ }, {
659
+ label: "floor(-0.5)",
660
+ set: -0.5,
661
+ fn: "floor",
662
+ param: null,
663
+ expect: "-1"
664
+ }, {
665
+ label: "floor(-0.6)",
666
+ set: -0.6,
667
+ fn: "floor",
668
+ param: null,
669
+ expect: "-1"
670
+ }, {
671
+ label: "floor(10.4)",
672
+ set: 10.4,
673
+ fn: "floor",
674
+ param: null,
675
+ expect: "10"
676
+ }, {
677
+ label: "floor(10.4, 1)",
678
+ set: 10.4,
679
+ fn: "floor",
680
+ param: 1,
681
+ expect: "10.4"
682
+ }, {
683
+ label: "floor(10.5)",
684
+ set: 10.5,
685
+ fn: "floor",
686
+ param: null,
687
+ expect: "10"
688
+ }, {
689
+ label: "floor(10.6)",
690
+ set: 10.6,
691
+ fn: "floor",
692
+ param: null,
693
+ expect: "10"
694
+ }, {
695
+ label: "floor(-10.4)",
696
+ set: -10.4,
697
+ fn: "floor",
698
+ param: null,
699
+ expect: "-11"
700
+ }, {
701
+ label: "floor(-10.5)",
702
+ set: -10.5,
703
+ fn: "floor",
704
+ param: null,
705
+ expect: "-11"
706
+ }, {
707
+ label: "floor(-10.6)",
708
+ set: -10.6,
709
+ fn: "floor",
710
+ param: null,
711
+ expect: "-11"
712
+ }, {
713
+ label: "floor(-10.543,3)",
714
+ set: -10.543,
715
+ fn: "floor",
716
+ param: 3,
717
+ expect: "-10.543"
718
+ }, {
719
+ label: "floor(10.543,3)",
720
+ set: 10.543,
721
+ fn: "floor",
722
+ param: 3,
723
+ expect: "10.543"
724
+ }, {
725
+ label: "round(-10.543,3)",
726
+ set: -10.543,
727
+ fn: "round",
728
+ param: 3,
729
+ expect: "-10.543"
730
+ }, {
731
+ label: "round(10.543,3)",
732
+ set: 10.543,
733
+ fn: "round",
734
+ param: 3,
735
+ expect: "10.543"
736
+ }, {
737
+ label: "round(10.4)",
738
+ set: 10.4,
739
+ fn: "round",
740
+ param: null,
741
+ expect: "10"
742
+ }, {
743
+ label: "round(10.5)",
744
+ set: 10.5,
745
+ fn: "round",
746
+ param: null,
747
+ expect: "11"
748
+ }, {
749
+ label: "round(10.5, 1)",
750
+ set: 10.5,
751
+ fn: "round",
752
+ param: 1,
753
+ expect: "10.5"
754
+ }, {
755
+ label: "round(10.6)",
756
+ set: 10.6,
757
+ fn: "round",
758
+ param: null,
759
+ expect: "11"
760
+ }, {
761
+ label: "round(-10.4)",
762
+ set: -10.4,
763
+ fn: "round",
764
+ param: null,
765
+ expect: "-10"
766
+ }, {
767
+ label: "round(-10.5)",
768
+ set: -10.5,
769
+ fn: "round",
770
+ param: null,
771
+ expect: "-10"
772
+ }, {
773
+ label: "round(-10.6)",
774
+ set: -10.6,
775
+ fn: "round",
776
+ param: null,
777
+ expect: "-11"
778
+ }, {
779
+ label: "round(-0.4)",
780
+ set: -0.4,
781
+ fn: "round",
782
+ param: null,
783
+ expect: "0"
784
+ }, {
785
+ label: "round(-0.5)",
786
+ set: -0.5,
787
+ fn: "round",
788
+ param: null,
789
+ expect: "0"
790
+ }, {
791
+ label: "round(-0.6)",
792
+ set: -0.6,
793
+ fn: "round",
794
+ param: null,
795
+ expect: "-1"
796
+ }, {
797
+ label: "round(-0)",
798
+ set: -0,
799
+ fn: "round",
800
+ param: null,
801
+ expect: "0"
802
+ }, {
803
+ label: "round(big fraction)",
804
+ set: [
805
+ '409652136432929109317120'.repeat(100),
806
+ '63723676445298091081155'.repeat(100)
807
+ ],
808
+ fn: "round",
809
+ param: null,
810
+ expect: "6428570341270001560623330590225448467479093479780591305451264291405695842465355472558570608574213642"
811
+ }, {
812
+ label: "round(big numerator)",
813
+ set: ['409652136432929109317'.repeat(100), 10],
814
+ fn: "round",
815
+ param: null,
816
+ expect: '409652136432929109317'.repeat(99) + '40965213643292910932'
817
+ }, {
818
+ label: "17402216385200408/5539306332998545",
819
+ set: [17402216385200408, 5539306332998545],
820
+ fn: "add",
821
+ param: 0,
822
+ expect: "3.141587653589870"
823
+ }, {
824
+ label: "17402216385200401/553930633299855",
825
+ set: [17402216385200401, 553930633299855],
826
+ fn: "add",
827
+ param: 0,
828
+ expect: "31.415876535898660"
829
+ }, {
830
+ label: "1283191/418183",
831
+ set: [1283191, 418183],
832
+ fn: "add",
833
+ param: 0,
834
+ expect: "3.068491545567371"
835
+ }, {
836
+ label: "1.001",
837
+ set: "1.001",
838
+ fn: "add",
839
+ param: 0,
840
+ expect: "1.001"
841
+ }, {
842
+ label: "99+1",
843
+ set: [99, 1],
844
+ fn: "add",
845
+ param: 1,
846
+ expect: "100"
847
+ }, {
848
+ label: "gcd(5/8, 3/7)",
849
+ set: [5, 8],
850
+ fn: "gcd",
851
+ param: [3, 7],
852
+ expect: "0.017(857142)" // == 1/56
853
+ }, {
854
+ label: "gcd(52, 39)",
855
+ set: 52,
856
+ fn: "gcd",
857
+ param: 39,
858
+ expect: "13"
859
+ }, {
860
+ label: "gcd(51357, 3819)",
861
+ set: 51357,
862
+ fn: "gcd",
863
+ param: 3819,
864
+ expect: "57"
865
+ }, {
866
+ label: "gcd(841, 299)",
867
+ set: 841,
868
+ fn: "gcd",
869
+ param: 299,
870
+ expect: "1"
871
+ }, {
872
+ label: "gcd(2/3, 7/5)",
873
+ set: [2, 3],
874
+ fn: "gcd",
875
+ param: [7, 5],
876
+ expect: "0.0(6)" // == 1/15
877
+ }, {
878
+ label: "lcm(-3, 3)",
879
+ set: -3,
880
+ fn: "lcm",
881
+ param: 3,
882
+ expect: "3"
883
+ }, {
884
+ label: "lcm(3,-3)",
885
+ set: 3,
886
+ fn: "lcm",
887
+ param: -3,
888
+ expect: "3"
889
+ }, {
890
+ label: "lcm(0,3)",
891
+ set: 0,
892
+ fn: "lcm",
893
+ param: 3,
894
+ expect: "0"
895
+ }, {
896
+ label: "lcm(3, 0)",
897
+ set: 3,
898
+ fn: "lcm",
899
+ param: 0,
900
+ expect: "0"
901
+ }, {
902
+ label: "lcm(0, 0)",
903
+ set: 0,
904
+ fn: "lcm",
905
+ param: 0,
906
+ expect: "0"
907
+ }, {
908
+ label: "lcm(200, 333)",
909
+ set: 200,
910
+ fn: "lcm",
911
+ param: 333, expect: "66600"
912
+ },
913
+ {
914
+ label: "1 + -1",
915
+ set: 1,
916
+ fn: "add",
917
+ param: -1,
918
+ expect: "0"
919
+ }, {
920
+ label: "3/10+3/14",
921
+ set: "3/10",
922
+ fn: "add",
923
+ param: "3/14",
924
+ expect: "0.5(142857)"
925
+ }, {
926
+ label: "3/10-3/14",
927
+ set: "3/10",
928
+ fn: "sub",
929
+ param: "3/14",
930
+ expect: "0.0(857142)"
931
+ }, {
932
+ label: "3/10*3/14",
933
+ set: "3/10",
934
+ fn: "mul",
935
+ param: "3/14",
936
+ expect: "0.06(428571)"
937
+ }, {
938
+ label: "3/10 / 3/14",
939
+ set: "3/10",
940
+ fn: "div",
941
+ param: "3/14",
942
+ expect: "1.4"
943
+ }, {
944
+ label: "1-2",
945
+ set: "1",
946
+ fn: "sub",
947
+ param: "2",
948
+ expect: "-1"
949
+ }, {
950
+ label: "1--1",
951
+ set: "1",
952
+ fn: "sub",
953
+ param: "-1",
954
+ expect: "2"
955
+ }, {
956
+ label: "0/1*1/3",
957
+ set: "0/1",
958
+ fn: "mul",
959
+ param: "1/3",
960
+ expect: "0"
961
+ }, {
962
+ label: "3/10 * 8/12",
963
+ set: "3/10",
964
+ fn: "mul",
965
+ param: "8/12",
966
+ expect: "0.2"
967
+ }, {
968
+ label: ".5+5",
969
+ set: ".5",
970
+ fn: "add",
971
+ param: 5, expect: "5.5"
972
+ },
973
+ {
974
+ label: "10/12-5/60",
975
+ set: "10/12",
976
+ fn: "sub",
977
+ param: "5/60",
978
+ expect: "0.75"
979
+ }, {
980
+ label: "10/15 / 3/4",
981
+ set: "10/15",
982
+ fn: "div",
983
+ param: "3/4",
984
+ expect: "0.(8)"
985
+ }, {
986
+ label: "1/4 + 3/8",
987
+ set: "1/4",
988
+ fn: "add",
989
+ param: "3/8",
990
+ expect: "0.625"
991
+ }, {
992
+ label: "2-1/3",
993
+ set: "2",
994
+ fn: "sub",
995
+ param: "1/3",
996
+ expect: "1.(6)"
997
+ }, {
998
+ label: "5*6",
999
+ set: "5",
1000
+ fn: "mul",
1001
+ param: 6,
1002
+ expect: "30"
1003
+ }, {
1004
+ label: "1/2-1/5",
1005
+ set: "1/2",
1006
+ fn: "sub",
1007
+ param: "1/5",
1008
+ expect: "0.3"
1009
+ }, {
1010
+ label: "1/2-5",
1011
+ set: "1/2",
1012
+ fn: "add",
1013
+ param: -5,
1014
+ expect: "-4.5"
1015
+ }, {
1016
+ label: "1*-1",
1017
+ set: "1",
1018
+ fn: "mul",
1019
+ param: -1,
1020
+ expect: "-1"
1021
+ }, {
1022
+ label: "5/10",
1023
+ set: 5.0,
1024
+ fn: "div",
1025
+ param: 10,
1026
+ expect: "0.5"
1027
+ }, {
1028
+ label: "1/-1",
1029
+ set: "1",
1030
+ fn: "div",
1031
+ param: -1,
1032
+ expect: "-1"
1033
+ }, {
1034
+ label: "4/5 + 13/2",
1035
+ set: "4/5",
1036
+ fn: "add",
1037
+ param: "13/2",
1038
+ expect: "7.3"
1039
+ }, {
1040
+ label: "4/5 + 61/2",
1041
+ set: "4/5",
1042
+ fn: "add",
1043
+ param: "61/2",
1044
+ expect: "31.3"
1045
+ }, {
1046
+ label: "0.8 + 6.5",
1047
+ set: "0.8",
1048
+ fn: "add",
1049
+ param: "6.5",
1050
+ expect: "7.3"
1051
+ }, {
1052
+ label: "2/7 inverse",
1053
+ set: "2/7",
1054
+ fn: "inverse",
1055
+ param: null,
1056
+ expect: "3.5"
1057
+ }, {
1058
+ label: "neg 1/3",
1059
+ set: "1/3",
1060
+ fn: "neg",
1061
+ param: null,
1062
+ expect: "-0.(3)"
1063
+ }, {
1064
+ label: "1/2+1/3",
1065
+ set: "1/2",
1066
+ fn: "add",
1067
+ param: "1/3",
1068
+ expect: "0.8(3)"
1069
+ }, {
1070
+ label: "1/2+3",
1071
+ set: ".5",
1072
+ fn: "add",
1073
+ param: 3,
1074
+ expect: "3.5"
1075
+ }, {
1076
+ label: "1/2+3.14",
1077
+ set: "1/2",
1078
+ fn: "add",
1079
+ param: "3.14",
1080
+ expect: "3.64"
1081
+ }, {
1082
+ label: "3.5 < 4.1",
1083
+ set: 3.5,
1084
+ fn: "compare",
1085
+ param: 4.1,
1086
+ expect: "-1"
1087
+ }, {
1088
+ label: "3.5 > 4.1",
1089
+ set: 4.1,
1090
+ fn: "compare",
1091
+ param: 3.1,
1092
+ expect: "1"
1093
+ }, {
1094
+ label: "-3.5 > -4.1",
1095
+ set: -3.5,
1096
+ fn: "compare",
1097
+ param: -4.1,
1098
+ expect: "1"
1099
+ }, {
1100
+ label: "-3.5 > -4.1",
1101
+ set: -4.1,
1102
+ fn: "compare",
1103
+ param: -3.5,
1104
+ expect: "-1"
1105
+ }, {
1106
+ label: "4.3 == 4.3",
1107
+ set: 4.3,
1108
+ fn: "compare",
1109
+ param: 4.3,
1110
+ expect: "0"
1111
+ }, {
1112
+ label: "-4.3 == -4.3",
1113
+ set: -4.3,
1114
+ fn: "compare",
1115
+ param: -4.3,
1116
+ expect: "0"
1117
+ }, {
1118
+ label: "-4.3 < 4.3",
1119
+ set: -4.3,
1120
+ fn: "compare",
1121
+ param: 4.3,
1122
+ expect: "-1"
1123
+ }, {
1124
+ label: "4.3 == -4.3",
1125
+ set: 4.3,
1126
+ fn: "compare",
1127
+ param: -4.3,
1128
+ expect: "1"
1129
+ }, {
1130
+ label: "2^0.5",
1131
+ set: 2,
1132
+ fn: "pow",
1133
+ param: 0.5,
1134
+ expect: "null"
1135
+ }, {
1136
+ label: "(-8/27)^(1/3)",
1137
+ set: [-8, 27],
1138
+ fn: "pow",
1139
+ param: [1, 3],
1140
+ expect: "null"
1141
+ }, {
1142
+ label: "(-8/27)^(2/3)",
1143
+ set: [-8, 27],
1144
+ fn: "pow",
1145
+ param: [2, 3],
1146
+ expect: "null"
1147
+ }, {
1148
+ label: "(-32/243)^(5/3)",
1149
+ set: [-32, 243],
1150
+ fn: "pow",
1151
+ param: [5, 3],
1152
+ expect: "null"
1153
+ }, {
1154
+ label: "sqrt(0)",
1155
+ set: 0,
1156
+ fn: "pow",
1157
+ param: 0.5,
1158
+ expect: "0"
1159
+ }, {
1160
+ label: "27^(2/3)",
1161
+ set: 27,
1162
+ fn: "pow",
1163
+ param: "2/3",
1164
+ expect: "9"
1165
+ }, {
1166
+ label: "(243/1024)^(2/5)",
1167
+ set: "243/1024",
1168
+ fn: "pow",
1169
+ param: "2/5",
1170
+ expect: "0.5625"
1171
+ }, {
1172
+ label: "-0.5^-3",
1173
+ set: -0.5,
1174
+ fn: "pow",
1175
+ param: -3,
1176
+ expect: "-8"
1177
+ }, {
1178
+ label: "",
1179
+ set: -3,
1180
+ fn: "pow",
1181
+ param: -3,
1182
+ expect: "-0.(037)"
1183
+ }, {
1184
+ label: "-3",
1185
+ set: -3,
1186
+ fn: "pow",
1187
+ param: 2,
1188
+ expect: "9"
1189
+ }, {
1190
+ label: "-3",
1191
+ set: -3,
1192
+ fn: "pow",
1193
+ param: 3,
1194
+ expect: "-27"
1195
+ }, {
1196
+ label: "0^0",
1197
+ set: 0,
1198
+ fn: "pow",
1199
+ param: 0,
1200
+ expect: "1"
1201
+ }, {
1202
+ label: "2/3^7",
1203
+ set: [2, 3],
1204
+ fn: "pow",
1205
+ param: 7,
1206
+ expect: "0.(058527663465935070873342478280749885688157293095564700502972107910379515317786922725194330132601737540009144947416552354823959762231367169638774577046181984453589391860996799268404206675811614083219021490626428898033836305441243712848651120256)"
1207
+ }, {
1208
+ label: "-0.6^4",
1209
+ set: -0.6,
1210
+ fn: "pow",
1211
+ param: 4,
1212
+ expect: "0.1296"
1213
+ }, {
1214
+ label: "8128371:12394 - 8128371/12394",
1215
+ set: "8128371:12394",
1216
+ fn: "sub",
1217
+ param: "8128371/12394",
1218
+ expect: "0"
1219
+ }, {
1220
+ label: "3/4 + 1/4",
1221
+ set: "3/4",
1222
+ fn: "add",
1223
+ param: "1/4",
1224
+ expect: "1"
1225
+ }, {
1226
+ label: "1/10 + 2/10",
1227
+ set: "1/10",
1228
+ fn: "add",
1229
+ param: "2/10",
1230
+ expect: "0.3"
1231
+ }, {
1232
+ label: "5/10 + 2/10",
1233
+ set: "5/10",
1234
+ fn: "add",
1235
+ param: "2/10",
1236
+ expect: "0.7"
1237
+ }, {
1238
+ label: "18/10 + 2/10",
1239
+ set: "18/10",
1240
+ fn: "add",
1241
+ param: "2/10",
1242
+ expect: "2"
1243
+ }, {
1244
+ label: "1/3 + 1/6",
1245
+ set: "1/3",
1246
+ fn: "add",
1247
+ param: "1/6",
1248
+ expect: "0.5"
1249
+ }, {
1250
+ label: "1/3 + 2/6",
1251
+ set: "1/3",
1252
+ fn: "add",
1253
+ param: "2/6",
1254
+ expect: "0.(6)"
1255
+ }, {
1256
+ label: "3/4 / 1/4",
1257
+ set: "3/4",
1258
+ fn: "div",
1259
+ param: "1/4",
1260
+ expect: "3"
1261
+ }, {
1262
+ label: "1/10 / 2/10",
1263
+ set: "1/10",
1264
+ fn: "div",
1265
+ param: "2/10",
1266
+ expect: "0.5"
1267
+ }, {
1268
+ label: "5/10 / 2/10",
1269
+ set: "5/10",
1270
+ fn: "div",
1271
+ param: "2/10",
1272
+ expect: "2.5"
1273
+ }, {
1274
+ label: "18/10 / 2/10",
1275
+ set: "18/10",
1276
+ fn: "div",
1277
+ param: "2/10",
1278
+ expect: "9"
1279
+ }, {
1280
+ label: "1/3 / 1/6",
1281
+ set: "1/3",
1282
+ fn: "div",
1283
+ param: "1/6",
1284
+ expect: "2"
1285
+ }, {
1286
+ label: "1/3 / 2/6",
1287
+ set: "1/3",
1288
+ fn: "div",
1289
+ param: "2/6",
1290
+ expect: "1"
1291
+ }, {
1292
+ label: "3/4 * 1/4",
1293
+ set: "3/4",
1294
+ fn: "mul",
1295
+ param: "1/4",
1296
+ expect: "0.1875"
1297
+ }, {
1298
+ label: "1/10 * 2/10",
1299
+ set: "1/10",
1300
+ fn: "mul",
1301
+ param: "2/10",
1302
+ expect: "0.02"
1303
+ }, {
1304
+ label: "5/10 * 2/10",
1305
+ set: "5/10",
1306
+ fn: "mul",
1307
+ param: "2/10",
1308
+ expect: "0.1"
1309
+ }, {
1310
+ label: "18/10 * 2/10",
1311
+ set: "18/10",
1312
+ fn: "mul",
1313
+ param: "2/10",
1314
+ expect: "0.36"
1315
+ }, {
1316
+ label: "1/3 * 1/6",
1317
+ set: "1/3",
1318
+ fn: "mul",
1319
+ param: "1/6",
1320
+ expect: "0.0(5)"
1321
+ }, {
1322
+ label: "1/3 * 2/6",
1323
+ set: "1/3",
1324
+ fn: "mul",
1325
+ param: "2/6",
1326
+ expect: "0.(1)"
1327
+ }, {
1328
+ label: "5/4 - 1/4",
1329
+ set: "5/4",
1330
+ fn: "sub",
1331
+ param: "1/4",
1332
+ expect: "1"
1333
+ }, {
1334
+ label: "5/10 - 2/10",
1335
+ set: "5/10",
1336
+ fn: "sub",
1337
+ param: "2/10",
1338
+ expect: "0.3"
1339
+ }, {
1340
+ label: "9/10 - 2/10",
1341
+ set: "9/10",
1342
+ fn: "sub",
1343
+ param: "2/10",
1344
+ expect: "0.7"
1345
+ }, {
1346
+ label: "22/10 - 2/10",
1347
+ set: "22/10",
1348
+ fn: "sub",
1349
+ param: "2/10",
1350
+ expect: "2"
1351
+ }, {
1352
+ label: "2/3 - 1/6",
1353
+ set: "2/3",
1354
+ fn: "sub",
1355
+ param: "1/6",
1356
+ expect: "0.5"
1357
+ }, {
1358
+ label: "3/3 - 2/6",
1359
+ set: "3/3",
1360
+ fn: "sub",
1361
+ param: "2/6",
1362
+ expect: "0.(6)"
1363
+ }, {
1364
+ label: "0.006999999999999999",
1365
+ set: 0.006999999999999999,
1366
+ fn: "add",
1367
+ param: 0,
1368
+ expect: "0.007"
1369
+ }, {
1370
+ label: "1/7 - 1",
1371
+ set: 1 / 7,
1372
+ fn: "add",
1373
+ param: -1,
1374
+ expect: "-0.(857142)"
1375
+ }, {
1376
+ label: "0.0065 + 0.0005",
1377
+ set: 0.0065,
1378
+ fn: "add",
1379
+ param: 0.0005,
1380
+ expect: "0.007"
1381
+ }, {
1382
+ label: "6.5/.5",
1383
+ set: 6.5,
1384
+ fn: "div",
1385
+ param: .5,
1386
+ expect: "13"
1387
+ }, {
1388
+ label: "0.999999999999999999999999999",
1389
+ set: 0.999999999999999999999999999,
1390
+ fn: "sub",
1391
+ param: 1,
1392
+ expect: "0"
1393
+ }, {
1394
+ label: "0.5833333333333334",
1395
+ set: 0.5833333333333334,
1396
+ fn: "add",
1397
+ param: 0,
1398
+ expect: "0.58(3)"
1399
+ }, {
1400
+ label: "1.75/3",
1401
+ set: 1.75 / 3,
1402
+ fn: "add",
1403
+ param: 0,
1404
+ expect: "0.58(3)"
1405
+ }, {
1406
+ label: "3.3333333333333",
1407
+ set: 3.3333333333333,
1408
+ fn: "add",
1409
+ param: 0,
1410
+ expect: "3.(3)"
1411
+ }, {
1412
+ label: "4.285714285714285714285714",
1413
+ set: 4.285714285714285714285714,
1414
+ fn: "add",
1415
+ param: 0,
1416
+ expect: "4.(285714)"
1417
+ }, {
1418
+ label: "-4",
1419
+ set: -4,
1420
+ fn: "neg",
1421
+ param: 0,
1422
+ expect: "4"
1423
+ }, {
1424
+ label: "4",
1425
+ set: 4,
1426
+ fn: "neg",
1427
+ param: 0,
1428
+ expect: "-4"
1429
+ }, {
1430
+ label: "0",
1431
+ set: 0,
1432
+ fn: "neg",
1433
+ param: 0,
1434
+ expect: "0"
1435
+ }, {
1436
+ label: "6869570742453802/5329686054127205",
1437
+ set: "6869570742453802/5329686054127205",
1438
+ fn: "neg",
1439
+ param: 0,
1440
+ expect: "-1.288925965373540"
1441
+ }, {
1442
+ label: "686970702/53212205",
1443
+ set: "686970702/53212205",
1444
+ fn: "neg",
1445
+ param: 0,
1446
+ expect: "-12.910021338149772"
1447
+ }, {
1448
+ label: "1/3000000000000000",
1449
+ set: "1/3000000000000000",
1450
+ fn: "add",
1451
+ param: 0,
1452
+ expect: "0.000000000000000(3)"
1453
+ }, {
1454
+ label: "toString(15) .0000000000000003",
1455
+ set: ".0000000000000003",
1456
+ fn: "toString",
1457
+ param: 15,
1458
+ expect: "0.000000000000000"
1459
+ }, {
1460
+ label: "toString(16) .0000000000000003",
1461
+ set: ".0000000000000003",
1462
+ fn: "toString",
1463
+ param: 16,
1464
+ expect: "0.0000000000000003"
1465
+ }, {
1466
+ label: "12 / 4.3",
1467
+ set: 12,
1468
+ set2: 4.3,
1469
+ fn: "toString",
1470
+ param: null,
1471
+ expectError: NonIntegerParameter()
1472
+ }, {
1473
+ label: "12.5 / 4",
1474
+ set: 12.5,
1475
+ set2: 4,
1476
+ fn: "toString",
1477
+ param: null,
1478
+ expectError: NonIntegerParameter()
1479
+ }, {
1480
+ label: "0.9 round to multiple of 1/8",
1481
+ set: .9,
1482
+ fn: "roundTo",
1483
+ param: "1/8",
1484
+ expect: "0.875"
1485
+ }, {
1486
+ label: "1/3 round to multiple of 1/16",
1487
+ set: 1 / 3,
1488
+ fn: "roundTo",
1489
+ param: "1/16",
1490
+ expect: "0.3125"
1491
+ }, {
1492
+ label: "1/3 round to multiple of 1/16",
1493
+ set: -1 / 3,
1494
+ fn: "roundTo",
1495
+ param: "1/16",
1496
+ expect: "-0.3125"
1497
+ }, {
1498
+ label: "1/2 round to multiple of 1/4",
1499
+ set: 1 / 2,
1500
+ fn: "roundTo",
1501
+ param: "1/4",
1502
+ expect: "0.5"
1503
+ }, {
1504
+ label: "1/4 round to multiple of 1/2",
1505
+ set: 1 / 4,
1506
+ fn: "roundTo",
1507
+ param: "1/2",
1508
+ expect: "0.5"
1509
+ }, {
1510
+ label: "10/3 round to multiple of 1/2",
1511
+ set: "10/3",
1512
+ fn: "roundTo",
1513
+ param: "1/2",
1514
+ expect: "3.5"
1515
+ }, {
1516
+ label: "-10/3 round to multiple of 1/2",
1517
+ set: "-10/3",
1518
+ fn: "roundTo",
1519
+ param: "1/2",
1520
+ expect: "-3.5"
1521
+ }, {
1522
+ label: "log_2(8)",
1523
+ set: "8",
1524
+ fn: "log",
1525
+ param: "2",
1526
+ expect: "3" // because 2^3 = 8
1527
+ }, {
1528
+ label: "log_2(3)",
1529
+ set: "3",
1530
+ fn: "log",
1531
+ param: "2",
1532
+ expect: 'null' // because 2^(p/q) != 3
1533
+ }, {
1534
+ label: "log_10(1000)",
1535
+ set: "1000",
1536
+ fn: "log",
1537
+ param: "10",
1538
+ expect: "3" // because 10^3 = 1000
1539
+ }, {
1540
+ label: "log_27(81)",
1541
+ set: "81",
1542
+ fn: "log",
1543
+ param: "27",
1544
+ expect: "1.(3)" // because 27^(4/3) = 81
1545
+ }, {
1546
+ label: "log_27(9)",
1547
+ set: "9",
1548
+ fn: "log",
1549
+ param: "27",
1550
+ expect: "0.(6)" // because 27^(2/3) = 9
1551
+ }, {
1552
+ label: "log_9/4(27/8)",
1553
+ set: "27/8",
1554
+ fn: "log",
1555
+ param: "9/4",
1556
+ expect: "1.5" // because (9/4)^(3/2) = 27/8
1557
+ }];
1558
+
1559
+ describe('Fraction', function () {
1560
+ for (var i = 0; i < tests.length; i++) {
1561
+
1562
+ (function (i) {
1563
+ var action;
1564
+
1565
+ if (tests[i].fn) {
1566
+ action = function () {
1567
+ var x = Fraction(tests[i].set, tests[i].set2)[tests[i].fn](tests[i].param);
1568
+ if (x === null) return "null";
1569
+ return x.toString();
1570
+ };
1571
+ } else {
1572
+ action = function () {
1573
+ var x = new Fraction(tests[i].set, tests[i].set2);
1574
+ if (x === null) return "null";
1575
+ return x.toString();
1576
+ };
1577
+ }
1578
+
1579
+ it(String(tests[i].label || tests[i].set), function () {
1580
+ if (tests[i].expectError) {
1581
+ assert.throws(action, tests[i].expectError);
1582
+ } else {
1583
+ assert.equal(action(), tests[i].expect);
1584
+ }
1585
+ });
1586
+
1587
+ })(i);
1588
+ }
1589
+ });
1590
+
1591
+ describe('JSON', function () {
1592
+
1593
+ it("Should be possible to stringify the object", function () {
1594
+
1595
+ if (typeof Fraction(1).n !== 'number') {
1596
+ return;
1597
+ }
1598
+ assert.equal('{"s":1,"n":14623,"d":330}', JSON.stringify(new Fraction("44.3(12)")));
1599
+ assert.equal('{"s":-1,"n":2,"d":1}', JSON.stringify(new Fraction(-1 / 2).inverse()));
1600
+ });
1601
+ });
1602
+
1603
+ describe('Arguments', function () {
1604
+
1605
+ it("Should be possible to use different kind of params", function () {
1606
+
1607
+ // String
1608
+ var fraction = new Fraction("0.1");
1609
+ assert.equal("1/10", fraction.n + "/" + fraction.d);
1610
+
1611
+ var fraction = new Fraction("6234/6460");
1612
+ assert.equal("3117/3230", fraction.n + "/" + fraction.d);
1613
+
1614
+ // Two params
1615
+ var fraction = new Fraction(1, 2);
1616
+ assert.equal("1/2", fraction.n + "/" + fraction.d);
1617
+
1618
+ // Object
1619
+ var fraction = new Fraction({ n: 1, d: 3 });
1620
+ assert.equal("1/3", fraction.n + "/" + fraction.d);
1621
+
1622
+ // Array
1623
+ var fraction = new Fraction([1, 4]);
1624
+ assert.equal("1/4", fraction.n + "/" + fraction.d);
1625
+ });
1626
+ });
1627
+
1628
+ describe('fractions', function () {
1629
+
1630
+ it("Should pass 0.08 = 2/25", function () {
1631
+
1632
+ var fraction = new Fraction("0.08");
1633
+ assert.equal("2/25", fraction.n + "/" + fraction.d);
1634
+ });
1635
+
1636
+ it("Should pass 0.200 = 1/5", function () {
1637
+
1638
+ var fraction = new Fraction("0.200");
1639
+ assert.equal("1/5", fraction.n + "/" + fraction.d);
1640
+ });
1641
+
1642
+ it("Should pass 0.125 = 1/8", function () {
1643
+
1644
+ var fraction = new Fraction("0.125");
1645
+ assert.equal("1/8", fraction.n + "/" + fraction.d);
1646
+ });
1647
+
1648
+ it("Should pass 8.36 = 209/25", function () {
1649
+
1650
+ var fraction = new Fraction(8.36);
1651
+ assert.equal("209/25", fraction.n + "/" + fraction.d);
1652
+ });
1653
+
1654
+ });
1655
+
1656
+ describe('constructors', function () {
1657
+
1658
+ it("Should pass 0.08 = 2/25", function () {
1659
+
1660
+ var tmp = new Fraction({ d: 4, n: 2, s: -1 });
1661
+ assert.equal("-1/2", tmp.s * tmp.n + "/" + tmp.d);
1662
+
1663
+ var tmp = new Fraction(-88.3);
1664
+ assert.equal("-883/10", tmp.s * tmp.n + "/" + tmp.d);
1665
+
1666
+ var tmp = new Fraction(-88.3).clone();
1667
+ assert.equal("-883/10", tmp.s * tmp.n + "/" + tmp.d);
1668
+
1669
+ var tmp = new Fraction("123.'3'");
1670
+ assert.equal("370/3", tmp.s * tmp.n + "/" + tmp.d);
1671
+
1672
+ var tmp = new Fraction("123.'3'").clone();
1673
+ assert.equal("370/3", tmp.s * tmp.n + "/" + tmp.d);
1674
+
1675
+ var tmp = new Fraction([-1023461776, 334639305]);
1676
+ tmp = tmp.add([4, 25]);
1677
+ assert.equal("-4849597436/1673196525", tmp.s * tmp.n + "/" + tmp.d);
1678
+ });
1679
+ });
1680
+
1681
+ describe('Latex Output', function () {
1682
+
1683
+ it("Should pass 123.'3' = \\frac{370}{3}", function () {
1684
+
1685
+ var tmp = new Fraction("123.'3'");
1686
+ assert.equal("\\frac{370}{3}", tmp.toLatex());
1687
+ });
1688
+
1689
+ it("Should pass 1.'3' = \\frac{4}{3}", function () {
1690
+
1691
+ var tmp = new Fraction("1.'3'");
1692
+ assert.equal("\\frac{4}{3}", tmp.toLatex());
1693
+ });
1694
+
1695
+ it("Should pass -1.0000000000 = -1", function () {
1696
+
1697
+ var tmp = new Fraction("-1.0000000000");
1698
+ assert.equal('-1', tmp.toLatex());
1699
+ });
1700
+
1701
+ it("Should pass -0.0000000000 = 0", function () {
1702
+
1703
+ var tmp = new Fraction("-0.0000000000");
1704
+ assert.equal('0', tmp.toLatex());
1705
+ });
1706
+ });
1707
+
1708
+ describe('Fraction Output', function () {
1709
+
1710
+ it("Should pass 123.'3' = 123 1/3", function () {
1711
+
1712
+ var tmp = new Fraction("123.'3'");
1713
+ assert.equal('370/3', tmp.toFraction());
1714
+ });
1715
+
1716
+ it("Should pass 1.'3' = 1 1/3", function () {
1717
+
1718
+ var tmp = new Fraction("1.'3'");
1719
+ assert.equal('4/3', tmp.toFraction());
1720
+ });
1721
+
1722
+ it("Should pass -1.0000000000 = -1", function () {
1723
+
1724
+ var tmp = new Fraction("-1.0000000000");
1725
+ assert.equal('-1', tmp.toFraction());
1726
+ });
1727
+
1728
+ it("Should pass -0.0000000000 = 0", function () {
1729
+
1730
+ var tmp = new Fraction("-0.0000000000");
1731
+ assert.equal('0', tmp.toFraction());
1732
+ });
1733
+
1734
+ it("Should pass 1/-99/293 = -1/29007", function () {
1735
+
1736
+ var tmp = new Fraction(-99).inverse().div(293);
1737
+ assert.equal('-1/29007', tmp.toFraction());
1738
+ });
1739
+
1740
+ it('Should work with large calculations', function () {
1741
+ var x = Fraction(1123875);
1742
+ var y = Fraction(1238750184);
1743
+ var z = Fraction(1657134);
1744
+ var r = Fraction(77344464613500, 92063);
1745
+ assert.equal(x.mul(y).div(z).toFraction(), r.toFraction());
1746
+ });
1747
+ });
1748
+
1749
+ describe('Fraction toContinued', function () {
1750
+
1751
+ it("Should pass 415/93", function () {
1752
+
1753
+ var tmp = new Fraction(415, 93);
1754
+ assert.equal('4,2,6,7', tmp.toContinued().toString());
1755
+ });
1756
+
1757
+ it("Should pass 0/2", function () {
1758
+
1759
+ var tmp = new Fraction(0, 2);
1760
+ assert.equal('0', tmp.toContinued().toString());
1761
+ });
1762
+
1763
+ it("Should pass 1/7", function () {
1764
+
1765
+ var tmp = new Fraction(1, 7);
1766
+ assert.equal('0,7', tmp.toContinued().toString());
1767
+ });
1768
+
1769
+ it("Should pass 23/88", function () {
1770
+
1771
+ var tmp = new Fraction('23/88');
1772
+ assert.equal('0,3,1,4,1,3', tmp.toContinued().toString());
1773
+ });
1774
+
1775
+ it("Should pass 1/99", function () {
1776
+
1777
+ var tmp = new Fraction('1/99');
1778
+ assert.equal('0,99', tmp.toContinued().toString());
1779
+ });
1780
+
1781
+ it("Should pass 1768/99", function () {
1782
+
1783
+ var tmp = new Fraction('1768/99');
1784
+ assert.equal('17,1,6,14', tmp.toContinued().toString());
1785
+ });
1786
+
1787
+ it("Should pass 1768/99", function () {
1788
+
1789
+ var tmp = new Fraction('7/8');
1790
+ assert.equal('0,1,7', tmp.toContinued().toString());
1791
+ });
1792
+
1793
+ });
1794
+
1795
+
1796
+ describe('Fraction simplify', function () {
1797
+
1798
+ it("Should pass 415/93", function () {
1799
+
1800
+ var tmp = new Fraction(415, 93);
1801
+ assert.equal('9/2', tmp.simplify(0.1).toFraction());
1802
+ assert.equal('58/13', tmp.simplify(0.01).toFraction());
1803
+ assert.equal('415/93', tmp.simplify(0.0001).toFraction());
1804
+ });
1805
+
1806
+ });
web/node_modules/function-bind/.eslintrc ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "root": true,
3
+
4
+ "extends": "@ljharb",
5
+
6
+ "rules": {
7
+ "func-name-matching": 0,
8
+ "indent": [2, 4],
9
+ "no-new-func": [1],
10
+ },
11
+
12
+ "overrides": [
13
+ {
14
+ "files": "test/**",
15
+ "rules": {
16
+ "max-lines-per-function": 0,
17
+ "strict": [0]
18
+ },
19
+ },
20
+ ],
21
+ }
web/node_modules/function-bind/.github/FUNDING.yml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # These are supported funding model platforms
2
+
3
+ github: [ljharb]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: npm/function-bind
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
web/node_modules/function-bind/.github/SECURITY.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # Security
2
+
3
+ Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report.
web/node_modules/function-bind/.nycrc ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "all": true,
3
+ "check-coverage": false,
4
+ "reporter": ["text-summary", "text", "html", "json"],
5
+ "lines": 86,
6
+ "statements": 85.93,
7
+ "functions": 82.43,
8
+ "branches": 76.06,
9
+ "exclude": [
10
+ "coverage",
11
+ "test"
12
+ ]
13
+ }
web/node_modules/function-bind/CHANGELOG.md ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [v1.1.2](https://github.com/ljharb/function-bind/compare/v1.1.1...v1.1.2) - 2023-10-12
9
+
10
+ ### Merged
11
+
12
+ - Point to the correct file [`#16`](https://github.com/ljharb/function-bind/pull/16)
13
+
14
+ ### Commits
15
+
16
+ - [Tests] migrate tests to Github Actions [`4f8b57c`](https://github.com/ljharb/function-bind/commit/4f8b57c02f2011fe9ae353d5e74e8745f0988af8)
17
+ - [Tests] remove `jscs` [`90eb2ed`](https://github.com/ljharb/function-bind/commit/90eb2edbeefd5b76cd6c3a482ea3454db169b31f)
18
+ - [meta] update `.gitignore` [`53fcdc3`](https://github.com/ljharb/function-bind/commit/53fcdc371cd66634d6e9b71c836a50f437e89fed)
19
+ - [Tests] up to `node` `v11.10`, `v10.15`, `v9.11`, `v8.15`, `v6.16`, `v4.9`; use `nvm install-latest-npm`; run audit script in tests [`1fe8f6e`](https://github.com/ljharb/function-bind/commit/1fe8f6e9aed0dfa8d8b3cdbd00c7f5ea0cd2b36e)
20
+ - [meta] add `auto-changelog` [`1921fcb`](https://github.com/ljharb/function-bind/commit/1921fcb5b416b63ffc4acad051b6aad5722f777d)
21
+ - [Robustness] remove runtime dependency on all builtins except `.apply` [`f743e61`](https://github.com/ljharb/function-bind/commit/f743e61aa6bb2360358c04d4884c9db853d118b7)
22
+ - Docs: enable badges; update wording [`503cb12`](https://github.com/ljharb/function-bind/commit/503cb12d998b5f91822776c73332c7adcd6355dd)
23
+ - [readme] update badges [`290c5db`](https://github.com/ljharb/function-bind/commit/290c5dbbbda7264efaeb886552a374b869a4bb48)
24
+ - [Tests] switch to nyc for coverage [`ea360ba`](https://github.com/ljharb/function-bind/commit/ea360ba907fc2601ed18d01a3827fa2d3533cdf8)
25
+ - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` [`cae5e9e`](https://github.com/ljharb/function-bind/commit/cae5e9e07a5578dc6df26c03ee22851ce05b943c)
26
+ - [meta] add `funding` field; create FUNDING.yml [`c9f4274`](https://github.com/ljharb/function-bind/commit/c9f4274aa80ea3aae9657a3938fdba41a3b04ca6)
27
+ - [Tests] fix eslint errors from #15 [`f69aaa2`](https://github.com/ljharb/function-bind/commit/f69aaa2beb2fdab4415bfb885760a699d0b9c964)
28
+ - [actions] fix permissions [`99a0cd9`](https://github.com/ljharb/function-bind/commit/99a0cd9f3b5bac223a0d572f081834cd73314be7)
29
+ - [meta] use `npmignore` to autogenerate an npmignore file [`f03b524`](https://github.com/ljharb/function-bind/commit/f03b524ca91f75a109a5d062f029122c86ecd1ae)
30
+ - [Dev Deps] update `@ljharb/eslint‑config`, `eslint`, `tape` [`7af9300`](https://github.com/ljharb/function-bind/commit/7af930023ae2ce7645489532821e4fbbcd7a2280)
31
+ - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `covert`, `tape` [`64a9127`](https://github.com/ljharb/function-bind/commit/64a9127ab0bd331b93d6572eaf6e9971967fc08c)
32
+ - [Tests] use `aud` instead of `npm audit` [`e75069c`](https://github.com/ljharb/function-bind/commit/e75069c50010a8fcce2a9ce2324934c35fdb4386)
33
+ - [Dev Deps] update `@ljharb/eslint-config`, `aud`, `tape` [`d03555c`](https://github.com/ljharb/function-bind/commit/d03555ca59dea3b71ce710045e4303b9e2619e28)
34
+ - [meta] add `safe-publish-latest` [`9c8f809`](https://github.com/ljharb/function-bind/commit/9c8f8092aed027d7e80c94f517aa892385b64f09)
35
+ - [Dev Deps] update `@ljharb/eslint-config`, `tape` [`baf6893`](https://github.com/ljharb/function-bind/commit/baf6893e27f5b59abe88bc1995e6f6ed1e527397)
36
+ - [meta] create SECURITY.md [`4db1779`](https://github.com/ljharb/function-bind/commit/4db17799f1f28ae294cb95e0081ca2b591c3911b)
37
+ - [Tests] add `npm run audit` [`c8b38ec`](https://github.com/ljharb/function-bind/commit/c8b38ec40ed3f85dabdee40ed4148f1748375bc2)
38
+ - Revert "Point to the correct file" [`05cdf0f`](https://github.com/ljharb/function-bind/commit/05cdf0fa205c6a3c5ba40bbedd1dfa9874f915c9)
39
+
40
+ ## [v1.1.1](https://github.com/ljharb/function-bind/compare/v1.1.0...v1.1.1) - 2017-08-28
41
+
42
+ ### Commits
43
+
44
+ - [Tests] up to `node` `v8`; newer npm breaks on older node; fix scripts [`817f7d2`](https://github.com/ljharb/function-bind/commit/817f7d28470fdbff8ef608d4d565dd4d1430bc5e)
45
+ - [Dev Deps] update `eslint`, `jscs`, `tape`, `@ljharb/eslint-config` [`854288b`](https://github.com/ljharb/function-bind/commit/854288b1b6f5c555f89aceb9eff1152510262084)
46
+ - [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`83e639f`](https://github.com/ljharb/function-bind/commit/83e639ff74e6cd6921285bccec22c1bcf72311bd)
47
+ - Only apps should have lockfiles [`5ed97f5`](https://github.com/ljharb/function-bind/commit/5ed97f51235c17774e0832e122abda0f3229c908)
48
+ - Use a SPDX-compliant “license” field. [`5feefea`](https://github.com/ljharb/function-bind/commit/5feefea0dc0193993e83e5df01ded424403a5381)
49
+
50
+ ## [v1.1.0](https://github.com/ljharb/function-bind/compare/v1.0.2...v1.1.0) - 2016-02-14
51
+
52
+ ### Commits
53
+
54
+ - Update `eslint`, `tape`; use my personal shared `eslint` config [`9c9062a`](https://github.com/ljharb/function-bind/commit/9c9062abbe9dd70b59ea2c3a3c3a81f29b457097)
55
+ - Add `npm run eslint` [`dd96c56`](https://github.com/ljharb/function-bind/commit/dd96c56720034a3c1ffee10b8a59a6f7c53e24ad)
56
+ - [New] return the native `bind` when available. [`82186e0`](https://github.com/ljharb/function-bind/commit/82186e03d73e580f95ff167e03f3582bed90ed72)
57
+ - [Dev Deps] update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`a3dd767`](https://github.com/ljharb/function-bind/commit/a3dd76720c795cb7f4586b0544efabf8aa107b8b)
58
+ - Update `eslint` [`3dae2f7`](https://github.com/ljharb/function-bind/commit/3dae2f7423de30a2d20313ddb1edc19660142fe9)
59
+ - Update `tape`, `covert`, `jscs` [`a181eee`](https://github.com/ljharb/function-bind/commit/a181eee0cfa24eb229c6e843a971f36e060a2f6a)
60
+ - [Tests] up to `node` `v5.6`, `v4.3` [`964929a`](https://github.com/ljharb/function-bind/commit/964929a6a4ddb36fb128de2bcc20af5e4f22e1ed)
61
+ - Test up to `io.js` `v2.1` [`2be7310`](https://github.com/ljharb/function-bind/commit/2be7310f2f74886a7124ca925be411117d41d5ea)
62
+ - Update `tape`, `jscs`, `eslint`, `@ljharb/eslint-config` [`45f3d68`](https://github.com/ljharb/function-bind/commit/45f3d6865c6ca93726abcef54febe009087af101)
63
+ - [Dev Deps] update `tape`, `jscs` [`6e1340d`](https://github.com/ljharb/function-bind/commit/6e1340d94642deaecad3e717825db641af4f8b1f)
64
+ - [Tests] up to `io.js` `v3.3`, `node` `v4.1` [`d9bad2b`](https://github.com/ljharb/function-bind/commit/d9bad2b778b1b3a6dd2876087b88b3acf319f8cc)
65
+ - Update `eslint` [`935590c`](https://github.com/ljharb/function-bind/commit/935590caa024ab356102e4858e8fc315b2ccc446)
66
+ - [Dev Deps] update `jscs`, `eslint`, `@ljharb/eslint-config` [`8c9a1ef`](https://github.com/ljharb/function-bind/commit/8c9a1efd848e5167887aa8501857a0940a480c57)
67
+ - Test on `io.js` `v2.2` [`9a3a38c`](https://github.com/ljharb/function-bind/commit/9a3a38c92013aed6e108666e7bd40969b84ac86e)
68
+ - Run `travis-ci` tests on `iojs` and `node` v0.12; speed up builds; allow 0.8 failures. [`69afc26`](https://github.com/ljharb/function-bind/commit/69afc2617405b147dd2a8d8ae73ca9e9283f18b4)
69
+ - [Dev Deps] Update `tape`, `eslint` [`36c1be0`](https://github.com/ljharb/function-bind/commit/36c1be0ab12b45fe5df6b0fdb01a5d5137fd0115)
70
+ - Update `tape`, `jscs` [`98d8303`](https://github.com/ljharb/function-bind/commit/98d8303cd5ca1c6b8f985469f86b0d44d7d45f6e)
71
+ - Update `jscs` [`9633a4e`](https://github.com/ljharb/function-bind/commit/9633a4e9fbf82051c240855166e468ba8ba0846f)
72
+ - Update `tape`, `jscs` [`c80ef0f`](https://github.com/ljharb/function-bind/commit/c80ef0f46efc9791e76fa50de4414092ac147831)
73
+ - Test up to `io.js` `v3.0` [`7e2c853`](https://github.com/ljharb/function-bind/commit/7e2c8537d52ab9cf5a655755561d8917684c0df4)
74
+ - Test on `io.js` `v2.4` [`5a199a2`](https://github.com/ljharb/function-bind/commit/5a199a27ba46795ba5eaf0845d07d4b8232895c9)
75
+ - Test on `io.js` `v2.3` [`a511b88`](https://github.com/ljharb/function-bind/commit/a511b8896de0bddf3b56862daa416c701f4d0453)
76
+ - Fixing a typo from 822b4e1938db02dc9584aa434fd3a45cb20caf43 [`732d6b6`](https://github.com/ljharb/function-bind/commit/732d6b63a9b33b45230e630dbcac7a10855d3266)
77
+ - Update `jscs` [`da52a48`](https://github.com/ljharb/function-bind/commit/da52a4886c06d6490f46ae30b15e4163ba08905d)
78
+ - Lock covert to v1.0.0. [`d6150fd`](https://github.com/ljharb/function-bind/commit/d6150fda1e6f486718ebdeff823333d9e48e7430)
79
+
80
+ ## [v1.0.2](https://github.com/ljharb/function-bind/compare/v1.0.1...v1.0.2) - 2014-10-04
81
+
82
+ ## [v1.0.1](https://github.com/ljharb/function-bind/compare/v1.0.0...v1.0.1) - 2014-10-03
83
+
84
+ ### Merged
85
+
86
+ - make CI build faster [`#3`](https://github.com/ljharb/function-bind/pull/3)
87
+
88
+ ### Commits
89
+
90
+ - Using my standard jscs.json [`d8ee94c`](https://github.com/ljharb/function-bind/commit/d8ee94c993eff0a84cf5744fe6a29627f5cffa1a)
91
+ - Adding `npm run lint` [`7571ab7`](https://github.com/ljharb/function-bind/commit/7571ab7dfdbd99b25a1dbb2d232622bd6f4f9c10)
92
+ - Using consistent indentation [`e91a1b1`](https://github.com/ljharb/function-bind/commit/e91a1b13a61e99ec1e530e299b55508f74218a95)
93
+ - Updating jscs [`7e17892`](https://github.com/ljharb/function-bind/commit/7e1789284bc629bc9c1547a61c9b227bbd8c7a65)
94
+ - Using consistent quotes [`c50b57f`](https://github.com/ljharb/function-bind/commit/c50b57fcd1c5ec38320979c837006069ebe02b77)
95
+ - Adding keywords [`cb94631`](https://github.com/ljharb/function-bind/commit/cb946314eed35f21186a25fb42fc118772f9ee00)
96
+ - Directly export a function expression instead of using a declaration, and relying on hoisting. [`5a33c5f`](https://github.com/ljharb/function-bind/commit/5a33c5f45642de180e0d207110bf7d1843ceb87c)
97
+ - Naming npm URL and badge in README; use SVG [`2aef8fc`](https://github.com/ljharb/function-bind/commit/2aef8fcb79d54e63a58ae557c4e60949e05d5e16)
98
+ - Naming deps URLs in README [`04228d7`](https://github.com/ljharb/function-bind/commit/04228d766670ee45ca24e98345c1f6a7621065b5)
99
+ - Naming travis-ci URLs in README; using SVG [`62c810c`](https://github.com/ljharb/function-bind/commit/62c810c2f54ced956cd4d4ab7b793055addfe36e)
100
+ - Make sure functions are invoked correctly (also passing coverage tests) [`2b289b4`](https://github.com/ljharb/function-bind/commit/2b289b4dfbf037ffcfa4dc95eb540f6165e9e43a)
101
+ - Removing the strict mode pragmas; they make tests fail. [`1aa701d`](https://github.com/ljharb/function-bind/commit/1aa701d199ddc3782476e8f7eef82679be97b845)
102
+ - Adding myself as a contributor [`85fd57b`](https://github.com/ljharb/function-bind/commit/85fd57b0860e5a7af42de9a287f3f265fc6d72fc)
103
+ - Adding strict mode pragmas [`915b08e`](https://github.com/ljharb/function-bind/commit/915b08e084c86a722eafe7245e21db74aa21ca4c)
104
+ - Adding devDeps URLs to README [`4ccc731`](https://github.com/ljharb/function-bind/commit/4ccc73112c1769859e4ca3076caf4086b3cba2cd)
105
+ - Fixing the description. [`a7a472c`](https://github.com/ljharb/function-bind/commit/a7a472cf649af515c635cf560fc478fbe48999c8)
106
+ - Using a function expression instead of a function declaration. [`b5d3e4e`](https://github.com/ljharb/function-bind/commit/b5d3e4ea6aaffc63888953eeb1fbc7ff45f1fa14)
107
+ - Updating tape [`f086be6`](https://github.com/ljharb/function-bind/commit/f086be6029fb56dde61a258c1340600fa174d1e0)
108
+ - Updating jscs [`5f9bdb3`](https://github.com/ljharb/function-bind/commit/5f9bdb375ab13ba48f30852aab94029520c54d71)
109
+ - Updating jscs [`9b409ba`](https://github.com/ljharb/function-bind/commit/9b409ba6118e23395a4e5d83ef39152aab9d3bfc)
110
+ - Run coverage as part of tests. [`8e1b6d4`](https://github.com/ljharb/function-bind/commit/8e1b6d459f047d1bd4fee814e01247c984c80bd0)
111
+ - Run linter as part of tests [`c1ca83f`](https://github.com/ljharb/function-bind/commit/c1ca83f832df94587d09e621beba682fabfaa987)
112
+ - Updating covert [`701e837`](https://github.com/ljharb/function-bind/commit/701e83774b57b4d3ef631e1948143f43a72f4bb9)
113
+
114
+ ## [v1.0.0](https://github.com/ljharb/function-bind/compare/v0.2.0...v1.0.0) - 2014-08-09
115
+
116
+ ### Commits
117
+
118
+ - Make sure old and unstable nodes don't fail Travis [`27adca3`](https://github.com/ljharb/function-bind/commit/27adca34a4ab6ad67b6dfde43942a1b103ce4d75)
119
+ - Fixing an issue when the bound function is called as a constructor in ES3. [`e20122d`](https://github.com/ljharb/function-bind/commit/e20122d267d92ce553859b280cbbea5d27c07731)
120
+ - Adding `npm run coverage` [`a2e29c4`](https://github.com/ljharb/function-bind/commit/a2e29c4ecaef9e2f6cd1603e868c139073375502)
121
+ - Updating tape [`b741168`](https://github.com/ljharb/function-bind/commit/b741168b12b235b1717ff696087645526b69213c)
122
+ - Upgrading tape [`63631a0`](https://github.com/ljharb/function-bind/commit/63631a04c7fbe97cc2fa61829cc27246d6986f74)
123
+ - Updating tape [`363cb46`](https://github.com/ljharb/function-bind/commit/363cb46dafb23cb3e347729a22f9448051d78464)
124
+
125
+ ## v0.2.0 - 2014-03-23
126
+
127
+ ### Commits
128
+
129
+ - Updating test coverage to match es5-shim. [`aa94d44`](https://github.com/ljharb/function-bind/commit/aa94d44b8f9d7f69f10e060db7709aa7a694e5d4)
130
+ - initial [`942ee07`](https://github.com/ljharb/function-bind/commit/942ee07e94e542d91798137bc4b80b926137e066)
131
+ - Setting the bound function's length properly. [`079f46a`](https://github.com/ljharb/function-bind/commit/079f46a2d3515b7c0b308c2c13fceb641f97ca25)
132
+ - Ensuring that some older browsers will throw when given a regex. [`36ac55b`](https://github.com/ljharb/function-bind/commit/36ac55b87f460d4330253c92870aa26fbfe8227f)
133
+ - Removing npm scripts that don't have dependencies [`9d2be60`](https://github.com/ljharb/function-bind/commit/9d2be600002cb8bc8606f8f3585ad3e05868c750)
134
+ - Updating tape [`297a4ac`](https://github.com/ljharb/function-bind/commit/297a4acc5464db381940aafb194d1c88f4e678f3)
135
+ - Skipping length tests for now. [`d9891ea`](https://github.com/ljharb/function-bind/commit/d9891ea4d2aaffa69f408339cdd61ff740f70565)
136
+ - don't take my tea [`dccd930`](https://github.com/ljharb/function-bind/commit/dccd930bfd60ea10cb178d28c97550c3bc8c1e07)
web/node_modules/function-bind/LICENSE ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2013 Raynos.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
20
+
web/node_modules/function-bind/README.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # function-bind <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
2
+
3
+ [![github actions][actions-image]][actions-url]
4
+ <!--[![coverage][codecov-image]][codecov-url]-->
5
+ [![dependency status][deps-svg]][deps-url]
6
+ [![dev dependency status][dev-deps-svg]][dev-deps-url]
7
+ [![License][license-image]][license-url]
8
+ [![Downloads][downloads-image]][downloads-url]
9
+
10
+ [![npm badge][npm-badge-png]][package-url]
11
+
12
+ Implementation of function.prototype.bind
13
+
14
+ Old versions of phantomjs, Internet Explorer < 9, and node < 0.6 don't support `Function.prototype.bind`.
15
+
16
+ ## Example
17
+
18
+ ```js
19
+ Function.prototype.bind = require("function-bind")
20
+ ```
21
+
22
+ ## Installation
23
+
24
+ `npm install function-bind`
25
+
26
+ ## Contributors
27
+
28
+ - Raynos
29
+
30
+ ## MIT Licenced
31
+
32
+ [package-url]: https://npmjs.org/package/function-bind
33
+ [npm-version-svg]: https://versionbadg.es/Raynos/function-bind.svg
34
+ [deps-svg]: https://david-dm.org/Raynos/function-bind.svg
35
+ [deps-url]: https://david-dm.org/Raynos/function-bind
36
+ [dev-deps-svg]: https://david-dm.org/Raynos/function-bind/dev-status.svg
37
+ [dev-deps-url]: https://david-dm.org/Raynos/function-bind#info=devDependencies
38
+ [npm-badge-png]: https://nodei.co/npm/function-bind.png?downloads=true&stars=true
39
+ [license-image]: https://img.shields.io/npm/l/function-bind.svg
40
+ [license-url]: LICENSE
41
+ [downloads-image]: https://img.shields.io/npm/dm/function-bind.svg
42
+ [downloads-url]: https://npm-stat.com/charts.html?package=function-bind
43
+ [codecov-image]: https://codecov.io/gh/Raynos/function-bind/branch/main/graphs/badge.svg
44
+ [codecov-url]: https://app.codecov.io/gh/Raynos/function-bind/
45
+ [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/Raynos/function-bind
46
+ [actions-url]: https://github.com/Raynos/function-bind/actions
web/node_modules/function-bind/implementation.js ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ /* eslint no-invalid-this: 1 */
4
+
5
+ var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
6
+ var toStr = Object.prototype.toString;
7
+ var max = Math.max;
8
+ var funcType = '[object Function]';
9
+
10
+ var concatty = function concatty(a, b) {
11
+ var arr = [];
12
+
13
+ for (var i = 0; i < a.length; i += 1) {
14
+ arr[i] = a[i];
15
+ }
16
+ for (var j = 0; j < b.length; j += 1) {
17
+ arr[j + a.length] = b[j];
18
+ }
19
+
20
+ return arr;
21
+ };
22
+
23
+ var slicy = function slicy(arrLike, offset) {
24
+ var arr = [];
25
+ for (var i = offset || 0, j = 0; i < arrLike.length; i += 1, j += 1) {
26
+ arr[j] = arrLike[i];
27
+ }
28
+ return arr;
29
+ };
30
+
31
+ var joiny = function (arr, joiner) {
32
+ var str = '';
33
+ for (var i = 0; i < arr.length; i += 1) {
34
+ str += arr[i];
35
+ if (i + 1 < arr.length) {
36
+ str += joiner;
37
+ }
38
+ }
39
+ return str;
40
+ };
41
+
42
+ module.exports = function bind(that) {
43
+ var target = this;
44
+ if (typeof target !== 'function' || toStr.apply(target) !== funcType) {
45
+ throw new TypeError(ERROR_MESSAGE + target);
46
+ }
47
+ var args = slicy(arguments, 1);
48
+
49
+ var bound;
50
+ var binder = function () {
51
+ if (this instanceof bound) {
52
+ var result = target.apply(
53
+ this,
54
+ concatty(args, arguments)
55
+ );
56
+ if (Object(result) === result) {
57
+ return result;
58
+ }
59
+ return this;
60
+ }
61
+ return target.apply(
62
+ that,
63
+ concatty(args, arguments)
64
+ );
65
+
66
+ };
67
+
68
+ var boundLength = max(0, target.length - args.length);
69
+ var boundArgs = [];
70
+ for (var i = 0; i < boundLength; i++) {
71
+ boundArgs[i] = '$' + i;
72
+ }
73
+
74
+ bound = Function('binder', 'return function (' + joiny(boundArgs, ',') + '){ return binder.apply(this,arguments); }')(binder);
75
+
76
+ if (target.prototype) {
77
+ var Empty = function Empty() {};
78
+ Empty.prototype = target.prototype;
79
+ bound.prototype = new Empty();
80
+ Empty.prototype = null;
81
+ }
82
+
83
+ return bound;
84
+ };
web/node_modules/function-bind/index.js ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var implementation = require('./implementation');
4
+
5
+ module.exports = Function.prototype.bind || implementation;
web/node_modules/function-bind/package.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "function-bind",
3
+ "version": "1.1.2",
4
+ "description": "Implementation of Function.prototype.bind",
5
+ "keywords": [
6
+ "function",
7
+ "bind",
8
+ "shim",
9
+ "es5"
10
+ ],
11
+ "author": "Raynos <raynos2@gmail.com>",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/Raynos/function-bind.git"
15
+ },
16
+ "funding": {
17
+ "url": "https://github.com/sponsors/ljharb"
18
+ },
19
+ "main": "index",
20
+ "homepage": "https://github.com/Raynos/function-bind",
21
+ "contributors": [
22
+ {
23
+ "name": "Raynos"
24
+ },
25
+ {
26
+ "name": "Jordan Harband",
27
+ "url": "https://github.com/ljharb"
28
+ }
29
+ ],
30
+ "bugs": {
31
+ "url": "https://github.com/Raynos/function-bind/issues",
32
+ "email": "raynos2@gmail.com"
33
+ },
34
+ "devDependencies": {
35
+ "@ljharb/eslint-config": "^21.1.0",
36
+ "aud": "^2.0.3",
37
+ "auto-changelog": "^2.4.0",
38
+ "eslint": "=8.8.0",
39
+ "in-publish": "^2.0.1",
40
+ "npmignore": "^0.3.0",
41
+ "nyc": "^10.3.2",
42
+ "safe-publish-latest": "^2.0.0",
43
+ "tape": "^5.7.1"
44
+ },
45
+ "license": "MIT",
46
+ "scripts": {
47
+ "prepublishOnly": "safe-publish-latest",
48
+ "prepublish": "not-in-publish || npm run prepublishOnly",
49
+ "prepack": "npmignore --auto --commentLines=autogenerated",
50
+ "pretest": "npm run lint",
51
+ "test": "npm run tests-only",
52
+ "posttest": "aud --production",
53
+ "tests-only": "nyc tape 'test/**/*.js'",
54
+ "lint": "eslint --ext=js,mjs .",
55
+ "version": "auto-changelog && git add CHANGELOG.md",
56
+ "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
57
+ },
58
+ "testling": {
59
+ "files": "test/index.js",
60
+ "browsers": [
61
+ "ie/8..latest",
62
+ "firefox/16..latest",
63
+ "firefox/nightly",
64
+ "chrome/22..latest",
65
+ "chrome/canary",
66
+ "opera/12..latest",
67
+ "opera/next",
68
+ "safari/5.1..latest",
69
+ "ipad/6.0..latest",
70
+ "iphone/6.0..latest",
71
+ "android-browser/4.2..latest"
72
+ ]
73
+ },
74
+ "auto-changelog": {
75
+ "output": "CHANGELOG.md",
76
+ "template": "keepachangelog",
77
+ "unreleased": false,
78
+ "commitLimit": false,
79
+ "backfillLimit": false,
80
+ "hideCredit": true
81
+ },
82
+ "publishConfig": {
83
+ "ignore": [
84
+ ".github/workflows"
85
+ ]
86
+ }
87
+ }