@gradin/vue-utils 0.0.8 → 1.0.0

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/README.md CHANGED
@@ -12,6 +12,7 @@ Table of Contents:
12
12
  - [Features](#features)
13
13
  - [Improved Vue Reactive](#improved-vue-reactive)
14
14
  - [Watch Route Query and Params Changes](#watch-route-query-and-params-changes)
15
+ - [Helpers for Years](#helpers-for-years)
15
16
  - [Development](#development)
16
17
 
17
18
  ## Installation
@@ -127,7 +128,7 @@ Usage:
127
128
 
128
129
  whenRouteChange(getData) // will call getData once at the beginning, and again when the route query or params changes.
129
130
 
130
- // or if you want just to track route query page
131
+ // or if you want to track just the route query.search
131
132
  const highlightMatchesSearch = () => {
132
133
  //
133
134
  }
@@ -139,6 +140,20 @@ Usage:
139
140
  )
140
141
  ```
141
142
 
143
+ ### Helpers for Years
144
+
145
+ Usage:
146
+ ```typescript
147
+ import {
148
+ currentYear, // the current year (e.g. 2026)
149
+ releaseYear, // e.g 2024
150
+ footerYear, // e.g 2024-2026
151
+ yearsSinceRelease, // e.g [2024, 2025, 2026]
152
+ } from '@gradin/vue-utils';
153
+ ```
154
+
155
+ To use `releaseYear`, `footerYear`, `yearsSinceRelease`, you need to set the `VITE_APP_RELEASE_YEAR` environment variable to the year your project was released. If not set, it will default to the current year.
156
+
142
157
  ## Development
143
158
 
144
159
  To Deploy:
@@ -0,0 +1,7 @@
1
+ var _a;
2
+ export const currentYear = new Date().getFullYear();
3
+ export const releaseYear = Number((_a = import.meta.env.VITE_APP_RELEASE_YEAR) !== null && _a !== void 0 ? _a : 0) || currentYear;
4
+ export const footerYear = releaseYear === currentYear ? `${currentYear}` : `${releaseYear}-${currentYear}`;
5
+ export const yearsSinceRelease = currentYear - releaseYear > 0
6
+ ? Array.from({ length: currentYear - releaseYear + 1 }, (_, i) => currentYear - i)
7
+ : [currentYear];
package/dist/index.js CHANGED
@@ -1,39 +1,5 @@
1
- import { reactive, watch } from "vue";
2
- import { useRoute } from 'vue-router';
3
- export const resetableReactive = (data) => {
4
- const initialValue = Object.assign({}, data);
5
- const form = reactive(data);
6
- Object.defineProperty(form, 'reset', {
7
- value: () => {
8
- Object.assign(form, initialValue);
9
- },
10
- enumerable: false, // <== this hides it from JSON.stringify and Object.keys
11
- });
12
- Object.defineProperty(form, 'set', {
13
- value: (newValue) => {
14
- for (const key in initialValue) {
15
- if (key in newValue) {
16
- form[key] = newValue[key];
17
- }
18
- }
19
- },
20
- enumerable: false, // <== this hides it from JSON.stringify and Object.keys
21
- });
22
- return form;
23
- };
1
+ import { resetableReactive } from "./resetable-reactive";
2
+ export { resetableReactive } from "./resetable-reactive";
24
3
  export const gReactive = resetableReactive; // alias
25
- /**
26
- * Watch the route full path, and trigger callback when query / params change
27
- * but don't trigger when route name change (move away to other page).
28
- * Optional watchSource to watch just specific part of the route (not fullPath).
29
- */
30
- export const whenRouteChange = (callback, watchSource) => {
31
- const route = useRoute();
32
- const routeName = route.name; // cache route name
33
- const watchRouteParamsAndQuery = () => JSON.stringify([route.query, route.params]);
34
- watch(watchSource !== null && watchSource !== void 0 ? watchSource : watchRouteParamsAndQuery, () => {
35
- if (route.name === routeName) {
36
- callback();
37
- }
38
- }, { immediate: true });
39
- };
4
+ export { currentYear, footerYear, releaseYear, yearsSinceRelease } from "./footer-year";
5
+ export { whenRouteChange } from "./when-route-change";
@@ -0,0 +1,22 @@
1
+ import { reactive } from "vue";
2
+ export const resetableReactive = (data) => {
3
+ const initialValue = Object.assign({}, data);
4
+ const form = reactive(data);
5
+ Object.defineProperty(form, 'reset', {
6
+ value: () => {
7
+ Object.assign(form, initialValue);
8
+ },
9
+ enumerable: false, // <== this hides it from JSON.stringify and Object.keys
10
+ });
11
+ Object.defineProperty(form, 'set', {
12
+ value: (newValue) => {
13
+ for (const key in initialValue) {
14
+ if (key in newValue) {
15
+ form[key] = newValue[key];
16
+ }
17
+ }
18
+ },
19
+ enumerable: false, // <== this hides it from JSON.stringify and Object.keys
20
+ });
21
+ return form;
22
+ };
@@ -0,0 +1,4 @@
1
+ export declare const currentYear: number;
2
+ export declare const releaseYear: number;
3
+ export declare const footerYear: string;
4
+ export declare const yearsSinceRelease: number[];
@@ -1,14 +1,7 @@
1
- export declare const resetableReactive: <T extends object>(data: T) => T & {
2
- reset: () => void;
3
- set: (newValue: Partial<T>) => void;
4
- };
1
+ export { resetableReactive } from "./resetable-reactive";
5
2
  export declare const gReactive: <T extends object>(data: T) => T & {
6
3
  reset: () => void;
7
4
  set: (newValue: Partial<T>) => void;
8
5
  };
9
- /**
10
- * Watch the route full path, and trigger callback when query / params change
11
- * but don't trigger when route name change (move away to other page).
12
- * Optional watchSource to watch just specific part of the route (not fullPath).
13
- */
14
- export declare const whenRouteChange: (callback: () => void, watchSource?: () => unknown) => void;
6
+ export { currentYear, footerYear, releaseYear, yearsSinceRelease } from "./footer-year";
7
+ export { whenRouteChange } from "./when-route-change";
@@ -0,0 +1,4 @@
1
+ export declare const resetableReactive: <T extends object>(data: T) => T & {
2
+ reset: () => void;
3
+ set: (newValue: Partial<T>) => void;
4
+ };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Watch the route full path, and trigger callback when query / params change
3
+ * but don't trigger when route name change (move away to other page).
4
+ * Optional watchSource to watch just specific part of the route (not fullPath).
5
+ */
6
+ export declare const whenRouteChange: (callback: () => void, watchSource?: () => unknown) => void;
@@ -0,0 +1,17 @@
1
+ import { watch } from "vue";
2
+ import { useRoute } from 'vue-router';
3
+ /**
4
+ * Watch the route full path, and trigger callback when query / params change
5
+ * but don't trigger when route name change (move away to other page).
6
+ * Optional watchSource to watch just specific part of the route (not fullPath).
7
+ */
8
+ export const whenRouteChange = (callback, watchSource) => {
9
+ const route = useRoute();
10
+ const routeName = route.name; // cache route name
11
+ const watchRouteParamsAndQuery = () => JSON.stringify([route.query, route.params]);
12
+ watch(watchSource !== null && watchSource !== void 0 ? watchSource : watchRouteParamsAndQuery, () => {
13
+ if (route.name === routeName) {
14
+ callback();
15
+ }
16
+ }, { immediate: true });
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradin/vue-utils",
3
- "version": "0.0.8",
3
+ "version": "1.0.0",
4
4
  "description": "Useful utilities for Vue projects.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -35,15 +35,16 @@
35
35
  },
36
36
  "homepage": "https://github.com/gradints/vue-utils#readme",
37
37
  "dependencies": {
38
- "vue": "^3.5.27"
38
+ "vue": "^3.5.30"
39
39
  },
40
40
  "devDependencies": {
41
- "eslint": "^9.39.2",
41
+ "@eslint/js": "^10.0.1",
42
+ "@stylistic/eslint-plugin": "^5.10.0",
42
43
  "eslint-plugin-simple-import-sort": "^12.1.1",
43
44
  "typescript": "^5.9.3",
44
- "typescript-eslint": "^8.54.0"
45
+ "typescript-eslint": "^8.57.2"
45
46
  },
46
47
  "peerDependencies": {
47
48
  "vue-router": "^4.6.3 || ^5.0.0"
48
49
  }
49
- }
50
+ }