npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

stringops

v1.1.2

Published

String functions you'll wish you had before.

Downloads

6

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.

NPM version Known Vulnerabilities npm NPM downloads Gitter

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

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

<script type="module" src="https://unpkg.com/stringops@latest/stringops.js"></script>

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.

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.

Tests

To run all of the available tests for stringops use:

$ npm run test