@ciwergrp/nuxid 1.16.1 → 1.16.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.
- package/README.md +2 -1
- package/dist/module.d.mts +5 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +5 -1
- package/dist/runtime/helper/string/index.d.ts +3 -1
- package/dist/runtime/helper/string/index.js +3 -0
- package/dist/runtime/helper/string/normalizeValue.d.ts +2 -0
- package/dist/runtime/helper/string/normalizeValue.js +39 -0
- package/docs/.docs/helpers/string.md +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ export default defineNuxtConfig({
|
|
|
31
31
|
- `alias` (`Array<[from, to]>`)
|
|
32
32
|
- **Validator helpers** (enabled by default): Element Plus friendly `createValidationRules` plus `ValidationRule` and `ValidationOptions` types. Auto-imported when enabled.
|
|
33
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/date helpers with configurable factory (`number().abbreviate()`) or prefixed (`NumberAbbreviate()`) styles, locale lookups, currency defaults, and timezone source configuration (`query`/`cookie`/`localStorage`/`static`).
|
|
34
|
+
- **Helper utilities** (enabled by default): array/object/number/string/date helpers with configurable factory (`number().abbreviate()`, `string().normalizeValue()`) or prefixed (`NumberAbbreviate()`) styles, locale lookups, currency defaults, and timezone source configuration (`query`/`cookie`/`localStorage`/`static`).
|
|
35
35
|
- **Cursor fetch composable** (enabled by default): `useCursorFetch` wraps `$fetch`, supports cursor pagination, polling, reactive params, custom fetchers, and configurable cursor/meta keys. Auto-imported when enabled.
|
|
36
36
|
- **Pinia integration** (enabled by default): injects Pinia, auto-imports core helpers (`defineStore`, `storeToRefs`, etc.), and auto-imports stores from `stores` by default.
|
|
37
37
|
- **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`.
|
|
@@ -74,6 +74,7 @@ if (form.errors) {
|
|
|
74
74
|
```ts
|
|
75
75
|
const price = number().currency(4200)
|
|
76
76
|
const slug = string().slug('Hello World')
|
|
77
|
+
const label = string().normalizeValue('')
|
|
77
78
|
```
|
|
78
79
|
|
|
79
80
|
**Cursor fetch example**
|
package/dist/module.d.mts
CHANGED
|
@@ -54,6 +54,10 @@ interface ValidatorOptions {
|
|
|
54
54
|
}
|
|
55
55
|
type ValidatorFeatureInput = boolean | Partial<ValidatorOptions> | undefined;
|
|
56
56
|
|
|
57
|
+
interface IconOptionClientBundle {
|
|
58
|
+
scan?: boolean;
|
|
59
|
+
icons?: string[];
|
|
60
|
+
}
|
|
57
61
|
interface IconOptionConfig {
|
|
58
62
|
/**
|
|
59
63
|
* Default component name
|
|
@@ -94,6 +98,7 @@ interface IconOptionConfig {
|
|
|
94
98
|
* Extra options passed directly to @nuxt/icon
|
|
95
99
|
*/
|
|
96
100
|
extend?: Record<string, any>;
|
|
101
|
+
clientBundle?: IconOptionClientBundle;
|
|
97
102
|
}
|
|
98
103
|
interface IconOptions {
|
|
99
104
|
/**
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -113,7 +113,10 @@ const iconDefaults = {
|
|
|
113
113
|
componentName: "KIcon",
|
|
114
114
|
size: "1.25em",
|
|
115
115
|
class: "align-middle inline-block text-current",
|
|
116
|
-
mode: "svg"
|
|
116
|
+
mode: "svg",
|
|
117
|
+
clientBundle: {
|
|
118
|
+
scan: true
|
|
119
|
+
}
|
|
117
120
|
}
|
|
118
121
|
};
|
|
119
122
|
function resolveIconOptions(input) {
|
|
@@ -308,6 +311,7 @@ function registerHelperFeature(options, { from, plugin }) {
|
|
|
308
311
|
"lcfirst",
|
|
309
312
|
"length",
|
|
310
313
|
"lower",
|
|
314
|
+
"normalizeValue",
|
|
311
315
|
"padBoth",
|
|
312
316
|
"padLeft",
|
|
313
317
|
"padRight",
|
|
@@ -3,6 +3,7 @@ import { length, ltrim, rtrim, start, finish } from './basic.js';
|
|
|
3
3
|
import { camel, kebab, lcfirst, lower, snake, studly, title, ucfirst, upper } from './case.js';
|
|
4
4
|
import { contains, containsAll, endsWith, startsWith } from './match.js';
|
|
5
5
|
import { defaultLocale, useLocale, withLocale } from './locale.js';
|
|
6
|
+
import { normalizeValue } from './normalizeValue.js';
|
|
6
7
|
import { padBoth, padLeft, padRight } from './pad.js';
|
|
7
8
|
import { remove, replace, replaceFirst, replaceLast } from './replace.js';
|
|
8
9
|
import { slug } from './slug.js';
|
|
@@ -27,6 +28,7 @@ export interface StringHelper {
|
|
|
27
28
|
length: typeof length;
|
|
28
29
|
lower: typeof lower;
|
|
29
30
|
ltrim: typeof ltrim;
|
|
31
|
+
normalizeValue: typeof normalizeValue;
|
|
30
32
|
padBoth: typeof padBoth;
|
|
31
33
|
padLeft: typeof padLeft;
|
|
32
34
|
padRight: typeof padRight;
|
|
@@ -50,4 +52,4 @@ export interface StringHelper {
|
|
|
50
52
|
withLocale: typeof withLocale;
|
|
51
53
|
}
|
|
52
54
|
export declare function string(): StringHelper;
|
|
53
|
-
export { after, afterLast, ascii, before, beforeLast, between, betweenFirst, defaultLocale, camel, contains, containsAll, endsWith, finish, kebab, lcfirst, length, lower, padBoth, padLeft, padRight, remove, replace, replaceFirst, replaceLast, rtrim, slug, snake, start, startsWith, studly, title, transliterate, ucfirst, upper, wordCount, words, useLocale, withLocale, };
|
|
55
|
+
export { after, afterLast, ascii, before, beforeLast, between, betweenFirst, defaultLocale, camel, contains, containsAll, endsWith, finish, kebab, lcfirst, length, lower, normalizeValue, padBoth, padLeft, padRight, remove, replace, replaceFirst, replaceLast, rtrim, slug, snake, start, startsWith, studly, title, transliterate, ucfirst, upper, wordCount, words, useLocale, withLocale, };
|
|
@@ -3,6 +3,7 @@ import { length, ltrim, rtrim, start, finish } from "./basic.js";
|
|
|
3
3
|
import { camel, kebab, lcfirst, lower, snake, studly, title, ucfirst, upper } from "./case.js";
|
|
4
4
|
import { contains, containsAll, endsWith, startsWith } from "./match.js";
|
|
5
5
|
import { defaultLocale, useLocale, withLocale } from "./locale.js";
|
|
6
|
+
import { normalizeValue } from "./normalizeValue.js";
|
|
6
7
|
import { padBoth, padLeft, padRight } from "./pad.js";
|
|
7
8
|
import { remove, replace, replaceFirst, replaceLast } from "./replace.js";
|
|
8
9
|
import { slug } from "./slug.js";
|
|
@@ -28,6 +29,7 @@ export function string() {
|
|
|
28
29
|
length,
|
|
29
30
|
lower,
|
|
30
31
|
ltrim,
|
|
32
|
+
normalizeValue,
|
|
31
33
|
padBoth,
|
|
32
34
|
padLeft,
|
|
33
35
|
padRight,
|
|
@@ -69,6 +71,7 @@ export {
|
|
|
69
71
|
lcfirst,
|
|
70
72
|
length,
|
|
71
73
|
lower,
|
|
74
|
+
normalizeValue,
|
|
72
75
|
padBoth,
|
|
73
76
|
padLeft,
|
|
74
77
|
padRight,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function isEmpty(value) {
|
|
2
|
+
if (value == null)
|
|
3
|
+
return true;
|
|
4
|
+
if (typeof value.length === "number") {
|
|
5
|
+
return value.length === 0;
|
|
6
|
+
}
|
|
7
|
+
const tag = Object.prototype.toString.call(value);
|
|
8
|
+
if (tag === "[object Map]" || tag === "[object Set]") {
|
|
9
|
+
return value.size === 0;
|
|
10
|
+
}
|
|
11
|
+
const type = typeof value;
|
|
12
|
+
if (type !== "object" && type !== "function") {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const proto = Object.getPrototypeOf(value);
|
|
16
|
+
const isPlainish = proto === null || proto === Object.prototype || Object.getPrototypeOf(proto) === null;
|
|
17
|
+
if (!isPlainish && tag !== "[object Object]") {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return Object.keys(value).length === 0;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeValue(value, newValue) {
|
|
23
|
+
if (typeof value === "boolean") {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "number") {
|
|
27
|
+
return value.toLocaleString();
|
|
28
|
+
}
|
|
29
|
+
if (newValue) {
|
|
30
|
+
return newValue;
|
|
31
|
+
}
|
|
32
|
+
if (!isEmpty(value)) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === "string" && value === "") {
|
|
36
|
+
return "-";
|
|
37
|
+
}
|
|
38
|
+
return "-";
|
|
39
|
+
}
|
|
@@ -5,7 +5,7 @@ outline: [2, 3]
|
|
|
5
5
|
|
|
6
6
|
# String Helpers
|
|
7
7
|
|
|
8
|
-
String helpers cover casing, trimming, matching, and
|
|
8
|
+
String helpers cover casing, trimming, matching, slug formatting, and value normalization.
|
|
9
9
|
|
|
10
10
|
Factory style:
|
|
11
11
|
|
|
@@ -140,6 +140,13 @@ Parameters: `value` (string).
|
|
|
140
140
|
- Simple usage: `string().lower('Hello')` = `'hello'`
|
|
141
141
|
- Advanced usage: `string().lower('HELLO WORLD')` = `'hello world'`
|
|
142
142
|
|
|
143
|
+
### normalizeValue
|
|
144
|
+
Summary: Normalizes empty values to `-`, preserves booleans, and formats numbers with locale separators.
|
|
145
|
+
Parameters: `value` (unknown), `newValue` (unknown, optional).
|
|
146
|
+
- Returns: `unknown`.
|
|
147
|
+
- Simple usage: `string().normalizeValue('')` = `'-'`
|
|
148
|
+
- Advanced usage: `string().normalizeValue(12000)` = `'12,000'`
|
|
149
|
+
|
|
143
150
|
### ltrim
|
|
144
151
|
Summary: Trims left side using `trimStart` or a mask regex.
|
|
145
152
|
Parameters: `value` (string), `mask` (string, optional).
|