cbor-web 8.1.0 → 9.0.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.
@@ -0,0 +1,483 @@
1
+ /// <reference types="node" />
2
+ export = Encoder;
3
+ /**
4
+ * @typedef ObjectOptions
5
+ * @property {boolean} [indefinite = false] Force indefinite encoding for this
6
+ * object.
7
+ * @property {boolean} [skipTypes = false] Do not use available type mappings
8
+ * for this object, but encode it as a "normal" JS object would be.
9
+ */
10
+ /**
11
+ * @typedef EncodingOptions
12
+ * @property {any[]|object} [genTypes=[]] Array of pairs of
13
+ * `type`, `function(Encoder)` for semantic types to be encoded. Not
14
+ * needed for Array, Date, Buffer, Map, RegExp, Set, or URL.
15
+ * If an object, the keys are the constructor names for the types.
16
+ * @property {boolean} [canonical=false] Should the output be
17
+ * canonicalized.
18
+ * @property {boolean|WeakSet} [detectLoops=false] Should object loops
19
+ * be detected? This will currently add memory to track every part of the
20
+ * object being encoded in a WeakSet. Do not encode
21
+ * the same object twice on the same encoder, without calling
22
+ * `removeLoopDetectors` in between, which will clear the WeakSet.
23
+ * You may pass in your own WeakSet to be used; this is useful in some
24
+ * recursive scenarios.
25
+ * @property {("number"|"float"|"int"|"string")} [dateType="number"] -
26
+ * how should dates be encoded? "number" means float or int, if no
27
+ * fractional seconds.
28
+ * @property {any} [encodeUndefined=undefined] How should an
29
+ * "undefined" in the input be encoded. By default, just encode a CBOR
30
+ * undefined. If this is a buffer, use those bytes without re-encoding
31
+ * them. If this is a function, the function will be called (which is a
32
+ * good time to throw an exception, if that's what you want), and the
33
+ * return value will be used according to these rules. Anything else will
34
+ * be encoded as CBOR.
35
+ * @property {boolean} [disallowUndefinedKeys=false] Should
36
+ * "undefined" be disallowed as a key in a Map that is serialized? If
37
+ * this is true, encode(new Map([[undefined, 1]])) will throw an
38
+ * exception. Note that it is impossible to get a key of undefined in a
39
+ * normal JS object.
40
+ * @property {boolean} [collapseBigIntegers=false] Should integers
41
+ * that come in as ECMAscript bigint's be encoded
42
+ * as normal CBOR integers if they fit, discarding type information?
43
+ * @property {number} [chunkSize=4096] Number of characters or bytes
44
+ * for each chunk, if obj is a string or Buffer, when indefinite encoding.
45
+ * @property {boolean} [omitUndefinedProperties=false] When encoding
46
+ * objects or Maps, do not include a key if its corresponding value is
47
+ * `undefined`.
48
+ */
49
+ /**
50
+ * Transform JavaScript values into CBOR bytes. The `Writable` side of
51
+ * the stream is in object mode.
52
+ *
53
+ * @extends stream.Transform
54
+ */
55
+ declare class Encoder extends stream.Transform {
56
+ /**
57
+ * Encode an array and all of its elements.
58
+ *
59
+ * @param {Encoder} gen Encoder to use.
60
+ * @param {any[]} obj Array to encode.
61
+ * @param {object} [opts] Options.
62
+ * @param {boolean} [opts.indefinite=false] Use indefinite encoding?
63
+ * @returns {boolean} True on success.
64
+ */
65
+ static pushArray(gen: Encoder, obj: any[], opts?: {
66
+ indefinite?: boolean;
67
+ }): boolean;
68
+ /**
69
+ * @param {Encoder} gen Encoder.
70
+ * @param {Date} obj Date to encode.
71
+ * @returns {boolean} True on success.
72
+ * @ignore
73
+ */
74
+ static _pushDate(gen: Encoder, obj: Date): boolean;
75
+ /**
76
+ * @param {Encoder} gen Encoder.
77
+ * @param {Buffer} obj Buffer to encode.
78
+ * @returns {boolean} True on success.
79
+ * @ignore
80
+ */
81
+ static _pushBuffer(gen: Encoder, obj: Buffer): boolean;
82
+ /**
83
+ * @param {Encoder} gen Encoder.
84
+ * @param {NoFilter} obj Buffer to encode.
85
+ * @returns {boolean} True on success.
86
+ * @ignore
87
+ */
88
+ static _pushNoFilter(gen: Encoder, obj: NoFilter): boolean;
89
+ /**
90
+ * @param {Encoder} gen Encoder.
91
+ * @param {RegExp} obj RegExp to encode.
92
+ * @returns {boolean} True on success.
93
+ * @ignore
94
+ */
95
+ static _pushRegexp(gen: Encoder, obj: RegExp): boolean;
96
+ /**
97
+ * @param {Encoder} gen Encoder.
98
+ * @param {Set} obj Set to encode.
99
+ * @returns {boolean} True on success.
100
+ * @ignore
101
+ */
102
+ static _pushSet(gen: Encoder, obj: Set<any>): boolean;
103
+ /**
104
+ * @param {Encoder} gen Encoder.
105
+ * @param {URL} obj URL to encode.
106
+ * @returns {boolean} True on success.
107
+ * @ignore
108
+ */
109
+ static _pushURL(gen: Encoder, obj: URL): boolean;
110
+ /**
111
+ * @param {Encoder} gen Encoder.
112
+ * @param {object} obj Boxed String, Number, or Boolean object to encode.
113
+ * @returns {boolean} True on success.
114
+ * @ignore
115
+ */
116
+ static _pushBoxed(gen: Encoder, obj: object): boolean;
117
+ /**
118
+ * @param {Encoder} gen Encoder.
119
+ * @param {Map} obj Map to encode.
120
+ * @returns {boolean} True on success.
121
+ * @throws {Error} Map key that is undefined.
122
+ * @ignore
123
+ */
124
+ static _pushMap(gen: Encoder, obj: Map<any, any>, opts: any): boolean;
125
+ /**
126
+ * @param {Encoder} gen Encoder.
127
+ * @param {NodeJS.TypedArray} obj Array to encode.
128
+ * @returns {boolean} True on success.
129
+ * @ignore
130
+ */
131
+ static _pushTypedArray(gen: Encoder, obj: NodeJS.TypedArray): boolean;
132
+ /**
133
+ * @param {Encoder} gen Encoder.
134
+ * @param { ArrayBuffer } obj Array to encode.
135
+ * @returns {boolean} True on success.
136
+ * @ignore
137
+ */
138
+ static _pushArrayBuffer(gen: Encoder, obj: ArrayBuffer): boolean;
139
+ /**
140
+ * Encode the given object with indefinite length. There are apparently
141
+ * some (IMO) broken implementations of poorly-specified protocols that
142
+ * REQUIRE indefinite-encoding. See the example for how to add this as an
143
+ * `encodeCBOR` function to an object or class to get indefinite encoding.
144
+ *
145
+ * @param {Encoder} gen The encoder to use.
146
+ * @param {string|Buffer|Array|Map|object} [obj] The object to encode. If
147
+ * null, use "this" instead.
148
+ * @param {EncodingOptions} [options={}] Options for encoding.
149
+ * @returns {boolean} True on success.
150
+ * @throws {Error} No object to encode or invalid indefinite encoding.
151
+ * @example <caption>Force indefinite encoding:</caption>
152
+ * const o = {
153
+ * a: true,
154
+ * encodeCBOR: cbor.Encoder.encodeIndefinite,
155
+ * }
156
+ * const m = []
157
+ * m.encodeCBOR = cbor.Encoder.encodeIndefinite
158
+ * cbor.encodeOne([o, m])
159
+ */
160
+ static encodeIndefinite(gen: Encoder, obj?: string | Buffer | any[] | Map<any, any> | object, options?: EncodingOptions): boolean;
161
+ /**
162
+ * Encode one or more JavaScript objects, and return a Buffer containing the
163
+ * CBOR bytes.
164
+ *
165
+ * @param {...any} objs The objects to encode.
166
+ * @returns {Buffer} The encoded objects.
167
+ */
168
+ static encode(...objs: any[]): Buffer;
169
+ /**
170
+ * Encode one or more JavaScript objects canonically (slower!), and return
171
+ * a Buffer containing the CBOR bytes.
172
+ *
173
+ * @param {...any} objs The objects to encode.
174
+ * @returns {Buffer} The encoded objects.
175
+ */
176
+ static encodeCanonical(...objs: any[]): Buffer;
177
+ /**
178
+ * Encode one JavaScript object using the given options.
179
+ *
180
+ * @param {any} obj The object to encode.
181
+ * @param {EncodingOptions} [options={}] Passed to the Encoder constructor.
182
+ * @returns {Buffer} The encoded objects.
183
+ * @static
184
+ */
185
+ static encodeOne(obj: any, options?: EncodingOptions): Buffer;
186
+ /**
187
+ * Encode one JavaScript object using the given options in a way that
188
+ * is more resilient to objects being larger than the highWaterMark
189
+ * number of bytes. As with the other static encode functions, this
190
+ * will still use a large amount of memory. Use a stream-based approach
191
+ * directly if you need to process large and complicated inputs.
192
+ *
193
+ * @param {any} obj The object to encode.
194
+ * @param {EncodingOptions} [options={}] Passed to the Encoder constructor.
195
+ * @returns {Promise<Buffer>} A promise for the encoded buffer.
196
+ */
197
+ static encodeAsync(obj: any, options?: EncodingOptions): Promise<Buffer>;
198
+ static set SEMANTIC_TYPES(arg: {
199
+ [x: string]: EncodeFunction;
200
+ });
201
+ /**
202
+ * The currently supported set of semantic types. May be modified by plugins.
203
+ *
204
+ * @type {SemanticMap}
205
+ */
206
+ static get SEMANTIC_TYPES(): {
207
+ [x: string]: EncodeFunction;
208
+ };
209
+ /**
210
+ * Reset the supported semantic types to the original set, before any
211
+ * plugins modified the list.
212
+ */
213
+ static reset(): void;
214
+ /**
215
+ * Creates an instance of Encoder.
216
+ *
217
+ * @param {EncodingOptions} [options={}] Options for the encoder.
218
+ */
219
+ constructor(options?: EncodingOptions);
220
+ canonical: boolean;
221
+ encodeUndefined: any;
222
+ disallowUndefinedKeys: boolean;
223
+ dateType: "string" | "number" | "float" | "int";
224
+ collapseBigIntegers: boolean;
225
+ /** @type {WeakSet?} */
226
+ detectLoops: WeakSet<any> | null;
227
+ omitUndefinedProperties: boolean;
228
+ semanticTypes: {
229
+ [x: string]: EncodeFunction;
230
+ };
231
+ /**
232
+ * @param {number} val Number(0-255) to encode.
233
+ * @returns {boolean} True on success.
234
+ * @ignore
235
+ */
236
+ _pushUInt8(val: number): boolean;
237
+ /**
238
+ * @param {number} val Number(0-65535) to encode.
239
+ * @returns {boolean} True on success.
240
+ * @ignore
241
+ */
242
+ _pushUInt16BE(val: number): boolean;
243
+ /**
244
+ * @param {number} val Number(0..2**32-1) to encode.
245
+ * @returns {boolean} True on success.
246
+ * @ignore
247
+ */
248
+ _pushUInt32BE(val: number): boolean;
249
+ /**
250
+ * @param {number} val Number to encode as 4-byte float.
251
+ * @returns {boolean} True on success.
252
+ * @ignore
253
+ */
254
+ _pushFloatBE(val: number): boolean;
255
+ /**
256
+ * @param {number} val Number to encode as 8-byte double.
257
+ * @returns {boolean} True on success.
258
+ * @ignore
259
+ */
260
+ _pushDoubleBE(val: number): boolean;
261
+ /**
262
+ * @returns {boolean} True on success.
263
+ * @ignore
264
+ */
265
+ _pushNaN(): boolean;
266
+ /**
267
+ * @param {number} obj Positive or negative infinity.
268
+ * @returns {boolean} True on success.
269
+ * @ignore
270
+ */
271
+ _pushInfinity(obj: number): boolean;
272
+ /**
273
+ * Choose the best float representation for a number and encode it.
274
+ *
275
+ * @param {number} obj A number that is known to be not-integer, but not
276
+ * how many bytes of precision it needs.
277
+ * @returns {boolean} True on success.
278
+ * @ignore
279
+ */
280
+ _pushFloat(obj: number): boolean;
281
+ /**
282
+ * Choose the best integer representation for a postive number and encode
283
+ * it. If the number is over MAX_SAFE_INTEGER, fall back on float (but I
284
+ * don't remember why).
285
+ *
286
+ * @param {number} obj A positive number that is known to be an integer,
287
+ * but not how many bytes of precision it needs.
288
+ * @param {number} mt The Major Type number to combine with the integer.
289
+ * Not yet shifted.
290
+ * @param {number} [orig] The number before it was transformed to positive.
291
+ * If the mt is NEG_INT, and the positive number is over MAX_SAFE_INT,
292
+ * then we'll encode this as a float rather than making the number
293
+ * negative again and losing precision.
294
+ * @returns {boolean} True on success.
295
+ * @ignore
296
+ */
297
+ _pushInt(obj: number, mt: number, orig?: number): boolean;
298
+ /**
299
+ * Choose the best integer representation for a number and encode it.
300
+ *
301
+ * @param {number} obj A number that is known to be an integer,
302
+ * but not how many bytes of precision it needs.
303
+ * @returns {boolean} True on success.
304
+ * @ignore
305
+ */
306
+ _pushIntNum(obj: number): boolean;
307
+ /**
308
+ * @param {number} obj Plain JS number to encode.
309
+ * @returns {boolean} True on success.
310
+ * @ignore
311
+ */
312
+ _pushNumber(obj: number): boolean;
313
+ /**
314
+ * @param {string} obj String to encode.
315
+ * @returns {boolean} True on success.
316
+ * @ignore
317
+ */
318
+ _pushString(obj: string): boolean;
319
+ /**
320
+ * @param {boolean} obj Bool to encode.
321
+ * @returns {boolean} True on success.
322
+ * @ignore
323
+ */
324
+ _pushBoolean(obj: boolean): boolean;
325
+ /**
326
+ * @param {undefined} obj Ignored.
327
+ * @returns {boolean} True on success.
328
+ * @ignore
329
+ */
330
+ _pushUndefined(obj: undefined): boolean;
331
+ /**
332
+ * @param {null} obj Ignored.
333
+ * @returns {boolean} True on success.
334
+ * @ignore
335
+ */
336
+ _pushNull(obj: null): boolean;
337
+ /**
338
+ * @param {number} tag Tag number to encode.
339
+ * @returns {boolean} True on success.
340
+ * @ignore
341
+ */
342
+ _pushTag(tag: number): boolean;
343
+ /**
344
+ * @param {bigint} obj BigInt to encode.
345
+ * @returns {boolean} True on success.
346
+ * @ignore
347
+ */
348
+ _pushJSBigint(obj: bigint): boolean;
349
+ /**
350
+ * @param {object} obj Object to encode.
351
+ * @param {ObjectOptions} [opts] Options for encoding this object.
352
+ * @returns {boolean} True on success.
353
+ * @throws {Error} Loop detected.
354
+ * @ignore
355
+ */
356
+ _pushObject(obj: object, opts?: ObjectOptions): boolean;
357
+ /**
358
+ * @param {any[]} objs Array of supported things.
359
+ * @returns {Buffer} Concatenation of encodings for the supported things.
360
+ * @ignore
361
+ */
362
+ _encodeAll(objs: any[]): Buffer;
363
+ /**
364
+ * Add an encoding function to the list of supported semantic types. This
365
+ * is useful for objects for which you can't add an encodeCBOR method.
366
+ *
367
+ * @param {string|Function} type The type to encode.
368
+ * @param {EncodeFunction} fun The encoder to use.
369
+ * @returns {EncodeFunction?} The previous encoder or undefined if there
370
+ * wasn't one.
371
+ * @throws {TypeError} Invalid function.
372
+ */
373
+ addSemanticType(type: string | Function, fun: EncodeFunction): EncodeFunction | null;
374
+ /**
375
+ * Push any supported type onto the encoded stream.
376
+ *
377
+ * @param {any} obj The thing to encode.
378
+ * @returns {boolean} True on success.
379
+ * @throws {TypeError} Unknown type for obj.
380
+ */
381
+ pushAny(obj: any): boolean;
382
+ /**
383
+ * Remove the loop detector WeakSet for this Encoder.
384
+ *
385
+ * @returns {boolean} True when the Encoder was reset, else false.
386
+ */
387
+ removeLoopDetectors(): boolean;
388
+ }
389
+ declare namespace Encoder {
390
+ export { EncodeFunction, SemanticMap, ObjectOptions, EncodingOptions };
391
+ }
392
+ import stream = require("stream");
393
+ /**
394
+ * Generate the CBOR for a value. If you are using this, you'll either need
395
+ * to call {@link Encoder.write } with a Buffer, or look into the internals of
396
+ * Encoder to reuse existing non-documented behavior.
397
+ */
398
+ type EncodeFunction = (enc: Encoder, val: any) => boolean;
399
+ type ObjectOptions = {
400
+ /**
401
+ * Force indefinite encoding for this
402
+ * object.
403
+ */
404
+ indefinite?: boolean;
405
+ /**
406
+ * Do not use available type mappings
407
+ * for this object, but encode it as a "normal" JS object would be.
408
+ */
409
+ skipTypes?: boolean;
410
+ };
411
+ import { Buffer } from "buffer";
412
+ import NoFilter = require("nofilter");
413
+ type EncodingOptions = {
414
+ /**
415
+ * Array of pairs of
416
+ * `type`, `function(Encoder)` for semantic types to be encoded. Not
417
+ * needed for Array, Date, Buffer, Map, RegExp, Set, or URL.
418
+ * If an object, the keys are the constructor names for the types.
419
+ */
420
+ genTypes?: any[] | object;
421
+ /**
422
+ * Should the output be
423
+ * canonicalized.
424
+ */
425
+ canonical?: boolean;
426
+ /**
427
+ * Should object loops
428
+ * be detected? This will currently add memory to track every part of the
429
+ * object being encoded in a WeakSet. Do not encode
430
+ * the same object twice on the same encoder, without calling
431
+ * `removeLoopDetectors` in between, which will clear the WeakSet.
432
+ * You may pass in your own WeakSet to be used; this is useful in some
433
+ * recursive scenarios.
434
+ */
435
+ detectLoops?: boolean | WeakSet<any>;
436
+ /**
437
+ * -
438
+ * how should dates be encoded? "number" means float or int, if no
439
+ * fractional seconds.
440
+ */
441
+ dateType?: ("number" | "float" | "int" | "string");
442
+ /**
443
+ * How should an
444
+ * "undefined" in the input be encoded. By default, just encode a CBOR
445
+ * undefined. If this is a buffer, use those bytes without re-encoding
446
+ * them. If this is a function, the function will be called (which is a
447
+ * good time to throw an exception, if that's what you want), and the
448
+ * return value will be used according to these rules. Anything else will
449
+ * be encoded as CBOR.
450
+ */
451
+ encodeUndefined?: any;
452
+ /**
453
+ * Should
454
+ * "undefined" be disallowed as a key in a Map that is serialized? If
455
+ * this is true, encode(new Map([[undefined, 1]])) will throw an
456
+ * exception. Note that it is impossible to get a key of undefined in a
457
+ * normal JS object.
458
+ */
459
+ disallowUndefinedKeys?: boolean;
460
+ /**
461
+ * Should integers
462
+ * that come in as ECMAscript bigint's be encoded
463
+ * as normal CBOR integers if they fit, discarding type information?
464
+ */
465
+ collapseBigIntegers?: boolean;
466
+ /**
467
+ * Number of characters or bytes
468
+ * for each chunk, if obj is a string or Buffer, when indefinite encoding.
469
+ */
470
+ chunkSize?: number;
471
+ /**
472
+ * When encoding
473
+ * objects or Maps, do not include a key if its corresponding value is
474
+ * `undefined`.
475
+ */
476
+ omitUndefinedProperties?: boolean;
477
+ };
478
+ /**
479
+ * A mapping from tag number to a tag decoding function.
480
+ */
481
+ type SemanticMap = {
482
+ [x: string]: EncodeFunction;
483
+ };
@@ -0,0 +1,81 @@
1
+ export = CborMap;
2
+ /**
3
+ * Wrapper around a JavaScript Map object that allows the keys to be
4
+ * any complex type. The base Map object allows this, but will only
5
+ * compare the keys by identity, not by value. CborMap translates keys
6
+ * to CBOR first (and base64's them to ensure by-value comparison).
7
+ *
8
+ * This is not a subclass of Object, because it would be tough to get
9
+ * the semantics to be an exact match.
10
+ *
11
+ * @extends Map
12
+ */
13
+ declare class CborMap extends Map<any, any> {
14
+ /**
15
+ * @ignore
16
+ */
17
+ static _encode(key: any): string;
18
+ /**
19
+ * @ignore
20
+ */
21
+ static _decode(key: any): any;
22
+ /**
23
+ * Creates an instance of CborMap.
24
+ *
25
+ * @param {Iterable<any>} [iterable] An Array or other iterable
26
+ * object whose elements are key-value pairs (arrays with two elements, e.g.
27
+ * <code>[[ 1, 'one' ],[ 2, 'two' ]]</code>). Each key-value pair is added
28
+ * to the new CborMap; null values are treated as undefined.
29
+ */
30
+ constructor(iterable?: Iterable<any>);
31
+ /**
32
+ * Adds or updates an element with a specified key and value.
33
+ *
34
+ * @param {any} key The key identifying the element to store.
35
+ * Can be any type, which will be serialized into CBOR and compared by
36
+ * value.
37
+ * @param {any} val The element to store.
38
+ * @returns {this} This object.
39
+ */
40
+ set(key: any, val: any): this;
41
+ /**
42
+ * Returns a new Iterator object that contains the keys for each element
43
+ * in the Map object in insertion order. The keys are decoded into their
44
+ * original format.
45
+ *
46
+ * @yields {any} The keys of the map.
47
+ */
48
+ keys(): Generator<any, void, unknown>;
49
+ /**
50
+ * Returns a new Iterator object that contains the [key, value] pairs for
51
+ * each element in the Map object in insertion order.
52
+ *
53
+ * @returns {IterableIterator<any>} Key value pairs.
54
+ * @yields {any[]} Key value pairs.
55
+ */
56
+ entries(): IterableIterator<any>;
57
+ /**
58
+ * Executes a provided function once per each key/value pair in the Map
59
+ * object, in insertion order.
60
+ *
61
+ * @param {function(any, any, Map): undefined} fun Function to execute for
62
+ * each element, which takes a value, a key, and the Map being traversed.
63
+ * @param {any} thisArg Value to use as this when executing callback.
64
+ * @throws {TypeError} Invalid function.
65
+ */
66
+ forEach(fun: (arg0: any, arg1: any, arg2: Map<any, any>) => undefined, thisArg: any): void;
67
+ /**
68
+ * Push the simple value onto the CBOR stream.
69
+ *
70
+ * @param {object} gen The generator to push onto.
71
+ * @returns {boolean} True on success.
72
+ */
73
+ encodeCBOR(gen: object): boolean;
74
+ /**
75
+ * Returns a new Iterator object that contains the [key, value] pairs for
76
+ * each element in the Map object in insertion order.
77
+ *
78
+ * @returns {IterableIterator} Key value pairs.
79
+ */
80
+ [Symbol.iterator](): IterableIterator<any>;
81
+ }
@@ -0,0 +1,36 @@
1
+ export = ObjectRecorder;
2
+ /**
3
+ * Record objects that pass by in a stream. If the same object is used more
4
+ * than once, it can be value-shared using shared values.
5
+ *
6
+ * @see {@link http://cbor.schmorp.de/value-sharing}
7
+ */
8
+ declare class ObjectRecorder {
9
+ /**
10
+ * Clear all of the objects that have been seen. Revert to recording mode.
11
+ */
12
+ clear(): void;
13
+ map: WeakMap<object, any>;
14
+ count: number;
15
+ recording: boolean;
16
+ /**
17
+ * Stop recording.
18
+ */
19
+ stop(): void;
20
+ /**
21
+ * Determine if wrapping a tag 28 or 29 around an object that has been
22
+ * reused is appropriate. This method stores state for which objects have
23
+ * been seen.
24
+ *
25
+ * @param {object} obj Any object about to be serialized.
26
+ * @returns {number} If recording: -1 for first use, index for second use.
27
+ * If not recording, -1 for never-duplicated, -2 for first use, index for
28
+ * subsequent uses.
29
+ * @throws {Error} Recording does not match playback.
30
+ */
31
+ check(obj: object): number;
32
+ }
33
+ declare namespace ObjectRecorder {
34
+ const NEVER: number;
35
+ const FIRST: number;
36
+ }
@@ -0,0 +1,21 @@
1
+ export = SharedValueEncoder;
2
+ /**
3
+ * Implement value sharing.
4
+ *
5
+ * @see {@link cbor.schmorp.de/value-sharing}
6
+ */
7
+ declare class SharedValueEncoder extends Encoder {
8
+ constructor(opts: any);
9
+ valueSharing: ObjectRecorder;
10
+ /**
11
+ * Between encoding runs, stop recording, and start outputing correct tags.
12
+ */
13
+ stopRecording(): void;
14
+ /**
15
+ * Remove the existing recording and start over. Do this between encoding
16
+ * pairs.
17
+ */
18
+ clearRecording(): void;
19
+ }
20
+ import Encoder = require("./encoder");
21
+ import ObjectRecorder = require("./objectRecorder");
@@ -0,0 +1,47 @@
1
+ export = Simple;
2
+ /**
3
+ * A CBOR Simple Value that does not map onto a known constant.
4
+ */
5
+ declare class Simple {
6
+ /**
7
+ * Is the given object a Simple?
8
+ *
9
+ * @param {any} obj Object to test.
10
+ * @returns {boolean} Is it Simple?
11
+ */
12
+ static isSimple(obj: any): boolean;
13
+ /**
14
+ * Decode from the CBOR additional information into a JavaScript value.
15
+ * If the CBOR item has no parent, return a "safe" symbol instead of
16
+ * `null` or `undefined`, so that the value can be passed through a
17
+ * stream in object mode.
18
+ *
19
+ * @param {number} val The CBOR additional info to convert.
20
+ * @param {boolean} [has_parent=true] Does the CBOR item have a parent?
21
+ * @param {boolean} [parent_indefinite=false] Is the parent element
22
+ * indefinitely encoded?
23
+ * @returns {(null|undefined|boolean|symbol|Simple)} The decoded value.
24
+ * @throws {Error} Invalid BREAK.
25
+ */
26
+ static decode(val: number, has_parent?: boolean, parent_indefinite?: boolean): (null | undefined | boolean | symbol | Simple);
27
+ /**
28
+ * Creates an instance of Simple.
29
+ *
30
+ * @param {number} value The simple value's integer value.
31
+ */
32
+ constructor(value: number);
33
+ value: number;
34
+ /**
35
+ * Debug string for simple value.
36
+ *
37
+ * @returns {string} Formated string of `simple(value)`.
38
+ */
39
+ toString(): string;
40
+ /**
41
+ * Push the simple value onto the CBOR stream.
42
+ *
43
+ * @param {object} gen The generator to push onto.
44
+ * @returns {boolean} True on success.
45
+ */
46
+ encodeCBOR(gen: object): boolean;
47
+ }