greip.js 2.0.0 → 2.1.1
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/lib/index.d.ts +6 -0
- package/lib/index.js +296 -0
- package/lib/types.d.ts +12 -0
- package/lib/types.js +2 -0
- package/lib/util.d.ts +7 -0
- package/lib/util.js +35 -0
- package/package.json +24 -4
- package/gre-geoip.js +0 -184
- package/index.js +0 -280
- package/main.js +0 -8
- package/src/util.js +0 -33
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Options } from './types';
|
|
2
|
+
export declare const GeoIP: (options: Options) => Promise<unknown>;
|
|
3
|
+
export declare const Lookup: (options: Options) => Promise<unknown>;
|
|
4
|
+
export declare const BulkLookup: (options: Options) => Promise<unknown>;
|
|
5
|
+
export declare const Country: (options: Options) => Promise<unknown>;
|
|
6
|
+
export declare const BadWord: (options: Options) => Promise<unknown>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BadWord = exports.Country = exports.BulkLookup = exports.Lookup = exports.GeoIP = void 0;
|
|
4
|
+
var util_1 = require("./util");
|
|
5
|
+
var GeoIP = function (options) {
|
|
6
|
+
if (typeof options !== 'object')
|
|
7
|
+
options = {};
|
|
8
|
+
if (!options.key || options.key.length < 1) {
|
|
9
|
+
throw new Error('You should pass the API Key.');
|
|
10
|
+
}
|
|
11
|
+
return new Promise(function (resolve, reject) {
|
|
12
|
+
var params = options.params || [];
|
|
13
|
+
var format = options.format || 'JSON';
|
|
14
|
+
var lang = options.lang || 'EN';
|
|
15
|
+
var mode = options.mode || 'live';
|
|
16
|
+
lang = lang.toUpperCase();
|
|
17
|
+
// Validate the params variable items
|
|
18
|
+
params.forEach(function (perParam) {
|
|
19
|
+
if (perParam.length > 0) {
|
|
20
|
+
if (!util_1.availableGeoIPParams.includes(perParam)) {
|
|
21
|
+
reject(new Error('The "' +
|
|
22
|
+
perParam +
|
|
23
|
+
'" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
// Validate the format variable
|
|
28
|
+
if (!util_1.availableFormats.includes(format)) {
|
|
29
|
+
reject(new Error('The `format` option value "' +
|
|
30
|
+
lang +
|
|
31
|
+
'" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
32
|
+
}
|
|
33
|
+
// Validate the lang variable
|
|
34
|
+
if (!util_1.availableLanguages.includes(lang)) {
|
|
35
|
+
reject(new Error('The `lang` option value "' +
|
|
36
|
+
lang +
|
|
37
|
+
'" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
38
|
+
}
|
|
39
|
+
// Validate the mode variable
|
|
40
|
+
if (mode !== 'live' && mode !== 'test') {
|
|
41
|
+
reject(new Error('The `mode` option value "' +
|
|
42
|
+
lang +
|
|
43
|
+
'" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
44
|
+
}
|
|
45
|
+
(0, util_1.makeHttpRquest)('GeoIP', {
|
|
46
|
+
"key": options.key,
|
|
47
|
+
"params": params.join(','),
|
|
48
|
+
"format": format,
|
|
49
|
+
"lang": lang,
|
|
50
|
+
"mode": mode,
|
|
51
|
+
}, function (res) {
|
|
52
|
+
if (typeof res !== 'object')
|
|
53
|
+
res = JSON.parse(res);
|
|
54
|
+
resolve(res);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.GeoIP = GeoIP;
|
|
59
|
+
var Lookup = function (options) {
|
|
60
|
+
if (typeof options !== 'object')
|
|
61
|
+
options = {};
|
|
62
|
+
if (!options.key || options.key.length < 1) {
|
|
63
|
+
throw new Error('You should pass the API Key.');
|
|
64
|
+
}
|
|
65
|
+
return new Promise(function (resolve, reject) {
|
|
66
|
+
var ip = options.ip || '';
|
|
67
|
+
var params = options.params || [];
|
|
68
|
+
var format = options.format || 'JSON';
|
|
69
|
+
var lang = options.lang || 'EN';
|
|
70
|
+
var mode = options.mode || 'live';
|
|
71
|
+
lang = lang.toUpperCase();
|
|
72
|
+
// Validate the ip variable
|
|
73
|
+
if (ip.length < 7) {
|
|
74
|
+
reject(new Error('You should pass the `ip` parameter.'));
|
|
75
|
+
}
|
|
76
|
+
// Validate the params variable items
|
|
77
|
+
params.forEach(function (perParam) {
|
|
78
|
+
if (perParam.length > 0) {
|
|
79
|
+
if (!util_1.availableGeoIPParams.includes(perParam)) {
|
|
80
|
+
reject(new Error('The "' +
|
|
81
|
+
perParam +
|
|
82
|
+
'" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Validate the format variable
|
|
87
|
+
if (!util_1.availableFormats.includes(format)) {
|
|
88
|
+
reject(new Error('The `format` option value "' +
|
|
89
|
+
lang +
|
|
90
|
+
'" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
91
|
+
}
|
|
92
|
+
// Validate the lang variable
|
|
93
|
+
if (!util_1.availableLanguages.includes(lang)) {
|
|
94
|
+
reject(new Error('The `lang` option value "' +
|
|
95
|
+
lang +
|
|
96
|
+
'" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
97
|
+
}
|
|
98
|
+
// Validate the mode variable
|
|
99
|
+
if (mode !== 'live' && mode !== 'test') {
|
|
100
|
+
reject(new Error('The `mode` option value "' +
|
|
101
|
+
lang +
|
|
102
|
+
'" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
103
|
+
}
|
|
104
|
+
(0, util_1.makeHttpRquest)('IPLookup', {
|
|
105
|
+
"ip": ip,
|
|
106
|
+
"key": options.key,
|
|
107
|
+
"params": params.join(','),
|
|
108
|
+
"format": format,
|
|
109
|
+
"lang": lang,
|
|
110
|
+
"mode": mode,
|
|
111
|
+
}, function (res) {
|
|
112
|
+
if (typeof res !== 'object')
|
|
113
|
+
res = JSON.parse(res);
|
|
114
|
+
resolve(res);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
exports.Lookup = Lookup;
|
|
119
|
+
var BulkLookup = function (options) {
|
|
120
|
+
if (typeof options !== 'object')
|
|
121
|
+
options = {};
|
|
122
|
+
if (!options.key || options.key.length < 1) {
|
|
123
|
+
throw new Error('You should pass the API Key.');
|
|
124
|
+
}
|
|
125
|
+
return new Promise(function (resolve, reject) {
|
|
126
|
+
var ips = options.ips || [];
|
|
127
|
+
var params = options.params || [];
|
|
128
|
+
var format = options.format || 'JSON';
|
|
129
|
+
var lang = options.lang || 'EN';
|
|
130
|
+
var mode = options.mode || 'live';
|
|
131
|
+
lang = lang.toUpperCase();
|
|
132
|
+
if (typeof ips !== 'object')
|
|
133
|
+
ips = [];
|
|
134
|
+
// Validate the ip variable
|
|
135
|
+
if (ips.length < 1) {
|
|
136
|
+
reject(new Error('You should pass the `ips` parameter.'));
|
|
137
|
+
}
|
|
138
|
+
ips.forEach(function (perParam) {
|
|
139
|
+
if (perParam.length < 7) {
|
|
140
|
+
reject(new Error('You should pass a valid IP Addresses in the `ips` parameter.'));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// Validate the params variable items
|
|
144
|
+
params.forEach(function (perParam) {
|
|
145
|
+
if (perParam.length > 0) {
|
|
146
|
+
if (!util_1.availableGeoIPParams.includes(perParam)) {
|
|
147
|
+
reject(new Error('The "' +
|
|
148
|
+
perParam +
|
|
149
|
+
'" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
// Validate the format variable
|
|
154
|
+
if (!util_1.availableFormats.includes(format)) {
|
|
155
|
+
reject(new Error('The `format` option value "' +
|
|
156
|
+
lang +
|
|
157
|
+
'" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
158
|
+
}
|
|
159
|
+
// Validate the lang variable
|
|
160
|
+
if (!util_1.availableLanguages.includes(lang)) {
|
|
161
|
+
reject(new Error('The `lang` option value "' +
|
|
162
|
+
lang +
|
|
163
|
+
'" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
164
|
+
}
|
|
165
|
+
// Validate the mode variable
|
|
166
|
+
if (mode !== 'live' && mode !== 'test') {
|
|
167
|
+
reject(new Error('The `mode` option value "' +
|
|
168
|
+
lang +
|
|
169
|
+
'" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
170
|
+
}
|
|
171
|
+
(0, util_1.makeHttpRquest)('BulkLookup', {
|
|
172
|
+
"ips": ips,
|
|
173
|
+
"key": options.key,
|
|
174
|
+
"params": params.join(','),
|
|
175
|
+
"format": format,
|
|
176
|
+
"lang": lang,
|
|
177
|
+
"mode": mode,
|
|
178
|
+
}, function (res) {
|
|
179
|
+
if (typeof res !== 'object')
|
|
180
|
+
res = JSON.parse(res);
|
|
181
|
+
resolve(res);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
exports.BulkLookup = BulkLookup;
|
|
186
|
+
var Country = function (options) {
|
|
187
|
+
if (typeof options !== 'object')
|
|
188
|
+
options = {};
|
|
189
|
+
if (!options.key || options.key.length < 1) {
|
|
190
|
+
throw new Error('You should pass the API Key.');
|
|
191
|
+
}
|
|
192
|
+
return new Promise(function (resolve, reject) {
|
|
193
|
+
var countryCode = options.countryCode || '';
|
|
194
|
+
var params = options.params || [];
|
|
195
|
+
var format = options.format || 'JSON';
|
|
196
|
+
var lang = options.lang || 'EN';
|
|
197
|
+
var mode = options.mode || 'live';
|
|
198
|
+
countryCode = countryCode.toUpperCase();
|
|
199
|
+
lang = lang.toUpperCase();
|
|
200
|
+
// Validate the countryCode variable
|
|
201
|
+
if (countryCode.length !== 2) {
|
|
202
|
+
reject(new Error('You should pass the `countryCode` parameter. Also, it should be a `ISO 3166-1 alpha-2` format.\nRead more at: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2'));
|
|
203
|
+
}
|
|
204
|
+
// Validate the params variable items
|
|
205
|
+
params.forEach(function (perParam) {
|
|
206
|
+
if (perParam.length > 0) {
|
|
207
|
+
if (!util_1.availableCountryParams.includes(perParam)) {
|
|
208
|
+
reject(new Error('The "' +
|
|
209
|
+
perParam +
|
|
210
|
+
'" module you used is unknown.\nYou can use: `language`, `flag`, `currency` and/or `timezone`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
// Validate the format variable
|
|
215
|
+
if (!util_1.availableFormats.includes(format)) {
|
|
216
|
+
reject(new Error('The `format` option value "' +
|
|
217
|
+
lang +
|
|
218
|
+
'" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
219
|
+
}
|
|
220
|
+
// Validate the lang variable
|
|
221
|
+
if (!util_1.availableLanguages.includes(lang)) {
|
|
222
|
+
reject(new Error('The `lang` option value "' +
|
|
223
|
+
lang +
|
|
224
|
+
'" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
225
|
+
}
|
|
226
|
+
// Validate the mode variable
|
|
227
|
+
if (mode !== 'live' && mode !== 'test') {
|
|
228
|
+
reject(new Error('The `mode` option value "' +
|
|
229
|
+
lang +
|
|
230
|
+
'" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
231
|
+
}
|
|
232
|
+
(0, util_1.makeHttpRquest)('Country', {
|
|
233
|
+
"CountryCode": countryCode,
|
|
234
|
+
"key": options.key,
|
|
235
|
+
"params": params.join(','),
|
|
236
|
+
"format": format,
|
|
237
|
+
"lang": lang,
|
|
238
|
+
"mode": mode,
|
|
239
|
+
}, function (res) {
|
|
240
|
+
if (typeof res !== 'object')
|
|
241
|
+
res = JSON.parse(res);
|
|
242
|
+
resolve(res);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
};
|
|
246
|
+
exports.Country = Country;
|
|
247
|
+
var BadWord = function (options) {
|
|
248
|
+
if (typeof options !== 'object')
|
|
249
|
+
options = {};
|
|
250
|
+
if (!options.key || options.key.length < 1) {
|
|
251
|
+
throw new Error('You should pass the API Key.');
|
|
252
|
+
}
|
|
253
|
+
return new Promise(function (resolve, reject) {
|
|
254
|
+
var text = options.text || '';
|
|
255
|
+
var params = options.params || [];
|
|
256
|
+
var format = options.format || 'JSON';
|
|
257
|
+
var lang = options.lang || 'EN';
|
|
258
|
+
var mode = options.mode || 'live';
|
|
259
|
+
lang = lang.toUpperCase();
|
|
260
|
+
// Validate the text variable
|
|
261
|
+
if (text.length < 1) {
|
|
262
|
+
reject(new Error('You should pass the `text` parameter.'));
|
|
263
|
+
}
|
|
264
|
+
// Validate the format variable
|
|
265
|
+
if (!util_1.availableFormats.includes(format)) {
|
|
266
|
+
reject(new Error('The `format` option value "' +
|
|
267
|
+
lang +
|
|
268
|
+
'" you specified is unknown.\nYou can use: `JSON`, `XML` or `CSV`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
269
|
+
}
|
|
270
|
+
// Validate the lang variable
|
|
271
|
+
if (!util_1.availableLanguages.includes(lang)) {
|
|
272
|
+
reject(new Error('The `lang` option value "' +
|
|
273
|
+
lang +
|
|
274
|
+
'" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
275
|
+
}
|
|
276
|
+
// Validate the mode variable
|
|
277
|
+
if (mode !== 'live' && mode !== 'test') {
|
|
278
|
+
reject(new Error('The `mode` option value "' +
|
|
279
|
+
lang +
|
|
280
|
+
'" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
281
|
+
}
|
|
282
|
+
(0, util_1.makeHttpRquest)('badWords', {
|
|
283
|
+
"text": text,
|
|
284
|
+
"key": options.key,
|
|
285
|
+
"params": params.join(','),
|
|
286
|
+
"format": format,
|
|
287
|
+
"lang": lang,
|
|
288
|
+
"mode": mode,
|
|
289
|
+
}, function (res) {
|
|
290
|
+
if (typeof res !== 'object')
|
|
291
|
+
res = JSON.parse(res);
|
|
292
|
+
resolve(res);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
};
|
|
296
|
+
exports.BadWord = BadWord;
|
package/lib/types.d.ts
ADDED
package/lib/types.js
ADDED
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const baseURL = "https://gregeoip.com/";
|
|
2
|
+
export declare const availableGeoIPParams: string[];
|
|
3
|
+
export declare const availableLanguages: string[];
|
|
4
|
+
export declare const availableFormats: string[];
|
|
5
|
+
export declare const availableCountryParams: string[];
|
|
6
|
+
export declare const serialize: (obj: any) => string;
|
|
7
|
+
export declare const makeHttpRquest: (endpoint: string, options: any, callback: (data: object) => void) => void;
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeHttpRquest = exports.serialize = exports.availableCountryParams = exports.availableFormats = exports.availableLanguages = exports.availableGeoIPParams = exports.baseURL = void 0;
|
|
4
|
+
var axios_1 = require("axios");
|
|
5
|
+
exports.baseURL = 'https://gregeoip.com/';
|
|
6
|
+
exports.availableGeoIPParams = ['location', 'security', 'timezone', 'currency', 'device'];
|
|
7
|
+
exports.availableLanguages = ['EN', 'AR', 'DE', 'FR', 'ES', 'JA', 'ZH', 'RU'];
|
|
8
|
+
exports.availableFormats = ['JSON', 'XML', 'CSV', 'Newline'];
|
|
9
|
+
exports.availableCountryParams = ['language', 'flag', 'currency', 'timezone'];
|
|
10
|
+
var serialize = function (obj) {
|
|
11
|
+
var str = [];
|
|
12
|
+
for (var p in obj)
|
|
13
|
+
if (obj.hasOwnProperty(p)) {
|
|
14
|
+
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
15
|
+
}
|
|
16
|
+
return str.join('&');
|
|
17
|
+
};
|
|
18
|
+
exports.serialize = serialize;
|
|
19
|
+
var makeHttpRquest = function (endpoint, options, callback) {
|
|
20
|
+
options.source = 'JS-Package';
|
|
21
|
+
axios_1.default
|
|
22
|
+
.get(exports.baseURL + '/' + endpoint + '?' + (0, exports.serialize)(options))
|
|
23
|
+
.then(function (response) {
|
|
24
|
+
if (response.status === 200) {
|
|
25
|
+
callback(response.data);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('An unknown error occurred while sending the request to GRE GeoIP API.');
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
.catch(function (error) {
|
|
32
|
+
throw new Error('An unknown error occurred while sending the request to GRE GeoIP API.');
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.makeHttpRquest = makeHttpRquest;
|
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "greip.js",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "The official JS library of Greip.",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"author": {
|
|
7
6
|
"name": "GRE Development Ltd.",
|
|
8
7
|
"email": "info@greip.io",
|
|
9
8
|
"url": "https://greip.io"
|
|
10
9
|
},
|
|
11
10
|
"license": "MIT",
|
|
12
|
-
"main": "index.
|
|
11
|
+
"main": "lib/index.d.ts",
|
|
12
|
+
"types": "lib/index.d.ts",
|
|
13
13
|
"keywords": [
|
|
14
14
|
"ip",
|
|
15
15
|
"api",
|
|
16
16
|
"geolocation",
|
|
17
17
|
"geoip"
|
|
18
18
|
],
|
|
19
|
+
"files": [
|
|
20
|
+
"lib/**/*"
|
|
21
|
+
],
|
|
19
22
|
"homepage": "https://github.com/gre-dev/Greip-JS#readme",
|
|
20
23
|
"bugs": {
|
|
21
24
|
"url": "https://github.com/gre-dev/Greip-JS/issues",
|
|
@@ -26,7 +29,15 @@
|
|
|
26
29
|
"url": "https://www.patreon.com/gredev"
|
|
27
30
|
},
|
|
28
31
|
"scripts": {
|
|
29
|
-
"test": "
|
|
32
|
+
"test": "jest --config jestconfig.json",
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
|
|
35
|
+
"lint": "tslint -p tsconfig.json",
|
|
36
|
+
"prepare" : "npm run build",
|
|
37
|
+
"prepublishOnly" : "npm test && npm run lint",
|
|
38
|
+
"preversion" : "npm run lint",
|
|
39
|
+
"version" : "npm run format && git add -A src",
|
|
40
|
+
"postversion" : "git push && git push --tags"
|
|
30
41
|
},
|
|
31
42
|
"repository": {
|
|
32
43
|
"type": "git",
|
|
@@ -34,5 +45,14 @@
|
|
|
34
45
|
},
|
|
35
46
|
"dependencies": {
|
|
36
47
|
"axios": "^0.25.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/jest": "^29.2.4",
|
|
51
|
+
"jest": "^29.3.1",
|
|
52
|
+
"prettier": "^2.8.1",
|
|
53
|
+
"ts-jest": "^29.0.3",
|
|
54
|
+
"tslint": "^6.1.3",
|
|
55
|
+
"tslint-config-prettier": "^1.18.0",
|
|
56
|
+
"typescript": "^4.9.3"
|
|
37
57
|
}
|
|
38
58
|
}
|
package/gre-geoip.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
class GREGeoIP {
|
|
2
|
-
#key;
|
|
3
|
-
#baseURL = 'https://gregeoip.com/';
|
|
4
|
-
#availableGeoIPParams = ['location', 'security', 'timezone', 'currency', 'device'];
|
|
5
|
-
#availableLanguages = ['EN', 'AR', 'DE', 'FR', 'ES', 'JA', 'ZH', 'RU'];
|
|
6
|
-
#availableFormats = ['JSON', 'XML', 'CSV', 'Newline'];
|
|
7
|
-
#availableCountryParams = ['language', 'flag', 'currency', 'timezone'];
|
|
8
|
-
|
|
9
|
-
constructor(key) {
|
|
10
|
-
if (key && key.length > 0){
|
|
11
|
-
this.#key = key;
|
|
12
|
-
}else{
|
|
13
|
-
throw new Error('You should pass the API Key.');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
#serialize = function (obj) {
|
|
18
|
-
var str = [];
|
|
19
|
-
for (var p in obj)
|
|
20
|
-
if (obj.hasOwnProperty(p)) {
|
|
21
|
-
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
22
|
-
}
|
|
23
|
-
return str.join('&');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#makeHttpRquest(endpoint, options, callback) {
|
|
27
|
-
options.source = 'JS-Package';
|
|
28
|
-
let xmlHttp = new XMLHttpRequest();
|
|
29
|
-
xmlHttp.onreadystatechange = function () {
|
|
30
|
-
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
|
|
31
|
-
callback(xmlHttp.responseText);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
xmlHttp.open('GET', this.#baseURL + '/' + endpoint + '?' + this.#serialize(options), true); // true for asynchronous
|
|
35
|
-
xmlHttp.send(null);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
geoip(options = {}) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
let params = options.params || [];
|
|
41
|
-
let format = options.format || 'JSON';
|
|
42
|
-
let lang = options.lang || 'EN';
|
|
43
|
-
let mode = options.mode || 'live';
|
|
44
|
-
lang = lang.toUpperCase();
|
|
45
|
-
|
|
46
|
-
// Validate the params variable items
|
|
47
|
-
params.forEach(perParam => {
|
|
48
|
-
if (perParam.length > 0) {
|
|
49
|
-
if (!this.#availableGeoIPParams.includes(perParam)) {
|
|
50
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// Validate the format variable
|
|
56
|
-
if (!this.#availableFormats.includes(format)) {
|
|
57
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Validate the lang variable
|
|
61
|
-
if (!this.#availableLanguages.includes(lang)) {
|
|
62
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Validate the mode variable
|
|
66
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
67
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
68
|
-
}
|
|
69
|
-
this.#makeHttpRquest('GeoIP', {
|
|
70
|
-
'key': this.#key,
|
|
71
|
-
'params': params.join(','),
|
|
72
|
-
'format': format,
|
|
73
|
-
'lang': lang,
|
|
74
|
-
'mode': mode
|
|
75
|
-
}, (res) => {
|
|
76
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
77
|
-
resolve(res);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
lookup(options = {}) {
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
let ip = options.ip || '';
|
|
85
|
-
let params = options.params || [];
|
|
86
|
-
let format = options.format || 'JSON';
|
|
87
|
-
let lang = options.lang || 'EN';
|
|
88
|
-
let mode = options.mode || 'live';
|
|
89
|
-
lang = lang.toUpperCase();
|
|
90
|
-
|
|
91
|
-
// Validate the ip variable
|
|
92
|
-
if (ip.length < 7){
|
|
93
|
-
reject(new Error('You should pass the `ip` parameter.'))
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Validate the params variable items
|
|
97
|
-
params.forEach(perParam => {
|
|
98
|
-
if (perParam.length > 0) {
|
|
99
|
-
if (!this.#availableGeoIPParams.includes(perParam)) {
|
|
100
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// Validate the format variable
|
|
106
|
-
if (!this.#availableFormats.includes(format)) {
|
|
107
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Validate the lang variable
|
|
111
|
-
if (!this.#availableLanguages.includes(lang)) {
|
|
112
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Validate the mode variable
|
|
116
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
117
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
118
|
-
}
|
|
119
|
-
this.#makeHttpRquest('IPLookup', {
|
|
120
|
-
'ip': ip,
|
|
121
|
-
'key': this.#key,
|
|
122
|
-
'params': params.join(','),
|
|
123
|
-
'format': format,
|
|
124
|
-
'lang': lang,
|
|
125
|
-
'mode': mode
|
|
126
|
-
}, (res) => {
|
|
127
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
128
|
-
resolve(res);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
country(options = {}) {
|
|
134
|
-
return new Promise((resolve, reject) => {
|
|
135
|
-
let countryCode = options.countryCode || '';
|
|
136
|
-
let params = options.params || [];
|
|
137
|
-
let format = options.format || 'JSON';
|
|
138
|
-
let lang = options.lang || 'EN';
|
|
139
|
-
let mode = options.mode || 'live';
|
|
140
|
-
countryCode = countryCode.toUpperCase();
|
|
141
|
-
lang = lang.toUpperCase();
|
|
142
|
-
|
|
143
|
-
// Validate the countryCode variable
|
|
144
|
-
if (countryCode.length !== 2){
|
|
145
|
-
reject(new Error('You should pass the `countryCode` parameter. Also, it should be a `ISO 3166-1 alpha-2` format.\nRead more at: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2'));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// Validate the params variable items
|
|
149
|
-
params.forEach(perParam => {
|
|
150
|
-
if (perParam.length > 0) {
|
|
151
|
-
if (!this.#availableCountryParams.includes(perParam)) {
|
|
152
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `language`, `flag`, `currency` and/or `timezone`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Validate the format variable
|
|
158
|
-
if (!this.#availableFormats.includes(format)) {
|
|
159
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Validate the lang variable
|
|
163
|
-
if (!this.#availableLanguages.includes(lang)) {
|
|
164
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Validate the mode variable
|
|
168
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
169
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
170
|
-
}
|
|
171
|
-
this.#makeHttpRquest('Country', {
|
|
172
|
-
'CountryCode': countryCode,
|
|
173
|
-
'key': this.#key,
|
|
174
|
-
'params': params.join(','),
|
|
175
|
-
'format': format,
|
|
176
|
-
'lang': lang,
|
|
177
|
-
'mode': mode
|
|
178
|
-
}, (res) => {
|
|
179
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
180
|
-
resolve(res);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
package/index.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { availableGeoIPParams, availableLanguages, availableFormats, availableCountryParams, makeHttpRquest } from "./src/util.js";
|
|
2
|
-
|
|
3
|
-
export function GeoIP(options) {
|
|
4
|
-
if (typeof options !== "object") options = {};
|
|
5
|
-
|
|
6
|
-
if (!options.key || options.key.length < 1) {
|
|
7
|
-
throw new Error('You should pass the API Key.');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
let params = options.params || [];
|
|
12
|
-
let format = options.format || 'JSON';
|
|
13
|
-
let lang = options.lang || 'EN';
|
|
14
|
-
let mode = options.mode || 'live';
|
|
15
|
-
lang = lang.toUpperCase();
|
|
16
|
-
|
|
17
|
-
// Validate the params variable items
|
|
18
|
-
params.forEach(perParam => {
|
|
19
|
-
if (perParam.length > 0) {
|
|
20
|
-
if (!availableGeoIPParams.includes(perParam)) {
|
|
21
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
// Validate the format variable
|
|
27
|
-
if (!availableFormats.includes(format)) {
|
|
28
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Validate the lang variable
|
|
32
|
-
if (!availableLanguages.includes(lang)) {
|
|
33
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Validate the mode variable
|
|
37
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
38
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/geoip-method#options'));
|
|
39
|
-
}
|
|
40
|
-
makeHttpRquest('GeoIP', {
|
|
41
|
-
'key': options.key,
|
|
42
|
-
'params': params.join(','),
|
|
43
|
-
'format': format,
|
|
44
|
-
'lang': lang,
|
|
45
|
-
'mode': mode
|
|
46
|
-
}, (res) => {
|
|
47
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
48
|
-
resolve(res);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function Lookup(options) {
|
|
54
|
-
if (typeof options !== "object") options = {};
|
|
55
|
-
|
|
56
|
-
if (!options.key || options.key.length < 1) {
|
|
57
|
-
throw new Error('You should pass the API Key.');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return new Promise((resolve, reject) => {
|
|
61
|
-
let ip = options.ip || '';
|
|
62
|
-
let params = options.params || [];
|
|
63
|
-
let format = options.format || 'JSON';
|
|
64
|
-
let lang = options.lang || 'EN';
|
|
65
|
-
let mode = options.mode || 'live';
|
|
66
|
-
lang = lang.toUpperCase();
|
|
67
|
-
|
|
68
|
-
// Validate the ip variable
|
|
69
|
-
if (ip.length < 7) {
|
|
70
|
-
reject(new Error('You should pass the `ip` parameter.'))
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Validate the params variable items
|
|
74
|
-
params.forEach(perParam => {
|
|
75
|
-
if (perParam.length > 0) {
|
|
76
|
-
if (!availableGeoIPParams.includes(perParam)) {
|
|
77
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Validate the format variable
|
|
83
|
-
if (!availableFormats.includes(format)) {
|
|
84
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Validate the lang variable
|
|
88
|
-
if (!availableLanguages.includes(lang)) {
|
|
89
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Validate the mode variable
|
|
93
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
94
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
95
|
-
}
|
|
96
|
-
makeHttpRquest('IPLookup', {
|
|
97
|
-
'ip': ip,
|
|
98
|
-
'key': options.key,
|
|
99
|
-
'params': params.join(','),
|
|
100
|
-
'format': format,
|
|
101
|
-
'lang': lang,
|
|
102
|
-
'mode': mode
|
|
103
|
-
}, (res) => {
|
|
104
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
105
|
-
resolve(res);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function BulkLookup(options) {
|
|
111
|
-
if (typeof options !== "object") options = {};
|
|
112
|
-
|
|
113
|
-
if (!options.key || options.key.length < 1) {
|
|
114
|
-
throw new Error('You should pass the API Key.');
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return new Promise((resolve, reject) => {
|
|
118
|
-
let ips = options.ips || [];
|
|
119
|
-
let params = options.params || [];
|
|
120
|
-
let format = options.format || 'JSON';
|
|
121
|
-
let lang = options.lang || 'EN';
|
|
122
|
-
let mode = options.mode || 'live';
|
|
123
|
-
lang = lang.toUpperCase();
|
|
124
|
-
|
|
125
|
-
if (typeof ips !== "object") ips = [];
|
|
126
|
-
|
|
127
|
-
// Validate the ip variable
|
|
128
|
-
if (ips.length < 1) {
|
|
129
|
-
reject(new Error('You should pass the `ips` parameter.'))
|
|
130
|
-
}
|
|
131
|
-
ips.forEach(perParam => {
|
|
132
|
-
if (perParam.length < 7) {
|
|
133
|
-
reject(new Error('You should pass a valid IP Addresses in the `ips` parameter.'))
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Validate the params variable items
|
|
138
|
-
params.forEach(perParam => {
|
|
139
|
-
if (perParam.length > 0) {
|
|
140
|
-
if (!availableGeoIPParams.includes(perParam)) {
|
|
141
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `location`, `security`, `timezone`, `currency` and/or `device`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
// Validate the format variable
|
|
147
|
-
if (!availableFormats.includes(format)) {
|
|
148
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Validate the lang variable
|
|
152
|
-
if (!availableLanguages.includes(lang)) {
|
|
153
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// Validate the mode variable
|
|
157
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
158
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/lookup-method#options'));
|
|
159
|
-
}
|
|
160
|
-
makeHttpRquest('BulkLookup', {
|
|
161
|
-
'ips': ips,
|
|
162
|
-
'key': options.key,
|
|
163
|
-
'params': params.join(','),
|
|
164
|
-
'format': format,
|
|
165
|
-
'lang': lang,
|
|
166
|
-
'mode': mode
|
|
167
|
-
}, (res) => {
|
|
168
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
169
|
-
resolve(res);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function Country(options) {
|
|
175
|
-
if (typeof options !== "object") options = {};
|
|
176
|
-
|
|
177
|
-
if (!options.key || options.key.length < 1) {
|
|
178
|
-
throw new Error('You should pass the API Key.');
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return new Promise((resolve, reject) => {
|
|
182
|
-
var countryCode = options.countryCode || '';
|
|
183
|
-
var params = options.params || [];
|
|
184
|
-
var format = options.format || 'JSON';
|
|
185
|
-
var lang = options.lang || 'EN';
|
|
186
|
-
var mode = options.mode || 'live';
|
|
187
|
-
|
|
188
|
-
countryCode = countryCode.toUpperCase();
|
|
189
|
-
lang = lang.toUpperCase();
|
|
190
|
-
|
|
191
|
-
// Validate the countryCode variable
|
|
192
|
-
if (countryCode.length !== 2) {
|
|
193
|
-
reject(new Error('You should pass the `countryCode` parameter. Also, it should be a `ISO 3166-1 alpha-2` format.\nRead more at: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2'));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Validate the params variable items
|
|
197
|
-
params.forEach(perParam => {
|
|
198
|
-
if (perParam.length > 0) {
|
|
199
|
-
if (!availableCountryParams.includes(perParam)) {
|
|
200
|
-
reject(new Error('The "' + perParam + '" module you used is unknown.\nYou can use: `language`, `flag`, `currency` and/or `timezone`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
// Validate the format variable
|
|
206
|
-
if (!availableFormats.includes(format)) {
|
|
207
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML`, `CSV` or `Newline`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Validate the lang variable
|
|
211
|
-
if (!availableLanguages.includes(lang)) {
|
|
212
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Validate the mode variable
|
|
216
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
217
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
218
|
-
}
|
|
219
|
-
makeHttpRquest('Country', {
|
|
220
|
-
'CountryCode': countryCode,
|
|
221
|
-
'key': options.key,
|
|
222
|
-
'params': params.join(','),
|
|
223
|
-
'format': format,
|
|
224
|
-
'lang': lang,
|
|
225
|
-
'mode': mode
|
|
226
|
-
}, (res) => {
|
|
227
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
228
|
-
resolve(res);
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export function BadWord(options) {
|
|
234
|
-
if (typeof options !== "object") options = {};
|
|
235
|
-
|
|
236
|
-
if (!options.key || options.key.length < 1) {
|
|
237
|
-
throw new Error('You should pass the API Key.');
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return new Promise((resolve, reject) => {
|
|
241
|
-
var text = options.text || '';
|
|
242
|
-
var params = options.params || [];
|
|
243
|
-
var format = options.format || 'JSON';
|
|
244
|
-
var lang = options.lang || 'EN';
|
|
245
|
-
var mode = options.mode || 'live';
|
|
246
|
-
|
|
247
|
-
lang = lang.toUpperCase();
|
|
248
|
-
|
|
249
|
-
// Validate the text variable
|
|
250
|
-
if (text.length < 1) {
|
|
251
|
-
reject(new Error('You should pass the `text` parameter.'));
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Validate the format variable
|
|
255
|
-
if (!availableFormats.includes(format)) {
|
|
256
|
-
reject(new Error('The `format` option value "' + lang + '" you specified is unknown.\nYou can use: `JSON`, `XML` or `CSV`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Validate the lang variable
|
|
260
|
-
if (!availableLanguages.includes(lang)) {
|
|
261
|
-
reject(new Error('The `lang` option value "' + lang + '" you specified is unknown.\nYou can use: `EN`, `AR`, `DE`, `FR`, `ES`, `JA`, `ZH` or `RU`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Validate the mode variable
|
|
265
|
-
if (mode !== 'live' && mode !== 'test') {
|
|
266
|
-
reject(new Error('The `mode` option value "' + lang + '" you specified is unknown.\nYou can use: `live` or `test`.\nRead more at: https://geoip-docs.gredev.io/sdks/js/country-method#options'));
|
|
267
|
-
}
|
|
268
|
-
makeHttpRquest('badWords', {
|
|
269
|
-
'text': text,
|
|
270
|
-
'key': options.key,
|
|
271
|
-
'params': params.join(','),
|
|
272
|
-
'format': format,
|
|
273
|
-
'lang': lang,
|
|
274
|
-
'mode': mode
|
|
275
|
-
}, (res) => {
|
|
276
|
-
if (typeof res !== 'object') res = JSON.parse(res);
|
|
277
|
-
resolve(res);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
}
|
package/main.js
DELETED
package/src/util.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
|
-
|
|
3
|
-
export const baseURL = "https://gregeoip.com/";
|
|
4
|
-
export const availableGeoIPParams = ['location', 'security', 'timezone', 'currency', 'device'];
|
|
5
|
-
export const availableLanguages = ['EN', 'AR', 'DE', 'FR', 'ES', 'JA', 'ZH', 'RU'];
|
|
6
|
-
export const availableFormats = ['JSON', 'XML', 'CSV', 'Newline'];
|
|
7
|
-
export const availableCountryParams = ['language', 'flag', 'currency', 'timezone'];
|
|
8
|
-
|
|
9
|
-
export function serialize(obj) {
|
|
10
|
-
var str = [];
|
|
11
|
-
for (var p in obj)
|
|
12
|
-
if (obj.hasOwnProperty(p)) {
|
|
13
|
-
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
|
|
14
|
-
}
|
|
15
|
-
return str.join('&');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function makeHttpRquest(endpoint, options, callback) {
|
|
19
|
-
options.source = 'JS-Package';
|
|
20
|
-
|
|
21
|
-
axios.get(baseURL + '/' + endpoint + '?' + serialize(options))
|
|
22
|
-
.then(function (response) {
|
|
23
|
-
if (response.status === 200) {
|
|
24
|
-
callback(response.data);
|
|
25
|
-
} else {
|
|
26
|
-
throw new Error('An unknown error occurred while sending the request to GRE GeoIP API.');
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
.catch(function (error) {
|
|
30
|
-
console.error(error);
|
|
31
|
-
throw new Error('An unknown error occurred while sending the request to GRE GeoIP API.');
|
|
32
|
-
});
|
|
33
|
-
}
|