Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"isly",
"isoly",
"langly",
"måndag",
"paramly",
"persistly",
"selectivly",
Expand All @@ -58,10 +59,10 @@
"smoothly",
"tidily",
"transactly",
"transcoders",
"typedly",
"uply",
"måndag",
"transcoders"
"Utily"
],
"typescript.tsdk": "node_modules/typescript/lib"
}
24 changes: 12 additions & 12 deletions Address/GB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export type GB = {
}

export namespace GB {
export const type = isly.object<GB>(
{
countryCode: isly.string<"GB">("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 { type, is, flawed } = isly
.object<GB>(
{
countryCode: isly.string("value", "GB"),
street: isly.string(),
building: isly.string(),
zipCode: isly.string(),
city: isly.string(),
},
"isoly.Address.GB"
)
.bind()
}
26 changes: 13 additions & 13 deletions Address/Generic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export type Generic = {
}

export namespace Generic {
export const type = isly.object<Generic>(
{
countryCode: CountryCode.Alpha2.type,
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 { type, is, flawed } = isly
.object<Generic>(
{
countryCode: CountryCode.Alpha2.type,
street: isly.string(),
zipCode: isly.string(),
city: isly.string(),
county: isly.string().optional(),
state: isly.string().optional(),
},
"isoly.Address.Generic"
)
.bind()
}
22 changes: 11 additions & 11 deletions Address/SE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export type SE = {
}

export namespace SE {
export const type = isly.object<SE>(
{
countryCode: isly.string<"SE">("SE"),
street: isly.string(),
zipCode: isly.string(),
city: isly.string(),
},
"isoly.Address.SE"
)
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.object<SE>(
{
countryCode: isly.string<"SE">("value", "SE"),
street: isly.string(),
zipCode: isly.string(),
city: isly.string(),
},
"isoly.Address.SE"
)
.bind()
}
2 changes: 1 addition & 1 deletion Address/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export namespace Address {
export import Generic = AddressGeneric
export import GB = AddressGB
export import SE = AddressSE
export const type = isly.named("isoly.Address", isly.union<Address>(Generic.type, GB.type, SE.type))
export const { type, is, flawed } = isly.union<Address>(Generic.type, GB.type, SE.type).rename("isoly.Address").bind()
}
7 changes: 4 additions & 3 deletions CallingCode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,10 @@ export namespace CallingCode {
"+260",
"+263",
] as const
export const type = isly.named("isoly.CallingCode", isly.string<CallingCode>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<CallingCode>("value", ...values)
.rename("isoly.CallingCode")
.bind()
export function from(country: CountryCode.Alpha2): CallingCode | undefined {
return alpha2toCallingCode[country]
}
Expand Down
6 changes: 3 additions & 3 deletions CountryCode/Alpha2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@
"ZM",
"ZW",
] as const
export const type = isly.named("isoly.CountryCode.Alpha2", isly.string<Alpha2>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly.string<Alpha2>("value", ...values)

Check warning on line 260 in CountryCode/Alpha2.ts

View workflow job for this annotation

GitHub Actions / Lint

Insert ´⏎↹↹´
.rename("isoly.CountryCode.Alpha2")
.bind()
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 {
Expand Down
7 changes: 4 additions & 3 deletions CountryCode/Alpha3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ export namespace Alpha3 {
"ZMB",
"ZWE",
] as const
export const type = isly.named("isoly.CountryCode.Alpha3", isly.string<Alpha3>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Alpha3>("value", ...values)
.rename("isoly.CountryCode.Alpha3")
.bind()
export function from(country: Alpha2 | Numeric): Alpha3 {
return typeof country == "number" ? from(Alpha2.from(country)) : alpha2ToAlpha3[country]
}
Expand Down
7 changes: 4 additions & 3 deletions CountryCode/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ 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<Numeric>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.number<Numeric>("value", ...values)
.rename("isoly.CountryCode.Numeric")
.bind()
export function from(country: Alpha2 | Alpha3): Numeric {
return Alpha2.is(country) ? alpha2ToNumeric[country] : from(Alpha2.from(country))
}
Expand Down
7 changes: 4 additions & 3 deletions CountryCode/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export namespace CountryCode {
export import Alpha3 = CountryCodeAlpha3
export import Name = CountryCodeName
export import Numeric = CountryCodeNumeric
export const type = isly.union<CountryCode>(Alpha2.type, Alpha3.type, Numeric.type)
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.union<CountryCode>(Alpha2.type, Alpha3.type, Numeric.type)
.rename("isoly.CountryCode")
.bind()
}
7 changes: 4 additions & 3 deletions Currency/Code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ export namespace Code {
"997",
"999",
] as const
export const type = isly.named("isoly.CurrencyCode", isly.string<Code>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Code>("value", ...values)
.rename("isoly.CurrencyCode")
.bind()
export function from(currency: Currency): Code {
return {
ALL: "008",
Expand Down
7 changes: 4 additions & 3 deletions Currency/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,10 @@ export namespace Currency {
"ZMW",
"ZWL",
] as const
export const type = isly.named("isoly.Currency", isly.string<Currency>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Currency>("value", ...values)
.rename("isoly.Currency")
.bind()
export type Code = CurrencyCode
export const Code = CurrencyCode
export function round(value: number, currency: Currency): number {
Expand Down
7 changes: 4 additions & 3 deletions Date/Day/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ 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<Numeric>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.number<Numeric>("value", ...values)
.rename("isoly.Date.Day.Numeric")
.bind()

export function parse(value: Day): Numeric
export function parse(value: string): Numeric | undefined
Expand Down
7 changes: 4 additions & 3 deletions Date/Day/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ export namespace Day {
"30",
"31",
] as const
export const type = isly.named("isoly.Date.Day", isly.string<Day>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Day>("value", ...values)
.rename("isoly.Date.Day")
.bind()
export function create(value: Day.Numeric): Day
export function create(value: number): Day | undefined
export function create(value: number): string | undefined {
Expand Down
7 changes: 4 additions & 3 deletions Date/Month/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ 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<Numeric>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.number<Numeric>("value", ...values)
.rename("isoly.Date.Month.Numeric")
.bind()

export function parse(value: Month): Numeric
export function parse(value: string): Numeric | undefined
Expand Down
7 changes: 4 additions & 3 deletions Date/Month/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ 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<Month>(values))
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Month>("value", ...values)
.rename("isoly.Date.Month")
.bind()
export function create(value: Numeric): Month
export function create(value: number): Month | undefined
export function create(value: number): string | undefined {
Expand Down
12 changes: 6 additions & 6 deletions Date/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface Numeric {
}

export namespace Numeric {
export const type = isly.object<Numeric>(
{ 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 { type, is, flawed } = isly
.object<Numeric>(
{ years: isly.number().optional(), months: isly.number().optional(), days: isly.number().optional() },
"isoly.Date.Numeric"
)
.bind()
export function parse(value: Date | string | undefined): Numeric {
const [year, month, day] =
value
Expand Down
12 changes: 6 additions & 6 deletions Date/Year/Numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Numeric>(value => value >= 0 && value <= 9999 && Number.isInteger(value))
)
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.number<Numeric>("range", 0, 9999)
.restrict("integer")
.rename("isoly.Date.Year.Numeric")
.describe("Numeric year between 0 and 9999.")
.bind()
export function parse(value: Year): Numeric
export function parse(value: string): Numeric | undefined
export function parse(value: string | Year): Numeric | undefined {
Expand Down
11 changes: 5 additions & 6 deletions Date/Year/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Year>((value: string) => /^[0-9]{4}$/.test(value), "YYYY")
)
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.string<Year>("value", /^[0-9]{4}$/)
.rename("isoly.Date.Year")
.describe("Year in a 4-digit form (YYYY).")
.bind()
export function create(value: Numeric): Year
export function create(value: number): Year | undefined
export function create(value: number | Numeric): Year | undefined {
Expand Down
12 changes: 5 additions & 7 deletions Date/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export namespace Date {
export import Numeric = DateNumeric
export import Year = DateYear

export const type = isly.named(
"isoly.Date",
isly.string<Date>((value: string) => {
export const { type, is, flawed } = isly
.string<Date>((value: string) => {
const splitted = /^\d{4}-\d{2}-\d{2}$/.test(value) && Date.split(value)
return (
splitted &&
Expand All @@ -26,10 +25,9 @@ export namespace Date {
Date.Month.length(splitted[1], splitted[0]) >= Date.Day.Numeric.parse(splitted[2])
)
}, "YYYY-MM-DD")
)
export const is = type.is
export const flaw = type.flaw

.rename("isoly.Date")
.describe("Date string in format YYYY-MM-DD.")
.bind()
export function split(value: Date): [Year, Month, Day] {
return value.split("-", 3) as [Year, Month, Day]
}
Expand Down
6 changes: 3 additions & 3 deletions DateRange/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface DateRange {
}

export namespace DateRange {
export const type = isly.object<DateRange>({ start: Date.type, end: Date.type }, "isoly.DateRange")
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.object<DateRange>({ start: Date.type, end: Date.type }, "isoly.DateRange")
.bind()
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 {
Expand Down
14 changes: 7 additions & 7 deletions DateSpan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export interface DateSpan {
}

export namespace DateSpan {
export const type = isly.object<DateSpan>({
years: isly.number().optional(),
months: isly.number().optional(),
days: isly.number().optional(),
})
export const is = type.is
export const flaw = type.flaw
export const { type, is, flawed } = isly
.object<DateSpan>({
years: isly.number().optional(),
months: isly.number().optional(),
days: isly.number().optional(),
})
.bind()
}
Loading
Loading