From 62b6c3f9d08b89682fc764f689fb2b3f38c2adc2 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 17:10:48 -0500 Subject: [PATCH 01/16] Get rid of mjs --- Readme.md | 8 +----- index.d.mts | 4 --- index.d.ts | 31 ++------------------ index.js | 13 ++------- index.mjs | 81 ---------------------------------------------------- package.json | 13 +++++---- test.js | 4 +-- 7 files changed, 17 insertions(+), 137 deletions(-) delete mode 100644 index.d.mts delete mode 100644 index.mjs diff --git a/Readme.md b/Readme.md index 5951cfd..7e08065 100644 --- a/Readme.md +++ b/Readme.md @@ -13,12 +13,6 @@ then in your app: import parse from 'parse-duration' ``` -or CommonJS: - -```js -var parse = require('parse-duration') -``` - ## API ### parse(str, format='ms') @@ -90,7 +84,7 @@ parse('2e3s') // => 2000 * s And its easy to add more, including unicode: ```js -parse['сек'] = parse['sec'] +parse.unit['сек'] = parse.unit['sec'] parse('5сек') // => 5000 ``` diff --git a/index.d.mts b/index.d.mts deleted file mode 100644 index 64d0774..0000000 --- a/index.d.mts +++ /dev/null @@ -1,4 +0,0 @@ -// ./index.d.mts - -export * from './index.js' -export { default } from './index.js' diff --git a/index.d.ts b/index.d.ts index 4ac42a4..64d0774 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,29 +1,4 @@ -// ./index.d.ts +// ./index.d.mts -declare namespace parse { - /** - * convert `str` to ms - */ - type Units = - 'nanosecond' | 'ns' | - 'µs' | 'μs' | 'us' | 'microsecond' | - 'millisecond' | 'ms' | - 'second' | 'sec' | 's' | - 'minute' | 'min' | 'm' | - 'hour' | 'hr' | 'h' | - 'day' | 'd' | - 'week' | 'wk' | 'w' | - 'month' | 'b' | - 'year' | 'yr' | 'y' -} - -type Parse = { - (input: string, format?: parse.Units): number | null; - [key: string]: number; -} & { - default: Parse -} - -declare const parse: Parse; - -export = parse; +export * from './index.js' +export { default } from './index.js' diff --git a/index.js b/index.js index 6741865..f6b829a 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,5 @@ -'use strict' +let durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig -var durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig - -module.exports = parse -// enable default import syntax in typescript -module.exports.default = parse /** * conversion ratios @@ -58,10 +53,6 @@ parse.nanosecond = */ function parse(str = '', format = 'ms') { - if (!Object.prototype.hasOwnProperty.call(parse, format)) { - throw new TypeError('Invalid format "' + format + '"') - } - var result = null, prevUnits // ignore commas/placeholders str = (str + '').replace(/(\d)[,_](\d)/g, '$1$2') @@ -86,3 +77,5 @@ function parse(str = '', format = 'ms') { return result && ((result / (parse[format] || 1)) * (str[0] === '-' ? -1 : 1)) } + +export default parse diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f6b829a..0000000 --- a/index.mjs +++ /dev/null @@ -1,81 +0,0 @@ -let durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig - - -/** - * conversion ratios - */ - -parse.year = - parse.yr = - parse.y = 60000 * 60 * 24 * 365.25 - -parse.month = - parse.b = 60000 * 60 * 24 * (365.25 / 12) - -parse.week = - parse.wk = - parse.w = 60000 * 60 * 24 * 7 - -parse.day = - parse.d = 60000 * 60 * 24 - -parse.hour = - parse.hr = - parse.h = 60000 * 60 - -parse.minute = - parse.min = - parse.m = 60000 - -parse.second = - parse.sec = - parse.s = 1000 - -parse.millisecond = - parse.millisec = - parse.ms = 1 - -parse['µs'] = - parse['μs'] = - parse.us = - parse.microsecond = 1 / 1e3 - -parse.nanosecond = - parse.ns = 1 / 1e6 - - -/** - * convert `str` to ms - * - * @param {String} str - * @param {String} format - * @return {Number} - */ - -function parse(str = '', format = 'ms') { - var result = null, prevUnits - // ignore commas/placeholders - str = (str + '').replace(/(\d)[,_](\d)/g, '$1$2') - str.replace(durationRE, function (_, n, units) { - // if no units, find next smallest units or fall back to format value (ms) - if (!units) { - if (prevUnits) { - for (var u in parse) if (parse[u] < prevUnits) { units = u; break } - } - else units = format - } - else units = units.toLowerCase() - if (Object.prototype.hasOwnProperty.call(parse, units)) { - units = parse[units] - } else if (Object.prototype.hasOwnProperty.call(parse, units.replace(/s$/, ''))) { - units = parse[units.replace(/s$/, '')] - } else { - units = null - } - if (units) result = (result || 0) + Math.abs(parseFloat(n, 10)) * units, prevUnits = units - }) - - return result && ((result / (parse[format] || 1)) * (str[0] === '-' ? -1 : 1)) -} - -export default parse diff --git a/package.json b/package.json index fc49dbf..e21475b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "parse-duration", "version": "1.1.2", - "description": "convert a human readable duration string to a duration format", + "description": "Convert a human readable duration string to a duration format", "keywords": [ "parse", "duration", @@ -10,8 +10,9 @@ "module": "./index.mjs", "main": "./index.js", "types": "./index.d.ts", + "type": "module", "exports": { - "import": "./index.mjs", + "import": "./index.js", "default": "./index.js" }, "dependencies": {}, @@ -24,11 +25,13 @@ "repository": "git://github.com/jkroso/parse-duration.git", "bugs": "https://github.com/jkroso/parse-duration/issues", "author": "Jake Rosoman", + "contributors": [ + "Jake Rosoman", + "Dmitry Iv " + ], "files": [ "index.js", - "index.mjs", - "index.d.ts", - "index.d.mts" + "index.d.ts" ], "license": "MIT", "typings": "./index.d.ts" diff --git a/test.js b/test.js index 1da57ab..b43f595 100644 --- a/test.js +++ b/test.js @@ -3,7 +3,7 @@ let t = require('tape') let parse = require('./') -let { ns, h, b, s, ms, d, y, m } = parse +let { ns, h, b, s, ms, d, y, m } = parse.unit t('ms, millisecond, milliseconds', t => { t.equal(parse('100ms'), 100) @@ -126,7 +126,7 @@ t('format', t => { }) t('unicode support', t => { - parse['сек'] = parse['s'] // ru seconds + parse.unit['сек'] = parse.unit['s'] // ru seconds t.equal(parse('5сек'), 5000) t.end() }) From ddd867880a386db634b9874b66495b3d89d179a3 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 17:24:50 -0500 Subject: [PATCH 02/16] Make esm only --- index.js | 62 ++++++++-------------------------------------------- locale/en.js | 42 +++++++++++++++++++++++++++++++++++ package.json | 6 ++--- test.js | 4 ++-- 4 files changed, 55 insertions(+), 59 deletions(-) create mode 100644 locale/en.js diff --git a/index.js b/index.js index f6b829a..c90f308 100644 --- a/index.js +++ b/index.js @@ -1,48 +1,8 @@ -let durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig - - -/** - * conversion ratios - */ - -parse.year = - parse.yr = - parse.y = 60000 * 60 * 24 * 365.25 - -parse.month = - parse.b = 60000 * 60 * 24 * (365.25 / 12) - -parse.week = - parse.wk = - parse.w = 60000 * 60 * 24 * 7 - -parse.day = - parse.d = 60000 * 60 * 24 +import unit from './locale/en.js' -parse.hour = - parse.hr = - parse.h = 60000 * 60 - -parse.minute = - parse.min = - parse.m = 60000 - -parse.second = - parse.sec = - parse.s = 1000 - -parse.millisecond = - parse.millisec = - parse.ms = 1 - -parse['µs'] = - parse['μs'] = - parse.us = - parse.microsecond = 1 / 1e3 - -parse.nanosecond = - parse.ns = 1 / 1e6 +let durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig +parse.unit = unit /** * convert `str` to ms @@ -53,29 +13,25 @@ parse.nanosecond = */ function parse(str = '', format = 'ms') { - var result = null, prevUnits + let result = null, prevUnits // ignore commas/placeholders str = (str + '').replace(/(\d)[,_](\d)/g, '$1$2') str.replace(durationRE, function (_, n, units) { // if no units, find next smallest units or fall back to format value (ms) if (!units) { if (prevUnits) { - for (var u in parse) if (parse[u] < prevUnits) { units = u; break } + for (var u in parse.unit) if (parse.unit[u] < prevUnits) { units = u; break } } else units = format } else units = units.toLowerCase() - if (Object.prototype.hasOwnProperty.call(parse, units)) { - units = parse[units] - } else if (Object.prototype.hasOwnProperty.call(parse, units.replace(/s$/, ''))) { - units = parse[units.replace(/s$/, '')] - } else { - units = null - } + + units = parse.unit[units] || parse.unit[units.replace(/s$/, '')] + if (units) result = (result || 0) + Math.abs(parseFloat(n, 10)) * units, prevUnits = units }) - return result && ((result / (parse[format] || 1)) * (str[0] === '-' ? -1 : 1)) + return result && ((result / (parse.unit[format] || 1)) * (str[0] === '-' ? -1 : 1)) } export default parse diff --git a/locale/en.js b/locale/en.js new file mode 100644 index 0000000..c292675 --- /dev/null +++ b/locale/en.js @@ -0,0 +1,42 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.year = y +unit.yr = y +unit.y = y + +unit.month = y / 12 +unit.b = y / 12 + +unit.week = d * 7 +unit.wk = d * 7 +unit.w = d * 7 + +unit.day = d +unit.d = d + +unit.hour = h +unit.hr = h +unit.h = h + +unit.minute = m +unit.min = m +unit.m = m + +unit.second = 1000 +unit.sec = 1000 +unit.s = 1000 + +unit.millisecond = 1 +unit.millisec = 1 +unit.ms = 1 + +unit['µs'] = 1e-3 +unit['μs'] = 1e-3 +unit.us = 1e-3 +unit.microsecond = 1e-3 + +unit.nanosecond = 1e-6 +unit.ns = 1e-6 + +export default unit diff --git a/package.json b/package.json index e21475b..d4261c4 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,11 @@ "duration", "time" ], - "module": "./index.mjs", + "module": "./index.js", "main": "./index.js", "types": "./index.d.ts", "type": "module", "exports": { - "import": "./index.js", "default": "./index.js" }, "dependencies": {}, @@ -33,6 +32,5 @@ "index.js", "index.d.ts" ], - "license": "MIT", - "typings": "./index.d.ts" + "license": "MIT" } diff --git a/test.js b/test.js index b43f595..537e18f 100644 --- a/test.js +++ b/test.js @@ -1,7 +1,7 @@ 'use strict' -let t = require('tape') -let parse = require('./') +import t from 'tape' +import parse from './index.js' let { ns, h, b, s, ms, d, y, m } = parse.unit From 53c06933e24c0bdc75f49f9af4b8e97fed5cc1c6 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 17:27:49 -0500 Subject: [PATCH 03/16] Split proto test --- test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test.js b/test.js index 537e18f..c5bab82 100644 --- a/test.js +++ b/test.js @@ -104,8 +104,16 @@ t('invalid', t => { t.equal(parse('abc'), null) t.equal(parse(), null) t.equal(parse('I have 2 mangoes and 5 apples'), null) + t.end() +}) + +t('invalid: prototype names', t => { t.equal(parse('2call 3apply'), null) t.equal(parse('1arguments'), null) + t.equal(parse('1arguments'), null) + t.equal(parse('1constructor'), null) + t.equal(parse('1call'), null) + t.equal(parse('1name'), null) t.end() }) From 76c787ad21162883f64bce4f3f1603558fec146d Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 18:32:40 -0500 Subject: [PATCH 04/16] Add locales --- Readme.md | 17 +++++++++++++++-- locale/de.js | 15 +++++++++++++++ locale/en.js | 47 ++++++++++------------------------------------- locale/es.js | 15 +++++++++++++++ locale/fr.js | 15 +++++++++++++++ locale/ja.js | 15 +++++++++++++++ locale/pt.js | 15 +++++++++++++++ locale/ru.js | 15 +++++++++++++++ locale/zh.js | 15 +++++++++++++++ 9 files changed, 130 insertions(+), 39 deletions(-) create mode 100644 locale/de.js create mode 100644 locale/es.js create mode 100644 locale/fr.js create mode 100644 locale/ja.js create mode 100644 locale/pt.js create mode 100644 locale/ru.js create mode 100644 locale/zh.js diff --git a/Readme.md b/Readme.md index 7e08065..aa45d61 100644 --- a/Readme.md +++ b/Readme.md @@ -84,8 +84,8 @@ parse('2e3s') // => 2000 * s And its easy to add more, including unicode: ```js -parse.unit['сек'] = parse.unit['sec'] -parse('5сек') // => 5000 +parse.unit['μs'] = parse.unit['microsecond'] +parse('5μs') // => 5000 ``` The output format can also be defined @@ -93,3 +93,16 @@ The output format can also be defined ```js parse('1hr 20mins', 'm') // => 80 ``` + +## Locales + +Locale can be switched from default `en` to any other, [see /locale](/locale). + +```js +import es from 'parse-duration/locale/es.js' +import parse from 'parse-duration' + +parse.unit = es + +parse('1 hora 20 minutos', 'm') // => 80 +``` diff --git a/locale/de.js b/locale/de.js new file mode 100644 index 0000000..03d927e --- /dev/null +++ b/locale/de.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.Jahr = unit.j = y +unit.Monat = unit.mon = y / 12 +unit.Woche = unit.wo = d * 7 +unit.Tag = unit.t = d +unit.Stunde = unit.std = unit.h = h +unit.Minute = unit.min = unit.m = m +unit.Sekunde = unit.sek = unit.s = 1000 +unit.Millisekunde = unit.ms = 1 +unit['µs'] = unit['μs'] = unit.Mikrosekunde = 1e-3 +unit.Nanosekunde = unit.ns = 1e-6 + +export default unit diff --git a/locale/en.js b/locale/en.js index c292675..bf4f4c7 100644 --- a/locale/en.js +++ b/locale/en.js @@ -1,42 +1,15 @@ const unit = Object.create(null) const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 -unit.year = y -unit.yr = y -unit.y = y - -unit.month = y / 12 -unit.b = y / 12 - -unit.week = d * 7 -unit.wk = d * 7 -unit.w = d * 7 - -unit.day = d -unit.d = d - -unit.hour = h -unit.hr = h -unit.h = h - -unit.minute = m -unit.min = m -unit.m = m - -unit.second = 1000 -unit.sec = 1000 -unit.s = 1000 - -unit.millisecond = 1 -unit.millisec = 1 -unit.ms = 1 - -unit['µs'] = 1e-3 -unit['μs'] = 1e-3 -unit.us = 1e-3 -unit.microsecond = 1e-3 - -unit.nanosecond = 1e-6 -unit.ns = 1e-6 +unit.year = unit.yr = unit.y = y +unit.month = unit.b = y / 12 +unit.week = unit.wk = unit.w = d * 7 +unit.day = unit.d = d +unit.hour = unit.hr = unit.h = h +unit.minute = unit.min = unit.m = m +unit.second = unit.sec = unit.s = 1000 +unit.millisecond = unit.millisec = unit.ms = 1 +unit['µs'] = unit['μs'] = unit.us = unit.microsecond = 1e-3 +unit.nanosecond = unit.ns = 1e-6 export default unit diff --git a/locale/es.js b/locale/es.js new file mode 100644 index 0000000..269735a --- /dev/null +++ b/locale/es.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.año = unit.a = y +unit.mes = unit.b = y / 12 +unit.semana = unit.w = d * 7 +unit.día = unit.d = d +unit.hora = unit.hr = h +unit.minuto = unit.min = unit.m = m +unit.segundo = unit.sec = unit.s = 1000 +unit.milisegundo = unit.ms = 1 +unit['µs'] = unit['μs'] = unit.us = unit.microsegundo = 1e-3 +unit.nanosegundo = unit.ns = 1e-6 + +export default unit diff --git a/locale/fr.js b/locale/fr.js new file mode 100644 index 0000000..6bd9b52 --- /dev/null +++ b/locale/fr.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.année = unit.an = unit.a = y +unit.mois = unit.mo = y / 12 +unit.semaine = unit.sem = d * 7 +unit.jour = unit.j = d +unit.heure = unit.h = h +unit.minute = unit.min = unit.m = m +unit.seconde = unit.sec = unit.s = 1000 +unit.milliseconde = unit.ms = 1 +unit['µs'] = unit['μs'] = unit.microseconde = 1e-3 +unit.nanoseconde = unit.ns = 1e-6 + +export default unit diff --git a/locale/ja.js b/locale/ja.js new file mode 100644 index 0000000..647d1e4 --- /dev/null +++ b/locale/ja.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.年 = unit.年間 = y +unit.月 = unit.ヶ月 = y / 12 +unit.週 = unit.週間 = d * 7 +unit.日 = unit.d = d +unit.時間 = unit.時 = unit.h = h +unit.分 = unit.分間 = unit.m = m +unit.秒 = unit.秒間 = unit.s = 1000 +unit.ミリ秒 = unit.ms = 1 +unit['マイクロ秒'] = unit['μs'] = 1e-3 +unit.ナノ秒 = unit.ns = 1e-6 + +export default unit diff --git a/locale/pt.js b/locale/pt.js new file mode 100644 index 0000000..8f4dad0 --- /dev/null +++ b/locale/pt.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.ano = unit.a = y +unit.mês = unit.mes = y / 12 +unit.semana = unit.sem = d * 7 +unit.dia = unit.d = d +unit.hora = unit.h = h +unit.minuto = unit.min = unit.m = m +unit.segundo = unit.seg = unit.s = 1000 +unit.milissegundo = unit.ms = 1 +unit['µs'] = unit['μs'] = unit.microssegundo = 1e-3 +unit.nanossegundo = unit.ns = 1e-6 + +export default unit diff --git a/locale/ru.js b/locale/ru.js new file mode 100644 index 0000000..dde6a8e --- /dev/null +++ b/locale/ru.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.год = unit.г = unit.y = y +unit.месяц = unit.мес = unit.m = y / 12 +unit.неделя = unit.нед = unit.w = d * 7 +unit.день = unit.д = unit.d = d +unit.час = unit.ч = unit.h = h +unit.минута = unit.мин = unit.m = m +unit.секунда = unit.сек = unit.с = unit.s = 1000 +unit.миллисекунда = unit.мс = unit.ms = 1 +unit['микросекунда'] = unit['мкс'] = unit['μs'] = unit.us = 1e-3 +unit.наносекунда = unit.нс = unit.ns = 1e-6 + +export default unit diff --git a/locale/zh.js b/locale/zh.js new file mode 100644 index 0000000..60b7d0d --- /dev/null +++ b/locale/zh.js @@ -0,0 +1,15 @@ +const unit = Object.create(null) +const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 + +unit.年 = unit.y = y +unit.月 = y / 12 +unit.周 = unit.星期 = d * 7 +unit.天 = unit.日 = unit.d = d +unit.小时 = unit.时 = unit.h = h +unit.分钟 = unit.分 = unit.m = m +unit.秒 = unit.秒钟 = unit.s = 1000 +unit.毫秒 = unit.ms = 1 +unit['微秒'] = unit['μs'] = 1e-3 +unit.纳秒 = unit.ns = 1e-6 + +export default unit From c7ebf299d68e115f0db04bab1dddcf2dcac4a5df Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:06:10 -0500 Subject: [PATCH 05/16] Complete locales --- index.js | 10 ++++------ locale/de.js | 25 +++++++++++++------------ locale/en.js | 2 +- locale/es.js | 25 +++++++++++++------------ locale/fr.js | 25 +++++++++++++------------ locale/ja.js | 25 +++++++++++++------------ locale/pt.js | 25 +++++++++++++------------ locale/ru.js | 25 +++++++++++++------------ locale/zh.js | 25 +++++++++++++------------ test.js | 7 +++++++ 10 files changed, 103 insertions(+), 91 deletions(-) diff --git a/index.js b/index.js index c90f308..8fcd814 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ -import unit from './locale/en.js' +import en from './locale/en.js' let durationRE = /(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/uig -parse.unit = unit +parse.unit = en /** * convert `str` to ms @@ -12,11 +12,11 @@ parse.unit = unit * @return {Number} */ -function parse(str = '', format = 'ms') { +export default function parse(str = '', format = 'ms') { let result = null, prevUnits // ignore commas/placeholders str = (str + '').replace(/(\d)[,_](\d)/g, '$1$2') - str.replace(durationRE, function (_, n, units) { + str.replace(durationRE, (_, n, units) => { // if no units, find next smallest units or fall back to format value (ms) if (!units) { if (prevUnits) { @@ -33,5 +33,3 @@ function parse(str = '', format = 'ms') { return result && ((result / (parse.unit[format] || 1)) * (str[0] === '-' ? -1 : 1)) } - -export default parse diff --git a/locale/de.js b/locale/de.js index 03d927e..4d724ed 100644 --- a/locale/de.js +++ b/locale/de.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.Jahr = unit.j = y -unit.Monat = unit.mon = y / 12 -unit.Woche = unit.wo = d * 7 -unit.Tag = unit.t = d -unit.Stunde = unit.std = unit.h = h -unit.Minute = unit.min = unit.m = m -unit.Sekunde = unit.sek = unit.s = 1000 -unit.Millisekunde = unit.ms = 1 -unit['µs'] = unit['μs'] = unit.Mikrosekunde = 1e-3 -unit.Nanosekunde = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.jahr = unit.j = en.y +unit.monat = en.month +unit.woche = en.w +unit.tag = unit.t = en.d +unit.stunde = en.h +unit.minute = en.m +unit.sekunde = en.s +unit.millisekunde = en.ms +unit.mikrosekunde = en.us +unit.nanosekunde = en.ns export default unit diff --git a/locale/en.js b/locale/en.js index bf4f4c7..5aab77a 100644 --- a/locale/en.js +++ b/locale/en.js @@ -9,7 +9,7 @@ unit.hour = unit.hr = unit.h = h unit.minute = unit.min = unit.m = m unit.second = unit.sec = unit.s = 1000 unit.millisecond = unit.millisec = unit.ms = 1 -unit['µs'] = unit['μs'] = unit.us = unit.microsecond = 1e-3 +unit.µs = unit.μs = unit.us = unit.microsecond = 1e-3 unit.nanosecond = unit.ns = 1e-6 export default unit diff --git a/locale/es.js b/locale/es.js index 269735a..c1bb599 100644 --- a/locale/es.js +++ b/locale/es.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.año = unit.a = y -unit.mes = unit.b = y / 12 -unit.semana = unit.w = d * 7 -unit.día = unit.d = d -unit.hora = unit.hr = h -unit.minuto = unit.min = unit.m = m -unit.segundo = unit.sec = unit.s = 1000 -unit.milisegundo = unit.ms = 1 -unit['µs'] = unit['μs'] = unit.us = unit.microsegundo = 1e-3 -unit.nanosegundo = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.año = unit.a = en.y +unit.mes = unit.b = en.month +unit.semana = en.w +unit.día = en.d +unit.hora = en.h +unit.minuto = en.m +unit.segundo = en.s +unit.milisegundo = en.ms +unit.microsegundo = en.us +unit.nanosegundo = en.ns export default unit diff --git a/locale/fr.js b/locale/fr.js index 6bd9b52..aab38b3 100644 --- a/locale/fr.js +++ b/locale/fr.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.année = unit.an = unit.a = y -unit.mois = unit.mo = y / 12 -unit.semaine = unit.sem = d * 7 -unit.jour = unit.j = d -unit.heure = unit.h = h -unit.minute = unit.min = unit.m = m -unit.seconde = unit.sec = unit.s = 1000 -unit.milliseconde = unit.ms = 1 -unit['µs'] = unit['μs'] = unit.microseconde = 1e-3 -unit.nanoseconde = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.année = unit.an = unit.a = en.y +unit.mois = unit.mo = en.month +unit.semaine = unit.sem = en.w +unit.jour = unit.j = en.d +unit.heure = en.h +unit.minute = en.m +unit.seconde = en.s +unit.milliseconde = en.ms +unit.microseconde = en.us +unit.nanoseconde = en.ns export default unit diff --git a/locale/ja.js b/locale/ja.js index 647d1e4..b870a88 100644 --- a/locale/ja.js +++ b/locale/ja.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.年 = unit.年間 = y -unit.月 = unit.ヶ月 = y / 12 -unit.週 = unit.週間 = d * 7 -unit.日 = unit.d = d -unit.時間 = unit.時 = unit.h = h -unit.分 = unit.分間 = unit.m = m -unit.秒 = unit.秒間 = unit.s = 1000 -unit.ミリ秒 = unit.ms = 1 -unit['マイクロ秒'] = unit['μs'] = 1e-3 -unit.ナノ秒 = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.年 = unit.年間 = en.y +unit.月 = unit.ヶ月 = en.month +unit.週 = unit.週間 = en.w +unit.日 = en.d +unit.時間 = unit.時 = en.h +unit.分 = unit.分間 = en.m +unit.秒 = unit.秒間 = en.s +unit.ミリ秒 = en.ms +unit.マイクロ秒 = en.us +unit.ナノ秒 = en.ns export default unit diff --git a/locale/pt.js b/locale/pt.js index 8f4dad0..1c2c9d3 100644 --- a/locale/pt.js +++ b/locale/pt.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.ano = unit.a = y -unit.mês = unit.mes = y / 12 -unit.semana = unit.sem = d * 7 -unit.dia = unit.d = d -unit.hora = unit.h = h -unit.minuto = unit.min = unit.m = m -unit.segundo = unit.seg = unit.s = 1000 -unit.milissegundo = unit.ms = 1 -unit['µs'] = unit['μs'] = unit.microssegundo = 1e-3 -unit.nanossegundo = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.ano = unit.a = en.y +unit.mês = unit.mes = en.month +unit.semana = unit.sem = en.w +unit.dia = en.d +unit.hora = en.h +unit.minuto = en.m +unit.segundo = unit.seg = en.s +unit.milissegundo = en.ms +unit.microssegundo = en.us +unit.nanossegundo = en.ns export default unit diff --git a/locale/ru.js b/locale/ru.js index dde6a8e..6c87b39 100644 --- a/locale/ru.js +++ b/locale/ru.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.год = unit.г = unit.y = y -unit.месяц = unit.мес = unit.m = y / 12 -unit.неделя = unit.нед = unit.w = d * 7 -unit.день = unit.д = unit.d = d -unit.час = unit.ч = unit.h = h -unit.минута = unit.мин = unit.m = m -unit.секунда = unit.сек = unit.с = unit.s = 1000 -unit.миллисекунда = unit.мс = unit.ms = 1 -unit['микросекунда'] = unit['мкс'] = unit['μs'] = unit.us = 1e-3 -unit.наносекунда = unit.нс = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.год = unit.г = en.y +unit.месяц = unit.мес = en.month +unit.неделя = unit.нед = en.w +unit.день = unit.д = en.d +unit.час = unit.ч = en.h +unit.минута = unit.мин = en.m +unit.секунда = unit.сек = en.s +unit.миллисекунда = unit.мс = en.ms +unit.микросекунда = unit.мкс = en.us +unit.наносекунда = unit.нс = en.ns export default unit diff --git a/locale/zh.js b/locale/zh.js index 60b7d0d..72d0de6 100644 --- a/locale/zh.js +++ b/locale/zh.js @@ -1,15 +1,16 @@ -const unit = Object.create(null) -const m = 60000, h = m * 60, d = h * 24, y = d * 365.25 +import en from './en.js' -unit.年 = unit.y = y -unit.月 = y / 12 -unit.周 = unit.星期 = d * 7 -unit.天 = unit.日 = unit.d = d -unit.小时 = unit.时 = unit.h = h -unit.分钟 = unit.分 = unit.m = m -unit.秒 = unit.秒钟 = unit.s = 1000 -unit.毫秒 = unit.ms = 1 -unit['微秒'] = unit['μs'] = 1e-3 -unit.纳秒 = unit.ns = 1e-6 +const unit = Object.create(en) + +unit.年 = en.y +unit.月 = en.month +unit.周 = unit.星期 = en.w +unit.天 = unit.日 = en.d +unit.小时 = unit.时 = en.h +unit.分钟 = unit.分 = en.m +unit.秒 = unit.秒钟 = en.s +unit.毫秒 = en.ms +unit.微秒 = en.us +unit.纳秒 = en.ns export default unit diff --git a/test.js b/test.js index c5bab82..a223387 100644 --- a/test.js +++ b/test.js @@ -2,6 +2,7 @@ import t from 'tape' import parse from './index.js' +import es from './locale/es.js' let { ns, h, b, s, ms, d, y, m } = parse.unit @@ -150,3 +151,9 @@ t('upper-case characters', t => { t.equal(parse('1MS'), 1) t.end() }) + +t('locales', t => { + parse.unit = es + t.equal(parse('1 hora 20 minutos', 'm'), 80) + t.end() +}) From 873002b3f94b183fce86b52260b5c9086e2b41b3 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:06:14 -0500 Subject: [PATCH 06/16] Update Readme.md --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index aa45d61..465f9eb 100644 --- a/Readme.md +++ b/Readme.md @@ -97,6 +97,7 @@ parse('1hr 20mins', 'm') // => 80 ## Locales Locale can be switched from default `en` to any other, [see /locale](/locale). +Locales extend english locale. ```js import es from 'parse-duration/locale/es.js' @@ -105,4 +106,5 @@ import parse from 'parse-duration' parse.unit = es parse('1 hora 20 minutos', 'm') // => 80 +parse('1 hour 20 minutes', 'm') // => 80 ``` From f3bb98e6ab17b068c0e33f67ad8c52b7b15d80c0 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:07:17 -0500 Subject: [PATCH 07/16] Add meta license --- Readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Readme.md b/Readme.md index 465f9eb..d56d42c 100644 --- a/Readme.md +++ b/Readme.md @@ -108,3 +108,7 @@ parse.unit = es parse('1 hora 20 minutos', 'm') // => 80 parse('1 hour 20 minutes', 'm') // => 80 ``` + +--- + +[ॐ](https://github.com/krishnized/license) From ceec9bd8b7bfcf176ab72f59145d28c8c527e1d1 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:08:29 -0500 Subject: [PATCH 08/16] Update Readme.md --- Readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index d56d42c..b3e4cec 100644 --- a/Readme.md +++ b/Readme.md @@ -109,6 +109,4 @@ parse('1 hora 20 minutos', 'm') // => 80 parse('1 hour 20 minutes', 'm') // => 80 ``` ---- - -[ॐ](https://github.com/krishnized/license) + From 6e080522925de21ff8b30cb00b947bad306e667e Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:08:54 -0500 Subject: [PATCH 09/16] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index b3e4cec..1108370 100644 --- a/Readme.md +++ b/Readme.md @@ -109,4 +109,4 @@ parse('1 hora 20 minutos', 'm') // => 80 parse('1 hour 20 minutes', 'm') // => 80 ``` - +

From 112df5111360651b3a84cbae51ea91247ae9a743 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:09:12 -0500 Subject: [PATCH 10/16] Center --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 1108370..fdd9fca 100644 --- a/Readme.md +++ b/Readme.md @@ -109,4 +109,4 @@ parse('1 hora 20 minutos', 'm') // => 80 parse('1 hour 20 minutes', 'm') // => 80 ``` -

+

From 154e52c7a96fbeac5f61185cd3d7c6cbc7e00797 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:15:12 -0500 Subject: [PATCH 11/16] Ignore exports --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d4261c4..6c24c77 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,6 @@ "main": "./index.js", "types": "./index.d.ts", "type": "module", - "exports": { - "default": "./index.js" - }, "dependencies": {}, "devDependencies": { "tape": "^4.8.0" @@ -30,7 +27,8 @@ ], "files": [ "index.js", - "index.d.ts" + "index.d.ts", + "locale" ], "license": "MIT" } From 018bfc7cce0132afb70ca583ab89ebece5bf175c Mon Sep 17 00:00:00 2001 From: Dmitry Iv Date: Fri, 24 Jan 2025 19:15:26 -0500 Subject: [PATCH 12/16] 2.0.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d614017..fc6a0e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "parse-duration", - "version": "1.1.2", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "parse-duration", - "version": "1.1.2", + "version": "2.0.0", "license": "MIT", "devDependencies": { "tape": "^4.8.0" diff --git a/package.json b/package.json index 6c24c77..a39297e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "parse-duration", - "version": "1.1.2", + "version": "2.0.0", "description": "Convert a human readable duration string to a duration format", "keywords": [ "parse", From de26d00acbaff4556a59cbc358fd0389db6885c3 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:20:14 -0500 Subject: [PATCH 13/16] Update badge --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index fdd9fca..9c9a20f 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,5 @@ -# parse-duration [![Build Status](https://travis-ci.org/jkroso/parse-duration.svg?branch=master)](https://travis-ci.org/jkroso/parse-duration) +# parse-duration [![Test](https://github.com/jkroso/parse-duration/actions/workflows/test.yml/badge.svg)](https://github.com/jkroso/parse-duration/actions/workflows/test.yml) convert a human readable duration to ms From 555f84fdecfd1c30c5cb6af84c82b57cf86fedbc Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:37:03 -0500 Subject: [PATCH 14/16] Shorter readme --- Readme.md | 101 +++++++++++++++--------------------------------------- 1 file changed, 27 insertions(+), 74 deletions(-) diff --git a/Readme.md b/Readme.md index 9c9a20f..60632b2 100644 --- a/Readme.md +++ b/Readme.md @@ -1,103 +1,56 @@ # parse-duration [![Test](https://github.com/jkroso/parse-duration/actions/workflows/test.yml/badge.svg)](https://github.com/jkroso/parse-duration/actions/workflows/test.yml) - convert a human readable duration to ms - -## Installation +Convert a human readable duration to ms. [![NPM](https://nodei.co/npm/parse-duration.png?mini=true)](https://npmjs.org/package/parse-duration) -then in your app: +## Usage ```js import parse from 'parse-duration' -``` - -## API - -### parse(str, format='ms') - -Convert `str` to ms - -```js -var ns = parse('1ns') // => 1 / 1e6 -var μs = parse('1μs') // => 1 / 1000 -var ms = parse('1ms') // => 1 -var s = parse('1s') // => ms * 1000 -var m = parse('1m') // => s * 60 -var h = parse('1h') // => m * 60 -var d = parse('1d') // => h * 24 -var w = parse('1w') // => d * 7 -var y = parse('1y') // => d * 365.25 -``` - -It can also handle basic compound expressions -```js +// Parse different time units +let ns = parse('1ns') // => 1 / 1e6 +let μs = parse('1μs') // => 1 / 1000 +let ms = parse('1ms') // => 1 +let s = parse('1s') // => ms * 1000 +let m = parse('1m') // => s * 60 +let h = parse('1h') // => m * 60 +let d = parse('1d') // => h * 24 +let w = parse('1w') // => d * 7 +let y = parse('1y') // => d * 365.25 + +// compound expressions parse('1hr 20mins') // => 1 * h + 20 * m parse('1 hr 20 mins') // => 1 * h + 20 * m -``` - -youtube format -```js +// youtube format parse('1h20m0s') // => 1 * h + 20 * m -``` -comma seperated numbers - -```js +// comma seperated numbers parse('27,681 ns') // => 27681 * ns -``` - -And most other types of noise -```js +// noisy input parse('running length: 1hour:20mins') // => 1 * h + 20 * m -``` - -You can even use negatives -```js +// negatives parse('-1hr 40mins') // => 1 * h + 40 * m -``` -And exponents - -```js +// exponents parse('2e3s') // => 2000 * s -``` - -#### Available unit types are: -- nanoseconds (ns) -- microseconds (μs) -- milliseconds (ms) -- seconds (s, sec) -- minutes (m, min) -- hours (h, hr) -- days (d) -- weeks (w, wk) -- months -- years (y, yr) - -And its easy to add more, including unicode: - -```js -parse.unit['μs'] = parse.unit['microsecond'] -parse('5μs') // => 5000 -``` - -The output format can also be defined - -```js +// custom output format parse('1hr 20mins', 'm') // => 80 + +// add units +parse.unit['μs'] = parse.unit.microsecond +parse('5μs') // => 0.005 ``` ## Locales -Locale can be switched from default `en` to any other, [see /locale](/locale). -Locales extend english locale. +Switch the default en locale to another language ([see /locale](/locale)). ```js import es from 'parse-duration/locale/es.js' @@ -105,8 +58,8 @@ import parse from 'parse-duration' parse.unit = es -parse('1 hora 20 minutos', 'm') // => 80 -parse('1 hour 20 minutes', 'm') // => 80 +parse('1 hora 20 minutos', 'm') // 80 +parse('1 hour 20 minutes', 'm') // 80 - extends english locale ```

From 1ed3f92400cbd78ece7bd766f95a66159cf7a845 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Fri, 24 Jan 2025 19:38:02 -0500 Subject: [PATCH 15/16] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 60632b2..490f2ba 100644 --- a/Readme.md +++ b/Readme.md @@ -10,7 +10,7 @@ Convert a human readable duration to ms. ```js import parse from 'parse-duration' -// Parse different time units +// parse different time units let ns = parse('1ns') // => 1 / 1e6 let μs = parse('1μs') // => 1 / 1000 let ms = parse('1ms') // => 1 From 7f772bb062abfd7e4c648182f46ec4c5e9ebd860 Mon Sep 17 00:00:00 2001 From: "Dmitry Iv." Date: Sun, 26 Jan 2025 13:02:29 -0500 Subject: [PATCH 16/16] Add separators --- index.js | 6 +++++- locale/de.js | 3 +++ locale/en.js | 3 +++ locale/es.js | 3 +++ locale/fr.js | 3 +++ locale/ja.js | 3 +++ locale/pt.js | 3 +++ locale/ru.js | 3 +++ locale/zh.js | 3 +++ test.js | 18 ++++++++++++++++++ 10 files changed, 47 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8fcd814..ad25736 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,11 @@ parse.unit = en export default function parse(str = '', format = 'ms') { let result = null, prevUnits // ignore commas/placeholders - str = (str + '').replace(/(\d)[,_](\d)/g, '$1$2') + str = (str + '') + .replace(/(\d)[_ ](\d)/g, '$1$2') // ignore placeholders + .replaceAll(parse.unit.group, '') // remove group separator + .replaceAll(parse.unit.decimal, '.') // normalize decimal separator + str.replace(durationRE, (_, n, units) => { // if no units, find next smallest units or fall back to format value (ms) if (!units) { diff --git a/locale/de.js b/locale/de.js index 4d724ed..b8b0a45 100644 --- a/locale/de.js +++ b/locale/de.js @@ -13,4 +13,7 @@ unit.millisekunde = en.ms unit.mikrosekunde = en.us unit.nanosekunde = en.ns +unit.group = '.' +unit.decimal = ',' + export default unit diff --git a/locale/en.js b/locale/en.js index 5aab77a..bd373ff 100644 --- a/locale/en.js +++ b/locale/en.js @@ -12,4 +12,7 @@ unit.millisecond = unit.millisec = unit.ms = 1 unit.µs = unit.μs = unit.us = unit.microsecond = 1e-3 unit.nanosecond = unit.ns = 1e-6 +unit.group = ',' +unit.decimal = '.' + export default unit diff --git a/locale/es.js b/locale/es.js index c1bb599..1af9be9 100644 --- a/locale/es.js +++ b/locale/es.js @@ -13,4 +13,7 @@ unit.milisegundo = en.ms unit.microsegundo = en.us unit.nanosegundo = en.ns +unit.group = '.' +unit.decimal = ',' + export default unit diff --git a/locale/fr.js b/locale/fr.js index aab38b3..ade1de2 100644 --- a/locale/fr.js +++ b/locale/fr.js @@ -13,4 +13,7 @@ unit.milliseconde = en.ms unit.microseconde = en.us unit.nanoseconde = en.ns +unit.group = ' ' +unit.decimal = ',' + export default unit diff --git a/locale/ja.js b/locale/ja.js index b870a88..2d33e53 100644 --- a/locale/ja.js +++ b/locale/ja.js @@ -13,4 +13,7 @@ unit.ミリ秒 = en.ms unit.マイクロ秒 = en.us unit.ナノ秒 = en.ns +unit.group = ',' +unit.decimal = '.' + export default unit diff --git a/locale/pt.js b/locale/pt.js index 1c2c9d3..3db11e8 100644 --- a/locale/pt.js +++ b/locale/pt.js @@ -13,4 +13,7 @@ unit.milissegundo = en.ms unit.microssegundo = en.us unit.nanossegundo = en.ns +unit.group = '.' +unit.decimal = ',' + export default unit diff --git a/locale/ru.js b/locale/ru.js index 6c87b39..edaa012 100644 --- a/locale/ru.js +++ b/locale/ru.js @@ -13,4 +13,7 @@ unit.миллисекунда = unit.мс = en.ms unit.микросекунда = unit.мкс = en.us unit.наносекунда = unit.нс = en.ns +unit.group = ' ' +unit.decimal = ',' + export default unit diff --git a/locale/zh.js b/locale/zh.js index 72d0de6..395ad5a 100644 --- a/locale/zh.js +++ b/locale/zh.js @@ -13,4 +13,7 @@ unit.毫秒 = en.ms unit.微秒 = en.us unit.纳秒 = en.ns +unit.group = ',' +unit.decimal = '.' + export default unit diff --git a/test.js b/test.js index a223387..c29f000 100644 --- a/test.js +++ b/test.js @@ -3,6 +3,8 @@ import t from 'tape' import parse from './index.js' import es from './locale/es.js' +import en from './locale/en.js' +import de from './locale/de.js' let { ns, h, b, s, ms, d, y, m } = parse.unit @@ -157,3 +159,19 @@ t('locales', t => { t.equal(parse('1 hora 20 minutos', 'm'), 80) t.end() }) + +t('locale separators', t => { + parse.unit = en + t.equal(parse('3.14 seconds'), 3140) + t.equal(parse('"1,23,456.789 seconds'), 123456789) + t.equal(parse('"1,23,456.789s'), 123456789) + t.equal(parse('"30,000.65 seconds'), 30000650) + + parse.unit = de + t.equal(parse('3,14 seconds'), 3140) + t.equal(parse('"123.456,789 seconds'), 123456789) + t.equal(parse('"30.000,65 seconds'), 30000650) + t.equal(parse('"30 000,65 seconds'), 30000650) + t.equal(parse('"30_000,65 seconds'), 30000650) + t.end() +})