Repository: plexis-js/plexis
Pull request #66 (2019-10-24 05:05:00)

feat(is-numeric): implementation of isNumeric feature
#54 


Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index 6b9b1c6..d6ee853 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -5,6 +5,7 @@
 - [distance](/packages/distance)
 - [isLowerCase](/packages/isLowerCase)
 - [isUpperCase](/packages/isUpperCase)
+- [isNumeric](/packages/isNumeric)
 - [startsWith](/packages/startsWith)
 - [toChicago](/packages/toChicago)
 - [toLower](/packages/toLower)
diff --git a/packages/isNumeric/README.md b/packages/isNumeric/README.md
new file mode 100644
index 0000000..a4dfd84
--- /dev/null
+++ b/packages/isNumeric/README.md
@@ -0,0 +1,40 @@
+# `@plexis/isNumeric`
+
+Validates if argument is valid numeric value.
+
+**Installation**
+`npm i @plexis/is-numeric`
+
+**Usage**
+
+```javascript
+import isNumeric from '@plexis/is-numeric';
+
+isNumeric('1000');
+// => true
+
+isNumeric('Infinity');
+// => true
+
+isNumeric('-100.4');
+// => true
+
+isNumeric('1E+2');
+// => true
+
+isNumeric('0xFF');
+// => true
+
+isNumeric('-');
+// => false
+
+isNumeric('one');
+// => false
+```
+
+**Aliases**
+
+```javascript
+import {isNum} from 'plexis';
+import {isNumeric} from 'plexis';
+```
diff --git a/packages/isNumeric/package.json b/packages/isNumeric/package.json
new file mode 100644
index 0000000..b89cbcb
--- /dev/null
+++ b/packages/isNumeric/package.json
@@ -0,0 +1,27 @@
+{
+  "name": "@plexis/is-numeric",
+  "version": "0.0.15",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "author": "edKim <nauthiz.jera@gmail.com>",
+  "license": "MIT",
+  "files": [
+    "dist",
+    "src"
+  ],
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "format",
+    "validate"
+  ],
+  "publishConfig": {
+    "access": "public"
+  },
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  }
+}
diff --git a/packages/isNumeric/src/index.js b/packages/isNumeric/src/index.js
new file mode 100644
index 0000000..9b97e43
--- /dev/null
+++ b/packages/isNumeric/src/index.js
@@ -0,0 +1,12 @@
+/**
+ * @description Checks whether the argument given is a number
+ * @param {Any} value to validate
+ * @return {boolean} Whether the argument passed was a number or not
+ * @example
+ * isNumeric('1000') // returns true
+ * isNumeric('Foo') // returns false
+ */
+
+const isNumeric = value => !isNaN(Number(value));
+
+export default isNumeric;
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index 9d43cef..b2b4195 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -19,6 +19,7 @@
     "@plexis/is-lowercase": "^0.0.18",
     "@plexis/is-string": "^0.0.18",
     "@plexis/is-uppercase": "^0.0.18",
+    "@plexis/is-numeric": "^0.0.15",
     "@plexis/starts-with": "^0.0.18",
     "@plexis/to-camel-case": "^0.0.18",
     "@plexis/to-chicago": "^0.0.18",
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index 30f3cd7..bf5eaa3 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -1,6 +1,7 @@
 export {default as toPred, default as toPredecessor} from '@plexis/to-pred';
 export {default as toSucc, default as toSuccessor} from '@plexis/to-succ';
 export {default as toTitle, default as titleize} from '@plexis/to-title';
+export {default as isNumeric, default as isNum} from '@plexis/is-numeric';
 export {
   default as toCamelCase,
   default as camelize,


Test patch:
diff --git a/packages/isNumeric/test/isNumeric.test.js b/packages/isNumeric/test/isNumeric.test.js
new file mode 100644
index 0000000..9d3363d
--- /dev/null
+++ b/packages/isNumeric/test/isNumeric.test.js
@@ -0,0 +1,37 @@
+'use strict';
+
+import isNumeric from '../src';
+
+describe('@plexis/isNumeric', () => {
+  it('check a valid numeric value `1000` ', () => {
+    expect(isNumeric('1000')).toBe(true);
+  });
+
+  it('test if Infinity is a valid number', () => {
+    expect(isNumeric('Infinity')).toBe(true);
+  });
+
+  it('test against a negative numeric value', () => {
+    expect(isNumeric('-100.4')).toBe(true);
+  });
+
+  it('test against a number in exponent shorthand', () => {
+    expect(isNumeric('1E+2')).toBe(true);
+  });
+
+  it('test against a hex number', () => {
+    expect(isNumeric('0xFF')).toBe(true);
+  });
+
+  it('test against a dash', () => {
+    expect(isNumeric('-')).toBe(false);
+  });
+
+  it('test against a string representation of a number', () => {
+    expect(isNumeric('one')).toBe(false);
+  });
+
+  it('test against a number', () => {
+    expect(isNumeric(100)).toBe(true);
+  });
+});
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index e594424..8edc145 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -9,6 +9,8 @@ Array [
   "toSuccessor",
   "toTitle",
   "titleize",
+  "isNumeric",
+  "isNum",
   "toCamelCase",
   "camelize",
   "camelCase",