UNPKG

helene

Version:
57 lines 2.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EJSON = void 0; const clone_1 = require("./clone"); const equals_1 = require("./equals"); const is_binary_1 = require("./is-binary"); const parse_1 = require("./parse"); const stringify_1 = require("./stringify"); const from_json_value_1 = require("./from-json-value"); const to_json_value_1 = require("./to-json-value"); const utils_1 = require("./utils"); const built_in_converters_1 = require("./built-in-converters"); const custom_types_1 = require("./custom-types"); const adjust_types_from_json_value_1 = require("./adjust-types-from-json-value"); const adjust_types_to_json_value_1 = require("./helpers/adjust-types-to-json-value"); exports.EJSON = { clone: clone_1.clone, equals: equals_1.equals, isBinary: is_binary_1.isBinary, parse: parse_1.parse, stringify: stringify_1.stringify, fromJSONValue: from_json_value_1.fromJSONValue, toJSONValue: to_json_value_1.toJSONValue, newBinary: utils_1.newBinary, /** * @summary Add a custom datatype to EJSON. * @locus Anywhere * @param {String} name A tag for your custom type; must be unique among * custom data types defined in your project, and must * match the result of your type's `typeName` method. * @param {Function} factory A function that deserializes a JSON-compatible * value into an instance of your type. This should * match the serialization performed by your * type's `toJSONValue` method. */ addType(name, factory) { if (custom_types_1.customTypes.has(name)) { throw new Error(`Type ${name} already present`); } custom_types_1.customTypes.set(name, factory); }, _isCustomType(obj) { return (obj && (0, utils_1.isFunction)(obj.toJSONValue) && (0, utils_1.isFunction)(obj.typeName) && custom_types_1.customTypes.has(obj.typeName())); }, _getTypes(isOriginal = false) { return isOriginal ? custom_types_1.customTypes : (0, utils_1.convertMapToObject)(custom_types_1.customTypes); }, _getConverters() { return built_in_converters_1.builtinConverters; }, _adjustTypesToJSONValue: adjust_types_to_json_value_1.adjustTypesToJSONValue, _adjustTypesFromJSONValue: adjust_types_from_json_value_1.adjustTypesFromJSONValue, }; //# sourceMappingURL=index.js.map