@leankylin-sheet/formula-parser 3.1.29 → 3.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/error.d.ts +10 -0
- package/dist/evaluate-by-operator/evaluate-by-operator.d.ts +2 -0
- package/dist/evaluate-by-operator/operator/add.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/ampersand.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/divide.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/equal.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/formula-function.d.ts +7 -0
- package/dist/evaluate-by-operator/operator/greater-than-or-equal.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/greater-than.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/less-than-or-equal.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/less-than.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/minus.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/multiply.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/not-equal.d.ts +6 -0
- package/dist/evaluate-by-operator/operator/power.d.ts +6 -0
- package/dist/grammar-parser/grammar-parser.d.ts +4 -0
- package/dist/helper/cell.d.ts +6 -0
- package/dist/helper/number.d.ts +2 -0
- package/dist/helper/string.d.ts +1 -0
- package/{es/index.js → dist/index.d.ts} +5 -5
- package/{lib/grammar-parser/grammar-parser.js → dist/index.esm.js} +856 -46
- package/{es/grammar-parser/grammar-parser.js → dist/index.js} +903 -42
- package/dist/parser.d.ts +20 -0
- package/dist/supported-formulas.d.ts +2 -0
- package/package.json +6 -18
- package/LICENSE +0 -21
- package/es/error.js +0 -45
- package/es/evaluate-by-operator/evaluate-by-operator.js +0 -70
- package/es/evaluate-by-operator/operator/add.js +0 -16
- package/es/evaluate-by-operator/operator/ampersand.js +0 -10
- package/es/evaluate-by-operator/operator/divide.js +0 -21
- package/es/evaluate-by-operator/operator/equal.js +0 -5
- package/es/evaluate-by-operator/operator/formula-function.js +0 -40
- package/es/evaluate-by-operator/operator/greater-than-or-equal.js +0 -5
- package/es/evaluate-by-operator/operator/greater-than.js +0 -5
- package/es/evaluate-by-operator/operator/less-than-or-equal.js +0 -5
- package/es/evaluate-by-operator/operator/less-than.js +0 -5
- package/es/evaluate-by-operator/operator/minus.js +0 -16
- package/es/evaluate-by-operator/operator/multiply.js +0 -16
- package/es/evaluate-by-operator/operator/not-equal.js +0 -5
- package/es/evaluate-by-operator/operator/power.js +0 -11
- package/es/grammar-parser/grammar-parser.jison +0 -230
- package/es/helper/cell.js +0 -117
- package/es/helper/number.js +0 -25
- package/es/helper/string.js +0 -13
- package/es/parser.js +0 -306
- package/es/supported-formulas.js +0 -3
- package/lib/error.js +0 -53
- package/lib/evaluate-by-operator/evaluate-by-operator.js +0 -77
- package/lib/evaluate-by-operator/operator/add.js +0 -23
- package/lib/evaluate-by-operator/operator/ampersand.js +0 -17
- package/lib/evaluate-by-operator/operator/divide.js +0 -28
- package/lib/evaluate-by-operator/operator/equal.js +0 -12
- package/lib/evaluate-by-operator/operator/formula-function.js +0 -51
- package/lib/evaluate-by-operator/operator/greater-than-or-equal.js +0 -12
- package/lib/evaluate-by-operator/operator/greater-than.js +0 -12
- package/lib/evaluate-by-operator/operator/less-than-or-equal.js +0 -12
- package/lib/evaluate-by-operator/operator/less-than.js +0 -12
- package/lib/evaluate-by-operator/operator/minus.js +0 -23
- package/lib/evaluate-by-operator/operator/multiply.js +0 -23
- package/lib/evaluate-by-operator/operator/not-equal.js +0 -12
- package/lib/evaluate-by-operator/operator/power.js +0 -18
- package/lib/grammar-parser/grammar-parser.jison +0 -230
- package/lib/helper/cell.js +0 -128
- package/lib/helper/number.js +0 -32
- package/lib/helper/string.js +0 -19
- package/lib/index.js +0 -115
- package/lib/parser.js +0 -314
- package/lib/supported-formulas.js +0 -12
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '=';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 === exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.SYMBOL = void 0;
|
|
8
|
-
exports["default"] = func;
|
|
9
|
-
var formulajs = _interopRequireWildcard(require("@formulajs/formulajs"));
|
|
10
|
-
var _supportedFormulas = _interopRequireDefault(require("./../../supported-formulas"));
|
|
11
|
-
var _error = require("./../../error");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
|
15
|
-
var SYMBOL = exports.SYMBOL = _supportedFormulas["default"];
|
|
16
|
-
function func(symbol) {
|
|
17
|
-
return function __formulaFunction() {
|
|
18
|
-
symbol = symbol.toUpperCase();
|
|
19
|
-
var symbolParts = symbol.split('.');
|
|
20
|
-
var foundFormula = false;
|
|
21
|
-
var result;
|
|
22
|
-
if (symbolParts.length === 1) {
|
|
23
|
-
if (formulajs[symbolParts[0]]) {
|
|
24
|
-
foundFormula = true;
|
|
25
|
-
result = formulajs[symbolParts[0]].apply(formulajs, arguments);
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
var length = symbolParts.length;
|
|
29
|
-
var index = 0;
|
|
30
|
-
var nestedFormula = formulajs;
|
|
31
|
-
while (index < length) {
|
|
32
|
-
nestedFormula = nestedFormula[symbolParts[index]];
|
|
33
|
-
index++;
|
|
34
|
-
if (!nestedFormula) {
|
|
35
|
-
nestedFormula = null;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
if (nestedFormula) {
|
|
40
|
-
foundFormula = true;
|
|
41
|
-
result = nestedFormula.apply(void 0, arguments);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (!foundFormula) {
|
|
45
|
-
throw Error(_error.ERROR_NAME);
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
func.isFactory = true;
|
|
51
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '>=';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 >= exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '>';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 > exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '<=';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 <= exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '<';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 < exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var _number = require("./../../helper/number");
|
|
9
|
-
var _error = require("./../../error");
|
|
10
|
-
var SYMBOL = exports.SYMBOL = '-';
|
|
11
|
-
function func(first) {
|
|
12
|
-
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
13
|
-
rest[_key - 1] = arguments[_key];
|
|
14
|
-
}
|
|
15
|
-
var result = rest.reduce(function (acc, value) {
|
|
16
|
-
return acc - (0, _number.toNumber)(value);
|
|
17
|
-
}, (0, _number.toNumber)(first));
|
|
18
|
-
if (isNaN(result)) {
|
|
19
|
-
throw Error(_error.ERROR_VALUE);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var _number = require("./../../helper/number");
|
|
9
|
-
var _error = require("./../../error");
|
|
10
|
-
var SYMBOL = exports.SYMBOL = '*';
|
|
11
|
-
function func(first) {
|
|
12
|
-
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
13
|
-
rest[_key - 1] = arguments[_key];
|
|
14
|
-
}
|
|
15
|
-
var result = rest.reduce(function (acc, value) {
|
|
16
|
-
return acc * (0, _number.toNumber)(value);
|
|
17
|
-
}, (0, _number.toNumber)(first));
|
|
18
|
-
if (isNaN(result)) {
|
|
19
|
-
throw Error(_error.ERROR_VALUE);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var SYMBOL = exports.SYMBOL = '<>';
|
|
9
|
-
function func(exp1, exp2) {
|
|
10
|
-
return exp1 !== exp2;
|
|
11
|
-
}
|
|
12
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SYMBOL = void 0;
|
|
7
|
-
exports["default"] = func;
|
|
8
|
-
var _number = require("./../../helper/number");
|
|
9
|
-
var _error = require("./../../error");
|
|
10
|
-
var SYMBOL = exports.SYMBOL = '^';
|
|
11
|
-
function func(exp1, exp2) {
|
|
12
|
-
var result = Math.pow((0, _number.toNumber)(exp1), (0, _number.toNumber)(exp2));
|
|
13
|
-
if (isNaN(result)) {
|
|
14
|
-
throw Error(_error.ERROR_VALUE);
|
|
15
|
-
}
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
func.SYMBOL = SYMBOL;
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/* description: Parses end evaluates mathematical expressions. */
|
|
2
|
-
/* lexical grammar */
|
|
3
|
-
%lex
|
|
4
|
-
%%
|
|
5
|
-
\s+ {/* skip whitespace */}
|
|
6
|
-
'"'("\\"["]|[^"])*'"' {return 'STRING';}
|
|
7
|
-
"'"('\\'[']|[^'])*"'" {return 'STRING';}
|
|
8
|
-
[A-Za-z]{1,}[A-Za-z_0-9\.]+(?=[(]) {return 'FUNCTION';}
|
|
9
|
-
'#'[A-Z0-9\/]+('!'|'?')? {return 'ERROR';}
|
|
10
|
-
'$'[A-Za-z]+'$'[0-9]+ {return 'ABSOLUTE_CELL';}
|
|
11
|
-
'$'[A-Za-z]+[0-9]+ {return 'MIXED_CELL';}
|
|
12
|
-
[A-Za-z]+'$'[0-9]+ {return 'MIXED_CELL';}
|
|
13
|
-
[A-Za-z]+[0-9]+ {return 'RELATIVE_CELL';}
|
|
14
|
-
[A-Za-z\.]+(?=[(]) {return 'FUNCTION';}
|
|
15
|
-
[A-Za-z]{1,}[A-Za-z_0-9]+ {return 'VARIABLE';}
|
|
16
|
-
[A-Za-z_]+ {return 'VARIABLE';}
|
|
17
|
-
[0-9]+ {return 'NUMBER';}
|
|
18
|
-
'['(.*)?']' {return 'ARRAY';}
|
|
19
|
-
"&" {return '&';}
|
|
20
|
-
" " {return ' ';}
|
|
21
|
-
[.] {return 'DECIMAL';}
|
|
22
|
-
":" {return ':';}
|
|
23
|
-
";" {return ';';}
|
|
24
|
-
"," {return ',';}
|
|
25
|
-
"*" {return '*';}
|
|
26
|
-
"/" {return '/';}
|
|
27
|
-
"-" {return '-';}
|
|
28
|
-
"+" {return '+';}
|
|
29
|
-
"^" {return '^';}
|
|
30
|
-
"(" {return '(';}
|
|
31
|
-
")" {return ')';}
|
|
32
|
-
">" {return '>';}
|
|
33
|
-
"<" {return '<';}
|
|
34
|
-
"NOT" {return 'NOT';}
|
|
35
|
-
'"' {return '"';}
|
|
36
|
-
"'" {return "'";}
|
|
37
|
-
"!" {return "!";}
|
|
38
|
-
"=" {return '=';}
|
|
39
|
-
"%" {return '%';}
|
|
40
|
-
[#] {return '#';}
|
|
41
|
-
<<EOF>> {return 'EOF';}
|
|
42
|
-
/lex
|
|
43
|
-
|
|
44
|
-
/* operator associations and precedence (low-top, high-bottom) */
|
|
45
|
-
%left '='
|
|
46
|
-
%left '<=' '>=' '<>' 'NOT' '||'
|
|
47
|
-
%left '>' '<'
|
|
48
|
-
%left '+' '-'
|
|
49
|
-
%left '*' '/'
|
|
50
|
-
%left '^'
|
|
51
|
-
%left '&'
|
|
52
|
-
%left '%'
|
|
53
|
-
%left UMINUS
|
|
54
|
-
|
|
55
|
-
%start expressions
|
|
56
|
-
|
|
57
|
-
%% /* language grammar */
|
|
58
|
-
|
|
59
|
-
expressions
|
|
60
|
-
: expression EOF {
|
|
61
|
-
return $1;
|
|
62
|
-
}
|
|
63
|
-
;
|
|
64
|
-
|
|
65
|
-
expression
|
|
66
|
-
: variableSequence {
|
|
67
|
-
$$ = yy.callVariable($1[0]);
|
|
68
|
-
}
|
|
69
|
-
| number {
|
|
70
|
-
$$ = yy.toNumber($1);
|
|
71
|
-
}
|
|
72
|
-
| STRING {
|
|
73
|
-
$$ = yy.trimEdges($1);
|
|
74
|
-
}
|
|
75
|
-
| expression '&' expression {
|
|
76
|
-
$$ = yy.evaluateByOperator('&', [$1, $3]);
|
|
77
|
-
}
|
|
78
|
-
| expression '=' expression {
|
|
79
|
-
$$ = yy.evaluateByOperator('=', [$1, $3]);
|
|
80
|
-
}
|
|
81
|
-
| expression '+' expression {
|
|
82
|
-
$$ = yy.evaluateByOperator('+', [$1, $3]);
|
|
83
|
-
}
|
|
84
|
-
| '(' expression ')' {
|
|
85
|
-
$$ = $2;
|
|
86
|
-
}
|
|
87
|
-
| expression '<' '=' expression {
|
|
88
|
-
$$ = yy.evaluateByOperator('<=', [$1, $4]);
|
|
89
|
-
}
|
|
90
|
-
| expression '>' '=' expression {
|
|
91
|
-
$$ = yy.evaluateByOperator('>=', [$1, $4]);
|
|
92
|
-
}
|
|
93
|
-
| expression '<' '>' expression {
|
|
94
|
-
$$ = yy.evaluateByOperator('<>', [$1, $4]);
|
|
95
|
-
}
|
|
96
|
-
| expression NOT expression {
|
|
97
|
-
$$ = yy.evaluateByOperator('NOT', [$1, $3]);
|
|
98
|
-
}
|
|
99
|
-
| expression '>' expression {
|
|
100
|
-
$$ = yy.evaluateByOperator('>', [$1, $3]);
|
|
101
|
-
}
|
|
102
|
-
| expression '<' expression {
|
|
103
|
-
$$ = yy.evaluateByOperator('<', [$1, $3]);
|
|
104
|
-
}
|
|
105
|
-
| expression '-' expression {
|
|
106
|
-
$$ = yy.evaluateByOperator('-', [$1, $3]);
|
|
107
|
-
}
|
|
108
|
-
| expression '*' expression {
|
|
109
|
-
$$ = yy.evaluateByOperator('*', [$1, $3]);
|
|
110
|
-
}
|
|
111
|
-
| expression '/' expression {
|
|
112
|
-
$$ = yy.evaluateByOperator('/', [$1, $3]);
|
|
113
|
-
}
|
|
114
|
-
| expression '^' expression {
|
|
115
|
-
$$ = yy.evaluateByOperator('^', [$1, $3]);
|
|
116
|
-
}
|
|
117
|
-
| '-' expression {
|
|
118
|
-
var n1 = yy.invertNumber($2);
|
|
119
|
-
|
|
120
|
-
$$ = n1;
|
|
121
|
-
|
|
122
|
-
if (isNaN($$)) {
|
|
123
|
-
$$ = 0;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
| '+' expression {
|
|
127
|
-
var n1 = yy.toNumber($2);
|
|
128
|
-
|
|
129
|
-
$$ = n1;
|
|
130
|
-
|
|
131
|
-
if (isNaN($$)) {
|
|
132
|
-
$$ = 0;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
| FUNCTION '(' ')' {
|
|
136
|
-
$$ = yy.callFunction($1);
|
|
137
|
-
}
|
|
138
|
-
| FUNCTION '(' expseq ')' {
|
|
139
|
-
$$ = yy.callFunction($1, $3);
|
|
140
|
-
}
|
|
141
|
-
| cell
|
|
142
|
-
| error
|
|
143
|
-
| error error
|
|
144
|
-
;
|
|
145
|
-
|
|
146
|
-
cell
|
|
147
|
-
: ABSOLUTE_CELL {
|
|
148
|
-
$$ = yy.cellValue($1);
|
|
149
|
-
}
|
|
150
|
-
| RELATIVE_CELL {
|
|
151
|
-
$$ = yy.cellValue($1);
|
|
152
|
-
}
|
|
153
|
-
| MIXED_CELL {
|
|
154
|
-
$$ = yy.cellValue($1);
|
|
155
|
-
}
|
|
156
|
-
| ABSOLUTE_CELL ':' ABSOLUTE_CELL {
|
|
157
|
-
$$ = yy.rangeValue($1, $3);
|
|
158
|
-
}
|
|
159
|
-
| ABSOLUTE_CELL ':' RELATIVE_CELL {
|
|
160
|
-
$$ = yy.rangeValue($1, $3);
|
|
161
|
-
}
|
|
162
|
-
| ABSOLUTE_CELL ':' MIXED_CELL {
|
|
163
|
-
$$ = yy.rangeValue($1, $3);
|
|
164
|
-
}
|
|
165
|
-
| RELATIVE_CELL ':' ABSOLUTE_CELL {
|
|
166
|
-
$$ = yy.rangeValue($1, $3);
|
|
167
|
-
}
|
|
168
|
-
| RELATIVE_CELL ':' RELATIVE_CELL {
|
|
169
|
-
$$ = yy.rangeValue($1, $3);
|
|
170
|
-
}
|
|
171
|
-
| RELATIVE_CELL ':' MIXED_CELL {
|
|
172
|
-
$$ = yy.rangeValue($1, $3);
|
|
173
|
-
}
|
|
174
|
-
| MIXED_CELL ':' ABSOLUTE_CELL {
|
|
175
|
-
$$ = yy.rangeValue($1, $3);
|
|
176
|
-
}
|
|
177
|
-
| MIXED_CELL ':' RELATIVE_CELL {
|
|
178
|
-
$$ = yy.rangeValue($1, $3);
|
|
179
|
-
}
|
|
180
|
-
| MIXED_CELL ':' MIXED_CELL {
|
|
181
|
-
$$ = yy.rangeValue($1, $3);
|
|
182
|
-
}
|
|
183
|
-
;
|
|
184
|
-
|
|
185
|
-
expseq
|
|
186
|
-
: expression {
|
|
187
|
-
$$ = [$1];
|
|
188
|
-
}
|
|
189
|
-
| ARRAY {
|
|
190
|
-
$$ = yy.trimEdges(yytext).split(',');
|
|
191
|
-
}
|
|
192
|
-
| expseq ';' expression {
|
|
193
|
-
$1.push($3);
|
|
194
|
-
$$ = $1;
|
|
195
|
-
}
|
|
196
|
-
| expseq ',' expression {
|
|
197
|
-
$1.push($3);
|
|
198
|
-
$$ = $1;
|
|
199
|
-
}
|
|
200
|
-
;
|
|
201
|
-
|
|
202
|
-
variableSequence
|
|
203
|
-
: VARIABLE {
|
|
204
|
-
$$ = [$1];
|
|
205
|
-
}
|
|
206
|
-
| variableSequence DECIMAL VARIABLE {
|
|
207
|
-
$$ = (Array.isArray($1) ? $1 : [$1]);
|
|
208
|
-
$$.push($3);
|
|
209
|
-
}
|
|
210
|
-
;
|
|
211
|
-
|
|
212
|
-
number
|
|
213
|
-
: NUMBER {
|
|
214
|
-
$$ = $1;
|
|
215
|
-
}
|
|
216
|
-
| NUMBER DECIMAL NUMBER {
|
|
217
|
-
$$ = ($1 + '.' + $3) * 1;
|
|
218
|
-
}
|
|
219
|
-
| number '%' {
|
|
220
|
-
$$ = $1 * 0.01;
|
|
221
|
-
}
|
|
222
|
-
;
|
|
223
|
-
|
|
224
|
-
error
|
|
225
|
-
: ERROR {
|
|
226
|
-
$$ = yy.throwError($1);
|
|
227
|
-
}
|
|
228
|
-
;
|
|
229
|
-
|
|
230
|
-
%%
|
package/lib/helper/cell.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.columnIndexToLabel = columnIndexToLabel;
|
|
7
|
-
exports.columnLabelToIndex = columnLabelToIndex;
|
|
8
|
-
exports.extractLabel = extractLabel;
|
|
9
|
-
exports.rowIndexToLabel = rowIndexToLabel;
|
|
10
|
-
exports.rowLabelToIndex = rowLabelToIndex;
|
|
11
|
-
exports.toLabel = toLabel;
|
|
12
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
14
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
/**
|
|
19
|
-
* Convert row label to index.
|
|
20
|
-
*
|
|
21
|
-
* @param {String} label Row label (eq. '1', '5')
|
|
22
|
-
* @returns {Number} Returns -1 if label is not recognized otherwise proper row index.
|
|
23
|
-
*/
|
|
24
|
-
function rowLabelToIndex(label) {
|
|
25
|
-
var result = parseInt(label, 10);
|
|
26
|
-
if (isNaN(result)) {
|
|
27
|
-
result = -1;
|
|
28
|
-
} else {
|
|
29
|
-
result = Math.max(result - 1, -1);
|
|
30
|
-
}
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Convert row index to label.
|
|
36
|
-
*
|
|
37
|
-
* @param {Number} row Row index.
|
|
38
|
-
* @returns {String} Returns row label (eq. '1', '7').
|
|
39
|
-
*/
|
|
40
|
-
function rowIndexToLabel(row) {
|
|
41
|
-
var result = '';
|
|
42
|
-
if (row >= 0) {
|
|
43
|
-
result = "".concat(row + 1);
|
|
44
|
-
}
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
var COLUMN_LABEL_BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
48
|
-
var COLUMN_LABEL_BASE_LENGTH = COLUMN_LABEL_BASE.length;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Convert column label to index.
|
|
52
|
-
*
|
|
53
|
-
* @param {String} label Column label (eq. 'ABB', 'CNQ')
|
|
54
|
-
* @returns {Number} Returns -1 if label is not recognized otherwise proper column index.
|
|
55
|
-
*/
|
|
56
|
-
function columnLabelToIndex(label) {
|
|
57
|
-
var result = 0;
|
|
58
|
-
if (typeof label === 'string') {
|
|
59
|
-
label = label.toUpperCase();
|
|
60
|
-
for (var i = 0, j = label.length - 1; i < label.length; i += 1, j -= 1) {
|
|
61
|
-
result += Math.pow(COLUMN_LABEL_BASE_LENGTH, j) * (COLUMN_LABEL_BASE.indexOf(label[i]) + 1);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
--result;
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Convert column index to label.
|
|
70
|
-
*
|
|
71
|
-
* @param {Number} column Column index.
|
|
72
|
-
* @returns {String} Returns column label (eq. 'ABB', 'CNQ').
|
|
73
|
-
*/
|
|
74
|
-
function columnIndexToLabel(column) {
|
|
75
|
-
var result = '';
|
|
76
|
-
while (column >= 0) {
|
|
77
|
-
result = String.fromCharCode(column % COLUMN_LABEL_BASE_LENGTH + 97) + result;
|
|
78
|
-
column = Math.floor(column / COLUMN_LABEL_BASE_LENGTH) - 1;
|
|
79
|
-
}
|
|
80
|
-
return result.toUpperCase();
|
|
81
|
-
}
|
|
82
|
-
var simpleSheetName = "[A-Za-z0-9_\xC0-\u02AF]+";
|
|
83
|
-
var quotedSheetName = "'(?:(?!').|'')*'";
|
|
84
|
-
var sheetNameRegexp = "(".concat(simpleSheetName, "|").concat(quotedSheetName, ")!");
|
|
85
|
-
var LABEL_EXTRACT_REGEXP = new RegExp("^(?:".concat(sheetNameRegexp, ")?([$])?([A-Za-z]*)([$])?([0-9]*)$"));
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Extract cell coordinates.
|
|
89
|
-
*
|
|
90
|
-
* @param {String} label Cell coordinates (eq. 'A1', '$B6', '$N$98').
|
|
91
|
-
* @returns {Array} Returns an array of objects.
|
|
92
|
-
*/
|
|
93
|
-
function extractLabel(label) {
|
|
94
|
-
if (typeof label !== 'string' || !LABEL_EXTRACT_REGEXP.test(label)) {
|
|
95
|
-
return [];
|
|
96
|
-
}
|
|
97
|
-
var _label$toUpperCase$ma = label.toUpperCase().match(LABEL_EXTRACT_REGEXP),
|
|
98
|
-
_label$toUpperCase$ma2 = _slicedToArray(_label$toUpperCase$ma, 6),
|
|
99
|
-
sheetNameStr = _label$toUpperCase$ma2[1],
|
|
100
|
-
columnAbs = _label$toUpperCase$ma2[2],
|
|
101
|
-
column = _label$toUpperCase$ma2[3],
|
|
102
|
-
rowAbs = _label$toUpperCase$ma2[4],
|
|
103
|
-
row = _label$toUpperCase$ma2[5];
|
|
104
|
-
if (column == null && row == null) return [];
|
|
105
|
-
var sheetName = sheetNameStr == null ? null : label.slice(0, sheetNameStr.length).replace(/^'|'$/g, "").replace(/''/g, "'");
|
|
106
|
-
return [{
|
|
107
|
-
index: rowLabelToIndex(row),
|
|
108
|
-
label: row,
|
|
109
|
-
isAbsolute: rowAbs === '$'
|
|
110
|
-
}, {
|
|
111
|
-
index: columnLabelToIndex(column),
|
|
112
|
-
label: column,
|
|
113
|
-
isAbsolute: columnAbs === '$'
|
|
114
|
-
}, sheetName];
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Convert row and column indexes into cell label.
|
|
119
|
-
*
|
|
120
|
-
* @param {Object} row Object with `index` and `isAbsolute` properties.
|
|
121
|
-
* @param {Object} column Object with `index` and `isAbsolute` properties.
|
|
122
|
-
* @returns {String} Returns cell label.
|
|
123
|
-
*/
|
|
124
|
-
function toLabel(row, column) {
|
|
125
|
-
var rowLabel = (row.isAbsolute ? '$' : '') + rowIndexToLabel(row.index);
|
|
126
|
-
var columnLabel = (column.isAbsolute ? '$' : '') + columnIndexToLabel(column.index);
|
|
127
|
-
return columnLabel + rowLabel;
|
|
128
|
-
}
|
package/lib/helper/number.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.invertNumber = invertNumber;
|
|
7
|
-
exports.toNumber = toNumber;
|
|
8
|
-
/**
|
|
9
|
-
* Convert value into number.
|
|
10
|
-
*
|
|
11
|
-
* @param {String|Number} number
|
|
12
|
-
* @returns {*}
|
|
13
|
-
*/
|
|
14
|
-
function toNumber(number) {
|
|
15
|
-
var result;
|
|
16
|
-
if (typeof number === 'number') {
|
|
17
|
-
result = number;
|
|
18
|
-
} else if (typeof number === 'string') {
|
|
19
|
-
result = number.indexOf('.') > -1 ? parseFloat(number) : parseInt(number, 10);
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Invert provided number.
|
|
26
|
-
*
|
|
27
|
-
* @param {Number} number
|
|
28
|
-
* @returns {Number} Returns inverted number.
|
|
29
|
-
*/
|
|
30
|
-
function invertNumber(number) {
|
|
31
|
-
return -1 * toNumber(number);
|
|
32
|
-
}
|
package/lib/helper/string.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.trimEdges = trimEdges;
|
|
7
|
-
/* eslint-disable import/prefer-default-export */
|
|
8
|
-
/**
|
|
9
|
-
* Trim value by cutting character starting from the beginning and ending at the same time.
|
|
10
|
-
*
|
|
11
|
-
* @param {String} string String to trimming.
|
|
12
|
-
* @param {Number} [margin=1] Number of character to cut.
|
|
13
|
-
* @returns {String}
|
|
14
|
-
*/
|
|
15
|
-
function trimEdges(string) {
|
|
16
|
-
var margin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
17
|
-
string = string.substring(margin, string.length - margin);
|
|
18
|
-
return string;
|
|
19
|
-
}
|