Skip to content

Commit be0d9aa

Browse files
committed
Sync the package in examples
1 parent 52413ac commit be0d9aa

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

development/src/phone-hooks/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import {ChangeEvent, KeyboardEvent, useCallback, useMemo, useRef, useState} from "react";
24

35
import {PhoneNumber, usePhoneOptions} from "./types";
@@ -10,11 +12,8 @@ const slots = new Set(".");
1012

1113
export const getMetadata = (rawValue: string, countriesList: typeof countries = countries, country: any = null) => {
1214
country = country == null && rawValue.startsWith("44") ? "gb" : country;
13-
if (country != null) {
14-
countriesList = countriesList.filter((c) => c[0] === country);
15-
countriesList = countriesList.sort((a, b) => b[2].length - a[2].length);
16-
}
17-
return countriesList.find((c) => rawValue.startsWith(c[2]));
15+
if (country != null) countriesList = countriesList.filter((c) => c[0] === country);
16+
return [...countriesList].sort((a, b) => b[2].length - a[2].length).find((c) => rawValue.startsWith(c[2]));
1817
}
1918

2019
export const getCountry = (countryCode: keyof typeof countries) => {
@@ -36,8 +35,9 @@ export const cleanInput = (input: any, pattern: string) => {
3635
return Array.from(pattern, c => input[0] === c || slots.has(c) ? input.shift() || c : c);
3736
}
3837

39-
export const getFormattedNumber = (rawValue: any, pattern: string) => {
38+
export const getFormattedNumber = (rawValue: any, pattern?: string) => {
4039
/** Returns the reformatted input value based on the given pattern */
40+
pattern = pattern || getMetadata(rawValue)?.[3] || "";
4141
return displayFormat(cleanInput(rawValue, pattern.replaceAll(/\d/g, ".")).join(""));
4242
}
4343

development/src/phone-hooks/styles.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
export const jsonToCss = (stylesheet: object) => {
24
/** Convert the given `stylesheet` object to raw CSS */
35
return Object.entries(stylesheet).map(([selector, rules]) => {

development/src/phone-hooks/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
export interface PhoneNumber {
24
countryCode?: number | null;
35
areaCode?: string | null;

0 commit comments

Comments
 (0)