From 8329018852862890d864aa71dd6c3b02975f1857 Mon Sep 17 00:00:00 2001 From: sinclair Date: Fri, 27 Dec 2024 18:48:23 +0900 Subject: [PATCH] Formats --- src/format/date-time.ts | 14 ++++---------- src/format/date.ts | 14 ++++---------- src/format/duration.ts | 16 +++++----------- src/format/email.ts | 14 ++++---------- src/format/hostname.ts | 14 ++++---------- src/format/idn-email.ts | 2 -- src/format/idn-hostname.ts | 2 -- src/format/ipv4.ts | 18 ++++++------------ src/format/ipv6.ts | 16 ++++++++-------- src/format/iri-reference.ts | 2 -- src/format/iri.ts | 2 -- src/format/json-pointer.ts | 14 ++++---------- src/format/regex.ts | 4 ---- src/format/time.ts | 9 ++++----- src/format/uri-reference.ts | 11 +++++------ src/format/uri-template.ts | 14 ++++---------- src/format/uri.ts | 14 ++++---------- src/format/uuid.ts | 14 ++++---------- test/runtime/format/date-time.ts | 4 ++-- 19 files changed, 62 insertions(+), 136 deletions(-) diff --git a/src/format/date-time.ts b/src/format/date-time.ts index 2f5c25f4..ee18b639 100644 --- a/src/format/date-time.ts +++ b/src/format/date-time.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,11 +26,6 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This code ported form the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - import { IsDate } from './date' import { IsTime } from './time' @@ -42,7 +33,10 @@ const DateTimeSeperator = /t|\s/i /** * Returns true of this string is a date-time - * @documentation https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @spec https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `2020-12-12T20:20:40+00:00` */ export function IsDateTime(value: string, strictTimeZone?: boolean): boolean { diff --git a/src/format/date.ts b/src/format/date.ts index d55359e1..36be2f40 100644 --- a/src/format/date.ts +++ b/src/format/date.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,11 +26,6 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// -------------------------------------------------------------------------- -// This code ported form the ajv-format project for compatibility. All credit -// goes to Evgeny Poberezkin and contributors. -// -------------------------------------------------------------------------- - const Days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] const Date = /^(\d\d\d\d)-(\d\d)-(\d\d)$/ @@ -43,7 +34,10 @@ function IsLeapYear(year: number): boolean { } /** * Returns true of this string is a date - * @documentation https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @spec https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `2020-12-12` */ export function IsDate(value: string): boolean { diff --git a/src/format/duration.ts b/src/format/duration.ts index 69f334a9..cfe28905 100644 --- a/src/format/duration.ts +++ b/src/format/duration.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const Duration = /^P(?!$)((\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?|(\d+W)?)$/ /** - * `[Ajv-Formats]` Returns true if this string is a duration - * @documentation https://datatracker.ietf.org/doc/html/rfc3339#appendix-A + * Returns true if this string is a duration + * @spec https://datatracker.ietf.org/doc/html/rfc3339#appendix-A + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `P3D` */ export function IsDuration(value: string): boolean { diff --git a/src/format/email.ts b/src/format/email.ts index 50870ceb..6f6cf6fe 100644 --- a/src/format/email.ts +++ b/src/format/email.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - 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 /** * Returns true if this string is an email address. - * @documentation https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2 + * @spec https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.2 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `example@domain.com` */ export function IsEmail(value: string): boolean { diff --git a/src/format/hostname.ts b/src/format/hostname.ts index 84058044..10bfdbb9 100644 --- a/src/format/hostname.ts +++ b/src/format/hostname.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const Hostname = /^(?=.{1,253}\.?$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*\.?$/i /** * Returns true if this string is a hostname - * @documentation https://datatracker.ietf.org/doc/html/rfc1123#section-2.1 + * @spec https://datatracker.ietf.org/doc/html/rfc1123#section-2.1 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `domain.com` */ export function IsHostname(value: string): boolean { diff --git a/src/format/idn-email.ts b/src/format/idn-email.ts index d56e2d69..a1402897 100644 --- a/src/format/idn-email.ts +++ b/src/format/idn-email.ts @@ -4,8 +4,6 @@ The MIT License (MIT) -Copyright (c) 2017-2024 Haydn Paterson (sinclair) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/src/format/idn-hostname.ts b/src/format/idn-hostname.ts index 62c8b95a..808447bb 100644 --- a/src/format/idn-hostname.ts +++ b/src/format/idn-hostname.ts @@ -4,8 +4,6 @@ The MIT License (MIT) -Copyright (c) 2017-2024 Haydn Paterson (sinclair) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/src/format/ipv4.ts b/src/format/ipv4.ts index 80469d14..e74b4baf 100644 --- a/src/format/ipv4.ts +++ b/src/format/ipv4.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,20 +26,18 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - -const pattern = /^(?:(?: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)$/ +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)$/ /** * Returns true if this string is a ipv4 format. - * @documentation https://datatracker.ietf.org/doc/html/rfc2673#section-3.2 + * @spec https://datatracker.ietf.org/doc/html/rfc2673#section-3.2 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `127.0.0.1` * ``` */ export function IsIpv4(value: string): boolean { - return pattern.test(value) + return IpV4.test(value) } FormatRegistry.Set('ipv4', IsIpv4) diff --git a/src/format/ipv6.ts b/src/format/ipv6.ts index 1eac77e5..ee8f1c5f 100644 --- a/src/format/ipv6.ts +++ b/src/format/ipv6.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -31,18 +27,22 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' // ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. +// This expression is borrowed the ajv-format project for compatibility. // All credit goes to Evgeny Poberezkin and contributors. // ------------------------------------------------------------------ -const pattern = /^((([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 +const Ipv6 = + /^((([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 /** * Returns true if this string is a Ipv6 format. - * @documentation https://datatracker.ietf.org/doc/html/rfc2373#section-2.2 + * @spec https://datatracker.ietf.org/doc/html/rfc2373#section-2.2 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `::1` */ export function IsIpv6(value: string): boolean { - return pattern.test(value) + return Ipv6.test(value) } FormatRegistry.Set('ipv6', IsIpv6) diff --git a/src/format/iri-reference.ts b/src/format/iri-reference.ts index 1906ab30..7eb25222 100644 --- a/src/format/iri-reference.ts +++ b/src/format/iri-reference.ts @@ -4,8 +4,6 @@ The MIT License (MIT) -Copyright (c) 2017-2024 Haydn Paterson (sinclair) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/src/format/iri.ts b/src/format/iri.ts index 05825d7c..fb5dfbae 100644 --- a/src/format/iri.ts +++ b/src/format/iri.ts @@ -4,8 +4,6 @@ The MIT License (MIT) -Copyright (c) 2017-2024 Haydn Paterson (sinclair) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/src/format/json-pointer.ts b/src/format/json-pointer.ts index 3ad4f293..87824b86 100644 --- a/src/format/json-pointer.ts +++ b/src/format/json-pointer.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const JsonPointer = /^(?:\/(?:[^~/]|~0|~1)*)*$/ /** * Returns true if this string is a json-pointer - * @documentation https://datatracker.ietf.org/doc/html/rfc6901 + * @spec https://datatracker.ietf.org/doc/html/rfc6901 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `/values/0/value` */ export function IsJsonPointer(value: string): boolean { diff --git a/src/format/regex.ts b/src/format/regex.ts index b083e460..3c0cd038 100644 --- a/src/format/regex.ts +++ b/src/format/regex.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights diff --git a/src/format/time.ts b/src/format/time.ts index e3e4566a..46cedd78 100644 --- a/src/format/time.ts +++ b/src/format/time.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -39,7 +35,10 @@ const TIME = /^(\d\d):(\d\d):(\d\d(?:\.\d+)?)(z|([+-])(\d\d)(?::?(\d\d))?)?$/i /** * Returns true of this string is a iso time. - * @documentation https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @spec https://datatracker.ietf.org/doc/html/rfc3339#section-5.6 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `20:20:39+00:00` */ export function IsTime(value: string, strictTimeZone?: boolean): boolean { diff --git a/src/format/uri-reference.ts b/src/format/uri-reference.ts index 260ca7c4..e11e71e1 100644 --- a/src/format/uri-reference.ts +++ b/src/format/uri-reference.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -31,7 +27,7 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' // ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. +// This expression is borrowed the ajv-format project for compatibility. // All credit goes to Evgeny Poberezkin and contributors. // ------------------------------------------------------------------ @@ -39,7 +35,10 @@ const URI_REFERENCE = /^(?:(?:[a-z][a-z0-9+\-.]*:)?\/?\/)?(?:[^\\\s#][^\s#]*)?(? /** * Returns true if this string is a uri-reference - * @documentation https://datatracker.ietf.org/doc/html/rfc3986#section-4.1 + * @spec https://datatracker.ietf.org/doc/html/rfc3986#section-4.1 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `/path/to/resource` */ export function IsUriReference(value: string): boolean { diff --git a/src/format/uri-template.ts b/src/format/uri-template.ts index a6f01d40..a68099bc 100644 --- a/src/format/uri-template.ts +++ b/src/format/uri-template.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const UrlTemplate = /^(?:(?:[^\x00-\x20"'<>%\\^`{|}]|%[0-9a-f]{2})|\{[+#./;?&=,!@|]?(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?(?:,(?:[a-z0-9_]|%[0-9a-f]{2})+(?::[1-9][0-9]{0,3}|\*)?)*\})*$/i /** * Returns true if this string is a uri-template - * @documentation https://datatracker.ietf.org/doc/html/rfc6570 + * @spec https://datatracker.ietf.org/doc/html/rfc6570 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `/products/{category}/{productId}/reviews/{reviewId}` */ export function IsUriTemplate(value: string): boolean { diff --git a/src/format/uri.ts b/src/format/uri.ts index e73f6926..66daf909 100644 --- a/src/format/uri.ts +++ b/src/format/uri.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const Uri = /^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i /** * Returns true if this string is a uri - * @documentation https://datatracker.ietf.org/doc/html/rfc3986 + * @spec https://datatracker.ietf.org/doc/html/rfc3986 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `https://www.example.com/path/to/resource?query=value#fragment` */ export function IsUri(value: string): boolean { diff --git a/src/format/uuid.ts b/src/format/uuid.ts index 75e96be9..056e5b41 100644 --- a/src/format/uuid.ts +++ b/src/format/uuid.ts @@ -4,10 +4,6 @@ The MIT License (MIT) -2020 Evgeny Poberezkin -2024 Haydn Paterson (sinclair) - - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights @@ -30,16 +26,14 @@ THE SOFTWARE. import { FormatRegistry } from '../type/index' -// ------------------------------------------------------------------ -// This expression is borrowed the ajv-format project for compatibility. -// All credit goes to Evgeny Poberezkin and contributors. -// ------------------------------------------------------------------ - const Uuid = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i /** * Returns true if this string is a uuid - * @documentation https://datatracker.ietf.org/doc/html/rfc4122 + * @spec https://datatracker.ietf.org/doc/html/rfc4122 + * @see https://github.com/ajv-validator/ajv-formats + * @author Evgeny Poberezkin and contributors + * @license MIT * @example `00000000-0000-0000-0000-000000000000` */ export function IsUuid(value: string): boolean { diff --git a/test/runtime/format/date-time.ts b/test/runtime/format/date-time.ts index ffcefdca..902acc8b 100644 --- a/test/runtime/format/date-time.ts +++ b/test/runtime/format/date-time.ts @@ -3,7 +3,7 @@ import * as Format from '@sinclair/typebox/format' describe('format/IsDateTime', () => { it('Should validate DateTime 1', () => { - Assert.IsFalse(Format.IsDateTime('not-a-iso-date-time')) + Assert.IsFalse(Format.IsDateTime('not-a-date-time')) }) it('Should validate DateTime 2', () => { Assert.IsTrue(Format.IsDateTime('2023-10-01T12:00:00Z')) @@ -15,6 +15,6 @@ describe('format/IsDateTime', () => { Assert.IsFalse(Format.IsDateTime('2023-10-01')) }) it('Should validate DateTime 5', () => { - Assert.IsFalse(Format.IsDateTime('2023-10-01T12:00:00')) + Assert.IsTrue(Format.IsDateTime('2023-10-01T12:00:00')) }) })