escaper

WebJar for escaper

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

escaper
Последняя версия

Последняя версия

2.5.3
Дата

Дата

Тип

Тип

jar
Описание

Описание

escaper
WebJar for escaper
Ссылка на сайт

Ссылка на сайт

http://webjars.org
Система контроля версий

Система контроля версий

https://github.com/kobezzza/Escaper

Скачать escaper

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/escaper/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>escaper</artifactId>
    <version>2.5.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/escaper/
implementation 'org.webjars.npm:escaper:2.5.3'
// https://jarcasting.com/artifacts/org.webjars.npm/escaper/
implementation ("org.webjars.npm:escaper:2.5.3")
'org.webjars.npm:escaper:jar:2.5.3'
<dependency org="org.webjars.npm" name="escaper" rev="2.5.3">
  <artifact name="escaper" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='escaper', version='2.5.3')
)
libraryDependencies += "org.webjars.npm" % "escaper" % "2.5.3"
[org.webjars.npm/escaper "2.5.3"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Escaper

Escaper is a small JavaScript library to replace string literals, regular expressions, and comments from 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 a 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.

Версии библиотеки

Версия
2.5.3