Package Exports
- stringops
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (stringops) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
StringOps
StringOps is made to fill in the gaps of String methods in JavaScript that currently exist in other languages but not yet in JavaScript.
If using ES6 imports then you can just import the methods you need to save space.
Installation
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 = require('stringops');
Or if you're developing in an environment that allows the use of imports, you can use:
// Webpack
import * as stringoops from 'stringops';
// Browser
import * as stringops from './path/to/stringops.js';
Or even further you can import just the methods you need:
import { ltrim, ucwords, nthIndexOf } from './path/to/stringops.js';
Documentation
Please see the files in the docs
directory:
API
A breakdown of all of the API can be found below:
Conversion Functions
bin2Hex(bin) Converts a binary string to hexadecimal.
hex2Bin(hex) Converts a hexadecimal to a binary string.
Search/Find Functions
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.
Transform Functions
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.
Tests
To run all of the available tests for stringops use:
$ npm run test