libphonenumber-js 1.10.51 → 1.10.53
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 +26 -23
- package/build/parseIncompletePhoneNumber.js +17 -2
- package/build/parseIncompletePhoneNumber.js.map +1 -1
- package/build/parseIncompletePhoneNumber.test.js +38 -0
- package/build/parseIncompletePhoneNumber.test.js.map +1 -1
- package/bundle/libphonenumber-js.min.js +1 -1
- package/bundle/libphonenumber-js.min.js.map +1 -1
- package/bundle/libphonenumber-max.js +1 -1
- package/bundle/libphonenumber-max.js.map +1 -1
- package/bundle/libphonenumber-min.js +1 -1
- package/bundle/libphonenumber-min.js.map +1 -1
- package/bundle/libphonenumber-mobile.js +1 -1
- package/bundle/libphonenumber-mobile.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.js +17 -2
- package/es6/parseIncompletePhoneNumber.js.map +1 -1
- package/es6/parseIncompletePhoneNumber.test.js +38 -0
- package/es6/parseIncompletePhoneNumber.test.js.map +1 -1
- package/metadata.full.json +1 -1
- package/metadata.full.json.js +1 -1
- package/metadata.max.json +1 -1
- package/metadata.max.json.js +1 -1
- package/metadata.min.json +1 -1
- package/metadata.min.json.js +1 -1
- package/metadata.mobile.json +1 -1
- package/metadata.mobile.json.js +1 -1
- package/package.json +1 -1
- package/source/parseIncompletePhoneNumber.js +16 -2
- package/source/parseIncompletePhoneNumber.test.js +45 -0
package/package.json
CHANGED
|
@@ -37,15 +37,29 @@ export default function parseIncompletePhoneNumber(string) {
|
|
|
37
37
|
* [`input-format`](https://gitlab.com/catamphetamine/input-format).
|
|
38
38
|
* @param {string} character - Yet another character from raw input string.
|
|
39
39
|
* @param {string?} prevParsedCharacters - Previous parsed characters.
|
|
40
|
-
* @param {
|
|
40
|
+
* @param {function?} emitEvent - An optional "emit event" function.
|
|
41
41
|
* @return {string?} The parsed character.
|
|
42
42
|
*/
|
|
43
|
-
export function parsePhoneNumberCharacter(character, prevParsedCharacters) {
|
|
43
|
+
export function parsePhoneNumberCharacter(character, prevParsedCharacters, emitEvent) {
|
|
44
44
|
// Only allow a leading `+`.
|
|
45
45
|
if (character === '+') {
|
|
46
46
|
// If this `+` is not the first parsed character
|
|
47
47
|
// then discard it.
|
|
48
48
|
if (prevParsedCharacters) {
|
|
49
|
+
// `emitEvent` argument was added to this `export`ed function on Dec 26th, 2023.
|
|
50
|
+
// Any 3rd-party code that used to `import` and call this function before that
|
|
51
|
+
// won't be passing any `emitEvent` argument.
|
|
52
|
+
//
|
|
53
|
+
// The addition of the `emitEvent` argument was to fix the slightly-weird behavior
|
|
54
|
+
// of parsing an input string when the user inputs something like `"2+7"
|
|
55
|
+
// https://github.com/catamphetamine/react-phone-number-input/issues/437
|
|
56
|
+
//
|
|
57
|
+
// If the parser encounters an unexpected `+` in a string being parsed
|
|
58
|
+
// then it simply discards that out-of-place `+` and any following characters.
|
|
59
|
+
//
|
|
60
|
+
if (typeof emitEvent === 'function') {
|
|
61
|
+
emitEvent('end')
|
|
62
|
+
}
|
|
49
63
|
return
|
|
50
64
|
}
|
|
51
65
|
return '+'
|
|
@@ -33,4 +33,49 @@ describe('parseIncompletePhoneNumber', () => {
|
|
|
33
33
|
// Parses non-European digits.
|
|
34
34
|
parseIncompletePhoneNumber('+٤٤٢٣٢٣٢٣٤').should.equal('+442323234')
|
|
35
35
|
})
|
|
36
|
+
|
|
37
|
+
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (international number)', () => {
|
|
38
|
+
let stopped = false
|
|
39
|
+
|
|
40
|
+
const emit = (event) => {
|
|
41
|
+
switch (event) {
|
|
42
|
+
case 'end':
|
|
43
|
+
stopped = true
|
|
44
|
+
break
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
parsePhoneNumberCharacter('+', undefined, emit).should.equal('+')
|
|
49
|
+
expect(stopped).to.equal(false)
|
|
50
|
+
|
|
51
|
+
parsePhoneNumberCharacter('1', '+', emit).should.equal('1')
|
|
52
|
+
expect(stopped).to.equal(false)
|
|
53
|
+
|
|
54
|
+
expect(parsePhoneNumberCharacter('+', '+1', emit)).to.equal(undefined)
|
|
55
|
+
expect(stopped).to.equal(true)
|
|
56
|
+
|
|
57
|
+
expect(parsePhoneNumberCharacter('2', '+1', emit)).to.equal('2')
|
|
58
|
+
expect(stopped).to.equal(true)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('should work with a new `context` argument in `parsePhoneNumberCharacter()` function (national number)', () => {
|
|
62
|
+
let stopped = false
|
|
63
|
+
|
|
64
|
+
const emit = (event) => {
|
|
65
|
+
switch (event) {
|
|
66
|
+
case 'end':
|
|
67
|
+
stopped = true
|
|
68
|
+
break
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
parsePhoneNumberCharacter('2', undefined, emit).should.equal('2')
|
|
73
|
+
expect(stopped).to.equal(false)
|
|
74
|
+
|
|
75
|
+
expect(parsePhoneNumberCharacter('+', '2', emit)).to.equal(undefined)
|
|
76
|
+
expect(stopped).to.equal(true)
|
|
77
|
+
|
|
78
|
+
expect(parsePhoneNumberCharacter('1', '2', emit)).to.equal('1')
|
|
79
|
+
expect(stopped).to.equal(true)
|
|
80
|
+
})
|
|
36
81
|
})
|