mocha 5.1.0 → 6.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +653 -981
- package/README.md +2 -1
- package/{images → assets/growl}/error.png +0 -0
- package/{images → assets/growl}/ok.png +0 -0
- package/bin/_mocha +4 -595
- package/bin/mocha +84 -58
- package/bin/options.js +6 -39
- package/browser-entry.js +21 -17
- package/lib/browser/growl.js +164 -2
- package/lib/browser/progress.js +11 -11
- package/lib/{template.html → browser/template.html} +0 -0
- package/lib/browser/tty.js +2 -2
- package/lib/cli/cli.js +68 -0
- package/lib/cli/commands.js +13 -0
- package/lib/cli/config.js +79 -0
- package/lib/cli/index.js +9 -0
- package/lib/cli/init.js +37 -0
- package/lib/cli/node-flags.js +48 -0
- package/lib/cli/one-and-dones.js +70 -0
- package/lib/cli/options.js +299 -0
- package/lib/cli/run-helpers.js +328 -0
- package/lib/cli/run-option-metadata.js +72 -0
- package/lib/cli/run.js +293 -0
- package/lib/context.js +14 -14
- package/lib/errors.js +139 -0
- package/lib/growl.js +135 -0
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +14 -13
- package/lib/interfaces/common.js +59 -16
- package/lib/interfaces/exports.js +4 -7
- package/lib/interfaces/qunit.js +8 -10
- package/lib/interfaces/tdd.js +10 -11
- package/lib/mocha.js +442 -255
- package/lib/mocharc.json +10 -0
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +92 -117
- package/lib/reporters/doc.js +18 -9
- package/lib/reporters/dot.js +13 -13
- package/lib/reporters/html.js +76 -47
- package/lib/reporters/json-stream.js +38 -23
- package/lib/reporters/json.js +26 -23
- package/lib/reporters/landing.js +9 -8
- package/lib/reporters/list.js +11 -10
- package/lib/reporters/markdown.js +13 -12
- package/lib/reporters/min.js +4 -3
- package/lib/reporters/nyan.js +36 -35
- package/lib/reporters/progress.js +8 -7
- package/lib/reporters/spec.js +14 -11
- package/lib/reporters/tap.js +243 -32
- package/lib/reporters/xunit.js +52 -33
- package/lib/runnable.js +103 -90
- package/lib/runner.js +156 -107
- package/lib/stats-collector.js +81 -0
- package/lib/suite.js +57 -51
- package/lib/test.js +13 -13
- package/lib/utils.js +192 -103
- package/mocha.js +3836 -2046
- package/package.json +122 -38
- package/bin/.eslintrc.yml +0 -3
- package/lib/browser/.eslintrc.yml +0 -4
- package/lib/ms.js +0 -94
- package/lib/reporters/base.js.orig +0 -498
- package/lib/reporters/json.js.orig +0 -128
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mocha",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-1",
|
|
4
4
|
"description": "simple, flexible, fun test framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mocha",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"badunk <baduncaduncan@gmail.com>",
|
|
57
57
|
"Bamieh <ahmadbamieh@gmail.com>",
|
|
58
58
|
"Ben Bradley <ben@bradleyit.com>",
|
|
59
|
+
"Ben Glassman <benglass@users.noreply.github.com>",
|
|
59
60
|
"Ben Harris <benhdev@gmail.com>",
|
|
60
61
|
"Ben Hutchison <ben@aldaviva.com>",
|
|
61
62
|
"Ben Lindsey <ben.lindsey@vungle.com>",
|
|
@@ -74,6 +75,7 @@
|
|
|
74
75
|
"Brian Lalor <blalor@bravo5.org>",
|
|
75
76
|
"Brian M. Carlson <brian.m.carlson@gmail.com>",
|
|
76
77
|
"Brian Moore <guardbionic-github@yahoo.com>",
|
|
78
|
+
"Brittany Moore <moore.brittanyann@gmail.com>",
|
|
77
79
|
"Bryan Donovan <bdondo@gmail.com>",
|
|
78
80
|
"Buck Doyle <b@chromatin.ca>",
|
|
79
81
|
"C. Scott Ananian <cscott@cscott.net>",
|
|
@@ -83,6 +85,7 @@
|
|
|
83
85
|
"Casey Foster <casey@caseywebdev.com>",
|
|
84
86
|
"Charles Lowell <cowboyd@frontside.io>",
|
|
85
87
|
"Charles Merriam <charles.merriam@gmail.com>",
|
|
88
|
+
"Charles Samborski <demurgos@demurgos.net>",
|
|
86
89
|
"Charlie Rudolph <charles.w.rudolph@gmail.com>",
|
|
87
90
|
"Chris <chrisleck@users.noreply.github.com>",
|
|
88
91
|
"Chris Buckley <chris@cmbuckley.co.uk>",
|
|
@@ -107,8 +110,10 @@
|
|
|
107
110
|
"David Henderson <david.henderson@triggeredmessaging.com>",
|
|
108
111
|
"David M. Lee <leedm777@yahoo.com>",
|
|
109
112
|
"David Neubauer <davidneub@gmail.com>",
|
|
113
|
+
"DavNej <davnej.dev@gmail.com>",
|
|
110
114
|
"Denis Bardadym <bardadymchik@gmail.com>",
|
|
111
115
|
"Devin Weaver <suki@tritarget.org>",
|
|
116
|
+
"dfberry <dinaberry@outlook.com>",
|
|
112
117
|
"Di Wu <dwu@palantir.com>",
|
|
113
118
|
"Dina Berry <dfberry@users.noreply.github.com>",
|
|
114
119
|
"Diogo Monteiro <diogo.gmt@gmail.com>",
|
|
@@ -129,12 +134,15 @@
|
|
|
129
134
|
"Erik Eng <mail@ptz0n.se>",
|
|
130
135
|
"Eugene Tiutiunnyk <eugene.tiutiunnyk@lookout.com>",
|
|
131
136
|
"Fabio M. Costa <fabiomcosta@gmail.com>",
|
|
137
|
+
"Fábio Santos <fabiosantosart@gmail.com>",
|
|
132
138
|
"Fagner Brack <github3@fagnermartins.com>",
|
|
139
|
+
"fargies <fargies@users.noreply.github.com>",
|
|
133
140
|
"FARKAS Máté <mate.farkas@virtual-call-center.eu>",
|
|
134
141
|
"fcrisci <fabio.crisci@amadeus.com>",
|
|
135
142
|
"Fede Ramirez <i@2fd.me>",
|
|
136
143
|
"Fedor Indutny <fedor.indutny@gmail.com>",
|
|
137
144
|
"fengmk2 <fengmk2@gmail.com>",
|
|
145
|
+
"Fin Chen <finfin@gmail.com>",
|
|
138
146
|
"Florian Margaine <florian@margaine.com>",
|
|
139
147
|
"FND <FND@users.noreply.github.com>",
|
|
140
148
|
"fool2fish <fool2fish@gmail.com>",
|
|
@@ -151,6 +159,7 @@
|
|
|
151
159
|
"gaye <gaye@mozilla.com>",
|
|
152
160
|
"gigadude <gigadude@users.noreply.github.com>",
|
|
153
161
|
"Giovanni Bassi <giggio@giggio.net>",
|
|
162
|
+
"gizemkeser <44727928+gizemkeser@users.noreply.github.com>",
|
|
154
163
|
"Glen Huang <curvedmark@gmail.com>",
|
|
155
164
|
"Glen Mailer <glenjamin@gmail.com>",
|
|
156
165
|
"grasGendarme <me@grasgendar.me>",
|
|
@@ -193,6 +202,7 @@
|
|
|
193
202
|
"Jason Lai <jason@getpebble.com>",
|
|
194
203
|
"Jason Leyba <jmleyba@gmail.com>",
|
|
195
204
|
"Javier Aranda <javierav@javierav.com>",
|
|
205
|
+
"Jayasankar <jayasankar.m@gmail.com>",
|
|
196
206
|
"Jean Ponchon <gelule@gmail.com>",
|
|
197
207
|
"Jeff Kunkle <jeff.kunkle@nearinfinity.com>",
|
|
198
208
|
"Jeff Schilling <jeff.schilling@q2ebanking.com>",
|
|
@@ -229,6 +239,7 @@
|
|
|
229
239
|
"Joshua Krall <joshuakrall@pobox.com>",
|
|
230
240
|
"JP Bochi <jpbochi@gmail.com>",
|
|
231
241
|
"jsdevel <js.developer.undefined@gmail.com>",
|
|
242
|
+
"Juerg B <44573692+juergba@users.noreply.github.com>",
|
|
232
243
|
"Julien Wajsberg <felash@gmail.com>",
|
|
233
244
|
"Jupp Müller <jupp0r@gmail.com>",
|
|
234
245
|
"Jussi Virtanen <jussi.k.virtanen@gmail.com>",
|
|
@@ -264,8 +275,10 @@
|
|
|
264
275
|
"Mal Graty <mal.graty@googlemail.com>",
|
|
265
276
|
"Marais Rossouw <me@maraisr.com>",
|
|
266
277
|
"Marc Kuo <kuomarc2@gmail.com>",
|
|
278
|
+
"Marc Udoff <mlucool@gmail.com>",
|
|
267
279
|
"Marcello Bastea-Forte <marcello@cellosoft.com>",
|
|
268
280
|
"Mark Banner <standard8@mozilla.com>",
|
|
281
|
+
"Mark Owsiak <mark.owsiak@gmail.com>",
|
|
269
282
|
"Markus Tacker <m@coderbyheart.com>",
|
|
270
283
|
"Martin Marko <marcus@gratex.com>",
|
|
271
284
|
"Mathieu Desvé <mathieudesve@MacBook-Pro-de-Mathieu.local>",
|
|
@@ -299,6 +312,7 @@
|
|
|
299
312
|
"Nathan Rajlich <nathan@tootallnate.net>",
|
|
300
313
|
"nexdrew <andrew.goode@nextraq.com>",
|
|
301
314
|
"Nick Fitzgerald <fitzgen@gmail.com>",
|
|
315
|
+
"Nicolas Girault <nic.girault@gmail.com>",
|
|
302
316
|
"Nicolo Taddei <taddei.uk@gmail.com>",
|
|
303
317
|
"Nik Nyby <nnyby@columbia.edu>",
|
|
304
318
|
"Nikolaos Georgiou <Nikolaos.Georgiou@gmail.com>",
|
|
@@ -311,11 +325,13 @@
|
|
|
311
325
|
"Oscar Godson <oscargodson@outlook.com>",
|
|
312
326
|
"Outsider <outsideris@gmail.com>",
|
|
313
327
|
"oveddan <stangogh@gmail.com>",
|
|
328
|
+
"P. Roebuck <plroebuck@users.noreply.github.com>",
|
|
314
329
|
"Panu Horsmalahti <panu.horsmalahti@iki.fi>",
|
|
315
330
|
"Parker Moore <parkrmoore@gmail.com>",
|
|
316
331
|
"Pat Finnigan <patrick.k.finnigan@gmail.com>",
|
|
317
332
|
"Paul Armstrong <paul@paularmstrongdesigns.com>",
|
|
318
333
|
"Paul Miller <paul@paulmillr.com>",
|
|
334
|
+
"Paul Roebuck <plroebuck@users.noreply.github.com>",
|
|
319
335
|
"Pavel Zubkou <pavel.zubkou@gmail.com>",
|
|
320
336
|
"Pete Hawkins <pete@petes-imac.frontinternal.net>",
|
|
321
337
|
"Peter Müller <munter@fumle.dk>",
|
|
@@ -389,6 +405,7 @@
|
|
|
389
405
|
"Stone <baoshi.li@adleida.com>",
|
|
390
406
|
"Sulabh Bista <sul4bh@gmail.com>",
|
|
391
407
|
"Sune Simonsen <sune@we-knowhow.dk>",
|
|
408
|
+
"Svetlana <39729453+Lana-Light@users.noreply.github.com>",
|
|
392
409
|
"Tapiwa Kelvin <tapiwa@munzwa.tk>",
|
|
393
410
|
"Ted Yavuzkurt <hello@TedY.io>",
|
|
394
411
|
"Teddy Zeenny <teddyzeenny@gmail.com>",
|
|
@@ -398,11 +415,13 @@
|
|
|
398
415
|
"Thomas Grainger <tagrain@gmail.com>",
|
|
399
416
|
"Thomas Vantuycom <thomasvantuycom@protonmail.com>",
|
|
400
417
|
"Tim Ehat <timehat@gmail.com>",
|
|
418
|
+
"Tim Harshman <goteamtim+git@gmail.com>",
|
|
401
419
|
"Timo Tijhof <krinklemail@gmail.com>",
|
|
402
420
|
"Timothy Gu <timothygu99@gmail.com>",
|
|
403
421
|
"Tingan Ho <tingan87@gmail.com>",
|
|
404
422
|
"tmont <tommy.mont@gmail.com>",
|
|
405
423
|
"Tobias Bieniek <tobias.bieniek@gmail.com>",
|
|
424
|
+
"Tobias Mollstam <tobias@mollstam.com>",
|
|
406
425
|
"Todd Agulnick <tagulnick@onjack.com>",
|
|
407
426
|
"Tom Coquereau <tom@thau.me>",
|
|
408
427
|
"Tom Hughes <tom@compton.nu>",
|
|
@@ -441,81 +460,146 @@
|
|
|
441
460
|
"type": "git",
|
|
442
461
|
"url": "https://github.com/mochajs/mocha.git"
|
|
443
462
|
},
|
|
463
|
+
"bugs": {
|
|
464
|
+
"url": "https://github.com/mochajs/mocha/issues/"
|
|
465
|
+
},
|
|
466
|
+
"homepage": "https://mochajs.org/",
|
|
467
|
+
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
|
|
468
|
+
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",
|
|
444
469
|
"bin": {
|
|
445
470
|
"mocha": "./bin/mocha",
|
|
446
471
|
"_mocha": "./bin/_mocha"
|
|
447
472
|
},
|
|
473
|
+
"directories": {
|
|
474
|
+
"lib": "./lib",
|
|
475
|
+
"test": "./test"
|
|
476
|
+
},
|
|
448
477
|
"engines": {
|
|
449
|
-
"node": ">=
|
|
478
|
+
"node": ">= 6.0.0"
|
|
450
479
|
},
|
|
451
480
|
"scripts": {
|
|
452
481
|
"prepublishOnly": "nps test clean build",
|
|
453
482
|
"start": "nps",
|
|
454
|
-
"test": "nps test"
|
|
483
|
+
"test": "nps test",
|
|
484
|
+
"version": "nps version"
|
|
455
485
|
},
|
|
456
486
|
"dependencies": {
|
|
487
|
+
"ansi-colors": "3.2.3",
|
|
457
488
|
"browser-stdout": "1.3.1",
|
|
458
|
-
"
|
|
459
|
-
"debug": "3.1.0",
|
|
489
|
+
"debug": "3.2.6",
|
|
460
490
|
"diff": "3.5.0",
|
|
461
491
|
"escape-string-regexp": "1.0.5",
|
|
462
|
-
"
|
|
463
|
-
"
|
|
464
|
-
"
|
|
492
|
+
"findup-sync": "2.0.0",
|
|
493
|
+
"glob": "7.1.3",
|
|
494
|
+
"growl": "1.10.5",
|
|
495
|
+
"he": "1.2.0",
|
|
496
|
+
"js-yaml": "3.12.0",
|
|
497
|
+
"log-symbols": "2.2.0",
|
|
465
498
|
"minimatch": "3.0.4",
|
|
466
499
|
"mkdirp": "0.5.1",
|
|
467
|
-
"
|
|
500
|
+
"ms": "2.1.1",
|
|
501
|
+
"node-environment-flags": "1.0.2",
|
|
502
|
+
"object.assign": "4.1.0",
|
|
503
|
+
"strip-json-comments": "2.0.1",
|
|
504
|
+
"supports-color": "6.0.0",
|
|
505
|
+
"which": "1.3.1",
|
|
506
|
+
"wide-align": "1.1.3",
|
|
507
|
+
"yargs": "12.0.5",
|
|
508
|
+
"yargs-parser": "11.1.1",
|
|
509
|
+
"yargs-unparser": "1.5.0"
|
|
468
510
|
},
|
|
469
511
|
"devDependencies": {
|
|
470
|
-
"
|
|
471
|
-
"
|
|
472
|
-
"
|
|
512
|
+
"@mocha/contributors": "^1.0.3",
|
|
513
|
+
"@mocha/docdash": "^1.0.1",
|
|
514
|
+
"assetgraph-builder": "^6.4.2",
|
|
515
|
+
"browserify": "^16.2.3",
|
|
516
|
+
"browserify-package-json": "^1.0.1",
|
|
517
|
+
"chai": "^4.2.0",
|
|
473
518
|
"coffee-script": "^1.10.0",
|
|
474
|
-
"coveralls": "^3.0.
|
|
475
|
-
"cross-spawn": "^
|
|
476
|
-
"
|
|
477
|
-
"eslint": "^
|
|
478
|
-
"eslint-config-semistandard": "^
|
|
479
|
-
"eslint-config-standard": "^
|
|
480
|
-
"eslint-plugin-import": "^2.
|
|
481
|
-
"eslint-plugin-node": "^
|
|
482
|
-
"eslint-plugin-
|
|
483
|
-
"eslint-plugin-
|
|
484
|
-
"
|
|
485
|
-
"
|
|
486
|
-
"
|
|
519
|
+
"coveralls": "^3.0.2",
|
|
520
|
+
"cross-spawn": "^6.0.5",
|
|
521
|
+
"eslint": "^5.10.0",
|
|
522
|
+
"eslint-config-prettier": "^3.3.0",
|
|
523
|
+
"eslint-config-semistandard": "^13.0.0",
|
|
524
|
+
"eslint-config-standard": "^12.0.0",
|
|
525
|
+
"eslint-plugin-import": "^2.14.0",
|
|
526
|
+
"eslint-plugin-node": "^8.0.0",
|
|
527
|
+
"eslint-plugin-prettier": "^3.0.0",
|
|
528
|
+
"eslint-plugin-promise": "^4.0.1",
|
|
529
|
+
"eslint-plugin-standard": "^4.0.0",
|
|
530
|
+
"husky": "^1.2.1",
|
|
531
|
+
"jsdoc": "^3.5.5",
|
|
532
|
+
"karma": "^3.1.1",
|
|
533
|
+
"karma-browserify": "^5.3.0",
|
|
487
534
|
"karma-chrome-launcher": "^2.0.0",
|
|
488
|
-
"karma-expect": "^1.1.2",
|
|
489
535
|
"karma-mocha": "^1.3.0",
|
|
490
536
|
"karma-mocha-reporter": "^2.2.4",
|
|
491
537
|
"karma-sauce-launcher": "^1.2.0",
|
|
538
|
+
"lint-staged": "^8.1.0",
|
|
539
|
+
"markdown-magic": "^0.1.25",
|
|
540
|
+
"markdown-magic-package-json": "^2.0.0",
|
|
492
541
|
"markdown-toc": "^1.2.0",
|
|
493
|
-
"markdownlint-cli": "^0.
|
|
494
|
-
"nps": "^5.
|
|
495
|
-
"nyc": "^
|
|
542
|
+
"markdownlint-cli": "^0.13.0",
|
|
543
|
+
"nps": "^5.9.3",
|
|
544
|
+
"nyc": "^13.1.0",
|
|
545
|
+
"prettier": "^1.15.3",
|
|
546
|
+
"remark": "^10.0.1",
|
|
547
|
+
"remark-github": "^7.0.5",
|
|
548
|
+
"remark-inline-links": "^3.1.2",
|
|
549
|
+
"rewiremock": "^3.12.3",
|
|
496
550
|
"rimraf": "^2.5.2",
|
|
497
|
-
"
|
|
498
|
-
"
|
|
551
|
+
"sinon": "^7.1.1",
|
|
552
|
+
"strip-ansi": "^5.0.0",
|
|
553
|
+
"svgo": "^1.1.1",
|
|
554
|
+
"through2": "^3.0.0",
|
|
555
|
+
"to-vfile": "^5.0.2",
|
|
556
|
+
"unexpected": "^10.39.2",
|
|
557
|
+
"unexpected-sinon": "^10.10.1",
|
|
499
558
|
"watchify": "^3.7.0"
|
|
500
559
|
},
|
|
501
560
|
"files": [
|
|
502
|
-
"bin",
|
|
503
|
-
"
|
|
504
|
-
"lib",
|
|
561
|
+
"bin/{*mocha,options.js}",
|
|
562
|
+
"assets/growl/*.png",
|
|
563
|
+
"lib/**/*.{js,html,json}",
|
|
505
564
|
"index.js",
|
|
506
565
|
"mocha.css",
|
|
507
566
|
"mocha.js",
|
|
508
567
|
"browser-entry.js"
|
|
509
568
|
],
|
|
569
|
+
"browserify": {
|
|
570
|
+
"transform": [
|
|
571
|
+
"./scripts/package-json-cullify"
|
|
572
|
+
]
|
|
573
|
+
},
|
|
510
574
|
"browser": {
|
|
511
|
-
"growl": "./lib/browser/growl.js",
|
|
512
|
-
"tty": "./lib/browser/tty.js",
|
|
513
575
|
"./index.js": "./browser-entry.js",
|
|
576
|
+
"./lib/growl.js": "./lib/browser/growl.js",
|
|
577
|
+
"tty": "./lib/browser/tty.js",
|
|
514
578
|
"fs": false,
|
|
515
579
|
"glob": false,
|
|
516
580
|
"path": false,
|
|
517
581
|
"supports-color": false
|
|
518
582
|
},
|
|
519
|
-
"
|
|
520
|
-
|
|
583
|
+
"prettier": {
|
|
584
|
+
"singleQuote": true,
|
|
585
|
+
"bracketSpacing": false
|
|
586
|
+
},
|
|
587
|
+
"yargs": {
|
|
588
|
+
"combine-arrays": true,
|
|
589
|
+
"short-option-groups": false,
|
|
590
|
+
"dot-notation": false
|
|
591
|
+
},
|
|
592
|
+
"gitter": "https://gitter.im/mochajs/mocha",
|
|
593
|
+
"@mocha/contributors": {
|
|
594
|
+
"exclude": [
|
|
595
|
+
"greenkeeperio-bot <support@greenkeeper.io>",
|
|
596
|
+
"greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>",
|
|
597
|
+
"TJ Holowaychuk <tj@vision-media.ca>"
|
|
598
|
+
]
|
|
599
|
+
},
|
|
600
|
+
"husky": {
|
|
601
|
+
"hooks": {
|
|
602
|
+
"pre-commit": "lint-staged"
|
|
603
|
+
}
|
|
604
|
+
}
|
|
521
605
|
}
|
package/bin/.eslintrc.yml
DELETED
package/lib/ms.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* @module milliseconds
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Helpers.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
var s = 1000;
|
|
10
|
-
var m = s * 60;
|
|
11
|
-
var h = m * 60;
|
|
12
|
-
var d = h * 24;
|
|
13
|
-
var y = d * 365.25;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Parse or format the given `val`.
|
|
17
|
-
*
|
|
18
|
-
* @memberof Mocha
|
|
19
|
-
* @public
|
|
20
|
-
* @api public
|
|
21
|
-
* @param {string|number} val
|
|
22
|
-
* @return {string|number}
|
|
23
|
-
*/
|
|
24
|
-
module.exports = function (val) {
|
|
25
|
-
if (typeof val === 'string') {
|
|
26
|
-
return parse(val);
|
|
27
|
-
}
|
|
28
|
-
return format(val);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Parse the given `str` and return milliseconds.
|
|
33
|
-
*
|
|
34
|
-
* @api private
|
|
35
|
-
* @param {string} str
|
|
36
|
-
* @return {number}
|
|
37
|
-
*/
|
|
38
|
-
function parse (str) {
|
|
39
|
-
var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
|
|
40
|
-
if (!match) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
var n = parseFloat(match[1]);
|
|
44
|
-
var type = (match[2] || 'ms').toLowerCase();
|
|
45
|
-
switch (type) {
|
|
46
|
-
case 'years':
|
|
47
|
-
case 'year':
|
|
48
|
-
case 'y':
|
|
49
|
-
return n * y;
|
|
50
|
-
case 'days':
|
|
51
|
-
case 'day':
|
|
52
|
-
case 'd':
|
|
53
|
-
return n * d;
|
|
54
|
-
case 'hours':
|
|
55
|
-
case 'hour':
|
|
56
|
-
case 'h':
|
|
57
|
-
return n * h;
|
|
58
|
-
case 'minutes':
|
|
59
|
-
case 'minute':
|
|
60
|
-
case 'm':
|
|
61
|
-
return n * m;
|
|
62
|
-
case 'seconds':
|
|
63
|
-
case 'second':
|
|
64
|
-
case 's':
|
|
65
|
-
return n * s;
|
|
66
|
-
case 'ms':
|
|
67
|
-
return n;
|
|
68
|
-
default:
|
|
69
|
-
// No default case
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Format for `ms`.
|
|
75
|
-
*
|
|
76
|
-
* @api private
|
|
77
|
-
* @param {number} ms
|
|
78
|
-
* @return {string}
|
|
79
|
-
*/
|
|
80
|
-
function format (ms) {
|
|
81
|
-
if (ms >= d) {
|
|
82
|
-
return Math.round(ms / d) + 'd';
|
|
83
|
-
}
|
|
84
|
-
if (ms >= h) {
|
|
85
|
-
return Math.round(ms / h) + 'h';
|
|
86
|
-
}
|
|
87
|
-
if (ms >= m) {
|
|
88
|
-
return Math.round(ms / m) + 'm';
|
|
89
|
-
}
|
|
90
|
-
if (ms >= s) {
|
|
91
|
-
return Math.round(ms / s) + 's';
|
|
92
|
-
}
|
|
93
|
-
return ms + 'ms';
|
|
94
|
-
}
|