@fileverse-dev/formulajs 4.4.11-mod-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +52 -0
- package/README.md +125 -0
- package/bin/cli.js +58 -0
- package/lib/browser/formula.js +11307 -0
- package/lib/browser/formula.min.js +3 -0
- package/lib/browser/formula.min.js.map +1 -0
- package/lib/cjs/index.cjs +14007 -0
- package/lib/esm/index.mjs +13580 -0
- package/package.json +81 -0
- package/types/cjs/index.d.cts +5051 -0
- package/types/esm/index.d.mts +5051 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
Copyright (c) 2014 Sutoiku, Inc.
|
|
2
|
+
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
|
|
6
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
7
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
11
|
+
Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
14
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
15
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
16
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
17
|
+
|
|
18
|
+
Other libraries included:
|
|
19
|
+
|
|
20
|
+
BESSELI, BESSELJ, BESSELK, BESSELY functions:
|
|
21
|
+
|
|
22
|
+
Copyright (c) 2013 SheetJS
|
|
23
|
+
|
|
24
|
+
The MIT License (MIT)
|
|
25
|
+
|
|
26
|
+
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:
|
|
27
|
+
|
|
28
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
29
|
+
|
|
30
|
+
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.
|
|
31
|
+
|
|
32
|
+
jStat - JavaScript Statistical Library:
|
|
33
|
+
|
|
34
|
+
Copyright (c) 2013 jStat
|
|
35
|
+
|
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
37
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
38
|
+
in the Software without restriction, including without limitation the rights
|
|
39
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
40
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
41
|
+
furnished to do so, subject to the following conditions:
|
|
42
|
+
|
|
43
|
+
The above copyright notice and this permission notice shall be included in
|
|
44
|
+
all copies or substantial portions of the Software.
|
|
45
|
+
|
|
46
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
47
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
48
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
49
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
50
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
51
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
52
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Formula.js
|
|
2
|
+
|
|
3
|
+
[](https://github.com/formulajs/formulajs/actions/workflows/unit-tests.yaml) [](https://github.com/formulajs/formulajs/actions/workflows/npm-publish.yaml)
|
|
4
|
+
|
|
5
|
+
[Official website and documentation is here](https://formulajs.info)
|
|
6
|
+
|
|
7
|
+
## Use it
|
|
8
|
+
|
|
9
|
+
### In browser
|
|
10
|
+
|
|
11
|
+
[](https://www.jsdelivr.com/package/npm/@formulajs/formulajs)
|
|
12
|
+
|
|
13
|
+
Powered by [jsDelivr](https://www.jsdelivr.com/), you can use the latest version of Formula.js:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@formulajs/formulajs/lib/browser/formula.min.js"></script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Then the functions can be accessed as
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
formulajs.DATE(2008, 7, 8)
|
|
23
|
+
formulajs.SUM([1, 2, 3])
|
|
24
|
+
...
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### In node
|
|
28
|
+
|
|
29
|
+
[](https://www.npmjs.com/package/@formulajs/formulajs) [](https://www.npmjs.com/package/@formulajs/formulajs)
|
|
30
|
+
|
|
31
|
+
Install the package:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
npm i @formulajs/formulajs
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
#### import
|
|
38
|
+
|
|
39
|
+
```javascript
|
|
40
|
+
import * as formulajs from '@formulajs/formulajs' // import entire package
|
|
41
|
+
|
|
42
|
+
formulajs.SUM([1, 2, 3]) // 6
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
import { SUM } from '@formulajs/formulajs' // import individual components
|
|
47
|
+
|
|
48
|
+
SUM([1, 2, 3]) // 6
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
#### require
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
const formulajs = require('@formulajs/formulajs') // require entire package
|
|
55
|
+
|
|
56
|
+
formulajs.SUM([1, 2, 3]) // 6
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const { SUM } = require('@formulajs/formulajs') // require individual components
|
|
61
|
+
|
|
62
|
+
SUM([1, 2, 3]) // 6
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Command Line Interface (CLI)
|
|
66
|
+
|
|
67
|
+
When Formula.js is installed globally using npm, it can be used from the command line. To install Formula.js globally:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
npm i -g @formulajs/formulajs
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
After installation, Formula.js is available via the command line:
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
$ formulajs
|
|
77
|
+
> SUM(1,2,3)
|
|
78
|
+
6
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Differences between Excel functions and Formula.js
|
|
82
|
+
|
|
83
|
+
### Date
|
|
84
|
+
|
|
85
|
+
The functions `DATE, DATEVALUE, EDATE, EOMONT, NOW, TODAY`return plain JS Date instead of the serial Excel number.
|
|
86
|
+
|
|
87
|
+
Copying composite formula directly from Excel into JS will not work out of the box:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
= DATE(2020,5,9) - DATE(2020,5,8) // Formula.js: 86400000 / Excel: 1
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
It is not recommended to use `DATEVALUE` to parse string representing a date. Formula.js uses `new Date('YOUR STRING')` under the hood. There are better libraries to do this job (for example Moment.js)
|
|
94
|
+
|
|
95
|
+
## Migration guide
|
|
96
|
+
|
|
97
|
+
### From Formula.js
|
|
98
|
+
|
|
99
|
+
If you were previously using [formulajs from Sutoiku](https://www.npmjs.com/package/formulajs), some functions have been
|
|
100
|
+
removed, due to dependency simplification.
|
|
101
|
+
|
|
102
|
+
Text functions:
|
|
103
|
+
|
|
104
|
+
`FIXED, TEXT, DOLLAR, VALUE`
|
|
105
|
+
|
|
106
|
+
Math functions:
|
|
107
|
+
|
|
108
|
+
`MDETERM, MINVERSE, MMULT, MUNIT`
|
|
109
|
+
|
|
110
|
+
Otherwise, the 2 packages are fully compatible. You can swap them.
|
|
111
|
+
|
|
112
|
+
### From @handsontable/formulajs
|
|
113
|
+
|
|
114
|
+
The code of this package is originally forked from @handsontable/formulajs version 2.0.2 (released in January 2020). The
|
|
115
|
+
two packages were identical at the time. There is no regression, only fixes and new functions since the fork.
|
|
116
|
+
|
|
117
|
+
## Historic
|
|
118
|
+
|
|
119
|
+
Original Formula.js project was developed and maintained by Ismael Chang Ghalimi, with support from Sutoiku and help from
|
|
120
|
+
the following contributors: Ilmari Karonen, Sébastien Loisel, Trevor Norris, Roönaän, Hannes Stiebitzhofer.
|
|
121
|
+
|
|
122
|
+
It was then forked and extended by the [handsontable/formula.js](https://github.com/handsontable/formula.js) mainly
|
|
123
|
+
contributed by [@budnix](https://github.com/budnix).
|
|
124
|
+
|
|
125
|
+
As of September 2023, the repo is officially detached from its Handsontable and Sutoiku origins.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/* global console, process*/
|
|
4
|
+
|
|
5
|
+
// eslint-disable-next-line no-unused-vars
|
|
6
|
+
import * as formulajs from '../lib/esm/index.mjs'
|
|
7
|
+
import * as readline from 'readline'
|
|
8
|
+
|
|
9
|
+
function runStream(input, output) {
|
|
10
|
+
const rl = readline.createInterface({
|
|
11
|
+
input: input || process.stdin,
|
|
12
|
+
output: output || process.stdout
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
if (rl.output.isTTY) {
|
|
16
|
+
rl.setPrompt('> ')
|
|
17
|
+
rl.prompt()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
rl.on('line', (line) => {
|
|
21
|
+
const expr = line.trim()
|
|
22
|
+
|
|
23
|
+
switch (expr.toLowerCase()) {
|
|
24
|
+
case 'quit':
|
|
25
|
+
case 'exit':
|
|
26
|
+
rl.close()
|
|
27
|
+
break
|
|
28
|
+
case 'clear':
|
|
29
|
+
if (rl.output.isTTY) {
|
|
30
|
+
rl.prompt()
|
|
31
|
+
}
|
|
32
|
+
break
|
|
33
|
+
default:
|
|
34
|
+
if (!expr) {
|
|
35
|
+
break
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
let result = eval('formulajs.' + expr)
|
|
40
|
+
console.log(result)
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log(err.toString())
|
|
43
|
+
}
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (rl.output.isTTY) {
|
|
48
|
+
rl.prompt()
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
rl.on('close', () => {
|
|
53
|
+
console.log()
|
|
54
|
+
process.exit(0)
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
runStream(process.stdin, process.stdout)
|