Repository: plexis-js/plexis
Pull request #28 (2019-10-20 19:37:23)

Added isAlpha method
Added the isAlpha function, fixed an export typo from last PR and should pass all CI this time 😅


Patch:
diff --git a/docs/pages/api.md b/docs/pages/api.md
index d6ee853..6e3c98c 100644
--- a/docs/pages/api.md
+++ b/docs/pages/api.md
@@ -3,6 +3,7 @@
 - [cache](/packages/cache)
 - [compose](/packages/compose)
 - [distance](/packages/distance)
+- [isAlpha](/packages/isAlpha)
 - [isLowerCase](/packages/isLowerCase)
 - [isUpperCase](/packages/isUpperCase)
 - [isNumeric](/packages/isNumeric)
diff --git a/packages/isAlpha/.npmignore b/packages/isAlpha/.npmignore
new file mode 100644
index 0000000..552cf85
--- /dev/null
+++ b/packages/isAlpha/.npmignore
@@ -0,0 +1,17 @@
+.DS_Store
+*.test.js
+.prettierrc
+.github
+.template
+.package-template
+.nyc_output
+.circleci
+.commitlintrc.js
+coverage
+coverage.lcov
+docs
+babel.config.js
+test
+CONTRIBUTING.md
+CODE_OF_CONDUCT.md
+LICENCE
\ No newline at end of file
diff --git a/packages/isAlpha/README.md b/packages/isAlpha/README.md
new file mode 100644
index 0000000..654ff6c
--- /dev/null
+++ b/packages/isAlpha/README.md
@@ -0,0 +1,22 @@
+# `@plexis/isAlpha`
+
+Check whether a string contains only alpha characters.
+
+**Installation**
+`npm i @plexis/is-alpha`
+
+**Usage**
+
+```javascript
+import isAlpha from '@plexis/is-alpha';
+
+isAlpha('Foo Bar'); // returns false
+isAlpha('FooBar'); // returns true
+isAlpha('f00b4r'); // returns false
+```
+
+**Aliases**
+
+```javascript
+import {isAlpha} from 'plexis';
+```
diff --git a/packages/isAlpha/package.json b/packages/isAlpha/package.json
new file mode 100644
index 0000000..7ecee28
--- /dev/null
+++ b/packages/isAlpha/package.json
@@ -0,0 +1,27 @@
+{
+  "name": "@plexis/is-alpha",
+  "version": "0.0.12",
+  "main": "dist/index.js",
+  "module": "dist/index.esm.js",
+  "jsnext:main": "./src/index.js",
+  "authors": [
+    "Rob Fairclough https://github.com/robfairclough"
+  ],
+  "license": "MIT",
+  "keywords": [
+    "utility",
+    "string",
+    "parse",
+    "format",
+    "validate",
+    "alpha",
+    "ascii"
+  ],
+  "repository": {
+    "type": "git",
+    "url": "git+https://github.com/plexis-js/plexis.git"
+  },
+  "publishConfig": {
+    "access": "public"
+  }
+}
diff --git a/packages/isAlpha/src/index.js b/packages/isAlpha/src/index.js
new file mode 100644
index 0000000..da63980
--- /dev/null
+++ b/packages/isAlpha/src/index.js
@@ -0,0 +1,17 @@
+/**
+ * @description Checks whether a given string contains only alpha characters
+ * @param {string} text
+ * @example
+ * isAlpha('Hello') // returns true
+ * isAlpha('Hello, there!') // returns false
+ * isAlpha('123') // returns false
+ * isAlpha('oneTwoThree') // returns true
+ */
+
+const isAlpha = text => {
+  if (!text || typeof text !== 'string') return false;
+  if (/[^a-z]/gi.test(text)) return false;
+  return true;
+};
+
+export default isAlpha;
diff --git a/packages/plexis/package.json b/packages/plexis/package.json
index b40bc1f..9cdf0b8 100644
--- a/packages/plexis/package.json
+++ b/packages/plexis/package.json
@@ -16,6 +16,7 @@
     "@plexis/compose": "^0.0.19",
     "@plexis/distance": "^0.0.19",
     "@plexis/escape-html": "^0.0.19",
+    "@plexis/is-alpha": "^0.0.12",
     "@plexis/is-lowercase": "^0.0.19",
     "@plexis/is-numeric": "^0.0.19",
     "@plexis/is-string": "^0.0.19",
diff --git a/packages/plexis/src/index.js b/packages/plexis/src/index.js
index bf5eaa3..372ccb9 100644
--- a/packages/plexis/src/index.js
+++ b/packages/plexis/src/index.js
@@ -17,6 +17,7 @@ export {
   default as cleanDiacritics,
   default as removeDiacritics
 } from '@plexis/without-diacritics';
+export {default as isAlpha} from '@plexis/is-alpha';
 export {default as isLowerCase, default as isLower} from '@plexis/is-lowercase';
 export {default as isUpperCase, default as isUpper} from '@plexis/is-uppercase';
 export {default as compose, default as _do} from '@plexis/compose';


Test patch:
diff --git a/packages/isAlpha/test/index.js b/packages/isAlpha/test/index.js
new file mode 100644
index 0000000..fc86f5e
--- /dev/null
+++ b/packages/isAlpha/test/index.js
@@ -0,0 +1,29 @@
+import isAlpha from '../src';
+
+describe('isAlpha function', () => {
+  it('should return false for an empty string', () => {
+    expect(isAlpha('')).toBe(false);
+  });
+
+  it('should return false for a numeric input regardless of type', () => {
+    expect(isAlpha(1)).toBe(false);
+    expect(isAlpha('1')).toBe(false);
+    expect(isAlpha({1: '1'})).toBe(false);
+  });
+
+  it('should return true for a single word', () => {
+    expect(isAlpha('word')).toBe(true);
+  });
+
+  it('should return false for a string with spaces', () => {
+    expect(isAlpha('Hello, there')).toBe(false);
+  });
+
+  it('should return false for a string with punctuation', () => {
+    expect(isAlpha('hey!')).toBe(false);
+  });
+
+  it('should return true for an all-alpha string with mixed case', () => {
+    expect(isAlpha('wHaTtHeTeSt')).toBe(true);
+  });
+});
diff --git a/packages/plexis/test/__snapshots__/index.js.snap b/packages/plexis/test/__snapshots__/index.js.snap
index 8edc145..d8415a4 100644
--- a/packages/plexis/test/__snapshots__/index.js.snap
+++ b/packages/plexis/test/__snapshots__/index.js.snap
@@ -20,6 +20,7 @@ Array [
   "withoutDiacritics",
   "cleanDiacritics",
   "removeDiacritics",
+  "isAlpha",
   "isLowerCase",
   "isLower",
   "isUpperCase",