@roniemartinez/iptocc 1.0.0-alpha.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.
Files changed (43) hide show
  1. package/README.md +40 -0
  2. package/cli.cjs +31 -0
  3. package/package.json +69 -0
  4. package/pkg-bundler/LICENSE-APACHE +202 -0
  5. package/pkg-bundler/LICENSE-MIT +21 -0
  6. package/pkg-bundler/README.md +40 -0
  7. package/pkg-bundler/iptocc_wasm.d.ts +11 -0
  8. package/pkg-bundler/iptocc_wasm.js +9 -0
  9. package/pkg-bundler/iptocc_wasm_bg.js +170 -0
  10. package/pkg-bundler/iptocc_wasm_bg.wasm +0 -0
  11. package/pkg-bundler/iptocc_wasm_bg.wasm.d.ts +9 -0
  12. package/pkg-bundler/package.json +26 -0
  13. package/pkg-deno/LICENSE-APACHE +202 -0
  14. package/pkg-deno/LICENSE-MIT +21 -0
  15. package/pkg-deno/README.md +40 -0
  16. package/pkg-deno/iptocc_wasm.d.ts +11 -0
  17. package/pkg-deno/iptocc_wasm.js +163 -0
  18. package/pkg-deno/iptocc_wasm_bg.wasm +0 -0
  19. package/pkg-deno/iptocc_wasm_bg.wasm.d.ts +9 -0
  20. package/pkg-no-modules/LICENSE-APACHE +202 -0
  21. package/pkg-no-modules/LICENSE-MIT +21 -0
  22. package/pkg-no-modules/README.md +40 -0
  23. package/pkg-no-modules/iptocc_wasm.d.ts +35 -0
  24. package/pkg-no-modules/iptocc_wasm.js +268 -0
  25. package/pkg-no-modules/iptocc_wasm_bg.wasm +0 -0
  26. package/pkg-no-modules/iptocc_wasm_bg.wasm.d.ts +9 -0
  27. package/pkg-no-modules/package.json +20 -0
  28. package/pkg-nodejs/LICENSE-APACHE +202 -0
  29. package/pkg-nodejs/LICENSE-MIT +21 -0
  30. package/pkg-nodejs/README.md +40 -0
  31. package/pkg-nodejs/iptocc_wasm.d.ts +11 -0
  32. package/pkg-nodejs/iptocc_wasm.js +176 -0
  33. package/pkg-nodejs/iptocc_wasm_bg.wasm +0 -0
  34. package/pkg-nodejs/iptocc_wasm_bg.wasm.d.ts +9 -0
  35. package/pkg-nodejs/package.json +22 -0
  36. package/pkg-web/LICENSE-APACHE +202 -0
  37. package/pkg-web/LICENSE-MIT +21 -0
  38. package/pkg-web/README.md +40 -0
  39. package/pkg-web/iptocc_wasm.d.ts +45 -0
  40. package/pkg-web/iptocc_wasm.js +270 -0
  41. package/pkg-web/iptocc_wasm_bg.wasm +0 -0
  42. package/pkg-web/iptocc_wasm_bg.wasm.d.ts +9 -0
  43. package/pkg-web/package.json +24 -0
@@ -0,0 +1,270 @@
1
+ /* @ts-self-types="./iptocc_wasm.d.ts" */
2
+
3
+ /**
4
+ * Looks up the ISO 3166-1 alpha-2 country code for an IPv4 or IPv6 address.
5
+ *
6
+ * Accepts either a single address string or an array of address strings.
7
+ * Returns a string (or `null`) for a single input, or an array of
8
+ * string-or-null for an array input. Throws `TypeError` on any other input.
9
+ * @param {any} input
10
+ * @returns {any}
11
+ */
12
+ export function country_code(input) {
13
+ const ret = wasm.country_code(input);
14
+ if (ret[2]) {
15
+ throw takeFromExternrefTable0(ret[1]);
16
+ }
17
+ return takeFromExternrefTable0(ret[0]);
18
+ }
19
+
20
+ function __wbg_get_imports() {
21
+ const import0 = {
22
+ __proto__: null,
23
+ __wbg_Error_2e59b1b37a9a34c3: function(arg0, arg1) {
24
+ const ret = Error(getStringFromWasm0(arg0, arg1));
25
+ return ret;
26
+ },
27
+ __wbg___wbindgen_string_get_914df97fcfa788f2: function(arg0, arg1) {
28
+ const obj = arg1;
29
+ const ret = typeof(obj) === 'string' ? obj : undefined;
30
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
31
+ var len1 = WASM_VECTOR_LEN;
32
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
33
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
34
+ },
35
+ __wbg___wbindgen_throw_81fc77679af83bc6: function(arg0, arg1) {
36
+ throw new Error(getStringFromWasm0(arg0, arg1));
37
+ },
38
+ __wbg_from_741da0f916ab74aa: function(arg0) {
39
+ const ret = Array.from(arg0);
40
+ return ret;
41
+ },
42
+ __wbg_get_4848e350b40afc16: function(arg0, arg1) {
43
+ const ret = arg0[arg1 >>> 0];
44
+ return ret;
45
+ },
46
+ __wbg_isArray_db61795ad004c139: function(arg0) {
47
+ const ret = Array.isArray(arg0);
48
+ return ret;
49
+ },
50
+ __wbg_length_6e821edde497a532: function(arg0) {
51
+ const ret = arg0.length;
52
+ return ret;
53
+ },
54
+ __wbg_new_with_length_1c0fb14ea44d1c09: function(arg0) {
55
+ const ret = new Array(arg0 >>> 0);
56
+ return ret;
57
+ },
58
+ __wbg_set_6c60b2e8ad0e9383: function(arg0, arg1, arg2) {
59
+ arg0[arg1 >>> 0] = arg2;
60
+ },
61
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
62
+ // Cast intrinsic for `Ref(String) -> Externref`.
63
+ const ret = getStringFromWasm0(arg0, arg1);
64
+ return ret;
65
+ },
66
+ __wbindgen_init_externref_table: function() {
67
+ const table = wasm.__wbindgen_externrefs;
68
+ const offset = table.grow(4);
69
+ table.set(0, undefined);
70
+ table.set(offset + 0, undefined);
71
+ table.set(offset + 1, null);
72
+ table.set(offset + 2, true);
73
+ table.set(offset + 3, false);
74
+ },
75
+ };
76
+ return {
77
+ __proto__: null,
78
+ "./iptocc_wasm_bg.js": import0,
79
+ };
80
+ }
81
+
82
+ let cachedDataViewMemory0 = null;
83
+ function getDataViewMemory0() {
84
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
85
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
86
+ }
87
+ return cachedDataViewMemory0;
88
+ }
89
+
90
+ function getStringFromWasm0(ptr, len) {
91
+ ptr = ptr >>> 0;
92
+ return decodeText(ptr, len);
93
+ }
94
+
95
+ let cachedUint8ArrayMemory0 = null;
96
+ function getUint8ArrayMemory0() {
97
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
98
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
99
+ }
100
+ return cachedUint8ArrayMemory0;
101
+ }
102
+
103
+ function isLikeNone(x) {
104
+ return x === undefined || x === null;
105
+ }
106
+
107
+ function passStringToWasm0(arg, malloc, realloc) {
108
+ if (realloc === undefined) {
109
+ const buf = cachedTextEncoder.encode(arg);
110
+ const ptr = malloc(buf.length, 1) >>> 0;
111
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
112
+ WASM_VECTOR_LEN = buf.length;
113
+ return ptr;
114
+ }
115
+
116
+ let len = arg.length;
117
+ let ptr = malloc(len, 1) >>> 0;
118
+
119
+ const mem = getUint8ArrayMemory0();
120
+
121
+ let offset = 0;
122
+
123
+ for (; offset < len; offset++) {
124
+ const code = arg.charCodeAt(offset);
125
+ if (code > 0x7F) break;
126
+ mem[ptr + offset] = code;
127
+ }
128
+ if (offset !== len) {
129
+ if (offset !== 0) {
130
+ arg = arg.slice(offset);
131
+ }
132
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
133
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
134
+ const ret = cachedTextEncoder.encodeInto(arg, view);
135
+
136
+ offset += ret.written;
137
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
138
+ }
139
+
140
+ WASM_VECTOR_LEN = offset;
141
+ return ptr;
142
+ }
143
+
144
+ function takeFromExternrefTable0(idx) {
145
+ const value = wasm.__wbindgen_externrefs.get(idx);
146
+ wasm.__externref_table_dealloc(idx);
147
+ return value;
148
+ }
149
+
150
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
151
+ cachedTextDecoder.decode();
152
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
153
+ let numBytesDecoded = 0;
154
+ function decodeText(ptr, len) {
155
+ numBytesDecoded += len;
156
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
157
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
158
+ cachedTextDecoder.decode();
159
+ numBytesDecoded = len;
160
+ }
161
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
162
+ }
163
+
164
+ const cachedTextEncoder = new TextEncoder();
165
+
166
+ if (!('encodeInto' in cachedTextEncoder)) {
167
+ cachedTextEncoder.encodeInto = function (arg, view) {
168
+ const buf = cachedTextEncoder.encode(arg);
169
+ view.set(buf);
170
+ return {
171
+ read: arg.length,
172
+ written: buf.length
173
+ };
174
+ };
175
+ }
176
+
177
+ let WASM_VECTOR_LEN = 0;
178
+
179
+ let wasmModule, wasm;
180
+ function __wbg_finalize_init(instance, module) {
181
+ wasm = instance.exports;
182
+ wasmModule = module;
183
+ cachedDataViewMemory0 = null;
184
+ cachedUint8ArrayMemory0 = null;
185
+ wasm.__wbindgen_start();
186
+ return wasm;
187
+ }
188
+
189
+ async function __wbg_load(module, imports) {
190
+ if (typeof Response === 'function' && module instanceof Response) {
191
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
192
+ try {
193
+ return await WebAssembly.instantiateStreaming(module, imports);
194
+ } catch (e) {
195
+ const validResponse = module.ok && expectedResponseType(module.type);
196
+
197
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
198
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
199
+
200
+ } else { throw e; }
201
+ }
202
+ }
203
+
204
+ const bytes = await module.arrayBuffer();
205
+ return await WebAssembly.instantiate(bytes, imports);
206
+ } else {
207
+ const instance = await WebAssembly.instantiate(module, imports);
208
+
209
+ if (instance instanceof WebAssembly.Instance) {
210
+ return { instance, module };
211
+ } else {
212
+ return instance;
213
+ }
214
+ }
215
+
216
+ function expectedResponseType(type) {
217
+ switch (type) {
218
+ case 'basic': case 'cors': case 'default': return true;
219
+ }
220
+ return false;
221
+ }
222
+ }
223
+
224
+ function initSync(module) {
225
+ if (wasm !== undefined) return wasm;
226
+
227
+
228
+ if (module !== undefined) {
229
+ if (Object.getPrototypeOf(module) === Object.prototype) {
230
+ ({module} = module)
231
+ } else {
232
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
233
+ }
234
+ }
235
+
236
+ const imports = __wbg_get_imports();
237
+ if (!(module instanceof WebAssembly.Module)) {
238
+ module = new WebAssembly.Module(module);
239
+ }
240
+ const instance = new WebAssembly.Instance(module, imports);
241
+ return __wbg_finalize_init(instance, module);
242
+ }
243
+
244
+ async function __wbg_init(module_or_path) {
245
+ if (wasm !== undefined) return wasm;
246
+
247
+
248
+ if (module_or_path !== undefined) {
249
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
250
+ ({module_or_path} = module_or_path)
251
+ } else {
252
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
253
+ }
254
+ }
255
+
256
+ if (module_or_path === undefined) {
257
+ module_or_path = new URL('iptocc_wasm_bg.wasm', import.meta.url);
258
+ }
259
+ const imports = __wbg_get_imports();
260
+
261
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
262
+ module_or_path = fetch(module_or_path);
263
+ }
264
+
265
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
266
+
267
+ return __wbg_finalize_init(instance, module);
268
+ }
269
+
270
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,9 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const country_code: (a: any) => [number, number, number];
5
+ export const __wbindgen_malloc: (a: number, b: number) => number;
6
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
7
+ export const __wbindgen_externrefs: WebAssembly.Table;
8
+ export const __externref_table_dealloc: (a: number) => void;
9
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "iptocc-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "Ronie Martinez <ronmarti18@gmail.com>"
6
+ ],
7
+ "description": "WASM bindings for iptocc, a fast IP-to-country lookup library written in Rust",
8
+ "version": "1.0.0-alpha.1",
9
+ "license": "MIT OR Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/roniemartinez/IPToCC"
13
+ },
14
+ "files": [
15
+ "iptocc_wasm_bg.wasm",
16
+ "iptocc_wasm.js",
17
+ "iptocc_wasm.d.ts"
18
+ ],
19
+ "main": "iptocc_wasm.js",
20
+ "types": "iptocc_wasm.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }