Skip to content

Commit 18d1cf7

Browse files
authored
Revision 0.31.0 (#525)
1 parent 920343c commit 18d1cf7

File tree

290 files changed

+8014
-3458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

290 files changed

+8014
-3458
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as ValueErrors from '@sinclair/typebox/errors'
1+
import * as Errors from '@sinclair/typebox/errors'
22

3-
console.log(ValueErrors)
3+
console.log(Errors)

changelog/0.31.0.md

+331
Large diffs are not rendered by default.

examples/collections/array.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
30-
import { TSchema, Static } from '@sinclair/typebox'
30+
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
3131
import { Value } from '@sinclair/typebox/value'
3232

3333
// ----------------------------------------------------------------
3434
// TypeArrayError
3535
// ----------------------------------------------------------------
36-
export class TypeArrayError extends Error {
36+
export class TypeArrayError extends TypeBoxError {
3737
constructor(message: string) {
3838
super(`${message}`)
3939
}
4040
}
41-
export class TypeArrayLengthError extends Error {
41+
export class TypeArrayLengthError extends TypeBoxError {
4242
constructor() {
4343
super('arrayLength not a number')
4444
}

examples/collections/map.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
30-
import { TSchema, Static } from '@sinclair/typebox'
30+
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
3131
import { Value } from '@sinclair/typebox/value'
3232

3333
// ----------------------------------------------------------------
3434
// TypeMapKeyError
3535
// ----------------------------------------------------------------
36-
export class TypeMapKeyError extends Error {
36+
export class TypeMapKeyError extends TypeBoxError {
3737
constructor(message: string) {
3838
super(`${message} for key`)
3939
}
4040
}
41-
export class TypeMapValueError extends Error {
41+
export class TypeMapValueError extends TypeBoxError {
4242
constructor(key: unknown, message: string) {
4343
super(`${message} for key ${JSON.stringify(key)}`)
4444
}

examples/collections/set.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ THE SOFTWARE.
2727
---------------------------------------------------------------------------*/
2828

2929
import { TypeCheck, TypeCompiler, ValueError } from '@sinclair/typebox/compiler'
30-
import { TSchema, Static } from '@sinclair/typebox'
30+
import { TSchema, Static, TypeBoxError } from '@sinclair/typebox'
3131
import { Value } from '@sinclair/typebox/value'
3232

3333
// ----------------------------------------------------------------
3434
// Errors
3535
// ----------------------------------------------------------------
36-
export class TypeSetError extends Error {
36+
export class TypeSetError extends TypeBoxError {
3737
constructor(message: string) {
3838
super(`${message}`)
3939
}

examples/formats/date-time.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
---------------------------------------------------------------------------*/
26+
27+
import { IsDate } from './date'
28+
import { IsTime } from './time'
29+
30+
const DATE_TIME_SEPARATOR = /t|\s/i
31+
32+
/**
33+
* `[ajv-formats]` ISO8601 DateTime
34+
* @example `2020-12-12T20:20:40+00:00`
35+
*/
36+
export function IsDateTime(value: string, strictTimeZone?: boolean): boolean {
37+
const dateTime: string[] = value.split(DATE_TIME_SEPARATOR)
38+
return dateTime.length === 2 && IsDate(dateTime[0]) && IsTime(dateTime[1], strictTimeZone)
39+
}

examples/formats/date.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
---------------------------------------------------------------------------*/
26+
27+
const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
28+
const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/
29+
30+
function IsLeapYear(year: number): boolean {
31+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
32+
}
33+
/**
34+
* `[ajv-formats]` ISO8601 Date component
35+
* @example `2020-12-12`
36+
*/
37+
export function IsDate(value: string): boolean {
38+
const matches: string[] | null = DATE.exec(value)
39+
if (!matches) return false
40+
const year: number = +matches[1]
41+
const month: number = +matches[2]
42+
const day: number = +matches[3]
43+
return month >= 1 && month <= 12 && day >= 1 && day <= (month === 2 && IsLeapYear(year) ? 29 : DAYS[month])
44+
}

examples/formats/email.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
---------------------------------------------------------------------------*/
26+
27+
const Email = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i
28+
29+
/**
30+
* `[ajv-formats]` Internet Email Address [RFC 5321, section 4.1.2.](http://tools.ietf.org/html/rfc5321#section-4.1.2)
31+
* @example `[email protected]`
32+
*/
33+
export function IsEmail(value: string): boolean {
34+
return Email.test(value)
35+
}

examples/formats/index.ts

+36-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1-
export * from './standard'
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <[email protected]>
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
27+
---------------------------------------------------------------------------*/
28+
29+
export * from './date-time'
30+
export * from './date'
31+
export * from './email'
32+
export * from './ipv4'
33+
export * from './ipv6'
34+
export * from './time'
35+
export * from './url'
36+
export * from './uuid'

examples/formats/ipv4.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
---------------------------------------------------------------------------*/
26+
27+
const IPv4 = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)$/
28+
29+
/**
30+
* `[ajv-formats]` IPv4 address according to dotted-quad ABNF syntax as defined in [RFC 2673, section 3.2](http://tools.ietf.org/html/rfc2673#section-3.2)
31+
* @example `192.168.0.1`
32+
*/
33+
export function IsIPv4(value: string): boolean {
34+
return IPv4.test(value)
35+
}

examples/formats/ipv6.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*--------------------------------------------------------------------------
2+
3+
@sinclair/typebox/format
4+
5+
The MIT License (MIT)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
---------------------------------------------------------------------------*/
26+
27+
const IPv6 =
28+
/^((([0-9a-f]{1,4}:){7}([0-9a-f]{1,4}|:))|(([0-9a-f]{1,4}:){6}(:[0-9a-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){5}(((:[0-9a-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9a-f]{1,4}:){4}(((:[0-9a-f]{1,4}){1,3})|((:[0-9a-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){3}(((:[0-9a-f]{1,4}){1,4})|((:[0-9a-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){2}(((:[0-9a-f]{1,4}){1,5})|((:[0-9a-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9a-f]{1,4}:){1}(((:[0-9a-f]{1,4}){1,6})|((:[0-9a-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9a-f]{1,4}){1,7})|((:[0-9a-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))$/i
29+
30+
/**
31+
* `[ajv-formats]` IPv6 address as defined in [RFC 2373, section 2.2](http://tools.ietf.org/html/rfc2373#section-2.2).
32+
* @example `2001:0db8:85a3:0000:0000:8a2e:0370:7334`
33+
*/
34+
export function IsIPv6(value: string): boolean {
35+
return IPv6.test(value)
36+
}

examples/formats/readme.md

-19
This file was deleted.

examples/formats/standard.ts

-74
This file was deleted.

0 commit comments

Comments
 (0)