Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
new strip spaces + fix filterAlphaNumericPlus
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisweb committed Aug 31, 2020
1 parent e2ae560 commit 1e28fb5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 11 deletions.
4 changes: 2 additions & 2 deletions dist/@types/chrisweb-utilities/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { isServer, isClient } from './utilities/platform';
import { getUrlParameters, getUrlParameterByName, replaceUrlParameter } from './utilities/url';
import { decodeUri, encodeUri } from './utilities/uri';
import { removeString, isArray, includes, find, flat } from './utilities/array';
import { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders } from './utilities/string';
import { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, removeAllSpaces } from './utilities/string';
import { generateUUID } from './utilities/uuid';
import { removeElements } from './utilities/html';
import { log } from './utilities/log';
import { sleep } from './utilities/helper';
import { randomInteger, choice } from './utilities/random';
declare const version = "1.0.0";
export { version, getTimestamp, isServer, isClient, getUrlParameters, getUrlParameterByName, replaceUrlParameter, decodeUri, encodeUri, removeString, isArray, includes, find, flat, filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, generateUUID, removeElements, log, sleep, randomInteger, choice };
export { version, getTimestamp, isServer, isClient, getUrlParameters, getUrlParameterByName, replaceUrlParameter, decodeUri, encodeUri, removeString, isArray, includes, find, flat, filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, generateUUID, removeElements, log, sleep, randomInteger, choice, removeAllSpaces };
9 changes: 7 additions & 2 deletions dist/@types/chrisweb-utilities/utilities/string.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param inputString
* @param specialCharacters
*/
declare const filterAlphaNumericPlus: (inputString: string, specialCharacters: string) => string | boolean;
declare const filterAlphaNumericPlus: (inputString: string, specialCharacters?: string) => string | boolean;
/**
* capitalise first letter of a string
* @param inputString
Expand All @@ -30,4 +30,9 @@ declare const getSubstringIndex: (inputString: string, substring: string, nthTim
* @param replacements
*/
declare const replacePlaceholders: (input: string, replacements: string) => string;
export { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders };
/**
* remove all spaces from a string
* @param input
*/
declare const removeAllSpaces: (input: string) => string;
export { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, removeAllSpaces };
9 changes: 8 additions & 1 deletion dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.esm.js.map

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isServer, isClient } from './utilities/platform';
import { getUrlParameters, getUrlParameterByName, replaceUrlParameter } from './utilities/url';
import { decodeUri, encodeUri } from './utilities/uri';
import { removeString, isArray, includes, find, flat } from './utilities/array';
import { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders } from './utilities/string';
import { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, removeAllSpaces } from './utilities/string';
import { generateUUID } from './utilities/uuid';
import { removeElements } from './utilities/html';
import { log } from './utilities/log';
Expand Down Expand Up @@ -37,5 +37,6 @@ export {
log,
sleep,
randomInteger,
choice
choice,
removeAllSpaces
};
12 changes: 10 additions & 2 deletions src/utilities/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @param inputString
* @param specialCharacters
*/
const filterAlphaNumericPlus = (inputString: string, specialCharacters: string): string|boolean => {
const filterAlphaNumericPlus = (inputString: string, specialCharacters?: string): string|boolean => {

if (typeof (inputString) === 'string' && inputString.length > 0) {

Expand Down Expand Up @@ -105,4 +105,12 @@ const replacePlaceholders = (input: string, replacements: string): string => {

};

export { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders };
/**
* remove all spaces from a string
* @param input
*/
const removeAllSpaces = (input: string): string => {
return input.replace(/\s/g,'');
};

export { filterAlphaNumericPlus, capitaliseFirstLetter, stringContains, getSubstringIndex, replacePlaceholders, removeAllSpaces };
21 changes: 21 additions & 0 deletions tests/string.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { filterAlphaNumericPlus, removeAllSpaces } from '../src/utilities/string';

test('test to check alpha + numeric filter works', () => {
const filtered = filterAlphaNumericPlus(' foo 123 bar #!$%&/()? baz ');
expect(filtered).toBe('foo123barbaz')
});

test('test to check alpha + numeric plus filter works', () => {
const filtered = filterAlphaNumericPlus(' foo bar !$% baz ', '!$%');
expect(filtered).toBe('foobar!$%baz')
});

test('test to check alpha + numeric filter works accepts space as specialcharacter that shouldnt get filtered', () => {
const filtered = filterAlphaNumericPlus(' foo bar #!$%&/()? baz ', ' ');
expect(filtered).toBe(' foo bar baz ')
});

test('test to check if removing spaces works', () => {
const noSpacesString = removeAllSpaces(' foo bar baz ');
expect(noSpacesString).toBe('foobarbaz')
});

0 comments on commit 1e28fb5

Please sign in to comment.