From 507f2502c4631c473c62a22544ace4f14c2ece39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20R=C3=A4ntil=C3=A4?= Date: Thu, 9 Dec 2021 08:46:45 +0100 Subject: [PATCH] fix(compat): replace const with var, potentially fixing old browser issues fix #71 --- lib/index.js | 6 +++--- package.json | 6 +++++- scripts/rewrite.ts | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 scripts/rewrite.ts diff --git a/lib/index.js b/lib/index.js index 7285e50..0e18190 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,7 +3,7 @@ Copyright The Closure Library Authors. SPDX-License-Identifier: Apache-2.0 */ -var aa=this||self;function h(a,b){function c(){}c.prototype=b.prototype;a.Ca=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.Ia=function(d,e,f){for(var g=Array(arguments.length-2),l=2;ld;++d){c=void 0;if(a.length{if(b.hasOwnProperty(c))return!1;b[c]=1;return!0})}V.getSupportedRegionCodes=function(){return Fb(Oa())}; +var W=["PhoneNumber$$module$src$index"],X=aa;W[0]in X||"undefined"==typeof X.execScript||X.execScript("var "+W[0]);for(var Y;W.length&&(Y=W.shift());)W.length||void 0===V?X[Y]&&X[Y]!==Object.prototype[Y]?X=X[Y]:X=X[Y]={}:X[Y]=V;function Eb(a){return M(a)?Xa(T,a):0}V.getCountryCodeForRegionCode=Eb;V.getRegionCodeForCountryCode=function(a){return R(a)};function Fb(a){var b={};return a.filter(c=>{if(b.hasOwnProperty(c))return!1;b[c]=1;return!0})}V.getSupportedRegionCodes=function(){return Fb(Oa())}; V.getSupportedCallingCodes=function(){return Fb(Qa())};V.getExample=function(a,b){var c;b?c=Ya(a,Bb(b)):c=Ya(a,0);return new V(c,a)};V.getAsYouType=function(a){return new Z(a)};V.prototype.toJSON=function(){return this.g};V.prototype.toJSON=V.prototype.toJSON;V.prototype.ia=function(){return this.g.canBeInternationallyDialled};V.prototype.canBeInternationallyDialled=V.prototype.ia;V.prototype.za=function(){return this.g.valid};V.prototype.isValid=V.prototype.za;V.prototype.ya=function(){return this.g.possible}; V.prototype.isPossible=V.prototype.ya;V.prototype.ua=function(){return this.g.type};V.prototype.getType=V.prototype.ua;V.prototype.xa=function(){return"mobile"===this.g.type||"fixed-line-or-mobile"===this.g.type};V.prototype.isMobile=V.prototype.xa;V.prototype.wa=function(){return"fixed-line"===this.g.type||"fixed-line-or-mobile"===this.g.type};V.prototype.isFixedLine=V.prototype.wa;V.prototype.qa=function(a){return this.g.number[null==a?"e164":a]};V.prototype.getNumber=V.prototype.qa; V.prototype.ra=function(a){return Wa(this.h,a)};V.prototype.getNumberFrom=V.prototype.ra;V.prototype.ta=function(){return this.g.regionCode};V.prototype.getRegionCode=V.prototype.ta;V.prototype.ha=function(){return Eb(this.g.regionCode)};V.prototype.getCountryCode=V.prototype.ha;function Z(a){this.l=a;this.j=new jb(a);this.g=this.h=""}Z.prototype.pa=function(a){this.h+=a;var b=this.j;b.ka=qb(b,a);return this.g=b.ka};Z.prototype.addChar=Z.prototype.pa;Z.prototype.Aa=function(){return this.g}; diff --git a/package.json b/package.json index ef53843..599a779 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,9 @@ "main": "./index.js", "types": "./index.d.ts", "scripts": { - "build": "node_modules/.bin/gulp", + "build:libphonenumber": "node_modules/.bin/gulp", + "build:rewrite": "ts-node scripts/rewrite.ts", + "build": "yarn build:libphonenumber && yarn build:rewrite", "test": "scripts/test.sh", "cz": "git-cz", "semantic-release": "semantic-release" @@ -41,6 +43,7 @@ "devDependencies": { "@types/mkdirp": "^1.0.1", "@types/mocha": "8.2.2", + "@types/node": "^16.11.12", "chai": "4.3.4", "commitizen": "^4.2.4", "cz-conventional-changelog": "^3.3.0", @@ -52,6 +55,7 @@ "pre-commit": "1.x", "replace": "1.2.1", "rimraf-promise": "2.x", + "ts-node": "^10.4.0", "typescript": "^4.2.4" }, "config": { diff --git a/scripts/rewrite.ts b/scripts/rewrite.ts new file mode 100644 index 0000000..c35c250 --- /dev/null +++ b/scripts/rewrite.ts @@ -0,0 +1,15 @@ + +import { promises } from 'fs' +import * as path from 'path' + +const { readFile, writeFile } = promises; + +const distFile = path.resolve( __dirname, '..', 'lib', 'index.js' ); + +async function rewrite( ) +{ + const data = await readFile( distFile, 'utf-8' ); + const res = data.replace( /\bconst /g, 'var ' ); + await writeFile( distFile, res, 'utf-8' ); +} +rewrite( );