@vnejs/plugins.time.date 0.1.6
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/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/date.d.ts +15 -0
- package/dist/modules/date.js +35 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/dist/utils/date.d.ts +13 -0
- package/dist/utils/date.js +1 -0
- package/package.json +46 -0
- package/src/index.ts +6 -0
- package/src/modules/date.ts +53 -0
- package/src/types.ts +17 -0
- package/src/utils/date.ts +15 -0
- package/tsconfig.json +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.time.date.contract";
|
|
3
|
+
import { DateModule } from "./modules/date.js";
|
|
4
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [DateModule]);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import type { DatePluginConstants, DatePluginEvents, DatePluginParams, DatePluginSettings } from "../types.js";
|
|
3
|
+
import type { DateState, DateValuePayload, ScenarioLineExecPayload } from "../utils/date.js";
|
|
4
|
+
export declare class DateModule extends Module<DatePluginEvents, DatePluginConstants, DatePluginSettings, DatePluginParams, DateState> {
|
|
5
|
+
name: string;
|
|
6
|
+
subscribe: () => void;
|
|
7
|
+
init: () => Promise<unknown[]> | undefined;
|
|
8
|
+
onLineExec: ({ line }?: ScenarioLineExecPayload) => Promise<void>;
|
|
9
|
+
onDateSet: ({ days, months, years }?: DateValuePayload) => void;
|
|
10
|
+
onDateAdd: ({ days, months, years }?: DateValuePayload) => void;
|
|
11
|
+
onStateSet: ({ [this.name]: state }?: Record<string, DateState | undefined>) => Promise<void>;
|
|
12
|
+
changeDate: (days?: number, months?: number, years?: number) => void;
|
|
13
|
+
getDefaultState: () => DateState;
|
|
14
|
+
emitDateEvent: (action: string, arg: DateValuePayload) => Promise<unknown[]> | undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
export class DateModule extends Module {
|
|
4
|
+
name = "date";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.DATE.SET, this.onDateSet);
|
|
7
|
+
this.on(this.EVENTS.DATE.ADD, this.onDateAdd);
|
|
8
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
9
|
+
this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
|
|
10
|
+
};
|
|
11
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
12
|
+
onLineExec = async ({ line = "" } = {}) => {
|
|
13
|
+
const [action = "", days = 0, months = 0, years = 0] = tokenizeExecLine(line);
|
|
14
|
+
await this.emitDateEvent(String(action), { days: Number(days), months: Number(months), years: Number(years) });
|
|
15
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
16
|
+
};
|
|
17
|
+
onDateSet = ({ days = 0, months = 0, years = 0 } = {}) => this.changeDate(days + 1, months, years);
|
|
18
|
+
onDateAdd = ({ days = 0, months = 0, years = 0 } = {}) => this.changeDate(this.state.days + days, this.state.months + months, this.state.years + years);
|
|
19
|
+
onStateSet = async ({ [this.name]: state } = {}) => this.setState((await this.emitOne(this.EVENTS.VENDORS.CLONE, state)));
|
|
20
|
+
changeDate = (days = 0, months = 0, years = 0) => {
|
|
21
|
+
const w = new Date();
|
|
22
|
+
w.setDate(days);
|
|
23
|
+
w.setMonth(months);
|
|
24
|
+
w.setFullYear(years);
|
|
25
|
+
this.setState({ days: w.getDate(), months: w.getMonth(), years: w.getFullYear() });
|
|
26
|
+
this.emit(this.EVENTS.DATE.CHANGED);
|
|
27
|
+
};
|
|
28
|
+
getDefaultState = () => ({ days: 0, months: 0, years: 0 });
|
|
29
|
+
emitDateEvent = (action, arg) => {
|
|
30
|
+
if (action === this.CONST.DATE.ACTIONS.ADD)
|
|
31
|
+
return this.emit(this.EVENTS.DATE.ADD, arg);
|
|
32
|
+
if (action === this.CONST.DATE.ACTIONS.SET)
|
|
33
|
+
return this.emit(this.EVENTS.DATE.SET, arg);
|
|
34
|
+
};
|
|
35
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
3
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
4
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
|
|
5
|
+
import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.time.date.contract";
|
|
6
|
+
export type DatePluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<VendorsPluginName, VendorsSubscribeEvents>;
|
|
7
|
+
export type DatePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
|
8
|
+
export type DatePluginSettings = VnePluginSettingsMapRegistry;
|
|
9
|
+
export type DatePluginParams = VnePluginParamsMapRegistry;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.time.date",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.time.date.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.1.0",
|
|
37
|
+
"@vnejs/module": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.scenario.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/plugins.core.state.contract": "~0.0.1",
|
|
40
|
+
"@vnejs/plugins.core.vendors.contract": "~0.0.1",
|
|
41
|
+
"@vnejs/shared": "~0.0.9"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@vnejs/configs.ts-common": "~0.0.1"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.time.date.contract";
|
|
3
|
+
|
|
4
|
+
import { DateModule } from "./modules/date.js";
|
|
5
|
+
|
|
6
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [DateModule]);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Module } from "@vnejs/module";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
|
|
4
|
+
import type { DatePluginConstants, DatePluginEvents, DatePluginParams, DatePluginSettings } from "../types.js";
|
|
5
|
+
import type { DateState, DateValuePayload, ScenarioLineExecPayload } from "../utils/date.js";
|
|
6
|
+
|
|
7
|
+
export class DateModule extends Module<DatePluginEvents, DatePluginConstants, DatePluginSettings, DatePluginParams, DateState> {
|
|
8
|
+
name = "date";
|
|
9
|
+
|
|
10
|
+
subscribe = () => {
|
|
11
|
+
this.on(this.EVENTS.DATE.SET, this.onDateSet);
|
|
12
|
+
this.on(this.EVENTS.DATE.ADD, this.onDateAdd);
|
|
13
|
+
|
|
14
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
15
|
+
this.on(this.EVENTS.STATE.CLEAR, this.setDefaultState);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
19
|
+
|
|
20
|
+
onLineExec = async ({ line = "" }: ScenarioLineExecPayload = {}) => {
|
|
21
|
+
const [action = "", days = 0, months = 0, years = 0] = tokenizeExecLine(line);
|
|
22
|
+
|
|
23
|
+
await this.emitDateEvent(String(action), { days: Number(days), months: Number(months), years: Number(years) });
|
|
24
|
+
|
|
25
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
onDateSet = ({ days = 0, months = 0, years = 0 }: DateValuePayload = {}) => this.changeDate(days + 1, months, years);
|
|
29
|
+
|
|
30
|
+
onDateAdd = ({ days = 0, months = 0, years = 0 }: DateValuePayload = {}) =>
|
|
31
|
+
this.changeDate(this.state.days + days, this.state.months + months, this.state.years + years);
|
|
32
|
+
|
|
33
|
+
onStateSet = async ({ [this.name]: state }: Record<string, DateState | undefined> = {}) =>
|
|
34
|
+
this.setState((await this.emitOne(this.EVENTS.VENDORS.CLONE, state)) as DateState);
|
|
35
|
+
|
|
36
|
+
changeDate = (days = 0, months = 0, years = 0) => {
|
|
37
|
+
const w = new Date();
|
|
38
|
+
w.setDate(days);
|
|
39
|
+
w.setMonth(months);
|
|
40
|
+
w.setFullYear(years);
|
|
41
|
+
|
|
42
|
+
this.setState({ days: w.getDate(), months: w.getMonth(), years: w.getFullYear() });
|
|
43
|
+
|
|
44
|
+
this.emit(this.EVENTS.DATE.CHANGED);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
getDefaultState = (): DateState => ({ days: 0, months: 0, years: 0 });
|
|
48
|
+
|
|
49
|
+
emitDateEvent = (action: string, arg: DateValuePayload) => {
|
|
50
|
+
if (action === this.CONST.DATE.ACTIONS.ADD) return this.emit(this.EVENTS.DATE.ADD, arg);
|
|
51
|
+
if (action === this.CONST.DATE.ACTIONS.SET) return this.emit(this.EVENTS.DATE.SET, arg);
|
|
52
|
+
};
|
|
53
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
3
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
|
|
4
|
+
import type { PluginName as VendorsPluginName, SubscribeEvents as VendorsSubscribeEvents } from "@vnejs/plugins.core.vendors.contract";
|
|
5
|
+
import type { Constants, PluginName, SubscribeEvents } from "@vnejs/plugins.time.date.contract";
|
|
6
|
+
|
|
7
|
+
export type DatePluginEvents = VnePluginEventsMapRegistry &
|
|
8
|
+
Record<PluginName, SubscribeEvents> &
|
|
9
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
10
|
+
Record<StatePluginName, StateSubscribeEvents> &
|
|
11
|
+
Record<VendorsPluginName, VendorsSubscribeEvents>;
|
|
12
|
+
|
|
13
|
+
export type DatePluginConstants = VnePluginConstantsMapRegistry & Record<PluginName, Constants>;
|
|
14
|
+
|
|
15
|
+
export type DatePluginSettings = VnePluginSettingsMapRegistry;
|
|
16
|
+
|
|
17
|
+
export type DatePluginParams = VnePluginParamsMapRegistry;
|