@full-pack/string-pack
A lightweight and versatile String Utility Package for Node.js & Browser.
Contents
install
npm install @full-pack/string-pack
require
const { ... } = require('@full-pack/string-pack');
import
import { ... } from '@full-pack/string-pack';
API
padding
Adds padding to given string.
padStart
Pads the start of a string with a specified fill string a certain number of times.
padStart('hello', 'abc', 3)
padStart('hello', 'abc', 3, 8)
padEnd
Pads the end of a string with a specified fill string a certain number of times.
padEnd('hello', 'abc', 3);
padEnd('hello', 'abc', 3, 8);
padBidirectional
Pads a string with a specified fill string a certain number of times on both ends.
padBidirectional('hello', '*', 2);
padBidirectional('world', '-', 3, 10);
padBidirectional('example', '*', 2, 10, 0);
merge
Merges an array of strings into a single string using a specified separator.
merge('-', 'apple', 'orange', 'banana');
merge(true, 'apple', 'orange');
merge(false, 'apple', 'orange', 'banana');
compare
Performs a strict comparison between two strings.
compare("hello", "hello");
compare("abc", "ABC");
looseCompare
Performs a case-insensitive loose comparison between two strings.
looseCompare("hello", "HELLO");
looseCompare('abc', '123');
capitalizeInitial
Capitalizes the first letter of a word in a string.
capitalizeInitial('hello');
capitalizeInitial(':> hello');
capitalizeWords
Capitalizes the first letter of each word in a given string.
capitalizeWords('hello world');
capitalizeWords('Sphinx of black quartz:-judge my vow');
Case Conversion
snakeCase
Converts a string to snake_case format.
snakeCase('hello WorLd');
snakeCase('from-kebab-case');
snakeCase('snake Case With Numbers123', true);
kebabCase
Converts a string to kebab-case format.
kebabCase('h3llo WoRld');
kebabCase('from_snake_case');
kebabCase('kebab Case With Numbers123', true);
camelCase
Converts a string to camelCase format.
camelCase('hello WoRld');
camelCase('Test CaSe ExamplE');
camelCase('camel Case With Numbers123');
pascalCase
Converts a string to PascalCase format.
pascalCase('hello WoRld');
pascalCase('Test CaSe ExamplE');
pascalCase('pasCal Case With Numbers123');
Case Validation
isSnakeCase
Checks if a string is in snake_case format.
isSnakeCase('snake_case_example');
isSnakeCase('hello_world');
isSnakeCase('with_1234', true);
isSnakeCase('pi_3_14', true);
isSnakeCase('123at_start');
isSnakeCase(' no_space_allowed');
isSnakeCase('no_CAPS');
isKebabCase
Checks if a string is in kebab-case format.
isKebabCase('kebab-case-example');
isKebabCase('hello-world');
isKebabCase('with-1234', true);
isKebabCase('pi-3-14', true);
isKebabCase('123at-start');
isKebabCase(' no-space-allowed');
isKebabCase('no-CAPS');
isCamelCase
Checks if a string is in camelCase format.
isCamelCase('camelCaseExample');
isCamelCase('helloWorld');
isCamelCase('CAMEL');
isCamelCase(' noSpaceAllowed');
isCamelCase('withThe1234');
isPascalCase
Checks if a string is in PascalCase format.
isPascalCase('PascalCaseExample');
isPascalCase('HelloWorld');
isPascalCase('PASCAL');
isPascalCase(' NoSpaceAllowed');;
isPascalCase('WithThe1234');
regionMatch
Compares two strings or regions for equality.
regionMatch('hello', 'hello');
const str1 = { str: 'hello world', start: 0, end: 5 };
const str2 = { str: 'hello there', start: 0, end: 5 };
regionMatch(str1, str2);
regionMatch('hello world', 'hello there', 0, 5)
regionMatch('hello world', 'hello there', 6, 11);
looseRegionMatch
Performs a loose comparison of two strings or regions for equality.
looseRegionMatch('hello', 'HeLLo');
const str1 = { str: ' hellO world', start: 1, end: 6 };
const str2 = { str: 'HelLo there', start: 0, end: 5 };
looseRegionMatch(str1, str2);
isAlpha
Checks if a string contains only alphabetic characters (A-Z, a-z).
isAlpha("HelloWorld");
isAlpha("Hello123");
isAlphaNumeric
Checks if a string contains only alphanumeric characters (A-Z, a-z, 0-9).
isAlphaNumeric("Hello01");
isAlphaNumeric("1234567890");
Reverse
Reverses the sequence of characters in given string.
reverse('bad')
Build
npm run build
License
The MIT License. Full License is here