Socket
Socket
Sign inDemoInstall

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.11 to 0.0.12

104

lib/jfogs.js

@@ -1,2 +0,1 @@

/**

@@ -8,41 +7,76 @@ * @file jfogs

* zswang (http://weibo.com/zswang)
* @version 0.0.11
* @date 2015-10-12
* @version 0.0.12
* @date 2015-12-04
*/
var esprima = require('esprima');
/**
* 对字符串进行utf8编码
*
* param {string} str 原始字符串
*/
function encodeUTF8(str) {
if (!str) {
/*<function name="encodeUTF8">*/
/**
* 对字符串进行 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;
}
return String(str).replace(
/[\u0080-\u07ff]/g,
function (c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xc0 | cc >> 6, 0x80 | cc & 0x3f);
/*</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, // 替换掉函数前后部分
''
);
}
).replace(
/[\u0800-\uffff]/g,
function (c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xe0 | cc >> 12, 0x80 | cc >> 6 & 0x3f, 0x80 | cc & 0x3f);
}
);
}
return template.replace(/#\{(.*?)\}/g, function(all, key) {
return json && (key in json) ? json[key] : "";
});
}
/*</function>*/
/**
* 格式化函数
*
* @param {String} template 模板
* @param {Object} json 数据项
*/
function format(template, json) {
return template.replace(/#\{(.*?)\}/g, function (all, key) {
return json[key];
});
}
/**
* 混淆 JS 代码

@@ -112,3 +146,3 @@ *

}
if (/^["']/.test(obj.raw)) {
if (/^(["']|\d)/.test(obj.raw)) {
if (parentKey !== 'key') { // 不能是 JSON 的 key

@@ -115,0 +149,0 @@ /* jslint evil: true */

{
"name": "jfogs",
"version": "0.0.11",
"version": "0.0.12",
"description": "Javascript code obfuscator",

@@ -28,7 +28,8 @@ "main": "index.js",

"devDependencies": {
"mocha": "2.0.1",
"istanbul": "0.3.17",
"should": "4.1.0",
"jshint": "2.8.0",
"jdists": "0.9.13"
"mocha": "^2.0.1",
"istanbul": "^0.3.17",
"should": "^4.1.0",
"jshint": "^2.8.0",
"jdists": "^1.3.1",
"jstrs": "^0.0.1"
},

@@ -39,3 +40,4 @@ "dependencies": {

"colors": "^1.0.3",
"optimist": "^0.6.1"
"optimist": "^0.6.1",
"jhtmls": "^0.1.9"
},

@@ -42,0 +44,0 @@ "scripts": {

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