Newtonian Physics Mockumentary

    TypeScript icon, indicating that this package has built-in type declarations

    1.1.2 • Public • Published


    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.

    NPM version Known Vulnerabilities npm NPM downloads issues license Gitter


    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';

    In the browser you can also use the unpkg script like so:

    <script type="module" src=""></script>


    Please see the files in the docs directory:


    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.

    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.

    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.

    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


    npm i stringops

    DownloadsWeekly Downloads






    Unpacked Size

    136 kB

    Total Files


    Last publish


    • robert.corponoi