Socket
Socket
Sign inDemoInstall

pretty-time

Package Overview
Dependencies
2
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 1.0.0

43

index.js
/*!
* pretty-time <https://github.com/jonschlinkert/pretty-time>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
* Copyright (c) 2015, 2018, Jon Schlinkert.
* Released under the MIT License.
*/

@@ -10,17 +10,7 @@

var isNumber = require('is-number');
var nano = require('nanoseconds');
var utils = require('./utils');
var scale = {
'w': 6048e11,
'd': 864e11,
'h': 36e11,
'm': 6e10,
's': 1e9,
'ms': 1e6,
'μs': 1e3,
'ns': 1,
};
const nano = require('nanoseconds');
const isNumber = require('is-number');
const utils = require('./utils');
function pretty(time, smallest, digits) {
module.exports = (time, smallest, digits) => {
if (!isNumber(time) && !Array.isArray(time)) {

@@ -38,9 +28,9 @@ throw new TypeError('expected an array or number in nanoseconds');

var num = isNumber(time) ? time : nano(time);
var res = '';
var prev;
let num = isNumber(time) ? time : nano(time);
let res = '';
let prev;
for (var uom in scale) {
var step = scale[uom];
var inc = num / step;
for (const uom of Object.keys(utils.scale)) {
const step = utils.scale[uom];
let inc = num / step;

@@ -67,9 +57,4 @@ if (smallest && utils.isSmallest(uom, smallest)) {

}
return res.trim();
}
/**
* Expose `pretty`
*/
module.exports = pretty;
};
{
"name": "pretty-time",
"description": "Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.",
"version": "0.2.0",
"version": "1.0.0",
"homepage": "https://github.com/jonschlinkert/pretty-time",

@@ -18,3 +18,3 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"engines": {
"node": ">=0.10.0"
"node": ">=4"
},

@@ -25,12 +25,8 @@ "scripts": {

"dependencies": {
"is-number": "^2.0.2",
"nanoseconds": "^0.1.0"
"is-number": "^5.0.0",
"nanoseconds": "^1.0.0"
},
"devDependencies": {
"gulp": "^3.9.0",
"gulp-istanbul": "^0.10.1",
"gulp-jshint": "^1.11.2",
"gulp-mocha": "^2.1.3",
"jshint-stylish": "^2.0.1",
"mocha": "*"
"gulp-format-md": "^1.0.0",
"mocha": "^3.5.3"
},

@@ -55,8 +51,16 @@ "keywords": [

"verb": {
"toc": false,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"related": {
"list": [
"o-clock",
"seconds",
"time-stamp",
"timescale",
"o-clock",
"seconds",
"week",

@@ -66,4 +70,7 @@ "weekday",

]
},
"lint": {
"reflinks": true
}
}
}

@@ -1,11 +0,13 @@

# pretty-time [![NPM version](https://badge.fury.io/js/pretty-time.svg)](http://badge.fury.io/js/pretty-time) [![Build Status](https://travis-ci.org/jonschlinkert/pretty-time.svg)](https://travis-ci.org/jonschlinkert/pretty-time)
# pretty-time [![NPM version](https://img.shields.io/npm/v/pretty-time.svg?style=flat)](https://www.npmjs.com/package/pretty-time) [![NPM monthly downloads](https://img.shields.io/npm/dm/pretty-time.svg?style=flat)](https://npmjs.org/package/pretty-time) [![NPM total downloads](https://img.shields.io/npm/dt/pretty-time.svg?style=flat)](https://npmjs.org/package/pretty-time) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/pretty-time.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/pretty-time)
> Easily format the time from node.js `process.hrtime`. Works with timescales ranging from weeks to nanoseconds.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
## Install
Install with [npm](https://www.npmjs.com/)
Install with [npm](https://www.npmjs.com/):
```sh
$ npm i pretty-time --save
$ npm install --save pretty-time
```

@@ -100,38 +102,69 @@

## Related projects
## About
* [o-clock](https://www.npmjs.com/package/o-clock): Simple utility for displaying the time in 12-hour clock format. | [homepage](https://github.com/jonschlinkert/o-clock)
* [seconds](https://www.npmjs.com/package/seconds): Get the number of seconds for a minute, hour, day and week. | [homepage](https://github.com/jonschlinkert/seconds)
* [time-stamp](https://www.npmjs.com/package/time-stamp): Get a formatted timestamp. | [homepage](https://github.com/jonschlinkert/time-stamp)
* [timescale](https://www.npmjs.com/package/timescale): Convert from one time scale to another. Nanosecond is the most atomic unit, week is… [more](https://www.npmjs.com/package/timescale) | [homepage](https://github.com/jonschlinkert/timescale)
* [week](https://www.npmjs.com/package/week): Get the current week number. | [homepage](https://github.com/jonschlinkert/week)
* [weekday](https://www.npmjs.com/package/weekday): Get the name and number of the current weekday. Or get the name of the… [more](https://www.npmjs.com/package/weekday) | [homepage](https://github.com/jonschlinkert/weekday)
* [year](https://www.npmjs.com/package/year): Simple utility to get the current year with 2 or 4 digits. | [homepage](https://github.com/jonschlinkert/year)
<details>
<summary><strong>Contributing</strong></summary>
## Running tests
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Install dev dependencies:
</details>
<details>
<summary><strong>Running Tests</strong></summary>
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
```sh
$ npm i -d && npm test
$ npm install && npm test
```
## Contributing
</details>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/pretty-time/issues/new).
<details>
<summary><strong>Building docs</strong></summary>
## Author
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
</details>
### Related projects
You might also be interested in these projects:
* [o-clock](https://www.npmjs.com/package/o-clock): Simple javascript utility for displaying the time in 12-hour clock format. | [homepage](https://github.com/jonschlinkert/o-clock "Simple javascript utility for displaying the time in 12-hour clock format.")
* [seconds](https://www.npmjs.com/package/seconds): Get the number of seconds for a minute, hour, day and week. | [homepage](https://github.com/jonschlinkert/seconds "Get the number of seconds for a minute, hour, day and week.")
* [time-stamp](https://www.npmjs.com/package/time-stamp): Get a formatted timestamp. | [homepage](https://github.com/jonschlinkert/time-stamp "Get a formatted timestamp.")
* [timescale](https://www.npmjs.com/package/timescale): Convert from one time scale to another. Nanosecond is the most atomic unit, week is… [more](https://github.com/jonschlinkert/timescale) | [homepage](https://github.com/jonschlinkert/timescale "Convert from one time scale to another. Nanosecond is the most atomic unit, week is the largest unit.")
* [week](https://www.npmjs.com/package/week): Get the current week number. | [homepage](https://github.com/datetime/week "Get the current week number.")
* [weekday](https://www.npmjs.com/package/weekday): Get the name and number of the current weekday. Or get the name of the… [more](https://github.com/datetime/weekday) | [homepage](https://github.com/datetime/weekday "Get the name and number of the current weekday. Or get the name of the weekday for a given number.")
* [year](https://www.npmjs.com/package/year): Simple utility to get the current year with 2 or 4 digits. | [homepage](https://github.com/jonschlinkert/year "Simple utility to get the current year with 2 or 4 digits.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 10 | [jonschlinkert](https://github.com/jonschlinkert) |
| 5 | [doowb](https://github.com/doowb) |
### Author
**Jon Schlinkert**
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
## License
### License
Copyright © 2015 Jon Schlinkert
Released under the MIT license.
Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 18, 2015._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on March 19, 2018._

@@ -1,12 +0,15 @@

'use strict';
const isNumber = require('is-number');
var isNumber = require('is-number');
exports.scale = {
'w': 6048e11,
'd': 864e11,
'h': 36e11,
'm': 6e10,
's': 1e9,
'ms': 1e6,
'μs': 1e3,
'ns': 1,
};
/**
* Expose `utils`
*/
var utils = module.exports;
utils.regex = {
exports.regex = {
'w': /^(w((ee)?k)?s?)$/,

@@ -22,12 +25,9 @@ 'd': /^(d(ay)?s?)$/,

utils.isSmallest = function(uom, unit) {
return utils.regex[uom].test(unit);
exports.isSmallest = function(uom, unit) {
return exports.regex[uom].test(unit);
};
utils.round = function(num, digits) {
num = Math.abs(num);
if (isNumber(digits)) {
return num.toFixed(digits);
}
return Math.round(num);
exports.round = function(num, digits) {
const n = Math.abs(num);
return isNumber(digits) ? n.toFixed(digits) : Math.round(n);
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc