typebox 1.1.21 → 1.1.23
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/build/format/email.d.mts +1 -1
- package/build/format/email.mjs +3 -24
- package/build/format/idn-email.d.mts +1 -1
- package/build/format/idn-email.mjs +3 -3
- package/build/system/environment/evaluate.mjs +1 -1
- package/build/value/convert/from-array.mjs +3 -4
- package/build/value/convert/from-bigint.mjs +0 -3
- package/build/value/convert/from-boolean.mjs +0 -3
- package/build/value/convert/from-integer.mjs +0 -3
- package/build/value/convert/from-null.mjs +0 -3
- package/build/value/convert/from-number.mjs +0 -3
- package/build/value/convert/from-string.mjs +0 -3
- package/build/value/convert/from-type.d.mts +2 -2
- package/build/value/convert/from-type.mjs +21 -21
- package/build/value/convert/from-undefined.mjs +0 -3
- package/build/value/convert/from-void.mjs +0 -3
- package/build/value/convert/try/try-array.d.mts +2 -0
- package/build/value/convert/try/try-array.mjs +6 -0
- package/build/value/convert/try/try-bigint.mjs +4 -33
- package/build/value/convert/try/try-boolean.mjs +3 -26
- package/build/value/convert/try/try-null.mjs +2 -19
- package/build/value/convert/try/try-number.mjs +6 -38
- package/build/value/convert/try/try-result.mjs +0 -1
- package/build/value/convert/try/try-string.mjs +6 -50
- package/build/value/convert/try/try-undefined.mjs +2 -19
- package/build/value/convert/try/try.d.mts +1 -0
- package/build/value/convert/try/try.mjs +1 -0
- package/package.json +30 -30
package/build/format/email.d.mts
CHANGED
package/build/format/email.mjs
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
const Email = /^(?!.*\.\.)[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is an Email
|
|
4
|
-
* @specification
|
|
4
|
+
* @specification ajv-formats
|
|
5
5
|
*/
|
|
6
6
|
export function IsEmail(value) {
|
|
7
|
-
|
|
8
|
-
const at = value.indexOf('@');
|
|
9
|
-
const quoted = value[0] === '"' && value[at - 1] === '"';
|
|
10
|
-
const ipLiteral = value[at + 1] === '[' && value[value.length - 1] === ']';
|
|
11
|
-
const ipv6 = ipLiteral && value.indexOf(':', at) !== -1;
|
|
12
|
-
const ipv4 = ipLiteral && !ipv6 && IsIPv4Internal(value, at + 2, value.length - 1);
|
|
13
|
-
return (at > 0 && at < value.length - 1) &&
|
|
14
|
-
!(
|
|
15
|
-
// .test@example.com
|
|
16
|
-
(!quoted && dot === 0) ||
|
|
17
|
-
// te..st@example.com
|
|
18
|
-
(!quoted && dot !== -1 && value.indexOf('.', dot + 1) === dot + 1) ||
|
|
19
|
-
// test.@example.com
|
|
20
|
-
(dot !== -1 && value.indexOf('@', dot) === dot + 1) ||
|
|
21
|
-
// joe bloggs@example.com
|
|
22
|
-
(!quoted && value.indexOf(' ') !== -1) ||
|
|
23
|
-
// user1@oceania.org, user2@oceania.org
|
|
24
|
-
(value.indexOf(',') !== -1) ||
|
|
25
|
-
// joe.bloggs@[127.0.0.300]
|
|
26
|
-
(ipLiteral && !ipv4 && !ipv6) ||
|
|
27
|
-
// joe.bloggs@invalid=domain.com
|
|
28
|
-
(value.indexOf('=', at) !== -1));
|
|
7
|
+
return Email.test(value);
|
|
29
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
const IdnEmail = /^(?!.*\.\.)[\p{L}\p{N}!#$%&'*+/=?^_`{|}~-]+(?:\.[\p{L}\p{N}!#$%&'*+/=?^_`{|}~-]+)*@[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?(?:\.[\p{L}\p{N}](?:[\p{L}\p{N}-]{0,61}[\p{L}\p{N}])?)*$/iu;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is an IdnEmail
|
|
4
|
-
* @specification
|
|
4
|
+
* @specification ajv-formats (unicode-extension)
|
|
5
5
|
*/
|
|
6
6
|
export function IsIdnEmail(value) {
|
|
7
|
-
return
|
|
7
|
+
return IdnEmail.test(value);
|
|
8
8
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
2
|
import { FromType } from './from-type.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { Try } from './try/index.mjs';
|
|
4
4
|
export function FromArray(context, type, value) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
: value;
|
|
5
|
+
const result = Try.TryArray(value);
|
|
6
|
+
return result.value.map(value => FromType(context, type.items, value));
|
|
8
7
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromBigInt(_context, _type, value) {
|
|
5
|
-
if (Guard.IsBigInt(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryBigInt(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromBoolean(_context, _type, value) {
|
|
5
|
-
if (Guard.IsBoolean(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryBoolean(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromInteger(_context, _type, value) {
|
|
5
|
-
if (Guard.IsInteger(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryNumber(value);
|
|
8
5
|
return Try.IsOk(result) ? Math.trunc(result.value) : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromNull(_context, _type, value) {
|
|
5
|
-
if (Guard.IsNull(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryNull(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromNumber(_context, _type, value) {
|
|
5
|
-
if (Guard.IsNumber(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryNumber(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromString(_context, _type, value) {
|
|
5
|
-
if (Guard.IsString(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryString(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
export declare function FromType(context:
|
|
1
|
+
import * as Type from '../../type/index.mjs';
|
|
2
|
+
export declare function FromType(context: Type.TProperties, type: Type.TSchema, value: unknown): unknown;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import * as
|
|
2
|
+
import * as Type from '../../type/index.mjs';
|
|
3
3
|
import { FromArray } from './from-array.mjs';
|
|
4
4
|
import { FromBase } from './from-base.mjs';
|
|
5
5
|
import { FromBigInt } from './from-bigint.mjs';
|
|
@@ -21,25 +21,25 @@ import { FromUndefined } from './from-undefined.mjs';
|
|
|
21
21
|
import { FromUnion } from './from-union.mjs';
|
|
22
22
|
import { FromVoid } from './from-void.mjs';
|
|
23
23
|
export function FromType(context, type, value) {
|
|
24
|
-
return (
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
24
|
+
return (Type.IsArray(type) ? FromArray(context, type, value) :
|
|
25
|
+
Type.IsBase(type) ? FromBase(context, type, value) :
|
|
26
|
+
Type.IsBigInt(type) ? FromBigInt(context, type, value) :
|
|
27
|
+
Type.IsBoolean(type) ? FromBoolean(context, type, value) :
|
|
28
|
+
Type.IsCyclic(type) ? FromCyclic(context, type, value) :
|
|
29
|
+
Type.IsEnum(type) ? FromEnum(context, type, value) :
|
|
30
|
+
Type.IsInteger(type) ? FromInteger(context, type, value) :
|
|
31
|
+
Type.IsIntersect(type) ? FromIntersect(context, type, value) :
|
|
32
|
+
Type.IsLiteral(type) ? FromLiteral(context, type, value) :
|
|
33
|
+
Type.IsNull(type) ? FromNull(context, type, value) :
|
|
34
|
+
Type.IsNumber(type) ? FromNumber(context, type, value) :
|
|
35
|
+
Type.IsObject(type) ? FromObject(context, type, value) :
|
|
36
|
+
Type.IsRecord(type) ? FromRecord(context, type, value) :
|
|
37
|
+
Type.IsRef(type) ? FromRef(context, type, value) :
|
|
38
|
+
Type.IsString(type) ? FromString(context, type, value) :
|
|
39
|
+
Type.IsTemplateLiteral(type) ? FromTemplateLiteral(context, type, value) :
|
|
40
|
+
Type.IsTuple(type) ? FromTuple(context, type, value) :
|
|
41
|
+
Type.IsUndefined(type) ? FromUndefined(context, type, value) :
|
|
42
|
+
Type.IsUnion(type) ? FromUnion(context, type, value) :
|
|
43
|
+
Type.IsVoid(type) ? FromVoid(context, type, value) :
|
|
44
44
|
value);
|
|
45
45
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromUndefined(_context, _type, value) {
|
|
5
|
-
if (Guard.IsUndefined(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryUndefined(value);
|
|
8
5
|
return Try.IsOk(result) ? result.value : value;
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import { Guard } from '../../guard/index.mjs';
|
|
3
2
|
import { Try } from './try/index.mjs';
|
|
4
3
|
export function FromVoid(_context, _type, value) {
|
|
5
|
-
if (Guard.IsUndefined(value))
|
|
6
|
-
return value;
|
|
7
4
|
const result = Try.TryUndefined(value);
|
|
8
5
|
return Try.IsOk(result) ? (void 0) : value;
|
|
9
6
|
}
|
|
@@ -1,34 +1,13 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail } from './try-result.mjs';
|
|
5
4
|
// ------------------------------------------------------------------
|
|
6
|
-
// BigInt
|
|
7
|
-
// ------------------------------------------------------------------
|
|
8
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
9
|
-
function FromBigInt(value) {
|
|
10
|
-
return Ok(value);
|
|
11
|
-
}
|
|
12
|
-
// deno-coverage-ignore-stop
|
|
13
|
-
// ------------------------------------------------------------------
|
|
14
5
|
// Boolean
|
|
15
6
|
// ------------------------------------------------------------------
|
|
16
7
|
function FromBoolean(value) {
|
|
17
8
|
return Guard.IsEqual(value, true) ? Ok(BigInt(1)) : Ok(BigInt(0));
|
|
18
9
|
}
|
|
19
10
|
// ------------------------------------------------------------------
|
|
20
|
-
// Number
|
|
21
|
-
// ------------------------------------------------------------------
|
|
22
|
-
function FromNumber(value) {
|
|
23
|
-
return Ok(BigInt(Math.trunc(value)));
|
|
24
|
-
}
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
// Null
|
|
27
|
-
// ------------------------------------------------------------------
|
|
28
|
-
function FromNull(value) {
|
|
29
|
-
return Ok(BigInt(0));
|
|
30
|
-
}
|
|
31
|
-
// ------------------------------------------------------------------
|
|
32
11
|
// String
|
|
33
12
|
// ------------------------------------------------------------------
|
|
34
13
|
const bigintPattern = /^-?(0|[1-9]\d*)n$/;
|
|
@@ -53,22 +32,14 @@ function FromString(value) {
|
|
|
53
32
|
Fail());
|
|
54
33
|
}
|
|
55
34
|
// ------------------------------------------------------------------
|
|
56
|
-
// Undefined
|
|
57
|
-
// ------------------------------------------------------------------
|
|
58
|
-
function FromUndefined(value) {
|
|
59
|
-
return Ok(BigInt(0));
|
|
60
|
-
}
|
|
61
|
-
// ------------------------------------------------------------------
|
|
62
35
|
// Try
|
|
63
36
|
// ------------------------------------------------------------------
|
|
64
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
65
37
|
export function TryBigInt(value) {
|
|
66
|
-
return (Guard.IsBigInt(value) ?
|
|
38
|
+
return (Guard.IsBigInt(value) ? Ok(value) :
|
|
67
39
|
Guard.IsBoolean(value) ? FromBoolean(value) :
|
|
68
|
-
Guard.IsNumber(value) ?
|
|
69
|
-
Guard.IsNull(value) ?
|
|
40
|
+
Guard.IsNumber(value) ? Ok(BigInt(Math.trunc(value))) :
|
|
41
|
+
Guard.IsNull(value) ? Ok(BigInt(0)) :
|
|
70
42
|
Guard.IsString(value) ? FromString(value) :
|
|
71
|
-
Guard.IsUndefined(value) ?
|
|
43
|
+
Guard.IsUndefined(value) ? Ok(BigInt(0)) :
|
|
72
44
|
Fail());
|
|
73
45
|
}
|
|
74
|
-
// deno-coverage-ignore-stop
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail } from './try-result.mjs';
|
|
5
4
|
// ------------------------------------------------------------------
|
|
@@ -11,14 +10,6 @@ function FromBigInt(value) {
|
|
|
11
10
|
Fail());
|
|
12
11
|
}
|
|
13
12
|
// ------------------------------------------------------------------
|
|
14
|
-
// Boolean
|
|
15
|
-
// ------------------------------------------------------------------
|
|
16
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
17
|
-
function FromBoolean(value) {
|
|
18
|
-
return Ok(value);
|
|
19
|
-
}
|
|
20
|
-
// deno-coverage-ignore-stop
|
|
21
|
-
// ------------------------------------------------------------------
|
|
22
13
|
// Number
|
|
23
14
|
// ------------------------------------------------------------------
|
|
24
15
|
function FromNumber(value) {
|
|
@@ -27,12 +18,6 @@ function FromNumber(value) {
|
|
|
27
18
|
Fail());
|
|
28
19
|
}
|
|
29
20
|
// ------------------------------------------------------------------
|
|
30
|
-
// Null
|
|
31
|
-
// ------------------------------------------------------------------
|
|
32
|
-
function FromNull(value) {
|
|
33
|
-
return Ok(false);
|
|
34
|
-
}
|
|
35
|
-
// ------------------------------------------------------------------
|
|
36
21
|
// String
|
|
37
22
|
// ------------------------------------------------------------------
|
|
38
23
|
function FromString(value) {
|
|
@@ -43,22 +28,14 @@ function FromString(value) {
|
|
|
43
28
|
Fail());
|
|
44
29
|
}
|
|
45
30
|
// ------------------------------------------------------------------
|
|
46
|
-
// Undefined
|
|
47
|
-
// ------------------------------------------------------------------
|
|
48
|
-
function FromUndefined(value) {
|
|
49
|
-
return Ok(false);
|
|
50
|
-
}
|
|
51
|
-
// ------------------------------------------------------------------
|
|
52
31
|
// Try
|
|
53
32
|
// ------------------------------------------------------------------
|
|
54
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
55
33
|
export function TryBoolean(value) {
|
|
56
34
|
return (Guard.IsBigInt(value) ? FromBigInt(value) :
|
|
57
|
-
Guard.IsBoolean(value) ?
|
|
35
|
+
Guard.IsBoolean(value) ? Ok(value) :
|
|
58
36
|
Guard.IsNumber(value) ? FromNumber(value) :
|
|
59
|
-
Guard.IsNull(value) ?
|
|
37
|
+
Guard.IsNull(value) ? Ok(false) :
|
|
60
38
|
Guard.IsString(value) ? FromString(value) :
|
|
61
|
-
Guard.IsUndefined(value) ?
|
|
39
|
+
Guard.IsUndefined(value) ? Ok(false) :
|
|
62
40
|
Fail());
|
|
63
41
|
}
|
|
64
|
-
// deno-coverage-ignore-stop
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail } from './try-result.mjs';
|
|
5
4
|
// ------------------------------------------------------------------
|
|
@@ -21,14 +20,6 @@ function FromNumber(value) {
|
|
|
21
20
|
return Guard.IsEqual(value, 0) ? Ok(null) : Fail();
|
|
22
21
|
}
|
|
23
22
|
// ------------------------------------------------------------------
|
|
24
|
-
// Null
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
27
|
-
function FromNull(value) {
|
|
28
|
-
return Ok(null);
|
|
29
|
-
}
|
|
30
|
-
// deno-coverage-ignore-stop
|
|
31
|
-
// ------------------------------------------------------------------
|
|
32
23
|
// String
|
|
33
24
|
// ------------------------------------------------------------------
|
|
34
25
|
function FromString(value) {
|
|
@@ -40,22 +31,14 @@ function FromString(value) {
|
|
|
40
31
|
return predicate ? Ok(null) : Fail();
|
|
41
32
|
}
|
|
42
33
|
// ------------------------------------------------------------------
|
|
43
|
-
// Undefined
|
|
44
|
-
// ------------------------------------------------------------------
|
|
45
|
-
function FromUndefined(value) {
|
|
46
|
-
return Ok(null);
|
|
47
|
-
}
|
|
48
|
-
// ------------------------------------------------------------------
|
|
49
34
|
// Try
|
|
50
35
|
// ------------------------------------------------------------------
|
|
51
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
52
36
|
export function TryNull(value) {
|
|
53
37
|
return (Guard.IsBigInt(value) ? FromBigInt(value) :
|
|
54
38
|
Guard.IsBoolean(value) ? FromBoolean(value) :
|
|
55
39
|
Guard.IsNumber(value) ? FromNumber(value) :
|
|
56
|
-
Guard.IsNull(value) ?
|
|
40
|
+
Guard.IsNull(value) ? Ok(null) :
|
|
57
41
|
Guard.IsString(value) ? FromString(value) :
|
|
58
|
-
Guard.IsUndefined(value) ?
|
|
42
|
+
Guard.IsUndefined(value) ? Ok(null) :
|
|
59
43
|
Fail());
|
|
60
44
|
}
|
|
61
|
-
// deno-coverage-ignore-stop
|
|
@@ -1,41 +1,17 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail, IsOk } from './try-result.mjs';
|
|
5
|
-
// ------------------------------------------------------------------
|
|
6
|
-
// Two-Phase
|
|
7
|
-
// ------------------------------------------------------------------
|
|
8
4
|
import { TryBigInt } from './try-bigint.mjs';
|
|
9
5
|
// ------------------------------------------------------------------
|
|
10
6
|
// BigInt
|
|
11
7
|
// ------------------------------------------------------------------
|
|
12
8
|
const maxBigInt = BigInt(Number.MAX_SAFE_INTEGER);
|
|
13
9
|
const minBigInt = BigInt(Number.MIN_SAFE_INTEGER);
|
|
14
|
-
function CanBigIntDowncast(value) {
|
|
15
|
-
return (value <= maxBigInt && value >= minBigInt);
|
|
16
|
-
}
|
|
17
10
|
function FromBigInt(value) {
|
|
18
|
-
return
|
|
11
|
+
return (value <= maxBigInt && value >= minBigInt) ? Ok(Number(value)) : Fail();
|
|
19
12
|
}
|
|
20
|
-
// ------------------------------------------------------------------
|
|
21
|
-
// Boolean
|
|
22
|
-
// ------------------------------------------------------------------
|
|
23
13
|
function FromBoolean(value) {
|
|
24
|
-
return value ?
|
|
25
|
-
}
|
|
26
|
-
// ------------------------------------------------------------------
|
|
27
|
-
// Number
|
|
28
|
-
// ------------------------------------------------------------------
|
|
29
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
30
|
-
function FromNumber(value) {
|
|
31
|
-
return Ok(value);
|
|
32
|
-
}
|
|
33
|
-
// deno-coverage-ignore-stop
|
|
34
|
-
// ------------------------------------------------------------------
|
|
35
|
-
// Null
|
|
36
|
-
// ------------------------------------------------------------------
|
|
37
|
-
function FromNull(value) {
|
|
38
|
-
return Ok(0);
|
|
14
|
+
return Ok(value ? 1 : 0);
|
|
39
15
|
}
|
|
40
16
|
// ------------------------------------------------------------------
|
|
41
17
|
// String
|
|
@@ -51,26 +27,18 @@ function FromString(value) {
|
|
|
51
27
|
return Ok(1);
|
|
52
28
|
const result = TryBigInt(value);
|
|
53
29
|
if (IsOk(result))
|
|
54
|
-
return
|
|
30
|
+
return (result.value <= maxBigInt && result.value >= minBigInt) ? Ok(Number(result.value)) : Fail();
|
|
55
31
|
return Fail();
|
|
56
32
|
}
|
|
57
33
|
// ------------------------------------------------------------------
|
|
58
|
-
// Undefined
|
|
59
|
-
// ------------------------------------------------------------------
|
|
60
|
-
function FromUndefined(value) {
|
|
61
|
-
return Ok(0);
|
|
62
|
-
}
|
|
63
|
-
// ------------------------------------------------------------------
|
|
64
34
|
// Try
|
|
65
35
|
// ------------------------------------------------------------------
|
|
66
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
67
36
|
export function TryNumber(value) {
|
|
68
37
|
return (Guard.IsBigInt(value) ? FromBigInt(value) :
|
|
69
38
|
Guard.IsBoolean(value) ? FromBoolean(value) :
|
|
70
|
-
Guard.IsNumber(value) ?
|
|
71
|
-
Guard.IsNull(value) ?
|
|
39
|
+
Guard.IsNumber(value) ? Ok(value) :
|
|
40
|
+
Guard.IsNull(value) ? Ok(0) :
|
|
72
41
|
Guard.IsString(value) ? FromString(value) :
|
|
73
|
-
Guard.IsUndefined(value) ?
|
|
42
|
+
Guard.IsUndefined(value) ? Ok(0) :
|
|
74
43
|
Fail());
|
|
75
44
|
}
|
|
76
|
-
// deno-coverage-ignore-stop
|
|
@@ -1,56 +1,12 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail } from './try-result.mjs';
|
|
5
|
-
// ------------------------------------------------------------------
|
|
6
|
-
// BigInt
|
|
7
|
-
// ------------------------------------------------------------------
|
|
8
|
-
function FromBigInt(value) {
|
|
9
|
-
return Ok(value.toString());
|
|
10
|
-
}
|
|
11
|
-
// ------------------------------------------------------------------
|
|
12
|
-
// Boolean
|
|
13
|
-
// ------------------------------------------------------------------
|
|
14
|
-
function FromBoolean(value) {
|
|
15
|
-
return Ok(value.toString());
|
|
16
|
-
}
|
|
17
|
-
// ------------------------------------------------------------------
|
|
18
|
-
// Number
|
|
19
|
-
// ------------------------------------------------------------------
|
|
20
|
-
function FromNumber(value) {
|
|
21
|
-
return Ok(value.toString());
|
|
22
|
-
}
|
|
23
|
-
// ------------------------------------------------------------------
|
|
24
|
-
// Null
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
function FromNull(value) {
|
|
27
|
-
return Ok('null');
|
|
28
|
-
}
|
|
29
|
-
// ------------------------------------------------------------------
|
|
30
|
-
// String
|
|
31
|
-
// ------------------------------------------------------------------
|
|
32
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
33
|
-
function FromString(value) {
|
|
34
|
-
return Ok(value);
|
|
35
|
-
}
|
|
36
|
-
// deno-coverage-ignore-stop
|
|
37
|
-
// ------------------------------------------------------------------
|
|
38
|
-
// Undefined
|
|
39
|
-
// ------------------------------------------------------------------
|
|
40
|
-
function FromUndefined(value) {
|
|
41
|
-
return Ok('');
|
|
42
|
-
}
|
|
43
|
-
// ------------------------------------------------------------------
|
|
44
|
-
// Try
|
|
45
|
-
// ------------------------------------------------------------------
|
|
46
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
47
4
|
export function TryString(value) {
|
|
48
|
-
return (Guard.IsBigInt(value) ?
|
|
49
|
-
Guard.IsBoolean(value) ?
|
|
50
|
-
Guard.IsNumber(value) ?
|
|
51
|
-
Guard.IsNull(value) ?
|
|
52
|
-
Guard.IsString(value) ?
|
|
53
|
-
Guard.IsUndefined(value) ?
|
|
5
|
+
return (Guard.IsBigInt(value) ? Ok(value.toString()) :
|
|
6
|
+
Guard.IsBoolean(value) ? Ok(value.toString()) :
|
|
7
|
+
Guard.IsNumber(value) ? Ok(value.toString()) :
|
|
8
|
+
Guard.IsNull(value) ? Ok('null') :
|
|
9
|
+
Guard.IsString(value) ? Ok(value) :
|
|
10
|
+
Guard.IsUndefined(value) ? Ok('') :
|
|
54
11
|
Fail());
|
|
55
12
|
}
|
|
56
|
-
// deno-coverage-ignore-stop
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
// deno-lint-ignore-file
|
|
3
2
|
import { Guard } from '../../../guard/index.mjs';
|
|
4
3
|
import { Ok, Fail } from './try-result.mjs';
|
|
5
4
|
// ------------------------------------------------------------------
|
|
@@ -21,12 +20,6 @@ function FromNumber(value) {
|
|
|
21
20
|
return Guard.IsEqual(value, 0) ? Ok(undefined) : Fail();
|
|
22
21
|
}
|
|
23
22
|
// ------------------------------------------------------------------
|
|
24
|
-
// Null
|
|
25
|
-
// ------------------------------------------------------------------
|
|
26
|
-
function FromNull(value) {
|
|
27
|
-
return Ok(undefined);
|
|
28
|
-
}
|
|
29
|
-
// ------------------------------------------------------------------
|
|
30
23
|
// String
|
|
31
24
|
// ------------------------------------------------------------------
|
|
32
25
|
function FromString(value) {
|
|
@@ -38,24 +31,14 @@ function FromString(value) {
|
|
|
38
31
|
return predicate ? Ok(undefined) : Fail();
|
|
39
32
|
}
|
|
40
33
|
// ------------------------------------------------------------------
|
|
41
|
-
// Undefined
|
|
42
|
-
// ------------------------------------------------------------------
|
|
43
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
44
|
-
function FromUndefined(value) {
|
|
45
|
-
return Ok(undefined);
|
|
46
|
-
}
|
|
47
|
-
// deno-coverage-ignore-stop
|
|
48
|
-
// ------------------------------------------------------------------
|
|
49
34
|
// Try
|
|
50
35
|
// ------------------------------------------------------------------
|
|
51
|
-
// deno-coverage-ignore-start - unreachable | guarded
|
|
52
36
|
export function TryUndefined(value) {
|
|
53
37
|
return (Guard.IsBigInt(value) ? FromBigInt(value) :
|
|
54
38
|
Guard.IsBoolean(value) ? FromBoolean(value) :
|
|
55
39
|
Guard.IsNumber(value) ? FromNumber(value) :
|
|
56
|
-
Guard.IsNull(value) ?
|
|
40
|
+
Guard.IsNull(value) ? Ok(undefined) :
|
|
57
41
|
Guard.IsString(value) ? FromString(value) :
|
|
58
|
-
Guard.IsUndefined(value) ?
|
|
42
|
+
Guard.IsUndefined(value) ? Ok(value) :
|
|
59
43
|
Fail());
|
|
60
44
|
}
|
|
61
|
-
// deno-coverage-ignore-stop
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typebox",
|
|
3
3
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.23",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"jsonschema"
|
|
@@ -16,21 +16,29 @@
|
|
|
16
16
|
"types": "./build/index.d.mts",
|
|
17
17
|
"module": "./build/index.mjs",
|
|
18
18
|
"exports": {
|
|
19
|
-
"./
|
|
20
|
-
"import": "./build/
|
|
21
|
-
"default": "./build/
|
|
19
|
+
"./system": {
|
|
20
|
+
"import": "./build/system/index.mjs",
|
|
21
|
+
"default": "./build/system/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./compile": {
|
|
24
|
+
"import": "./build/compile/index.mjs",
|
|
25
|
+
"default": "./build/compile/index.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./value": {
|
|
28
|
+
"import": "./build/value/index.mjs",
|
|
29
|
+
"default": "./build/value/index.mjs"
|
|
22
30
|
},
|
|
23
31
|
"./error": {
|
|
24
32
|
"import": "./build/error/index.mjs",
|
|
25
33
|
"default": "./build/error/index.mjs"
|
|
26
34
|
},
|
|
27
|
-
"./
|
|
28
|
-
"import": "./build/
|
|
29
|
-
"default": "./build/
|
|
35
|
+
"./guard": {
|
|
36
|
+
"import": "./build/guard/index.mjs",
|
|
37
|
+
"default": "./build/guard/index.mjs"
|
|
30
38
|
},
|
|
31
|
-
"./
|
|
32
|
-
"import": "./build/
|
|
33
|
-
"default": "./build/
|
|
39
|
+
"./schema": {
|
|
40
|
+
"import": "./build/schema/index.mjs",
|
|
41
|
+
"default": "./build/schema/index.mjs"
|
|
34
42
|
},
|
|
35
43
|
"./format": {
|
|
36
44
|
"import": "./build/format/index.mjs",
|
|
@@ -40,14 +48,6 @@
|
|
|
40
48
|
"import": "./build/type/index.mjs",
|
|
41
49
|
"default": "./build/type/index.mjs"
|
|
42
50
|
},
|
|
43
|
-
"./schema": {
|
|
44
|
-
"import": "./build/schema/index.mjs",
|
|
45
|
-
"default": "./build/schema/index.mjs"
|
|
46
|
-
},
|
|
47
|
-
"./value": {
|
|
48
|
-
"import": "./build/value/index.mjs",
|
|
49
|
-
"default": "./build/value/index.mjs"
|
|
50
|
-
},
|
|
51
51
|
".": {
|
|
52
52
|
"import": "./build/index.mjs",
|
|
53
53
|
"default": "./build/index.mjs"
|
|
@@ -55,17 +55,23 @@
|
|
|
55
55
|
},
|
|
56
56
|
"typesVersions": {
|
|
57
57
|
"*": {
|
|
58
|
-
"
|
|
59
|
-
"./build/
|
|
58
|
+
"system": [
|
|
59
|
+
"./build/system/index.d.mts"
|
|
60
|
+
],
|
|
61
|
+
"compile": [
|
|
62
|
+
"./build/compile/index.d.mts"
|
|
63
|
+
],
|
|
64
|
+
"value": [
|
|
65
|
+
"./build/value/index.d.mts"
|
|
60
66
|
],
|
|
61
67
|
"error": [
|
|
62
68
|
"./build/error/index.d.mts"
|
|
63
69
|
],
|
|
64
|
-
"
|
|
65
|
-
"./build/
|
|
70
|
+
"guard": [
|
|
71
|
+
"./build/guard/index.d.mts"
|
|
66
72
|
],
|
|
67
|
-
"
|
|
68
|
-
"./build/
|
|
73
|
+
"schema": [
|
|
74
|
+
"./build/schema/index.d.mts"
|
|
69
75
|
],
|
|
70
76
|
"format": [
|
|
71
77
|
"./build/format/index.d.mts"
|
|
@@ -73,12 +79,6 @@
|
|
|
73
79
|
"type": [
|
|
74
80
|
"./build/type/index.d.mts"
|
|
75
81
|
],
|
|
76
|
-
"schema": [
|
|
77
|
-
"./build/schema/index.d.mts"
|
|
78
|
-
],
|
|
79
|
-
"value": [
|
|
80
|
-
"./build/value/index.d.mts"
|
|
81
|
-
],
|
|
82
82
|
".": [
|
|
83
83
|
"./build/index.d.mts"
|
|
84
84
|
]
|