Comparing version 0.0.15 to 1.0.0-alpha.5
150
lib/jfogs.js
@@ -8,4 +8,4 @@ (function(exportName) { | ||
* zswang (http://weibo.com/zswang) | ||
* @version 0.0.15 | ||
* @date 2016-02-19 | ||
* @version 1.0.0-alpha.5 | ||
* @date 2019-01-04 | ||
*/ | ||
@@ -21,72 +21,80 @@ var esprimaInstance; | ||
var exports = {}; | ||
/*<function name="encodeUTF8">*/ | ||
/*<function name="encodeUTF8">*/ | ||
/** | ||
* 对字符串进行 utf8 编码 | ||
* | ||
* param str 原始字符串 | ||
* @example encodeUTF8():base | ||
```js | ||
console.log(encodeURI(jstrs.encodeUTF8('汉'))) | ||
// > %C3%A6%C2%B1%C2%89 | ||
``` | ||
* @example encodeUTF8():ascii | ||
```js | ||
console.log(jstrs.encodeUTF8('ascii')) | ||
// > ascii | ||
``` | ||
*/ | ||
function encodeUTF8(str) { | ||
return unescape(encodeURIComponent(str)); | ||
} /*</function>*/ | ||
/*<function name="format">*/ | ||
/** | ||
* 格式化函数 | ||
* | ||
* @param template 模板 | ||
* @param json 数据项 | ||
* @example format():array | ||
```js | ||
console.log(jstrs.format('#{0} #{1}', [1, 2])); | ||
// > 1 2 | ||
``` | ||
* @example format():object | ||
```js | ||
console.log(jstrs.format('#{level} -- #{color}', { | ||
color: 'red', | ||
level: 2 | ||
})); | ||
// > 2 -- red | ||
``` | ||
* @example format():undefined | ||
```js | ||
console.log(jstrs.format('#{level} -- #{color}', { | ||
color: 'red' | ||
})); | ||
// > -- red | ||
``` | ||
* @example format():function | ||
'''<jdists encoding="regex" pattern="/~/g" replacement="*" trigger="example" desc="~ 替换成 *">''' | ||
```js | ||
console.log(jstrs.format(function () { | ||
/~ | ||
#{color}: #{level} | ||
~/ | ||
}, { | ||
color: 'red', | ||
level: 2 | ||
})); | ||
// > red: 2 | ||
``` | ||
'''</jdists>''' | ||
*/ | ||
function format(template, json) { | ||
/*<funcTemplate>*/ | ||
if (typeof template === 'function') { | ||
// 函数多行注释处理 | ||
template = String(template).replace(/[^]*\/\*!?\s*|\s*\*\/[^]*/g, // 替换掉函数前后部分 | ||
''); | ||
} | ||
/*</funcTemplate>*/ | ||
return template.replace(/#\{(.*?)\}/g, function () { | ||
var params = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
params[_i] = arguments[_i]; | ||
} | ||
var key = params[1]; | ||
return json && key in json ? json[key] : ''; | ||
}); | ||
} /*</function>*/ | ||
/** | ||
* 对字符串进行 utf8 编码 | ||
* | ||
* param {string} str 原始字符串 | ||
'''<example>''' | ||
* @example encodeUTF8():base | ||
```js | ||
console.log(jstrs.encodeUTF8('汉')); | ||
// > æ± | ||
``` | ||
'''</example>''' | ||
*/ | ||
function encodeUTF8(str) { | ||
if (/[\u0080-\uffff]/.test(str)) { | ||
return unescape(encodeURIComponent(str)); | ||
} | ||
return str; | ||
} | ||
/*</function>*/ | ||
/*<function name="format">*/ | ||
/** | ||
* 格式化函数 | ||
* | ||
* @param {string} template 模板 | ||
* @param {object} json 数据项 | ||
'''<example>''' | ||
* @example format():array | ||
```js | ||
console.log(jstrs.format('#{0} #{1}', [1, 2])); | ||
// > 1 2 | ||
``` | ||
* @example format():object | ||
```js | ||
console.log(jstrs.format('#{level} -- #{color}', { | ||
color: 'red', | ||
level: 2 | ||
})); | ||
// > 2 -- red | ||
``` | ||
* @example format():function | ||
'''<jdists encoding="regex" pattern="/~/g" replacement="*" trigger="example">''' | ||
```js | ||
// "~" 替换成 "*" | ||
console.log(jstrs.format(function () { | ||
/~ | ||
#{color}: #{level} | ||
~/ | ||
}, { | ||
color: 'red', | ||
level: 2 | ||
})); | ||
// > red: 2 | ||
``` | ||
'''</jdists>''' | ||
'''</example>''' | ||
*/ | ||
function format(template, json) { | ||
if (typeof template === 'function') { // 函数多行注释处理 | ||
template = String(template).replace( | ||
/[^]*\/\*!?\s*|\s*\*\/[^]*/g, // 替换掉函数前后部分 | ||
'' | ||
); | ||
} | ||
return template.replace(/#\{(.*?)\}/g, function(all, key) { | ||
return json && (key in json) ? json[key] : ""; | ||
}); | ||
} | ||
/*</function>*/ | ||
/** | ||
* 混淆 JS 代码 | ||
@@ -93,0 +101,0 @@ * |
{ | ||
"name": "jfogs", | ||
"version": "0.0.15", | ||
"version": "1.0.0-alpha.5", | ||
"description": "Javascript code obfuscator", | ||
@@ -21,2 +21,8 @@ "main": "lib/jfogs.js", | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "finscn", | ||
"url": "http://fins.iteye.com/" | ||
} | ||
], | ||
"license": "MIT", | ||
@@ -28,11 +34,16 @@ "bugs": { | ||
"devDependencies": { | ||
"mocha": "^2.0.1", | ||
"istanbul": "^0.3.17", | ||
"should": "^4.1.0", | ||
"jshint": "^2.8.0", | ||
"jdists": "^1.3.1", | ||
"jstrs": "^0.0.1" | ||
"@types/escodegen": "0.0.6", | ||
"@types/esprima": "^4.0.2", | ||
"istanbul": "^0.4.5", | ||
"jdists": "^2.2.4", | ||
"jshint": "^2.9.7", | ||
"jstrs": "^1.1.7", | ||
"mocha": "^5.2.0", | ||
"should": "^4.6.5", | ||
"ts-node": "^6.0.5", | ||
"typescript": "^2.8.3" | ||
}, | ||
"dependencies": { | ||
"esprima": "^2.5.0", | ||
"esprima": "^4.0.0", | ||
"escodegen": "^1.9.0", | ||
"mkdirp": "^0.5.0", | ||
@@ -46,3 +57,4 @@ "colors": "^1.0.3", | ||
"lint": "jshint src/*.js", | ||
"dist": "npm run _update_version && jdists src/jfogs.js -o lib/jfogs.js && npm run lint && npm test" | ||
"dist": "npm run _update_version && jdists src/jfogs.js -o lib/jfogs.js && npm run lint && npm test", | ||
"debug": "ts-node src/index.ts" | ||
}, | ||
@@ -49,0 +61,0 @@ "files": [ |
@@ -0,0 +0,0 @@ # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coverage-image]][coverage-url] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21939
5
521
5
10
+ Addedescodegen@^1.9.0
+ Addeddeep-is@0.1.4(transitive)
+ Addedescodegen@1.14.3(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedestraverse@4.3.0(transitive)
+ Addedesutils@2.0.3(transitive)
+ Addedfast-levenshtein@2.0.6(transitive)
+ Addedlevn@0.3.0(transitive)
+ Addedoptionator@0.8.3(transitive)
+ Addedprelude-ls@1.1.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addedtype-check@0.3.2(transitive)
+ Addedword-wrap@1.2.5(transitive)
- Removedesprima@2.7.3(transitive)
Updatedesprima@^4.0.0