upgrade standard

This commit is contained in:
Michael Barrett 2019-08-24 10:02:47 +01:00
parent db9e0ec172
commit 58615f756d
4 changed files with 548 additions and 471 deletions

View File

@ -38,18 +38,18 @@ const UNIT_MAP = {
/**
* Parse a timestring
*
* @param {String} string
* @param {String} returnUnit
* @param {Object} opts
* @return {Number}
* @param {string} string
* @param {string} returnUnit
* @param {Object} opts
* @returns {number}
*/
function parseTimestring (string, returnUnit, opts) {
opts = Object.assign({}, DEFAULT_OPTS, opts || {})
let totalSeconds = 0
let unitValues = getUnitValues(opts)
let groups = string
const unitValues = getUnitValues(opts)
const groups = string
.toLowerCase()
.replace(/[^.\w+-]+/g, '')
.match(/[-+]?[0-9.]+[a-z]+/g)
@ -59,8 +59,8 @@ function parseTimestring (string, returnUnit, opts) {
}
groups.forEach(group => {
let value = group.match(/[0-9.]+/g)[0]
let unit = group.match(/[a-z]+/g)[0]
const value = group.match(/[0-9.]+/g)[0]
const unit = group.match(/[a-z]+/g)[0]
totalSeconds += getSeconds(value, unit, unitValues)
})
@ -80,7 +80,7 @@ function parseTimestring (string, returnUnit, opts) {
*/
function getUnitValues (opts) {
let unitValues = {
const unitValues = {
ms: 0.001,
s: 1,
m: 60,
@ -98,12 +98,12 @@ function getUnitValues (opts) {
/**
* Get the key for a unit
*
* @param {String} unit
* @returns {String}
* @param {string} unit
* @returns {string}
*/
function getUnitKey (unit) {
for (let key of Object.keys(UNIT_MAP)) {
for (const key of Object.keys(UNIT_MAP)) {
if (UNIT_MAP[key].indexOf(unit) > -1) {
return key
}
@ -115,10 +115,10 @@ function getUnitKey (unit) {
/**
* Get the number of seconds for a value, based on the unit
*
* @param {Number} value
* @param {String} unit
* @param {number} value
* @param {string} unit
* @param {Object} unitValues
* @returns {Number}
* @returns {number}
*/
function getSeconds (value, unit, unitValues) {
@ -128,10 +128,10 @@ function getSeconds (value, unit, unitValues) {
/**
* Convert a value from its existing unit to a new unit
*
* @param {Number} value
* @param {String} unit
* @param {number} value
* @param {string} unit
* @param {Object} unitValues
* @returns {Number}
* @returns {number}
*/
function convert (value, unit, unitValues) {

969
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -30,11 +30,11 @@
},
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"coveralls": "^3.0.6",
"istanbul": "^0.4.5",
"mocha": "^6.1.4",
"mocha": "^6.2.0",
"mocha-lcov-reporter": "1.3.0",
"standard": "^12.0.1",
"standard": "^13.1.0",
"watch": "^1.0.2"
}
}

View File

@ -1,10 +1,8 @@
/* globals describe, it */
const chai = require('chai')
const { expect } = require('chai')
const timestring = require('./index')
const expect = chai.expect
describe('timestring', () => {
it('can parse a timestring', () => {
expect(timestring('500ms')).to.equal(0.5)
@ -18,7 +16,7 @@ describe('timestring', () => {
})
it('can parse different unit identifiers', () => {
let unitMap = {
const unitMap = {
ms: ['ms', 'milli', 'millisecond', 'milliseconds'],
s: ['s', 'sec', 'secs', 'second', 'seconds'],
m: ['m', 'min', 'mins', 'minute', 'minutes'],
@ -69,7 +67,7 @@ describe('timestring', () => {
})
it('uses the passed options instead of the defaults', () => {
let opts = {
const opts = {
hoursPerDay: 1,
daysPerWeek: 2,
weeksPerMonth: 3,