@kaisarsofi/react-native-phone-input 1.0.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/LICENSE +20 -0
- package/README.md +467 -0
- package/lib/commonjs/CountryPicker.js +669 -0
- package/lib/commonjs/CountryPicker.js.map +1 -0
- package/lib/commonjs/Flag.js +23 -0
- package/lib/commonjs/Flag.js.map +1 -0
- package/lib/commonjs/PhoneInput.js +252 -0
- package/lib/commonjs/PhoneInput.js.map +1 -0
- package/lib/commonjs/countries.js +75 -0
- package/lib/commonjs/countries.js.map +1 -0
- package/lib/commonjs/data/countries.json +1472 -0
- package/lib/commonjs/index.js +71 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/safeArea.js +44 -0
- package/lib/commonjs/safeArea.js.map +1 -0
- package/lib/commonjs/theme.js +85 -0
- package/lib/commonjs/theme.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/value.js +68 -0
- package/lib/commonjs/value.js.map +1 -0
- package/lib/module/CountryPicker.js +665 -0
- package/lib/module/CountryPicker.js.map +1 -0
- package/lib/module/Flag.js +19 -0
- package/lib/module/Flag.js.map +1 -0
- package/lib/module/PhoneInput.js +248 -0
- package/lib/module/PhoneInput.js.map +1 -0
- package/lib/module/countries.js +65 -0
- package/lib/module/countries.js.map +1 -0
- package/lib/module/data/countries.json +1472 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/safeArea.js +39 -0
- package/lib/module/safeArea.js.map +1 -0
- package/lib/module/theme.js +81 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/value.js +62 -0
- package/lib/module/value.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/CountryPicker.d.ts +37 -0
- package/lib/typescript/commonjs/src/CountryPicker.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/Flag.d.ts +10 -0
- package/lib/typescript/commonjs/src/Flag.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/PhoneInput.d.ts +3 -0
- package/lib/typescript/commonjs/src/PhoneInput.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/countries.d.ts +28 -0
- package/lib/typescript/commonjs/src/countries.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +9 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/safeArea.d.ts +11 -0
- package/lib/typescript/commonjs/src/safeArea.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/theme.d.ts +53 -0
- package/lib/typescript/commonjs/src/theme.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types.d.ts +211 -0
- package/lib/typescript/commonjs/src/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/value.d.ts +22 -0
- package/lib/typescript/commonjs/src/value.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/CountryPicker.d.ts +37 -0
- package/lib/typescript/module/src/CountryPicker.d.ts.map +1 -0
- package/lib/typescript/module/src/Flag.d.ts +10 -0
- package/lib/typescript/module/src/Flag.d.ts.map +1 -0
- package/lib/typescript/module/src/PhoneInput.d.ts +3 -0
- package/lib/typescript/module/src/PhoneInput.d.ts.map +1 -0
- package/lib/typescript/module/src/countries.d.ts +28 -0
- package/lib/typescript/module/src/countries.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +9 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/safeArea.d.ts +11 -0
- package/lib/typescript/module/src/safeArea.d.ts.map +1 -0
- package/lib/typescript/module/src/theme.d.ts +53 -0
- package/lib/typescript/module/src/theme.d.ts.map +1 -0
- package/lib/typescript/module/src/types.d.ts +211 -0
- package/lib/typescript/module/src/types.d.ts.map +1 -0
- package/lib/typescript/module/src/value.d.ts +22 -0
- package/lib/typescript/module/src/value.d.ts.map +1 -0
- package/package.json +215 -0
- package/src/CountryPicker.tsx +805 -0
- package/src/Flag.tsx +17 -0
- package/src/PhoneInput.tsx +363 -0
- package/src/countries.ts +95 -0
- package/src/data/countries.json +1472 -0
- package/src/index.tsx +21 -0
- package/src/safeArea.ts +50 -0
- package/src/theme.ts +112 -0
- package/src/types.ts +229 -0
- package/src/value.ts +70 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "COUNTRIES", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _countries.COUNTRIES;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "CountryPicker", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _CountryPicker.CountryPicker;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "DARK_PALETTE", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _theme.DARK_PALETTE;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "Flag", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _Flag.Flag;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "LIGHT_PALETTE", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _theme.LIGHT_PALETTE;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "PhoneInput", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _PhoneInput.PhoneInput;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "getCountryByCode", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _countries.getCountryByCode;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "groupCountriesByLetter", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _countries.groupCountriesByLetter;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "sectionLetterFor", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _countries.sectionLetterFor;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "usePhoneInputPalette", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _theme.usePhoneInputPalette;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var _countries = require("./countries.js");
|
|
67
|
+
var _Flag = require("./Flag.js");
|
|
68
|
+
var _PhoneInput = require("./PhoneInput.js");
|
|
69
|
+
var _CountryPicker = require("./CountryPicker.js");
|
|
70
|
+
var _theme = require("./theme.js");
|
|
71
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_countries","require","_Flag","_PhoneInput","_CountryPicker","_theme"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AAOA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,cAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasSafeAreaContext = void 0;
|
|
7
|
+
exports.useOptionalSafeAreaInsets = useOptionalSafeAreaInsets;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
/**
|
|
10
|
+
* `react-native-safe-area-context` is an *optional* peer: this library ships no
|
|
11
|
+
* native modules, so it is never installed on our account. The guarded require
|
|
12
|
+
* is what makes that safe — Metro registers a `require` inside a try/catch as
|
|
13
|
+
* an optional dependency and emits a runtime throw instead of failing the
|
|
14
|
+
* build (`allowOptionalDependencies`, enabled by default in both
|
|
15
|
+
* `@expo/metro-config` and `@react-native/metro-config`). The catch also covers
|
|
16
|
+
* bundlers that hand the ESM build a scope with no `require` at all.
|
|
17
|
+
*/
|
|
18
|
+
let optionalModule = null;
|
|
19
|
+
try {
|
|
20
|
+
optionalModule = require('react-native-safe-area-context');
|
|
21
|
+
} catch {
|
|
22
|
+
optionalModule = null;
|
|
23
|
+
}
|
|
24
|
+
const FallbackContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Deliberately the *context* rather than `useSafeAreaInsets()`: that hook
|
|
28
|
+
* throws when no `SafeAreaProvider` is mounted above it, and plenty of apps
|
|
29
|
+
* carry the package transitively (React Navigation depends on it) without a
|
|
30
|
+
* provider in scope. Reading the context degrades to `null` instead.
|
|
31
|
+
*
|
|
32
|
+
* Resolved once at module scope so the identity is stable, which keeps the
|
|
33
|
+
* `useContext` call below an unconditional, rules-of-hooks-safe one.
|
|
34
|
+
*/
|
|
35
|
+
const InsetsContext = optionalModule?.SafeAreaInsetsContext ?? FallbackContext;
|
|
36
|
+
|
|
37
|
+
/** The ambient safe-area insets, or null when unavailable. */
|
|
38
|
+
function useOptionalSafeAreaInsets() {
|
|
39
|
+
return (0, _react.useContext)(InsetsContext);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Whether the optional peer resolved. Exported for diagnostics and tests. */
|
|
43
|
+
const hasSafeAreaContext = exports.hasSafeAreaContext = optionalModule?.SafeAreaInsetsContext != null;
|
|
44
|
+
//# sourceMappingURL=safeArea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","optionalModule","FallbackContext","createContext","InsetsContext","SafeAreaInsetsContext","useOptionalSafeAreaInsets","useContext","hasSafeAreaContext","exports"],"sourceRoot":"../../src","sources":["safeArea.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAIC,cAAqC,GAAG,IAAI;AAChD,IAAI;EACFA,cAAc,GAAGD,OAAO,CAAC,gCAAgC,CAAmB;AAC9E,CAAC,CAAC,MAAM;EACNC,cAAc,GAAG,IAAI;AACvB;AAEA,MAAMC,eAAe,gBAAG,IAAAC,oBAAa,EAAoB,IAAI,CAAC;;AAE9D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,aAAyC,GAC7CH,cAAc,EAAEI,qBAAqB,IAAIH,eAAe;;AAE1D;AACO,SAASI,yBAAyBA,CAAA,EAAsB;EAC7D,OAAO,IAAAC,iBAAU,EAACH,aAAa,CAAC;AAClC;;AAEA;AACO,MAAMI,kBAAkB,GAAAC,OAAA,CAAAD,kBAAA,GAAGP,cAAc,EAAEI,qBAAqB,IAAI,IAAI","ignoreList":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LIGHT_PALETTE = exports.DARK_PALETTE = void 0;
|
|
7
|
+
exports.usePhoneInputPalette = usePhoneInputPalette;
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
/** Which palette to render with. "system" follows the OS appearance. */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Every color the input and the country picker draw with. Both palettes are
|
|
14
|
+
* complete, so dark mode needs no configuration — pass nothing and the
|
|
15
|
+
* component follows the OS. Override individual tokens via the `palette`
|
|
16
|
+
* prop when you want the component to match your own design system.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Note the split with `theme`: `theme` styles the text field alone (its fill,
|
|
20
|
+
* its borders, its text), while this palette covers the field's neutral
|
|
21
|
+
* defaults *and* the whole picker sheet. Keeping them separate is what lets a
|
|
22
|
+
* field sitting on a colored background go fully custom without erasing the
|
|
23
|
+
* picker's separators or A-Z index along with it.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const LIGHT_PALETTE = exports.LIGHT_PALETTE = {
|
|
27
|
+
background: '#FFFFFF',
|
|
28
|
+
inputBackground: '#FFFFFF',
|
|
29
|
+
surface: '#F2F2F7',
|
|
30
|
+
surfacePressed: '#E5E5EA',
|
|
31
|
+
border: '#D1D1D6',
|
|
32
|
+
text: '#1C1C1E',
|
|
33
|
+
textMuted: '#8E8E93',
|
|
34
|
+
placeholder: '#8E8E93',
|
|
35
|
+
accent: '#007AFF',
|
|
36
|
+
accentContrast: '#FFFFFF',
|
|
37
|
+
danger: '#FF3B30',
|
|
38
|
+
disabled: '#C7C7CC',
|
|
39
|
+
handle: '#D1D1D6',
|
|
40
|
+
bubble: 'rgba(60,60,67,0.85)',
|
|
41
|
+
bubbleText: '#FFFFFF'
|
|
42
|
+
};
|
|
43
|
+
const DARK_PALETTE = exports.DARK_PALETTE = {
|
|
44
|
+
background: '#1C1C1E',
|
|
45
|
+
inputBackground: '#1C1C1E',
|
|
46
|
+
surface: '#2C2C2E',
|
|
47
|
+
surfacePressed: '#3A3A3C',
|
|
48
|
+
border: '#38383A',
|
|
49
|
+
text: '#FFFFFF',
|
|
50
|
+
textMuted: '#98989F',
|
|
51
|
+
placeholder: '#8E8E93',
|
|
52
|
+
accent: '#0A84FF',
|
|
53
|
+
accentContrast: '#FFFFFF',
|
|
54
|
+
danger: '#FF453A',
|
|
55
|
+
disabled: '#48484A',
|
|
56
|
+
handle: '#48484A',
|
|
57
|
+
bubble: 'rgba(120,120,128,0.9)',
|
|
58
|
+
bubbleText: '#FFFFFF'
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Resolves the palette for the current appearance. `colorScheme` forces one;
|
|
63
|
+
* "system" (the default) follows the OS and re-renders when it changes.
|
|
64
|
+
*/
|
|
65
|
+
function usePhoneInputPalette(colorScheme = 'system', overrides) {
|
|
66
|
+
const systemScheme = (0, _reactNative.useColorScheme)();
|
|
67
|
+
const resolved = colorScheme === 'system' ? systemScheme ?? 'light' : colorScheme;
|
|
68
|
+
|
|
69
|
+
// Keyed on the overrides' contents rather than their identity, because
|
|
70
|
+
// callers naturally write `palette={{ ... }}` inline. A new object every
|
|
71
|
+
// render would give the palette a new identity every render, and the picker
|
|
72
|
+
// memoizes ~20 style objects and its whole row list on that identity —
|
|
73
|
+
// serializing a handful of color strings is far cheaper than losing those.
|
|
74
|
+
const overridesKey = overrides ? JSON.stringify(overrides) : '';
|
|
75
|
+
return (0, _react.useMemo)(() => {
|
|
76
|
+
const base = resolved === 'dark' ? DARK_PALETTE : LIGHT_PALETTE;
|
|
77
|
+
return {
|
|
78
|
+
...base,
|
|
79
|
+
...overrides
|
|
80
|
+
};
|
|
81
|
+
// `overrides` is intentionally tracked through `overridesKey`.
|
|
82
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
83
|
+
}, [resolved, overridesKey]);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_react","LIGHT_PALETTE","exports","background","inputBackground","surface","surfacePressed","border","text","textMuted","placeholder","accent","accentContrast","danger","disabled","handle","bubble","bubbleText","DARK_PALETTE","usePhoneInputPalette","colorScheme","overrides","systemScheme","useColorScheme","resolved","overridesKey","JSON","stringify","useMemo","base"],"sourceRoot":"../../src","sources":["theme.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAgCO,MAAME,aAAgC,GAAAC,OAAA,CAAAD,aAAA,GAAG;EAC9CE,UAAU,EAAE,SAAS;EACrBC,eAAe,EAAE,SAAS;EAC1BC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE,SAAS;EACzBC,MAAM,EAAE,SAAS;EACjBC,IAAI,EAAE,SAAS;EACfC,SAAS,EAAE,SAAS;EACpBC,WAAW,EAAE,SAAS;EACtBC,MAAM,EAAE,SAAS;EACjBC,cAAc,EAAE,SAAS;EACzBC,MAAM,EAAE,SAAS;EACjBC,QAAQ,EAAE,SAAS;EACnBC,MAAM,EAAE,SAAS;EACjBC,MAAM,EAAE,qBAAqB;EAC7BC,UAAU,EAAE;AACd,CAAC;AAEM,MAAMC,YAA+B,GAAAhB,OAAA,CAAAgB,YAAA,GAAG;EAC7Cf,UAAU,EAAE,SAAS;EACrBC,eAAe,EAAE,SAAS;EAC1BC,OAAO,EAAE,SAAS;EAClBC,cAAc,EAAE,SAAS;EACzBC,MAAM,EAAE,SAAS;EACjBC,IAAI,EAAE,SAAS;EACfC,SAAS,EAAE,SAAS;EACpBC,WAAW,EAAE,SAAS;EACtBC,MAAM,EAAE,SAAS;EACjBC,cAAc,EAAE,SAAS;EACzBC,MAAM,EAAE,SAAS;EACjBC,QAAQ,EAAE,SAAS;EACnBC,MAAM,EAAE,SAAS;EACjBC,MAAM,EAAE,uBAAuB;EAC/BC,UAAU,EAAE;AACd,CAAC;;AAED;AACA;AACA;AACA;AACO,SAASE,oBAAoBA,CAClCC,WAAkC,GAAG,QAAQ,EAC7CC,SAAsC,EACnB;EACnB,MAAMC,YAAY,GAAG,IAAAC,2BAAc,EAAC,CAAC;EACrC,MAAMC,QAAQ,GACZJ,WAAW,KAAK,QAAQ,GAAIE,YAAY,IAAI,OAAO,GAAIF,WAAW;;EAEpE;EACA;EACA;EACA;EACA;EACA,MAAMK,YAAY,GAAGJ,SAAS,GAAGK,IAAI,CAACC,SAAS,CAACN,SAAS,CAAC,GAAG,EAAE;EAE/D,OAAO,IAAAO,cAAO,EAAC,MAAM;IACnB,MAAMC,IAAI,GAAGL,QAAQ,KAAK,MAAM,GAAGN,YAAY,GAAGjB,aAAa;IAC/D,OAAO;MAAE,GAAG4B,IAAI;MAAE,GAAGR;IAAU,CAAC;IAChC;IACA;EACF,CAAC,EAAE,CAACG,QAAQ,EAAEC,YAAY,CAAC,CAAC;AAC9B","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildValue = buildValue;
|
|
7
|
+
exports.callingCodeFor = callingCodeFor;
|
|
8
|
+
exports.readControlledValue = readControlledValue;
|
|
9
|
+
var _libphonenumberJs = require("libphonenumber-js");
|
|
10
|
+
var _countries = require("./countries.js");
|
|
11
|
+
/**
|
|
12
|
+
* The country's true calling code ("1" for Jamaica), as opposed to the
|
|
13
|
+
* extended `dialCode` ("1876") the picker shows to tell the NANP territories
|
|
14
|
+
* apart. Concatenating the latter with a national number double-counts the
|
|
15
|
+
* area code, so every international string is built from this instead.
|
|
16
|
+
*/
|
|
17
|
+
function callingCodeFor(country) {
|
|
18
|
+
try {
|
|
19
|
+
return (0, _libphonenumberJs.getCountryCallingCode)(country.code);
|
|
20
|
+
} catch {
|
|
21
|
+
return country.dialCode;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function buildValue(nationalNumber, country) {
|
|
25
|
+
const digits = nationalNumber.replace(/\D/g, '');
|
|
26
|
+
const valid = digits.length > 0 && (0, _libphonenumberJs.isValidPhoneNumber)(digits, country.code);
|
|
27
|
+
const e164 = valid ? (0, _libphonenumberJs.parsePhoneNumberFromString)(digits, country.code)?.number ?? null : null;
|
|
28
|
+
return {
|
|
29
|
+
nationalNumber: digits,
|
|
30
|
+
country: country.code,
|
|
31
|
+
dialCode: country.dialCode,
|
|
32
|
+
e164,
|
|
33
|
+
international: digits ? `+${callingCodeFor(country)}${digits}` : '',
|
|
34
|
+
isValid: valid
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Splits a controlled `value` into the national digits and, when the value is
|
|
40
|
+
* an international string, the country it implies. `current` is kept whenever
|
|
41
|
+
* its calling code still matches, so an explicit pick among the countries
|
|
42
|
+
* sharing a calling code (Jamaica vs the US on "+1") is not undone by the
|
|
43
|
+
* next keystroke.
|
|
44
|
+
*/
|
|
45
|
+
function readControlledValue(raw, current) {
|
|
46
|
+
if (!raw.startsWith('+')) {
|
|
47
|
+
return {
|
|
48
|
+
national: raw.replace(/\D/g, ''),
|
|
49
|
+
country: current
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const formatter = new _libphonenumberJs.AsYouType();
|
|
53
|
+
formatter.input(raw);
|
|
54
|
+
const callingCode = formatter.getCallingCode();
|
|
55
|
+
const national = formatter.getNationalNumber() ?? '';
|
|
56
|
+
if (!callingCode || callingCode === callingCodeFor(current)) {
|
|
57
|
+
return {
|
|
58
|
+
national,
|
|
59
|
+
country: current
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const next = (0, _countries.getCountryByCode)(formatter.getCountry()) ?? (0, _countries.getCountryByCallingCode)(callingCode);
|
|
63
|
+
return {
|
|
64
|
+
national,
|
|
65
|
+
country: next ?? current
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_libphonenumberJs","require","_countries","callingCodeFor","country","getCountryCallingCode","code","dialCode","buildValue","nationalNumber","digits","replace","valid","length","isValidPhoneNumber","e164","parsePhoneNumberFromString","number","international","isValid","readControlledValue","raw","current","startsWith","national","formatter","AsYouType","input","callingCode","getCallingCode","getNationalNumber","next","getCountryByCode","getCountry","getCountryByCallingCode"],"sourceRoot":"../../src","sources":["value.ts"],"mappings":";;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAMA,IAAAC,UAAA,GAAAD,OAAA;AAIA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAACC,OAAgB,EAAU;EACvD,IAAI;IACF,OAAO,IAAAC,uCAAqB,EAACD,OAAO,CAACE,IAAI,CAAC;EAC5C,CAAC,CAAC,MAAM;IACN,OAAOF,OAAO,CAACG,QAAQ;EACzB;AACF;AAEO,SAASC,UAAUA,CACxBC,cAAsB,EACtBL,OAAgB,EACC;EACjB,MAAMM,MAAM,GAAGD,cAAc,CAACE,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;EAChD,MAAMC,KAAK,GAAGF,MAAM,CAACG,MAAM,GAAG,CAAC,IAAI,IAAAC,oCAAkB,EAACJ,MAAM,EAAEN,OAAO,CAACE,IAAI,CAAC;EAC3E,MAAMS,IAAI,GAAGH,KAAK,GACb,IAAAI,4CAA0B,EAACN,MAAM,EAAEN,OAAO,CAACE,IAAI,CAAC,EAAEW,MAAM,IAAI,IAAI,GACjE,IAAI;EACR,OAAO;IACLR,cAAc,EAAEC,MAAM;IACtBN,OAAO,EAAEA,OAAO,CAACE,IAAI;IACrBC,QAAQ,EAAEH,OAAO,CAACG,QAAQ;IAC1BQ,IAAI;IACJG,aAAa,EAAER,MAAM,GAAG,IAAIP,cAAc,CAACC,OAAO,CAAC,GAAGM,MAAM,EAAE,GAAG,EAAE;IACnES,OAAO,EAAEP;EACX,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASQ,mBAAmBA,CACjCC,GAAW,EACXC,OAAgB,EACwB;EACxC,IAAI,CAACD,GAAG,CAACE,UAAU,CAAC,GAAG,CAAC,EAAE;IACxB,OAAO;MAAEC,QAAQ,EAAEH,GAAG,CAACV,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;MAAEP,OAAO,EAAEkB;IAAQ,CAAC;EAC/D;EACA,MAAMG,SAAS,GAAG,IAAIC,2BAAS,CAAC,CAAC;EACjCD,SAAS,CAACE,KAAK,CAACN,GAAG,CAAC;EACpB,MAAMO,WAAW,GAAGH,SAAS,CAACI,cAAc,CAAC,CAAC;EAC9C,MAAML,QAAQ,GAAGC,SAAS,CAACK,iBAAiB,CAAC,CAAC,IAAI,EAAE;EAEpD,IAAI,CAACF,WAAW,IAAIA,WAAW,KAAKzB,cAAc,CAACmB,OAAO,CAAC,EAAE;IAC3D,OAAO;MAAEE,QAAQ;MAAEpB,OAAO,EAAEkB;IAAQ,CAAC;EACvC;EACA,MAAMS,IAAI,GACR,IAAAC,2BAAgB,EAACP,SAAS,CAACQ,UAAU,CAAC,CAAC,CAAC,IACxC,IAAAC,kCAAuB,EAACN,WAAW,CAAC;EACtC,OAAO;IAAEJ,QAAQ;IAAEpB,OAAO,EAAE2B,IAAI,IAAIT;EAAQ,CAAC;AAC/C","ignoreList":[]}
|