npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

string-craft

v2.4.2

Published

Simple string manipulation library for TypeScript

Downloads

232

Readme

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 Provider | Build Status | |:-------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | SonarCloud | Quality Gate Status | | GitHub actions | build | | GitHub actions | build | | GitHub actions | build | | Codecov | codecov | | Stryker-mutator dashboard | Mutation testing badge |

Usage

Install

npm i string-craft

Import

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 | Indicates whether the specified string is an empty string ("") (reverse with isNotEmpty method). | value: string | boolean | | isNullOrEmpty | Indicates whether the specified string is null, undefined or an empty string ("") (reverse with isNotNullOrEmpty method). | value: string | null | undefined | boolean | | isBlank | Indicates whether a specified string is empty, or consists only of white-space characters (reverse with isNotBlank method). | value: string | boolean | | 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 | Indicates whether the specified string is a valid numeric string (reverse with isNotNumber method). | value: string | null | undefined | boolean | | isAlpha | Indicates whether a given value consists only of alphabetic characters (reverse with isNotAlpha method). | value: string | null | undefined | boolean | | isAlphaNumber | Indicates whether the specified string contains only alphabetic characters and numbers (reverse with isNotAlphaNumber method). | value: string | null | undefined | boolean | | 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 | Indicates whether the specified string contains at least one numeric digit (reverse with notContainsNumber method). | value: string | null | undefined | boolean | | containsAlpha | Indicates whether the specified string contains at least one alphabetic character (reverse with notContainsAlpha method). | value: string | null | undefined | boolean | | containsSpecialCharacter | Indicates whether a given string contains at least one special character (reverse with notContainsSpecialCharacter method). | value: string | null | undefined | boolean | | containsUpperCase | Indicates whether the specified string contains at least one uppercase letter. | value: string | null | undefined | boolean | | containsLowerCase | Indicates whether the specified string contains at least one lowercase letter. | value: string | null | undefined | boolean | | valueOrEmpty | Returns an empty string if the value is null, undefined, or blank; otherwise, returns the input value. | value: string | null | undefined | string | | removeAccents | Removes accents from a given string. | value: string | string | | join | Concatenates an array of strings using the specified separator between each member. | separator: string, values: (string | null | undefined)[] | string | | countWords | Counts the number of words in a sentence. | sentence: string | null | undefined | number | | toNumber | Converts a string representation of a number to a JavaScript number. | value: string | null | undefined | number | | toBoolean | Converts a string representation to a boolean value. | value: string | null | undefined | boolean |

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