Comparing version 2.17.0 to 2.18.0
{ | ||
"name": "nyks", | ||
"version": "2.17.0", | ||
"version": "2.18.0", | ||
"description": "nodejs exupery style", | ||
@@ -12,5 +12,3 @@ "keywords": [ | ||
"async": "^2.0.0-rc.2", | ||
"crc-32": "^0.3.0", | ||
"mout": "^1.0.0", | ||
"sprintf-js": "^1.0.3" | ||
"mout": "^1.0.0" | ||
}, | ||
@@ -34,3 +32,3 @@ "devDependencies": { | ||
"scripts": { | ||
"test": " node node_modules/istanbul/lib/cli.js cover -x \"crypto/*\" -x \"child_process/*\" node_modules/mocha/bin/_mocha test/" | ||
"test": "node node_modules/istanbul/lib/cli.js cover -x \"crypto/*\" -x \"string/sprintf.js\" -x \"string/crc32.js\" -x \"child_process/*\" node_modules/mocha/bin/_mocha test/" | ||
}, | ||
@@ -37,0 +35,0 @@ "readme": "# nyks toolkit\r\n\r\nExtend nodejs & javascript native API of missing functions.\r\n", |
@@ -1,31 +0,34 @@ | ||
nyks provide a set of "missing" stuffs in nodejs basic api. | ||
All those functions will eventually end up in the official API :-). | ||
# Motivation | ||
nyks provide a set of complentary modules nodejs basic api. | ||
Module are exported in a standard common JS module format and written in pure ES5 strict format. (no transpilation required nor used), just use browserify if you need nyks module in a browser environnement (no fancy / smart context detection from me, juste plain module). | ||
Module complete moutjs spirit with (mostly) nodejs specifics patterns. | ||
# Natives | ||
## child_process | ||
* require('child_process').exec_window(cmd, args, callback); | ||
child_process.exec equivalent for windowed applications. | ||
* require('nyks/child_process/exec')(cmd, options, callback); | ||
child_process.exec equivalent with sane API for arguments. | ||
* require('child_process').passthru(cmd, args, callback); | ||
* require('child_process').passthru(cmd, {args:args,env:env}, callback); | ||
callback(err, exit_code, last_stdout_line); | ||
* require('nyks/child_process/passthru')(cmd, args, callback); | ||
Like exec, but with stdout & stderr bound to current process IO streams. | ||
## path | ||
* path.which | ||
Return full path of a binary in env PATH | ||
* path.extend_PATH(path[,path2, ..]); | ||
Extend system PATH with new directory | ||
* require('nyks/path/which'(bin) | ||
Search for a binary in env PATH | ||
## util | ||
* require('util').md5(string) | ||
Return a hex encoded md5 hash | ||
* require('nyks/path/extend')( path[,path2, ..]); | ||
Extend system PATH with new directories | ||
## process | ||
* require('nyks/process/parseArgs')(process.argv.splice(2)) | ||
* require('nyks/process/parseArgs')([process.argv.splice(2)]) | ||
Command line args parser, aligned on yks patterns | ||
* require('nyks/process/splitArgs')("some string 'with escaped' content") | ||
@@ -55,4 +58,2 @@ Split a string into whitespace separated chunks | ||
* require('nyks/fs/clearFolderReccurcive')(path , options , callback) // options {file_to_keep:[] , size_to_delete:number(octet) , max_size:number(octet) , max_time:number(millisecond) } | ||
delete files in folder (you can delete the files created before max_time or and delete with size options) | ||
@@ -90,10 +91,2 @@ | ||
* require('nyks/string/startsWith')(str) | ||
Return boolean | ||
* require('nyks/string/endsWith')(str) | ||
Return boolean | ||
* require('nyks/string/replaces')(dict) | ||
@@ -100,0 +93,0 @@ Replace key => value in current string |
"use strict"; | ||
module.exports = require('crc-32').str; | ||
/** | ||
* from crc32.js (C) 2014-2015 SheetJS -- http://sheetjs.com | ||
*/ | ||
var use_buffer = typeof Buffer !== 'undefined'; | ||
var use_in32 = typeof Int32Array !== 'undefined'; | ||
var table = (function() { | ||
var c = 0, table = new Array(256); | ||
for(var n =0; n != 256; ++n) { | ||
c = n; | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
c = ((c&1) ? (-306674912 ^ (c >>> 1)) : (c >>> 1)); | ||
table[n] = c; | ||
} | ||
return use_in32 ? new Int32Array(table) : table; | ||
})(); | ||
/* charCodeAt is the best approach for binary strings */ | ||
function crc32_bstr(bstr) { | ||
if(bstr.length > 32768) if(use_buffer) return crc32_buf_8(new Buffer(bstr)); | ||
var crc = -1, L = bstr.length - 1; | ||
for(var i = 0; i < L;) { | ||
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8); | ||
crc = table[(crc ^ bstr.charCodeAt(i++)) & 0xFF] ^ (crc >>> 8); | ||
} | ||
if(i === L) crc = (crc >>> 8) ^ table[(crc ^ bstr.charCodeAt(i)) & 0xFF]; | ||
return crc ^ -1; | ||
} | ||
function crc32_buf(buf) { | ||
if(buf.length > 10000) return crc32_buf_8(buf); | ||
for(var crc = -1, i = 0, L=buf.length-3; i < L;) { | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
} | ||
while(i < L+3) crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
return crc ^ -1; | ||
} | ||
function crc32_buf_8(buf) { | ||
for(var crc = -1, i = 0, L=buf.length-7; i < L;) { | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
} | ||
while(i < L+7) crc = (crc >>> 8) ^ table[(crc^buf[i++])&0xFF]; | ||
return crc ^ -1; | ||
} | ||
/* much much faster to intertwine utf8 and crc */ | ||
function crc32_str(str) { | ||
for(var crc = -1, i = 0, L=str.length, c, d; i < L;) { | ||
c = str.charCodeAt(i++); | ||
if(c < 0x80) { | ||
crc = (crc >>> 8) ^ table[(crc ^ c) & 0xFF]; | ||
} else if(c < 0x800) { | ||
crc = (crc >>> 8) ^ table[(crc ^ (192|((c>>6)&31))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|(c&63))) & 0xFF]; | ||
} else if(c >= 0xD800 && c < 0xE000) { | ||
c = (c&1023)+64; d = str.charCodeAt(i++) & 1023; | ||
crc = (crc >>> 8) ^ table[(crc ^ (240|((c>>8)&7))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>2)&63))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|((d>>6)&15)|(c&3))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|(d&63))) & 0xFF]; | ||
} else { | ||
crc = (crc >>> 8) ^ table[(crc ^ (224|((c>>12)&15))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|((c>>6)&63))) & 0xFF]; | ||
crc = (crc >>> 8) ^ table[(crc ^ (128|(c&63))) & 0xFF]; | ||
} | ||
} | ||
return crc ^ -1; | ||
} | ||
module.exports = crc32_str; | ||
module.exports.buf = crc32_buf; | ||
module.exports.bstr = crc32_bstr; |
"use strict"; | ||
module.exports = require('sprintf-js').sprintf; | ||
/** | ||
* Note that this module is exclude from istanbul code coverage | ||
* TODO : complete tests (see tests/sprintf.js) for full coverage | ||
*/ | ||
var kindOf = require('mout/lang/kindOf'); | ||
var repeat = require('../string/repeat'); | ||
var re = { | ||
not_string: /[^s]/, | ||
number: /[diefg]/, | ||
json: /[j]/, | ||
not_json: /[^j]/, | ||
text: /^[^\x25]+/, | ||
modulo: /^\x25{2}/, | ||
placeholder: /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijosuxX])/, | ||
key: /^([a-z_][a-z_\d]*)/i, | ||
key_access: /^\.([a-z_][a-z_\d]*)/i, | ||
index_access: /^\[(\d+)\]/, | ||
sign: /^[\+\-]/ | ||
}; | ||
function sprintf() { | ||
var key = arguments[0], cache = sprintf.cache | ||
if (!(cache[key] && cache.hasOwnProperty(key))) { | ||
cache[key] = sprintf.parse(key) | ||
} | ||
return sprintf.format.call(null, cache[key], arguments) | ||
} | ||
sprintf.format = function(parse_tree, argv) { | ||
var cursor = 1, tree_length = parse_tree.length, node_type = "", arg, output = [], i, k, match, pad, pad_character, pad_length, is_positive = true, sign = "" | ||
for (i = 0; i < tree_length; i++) { | ||
node_type = kindOf(parse_tree[i]) | ||
if (node_type === "String") { | ||
output[output.length] = parse_tree[i] | ||
} | ||
else if (node_type === "Array") { | ||
match = parse_tree[i] // convenience purposes only | ||
if (match[2]) { // keyword argument | ||
arg = argv[cursor] | ||
for (k = 0; k < match[2].length; k++) { | ||
if (!arg.hasOwnProperty(match[2][k])) { | ||
throw new Error(sprintf("[sprintf] property '%s' does not exist", match[2][k])) | ||
} | ||
arg = arg[match[2][k]] | ||
} | ||
} | ||
else if (match[1]) { // positional argument (explicit) | ||
arg = argv[match[1]] | ||
} | ||
else { // positional argument (implicit) | ||
arg = argv[cursor++] | ||
} | ||
if (kindOf(arg) == "Function") { | ||
arg = arg() | ||
} | ||
if (re.not_string.test(match[8]) && re.not_json.test(match[8]) && (kindOf(arg) != "Number" && isNaN(arg))) { | ||
throw new TypeError(sprintf("[sprintf] expecting number but found %s", kindOf(arg))) | ||
} | ||
if (re.number.test(match[8])) { | ||
is_positive = arg >= 0 | ||
} | ||
switch (match[8]) { | ||
case "b": | ||
arg = arg.toString(2) | ||
break | ||
case "c": | ||
arg = String.fromCharCode(arg) | ||
break | ||
case "d": | ||
case "i": | ||
arg = parseInt(arg, 10) | ||
break | ||
case "j": | ||
arg = JSON.stringify(arg, null, match[6] ? parseInt(match[6]) : 0) | ||
break | ||
case "e": | ||
arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential() | ||
break | ||
case "f": | ||
arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg) | ||
break | ||
case "g": | ||
arg = match[7] ? parseFloat(arg).toPrecision(match[7]) : parseFloat(arg) | ||
break | ||
case "o": | ||
arg = arg.toString(8) | ||
break | ||
case "s": | ||
arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg) | ||
break | ||
case "u": | ||
arg = arg >>> 0 | ||
break | ||
case "x": | ||
arg = arg.toString(16) | ||
break | ||
case "X": | ||
arg = arg.toString(16).toUpperCase() | ||
break | ||
} | ||
if (re.json.test(match[8])) { | ||
output[output.length] = arg | ||
} | ||
else { | ||
if (re.number.test(match[8]) && (!is_positive || match[3])) { | ||
sign = is_positive ? "+" : "-" | ||
arg = arg.toString().replace(re.sign, "") | ||
} | ||
else { | ||
sign = "" | ||
} | ||
pad_character = match[4] ? match[4] === "0" ? "0" : match[4].charAt(1) : " " | ||
pad_length = match[6] - (sign + arg).length | ||
pad = match[6] ? (pad_length > 0 ? repeat(pad_character, pad_length) : "") : "" | ||
output[output.length] = match[5] ? sign + arg + pad : (pad_character === "0" ? sign + pad + arg : pad + sign + arg) | ||
} | ||
} | ||
} | ||
return output.join("") | ||
} | ||
sprintf.cache = {} | ||
sprintf.parse = function(fmt) { | ||
var _fmt = fmt, match = [], parse_tree = [], arg_names = 0 | ||
while (_fmt) { | ||
if ((match = re.text.exec(_fmt)) !== null) { | ||
parse_tree[parse_tree.length] = match[0] | ||
} | ||
else if ((match = re.modulo.exec(_fmt)) !== null) { | ||
parse_tree[parse_tree.length] = "%" | ||
} | ||
else if ((match = re.placeholder.exec(_fmt)) !== null) { | ||
if (match[2]) { | ||
arg_names |= 1 | ||
var field_list = [], replacement_field = match[2], field_match = [] | ||
if ((field_match = re.key.exec(replacement_field)) !== null) { | ||
field_list[field_list.length] = field_match[1] | ||
while ((replacement_field = replacement_field.substring(field_match[0].length)) !== "") { | ||
if ((field_match = re.key_access.exec(replacement_field)) !== null) { | ||
field_list[field_list.length] = field_match[1] | ||
} | ||
else if ((field_match = re.index_access.exec(replacement_field)) !== null) { | ||
field_list[field_list.length] = field_match[1] | ||
} | ||
else { | ||
throw new SyntaxError("[sprintf] failed to parse named argument key") | ||
} | ||
} | ||
} | ||
else { | ||
throw new SyntaxError("[sprintf] failed to parse named argument key") | ||
} | ||
match[2] = field_list | ||
} | ||
else { | ||
arg_names |= 2 | ||
} | ||
if (arg_names === 3) { | ||
throw new Error("[sprintf] mixing positional and named placeholders is not (yet) supported") | ||
} | ||
parse_tree[parse_tree.length] = match | ||
} | ||
else { | ||
throw new SyntaxError("[sprintf] unexpected placeholder") | ||
} | ||
_fmt = _fmt.substring(match[0].length) | ||
} | ||
return parse_tree | ||
} | ||
var vsprintf = function(fmt, argv, _argv) { | ||
_argv = (argv || []).slice(0) | ||
_argv.splice(0, 0, fmt) | ||
return sprintf.apply(null, _argv) | ||
} | ||
module.exports = sprintf; | ||
module.exports.vsprintf = vsprintf; | ||
@@ -9,6 +9,8 @@ "use strict"; | ||
if(str.length <= len) | ||
if(str.length <= Math.abs(len)) | ||
return str; | ||
if(len < 0) | ||
return pad + str.substr(len + pad.length); | ||
return str.substr(0, len - pad.length) + pad; | ||
} |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
40641
2
62
1043
1
111
- Removedcrc-32@^0.3.0
- Removedsprintf-js@^1.0.3
- Removedcrc-32@0.3.0(transitive)
- Removedsprintf-js@1.1.3(transitive)