@hzw-tech/utils 0.2.1 → 0.2.3

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.
@@ -53,6 +53,8 @@
53
53
  "nextTick": "writable",
54
54
  "onActivated": "writable",
55
55
  "onBeforeMount": "writable",
56
+ "onBeforeRouteLeave": "writable",
57
+ "onBeforeRouteUpdate": "writable",
56
58
  "onBeforeUnmount": "writable",
57
59
  "onBeforeUpdate": "writable",
58
60
  "onDeactivated": "writable",
@@ -89,7 +91,10 @@
89
91
  "useCssModule": "writable",
90
92
  "useCssVars": "writable",
91
93
  "useId": "writable",
94
+ "useLink": "writable",
92
95
  "useModel": "writable",
96
+ "useRoute": "writable",
97
+ "useRouter": "writable",
93
98
  "useSlots": "writable",
94
99
  "useTemplateRef": "writable",
95
100
  "utils": "writable",
package/dist/eslint.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { antfu } from '@antfu/eslint-config'
2
+ import { mergeObject } from './utils.js'
2
3
 
3
4
  function eslint(options) {
4
- return antfu({
5
+ const optionsDefault = {
5
6
  formatters: true,
6
7
  vue: {
7
8
  overrides: {
8
9
  'vue/component-definition-name-casing': ['error', 'kebab-case'],
9
10
  'vue/component-name-in-template-casing': ['error', 'kebab-case'],
11
+ 'vue/custom-event-name-casing': ['error', 'kebab-case'],
10
12
  },
11
13
  },
12
14
  rules: {
@@ -52,8 +54,8 @@ function eslint(options) {
52
54
  '**/auto-import?(s).d.ts',
53
55
  '**/components.d.ts',
54
56
  ],
55
- ...options,
56
- })
57
+ }
58
+ return antfu(mergeObject(optionsDefault, options))
57
59
  }
58
60
 
59
61
  export default eslint
@@ -40,6 +40,8 @@ declare global {
40
40
  const nextTick: typeof import('vue').nextTick
41
41
  const onActivated: typeof import('vue').onActivated
42
42
  const onBeforeMount: typeof import('vue').onBeforeMount
43
+ const onBeforeRouteLeave: typeof import('vue-router').onBeforeRouteLeave
44
+ const onBeforeRouteUpdate: typeof import('vue-router').onBeforeRouteUpdate
43
45
  const onBeforeUnmount: typeof import('vue').onBeforeUnmount
44
46
  const onBeforeUpdate: typeof import('vue').onBeforeUpdate
45
47
  const onDeactivated: typeof import('vue').onDeactivated
@@ -76,7 +78,10 @@ declare global {
76
78
  const useCssModule: typeof import('vue').useCssModule
77
79
  const useCssVars: typeof import('vue').useCssVars
78
80
  const useId: typeof import('vue').useId
81
+ const useLink: typeof import('vue-router').useLink
79
82
  const useModel: typeof import('vue').useModel
83
+ const useRoute: typeof import('vue-router').useRoute
84
+ const useRouter: typeof import('vue-router').useRouter
80
85
  const useSlots: typeof import('vue').useSlots
81
86
  const useTemplateRef: typeof import('vue').useTemplateRef
82
87
  const utils: typeof import('../ts/utils').utils
@@ -138,6 +143,8 @@ declare module 'vue' {
138
143
  readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
139
144
  readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
140
145
  readonly onBeforeMount: UnwrapRef<typeof import('vue')['onBeforeMount']>
146
+ readonly onBeforeRouteLeave: UnwrapRef<typeof import('vue-router')['onBeforeRouteLeave']>
147
+ readonly onBeforeRouteUpdate: UnwrapRef<typeof import('vue-router')['onBeforeRouteUpdate']>
141
148
  readonly onBeforeUnmount: UnwrapRef<typeof import('vue')['onBeforeUnmount']>
142
149
  readonly onBeforeUpdate: UnwrapRef<typeof import('vue')['onBeforeUpdate']>
143
150
  readonly onDeactivated: UnwrapRef<typeof import('vue')['onDeactivated']>
@@ -174,7 +181,10 @@ declare module 'vue' {
174
181
  readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
175
182
  readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
176
183
  readonly useId: UnwrapRef<typeof import('vue')['useId']>
184
+ readonly useLink: UnwrapRef<typeof import('vue-router')['useLink']>
177
185
  readonly useModel: UnwrapRef<typeof import('vue')['useModel']>
186
+ readonly useRoute: UnwrapRef<typeof import('vue-router')['useRoute']>
187
+ readonly useRouter: UnwrapRef<typeof import('vue-router')['useRouter']>
178
188
  readonly useSlots: UnwrapRef<typeof import('vue')['useSlots']>
179
189
  readonly useTemplateRef: UnwrapRef<typeof import('vue')['useTemplateRef']>
180
190
  readonly utils: UnwrapRef<typeof import('../ts/utils')['utils']>
package/dist/utils.js ADDED
@@ -0,0 +1,29 @@
1
+ function getType(data) {
2
+ const typeStr = Object.prototype.toString.call(data)
3
+ const end = typeStr.length - 1
4
+ return typeStr.substring(8, end)
5
+ }
6
+
7
+ export function mergeObject(oldObj, newObj) {
8
+ if (getType(oldObj) !== 'Object') {
9
+ console.error('utils.mergeObjectParams方法传递的默认参数不是Object类型')
10
+ return newObj
11
+ }
12
+ if (!newObj) {
13
+ return oldObj
14
+ }
15
+ for (const key in oldObj) {
16
+ if (Object.prototype.hasOwnProperty.call(oldObj, key)) {
17
+ const item = oldObj[key]
18
+ // 仅当新对象是Object类型才进行比对,其他类型的newObj不变
19
+ if (getType(newObj) === 'Object') {
20
+ if (newObj[key] === undefined) {
21
+ newObj[key] = item
22
+ } else if (getType(item) === 'Object') {
23
+ mergeObject(item, newObj[key])
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return newObj
29
+ }
package/dist/vite.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import process from 'node:process'
2
2
  import AutoImportVite from 'unplugin-auto-import/vite'
3
+ import { mergeObject } from './utils.js'
3
4
 
4
5
  function autoImport(options) {
5
6
  const { mode } = process.env
6
7
  const isPublish = mode === 'publish'
7
8
  const optDefault = {
8
- imports: ['pinia', 'vue'],
9
+ imports: ['pinia', 'vue', 'vue-router'],
9
10
  eslintrc: {
10
11
  enabled: true,
11
12
  globalsPropValue: 'writable',
@@ -28,13 +29,9 @@ function scss(options) {
28
29
  if (options && options.additionalData) {
29
30
  additionalData = options.additionalData
30
31
  }
31
- return {
32
- additionalData: `
33
- @use "@hzw-tech/utils/dist/styles/reference/index.scss" as *;
34
- ${additionalData}
35
- `,
36
- ...options,
37
- }
32
+ return mergeObject({
33
+ additionalData,
34
+ }, options)
38
35
  }
39
36
 
40
37
  export default {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hzw-tech/utils",
3
3
  "type": "module",
4
- "version": "0.2.1",
4
+ "version": "0.2.3",
5
5
  "description": "通用前端工具包,包含请求,正则校验,全局ts声明等",
6
6
  "author": "hzw-tech",
7
7
  "license": "MIT",