0.1.14 • Published 10 years ago

utilz v0.1.14

Weekly downloads
65
License
-
Repository
github
Last release
10 years ago

Utilz - Various Small Utility Functions for Node.js

Usage

npm install utilz

var utilz = require('utilz');

Examples

watchFile(fileName?)

Watch the specificed .js file and quit the server to restart if it has changed. Best used with Supervisord, or Forever (when it matures). filename: the file to watch, may be relative to process.cwd(); current .js if omitted.

utilz.watchFile();
utilz.watchFile(__dirname + '/other.js');

In production (NODE_ENV === 'production'), this will not restart imediatelly, but rather wait 2 seconds, to allow for all files to be replaced first, in the case of a full update.

timeSpan(timespanInMs)

Display time duration in human readable format, from number of days to milliseconds. t: the time interval in milliseconds.

var t1 = Date.now();
var t2 = new Date('Mon, 21 Dec 2012 21:20:12 GMT').getTime();

console.log(utilz.timeSpan(t2 - t1));

This will display an interval in the form of:

368d 11h 41m 17s 57ms

formatNumber(number, fractionDigits)

Format a number to the number of decimal places specified. n: the number to format. fr: the number of decimal places.

var n = 3.14159265;

console.log(utilz.formatNumber(n, 3));
console.log(utilz.formatNumber(n, 0));

This will display:

3.142
3

More...

More functions will be added in the future.

0.1.14

10 years ago

0.1.13

11 years ago

0.1.12

11 years ago

0.1.11

11 years ago

0.1.9

11 years ago

0.1.8

11 years ago

0.1.7

11 years ago

0.1.6

12 years ago

0.1.5

12 years ago

0.1.4

12 years ago

0.1.3

12 years ago

0.1.1

12 years ago

0.1.0

12 years ago