@desource/phone-mask-nuxt 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # @desource/phone-mask-nuxt
2
+
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release of phone-mask monorepo packages
8
+ - Core phone masking library with Google libphonenumber integration
9
+ - Vue 3 component and directive for phone input
10
+ - Nuxt 3 module with zero-config setup
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies []:
15
+ - @desource/phone-mask-vue@0.2.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DeSource Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,398 @@
1
+ # @desource/phone-mask-nuxt
2
+
3
+ > Nuxt 3 module for phone input with Google's libphonenumber data
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@desource/phone-mask-nuxt?color=blue&logo=nuxt.js)](https://www.npmjs.com/package/@desource/phone-mask-nuxt)
6
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/DeSource-Labs/phone-mask/blob/main/LICENSE)
7
+
8
+ Drop-in Nuxt 3 module with auto-imports, SSR support, and zero configuration.
9
+
10
+ ## ✨ Features
11
+
12
+ - 🎯 **Zero Config** β€” Works out of the box
13
+ - πŸ”„ **Auto-imports** β€” Components and composables
14
+ - 🌐 **SSR Compatible** β€” Server-side rendering ready
15
+ - 🎨 **Styleable** β€” Bring your own styles or use defaults
16
+ - πŸ”§ **TypeScript** β€” Fully typed
17
+ - ⚑ **Optimized** β€” Tree-shaking and code splitting
18
+
19
+ ## πŸ“¦ Installation
20
+
21
+ ```bash
22
+ npm install @desource/phone-mask-nuxt
23
+ # or
24
+ yarn add @desource/phone-mask-nuxt
25
+ # or
26
+ pnpm add @desource/phone-mask-nuxt
27
+ ```
28
+
29
+ ## πŸš€ Setup
30
+
31
+ Add the module to your `nuxt.config.ts`:
32
+
33
+ ```ts
34
+ export default defineNuxtConfig({
35
+ modules: ['@desource/phone-mask-nuxt']
36
+ });
37
+ ```
38
+
39
+ That's it! The component and directive are now auto-imported.
40
+
41
+ ## πŸ“– Usage
42
+
43
+ ### Basic Component
44
+
45
+ ```vue
46
+ <template>
47
+ <div>
48
+ <PhoneInput v-model="phone" country="US" />
49
+ <p>Phone: {{ phone }}</p>
50
+ </div>
51
+ </template>
52
+
53
+ <script setup lang="ts">
54
+ const phone = ref('');
55
+ </script>
56
+ ```
57
+
58
+ ### With Auto-detection
59
+
60
+ ```vue
61
+ <template>
62
+ <PhoneInput v-model="phone" detect @country-change="onCountryChange" />
63
+ </template>
64
+
65
+ <script setup>
66
+ const phone = ref('');
67
+
68
+ const onCountryChange = (country) => {
69
+ console.log('Detected country:', country.name);
70
+ };
71
+ </script>
72
+ ```
73
+
74
+ ### Using the Directive
75
+
76
+ ```vue
77
+ <template>
78
+ <div class="phone-wrapper">
79
+ <select v-model="selectedCountry">
80
+ <option value="US">πŸ‡ΊπŸ‡Έ +1</option>
81
+ <option value="GB">πŸ‡¬πŸ‡§ +44</option>
82
+ <option value="DE">πŸ‡©πŸ‡ͺ +49</option>
83
+ </select>
84
+
85
+ <input
86
+ v-phone-mask="{
87
+ country: selectedCountry,
88
+ onChange: handleChange
89
+ }"
90
+ class="phone-input"
91
+ />
92
+ </div>
93
+ </template>
94
+
95
+ <script setup>
96
+ const selectedCountry = ref('US');
97
+ const phone = ref('');
98
+
99
+ const handleChange = (fullNumber, digits) => {
100
+ phone.value = fullNumber;
101
+ };
102
+ </script>
103
+ ```
104
+
105
+ ## βš™οΈ Configuration
106
+
107
+ ### Module Options
108
+
109
+ Configure the module in `nuxt.config.ts`:
110
+
111
+ ```ts
112
+ export default defineNuxtConfig({
113
+ modules: ['@desource/phone-mask-nuxt'],
114
+
115
+ phoneMask: {
116
+ // Import styles automatically
117
+ css: true, // Default: true
118
+
119
+ // Register PhoneInput component
120
+ component: true, // Default: true
121
+
122
+ // Register v-phone-mask directive
123
+ directive: true, // Default: true
124
+
125
+ // Register shared helpers and types
126
+ helpers: true // Default: true
127
+ }
128
+ });
129
+ ```
130
+
131
+ ### Custom Styling
132
+
133
+ #### Option 1: Disable auto CSS import
134
+
135
+ ```ts
136
+ export default defineNuxtConfig({
137
+ modules: ['@desource/phone-mask-nuxt'],
138
+
139
+ phoneMask: {
140
+ css: false // Don't auto-import styles
141
+ }
142
+ });
143
+ ```
144
+
145
+ Then import manually where needed:
146
+
147
+ ```vue
148
+ <style>
149
+ @import '@desource/phone-mask-vue/assets/lib.css';
150
+
151
+ /* Your custom overrides */
152
+ .phone-input {
153
+ --pi-border: #your-color;
154
+ }
155
+ </style>
156
+ ```
157
+
158
+ #### Option 2: Override CSS variables
159
+
160
+ ```vue
161
+ <style>
162
+ :root {
163
+ --pi-bg: #f9fafb;
164
+ --pi-border: #e5e7eb;
165
+ --pi-border-focus: #3b82f6;
166
+ --pi-text: #111827;
167
+ }
168
+ </style>
169
+ ```
170
+
171
+ ## πŸ”§ TypeScript
172
+
173
+ The module provides automatic TypeScript support. Types are available globally:
174
+
175
+ ```ts
176
+ // Auto-imported types
177
+ import type {
178
+ PCountryKey,
179
+ PMaskBase,
180
+ PMaskBaseMap,
181
+ PMask,
182
+ PMaskMap,
183
+ PMaskWithFlag,
184
+ PMaskWithFlagMap,
185
+ PMaskFull,
186
+ PMaskFullMap,
187
+ PMaskPhoneNumber
188
+ } from '#phone-mask';
189
+ ```
190
+
191
+ ## πŸ“š Examples
192
+
193
+ ### Form Integration
194
+
195
+ ```vue
196
+ <template>
197
+ <form @submit.prevent="handleSubmit">
198
+ <div>
199
+ <label for="name">Name</label>
200
+ <input id="name" v-model="form.name" type="text" />
201
+ </div>
202
+
203
+ <div>
204
+ <label for="phone">Phone</label>
205
+ <PhoneInput id="phone" v-model="form.phone" country="US" @validation-change="phoneValid = $event" />
206
+ </div>
207
+
208
+ <button type="submit" :disabled="!phoneValid">Submit</button>
209
+ </form>
210
+ </template>
211
+
212
+ <script setup>
213
+ const form = reactive({
214
+ name: '',
215
+ phone: ''
216
+ });
217
+
218
+ const phoneValid = ref(false);
219
+
220
+ const handleSubmit = () => {
221
+ console.log('Form data:', form);
222
+ };
223
+ </script>
224
+ ```
225
+
226
+ ### With Pinia Store
227
+
228
+ ```ts
229
+ // stores/user.ts
230
+ import { defineStore } from 'pinia';
231
+
232
+ export const useUserStore = defineStore('user', {
233
+ state: () => ({
234
+ phoneDigits: '',
235
+ country: 'US'
236
+ }),
237
+
238
+ actions: {
239
+ setPhoneDigits(phone: string) {
240
+ this.phone = phone;
241
+ },
242
+
243
+ setCountry(id: string) {
244
+ this.country = id;
245
+ }
246
+ }
247
+ });
248
+ ```
249
+
250
+ ```vue
251
+ <template>
252
+ <PhoneInput
253
+ :model-value="userStore.phoneDigits"
254
+ :country="userStore.country"
255
+ @update:model-value="userStore.setPhoneDigits"
256
+ @country-change="userStore.setCountry($event.id)"
257
+ />
258
+ </template>
259
+
260
+ <script setup>
261
+ const userStore = useUserStore();
262
+ </script>
263
+ ```
264
+
265
+ ### Multi-step Form
266
+
267
+ ```vue
268
+ <template>
269
+ <div>
270
+ <div v-if="step === 1">
271
+ <h2>Step 1: Contact Info</h2>
272
+ <PhoneInput v-model="formData.phone" country="US" @validation-change="phoneValid = $event" />
273
+ <button @click="nextStep" :disabled="!phoneValid">Next</button>
274
+ </div>
275
+
276
+ <div v-if="step === 2">
277
+ <h2>Step 2: Verification</h2>
278
+ <p>We'll send a code to: {{ formData.phone }}</p>
279
+ <button @click="prevStep">Back</button>
280
+ <button @click="submit">Send Code</button>
281
+ </div>
282
+ </div>
283
+ </template>
284
+
285
+ <script setup>
286
+ const step = ref(1);
287
+ const phoneValid = ref(false);
288
+ const formData = reactive({
289
+ phone: ''
290
+ });
291
+
292
+ const nextStep = () => {
293
+ if (phoneValid.value) step.value++;
294
+ };
295
+
296
+ const prevStep = () => {
297
+ step.value--;
298
+ };
299
+
300
+ const submit = async () => {
301
+ // Send verification code
302
+ };
303
+ </script>
304
+ ```
305
+
306
+ ### i18n Integration
307
+
308
+ ```vue
309
+ <template>
310
+ <PhoneInput v-model="phone" :locale="$i18n.locale" :placeholder="$t('phone.placeholder')" />
311
+ </template>
312
+
313
+ <script setup>
314
+ const { locale, t } = useI18n();
315
+ const phone = ref('');
316
+ </script>
317
+ ```
318
+
319
+ ## 🎯 Auto-imports
320
+
321
+ The following are automatically imported (until disabled in nuxt.config.ts):
322
+
323
+ ### Components
324
+
325
+ - `PhoneInput` β€” Main phone input component
326
+
327
+ ### Directives
328
+
329
+ - `vPhoneMask` β€” Phone mask directive
330
+
331
+ ### Helpers
332
+
333
+ - `vPhoneMaskSetCountry` β€” Programmatically set country for directive
334
+ - `PMaskHelpers` β€” Utility functions for phone masks like:
335
+ - `getFlagEmoji`
336
+ - `countPlaceholders`
337
+ - `formatDigitsWithMap`
338
+ - `pickMaskVariant`
339
+ - `removeCountryCodePrefix`
340
+ - And more...
341
+
342
+ Read more about helpers in the [Utility Functions of @desource/phone-mask README](../phone-mask/README.md#utility-functions).
343
+
344
+ ### Types
345
+
346
+ All TypeScript types from `@desource/phone-mask-vue`
347
+
348
+ ## πŸ”„ Migration from Vue Plugin
349
+
350
+ If you're migrating from the Vue plugin:
351
+
352
+ **Before:**
353
+
354
+ ```ts
355
+ // main.ts
356
+ import PhoneMaskPlugin from '@desource/phone-mask-vue';
357
+ import '@desource/phone-mask-vue/style.css';
358
+
359
+ app.use(PhoneMaskPlugin);
360
+ ```
361
+
362
+ **After:**
363
+
364
+ ```ts
365
+ // nuxt.config.ts
366
+ export default defineNuxtConfig({
367
+ modules: ['@desource/phone-mask-nuxt']
368
+ });
369
+ ```
370
+
371
+ No changes needed in your components!
372
+
373
+ ## πŸ“¦ What's Included
374
+
375
+ - `PhoneInput` component (auto-imported)
376
+ - `vPhoneMask` directive (auto-imported)
377
+ - Default styles (auto-imported, can be disabled)
378
+ - TypeScript definitions (auto-imported)
379
+ - Utility functions (auto-imported)
380
+
381
+ ## πŸ”— Related
382
+
383
+ - [@desource/phone-mask](../phone-mask) β€” Core library
384
+ - [@desource/phone-mask-vue](../phone-mask-vue) β€” Vue 3 component
385
+
386
+ ## πŸ“„ License
387
+
388
+ [MIT](../../LICENSE) Β© 2025 DeSource Labs
389
+
390
+ ## 🀝 Contributing
391
+
392
+ See [Contributing Guide](../../CONTRIBUTING.md)
393
+
394
+ ---
395
+
396
+ <div align="center">
397
+ <sub>Made with ❀️ by <a href="https://github.com/DeSource-Labs">DeSource Labs</a></sub>
398
+ </div>
@@ -0,0 +1,12 @@
1
+ import { NuxtModule } from '@nuxt/schema';
2
+
3
+ interface ModuleOptions {
4
+ css?: boolean;
5
+ component?: boolean;
6
+ directive?: boolean;
7
+ helpers?: boolean;
8
+ }
9
+ declare const module: NuxtModule<ModuleOptions>;
10
+
11
+ export { module as default };
12
+ export type { ModuleOptions };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "phoneMask",
3
+ "compatibility": {
4
+ "nuxt": ">=3.0.0"
5
+ },
6
+ "configKey": "phoneMask",
7
+ "version": "0.2.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.2",
10
+ "unbuild": "unknown"
11
+ }
12
+ }
@@ -0,0 +1,61 @@
1
+ import { defineNuxtModule, createResolver, isNuxtMajorVersion, addPlugin, addImports, addComponent } from '@nuxt/kit';
2
+ import { fileURLToPath } from 'url';
3
+
4
+ const module = defineNuxtModule({
5
+ meta: {
6
+ name: "phoneMask",
7
+ compatibility: {
8
+ nuxt: ">=3.0.0"
9
+ }
10
+ },
11
+ defaults: {
12
+ css: true,
13
+ component: true,
14
+ directive: true,
15
+ helpers: true
16
+ },
17
+ async setup(options, nuxt) {
18
+ const { resolve } = createResolver(import.meta.url);
19
+ const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
20
+ nuxt.options.build.transpile.push(runtimeDir);
21
+ nuxt.hook("prepare:types", ({ references }) => {
22
+ references.push({ types: "@desource/phone-mask-nuxt" });
23
+ });
24
+ nuxt.hook("modules:done", () => {
25
+ if (!isNuxtMajorVersion(2, nuxt) && options.directive) {
26
+ addPlugin(resolve(runtimeDir, "plugin.phone-mask"));
27
+ }
28
+ });
29
+ if (options.helpers) {
30
+ const shared = resolve(runtimeDir, "shared");
31
+ addImports([
32
+ { name: "vPhoneMaskSetCountry", from: shared },
33
+ { name: "PMaskHelpers", from: shared },
34
+ { name: "vPhoneMask", from: shared },
35
+ { name: "PCountryKey", from: shared, type: true },
36
+ { name: "PMaskBase", from: shared, type: true },
37
+ { name: "PMaskBaseMap", from: shared, type: true },
38
+ { name: "PMask", from: shared, type: true },
39
+ { name: "PMaskMap", from: shared, type: true },
40
+ { name: "PMaskWithFlag", from: shared, type: true },
41
+ { name: "PMaskWithFlagMap", from: shared, type: true },
42
+ { name: "PMaskFull", from: shared, type: true },
43
+ { name: "PMaskFullMap", from: shared, type: true },
44
+ { name: "PMaskPhoneNumber", from: shared, type: true }
45
+ ]);
46
+ }
47
+ if (options.component) {
48
+ const componentDir = resolve(runtimeDir, "component");
49
+ addComponent({
50
+ name: "PhoneInput",
51
+ filePath: componentDir,
52
+ mode: "client"
53
+ });
54
+ }
55
+ if (options.css) {
56
+ nuxt.options.css.unshift("@desource/phone-mask-vue/assets/lib.css");
57
+ }
58
+ }
59
+ });
60
+
61
+ export { module as default };
@@ -0,0 +1,2 @@
1
+ import { PhoneInput } from '@desource/phone-mask-vue';
2
+ export default PhoneInput;
@@ -0,0 +1,2 @@
1
+ import { PhoneInput } from "@desource/phone-mask-vue";
2
+ export default PhoneInput;
@@ -0,0 +1,3 @@
1
+ import { type Plugin } from '#app';
2
+ declare const plugin: Plugin;
3
+ export default plugin;
@@ -0,0 +1,9 @@
1
+ import { vPhoneMask } from "@desource/phone-mask-vue";
2
+ import { defineNuxtPlugin } from "#app";
3
+ const plugin = defineNuxtPlugin({
4
+ name: "phone-mask",
5
+ setup(nuxtApp) {
6
+ nuxtApp.vueApp.directive("phone-mask", vPhoneMask);
7
+ }
8
+ });
9
+ export default plugin;
@@ -0,0 +1 @@
1
+ export { vPhoneMaskSetCountry, vPhoneMask, PMaskHelpers, type PCountryKey, type PMaskBase, type PMaskBaseMap, type PMask, type PMaskMap, type PMaskWithFlag, type PMaskWithFlagMap, type PMaskFull, type PMaskFullMap, type PMaskPhoneNumber } from '@desource/phone-mask-vue';
@@ -0,0 +1,5 @@
1
+ export {
2
+ vPhoneMaskSetCountry,
3
+ vPhoneMask,
4
+ PMaskHelpers
5
+ } from "@desource/phone-mask-vue";
@@ -0,0 +1,3 @@
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@desource/phone-mask-nuxt",
3
+ "version": "0.2.0",
4
+ "description": "🎯 Zero-config Nuxt 3 module for international phone masking. Powered by @desource/phone-mask with Google libphonenumber sync.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/types.d.mts",
9
+ "import": "./dist/module.mjs",
10
+ "require": "./dist/module.mjs"
11
+ }
12
+ },
13
+ "main": "./dist/module.mjs",
14
+ "files": [
15
+ "dist",
16
+ "CHANGELOG.md",
17
+ "README.md"
18
+ ],
19
+ "keywords": [
20
+ "nuxt",
21
+ "nuxt-module",
22
+ "nuxt3",
23
+ "vue",
24
+ "vue3",
25
+ "phone",
26
+ "mask",
27
+ "input",
28
+ "international",
29
+ "libphonenumber",
30
+ "country-code",
31
+ "phone-number",
32
+ "ssr",
33
+ "formatting",
34
+ "validation",
35
+ "typescript"
36
+ ],
37
+ "author": "Stefan Popov <stefan@desource-labs.org>",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "git+https://github.com/DeSource-Labs/phone-mask.git",
42
+ "directory": "packages/phone-mask-nuxt"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/DeSource-Labs/phone-mask/issues"
46
+ },
47
+ "homepage": "https://github.com/DeSource-Labs/phone-mask/tree/main/packages/phone-mask-nuxt#readme",
48
+ "private": false,
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "peerDependencies": {
53
+ "vue": "^3.4.33"
54
+ },
55
+ "dependencies": {
56
+ "@desource/phone-mask-vue": "0.2.0"
57
+ },
58
+ "devDependencies": {
59
+ "@nuxt/kit": "^4.2.0",
60
+ "@nuxt/module-builder": "^1.0.2",
61
+ "nuxt": "^4.1.3",
62
+ "vue": "^3.5.22"
63
+ },
64
+ "scripts": {
65
+ "postinstall": "nuxt prepare",
66
+ "clean": "rimraf dist",
67
+ "build": "nuxt-module-build build"
68
+ }
69
+ }