@sinclair/typebox 0.33.14 → 0.33.15

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.
@@ -1,3 +1,7 @@
1
+ /** Returns true if this value has this property key */
2
+ export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is Record<PropertyKey, unknown> & {
3
+ [_ in K]: unknown;
4
+ };
1
5
  /** Returns true if this value is an async iterator */
2
6
  export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<unknown>;
3
7
  /** Returns true if this value is an array */
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.HasPropertyKey = HasPropertyKey;
4
5
  exports.IsAsyncIterator = IsAsyncIterator;
5
6
  exports.IsArray = IsArray;
6
7
  exports.IsBigInt = IsBigInt;
@@ -17,6 +18,13 @@ exports.IsSymbol = IsSymbol;
17
18
  exports.IsUint8Array = IsUint8Array;
18
19
  exports.IsUndefined = IsUndefined;
19
20
  // --------------------------------------------------------------------------
21
+ // PropertyKey
22
+ // --------------------------------------------------------------------------
23
+ /** Returns true if this value has this property key */
24
+ function HasPropertyKey(value, key) {
25
+ return key in value;
26
+ }
27
+ // --------------------------------------------------------------------------
20
28
  // Object Instances
21
29
  // --------------------------------------------------------------------------
22
30
  /** Returns true if this value is an async iterator */
@@ -40,6 +40,10 @@ function FromArray(schema, references, value) {
40
40
  }
41
41
  return defaulted;
42
42
  }
43
+ function FromDate(schema, references, value) {
44
+ // special case intercept for dates
45
+ return (0, index_5.IsDate)(value) ? value : ValueOrDefault(schema, value);
46
+ }
43
47
  function FromIntersect(schema, references, value) {
44
48
  const defaulted = ValueOrDefault(schema, value);
45
49
  return schema.allOf.reduce((acc, schema) => {
@@ -131,6 +135,8 @@ function Visit(schema, references, value) {
131
135
  switch (schema_[index_4.Kind]) {
132
136
  case 'Array':
133
137
  return FromArray(schema_, references_, value);
138
+ case 'Date':
139
+ return FromDate(schema_, references_, value);
134
140
  case 'Intersect':
135
141
  return FromIntersect(schema_, references_, value);
136
142
  case 'Object':
@@ -45,7 +45,9 @@ export declare function IsBigInt64Array(value: unknown): value is BigInt64Array;
45
45
  /** Returns true if the value is a BigUint64Array */
46
46
  export declare function IsBigUint64Array(value: unknown): value is BigUint64Array;
47
47
  /** Returns true if this value has this property key */
48
- export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is ObjectType & Record<K, unknown>;
48
+ export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is Record<PropertyKey, unknown> & {
49
+ [_ in K]: unknown;
50
+ };
49
51
  /** Returns true of this value is an object type */
50
52
  export declare function IsObject(value: unknown): value is ObjectType;
51
53
  /** Returns true if this value is an array, but not a typed array */
@@ -129,12 +129,15 @@ function IsBigUint64Array(value) {
129
129
  return value instanceof globalThis.BigUint64Array;
130
130
  }
131
131
  // --------------------------------------------------------------------------
132
- // Standard
132
+ // PropertyKey
133
133
  // --------------------------------------------------------------------------
134
134
  /** Returns true if this value has this property key */
135
135
  function HasPropertyKey(value, key) {
136
136
  return key in value;
137
137
  }
138
+ // --------------------------------------------------------------------------
139
+ // Standard
140
+ // --------------------------------------------------------------------------
138
141
  /** Returns true of this value is an object type */
139
142
  function IsObject(value) {
140
143
  return value !== null && typeof value === 'object';
@@ -1,3 +1,7 @@
1
+ /** Returns true if this value has this property key */
2
+ export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is Record<PropertyKey, unknown> & {
3
+ [_ in K]: unknown;
4
+ };
1
5
  /** Returns true if this value is an async iterator */
2
6
  export declare function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<unknown>;
3
7
  /** Returns true if this value is an array */
@@ -1,4 +1,11 @@
1
1
  // --------------------------------------------------------------------------
2
+ // PropertyKey
3
+ // --------------------------------------------------------------------------
4
+ /** Returns true if this value has this property key */
5
+ export function HasPropertyKey(value, key) {
6
+ return key in value;
7
+ }
8
+ // --------------------------------------------------------------------------
2
9
  // Object Instances
3
10
  // --------------------------------------------------------------------------
4
11
  /** Returns true if this value is an async iterator */
@@ -5,7 +5,7 @@ import { Kind } from '../../type/symbols/index.mjs';
5
5
  // ------------------------------------------------------------------
6
6
  // ValueGuard
7
7
  // ------------------------------------------------------------------
8
- import { IsFunction, IsObject, IsArray, IsUndefined, HasPropertyKey } from '../guard/index.mjs';
8
+ import { IsArray, IsDate, IsFunction, IsObject, IsUndefined, HasPropertyKey } from '../guard/index.mjs';
9
9
  // ------------------------------------------------------------------
10
10
  // TypeGuard
11
11
  // ------------------------------------------------------------------
@@ -36,6 +36,10 @@ function FromArray(schema, references, value) {
36
36
  }
37
37
  return defaulted;
38
38
  }
39
+ function FromDate(schema, references, value) {
40
+ // special case intercept for dates
41
+ return IsDate(value) ? value : ValueOrDefault(schema, value);
42
+ }
39
43
  function FromIntersect(schema, references, value) {
40
44
  const defaulted = ValueOrDefault(schema, value);
41
45
  return schema.allOf.reduce((acc, schema) => {
@@ -127,6 +131,8 @@ function Visit(schema, references, value) {
127
131
  switch (schema_[Kind]) {
128
132
  case 'Array':
129
133
  return FromArray(schema_, references_, value);
134
+ case 'Date':
135
+ return FromDate(schema_, references_, value);
130
136
  case 'Intersect':
131
137
  return FromIntersect(schema_, references_, value);
132
138
  case 'Object':
@@ -45,7 +45,9 @@ export declare function IsBigInt64Array(value: unknown): value is BigInt64Array;
45
45
  /** Returns true if the value is a BigUint64Array */
46
46
  export declare function IsBigUint64Array(value: unknown): value is BigUint64Array;
47
47
  /** Returns true if this value has this property key */
48
- export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is ObjectType & Record<K, unknown>;
48
+ export declare function HasPropertyKey<K extends PropertyKey>(value: Record<any, unknown>, key: K): value is Record<PropertyKey, unknown> & {
49
+ [_ in K]: unknown;
50
+ };
49
51
  /** Returns true of this value is an object type */
50
52
  export declare function IsObject(value: unknown): value is ObjectType;
51
53
  /** Returns true if this value is an array, but not a typed array */
@@ -92,12 +92,15 @@ export function IsBigUint64Array(value) {
92
92
  return value instanceof globalThis.BigUint64Array;
93
93
  }
94
94
  // --------------------------------------------------------------------------
95
- // Standard
95
+ // PropertyKey
96
96
  // --------------------------------------------------------------------------
97
97
  /** Returns true if this value has this property key */
98
98
  export function HasPropertyKey(value, key) {
99
99
  return key in value;
100
100
  }
101
+ // --------------------------------------------------------------------------
102
+ // Standard
103
+ // --------------------------------------------------------------------------
101
104
  /** Returns true of this value is an object type */
102
105
  export function IsObject(value) {
103
106
  return value !== null && typeof value === 'object';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.33.14",
3
+ "version": "0.33.15",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",