Open
Description
Thank you for your library! I love using it, however I'm encountering an issue when using some users of my library due to a breaking change from v7.2.0 to v7.3.0. I've boiled down the issue to this simple reproduction.
This code when run on two different minor versions outputs radically different.
import { getAsYouType } from "awesome-phonenumber";
const ayt = getAsYouType( 'SE' );
ayt.addChar( '0' ); // -> '0'
ayt.addChar( '7' ); // -> '07'
console.log('number1:', ayt.getPhoneNumber());
ayt.addChar( '0' ); // -> '070'
ayt.addChar( '7' ); // -> '070 7'
ayt.addChar( '1' ); // -> '070 71'
ayt.addChar( '2' ); // -> '070 712'
ayt.addChar( '3' ); // -> '070 712 3'
ayt.addChar( '4' ); // -> '070 712 34'
ayt.addChar( '5' ); // -> '070 712 34 5'
ayt.addChar( '6' ); // -> '070 712 34 56'
ayt.removeChar( ); // -> '070 712 34 5'
ayt.addChar( '7' ); // -> '070 712 34 57'
console.log('number2:', ayt.getPhoneNumber());
v7.2.0
number1: {
number: {
input: "",
},
regionCode: "SE",
valid: false,
possible: false,
shortPossible: false,
shortValid: false,
possibility: "unknown",
}
number2: {
number: {
input: "07",
international: "+46 07",
national: "07",
e164: "+4607",
rfc3966: "tel:+46-07",
significant: "07",
},
regionCode: "SE",
valid: false,
possible: false,
shortPossible: false,
shortValid: false,
canBeInternationallyDialled: true,
possibility: "too-short",
type: "unknown",
typeIsMobile: false,
typeIsFixedLine: false,
countryCode: 46,
}
number3: {
number: {
input: "070-712 34 57",
international: "+46 70 712 34 57",
national: "070-712 34 57",
e164: "+46707123457",
rfc3966: "tel:+46-70-712-34-57",
significant: "707123457",
},
regionCode: "SE",
valid: true,
possible: true,
shortPossible: false,
shortValid: false,
canBeInternationallyDialled: true,
possibility: "is-possible",
type: "mobile",
typeIsMobile: true,
typeIsFixedLine: false,
countryCode: 46,
}
v7.3.0
number1: {
valid: false,
possible: false,
possibility: "invalid-country-code",
regionCode: "SE",
error: 523 | function sb(a,b){a=a.toString();if(0==a.length||"0"==a.charAt(0))return 0;for(var c,d=a.length,e=1;3>=e&&e<=d;++e)if(c=parseInt(a.substring(0,e),10),c in F)return b.g(a.substring(e)),c;return 0}
524 | function tb(a,b,c,d,e){if(0==b.length)return 0;b=new z(b);var f;null!=c&&(f=p(c,11));null==f&&(f="NonMatch");var g=b.toString();if(0==g.length)f=20;else if(H.test(g))g=g.replace(H,""),A(b),b.g(Za(g)),f=1;else {g=new RegExp(f);ab(b);f=b.toString();if(0==f.search(g)){g=f.match(g)[0].length;var k=f.substring(g).match(Ma);k&&null!=k[1]&&0<k[1].length&&"0"==$a(k[1],Ha)?f=false:(A(b),b.g(f.substring(g)),f=true);}else f=false;f=f?5:20;}if(20!=f){if(2>=b.h.length)throw Error("Phone number too short after IDD");a=sb(b,
525 | d);if(0!=a)return q(e,1,a),a;throw Error("Invalid country calling code");}if(null!=c&&(f=u(c,10),g=""+f,k=b.toString(),0==k.lastIndexOf(g,0)&&(g=new z(k.substring(g.length)),k=p(c,1),k=new RegExp(u(k,2)),ub(g,c,null),g=g.toString(),!J(k,b.toString())&&J(k,g)||3==rb(a,b.toString(),c,-1))))return d.g(g),q(e,1,f),f;q(e,1,0);return 0}
526 | function ub(a,b,c){var d=a.toString(),e=d.length,f=p(b,15);if(0!=e&&null!=f&&0!=f.length){var g=new RegExp("^(?:"+f+")");if(e=g.exec(d)){f=new RegExp(u(p(b,1),2));var k=J(f,d),n=e.length-1;b=p(b,16);if(null==b||0==b.length||null==e[n]||0==e[n].length){if(!k||J(f,d.substring(e[0].length)))null!=c&&0<n&&null!=e[n]&&c.g(e[1]),a.set(d.substring(e[0].length));}else if(d=d.replace(g,b),!k||J(f,d))null!=c&&0<n&&c.g(e[1]),a.set(d);}}}
527 | function mb(a,b,c){if(null==b)throw Error("The string supplied did not seem to be a phone number");if(250<b.length)throw Error("The string supplied is too long to be a phone number");var d=new z;var e=b.indexOf(";phone-context=");if(-1===e)e=null;else if(e+=15,e>=b.length)e="";else {var f=b.indexOf(";",e);e=-1!==f?b.substring(e,f):b.substring(e);}var g=e;null==g?f=true:0===g.length?f=false:(f=Ra.exec(g),g=Sa.exec(g),f=null!==f||null!==g);if(!f)throw Error("The string supplied did not seem to be a phone number");
528 | null!=e?("+"===e.charAt(0)&&d.g(e),e=b.indexOf("tel:"),d.g(b.substring(0<=e?e+4:0,b.indexOf(";phone-context=")))):(e=d.g,b=null!=b?b:"",f=b.search(Na),0<=f?(b=b.substring(f),b=b.replace(Pa,""),f=b.search(Oa),0<=f&&(b=b.substring(0,f))):b="",e.call(d,b));b=d.toString();e=b.indexOf(";isub=");0<e&&(A(d),d.g(b.substring(0,e)));if(!Ya(d.toString()))throw Error("The string supplied did not seem to be a phone number");b=d.toString();if(!(K(c)||null!=b&&0<b.length&&H.test(b)))throw Error("Invalid country calling code");
error: The string supplied did not seem to be a phone number
at mb (/home/bjorn/Desktop/awesome-test/node_modules/awesome-phonenumber/index-esm.mjs:528:355)
at bc (/home/bjorn/Desktop/awesome-test/node_modules/awesome-phonenumber/index-esm.mjs:701:244)
at dc (/home/bjorn/Desktop/awesome-test/node_modules/awesome-phonenumber/index-esm.mjs:702:22)
at /home/bjorn/Desktop/awesome-test/index.ts:4:29
,
}
number2: [Object: null prototype] {
number: [Object: null prototype] {
input: "07",
international: [Getter],
national: [Getter],
e164: [Getter],
rfc3966: [Getter],
significant: [Getter],
},
regionCode: "SE",
valid: false,
possible: false,
possibility: [Getter],
shortValid: [Getter],
shortPossible: [Getter],
type: "unknown",
typeIsMobile: false,
typeIsFixedLine: false,
canBeInternationallyDialled: [Getter],
countryCode: [Getter],
}
number3: [Object: null prototype] {
number: [Object: null prototype] {
input: "070-712 34 57",
international: [Getter],
national: [Getter],
e164: [Getter],
rfc3966: [Getter],
significant: [Getter],
},
regionCode: "SE",
valid: true,
possible: true,
possibility: [Getter],
shortValid: [Getter],
shortPossible: [Getter],
type: "mobile",
typeIsMobile: true,
typeIsFixedLine: false,
canBeInternationallyDialled: [Getter],
countryCode: [Getter],
}
This might be related to issue #128.
Metadata
Metadata
Assignees
Labels
No labels