Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Small JavaScript library for replacing string literals, regular expressions and comments in JavaScript syntax.
JavaScript HTML
Failed to load latest commit information.
dist Version update
lib Version update
predefs/src Version update
spec Refactoring
.editorconfig Some updates
.gitattributes Configs update
.gitignore Hotfix
.jscsrc Small update
.travis.yml Version update
.yaspellerrc Hotfix
CODE_OF_CONDUCT.md Some updates
LICENSE Added new year
README.md Small update
README.ru.md Small update
bower.json Version update
externs.js Обновление
gulpfile.js Version update
package.json Version update

README.md

Escaper

Escaper is a small JavaScript library for replacing string literals, regular expressions and comments in JavaScript syntax.

Russian documentation

NPM version NPM dependencies 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

var str = '"foo" 1 + /foo/ + 2 /* 1 */ 3',
    content = [];

// __ESCAPER_QUOT__0_ 1 + __ESCAPER_QUOT__1_ + 2 __ESCAPER_QUOT__2_ 3
str = Escaper.replace(str, true, content);

// "foo" 1 + /foo/ + 2 /* 1 */ 3
Escaper.paste(str, content);

API

Escaper.replace(str, opt_withComment, opt_quotContent)

The method replaces all found blocks ' ... ', " ... ", ` ... `, / ... /, // ..., /* ... */ to __ESCAPER_QUOT__number_ in a string and returns a new string.

Arguments

  • string str — the source string;
  • (Object|boolean)= opt_withCommentsOrParams = false — parameters:
{
  '@all'     : true, // Replaces all found matches
  '@comments': true, // Replaces all kinds of comments
  '@strings' : true, // Replaces all kinds of string literals
  '@literals': true, // Replaces all kinds of string literals
                     // and regular expressions

  "'"        : true,
  '"'        : true,
  '`'        : true,
  '/'        : true,
  '//'       : true,
  '/*'       : true,
  '/**'      : true,
  '/*!'      : true
}

If a parameter value is set to -1, then all found matches will be removed from the final string, or if the value will be set to true/false they will be included/excluded.

If parameter opt_withCommentsOrParams is boolean:

true  // Replaces all found matches
false // Replaces all kinds of string literals and regular expressions
  • Array= opt_quotContent = Escaper.quotContent — an array for matches.

@return {string}

Escaper.paste(str, opt_quotContent)

The method replaces all found blocks __ESCAPER_QUOT__number_ to real content in a string and returns a new string.

Arguments

  • string str — the source string;
  • Array= opt_quotContent = Escaper.quotContent — an array of matches.

@return {string}

License

The MIT License.

Something went wrong with that request. Please try again.