Repository: plexis-js/plexis
Pull request #88 (2019-10-27 15:47:40)

Feature: `withoutHTML / removeHTML`
Fix for #53 


Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index d8497a1..916c006 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -25,4 +25,5 @@
 - [toTitle](/packages/toTitle)
 - [when](/packages/when)
 - [withoutDiacritics](/packages/withoutDiacritics)
+- [withoutHTML](/packages/withoutHTML)
 - [withoutIndent](/packages/withoutIndent)
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index e0887af..8066a50 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -36,6 +36,7 @@
     "@plexis/to-title": "^0.0.21",
     "@plexis/when": "^0.0.21",
     "@plexis/without-diacritics": "^0.0.21",
+    "@plexis/without-html": "^0.0.21",
     "@plexis/without-indent": "^0.0.21"
   },
   "keywords": [
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index 042f0e2..2b95ef6 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -51,3 +51,4 @@ export {
   default as isAlphanumeric,
   default as isAlphaDigit
 } from '@plexis/is-alphanumeric';
+export {default as withoutHTML, default as removeHTML} from '@plexis/without-html';
diff --git a/packages/withoutHTML/README.md b/packages/withoutHTML/README.md
new file mode 100644
index 0000000..013a6cb
--- /dev/null
+++ b/packages/withoutHTML/README.md
@@ -0,0 +1,25 @@
+# `@plexis/withoutHTML`
+
+Removes HTML tags from the input text.
+
+**Installation**
+`npm i @plexis/without-html`
+
+**Usage**
+
+```javascript
+import withoutHTML from '@plexis/without-html';
+
+withoutHTML('Hello world'); // => 'Hello world'
+withoutHTML('<p>Hello</p> world'); // => ' world'
+withoutHTML('<p Hello world'); // => '<p Hello world'
+withoutHTML('<p id="">Hello world</p>'); // => ''
+withoutHTML('<p id="" Hello world</p> <b></b> from the underground'); // => ' from the underground'
+```
+
+**Aliases**
+
+```javascript
+import withoutHTML from '@plexis/without-html';
+import {withoutHTML, removeHTML} from 'plexis';
+```
diff --git a/packages/withoutHTML/package.json b/packages/withoutHTML/package.json
new file mode 100644
index 0000000..c583dc8
--- /dev/null
+++ b/packages/withoutHTML/package.json
@@ -0,0 +1,29 @@
+{
+  "name": "@plexis/without-html",
+  "version": "0.0.21",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "authors": [
+    "Gopi Krishna <gopiwayz@gmail.com> (https://bgopikrishna.me)"
+  ],
+  "license": "MIT",
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "format",
+    "validate"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
diff --git a/packages/withoutHTML/src/index.js b/packages/withoutHTML/src/index.js
new file mode 100644
index 0000000..9c36552
--- /dev/null
+++ b/packages/withoutHTML/src/index.js
@@ -0,0 +1,20 @@
+/**
+ * @description Remove HTML tags from the input text
+ * @param {String} text
+ * @returns {String} text without HTML
+ * @example
+ * withoutHTML('Hello world') => 'Hello world'
+ * withoutHTML('<p>Hello</p> world') => ' world'
+ * withoutHTML('<p Hello world') => '<p Hello world'
+ * withoutHTML('<p id="">Hello world</p>') => ''
+ * withoutHTML('<p id="" Hello world</p> <b></b> from the underground ') => ' from the underground'
+ */
+
+const withoutHTML = string => {
+  const wordPatt = /[^>]+>/g;
+  const stringWithOutHtml = string.replace(wordPatt, '');
+
+  return stringWithOutHtml;
+};
+
+export default withoutHTML;


Test patch:
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index 6239750..c445981 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -53,5 +53,7 @@ Array [
   "isAlphaNumeric",
   "isAlphanumeric",
   "isAlphaDigit",
+  "withoutHTML",
+  "removeHTML",
 ]
 `;
diff --git a/packages/withoutHTML/test/index.js b/packages/withoutHTML/test/index.js
new file mode 100644
index 0000000..41f8e3d
--- /dev/null
+++ b/packages/withoutHTML/test/index.js
@@ -0,0 +1,11 @@
+import withoutHTML from '../src';
+
+it('Remove HTML tags from the input text', () => {
+  expect(withoutHTML('Hello world')).toBe('Hello world');
+  expect(withoutHTML('<p>Hello</p> world')).toBe(' world');
+  expect(withoutHTML('<p Hello world')).toBe('<p Hello world');
+  expect(withoutHTML('<p id="">Hello world</p>')).toBe('');
+  expect(withoutHTML('<p id="" Hello world</p> <b></b> from the underground')).toBe(
+    ' from the underground'
+  );
+});