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 🙏

© 2025 – Pkg Stats / Ryan Hefner

jstring

v1.3.0

Published

A Node.js library, designed to simplify work with string validation and sanitization.

Downloads

19

Readme

jstring

Build Status A Node.js library, designed to simplify work with string validation and sanitization.

Installation

npm install jstring

When should I use jstring?

You need deal with string validation or sanitization in your Node.js project.

Installation

var jstring = require('jstring');

Usage

handleString(string, task)

Main sanitization method, that takes string and task object, and return string after processing. (All jstring methods have public access, and You can use them direct. This method is developed for convenience).

string

Source string.

task

A object, that contains necessary functions and their parameters. {function: [param], function: [param]} Can be used with: removeTags; cut;

return

String processed.

Example

jstring.handleString('Foo <Bar>Buzz', { cut: 6,
                                        removeTags:null,
                                        replace: ['Fo', 'FO', true]
                                      });
//return: FOo Bu

removeTags(string[, except])

Removes all <> and &lt;&gt; elements of the string.

string

Source string.

except

A string, or array, that contains exclusion tag names. (Notice that closing tags is added automatically. For example if you pass 'div' as except - tag </div> will not be deleted.)

return

String processed.

Example

jstring.removeTags('Foo <Bar><Buzz>');
//return: Foo
jstring.removeTags('Foo <Bar><Buzz>', Bar);
//return: Foo <Bar>
jstring.removeTags('Foo &lt;Bar&gt;<Buzz>', Bar);
//return: Foo

cut(string, length)

Cuts the string from start to length.

string

Source string.

length

The length by which the source string will be cut including.

return

String processed.

Example

jstring.cut('Foo <Bar><Buzz>', 9);
//return: Foo <Bar>

toLow(string)

Just a wrapper over toLowerCase method, to allow use it in handleString method.

string

Source string.

return

String processed.

Example

jstring.toLow('Foo Bar');
//return: foo bar

toUp(string)

Just a wrapper over toUpperCase method, to allow use it in handleString method.

string

Source string.

return

String processed.

Example

jstring.toUp('Foo Bar');
//return: FOO BAR

capitalize(string)

Makes first character of the string capitalized.

string

Source string.

return

String processed.

Example

jstring.capitalize('foo Bar');
//return: Foo Bar

minifyWhitespace(string)

Removes extra whitespace.

string

Source string.

return

String processed.

Example

jstring.minifyWhitespace('Foo   Bar  Buzz');
//return: Foo Bar Buzz

replace(string, [searchString, replaceString[, caseStrict]])

Replaces substring in main string on new string.

string

Source string.

searchString

String, that need to be replaced with replaceString.

replaceString

String, that need to be placed instead searchString.

caseStrict

Boolean if replacement should be done strict by case sensitivity (true if case of searchString is matters).

return

String processed.

Example

jstring.replace('Foo Bar foo', ['foo', 'buzz']);
//return: buzz Bar foo
jstring.replace('Foo Bar foo', ['foo', 'buzz', true]);
//return: Foo Bar buzz

replaceAll(string, [searchString, replaceString[, caseStrict]])

Replaces all occurrences of substring in main string on new string.

string

Source string.

searchString

Strings, that need to be replaced with replaceString.

replaceString

String, that need to be placed instead searchString.

caseStrict

Boolean if replacement should be done strict by case sensitivity (true if case of searchString is matters).

return

String processed.

Example

jstring.replace('Foo Bar foo', ['foo', 'buzz']);
//return: buzz Bar buzz
jstring.replace('Foo Bar foo', ['foo', 'buzz', true]);
//return: Foo Bar buzz

left(string, length)

Returns left part of string with length.

string

Source string.

length

Length of string, that need to be cut from start.

return

String processed.

Example

jstring.left('Foo Bar foo', 3);
//return: Foo
jstring.left('Foo Bar foo', 5);
//return: Foo B

right(string, length)

Returns right part of string with length.

string

Source string.

length

Length of string, that need to be cut to end.

return

String processed.

Example

jstring.right('Foo Bar foo', 3);
//return: foo
jstring.right('Foo Bar foo', 5);
//return: r foo  

repeat(string, n)

Returns the string, repeated n times.

string

Source string.

n

Count of repeat times.

return

String processed.

Example

jstring.repeat('Foo', 3);
//return: FooFooFoo
jstring.repeat('Foo Bar', 2);
//return: Foo BarFoo Bar

forEach(string[, callback])

Iterate through every char of incoming string and call the callback function to it.

string

Source string.

callback(value, index)

Callback function, that will be called to each char of string.

value

Char of string.

index

Index of value in string.

Example

jstring.forEach('FooBar', function(value, index){
    console.log(value, index);
});
//outputs:
F 0
o 1
o 2
B 3
a 4
r 5

isAlpha(string)

Checks if the source string contains only letters.

string

Source string.

return

Boolean is the source string contains only letters.

Example

jstring.isAlpha('Foo <Bar><Buzz>');
//return: false
jstring.isAlpha('Foo BarBuzz');
//return: true

isAlphanumeric(string)

Checks if the source string contains only letters and numbers.

string

Source string.

return

Boolean is the source string contains only letters and numbers.

Example

jstring.isAlphanumeric('Foo <Bar><Buzz> 67');
//return: false
jstring.isAlphanumeric('Foo BarBuzz 67');
//return: true

isEmail(string)

Checks if the source string is a valid email.

string

Source string.

return

Boolean is the source string is a valid email.

Example

jstring.isEmail('[email protected]');
//return: true
jstring.isEmail('Foo Bar');
//return: false

isUpper(string, strict)

Checks if the source string is uppercase.

string

Source string.

strict

Set to true if test should be strict (return true only if all chars of string is uppercase).

return

Boolean is the source string is uppercase.

Example

jstring.isUpper('Foo Bar');
//return: true
jstring.isUpper('foo bar');
//return: false
jstring.isUpper('Foo Bar', true);
//return: false

isLower(string, strict)

Checks if the source string is lowercase.

string

Source string.

strict

Set to true if test should be strict (return true only if all chars of string is lowercase).

return

Boolean is the source string is lowercase.

Example

jstring.isLower('Foo Bar');
//return: true
jstring.isLower('FOO BAR');
//return: false
jstring.isLower('Foo Bar', true);
//return: false