Comparing version 0.1.1 to 0.1.2
35
index.js
@@ -14,12 +14,6 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
var m = str.length; | ||
for (var i = 0; i < m; i++) { | ||
if (str.charCodeAt(i) > 32) { | ||
break; | ||
} | ||
for (var i = 0; i < m && str.charCodeAt(i) < 33; i++) { | ||
} | ||
for (var j = m - 1; j > i; j--) { | ||
if (str.charCodeAt(j) > 32) { | ||
break; | ||
} | ||
for (var j = m - 1; j > i && str.charCodeAt(j) < 33; j--) { | ||
} | ||
@@ -42,2 +36,3 @@ | ||
'filters' : [], | ||
'handles' : [], /**< 产出列处理规则 */ | ||
'fields' : [], | ||
@@ -51,11 +46,23 @@ 'routes' : {}, | ||
/* {{{ function _buildRow() */ | ||
if (!Array.isArray(_options.fields) || _options.fields.length < 1) { | ||
var _buildRow = new Function('row', Util.format("return row.join('%s');", _options.EOF)); | ||
function _deal(row) { | ||
row.forEach(function (f, i) { | ||
if (handles[i]) { | ||
row[i] = (handles[i])(f); | ||
} | ||
}); | ||
} | ||
var _buildRow = new Function(['row', 'handles'], _deal.toString() + '\n_deal(row);\n' + Util.format("return row.join('%s');", _options.EOF)); | ||
} else { | ||
function _fn(f, i) { | ||
if (handles[i]) { | ||
return (handles[i])(f); | ||
} | ||
return f; | ||
} | ||
var _temp = []; | ||
_options.fields.forEach(function (k) { | ||
_temp.push(Util.format('row[%d]', k)); | ||
_options.fields.forEach(function (k, i) { | ||
_temp.push(Util.format('_fn(row[%d], %d)', k, i)); | ||
}); | ||
var _buildRow = new Function('row', 'return ' + _temp.join(Util.format(" + '%s' + ", _options.EOF)) + ';'); | ||
var _buildRow = new Function(['row', 'handles'], _fn.toString() + '\nreturn ' + _temp.join(Util.format(" + '%s' + ", _options.EOF)) + ';'); | ||
} | ||
@@ -141,3 +148,3 @@ | ||
var idx = _getRoute(row); | ||
var txt = _buildRow(row) + _options.EOL; | ||
var txt = _buildRow(row, _options.handles) + _options.EOL; | ||
@@ -144,0 +151,0 @@ if (undefined === _wcache[idx]) { |
{ | ||
"name": "filesplit", | ||
"version": "0.1.1", | ||
"author": "Aleafs Zhang (zhangxc83@gmail.com)", | ||
"version": "0.1.2", | ||
"author": "Aleafs Zhang (zhangxc83@gmail.com), iseeyou1987 (21.aoei@gmail.com)", | ||
"contributors": [], | ||
"homepage": "git@github.com:iseeyou1987/filesplit.git", | ||
"description": "A high speed file splitor on Node.js", | ||
"keywords": [ "filesplit", "cut", "split" ], | ||
"keywords": [ | ||
"filesplit", | ||
"cut", | ||
"split" | ||
], | ||
"dependencies": {}, | ||
@@ -14,9 +18,14 @@ "engines": { | ||
"devDependencies": { | ||
"should" : ">=0.4.2", | ||
"mocha" : ">=0.9.0" | ||
"should": ">=0.4.2", | ||
"mocha": ">=0.9.0" | ||
}, | ||
"main" : "./index.js", | ||
"main": "./index.js", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"optionalDependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/iseeyou1987/filesplit.git" | ||
} | ||
} |
@@ -23,3 +23,3 @@ [![Build Status](https://secure.travis-ci.org/aleafs/filesplit.png?branch=master)](http://travis-ci.org/aleafs/filesplit) | ||
Thanks goes to the people who have contributed code to this module, see the [GitHub Contributors page](https://github.com/aleafs/filesplit/graphs/contributors). | ||
Thanks goes to the people who have contributed code to this module, see the [GitHub Contributors page](https://github.com/iseeyou1987/filesplit/graphs/contributors). | ||
@@ -30,3 +30,3 @@ # License # | ||
Copyright (c) 2012 aleafs and other filesplit contributors | ||
Copyright (c) 2012 iseeyou1987 and other filesplit contributors | ||
@@ -33,0 +33,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
@@ -5,2 +5,3 @@ /* vim: set expandtab tabstop=2 shiftwidth=2 foldmethod=marker: */ | ||
var splitor = require(__dirname + '/../'); | ||
var fs = require('fs'); | ||
@@ -13,3 +14,2 @@ var cleanOutput = function (callback) { | ||
var fs = require('fs'); | ||
@@ -142,3 +142,51 @@ /* {{{ should_read_wrong_character_when_not_set_encoding() */ | ||
it('should_field_handle_works_fine', function (done) { | ||
var _input = [__dirname + '/res/test_input_1.txt', __dirname + '/res/test_input_2.txt']; | ||
var caller = splitor.create(_input, __dirname + '/res/output', { | ||
'EOF' : String.fromCharCode(1), | ||
'bufferSize' : 1024, | ||
'maxLines' : 30, | ||
'routes' : {'thedate' : 0}, | ||
'fields' : [1,0,4,3], | ||
'filters' : [splitor.trim], | ||
'handles' : [,,,_S] | ||
}); | ||
function _S(str) { | ||
return ['$', str, '$'].join(''); | ||
} | ||
caller(function (error, result) { | ||
should.ok(!error); | ||
var _content = fs.readFileSync(result['thedate=20120623'][0].file).toString().trim(); | ||
_content.split('\n').forEach(function (l) { | ||
var fields = l.split(String.fromCharCode(1)); | ||
fields.pop().should.match(/^\$.*\$$/); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
it('should_field_handle_works_fine_when_no_fields_given', function (done) { | ||
var _input = [__dirname + '/res/test_input_1.txt', __dirname + '/res/test_input_2.txt']; | ||
var caller = splitor.create(_input, __dirname + '/res/output', { | ||
'EOF' : String.fromCharCode(1), | ||
'bufferSize' : 1024, | ||
'maxLines' : 30, | ||
'routes' : {'thedate' : 0}, | ||
'filters' : [splitor.trim], | ||
'handles' : [,,,,_S] | ||
}); | ||
function _S(str) { | ||
return ['$', str, '$'].join(''); | ||
} | ||
caller(function (error, result) { | ||
should.ok(!error); | ||
var _content = fs.readFileSync(result['thedate=20120623'][0].file).toString().trim(); | ||
_content.split('\n').forEach(function (l) { | ||
var fields = l.split(String.fromCharCode(1)); | ||
fields.pop().should.match(/^\$.*\$$/); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
17159
340
3
6