', '')).toBe(4);
11 | });
12 |
13 | it('Levenshtein Distance should be the same for the same strings', () => {
14 | expect(distance('flaw', 'lawn')).toBe(2);
15 | expect(distance('lawn', 'flaw')).toBe(2);
16 | expect(distance('encyclopedia', 'cat')).toBe(11);
17 | expect(distance('cat', 'encyclopedia')).toBe(11);
18 | });
19 |
20 | it('Should return a Levenshtein Distance of 0 for non-strings', () => {
21 | expect(distance(x => 0, 'back')).toBe(0);
22 | expect(distance(9, 'back')).toBe(0);
23 | expect(distance(45, 0)).toBe(0);
24 | });
25 |
26 | it('Should return a number', () => {
27 | expect(typeof distance('book', 'back')).toBe('number');
28 | });
29 |
--------------------------------------------------------------------------------
/packages/endsWith/README.md:
--------------------------------------------------------------------------------
1 | # `endsWith`
2 |
3 | Checks whether the input text ends with the given pattern
4 |
5 | `npm i @plexis/ends-with`
6 |
7 | ## Usage
8 |
9 | ```javascript
10 | import endsWith from '@plexis/ends-with';
11 |
12 | const txt = 'This is me';
13 |
14 | endsWith(txt, 'is me'); // true
15 | endsWith(txt, 'is m', txt.length - 1); // true
16 | endsWith(txt, 'is m', txt.length); // false
17 | endsWith(txt, 'Foo'); // false
18 | ```
19 |
--------------------------------------------------------------------------------
/packages/endsWith/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/ends-with",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | },
26 | "dependencies": {
27 | "@plexis/is-string": "^0.0.22"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/endsWith/src/index.js:
--------------------------------------------------------------------------------
1 | import isString from '@plexis/is-string';
2 |
3 | /**
4 | * @description Checks whether the input text ends with the given pattern
5 | *
6 | * @param {String} text - String to be tested
7 | * @param {String|Regex} pattern - Pattern to be checked against text
8 | * @param {Number} startingPosition, optional - The position of the end of the string
9 | *
10 | * @example
11 | *
12 | * endsWith('This is me', 'is me') // true
13 | * endsWith('This is me', 'is m', ('This is me').length - 1) // true
14 | * endsWith('This is me', 'is m', ('This is me').length) // false
15 | * endsWith('This is me', 'Foo') // false
16 | */
17 | const endsWith = (text, pattern, startingPosition = text.length) => {
18 | if (isString(pattern)) {
19 | return text.endsWith(pattern, startingPosition);
20 | }
21 |
22 | if (pattern instanceof RegExp) {
23 | const stringPattern = String(pattern);
24 | const flags = stringPattern.slice(stringPattern.lastIndexOf('/') + 1);
25 |
26 | const leadingAndTrailingSlashes = new RegExp(`(?:^\/|\/${flags}$)`, 'g');
27 | const internalRegexString = stringPattern.replace(leadingAndTrailingSlashes, '');
28 | const endsWithRegex = new RegExp(`${internalRegexString}$`, flags);
29 |
30 | return endsWithRegex.test(text.slice(0, startingPosition));
31 | }
32 |
33 | return false;
34 | };
35 |
36 | export default endsWith;
37 |
--------------------------------------------------------------------------------
/packages/endsWith/test/ends-with.test.js:
--------------------------------------------------------------------------------
1 | import endsWith from '../src';
2 |
3 | describe('@plexis/ends-with', () => {
4 | const baseString = 'A normal string';
5 |
6 | it('receives strings as pattern', () => {
7 | expect(endsWith(baseString, 'string')).toBe(true);
8 | expect(endsWith(baseString, 'normal')).toBe(false);
9 | });
10 |
11 | it('receives regex as pattern', () => {
12 | expect(endsWith(baseString, /strr*[r|i]ng/)).toBe(true);
13 | expect(endsWith(baseString, /normal\/\s/m)).toBe(false);
14 | });
15 |
16 | it('takes starting position into consideration for string', () => {
17 | expect(endsWith(baseString, 'normal', 'A normal'.length)).toBe(true);
18 | expect(endsWith(baseString, 'string', 'A normal'.length)).toBe(false);
19 | });
20 |
21 | it('takes starting position into consideration for regex', () => {
22 | expect(endsWith(baseString, /n.rmal/, 'A normal'.length)).toBe(true);
23 | expect(endsWith(baseString, /string/, 'A normal'.length)).toBe(false);
24 | });
25 |
26 | it('is false for non-string and non-regex patterns', () => {
27 | expect(endsWith(baseString, false)).toBe(false);
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/escapeHTML/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/escapeHTML`
2 |
3 | Takes the input text and converts HTML special characters to their entity equivalents.
4 |
5 | **Installation**
6 | `npm i @plexis/escape-html`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import escapeHTML from '@plexis/escape-html';
12 |
13 | escapeHTML('ABCD'); // returns 'ABCD'
14 | escapeHtml('<3'); // returns '<3'
15 | escapeHtml(' This is cool '); // returns '<p>This is cool</p>'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {escapeHTML} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/escapeHTML/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/escape-html",
3 | "version": "0.0.22",
4 | "description": "Takes the input text and converts HTML special characters to their entity equivalents.",
5 | "main": "dist/index.js",
6 | "module": "dist/index.esm.js",
7 | "jsnext:main": "./src/index.js",
8 | "files": [
9 | "dist",
10 | "src"
11 | ],
12 | "authors": [
13 | "Nikhil Vats "
14 | ],
15 | "license": "MIT",
16 | "keywords": [
17 | "utility",
18 | "string",
19 | "parse",
20 | "escapeHTML"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/escapeHTML/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Takes the input text and converts HTML special characters to their entity equivalents.
3 | * @param {String} text
4 | * @example
5 | * escapeHTML('ABCD'); // returns 'ABCD'
6 | * escapeHtml('<3') // returns '<3'
7 | * escapeHtml('This is cool ') // returns '<p>This is cool</p>'
8 | */
9 | const escapeHTML = text => {
10 | var map = {
11 | '&': '&',
12 | '<': '<',
13 | '>': '>',
14 | '"': '"',
15 | "'": '''
16 | };
17 |
18 | return text.replace(/[&<>"']/g, function(m) {
19 | return map[m];
20 | });
21 | };
22 |
23 | export default escapeHTML;
24 |
--------------------------------------------------------------------------------
/packages/escapeHTML/test/index.js:
--------------------------------------------------------------------------------
1 | import escapeHTML from '../src';
2 |
3 | it('converts HTML special characters in a string to entity equivalents', () => {
4 | expect(escapeHTML('ABCD')).toBe('ABCD');
5 | expect(escapeHTML('<3')).toBe('<3');
6 | expect(escapeHTML('This is cool ')).toBe('<p>This is cool</p>');
7 | expect(escapeHTML('"Rise" & \'Shine\' ')).toBe(
8 | '<div>"Rise" & 'Shine'</div>'
9 | );
10 | });
11 |
--------------------------------------------------------------------------------
/packages/head/README.md:
--------------------------------------------------------------------------------
1 | ## `head`
2 |
3 | Extracts the first length characters from the input text.
4 |
5 | `npm i @plexis/head`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import head from '@plexis/head';
11 |
12 | head(); // => ''
13 | head('Hello'); // => 'H'
14 | head('Hello', 2); // => 'He'
15 | head('Hello', 100); // => 'Hello'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {head} from 'plexis';
22 | import {first} from 'plexis';
23 | import {popFirst} from 'plexis';
24 | ```
25 |
--------------------------------------------------------------------------------
/packages/head/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/head",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/head/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Extracts the first length characters from the input text.
3 | * @param {String} text
4 | * @param {Number} length
5 | * @example
6 | * head(); // => ''
7 | * head('Hello'); // => 'H'
8 | * head('Hello', 2); // => 'He'
9 | * head('Hello', 100); // => 'Hello'
10 | */
11 | const head = (text = '', length = 1) => {
12 | if (typeof text !== 'string') {
13 | throw new Error('Input text must be of type string');
14 | }
15 |
16 | if (isNaN(length) || typeof length !== 'number') {
17 | throw new Error('Length characters must be of type number');
18 | }
19 |
20 | return text.substr(0, length);
21 | };
22 |
23 | export default head;
24 |
--------------------------------------------------------------------------------
/packages/head/test/index.js:
--------------------------------------------------------------------------------
1 | import head from '../src';
2 |
3 | describe('returns the first length characters from the input text', () => {
4 | const cases = [{text: 'John'}, {text: 'Doe', length: 2}, {text: 'Hello', length: 100}];
5 | const expected = ['J', 'Do', 'Hello'];
6 |
7 | cases.forEach(({text, length}, i) => {
8 | test(`head(${text},${length})`, () => {
9 | expect(head(text, length)).toBe(expected[i]);
10 | });
11 | });
12 | });
13 |
14 | test('returns empty string if there is no input text provided', () => {
15 | expect(head()).toBe('');
16 | });
17 |
18 | describe('throws error if text is invalid', () => {
19 | const invalids = [null, NaN, {key: 'value'}, ['invalid'], 55];
20 |
21 | invalids.forEach(invalid => {
22 | test(`head(${invalid})`, () => {
23 | expect(() => {
24 | head(invalid);
25 | }).toThrow();
26 | });
27 | });
28 | });
29 |
30 | describe('throws error if length is invalid', () => {
31 | const invalids = [NaN, null, '55', {key: 'value'}, ['invalid']];
32 |
33 | invalids.forEach(invalid => {
34 | test(`head('Hello',${invalid})`, () => {
35 | expect(() => {
36 | head('Hello', invalid);
37 | }).toThrow();
38 | });
39 | });
40 | });
41 |
--------------------------------------------------------------------------------
/packages/includes/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/includes`
2 |
3 | Checks if the search is part of the input string in the given position
4 |
5 | **Installation**
6 | `npm i @plexis/includes`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import includes from '@plexis/includes';
12 |
13 | includes(); // => false
14 | includes(''); // => false
15 | includes('', ''); // => true
16 | includes('Foo', 'Foo'); // => true
17 | includes('Foo', 'Foo'); // => true
18 | includes('Foo', 'Foo', 2); // => false
19 | includes('Foo', 'oo'); // => true
20 | includes('Foo', 'Oo'); // => false
21 | ```
22 |
23 | **Aliases**
24 |
25 | ```javascript
26 | import includes from '@plexis/includes';
27 | import {includes, has} from 'plexis';
28 | ```
29 |
--------------------------------------------------------------------------------
/packages/includes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/includes",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "author": "edKim ",
8 | "license": "MIT",
9 | "files": [
10 | "dist",
11 | "src"
12 | ],
13 | "keywords": [
14 | "utility",
15 | "string",
16 | "parse",
17 | "format",
18 | "validate"
19 | ],
20 | "publishConfig": {
21 | "access": "public"
22 | },
23 | "repository": {
24 | "type": "git",
25 | "url": "git+https://github.com/plexis-js/plexis.git"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/includes/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks if the search is part of the input string in the given position
3 | * @params {string} [inputString] input string
4 | * @params {string) [searchString] search string
5 | * @params {number} [position] - check at given position
6 | * @return {boolean} Whether string2 is part of string1
7 | * @example
8 | * includes('Foo', 'oo') // returns true
9 | * includes('Foo', 'Foo', 2) // returns false
10 | */
11 |
12 | const includes = (inputString, searchString, position = 0) =>
13 | !!(
14 | typeof inputString === 'string' &&
15 | typeof searchString === 'string' &&
16 | RegExp(searchString, 'g').test(inputString.substring(position))
17 | );
18 |
19 | export default includes;
20 |
--------------------------------------------------------------------------------
/packages/includes/test/includes.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import includes from '../src';
4 |
5 | describe('@plexis/isNumeric', () => {
6 | it('no first or second string parameter given', () => {
7 | expect(includes()).toBe(false);
8 | });
9 |
10 | it('no second parameter given', () => {
11 | expect(includes('')).toBe(false);
12 | });
13 |
14 | it('empty string given for first and second string parameters', () => {
15 | expect(includes('', '')).toBe(true);
16 | });
17 |
18 | it('Equal first string and second string parameters', () => {
19 | expect(includes('Foo', 'Foo')).toBe(true);
20 | });
21 |
22 | it('Equal first string and second string with starting position of 2', () => {
23 | expect(includes('Foo', 'Foo', 2)).toBe(false);
24 | });
25 |
26 | it('Second parameter as substring of first parameter', () => {
27 | expect(includes('Foo', 'oo')).toBe(true);
28 | });
29 |
30 | it('Second parameter as substring of first parameter, but substring has different casing', () => {
31 | expect(includes('Foo', 'Oo')).toBe(false);
32 | });
33 |
34 | it('Second parameter as non string value', () => {
35 | expect(includes('Foo', false)).toBe(false);
36 | });
37 |
38 | it('First parameter as non string value', () => {
39 | expect(includes(null, 'Foo')).toBe(false);
40 | });
41 | });
42 |
--------------------------------------------------------------------------------
/packages/insert/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/insert`
2 |
3 | Inserts into the input text a string at specified position.
4 |
5 | `npm i @plexis/insert`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import insert from '@plexis/insert';
11 |
12 | insert(); // returns ''
13 | insert('foo ba'); // returns 'foo ba'
14 | insert('foo ba', 'r'); // returns 'foo bar'
15 | insert('foo ba', 'r', 1); // returns 'foo bar'
16 | insert('foo ba', 'r', 100); // returns 'foo bar'
17 | insert('foo ba', 'r', -100); // returns 'foo bar'
18 | insert('oo bar', 'r', 0); // returns 'foo bar'
19 | ```
20 |
21 | **Aliases**
22 |
23 | ```javascript
24 | import insert from '@plexis/insert';
25 | import {insert} from 'plexis';
26 | ```
27 |
--------------------------------------------------------------------------------
/packages/insert/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/insert",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "description": "Inserts into the input text a string at specified position.",
8 | "keywords": [
9 | "utility",
10 | "string",
11 | "format"
12 | ],
13 | "author": "Angel Gonzalez ",
14 | "homepage": "https://github.com/plexis-js/plexis#readme",
15 | "license": "MIT",
16 | "files": [
17 | "lib"
18 | ],
19 | "publishConfig": {
20 | "access": "public"
21 | },
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "bugs": {
27 | "url": "https://github.com/plexis-js/plexis/issues"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/insert/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Inserts into the input text a string at specified position
3 | * @param {String} text
4 | * @param {String} textToInsert
5 | * @param {Number} insertPosition
6 | *
7 | * @example
8 | * insert('foo ba'); // returns 'foo ba'
9 | * insert('foo ba', "r"); // returns 'foo bar'
10 | * insert('foo ba', "r", 6); // returns 'foo bar'
11 | * insert('foo ba', "r", 100); // returns 'foo bar'
12 | * insert('foo ba', "r", -100); // returns 'foo bar'
13 | * insert('oo bar', "f", 0); // returns 'foo bar'
14 | */
15 |
16 | const insert = (text = '', textToInsert = '', insertPosition = text.length) => {
17 | if (insertPosition < 0 || insertPosition > text.length || textToInsert === '') {
18 | return text + textToInsert;
19 | }
20 | return text.slice(0, insertPosition) + textToInsert + text.slice(insertPosition);
21 | };
22 |
23 | export default insert;
24 |
--------------------------------------------------------------------------------
/packages/insert/test/insert.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import insert from '../src';
4 | describe('@plexis/to-human', () => {
5 | it('returns an empty string', () => {
6 | expect(insert()).toBe('');
7 | expect(insert('')).toBe('');
8 | expect(insert('', '')).toBe('');
9 | expect(insert('', '', 0)).toBe('');
10 | expect(insert('', '', 100)).toBe('');
11 | });
12 |
13 | it('returns the same input', () => {
14 | expect(insert('foo bar')).toBe('foo bar');
15 | expect(insert('foo bar', '')).toBe('foo bar');
16 | expect(insert('foo bar', '', 100)).toBe('foo bar');
17 | });
18 |
19 | it('return the input with inserted text at the end', () => {
20 | expect(insert('foo ba', 'r', 6)).toBe('foo bar');
21 | expect(insert('foo ba', 'r', 100)).toBe('foo bar');
22 | expect(insert('foo ba', 'r', -100)).toBe('foo bar');
23 | });
24 |
25 | it('return the input with inserted text at n position', () => {
26 | expect(insert('foo br', 'a', 5)).toBe('foo bar');
27 | expect(insert('foo ba', 'r', 100)).toBe('foo bar');
28 | expect(insert('foo ba', 'r', -100)).toBe('foo bar');
29 | expect(insert('oo bar', 'f', 0)).toBe('foo bar');
30 | });
31 | });
32 |
--------------------------------------------------------------------------------
/packages/isAlpha/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.test.js
3 | .prettierrc
4 | .github
5 | .template
6 | .package-template
7 | .nyc_output
8 | .circleci
9 | .commitlintrc.js
10 | coverage
11 | coverage.lcov
12 | docs
13 | babel.config.js
14 | test
15 | CONTRIBUTING.md
16 | CODE_OF_CONDUCT.md
17 | LICENCE
--------------------------------------------------------------------------------
/packages/isAlpha/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/isAlpha`
2 |
3 | Check whether a string contains only alpha characters.
4 |
5 | **Installation**
6 | `npm i @plexis/is-alpha`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import isAlpha from '@plexis/is-alpha';
12 |
13 | isAlpha('Foo Bar'); // returns false
14 | isAlpha('FooBar'); // returns true
15 | isAlpha('f00b4r'); // returns false
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {isAlpha} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/isAlpha/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-alpha",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "authors": [
8 | "Rob Fairclough https://github.com/robfairclough"
9 | ],
10 | "license": "MIT",
11 | "keywords": [
12 | "utility",
13 | "string",
14 | "parse",
15 | "format",
16 | "validate",
17 | "alpha",
18 | "ascii"
19 | ],
20 | "repository": {
21 | "type": "git",
22 | "url": "git+https://github.com/plexis-js/plexis.git"
23 | },
24 | "publishConfig": {
25 | "access": "public"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/isAlpha/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether a given string contains only alpha characters
3 | * @param {string} text
4 | * @example
5 | * isAlpha('Hello') // returns true
6 | * isAlpha('Hello, there!') // returns false
7 | * isAlpha('123') // returns false
8 | * isAlpha('oneTwoThree') // returns true
9 | */
10 |
11 | const isAlpha = text => {
12 | if (!text || typeof text !== 'string') return false;
13 | if (/[^a-z]/gi.test(text)) return false;
14 | return true;
15 | };
16 |
17 | export default isAlpha;
18 |
--------------------------------------------------------------------------------
/packages/isAlpha/test/index.js:
--------------------------------------------------------------------------------
1 | import isAlpha from '../src';
2 |
3 | describe('isAlpha function', () => {
4 | it('should return false for an empty string', () => {
5 | expect(isAlpha('')).toBe(false);
6 | });
7 |
8 | it('should return false for a numeric input regardless of type', () => {
9 | expect(isAlpha(1)).toBe(false);
10 | expect(isAlpha('1')).toBe(false);
11 | expect(isAlpha({1: '1'})).toBe(false);
12 | });
13 |
14 | it('should return true for a single word', () => {
15 | expect(isAlpha('word')).toBe(true);
16 | });
17 |
18 | it('should return false for a string with spaces', () => {
19 | expect(isAlpha('Hello, there')).toBe(false);
20 | });
21 |
22 | it('should return false for a string with punctuation', () => {
23 | expect(isAlpha('hey!')).toBe(false);
24 | });
25 |
26 | it('should return true for an all-alpha string with mixed case', () => {
27 | expect(isAlpha('wHaTtHeTeSt')).toBe(true);
28 | });
29 | });
30 |
--------------------------------------------------------------------------------
/packages/isAlphaNumeric/.npmignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | *.test.js
3 | .prettierrc
4 | .github
5 | .template
6 | .package-template
7 | .nyc_output
8 | .circleci
9 | .commitlintrc.js
10 | coverage
11 | coverage.lcov
12 | docs
13 | babel.config.js
14 | test
15 | CONTRIBUTING.md
16 | CODE_OF_CONDUCT.md
17 | LICENCE
--------------------------------------------------------------------------------
/packages/isAlphaNumeric/README.md:
--------------------------------------------------------------------------------
1 | ## `isAlphaNumeric`
2 |
3 | Checks whether the input is a string containing only alphanumeric characters.
4 |
5 | `npm i @plexis/is-alphanumeric`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import isAlphaNumeric from '@plexis/is-alphanumeric';
11 |
12 | isAlphaNumeric('foo123BAR'); // returns true
13 | isAlphaNumeric('1.0'); // returns false
14 | isAlphaNumeric('bar!'); // returns false
15 | isAlphaNumeric(''); // returns false
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import isAlphaNumeric from '@plexis/is-alphanumeric';
22 | import {isAlphaNumeric, isAlphanumeric, isAlphaDigit} from 'plexis';
23 | ```
24 |
--------------------------------------------------------------------------------
/packages/isAlphaNumeric/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-alphanumeric",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "license": "MIT",
8 | "keywords": [
9 | "utility",
10 | "string",
11 | "parse",
12 | "format",
13 | "validate"
14 | ],
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/plexis-js/plexis.git"
18 | },
19 | "publishConfig": {
20 | "access": "public"
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/packages/isAlphaNumeric/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input is a string containing only alphanumeric characters
3 | * @param {String} text
4 | * @example
5 | * isAlphaNumeric('fooBAR') // returns true
6 | * isAlphaNumeric('123') // returns true
7 | * isAlphaNumeric('foo123BAR') // returns true
8 | * isAlphaNumeric('1.0') // returns false
9 | * isAlphaNumeric('bar!') // returns false
10 | * isAlphaNumeric('') // returns false
11 | */
12 | const isAlphaNumeric = text => (typeof text === 'string' ? /^[A-Za-z0-9]+$/.test(text) : false);
13 |
14 | export default isAlphaNumeric;
15 |
--------------------------------------------------------------------------------
/packages/isAlphaNumeric/test/index.js:
--------------------------------------------------------------------------------
1 | import isAlphaNumeric from '../src';
2 |
3 | it('should return true for a string of alphabetical characters (upper- and lower-case)', () => {
4 | expect(isAlphaNumeric('fooBAR')).toBe(true);
5 | });
6 |
7 | it('should return true for a string of numeric characters', () => {
8 | expect(isAlphaNumeric('123')).toBe(true);
9 | });
10 |
11 | it('should return true for a string of alphabetical and numeric characters', () => {
12 | expect(isAlphaNumeric('fooBAR123')).toBe(true);
13 | });
14 |
15 | it('should return false for strings with non-numeric characters', () => {
16 | expect(isAlphaNumeric('!')).toBe(false);
17 | expect(isAlphaNumeric('@')).toBe(false);
18 | expect(isAlphaNumeric('.')).toBe(false);
19 | expect(isAlphaNumeric(' ')).toBe(false);
20 | expect(isAlphaNumeric('-')).toBe(false);
21 | expect(isAlphaNumeric('_')).toBe(false);
22 | expect(isAlphaNumeric('=')).toBe(false);
23 | expect(isAlphaNumeric('+')).toBe(false);
24 | expect(isAlphaNumeric('(')).toBe(false);
25 | expect(isAlphaNumeric('^')).toBe(false);
26 | expect(isAlphaNumeric('ä')).toBe(false);
27 | });
28 |
29 | it('should return false for an empty string', () => {
30 | expect(isAlphaNumeric('')).toBe(false);
31 | });
32 |
33 | it('should return false for inputs that are not strings', () => {
34 | expect(isAlphaNumeric(0)).toBe(false);
35 | expect(isAlphaNumeric(1.5)).toBe(false);
36 | expect(isAlphaNumeric(true)).toBe(false);
37 | expect(isAlphaNumeric(null)).toBe(false);
38 | expect(isAlphaNumeric(undefined)).toBe(false);
39 | expect(isAlphaNumeric({foo: 'bar'})).toBe(false);
40 | expect(isAlphaNumeric(['foo', 'bar'])).toBe(false);
41 | });
42 |
--------------------------------------------------------------------------------
/packages/isEmpty/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/is-empty`
2 |
3 | Checks whether the input text is empty.
4 |
5 | **Installation**
6 | `npm i @plexis/to-lower`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import isEmpty from '@plexis/isEmpty';
12 |
13 | isEmpty(''); // returns true
14 | isEmpty(' '); // returns true
15 | isEmpty(' b '); // returns false
16 | isEmpty('Hello'); //returns false
17 | ```
18 |
19 | **Aliases**
20 |
21 | ```javascript
22 | import isEmpty from '@plexis/is-empty';
23 | import {isEmpty} from 'plexis';
24 | ```
25 |
--------------------------------------------------------------------------------
/packages/isEmpty/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-empty",
3 | "version": "0.0.22",
4 | "description": "Checks whether the input text is empty.",
5 | "main": "dist/index.js",
6 | "module": "dist/index.esm.js",
7 | "jsnext:main": "./src/index.js",
8 | "author": "eElec ",
9 | "files": [
10 | "dist",
11 | "src"
12 | ],
13 | "license": "MIT",
14 | "keywords": [
15 | "utility",
16 | "string",
17 | "parse",
18 | "format",
19 | "validate"
20 | ],
21 | "repository": {
22 | "type": "git",
23 | "url": "git+https://github.com/plexis-js/plexis.git"
24 | },
25 | "publishConfig": {
26 | "access": "public"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/packages/isEmpty/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input text is empty
3 | * @param {String} text
4 | * @example
5 | * isEmpty('') // returns true
6 | * isEmpty(' ') // returns true
7 | * isEmpty(' b ') // returns false
8 | */
9 | const isEmpty = text => /^\s*$/.test(text);
10 |
11 | export default isEmpty;
12 |
--------------------------------------------------------------------------------
/packages/isEmpty/test/index.js:
--------------------------------------------------------------------------------
1 | import isEmpty from '../src/';
2 |
3 | it('check empty string', () => {
4 | expect(isEmpty('')).toBe(true);
5 | });
6 |
7 | it('check string with spaces', () => {
8 | expect(isEmpty(' ')).toBe(true);
9 | });
10 |
11 | it('check string ith spaces and character', () => {
12 | expect(isEmpty(' b ')).toBe(false);
13 | });
14 |
15 | it('check string with characters', () => {
16 | expect(isEmpty('Hello')).toBe(false);
17 | });
18 |
--------------------------------------------------------------------------------
/packages/isLowerCase/README.md:
--------------------------------------------------------------------------------
1 | ## `isLowerCase`
2 |
3 | Checks whether the input is a string containing only lowercase characters
4 |
5 | `npm i @plexis/is-lowercase`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import isLowerCase from '@plexis/is-lowercase';
11 |
12 | isLowerCase('foo'); // returns true
13 | isLowerCase('Foo'); // returns false
14 | isLowerCase('BAR'); // returns false
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import {isLowerCase} from 'plexis';
21 | import {isLower} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/isLowerCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-lowercase",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/isLowerCase/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input is a string containing only lowercase characters
3 | * @param {String} text
4 | * @example
5 | * isLowerCase('foo') // returns true
6 | * isLowerCase('Foo') // returns false
7 | * isLowerCase('BAR') // returns false
8 | */
9 | const isLowerCase = text => text === text.toLowerCase();
10 |
11 | export default isLowerCase;
12 |
--------------------------------------------------------------------------------
/packages/isLowerCase/test/index.js:
--------------------------------------------------------------------------------
1 | import isLowerCase from '../src';
2 |
3 | it('check a uppercase string', () => {
4 | expect(isLowerCase('HELLO')).toBe(false);
5 | });
6 |
7 | it('check a lowercase with spaces string', () => {
8 | expect(isLowerCase('foo bar')).toBe(true);
9 | });
10 |
11 | it('check a lowercase string', () => {
12 | expect(isLowerCase('hello')).toBe(true);
13 | });
14 |
15 | it('check a lowercase string with an uppercase char in the middle', () => {
16 | expect(isLowerCase('hello Foo bar')).toBe(false);
17 | });
18 |
--------------------------------------------------------------------------------
/packages/isNumeric/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/isNumeric`
2 |
3 | Validates if argument is valid numeric value.
4 |
5 | **Installation**
6 | `npm i @plexis/is-numeric`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import isNumeric from '@plexis/is-numeric';
12 |
13 | isNumeric('1000');
14 | // => true
15 |
16 | isNumeric('Infinity');
17 | // => true
18 |
19 | isNumeric('-100.4');
20 | // => true
21 |
22 | isNumeric('1E+2');
23 | // => true
24 |
25 | isNumeric('0xFF');
26 | // => true
27 |
28 | isNumeric('-');
29 | // => false
30 |
31 | isNumeric('one');
32 | // => false
33 | ```
34 |
35 | **Aliases**
36 |
37 | ```javascript
38 | import {isNum} from 'plexis';
39 | import {isNumeric} from 'plexis';
40 | ```
41 |
--------------------------------------------------------------------------------
/packages/isNumeric/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-numeric",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "author": "edKim ",
8 | "license": "MIT",
9 | "files": [
10 | "dist",
11 | "src"
12 | ],
13 | "keywords": [
14 | "utility",
15 | "string",
16 | "parse",
17 | "format",
18 | "validate"
19 | ],
20 | "publishConfig": {
21 | "access": "public"
22 | },
23 | "repository": {
24 | "type": "git",
25 | "url": "git+https://github.com/plexis-js/plexis.git"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/isNumeric/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the argument given is a number
3 | * @param {Any} value to validate
4 | * @return {boolean} Whether the argument passed was a number or not
5 | * @example
6 | * isNumeric('1000') // returns true
7 | * isNumeric('Foo') // returns false
8 | */
9 |
10 | const isNumeric = value => !isNaN(Number(value));
11 |
12 | export default isNumeric;
13 |
--------------------------------------------------------------------------------
/packages/isNumeric/test/isNumeric.test.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import isNumeric from '../src';
4 |
5 | describe('@plexis/isNumeric', () => {
6 | it('check a valid numeric value `1000` ', () => {
7 | expect(isNumeric('1000')).toBe(true);
8 | });
9 |
10 | it('test if Infinity is a valid number', () => {
11 | expect(isNumeric('Infinity')).toBe(true);
12 | });
13 |
14 | it('test against a negative numeric value', () => {
15 | expect(isNumeric('-100.4')).toBe(true);
16 | });
17 |
18 | it('test against a number in exponent shorthand', () => {
19 | expect(isNumeric('1E+2')).toBe(true);
20 | });
21 |
22 | it('test against a hex number', () => {
23 | expect(isNumeric('0xFF')).toBe(true);
24 | });
25 |
26 | it('test against a dash', () => {
27 | expect(isNumeric('-')).toBe(false);
28 | });
29 |
30 | it('test against a string representation of a number', () => {
31 | expect(isNumeric('one')).toBe(false);
32 | });
33 |
34 | it('test against a number', () => {
35 | expect(isNumeric(100)).toBe(true);
36 | });
37 | });
38 |
--------------------------------------------------------------------------------
/packages/isString/README.md:
--------------------------------------------------------------------------------
1 | ## `isString`
2 |
3 | Checks whether the input is a string primitive type.
4 |
5 | `npm i @plexis/is-string`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import isString from '@plexis/is-string';
11 |
12 | isString('Foo'); // returns 'true'
13 | isString(1); // returns 'false'
14 | isString(null); // returns 'false'
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import {isString} from 'plexis';
21 | ```
22 |
--------------------------------------------------------------------------------
/packages/isString/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-string",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/isString/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input is a string primitive type.
3 | * @param {String} param
4 | * @returns {Boolean}
5 | * @example
6 | * isString('Foo') // returns 'true'
7 | * isString(1) // returns 'false'
8 | * isString(null) // returns 'false'
9 | */
10 | const isString = param => typeof param === 'string';
11 |
12 | export default isString;
13 |
--------------------------------------------------------------------------------
/packages/isString/test/index.js:
--------------------------------------------------------------------------------
1 | import isString from '../src';
2 |
3 | it('returns false for non-string types', () => {
4 | const nonStrings = [5, false, true, null, undefined, {}, [1, 2], []];
5 |
6 | nonStrings.forEach(param => {
7 | expect(isString(param)).toBe(false);
8 | });
9 | });
10 |
11 | it('returns true for string type', () => {
12 | const strings = [
13 | 'Foo',
14 | '',
15 | false.toString(),
16 | (1).toString(),
17 | {foo: 'bar'}.toString(),
18 | [1, 2, 3, 4].toString()
19 | ];
20 |
21 | strings.forEach(param => {
22 | expect(isString(param)).toBe(true);
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/packages/isUpperCase/README.md:
--------------------------------------------------------------------------------
1 | ## `isUpperCase`
2 |
3 | Checks whether the input is a string containing only uppercase characters
4 |
5 | `npm i @plexis/is-uppercase`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import isUpperCase from '@plexis/is-uppercase';
11 |
12 | isUpperCase️('b'); // returns false
13 | isUpperCase️('B'); // returns true
14 | isUpperCase️('BCD'); // returns true
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import {isUpperCase} from 'plexis';
21 | import {isUpper} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/isUpperCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/is-uppercase",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/isUpperCase/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input is a string containing only uppercase characters
3 | * @param {String} text
4 | * @example
5 | * isUpperCase️('b') // returns false
6 | * isUpperCase️('B') // returns true
7 | * isUpperCase️('BCD') // returns true
8 | */
9 | const isUpperCase️ = text => text === text.toUpperCase();
10 |
11 | export default isUpperCase️;
12 |
--------------------------------------------------------------------------------
/packages/isUpperCase/test/index.js:
--------------------------------------------------------------------------------
1 | import isUpperCase from '../src';
2 |
3 | it('check a uppercase string', () => {
4 | expect(isUpperCase('HELLO')).toBe(true);
5 | });
6 |
7 | it('check a uppercase with spaces string', () => {
8 | expect(isUpperCase('HELLO FOO BAR')).toBe(true);
9 | });
10 |
11 | it('check a lowercase string', () => {
12 | expect(isUpperCase('hello')).toBe(false);
13 | });
14 |
15 | it('check a uppercase string with an lowercase char in the middle', () => {
16 | expect(isUpperCase('HELLO FOo BAR')).toBe(false);
17 | });
18 |
--------------------------------------------------------------------------------
/packages/plexis/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ### Plexis: Lo-fi, powerful, community-driven string manipulation library.
4 |
5 |
6 |
7 | Learn more about [Plexis](/README.md) or take a look at the [API](/docs/pages/api.md).
8 |
--------------------------------------------------------------------------------
/packages/plexis/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "plexis",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "dependencies": {
16 | "@plexis/compare": "^0.0.22",
17 | "@plexis/compose": "^0.0.22",
18 | "@plexis/count": "^0.0.22",
19 | "@plexis/distance": "^0.0.22",
20 | "@plexis/ends-with": "^0.0.22",
21 | "@plexis/escape-html": "^0.0.22",
22 | "@plexis/head": "^0.0.22",
23 | "@plexis/includes": "^0.0.22",
24 | "@plexis/insert": "^0.0.22",
25 | "@plexis/is-alpha": "^0.0.22",
26 | "@plexis/is-alphanumeric": "^0.0.22",
27 | "@plexis/is-lowercase": "^0.0.22",
28 | "@plexis/is-numeric": "^0.0.22",
29 | "@plexis/is-string": "^0.0.22",
30 | "@plexis/is-uppercase": "^0.0.22",
31 | "@plexis/starts-with": "^0.0.22",
32 | "@plexis/tail": "^0.0.22",
33 | "@plexis/to-camel-case": "^0.0.22",
34 | "@plexis/to-capitals": "^0.0.22",
35 | "@plexis/to-chicago": "^0.0.22",
36 | "@plexis/to-chunks": "^0.0.22",
37 | "@plexis/to-human": "^0.0.22",
38 | "@plexis/to-lower": "^0.0.22",
39 | "@plexis/to-pascal-case": "^0.0.22",
40 | "@plexis/to-plural": "^0.0.22",
41 | "@plexis/to-pred": "^0.0.22",
42 | "@plexis/to-snake-case": "^0.0.22",
43 | "@plexis/to-succ": "^0.0.22",
44 | "@plexis/to-swap": "^0.0.22",
45 | "@plexis/to-swap-case": "^0.0.22",
46 | "@plexis/to-title": "^0.0.22",
47 | "@plexis/when": "^0.0.22",
48 | "@plexis/without-diacritics": "^0.0.22",
49 | "@plexis/without-html": "^0.0.22",
50 | "@plexis/without-indent": "^0.0.22",
51 | "@plexis/is-empty": "^0.0.22",
52 | "@plexis/count-words": "^0.0.22",
53 | "@plexis/to-ellipsis": "^0.0.22"
54 | },
55 | "keywords": [
56 | "utility",
57 | "string",
58 | "parse",
59 | "format",
60 | "validate"
61 | ],
62 | "repository": {
63 | "type": "git",
64 | "url": "git+https://github.com/plexis-js/plexis.git"
65 | },
66 | "publishConfig": {
67 | "access": "public"
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/packages/plexis/src/index.js:
--------------------------------------------------------------------------------
1 | export {
2 | default as compare,
3 | default as compareLikeHuman,
4 | default as naturalCompare
5 | } from '@plexis/compare';
6 | export {default as compose, default as _do} from '@plexis/compose';
7 | export {default as count} from '@plexis/count';
8 | export {
9 | default as calcLevenshtein,
10 | default as distance,
11 | default as levenshtein
12 | } from '@plexis/distance';
13 | export {default as endsWith} from '@plexis/ends-with';
14 | export {default as escapeHTML} from '@plexis/escape-html';
15 | export {default as head, default as first, default as popFirst} from '@plexis/head';
16 | export {default as insert} from '@plexis/insert';
17 | export {default as isAlpha} from '@plexis/is-alpha';
18 | export {default as isLower, default as isLowerCase} from '@plexis/is-lowercase';
19 | export {default as isNum, default as isNumeric} from '@plexis/is-numeric';
20 | export {default as includes, default as has} from '@plexis/includes';
21 | export {default as isString} from '@plexis/is-string';
22 | export {default as isUpper, default as isUpperCase} from '@plexis/is-uppercase';
23 | export {default as startsWith} from '@plexis/starts-with';
24 | export {
25 | default as camelCase,
26 | default as camelize,
27 | default as toCamelCase
28 | } from '@plexis/to-camel-case';
29 | export {
30 | default as toCapitals,
31 | default as toFirstCapital,
32 | default as capitalize
33 | } from '@plexis/to-capitals';
34 | export {
35 | default as toChicagoManualStyle,
36 | default as toChicagoStyle,
37 | default as toChicagoTitle,
38 | default as toTurabian
39 | } from '@plexis/to-chicago';
40 | export {default as toSwapCase, default as swapCase} from '@plexis/to-swap-case';
41 | export {default as toChunks} from '@plexis/to-chunks';
42 | export {
43 | default as decapitalize,
44 | default as toFirstLower,
45 | default as toLower
46 | } from '@plexis/to-lower';
47 | export {default as classify, default as toPascalCase} from '@plexis/to-pascal-case';
48 | export {default as pluralize, default as toPlural} from '@plexis/to-plural';
49 | export {default as toPred, default as toPredecessor} from '@plexis/to-pred';
50 | export {default as snakeCase, default as toSnakeCase} from '@plexis/to-snake-case';
51 | export {default as toSucc, default as toSuccessor} from '@plexis/to-succ';
52 | export {default as titleize, default as toTitle} from '@plexis/to-title';
53 | export {default as _when} from '@plexis/when';
54 | export {default as humanize, default as toHuman} from '@plexis/to-human';
55 | export {
56 | default as cleanDiacritics,
57 | default as removeDiacritics,
58 | default as withoutDiacritics
59 | } from '@plexis/without-diacritics';
60 | export {
61 | default as dedent,
62 | default as removeIndent,
63 | default as withoutIndent
64 | } from '@plexis/without-indent';
65 | export {
66 | default as isAlphaNumeric,
67 | default as isAlphanumeric,
68 | default as isAlphaDigit
69 | } from '@plexis/is-alphanumeric';
70 | export {default as withoutHTML, default as removeHTML} from '@plexis/without-html';
71 | export {default as isEmpty} from '@plexis/is-empty';
72 | export {default as tail, default as rest, default as last, default as pop} from '@plexis/tail';
73 | export {default as toSwap, default as swap} from '@plexis/to-swap';
74 | export {default as countWords} from '@plexis/count-words';
75 | export {default as toEllipsis, default as truncate, default as fit} from '@plexis/to-ellipsis';
76 |
--------------------------------------------------------------------------------
/packages/plexis/test/__snapshots__/index.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`allows using all the available utilities 1`] = `
4 | Array [
5 | "__esModule",
6 | "compare",
7 | "compareLikeHuman",
8 | "naturalCompare",
9 | "compose",
10 | "_do",
11 | "count",
12 | "calcLevenshtein",
13 | "distance",
14 | "levenshtein",
15 | "endsWith",
16 | "escapeHTML",
17 | "head",
18 | "first",
19 | "popFirst",
20 | "insert",
21 | "isAlpha",
22 | "isLower",
23 | "isLowerCase",
24 | "isNum",
25 | "isNumeric",
26 | "includes",
27 | "has",
28 | "isString",
29 | "isUpper",
30 | "isUpperCase",
31 | "startsWith",
32 | "camelCase",
33 | "camelize",
34 | "toCamelCase",
35 | "toCapitals",
36 | "toFirstCapital",
37 | "capitalize",
38 | "toChicagoManualStyle",
39 | "toChicagoStyle",
40 | "toChicagoTitle",
41 | "toTurabian",
42 | "toSwapCase",
43 | "swapCase",
44 | "toChunks",
45 | "decapitalize",
46 | "toFirstLower",
47 | "toLower",
48 | "classify",
49 | "toPascalCase",
50 | "pluralize",
51 | "toPlural",
52 | "toPred",
53 | "toPredecessor",
54 | "snakeCase",
55 | "toSnakeCase",
56 | "toSucc",
57 | "toSuccessor",
58 | "titleize",
59 | "toTitle",
60 | "_when",
61 | "humanize",
62 | "toHuman",
63 | "cleanDiacritics",
64 | "removeDiacritics",
65 | "withoutDiacritics",
66 | "dedent",
67 | "removeIndent",
68 | "withoutIndent",
69 | "isAlphaNumeric",
70 | "isAlphanumeric",
71 | "isAlphaDigit",
72 | "withoutHTML",
73 | "removeHTML",
74 | "isEmpty",
75 | "tail",
76 | "rest",
77 | "last",
78 | "pop",
79 | "toSwap",
80 | "swap",
81 | "countWords",
82 | "toEllipsis",
83 | "truncate",
84 | "fit",
85 | ]
86 | `;
87 |
--------------------------------------------------------------------------------
/packages/plexis/test/index.js:
--------------------------------------------------------------------------------
1 | import * as plexis from '../src/index';
2 |
3 | it('allows using all the available utilities', () => {
4 | expect(Object.keys(plexis)).toMatchSnapshot();
5 | });
6 |
--------------------------------------------------------------------------------
/packages/repeat/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/repeat`
2 |
3 | Repeats the input text number of times.
4 |
5 | **Installation**
6 | `npm i @plexis/repeat`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import repeat from '@plexis/repeat';
12 |
13 | repeat('ABCD');
14 | // => true
15 |
16 | repeat('Apollo11', 2);
17 | // => 'Apollo11Apollo11'
18 |
19 | repeat('x', 2);
20 | // => 'xx'
21 |
22 | repeat('x', 2, '+');
23 | // => 'x+x'
24 |
25 | repeat('xx', 2, '_');
26 | // => 'xx_xx'
27 | ```
28 |
29 | **Aliases**
30 |
31 | ```javascript
32 | import repeat from '@plexis/repeat';
33 | import {repeat, multiply} from 'plexis';
34 | ```
35 |
--------------------------------------------------------------------------------
/packages/repeat/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/repeat",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Lazar Vasic "
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "function"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/repeat/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Repeats the input text number of times.
3 | * @param {String} [text] The input text.
4 | * @returns {Integer} times How many times shall we repeat the text, default to 1
5 | * @param {String} glue The glue for the output, default to ''
6 | * @returns {String} The repeated string;
7 | */
8 |
9 | const repeat = (text, times = 1, glue = '') => {
10 | let result = `${text}${glue}`.repeat(times);
11 | if (glue) {
12 | return result.slice(0, result.length - 1);
13 | }
14 | return result;
15 | };
16 |
17 | export default repeat;
18 |
--------------------------------------------------------------------------------
/packages/repeat/test/index.js:
--------------------------------------------------------------------------------
1 | import repeat from '../src';
2 |
3 | it('repeat text with repeat param and default glue', () => {
4 | const result = repeat('ABCD');
5 | expect(result).toBe('ABCD');
6 | });
7 |
8 | it('repeat text with repeat param and default glue', () => {
9 | const result = repeat('Apollo11', 2);
10 | expect(result).toBe('Apollo11Apollo11');
11 | });
12 |
13 | it('repeat text with repeat param and glue', () => {
14 | const result = repeat('x', 2, '+');
15 | expect(result).toBe('x+x');
16 | });
17 |
18 | it('repeat text with repeat param and glue', () => {
19 | const result = repeat('xx', 2, '_');
20 | expect(result).toBe('xx_xx');
21 | });
22 |
--------------------------------------------------------------------------------
/packages/startsWith/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/startsWith`
2 |
3 | Checks whether the input text starts with the given pattern.
4 |
5 | `npm i @plexis/starts-with`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import startsWith from '@plexis/starts-with';
11 |
12 | startsWith('This is me', 'This is'); // returns true
13 | startsWith('This is me', 'This is', 1); // returns false
14 | startsWith(/[@!#$]/, '@plexis is great!'); // returns true
15 | startsWith(/[A-Z]/, '@plexis is great!'); // returns false
16 | ```
17 |
--------------------------------------------------------------------------------
/packages/startsWith/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/starts-with",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "author": "Brandon Skinner ",
12 | "license": "MIT",
13 | "keywords": [
14 | "utility",
15 | "string",
16 | "parse",
17 | "format",
18 | "validate"
19 | ],
20 | "repository": {
21 | "type": "git",
22 | "url": "git+https://github.com/plexis-js/plexis.git"
23 | },
24 | "publishConfig": {
25 | "access": "public"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/startsWith/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Checks whether the input text starts with the given pattern.
3 | * @param {String} text
4 | * @param {String|Regex} pattern
5 | * @param {Number} startingPosition, optional
6 | * @example
7 | * startsWith('This is me', 'This is'); // returns true
8 | * startsWith('This is me', 'This is', 1); // returns false
9 | * startsWith(/[@!#$]/, '@plexis is great!'); // returns true
10 | */
11 | const startsWith = (text, pattern, startingPosition) => {
12 | try {
13 | if (typeof pattern === 'object') {
14 | return text.slice(startingPosition).search(new RegExp(pattern)) === 0 ? true : false;
15 | }
16 | } catch (e) {}
17 |
18 | return text.slice(startingPosition).indexOf(pattern) === 0 ? true : false;
19 | };
20 |
21 | export default startsWith;
22 |
--------------------------------------------------------------------------------
/packages/startsWith/test/index.js:
--------------------------------------------------------------------------------
1 | import startsWith from '../src';
2 |
3 | it('Matches single characters', () => {
4 | expect(startsWith('Hello', 'H')).toBe(true);
5 | });
6 |
7 | it("Doesn't match single characters not at front of string", () => {
8 | expect(startsWith('Hello', 'l')).toBe(false);
9 | });
10 |
11 | it('Matches single characters with startingPosition set at character index', () => {
12 | expect(startsWith('Help', 'l', 2)).toBe(true);
13 | });
14 |
15 | it('Matches single word strings', () => {
16 | expect(startsWith('Hello there champ!', 'Hello')).toBe(true);
17 | });
18 |
19 | it("Doesn't match single word strings not at front of string", () => {
20 | expect(startsWith('Hello there champ!', 'there')).toBe(false);
21 | });
22 |
23 | it('Matches single word strings with startingPosition set at word index', () => {
24 | expect(startsWith('Hello there champ!', 'there', 6)).toBe(true);
25 | });
26 |
27 | it('Matches single character regex', () => {
28 | expect(startsWith('@plexis is great!', /[@]/)).toBe(true);
29 | });
30 |
31 | it("Doesn't match single character regex not at front of string", () => {
32 | expect(startsWith('@plexis is great!', /[!]/)).toBe(false);
33 | });
34 |
35 | it('Matches single word string', () => {
36 | expect(startsWith('@plexis is great!', /is/, 8)).toBe(true);
37 | });
38 |
39 | it('Matches complex regex(HTML tag)', () => {
40 | expect(startsWith('Table Cell | ', /<([\w]+).*>(.*?)<\/\1>/)).toBe(true);
41 | });
42 |
--------------------------------------------------------------------------------
/packages/tail/README.md:
--------------------------------------------------------------------------------
1 | ## `head`
2 |
3 | Extracts the last length characters from the input text
4 |
5 | `npm i @plexis/tail`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import tail from '@plexis/tail';
11 | tail(); // => ''
12 | tail('Hello'); // => 'o'
13 | tail('Hello', 2); // => 'lo'
14 | tail('Hello', 100); // => 'Hello'
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import {tail} from 'plexis';
21 | import {rest} from 'plexis';
22 | import {last} from 'plexis';
23 | import {pop} from 'plexis';
24 | ```
25 |
--------------------------------------------------------------------------------
/packages/tail/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/tail",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/tail/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Extracts the last length characters from the input text
3 | * @param {String} text
4 | * @param {Number} endingPosition, optional
5 | * @example
6 | * tail(); // returns ''
7 | * tail('Hello'); // returns 'o'
8 | * tail('Hello', 2); // returns 'lo'
9 | * tail('Hello', 100); // returns 'Hello'
10 | */
11 |
12 | const tail = (text, endingPosition = 1) =>
13 | text ? text.substring(text.length - endingPosition) : '';
14 |
15 | export default tail;
16 |
--------------------------------------------------------------------------------
/packages/tail/test/index.js:
--------------------------------------------------------------------------------
1 | import tail from '../src';
2 |
3 | it('Extracts the last length characters from the input text', () => {
4 | expect(tail()).toBe('');
5 | expect(tail('Hello')).toBe('o');
6 | expect(tail('Hello', 2)).toBe('lo');
7 | expect(tail('Hello', 100)).toBe('Hello');
8 | });
9 |
--------------------------------------------------------------------------------
/packages/toCamelCase/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/toCamelCase`
2 |
3 | Converts the input text to camelCase.
4 |
5 | **Installation**
6 | `npm i @plexis/to-camel-case`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toCamelCase from '@plexis/to-camel-case';
12 |
13 | toCamelCase('Cool'); //=> 'cool'
14 | toCamelCase('cool mate'); // => 'coolMate'
15 | toCamelCase('Hey how are you today?'); // => 'heyHowAreYouToday'
16 | toCamelCase('PascalCase'); // => 'pascalCase'
17 | toCamelCase('kebab-case'); // => kebabCase
18 | ```
19 |
20 | **Aliases**
21 |
22 | ```javascript
23 | import {toCamelCase} from 'plexis';
24 | import {camelCase} from 'plexis';
25 | import {camelize} from 'plexis';
26 | ```
27 |
--------------------------------------------------------------------------------
/packages/toCamelCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-camel-case",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toCamelCase/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to camel case
3 | * @param {String} text
4 | * @returns {String} camel case text
5 | * @example
6 | * toCamelCase('Cool'); //=> 'cool'
7 | * toCamelCase('cool mate'); // => 'coolMate'
8 | * toCamelCase('Hey how are you today?'); // => 'heyHowAreYouToday'
9 | * toCamelCase('PascalCase'); // => 'pascalCase'
10 | * toCamelCase('kebab-case'); // => kebabCase
11 | */
12 |
13 | const toCamelCase = string => {
14 | const lowerUpper = (letter, index) => {
15 | return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
16 | };
17 | const wordPatt = /^\w|[A-Z]|\b\w/g;
18 | const symbolPatt = /[^a-zA-Z0-9]/g;
19 | let result = string
20 | .trim()
21 | .replace(wordPatt, lowerUpper)
22 | .replace(symbolPatt, '');
23 | return result;
24 | };
25 |
26 | export default toCamelCase;
27 |
--------------------------------------------------------------------------------
/packages/toCamelCase/test/index.js:
--------------------------------------------------------------------------------
1 | import toCamelCase from '../src';
2 |
3 | it('converts a given string to camel case', () => {
4 | expect(toCamelCase('Cool')).toBe('cool');
5 | expect(toCamelCase('cool mate')).toBe('coolMate');
6 | expect(toCamelCase('Hey how are you today?')).toBe('heyHowAreYouToday');
7 | expect(toCamelCase('PascalCase')).toBe('pascalCase');
8 | expect(toCamelCase('kebab-case')).toBe('kebabCase');
9 | expect(toCamelCase('')).toBe('');
10 | expect(toCamelCase(' ')).toBe('');
11 | expect(toCamelCase(' kebab-case PascalCase @hello! ')).toBe('kebabCasePascalCaseHello');
12 | });
13 |
--------------------------------------------------------------------------------
/packages/toCapitals/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/to-capitals`
2 |
3 | Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case.
4 |
5 | `npm i @plexis/to-capitals`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import toCapitals from '@plexis/to-capitals';
11 |
12 | toCapitals('foo Bar'); // returns 'Foo Bar'
13 | toCapitals('fOO Bar'); // returns 'FOO Bar'
14 | toCapitals('fOO Bar', true); // returns 'Foo bar'
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import toCapitals from '@plexis/to-capitals';
21 | import {toCapitals, toFirstCapital, capitalize} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/toCapitals/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-capitals",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "description": "Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case",
8 | "keywords": [
9 | "utility",
10 | "string"
11 | ],
12 | "author": "Angel Gonzalez ",
13 | "homepage": "https://github.com/plexis-js/plexis#readme",
14 | "license": "MIT",
15 | "files": [
16 | "lib"
17 | ],
18 | "publishConfig": {
19 | "access": "public"
20 | },
21 | "repository": {
22 | "type": "git",
23 | "url": "git+https://github.com/plexis-js/plexis.git"
24 | },
25 | "bugs": {
26 | "url": "https://github.com/plexis-js/plexis/issues"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/packages/toCapitals/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts the first character of the input text to upper case. If the second parameter is true, the method converts the rest of the subject to lower case.
3 | * @param {String} text
4 | * @param {Boolean} isLowercase
5 | * @example
6 | * toPred('foo Bar') // returns 'Foo Bar'
7 | * toPred('fOO Bar') // returns 'FOO Bar'
8 | * toPred('fOO Bar', true) // returns 'Foo bar'
9 | */
10 | const toCapitals = (text = '', isLowercase = false) => {
11 | let firstCharacter = text.charAt(0).toUpperCase();
12 | let restOfString = isLowercase ? text.slice(1).toLowerCase() : text.slice(1);
13 |
14 | return firstCharacter + restOfString;
15 | };
16 |
17 | export default toCapitals;
18 |
--------------------------------------------------------------------------------
/packages/toCapitals/test/index.js:
--------------------------------------------------------------------------------
1 | import toCapitals from '../src';
2 |
3 | describe('@plexis/to-capitals', () => {
4 | it('no params, should be empty string', () => {
5 | expect(toCapitals()).toBe('');
6 | });
7 |
8 | it('empty string,, should be empty strin', () => {
9 | expect(toCapitals('')).toBe('');
10 | });
11 |
12 | it('should capitalize only first letter, the rest of the string must be intact', () => {
13 | expect(toCapitals('foO bar')).toBe('FoO bar');
14 | });
15 |
16 | it('should capitalize only first letter, the rest of the string must be intact', () => {
17 | expect(toCapitals('foO bAr')).toBe('FoO bAr');
18 | });
19 |
20 | it('should capitalize the first letter, the rest of the subject to lower case.', () => {
21 | expect(toCapitals('FOO BAR', true)).toBe('Foo bar');
22 | });
23 | });
24 |
--------------------------------------------------------------------------------
/packages/toChicago/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/to-chicago`
2 |
3 | Convert text into Chicago style
4 |
5 | `npm i @plexis/to-chicago`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import toChicago from '@plexis/to-chicago';
11 |
12 | toChicago('This is a title'); // returns 'This Is a Title'
13 | toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.'
14 | toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case'
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import toChicago from '@plexis/to-chicago';
21 | import {toTurabian, toChicagoManualStyle, toChicagoStyle, toChicagoTitle} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/toChicago/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-chicago",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "authors": [
8 | "Nguyễn Tuấn Dũng "
9 | ],
10 | "files": [
11 | "dist",
12 | "src"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format"
20 | ],
21 | "repository": {
22 | "type": "git",
23 | "url": "git+https://github.com/plexis-js/plexis.git"
24 | },
25 | "publishConfig": {
26 | "access": "public"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/packages/toChicago/src/index.js:
--------------------------------------------------------------------------------
1 | const formatWord = word =>
2 | word
3 | .split('-')
4 | .map(s => s.charAt(0).toUpperCase() + s.toLowerCase().substring(1))
5 | .join('-');
6 |
7 | // Prepositions list
8 | const wordException = [
9 | 'a',
10 | 'an',
11 | 'the',
12 | 'and',
13 | 'or',
14 | 'aboard',
15 | 'about',
16 | 'above',
17 | 'across',
18 | 'after',
19 | 'against',
20 | 'along',
21 | 'amid',
22 | 'among',
23 | 'around',
24 | 'as',
25 | 'at',
26 | 'before',
27 | 'behind',
28 | 'below',
29 | 'beneath',
30 | 'beside',
31 | 'between',
32 | 'beyond',
33 | 'but',
34 | 'by',
35 | 'concerning',
36 | 'considering',
37 | 'despite',
38 | 'down',
39 | 'during',
40 | 'except',
41 | 'following',
42 | 'for',
43 | 'from',
44 | 'in',
45 | 'inside',
46 | 'into',
47 | 'like',
48 | 'minus',
49 | 'near',
50 | 'next',
51 | 'of',
52 | 'off',
53 | 'on',
54 | 'onto',
55 | 'opposite',
56 | 'out',
57 | 'outside',
58 | 'over',
59 | 'past',
60 | 'per',
61 | 'plus',
62 | 'regarding',
63 | 'round',
64 | 'save',
65 | 'since',
66 | 'than',
67 | 'through',
68 | 'to',
69 | 'toward',
70 | 'under',
71 | 'underneath',
72 | 'unlike',
73 | 'until',
74 | 'up',
75 | 'upon',
76 | 'versus',
77 | 'via',
78 | 'with',
79 | 'within',
80 | 'without'
81 | ];
82 |
83 | const formatSentence = sentence =>
84 | sentence
85 | .trim()
86 | .split(/\s+/)
87 | .map((word, index) =>
88 | index > 0 && wordException.includes(word.toLowerCase())
89 | ? word.toLowerCase()
90 | : formatWord(word)
91 | )
92 | .join(' ');
93 |
94 | /**
95 | * @description Convert text into Chicago style
96 | * @param {String} text The text to transform
97 | * @returns {String} Returns text transformed according to the The Chicago Manual of Style.
98 | * @example
99 | * toChicago('This is a title'); // returns 'This Is a Title'
100 | * toChicago('in Turabian shows a sample title page for a class paper.'); // returns 'In Turabian Shows a Sample Title Page for a Class Paper.'
101 | * toChicago('camelCase PascalCase snake_case and kebab-case'); // returns 'Camelcase Pascalcase Snake_case and Kebab-Case'
102 |
103 | */
104 | const toChicago = text =>
105 | text
106 | .replace(/\s+/, ' ')
107 | .replace(/\s+([.?!,:;])\s*/, '$1 ')
108 | .concat('.')
109 | .match(/(.*?)([.?!])/g)
110 | .map(sentence => sentence.match(/(.*?)([.?!])/))
111 | .map(x => formatSentence(x[1]) + x[2])
112 | .join(' ')
113 | .slice(0, -1)
114 | .trimRight();
115 |
116 | export default toChicago;
117 |
--------------------------------------------------------------------------------
/packages/toChicago/test/index.js:
--------------------------------------------------------------------------------
1 | import toChicago from '../src';
2 |
3 | it('transform normal string', () => {
4 | expect(toChicago('This is a title')).toBe('This Is a Title');
5 | });
6 |
7 | it('transform mixed sentence', () => {
8 | expect(toChicago('in Turabian shows a sample title page for a class paper.')).toBe(
9 | 'In Turabian Shows a Sample Title Page for a Class Paper.'
10 | );
11 | });
12 |
13 | it('transform edge case', () => {
14 | expect(toChicago('camelCase PascalCase snake_case and kebab-case')).toBe(
15 | 'Camelcase Pascalcase Snake_case and Kebab-Case'
16 | );
17 | });
18 |
--------------------------------------------------------------------------------
/packages/toChunks/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/to-chunks`
2 |
3 | Splits the input text into an array of chunks.
4 |
5 | **Installation**
6 | `npm i @plexis/to-chunks`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toChunks from '@plexis/to-chunks';
12 |
13 | toChunks('Hello world');
14 | // => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
15 |
16 | toChunks(' ');
17 | // => [' ', ' ', ' ']
18 |
19 | toChunks('1234567', 2);
20 | // => ['12', '34', '56', '7']
21 |
22 | toChunks('1234567', 6);
23 | // => ['123456', '7']
24 | ```
25 |
26 | **Aliases**
27 |
28 | ```javascript
29 | import toChunks from '@plexis/to-chunks';
30 | import {toChunks, chop} from 'plexis';
31 | ```
32 |
--------------------------------------------------------------------------------
/packages/toChunks/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-chunks",
3 | "version": "0.0.22",
4 | "description": "Splits the input text into an array of chunks.",
5 | "main": "dist/index.js",
6 | "module": "dist/index.esm.js",
7 | "jsnext:main": "./src/index.js",
8 | "files": [
9 | "dist",
10 | "src"
11 | ],
12 | "author": "korczynsk1",
13 | "license": "MIT",
14 | "keywords": [
15 | "chunks",
16 | "string"
17 | ],
18 | "repository": {
19 | "type": "git",
20 | "url": "git+https://github.com/plexis-js/plexis.git"
21 | },
22 | "publishConfig": {
23 | "access": "public"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/packages/toChunks/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to its equivalent predecessor
3 | * @param {String} text The input String
4 | * @param {Integer} chunkSize The size of each chunk, default to 1
5 | * @example
6 | * toChunks('Hello world'); // => ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
7 | * toChunks(' '); // => [' ', ' ', ' ']
8 | * toChunks('1234567', 2); // => ['12', '34', '56', '7']
9 | * toChunks('1234567', 6) // => ['123456', '7']
10 | */
11 | const toChunks = (text, chunkSize = 1) => text.match(new RegExp(`.{1,${chunkSize}}`, 'g'));
12 |
13 | export default toChunks;
14 |
--------------------------------------------------------------------------------
/packages/toChunks/test/index.js:
--------------------------------------------------------------------------------
1 | import toChunks from '../src';
2 |
3 | it('create chunks with default chunksize', () => {
4 | expect(toChunks('Hello world')).toStrictEqual([
5 | 'H',
6 | 'e',
7 | 'l',
8 | 'l',
9 | 'o',
10 | ' ',
11 | 'w',
12 | 'o',
13 | 'r',
14 | 'l',
15 | 'd'
16 | ]);
17 | });
18 |
19 | it('create chunks of empty strings', () => {
20 | expect(toChunks(' ')).toStrictEqual([' ', ' ', ' ']);
21 | });
22 |
23 | it('create chunks for chunk size equal 2', () => {
24 | expect(toChunks('1234567', 2)).toStrictEqual(['12', '34', '56', '7']);
25 | });
26 |
27 | it('create chunks for chunk size equal 6', () => {
28 | expect(toChunks('1234567', 6)).toStrictEqual(['123456', '7']);
29 | });
30 |
--------------------------------------------------------------------------------
/packages/toEllipsis/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/to-ellipsis`
2 |
3 | Truncates the input text to the desired length.
4 |
5 | **Installation**
6 | `npm i @plexis/to-ellipsis`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toEllipsis from '@plexis/to-ellipsis';
12 |
13 | toEllipsis('foo'); // retruns 'foo'
14 | toEllipsis('foo', 1); // retruns 'f..'
15 | toEllipsis('foo', 3); // retruns 'foo'
16 | toEllipsis('Last night I dreamt I went to Manderley again.', 5); // retruns 'Last ...'
17 | ```
18 |
19 | ## Aliases
20 |
21 | ```javascript
22 | import toEllipsis from '@plexis/to-ellipsis';
23 | import {toEllipsis, truncate, fit} from 'plexis';
24 | ```
25 |
--------------------------------------------------------------------------------
/packages/toEllipsis/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-ellipsis",
3 | "version": "0.0.22",
4 | "description": "Truncates the input text to the desired length.",
5 | "keywords": [
6 | "utility",
7 | "string",
8 | "truncate"
9 | ],
10 | "author": "protob ",
11 | "homepage": "https://github.com/plexis-js/plexis.git",
12 | "license": "MIT",
13 | "main": "dist/index.js",
14 | "module": "dist/index.esm.js",
15 | "jsnext:main": "./src/index.js",
16 | "files": [
17 | "dist",
18 | "src"
19 | ],
20 | "publishConfig": {
21 | "access": "public"
22 | },
23 | "repository": {
24 | "type": "git",
25 | "url": "git+https://github.com/plexis-js/plexis.git"
26 | },
27 | "bugs": {
28 | "url": "https://github.com/plexis-js/plexis/issues"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packages/toEllipsis/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Truncates the input text to the desired length.
3 | * @param {String} string
4 | * @param {Number} limit
5 | * @example
6 | * toEllipsis('foo'); //=> 'foo'
7 | * toEllipsis('foo', 1); // => 'f..'
8 | * toEllipsis('foo', 3); // => 'foo'
9 | * toEllipsis('Last night I dreamt I went to Manderley again.', 5); // => 'Last ...'
10 | */
11 |
12 | const toEllipsis = (string, limit) => {
13 | if (isNaN(limit)) return string;
14 | const suffix = string.length <= limit ? '' : '...';
15 | return string.substring(0, limit) + suffix;
16 | };
17 |
18 | export default toEllipsis;
19 |
--------------------------------------------------------------------------------
/packages/toEllipsis/test/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | import toEllipsis from '../src';
4 |
5 | describe('@plexis/toEllipsis', () => {
6 | it('should retrun ...', () => {
7 | expect(toEllipsis('foo', 0)).toBe('...');
8 | });
9 | it('should retrun foo', () => {
10 | expect(toEllipsis('foo')).toBe('foo');
11 | });
12 | it('should retrun foo', () => {
13 | expect(toEllipsis('foo', Infinity)).toBe('foo');
14 | });
15 | it('should retrun foo', () => {
16 | expect(toEllipsis('foo', 3)).toBe('foo');
17 | });
18 | it('should retrun Last ...', () => {
19 | expect(toEllipsis('Last night I dreamt I went to Manderley again.', 5)).toBe('Last ...');
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/packages/toHuman/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/to-human`
2 |
3 | Converts a string into a human readable text
4 |
5 | ## Installation
6 |
7 | `npm i @plexis/to-human`
8 |
9 | ## Usage
10 |
11 | ```javascript
12 | import toHuman from '@plexis/to-human';
13 |
14 | toHuman('foo'); // => 'Foo'
15 | toHuman('foo bar'); // => 'Foo bar'
16 | toHuman(' foo-bar baz quxQuux corge_grault GarplyWaldo'); // => 'Foo bar baz qux quux corge grault garply waldo'
17 | toHuman(' foo-bar-baz qux quux'); // => 'Foo bar baz qux quux'
18 | ```
19 |
20 | ## Aliases
21 |
22 | ```javascript
23 | import toHuman from '@plexis/to-human';
24 | import {toHuman, humanize} from 'plexis';
25 | ```
26 |
--------------------------------------------------------------------------------
/packages/toHuman/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-human",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "description": "Converts a string into a human readable text",
8 | "keywords": [
9 | "utility",
10 | "string",
11 | "parse",
12 | "format",
13 | "validate"
14 | ],
15 | "author": "Angel Gonzalez ",
16 | "homepage": "https://github.com/plexis-js/plexis#readme",
17 | "license": "MIT",
18 | "files": [
19 | "lib"
20 | ],
21 | "publishConfig": {
22 | "access": "public"
23 | },
24 | "repository": {
25 | "type": "git",
26 | "url": "git+https://github.com/plexis-js/plexis.git"
27 | },
28 | "bugs": {
29 | "url": "https://github.com/plexis-js/plexis/issues"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/packages/toHuman/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string into a human readable text
3 | * @param {String} text
4 | * @example
5 | * toHuman('foo') // returns 'Foo'
6 | * toHuman('foo bar') // returns 'Foo bar'
7 | * toHuman(' foo-bar-baz qux quux') // returns 'Foo bar baz qux quux'
8 | */
9 | const toHuman = text =>
10 | text
11 | .trim()
12 | .replace(/_|-/g, ' ')
13 | .trim()
14 | .replace(/([A-Z])/g, word => ' ' + word.toLowerCase())
15 | .trim()
16 | .replace(/^[a-z]/g, first => first.toUpperCase())
17 | .replace(/\s\s+/g, ' ')
18 | .trim();
19 |
20 | export default toHuman;
21 |
--------------------------------------------------------------------------------
/packages/toHuman/test/index.js:
--------------------------------------------------------------------------------
1 | import toHuman from '../src';
2 |
3 | describe('@plexis/to-human', () => {
4 | it('Converts a string into a human readable text', () => {
5 | expect(toHuman('foo')).toBe('Foo');
6 | expect(toHuman('foo bar')).toBe('Foo bar');
7 | expect(toHuman(' foo-bar baz quxQuux corge_grault GarplyWaldo')).toBe(
8 | 'Foo bar baz qux quux corge grault garply waldo'
9 | );
10 | expect(toHuman(' foo-bar-baz qux quux')).toBe('Foo bar baz qux quux');
11 | expect(toHuman('fooBar qux-core - _ ')).toBe('Foo bar qux core');
12 | expect(toHuman('foo_')).toBe('Foo');
13 | expect(toHuman('foo-')).toBe('Foo');
14 | expect(toHuman('_foo')).toBe('Foo');
15 | expect(toHuman('Foo bar')).toBe('Foo bar');
16 | expect(toHuman('Foo')).toBe('Foo');
17 | expect(toHuman(' foo ')).toBe('Foo');
18 | expect(toHuman(' Foo ')).toBe('Foo');
19 | expect(toHuman('-Foo ')).toBe('Foo');
20 | expect(toHuman('Foo Bar foo')).toBe('Foo bar foo');
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/packages/toLower/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/toLower`
2 |
3 | Lowercase the first letter of the given string.
4 |
5 | **Installation**
6 | `npm i @plexis/to-lower`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toLower from '@plexis/to-lower';
12 |
13 | toLower('Foo Bar', false); // returns 'foo Bar'
14 | toLower('Foo Bar', true); // returns 'foo bar'
15 | toLower('FOO BAR', false); // returns 'fOO BAR'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {toLower} from 'plexis';
22 | import {toFirstLower} from 'plexis';
23 | import {decapitalize} from 'plexis';
24 | ```
25 |
--------------------------------------------------------------------------------
/packages/toLower/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-lower",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "4doge https://github.com/4doge"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toLower/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Lowercase the first letter of the given string.
3 | * @param {String} text
4 | * @param {Boolean} isLowecase
5 | * @example
6 | * toLower('Foo Bar', false) // returns 'foo Bar'
7 | * toLower('Foo Bar', true) // returns 'foo bar'
8 | */
9 | const toLower = (text, isLower) => {
10 | const s = isLower ? text.slice(1).toLowerCase() : text.slice(1);
11 | return text.charAt(0).toLowerCase() + s;
12 | };
13 |
14 | export default toLower;
15 |
--------------------------------------------------------------------------------
/packages/toLower/test/index.js:
--------------------------------------------------------------------------------
1 | import toLower from '../src';
2 |
3 | it('lowercase only the first letter in single word', () => {
4 | expect(toLower('HeLLo', false)).toBe('heLLo');
5 | });
6 |
7 | it('lowercase only the first letter in multiword sentense', () => {
8 | expect(toLower('HeLLo WorLD', false)).toBe('heLLo WorLD');
9 | });
10 |
11 | it('lowercase all single word letters', () => {
12 | expect(toLower('HeLLo', true)).toBe('hello');
13 | });
14 |
15 | it('lowercase all multiword sentense letters', () => {
16 | expect(toLower('HeLLo WorLD', true)).toBe('hello world');
17 | });
18 |
--------------------------------------------------------------------------------
/packages/toPascalCase/README.md:
--------------------------------------------------------------------------------
1 | ## `toPascalCase`
2 |
3 | Converts the input text to pascal case
4 |
5 | `npm i @plexis/name-of-the-module`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import toPascalCase from '@plexis/to-pascal-case';
11 |
12 | toPascalCase('Cool');
13 | // => 'Cool'
14 |
15 | toPascalCase('cool mate');
16 | // => 'CoolMate'
17 |
18 | toPascalCase('Hey how are you today?');
19 | // => 'HeyHowAreYouToday'
20 |
21 | toPascalCase('camelCase');
22 | // => 'CamelCase'
23 |
24 | toPascalCase('kebab-case');
25 | // => KebabCase
26 | ```
27 |
28 | **Aliases**
29 |
30 | ```javascript
31 | import toPascalCase from '@plexis/to-pascal-case';
32 | import {toPascalCase, classify} from 'plexis';
33 | ```
34 |
--------------------------------------------------------------------------------
/packages/toPascalCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-pascal-case",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Jack Chapman "
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toPascalCase/src/index.js:
--------------------------------------------------------------------------------
1 | // to be replaced with @plexis/toCamelCase
2 | const toCamelCase = text => {
3 | const lowerUpper = (letter, index) => {
4 | return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
5 | };
6 | const wordPatt = /^\w|[A-Z]|\b\w/g;
7 | const symbolPatt = /[^a-zA-Z0-9]/g;
8 | return text
9 | .trim()
10 | .replace(wordPatt, lowerUpper)
11 | .replace(symbolPatt, '');
12 | };
13 |
14 | /**
15 | * @description Convert a word to pascal case
16 | * @param {String} text
17 | * @example
18 | * toPascalCase('foo') // returns 'Foo'
19 | * toPred('foo bar') // returns 'FooBar'
20 | * toPred('FOO BAR BAZ') // returns 'FooBarBaz'
21 | */
22 | const toPascalCase = text => {
23 | const result = toCamelCase(text);
24 | return result.charAt(0).toUpperCase() + result.substr(1);
25 | };
26 |
27 | export default toPascalCase;
28 |
--------------------------------------------------------------------------------
/packages/toPascalCase/test/index.js:
--------------------------------------------------------------------------------
1 | import toPascalCase from '../src';
2 |
3 | it('Works with single characters', () => {
4 | expect(toPascalCase('h')).toBe('H');
5 | });
6 |
7 | it('Works will full words', () => {
8 | expect(toPascalCase('hello')).toBe('Hello');
9 | });
10 |
11 | it('Works with strange cases on a single word', () => {
12 | expect(toPascalCase('hEllO')).toBe('HEllO');
13 | });
14 |
15 | it('Works with multiple words', () => {
16 | expect(toPascalCase('Hello there')).toBe('HelloThere');
17 | });
18 |
19 | it('Removes symbols', () => {
20 | expect(toPascalCase('@@@hello@@@')).toBe('Hello');
21 | });
22 |
23 | it('Works with long strings', () => {
24 | expect(toPascalCase('This is a long string compared to the other tests')).toBe(
25 | 'ThisIsALongStringComparedToTheOtherTests'
26 | );
27 | });
28 |
29 | it('Converts camelCase properly', () => {
30 | expect(toPascalCase('camelCase')).toBe('CamelCase');
31 | });
32 |
33 | it('Converts kebab-case properly', () => {
34 | expect(toPascalCase('kebab-case')).toBe('KebabCase');
35 | });
36 |
--------------------------------------------------------------------------------
/packages/toPlural/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/to-plural`
2 |
3 | Converts a word to its plural form
4 |
5 | ## Installation
6 |
7 | `npm i @plexis/to-plural`
8 |
9 | ## Usage
10 |
11 | ```javascript
12 | import toPlural from '@plexis/to-plural';
13 |
14 | toPlural('example'); // => 'examples'
15 | toPlural('example', 10); // => 'examples'
16 | toPlural('example', 1); // => 'example'
17 | toPlural('example', 'examplez', 10); // => 'examplez'
18 | toPlural('example', 'examplez', 1); // => 'example'
19 | ```
20 |
21 | ## Aliases
22 |
23 | ```javascript
24 | import toPlural from '@plexis/to-plural';
25 | import {toPlural, pluralize} from 'plexis';
26 | ```
27 |
--------------------------------------------------------------------------------
/packages/toPlural/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-plural",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "description": "Converts a word to its plural form",
8 | "keywords": [
9 | "utility",
10 | "string",
11 | "parse",
12 | "format",
13 | "validate"
14 | ],
15 | "author": "shilangyu ",
16 | "homepage": "https://github.com/plexis-js/plexis#readme",
17 | "license": "MIT",
18 | "files": [
19 | "lib"
20 | ],
21 | "publishConfig": {
22 | "access": "public"
23 | },
24 | "repository": {
25 | "type": "git",
26 | "url": "git+https://github.com/plexis-js/plexis.git"
27 | },
28 | "bugs": {
29 | "url": "https://github.com/plexis-js/plexis/issues"
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/packages/toPlural/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a word to its plural form
3 | * @param {String} word
4 | * @param {String} pluralForm
5 | * @param {Number} count
6 | * @returns {String} pluralized word
7 | * @example
8 | * toPlural('example'); // => 'examples'
9 | * toPlural('example', 10); // => 'examples'
10 | * toPlural('example', 1); // => 'example'
11 | * toPlural('example', 'examplez', 10); // => 'examplez'
12 | * toPlural('example', 'examplez', 1); // => 'example'
13 | */
14 |
15 | const toPlural = (word, ...rest) => {
16 | if (rest.length === 1 && typeof rest[0] === 'string') return word;
17 |
18 | const isPlural = rest.length === 0 || Math.abs(rest[rest.length - 1]) !== 1;
19 | const pluralForm = rest.length === 2 ? rest[0] : `${word}s`;
20 |
21 | return isPlural ? pluralForm : word;
22 | };
23 |
24 | export default toPlural;
25 |
--------------------------------------------------------------------------------
/packages/toPlural/test/index.js:
--------------------------------------------------------------------------------
1 | import toPlural from '../src';
2 |
3 | describe('@plexis/to-plural', () => {
4 | it('converts a given string to its plural form', () => {
5 | expect(toPlural('example')).toBe('examples');
6 | expect(toPlural('example', 10)).toBe('examples');
7 | expect(toPlural('example', 1)).toBe('example');
8 | expect(toPlural('example', 0)).toBe('examples');
9 | expect(toPlural('example', -1)).toBe('example');
10 | expect(toPlural('example', 'examplez', 10)).toBe('examplez');
11 | expect(toPlural('example', 'examplez', 0)).toBe('examplez');
12 | expect(toPlural('example', 'examplez', 1)).toBe('example');
13 | expect(toPlural('example', 'examplez', -1)).toBe('example');
14 | expect(toPlural('example', 'examplez')).toBe('example');
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/toPred/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/toPred`
2 |
3 | Converts a string to its equivalent predecessor.
4 |
5 | **Installation**
6 | `npm i @plexis/to-pred`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toPred from '@plexis/to-pred';
12 |
13 | toPred('b'); // returns 'a'
14 | toPred('B'); // returns 'A'
15 | toPred('BCD'); // returns 'ABC'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {toPred} from 'plexis';
22 | import {toPredecessor} from 'plexis';
23 | ```
24 |
--------------------------------------------------------------------------------
/packages/toPred/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-pred",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toPred/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to its equivalent predecessor
3 | * @param {String} text
4 | * @example
5 | * toPred('b') // returns 'a'
6 | * toPred('B') // returns 'A'
7 | * toPred('BCD') // returns 'ABC'
8 | */
9 | const toPred = text =>
10 | text
11 | .split('')
12 | .map(s => String.fromCharCode(s.charCodeAt(0) - 1))
13 | .join('');
14 |
15 | export default toPred;
16 |
--------------------------------------------------------------------------------
/packages/toPred/test/index.js:
--------------------------------------------------------------------------------
1 | import toPred from '../src';
2 |
3 | it('converts a single char to its predecessor', () => {
4 | expect(toPred('b')).toBe('a');
5 | expect(toPred('B')).toBe('A');
6 | });
7 |
8 | it('converts a sentence to its predecessor', () => {
9 | expect(toPred('LoremIpsum')).toBe('KnqdlHortl');
10 | });
11 |
12 | it('converts a sentence its predecessor for other languages as well', () => {
13 | expect(toPred('κείμενο')).toBe('ιδήλδμξ');
14 | expect(toPred('публикация')).toBe('отакзйЯхзю');
15 | expect(toPred('台匿名的打印机刻意打乱了')).toBe('可匾同皃扒卯朹刺愎扒买亅');
16 | });
17 |
--------------------------------------------------------------------------------
/packages/toSnakeCase/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/toSnakeCase`
2 |
3 | Converts the input text to camelCase.
4 |
5 | **Installation**
6 | `npm i @plexis/to-snake-case`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toSnakeCase from '@plexis/to-snake-case';
12 |
13 | toSnakeCase('Cool'); // => 'cool'
14 | toSnakeCase('cool mate'); // => 'cool_mate'
15 | toSnakeCase('Hey how are you today?'); // => 'hey_how_are_you_today'
16 | toSnakeCase('PascalCase'); // => 'pascal_case'
17 | toSnakeCase('kebab-case'); // => kebab_case
18 | ```
19 |
20 | **Aliases**
21 |
22 | ```javascript
23 | import {toSnakeCase} from 'plexis';
24 | import {snakeCase} from 'plexis';
25 | ```
26 |
--------------------------------------------------------------------------------
/packages/toSnakeCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-snake-case",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Gopi Krishna (https://bgopikrishna.me)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toSnakeCase/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to snake case
3 | * @param {String} text
4 | * @returns {String} snake case text
5 | * @example
6 | * toSnakeCase('Cool') => 'cool'
7 | * toSnakeCase('cool mate') => 'cool_mate'
8 | * toSnakeCase('Hey how are you today?') => 'hey_how_are_you_today'
9 | * toSnakeCase('PascalCase') => 'pascal_case'
10 | * toSnakeCase('kebab-case') => 'kebab_case'
11 | */
12 |
13 | const toSnakeCase = string => {
14 | const removeSym = (letter, index, string) => {
15 | return string.length - 1 === index ? '' : '_';
16 | };
17 | const pascalAndCamelParser = l => {
18 | return (l[0] + '_' + l[1]).toLowerCase();
19 | };
20 |
21 | const wordPatt = /[\w]([A-Z])/g;
22 | const symbolPatt = /[^a-zA-Z0-9]/g;
23 | let result = string
24 | .trim()
25 | .replace(wordPatt, pascalAndCamelParser)
26 | .replace(symbolPatt, removeSym)
27 | .toLowerCase();
28 |
29 | return result;
30 | };
31 |
32 | export default toSnakeCase;
33 |
--------------------------------------------------------------------------------
/packages/toSnakeCase/test/index.js:
--------------------------------------------------------------------------------
1 | import toSnakeCase from '../src';
2 |
3 | it('converts a given string to snake case', () => {
4 | expect(toSnakeCase('Cool')).toBe('cool');
5 | expect(toSnakeCase('cool mate')).toBe('cool_mate');
6 | expect(toSnakeCase('Hey how are you today?')).toBe('hey_how_are_you_today');
7 | expect(toSnakeCase('PascalCase')).toBe('pascal_case');
8 | expect(toSnakeCase('kebab-case')).toBe('kebab_case');
9 | });
10 |
--------------------------------------------------------------------------------
/packages/toSucc/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/toSucc`
2 |
3 | Converts a string to its equivalent successor.
4 |
5 | **Installation**
6 | `npm i @plexis/to-succ`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toSucc from '@plexis/to-succ';
12 |
13 | toSucc('a'); // returns 'b'
14 | toSucc('A'); // returns 'B'
15 | toSucc('ABCD'); // returns 'BCDE'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {toSucc} from 'plexis';
22 | import {toSuccessor} from 'plexis';
23 | ```
24 |
--------------------------------------------------------------------------------
/packages/toSucc/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-succ",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toSucc/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to its equivalent successor
3 | * @param {String} text
4 | * @example
5 | * toSucc('a') // returns 'b'
6 | * toSucc('A') // returns 'B'
7 | * toSucc('ABCD') // returns 'BCDE'
8 | */
9 |
10 | const toSucc = text =>
11 | text
12 | .split('')
13 | .map(s => String.fromCharCode(s.charCodeAt(0) + 1))
14 |
15 | .join('');
16 |
17 | export default toSucc;
18 |
--------------------------------------------------------------------------------
/packages/toSucc/test/index.js:
--------------------------------------------------------------------------------
1 | import toSucc from '../src';
2 |
3 | it('converts a single char to its successor', () => {
4 | expect(toSucc('a')).toBe('b');
5 | expect(toSucc('A')).toBe('B');
6 | });
7 |
8 | it('converts a sentence to its successor', () => {
9 | expect(toSucc('LoremIpsum')).toBe('MpsfnJqtvn');
10 | });
11 |
12 | it('converts a sentence for other languages', () => {
13 | expect(toSucc('κείμενο')).toBe('λζΰνζξπ');
14 | expect(toSucc('публикация')).toBe('рфвмйлбчйѐ');
15 | expect(toSucc('台匿名的打印机刻意打乱了')).toBe('叱區后皅扔危朻刼愐扔乲亇');
16 | });
17 |
--------------------------------------------------------------------------------
/packages/toSwap/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/toSwap`
2 |
3 | Swaps every character with the next one in a given string.
4 |
5 | `npm i @plexis/to-swap`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import toSwap from '@plexis/to-swap';
11 |
12 | toSwap('ab'); // returns 'ba'
13 | toSwap('abc'); // returns 'bac'
14 | toSwap('abcd'); // returns 'badc'
15 | toSwap('a b'); // returns ' ab'
16 | ```
17 |
18 | **Aliases**
19 |
20 | ```javascript
21 | import {toSwap} from 'plexis';
22 | import {swap} from 'plexis';
23 | ```
24 |
--------------------------------------------------------------------------------
/packages/toSwap/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-swap",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "David Medeiros "
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toSwap/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Swaps every character in a string, until the end of the string
3 | * @param {String} string
4 | * @example
5 | * toSwap('ab') // returns 'ab'
6 | * toSwap('a b') // returns ' ab'
7 | * toSwap('abcd') // returns 'badc'
8 | * @returns {String} reordered letters
9 | */
10 | const toSwap = string => {
11 | var arr = string.split('');
12 | arr.forEach((current, index, array) => {
13 | if (index % 2 == 0) {
14 | array[index] = array[index + 1];
15 | array[index + 1] = current;
16 | }
17 | });
18 | return arr.join('');
19 | };
20 |
21 | export default toSwap;
22 |
--------------------------------------------------------------------------------
/packages/toSwap/test/index.js:
--------------------------------------------------------------------------------
1 | import toSwap from '../src';
2 |
3 | it('Swap only small strings', () => {
4 | expect(toSwap('ab')).toBe('ba');
5 | expect(toSwap('a')).toBe('a');
6 | });
7 | it('Swap an odd number of letters', () => {
8 | expect(toSwap('abc')).toBe('bac');
9 | expect(toSwap('abcd')).toBe('badc');
10 | });
11 | it('Swap with spaces', () => {
12 | expect(toSwap('a b')).toBe(' ab');
13 | expect(toSwap('ab cd')).toBe('bac d');
14 | });
15 | it('Swap Random Characters', () => {
16 | expect(toSwap('1;3')).toBe(';13');
17 | expect(toSwap('.,][')).toBe(',.[]');
18 | });
19 | it('Empty string case', () => {
20 | expect(toSwap('')).toBe('');
21 | });
22 |
--------------------------------------------------------------------------------
/packages/toSwapCase/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/to-swap-case`
2 |
3 | Swaps lowercase to uppercase and vice versa for the input text.
4 |
5 | **Installation**
6 | `npm i @plexis/to-swap-case`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toSwapCase from '@plexis/to-swap-case';
12 |
13 | toSwapCase('Hello WORLD'); // => 'hELLO world'
14 | toSwapCase('123 toys'); // => '123 TOYS'
15 | ```
16 |
17 | **Aliases**
18 |
19 | ```javascript
20 | import toSwapCase from '@plexis/to-swap-case';
21 | import {toSwapCase, swapCase} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/toSwapCase/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-swap-case",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Nowtryz (https://nowtryz.net)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toSwapCase/src/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | /**
4 | * Swaps lowercase to uppercase and vice versa for the input text.
5 | * @param {String} input
6 | * @returns {String} swaped text
7 | * @example
8 | * toSwapCase('Hello WORLD'); // => 'hELLO world'
9 | * toSwapCase('123 toys'); // => '123 TOYS'
10 | */
11 | export default input =>
12 | input
13 | .toString()
14 | .split('')
15 | .map(c => {
16 | const lower = c.toLocaleLowerCase();
17 | return lower === c ? c.toLocaleUpperCase() : lower;
18 | })
19 | .join('');
20 |
--------------------------------------------------------------------------------
/packages/toSwapCase/test/swap-case.test.js:
--------------------------------------------------------------------------------
1 | import swapCase from '../src';
2 |
3 | describe('@plexis/to-swap-case', () => {
4 | it('Swap single char', () => {
5 | expect(swapCase('a')).toBe('A');
6 | expect(swapCase('B')).toBe('b');
7 | expect(swapCase('5')).toBe('5');
8 | });
9 |
10 | it('Swap charters of a sentence', () => {
11 | expect(swapCase('Hello WORLD')).toBe('hELLO world');
12 | expect(swapCase('123 toys')).toBe('123 TOYS');
13 | expect(swapCase('654 À Á Â Ã Ä Å Æ Ç È É Ê ę')).toBe('654 à á â ã ä å æ ç è é ê Ę');
14 | });
15 | });
16 |
--------------------------------------------------------------------------------
/packages/toTitle/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/toTitle`
2 |
3 | Converts a string to a title, capitalizes the first letter of each word.
4 |
5 | **Installation**
6 | `npm i @plexis/to-title`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import toTitle from '@plexis/to-title';
12 |
13 | toTitle('this is cool mate'); // returns 'This Is Cool Mate'
14 | ```
15 |
16 | **Aliases**
17 |
18 | ```javascript
19 | import {toTitle} from 'plexis';
20 | import {titleize} from 'plexis';
21 | ```
22 |
--------------------------------------------------------------------------------
/packages/toTitle/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/to-title",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/toTitle/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Converts a string to a title, capitalizes the first letter of each word.
3 | * @param {String} text
4 | * @example
5 | * toTitle('this is cool mate') // returns 'This Is Cool Mate'
6 | */
7 | const toTitle = text =>
8 | text
9 | .toLowerCase()
10 | .split(' ')
11 | .map(s => s.charAt(0).toUpperCase() + s.substring(1))
12 | .join(' ');
13 |
14 | export default toTitle;
15 |
--------------------------------------------------------------------------------
/packages/toTitle/test/index.js:
--------------------------------------------------------------------------------
1 | import toTitle from '../src';
2 |
3 | it('converts a sigle word sentence to a title', () => {
4 | expect(toTitle('this')).toBe('This');
5 | });
6 |
7 | it('converts a multiword sentence to a title', () => {
8 | expect(toTitle('this is cool mate')).toBe('This Is Cool Mate');
9 | });
10 |
11 | it('converts a multiword sentence to a title for any given language', () => {
12 | // lipsum.com
13 | // Greek
14 | expect(
15 | toTitle(
16 | 'Το Lorem Ipsum είναι απλά ένα κείμενο χωρίς νόημα για τους επαγγελματίες της τυπογραφίας και στοιχειοθεσίας.'
17 | )
18 | ).toBe(
19 | 'Το Lorem Ipsum Είναι Απλά Ένα Κείμενο Χωρίς Νόημα Για Τους Επαγγελματίες Της Τυπογραφίας Και Στοιχειοθεσίας.'
20 | );
21 |
22 | // French
23 | expect(toTitle("Est qu'il possède une distribution de l'imprimerie depuis")).toBe(
24 | "Est Qu'il Possède Une Distribution De L'imprimerie Depuis"
25 | );
26 |
27 | // Spanish
28 | expect(toTitle('el texto de relleno estándar de las industrias desde el año 1500')).toBe(
29 | 'El Texto De Relleno Estándar De Las Industrias Desde El Año 1500'
30 | );
31 | });
32 |
--------------------------------------------------------------------------------
/packages/when/README.md:
--------------------------------------------------------------------------------
1 | ## `when`
2 |
3 | `when` is used for checking and chaining within the composition for supercharged functions.
4 |
5 | `npm i @plexis/when`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import compose from '@plexis/compose';
11 | import when from '@plexis/when';
12 |
13 | const inc = x => x + 1;
14 | const add = (x, y) => x + y;
15 | const setToZero = () => 0;
16 |
17 | const compose = (...fns) => x => fns.reduce((r, f) => f(r), x);
18 | const when = (cond, f) => x => (cond(x) ? f(x) : x);
19 |
20 | const ops = compose(
21 | inc,
22 | x => add(x, 2),
23 | when(num => num > 0, compose(setToZero))
24 | );
25 |
26 | ops(1); // returns 0
27 | ops(100); // returns 0
28 | ops(-100); // returns -97
29 | ```
30 |
31 | **Aliases**
32 |
33 | ```javascript
34 | import when from '@plexis/when';
35 | import {when} from 'plexis';
36 | ```
37 |
--------------------------------------------------------------------------------
/packages/when/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/when",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/when/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Is used for checking and chaining within the composition for supercharged functions.
3 | * @param {Function|Boolean} [checking] A function or condition to check.
4 | * @param {Function} [func] The function to invoke.
5 | * @returns {Function} Returns the new composite function.
6 | * @example
7 | * _when(num => num < 0, () => 0)(-1) // returns 0
8 | */
9 | const _when = (checking, func) => value => {
10 | if (checking === true || (typeof checking === 'function' && checking(value))) {
11 | return func(value);
12 | }
13 | return value;
14 | };
15 |
16 | export default _when;
17 |
--------------------------------------------------------------------------------
/packages/when/test/index.js:
--------------------------------------------------------------------------------
1 | import _when from '../src';
2 |
3 | it('executes the function if the condition is a boolean and true', () => {
4 | const mock = jest.fn();
5 | _when(true, mock)(1);
6 | expect(mock).toHaveBeenCalledTimes(1);
7 | expect(mock).toHaveBeenCalledWith(1);
8 | });
9 |
10 | it("doesn't execute the function if the condition is a boolean and false", () => {
11 | const mock = jest.fn();
12 | _when(false, mock)(1);
13 | expect(mock).toHaveBeenCalledTimes(0);
14 | });
15 |
16 | it('executes the function if the condition is a function and evaluates to true', () => {
17 | const mock = jest.fn();
18 | _when(x => x > 0, mock)(1);
19 | expect(mock).toHaveBeenCalledTimes(1);
20 | expect(mock).toHaveBeenCalledWith(1);
21 | });
22 |
23 | it("doesn't execute the function if the condition is a function and evaluates to false", () => {
24 | const mock = jest.fn();
25 | _when(x => x > 0, mock)(-1);
26 | expect(mock).toHaveBeenCalledTimes(0);
27 | });
28 |
--------------------------------------------------------------------------------
/packages/withoutDiacritics/README.md:
--------------------------------------------------------------------------------
1 | ## `@plexis/withoutDiacritics`
2 |
3 | Cleanups a string from diacritics.
4 |
5 | **Installation**
6 | `npm i @plexis/without-diacritics`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import withoutDiacritics from '@plexis/without-diacritics';
12 |
13 | withoutDiacritics('áéíóú'); // returns 'aeiou'
14 | ```
15 |
16 | **Aliases**
17 |
18 | ```javascript
19 | import {withoutDiacritics} from 'plexis';
20 | import {cleanDiacritics} from 'plexis';
21 | import {removeDiacritics} from 'plexis';
22 | ```
23 |
--------------------------------------------------------------------------------
/packages/withoutDiacritics/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/without-diacritics",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Theodore Vorillas (https://vorillaz.com)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/withoutDiacritics/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Cleanups a string from diacritics.
3 | * @param {String} text
4 | * @example
5 | * withoutDiacritics('áéíóú') // returns 'aeiou'
6 | */
7 | const withoutDiacritics = text => text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
8 |
9 | export default withoutDiacritics;
10 |
--------------------------------------------------------------------------------
/packages/withoutDiacritics/test/index.js:
--------------------------------------------------------------------------------
1 | import withoutDiacritics from '../src';
2 |
3 | it('removes any diacritics for Galician', () => {
4 | expect(withoutDiacritics('áéíóú')).toBe('aeiou');
5 | });
6 |
7 | it('removes any diacritics for Greek', () => {
8 | expect(withoutDiacritics('Άά Έέ Ήή Ίί Όό Ύύ Ώώ ΐ ΰ Ϊϊ Ϋϋ')).toBe(
9 | 'Αα Εε Ηη Ιι Οο Υυ Ωω ι υ Ιι Υυ'
10 | );
11 | });
12 |
13 | it('removes any diacritics for Latvian', () => {
14 | expect(withoutDiacritics('āēīūčģķļņšž')).toBe('aeiucgklnsz');
15 | });
16 |
17 | it('removes any diacritics for Czech', () => {
18 | expect(withoutDiacritics('č ď ě ň ř š ť ž')).toBe('c d e n r s t z');
19 | });
20 |
--------------------------------------------------------------------------------
/packages/withoutHTML/README.md:
--------------------------------------------------------------------------------
1 | # `@plexis/withoutHTML`
2 |
3 | Removes HTML tags from the input text.
4 |
5 | **Installation**
6 | `npm i @plexis/without-html`
7 |
8 | **Usage**
9 |
10 | ```javascript
11 | import withoutHTML from '@plexis/without-html';
12 |
13 | withoutHTML('Hello world'); // => 'Hello world'
14 | withoutHTML('Hello world'); // => ' world'
15 | withoutHTML(' ' Hello world '); // => ''
17 | withoutHTML(' from the underground'); // => ' from the underground'
18 | ```
19 |
20 | **Aliases**
21 |
22 | ```javascript
23 | import withoutHTML from '@plexis/without-html';
24 | import {withoutHTML, removeHTML} from 'plexis';
25 | ```
26 |
--------------------------------------------------------------------------------
/packages/withoutHTML/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/without-html",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "authors": [
12 | "Gopi Krishna (https://bgopikrishna.me)"
13 | ],
14 | "license": "MIT",
15 | "keywords": [
16 | "utility",
17 | "string",
18 | "parse",
19 | "format",
20 | "validate"
21 | ],
22 | "repository": {
23 | "type": "git",
24 | "url": "git+https://github.com/plexis-js/plexis.git"
25 | },
26 | "publishConfig": {
27 | "access": "public"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/withoutHTML/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Remove HTML tags from the input text
3 | * @param {String} text
4 | * @returns {String} text without HTML
5 | * @example
6 | * withoutHTML('Hello world') => 'Hello world'
7 | * withoutHTML('Hello world') => ' world'
8 | * withoutHTML(' ' Hello world ') => ''
10 | * withoutHTML(' from the underground ') => ' from the underground'
11 | */
12 |
13 | const withoutHTML = string => {
14 | const wordPatt = /[^>]+>/g;
15 | const stringWithOutHtml = string.replace(wordPatt, '');
16 |
17 | return stringWithOutHtml;
18 | };
19 |
20 | export default withoutHTML;
21 |
--------------------------------------------------------------------------------
/packages/withoutHTML/test/index.js:
--------------------------------------------------------------------------------
1 | import withoutHTML from '../src';
2 |
3 | it('Remove HTML tags from the input text', () => {
4 | expect(withoutHTML('Hello world')).toBe('Hello world');
5 | expect(withoutHTML(' Hello world')).toBe(' world');
6 | expect(withoutHTML('Hello world ')).toBe('');
8 | expect(withoutHTML(' from the underground')).toBe(
9 | ' from the underground'
10 | );
11 | });
12 |
--------------------------------------------------------------------------------
/packages/withoutIndent/README.md:
--------------------------------------------------------------------------------
1 | ## `withoutIndent`
2 |
3 | Removes leading whitespaces from each line in a string
4 |
5 | `npm i @plexis/without-indent`
6 |
7 | **Usage**
8 |
9 | ```javascript
10 | import withoutIndent from '@plexis/without-indent';
11 |
12 | withoutIndent('\t\t\tHello World'); // returns 'Hello World'
13 | withoutIndent('\n\tHello\n\tWorld'); // returns '\nHello\nWorld'
14 | ```
15 |
16 | **Aliases**
17 |
18 | ```javascript
19 | import {removeIndent} from 'plexis';
20 | import {dedent} from 'plexis';
21 | ```
22 |
--------------------------------------------------------------------------------
/packages/withoutIndent/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@plexis/without-indent",
3 | "version": "0.0.22",
4 | "main": "dist/index.js",
5 | "module": "dist/index.esm.js",
6 | "jsnext:main": "./src/index.js",
7 | "files": [
8 | "dist",
9 | "src"
10 | ],
11 | "license": "MIT",
12 | "keywords": [
13 | "utility",
14 | "string",
15 | "parse",
16 | "format",
17 | "validate"
18 | ],
19 | "repository": {
20 | "type": "git",
21 | "url": "git+https://github.com/plexis-js/plexis.git"
22 | },
23 | "publishConfig": {
24 | "access": "public"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/packages/withoutIndent/src/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * @description Removes leading whitespaces from every line in the given string
3 | * @param {String} text
4 | * @param {Number} [removeUpTo] - Specifies how many whitespaces to remove
5 | * @example
6 | *
7 | * withoutIndent('\t\t\tHello World'); // returns 'Hello World'
8 | * withoutIndent('\n\tHello\n\tWorld'); // returns '\nHello\nWorld'
9 | * withoutIndent('\n\tHello\n\t\t\tWorld', 2); // returns '\nHello\n\tWorld'
10 | */
11 | const withoutIndent = (text, removeUpTo) => {
12 | if (removeUpTo <= 0) return text;
13 | const howMany = typeof removeUpTo === 'number' ? `{1,${removeUpTo}}` : '+';
14 | const regex = new RegExp(`^[ \\t\\r]${howMany}|(?<=\\n+)[ \\t\\r]${howMany}`, 'g');
15 | return text.replace(regex, '');
16 | };
17 |
18 | export default withoutIndent;
19 |
--------------------------------------------------------------------------------
/packages/withoutIndent/test/index.js:
--------------------------------------------------------------------------------
1 | import withoutIndent from '../src';
2 |
3 | it('removes an indent from the front', () => {
4 | expect(withoutIndent('\tHello')).toBe('Hello');
5 | expect(withoutIndent('\rHello')).toBe('Hello');
6 | expect(withoutIndent(' Hello')).toBe('Hello');
7 | });
8 |
9 | it("doesn't remove newline characters", () => {
10 | expect(withoutIndent('\nHello')).toBe('\nHello');
11 | });
12 |
13 | it("doesn't remove anything when there's no indent", () => {
14 | expect(withoutIndent('Hello')).toBe('Hello');
15 | });
16 |
17 | it('removes multiple indents.', () => {
18 | expect(withoutIndent('\t\t\tHello')).toBe('Hello');
19 | });
20 |
21 | it('removes indents on multiple lines', () => {
22 | expect(withoutIndent('\t\tHello\n\t\tWorld')).toBe('Hello\nWorld');
23 | });
24 |
25 | it("doesn't remove indents that aren't at the beginning of a line.", () => {
26 | expect(withoutIndent('Hello\t')).toBe('Hello\t');
27 | });
28 |
29 | it('removes only specified amount of indents', () => {
30 | expect(withoutIndent('\t\t\t\tHello', 3)).toBe('\tHello');
31 | });
32 |
33 | it("doesn't remove extra characters when amount specified exceeds indents", () => {
34 | expect(withoutIndent('\t\tHello', 3)).toBe('Hello');
35 | });
36 |
37 | it("doesn't remove indents when 0 is given as amount", () => {
38 | expect(withoutIndent('\tHello', 0)).toBe('\tHello');
39 | });
40 |
41 | it('removes a mix of different indent characters', () => {
42 | expect(withoutIndent('\t \rHello')).toBe('Hello');
43 | });
44 |
--------------------------------------------------------------------------------
|