@node-cli/timer 1.0.6 → 1.0.7
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/dist/utilities.js +2 -2
- package/dist/utilities.js.map +1 -1
- package/package.json +9 -5
package/dist/utilities.js
CHANGED
|
@@ -55,10 +55,10 @@ export const extractDuration = (config)=>{
|
|
|
55
55
|
});
|
|
56
56
|
this.startTime = Date.now();
|
|
57
57
|
spinner.start(this.introMessage);
|
|
58
|
-
// update the spinner every second
|
|
58
|
+
// update the spinner every second.
|
|
59
59
|
this.printRemainingTime();
|
|
60
60
|
const timer = setInterval(this.printRemainingTime, 1000);
|
|
61
|
-
// kill the spinner when the timer is done
|
|
61
|
+
// kill the spinner when the timer is done.
|
|
62
62
|
setTimeout(()=>{
|
|
63
63
|
const message = "Time's up!";
|
|
64
64
|
if (this.config.flags.notification) {
|
package/dist/utilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { Logger, Spinner } from \"@node-cli/logger\";\nimport moment, { Duration } from \"moment\";\n\nimport notifier from \"node-notifier\";\nimport { Configuration } from \"./parse.js\";\n\nconst logger = new Logger();\nconst spinner = new Spinner();\n\nconst UNITS = {\n\tms: 1000,\n\ts: 1000 * 1000,\n\tm: 1000 * 1000 * 60,\n\th: 1000 * 1000 * 60 * 60,\n\td: 1000 * 1000 * 60 * 60 * 24,\n\tw: 1000 * 1000 * 60 * 60 * 24 * 7,\n};\n\nexport const timeToMicroseconds = (value: string, unit: string) => {\n\tconst result = UNITS[unit];\n\treturn result ? Number.parseInt(value, 10) * result : 0;\n};\n\nexport const extractDuration = (config: Configuration): Duration => {\n\tconst { parameters, showHelp } = config;\n\tlet totalMicroseconds = 0;\n\n\t/* v8 ignore next 6 */\n\tif (\n\t\tObject.entries(parameters).length === 0 ||\n\t\tObject.entries(parameters).length > 1\n\t) {\n\t\tshowHelp();\n\t}\n\n\tconst groups = parameters[\"0\"].toLowerCase().match(/[+-]?[\\d.]+[a-z]+/g);\n\n\t/* v8 ignore next 2 */\n\tif (groups === null) {\n\t\tshowHelp();\n\t} else {\n\t\tfor (const g of groups) {\n\t\t\tconst value = g.match(/[\\d.]+/g)[0];\n\t\t\tconst unit = g.match(/[a-z]+/g)[0];\n\t\t\ttotalMicroseconds += timeToMicroseconds(value, unit);\n\t\t}\n\t\treturn moment.duration(totalMicroseconds / UNITS.ms);\n\t}\n};\n\n/* v8 ignore next 60 */\nexport class Timer {\n\tconfig: Configuration;\n\tstartTime: number;\n\ttimerDurationMilliSeconds: number;\n\tintroMessage: string;\n\ttimerDurationSeconds: number;\n\n\tconstructor(config: Configuration) {\n\t\tthis.config = config;\n\t\tconst result: Duration = extractDuration(this.config);\n\t\tthis.timerDurationMilliSeconds = result.asMilliseconds();\n\t\tthis.timerDurationSeconds = result.asSeconds();\n\t\tthis.introMessage = `${result.hours()}h ${result.minutes()}m ${result.seconds()}s`;\n\t}\n\n\tstart = () => {\n\t\tif (this.timerDurationMilliSeconds > 0) {\n\t\t\tlogger.printBox(`${this.introMessage} `, {\n\t\t\t\tpadding: 0,\n\t\t\t\tborderColor: \"cyan\",\n\t\t\t\ttitle: \"Timer Configuration\",\n\t\t\t});\n\n\t\t\tthis.startTime = Date.now();\n\t\t\tspinner.start(this.introMessage);\n\n\t\t\t// update the spinner every second
|
|
1
|
+
{"version":3,"sources":["../src/utilities.ts"],"sourcesContent":["import { Logger, Spinner } from \"@node-cli/logger\";\nimport moment, { Duration } from \"moment\";\n\nimport notifier from \"node-notifier\";\nimport { Configuration } from \"./parse.js\";\n\nconst logger = new Logger();\nconst spinner = new Spinner();\n\nconst UNITS = {\n\tms: 1000,\n\ts: 1000 * 1000,\n\tm: 1000 * 1000 * 60,\n\th: 1000 * 1000 * 60 * 60,\n\td: 1000 * 1000 * 60 * 60 * 24,\n\tw: 1000 * 1000 * 60 * 60 * 24 * 7,\n};\n\nexport const timeToMicroseconds = (value: string, unit: string) => {\n\tconst result = UNITS[unit];\n\treturn result ? Number.parseInt(value, 10) * result : 0;\n};\n\nexport const extractDuration = (config: Configuration): Duration => {\n\tconst { parameters, showHelp } = config;\n\tlet totalMicroseconds = 0;\n\n\t/* v8 ignore next 6 */\n\tif (\n\t\tObject.entries(parameters).length === 0 ||\n\t\tObject.entries(parameters).length > 1\n\t) {\n\t\tshowHelp();\n\t}\n\n\tconst groups = parameters[\"0\"].toLowerCase().match(/[+-]?[\\d.]+[a-z]+/g);\n\n\t/* v8 ignore next 2 */\n\tif (groups === null) {\n\t\tshowHelp();\n\t} else {\n\t\tfor (const g of groups) {\n\t\t\tconst value = g.match(/[\\d.]+/g)[0];\n\t\t\tconst unit = g.match(/[a-z]+/g)[0];\n\t\t\ttotalMicroseconds += timeToMicroseconds(value, unit);\n\t\t}\n\t\treturn moment.duration(totalMicroseconds / UNITS.ms);\n\t}\n};\n\n/* v8 ignore next 60 */\nexport class Timer {\n\tconfig: Configuration;\n\tstartTime: number;\n\ttimerDurationMilliSeconds: number;\n\tintroMessage: string;\n\ttimerDurationSeconds: number;\n\n\tconstructor(config: Configuration) {\n\t\tthis.config = config;\n\t\tconst result: Duration = extractDuration(this.config);\n\t\tthis.timerDurationMilliSeconds = result.asMilliseconds();\n\t\tthis.timerDurationSeconds = result.asSeconds();\n\t\tthis.introMessage = `${result.hours()}h ${result.minutes()}m ${result.seconds()}s`;\n\t}\n\n\tstart = () => {\n\t\tif (this.timerDurationMilliSeconds > 0) {\n\t\t\tlogger.printBox(`${this.introMessage} `, {\n\t\t\t\tpadding: 0,\n\t\t\t\tborderColor: \"cyan\",\n\t\t\t\ttitle: \"Timer Configuration\",\n\t\t\t});\n\n\t\t\tthis.startTime = Date.now();\n\t\t\tspinner.start(this.introMessage);\n\n\t\t\t// update the spinner every second.\n\t\t\tthis.printRemainingTime();\n\t\t\tconst timer = setInterval(this.printRemainingTime, 1000);\n\n\t\t\t// kill the spinner when the timer is done.\n\t\t\tsetTimeout(() => {\n\t\t\t\tconst message = \"Time's up!\";\n\t\t\t\tif (this.config.flags.notification) {\n\t\t\t\t\tnotifier.notify({\n\t\t\t\t\t\tmessage,\n\t\t\t\t\t\tsound: \"Funk\",\n\t\t\t\t\t\ttitle: \"Timer Notification\",\n\t\t\t\t\t\twait: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tclearInterval(timer);\n\t\t\t\tthis.printRemainingTime(message);\n\t\t\t\tspinner.stop();\n\t\t\t}, this.timerDurationMilliSeconds);\n\t\t}\n\t};\n\n\tprivate printRemainingTime = (message: string | void) => {\n\t\tif (message) {\n\t\t\tspinner.text = message;\n\t\t} else {\n\t\t\tconst elapsed = (Date.now() - this.startTime) / 1000;\n\t\t\tconst duration = moment.duration(\n\t\t\t\t(this.timerDurationSeconds - elapsed) * 1000,\n\t\t\t);\n\t\t\tspinner.text = `${duration.hours()}h ${duration.minutes()}m ${duration.seconds()}s`;\n\t\t}\n\t};\n}\n"],"names":["Logger","Spinner","moment","notifier","logger","spinner","UNITS","ms","s","m","h","d","w","timeToMicroseconds","value","unit","result","Number","parseInt","extractDuration","config","parameters","showHelp","totalMicroseconds","Object","entries","length","groups","toLowerCase","match","g","duration","Timer","startTime","timerDurationMilliSeconds","introMessage","timerDurationSeconds","asMilliseconds","asSeconds","hours","minutes","seconds","start","printBox","padding","borderColor","title","Date","now","printRemainingTime","timer","setInterval","setTimeout","message","flags","notification","notify","sound","wait","clearInterval","stop","text","elapsed"],"mappings":"AAAA,SAASA,MAAM,EAAEC,OAAO,QAAQ,mBAAmB;AACnD,OAAOC,YAA0B,SAAS;AAE1C,OAAOC,cAAc,gBAAgB;AAGrC,MAAMC,SAAS,IAAIJ;AACnB,MAAMK,UAAU,IAAIJ;AAEpB,MAAMK,QAAQ;IACbC,IAAI;IACJC,GAAG,OAAO;IACVC,GAAG,OAAO,OAAO;IACjBC,GAAG,OAAO,OAAO,KAAK;IACtBC,GAAG,OAAO,OAAO,KAAK,KAAK;IAC3BC,GA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-cli/timer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Dead simpler CLI timer",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"exports": "./dist/timer.js",
|
|
10
10
|
"bin": "dist/timer.js",
|
|
11
11
|
"files": [
|
|
12
|
-
"dist"
|
|
12
|
+
"dist",
|
|
13
|
+
"README.md"
|
|
13
14
|
],
|
|
14
15
|
"node": ">=16",
|
|
15
16
|
"scripts": {
|
|
@@ -18,15 +19,17 @@
|
|
|
18
19
|
"build:js": "swc --strip-leading-paths --source-maps --out-dir dist src",
|
|
19
20
|
"build:types": "tsc",
|
|
20
21
|
"clean": "rimraf dist types coverage",
|
|
22
|
+
"comments:fix": "comments --merge-line-comments 'src/**/*.ts'",
|
|
21
23
|
"lint": "biome lint src",
|
|
24
|
+
"lint:fix": "biome check src --write --no-errors-on-unmatched",
|
|
22
25
|
"test": "vitest run --globals",
|
|
23
26
|
"test:coverage": "vitest run --coverage --globals",
|
|
24
27
|
"test:watch": "vitest --globals",
|
|
25
28
|
"watch": "swc --strip-leading-paths --watch --out-dir dist src"
|
|
26
29
|
},
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@node-cli/logger": "
|
|
29
|
-
"@node-cli/parser": "
|
|
31
|
+
"@node-cli/logger": "../logger",
|
|
32
|
+
"@node-cli/parser": "../parser",
|
|
30
33
|
"moment": "2.30.1",
|
|
31
34
|
"node-notifier": "10.0.1"
|
|
32
35
|
},
|
|
@@ -34,8 +37,9 @@
|
|
|
34
37
|
"access": "public"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
40
|
+
"@node-cli/comments": "0.2.0",
|
|
37
41
|
"@vitest/coverage-v8": "3.2.4",
|
|
38
42
|
"vitest": "3.2.4"
|
|
39
43
|
},
|
|
40
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "d90392dcb766dd605bc3eeabc7c7a7ab0c8e6da6"
|
|
41
45
|
}
|