2.4.2 • Published 1 year ago
string-craft v2.4.2
string-craft
Simple string manipulation library for TypeScript.
string-craft is a comprehensive TypeScript library designed to simplify and enhance string manipulation tasks.
CI Status
The following table lists live workflows from various CI providers.
| CI Provider | Build Status |
|---|---|
| SonarCloud | |
| GitHub actions | |
| GitHub actions | |
| GitHub actions | |
| Codecov | |
| Stryker-mutator dashboard |
Usage
Install
npm i string-craftImport
import { String } from 'string-craft';Fields
| Name | Description |
|---|---|
EMPTY | Represents the empty string. This field is read-only. The value of this field is the zero-length string (""). |
EMPTY
String.EMPTY;
// ""Methods
| Name | Description | Input parameters | Return |
|---|---|---|---|
[isEmpty](#isEmpty) | Indicates whether the specified string is an empty string ("") (reverse with isNotEmpty method). | value: string | boolean |
[isNullOrEmpty](#isNullOrEmpty) | Indicates whether the specified string is null, undefined or an empty string ("") (reverse with isNotNullOrEmpty method). | value: string | null | undefined | boolean |
[isBlank](#isBlank) | Indicates whether a specified string is empty, or consists only of white-space characters (reverse with isNotBlank method). | value: string | boolean |
[isNullOrBlank](#isNullOrBlank) | Indicates whether a specified string is null, undefined, empty, or consists only of white-space characters (reverse with isNotNullOrBlank method). | value: string | null | undefined | boolean |
[isNumber](#isNumber) | Indicates whether the specified string is a valid numeric string (reverse with isNotNumber method). | value: string | null | undefined | boolean |
[isAlpha](#isAlpha) | Indicates whether a given value consists only of alphabetic characters (reverse with isNotAlpha method). | value: string | null | undefined | boolean |
[isAlphaNumber](#isAlphaNumber) | Indicates whether the specified string contains only alphabetic characters and numbers (reverse with isNotAlphaNumber method). | value: string | null | undefined | boolean |
[isBasicStrongPassword](#isBasicStrongPassword) | Indicates whether the specified string contains at least 1 uppercase letter, 1 lowercase letter, 1 number, 1 special character and a minimum length of 12 characters. | value: string | null | undefined | boolean |
[containsNumber](#containsNumber) | Indicates whether the specified string contains at least one numeric digit (reverse with notContainsNumber method). | value: string | null | undefined | boolean |
[containsAlpha](#containsAlpha) | Indicates whether the specified string contains at least one alphabetic character (reverse with notContainsAlpha method). | value: string | null | undefined | boolean |
[containsSpecialCharacter](#containsSpecialCharacter) | Indicates whether a given string contains at least one special character (reverse with notContainsSpecialCharacter method). | value: string | null | undefined | boolean |
[containsUpperCase](#containsUpperCase) | Indicates whether the specified string contains at least one uppercase letter. | value: string | null | undefined | boolean |
[containsLowerCase](#containsLowerCase) | Indicates whether the specified string contains at least one lowercase letter. | value: string | null | undefined | boolean |
[valueOrEmpty](#valueOrEmpty) | Returns an empty string if the value is null, undefined, or blank; otherwise, returns the input value. | value: string | null | undefined | string |
[removeAccents](#removeAccents) | Removes accents from a given string. | value: string | string |
[join](#join) | Concatenates an array of strings using the specified separator between each member. | separator: string, values: (string | null | undefined)[] | string |
[countWords](#countWords) | Counts the number of words in a sentence. | sentence: string | null | undefined | number |
[toNumber](#toNumber) | Converts a string representation of a number to a JavaScript number. | value: string | null | undefined | number |
[toBoolean](#toBoolean) | Converts a string representation to a boolean value. | value: string | null | undefined | boolean |
isEmpty
String.isEmpty('value');
// false
String.isEmpty(' ');
// false
String.isEmpty('');
// trueisNullOrEmpty
String.isNullOrEmpty('value');
// false
String.isNullOrEmpty(' ');
// false
String.isNullOrEmpty(null);
// true
String.isNullOrEmpty('');
// trueisBlank
String.isBlank('value');
// false
String.isBlank(' ');
// true
String.isBlank('');
// trueisNullOrBlank
String.isNullOrBlank('value');
// false
String.isNullOrBlank(' ');
// true
String.isNullOrBlank(null);
// true
String.isNullOrBlank('');
// trueremoveAccents
String.removeAccents('déjà là');
// 'deja la'join
String.join('; ', 'apple', 'banana', 'orange', 'grape');
// 'apple; banana; orange; grape'countWords
String.countWords('Hello world');
// 2
String.countWords('hello - all the world ! WAIT!');
// 5isNumber
String.isNumber('Hello world');
// false
String.isNumber('');
// false
String.isNumber(' ');
// false
String.isNumber(null);
// false
String.isNumber('99');
// trueisAlpha
String.isAlpha('123abc');
// false
String.isAlpha('abc');
// trueisAlphaNumber
String.isAlphaNumber('123abc');
// true
String.isAlphaNumber('abc');
// false
String.isAlphaNumber('123');
// false
String.isAlphaNumber('abc-123');
// falsecontainsSpecialCharacter
String.containsSpecialCharacter('123abc');
// false
String.containsSpecialCharacter('123abc/');
// truecontainsNumber
String.containsNumber('^abc1def+');
// true
String.containsNumber('!abc&def/');
// falsecontainsAlpha
String.containsAlpha('^123a456+');
// true
String.containsAlpha('!123&456/');
// falsecontainsUpperCase
String.containsUpperCase('abcDef');
// true
String.containsUpperCase('abcdef');
// false
String.containsUpperCase('12!@');
// falsecontainsLowerCase
String.containsLowerCase('ABCdEF');
// true
String.containsLowerCase('ABCD');
// false
String.containsLowerCase('12!@');
// falseisBasicStrongPassword
String.isBasicStrongPassword('123456789AB@');
// false
String.isBasicStrongPassword('123456789ab@');
// false
String.isBasicStrongPassword('12345678901@');
// false
String.isBasicStrongPassword('123456789aBC');
// false
String.isBasicStrongPassword('123abC#$');
// false
String.isBasicStrongPassword('1234abcefgH!');
// truetoNumber
String.toNumber(null);
// 0String.toNumber(undefined);
// 0String.toNumber(' ');
// 0String.toNumber('A123@');
// 0String.toNumber('true');
// 0String.toNumber('10');
// 10String.toNumber('-10');
// -10String.toNumber('10.1234');
// 10.1234toBoolean
String.toBoolean(undefined);
// falseString.toBoolean(' ');
// falseString.toBoolean('1');
// trueString.toBoolean('true');
// truevalueOrEmpty
String.valueOrEmpty(undefined);
// ''String.valueOrEmpty(null);
// ''String.valueOrEmpty(' ');
// ''String.valueOrEmpty('pomme de terre');
// 'pomme de terre'License
This software is released under the terms of the MIT license. See LICENSE.
Contribute
The code is written in TDD and therefore has a nice code coverage by the tests, please keep this cap ;)
Install
npm installTest
Unit test
The code is covered by unit tests with [Vitest](https://vitest.dev/).
npm run testCoverage
npm run test:coverageMutation test
Possibility to run mutation tests with [Stryker](https://stryker-mutator.io/docs/stryker-js/introduction/).
npm run test:mutation