@optique/core 1.1.0-dev.2057 → 1.1.0-dev.2069
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/valueparser.cjs +1223 -0
- package/dist/valueparser.d.cts +232 -1
- package/dist/valueparser.d.ts +232 -1
- package/dist/valueparser.js +1222 -1
- package/package.json +1 -1
package/dist/valueparser.d.cts
CHANGED
|
@@ -747,6 +747,83 @@ declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync",
|
|
|
747
747
|
* @since 1.1.0
|
|
748
748
|
*/
|
|
749
749
|
declare function fileSize(options: FileSizeOptionsBigInt): ValueParser<"sync", bigint>;
|
|
750
|
+
/**
|
|
751
|
+
* A structured CSS color value with normalized RGBA components.
|
|
752
|
+
* @since 1.1.0
|
|
753
|
+
*/
|
|
754
|
+
interface Color {
|
|
755
|
+
/** Red channel, 0–255. */
|
|
756
|
+
readonly r: number;
|
|
757
|
+
/** Green channel, 0–255. */
|
|
758
|
+
readonly g: number;
|
|
759
|
+
/** Blue channel, 0–255. */
|
|
760
|
+
readonly b: number;
|
|
761
|
+
/** Alpha channel, 0–1 (1 = fully opaque). */
|
|
762
|
+
readonly a: number;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* The CSS color notation a {@link color} parser accepts.
|
|
766
|
+
* @since 1.1.0
|
|
767
|
+
*/
|
|
768
|
+
type ColorFormat = "hex" | "rgb" | "hsl" | "named";
|
|
769
|
+
/**
|
|
770
|
+
* Options for creating a {@link color} value parser.
|
|
771
|
+
* @since 1.1.0
|
|
772
|
+
*/
|
|
773
|
+
interface ColorOptions {
|
|
774
|
+
/**
|
|
775
|
+
* The metavariable name for this parser. Used in help messages to
|
|
776
|
+
* indicate what kind of value this parser expects.
|
|
777
|
+
* @default `"COLOR"`
|
|
778
|
+
*/
|
|
779
|
+
readonly metavar?: NonEmptyString;
|
|
780
|
+
/**
|
|
781
|
+
* Restricts which CSS color notations are accepted. Defaults to all
|
|
782
|
+
* four notations: `"hex"`, `"rgb"`, `"hsl"`, and `"named"`.
|
|
783
|
+
* @default all formats
|
|
784
|
+
*/
|
|
785
|
+
readonly formats?: readonly ColorFormat[];
|
|
786
|
+
/**
|
|
787
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
788
|
+
* @default `{ r: 0, g: 0, b: 0, a: 1 }`
|
|
789
|
+
* @since 1.1.0
|
|
790
|
+
*/
|
|
791
|
+
readonly placeholder?: Color;
|
|
792
|
+
/**
|
|
793
|
+
* Custom error messages for color parsing failures.
|
|
794
|
+
* @since 1.1.0
|
|
795
|
+
*/
|
|
796
|
+
readonly errors?: {
|
|
797
|
+
/**
|
|
798
|
+
* Custom error message when the input is not a valid CSS color string.
|
|
799
|
+
* Can be a static message or a function that receives the raw input.
|
|
800
|
+
*/
|
|
801
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Creates a value parser that accepts CSS color strings and returns a
|
|
806
|
+
* structured {@link Color} object with normalized RGBA components.
|
|
807
|
+
*
|
|
808
|
+
* Supported input notations by default:
|
|
809
|
+
* - Hex: `#rgb`, `#rrggbb`, `#rgba`, `#rrggbbaa`
|
|
810
|
+
* - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`
|
|
811
|
+
* - HSL: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
|
|
812
|
+
* - Named: all 148 CSS Level 4 named colors (e.g., `red`, `rebeccapurple`)
|
|
813
|
+
*
|
|
814
|
+
* The `format()` method always outputs canonical lowercase hex
|
|
815
|
+
* (`#rrggbb` when fully opaque, `#rrggbbaa` otherwise).
|
|
816
|
+
*
|
|
817
|
+
* @param options Configuration options for the parser.
|
|
818
|
+
* @returns A sync value parser producing {@link Color} objects.
|
|
819
|
+
* @throws {TypeError} If {@link ColorOptions.metavar} is an empty string, or
|
|
820
|
+
* if {@link ColorOptions.formats} contains an invalid format name.
|
|
821
|
+
* @throws {RangeError} If {@link ValueParser.format} is called with a
|
|
822
|
+
* {@link Color} whose `r`, `g`, or `b` channel is not an integer in
|
|
823
|
+
* 0–255, or whose `a` channel is not a finite number in 0–1.
|
|
824
|
+
* @since 1.1.0
|
|
825
|
+
*/
|
|
826
|
+
declare function color(options?: ColorOptions): ValueParser<"sync", Color>;
|
|
750
827
|
/**
|
|
751
828
|
* Options for creating a {@link url} parser.
|
|
752
829
|
*/
|
|
@@ -2328,5 +2405,159 @@ interface CidrOptions {
|
|
|
2328
2405
|
* @since 0.10.0
|
|
2329
2406
|
*/
|
|
2330
2407
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
2408
|
+
/**
|
|
2409
|
+
* A normalized Semantic Versioning 2.0.0 string.
|
|
2410
|
+
*
|
|
2411
|
+
* Covers all four valid forms:
|
|
2412
|
+
* - `MAJOR.MINOR.PATCH`
|
|
2413
|
+
* - `MAJOR.MINOR.PATCH-preRelease`
|
|
2414
|
+
* - `MAJOR.MINOR.PATCH+metadata`
|
|
2415
|
+
* - `MAJOR.MINOR.PATCH-preRelease+metadata`
|
|
2416
|
+
*
|
|
2417
|
+
* Note: this type uses TypeScript template literals as a coarse structural
|
|
2418
|
+
* hint. The `${number}` slots accept any JavaScript number serialization
|
|
2419
|
+
* (including negative numbers, decimals, and `Infinity`), so the type alone
|
|
2420
|
+
* does not guarantee full SemVer 2.0.0 validity. Full validation is
|
|
2421
|
+
* enforced at parse time by {@link semVer}. Only values returned by
|
|
2422
|
+
* `semVer().parse()` are guaranteed to conform to the specification.
|
|
2423
|
+
*
|
|
2424
|
+
* @since 1.1.0
|
|
2425
|
+
*/
|
|
2426
|
+
type SemVerString = `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}` | `${number}.${number}.${number}+${string}` | `${number}.${number}.${number}-${string}+${string}`;
|
|
2427
|
+
/**
|
|
2428
|
+
* A parsed Semantic Versioning 2.0.0 value as a structured object.
|
|
2429
|
+
*
|
|
2430
|
+
* @since 1.1.0
|
|
2431
|
+
*/
|
|
2432
|
+
interface SemVer {
|
|
2433
|
+
/**
|
|
2434
|
+
* The major version number.
|
|
2435
|
+
*
|
|
2436
|
+
* This field is a JavaScript `number`, so it is limited to
|
|
2437
|
+
* {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Inputs whose major
|
|
2438
|
+
* component exceeds this value are rejected by {@link semVer} in object
|
|
2439
|
+
* mode; use string mode to handle arbitrarily large version numbers.
|
|
2440
|
+
*/
|
|
2441
|
+
readonly major: number;
|
|
2442
|
+
/**
|
|
2443
|
+
* The minor version number.
|
|
2444
|
+
*
|
|
2445
|
+
* Same safe-integer constraint as {@link major}.
|
|
2446
|
+
*/
|
|
2447
|
+
readonly minor: number;
|
|
2448
|
+
/**
|
|
2449
|
+
* The patch version number.
|
|
2450
|
+
*
|
|
2451
|
+
* Same safe-integer constraint as {@link major}.
|
|
2452
|
+
*/
|
|
2453
|
+
readonly patch: number;
|
|
2454
|
+
/**
|
|
2455
|
+
* The pre-release identifier (the part after `-`, before `+`), if present.
|
|
2456
|
+
* Example: `"alpha.1"` for `1.0.0-alpha.1`.
|
|
2457
|
+
*/
|
|
2458
|
+
readonly preRelease?: string;
|
|
2459
|
+
/**
|
|
2460
|
+
* The build metadata (the part after `+`), if present.
|
|
2461
|
+
* Example: `"build.42"` for `1.0.0+build.42`.
|
|
2462
|
+
*/
|
|
2463
|
+
readonly metadata?: string;
|
|
2464
|
+
}
|
|
2465
|
+
/** @internal */
|
|
2466
|
+
interface SemVerOptionsBase {
|
|
2467
|
+
/**
|
|
2468
|
+
* The metavariable name for this parser. Used in help messages.
|
|
2469
|
+
* @default `"SEMVER"`
|
|
2470
|
+
*/
|
|
2471
|
+
readonly metavar?: NonEmptyString;
|
|
2472
|
+
/**
|
|
2473
|
+
* Whether to accept an optional leading `v` character (e.g. `v1.2.3`).
|
|
2474
|
+
* The `v` prefix is stripped; output is always the canonical unprefixed form.
|
|
2475
|
+
* @default false
|
|
2476
|
+
*/
|
|
2477
|
+
readonly allowPrefix?: boolean;
|
|
2478
|
+
/**
|
|
2479
|
+
* Custom error messages for parse failures.
|
|
2480
|
+
* @since 1.1.0
|
|
2481
|
+
*/
|
|
2482
|
+
readonly errors?: {
|
|
2483
|
+
/**
|
|
2484
|
+
* Message when input is not a valid SemVer string.
|
|
2485
|
+
* Can be a static message or a function receiving the rejected input.
|
|
2486
|
+
*/
|
|
2487
|
+
readonly invalidSemVer?: Message | ((input: string) => Message);
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Options for {@link semVer} in string mode (the default).
|
|
2492
|
+
*
|
|
2493
|
+
* @since 1.1.0
|
|
2494
|
+
*/
|
|
2495
|
+
interface SemVerOptionsString extends SemVerOptionsBase {
|
|
2496
|
+
/** Return a {@link SemVerString} template-literal type. */
|
|
2497
|
+
readonly type?: "string";
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Options for {@link semVer} in object mode.
|
|
2501
|
+
*
|
|
2502
|
+
* In object mode, version components are stored as JavaScript `number`
|
|
2503
|
+
* values. Components exceeding {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1)
|
|
2504
|
+
* cannot be represented exactly and are therefore rejected with a parse
|
|
2505
|
+
* error. Use string mode (the default) if you need to handle version
|
|
2506
|
+
* numbers of arbitrary magnitude.
|
|
2507
|
+
*
|
|
2508
|
+
* @since 1.1.0
|
|
2509
|
+
*/
|
|
2510
|
+
interface SemVerOptionsObject extends SemVerOptionsBase {
|
|
2511
|
+
/** Return a structured {@link SemVer} object. */
|
|
2512
|
+
readonly type: "object";
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings.
|
|
2516
|
+
*
|
|
2517
|
+
* In string mode (the default), the parser returns a {@link SemVerString}
|
|
2518
|
+
* template-literal type. String mode accepts any spec-valid SemVer input,
|
|
2519
|
+
* including version components of arbitrary magnitude.
|
|
2520
|
+
*
|
|
2521
|
+
* In object mode (`type: "object"`), the parser returns a structured
|
|
2522
|
+
* {@link SemVer} value with `major`, `minor`, `patch`, and optional
|
|
2523
|
+
* `preRelease` and `metadata` fields. Because the numeric components are
|
|
2524
|
+
* stored as JavaScript `number`, object mode additionally rejects inputs
|
|
2525
|
+
* whose major, minor, or patch value exceeds
|
|
2526
|
+
* {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Use string mode if you need
|
|
2527
|
+
* to handle arbitrarily large version numbers.
|
|
2528
|
+
*
|
|
2529
|
+
* Both modes strictly enforce the SemVer 2.0.0 specification: no leading
|
|
2530
|
+
* zeros in numeric components, no empty pre-release or build identifiers,
|
|
2531
|
+
* and no invalid characters.
|
|
2532
|
+
*
|
|
2533
|
+
* [Semantic Versioning 2.0.0]: https://semver.org/
|
|
2534
|
+
*
|
|
2535
|
+
* @param options Configuration options.
|
|
2536
|
+
* @returns A {@link ValueParser} that validates SemVer strings.
|
|
2537
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
|
|
2538
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
|
|
2539
|
+
* boolean.
|
|
2540
|
+
* @throws {TypeError} If {@link SemVerOptionsString.type} is not `"string"`,
|
|
2541
|
+
* `"object"`, or `undefined`.
|
|
2542
|
+
* @since 1.1.0
|
|
2543
|
+
*/
|
|
2544
|
+
declare function semVer(options?: SemVerOptionsString): ValueParser<"sync", SemVerString>;
|
|
2545
|
+
/**
|
|
2546
|
+
* Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings,
|
|
2547
|
+
* returning a structured {@link SemVer} object.
|
|
2548
|
+
*
|
|
2549
|
+
* [Semantic Versioning 2.0.0]: https://semver.org/
|
|
2550
|
+
*
|
|
2551
|
+
* @param options Configuration options with `type: "object"`.
|
|
2552
|
+
* @returns A {@link ValueParser} that converts SemVer strings to {@link SemVer}
|
|
2553
|
+
* objects.
|
|
2554
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
|
|
2555
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
|
|
2556
|
+
* boolean.
|
|
2557
|
+
* @throws {TypeError} If {@link SemVerOptionsObject.type} is not `"string"`,
|
|
2558
|
+
* `"object"`, or `undefined`.
|
|
2559
|
+
* @since 1.1.0
|
|
2560
|
+
*/
|
|
2561
|
+
declare function semVer(options: SemVerOptionsObject): ValueParser<"sync", SemVer>;
|
|
2331
2562
|
//#endregion
|
|
2332
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2563
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -747,6 +747,83 @@ declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync",
|
|
|
747
747
|
* @since 1.1.0
|
|
748
748
|
*/
|
|
749
749
|
declare function fileSize(options: FileSizeOptionsBigInt): ValueParser<"sync", bigint>;
|
|
750
|
+
/**
|
|
751
|
+
* A structured CSS color value with normalized RGBA components.
|
|
752
|
+
* @since 1.1.0
|
|
753
|
+
*/
|
|
754
|
+
interface Color {
|
|
755
|
+
/** Red channel, 0–255. */
|
|
756
|
+
readonly r: number;
|
|
757
|
+
/** Green channel, 0–255. */
|
|
758
|
+
readonly g: number;
|
|
759
|
+
/** Blue channel, 0–255. */
|
|
760
|
+
readonly b: number;
|
|
761
|
+
/** Alpha channel, 0–1 (1 = fully opaque). */
|
|
762
|
+
readonly a: number;
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* The CSS color notation a {@link color} parser accepts.
|
|
766
|
+
* @since 1.1.0
|
|
767
|
+
*/
|
|
768
|
+
type ColorFormat = "hex" | "rgb" | "hsl" | "named";
|
|
769
|
+
/**
|
|
770
|
+
* Options for creating a {@link color} value parser.
|
|
771
|
+
* @since 1.1.0
|
|
772
|
+
*/
|
|
773
|
+
interface ColorOptions {
|
|
774
|
+
/**
|
|
775
|
+
* The metavariable name for this parser. Used in help messages to
|
|
776
|
+
* indicate what kind of value this parser expects.
|
|
777
|
+
* @default `"COLOR"`
|
|
778
|
+
*/
|
|
779
|
+
readonly metavar?: NonEmptyString;
|
|
780
|
+
/**
|
|
781
|
+
* Restricts which CSS color notations are accepted. Defaults to all
|
|
782
|
+
* four notations: `"hex"`, `"rgb"`, `"hsl"`, and `"named"`.
|
|
783
|
+
* @default all formats
|
|
784
|
+
*/
|
|
785
|
+
readonly formats?: readonly ColorFormat[];
|
|
786
|
+
/**
|
|
787
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
788
|
+
* @default `{ r: 0, g: 0, b: 0, a: 1 }`
|
|
789
|
+
* @since 1.1.0
|
|
790
|
+
*/
|
|
791
|
+
readonly placeholder?: Color;
|
|
792
|
+
/**
|
|
793
|
+
* Custom error messages for color parsing failures.
|
|
794
|
+
* @since 1.1.0
|
|
795
|
+
*/
|
|
796
|
+
readonly errors?: {
|
|
797
|
+
/**
|
|
798
|
+
* Custom error message when the input is not a valid CSS color string.
|
|
799
|
+
* Can be a static message or a function that receives the raw input.
|
|
800
|
+
*/
|
|
801
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Creates a value parser that accepts CSS color strings and returns a
|
|
806
|
+
* structured {@link Color} object with normalized RGBA components.
|
|
807
|
+
*
|
|
808
|
+
* Supported input notations by default:
|
|
809
|
+
* - Hex: `#rgb`, `#rrggbb`, `#rgba`, `#rrggbbaa`
|
|
810
|
+
* - RGB: `rgb(r, g, b)`, `rgba(r, g, b, a)`
|
|
811
|
+
* - HSL: `hsl(h, s%, l%)`, `hsla(h, s%, l%, a)`
|
|
812
|
+
* - Named: all 148 CSS Level 4 named colors (e.g., `red`, `rebeccapurple`)
|
|
813
|
+
*
|
|
814
|
+
* The `format()` method always outputs canonical lowercase hex
|
|
815
|
+
* (`#rrggbb` when fully opaque, `#rrggbbaa` otherwise).
|
|
816
|
+
*
|
|
817
|
+
* @param options Configuration options for the parser.
|
|
818
|
+
* @returns A sync value parser producing {@link Color} objects.
|
|
819
|
+
* @throws {TypeError} If {@link ColorOptions.metavar} is an empty string, or
|
|
820
|
+
* if {@link ColorOptions.formats} contains an invalid format name.
|
|
821
|
+
* @throws {RangeError} If {@link ValueParser.format} is called with a
|
|
822
|
+
* {@link Color} whose `r`, `g`, or `b` channel is not an integer in
|
|
823
|
+
* 0–255, or whose `a` channel is not a finite number in 0–1.
|
|
824
|
+
* @since 1.1.0
|
|
825
|
+
*/
|
|
826
|
+
declare function color(options?: ColorOptions): ValueParser<"sync", Color>;
|
|
750
827
|
/**
|
|
751
828
|
* Options for creating a {@link url} parser.
|
|
752
829
|
*/
|
|
@@ -2328,5 +2405,159 @@ interface CidrOptions {
|
|
|
2328
2405
|
* @since 0.10.0
|
|
2329
2406
|
*/
|
|
2330
2407
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
2408
|
+
/**
|
|
2409
|
+
* A normalized Semantic Versioning 2.0.0 string.
|
|
2410
|
+
*
|
|
2411
|
+
* Covers all four valid forms:
|
|
2412
|
+
* - `MAJOR.MINOR.PATCH`
|
|
2413
|
+
* - `MAJOR.MINOR.PATCH-preRelease`
|
|
2414
|
+
* - `MAJOR.MINOR.PATCH+metadata`
|
|
2415
|
+
* - `MAJOR.MINOR.PATCH-preRelease+metadata`
|
|
2416
|
+
*
|
|
2417
|
+
* Note: this type uses TypeScript template literals as a coarse structural
|
|
2418
|
+
* hint. The `${number}` slots accept any JavaScript number serialization
|
|
2419
|
+
* (including negative numbers, decimals, and `Infinity`), so the type alone
|
|
2420
|
+
* does not guarantee full SemVer 2.0.0 validity. Full validation is
|
|
2421
|
+
* enforced at parse time by {@link semVer}. Only values returned by
|
|
2422
|
+
* `semVer().parse()` are guaranteed to conform to the specification.
|
|
2423
|
+
*
|
|
2424
|
+
* @since 1.1.0
|
|
2425
|
+
*/
|
|
2426
|
+
type SemVerString = `${number}.${number}.${number}` | `${number}.${number}.${number}-${string}` | `${number}.${number}.${number}+${string}` | `${number}.${number}.${number}-${string}+${string}`;
|
|
2427
|
+
/**
|
|
2428
|
+
* A parsed Semantic Versioning 2.0.0 value as a structured object.
|
|
2429
|
+
*
|
|
2430
|
+
* @since 1.1.0
|
|
2431
|
+
*/
|
|
2432
|
+
interface SemVer {
|
|
2433
|
+
/**
|
|
2434
|
+
* The major version number.
|
|
2435
|
+
*
|
|
2436
|
+
* This field is a JavaScript `number`, so it is limited to
|
|
2437
|
+
* {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Inputs whose major
|
|
2438
|
+
* component exceeds this value are rejected by {@link semVer} in object
|
|
2439
|
+
* mode; use string mode to handle arbitrarily large version numbers.
|
|
2440
|
+
*/
|
|
2441
|
+
readonly major: number;
|
|
2442
|
+
/**
|
|
2443
|
+
* The minor version number.
|
|
2444
|
+
*
|
|
2445
|
+
* Same safe-integer constraint as {@link major}.
|
|
2446
|
+
*/
|
|
2447
|
+
readonly minor: number;
|
|
2448
|
+
/**
|
|
2449
|
+
* The patch version number.
|
|
2450
|
+
*
|
|
2451
|
+
* Same safe-integer constraint as {@link major}.
|
|
2452
|
+
*/
|
|
2453
|
+
readonly patch: number;
|
|
2454
|
+
/**
|
|
2455
|
+
* The pre-release identifier (the part after `-`, before `+`), if present.
|
|
2456
|
+
* Example: `"alpha.1"` for `1.0.0-alpha.1`.
|
|
2457
|
+
*/
|
|
2458
|
+
readonly preRelease?: string;
|
|
2459
|
+
/**
|
|
2460
|
+
* The build metadata (the part after `+`), if present.
|
|
2461
|
+
* Example: `"build.42"` for `1.0.0+build.42`.
|
|
2462
|
+
*/
|
|
2463
|
+
readonly metadata?: string;
|
|
2464
|
+
}
|
|
2465
|
+
/** @internal */
|
|
2466
|
+
interface SemVerOptionsBase {
|
|
2467
|
+
/**
|
|
2468
|
+
* The metavariable name for this parser. Used in help messages.
|
|
2469
|
+
* @default `"SEMVER"`
|
|
2470
|
+
*/
|
|
2471
|
+
readonly metavar?: NonEmptyString;
|
|
2472
|
+
/**
|
|
2473
|
+
* Whether to accept an optional leading `v` character (e.g. `v1.2.3`).
|
|
2474
|
+
* The `v` prefix is stripped; output is always the canonical unprefixed form.
|
|
2475
|
+
* @default false
|
|
2476
|
+
*/
|
|
2477
|
+
readonly allowPrefix?: boolean;
|
|
2478
|
+
/**
|
|
2479
|
+
* Custom error messages for parse failures.
|
|
2480
|
+
* @since 1.1.0
|
|
2481
|
+
*/
|
|
2482
|
+
readonly errors?: {
|
|
2483
|
+
/**
|
|
2484
|
+
* Message when input is not a valid SemVer string.
|
|
2485
|
+
* Can be a static message or a function receiving the rejected input.
|
|
2486
|
+
*/
|
|
2487
|
+
readonly invalidSemVer?: Message | ((input: string) => Message);
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Options for {@link semVer} in string mode (the default).
|
|
2492
|
+
*
|
|
2493
|
+
* @since 1.1.0
|
|
2494
|
+
*/
|
|
2495
|
+
interface SemVerOptionsString extends SemVerOptionsBase {
|
|
2496
|
+
/** Return a {@link SemVerString} template-literal type. */
|
|
2497
|
+
readonly type?: "string";
|
|
2498
|
+
}
|
|
2499
|
+
/**
|
|
2500
|
+
* Options for {@link semVer} in object mode.
|
|
2501
|
+
*
|
|
2502
|
+
* In object mode, version components are stored as JavaScript `number`
|
|
2503
|
+
* values. Components exceeding {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1)
|
|
2504
|
+
* cannot be represented exactly and are therefore rejected with a parse
|
|
2505
|
+
* error. Use string mode (the default) if you need to handle version
|
|
2506
|
+
* numbers of arbitrary magnitude.
|
|
2507
|
+
*
|
|
2508
|
+
* @since 1.1.0
|
|
2509
|
+
*/
|
|
2510
|
+
interface SemVerOptionsObject extends SemVerOptionsBase {
|
|
2511
|
+
/** Return a structured {@link SemVer} object. */
|
|
2512
|
+
readonly type: "object";
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings.
|
|
2516
|
+
*
|
|
2517
|
+
* In string mode (the default), the parser returns a {@link SemVerString}
|
|
2518
|
+
* template-literal type. String mode accepts any spec-valid SemVer input,
|
|
2519
|
+
* including version components of arbitrary magnitude.
|
|
2520
|
+
*
|
|
2521
|
+
* In object mode (`type: "object"`), the parser returns a structured
|
|
2522
|
+
* {@link SemVer} value with `major`, `minor`, `patch`, and optional
|
|
2523
|
+
* `preRelease` and `metadata` fields. Because the numeric components are
|
|
2524
|
+
* stored as JavaScript `number`, object mode additionally rejects inputs
|
|
2525
|
+
* whose major, minor, or patch value exceeds
|
|
2526
|
+
* {@link Number.MAX_SAFE_INTEGER} (2⁵³ − 1). Use string mode if you need
|
|
2527
|
+
* to handle arbitrarily large version numbers.
|
|
2528
|
+
*
|
|
2529
|
+
* Both modes strictly enforce the SemVer 2.0.0 specification: no leading
|
|
2530
|
+
* zeros in numeric components, no empty pre-release or build identifiers,
|
|
2531
|
+
* and no invalid characters.
|
|
2532
|
+
*
|
|
2533
|
+
* [Semantic Versioning 2.0.0]: https://semver.org/
|
|
2534
|
+
*
|
|
2535
|
+
* @param options Configuration options.
|
|
2536
|
+
* @returns A {@link ValueParser} that validates SemVer strings.
|
|
2537
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
|
|
2538
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
|
|
2539
|
+
* boolean.
|
|
2540
|
+
* @throws {TypeError} If {@link SemVerOptionsString.type} is not `"string"`,
|
|
2541
|
+
* `"object"`, or `undefined`.
|
|
2542
|
+
* @since 1.1.0
|
|
2543
|
+
*/
|
|
2544
|
+
declare function semVer(options?: SemVerOptionsString): ValueParser<"sync", SemVerString>;
|
|
2545
|
+
/**
|
|
2546
|
+
* Creates a {@link ValueParser} for [Semantic Versioning 2.0.0] strings,
|
|
2547
|
+
* returning a structured {@link SemVer} object.
|
|
2548
|
+
*
|
|
2549
|
+
* [Semantic Versioning 2.0.0]: https://semver.org/
|
|
2550
|
+
*
|
|
2551
|
+
* @param options Configuration options with `type: "object"`.
|
|
2552
|
+
* @returns A {@link ValueParser} that converts SemVer strings to {@link SemVer}
|
|
2553
|
+
* objects.
|
|
2554
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.metavar} is an empty string.
|
|
2555
|
+
* @throws {TypeError} If {@link SemVerOptionsBase.allowPrefix} is not a
|
|
2556
|
+
* boolean.
|
|
2557
|
+
* @throws {TypeError} If {@link SemVerOptionsObject.type} is not `"string"`,
|
|
2558
|
+
* `"object"`, or `undefined`.
|
|
2559
|
+
* @since 1.1.0
|
|
2560
|
+
*/
|
|
2561
|
+
declare function semVer(options: SemVerOptionsObject): ValueParser<"sync", SemVer>;
|
|
2331
2562
|
//#endregion
|
|
2332
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2563
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, Color, ColorFormat, ColorOptions, DeferredMap, DomainOptions, EmailOptions, FileSizeOptions, FileSizeOptionsBigInt, FileSizeOptionsNumber, FileSizeUnit, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SemVer, SemVerOptionsObject, SemVerOptionsString, SemVerString, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, checkBooleanOption, checkEnumOption, choice, cidr, color, domain, email, ensureNonEmptyString, fileSize, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, semVer, socketAddress, string, url, uuid };
|