spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[Text.CLEAN] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-10-08 17:19:15
stats
8 file(s) changed, 64 insertions(+), 6 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Text.js
src/Formulas/AllFormulas.ts
src/Formulas/Text.ts
tests/Formulas/TextTest.ts
tests/SheetFormulaTest.ts
  1diff --git a/DOCS.md b/DOCS.md
  2index 613a1c8..62f8a56 100644
  3--- a/DOCS.md
  4+++ b/DOCS.md
  5@@ -2479,3 +2479,12 @@
  6 @returns {number} 
  7 @constructor
  8 ```
  9+
 10+### CLEAN 
 11+
 12+```
 13+  Removes all non-printing characters from the string. 
 14+@param text - The text from which to remove all non-printable characters. 
 15+@returns {string} 
 16+@constructor
 17+```
 18diff --git a/TODO.md b/TODO.md
 19index 396e867..e8553a7 100644
 20--- a/TODO.md
 21+++ b/TODO.md
 22@@ -43,7 +43,6 @@ Many of these formulas can be written by allowing the Sheet and Parser to return
 23 
 24 
 25 ### Easy formulas to write
 26-* CLEAN
 27 * MID
 28 * PROPER
 29 * REGEXEXTRACT - May be difficult considering language differences.
 30diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
 31index 6215687..e1d2c7a 100644
 32--- a/dist/Formulas/AllFormulas.js
 33+++ b/dist/Formulas/AllFormulas.js
 34@@ -235,6 +235,7 @@ exports.RIGHT = Text_1.RIGHT;
 35 exports.SEARCH = Text_1.SEARCH;
 36 exports.REPT = Text_1.REPT;
 37 exports.VALUE = Text_1.VALUE;
 38+exports.CLEAN = Text_1.CLEAN;
 39 var Date_1 = require("./Date");
 40 exports.DATE = Date_1.DATE;
 41 exports.DATEVALUE = Date_1.DATEVALUE;
 42diff --git a/dist/Formulas/Text.js b/dist/Formulas/Text.js
 43index ebd711b..8eb403f 100644
 44--- a/dist/Formulas/Text.js
 45+++ b/dist/Formulas/Text.js
 46@@ -850,3 +850,15 @@ var VALUE = function (value) {
 47     return TypeConverter_1.TypeConverter.firstValueAsNumber(value);
 48 };
 49 exports.VALUE = VALUE;
 50+/**
 51+ * Removes all non-printing characters from the string.
 52+ * @param text - The text from which to remove all non-printable characters.
 53+ * @returns {string}
 54+ * @constructor
 55+ */
 56+var CLEAN = function (text) {
 57+    ArgsChecker_1.ArgsChecker.checkLength(arguments, 1, "CLEAN");
 58+    text = TypeConverter_1.TypeConverter.firstValueAsString(text);
 59+    return text.replace(/[\0-\x1F]/g, "");
 60+};
 61+exports.CLEAN = CLEAN;
 62diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
 63index 6abe939..33620e6 100644
 64--- a/src/Formulas/AllFormulas.ts
 65+++ b/src/Formulas/AllFormulas.ts
 66@@ -242,7 +242,8 @@ import {
 67   RIGHT,
 68   SEARCH,
 69   REPT,
 70-  VALUE
 71+  VALUE,
 72+  CLEAN
 73 } from "./Text"
 74 import {
 75   DATE,
 76@@ -545,5 +546,6 @@ export {
 77   RIGHT,
 78   SEARCH,
 79   REPT,
 80-  VALUE
 81+  VALUE,
 82+  CLEAN
 83 }
 84\ No newline at end of file
 85diff --git a/src/Formulas/Text.ts b/src/Formulas/Text.ts
 86index c80e535..9a6953d 100644
 87--- a/src/Formulas/Text.ts
 88+++ b/src/Formulas/Text.ts
 89@@ -882,6 +882,18 @@ let VALUE = function (value) {
 90   return TypeConverter.firstValueAsNumber(value);
 91 };
 92 
 93+/**
 94+ * Removes all non-printing characters from the string.
 95+ * @param text - The text from which to remove all non-printable characters.
 96+ * @returns {string}
 97+ * @constructor
 98+ */
 99+let CLEAN = function (text) {
100+  ArgsChecker.checkLength(arguments, 1, "CLEAN");
101+  text = TypeConverter.firstValueAsString(text);
102+  return text.replace(/[\0-\x1F]/g, "");
103+};
104+
105 export {
106   ARABIC,
107   CHAR,
108@@ -902,5 +914,6 @@ export {
109   RIGHT,
110   SEARCH,
111   REPT,
112-  VALUE
113+  VALUE,
114+  CLEAN
115 }
116\ No newline at end of file
117diff --git a/tests/Formulas/TextTest.ts b/tests/Formulas/TextTest.ts
118index f2e1dbb..f8073f9 100644
119--- a/tests/Formulas/TextTest.ts
120+++ b/tests/Formulas/TextTest.ts
121@@ -18,7 +18,8 @@ import {
122   RIGHT,
123   SEARCH,
124   REPT,
125-  VALUE
126+  VALUE,
127+  CLEAN
128 } from "../../src/Formulas/Text";
129 import * as ERRORS from "../../src/Errors";
130 import {
131@@ -499,4 +500,21 @@ test("VALUE", function(){
132   catchAndAssertEquals(function() {
133     VALUE("str");
134   }, ERRORS.VALUE_ERROR);
135+  catchAndAssertEquals(function() {
136+    VALUE.apply(this, [1, 2]);
137+  }, ERRORS.NA_ERROR);
138+});
139+
140+test("CLEAN", function(){
141+  assertEquals(CLEAN("hello"), "hello");
142+  assertEquals(CLEAN("hello¿Ãš"), "hello¿Ãš");
143+  assertEquals(CLEAN("hello"+CHAR(31)), "hello");
144+  assertEquals(CLEAN("hello\n"), "hello");
145+  assertEquals(CLEAN(10), "10");
146+  catchAndAssertEquals(function() {
147+    CLEAN.apply(this, []);
148+  }, ERRORS.NA_ERROR);
149+  catchAndAssertEquals(function() {
150+    CLEAN.apply(this, [1, 2]);
151+  }, ERRORS.NA_ERROR);
152 });
153diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
154index 37c89ae..001e768 100644
155--- a/tests/SheetFormulaTest.ts
156+++ b/tests/SheetFormulaTest.ts
157@@ -1077,6 +1077,10 @@ test("Sheet VALUE", function(){
158   assertFormulaEquals('=VALUE("10")', 10);
159 });
160 
161+test("Sheet CLEAN", function(){
162+  assertFormulaEquals('=CLEAN("hello"&CHAR(31))', "hello");
163+});
164+
165 test("Sheet parsing error", function(){
166   assertFormulaEqualsError('= 10e', PARSE_ERROR);
167   assertFormulaEqualsError('= SUM(', PARSE_ERROR);