@vnejs/plugins.feature.date 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/modules/date.js +8 -12
  2. package/package.json +1 -1
package/modules/date.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Module } from "@vnejs/module";
2
+ import { tokenizeExecLine } from "@vnejs/helpers";
2
3
 
3
4
  export class DateModule extends Module {
4
5
  name = "date";
@@ -14,19 +15,9 @@ export class DateModule extends Module {
14
15
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
15
16
 
16
17
  onLineExec = async ({ line = "" } = {}) => {
17
- const [action, ...values] = line.split(" ");
18
+ const [action = "", days = 0, months = 0, years = 0] = tokenizeExecLine(line);
18
19
 
19
- const days = Number(values[0] || 0) || 0;
20
- const months = Number(values[1] || 0) || 0;
21
- const years = Number(values[2] || 0) || 0;
22
-
23
- switch (action) {
24
- case this.CONST.DATE.ACTIONS.ADD:
25
- await this.emit(this.EVENTS.DATE.ADD, { days, months, years });
26
- break;
27
- case this.CONST.DATE.ACTIONS.SET:
28
- await this.emit(this.EVENTS.DATE.SET, { days, months, years });
29
- }
20
+ await this.emitDateEvent(action, { days, months, years });
30
21
 
31
22
  this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
32
23
  };
@@ -48,4 +39,9 @@ export class DateModule extends Module {
48
39
  };
49
40
 
50
41
  getDefaultState = () => ({ days: 0, months: 0, years: 0 });
42
+
43
+ emitDateEvent = (action, arg) => {
44
+ if (action === this.CONST.DATE.ACTIONS.ADD) return this.emit(this.EVENTS.DATE.ADD, arg);
45
+ if (action === this.CONST.DATE.ACTIONS.SET) return this.emit(this.EVENTS.DATE.SET, arg);
46
+ };
51
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.feature.date",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",