protobufjs 8.1.6-experimental → 8.2.0

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 (76) hide show
  1. package/README.md +219 -565
  2. package/dist/light/protobuf.js +1986 -1483
  3. package/dist/light/protobuf.js.map +1 -1
  4. package/dist/light/protobuf.min.js +3 -3
  5. package/dist/light/protobuf.min.js.map +1 -1
  6. package/dist/minimal/protobuf.js +1122 -861
  7. package/dist/minimal/protobuf.js.map +1 -1
  8. package/dist/minimal/protobuf.min.js +3 -3
  9. package/dist/minimal/protobuf.min.js.map +1 -1
  10. package/dist/protobuf.js +2089 -1513
  11. package/dist/protobuf.js.map +1 -1
  12. package/dist/protobuf.min.js +3 -3
  13. package/dist/protobuf.min.js.map +1 -1
  14. package/ext/README.md +81 -0
  15. package/ext/descriptor/README.md +3 -70
  16. package/ext/descriptor/index.d.ts +1 -191
  17. package/ext/descriptor/index.js +1 -1161
  18. package/ext/descriptor.d.ts +309 -0
  19. package/ext/descriptor.js +1236 -0
  20. package/ext/textformat.d.ts +30 -0
  21. package/ext/textformat.js +1249 -0
  22. package/google/protobuf/compiler/plugin.json +126 -0
  23. package/google/protobuf/compiler/plugin.proto +47 -0
  24. package/google/protobuf/descriptor.json +2 -2
  25. package/google/protobuf/descriptor.proto +2 -1
  26. package/index.d.ts +590 -476
  27. package/package.json +23 -38
  28. package/src/converter.js +60 -24
  29. package/src/decoder.js +122 -49
  30. package/src/encoder.js +10 -2
  31. package/src/enum.js +4 -1
  32. package/src/field.js +10 -7
  33. package/src/mapfield.js +1 -0
  34. package/src/message.js +7 -6
  35. package/src/method.js +4 -3
  36. package/src/namespace.js +23 -12
  37. package/src/object.js +24 -19
  38. package/src/oneof.js +2 -0
  39. package/src/parse.js +114 -46
  40. package/src/reader.js +145 -30
  41. package/src/reader_buffer.js +24 -3
  42. package/src/root.js +7 -4
  43. package/src/service.js +12 -6
  44. package/src/tokenize.js +6 -1
  45. package/src/type.js +48 -25
  46. package/src/types.js +1 -1
  47. package/src/util/aspromise.d.ts +13 -0
  48. package/src/util/aspromise.js +52 -0
  49. package/src/util/base64.d.ts +32 -0
  50. package/src/util/base64.js +146 -0
  51. package/src/util/codegen.d.ts +31 -0
  52. package/src/util/codegen.js +113 -0
  53. package/src/util/eventemitter.d.ts +45 -0
  54. package/src/util/eventemitter.js +84 -0
  55. package/src/util/fetch.d.ts +56 -0
  56. package/src/util/fetch.js +112 -0
  57. package/src/util/float.d.ts +83 -0
  58. package/src/util/float.js +335 -0
  59. package/src/util/fs.js +11 -0
  60. package/src/util/inquire.d.ts +10 -0
  61. package/src/util/inquire.js +38 -0
  62. package/src/util/minimal.js +67 -12
  63. package/src/util/path.d.ts +22 -0
  64. package/src/util/path.js +72 -0
  65. package/src/util/patterns.js +8 -0
  66. package/src/util/pool.d.ts +32 -0
  67. package/src/util/pool.js +48 -0
  68. package/src/util/utf8.d.ts +24 -0
  69. package/src/util/utf8.js +104 -0
  70. package/src/util.js +30 -13
  71. package/src/verifier.js +7 -4
  72. package/src/wrappers.js +4 -3
  73. package/src/writer.js +27 -4
  74. package/src/writer_buffer.js +12 -0
  75. package/tsconfig.json +2 -2
  76. package/ext/descriptor/test.js +0 -54
@@ -0,0 +1,335 @@
1
+ "use strict";
2
+
3
+ module.exports = factory(factory);
4
+
5
+ /**
6
+ * Reads / writes floats / doubles from / to buffers.
7
+ * @name util.float
8
+ * @namespace
9
+ */
10
+
11
+ /**
12
+ * Writes a 32 bit float to a buffer using little endian byte order.
13
+ * @name util.float.writeFloatLE
14
+ * @function
15
+ * @param {number} val Value to write
16
+ * @param {Uint8Array} buf Target buffer
17
+ * @param {number} pos Target buffer offset
18
+ * @returns {undefined}
19
+ */
20
+
21
+ /**
22
+ * Writes a 32 bit float to a buffer using big endian byte order.
23
+ * @name util.float.writeFloatBE
24
+ * @function
25
+ * @param {number} val Value to write
26
+ * @param {Uint8Array} buf Target buffer
27
+ * @param {number} pos Target buffer offset
28
+ * @returns {undefined}
29
+ */
30
+
31
+ /**
32
+ * Reads a 32 bit float from a buffer using little endian byte order.
33
+ * @name util.float.readFloatLE
34
+ * @function
35
+ * @param {Uint8Array} buf Source buffer
36
+ * @param {number} pos Source buffer offset
37
+ * @returns {number} Value read
38
+ */
39
+
40
+ /**
41
+ * Reads a 32 bit float from a buffer using big endian byte order.
42
+ * @name util.float.readFloatBE
43
+ * @function
44
+ * @param {Uint8Array} buf Source buffer
45
+ * @param {number} pos Source buffer offset
46
+ * @returns {number} Value read
47
+ */
48
+
49
+ /**
50
+ * Writes a 64 bit double to a buffer using little endian byte order.
51
+ * @name util.float.writeDoubleLE
52
+ * @function
53
+ * @param {number} val Value to write
54
+ * @param {Uint8Array} buf Target buffer
55
+ * @param {number} pos Target buffer offset
56
+ * @returns {undefined}
57
+ */
58
+
59
+ /**
60
+ * Writes a 64 bit double to a buffer using big endian byte order.
61
+ * @name util.float.writeDoubleBE
62
+ * @function
63
+ * @param {number} val Value to write
64
+ * @param {Uint8Array} buf Target buffer
65
+ * @param {number} pos Target buffer offset
66
+ * @returns {undefined}
67
+ */
68
+
69
+ /**
70
+ * Reads a 64 bit double from a buffer using little endian byte order.
71
+ * @name util.float.readDoubleLE
72
+ * @function
73
+ * @param {Uint8Array} buf Source buffer
74
+ * @param {number} pos Source buffer offset
75
+ * @returns {number} Value read
76
+ */
77
+
78
+ /**
79
+ * Reads a 64 bit double from a buffer using big endian byte order.
80
+ * @name util.float.readDoubleBE
81
+ * @function
82
+ * @param {Uint8Array} buf Source buffer
83
+ * @param {number} pos Source buffer offset
84
+ * @returns {number} Value read
85
+ */
86
+
87
+ // Factory function for the purpose of node-based testing in modified global environments
88
+ function factory(exports) {
89
+
90
+ // float: typed array
91
+ if (typeof Float32Array !== "undefined") (function() {
92
+
93
+ var f32 = new Float32Array([ -0 ]),
94
+ f8b = new Uint8Array(f32.buffer),
95
+ le = f8b[3] === 128;
96
+
97
+ function writeFloat_f32_cpy(val, buf, pos) {
98
+ f32[0] = val;
99
+ buf[pos ] = f8b[0];
100
+ buf[pos + 1] = f8b[1];
101
+ buf[pos + 2] = f8b[2];
102
+ buf[pos + 3] = f8b[3];
103
+ }
104
+
105
+ function writeFloat_f32_rev(val, buf, pos) {
106
+ f32[0] = val;
107
+ buf[pos ] = f8b[3];
108
+ buf[pos + 1] = f8b[2];
109
+ buf[pos + 2] = f8b[1];
110
+ buf[pos + 3] = f8b[0];
111
+ }
112
+
113
+ /* istanbul ignore next */
114
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
115
+ /* istanbul ignore next */
116
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
117
+
118
+ function readFloat_f32_cpy(buf, pos) {
119
+ f8b[0] = buf[pos ];
120
+ f8b[1] = buf[pos + 1];
121
+ f8b[2] = buf[pos + 2];
122
+ f8b[3] = buf[pos + 3];
123
+ return f32[0];
124
+ }
125
+
126
+ function readFloat_f32_rev(buf, pos) {
127
+ f8b[3] = buf[pos ];
128
+ f8b[2] = buf[pos + 1];
129
+ f8b[1] = buf[pos + 2];
130
+ f8b[0] = buf[pos + 3];
131
+ return f32[0];
132
+ }
133
+
134
+ /* istanbul ignore next */
135
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
136
+ /* istanbul ignore next */
137
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
138
+
139
+ // float: ieee754
140
+ })(); else (function() {
141
+
142
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
143
+ var sign = val < 0 ? 1 : 0;
144
+ if (sign)
145
+ val = -val;
146
+ if (val === 0)
147
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
148
+ else if (isNaN(val))
149
+ writeUint(2143289344, buf, pos);
150
+ else if (val > 3.4028234663852886e+38) // +-Infinity
151
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
152
+ else if (val < 1.1754943508222875e-38) // denormal
153
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
154
+ else {
155
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
156
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
157
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
158
+ }
159
+ }
160
+
161
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
162
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
163
+
164
+ function readFloat_ieee754(readUint, buf, pos) {
165
+ var uint = readUint(buf, pos),
166
+ sign = (uint >> 31) * 2 + 1,
167
+ exponent = uint >>> 23 & 255,
168
+ mantissa = uint & 8388607;
169
+ return exponent === 255
170
+ ? mantissa
171
+ ? NaN
172
+ : sign * Infinity
173
+ : exponent === 0 // denormal
174
+ ? sign * 1.401298464324817e-45 * mantissa
175
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
176
+ }
177
+
178
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
179
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
180
+
181
+ })();
182
+
183
+ // double: typed array
184
+ if (typeof Float64Array !== "undefined") (function() {
185
+
186
+ var f64 = new Float64Array([-0]),
187
+ f8b = new Uint8Array(f64.buffer),
188
+ le = f8b[7] === 128;
189
+
190
+ function writeDouble_f64_cpy(val, buf, pos) {
191
+ f64[0] = val;
192
+ buf[pos ] = f8b[0];
193
+ buf[pos + 1] = f8b[1];
194
+ buf[pos + 2] = f8b[2];
195
+ buf[pos + 3] = f8b[3];
196
+ buf[pos + 4] = f8b[4];
197
+ buf[pos + 5] = f8b[5];
198
+ buf[pos + 6] = f8b[6];
199
+ buf[pos + 7] = f8b[7];
200
+ }
201
+
202
+ function writeDouble_f64_rev(val, buf, pos) {
203
+ f64[0] = val;
204
+ buf[pos ] = f8b[7];
205
+ buf[pos + 1] = f8b[6];
206
+ buf[pos + 2] = f8b[5];
207
+ buf[pos + 3] = f8b[4];
208
+ buf[pos + 4] = f8b[3];
209
+ buf[pos + 5] = f8b[2];
210
+ buf[pos + 6] = f8b[1];
211
+ buf[pos + 7] = f8b[0];
212
+ }
213
+
214
+ /* istanbul ignore next */
215
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
216
+ /* istanbul ignore next */
217
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
218
+
219
+ function readDouble_f64_cpy(buf, pos) {
220
+ f8b[0] = buf[pos ];
221
+ f8b[1] = buf[pos + 1];
222
+ f8b[2] = buf[pos + 2];
223
+ f8b[3] = buf[pos + 3];
224
+ f8b[4] = buf[pos + 4];
225
+ f8b[5] = buf[pos + 5];
226
+ f8b[6] = buf[pos + 6];
227
+ f8b[7] = buf[pos + 7];
228
+ return f64[0];
229
+ }
230
+
231
+ function readDouble_f64_rev(buf, pos) {
232
+ f8b[7] = buf[pos ];
233
+ f8b[6] = buf[pos + 1];
234
+ f8b[5] = buf[pos + 2];
235
+ f8b[4] = buf[pos + 3];
236
+ f8b[3] = buf[pos + 4];
237
+ f8b[2] = buf[pos + 5];
238
+ f8b[1] = buf[pos + 6];
239
+ f8b[0] = buf[pos + 7];
240
+ return f64[0];
241
+ }
242
+
243
+ /* istanbul ignore next */
244
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
245
+ /* istanbul ignore next */
246
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
247
+
248
+ // double: ieee754
249
+ })(); else (function() {
250
+
251
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
252
+ var sign = val < 0 ? 1 : 0;
253
+ if (sign)
254
+ val = -val;
255
+ if (val === 0) {
256
+ writeUint(0, buf, pos + off0);
257
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
258
+ } else if (isNaN(val)) {
259
+ writeUint(0, buf, pos + off0);
260
+ writeUint(2146959360, buf, pos + off1);
261
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
262
+ writeUint(0, buf, pos + off0);
263
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
264
+ } else {
265
+ var mantissa;
266
+ if (val < 2.2250738585072014e-308) { // denormal
267
+ mantissa = val / 5e-324;
268
+ writeUint(mantissa >>> 0, buf, pos + off0);
269
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
270
+ } else {
271
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
272
+ if (exponent === 1024)
273
+ exponent = 1023;
274
+ mantissa = val * Math.pow(2, -exponent);
275
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
276
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
277
+ }
278
+ }
279
+ }
280
+
281
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
282
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
283
+
284
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
285
+ var lo = readUint(buf, pos + off0),
286
+ hi = readUint(buf, pos + off1);
287
+ var sign = (hi >> 31) * 2 + 1,
288
+ exponent = hi >>> 20 & 2047,
289
+ mantissa = 4294967296 * (hi & 1048575) + lo;
290
+ return exponent === 2047
291
+ ? mantissa
292
+ ? NaN
293
+ : sign * Infinity
294
+ : exponent === 0 // denormal
295
+ ? sign * 5e-324 * mantissa
296
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
297
+ }
298
+
299
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
300
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
301
+
302
+ })();
303
+
304
+ return exports;
305
+ }
306
+
307
+ // uint helpers
308
+
309
+ function writeUintLE(val, buf, pos) {
310
+ buf[pos ] = val & 255;
311
+ buf[pos + 1] = val >>> 8 & 255;
312
+ buf[pos + 2] = val >>> 16 & 255;
313
+ buf[pos + 3] = val >>> 24;
314
+ }
315
+
316
+ function writeUintBE(val, buf, pos) {
317
+ buf[pos ] = val >>> 24;
318
+ buf[pos + 1] = val >>> 16 & 255;
319
+ buf[pos + 2] = val >>> 8 & 255;
320
+ buf[pos + 3] = val & 255;
321
+ }
322
+
323
+ function readUintLE(buf, pos) {
324
+ return (buf[pos ]
325
+ | buf[pos + 1] << 8
326
+ | buf[pos + 2] << 16
327
+ | buf[pos + 3] << 24) >>> 0;
328
+ }
329
+
330
+ function readUintBE(buf, pos) {
331
+ return (buf[pos ] << 24
332
+ | buf[pos + 1] << 16
333
+ | buf[pos + 2] << 8
334
+ | buf[pos + 3]) >>> 0;
335
+ }
package/src/util/fs.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ var fs = null;
4
+ try {
5
+ fs = require(/* webpackIgnore: true */ "fs");
6
+ if (!fs || !fs.readFile || !fs.readFileSync)
7
+ fs = null;
8
+ } catch (e) {
9
+ // `fs` is unavailable in browsers and browser-like bundles.
10
+ }
11
+ module.exports = fs;
@@ -0,0 +1,10 @@
1
+ export = inquire;
2
+
3
+ /**
4
+ * Requires a module only if available.
5
+ * @memberof util
6
+ * @param {string} moduleName Module to require
7
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
8
+ * @deprecated Legacy optional require helper. Will be removed in a future release.
9
+ */
10
+ declare function inquire(moduleName: string): object;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ module.exports = inquire;
3
+
4
+ /**
5
+ * Requires a module only if available.
6
+ * @memberof util
7
+ * @param {string} moduleName Module to require
8
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
9
+ * @deprecated Legacy optional require helper. Will be removed in a future release.
10
+ */
11
+ function inquire(moduleName) {
12
+ try {
13
+ if (typeof require !== "function") {
14
+ return null;
15
+ }
16
+ var mod = require(moduleName);
17
+ if (mod && (mod.length || Object.keys(mod).length)) return mod;
18
+ return null;
19
+ } catch (err) {
20
+ // ignore
21
+ return null;
22
+ }
23
+ }
24
+
25
+ /*
26
+ // maybe worth a shot to prevent renaming issues:
27
+ // see: https://github.com/webpack/webpack/blob/master/lib/dependencies/CommonJsRequireDependencyParserPlugin.js
28
+ // triggers on:
29
+ // - expression require.cache
30
+ // - expression require (???)
31
+ // - call require
32
+ // - call require:commonjs:item
33
+ // - call require:commonjs:context
34
+
35
+ Object.defineProperty(Function.prototype, "__self", { get: function() { return this; } });
36
+ var r = require.__self;
37
+ delete Function.prototype.__self;
38
+ */
@@ -2,25 +2,25 @@
2
2
  var util = exports;
3
3
 
4
4
  // used to return a Promise where callback is omitted
5
- util.asPromise = require("@protobufjs/aspromise");
5
+ util.asPromise = require("./aspromise");
6
6
 
7
7
  // converts to / from base64 encoded strings
8
- util.base64 = require("@protobufjs/base64");
8
+ util.base64 = require("./base64");
9
9
 
10
10
  // base class of rpc.Service
11
- util.EventEmitter = require("@protobufjs/eventemitter");
11
+ util.EventEmitter = require("./eventemitter");
12
12
 
13
13
  // float handling accross browsers
14
- util.float = require("@protobufjs/float");
14
+ util.float = require("./float");
15
15
 
16
16
  // requires modules optionally and hides the call from bundlers
17
- util.inquire = require("@protobufjs/inquire");
17
+ util.inquire = require("./inquire");
18
18
 
19
19
  // converts to / from utf8 encoded strings
20
- util.utf8 = require("@protobufjs/utf8");
20
+ util.utf8 = require("./utf8");
21
21
 
22
22
  // provides a node-like buffer pool in the browser
23
- util.pool = require("@protobufjs/pool");
23
+ util.pool = require("./pool");
24
24
 
25
25
  // utility to work with the low and high bits of a 64 bit value
26
26
  util.LongBits = require("./longbits");
@@ -125,7 +125,7 @@ util.isSet = function isSet(obj, prop) {
125
125
  */
126
126
  util.Buffer = (function() {
127
127
  try {
128
- var Buffer = util.inquire("buffer").Buffer;
128
+ var Buffer = util.global.Buffer;
129
129
  // refuse to use non-node buffers if not explicitly assigned (perf reasons):
130
130
  return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
131
131
  } catch (e) {
@@ -179,14 +179,22 @@ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore n
179
179
  */
180
180
  util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
181
181
  || /* istanbul ignore next */ util.global.Long
182
- || util.inquire("long");
182
+ || (function() {
183
+ try {
184
+ var Long = require("long");
185
+ return Long && Long.isLong ? Long : null;
186
+ } catch (e) {
187
+ /* istanbul ignore next */
188
+ return null;
189
+ }
190
+ })();
183
191
 
184
192
  /**
185
193
  * Regular expression used to verify 2 bit (`bool`) map keys.
186
194
  * @type {RegExp}
187
195
  * @const
188
196
  */
189
- util.key2Re = /^true|false|0|1$/;
197
+ util.key2Re = /^(?:true|false|0|1)$/;
190
198
 
191
199
  /**
192
200
  * Regular expression used to verify 32 bit (`int32` etc.) map keys.
@@ -200,7 +208,7 @@ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
200
208
  * @type {RegExp}
201
209
  * @const
202
210
  */
203
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
211
+ util.key64Re = /^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/; // eslint-disable-line no-control-regex
204
212
 
205
213
  /**
206
214
  * Converts a number or long to an 8 characters long hash string.
@@ -226,6 +234,27 @@ util.longFromHash = function longFromHash(hash, unsigned) {
226
234
  return bits.toNumber(Boolean(unsigned));
227
235
  };
228
236
 
237
+ /**
238
+ * Converts a 64 bit key to a long or number if it is an 8 characters long hash string.
239
+ * @param {string} key Map key
240
+ * @param {boolean} [unsigned=false] Whether unsigned or not
241
+ * @returns {Long|number|string} Original value
242
+ */
243
+ util.longFromKey = function longFromKey(key, unsigned) {
244
+ return util.key64Re.test(key) && !util.key32Re.test(key)
245
+ ? util.longFromHash(key, unsigned)
246
+ : key;
247
+ };
248
+
249
+ /**
250
+ * Converts a boolean key to a boolean value.
251
+ * @param {string} key Map key
252
+ * @returns {boolean} Boolean value
253
+ */
254
+ util.boolFromKey = function boolFromKey(key) {
255
+ return key === "true" || key === "1";
256
+ };
257
+
229
258
  /**
230
259
  * Merges the properties of the source object into the destination object.
231
260
  * @memberof util
@@ -237,12 +266,38 @@ util.longFromHash = function longFromHash(hash, unsigned) {
237
266
  function merge(dst, src, ifNotSet) { // used by converters
238
267
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
239
268
  if (dst[keys[i]] === undefined || !ifNotSet)
240
- dst[keys[i]] = src[keys[i]];
269
+ if (keys[i] !== "__proto__")
270
+ dst[keys[i]] = src[keys[i]];
241
271
  return dst;
242
272
  }
243
273
 
244
274
  util.merge = merge;
245
275
 
276
+ /**
277
+ * Recursion limit.
278
+ * @memberof util
279
+ * @type {number}
280
+ */
281
+ util.recursionLimit = 100;
282
+
283
+ /**
284
+ * Makes a property safe for assignment as an own property.
285
+ * @memberof util
286
+ * @param {Object.<string,*>} obj Object
287
+ * @param {string} key Property key
288
+ * @param {boolean} [enumerable=true] Whether the property should be enumerable
289
+ * @returns {undefined}
290
+ */
291
+ util.makeProp = function makeProp(obj, key, enumerable) {
292
+ if (Object.prototype.hasOwnProperty.call(obj, key))
293
+ return;
294
+ Object.defineProperty(obj, key, {
295
+ enumerable: enumerable === undefined ? true : enumerable,
296
+ configurable: true,
297
+ writable: true
298
+ });
299
+ };
300
+
246
301
  /**
247
302
  * Converts the first character of a string to lower case.
248
303
  * @param {string} str String to convert
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Tests if the specified path is absolute.
3
+ * @param {string} path Path to test
4
+ * @returns {boolean} `true` if path is absolute
5
+ */
6
+ export function isAbsolute(path: string): boolean;
7
+
8
+ /**
9
+ * Normalizes the specified path.
10
+ * @param {string} path Path to normalize
11
+ * @returns {string} Normalized path
12
+ */
13
+ export function normalize(path: string): string;
14
+
15
+ /**
16
+ * Resolves the specified include path against the specified origin path.
17
+ * @param {string} originPath Path to the origin file
18
+ * @param {string} includePath Include path relative to origin path
19
+ * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
20
+ * @returns {string} Path to the include file
21
+ */
22
+ export function resolve(originPath: string, includePath: string, alreadyNormalized?: boolean): string;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * A minimal path module to resolve Unix, Windows and URL paths alike.
5
+ * @memberof util
6
+ * @namespace
7
+ */
8
+ var path = exports;
9
+
10
+ var isAbsolute =
11
+ /**
12
+ * Tests if the specified path is absolute.
13
+ * @param {string} path Path to test
14
+ * @returns {boolean} `true` if path is absolute
15
+ */
16
+ path.isAbsolute = function isAbsolute(path) {
17
+ return /^(?:\/|\w+:|\\\\\w+)/.test(path);
18
+ };
19
+
20
+ var normalize =
21
+ /**
22
+ * Normalizes the specified path.
23
+ * @param {string} path Path to normalize
24
+ * @returns {string} Normalized path
25
+ */
26
+ path.normalize = function normalize(path) {
27
+ var firstTwoCharacters = path.substring(0,2);
28
+ var uncPrefix = "";
29
+ if (firstTwoCharacters === "\\\\") {
30
+ uncPrefix = firstTwoCharacters;
31
+ path = path.substring(2);
32
+ }
33
+
34
+ path = path.replace(/\\/g, "/")
35
+ .replace(/\/{2,}/g, "/");
36
+ var parts = path.split("/"),
37
+ absolute = isAbsolute(path),
38
+ prefix = "";
39
+ if (absolute)
40
+ prefix = parts.shift() + "/";
41
+ for (var i = 0; i < parts.length;) {
42
+ if (parts[i] === "..") {
43
+ if (i > 0 && parts[i - 1] !== "..")
44
+ parts.splice(--i, 2);
45
+ else if (absolute)
46
+ parts.splice(i, 1);
47
+ else
48
+ ++i;
49
+ } else if (parts[i] === ".")
50
+ parts.splice(i, 1);
51
+ else
52
+ ++i;
53
+ }
54
+ return uncPrefix + prefix + parts.join("/");
55
+ };
56
+
57
+ /**
58
+ * Resolves the specified include path against the specified origin path.
59
+ * @param {string} originPath Path to the origin file
60
+ * @param {string} includePath Include path relative to origin path
61
+ * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
62
+ * @returns {string} Path to the include file
63
+ */
64
+ path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
65
+ if (!alreadyNormalized)
66
+ includePath = normalize(includePath);
67
+ if (isAbsolute(includePath))
68
+ return includePath;
69
+ if (!alreadyNormalized)
70
+ originPath = normalize(originPath);
71
+ return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
72
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ var patterns = exports;
4
+
5
+ patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
6
+ patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
7
+ patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
8
+ patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
@@ -0,0 +1,32 @@
1
+ export = pool;
2
+
3
+ /**
4
+ * An allocator as used by {@link util.pool}.
5
+ * @typedef PoolAllocator
6
+ * @type {function}
7
+ * @param {number} size Buffer size
8
+ * @returns {Uint8Array} Buffer
9
+ */
10
+ type PoolAllocator = (size: number) => Uint8Array;
11
+
12
+ /**
13
+ * A slicer as used by {@link util.pool}.
14
+ * @typedef PoolSlicer
15
+ * @type {function}
16
+ * @param {number} start Start offset
17
+ * @param {number} end End offset
18
+ * @returns {Uint8Array} Buffer slice
19
+ * @this {Uint8Array}
20
+ */
21
+ type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array;
22
+
23
+ /**
24
+ * A general purpose buffer pool.
25
+ * @memberof util
26
+ * @function
27
+ * @param {PoolAllocator} alloc Allocator
28
+ * @param {PoolSlicer} slice Slicer
29
+ * @param {number} [size=8192] Slab size
30
+ * @returns {PoolAllocator} Pooled allocator
31
+ */
32
+ declare function pool(alloc: PoolAllocator, slice: PoolSlicer, size?: number): PoolAllocator;