Skip to content

Commit

Permalink
add "jogs" processor
Browse files Browse the repository at this point in the history
  • Loading branch information
zswang committed Aug 19, 2015
1 parent ea65558 commit 45ec383
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/jdists.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Code block processing tools
* @author
* zswang (http://weibo.com/zswang)
* @version 0.9.13
* @date 2015-08-09
* @version 0.9.14
* @date 2015-08-20
*/
var fs = require('fs');
var scope = require('./scope');
Expand All @@ -21,6 +21,7 @@ var defaultProcessors = {
"html": require('../processor/processor-html'),
"indent": require('../processor/processor-indent'),
"jade": require('../processor/processor-jade'),
"jfogs": require('../processor/processor-jfogs'),
"jhtmls": require('../processor/processor-jhtmls'),
"jjencode": require('../processor/processor-jjencode'),
"jsdev": require('../processor/processor-jsdev'),
Expand Down
4 changes: 2 additions & 2 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Code block processing tools
* @author
* zswang (http://weibo.com/zswang)
* @version 0.9.13
* @date 2015-08-09
* @version 0.9.14
* @date 2015-08-20
*/
var colors = require('colors');
var util = require('util');
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jdists",
"version": "0.9.13",
"version": "0.9.14",
"description": "Code block processing tools",
"main": "index.js",
"bin": {
Expand Down Expand Up @@ -48,7 +48,8 @@
"optimist": "^0.6.1",
"jhtmls": "^0.1.7",
"jade": "^1.11.0",
"ejs": "^1.0.0"
"ejs": "^1.0.0",
"jfogs": "^0.0.1"
},
"scripts": {
"test": "istanbul cover --hook-run-in-context node_modules/mocha/bin/_mocha -- -R spec",
Expand Down
21 changes: 21 additions & 0 deletions processor/processor-jfogs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var jfogs = require('jfogs');

/**
* jfogs 代码混淆
*
* @param {string} content 文本内容
* @param {Object} attrs 属性
* @param {string} attrs.type 参数混淆方式
* @param {string} attrs.cross 添加混淆属性
* @param {Object} scope 作用域
* @param {Function} scope.execImport 导入数据
*/
module.exports = function processor(content, attrs, scope) {
if (!content) {
return content;
}
var options = {};
options.type = scope.execImport(attrs.type);
options.cross = /^(yes|on|true|ok)$/.test(scope.execImport(attrs.cross));
return jfogs.obfuscate(content, options);
};
50 changes: 50 additions & 0 deletions test/fixtures/jfogs+uglify.input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jfogs</title>
</head>
<body>
<div></div>
</body>
<script>
/*<jdists encoding="jfogs,uglify" cross="true" type="zero">*/
/**
* 贝赛尔公式,支持多维数组
*
* @param{Array[Array[number, ...],...]} items 每个参考点
* @param{number} rate 比率
* @return{number|Array[number, ...]} 返回
*/
function bezier(items, rate) {
if (!items || !items.length) {
return;
}
var first = items[0];
var second = items[1];
var level = first instanceof Array ? first.length : 0; // 下标数,0为非数组
var i;
switch (items.length) {
case 1:
return level ? first.slice() : first; // 数组需要克隆,非数组直接返回
case 2:
if (level) { // 非数组
var result = [];
for (i = 0; i < level; i++) {
result[i] = bezier([first[i], second[i]], rate);
}
return result;
}
return first + (second - first) * rate;
default:
var temp = [];
for (i = 1; i < items.length; i++) {
temp.push(bezier([items[i - 1], items[i]], rate));
}
return bezier(temp, rate);
}
}
console.log(bezier([1, 5], 0.2));
/*</jdists>*/
</script>
</html>
13 changes: 13 additions & 0 deletions test/fixtures/jfogs+uglify.output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>jfogs</title>
</head>
<body>
<div></div>
</body>
<script>
!function(r,n,e,t,a,f){function o(r,n){if(r&&r[i.ؠ̀]){var e,t=r[i.ء́],a=r[i.آ̂],f=t instanceof Array?t[i.ؠ̀]:0;switch(r[i.ؠ̀]){case 1:return f?t[i.أ̃]():t;case 2:if(f){var u=[];for(e=0;f>e;e++)u[e]=o([t[e],a[e]],n);return u}return t+(a-t)*n;default:var c=[];for(e=1;e<r[i.ؠ̀];e++)c[i.ؤ̄](o([r[e-1],r[e]],n));return o(c,n)}}}for(var u=arguments,c=0;c<u.length;c++)u[c]=u[c].replace(/./g,function(r){return{"‌":0,"‍":1}[r]}).replace(/.{7}/g,function(r){return String.fromCharCode(parseInt(r,2))});var i={};i.ؠ̀=r,i.ء́=n,i.آ̂=e,i.أ̃=t,i.ؤ̄=a,i.إ̅=f,console[i.إ̅](o([1,5],.2))}("‍‍‌‍‍‌‌‍‍‌‌‍‌‍‍‍‌‍‍‍‌‍‍‌‌‍‍‍‍‍‍‌‍‌‌‍‍‌‍‌‌‌","‌‍‍‌‌‌‌","‌‍‍‌‌‌‍","‍‍‍‌‌‍‍‍‍‌‍‍‌‌‍‍‌‍‌‌‍‍‍‌‌‌‍‍‍‍‌‌‍‌‍","‍‍‍‌‌‌‌‍‍‍‌‍‌‍‍‍‍‌‌‍‍‍‍‌‍‌‌‌","‍‍‌‍‍‌‌‍‍‌‍‍‍‍‍‍‌‌‍‍‍");
</script>
</html>

0 comments on commit 45ec383

Please sign in to comment.