{"version":3,"file":"uri.mjs","sources":["../../../../src/predefined/brand/string/uri.mts"],"sourcesContent":["import { type Brand, type NonEmptyString } from 'ts-type-forge';\nimport { brand } from '../../../brand/index.mjs';\nimport { string } from '../../../primitives/index.mjs';\nimport { type Type } from '../../../type.mjs';\n\n// An absolute URI/URL always has a non-empty scheme, so `Uri` is branded on\n// top of `NonEmptyString` and is assignable to it.\nexport type Uri = Brand<NonEmptyString, 'Uri'>;\n\n/**\n * @link https://url.spec.whatwg.org/\n */\nexport const uri = (\n  options?: Partial<\n    Readonly<{\n      defaultValue: string;\n    }>\n  >,\n): Type<Uri> =>\n  brand<NonEmptyString, readonly ['Uri']>({\n    baseType: string(options?.defaultValue ?? defaultUri, { nonempty: true }),\n    is: isUri,\n    brandKeys: ['Uri'],\n    typeName: 'Uri',\n  });\n\nconst defaultUri = 'https://example.com';\n\n// `URL.canParse` trims leading/trailing ASCII whitespace per the WHATWG URL parser, so\n// surrounding whitespace must be rejected explicitly to avoid accepting e.g. \" https://example.com \".\nconst isUri = (s: string): s is Uri => s === s.trim() && URL.canParse(s);\n\nif (import.meta.vitest !== undefined) {\n  test('defaultUri', () => {\n    assert.isTrue(isUri(defaultUri));\n  });\n}\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,GAAA,GAAM,CACjB,OAAA,KAMA,KAAA,CAAwC;AAAA,EACtC,QAAA,EAAU,OAAO,OAAA,EAAS,YAAA,IAAgB,YAAY,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,EACxE,EAAA,EAAI,KAAA;AAAA,EACJ,SAAA,EAAW,CAAC,KAAK,CAAA;AAAA,EACjB,QAAA,EAAU;AACZ,CAAC;AAEH,MAAM,UAAA,GAAa,qBAAA;AAInB,MAAM,KAAA,GAAQ,CAAC,CAAA,KAAwB,CAAA,KAAM,EAAE,IAAA,EAAK,IAAK,GAAA,CAAI,QAAA,CAAS,CAAC,CAAA;;;;"}