utilex

Utilex is a module that provides extra functions.

Utilex is a module that provides extra functions.

npm install utilex
var utilex = require('utilex');

Returns command line arguments

// command: node app.js --arg1 arg1Val --arg2 -arg3 arg3Val arg4 arg5 -c test/data-simple.json 
utilex.args();
// { 
//   "arg1": "arg1Val", 
//   "arg2": "", 
//   "arg3": "arg3Val", 
//   "arg4": "", 
//   "arg5": "", 
//   "c": "test/data-simple.json" 
// } 

Clears console

node -'require("./lib/utilex").consoleClear()'

Checks whether given directory is writable or not

utilex.dirIsWritable(__dirname);
// true 

Downloads file

utilex.download('http://www.google.com/images/srpr/logo11w.png', './google-logo.png', function(errfp) {
  if(err) console.log(err);
  console.log(fp + ' is downloaded.');
});
// done! 

Loads JSON file

utilex.jsonLoad('test/data-simple.json');
// { testKey: 'testVal' } 

Returns the length of given string

utilex.strLen('Hello 世界');
// 8 
utilex.strLen('Hello 世界', true);
// 12 

Returns a tasker for handling async events

var tasker = utilex.tasker();
 
tasker.results = [];
tasker.add({counter: 0});
tasker.run(function(tasknext) {
  tasker.results.push(++task.counter);
  if(task.counter < 10) {
    tasker.add({counter: task.counter});
  }
  next();
}, function() {
  console.log(tasker.results);
});
// [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] 

Returns an unique id

utilex.uid();
// '43cdacfded3a47298b32bfa47269fdd2b55b33d6' 

Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.