add lisp packages

This commit is contained in:
2020-12-05 21:29:49 +01:00
parent 85e20365ae
commit a6e2395755
7272 changed files with 1363243 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014-2018 Andrey Kobets (kobezzza)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,126 @@
Escaper
=======
Escaper is a small JavaScript library for replacing string literals, regular expressions and comments in JavaScript syntax.
[Russian documentation](https://github.com/kobezzza/Escaper/blob/master/README.ru.md)
[![NPM version](http://img.shields.io/npm/v/escaper.svg?style=flat)](http://badge.fury.io/js/escaper)
[![NPM devDependencies](http://img.shields.io/david/dev/kobezzza/Escaper.svg?style=flat)](https://david-dm.org/kobezzza/Escaper?type=dev)
[![Build Status](http://img.shields.io/travis/kobezzza/Escaper.svg?style=flat&branch=master)](https://travis-ci.org/kobezzza/Escaper)
[![Coverage Status](http://img.shields.io/coveralls/kobezzza/Escaper.svg?style=flat)](https://coveralls.io/r/kobezzza/Escaper?branch=master)
**Supports:**
* `' ... '`
* `" ... "`
* `` ` ... ` ``, `` ` ... ${...} ` ``
* `/ ... /`
* `// ...`, `//* ...`, `//! ...`, `//# ...`, `//@ ...`, `//$ ...`
* `/* ... */`, `/** ... */`, `/*! ... */`, `/*# ... */`, `/*@ ... */`, `/*$ ... */`
## Install
https://raw.githubusercontent.com/kobezzza/Escaper/master/dist/escaper.min.js
or
```bash
npm install escaper
```
or
```bash
bower install escaper
```
or
```bash
git clone https://github.com/kobezzza/Escaper
```
## Usage
```js
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_content)
The method replaces all found blocks `' ... '`, `" ... "`, `` ` ... ` ``, `/ ... /`, `// ...`, `/* ... */` to
`__ESCAPER_QUOT__number_` in a string and returns a new string.
**Arguments**
* `string` `str` — source string;
* `(Object|boolean)=` `opt_withCommentsOrParams = false` — parameters:
```js
{
// The template for replacement
'@label' : '__ESCAPER_QUOT__${pos}_',
'@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,
'//@' : 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:
```js
true // Replaces all found matches
false // Replaces all kinds of string literals and regular expressions
```
* `Array=` `opt_content = Escaper.content` — array for matches.
`@return {string}`
### Escaper.paste(str, opt_content)
The method replaces all found blocks `__ESCAPER_QUOT__number_` to real content in a string and returns a new string.
**Arguments**
* `string` `str` — source string;
* `Array=` `opt_content = Escaper.content` — array of matches;
* `RegExp=` `opt_rgxp` — RegExp for searching, e.g. `/__ESCAPER_QUOT__(\d+)_/g`.
`@return {string}`
## [License](https://github.com/kobezzza/Escaper/blob/master/LICENSE)
The MIT License.

View File

@@ -0,0 +1,126 @@
Escaper
=======
Библиотека для «экранирования» литералов строк, регулярных выражений и комментариев в синтаксисе JavaScript.
[Документация на английском](https://github.com/kobezzza/Escaper/blob/master/README.md)
[![NPM version](http://img.shields.io/npm/v/escaper.svg?style=flat)](http://badge.fury.io/js/escaper)
[![NPM devDependencies](http://img.shields.io/david/dev/kobezzza/Escaper.svg?style=flat)](https://david-dm.org/kobezzza/Escaper?type=dev)
[![Build Status](http://img.shields.io/travis/kobezzza/Escaper.svg?style=flat&branch=master)](https://travis-ci.org/kobezzza/Escaper)
[![Coverage Status](http://img.shields.io/coveralls/kobezzza/Escaper.svg?style=flat)](https://coveralls.io/r/kobezzza/Escaper?branch=master)
**Поддерживаются литералы:**
* `' ... '`
* `" ... "`
* `` ` ... ` ``, `` ` ... ${...} ` ``
* `/ ... /`
* `// ...`, `//* ...`, `//! ...`, `//# ...`, `//@ ...`, `//$ ...`
* `/* ... */`, `/** ... */`, `/*! ... */`, `/*# ... */`, `/*@ ... */`, `/*$ ... */`
## Установка
https://raw.githubusercontent.com/kobezzza/Escaper/master/dist/escaper.min.js
или
```bash
npm install escaper
```
или
```bash
bower install escaper
```
или
```bash
git clone https://github.com/kobezzza/Escaper
```
## Использование
```js
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_content)
Заметить блоки вида `' ... '`, `" ... "`, `` ` ... ` ``, `/ ... /`, `// ...`, `/* ... */` на
`__ESCAPER_QUOT__номер_` в указанной строке и вернуть новую строку.
**Аргументы**
* `string` `str` — исходная строка;
* `(Object|boolean)=` `opt_withCommentsOrParams = false` — таблица вырезаемых последовательностей:
Если установить значение параметру `-1`, то последовательность будет удаляться,
т.е. без возможности обратной замены, иначе `true`/`false` — включить/исключить последовательность.
```js
{
// Шаблон замены
'@label' : '__ESCAPER_QUOT__${pos}_',
'@all' : true, // Вырезаются все последовательности
'@comments': true, // Вырезаются все виды комментариев
'@strings' : true, // Вырезаются все виды литералов строк
'@literals': true, // Вырезаются все виды литералов строк
// и регулярных выражений
"'" : true,
'"' : true,
'`' : true,
'/' : true,
'//' : true,
'//*' : true,
'//!' : true,
'//#' : true,
'//@' : true,
'//$' : true,
'/*' : true,
'/**' : true,
'/*!' : true,
'/*#' : true,
'/*@' : true,
'/*$' : true
}
```
ИЛИ если `opt_withCommentsOrParams` — логическое значение, то
```js
true // Вырезаются литералы с комментариями
false // Вырезаются одни литералы
```
* `Array=` `opt_content = Escaper.content` — стек содержимого.
`@return {string}`
### Escaper.paste(str, opt_content)
Заметить `__ESCAPER_QUOT__номер_` в указанной строке на реальное содержимое и вернуть новую строку.
**Аргументы**
* `string` `str` — исходная строка;
* `Array=` `opt_content = Escaper.content` — стек содержимого;
* `RegExp=` `opt_rgxp` — регулярное выражение для поиска, например `/__ESCAPER_QUOT__(\d+)_/g`.
`@return {string}`
## [Лицензия](https://github.com/kobezzza/Escaper/blob/master/LICENSE)
The MIT License.

View File

@@ -0,0 +1,474 @@
/*!
* Escaper v2.5.3
* https://github.com/kobezzza/Escaper
*
* Released under the MIT license
* https://github.com/kobezzza/Escaper/blob/master/LICENSE
*
* Date: Tue, 23 Jan 2018 15:58:45 GMT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define('Escaper', ['exports'], factory) :
(factory((global.Escaper = {})));
}(this, (function (exports) { 'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
var Escaper = void 0;
var escaper = Escaper = {
VERSION: [2, 5, 3],
content: [],
cache: {},
snakeskinRgxp: null,
symbols: null,
replace: replace,
paste: paste
};
var stringLiterals = {
'"': true,
'\'': true,
'`': true
};
var literals = {
'/': true
};
for (var key in stringLiterals) {
if (!stringLiterals.hasOwnProperty(key)) {
break;
}
literals[key] = true;
}
var singleComments = {
'//': true,
'//*': true,
'//!': true,
'//#': true,
'//@': true,
'//$': true
};
var multComments = {
'/*': true,
'/**': true,
'/*!': true,
'/*#': true,
'/*@': true,
'/*$': true
};
var keyArr = [];
var finalMap = {};
for (var _key in literals) {
if (!literals.hasOwnProperty(_key)) {
break;
}
keyArr.push(_key);
finalMap[_key] = true;
}
for (var _key2 in singleComments) {
if (!singleComments.hasOwnProperty(_key2)) {
break;
}
keyArr.push(_key2);
finalMap[_key2] = true;
}
for (var _key3 in multComments) {
if (!multComments.hasOwnProperty(_key3)) {
break;
}
keyArr.push(_key3);
finalMap[_key3] = true;
}
var rgxpFlags = [];
var rgxpFlagsMap = {
'g': true,
'm': true,
'i': true,
'y': true,
'u': true
};
for (var _key4 in rgxpFlagsMap) {
if (!rgxpFlagsMap.hasOwnProperty(_key4)) {
break;
}
rgxpFlags.push(_key4);
}
var escapeEndMap = {
'-': true,
'+': true,
'*': true,
'%': true,
'~': true,
'>': true,
'<': true,
'^': true,
',': true,
';': true,
'=': true,
'|': true,
'&': true,
'!': true,
'?': true,
':': true,
'(': true,
'{': true,
'[': true
};
var escapeEndWordMap = {
'return': true,
'yield': true,
'await': true,
'typeof': true,
'void': true,
'instanceof': true,
'delete': true,
'in': true,
'new': true,
'of': true
};
/**
* @param {!Object} obj
* @param {!Object} p
* @param {(boolean|number)} val
*/
function mix(obj, p, val) {
for (var _key5 in obj) {
if (!obj.hasOwnProperty(_key5)) {
break;
}
if (_key5 in p === false) {
p[_key5] = val;
}
}
}
var symbols = void 0;
var snakeskinRgxp = void 0;
var uSRgxp = /[^\s/]/;
var wRgxp = /[a-z]/;
var sRgxp = /\s/;
var nRgxp = /[\r\n]/;
var posRgxp = /\${pos}/g;
var objMap = {
'object': true,
'function': true
};
/**
* Replaces all found blocks ' ... ', " ... ", ` ... `, / ... /, // ..., /* ... *\/ to
* __ESCAPER_QUOT__number_ in a string and returns a new string
*
* @param {string} str - source string
* @param {(Object<string, boolean>|boolean)=} [opt_withCommentsOrParams=false] - parameters:
*
* (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)
*
* *) @label - template for replacement, e.g. __ESCAPER_QUOT__${pos}_
* *) @all - replaces all found matches
* *) @comments - replaces all kinds of comments
* *) @strings - replaces all kinds of string literals
* *) @literals - replaces all kinds of string literals and regular expressions
* *) `
* *) '
* *) "
* *) /
* *) //
* *) //*
* *) //!
* *) //#
* *) //@
* *) //$
* *) /*
* *) /**
* *) /*!
* *) /*#
* *) /*@
* *) /*$
*
* OR if the value is boolean, then will be replaced all found comments (true) / literals (false)
*
* @param {Array=} [opt_content=Escaper.content] - array for matches
* @param {?boolean=} [opt_snakeskin] - private parameter for using with Snakeskin
* @return {string}
*/
function replace(str, opt_withCommentsOrParams, opt_content, opt_snakeskin) {
symbols = symbols || Escaper.symbols || 'a-z';
snakeskinRgxp = snakeskinRgxp || Escaper.snakeskinRgxp || new RegExp('[!$' + symbols + '_]', 'i');
var _Escaper = Escaper,
cache = _Escaper.cache,
content = _Escaper.content;
var isObj = Boolean(opt_withCommentsOrParams && objMap[typeof opt_withCommentsOrParams === 'undefined' ? 'undefined' : _typeof(opt_withCommentsOrParams)]);
var p = isObj ? Object(opt_withCommentsOrParams) : {};
function mark(pos) {
if (p['@label']) {
return p['@label'].replace(posRgxp, pos);
}
return '__ESCAPER_QUOT__' + pos + '_';
}
var withComments = false;
if (typeof opt_withCommentsOrParams === 'boolean') {
withComments = Boolean(opt_withCommentsOrParams);
}
if ('@comments' in p) {
mix(multComments, p, p['@comments']);
mix(singleComments, p, p['@comments']);
delete p['@comments'];
}
if ('@strings' in p) {
mix(stringLiterals, p, p['@strings']);
delete p['@strings'];
}
if ('@literals' in p) {
mix(literals, p, p['@literals']);
delete p['@literals'];
}
if ('@all' in p) {
mix(finalMap, p, p['@all']);
delete p['@all'];
}
var cacheKey = '';
for (var i = -1; ++i < keyArr.length;) {
var el = keyArr[i];
if (multComments[el] || singleComments[el]) {
p[el] = withComments || p[el];
} else {
p[el] = p[el] || !isObj;
}
cacheKey += p[el] + ',';
}
var initStr = str,
stack = opt_content || content;
if (stack === content && cache[cacheKey] && cache[cacheKey][initStr]) {
return cache[cacheKey][initStr];
}
var begin = false,
end = true;
var escape = false,
comment = false;
var selectionStart = 0,
block = false;
var templateVar = 0,
filterStart = false;
var cut = void 0,
label = void 0;
var part = '',
rPart = '';
for (var _i = -1; ++_i < str.length;) {
var _el = str.charAt(_i);
var next = str.charAt(_i + 1),
word = str.substr(_i, 2),
extWord = str.substr(_i, 3);
if (!comment) {
if (!begin) {
if (_el === '/') {
if (singleComments[word] || multComments[word]) {
if (singleComments[extWord] || multComments[extWord]) {
comment = extWord;
} else {
comment = word;
}
}
if (comment) {
selectionStart = _i;
continue;
}
}
if (escapeEndMap[_el] || escapeEndWordMap[rPart]) {
end = true;
rPart = '';
} else if (uSRgxp.test(_el)) {
end = false;
}
if (wRgxp.test(_el)) {
part += _el;
} else {
rPart = part;
part = '';
}
var skip = false;
if (opt_snakeskin) {
if (_el === '|' && snakeskinRgxp.test(next)) {
filterStart = true;
end = false;
skip = true;
} else if (filterStart && sRgxp.test(_el)) {
filterStart = false;
end = true;
skip = true;
}
}
if (!skip) {
if (escapeEndMap[_el]) {
end = true;
} else if (uSRgxp.test(_el)) {
end = false;
}
}
}
// [] inside RegExp
if (begin === '/' && !escape) {
if (_el === '[') {
block = true;
} else if (_el === ']') {
block = false;
}
}
if (!begin && templateVar) {
if (_el === '}') {
templateVar--;
} else if (_el === '{') {
templateVar++;
}
if (!templateVar) {
_el = '`';
}
}
if (begin === '`' && !escape && word === '${') {
_el = '`';
_i++;
templateVar++;
}
if (finalMap[_el] && (_el !== '/' || end) && !begin) {
begin = _el;
selectionStart = _i;
} else if (begin && (_el === '\\' || escape)) {
escape = !escape;
} else if (finalMap[_el] && begin === _el && !escape && (begin !== '/' || !block)) {
if (_el === '/') {
for (var j = -1; ++j < rgxpFlags.length;) {
if (rgxpFlagsMap[str.charAt(_i + 1)]) {
_i++;
}
}
}
begin = false;
end = false;
if (p[_el]) {
cut = str.substring(selectionStart, _i + 1);
if (p[_el] === -1) {
label = '';
} else {
label = mark(stack.length);
stack.push(cut);
}
str = str.substring(0, selectionStart) + label + str.substring(_i + 1);
_i += label.length - cut.length;
}
}
} else if (nRgxp.test(next) && singleComments[comment] || multComments[_el + str.charAt(_i - 1)] && _i - selectionStart > 2 && multComments[comment]) {
if (p[comment]) {
cut = str.substring(selectionStart, _i + 1);
if (p[comment] === -1) {
label = '';
} else {
label = mark(stack.length);
stack.push(cut);
}
str = str.substring(0, selectionStart) + label + str.substring(_i + 1);
_i += label.length - cut.length;
}
comment = false;
}
}
if (stack === content) {
cache[cacheKey] = cache[cacheKey] || {};
cache[cacheKey][initStr] = str;
}
return str;
}
var pasteRgxp = /__ESCAPER_QUOT__(\d+)_/g;
/**
* Replaces all found blocks __ESCAPER_QUOT__number_ to real content in a string
* and returns a new string
*
* @param {string} str - source string
* @param {Array=} [opt_content=Escaper.content] - array of matches
* @param {RegExp=} [opt_rgxp] - RegExp for searching, e.g. /__ESCAPER_QUOT__(\d+)_/g
* @return {string}
*/
function paste(str, opt_content, opt_rgxp) {
return str.replace(opt_rgxp || pasteRgxp, function (str, pos) {
return (opt_content || Escaper.content)[pos];
});
}
exports['default'] = escaper;
exports.replace = replace;
exports.paste = paste;
Object.defineProperty(exports, '__esModule', { value: true });
})));

View File

@@ -0,0 +1,10 @@
/*! Escaper v2.5.3 | https://github.com/kobezzza/Escaper/blob/master/LICENSE */
(function(){'use strict';
function J(y){function D(b,d,l){for(var f in b){if(!b.hasOwnProperty(f))break;!1===f in d&&(d[f]=l)}}function O(b,d,l,y){function u(a){return c["@label"]?c["@label"].replace(T,a):"__ESCAPER_QUOT__"+a+"_"}K=K||E.symbols||"a-z";L=L||E.snakeskinRgxp||new RegExp("[!$"+K+"_]","i");var z=E,A=z.cache,z=z.content,B=!(!d||!U["undefined"===typeof d?"undefined":V(d)]),c=B?Object(d):{},m=!1;"boolean"===typeof d&&(m=!!d);"@comments"in c&&(D(f,c,c["@comments"]),D(q,c,c["@comments"]),delete c["@comments"]);"@strings"in
c&&(D(M,c,c["@strings"]),delete c["@strings"]);"@literals"in c&&(D(H,c,c["@literals"]),delete c["@literals"]);"@all"in c&&(D(C,c,c["@all"]),delete c["@all"]);d="";for(var k=-1;++k<F.length;){var g=F[k];c[g]=f[g]||q[g]?m||c[g]:c[g]||!B;d+=c[g]+","}B=b;l=l||z;if(l===z&&A[d]&&A[d][B])return A[d][B];for(var h=!1,p=!0,k=m=!1,g=0,t=!1,G=0,v=!1,n=void 0,a=void 0,w="",x="",e=-1;++e<b.length;){var a=b.charAt(e),n=b.charAt(e+1),I=b.substr(e,2),r=b.substr(e,3);if(!k){if(!h){if("/"===a){if(q[I]||f[I])k=q[r]||
f[r]?r:I;if(k){g=e;continue}}P[a]||W[x]?(p=!0,x=""):Q.test(a)&&(p=!1);X.test(a)?w+=a:(x=w,w="");r=!1;y&&("|"===a&&L.test(n)?(v=!0,p=!1,r=!0):v&&Y.test(a)&&(v=!1,r=p=!0));r||(P[a]?p=!0:Q.test(a)&&(p=!1))}"/"!==h||m||("["===a?t=!0:"]"===a&&(t=!1));!h&&G&&("}"===a?G--:"{"===a&&G++,G||(a="`"));"`"!==h||m||"${"!==I||(a="`",e++,G++);if(C[a]&&("/"!==a||p)&&!h)h=a,g=e;else if(h&&("\\"===a||m))m=!m;else if(C[a]&&h===a&&!m&&("/"!==h||!t)){if("/"===a)for(h=-1;++h<R.length;)N[b.charAt(e+1)]&&e++;p=h=!1;c[a]&&
(n=b.substring(g,e+1),-1===c[a]?a="":(a=u(l.length),l.push(n)),b=b.substring(0,g)+a+b.substring(e+1),e+=a.length-n.length)}}else if(Z.test(n)&&q[k]||f[a+b.charAt(e-1)]&&2<e-g&&f[k])c[k]&&(n=b.substring(g,e+1),-1===c[k]?a="":(a=u(l.length),l.push(n)),b=b.substring(0,g)+a+b.substring(e+1),e+=a.length-n.length),k=!1}l===z&&(A[d]=A[d]||{},A[d][B]=b);return b}function S(b,d,f){return b.replace(f||aa,function(b,f){return(d||E.content)[f]})}var V="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?
function(b){return typeof b}:function(b){return b&&"function"===typeof Symbol&&b.constructor===Symbol&&b!==Symbol.prototype?"symbol":typeof b},E=void 0,ba=E={VERSION:[2,5,3],content:[],cache:{},snakeskinRgxp:null,symbols:null,replace:O,paste:S},M={'"':!0,"'":!0,"`":!0},H={"/":!0},t;for(t in M){if(!M.hasOwnProperty(t))break;H[t]=!0}var q={"//":!0,"//*":!0,"//!":!0,"//#":!0,"//@":!0,"//$":!0},f={"/*":!0,"/**":!0,"/*!":!0,"/*#":!0,"/*@":!0,"/*$":!0},F=[],C={},u;for(u in H){if(!H.hasOwnProperty(u))break;
F.push(u);C[u]=!0}for(var v in q){if(!q.hasOwnProperty(v))break;F.push(v);C[v]=!0}for(var w in f){if(!f.hasOwnProperty(w))break;F.push(w);C[w]=!0}var R=[],N={g:!0,m:!0,i:!0,y:!0,u:!0},x;for(x in N){if(!N.hasOwnProperty(x))break;R.push(x)}var P={"-":!0,"+":!0,"*":!0,"%":!0,"~":!0,">":!0,"<":!0,"^":!0,",":!0,";":!0,"=":!0,"|":!0,"&":!0,"!":!0,"?":!0,":":!0,"(":!0,"{":!0,"[":!0},W={"return":!0,yield:!0,await:!0,"typeof":!0,"void":!0,"instanceof":!0,"delete":!0,"in":!0,"new":!0,of:!0},K=void 0,L=void 0,
Q=/[^\s/]/,X=/[a-z]/,Y=/\s/,Z=/[\r\n]/,T=/\${pos}/g,U={object:!0,"function":!0},aa=/__ESCAPER_QUOT__(\d+)_/g;y["default"]=ba;y.replace=O;y.paste=S;Object.defineProperty(y,"__esModule",{value:!0})}"object"===typeof exports&&"undefined"!==typeof module?J(exports):"function"===typeof define&&define.amd?define("Escaper",["exports"],J):J(this.Escaper={});
}).call(this);

View File

@@ -0,0 +1,44 @@
/*!
* Escaper
* https://github.com/kobezzza/Escaper
*
* Released under the MIT license
* https://github.com/kobezzza/Escaper/blob/master/LICENSE
*/
declare const Escaper: {
VERSION: any[];
cache: Record<string, string>;
content: string[];
snakeskinRgxp: RegExp | null;
symbols: string | null;
paste(str: string, content?: string[]);
replace(str: string, withComments?: boolean, content?: string[], snakeskin?: boolean);
replace(str: string, params: {
'@label'?: string,
'@all'?: boolean,
'@comments'?: boolean,
'@strings'?: boolean,
'@literals'?: boolean,
'`'?: boolean,
"'"?: boolean,
'"'?: boolean,
'/'?: boolean,
'//'?: boolean,
'//*'?: boolean,
'//!'?: boolean,
'//#'?: boolean,
'//@'?: boolean,
'//$'?: boolean,
'/*'?: boolean,
'/**'?: boolean,
'/*!'?: boolean,
'/*#'?: boolean,
'/*@'?: boolean,
'/*$'?: boolean
}, content?: string[], snakeskin?: boolean);
};
declare module 'escaper' {
export = Escaper;
}

View File

@@ -0,0 +1,41 @@
/*!
* Escaper
* https://github.com/kobezzza/Escaper
*
* Released under the MIT license
* https://github.com/kobezzza/Escaper/blob/master/LICENSE
*/
/** @const */
var Escaper = {
/** @type {!Array} */
VERSION: [],
/** @type {!Object} */
cache: [],
/** @type {!Array} */
content: [],
/** @type {?string} */
symbols: null,
/** @type {RegExp} */
snakeskinRgxp: null,
/**
* @param {string} str
* @param {(Object<string, boolean>|boolean)=} [opt_withCommentsOrParams]
* @param {Array=} [opt_content]
* @param {?boolean=} [opt_snakeskin]
* @return {string}
*/
replace: function (str, opt_withCommentsOrParams, opt_content, opt_snakeskin) {},
/**
* @param {string} str
* @param {Array=} [opt_content]
* @return {string}
*/
paste: function (str, opt_content) {}
};

View File

@@ -0,0 +1,62 @@
{
"name": "escaper",
"description": "Small JavaScript library for replacing string literals, regular expressions and comments in JavaScript syntax.",
"homepage": "https://github.com/kobezzza/Escaper",
"main": "dist/escaper.js",
"jsnext:main": "src/escaper.js",
"typings": "escaper.d.ts",
"version": "2.5.3",
"license": "MIT",
"author": {
"name": "kobezzza",
"email": "kobezzza@mail.ru",
"url": "https://github.com/kobezzza"
},
"repository": {
"type": "git",
"url": "git://github.com/kobezzza/Escaper.git"
},
"bugs": {
"url": "https://github.com/kobezzza/Escaper/issues"
},
"keywords": [
"javascript",
"string"
],
"devDependencies": {
"@types/gulp": "^4.0.5",
"babel-core": "^6.26.0",
"babel-plugin-transform-remove-strict-mode": "0.0.2",
"babel-preset-es2015-rollup": "^3.0.0",
"bower": "^1.8.2",
"closurecompiler-externs": "^1.0.4",
"coveralls": "^3.0.0",
"eslint": "^4.16.0",
"glob": "^7.1.2",
"gulp": "^4.0.0",
"gulp-bump": "^3.0.0",
"gulp-closure-compiler": "^0.4.0",
"gulp-download": "0.0.1",
"gulp-eol": "^0.2.0",
"gulp-header": "^2.0.1",
"gulp-ignore": "^2.0.2",
"gulp-istanbul": "^1.1.3",
"gulp-jasmine": "^3.0.0",
"gulp-load-plugins": "^1.5.0",
"gulp-monic": "^2.0.13",
"gulp-plumber": "^1.2.0",
"gulp-replace": "^0.6.1",
"gulp-rollup": "^2.16.1",
"gulp-run": "^1.6.8",
"gulp-wrap": "^0.13.0",
"jasmine": "^2.9.0",
"monic": "^2.5.1",
"rollup-plugin-babel": "^3.0.3",
"yaspeller": "^4.0.3"
},
"scripts": {
"test": "bower install && jasmine",
"test-coverage": "bower install && gulp test",
"full-test": "npm run test-coverage && yaspeller ./"
}
}

View File

@@ -0,0 +1,14 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Escaper</title>
<link rel="stylesheet" href="../bower_components/jasmine/lib/jasmine-core/jasmine.css">
<script src="../bower_components/jasmine/lib/jasmine-core/jasmine.js"></script>
<script src="../bower_components/jasmine/lib/jasmine-core/jasmine-html.js"></script>
<script src="../bower_components/jasmine/lib/jasmine-core/boot.js"></script>
<script src="../dist/escaper.min.js"></script>
<script src="tests.js"></script>
</head>
<body></body>
</html>

View File

@@ -0,0 +1,10 @@
/*!
* Escaper
* https://github.com/kobezzza/Escaper
*
* Released under the MIT license
* https://github.com/kobezzza/Escaper/blob/master/LICENSE
*/
global.Escaper = require('../dist/escaper.min');
require('./tests');

View File

@@ -0,0 +1,9 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
}

View File

@@ -0,0 +1,249 @@
/*!
* Escaper
* https://github.com/kobezzza/Escaper
*
* Released under the MIT license
* https://github.com/kobezzza/Escaper/blob/master/LICENSE
*/
describe('Escaper', function () {
it('should work with " ... "', function () {
var str = Escaper.replace('Hello "friend\\\""!');
expect(str)
.toBe('Hello __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str))
.toBe('Hello "friend\\\""!');
var str2 = Escaper.replace('Hello "friend\\\""!');
expect(str2)
.toBe('Hello __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str2))
.toBe('Hello "friend\\\""!');
var stack = [];
var str3 = Escaper.replace('Hello "friend\\\""!', false, stack);
expect(str3)
.toBe('Hello __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str3, stack))
.toBe('Hello "friend\\\""!');
stack = [];
var str4 = Escaper.replace('Hello "friend\\\""!', {'"': -1}, stack);
expect(str4)
.toBe('Hello !');
expect(Escaper.paste(str4, stack))
.toBe('Hello !');
});
it("should work with ' ... '", function () {
var str = Escaper.replace("Hello 'friend\\\''!");
expect(str)
.toBe('Hello __ESCAPER_QUOT__1_!');
expect(Escaper.paste(str))
.toBe("Hello 'friend\\\''!");
var stack = [];
var str2 = Escaper.replace("Hello 'friend\\\''!", false, stack);
expect(str2)
.toBe('Hello __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str2, stack))
.toBe("Hello 'friend\\\''!");
});
it('should work with ` ... `', function () {
var stack = [];
var str = Escaper.replace('Hello `friend`!', false, stack);
expect(str)
.toBe('Hello __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str, stack))
.toBe("Hello `friend`!");
var str2 = Escaper.replace('Hello `friend${1 + {foo: {}} + `foo` + /1/}`!', false, stack);
expect(str2)
.toBe('Hello __ESCAPER_QUOT__1_1 + {foo: {}} + __ESCAPER_QUOT__2_ + __ESCAPER_QUOT__3___ESCAPER_QUOT__4_!');
expect(Escaper.paste(str2, stack))
.toBe("Hello `friend${1 + {foo: {}} + `foo` + /1/}`!");
var str3 = Escaper.replace('Hello `friend\\${foo}`!', false, stack);
expect(str3)
.toBe('Hello __ESCAPER_QUOT__5_!');
expect(Escaper.paste(str3, stack))
.toBe('Hello `friend\\${foo}`!');
var str4 = Escaper.replace('Hello `friend${foo/* fooo */}`!', true, stack);
expect(str4)
.toBe('Hello __ESCAPER_QUOT__6_foo__ESCAPER_QUOT__7___ESCAPER_QUOT__8_!');
expect(Escaper.paste(str4, stack))
.toBe('Hello `friend${foo/* fooo */}`!');
});
it("should work with / ... /", function () {
var stack = [];
var str = Escaper.replace("Hello + /friend\\//gmi!", false, stack);
expect(str)
.toBe('Hello + __ESCAPER_QUOT__0_!');
expect(Escaper.paste(str, stack))
.toBe('Hello + /friend\\//gmi!');
var str2 = Escaper.replace("Hello, /friend\\/[//.]/gmi!", false, stack);
expect(str2)
.toBe('Hello, __ESCAPER_QUOT__1_!');
expect(Escaper.paste(str2, stack))
.toBe('Hello, /friend\\/[//.]/gmi!');
var str3 = Escaper.replace('/friend\\/[//.]/gmi!, /friend\\/[//.]/gmi', false, stack);
expect(str3)
.toBe('__ESCAPER_QUOT__2_!, __ESCAPER_QUOT__3_');
expect(Escaper.paste(str3, stack))
.toBe('/friend\\/[//.]/gmi!, /friend\\/[//.]/gmi');
});
it("should work with / ... / (advanced test)", function () {
var stack = [];
var str = Escaper.replace('2 >> /foo/ < /bar/ ^ /car/ [/bar/] foo typeof /mu/ /mu/', true, stack);
expect(str)
.toBe('2 >> __ESCAPER_QUOT__0_ < __ESCAPER_QUOT__1_ ^ __ESCAPER_QUOT__2_ [__ESCAPER_QUOT__3_] foo typeof __ESCAPER_QUOT__4_ /mu/');
expect(Escaper.paste(str, stack))
.toBe('2 >> /foo/ < /bar/ ^ /car/ [/bar/] foo typeof /mu/ /mu/');
});
it("should work with single-line comments", function () {
var stack = [];
var str = Escaper.replace(
("Hello // the comment\
\n Friend!"), true, stack);
expect(str)
.toBe('Hello __ESCAPER_QUOT__0_\n\t\t\tFriend!');
expect(Escaper.paste(str, stack))
.toBe('Hello // the comment\n\t\t\tFriend!');
});
it("should work with //!", function () {
var stack = [];
var str = Escaper.replace(
("Hello // the comment //! fffuuu\
\n//! fffuuuu\
\n Friend!"), {'//!': true}, stack);
expect(str)
.toBe('Hello // the comment //! fffuuu\n__ESCAPER_QUOT__0_\n\t\t\tFriend!');
expect(Escaper.paste(str, stack))
.toBe('Hello // the comment //! fffuuu\n//! fffuuuu\n\t\t\tFriend!');
});
it("should work with multiline comments", function () {
var stack = [];
var str = Escaper.replace('Hello /*/ the comment */ Friend!', true, stack);
expect(str)
.toBe('Hello __ESCAPER_QUOT__0_ Friend!');
expect(Escaper.paste(str, stack))
.toBe('Hello /*/ the comment */ Friend!');
});
it("should work with Snakeskin", function () {
var stack = [];
var str = Escaper.replace('foo|replace /hello/g|join "world"', true, stack, true);
expect(str)
.toBe('foo|replace __ESCAPER_QUOT__0_|join __ESCAPER_QUOT__1_');
expect(Escaper.paste(str, stack))
.toBe('foo|replace /hello/g|join "world"');
});
it("should work with custom parameters", function () {
var stack = [];
var str = Escaper.replace('"Hello" /* the comment */ + /Friend/gim /** foo */!', {
'"': true,
'/': true,
'/*': true
}, stack);
expect(str)
.toBe('__ESCAPER_QUOT__0_ __ESCAPER_QUOT__1_ + __ESCAPER_QUOT__2_ /** foo */!');
expect(Escaper.paste(str, stack))
.toBe('"Hello" /* the comment */ + /Friend/gim /** foo */!');
});
it("should work with deep literals", function () {
var stack = [];
var str = Escaper.replace('"Hello" /** "foo" */', {'"': true}, stack);
expect(str)
.toBe('__ESCAPER_QUOT__0_ /** "foo" */');
expect(Escaper.paste(str, stack))
.toBe('"Hello" /** "foo" */');
});
it("should work with @all", function () {
var stack = [];
var str = Escaper.replace('"Hello" /* the comment */ + /Friend/gim /** foo */!', {'@all': true, '/*': -1}, stack);
expect(str)
.toBe('__ESCAPER_QUOT__0_ + __ESCAPER_QUOT__1_ __ESCAPER_QUOT__2_!');
expect(Escaper.paste(str, stack))
.toBe('"Hello" + /Friend/gim /** foo */!');
});
it("should work with @comments", function () {
var stack = [];
var str = Escaper.replace('"Hello" /* the comment */ + /Friend/gim /** foo */!', {'@comments': -1}, stack);
expect(str)
.toBe('"Hello" + /Friend/gim !');
expect(Escaper.paste(str, stack))
.toBe('"Hello" + /Friend/gim !');
});
it("should work with @comments, @literals and @all", function () {
var stack = [];
var str = Escaper.replace('"Hello" /* the comment */ + /Friend/gim /** foo */!', {
'@all': -1,
'@comments': false,
'@literals': true
}, stack);
expect(str)
.toBe('__ESCAPER_QUOT__0_ /* the comment */ + __ESCAPER_QUOT__1_ /** foo */!');
expect(Escaper.paste(str, stack))
.toBe('"Hello" /* the comment */ + /Friend/gim /** foo */!');
});
});