If using ES6 imports then you can just import the methods you need to save space.
StringOps is available as both a Node.js package available through NPM and as an ES6 module.
To download StringOps through NPM, use the following command:
$ npm install stringops
From here you can either require the package:
const stringops = ;
Or if you're developing in an environment that allows the use of imports, you can use:
// Webpack;// Browser;
Or even further you can import just the methods you need:
In the browser you can also use the unpkg script like so:
Please see the files in the
A breakdown of all of the API can be found below:
bin2Hex(bin) Converts a binary string to hexadecimal.
hex2Bin(hex) Converts a hexadecimal to a binary string.
count(haystack, needle) Count the number of occurances that a substring is found in a string.
countChars(str) Counts the number of times each character appears in the string.
nthIndexOf(str, sub, occurance) Find the position of the nth occurance of a substring in a string.
levenshtein(str1, str2) Calculates the Levenshtein distance between two strings.
isAlnum(str) hecks to see if all of the characters in the text are alphanumeric.
isAlpha(str) Checks to see if all of the characters in the text are letters.
ucword(str) Capitalize the first letter of the first word.
ucwords(str) Capitalizes the first letter of every word.
lcword(str) Make the first letter of the first word lowercase.
lcwords(str) Make the first letters of each word lowercase.
wordwrap(str) Wraps a string to a given number of characters.
reverse(str) Reverses a string.
ltrim(str) Trim all whitespace from the beginning of a string.
rtrim(str) Trim all whitespace from the end of a string.
money(amount, [locale]) Formats a string into a representation of a type of currency. Currently only US/GB is supported is supported but more will be added with later updates.
pad(str, sub, [amount], [side]) Pads a string with a substring on one or both sides.
center(str, length, [char]) Makes a string take up a certain amount of characters with the provided string in the center.
swapcase(str) Swaps the case of each letter in a string.
To run all of the available tests for stringops use:
$ npm run test