@sinclair/typebox
Version:
JSONSchema Type Builder with Static Type Resolution for TypeScript
71 lines (63 loc) • 3.04 kB
JavaScript
;
/*--------------------------------------------------------------------------
@sinclair/typebox
The MIT License (MIT)
Copyright (c) 2022 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
---------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Value = exports.EditType = void 0;
const create_1 = require("./create");
const check_1 = require("./check");
const clone_1 = require("./clone");
const delta_1 = require("./delta");
const upcast_1 = require("./upcast");
var delta_2 = require("./delta");
Object.defineProperty(exports, "EditType", { enumerable: true, get: function () { return delta_2.EditType; } });
var Value;
(function (Value) {
/** Returns true if the value conforms to the given schema */
function Check(schema, value) {
return check_1.CheckValue.Check(schema, value);
}
Value.Check = Check;
/** Returns a deep clone of the given value */
function Clone(value) {
return clone_1.CloneValue.Create(value);
}
Value.Clone = Clone;
/** Creates a value from the given schema type */
function Create(schema) {
return create_1.CreateValue.Create(schema);
}
Value.Create = Create;
/** Diffs the value and produces edits to transform the value into the next value */
function Diff(value, next) {
return delta_1.DeltaValue.Diff(value, next);
}
Value.Diff = Diff;
/** Patches a value by applying a series of edits */
function Patch(value, edits) {
return delta_1.DeltaValue.Edit(value, edits);
}
Value.Patch = Patch;
/** Upcasts a value to match a schema while preserving as much information from the original value as possible. */
function Upcast(schema, value) {
return upcast_1.UpcastValue.Create(schema, value);
}
Value.Upcast = Upcast;
})(Value = exports.Value || (exports.Value = {}));