@sinclair/typebox 0.29.6 → 0.30.0-dev-1

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.
package/value/value.js CHANGED
@@ -28,72 +28,72 @@ THE SOFTWARE.
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.Value = void 0;
31
- const index_1 = require("../errors/index");
32
- const mutate_1 = require("./mutate");
33
- const hash_1 = require("./hash");
34
- const equal_1 = require("./equal");
35
- const cast_1 = require("./cast");
36
- const clone_1 = require("./clone");
37
- const convert_1 = require("./convert");
38
- const create_1 = require("./create");
39
- const check_1 = require("./check");
40
- const delta_1 = require("./delta");
41
- /** Provides functions to perform structural updates to JavaScript values */
31
+ const ValueErrors = require("../errors/index");
32
+ const ValueMutate = require("./mutate");
33
+ const ValueHash = require("./hash");
34
+ const ValueEqual = require("./equal");
35
+ const ValueCast = require("./cast");
36
+ const ValueClone = require("./clone");
37
+ const ValueConvert = require("./convert");
38
+ const ValueCreate = require("./create");
39
+ const ValueCheck = require("./check");
40
+ const ValueDelta = require("./delta");
41
+ /** Functions to perform structural operations on JavaScript values */
42
42
  var Value;
43
43
  (function (Value) {
44
+ /** Casts a value into a given type. The return value will retain as much information of the original value as possible. */
44
45
  function Cast(...args) {
45
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
46
- return cast_1.ValueCast.Cast(schema, references, value);
46
+ return ValueCast.Cast.apply(ValueCast, args);
47
47
  }
48
48
  Value.Cast = Cast;
49
+ /** Creates a value from the given type */
49
50
  function Create(...args) {
50
- const [schema, references] = args.length === 2 ? [args[0], args[1]] : [args[0], []];
51
- return create_1.ValueCreate.Create(schema, references);
51
+ return ValueCreate.Create.apply(ValueCreate, args);
52
52
  }
53
53
  Value.Create = Create;
54
+ /** Returns true if the value matches the given type. */
54
55
  function Check(...args) {
55
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
56
- return check_1.ValueCheck.Check(schema, references, value);
56
+ return ValueCheck.Check.apply(ValueCheck, args);
57
57
  }
58
58
  Value.Check = Check;
59
+ /** Converts any type mismatched values to their target type if a conversion is possible. */
59
60
  function Convert(...args) {
60
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
61
- return convert_1.ValueConvert.Convert(schema, references, value);
61
+ return ValueConvert.Convert.apply(ValueConvert, args);
62
62
  }
63
63
  Value.Convert = Convert;
64
64
  /** Returns a structural clone of the given value */
65
65
  function Clone(value) {
66
- return clone_1.ValueClone.Clone(value);
66
+ return ValueClone.Clone(value);
67
67
  }
68
68
  Value.Clone = Clone;
69
+ /** Returns an iterator for each error in this value. */
69
70
  function Errors(...args) {
70
- const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
71
- return index_1.ValueErrors.Errors(schema, references, value);
71
+ return ValueErrors.Errors.apply(ValueErrors, args);
72
72
  }
73
73
  Value.Errors = Errors;
74
74
  /** Returns true if left and right values are structurally equal */
75
75
  function Equal(left, right) {
76
- return equal_1.ValueEqual.Equal(left, right);
76
+ return ValueEqual.Equal(left, right);
77
77
  }
78
78
  Value.Equal = Equal;
79
79
  /** Returns edits to transform the current value into the next value */
80
80
  function Diff(current, next) {
81
- return delta_1.ValueDelta.Diff(current, next);
81
+ return ValueDelta.Diff(current, next);
82
82
  }
83
83
  Value.Diff = Diff;
84
84
  /** Returns a FNV1A-64 non cryptographic hash of the given value */
85
85
  function Hash(value) {
86
- return hash_1.ValueHash.Create(value);
86
+ return ValueHash.Hash(value);
87
87
  }
88
88
  Value.Hash = Hash;
89
89
  /** Returns a new value with edits applied to the given value */
90
90
  function Patch(current, edits) {
91
- return delta_1.ValueDelta.Patch(current, edits);
91
+ return ValueDelta.Patch(current, edits);
92
92
  }
93
93
  Value.Patch = Patch;
94
94
  /** Performs a deep mutable value assignment while retaining internal references. */
95
95
  function Mutate(current, next) {
96
- mutate_1.ValueMutate.Mutate(current, next);
96
+ ValueMutate.Mutate(current, next);
97
97
  }
98
98
  Value.Mutate = Mutate;
99
99
  })(Value || (exports.Value = Value = {}));
package/value/is.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export type ValueType = null | undefined | Function | symbol | bigint | number | boolean | string;
2
- export type ObjectType = Record<string | number | symbol, unknown>;
3
- export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | BigInt64Array | BigUint64Array;
4
- export type ArrayType = unknown[];
5
- export declare namespace Is {
6
- function Object(value: unknown): value is ObjectType;
7
- function Date(value: unknown): value is Date;
8
- function Array(value: unknown): value is ArrayType;
9
- function Value(value: unknown): value is ValueType;
10
- function TypedArray(value: unknown): value is TypedArrayType;
11
- }
package/value/is.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- /*--------------------------------------------------------------------------
3
-
4
- @sinclair/typebox/value
5
-
6
- The MIT License (MIT)
7
-
8
- Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in
18
- all copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
- THE SOFTWARE.
27
-
28
- ---------------------------------------------------------------------------*/
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.Is = void 0;
31
- var Is;
32
- (function (Is) {
33
- function Object(value) {
34
- return value !== null && typeof value === 'object' && !globalThis.Array.isArray(value) && !ArrayBuffer.isView(value) && !(value instanceof globalThis.Date);
35
- }
36
- Is.Object = Object;
37
- function Date(value) {
38
- return value instanceof globalThis.Date;
39
- }
40
- Is.Date = Date;
41
- function Array(value) {
42
- return globalThis.Array.isArray(value) && !ArrayBuffer.isView(value);
43
- }
44
- Is.Array = Array;
45
- function Value(value) {
46
- return value === null || value === undefined || typeof value === 'function' || typeof value === 'symbol' || typeof value === 'bigint' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'string';
47
- }
48
- Is.Value = Value;
49
- function TypedArray(value) {
50
- return ArrayBuffer.isView(value);
51
- }
52
- Is.TypedArray = TypedArray;
53
- })(Is || (exports.Is = Is = {}));