svelte-tel-input 3.2.0 → 3.2.2

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/LICENSE.md CHANGED
@@ -1 +1,21 @@
1
- ../../LICENSE.md
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 - Present Gyorgy Kallai, Budapest, Hungary.
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 CHANGED
@@ -1 +1,232 @@
1
- ../../README.md
1
+ <a name="readme-top"></a>
2
+
3
+ [![npm version](https://badge.fury.io/js/svelte-tel-input.svg)](https://badge.fury.io/js/svelte-tel-input)
4
+
5
+ # Svelte Tel Input
6
+
7
+ > Lightweight svelte tel/phone input standardizer.
8
+
9
+ <img src="https://raw.githubusercontent.com/gyurielf/svelte-tel-input/main/static/demo.gif" width="600px" align="center">
10
+
11
+ 🔥 Check it out live [here](https://svelte-tel-input.vercel.app/)
12
+
13
+ ## Installation
14
+
15
+ Svelte Tel Input is distributed via [npm](https://www.npmjs.com/package/svelte-tel-input).
16
+
17
+ ```bash
18
+ npm install --save svelte-tel-input
19
+ ```
20
+
21
+ ## Features
22
+
23
+ - Support SSR/SSG.
24
+ - Parse and validate phone number.You can store one exact format (`E164`), no matter how users type their phone numbers.
25
+ - Format (specified to its country), to make it more readable.
26
+ - Prevent non-digits typing into the input, except the leading `+` sign (and `space` optionally).
27
+ - Handle copy-pasted phone numbers, it's sanitize non-digit characters except the leading `+` sign (and `space` optionally).
28
+ - Automatic placeholder generation for the selected country.
29
+
30
+ ## Usage
31
+
32
+ ### Advanced
33
+
34
+ _Snippet would be too long_ - [REPL](https://stackblitz.com/edit/svelte-tel-input-repl-1jfaar?file=README.md) (StackBlitz)
35
+
36
+ ### Basic
37
+
38
+ [REPL](https://stackblitz.com/edit/svelte-tel-input-repl?file=README.md) (StackBlitz)
39
+
40
+ ```html
41
+ <script lang="ts">
42
+ import { TelInput, normalizedCountries } from 'svelte-tel-input';
43
+ import type { DetailedValue, CountryCode, E164Number } from 'svelte-tel-input/types';
44
+
45
+ // Any Country Code Alpha-2 (ISO 3166)
46
+ let selectedCountry: CountryCode | null = 'HU';
47
+
48
+ // You must use E164 number format. It's guarantee the parsing and storing consistency.
49
+ let value: E164Number | null = '+36301234567';
50
+
51
+ // Validity
52
+ let valid = true;
53
+
54
+ // Optional - Extended details about the parsed phone number
55
+ let detailedValue: DetailedValue | null = null;
56
+ </script>
57
+
58
+ <div class="wrapper">
59
+ <select
60
+ class="country-select {!valid && 'invalid'}"
61
+ aria-label="Default select example"
62
+ name="Country"
63
+ bind:value={selectedCountry}
64
+ >
65
+ <option value={null} hidden={selectedCountry !== null}>Please select</option>
66
+ {#each normalizedCountries as country (country.id)}
67
+ <option
68
+ value={country.iso2}
69
+ selected={country.iso2 === selectedCountry}
70
+ aria-selected={country.iso2 === selectedCountry}
71
+ >
72
+ {country.iso2} (+{country.dialCode})
73
+ </option>
74
+ {/each}
75
+ </select>
76
+ <TelInput bind:country={selectedCountry} bind:value bind:valid bind:detailedValue class="basic-tel-input {!isValid && 'invalid'}" />
77
+ </div>
78
+
79
+ <style>
80
+ .wrapper :global(.basic-tel-input) {
81
+ height: 32px;
82
+ padding-left: 12px;
83
+ padding-right: 12px;
84
+ border-radius: 6px;
85
+ border: 1px solid;
86
+ outline: none;
87
+ }
88
+
89
+ .wrapper :global(.country-select) {
90
+ height: 36px;
91
+ padding-left: 12px;
92
+ padding-right: 12px;
93
+ border-radius: 6px;
94
+ border: 1px solid;
95
+ outline: none;
96
+ }
97
+
98
+ .wrapper :global(.invalid) {
99
+ border-color: red;
100
+ }
101
+ </style>
102
+ ```
103
+
104
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
105
+
106
+ ## Props
107
+
108
+ The default export of the library is the main TelInput component. It has the following props:
109
+
110
+ | Property name | Type | Default Value | Usage |
111
+ | ------------- | ---------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
112
+ | value | `E164Number \| null` | `null` | [E164](https://en.wikipedia.org/wiki/E.164) is the international format of phone.numbers. This is the main entry point to store and/or load an existent phone number. |
113
+ | country | `CountryCode \| null` | `null` | It's accept any Country Code Alpha-2 (ISO 3166). You can set manually (e.g: by the user via a select). The parser will inspect the entered phone number and if it detect a valid country calling code, then it's automatically set the country to according to the detected country calling code. E.g: `+36` -> `HU` |
114
+ | disabled | `boolean` | `false` | It's block the parser and prevent entering input. You must handle its styling on your own. |
115
+ | valid | `boolean` | `true` | Indicates whether the entered tel number validity. |
116
+ | detailedValue | `DetailedValue \|null` | `null` | All of the formatted results of the tel input. |
117
+ | class | `string` | `` | You can pass down any classname to the component |
118
+ | required | `boolean \| null` | `null` | Set the required attribute on the input element |
119
+ | options | `TelInputOptions` | check below | Allow or disallow spaces in the input field |
120
+
121
+ Config options:
122
+
123
+ ```javascript
124
+ {
125
+ // Generates country specific placeholder for the selected country.
126
+ autoPlaceholder: true,
127
+ // Allow or disallow spaces in the input field
128
+ spaces: true,
129
+ // If you have a parsed phone number and you change country manually from outside, then it's set the `valid` prop to false.
130
+ invalidateOnCountryChange: false
131
+ }
132
+ ```
133
+
134
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
135
+
136
+ ## Dispatched Events
137
+
138
+ The default export of the library is the main TelInput component. It has the following props:
139
+
140
+ | Event name | Type |
141
+ | ------------------- | ---------------------- |
142
+ | updateValue | `E164Number \| null` |
143
+ | updateDetailedValue | `DetailedValue \|null` |
144
+ | updateCountry | `CountryCode \| null` |
145
+ | updateValid | `boolean` |
146
+ | parseError | `string` |
147
+
148
+ ## Use case of the event driven behavior
149
+
150
+ ```typescript
151
+ <script lang="ts">
152
+ // Imports, etc....
153
+ let value: E164Number | null = null;
154
+ const yourHandler = (e: CustomEvent<E164Number | null>) => {
155
+ value = e.detail //
156
+ // do stuff...
157
+ };
158
+ </script>
159
+
160
+ <TelInput value={cachedValue ?? value} on:updateValue={yourHandler} ... />
161
+ ```
162
+
163
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
164
+
165
+ ## Caveats
166
+
167
+ - In order to reset `value` and/or `country` from outside (you must pass (or set if you binded) `null` for the property) have some side-effects:
168
+
169
+ - Reseting the `value` will set (keep the `country` as is):
170
+ - `detailedValue` to `null`
171
+ - dispatch `updateDetailedValue` event
172
+ - Reseting the `country` will set:
173
+ - `value` to `null`
174
+ - `detailedValue` to `null`
175
+ - `valid` to `true` if `invalidateOnCountryChange` config option is false (_@default false_). Otherwise it will be `false`.
176
+ - and dispatch `updateValid`, `updateValue` `updateDetailedValue` events
177
+ - Reseting both `value` and `country` will set:
178
+ - `valid` to `true`
179
+ - `detailedValue` to `null`;
180
+
181
+ - Let's assume you pass a `US` `E164` number, which can be a partial `E164`, but long enough to determine the country and you pass `DE` country directly. The country will be updated to `US`, which is determined from the `E164` in this example. If the `E164` is not long enough to determine its country, then the country will stay what you passed to the component (`DE`).
182
+
183
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
184
+
185
+ ## Goals
186
+
187
+ - Solve the problem that a users can enter the same phone number in different formats.
188
+ - Storing a phone number in a standard format, that can be indexable and searchable in any database.
189
+ - Should be accessible for the the browser. Eg. for a `<a href="tel+36201234567 />`.
190
+ - The stored phone number format can be useable for any SMS gateway(e.g for 2FA) and if somebody can call the number from anywhere, it should work.
191
+
192
+ ## Dependencies
193
+
194
+ [libphonenumber-js](https://gitlab.com/catamphetamine/libphonenumber-js)
195
+
196
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
197
+
198
+ ## Changelog
199
+
200
+ | Package | Changelog |
201
+ | -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
202
+ | [@gyurielf/svelte-tel-input](https://github.com/gyurielf/svelte-tel-input/tree/main/packages/svelte-tel-input) | [Changelog](https://github.com/gyurielf/svelte-tel-input/blob/main/packages/svelte-tel-input/CHANGELOG.md) |
203
+
204
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
205
+
206
+ ## Roadmap
207
+
208
+ - [x] Add Changelog
209
+ - [x] Add CI/CD
210
+ - [x] Integrate libphonenumber
211
+ - [x] Implement parser
212
+ - [x] Add basics docs and examples
213
+ - [x] Add advanced examples
214
+ - [x] Generate placeholders autimatically
215
+ - [x] Move to monorepo
216
+ - [ ] Improve A11Y
217
+
218
+ See the [open issues](https://github.com/gyurielf/svelte-tel-input/issues) for a list of proposed features (and known issues).
219
+
220
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
221
+
222
+ ## Support
223
+
224
+ <a href="https://www.buymeacoffee.com/gyurielf" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
225
+
226
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
227
+
228
+ ## License
229
+
230
+ Distributed under the MIT License. See `LICENSE.md` for more information.
231
+
232
+ <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -1,5 +1,4 @@
1
- /// <reference types="svelte" />
2
1
  export declare const watcher: (initialValue: string | null, watchFunction: (oldVal: string | null, newVal: string | null) => void) => {
3
- subscribe: (this: void, run: import("svelte/store").Subscriber<string | null>, invalidate?: import("svelte/store").Invalidator<string | null> | undefined) => import("svelte/store").Unsubscriber;
2
+ subscribe: (this: void, run: import("svelte/store").Subscriber<string | null>, invalidate?: ((value?: string | null | undefined) => void) | undefined) => import("svelte/store").Unsubscriber;
4
3
  set: (value: string | null) => void;
5
4
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "svelte-tel-input",
3
3
  "description": "svelte-tel-input",
4
- "version": "3.2.0",
4
+ "version": "3.2.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/gyurielf/svelte-tel-input.git"
@@ -27,12 +27,10 @@
27
27
  "pnpm": ">= 8"
28
28
  },
29
29
  "peerDependencies": {
30
- "libphonenumber-js": "^1.10.30",
31
30
  "svelte": "^3.58.0 || ^4.0.0"
32
31
  },
33
32
  "dependencies": {
34
- "libphonenumber-js": "^1.10.37",
35
- "svelte": "^4.0.5"
33
+ "libphonenumber-js": "^1.10.37"
36
34
  },
37
35
  "devDependencies": {
38
36
  "@sveltejs/adapter-auto": "2.1.0",
@@ -41,27 +39,28 @@
41
39
  "@testing-library/svelte": "^4.0.3",
42
40
  "@testing-library/user-event": "^14.4.3",
43
41
  "@types/micromatch": "^4.0.2",
44
- "@typescript-eslint/eslint-plugin": "^6.0.0",
45
- "@typescript-eslint/parser": "^6.0.0",
42
+ "@typescript-eslint/eslint-plugin": "^6.1.0",
43
+ "@typescript-eslint/parser": "^6.1.0",
46
44
  "autoprefixer": "^10.4.14",
47
45
  "cssnano": "^6.0.1",
48
46
  "dotenv": "^16.3.1",
49
47
  "eslint": "^8.45.0",
50
48
  "eslint-config-prettier": "^8.8.0",
51
49
  "eslint-plugin-import": "^2.27.5",
52
- "eslint-plugin-svelte": "^2.32.2",
50
+ "eslint-plugin-svelte": "^2.32.4",
53
51
  "jsdom": "^22.1.0",
54
52
  "micromatch": "^4.0.5",
55
- "postcss": "^8.4.26",
53
+ "postcss": "^8.4.27",
56
54
  "prettier": "^2.8.8",
57
55
  "prettier-plugin-svelte": "^2.10.1",
58
56
  "publint": "^0.1.16",
57
+ "svelte": "^3.58.0",
59
58
  "svelte-check": "^3.4.6",
60
59
  "svelte2tsx": "^0.6.19",
61
60
  "tailwindcss": "^3.3.3",
62
61
  "tslib": "^2.6.0",
63
62
  "typescript": "^5.1.6",
64
- "vite": "^4.4.4",
63
+ "vite": "^4.4.6",
65
64
  "vitest": "^0.33.0"
66
65
  },
67
66
  "type": "module",