@ciwergrp/nuxid 1.0.5 → 1.1.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
@@ -1,37 +1,40 @@
1
1
  # Nuxid – Nuxt Essentials
2
2
 
3
- Nuxid bundles a handful of productivity helpers for Nuxt projects: icon defaults, lodash auto-imports, Element Plus validation helpers, and a flexible form composable. Enable the pieces you need and keep the rest off.
3
+ Nuxid bundles a set of productivity helpers for Nuxt projects: lodash auto-imports, Element Plus-friendly validation rules, a form composable, helper utilities, optional icon defaults, Element Plus setup, and Pinia integration. Enable the pieces you need and keep the rest off.
4
4
 
5
5
  ## Quick start
6
6
 
7
7
  Install and register the module:
8
8
 
9
9
  ```bash
10
- pnpm add nuxid
10
+ pnpm add @ciwergrp/nuxid
11
11
  ```
12
12
 
13
13
  ```ts
14
14
  // nuxt.config.ts
15
15
  export default defineNuxtConfig({
16
- modules: ['nuxid'],
16
+ modules: ['@ciwergrp/nuxid'],
17
17
  nuxid: {
18
- // lodash, validator, icon, and form are enabled by default
18
+ // lodash, validator, form, helper, and pinia are enabled by default
19
19
  },
20
20
  })
21
21
  ```
22
22
 
23
23
  ## Features
24
24
 
25
- - **Icon defaults** (`@nuxt/icon` dependency): component name `KIcon`, size `1.25em`, base class `align-middle inline-block text-current`, mode `svg`. Override via `nuxid.icon`, or disable with `nuxid.icon = false`.
26
- - **Lodash auto-imports**: imports from `lodash-es` with prefix `ki` (e.g. `kiDebounce`), skips prefix for names starting with `is`. Configure with:
25
+ - **Lodash auto-imports** (enabled by default): imports from `lodash-es` with prefix `ki` (e.g. `kiDebounce`), skips prefix for names starting with `is`. Configure with:
27
26
  - `enabled` (default `true`)
28
27
  - `prefix` (`false | string`, default `'ki'`)
29
28
  - `prefixSkip` (`string | string[] | false`, default `'is'`)
30
29
  - `upperAfterPrefix` (`boolean`, default `true`)
31
30
  - `exclude` (`string[]`)
32
31
  - `alias` (`Array<[from, to]>`)
33
- - **Validator helpers**: Element Plus friendly `createValidationRules` plus `ValidationRule` and `ValidationOptions` types. Auto-imported when enabled.
34
- - **Form composable**: `useForm` wraps `$fetch`, handles `processing`, `errors`, `response`, and builds `FormData` automatically (or always when `alwaysFormData: true`). Auto-imported when enabled.
32
+ - **Validator helpers** (enabled by default): Element Plus friendly `createValidationRules` plus `ValidationRule` and `ValidationOptions` types. Auto-imported when enabled.
33
+ - **Form composable** (enabled by default): `useHttp` wraps `$fetch`, handles `processing`, `errors`, `response`, and builds `FormData` automatically (or always when `alwaysFormData: true`). Auto-imported when enabled.
34
+ - **Helper utilities** (enabled by default): array/object/number/string helpers with configurable factory (`number().abbreviate()`) or prefixed (`NumberAbbreviate()`) styles, locale lookups, and currency defaults.
35
+ - **Pinia integration** (enabled by default): injects Pinia, auto-imports core helpers (`defineStore`, `storeToRefs`, etc.), and auto-imports stores from `stores` by default.
36
+ - **Icon defaults** (disabled by default): installs `@nuxt/icon` with default component name `KIcon`, size `1.25em`, base class `align-middle inline-block text-current`, mode `svg`. Configure via `nuxid.icon.config`.
37
+ - **Element Plus module** (disabled by default): installs `@element-plus/nuxt` with your provided config.
35
38
 
36
39
  ## Usage snippets
37
40
 
@@ -56,7 +59,7 @@ const rules = createValidationRules(
56
59
  **Form example**
57
60
 
58
61
  ```ts
59
- const form = useForm({ name: '', avatar: null }, { alwaysFormData: false })
62
+ const form = useHttp({ name: '', avatar: null }, { alwaysFormData: false })
60
63
 
61
64
  await form.post('/api/profile')
62
65
 
@@ -65,23 +68,44 @@ if (form.errors) {
65
68
  }
66
69
  ```
67
70
 
71
+ **Helper example**
72
+
73
+ ```ts
74
+ const price = number().currency(4200)
75
+ const slug = string().slug('Hello World')
76
+ ```
77
+
78
+ **Pinia example**
79
+
80
+ ```ts
81
+ export const useCartStore = defineStore('cart', {
82
+ state: () => ({ items: [] }),
83
+ })
84
+ ```
85
+
68
86
  ## Configuration reference
69
87
 
70
88
  ```ts
71
89
  export default defineNuxtConfig({
72
- modules: ['nuxid'],
90
+ modules: ['@ciwergrp/nuxid'],
73
91
  nuxid: {
74
92
  icon: {
75
- enabled: true,
76
- componentName: 'KIcon',
77
- size: '1.25em',
78
- class: 'align-middle inline-block text-current',
79
- mode: 'svg',
80
- provider: undefined,
81
- collections: undefined,
82
- aliases: undefined,
83
- fallbacks: undefined,
84
- extend: undefined,
93
+ enabled: false,
94
+ config: {
95
+ componentName: 'KIcon',
96
+ size: '1.25em',
97
+ class: 'align-middle inline-block text-current',
98
+ mode: 'svg',
99
+ provider: undefined,
100
+ collections: undefined,
101
+ aliases: undefined,
102
+ fallbacks: undefined,
103
+ extend: undefined,
104
+ },
105
+ },
106
+ elementPlus: {
107
+ enabled: false,
108
+ config: {},
85
109
  },
86
110
  lodash: {
87
111
  enabled: true,
@@ -97,6 +121,20 @@ export default defineNuxtConfig({
97
121
  form: {
98
122
  enabled: true,
99
123
  },
124
+ helper: {
125
+ enabled: true,
126
+ config: {
127
+ style: 'factory',
128
+ localeSource: 'cookie',
129
+ localeKey: 'lang',
130
+ localeFallback: 'en',
131
+ defaultCurrency: 'USD',
132
+ },
133
+ },
134
+ pinia: {
135
+ enabled: true,
136
+ storesDirs: ['stores'],
137
+ },
100
138
  },
101
139
  })
102
140
  ```
package/dist/module.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  export * from '../dist/runtime/form.js';
3
- export { default as useForm } from '../dist/runtime/form.js';
3
+ export { default as useHttp } from '../dist/runtime/form.js';
4
4
  export * from '../dist/runtime/validator.js';
5
5
  export * from '../dist/runtime/helper/index.js';
6
6
 
@@ -173,6 +173,29 @@ interface PiniaOptions {
173
173
  }
174
174
  type PiniaFeatureInput = boolean | Partial<PiniaOptions> | undefined;
175
175
 
176
+ interface VueUseOptions {
177
+ /**
178
+ * Enable VueUse integration
179
+ * @default true
180
+ */
181
+ enabled: boolean;
182
+ /**
183
+ * Enable auto-imports from @vueuse/nuxt
184
+ * @default true
185
+ */
186
+ autoImports: boolean;
187
+ /**
188
+ * Register VueUse SSR handlers
189
+ * @default false
190
+ */
191
+ ssrHandlers: boolean;
192
+ /**
193
+ * Extra VueUse functions to exclude from auto-imports
194
+ */
195
+ exclude: string[];
196
+ }
197
+ type VueUseFeatureInput = boolean | Partial<VueUseOptions> | undefined;
198
+
176
199
  interface ModuleOptions {
177
200
  lodash?: LodashFeatureInput;
178
201
  validator?: ValidatorFeatureInput;
@@ -181,6 +204,7 @@ interface ModuleOptions {
181
204
  elementPlus?: ElementPlusFeatureInput;
182
205
  helper?: HelperFeatureInput;
183
206
  pinia?: PiniaFeatureInput;
207
+ vueuse?: VueUseFeatureInput;
184
208
  }
185
209
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
186
210
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
3
  "configKey": "nuxid",
4
- "version": "1.0.5",
4
+ "version": "1.1.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -2,7 +2,7 @@ import { addImports, addPlugin, addImportsDir, defineNuxtModule, createResolver,
2
2
  import * as lodash from 'lodash-es';
3
3
  import { fileURLToPath } from 'node:url';
4
4
  export * from '../dist/runtime/form.js';
5
- export { default as useForm } from '../dist/runtime/form.js';
5
+ export { default as useHttp } from '../dist/runtime/form.js';
6
6
  export * from '../dist/runtime/validator.js';
7
7
  export * from '../dist/runtime/helper/index.js';
8
8
 
@@ -142,8 +142,8 @@ function registerFormFeature(options, { from }) {
142
142
  if (!options.enabled) {
143
143
  return;
144
144
  }
145
- addImports({ name: "default", as: "useForm", from });
146
- addImports({ name: "UseForm", as: "UseForm", from, type: true });
145
+ addImports({ name: "default", as: "useHttp", from });
146
+ addImports({ name: "UseHttp", as: "UseHttp", from, type: true });
147
147
  addImports({ name: "NuxidFormOptions", as: "NuxidFormOptions", from, type: true });
148
148
  }
149
149
 
@@ -373,6 +373,80 @@ function registerPiniaFeature(options, nuxt, { runtimeDir, payload, plugin, comp
373
373
  }
374
374
  }
375
375
 
376
+ const disabledFunctions = [
377
+ "toRefs",
378
+ "toRef",
379
+ "toValue",
380
+ "useFetch",
381
+ "useCookie",
382
+ "useHead",
383
+ "useStorage",
384
+ "useImage",
385
+ "useTitle"
386
+ ];
387
+
388
+ const vueuseDefaults = {
389
+ enabled: false,
390
+ autoImports: true,
391
+ ssrHandlers: false,
392
+ exclude: []
393
+ };
394
+ function resolveVueUseOptions(input) {
395
+ if (input === false) {
396
+ return { ...vueuseDefaults, enabled: false };
397
+ }
398
+ const overrides = typeof input === "boolean" || input === void 0 ? {} : input;
399
+ return {
400
+ ...vueuseDefaults,
401
+ ...overrides,
402
+ enabled: overrides?.enabled ?? true,
403
+ autoImports: overrides?.autoImports ?? vueuseDefaults.autoImports,
404
+ ssrHandlers: overrides?.ssrHandlers ?? vueuseDefaults.ssrHandlers,
405
+ exclude: [
406
+ ...disabledFunctions,
407
+ ...vueuseDefaults.exclude,
408
+ ...overrides?.exclude ?? []
409
+ ]
410
+ };
411
+ }
412
+ function registerVueUseFeature(options, nuxt) {
413
+ if (!options.enabled || !options.autoImports || !options.exclude.length) {
414
+ return;
415
+ }
416
+ const excluded = new Set(options.exclude);
417
+ const hasFrom = (value) => {
418
+ if (typeof value !== "object" || value === null || !("from" in value)) {
419
+ return false;
420
+ }
421
+ return typeof value.from === "string";
422
+ };
423
+ nuxt.hook("imports:sources", (sources) => {
424
+ for (let index = sources.length - 1; index >= 0; index -= 1) {
425
+ const source = sources[index];
426
+ const sourceFrom = source.from;
427
+ const hasVueUseSource = typeof sourceFrom === "string" && sourceFrom.startsWith("@vueuse/");
428
+ const hasVueUseImport = Array.isArray(source.imports) && source.imports.some((item) => typeof item === "object" && item !== null && hasFrom(item) && item.from.startsWith("@vueuse/"));
429
+ if (!hasVueUseSource && !hasVueUseImport) {
430
+ continue;
431
+ }
432
+ const filteredImports = (source.imports ?? []).filter((item) => {
433
+ if (typeof item === "string") {
434
+ return !excluded.has(item);
435
+ }
436
+ if (typeof item === "object" && item !== null && "name" in item) {
437
+ return !excluded.has(item.name);
438
+ }
439
+ return true;
440
+ });
441
+ if (!filteredImports.length) {
442
+ sources.splice(index, 1);
443
+ continue;
444
+ }
445
+ source.imports = filteredImports;
446
+ }
447
+ });
448
+ }
449
+
376
450
  const module$1 = defineNuxtModule({
377
451
  meta: {
378
452
  name: "@ciwergrp/nuxid",
@@ -382,9 +456,6 @@ const module$1 = defineNuxtModule({
382
456
  const dependencies = {
383
457
  "@sentry/nuxt": {
384
458
  version: "10.32.1"
385
- },
386
- "@vueuse/nuxt": {
387
- version: "14.1.0"
388
459
  }
389
460
  };
390
461
  return dependencies;
@@ -398,6 +469,7 @@ const module$1 = defineNuxtModule({
398
469
  const elementPlusOptions = resolveElementPlusOptions(options.elementPlus);
399
470
  const helperOptions = resolveHelperOptions(options.helper);
400
471
  const piniaOptions = resolvePiniaOptions(options.pinia);
472
+ const vueuseOptions = resolveVueUseOptions(options.vueuse);
401
473
  if (iconOptions.enabled) {
402
474
  await installModule("@nuxt/icon", iconOptions.config);
403
475
  }
@@ -432,6 +504,13 @@ const module$1 = defineNuxtModule({
432
504
  resolver
433
505
  });
434
506
  }
507
+ if (vueuseOptions.enabled) {
508
+ await installModule("@vueuse/nuxt", {
509
+ autoImports: vueuseOptions.autoImports,
510
+ ssrHandlers: vueuseOptions.ssrHandlers
511
+ });
512
+ registerVueUseFeature(vueuseOptions, nuxt);
513
+ }
435
514
  addPlugin(resolver.resolve("./runtime/plugin"));
436
515
  }
437
516
  });
@@ -1,7 +1,7 @@
1
1
  import type { HTTPMethod } from 'h3';
2
2
  import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
3
3
  export type FormFetcher = <T = any>(request: NitroFetchRequest, opts?: NitroFetchOptions<NitroFetchRequest>) => Promise<T>;
4
- export interface UseForm<DefaultResponseType = any> {
4
+ export interface UseHttp<DefaultResponseType = any> {
5
5
  _method?: HTTPMethod;
6
6
  submit: <APIResponseType = DefaultResponseType>(method: HTTPMethod, url: NitroFetchRequest, options?: NitroFetchOptions<NitroFetchRequest>) => Promise<APIResponseType>;
7
7
  post: <APIResponseType = DefaultResponseType>(url: NitroFetchRequest, options?: NitroFetchOptions<NitroFetchRequest>) => Promise<APIResponseType>;
@@ -18,4 +18,4 @@ export interface FormComposableOptions {
18
18
  fetcher?: FormFetcher;
19
19
  fetchOptions?: NitroFetchOptions<NitroFetchRequest>;
20
20
  }
21
- export default function useForm<TData extends object, DefaultResponseType = any>(initialData: TData, formOptions?: FormComposableOptions): TData & UseForm<DefaultResponseType>;
21
+ export default function useHttp<TData extends object, DefaultResponseType = any>(initialData: TData, formOptions?: FormComposableOptions): TData & UseHttp<DefaultResponseType>;
@@ -17,7 +17,7 @@ function normalizeValue(value) {
17
17
  }
18
18
  return value;
19
19
  }
20
- export default function useForm(initialData, formOptions) {
20
+ export default function useHttp(initialData, formOptions) {
21
21
  const form = reactive({
22
22
  ...initialData,
23
23
  response: null,
@@ -1,4 +1,3 @@
1
1
  import { defineNuxtPlugin } from "#app";
2
2
  export default defineNuxtPlugin((_nuxtApp) => {
3
- console.log("Plugin injected!");
4
3
  });
package/dist/types.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { type useForm } from '../dist/runtime/form.js'
1
+ export { type useHttp } from '../dist/runtime/form.js'
2
2
 
3
3
  export { default } from './module.mjs'
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciwergrp/nuxid",
3
- "version": "1.0.5",
3
+ "version": "1.1.0",
4
4
  "description": "All-in-one essential modules for Nuxt",
5
5
  "repository": {
6
6
  "type": "git",
@@ -75,7 +75,8 @@
75
75
  "nuxt": "^4.2.1",
76
76
  "typescript": "~5.9.3",
77
77
  "vitest": "^4.0.13",
78
- "vue-tsc": "^3.1.5"
78
+ "vue-tsc": "^3.1.5",
79
+ "@vueuse/nuxt": "14.1.0"
79
80
  },
80
81
  "scripts": {
81
82
  "dev": "npm run dev:prepare && nuxi dev playground",