New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

reg-escape

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reg-escape

Escapes special characters in a string so it can be used with RegExp

latest
Source
npmnpm
Version
0.2.1
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

reg-escape

Escapes special characters in a string so it can be used with RegExp

###usage

install: npm install --save reg-escape

reg-escape inserts escape characters before every RegExp special character in a given string so it can be used to test against in a regular expression.


var regEscape= require( 'reg-escape' );

var passwordCharacters= "~!@#$%^&*()_+|}{][\":?><`1234567890-=qwertyuiopasdfghjkl;'zxcvbnm,./";

// define passwords that can only exist of passwordCharacters,
// minimal 8, maximum 20 chars
var passwordLegit= new RegExp( '^['+ regEscape(passwordCharacters)+ ']{8,20}$' );
console.log( passwordLegit );
// /^[~!@#\$%\^\&\*\(\)_\+\|}{\]\[":\?\>\<`1234567890\-=qwertyuiopasdfghjkl;'zxcvbnm,\.\/]{8,20}$/

// the white space is not allowed, this will fail
var password= 'my./$^pass[ ]word';

console.log( passwordLegit.test(password) );
// false

console.log( passwordLegit.test('my./$^pass[]word'))
// true

<array> regEscape.SPECIAL_CHARS are the special characters used, you could modify this if needed.

###licence

MIT

Keywords

regescape

FAQs

Package last updated on 28 Oct 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts