@node-cli/timer 1.0.5 → 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/defaults.js CHANGED
@@ -1,6 +1,6 @@
1
- /* istanbul ignore file */ export const defaultFlags = {
1
+ /* v8 ignore start */ export const defaultFlags = {
2
2
  boring: false,
3
3
  notification: true
4
- };
4
+ }; /* v8 ignore stop */
5
5
 
6
6
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* istanbul ignore file */\nexport const defaultFlags = {\n\tboring: false,\n\tnotification: true,\n};\n"],"names":["defaultFlags","boring","notification"],"rangeMappings":";;;","mappings":"AAAA,wBAAwB,GACxB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,cAAc;AACf,EAAE"}
1
+ {"version":3,"sources":["../src/defaults.ts"],"sourcesContent":["/* v8 ignore start */\nexport const defaultFlags = {\n\tboring: false,\n\tnotification: true,\n};\n/* v8 ignore stop */\n"],"names":["defaultFlags","boring","notification"],"mappings":"AAAA,mBAAmB,GACnB,OAAO,MAAMA,eAAe;IAC3BC,QAAQ;IACRC,cAAc;AACf,EAAE,CACF,kBAAkB"}
package/dist/parse.js CHANGED
@@ -1,6 +1,6 @@
1
- import { parser } from "@node-cli/parser";
1
+ /* v8 ignore start */ import { parser } from "@node-cli/parser";
2
2
  import { defaultFlags } from "./defaults.js";
3
- /* istanbul ignore next */ export const config = parser({
3
+ /* v8 ignore next 45 */ export const config = parser({
4
4
  meta: import.meta,
5
5
  examples: [
6
6
  {
@@ -42,6 +42,6 @@ import { defaultFlags } from "./defaults.js";
42
42
  }
43
43
  },
44
44
  usage: "timer [formattedTime]"
45
- });
45
+ }); /* v8 ignore stop */
46
46
 
47
47
  //# sourceMappingURL=parse.js.map
package/dist/parse.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["import { parser } from \"@node-cli/parser\";\nimport { defaultFlags } from \"./defaults.js\";\n\nexport type Parameters = {\n\t[\"0\"]?: string;\n};\nexport type Configuration = {\n\tflags?: any;\n\tparameters?: Parameters;\n\tshowHelp?: () => void;\n};\n\n/* istanbul ignore next */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: \"timer 4h2m15s\",\n\t\t\tcomment: \"## Start a timer for 4 hours, 2 minutes and 15 seconds\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"timer 1m42s\",\n\t\t\tcomment: \"## Start a timer for 1 minute and 42 seconds\",\n\t\t},\n\t],\n\tflags: {\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tnotification: {\n\t\t\tshortFlag: \"n\",\n\t\t\tdefault: defaultFlags.notification,\n\t\t\tdescription: \"Display a notification when the timer is done\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tformattedTime: {\n\t\t\tdescription: \"Formatted time to start the timer\",\n\t\t},\n\t},\n\n\tusage: \"timer [formattedTime]\",\n});\n"],"names":["parser","defaultFlags","config","meta","examples","command","comment","flags","boring","shortFlag","default","description","type","help","notification","version","parameters","formattedTime","usage"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,YAAY,QAAQ,gBAAgB;AAW7C,wBAAwB,GACxB,OAAO,MAAMC,SAAwBF,OAAO;IAC3CG,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;KACA;IACDC,OAAO;QACNC,QAAQ;YACPC,WAAW;YACXC,SAAST,aAAaO,MAAM;YAC5BG,aAAa;YACbC,MAAM;QACP;QACAC,MAAM;YACLJ,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAE,cAAc;YACbL,WAAW;YACXC,SAAST,aAAaa,YAAY;YAClCH,aAAa;YACbC,MAAM;QACP;QACAG,SAAS;YACRN,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;IACD;IACAI,YAAY;QACXC,eAAe;YACdN,aAAa;QACd;IACD;IAEAO,OAAO;AACR,GAAG"}
1
+ {"version":3,"sources":["../src/parse.ts"],"sourcesContent":["/* v8 ignore start */\nimport { parser } from \"@node-cli/parser\";\nimport { defaultFlags } from \"./defaults.js\";\n\nexport type Parameters = {\n\t[\"0\"]?: string;\n};\nexport type Configuration = {\n\tflags?: any;\n\tparameters?: Parameters;\n\tshowHelp?: () => void;\n};\n\n/* v8 ignore next 45 */\nexport const config: Configuration = parser({\n\tmeta: import.meta,\n\texamples: [\n\t\t{\n\t\t\tcommand: \"timer 4h2m15s\",\n\t\t\tcomment: \"## Start a timer for 4 hours, 2 minutes and 15 seconds\",\n\t\t},\n\t\t{\n\t\t\tcommand: \"timer 1m42s\",\n\t\t\tcomment: \"## Start a timer for 1 minute and 42 seconds\",\n\t\t},\n\t],\n\tflags: {\n\t\tboring: {\n\t\t\tshortFlag: \"b\",\n\t\t\tdefault: defaultFlags.boring,\n\t\t\tdescription: \"Do not use color output\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\thelp: {\n\t\t\tshortFlag: \"h\",\n\t\t\tdescription: \"Display help instructions\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tnotification: {\n\t\t\tshortFlag: \"n\",\n\t\t\tdefault: defaultFlags.notification,\n\t\t\tdescription: \"Display a notification when the timer is done\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t\tversion: {\n\t\t\tshortFlag: \"v\",\n\t\t\tdescription: \"Output the current version\",\n\t\t\ttype: \"boolean\",\n\t\t},\n\t},\n\tparameters: {\n\t\tformattedTime: {\n\t\t\tdescription: \"Formatted time to start the timer\",\n\t\t},\n\t},\n\n\tusage: \"timer [formattedTime]\",\n});\n/* v8 ignore stop */\n"],"names":["parser","defaultFlags","config","meta","examples","command","comment","flags","boring","shortFlag","default","description","type","help","notification","version","parameters","formattedTime","usage"],"mappings":"AAAA,mBAAmB,GACnB,SAASA,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,YAAY,QAAQ,gBAAgB;AAW7C,qBAAqB,GACrB,OAAO,MAAMC,SAAwBF,OAAO;IAC3CG,MAAM;IACNC,UAAU;QACT;YACCC,SAAS;YACTC,SAAS;QACV;QACA;YACCD,SAAS;YACTC,SAAS;QACV;KACA;IACDC,OAAO;QACNC,QAAQ;YACPC,WAAW;YACXC,SAAST,aAAaO,MAAM;YAC5BG,aAAa;YACbC,MAAM;QACP;QACAC,MAAM;YACLJ,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;QACAE,cAAc;YACbL,WAAW;YACXC,SAAST,aAAaa,YAAY;YAClCH,aAAa;YACbC,MAAM;QACP;QACAG,SAAS;YACRN,WAAW;YACXE,aAAa;YACbC,MAAM;QACP;IACD;IACAI,YAAY;QACXC,eAAe;YACdN,aAAa;QACd;IACD;IAEAO,OAAO;AACR,GAAG,CACH,kBAAkB"}
package/dist/timer.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
- /* istanbul ignore file */ import { config } from "./parse.js";
2
+ /* v8 ignore start */ import { config } from "./parse.js";
3
3
  import { Timer } from "./utilities.js";
4
4
  const timer = new Timer(config);
5
- timer.start();
5
+ timer.start(); /* v8 ignore stop */
6
6
 
7
7
  //# sourceMappingURL=timer.js.map
package/dist/timer.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/timer.ts"],"sourcesContent":["#!/usr/bin/env node\n/* istanbul ignore file */\n\nimport { config } from \"./parse.js\";\nimport { Timer } from \"./utilities.js\";\n\nconst timer = new Timer(config);\ntimer.start();\n"],"names":["config","Timer","timer","start"],"rangeMappings":";;;;","mappings":";AACA,wBAAwB,GAExB,SAASA,MAAM,QAAQ,aAAa;AACpC,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,QAAQ,IAAID,MAAMD;AACxBE,MAAMC,KAAK"}
1
+ {"version":3,"sources":["../src/timer.ts"],"sourcesContent":["#!/usr/bin/env node\n/* v8 ignore start */\n\nimport { config } from \"./parse.js\";\nimport { Timer } from \"./utilities.js\";\n\nconst timer = new Timer(config);\ntimer.start();\n/* v8 ignore stop */\n"],"names":["config","Timer","timer","start"],"mappings":";AACA,mBAAmB,GAEnB,SAASA,MAAM,QAAQ,aAAa;AACpC,SAASC,KAAK,QAAQ,iBAAiB;AAEvC,MAAMC,QAAQ,IAAID,MAAMD;AACxBE,MAAMC,KAAK,IACX,kBAAkB"}
package/dist/utilities.js CHANGED
@@ -18,11 +18,11 @@ export const timeToMicroseconds = (value, unit)=>{
18
18
  export const extractDuration = (config)=>{
19
19
  const { parameters, showHelp } = config;
20
20
  let totalMicroseconds = 0;
21
- /* istanbul ignore if */ if (Object.entries(parameters).length === 0 || Object.entries(parameters).length > 1) {
21
+ /* v8 ignore next 6 */ if (Object.entries(parameters).length === 0 || Object.entries(parameters).length > 1) {
22
22
  showHelp();
23
23
  }
24
24
  const groups = parameters["0"].toLowerCase().match(/[+-]?[\d.]+[a-z]+/g);
25
- /* istanbul ignore if */ if (groups === null) {
25
+ /* v8 ignore next 2 */ if (groups === null) {
26
26
  showHelp();
27
27
  } else {
28
28
  for (const g of groups){
@@ -33,7 +33,7 @@ export const extractDuration = (config)=>{
33
33
  return moment.duration(totalMicroseconds / UNITS.ms);
34
34
  }
35
35
  };
36
- /* istanbul ignore next */ export class Timer {
36
+ /* v8 ignore next 60 */ export class Timer {
37
37
  config;
38
38
  startTime;
39
39
  timerDurationMilliSeconds;
@@ -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) {
@@ -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/* istanbul ignore if */\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/* istanbul ignore if */\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/* istanbul ignore next */\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","constructor","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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,GAAG,OAAO,OAAO,KAAK,KAAK,KAAK;AACjC;AAEA,OAAO,MAAMC,qBAAqB,CAACC,OAAeC;IACjD,MAAMC,SAASV,KAAK,CAACS,KAAK;IAC1B,OAAOC,SAASC,OAAOC,QAAQ,CAACJ,OAAO,MAAME,SAAS;AACvD,EAAE;AAEF,OAAO,MAAMG,kBAAkB,CAACC;IAC/B,MAAM,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAGF;IACjC,IAAIG,oBAAoB;IAExB,sBAAsB,GACtB,IACCC,OAAOC,OAAO,CAACJ,YAAYK,MAAM,KAAK,KACtCF,OAAOC,OAAO,CAACJ,YAAYK,MAAM,GAAG,GACnC;QACDJ;IACD;IAEA,MAA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,0CAA0C;YAC1CG,WAAW;gBACV,MAAMC,UAAU;gBAChB,IAAI,IAAI,CAAClC,MAAM,CAACmC,KAAK,CAACC,YAAY,EAAE;oBACnCrD,SAASsD,MAAM,CAAC;wBACfH;wBACAI,OAAO;wBACPX,OAAO;wBACPY,MAAM;oBACP;gBACD;gBACAC,cAAcT;gBACd,IAAI,CAACD,kBAAkB,CAACI;gBACxBjD,QAAQwD,IAAI;YACb,GAAG,IAAI,CAAC3B,yBAAyB;QAClC;IACD,EAAE;IAEMgB,qBAAqB,CAACI;QAC7B,IAAIA,SAAS;YACZjD,QAAQyD,IAAI,GAAGR;QAChB,OAAO;YACN,MAAMS,UAAU,AAACf,CAAAA,KAAKC,GAAG,KAAK,IAAI,CAAChB,SAAS,AAAD,IAAK;YAChD,MAAMF,WAAW7B,OAAO6B,QAAQ,CAC/B,AAAC,CAAA,IAAI,CAACK,oBAAoB,GAAG2B,OAAM,IAAK;YAEzC1D,QAAQyD,IAAI,GAAG,CAAC,EAAE/B,SAASS,KAAK,GAAG,EAAE,EAAET,SAASU,OAAO,GAAG,EAAE,EAAEV,SAASW,OAAO,GAAG,CAAC,CAAC;QACpF;IACD,EAAE;AACH"}
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,GAAG,OAAO,OAAO,KAAK,KAAK,KAAK;AACjC;AAEA,OAAO,MAAMC,qBAAqB,CAACC,OAAeC;IACjD,MAAMC,SAASV,KAAK,CAACS,KAAK;IAC1B,O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QAAQ,CAAC,GAAG,IAAI,CAACR,YAAY,CAAC,EAAE,CAAC,EAAE;gBACzCS,SAAS;gBACTC,aAAa;gBACbC,OAAO;YACR;YAEA,IAAI,CAACb,SAAS,GAAGc,KAAKC,GAAG;YACzB3C,QAAQqC,KAAK,CAAC,IAAI,CAACP,YAAY;YAE/B,mCAAmC;YACnC,IAAI,CAACc,kBAAkB;YACvB,MAAMC,QAAQC,YAAY,IAAI,CAACF,kBAAkB,EAAE;YAEnD,2CAA2C;YAC3CG,WAAW;gBACV,MAAMC,UAAU;gBAChB,IAAI,IAAI,CAACjC,MAAM,CAACkC,KAAK,CAACC,YAAY,EAAE;oBACnCpD,SAASqD,MAAM,CAAC;wBACfH;wBACAI,OAAO;wBACPX,OAAO;wBACPY,MAAM;oBACP;gBACD;gBACAC,cAAcT;gBACd,IAAI,CAACD,kBAAkB,CAACI;gBACxBhD,QAAQuD,IAAI;YACb,GAAG,IAAI,CAAC1B,yBAAyB;QAClC;IACD,EAAE;IAEMe,qBAAqB,CAACI;QAC7B,IAAIA,SAAS;YACZhD,QAAQwD,IAAI,GAAGR;QAChB,OAAO;YACN,MAAMS,UAAU,AAACf,CAAAA,KAAKC,GAAG,KAAK,IAAI,CAACf,SAAS,AAAD,IAAK;YAChD,MAAMF,WAAW7B,OAAO6B,QAAQ,CAC/B,AAAC,CAAA,IAAI,CAACK,oBAAoB,GAAG0B,OAAM,IAAK;YAEzCzD,QAAQwD,IAAI,GAAG,GAAG9B,SAASQ,KAAK,GAAG,EAAE,EAAER,SAASS,OAAO,GAAG,EAAE,EAAET,SAASU,OAAO,GAAG,CAAC,CAAC;QACpF;IACD,EAAE;AACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-cli/timer",
3
- "version": "1.0.5",
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,19 +19,27 @@
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",
22
- "test": "cross-env-shell NODE_OPTIONS=--experimental-vm-modules TZ=UTC jest",
23
- "test:coverage": "npm run test -- --coverage",
24
+ "lint:fix": "biome check src --write --no-errors-on-unmatched",
25
+ "test": "vitest run --globals",
26
+ "test:coverage": "vitest run --coverage --globals",
27
+ "test:watch": "vitest --globals",
24
28
  "watch": "swc --strip-leading-paths --watch --out-dir dist src"
25
29
  },
26
30
  "dependencies": {
27
- "@node-cli/logger": "1.2.5",
28
- "@node-cli/parser": "2.3.3",
31
+ "@node-cli/logger": "../logger",
32
+ "@node-cli/parser": "../parser",
29
33
  "moment": "2.30.1",
30
34
  "node-notifier": "10.0.1"
31
35
  },
32
36
  "publishConfig": {
33
37
  "access": "public"
34
38
  },
35
- "gitHead": "d7d79f8f71fb3225e5a214aba3a42a89470d8340"
39
+ "devDependencies": {
40
+ "@node-cli/comments": "0.2.0",
41
+ "@vitest/coverage-v8": "3.2.4",
42
+ "vitest": "3.2.4"
43
+ },
44
+ "gitHead": "d90392dcb766dd605bc3eeabc7c7a7ab0c8e6da6"
36
45
  }