Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jfogs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jfogs - npm Package Compare versions

Comparing version 0.0.15 to 1.0.0-alpha.5

LICENSE

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]

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc