🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

humanizer

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

humanizer

Humanize a value.

Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
206
-25.36%
Maintainers
1
Weekly downloads
 
Created
Source

Humanize Build Status

Humanize a value. Humanize provides "ago" libraries-like capabilities and so on... In fact, unlike other libraries, humanize can work with any type of unit and with any scale.

npm install humanizer
var time = require('humanizer');

// Define the time unit
time = new Humanize('ms', 1) // the base unit is 1 `ms`
   .unit('day',  24*3600*1000)
   .unit('hour', 3600*1000)
   .unit('min',  60*1000)
   .unit('sec',  1000)
   .setRound(function roundFn(val){ // set a (optional) round function
    return Math.round(val*10)/10;
  });

// time.humanize(value, [preferedUnit]);
time.humanize(60*1000); // [60, 'sec']
time.humanize(20*3600*1000); // [20, 'hour']
time.humanize(20*3600*1000, 'sec'); // [20, 'sec'] (feels more like a conversion to me though)

// time.humanizeRange(value, start, end, [preferedUnit]);
time.humanizeRange(4956, +new Date(2013, 3, 29), +new Date(2013, 3, 29, 15, 47)));
// -> [314, 'hour']
// -> 314 'things' by `hour`

Keywords

humanize

FAQs

Package last updated on 29 Apr 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts