escaper
A small JavaScript library to replace string literals, regular expressions, and comments from the JavaScript syntax.
Last updated 5 years ago by kobezzza .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install escaper 
SYNC missed versions from official npm registry.

Escaper

Escaper is a small JavaScript library to replace string literals, regular expressions, and comments from the JavaScript syntax.

Russian documentation

NPM version NPM devDependencies Build Status Coverage Status

Supports:

  • ' ... '
  • " ... "
  • ` ... `, ` ... ${...} `
  • / ... /
  • // ..., //* ..., //! ..., //# ..., //@ ..., //$ ...
  • /* ... */, /** ... */, /*! ... */, /*# ... */, /*@ ... */, /*$ ... */

Install

https://raw.githubusercontent.com/kobezzza/Escaper/master/dist/escaper.min.js

or

npm install escaper

or

bower install escaper

or

git clone https://github.com/kobezzza/Escaper

Usage

const
  str = 'Hello "world" and \'friends\'',
  content = [];

// Replaces all found matches
// 'Hello __ESCAPER_QUOT__0_ and __ESCAPER_QUOT__1_'
Escaper.replace(str, content)

// Replaces only single quotes
// 'Hello "world" and __ESCAPER_QUOT__0_'
Escaper.replace(str, ["'"])

// Cuts all found matches
// 'Hello and '
Escaper.replace(str, -1)

// Replaces all and cuts single quotes
// 'Hello __ESCAPER_QUOT__0_ and '
Escaper.replace(str, {"'": -1})

// Replaces all but strings
// 'Hello __ESCAPER_QUOT__0_ and \'friends\''
Escaper.replace(str, {strings: false})

// Replaces all, but strings can be only single quotes
// 'Hello "world" and __ESCAPER_QUOT__0_'
Escaper.replace(str, {strings: ["'"]})

// Replaces all, but strings can be only single quotes and it will be cut
// 'Hello "world" and '
Escaper.replace(str, {strings: {"'": -1}})

// Replaces all found escape blocks to a real content
// 'Hello "world" and \'friends\''
Escaper.paste(str, content);

API

Escaper.replace(str, how?, store?): string

Replaces all found blocks ' ... ', " ... ", ` ... `, / ... /, // ..., /* ... */ to escape blocks from the specified string and returns a new string.

Arguments

  • string str — source string;
  • string[] | Record<string, string[] | Record<string, boolean | -1> | false | -1> | false | -1 how? — parameters:

Possible values

If a value is set to -1, then all found matches will be removed from the final string. If the value is set to boolean it will be replaced/passed.

// Label of replacement, by default __ESCAPER_QUOT__${pos}_
'label'

// Singleline comment
'singleComments'

// Multiline comments
'multComments'

// All kinds of comments
'comments'

// All kinds of strings
'strings'

// All kinds of literals (except strings and comments)
'literals'

// Literals
"'"
'"'
'`'
'/'
'//'
'//*'
'//!'
'//#'
'//@'
'//$'
'/*'
'/**'
'/*!'
'/*#'
'/*@'
'/*$'

The parameters can be specified as an array (escapes only explicitly specified sequences) or like an object (disables/excludes by a literal or group). Also, if you set the parameter value as -1, then all found sequences will be removed from the string.

  • string[] store = Escaper.content — store for matches.

Escaper.paste(str, store?, rgxp?): string

Replaces all found escape blocks to real content from the specified string and returns a new string.

Arguments

  • string str — source string;
  • string[] store = Escaper.content — store of matches;
  • RegExp rgxp? — RegExp to search, e.g. /__ESCAPER_QUOT__(\d+)_/g.

License

The MIT License.

Current Tags

  • 3.0.6                                ...           latest (5 years ago)

160 Versions

  • 3.0.6                                ...           5 years ago
  • 3.0.5                                ...           6 years ago
  • 3.0.4                                ...           6 years ago
  • 3.0.3                                ...           7 years ago
  • 3.0.2                                ...           7 years ago
  • 3.0.1                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 2.5.3                                ...           8 years ago
  • 2.5.2                                ...           9 years ago
  • 2.5.1                                ...           9 years ago
  • 2.5.0                                ...           9 years ago
  • 2.4.34                                ...           9 years ago
  • 2.4.33                                ...           9 years ago
  • 2.4.32                                ...           9 years ago
  • 2.4.31                                ...           10 years ago
  • 2.4.30                                ...           10 years ago
  • 2.4.29                                ...           10 years ago
  • 2.4.28                                ...           10 years ago
  • 2.4.27                                ...           10 years ago
  • 2.4.26                                ...           10 years ago
  • 2.4.25                                ...           10 years ago
  • 2.4.24                                ...           10 years ago
  • 2.4.23                                ...           10 years ago
  • 2.4.22                                ...           10 years ago
  • 2.4.21                                ...           10 years ago
  • 2.4.20                                ...           10 years ago
  • 2.4.19                                ...           10 years ago
  • 2.4.18                                ...           10 years ago
  • 2.4.17                                ...           10 years ago
  • 2.4.16                                ...           10 years ago
  • 2.4.15                                ...           10 years ago
  • 2.4.14                                ...           10 years ago
  • 2.4.13                                ...           10 years ago
  • 2.4.12                                ...           11 years ago
  • 2.4.11                                ...           11 years ago
  • 2.4.10                                ...           11 years ago
  • 2.4.9                                ...           11 years ago
  • 2.4.8                                ...           11 years ago
  • 2.4.7                                ...           11 years ago
  • 2.4.6                                ...           11 years ago
  • 2.4.5                                ...           11 years ago
  • 2.4.4                                ...           11 years ago
  • 2.4.3                                ...           11 years ago
  • 2.4.2                                ...           11 years ago
  • 2.4.1                                ...           11 years ago
  • 2.4.0                                ...           11 years ago
  • 2.3.9                                ...           11 years ago
  • 2.3.8                                ...           11 years ago
  • 2.3.7                                ...           11 years ago
  • 2.3.6                                ...           11 years ago
  • 2.3.5                                ...           11 years ago
  • 2.3.4                                ...           11 years ago
  • 2.3.3                                ...           11 years ago
  • 2.3.2                                ...           11 years ago
  • 2.3.1                                ...           11 years ago
  • 2.3.0                                ...           11 years ago
  • 2.2.25                                ...           11 years ago
  • 2.2.24                                ...           11 years ago
  • 2.2.23                                ...           11 years ago
  • 2.2.22                                ...           11 years ago
  • 2.2.21                                ...           11 years ago
  • 2.2.20                                ...           11 years ago
  • 2.2.19                                ...           11 years ago
  • 2.2.18                                ...           11 years ago
  • 2.2.17                                ...           11 years ago
  • 2.2.16                                ...           11 years ago
  • 2.2.15                                ...           11 years ago
  • 2.2.14                                ...           11 years ago
  • 2.2.13                                ...           11 years ago
  • 2.2.12                                ...           11 years ago
  • 2.2.11                                ...           11 years ago
  • 2.2.10                                ...           11 years ago
  • 2.2.9                                ...           11 years ago
  • 2.2.8                                ...           11 years ago
  • 2.2.7                                ...           11 years ago
  • 2.2.6                                ...           11 years ago
  • 2.2.5                                ...           11 years ago
  • 2.2.4                                ...           11 years ago
  • 2.2.3                                ...           11 years ago
  • 2.2.2                                ...           11 years ago
  • 2.2.1                                ...           11 years ago
  • 2.2.0                                ...           11 years ago
  • 2.1.18                                ...           11 years ago
  • 2.1.17                                ...           11 years ago
  • 2.1.16                                ...           11 years ago
  • 2.1.15                                ...           11 years ago
  • 2.1.14                                ...           11 years ago
  • 2.1.13                                ...           11 years ago
  • 2.1.11                                ...           11 years ago
  • 2.1.10                                ...           11 years ago
  • 2.1.9                                ...           11 years ago
  • 2.1.8                                ...           11 years ago
  • 2.1.7                                ...           11 years ago
  • 2.1.6                                ...           11 years ago
  • 2.1.5                                ...           11 years ago
  • 2.1.4                                ...           11 years ago
  • 2.1.3                                ...           11 years ago
  • 2.1.2                                ...           11 years ago
  • 2.1.1                                ...           11 years ago
  • 2.1.0                                ...           11 years ago
  • 2.0.8                                ...           11 years ago
  • 2.0.7                                ...           11 years ago
  • 2.0.6                                ...           11 years ago
  • 2.0.5                                ...           11 years ago
  • 2.0.4                                ...           11 years ago
  • 2.0.3                                ...           11 years ago
  • 2.0.2                                ...           11 years ago
  • 2.0.1                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.4.18                                ...           11 years ago
  • 1.4.17                                ...           11 years ago
  • 1.4.16                                ...           11 years ago
  • 1.4.15                                ...           11 years ago
  • 1.4.14                                ...           11 years ago
  • 1.4.13                                ...           11 years ago
  • 1.4.12                                ...           11 years ago
  • 1.4.11                                ...           11 years ago
  • 1.4.10                                ...           11 years ago
  • 1.4.9                                ...           11 years ago
  • 1.4.8                                ...           11 years ago
  • 1.4.7                                ...           11 years ago
  • 1.4.6                                ...           11 years ago
  • 1.4.5                                ...           11 years ago
  • 1.4.4                                ...           11 years ago
  • 1.4.3                                ...           11 years ago
  • 1.4.2                                ...           12 years ago
  • 1.4.1                                ...           12 years ago
  • 1.4.0                                ...           12 years ago
  • 1.3.0                                ...           12 years ago
  • 1.2.6                                ...           12 years ago
  • 1.2.5                                ...           12 years ago
  • 1.2.4                                ...           12 years ago
  • 1.2.3                                ...           12 years ago
  • 1.2.2                                ...           12 years ago
  • 1.2.1                                ...           12 years ago
  • 1.2.0                                ...           12 years ago
  • 1.1.6                                ...           12 years ago
  • 1.1.5                                ...           12 years ago
  • 1.1.4                                ...           12 years ago
  • 1.1.3                                ...           12 years ago
  • 1.1.2                                ...           12 years ago
  • 1.1.1                                ...           12 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.8                                ...           12 years ago
  • 1.0.7                                ...           12 years ago
  • 1.0.6                                ...           12 years ago
  • 1.0.5                                ...           12 years ago
  • 1.0.4                                ...           12 years ago
  • 1.0.3                                ...           12 years ago
  • 1.0.2                                ...           12 years ago
  • 1.0.1                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.9                                ...           12 years ago
  • 0.0.8                                ...           12 years ago
  • 0.0.7                                ...           13 years ago
  • 0.0.5                                ...           13 years ago
  • 0.0.4                                ...           13 years ago
  • 0.0.3                                ...           13 years ago
  • 0.0.2                                ...           13 years ago
  • 0.0.1                                ...           13 years ago
Downloads
Today 0
This Week 7
This Month 44
Last Day 2
Last Week 96
Last Month 59
Dependencies (0)
None
Dev Dependencies (33)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |