@sinclair/typebox 0.32.14 → 0.32.16

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.
Files changed (58) hide show
  1. package/build/import/compiler/index.d.mts +1 -1
  2. package/build/import/compiler/index.mjs +1 -1
  3. package/build/import/errors/index.d.mts +2 -2
  4. package/build/import/errors/index.mjs +2 -2
  5. package/build/import/system/index.d.mts +2 -2
  6. package/build/import/system/index.mjs +2 -2
  7. package/build/import/system/system.d.mts +1 -1
  8. package/build/import/type/indexed/indexed.d.mts +1 -1
  9. package/build/import/type/indexed/indexed.mjs +3 -1
  10. package/build/import/type/template-literal/parse.mjs +24 -5
  11. package/build/import/type/template-literal/syntax.d.mts +1 -1
  12. package/build/import/value/cast/cast.mjs +2 -2
  13. package/build/import/value/clone/clone.mjs +2 -2
  14. package/build/import/value/convert/convert.mjs +2 -15
  15. package/build/import/value/delta/delta.d.mts +22 -22
  16. package/build/import/value/delta/delta.mjs +3 -3
  17. package/build/import/value/equal/equal.mjs +3 -3
  18. package/build/import/value/guard/guard.d.mts +34 -6
  19. package/build/import/value/guard/guard.mjs +71 -12
  20. package/build/import/value/hash/hash.mjs +2 -2
  21. package/build/import/value/index.d.mts +14 -14
  22. package/build/import/value/index.mjs +18 -18
  23. package/build/import/value/mutate/mutate.mjs +5 -5
  24. package/build/import/value/transform/decode.d.mts +3 -1
  25. package/build/import/value/transform/decode.mjs +62 -56
  26. package/build/import/value/transform/encode.d.mts +3 -1
  27. package/build/import/value/transform/encode.mjs +60 -54
  28. package/build/import/value/value/value.mjs +1 -1
  29. package/build/require/compiler/index.d.ts +1 -1
  30. package/build/require/compiler/index.js +16 -6
  31. package/build/require/errors/index.d.ts +2 -2
  32. package/build/require/errors/index.js +16 -10
  33. package/build/require/system/index.d.ts +2 -2
  34. package/build/require/system/index.js +16 -7
  35. package/build/require/system/system.d.ts +1 -1
  36. package/build/require/type/indexed/indexed.d.ts +1 -1
  37. package/build/require/type/indexed/indexed.js +3 -1
  38. package/build/require/type/template-literal/parse.js +24 -5
  39. package/build/require/type/template-literal/syntax.d.ts +1 -1
  40. package/build/require/value/cast/cast.js +1 -1
  41. package/build/require/value/clone/clone.js +1 -1
  42. package/build/require/value/convert/convert.js +33 -46
  43. package/build/require/value/delta/delta.d.ts +22 -22
  44. package/build/require/value/delta/delta.js +2 -2
  45. package/build/require/value/equal/equal.js +2 -2
  46. package/build/require/value/guard/guard.d.ts +34 -6
  47. package/build/require/value/guard/guard.js +89 -16
  48. package/build/require/value/hash/hash.js +1 -1
  49. package/build/require/value/index.d.ts +14 -14
  50. package/build/require/value/index.js +35 -71
  51. package/build/require/value/mutate/mutate.js +4 -4
  52. package/build/require/value/transform/decode.d.ts +3 -1
  53. package/build/require/value/transform/decode.js +59 -55
  54. package/build/require/value/transform/encode.d.ts +3 -1
  55. package/build/require/value/transform/encode.js +57 -53
  56. package/build/require/value/value/value.js +1 -1
  57. package/package.json +1 -1
  58. package/readme.md +1 -0
@@ -1,2 +1,2 @@
1
1
  export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
2
- export { TypeCompiler, TypeCheck, type TypeCompilerCodegenOptions, type TypeCompilerLanguageOption, TypeCompilerTypeGuardError, TypeCompilerUnknownTypeError } from './compiler.mjs';
2
+ export * from './compiler.mjs';
@@ -1,2 +1,2 @@
1
1
  export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
2
- export { TypeCompiler, TypeCheck, TypeCompilerTypeGuardError, TypeCompilerUnknownTypeError } from './compiler.mjs';
2
+ export * from './compiler.mjs';
@@ -1,2 +1,2 @@
1
- export { Errors, ValueError, ValueErrorIterator, ValueErrorType, ValueErrorsUnknownTypeError } from './errors.mjs';
2
- export { DefaultErrorFunction, GetErrorFunction, SetErrorFunction, type ErrorFunction, type ErrorFunctionParameter } from './function.mjs';
1
+ export * from './errors.mjs';
2
+ export * from './function.mjs';
@@ -1,2 +1,2 @@
1
- export { Errors, ValueErrorIterator, ValueErrorType, ValueErrorsUnknownTypeError } from './errors.mjs';
2
- export { DefaultErrorFunction, GetErrorFunction, SetErrorFunction } from './function.mjs';
1
+ export * from './errors.mjs';
2
+ export * from './function.mjs';
@@ -1,2 +1,2 @@
1
- export { TypeSystemPolicy } from './policy.mjs';
2
- export { TypeSystem, TypeSystemDuplicateFormat, TypeSystemDuplicateTypeKind } from './system.mjs';
1
+ export * from './policy.mjs';
2
+ export * from './system.mjs';
@@ -1,2 +1,2 @@
1
- export { TypeSystemPolicy } from './policy.mjs';
2
- export { TypeSystem, TypeSystemDuplicateFormat, TypeSystemDuplicateTypeKind } from './system.mjs';
1
+ export * from './policy.mjs';
2
+ export * from './system.mjs';
@@ -8,7 +8,7 @@ export declare class TypeSystemDuplicateFormat extends TypeBoxError {
8
8
  /** Creates user defined types and formats and provides overrides for value checking behaviours */
9
9
  export declare namespace TypeSystem {
10
10
  /** Creates a new type */
11
- function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("../type/unsafe/unsafe.mjs").TUnsafe<Type>;
11
+ function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => import("src/type/unsafe/unsafe.mjs").TUnsafe<Type>;
12
12
  /** Creates a new string format */
13
13
  function Format<F extends string>(format: F, check: (value: string) => boolean): F;
14
14
  }
@@ -16,7 +16,7 @@ import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
16
16
  type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Acc);
17
17
  type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
18
18
  type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
19
- type TFromUnionRest<T extends TSchema[]> = T;
19
+ type TFromUnionRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [] : TFromUnionRest<R, [L, ...Acc]> : Acc;
20
20
  type TFromUnion<T extends TSchema[], K extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<T, K>>>);
21
21
  type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? TUnionEvaluated<T> : TNever);
22
22
  type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
@@ -23,7 +23,9 @@ function FromIntersect(T, K) {
23
23
  }
24
24
  // prettier-ignore
25
25
  function FromUnionRest(T) {
26
- return T; // review this
26
+ return (T.some(L => IsNever(L))
27
+ ? []
28
+ : T);
27
29
  }
28
30
  // prettier-ignore
29
31
  function FromUnion(T, K) {
@@ -4,23 +4,42 @@ import { TypeBoxError } from '../error/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  export class TemplateLiteralParserError extends TypeBoxError {
6
6
  }
7
+ // -------------------------------------------------------------------
8
+ // Unescape
9
+ //
10
+ // Unescape for these control characters specifically. Note that this
11
+ // function is only called on non union group content, and where we
12
+ // still want to allow the user to embed control characters in that
13
+ // content. For review.
14
+ // -------------------------------------------------------------------
7
15
  // prettier-ignore
16
+ function Unescape(pattern) {
17
+ return pattern
18
+ .replace(/\\\$/g, '$')
19
+ .replace(/\\\*/g, '*')
20
+ .replace(/\\\^/g, '^')
21
+ .replace(/\\\|/g, '|')
22
+ .replace(/\\\(/g, '(')
23
+ .replace(/\\\)/g, ')');
24
+ }
25
+ // -------------------------------------------------------------------
26
+ // Control Characters
27
+ // -------------------------------------------------------------------
8
28
  function IsNonEscaped(pattern, index, char) {
9
29
  return pattern[index] === char && pattern.charCodeAt(index - 1) !== 92;
10
30
  }
11
- // prettier-ignore
12
31
  function IsOpenParen(pattern, index) {
13
32
  return IsNonEscaped(pattern, index, '(');
14
33
  }
15
- // prettier-ignore
16
34
  function IsCloseParen(pattern, index) {
17
35
  return IsNonEscaped(pattern, index, ')');
18
36
  }
19
- // prettier-ignore
20
37
  function IsSeparator(pattern, index) {
21
38
  return IsNonEscaped(pattern, index, '|');
22
39
  }
23
- // prettier-ignore
40
+ // -------------------------------------------------------------------
41
+ // Control Groups
42
+ // -------------------------------------------------------------------
24
43
  function IsGroup(pattern) {
25
44
  if (!(IsOpenParen(pattern, 0) && IsCloseParen(pattern, pattern.length - 1)))
26
45
  return false;
@@ -137,7 +156,7 @@ export function TemplateLiteralParse(pattern) {
137
156
  return (IsGroup(pattern) ? TemplateLiteralParse(InGroup(pattern)) :
138
157
  IsPrecedenceOr(pattern) ? Or(pattern) :
139
158
  IsPrecedenceAnd(pattern) ? And(pattern) :
140
- { type: 'const', const: pattern });
159
+ { type: 'const', const: Unescape(pattern) });
141
160
  }
142
161
  // ------------------------------------------------------------------
143
162
  // TemplateLiteralParseExact
@@ -12,7 +12,7 @@ type FromUnionLiteral<T extends string> = T extends `${infer L}|${infer R}` ? [T
12
12
  ];
13
13
  type FromUnion<T extends string> = TUnionEvaluated<FromUnionLiteral<T>>;
14
14
  type FromTerminal<T extends string> = T extends 'boolean' ? TBoolean : T extends 'bigint' ? TBigInt : T extends 'number' ? TNumber : T extends 'string' ? TString : FromUnion<T>;
15
- type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$${infer R}` ? [TLiteral<L>, ...FromString<R>] : T extends `${infer L}` ? [TLiteral<L>] : [
15
+ type FromString<T extends string> = T extends `{${infer L}}${infer R}` ? [FromTerminal<L>, ...FromString<R>] : T extends `${infer L}$\{${infer R1}\}${infer R2}` ? [TLiteral<L>, ...FromString<`{${R1}}`>, ...FromString<R2>] : T extends `${infer L}$\{${infer R1}\}` ? [TLiteral<L>, ...FromString<`{${R1}}`>] : T extends `${infer L}` ? [TLiteral<L>] : [
16
16
  ];
17
17
  export type TTemplateLiteralSyntax<T extends string> = (TTemplateLiteral<Assert<FromString<T>, TTemplateLiteralKind[]>>);
18
18
  /** Parses TemplateLiteralSyntax and returns a tuple of TemplateLiteralKinds */
@@ -1,4 +1,4 @@
1
- import { IsPlainObject, IsArray, IsString, IsNumber, IsNull } from '../guard/index.mjs';
1
+ import { IsStandardObject, IsArray, IsString, IsNumber, IsNull } from '../guard/index.mjs';
2
2
  import { TypeBoxError } from '../../type/error/index.mjs';
3
3
  import { Kind } from '../../type/symbols/index.mjs';
4
4
  import { Create } from '../create/index.mjs';
@@ -100,7 +100,7 @@ function FromConstructor(schema, references, value) {
100
100
  }
101
101
  function FromIntersect(schema, references, value) {
102
102
  const created = Create(schema, references);
103
- const mapped = IsPlainObject(created) && IsPlainObject(value) ? { ...created, ...value } : value;
103
+ const mapped = IsStandardObject(created) && IsStandardObject(value) ? { ...created, ...value } : value;
104
104
  return Check(schema, references, mapped) ? mapped : Create(schema, references);
105
105
  }
106
106
  function FromNever(schema, references, value) {
@@ -1,7 +1,7 @@
1
1
  // ------------------------------------------------------------------
2
2
  // ValueGuard
3
3
  // ------------------------------------------------------------------
4
- import { IsArray, IsDate, IsPlainObject, IsTypedArray, IsValueType } from '../guard/index.mjs';
4
+ import { IsArray, IsDate, IsStandardObject, IsTypedArray, IsValueType } from '../guard/index.mjs';
5
5
  // ------------------------------------------------------------------
6
6
  // Clonable
7
7
  // ------------------------------------------------------------------
@@ -30,7 +30,7 @@ export function Clone(value) {
30
30
  return ArrayType(value);
31
31
  if (IsDate(value))
32
32
  return DateType(value);
33
- if (IsPlainObject(value))
33
+ if (IsStandardObject(value))
34
34
  return ObjectType(value);
35
35
  if (IsTypedArray(value))
36
36
  return TypedArrayType(value);
@@ -1,9 +1,6 @@
1
1
  import { Clone } from '../clone/index.mjs';
2
- import { Check } from '../check/index.mjs';
3
2
  import { Deref } from '../deref/index.mjs';
4
- import { IsObject as IsObjectType } from '../../type/guard/type.mjs';
5
3
  import { Kind } from '../../type/symbols/index.mjs';
6
- import { Composite } from '../../type/composite/index.mjs';
7
4
  // ------------------------------------------------------------------
8
5
  // ValueGuard
9
6
  // ------------------------------------------------------------------
@@ -129,12 +126,8 @@ function FromDate(schema, references, value) {
129
126
  function FromInteger(schema, references, value) {
130
127
  return TryConvertInteger(value);
131
128
  }
132
- // prettier-ignore
133
129
  function FromIntersect(schema, references, value) {
134
- const allObjects = schema.allOf.every(schema => IsObjectType(schema));
135
- if (allObjects)
136
- return Visit(Composite(schema.allOf), references, value);
137
- return Visit(schema.allOf[0], references, value); // todo: fix this
130
+ return schema.allOf.reduce((value, schema) => Visit(schema, references, value), value);
138
131
  }
139
132
  function FromLiteral(schema, references, value) {
140
133
  return TryConvertLiteral(schema, value);
@@ -192,13 +185,7 @@ function FromUndefined(schema, references, value) {
192
185
  return TryConvertUndefined(value);
193
186
  }
194
187
  function FromUnion(schema, references, value) {
195
- for (const subschema of schema.anyOf) {
196
- const converted = Visit(subschema, references, value);
197
- if (Check(subschema, references, converted)) {
198
- return converted;
199
- }
200
- }
201
- return value;
188
+ return schema.anyOf.reduce((value, schema) => Visit(schema, references, value), value);
202
189
  }
203
190
  function Visit(schema, references, value) {
204
191
  const references_ = IsString(schema.$id) ? [...references, schema] : references;
@@ -1,34 +1,34 @@
1
1
  import type { Static } from '../../type/static/index.mjs';
2
2
  import { TypeBoxError } from '../../type/error/index.mjs';
3
3
  export type Insert = Static<typeof Insert>;
4
- export declare const Insert: import("../../type/object/object.mjs").TObject<{
5
- type: import("../../type/literal/literal.mjs").TLiteral<"insert">;
6
- path: import("../../type/string/string.mjs").TString;
7
- value: import("../../type/unknown/unknown.mjs").TUnknown;
4
+ export declare const Insert: import("src/type/object/object.mjs").TObject<{
5
+ type: import("src/type/literal/literal.mjs").TLiteral<"insert">;
6
+ path: import("src/type/string/string.mjs").TString;
7
+ value: import("src/type/unknown/unknown.mjs").TUnknown;
8
8
  }>;
9
9
  export type Update = Static<typeof Update>;
10
- export declare const Update: import("../../type/object/object.mjs").TObject<{
11
- type: import("../../type/literal/literal.mjs").TLiteral<"update">;
12
- path: import("../../type/string/string.mjs").TString;
13
- value: import("../../type/unknown/unknown.mjs").TUnknown;
10
+ export declare const Update: import("src/type/object/object.mjs").TObject<{
11
+ type: import("src/type/literal/literal.mjs").TLiteral<"update">;
12
+ path: import("src/type/string/string.mjs").TString;
13
+ value: import("src/type/unknown/unknown.mjs").TUnknown;
14
14
  }>;
15
15
  export type Delete = Static<typeof Delete>;
16
- export declare const Delete: import("../../type/object/object.mjs").TObject<{
17
- type: import("../../type/literal/literal.mjs").TLiteral<"delete">;
18
- path: import("../../type/string/string.mjs").TString;
16
+ export declare const Delete: import("src/type/object/object.mjs").TObject<{
17
+ type: import("src/type/literal/literal.mjs").TLiteral<"delete">;
18
+ path: import("src/type/string/string.mjs").TString;
19
19
  }>;
20
20
  export type Edit = Static<typeof Edit>;
21
- export declare const Edit: import("../../type/union/union-type.mjs").TUnion<[import("../../type/object/object.mjs").TObject<{
22
- type: import("../../type/literal/literal.mjs").TLiteral<"insert">;
23
- path: import("../../type/string/string.mjs").TString;
24
- value: import("../../type/unknown/unknown.mjs").TUnknown;
25
- }>, import("../../type/object/object.mjs").TObject<{
26
- type: import("../../type/literal/literal.mjs").TLiteral<"update">;
27
- path: import("../../type/string/string.mjs").TString;
28
- value: import("../../type/unknown/unknown.mjs").TUnknown;
29
- }>, import("../../type/object/object.mjs").TObject<{
30
- type: import("../../type/literal/literal.mjs").TLiteral<"delete">;
31
- path: import("../../type/string/string.mjs").TString;
21
+ export declare const Edit: import("src/type/union/union-type.mjs").TUnion<[import("src/type/object/object.mjs").TObject<{
22
+ type: import("src/type/literal/literal.mjs").TLiteral<"insert">;
23
+ path: import("src/type/string/string.mjs").TString;
24
+ value: import("src/type/unknown/unknown.mjs").TUnknown;
25
+ }>, import("src/type/object/object.mjs").TObject<{
26
+ type: import("src/type/literal/literal.mjs").TLiteral<"update">;
27
+ path: import("src/type/string/string.mjs").TString;
28
+ value: import("src/type/unknown/unknown.mjs").TUnknown;
29
+ }>, import("src/type/object/object.mjs").TObject<{
30
+ type: import("src/type/literal/literal.mjs").TLiteral<"delete">;
31
+ path: import("src/type/string/string.mjs").TString;
32
32
  }>]>;
33
33
  export declare class ValueDeltaError extends TypeBoxError {
34
34
  readonly value: unknown;
@@ -1,4 +1,4 @@
1
- import { IsPlainObject, IsArray, IsTypedArray, IsValueType, IsSymbol, IsUndefined } from '../guard/index.mjs';
1
+ import { IsStandardObject, IsArray, IsTypedArray, IsValueType, IsSymbol, IsUndefined } from '../guard/index.mjs';
2
2
  import { ValuePointer } from '../pointer/index.mjs';
3
3
  import { Clone } from '../clone/index.mjs';
4
4
  import { TypeBoxError } from '../../type/error/index.mjs';
@@ -55,7 +55,7 @@ function CreateDelete(path) {
55
55
  // Diffing Generators
56
56
  // ------------------------------------------------------------------
57
57
  function* ObjectType(path, current, next) {
58
- if (!IsPlainObject(next))
58
+ if (!IsStandardObject(next))
59
59
  return yield CreateUpdate(path, next);
60
60
  const currentKeys = [...globalThis.Object.keys(current), ...globalThis.Object.getOwnPropertySymbols(current)];
61
61
  const nextKeys = [...globalThis.Object.keys(next), ...globalThis.Object.getOwnPropertySymbols(next)];
@@ -115,7 +115,7 @@ function* ValueType(path, current, next) {
115
115
  yield CreateUpdate(path, next);
116
116
  }
117
117
  function* Visit(path, current, next) {
118
- if (IsPlainObject(current))
118
+ if (IsStandardObject(current))
119
119
  return yield* ObjectType(path, current, next);
120
120
  if (IsArray(current))
121
121
  return yield* ArrayType(path, current, next);
@@ -1,9 +1,9 @@
1
- import { IsPlainObject, IsDate, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
1
+ import { IsStandardObject, IsDate, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
2
2
  // ------------------------------------------------------------------
3
3
  // Equality Checks
4
4
  // ------------------------------------------------------------------
5
5
  function ObjectType(left, right) {
6
- if (!IsPlainObject(right))
6
+ if (!IsStandardObject(right))
7
7
  return false;
8
8
  const leftKeys = [...Object.keys(left), ...Object.getOwnPropertySymbols(left)];
9
9
  const rightKeys = [...Object.keys(right), ...Object.getOwnPropertySymbols(right)];
@@ -32,7 +32,7 @@ function ValueType(left, right) {
32
32
  // ------------------------------------------------------------------
33
33
  /** Returns true if the left value deep-equals the right */
34
34
  export function Equal(left, right) {
35
- if (IsPlainObject(left))
35
+ if (IsStandardObject(left))
36
36
  return ObjectType(left, right);
37
37
  if (IsDate(left))
38
38
  return DateType(left, right);
@@ -6,18 +6,46 @@ export type TypedArrayType = Int8Array | Uint8Array | Uint8ClampedArray | Int16A
6
6
  export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<any>;
7
7
  /** Returns true if this value is an iterator */
8
8
  export declare function IsIterator(value: unknown): value is IterableIterator<any>;
9
- /** Returns true if this value is a typed array */
10
- export declare function IsTypedArray(value: unknown): value is TypedArrayType;
9
+ /** Returns true if this value is not an instance of a class */
10
+ export declare function IsStandardObject(value: unknown): value is ObjectType;
11
+ /** Returns true if this value is an instance of a class */
12
+ export declare function IsInstanceObject(value: unknown): value is ObjectType;
11
13
  /** Returns true if this value is a Promise */
12
14
  export declare function IsPromise(value: unknown): value is Promise<unknown>;
13
- /** Returns true if the value is a Uint8Array */
14
- export declare function IsUint8Array(value: unknown): value is Uint8Array;
15
15
  /** Returns true if this value is a Date */
16
16
  export declare function IsDate(value: unknown): value is Date;
17
+ /** Returns true if this value is an instance of Map<K, T> */
18
+ export declare function IsMap(value: unknown): value is Map<unknown, unknown>;
19
+ /** Returns true if this value is an instance of Set<T> */
20
+ export declare function IsSet(value: unknown): value is Set<unknown>;
21
+ /** Returns true if this value is RegExp */
22
+ export declare function IsRegExp(value: unknown): value is RegExp;
23
+ /** Returns true if this value is a typed array */
24
+ export declare function IsTypedArray(value: unknown): value is TypedArrayType;
25
+ /** Returns true if the value is a Int8Array */
26
+ export declare function IsInt8Array(value: unknown): value is Int8Array;
27
+ /** Returns true if the value is a Uint8Array */
28
+ export declare function IsUint8Array(value: unknown): value is Uint8Array;
29
+ /** Returns true if the value is a Uint8ClampedArray */
30
+ export declare function IsUint8ClampedArray(value: unknown): value is Uint8ClampedArray;
31
+ /** Returns true if the value is a Int16Array */
32
+ export declare function IsInt16Array(value: unknown): value is Int16Array;
33
+ /** Returns true if the value is a Uint16Array */
34
+ export declare function IsUint16Array(value: unknown): value is Uint16Array;
35
+ /** Returns true if the value is a Int32Array */
36
+ export declare function IsInt32Array(value: unknown): value is Int32Array;
37
+ /** Returns true if the value is a Uint32Array */
38
+ export declare function IsUint32Array(value: unknown): value is Uint32Array;
39
+ /** Returns true if the value is a Float32Array */
40
+ export declare function IsFloat32Array(value: unknown): value is Float32Array;
41
+ /** Returns true if the value is a Float64Array */
42
+ export declare function IsFloat64Array(value: unknown): value is Float64Array;
43
+ /** Returns true if the value is a BigInt64Array */
44
+ export declare function IsBigInt64Array(value: unknown): value is BigInt64Array;
45
+ /** Returns true if the value is a BigUint64Array */
46
+ export declare function IsBigUint64Array(value: unknown): value is BigUint64Array;
17
47
  /** Returns true if this value has this property key */
18
48
  export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is ObjectType & Record<K, unknown>;
19
- /** Returns true if this object is not an instance of any other type */
20
- export declare function IsPlainObject(value: unknown): value is ObjectType;
21
49
  /** Returns true of this value is an object type */
22
50
  export declare function IsObject(value: unknown): value is ObjectType;
23
51
  /** Returns true if this value is an array, but not a typed array */
@@ -10,24 +10,87 @@ export function IsIterator(value) {
10
10
  return IsObject(value) && Symbol.iterator in value;
11
11
  }
12
12
  // --------------------------------------------------------------------------
13
- // Nominal
13
+ // Object Instances
14
14
  // --------------------------------------------------------------------------
15
- /** Returns true if this value is a typed array */
16
- export function IsTypedArray(value) {
17
- return ArrayBuffer.isView(value);
15
+ /** Returns true if this value is not an instance of a class */
16
+ export function IsStandardObject(value) {
17
+ return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
18
+ }
19
+ /** Returns true if this value is an instance of a class */
20
+ export function IsInstanceObject(value) {
21
+ return IsObject(value) && !IsArray(value) && IsFunction(value.constructor) && value.constructor.name !== 'Object';
18
22
  }
23
+ // --------------------------------------------------------------------------
24
+ // JavaScript
25
+ // --------------------------------------------------------------------------
19
26
  /** Returns true if this value is a Promise */
20
27
  export function IsPromise(value) {
21
28
  return value instanceof Promise;
22
29
  }
23
- /** Returns true if the value is a Uint8Array */
24
- export function IsUint8Array(value) {
25
- return value instanceof Uint8Array;
26
- }
27
30
  /** Returns true if this value is a Date */
28
31
  export function IsDate(value) {
29
32
  return value instanceof Date && Number.isFinite(value.getTime());
30
33
  }
34
+ /** Returns true if this value is an instance of Map<K, T> */
35
+ export function IsMap(value) {
36
+ return value instanceof globalThis.Map;
37
+ }
38
+ /** Returns true if this value is an instance of Set<T> */
39
+ export function IsSet(value) {
40
+ return value instanceof globalThis.Set;
41
+ }
42
+ /** Returns true if this value is RegExp */
43
+ export function IsRegExp(value) {
44
+ return value instanceof globalThis.RegExp;
45
+ }
46
+ /** Returns true if this value is a typed array */
47
+ export function IsTypedArray(value) {
48
+ return ArrayBuffer.isView(value);
49
+ }
50
+ /** Returns true if the value is a Int8Array */
51
+ export function IsInt8Array(value) {
52
+ return value instanceof globalThis.Int8Array;
53
+ }
54
+ /** Returns true if the value is a Uint8Array */
55
+ export function IsUint8Array(value) {
56
+ return value instanceof globalThis.Uint8Array;
57
+ }
58
+ /** Returns true if the value is a Uint8ClampedArray */
59
+ export function IsUint8ClampedArray(value) {
60
+ return value instanceof globalThis.Uint8ClampedArray;
61
+ }
62
+ /** Returns true if the value is a Int16Array */
63
+ export function IsInt16Array(value) {
64
+ return value instanceof globalThis.Int16Array;
65
+ }
66
+ /** Returns true if the value is a Uint16Array */
67
+ export function IsUint16Array(value) {
68
+ return value instanceof globalThis.Uint16Array;
69
+ }
70
+ /** Returns true if the value is a Int32Array */
71
+ export function IsInt32Array(value) {
72
+ return value instanceof globalThis.Int32Array;
73
+ }
74
+ /** Returns true if the value is a Uint32Array */
75
+ export function IsUint32Array(value) {
76
+ return value instanceof globalThis.Uint32Array;
77
+ }
78
+ /** Returns true if the value is a Float32Array */
79
+ export function IsFloat32Array(value) {
80
+ return value instanceof globalThis.Float32Array;
81
+ }
82
+ /** Returns true if the value is a Float64Array */
83
+ export function IsFloat64Array(value) {
84
+ return value instanceof globalThis.Float64Array;
85
+ }
86
+ /** Returns true if the value is a BigInt64Array */
87
+ export function IsBigInt64Array(value) {
88
+ return value instanceof globalThis.BigInt64Array;
89
+ }
90
+ /** Returns true if the value is a BigUint64Array */
91
+ export function IsBigUint64Array(value) {
92
+ return value instanceof globalThis.BigUint64Array;
93
+ }
31
94
  // --------------------------------------------------------------------------
32
95
  // Standard
33
96
  // --------------------------------------------------------------------------
@@ -35,10 +98,6 @@ export function IsDate(value) {
35
98
  export function HasPropertyKey(value, key) {
36
99
  return key in value;
37
100
  }
38
- /** Returns true if this object is not an instance of any other type */
39
- export function IsPlainObject(value) {
40
- return IsObject(value) && IsFunction(value.constructor) && value.constructor.name === 'Object';
41
- }
42
101
  /** Returns true of this value is an object type */
43
102
  export function IsObject(value) {
44
103
  return value !== null && typeof value === 'object';
@@ -1,4 +1,4 @@
1
- import { IsArray, IsBoolean, IsBigInt, IsDate, IsNull, IsNumber, IsPlainObject, IsString, IsSymbol, IsUint8Array, IsUndefined } from '../guard/index.mjs';
1
+ import { IsArray, IsBoolean, IsBigInt, IsDate, IsNull, IsNumber, IsStandardObject, IsString, IsSymbol, IsUint8Array, IsUndefined } from '../guard/index.mjs';
2
2
  import { TypeBoxError } from '../../type/error/index.mjs';
3
3
  // ------------------------------------------------------------------
4
4
  // Errors
@@ -120,7 +120,7 @@ function Visit(value) {
120
120
  return NullType(value);
121
121
  if (IsNumber(value))
122
122
  return NumberType(value);
123
- if (IsPlainObject(value))
123
+ if (IsStandardObject(value))
124
124
  return ObjectType(value);
125
125
  if (IsString(value))
126
126
  return StringType(value);
@@ -1,16 +1,16 @@
1
1
  export { ValueError, ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
2
- export { Cast, ValueCastError } from './cast/index.mjs';
3
- export { Check } from './check/index.mjs';
4
- export { Clean } from './clean/index.mjs';
5
- export { Clone } from './clone/index.mjs';
6
- export { Convert } from './convert/index.mjs';
7
- export { Create, ValueCreateError } from './create/index.mjs';
8
- export { Default } from './default/index.mjs';
9
- export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index.mjs';
10
- export { Equal } from './equal/index.mjs';
11
- export { Hash, ValueHashError } from './hash/index.mjs';
12
- export { Mutate, ValueMutateError, type Mutable } from './mutate/index.mjs';
13
- export { ValuePointer } from './pointer/index.mjs';
14
- export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
15
- export { ArrayType, HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, type ObjectType, type TypedArrayType, type ValueType, } from './guard/index.mjs';
2
+ export * from './guard/index.mjs';
3
+ export * from './cast/index.mjs';
4
+ export * from './check/index.mjs';
5
+ export * from './clean/index.mjs';
6
+ export * from './clone/index.mjs';
7
+ export * from './convert/index.mjs';
8
+ export * from './create/index.mjs';
9
+ export * from './default/index.mjs';
10
+ export * from './delta/index.mjs';
11
+ export * from './equal/index.mjs';
12
+ export * from './hash/index.mjs';
13
+ export * from './mutate/index.mjs';
14
+ export * from './pointer/index.mjs';
15
+ export * from './transform/index.mjs';
16
16
  export { Value } from './value/index.mjs';
@@ -1,28 +1,28 @@
1
1
  // ------------------------------------------------------------------
2
- // Value Errors (re-export)
2
+ // Errors (re-export)
3
3
  // ------------------------------------------------------------------
4
4
  export { ValueErrorType, ValueErrorIterator } from '../errors/index.mjs';
5
5
  // ------------------------------------------------------------------
6
- // Value Operators
6
+ // Guards
7
7
  // ------------------------------------------------------------------
8
- export { Cast, ValueCastError } from './cast/index.mjs';
9
- export { Check } from './check/index.mjs';
10
- export { Clean } from './clean/index.mjs';
11
- export { Clone } from './clone/index.mjs';
12
- export { Convert } from './convert/index.mjs';
13
- export { Create, ValueCreateError } from './create/index.mjs';
14
- export { Default } from './default/index.mjs';
15
- export { Diff, Patch, Edit, Delete, Insert, Update, ValueDeltaError } from './delta/index.mjs';
16
- export { Equal } from './equal/index.mjs';
17
- export { Hash, ValueHashError } from './hash/index.mjs';
18
- export { Mutate, ValueMutateError } from './mutate/index.mjs';
19
- export { ValuePointer } from './pointer/index.mjs';
20
- export { TransformDecode, TransformEncode, HasTransform, TransformDecodeCheckError, TransformDecodeError, TransformEncodeCheckError, TransformEncodeError } from './transform/index.mjs';
8
+ export * from './guard/index.mjs';
21
9
  // ------------------------------------------------------------------
22
- // Value Guards
10
+ // Operators
23
11
  // ------------------------------------------------------------------
24
- export { HasPropertyKey, IsArray, IsAsyncIterator, IsBigInt, IsBoolean, IsDate, IsFunction, IsInteger, IsIterator, IsNull, IsNumber, IsObject, IsPlainObject, IsPromise, IsString, IsSymbol, IsTypedArray, IsUint8Array, IsUndefined, IsValueType, } from './guard/index.mjs';
12
+ export * from './cast/index.mjs';
13
+ export * from './check/index.mjs';
14
+ export * from './clean/index.mjs';
15
+ export * from './clone/index.mjs';
16
+ export * from './convert/index.mjs';
17
+ export * from './create/index.mjs';
18
+ export * from './default/index.mjs';
19
+ export * from './delta/index.mjs';
20
+ export * from './equal/index.mjs';
21
+ export * from './hash/index.mjs';
22
+ export * from './mutate/index.mjs';
23
+ export * from './pointer/index.mjs';
24
+ export * from './transform/index.mjs';
25
25
  // ------------------------------------------------------------------
26
- // Value Namespace
26
+ // Namespace
27
27
  // ------------------------------------------------------------------
28
28
  export { Value } from './value/index.mjs';
@@ -1,4 +1,4 @@
1
- import { IsPlainObject, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
1
+ import { IsStandardObject, IsArray, IsTypedArray, IsValueType } from '../guard/index.mjs';
2
2
  import { ValuePointer } from '../pointer/index.mjs';
3
3
  import { Clone } from '../clone/index.mjs';
4
4
  import { TypeBoxError } from '../../type/error/index.mjs';
@@ -11,7 +11,7 @@ export class ValueMutateError extends TypeBoxError {
11
11
  }
12
12
  }
13
13
  function ObjectType(root, path, current, next) {
14
- if (!IsPlainObject(current)) {
14
+ if (!IsStandardObject(current)) {
15
15
  ValuePointer.Set(root, path, Clone(next));
16
16
  }
17
17
  else {
@@ -63,7 +63,7 @@ function Visit(root, path, current, next) {
63
63
  return ArrayType(root, path, current, next);
64
64
  if (IsTypedArray(next))
65
65
  return TypedArrayType(root, path, current, next);
66
- if (IsPlainObject(next))
66
+ if (IsStandardObject(next))
67
67
  return ObjectType(root, path, current, next);
68
68
  if (IsValueType(next))
69
69
  return ValueType(root, path, current, next);
@@ -76,8 +76,8 @@ function IsNonMutableValue(value) {
76
76
  }
77
77
  function IsMismatchedValue(current, next) {
78
78
  // prettier-ignore
79
- return ((IsPlainObject(current) && IsArray(next)) ||
80
- (IsArray(current) && IsPlainObject(next)));
79
+ return ((IsStandardObject(current) && IsArray(next)) ||
80
+ (IsArray(current) && IsStandardObject(next)));
81
81
  }
82
82
  // ------------------------------------------------------------------
83
83
  // Mutate
@@ -9,8 +9,10 @@ export declare class TransformDecodeCheckError extends TypeBoxError {
9
9
  }
10
10
  export declare class TransformDecodeError extends TypeBoxError {
11
11
  readonly schema: TSchema;
12
+ readonly path: string;
12
13
  readonly value: unknown;
13
- constructor(schema: TSchema, value: unknown, error: any);
14
+ readonly error: Error;
15
+ constructor(schema: TSchema, path: string, value: unknown, error: Error);
14
16
  }
15
17
  /**
16
18
  * `[Internal]` Decodes the value and returns the result. This function requires that