@optique/core 1.1.0-dev.2054 → 1.1.0-dev.2065
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 +1463 -0
- package/dist/valueparser.d.cts +241 -1
- package/dist/valueparser.d.ts +241 -1
- package/dist/valueparser.js +1462 -1
- package/package.json +1 -1
package/dist/valueparser.d.cts
CHANGED
|
@@ -584,6 +584,246 @@ interface FloatOptions {
|
|
|
584
584
|
* numbers.
|
|
585
585
|
*/
|
|
586
586
|
declare function float(options?: FloatOptions): ValueParser<"sync", number>;
|
|
587
|
+
/**
|
|
588
|
+
* A canonical file size unit string. SI units use powers of 1 000 by
|
|
589
|
+
* default; IEC units always use powers of 1 024.
|
|
590
|
+
* @since 1.1.0
|
|
591
|
+
*/
|
|
592
|
+
type FileSizeUnit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "KiB" | "MiB" | "GiB" | "TiB" | "PiB" | "EiB";
|
|
593
|
+
/**
|
|
594
|
+
* Options for creating a {@link fileSize} parser that returns `number`.
|
|
595
|
+
* @since 1.1.0
|
|
596
|
+
*/
|
|
597
|
+
interface FileSizeOptionsNumber {
|
|
598
|
+
/**
|
|
599
|
+
* The return type. Defaults to `"number"`.
|
|
600
|
+
* @default `"number"`
|
|
601
|
+
*/
|
|
602
|
+
readonly type?: "number";
|
|
603
|
+
/**
|
|
604
|
+
* The metavariable name for this parser. Used in help messages to
|
|
605
|
+
* indicate what kind of value this parser expects.
|
|
606
|
+
* @default `"SIZE"`
|
|
607
|
+
*/
|
|
608
|
+
readonly metavar?: NonEmptyString;
|
|
609
|
+
/**
|
|
610
|
+
* If `true`, negative byte values are accepted. Most size-related CLI
|
|
611
|
+
* options do not accept negative values, so this defaults to `false`.
|
|
612
|
+
* @default `false`
|
|
613
|
+
*/
|
|
614
|
+
readonly allowNegative?: boolean;
|
|
615
|
+
/**
|
|
616
|
+
* The unit to assume when the input contains only a number with no unit
|
|
617
|
+
* suffix (e.g., `"100"` with `defaultUnit: "MB"` → 100 000 000 bytes).
|
|
618
|
+
* When this option is absent, a bare number without a unit is rejected.
|
|
619
|
+
*/
|
|
620
|
+
readonly defaultUnit?: FileSizeUnit;
|
|
621
|
+
/**
|
|
622
|
+
* When `true`, SI suffixes (`KB`, `MB`, `GB`, …) are interpreted as
|
|
623
|
+
* binary powers of 1 024 rather than decimal powers of 1 000. This
|
|
624
|
+
* matches a widespread but technically incorrect convention where
|
|
625
|
+
* "1 KB" means 1 024 bytes. IEC suffixes (`KiB`, `MiB`, …) are
|
|
626
|
+
* unaffected by this option.
|
|
627
|
+
*
|
|
628
|
+
* @default `false`
|
|
629
|
+
* @since 1.1.0
|
|
630
|
+
*/
|
|
631
|
+
readonly siAsBinary?: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
634
|
+
* @default `0`
|
|
635
|
+
* @since 1.1.0
|
|
636
|
+
*/
|
|
637
|
+
readonly placeholder?: number;
|
|
638
|
+
/**
|
|
639
|
+
* Custom error messages for file size parsing failures.
|
|
640
|
+
* @since 1.1.0
|
|
641
|
+
*/
|
|
642
|
+
readonly errors?: {
|
|
643
|
+
/**
|
|
644
|
+
* Custom error message when the input is not a valid file size string.
|
|
645
|
+
* Can be a static message or a function that receives the raw input.
|
|
646
|
+
*/
|
|
647
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
648
|
+
/**
|
|
649
|
+
* Custom error message when a negative value is provided but
|
|
650
|
+
* {@link FileSizeOptionsNumber.allowNegative} is `false`.
|
|
651
|
+
* Can be a static message or a function that receives the byte value.
|
|
652
|
+
*/
|
|
653
|
+
readonly negativeNotAllowed?: Message | ((value: number) => Message);
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Options for creating a {@link fileSize} parser that returns `bigint`.
|
|
658
|
+
* Use this when byte counts may exceed `Number.MAX_SAFE_INTEGER` (roughly
|
|
659
|
+
* 9 PB), for example when working with EB/EiB-range values.
|
|
660
|
+
* @since 1.1.0
|
|
661
|
+
*/
|
|
662
|
+
interface FileSizeOptionsBigInt {
|
|
663
|
+
/**
|
|
664
|
+
* Must be set to `"bigint"` to select bigint output.
|
|
665
|
+
*/
|
|
666
|
+
readonly type: "bigint";
|
|
667
|
+
/**
|
|
668
|
+
* The metavariable name for this parser. Used in help messages to
|
|
669
|
+
* indicate what kind of value this parser expects.
|
|
670
|
+
* @default `"SIZE"`
|
|
671
|
+
*/
|
|
672
|
+
readonly metavar?: NonEmptyString;
|
|
673
|
+
/**
|
|
674
|
+
* If `true`, negative byte values are accepted.
|
|
675
|
+
* @default `false`
|
|
676
|
+
*/
|
|
677
|
+
readonly allowNegative?: boolean;
|
|
678
|
+
/**
|
|
679
|
+
* The unit to assume when the input contains only a number with no unit
|
|
680
|
+
* suffix. When absent, a bare number is rejected.
|
|
681
|
+
*/
|
|
682
|
+
readonly defaultUnit?: FileSizeUnit;
|
|
683
|
+
/**
|
|
684
|
+
* When `true`, SI suffixes (`KB`, `MB`, `GB`, …) are interpreted as
|
|
685
|
+
* binary powers of 1 024 rather than decimal powers of 1 000.
|
|
686
|
+
* @default `false`
|
|
687
|
+
* @since 1.1.0
|
|
688
|
+
*/
|
|
689
|
+
readonly siAsBinary?: boolean;
|
|
690
|
+
/**
|
|
691
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
692
|
+
* @default `0n`
|
|
693
|
+
* @since 1.1.0
|
|
694
|
+
*/
|
|
695
|
+
readonly placeholder?: bigint;
|
|
696
|
+
/**
|
|
697
|
+
* Custom error messages for file size parsing failures.
|
|
698
|
+
* @since 1.1.0
|
|
699
|
+
*/
|
|
700
|
+
readonly errors?: {
|
|
701
|
+
/**
|
|
702
|
+
* Custom error message when the input is not a valid file size string.
|
|
703
|
+
* Can be a static message or a function that receives the raw input.
|
|
704
|
+
*/
|
|
705
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
706
|
+
/**
|
|
707
|
+
* Custom error message when a negative value is provided but
|
|
708
|
+
* {@link FileSizeOptionsBigInt.allowNegative} is `false`.
|
|
709
|
+
* Can be a static message or a function that receives the byte value.
|
|
710
|
+
*/
|
|
711
|
+
readonly negativeNotAllowed?: Message | ((value: bigint) => Message);
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Options for creating a {@link fileSize} parser.
|
|
716
|
+
* @since 1.1.0
|
|
717
|
+
*/
|
|
718
|
+
type FileSizeOptions = FileSizeOptionsNumber | FileSizeOptionsBigInt;
|
|
719
|
+
/**
|
|
720
|
+
* Creates a {@link ValueParser} for human-readable file/data size strings
|
|
721
|
+
* that returns a `number` byte count.
|
|
722
|
+
*
|
|
723
|
+
* @param options Configuration options for the file size parser.
|
|
724
|
+
* @returns A {@link ValueParser} that parses file size strings into `number`
|
|
725
|
+
* byte counts.
|
|
726
|
+
* @throws {TypeError} If {@link FileSizeOptionsNumber.metavar} is an empty
|
|
727
|
+
* string, if {@link FileSizeOptionsNumber.allowNegative} or
|
|
728
|
+
* {@link FileSizeOptionsNumber.siAsBinary} is not a boolean, or if
|
|
729
|
+
* {@link FileSizeOptionsNumber.defaultUnit} is not a valid
|
|
730
|
+
* {@link FileSizeUnit}.
|
|
731
|
+
* @since 1.1.0
|
|
732
|
+
*/
|
|
733
|
+
declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync", number>;
|
|
734
|
+
/**
|
|
735
|
+
* Creates a {@link ValueParser} for human-readable file/data size strings
|
|
736
|
+
* that returns a `bigint` byte count. Use this when byte counts may exceed
|
|
737
|
+
* `Number.MAX_SAFE_INTEGER` (~9 PB), for example with EB/EiB-range values.
|
|
738
|
+
*
|
|
739
|
+
* @param options Configuration options for the file size parser.
|
|
740
|
+
* @returns A {@link ValueParser} that parses file size strings into `bigint`
|
|
741
|
+
* byte counts.
|
|
742
|
+
* @throws {TypeError} If {@link FileSizeOptionsBigInt.metavar} is an empty
|
|
743
|
+
* string, if {@link FileSizeOptionsBigInt.allowNegative} or
|
|
744
|
+
* {@link FileSizeOptionsBigInt.siAsBinary} is not a boolean, or if
|
|
745
|
+
* {@link FileSizeOptionsBigInt.defaultUnit} is not a valid
|
|
746
|
+
* {@link FileSizeUnit}.
|
|
747
|
+
* @since 1.1.0
|
|
748
|
+
*/
|
|
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>;
|
|
587
827
|
/**
|
|
588
828
|
* Options for creating a {@link url} parser.
|
|
589
829
|
*/
|
|
@@ -2166,4 +2406,4 @@ interface CidrOptions {
|
|
|
2166
2406
|
*/
|
|
2167
2407
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
2168
2408
|
//#endregion
|
|
2169
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, 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, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2409
|
+
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, 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, socketAddress, string, url, uuid };
|
package/dist/valueparser.d.ts
CHANGED
|
@@ -584,6 +584,246 @@ interface FloatOptions {
|
|
|
584
584
|
* numbers.
|
|
585
585
|
*/
|
|
586
586
|
declare function float(options?: FloatOptions): ValueParser<"sync", number>;
|
|
587
|
+
/**
|
|
588
|
+
* A canonical file size unit string. SI units use powers of 1 000 by
|
|
589
|
+
* default; IEC units always use powers of 1 024.
|
|
590
|
+
* @since 1.1.0
|
|
591
|
+
*/
|
|
592
|
+
type FileSizeUnit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "KiB" | "MiB" | "GiB" | "TiB" | "PiB" | "EiB";
|
|
593
|
+
/**
|
|
594
|
+
* Options for creating a {@link fileSize} parser that returns `number`.
|
|
595
|
+
* @since 1.1.0
|
|
596
|
+
*/
|
|
597
|
+
interface FileSizeOptionsNumber {
|
|
598
|
+
/**
|
|
599
|
+
* The return type. Defaults to `"number"`.
|
|
600
|
+
* @default `"number"`
|
|
601
|
+
*/
|
|
602
|
+
readonly type?: "number";
|
|
603
|
+
/**
|
|
604
|
+
* The metavariable name for this parser. Used in help messages to
|
|
605
|
+
* indicate what kind of value this parser expects.
|
|
606
|
+
* @default `"SIZE"`
|
|
607
|
+
*/
|
|
608
|
+
readonly metavar?: NonEmptyString;
|
|
609
|
+
/**
|
|
610
|
+
* If `true`, negative byte values are accepted. Most size-related CLI
|
|
611
|
+
* options do not accept negative values, so this defaults to `false`.
|
|
612
|
+
* @default `false`
|
|
613
|
+
*/
|
|
614
|
+
readonly allowNegative?: boolean;
|
|
615
|
+
/**
|
|
616
|
+
* The unit to assume when the input contains only a number with no unit
|
|
617
|
+
* suffix (e.g., `"100"` with `defaultUnit: "MB"` → 100 000 000 bytes).
|
|
618
|
+
* When this option is absent, a bare number without a unit is rejected.
|
|
619
|
+
*/
|
|
620
|
+
readonly defaultUnit?: FileSizeUnit;
|
|
621
|
+
/**
|
|
622
|
+
* When `true`, SI suffixes (`KB`, `MB`, `GB`, …) are interpreted as
|
|
623
|
+
* binary powers of 1 024 rather than decimal powers of 1 000. This
|
|
624
|
+
* matches a widespread but technically incorrect convention where
|
|
625
|
+
* "1 KB" means 1 024 bytes. IEC suffixes (`KiB`, `MiB`, …) are
|
|
626
|
+
* unaffected by this option.
|
|
627
|
+
*
|
|
628
|
+
* @default `false`
|
|
629
|
+
* @since 1.1.0
|
|
630
|
+
*/
|
|
631
|
+
readonly siAsBinary?: boolean;
|
|
632
|
+
/**
|
|
633
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
634
|
+
* @default `0`
|
|
635
|
+
* @since 1.1.0
|
|
636
|
+
*/
|
|
637
|
+
readonly placeholder?: number;
|
|
638
|
+
/**
|
|
639
|
+
* Custom error messages for file size parsing failures.
|
|
640
|
+
* @since 1.1.0
|
|
641
|
+
*/
|
|
642
|
+
readonly errors?: {
|
|
643
|
+
/**
|
|
644
|
+
* Custom error message when the input is not a valid file size string.
|
|
645
|
+
* Can be a static message or a function that receives the raw input.
|
|
646
|
+
*/
|
|
647
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
648
|
+
/**
|
|
649
|
+
* Custom error message when a negative value is provided but
|
|
650
|
+
* {@link FileSizeOptionsNumber.allowNegative} is `false`.
|
|
651
|
+
* Can be a static message or a function that receives the byte value.
|
|
652
|
+
*/
|
|
653
|
+
readonly negativeNotAllowed?: Message | ((value: number) => Message);
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Options for creating a {@link fileSize} parser that returns `bigint`.
|
|
658
|
+
* Use this when byte counts may exceed `Number.MAX_SAFE_INTEGER` (roughly
|
|
659
|
+
* 9 PB), for example when working with EB/EiB-range values.
|
|
660
|
+
* @since 1.1.0
|
|
661
|
+
*/
|
|
662
|
+
interface FileSizeOptionsBigInt {
|
|
663
|
+
/**
|
|
664
|
+
* Must be set to `"bigint"` to select bigint output.
|
|
665
|
+
*/
|
|
666
|
+
readonly type: "bigint";
|
|
667
|
+
/**
|
|
668
|
+
* The metavariable name for this parser. Used in help messages to
|
|
669
|
+
* indicate what kind of value this parser expects.
|
|
670
|
+
* @default `"SIZE"`
|
|
671
|
+
*/
|
|
672
|
+
readonly metavar?: NonEmptyString;
|
|
673
|
+
/**
|
|
674
|
+
* If `true`, negative byte values are accepted.
|
|
675
|
+
* @default `false`
|
|
676
|
+
*/
|
|
677
|
+
readonly allowNegative?: boolean;
|
|
678
|
+
/**
|
|
679
|
+
* The unit to assume when the input contains only a number with no unit
|
|
680
|
+
* suffix. When absent, a bare number is rejected.
|
|
681
|
+
*/
|
|
682
|
+
readonly defaultUnit?: FileSizeUnit;
|
|
683
|
+
/**
|
|
684
|
+
* When `true`, SI suffixes (`KB`, `MB`, `GB`, …) are interpreted as
|
|
685
|
+
* binary powers of 1 024 rather than decimal powers of 1 000.
|
|
686
|
+
* @default `false`
|
|
687
|
+
* @since 1.1.0
|
|
688
|
+
*/
|
|
689
|
+
readonly siAsBinary?: boolean;
|
|
690
|
+
/**
|
|
691
|
+
* A custom placeholder value used during deferred prompt resolution.
|
|
692
|
+
* @default `0n`
|
|
693
|
+
* @since 1.1.0
|
|
694
|
+
*/
|
|
695
|
+
readonly placeholder?: bigint;
|
|
696
|
+
/**
|
|
697
|
+
* Custom error messages for file size parsing failures.
|
|
698
|
+
* @since 1.1.0
|
|
699
|
+
*/
|
|
700
|
+
readonly errors?: {
|
|
701
|
+
/**
|
|
702
|
+
* Custom error message when the input is not a valid file size string.
|
|
703
|
+
* Can be a static message or a function that receives the raw input.
|
|
704
|
+
*/
|
|
705
|
+
readonly invalidFormat?: Message | ((input: string) => Message);
|
|
706
|
+
/**
|
|
707
|
+
* Custom error message when a negative value is provided but
|
|
708
|
+
* {@link FileSizeOptionsBigInt.allowNegative} is `false`.
|
|
709
|
+
* Can be a static message or a function that receives the byte value.
|
|
710
|
+
*/
|
|
711
|
+
readonly negativeNotAllowed?: Message | ((value: bigint) => Message);
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Options for creating a {@link fileSize} parser.
|
|
716
|
+
* @since 1.1.0
|
|
717
|
+
*/
|
|
718
|
+
type FileSizeOptions = FileSizeOptionsNumber | FileSizeOptionsBigInt;
|
|
719
|
+
/**
|
|
720
|
+
* Creates a {@link ValueParser} for human-readable file/data size strings
|
|
721
|
+
* that returns a `number` byte count.
|
|
722
|
+
*
|
|
723
|
+
* @param options Configuration options for the file size parser.
|
|
724
|
+
* @returns A {@link ValueParser} that parses file size strings into `number`
|
|
725
|
+
* byte counts.
|
|
726
|
+
* @throws {TypeError} If {@link FileSizeOptionsNumber.metavar} is an empty
|
|
727
|
+
* string, if {@link FileSizeOptionsNumber.allowNegative} or
|
|
728
|
+
* {@link FileSizeOptionsNumber.siAsBinary} is not a boolean, or if
|
|
729
|
+
* {@link FileSizeOptionsNumber.defaultUnit} is not a valid
|
|
730
|
+
* {@link FileSizeUnit}.
|
|
731
|
+
* @since 1.1.0
|
|
732
|
+
*/
|
|
733
|
+
declare function fileSize(options?: FileSizeOptionsNumber): ValueParser<"sync", number>;
|
|
734
|
+
/**
|
|
735
|
+
* Creates a {@link ValueParser} for human-readable file/data size strings
|
|
736
|
+
* that returns a `bigint` byte count. Use this when byte counts may exceed
|
|
737
|
+
* `Number.MAX_SAFE_INTEGER` (~9 PB), for example with EB/EiB-range values.
|
|
738
|
+
*
|
|
739
|
+
* @param options Configuration options for the file size parser.
|
|
740
|
+
* @returns A {@link ValueParser} that parses file size strings into `bigint`
|
|
741
|
+
* byte counts.
|
|
742
|
+
* @throws {TypeError} If {@link FileSizeOptionsBigInt.metavar} is an empty
|
|
743
|
+
* string, if {@link FileSizeOptionsBigInt.allowNegative} or
|
|
744
|
+
* {@link FileSizeOptionsBigInt.siAsBinary} is not a boolean, or if
|
|
745
|
+
* {@link FileSizeOptionsBigInt.defaultUnit} is not a valid
|
|
746
|
+
* {@link FileSizeUnit}.
|
|
747
|
+
* @since 1.1.0
|
|
748
|
+
*/
|
|
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>;
|
|
587
827
|
/**
|
|
588
828
|
* Options for creating a {@link url} parser.
|
|
589
829
|
*/
|
|
@@ -2166,4 +2406,4 @@ interface CidrOptions {
|
|
|
2166
2406
|
*/
|
|
2167
2407
|
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
2168
2408
|
//#endregion
|
|
2169
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DeferredMap, DomainOptions, EmailOptions, 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, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|
|
2409
|
+
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, 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, socketAddress, string, url, uuid };
|