Repository: plexis-js/plexis
Pull request #58 (2019-10-22 23:52:34)

Feature request: `toChunks / chop`
Implementation of Feature request: `toChunks / chop` #56


Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index c338e34..6b9b1c6 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -14,3 +14,4 @@
 - [withoutDiacritics](/packages/withoutDiacritics)
 - [withoutIndent](/packages/withoutIndent)
 - [isString](/packages/isString)
+- [escapeHTML](/packages/escapeHTML)
diff --git a/lerna.json b/lerna.json
index ef7e5d5..730e230 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
 {
-  "version": "0.0.17",
+  "version": "0.0.18",
   "npmClient": "yarn",
   "packages": [
     "packages/*"
diff --git a/packages/cache/package.json b/packages/cache/package.json
index 2b842ff..8d5c510 100644
--- a/packages/cache/package.json
+++ b/packages/cache/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/cache",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/compose/package.json b/packages/compose/package.json
index cf49e77..b365d7a 100644
--- a/packages/compose/package.json
+++ b/packages/compose/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/compose",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/distance/package.json b/packages/distance/package.json
index 0776e5c..9da0525 100644
--- a/packages/distance/package.json
+++ b/packages/distance/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/distance",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/escapeHTML/README.md b/packages/escapeHTML/README.md
new file mode 100644
index 0000000..541d211
--- /dev/null
+++ b/packages/escapeHTML/README.md
@@ -0,0 +1,22 @@
+# `@plexis/escapeHTML`
+
+Takes the input text and converts HTML special characters to their entity equivalents.
+
+**Installation**
+`npm i @plexis/escape-html`
+
+**Usage**
+
+```javascript
+import escapeHTML from '@plexis/escape-html';
+
+escapeHTML('ABCD'); // returns 'ABCD'
+escapeHtml('<3'); // returns '&lt;3'
+escapeHtml('<p>This is cool</p>'); // returns '&lt;p&gt;This is cool&lt;/p&gt;'
+```
+
+**Aliases**
+
+```javascript
+import {escapeHTML} from 'plexis';
+```
diff --git a/packages/escapeHTML/package.json b/packages/escapeHTML/package.json
new file mode 100644
index 0000000..107bc85
--- /dev/null
+++ b/packages/escapeHTML/package.json
@@ -0,0 +1,29 @@
+{
+  "name": "@plexis/escape-html",
+  "version": "0.0.18",
+  "description": "Takes the input text and converts HTML special characters to their entity equivalents.",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "authors": [
+    "Nikhil Vats <nikvats5499@gmail.com>"
+  ],
+  "license": "MIT",
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "escapeHTML"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
diff --git a/packages/escapeHTML/src/index.js b/packages/escapeHTML/src/index.js
new file mode 100644
index 0000000..cb53961
--- /dev/null
+++ b/packages/escapeHTML/src/index.js
@@ -0,0 +1,23 @@
+/**
+ * @description Takes the input text and converts HTML special characters to their entity equivalents.
+ * @param {String} text
+ * @example
+ * escapeHTML('ABCD'); // returns 'ABCD'
+ * escapeHtml('<3') // returns '&lt;3'
+ * escapeHtml('<p>This is cool</p>') // returns '&lt;p&gt;This is cool&lt;/p&gt;'
+ */
+const escapeHTML = text => {
+  var map = {
+    '&': '&amp;',
+    '<': '&lt;',
+    '>': '&gt;',
+    '"': '&quot;',
+    "'": '&#039;'
+  };
+
+  return text.replace(/[&<>"']/g, function(m) {
+    return map[m];
+  });
+};
+
+export default escapeHTML;
diff --git a/packages/isLowerCase/package.json b/packages/isLowerCase/package.json
index 44ffc83..96c4ed0 100644
--- a/packages/isLowerCase/package.json
+++ b/packages/isLowerCase/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/is-lowercase",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/isString/package.json b/packages/isString/package.json
index e40fc4c..992105c 100644
--- a/packages/isString/package.json
+++ b/packages/isString/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/is-string",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/isUpperCase/package.json b/packages/isUpperCase/package.json
index a81f630..cbff44c 100644
--- a/packages/isUpperCase/package.json
+++ b/packages/isUpperCase/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/is-uppercase",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index 9c45e81..9d43cef 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -1,6 +1,6 @@
 {
   "name": "plexis",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
@@ -13,22 +13,24 @@
   ],
   "license": "MIT",
   "dependencies": {
-    "@plexis/compose": "^0.0.17",
-    "@plexis/distance": "^0.0.17",
-    "@plexis/is-lowercase": "^0.0.17",
-    "@plexis/is-string": "^0.0.17",
-    "@plexis/is-uppercase": "^0.0.17",
-    "@plexis/starts-with": "^0.0.17",
-    "@plexis/to-camel-case": "^0.0.17",
-    "@plexis/to-chicago": "^0.0.17",
-    "@plexis/to-lower": "^0.0.17",
-    "@plexis/to-pascal-case": "^0.0.17",
-    "@plexis/to-pred": "^0.0.17",
-    "@plexis/to-succ": "^0.0.17",
-    "@plexis/to-title": "^0.0.17",
-    "@plexis/when": "^0.0.17",
-    "@plexis/without-diacritics": "^0.0.17",
-    "@plexis/without-indent": "^0.0.17"
+    "@plexis/compose": "^0.0.18",
+    "@plexis/distance": "^0.0.18",
+    "@plexis/escape-html": "^0.0.18",
+    "@plexis/is-lowercase": "^0.0.18",
+    "@plexis/is-string": "^0.0.18",
+    "@plexis/is-uppercase": "^0.0.18",
+    "@plexis/starts-with": "^0.0.18",
+    "@plexis/to-camel-case": "^0.0.18",
+    "@plexis/to-chicago": "^0.0.18",
+    "@plexis/to-lower": "^0.0.18",
+    "@plexis/to-pascal-case": "^0.0.18",
+    "@plexis/to-pred": "^0.0.18",
+    "@plexis/to-succ": "^0.0.18",
+    "@plexis/to-title": "^0.0.18",
+    "@plexis/when": "^0.0.18",
+    "@plexis/without-diacritics": "^0.0.18",
+    "@plexis/without-indent": "^0.0.18",
+    "@plexis/to-chunks": "^0.0.18"
   },
   "keywords": [
     "utility",
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index b5734f2..30f3cd7 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -26,6 +26,7 @@ export {
   default as toChicagoTitle
 } from '@plexis/to-chicago';
 export {default as startsWith} from '@plexis/starts-with';
+export {default as toChunks} from '@plexis/to-chunks';
 export {default as _when} from '@plexis/when';
 export {
   default as withoutIndent,
@@ -39,3 +40,4 @@ export {
 } from '@plexis/distance';
 export {default as isString} from '@plexis/is-string';
 export {default as toPascalCase, default as classify} from '@plexis/to-pascal-case';
+export {default as escapeHTML} from '@plexis/escape-html';
diff --git a/packages/repeat/package.json b/packages/repeat/package.json
index 6610c14..e7e3217 100644
--- a/packages/repeat/package.json
+++ b/packages/repeat/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/repeat",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/startsWith/package.json b/packages/startsWith/package.json
index c52214a..242fd6d 100644
--- a/packages/startsWith/package.json
+++ b/packages/startsWith/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/starts-with",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toCamelCase/package.json b/packages/toCamelCase/package.json
index 3879f1a..b60f940 100644
--- a/packages/toCamelCase/package.json
+++ b/packages/toCamelCase/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-camel-case",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toChicago/package.json b/packages/toChicago/package.json
index 2b4a108..3ef3698 100644
--- a/packages/toChicago/package.json
+++ b/packages/toChicago/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-chicago",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toChunks/README.md b/packages/toChunks/README.md
new file mode 100644
index 0000000..15534a0
--- /dev/null
+++ b/packages/toChunks/README.md
@@ -0,0 +1,31 @@
+# `@plexis/to-chunks`
+
+Splits the input text into an array of chunks.
+
+**Installation**
+`npm i @plexis/to-chunks`
+
+**Usage**
+
+```javascript
+import toChunks from '@plexis/to-chunks';
+
+toChunks('Hello world');
+// => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
+
+toChunks('   ');
+// => [' ', ' ', ' ']
+
+toChunks('1234567', 2);
+// => ['12', '34', '56', '7']
+
+toChunks('1234567', 6);
+// => ['123456', '7']
+```
+
+**Aliases**
+
+```javascript
+import toChunks from '@plexis/to-chunks';
+import {toChunks, chop} from 'plexis';
+```
diff --git a/packages/toChunks/package.json b/packages/toChunks/package.json
new file mode 100644
index 0000000..ff3bb50
--- /dev/null
+++ b/packages/toChunks/package.json
@@ -0,0 +1,25 @@
+{
+  "name": "@plexis/to-chunks",
+  "version": "0.0.18",
+  "description": "Splits the input text into an array of chunks.",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "author": "korczynsk1",
+  "license": "MIT",
+  "keywords": [
+    "chunks",
+    "string"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
\ No newline at end of file
diff --git a/packages/toChunks/src/index.js b/packages/toChunks/src/index.js
new file mode 100644
index 0000000..4596a82
--- /dev/null
+++ b/packages/toChunks/src/index.js
@@ -0,0 +1,13 @@
+/**
+ * @description Converts a string to its equivalent predecessor
+ * @param {String} text The input String
+ * @param {Integer} chunkSize The size of each chunk, default to 1
+ * @example
+ * toChunks('Hello world'); // => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
+ * toChunks('   '); // => [' ', ' ', ' ']
+ * toChunks('1234567', 2); // => ['12', '34', '56', '7']
+ * toChunks('1234567', 6) // => ['123456', '7']
+ */
+const toChunks = (text, chunkSize = 1) => text.match(new RegExp(`.{1,${chunkSize}}`, 'g'));
+
+export default toChunks;
diff --git a/packages/toLower/package.json b/packages/toLower/package.json
index a694168..c94c8e3 100644
--- a/packages/toLower/package.json
+++ b/packages/toLower/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-lower",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toPascalCase/package.json b/packages/toPascalCase/package.json
index 4ad9863..0687b7d 100644
--- a/packages/toPascalCase/package.json
+++ b/packages/toPascalCase/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-pascal-case",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toPred/package.json b/packages/toPred/package.json
index fbf2479..d2bc94f 100644
--- a/packages/toPred/package.json
+++ b/packages/toPred/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-pred",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toSucc/package.json b/packages/toSucc/package.json
index 553022b..b6ad32f 100644
--- a/packages/toSucc/package.json
+++ b/packages/toSucc/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-succ",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/toTitle/package.json b/packages/toTitle/package.json
index 87daadf..7540b0c 100644
--- a/packages/toTitle/package.json
+++ b/packages/toTitle/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/to-title",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/when/package.json b/packages/when/package.json
index 32861d9..92156b2 100644
--- a/packages/when/package.json
+++ b/packages/when/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/when",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/withoutDiacritics/package.json b/packages/withoutDiacritics/package.json
index 394329c..32c9269 100644
--- a/packages/withoutDiacritics/package.json
+++ b/packages/withoutDiacritics/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/without-diacritics",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",
diff --git a/packages/withoutIndent/package.json b/packages/withoutIndent/package.json
index cfc1856..5a11b12 100644
--- a/packages/withoutIndent/package.json
+++ b/packages/withoutIndent/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@plexis/without-indent",
-  "version": "0.0.17",
+  "version": "0.0.18",
   "main": "dist/index.js",
   "module": "dist/index.esm.js",
   "jsnext:main": "./src/index.js",


Test patch:
diff --git a/packages/escapeHTML/test/index.js b/packages/escapeHTML/test/index.js
new file mode 100644
index 0000000..a042e71
--- /dev/null
+++ b/packages/escapeHTML/test/index.js
@@ -0,0 +1,10 @@
+import escapeHTML from '../src';
+
+it('converts HTML special characters in a string to entity equivalents', () => {
+  expect(escapeHTML('ABCD')).toBe('ABCD');
+  expect(escapeHTML('<3')).toBe('&lt;3');
+  expect(escapeHTML('<p>This is cool</p>')).toBe('&lt;p&gt;This is cool&lt;/p&gt;');
+  expect(escapeHTML('<div>"Rise" & \'Shine\'</div>')).toBe(
+    '&lt;div&gt;&quot;Rise&quot; &amp; &#039;Shine&#039;&lt;/div&gt;'
+  );
+});
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index d11c642..e594424 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -29,6 +29,7 @@ Array [
   "toChicagoStyle",
   "toChicagoTitle",
   "startsWith",
+  "toChunks",
   "_when",
   "withoutIndent",
   "removeIndent",
@@ -39,5 +40,6 @@ Array [
   "isString",
   "toPascalCase",
   "classify",
+  "escapeHTML",
 ]
 `;
diff --git a/packages/toChunks/test/index.js b/packages/toChunks/test/index.js
new file mode 100644
index 0000000..5f6f655
--- /dev/null
+++ b/packages/toChunks/test/index.js
@@ -0,0 +1,29 @@
+import toChunks from '../src';
+
+it('create chunks with default chunksize', () => {
+  expect(toChunks('Hello world')).toStrictEqual([
+    'H',
+    'e',
+    'l',
+    'l',
+    'o',
+    ' ',
+    'w',
+    'o',
+    'r',
+    'l',
+    'd'
+  ]);
+});
+
+it('create chunks of empty strings', () => {
+  expect(toChunks('   ')).toStrictEqual([' ', ' ', ' ']);
+});
+
+it('create chunks for chunk size equal 2', () => {
+  expect(toChunks('1234567', 2)).toStrictEqual(['12', '34', '56', '7']);
+});
+
+it('create chunks for chunk size equal 6', () => {
+  expect(toChunks('1234567', 6)).toStrictEqual(['123456', '7']);
+});