Skip to content

Commit f3bed06

Browse files
committed
Use fetch API instead of simple-get
1 parent bec5b07 commit f3bed06

File tree

5 files changed

+18
-48
lines changed

5 files changed

+18
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Read more on `vue-form-generator`'s [instruction page](https://icebob.gitbooks.i
135135
## Highlights & Credits
136136
- Telephone Number parsing, validation by [libphonenumber-js](https://catamphetamine.github.io/libphonenumber-js/).
137137
- Country Codes data from [intl-tel-input](https://github.com/jackocnr/intl-tel-input/blob/master/src/js/data.js).
138-
- User's country by [ip2c.org](https://ip2c.org/s), request using [simple-get](https://www.npmjs.com/package/simple-get).
138+
- User's country by [ip2c.org](https://ip2c.org/s), request using [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
139139
140140
## Demo Usage
141141

package-lock.json

Lines changed: 4 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
"telephone input"
2727
],
2828
"dependencies": {
29-
"libphonenumber-js": "^1.7.18",
30-
"simple-get": "^3.0.3"
29+
"libphonenumber-js": "^1.7.18"
3130
},
3231
"devDependencies": {
3332
"babel-eslint": "^10.0.1",

src/assets/default-country.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
const get = require('simple-get');
2-
3-
const getCountry = function () {
4-
return new Promise((resolve, reject) => {
5-
get.concat('https://ip2c.org/s', (error, response, data) => {
6-
// Response: 1;CD;COD;COUNTRY
7-
if (error) {
8-
return reject(error);
9-
}
10-
const result = (data || '').toString();
1+
function getCountry() {
2+
return fetch('https://ip2c.org/s')
3+
.then(response => response.text())
4+
.then((response) => {
5+
const result = (response || '').toString();
116

127
if (!result || result[0] !== '1') {
13-
return reject(new Error('unable to fetch the country'));
8+
throw new Error('unable to fetch the country');
149
}
1510

16-
return resolve(result.substr(2, 2));
11+
return result.substr(2, 2);
1712
});
18-
});
19-
};
13+
}
2014

2115
export default getCountry;

src/vue-tel-input.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,10 @@ export default {
464464
if (!this.disabledFetchingCountry) {
465465
getCountry().then((res) => {
466466
this.activeCountry = this.findCountry(res) || this.activeCountry;
467-
}).finally(resolve);
467+
}).finally(resolve)
468+
.catch((error) => {
469+
console.warn(error);
470+
});
468471
} else {
469472
resolve();
470473
}

0 commit comments

Comments
 (0)