From 2bbf2cc9c8721f1e6089c2a14988cfa9fcb98444 Mon Sep 17 00:00:00 2001 From: Simon Mika Date: Wed, 5 Feb 2025 18:17:11 +0100 Subject: [PATCH 1/5] Fixed audit problem. --- package-lock.json | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9fd890a..d28bc67 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2045,6 +2045,21 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -4375,9 +4390,9 @@ } }, "node_modules/vite": { - "version": "5.4.11", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.11.tgz", - "integrity": "sha512-c7jFQRklXua0mTzneGW9QVyxFjUgwcihC4bXEtujIo2ouWCe1Ajt/amn2PCxYnhYfd5k09JX3SB7OYWFKYqj8Q==", + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz", + "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==", "dev": true, "license": "MIT", "dependencies": { @@ -6168,6 +6183,13 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, + "fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "optional": true + }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -7808,9 +7830,9 @@ } }, "vite": { - "version": "5.4.11", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.11.tgz", - "integrity": "sha512-c7jFQRklXua0mTzneGW9QVyxFjUgwcihC4bXEtujIo2ouWCe1Ajt/amn2PCxYnhYfd5k09JX3SB7OYWFKYqj8Q==", + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz", + "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==", "dev": true, "requires": { "esbuild": "^0.21.3", From d926089a8fdec9cf0247217ac7da209014f8197d Mon Sep 17 00:00:00 2001 From: Simon Mika Date: Wed, 5 Feb 2025 18:18:27 +0100 Subject: [PATCH 2/5] Improved configuration. --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9b4ecb2..32a97b3 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,10 @@ "scripts": { "lint": "eslint --max-warnings=0 '**/*.{ts,tsx}'", "fix": "eslint '**/*.{ts,tsx}' --fix", - "build": "rimraf dist/* && tsc -p tsconfig.mjs.json && tsc -p tsconfig.cjs.json", + "prebuild": "rimraf dist/*", + "build:mjs": "tsc -p tsconfig.mjs.json", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build": "npm run build:mjs", "test": "vitest --run", "coverage": "vitest --coverage", "prepare": "npm run build", From 65dd5891d5c7a1a5b2ed3ef9c5beaa5a385ea8db Mon Sep 17 00:00:00 2001 From: Simon Mika Date: Wed, 5 Feb 2025 19:52:28 +0100 Subject: [PATCH 3/5] Updated to new Isly. --- Address/GB.ts | 17 +++++++++-------- Address/Generic.ts | 17 +++++++++-------- Address/SE.ts | 13 ++++++------- Address/index.ts | 4 +++- CallingCode/index.ts | 6 +++--- CountryCode/Alpha2.ts | 6 +++--- CountryCode/Alpha3.ts | 6 +++--- CountryCode/Numeric.ts | 6 +++--- CountryCode/index.ts | 6 +++--- Currency/Code.ts | 6 +++--- Currency/index.ts | 6 +++--- Date/Day/Numeric.ts | 6 +++--- Date/Day/index.ts | 6 +++--- Date/Month/Numeric.ts | 6 +++--- Date/Month/index.ts | 6 +++--- Date/Numeric.ts | 9 +++++---- Date/Year/Numeric.ts | 12 ++++++------ Date/Year/index.ts | 11 +++++------ Date/index.ts | 16 +++++++++------- DateRange/index.ts | 6 +++--- DateSpan/index.ts | 12 ++++++------ DateTime/Numeric.ts | 11 ++++++----- DateTime/index.ts | 15 +++++++++------ DayOfWeek/Numeric.ts | 6 +++--- DayOfWeek/index.ts | 8 +++++--- Encoding/index.ts | 6 +++--- Language/index.ts | 6 +++--- Locale/index.ts | 6 +++--- Month/index.ts | 15 +++++++++------ Time/Hour.ts | 12 ++++++------ Time/Millisecond.ts | 17 ++++++++--------- Time/Minute.ts | 12 ++++++------ Time/Numeric.ts | 20 ++++++++++++-------- Time/Precision.ts | 6 +++--- Time/Second.ts | 12 ++++++------ Time/index.ts | 15 +++++++++------ TimeRange/index.ts | 6 +++--- TimeSpan/index.ts | 12 ++++++------ TimeZone/Offset.ts | 8 +++++--- TimeZone/index.ts | 6 +++--- Week/Number/Numeric.ts | 6 +++--- Week/Number/index.ts | 6 +++--- Week/Parts.ts | 6 +++--- Week/index.ts | 19 ++++++++++++------- 44 files changed, 223 insertions(+), 196 deletions(-) diff --git a/Address/GB.ts b/Address/GB.ts index 0cf7a7f..7a95b05 100644 --- a/Address/GB.ts +++ b/Address/GB.ts @@ -9,16 +9,17 @@ export type GB = { } export namespace GB { - export const type = isly.object( + export const type = isly( + "object", { - countryCode: isly.string<"GB">("GB"), - street: isly.string(), - building: isly.string(), - zipCode: isly.string(), - city: isly.string(), + countryCode: isly<"GB">("string", "value", "GB"), + street: isly("string"), + building: isly("string"), + zipCode: isly("string"), + city: isly("string"), }, "isoly.Address.GB" ) - export const is = type.is - export const flaw = type.flaw + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } diff --git a/Address/Generic.ts b/Address/Generic.ts index 4575a2c..f7d7a1a 100644 --- a/Address/Generic.ts +++ b/Address/Generic.ts @@ -11,17 +11,18 @@ export type Generic = { } export namespace Generic { - export const type = isly.object( + export const type = isly( + "object", { countryCode: CountryCode.Alpha2.type, - street: isly.string(), - zipCode: isly.string(), - city: isly.string(), - county: isly.string().optional(), - state: isly.string().optional(), + street: isly("string"), + zipCode: isly("string"), + city: isly("string"), + county: isly("string").optional(), + state: isly("string").optional(), }, "isoly.Address.Generic" ) - export const is = type.is - export const flaw = type.flaw + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } diff --git a/Address/SE.ts b/Address/SE.ts index 5ae61d8..ccf0153 100644 --- a/Address/SE.ts +++ b/Address/SE.ts @@ -8,15 +8,14 @@ export type SE = { } export namespace SE { - export const type = isly.object( + export const type = isly( + "object", { - countryCode: isly.string<"SE">("SE"), - street: isly.string(), - zipCode: isly.string(), - city: isly.string(), + countryCode: isly<"SE">("string", "value", "SE"), + street: isly("string"), + zipCode: isly("string"), + city: isly("string"), }, "isoly.Address.SE" ) - export const is = type.is - export const flaw = type.flaw } diff --git a/Address/index.ts b/Address/index.ts index 37d9996..83b6245 100644 --- a/Address/index.ts +++ b/Address/index.ts @@ -9,5 +9,7 @@ export namespace Address { export import Generic = AddressGeneric export import GB = AddressGB export import SE = AddressSE - export const type = isly.named("isoly.Address", isly.union
(Generic.type, GB.type, SE.type)) + export const type = isly
("union", Generic.type, GB.type, SE.type).rename("isoly.Address") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } diff --git a/CallingCode/index.ts b/CallingCode/index.ts index b74d513..97af71d 100644 --- a/CallingCode/index.ts +++ b/CallingCode/index.ts @@ -248,9 +248,9 @@ export namespace CallingCode { "+260", "+263", ] as const - export const type = isly.named("isoly.CallingCode", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.CallingCode") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(country: CountryCode.Alpha2): CallingCode | undefined { return alpha2toCallingCode[country] } diff --git a/CountryCode/Alpha2.ts b/CountryCode/Alpha2.ts index 3d8a14a..7d0a150 100644 --- a/CountryCode/Alpha2.ts +++ b/CountryCode/Alpha2.ts @@ -257,9 +257,9 @@ export namespace Alpha2 { "ZM", "ZW", ] as const - export const type = isly.named("isoly.CountryCode.Alpha2", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.CountryCode.Alpha2") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(country: Numeric | Alpha3): Alpha2 export function from(country: Numeric | number | Alpha3 | string): Alpha2 | undefined export function from(country: Numeric | number | Alpha3 | string): Alpha2 | undefined { diff --git a/CountryCode/Alpha3.ts b/CountryCode/Alpha3.ts index c6e3b7e..a971d15 100644 --- a/CountryCode/Alpha3.ts +++ b/CountryCode/Alpha3.ts @@ -257,9 +257,9 @@ export namespace Alpha3 { "ZMB", "ZWE", ] as const - export const type = isly.named("isoly.CountryCode.Alpha3", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.CountryCode.Alpha3") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(country: Alpha2 | Numeric): Alpha3 { return typeof country == "number" ? from(Alpha2.from(country)) : alpha2ToAlpha3[country] } diff --git a/CountryCode/Numeric.ts b/CountryCode/Numeric.ts index 4de29a5..7d57cfe 100644 --- a/CountryCode/Numeric.ts +++ b/CountryCode/Numeric.ts @@ -18,9 +18,9 @@ export namespace Numeric { 740, 744, 748, 752, 756, 760, 762, 764, 768, 772, 776, 780, 784, 788, 792, 795, 796, 798, 800, 804, 807, 818, 826, 831, 832, 833, 834, 840, 850, 854, 858, 860, 862, 876, 882, 887, 894, 926, ] as const - export const type = isly.named("isoly.CountryCode.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.CountryCode.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(country: Alpha2 | Alpha3): Numeric { return Alpha2.is(country) ? alpha2ToNumeric[country] : from(Alpha2.from(country)) } diff --git a/CountryCode/index.ts b/CountryCode/index.ts index 4fa50bb..426eb7e 100644 --- a/CountryCode/index.ts +++ b/CountryCode/index.ts @@ -11,7 +11,7 @@ export namespace CountryCode { export import Alpha3 = CountryCodeAlpha3 export import Name = CountryCodeName export import Numeric = CountryCodeNumeric - export const type = isly.union(Alpha2.type, Alpha3.type, Numeric.type) - export const is = type.is - export const flaw = type.flaw + export const type = isly("union", Alpha2.type, Alpha3.type, Numeric.type).rename("isoly.CountryCode") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } diff --git a/Currency/Code.ts b/Currency/Code.ts index c7d0070..96318c0 100644 --- a/Currency/Code.ts +++ b/Currency/Code.ts @@ -185,9 +185,9 @@ export namespace Code { "997", "999", ] as const - export const type = isly.named("isoly.CurrencyCode", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.CurrencyCode") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(currency: Currency): Code { return { ALL: "008", diff --git a/Currency/index.ts b/Currency/index.ts index 329b848..4294d1a 100644 --- a/Currency/index.ts +++ b/Currency/index.ts @@ -185,9 +185,9 @@ export namespace Currency { "ZMW", "ZWL", ] as const - export const type = isly.named("isoly.Currency", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Currency") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export type Code = CurrencyCode export const Code = CurrencyCode export function round(value: number, currency: Currency): number { diff --git a/Date/Day/Numeric.ts b/Date/Day/Numeric.ts index 1ab6b8d..84b38a1 100644 --- a/Date/Day/Numeric.ts +++ b/Date/Day/Numeric.ts @@ -7,9 +7,9 @@ export namespace Numeric { export const values = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, ] as const - export const type = isly.named("isoly.Date.Day.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.Date.Day.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function parse(value: Day): Numeric export function parse(value: string): Numeric | undefined diff --git a/Date/Day/index.ts b/Date/Day/index.ts index 8a8135c..f3a0a02 100644 --- a/Date/Day/index.ts +++ b/Date/Day/index.ts @@ -38,9 +38,9 @@ export namespace Day { "30", "31", ] as const - export const type = isly.named("isoly.Date.Day", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Date.Day") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function create(value: Day.Numeric): Day export function create(value: number): Day | undefined export function create(value: number): string | undefined { diff --git a/Date/Month/Numeric.ts b/Date/Month/Numeric.ts index f5b826f..e63385d 100644 --- a/Date/Month/Numeric.ts +++ b/Date/Month/Numeric.ts @@ -5,9 +5,9 @@ export type Numeric = typeof Numeric.values[number] export namespace Numeric { export const values = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] as const - export const type = isly.named("isoly.Date.Month.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.Date.Month.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function parse(value: Month): Numeric export function parse(value: string): Numeric | undefined diff --git a/Date/Month/index.ts b/Date/Month/index.ts index bdeb31a..6ea7f2a 100644 --- a/Date/Month/index.ts +++ b/Date/Month/index.ts @@ -7,9 +7,9 @@ export type Month = typeof Month.values[number] export namespace Month { export import Numeric = MonthNumeric export const values = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"] as const - export const type = isly.named("isoly.Date.Month", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Date.Month") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function create(value: Numeric): Month export function create(value: number): Month | undefined export function create(value: number): string | undefined { diff --git a/Date/Numeric.ts b/Date/Numeric.ts index 5a42f82..e5e46ea 100644 --- a/Date/Numeric.ts +++ b/Date/Numeric.ts @@ -8,12 +8,13 @@ export interface Numeric { } export namespace Numeric { - export const type = isly.object( - { years: isly.number().optional(), months: isly.number().optional(), days: isly.number().optional() }, + export const type = isly( + "object", + { years: isly("number").optional(), months: isly("number").optional(), days: isly("number").optional() }, "isoly.Date.Numeric" ) - export const is = type.is - export const flaw = type.flaw + export const is = type.is as typeof type.is + export const flawed = type.flawed as typeof type.flawed export function parse(value: Date | string | undefined): Numeric { const [year, month, day] = value diff --git a/Date/Year/Numeric.ts b/Date/Year/Numeric.ts index a4ddaa0..d10b2a8 100644 --- a/Date/Year/Numeric.ts +++ b/Date/Year/Numeric.ts @@ -3,12 +3,12 @@ import type { Year } from "./index" export type Numeric = number export namespace Numeric { - export const type = isly.named( - "isoly.Date.Year.Numeric", - isly.number(value => value >= 0 && value <= 9999 && Number.isInteger(value)) - ) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "range", 0, 9999) + .restrict("integer") + .rename("isoly.Date.Year.Numeric") + .describe("Numeric year between 0 and 9999.") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function parse(value: Year): Numeric export function parse(value: string): Numeric | undefined export function parse(value: string | Year): Numeric | undefined { diff --git a/Date/Year/index.ts b/Date/Year/index.ts index 78367de..15079d8 100644 --- a/Date/Year/index.ts +++ b/Date/Year/index.ts @@ -6,12 +6,11 @@ export type Year = `${Digit}${Digit}${Digit}${Digit}` export namespace Year { export import Numeric = YearNumeric - export const type = isly.named( - "isoly.Date.Year", - isly.string((value: string) => /^[0-9]{4}$/.test(value), "YYYY") - ) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", /^[0-9]{4}$/) + .rename("isoly.Date.Year") + .describe("Year in a 4-digit form (YYYY).") + export const is = type.is.bind(type) + export const flawed = type.flawed.bind(type) export function create(value: Numeric): Year export function create(value: number): Year | undefined export function create(value: number | Numeric): Year | undefined { diff --git a/Date/index.ts b/Date/index.ts index f145be5..19436de 100644 --- a/Date/index.ts +++ b/Date/index.ts @@ -14,9 +14,9 @@ export namespace Date { export import Numeric = DateNumeric export import Year = DateYear - export const type = isly.named( - "isoly.Date", - isly.string((value: string) => { + export const type = isly( + "string", + (value: string) => { const splitted = /^\d{4}-\d{2}-\d{2}$/.test(value) && Date.split(value) return ( splitted && @@ -25,11 +25,13 @@ export namespace Date { Date.Day.type.is(splitted[2]) && Date.Month.length(splitted[1], splitted[0]) >= Date.Day.Numeric.parse(splitted[2]) ) - }, "YYYY-MM-DD") + }, + "YYYY-MM-DD" ) - export const is = type.is - export const flaw = type.flaw - + .rename("isoly.Date") + .describe("Date string in format YYYY-MM-DD.") + export const is = type.is.bind(type) as typeof type.is as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed as typeof type.flawed export function split(value: Date): [Year, Month, Day] { return value.split("-", 3) as [Year, Month, Day] } diff --git a/DateRange/index.ts b/DateRange/index.ts index 194a20d..d83aae6 100644 --- a/DateRange/index.ts +++ b/DateRange/index.ts @@ -7,9 +7,9 @@ export interface DateRange { } export namespace DateRange { - export const type = isly.object({ start: Date.type, end: Date.type }, "isoly.DateRange") - export const is = type.is - export const flaw = type.flaw + export const type = isly("object", { start: Date.type, end: Date.type }, "isoly.DateRange") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function create(start: Date, end: Date): DateRange export function create(date: Date, length: DateSpan): DateRange export function create(start: Date, end: Date | DateSpan): DateRange { diff --git a/DateSpan/index.ts b/DateSpan/index.ts index 5aaed0e..3566418 100644 --- a/DateSpan/index.ts +++ b/DateSpan/index.ts @@ -7,11 +7,11 @@ export interface DateSpan { } export namespace DateSpan { - export const type = isly.object({ - years: isly.number().optional(), - months: isly.number().optional(), - days: isly.number().optional(), + export const type = isly("object", { + years: isly("number").optional(), + months: isly("number").optional(), + days: isly("number").optional(), }) - export const is = type.is - export const flaw = type.flaw + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } diff --git a/DateTime/Numeric.ts b/DateTime/Numeric.ts index f6ab10a..d9aca4b 100644 --- a/DateTime/Numeric.ts +++ b/DateTime/Numeric.ts @@ -8,13 +8,14 @@ import { DateTime } from "./index" export type Numeric = Date.Numeric & Time.Numeric & { zone?: TimeZone.Offset } export namespace Numeric { - export const type = isly.union( + export const type = isly( + "union", Date.Numeric.type, Time.Numeric.type, - isly.object<{ zone?: TimeZone.Offset }>({ zone: TimeZone.Offset.type.optional() }) - ) - export const is = type.is - export const flaw = type.flaw + isly<{ zone?: TimeZone.Offset }>("object", { zone: TimeZone.Offset.type.optional() }) + ).rename("isoly.DateTime.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function parse(value: DateTime | string): Numeric { const [date, splitted]: (string | undefined)[] = value.split("T", 2) const [time, zone]: (string | undefined)[] = splitted?.split(/(Z|[+-].{5})?$/, 2) ?? [] diff --git a/DateTime/index.ts b/DateTime/index.ts index dedb124..7c7adc2 100644 --- a/DateTime/index.ts +++ b/DateTime/index.ts @@ -10,15 +10,18 @@ export type DateTime = string export namespace DateTime { export import Numeric = DateTimeNumeric - export const type = isly.named( - "isoly.DateTime", - isly.string((value: string) => { + export const type = isly( + "string", + (value: string) => { const { date, time, timeZoneOffset } = DateTime.split(value) return Date.is(date) && Time.type.optional().is(time) && TimeZone.Offset.type.optional().is(timeZoneOffset) - }) + }, + "YYYY-MM-DDTHH[:mm[:ss[.fff]]][Z|(+|-)HH:MM]" ) - export const is = type.is - export const flaw = type.flaw + .rename("isoly.DateTime") + .describe("Valid ISO 8601 date-time formats include YYYY-MM-DDTHH[:mm[:ss[.fff]]][Z|(+|-)HH:MM].") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function split(value: DateTime): { date: Date time: Time | undefined diff --git a/DayOfWeek/Numeric.ts b/DayOfWeek/Numeric.ts index 87ee9fc..6cd4a93 100644 --- a/DayOfWeek/Numeric.ts +++ b/DayOfWeek/Numeric.ts @@ -5,9 +5,9 @@ export type Numeric = typeof Numeric.values[number] export namespace Numeric { export const values = [1, 2, 3, 4, 5, 6, 7] as const - export const type = isly.named("isoly.DayOfWeek.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.DayOfWeek.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(date: Date): Numeric { return (((Date.getWeekDay(date) + 7 - 1) % 7) + 1) as Numeric } diff --git a/DayOfWeek/index.ts b/DayOfWeek/index.ts index e757c08..8c75114 100644 --- a/DayOfWeek/index.ts +++ b/DayOfWeek/index.ts @@ -7,9 +7,11 @@ export type DayOfWeek = typeof DayOfWeek.values[number] export namespace DayOfWeek { export import Numeric = DayOfWeekNumeric export const values = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] as const - export const type = isly.named("isoly.DayOfWeek", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values) + .rename("isoly.DayOfWeek") + .describe("Lower case weekday name in English.") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function from(value: Numeric | Date): DayOfWeek { return Numeric.is(value) ? values[value - 1] : from(Numeric.from(value)) diff --git a/Encoding/index.ts b/Encoding/index.ts index 89f8160..e16fd23 100644 --- a/Encoding/index.ts +++ b/Encoding/index.ts @@ -77,9 +77,9 @@ export namespace Encoding { "ISO-2022-KR", "T.51", ] as const - export const type = isly.named("isoly.Encoding", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Encoding") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function parse(value: string): Encoding | undefined { let result: Encoding | undefined switch (value.toUpperCase()) { diff --git a/Language/index.ts b/Language/index.ts index 6e2f58e..4ca3040 100644 --- a/Language/index.ts +++ b/Language/index.ts @@ -189,9 +189,9 @@ export namespace Language { "za", "zu", ] as const - export const type = isly.named("isoly.Language", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Language") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function toName(language: Language): string { const names: Record = { ab: "Abkhazian", diff --git a/Locale/index.ts b/Locale/index.ts index 9f6f587..b2b5c86 100644 --- a/Locale/index.ts +++ b/Locale/index.ts @@ -216,9 +216,9 @@ export namespace Locale { "zh-TW", "zu-ZA", ] as const - export const type = isly.named("isoly.Locale", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Locale") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function toLanguage(locale: Locale): Language | undefined { const result = locale.split("-").shift() diff --git a/Month/index.ts b/Month/index.ts index 7b923f2..2b43de5 100644 --- a/Month/index.ts +++ b/Month/index.ts @@ -4,15 +4,18 @@ import { Date } from "../Date" export type Month = `${number}-${Date.Month}` export namespace Month { - export const type = isly.named( - "isoly.Month", - isly.string(value => { + export const type = isly( + "string", + value => { const match = /^(\d{4})-(\d{2})$/.exec(value) return !!match && Date.Year.is(match[1]) && Date.Month.is(match[2]) - }, "YYYY-MM") + }, + "YYYY-MM" ) - export const is = type.is - export const flaw = type.flaw + .rename("isoly.Month") + .describe("ISO 8601 month in the format YYYY-MM.") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function now(): Month { return from(Date.now()) diff --git a/Time/Hour.ts b/Time/Hour.ts index d860d35..c54328f 100644 --- a/Time/Hour.ts +++ b/Time/Hour.ts @@ -29,17 +29,17 @@ export namespace Hour { "22", "23", ] as const - export const type = isly.named("isoly.Time.Hour", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Time.Hour") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export type Numeric = typeof Numeric.values[number] export namespace Numeric { export const values = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, ] as const - export const type = isly.named("isoly.Time.Hour.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.Time.Hour.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } export function parse(value: Hour): Hour.Numeric export function parse(value: string): Hour.Numeric | undefined diff --git a/Time/Millisecond.ts b/Time/Millisecond.ts index 13e60e2..8134d8d 100644 --- a/Time/Millisecond.ts +++ b/Time/Millisecond.ts @@ -4,17 +4,16 @@ type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" export type Millisecond = `${Digit}${Digit}${Digit}` export namespace Millisecond { - export const type = isly.named("isoly.Time.Millisecond", isly.string(/^[0-9]{3}$/)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", /^[0-9]{3}$/) + .rename("isoly.Time.Millisecond") + .describe("Milliseconds expressed as 3 digits left padded with zeros when required.") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export type Numeric = number export namespace Numeric { - export const type = isly.named( - "isoly.Time.Millisecond.Numeric", - isly.number(value => value >= 0 && value <= 999) - ) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "range", 0, 999).rename("isoly.Time.Millisecond.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } export function parse(value: Millisecond): Millisecond.Numeric export function parse(value: string): Millisecond.Numeric | undefined diff --git a/Time/Minute.ts b/Time/Minute.ts index 40b42c2..1247eef 100644 --- a/Time/Minute.ts +++ b/Time/Minute.ts @@ -65,9 +65,9 @@ export namespace Minute { "58", "59", ] as const - export const type = isly.named("isoly.Time.Minute", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Time.Minute") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export type Numeric = typeof Numeric.values[number] export namespace Numeric { export const values = [ @@ -75,9 +75,9 @@ export namespace Minute { 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, ] as const - export const type = isly.named("isoly.Time.Minute.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.Time.Minute.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } export function parse(value: Minute): Minute.Numeric export function parse(value: string): Minute.Numeric | undefined diff --git a/Time/Numeric.ts b/Time/Numeric.ts index 7a33667..de6b515 100644 --- a/Time/Numeric.ts +++ b/Time/Numeric.ts @@ -5,14 +5,18 @@ import { Precision } from "./Precision" export type Numeric = Partial> export namespace Numeric { - export const type = isly.object({ - hours: isly.number().optional(), - minutes: isly.number().optional(), - seconds: isly.number().optional(), - milliseconds: isly.number().optional(), - }) - export const is = type.is - export const flaw = type.flaw + export const type = isly( + "object", + { + hours: isly("number").optional(), + minutes: isly("number").optional(), + seconds: isly("number").optional(), + milliseconds: isly("number").optional(), + }, + "isoly.Time.Numeric" + ) + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export function create(epoch: number, precision: Precision = "seconds"): Required { const integerDivision = (dividend: number, divisor: number) => [Math.trunc(dividend / divisor), dividend % divisor] const [s, milliseconds] = integerDivision(epoch * Precision.factor[precision], 1000) diff --git a/Time/Precision.ts b/Time/Precision.ts index 96be0a4..ec99d42 100644 --- a/Time/Precision.ts +++ b/Time/Precision.ts @@ -3,9 +3,9 @@ import { isly } from "isly" export type Precision = typeof Precision.values[number] export namespace Precision { export const values = ["hours", "minutes", "seconds", "milliseconds"] as const - export const type = isly.string(Precision.values) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Time.Minute.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export const factor = { hours: 3600000, minutes: 60000, diff --git a/Time/Second.ts b/Time/Second.ts index 67ebb04..12e7f77 100644 --- a/Time/Second.ts +++ b/Time/Second.ts @@ -66,9 +66,9 @@ export namespace Second { "59", "60", // Added leap second ] as const - export const type = isly.named("isoly.Time.Second", isly.string(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("string", "value", ...values).rename("isoly.Time.Second") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed export type Numeric = typeof Numeric.values[number] export namespace Numeric { export const values = [ @@ -134,9 +134,9 @@ export namespace Second { 59, 60, // Added leap second ] as const - export const type = isly.named("isoly.Time.Second.Numeric", isly.number(values)) - export const is = type.is - export const flaw = type.flaw + export const type = isly("number", "value", ...values).rename("isoly.Time.Second.Numeric") + export const is = type.is.bind(type) as typeof type.is + export const flawed = type.flawed.bind(type) as typeof type.flawed } export function parse(value: Second): Second.Numeric export function parse(value: string): Second.Numeric | undefined diff --git a/Time/index.ts b/Time/index.ts index 7c7a9ce..9022236 100644 --- a/Time/index.ts +++ b/Time/index.ts @@ -16,9 +16,9 @@ export namespace Time { export import Precision = TimePrecision export import Second = TimeSecond - export const type = isly.named( - "isoly.Time", - isly.string