Gathering detailed insights and metrics for humanizer
Gathering detailed insights and metrics for humanizer
Gathering detailed insights and metrics for humanizer
Gathering detailed insights and metrics for humanizer
npm install humanizer
70.7
Supply Chain
76
Quality
74.9
Maintenance
25
Vulnerability
100
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
9 Commits
1 Forks
3 Watching
4 Branches
1 Contributors
Updated on 22 Jan 2015
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
48%
37
Compared to previous day
Last week
110.6%
139
Compared to previous week
Last month
-17.3%
591
Compared to previous month
Last year
11.1%
6,188
Compared to previous year
1
3
Humanizer a value. Humanizer
provides "ago" libraries-like capabilities and so on...
In fact, unlike other libraries, humanizer
can work with any type of unit at any scale.
Humanizer is tested against browsers and NodeJS.
1npm install humanizer
1var Humanizer = require('humanizer'); 2 3// Define the time unit 4time = new Humanizer('ms', 1) // the base unit is 1 `ms` 5 .unit('day', 24*3600*1000) 6 .unit('hour', 3600*1000) 7 .unit('min', 60*1000) 8 .unit('sec', 1000) 9 .setRound(function roundFn(val){ // set a (optional) round function 10 return Math.round(val*10)/10; 11 }); 12 13 14### `humanizer.humanize(value, [toUnit])` 15 16```javascript 17time.humanize(60*1000); // returns [60, 'sec'] 18time.humanize(20*3600*1000); // returns [20, 'hour'] 19time.humanize(20*3600*1000, 'sec'); // returns [20, 'sec'] (we just did a unit conversion)
humanizer.humanizeRange({Number}value, {Number}start, {Number}end, [{Unit}toUnit])
1time.humanizeRange(4956, +new Date(2013, 3, 29), +new Date(2013, 3, 29, 15, 47)));
Returns [314, 'hour']
which we could translate to 314 things per hour
.
Sometimes you may want to specify a prefered unit:
1time.humanizeRange(100, +new Date(), +new Date()+(24*3600*1000), 'min');
Returns [0.1, 'min']
. Humm that's not good enough, we wanted the "min" unit but "0.1 things per min" do not say much to the user.
humanizer.smartMode({Boolean}toggle)
1time.smartMode(true);
With smartMode enabled if the value in toUnit
is to low (less than 1) humanizer will automatically find the best unit to display it.
1time.humanizeRange(100, +new Date(), +new Date()+(24*3600*1000), 'min');
Returns [4.2, 'hour']
, now that's better.
In fact the previous line with smartMode === true
is the same as humanizeRange
without the toUnit
argument when the value is less than 0.
1time.humanizeRange(100, +new Date(), +new Date()+(24*3600*1000));
humanizer.setSelector({Function}f(currentValue, unit, rawValue))
Well, but sometimes you may want to tell humanizer when a value is "good enough" and when it's not. By default, humanizer use the following function
1Humanize.DEFAULT_SELECTOR; // => 2function(currentValue, unit, rawValue){ 3 return currentValue > 1 && currentValue < 1000; 4}
To change this, just use time.setSelector({Function});
1time.setSelector(function(currentValue, unit, rawValue){ 2 return currentValue > 10 && currentValue < 1000; 3});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/9 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More