UNPKG

@jsonjoy.com/json-type

Version:

High-performance JSON Pointer implementation

44 lines (43 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Value = void 0; class Value { constructor(type, data) { this.type = type; this.data = data; } encode(codec) { const value = this.data; const type = this.type; if (value === undefined) return; const encoder = codec.encoder; if (!type) encoder.writeAny(value); else type.encoder(codec.format)(value, encoder); } } exports.Value = Value; if (process.env.NODE_ENV !== 'production') { const encode = Value.prototype.encode; Value.prototype.encode = function (codec) { try { encode.call(this, codec); } catch (error) { try { // tslint:disable-next-line no-console console.error(error); const type = this.type; if (type) { const err = type.validator('object')(this.data); // tslint:disable-next-line no-console console.error(err); } } catch { } throw error; } }; }