spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Making Errors.get use object instead of filtering array
author
Ben Vogt <[email protected]>
date
2017-01-01 21:05:42
stats
1 file(s) changed, 22 insertions(+), 8 deletions(-)
files
src/Errors.ts
 1diff --git a/src/Errors.ts b/src/Errors.ts
 2index 0e6d73a..5f45e71 100644
 3--- a/src/Errors.ts
 4+++ b/src/Errors.ts
 5@@ -1,20 +1,27 @@
 6 var Errors = {
 7-  errors: [
 8-    {type: 'NULL', output: '#NULL'},
 9-    {type: 'DIV_ZERO', output: '#DIV/0!'},
10-    {type: 'VALUE', output: '#VALUE!'},
11-    {type: 'REF', output: '#REF!'},
12-    {type: 'NAME', output: '#NAME?'},
13-    {type: 'NUM', output: '#NUM!'},
14-    {type: 'NOT_AVAILABLE', output: '#N/A!'},
15-    {type: 'ERROR', output: '#ERROR'}
16-  ],
17+  errors: {
18+    'NULL': '#NULL',
19+    '#NULL': '#NULL',
20+    'DIV_ZERO': '#DIV/0!',
21+    '#DIV/0!': '#DIV/0!',
22+    'VALUE': '#VALUE!',
23+    '#VALUE!': '#VALUE!',
24+    'REF': '#REF!',
25+    '#REF!': '#REF!',
26+    'NAME': '#NAME?',
27+    '#NAME?': '#NAME?',
28+    'NUM': '#NUM!',
29+    '#NUM!': '#NUM!',
30+    'NOT_AVAILABLE': '#N/A!',
31+    '#N/A!': '#N/A!',
32+    'ERROR': '#ERROR',
33+    '#ERROR': '#ERROR'
34+  },
35   get: function (type) {
36-    var error = Errors.errors.filter(function (item) {
37-      return item.type === type || item.output === type;
38-    })[0];
39-
40-    return error ? error.output : null;
41+    if (type in Errors.errors) {
42+      return Errors.errors[type];
43+    }
44+    return null;
45   }
46 };
47