You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

string-craft

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-craft

Simple string manipulation library for TypeScript

2.4.2
latest
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

string-craft

npm npm

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 ProviderBuild Status
SonarCloudQuality Gate Status
GitHub actionsbuild
GitHub actionsbuild
GitHub actionsbuild
Codecovcodecov
Stryker-mutator dashboardMutation testing badge

Usage

Install

npm i string-craft

Import

import { String } from 'string-craft';

Fields

NameDescription
EMPTYRepresents the empty string. This field is read-only. The value of this field is the zero-length string ("").

EMPTY

String.EMPTY;
// ""

Methods

NameDescriptionInput parametersReturn
isEmptyIndicates whether the specified string is an empty string ("") (reverse with isNotEmpty method).value: stringboolean
isNullOrEmptyIndicates whether the specified string is null, undefined or an empty string ("") (reverse with isNotNullOrEmpty method).value: string | null | undefinedboolean
isBlankIndicates whether a specified string is empty, or consists only of white-space characters (reverse with isNotBlank method).value: stringboolean
isNullOrBlankIndicates whether a specified string is null, undefined, empty, or consists only of white-space characters (reverse with isNotNullOrBlank method).value: string | null | undefinedboolean
isNumberIndicates whether the specified string is a valid numeric string (reverse with isNotNumber method).value: string | null | undefinedboolean
isAlphaIndicates whether a given value consists only of alphabetic characters (reverse with isNotAlpha method).value: string | null | undefinedboolean
isAlphaNumberIndicates whether the specified string contains only alphabetic characters and numbers (reverse with isNotAlphaNumber method).value: string | null | undefinedboolean
isBasicStrongPasswordIndicates 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 | undefinedboolean
containsNumberIndicates whether the specified string contains at least one numeric digit (reverse with notContainsNumber method).value: string | null | undefinedboolean
containsAlphaIndicates whether the specified string contains at least one alphabetic character (reverse with notContainsAlpha method).value: string | null | undefinedboolean
containsSpecialCharacterIndicates whether a given string contains at least one special character (reverse with notContainsSpecialCharacter method).value: string | null | undefinedboolean
containsUpperCaseIndicates whether the specified string contains at least one uppercase letter.value: string | null | undefinedboolean
containsLowerCaseIndicates whether the specified string contains at least one lowercase letter.value: string | null | undefinedboolean
valueOrEmptyReturns an empty string if the value is null, undefined, or blank; otherwise, returns the input value.value: string | null | undefinedstring
removeAccentsRemoves accents from a given string.value: stringstring
joinConcatenates an array of strings using the specified separator between each member.separator: string, values: (string | null | undefined)[]string
countWordsCounts the number of words in a sentence.sentence: string | null | undefinednumber
toNumberConverts a string representation of a number to a JavaScript number.value: string | null | undefinednumber
toBooleanConverts a string representation to a boolean value.value: string | null | undefinedboolean

isEmpty

String.isEmpty('value');
// false

String.isEmpty('  ');
// false

String.isEmpty('');
// true

isNullOrEmpty

String.isNullOrEmpty('value');
// false

String.isNullOrEmpty('  ');
// false

String.isNullOrEmpty(null);
// true

String.isNullOrEmpty('');
// true

isBlank

String.isBlank('value');
// false

String.isBlank('  ');
// true

String.isBlank('');
// true

isNullOrBlank

String.isNullOrBlank('value');
// false

String.isNullOrBlank('  ');
// true

String.isNullOrBlank(null);
// true

String.isNullOrBlank('');
// true

removeAccents

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!');
// 5

isNumber

String.isNumber('Hello world');
// false

String.isNumber('');
// false

String.isNumber('  ');
// false

String.isNumber(null);
// false

String.isNumber('99');
// true

isAlpha

String.isAlpha('123abc');
// false

String.isAlpha('abc');
// true

isAlphaNumber

String.isAlphaNumber('123abc');
// true

String.isAlphaNumber('abc');
// false

String.isAlphaNumber('123');
// false

String.isAlphaNumber('abc-123');
// false

containsSpecialCharacter

String.containsSpecialCharacter('123abc');
// false

String.containsSpecialCharacter('123abc/');
// true

containsNumber

String.containsNumber('^abc1def+');
// true

String.containsNumber('!abc&def/');
// false

containsAlpha

String.containsAlpha('^123a456+');
// true

String.containsAlpha('!123&456/');
// false

containsUpperCase

String.containsUpperCase('abcDef');
// true

String.containsUpperCase('abcdef');
// false

String.containsUpperCase('12!@');
// false

containsLowerCase

String.containsLowerCase('ABCdEF');
// true

String.containsLowerCase('ABCD');
// false

String.containsLowerCase('12!@');
// false

isBasicStrongPassword

String.isBasicStrongPassword('123456789AB@');
// false

String.isBasicStrongPassword('123456789ab@');
// false

String.isBasicStrongPassword('12345678901@');
// false

String.isBasicStrongPassword('123456789aBC');
// false

String.isBasicStrongPassword('123abC#$');
// false

String.isBasicStrongPassword('1234abcefgH!');
// true

toNumber

String.toNumber(null);
// 0
String.toNumber(undefined);
// 0
String.toNumber('   ');
// 0
String.toNumber('A123@');
// 0
String.toNumber('true');
// 0
String.toNumber('10');
// 10
String.toNumber('-10');
// -10
String.toNumber('10.1234');
// 10.1234

toBoolean

String.toBoolean(undefined);
// false
String.toBoolean(' ');
// false
String.toBoolean('1');
// true
String.toBoolean('true');
// true

valueOrEmpty

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 install

Test

Unit test

The code is covered by unit tests with Vitest.

npm run test
Coverage
npm run test:coverage

Mutation test

Possibility to run mutation tests with Stryker.

npm run test:mutation

Keywords

typescript

FAQs

Package last updated on 01 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts