A lightweight and versatile String Utility Package for Node.js & Browser.
npm install @full-pack/string-packconst{ ... }=require('@full-pack/string-pack');import{ ... }from'@full-pack/string-pack';Adds padding to given string.
Pads the start of a string with a specified fill string a certain number of times.
// Basic UsagepadStart('hello','abc',3)// abcabcabchello// Limiting total lengthpadStart('hello','abc',3,8)// abchelloPads the end of a string with a specified fill string a certain number of times.
// Basic UsagepadEnd('hello','abc',3);// helloabcabcabc// Limiting total lengthpadEnd('hello','abc',3,8);// helloabcPads a string with a specified fill string a certain number of times on both ends.
// Basic usagepadBidirectional('hello','*',{repeatCount: 2});// '**hello**'// Limiting total lengthpadBidirectional('world','-',{repeatCount: 3,maxLen: 10});// '--world---'// Controlling padding distributionpadBidirectional('example','*',{repeatCount: 2,maxLen: 10,bias: PaddingBias.START});// '**example*'Merges an array of strings into a single string using a specified separator.
merge('-','apple','orange','banana');// 'apple-orange-banana'merge(true,'apple','orange');// 'apple orange'merge(false,'apple','orange','banana');// 'appleorangebanana'Performs a strict comparison between two strings.
compare("hello","hello");// truecompare("abc","ABC");// falsePerforms a case-insensitive loose comparison between two strings.
looseCompare("hello","HELLO");// truelooseCompare('abc','123');// falseCapitalizes the first letter of a word in a string.
capitalizeInitial('hello');// 'Hello'capitalizeInitial(':> hello');// ':> Hello'Capitalizes the first letter of each word in a given string.
capitalizeWords('hello world');// 'Hello World'capitalizeWords('Sphinx of black quartz:-judge my vow');// 'Sphinx Of Black Quartz:-Judge My Vow'Converts a string to snake_case format.
snakeCase('hello WorLd');// 'hello_world'snakeCase('from-kebab-case');// 'from_kebab_case'snakeCase('snake Case With Numbers123',true);// 'snake_case_with_numbers_one_two_three'Converts a string to kebab-case format.
kebabCase('h3llo WoRld');// 'h3llo-world'kebabCase('from_snake_case');// 'from-snake-case'kebabCase('kebab Case With Numbers123',true);// 'kebab-case-with-numbers-one-two-three'Converts a string to camelCase format.
camelCase('hello WoRld');// 'helloWorld'camelCase('Test CaSe ExamplE');// 'testCaseExample'camelCase('camel Case With Numbers123');// 'camelCaseWithNumbers'Converts a string to PascalCase format.
pascalCase('hello WoRld');// 'HelloWorld'pascalCase('Test CaSe ExamplE');// 'TestCaseExample'pascalCase('pasCal Case With Numbers123');// 'PascalCaseWithNumbers'Checks if a string is in snake_case format.
// ValidisSnakeCase('snake_case_example');// trueisSnakeCase('hello_world');// true// Valid with alphanumeric flagisSnakeCase('with_1234',true);// trueisSnakeCase('pi_3_14',true);// true// InvalidisSnakeCase('123at_start');// falseisSnakeCase(' no_space_allowed');// falseisSnakeCase('no_CAPS');// falseChecks if a string is in kebab-case format.
// ValidisKebabCase('kebab-case-example');// trueisKebabCase('hello-world');// true// Valid with alphanumeric flagisKebabCase('with-1234',true);// trueisKebabCase('pi-3-14',true);// true// InvalidisKebabCase('123at-start');// falseisKebabCase(' no-space-allowed');// falseisKebabCase('no-CAPS');// falseChecks if a string is in camelCase format.
// ValidisCamelCase('camelCaseExample');// trueisCamelCase('helloWorld');// true// InvalidisCamelCase('CAMEL');// falseisCamelCase(' noSpaceAllowed');// falseisCamelCase('withThe1234');// falseChecks if a string is in PascalCase format.
// ValidisPascalCase('PascalCaseExample');// trueisPascalCase('HelloWorld');// true// InvalidisPascalCase('PASCAL');// falseisPascalCase(' NoSpaceAllowed');;// falseisPascalCase('WithThe1234');// falseCompares two strings or regions for equality.
// Matching identical stringsregionMatch('hello','hello');// true// Matching identical regions in stringsconststr1={str: 'hello world',start: 0,end: 5};conststr2={str: 'hello there',start: 0,end: 5};regionMatch(str1,str2);// true// ORregionMatch('hello world','hello there',0,5)// true// Not matching regionsregionMatch('hello world','hello there',6,11);// falsePerforms a loose comparison of two strings or regions for equality.
// Loose matching identical stringslooseRegionMatch('hello','HeLLo');// true// Loose matching identical regions in stringsconststr1={str: ' hellO world',start: 1,end: 6};conststr2={str: 'HelLo there',start: 0,end: 5};looseRegionMatch(str1,str2);// trueChecks if a string contains only alphabetic characters (A-Z, a-z).
isAlpha("HelloWorld");// trueisAlpha("Hello123");// falseChecks if a string contains only alphanumeric characters (A-Z, a-z, 0-9).
isAlphaNumeric("Hello01");// trueisAlphaNumeric("1234567890");// falseReverses the sequence of characters in given string.
reverse('bad')// 'dab'Full documentation here
npm run build
The MIT License. Full License is here
