@optique/core 0.10.0-dev.333 → 0.10.0-dev.342
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 +11 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/primitives.cjs +17 -15
- package/dist/primitives.js +17 -15
- package/dist/usage.cjs +2 -0
- package/dist/usage.js +2 -0
- package/dist/valueparser.cjs +1849 -0
- package/dist/valueparser.d.cts +1271 -1
- package/dist/valueparser.d.ts +1271 -1
- package/dist/valueparser.js +1839 -1
- package/package.json +1 -1
package/dist/valueparser.d.ts
CHANGED
|
@@ -555,5 +555,1275 @@ interface UuidOptions {
|
|
|
555
555
|
* strings.
|
|
556
556
|
*/
|
|
557
557
|
declare function uuid(options?: UuidOptions): ValueParser<"sync", Uuid>;
|
|
558
|
+
/**
|
|
559
|
+
* Options for creating a port parser that returns a JavaScript `number`.
|
|
560
|
+
*/
|
|
561
|
+
interface PortOptionsNumber {
|
|
562
|
+
/**
|
|
563
|
+
* The type of value to return.
|
|
564
|
+
* @default `"number"`
|
|
565
|
+
*/
|
|
566
|
+
readonly type?: "number";
|
|
567
|
+
/**
|
|
568
|
+
* The metavariable name for this parser. This is used in help messages to
|
|
569
|
+
* indicate what kind of value this parser expects. Usually a single
|
|
570
|
+
* word in uppercase, like `PORT`.
|
|
571
|
+
* @default `"PORT"`
|
|
572
|
+
*/
|
|
573
|
+
readonly metavar?: NonEmptyString;
|
|
574
|
+
/**
|
|
575
|
+
* Minimum allowed port number (inclusive).
|
|
576
|
+
* @default `1`
|
|
577
|
+
*/
|
|
578
|
+
readonly min?: number;
|
|
579
|
+
/**
|
|
580
|
+
* Maximum allowed port number (inclusive).
|
|
581
|
+
* @default `65535`
|
|
582
|
+
*/
|
|
583
|
+
readonly max?: number;
|
|
584
|
+
/**
|
|
585
|
+
* If `true`, disallows well-known ports (1-1023).
|
|
586
|
+
* These ports typically require root/administrator privileges on most systems.
|
|
587
|
+
* @default `false`
|
|
588
|
+
*/
|
|
589
|
+
readonly disallowWellKnown?: boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Custom error messages for port parsing failures.
|
|
592
|
+
* @since 0.10.0
|
|
593
|
+
*/
|
|
594
|
+
readonly errors?: {
|
|
595
|
+
/**
|
|
596
|
+
* Custom error message when input is not a valid port number.
|
|
597
|
+
* Can be a static message or a function that receives the input.
|
|
598
|
+
* @since 0.10.0
|
|
599
|
+
*/
|
|
600
|
+
invalidPort?: Message | ((input: string) => Message);
|
|
601
|
+
/**
|
|
602
|
+
* Custom error message when port is below minimum value.
|
|
603
|
+
* Can be a static message or a function that receives the port and minimum.
|
|
604
|
+
* @since 0.10.0
|
|
605
|
+
*/
|
|
606
|
+
belowMinimum?: Message | ((port: number, min: number) => Message);
|
|
607
|
+
/**
|
|
608
|
+
* Custom error message when port is above maximum value.
|
|
609
|
+
* Can be a static message or a function that receives the port and maximum.
|
|
610
|
+
* @since 0.10.0
|
|
611
|
+
*/
|
|
612
|
+
aboveMaximum?: Message | ((port: number, max: number) => Message);
|
|
613
|
+
/**
|
|
614
|
+
* Custom error message when well-known port is used but disallowed.
|
|
615
|
+
* Can be a static message or a function that receives the port.
|
|
616
|
+
* @since 0.10.0
|
|
617
|
+
*/
|
|
618
|
+
wellKnownNotAllowed?: Message | ((port: number) => Message);
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Options for creating a port parser that returns a `bigint`.
|
|
623
|
+
*/
|
|
624
|
+
interface PortOptionsBigInt {
|
|
625
|
+
/**
|
|
626
|
+
* Must be set to `"bigint"` to create a `bigint` parser.
|
|
627
|
+
*/
|
|
628
|
+
readonly type: "bigint";
|
|
629
|
+
/**
|
|
630
|
+
* The metavariable name for this parser. This is used in help messages to
|
|
631
|
+
* indicate what kind of value this parser expects. Usually a single
|
|
632
|
+
* word in uppercase, like `PORT`.
|
|
633
|
+
* @default `"PORT"`
|
|
634
|
+
*/
|
|
635
|
+
readonly metavar?: NonEmptyString;
|
|
636
|
+
/**
|
|
637
|
+
* Minimum allowed port number (inclusive).
|
|
638
|
+
* @default `1n`
|
|
639
|
+
*/
|
|
640
|
+
readonly min?: bigint;
|
|
641
|
+
/**
|
|
642
|
+
* Maximum allowed port number (inclusive).
|
|
643
|
+
* @default `65535n`
|
|
644
|
+
*/
|
|
645
|
+
readonly max?: bigint;
|
|
646
|
+
/**
|
|
647
|
+
* If `true`, disallows well-known ports (1-1023).
|
|
648
|
+
* These ports typically require root/administrator privileges on most systems.
|
|
649
|
+
* @default `false`
|
|
650
|
+
*/
|
|
651
|
+
readonly disallowWellKnown?: boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Custom error messages for port parsing failures.
|
|
654
|
+
* @since 0.10.0
|
|
655
|
+
*/
|
|
656
|
+
readonly errors?: {
|
|
657
|
+
/**
|
|
658
|
+
* Custom error message when input is not a valid port number.
|
|
659
|
+
* Can be a static message or a function that receives the input.
|
|
660
|
+
* @since 0.10.0
|
|
661
|
+
*/
|
|
662
|
+
invalidPort?: Message | ((input: string) => Message);
|
|
663
|
+
/**
|
|
664
|
+
* Custom error message when port is below minimum value.
|
|
665
|
+
* Can be a static message or a function that receives the port and minimum.
|
|
666
|
+
* @since 0.10.0
|
|
667
|
+
*/
|
|
668
|
+
belowMinimum?: Message | ((port: bigint, min: bigint) => Message);
|
|
669
|
+
/**
|
|
670
|
+
* Custom error message when port is above maximum value.
|
|
671
|
+
* Can be a static message or a function that receives the port and maximum.
|
|
672
|
+
* @since 0.10.0
|
|
673
|
+
*/
|
|
674
|
+
aboveMaximum?: Message | ((port: bigint, max: bigint) => Message);
|
|
675
|
+
/**
|
|
676
|
+
* Custom error message when well-known port is used but disallowed.
|
|
677
|
+
* Can be a static message or a function that receives the port.
|
|
678
|
+
* @since 0.10.0
|
|
679
|
+
*/
|
|
680
|
+
wellKnownNotAllowed?: Message | ((port: bigint) => Message);
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Creates a ValueParser for TCP/UDP port numbers that returns JavaScript numbers.
|
|
685
|
+
*
|
|
686
|
+
* @param options Configuration options for the port parser.
|
|
687
|
+
* @returns A {@link ValueParser} that parses strings into port numbers.
|
|
688
|
+
* @since 0.10.0
|
|
689
|
+
*/
|
|
690
|
+
declare function port(options?: PortOptionsNumber): ValueParser<"sync", number>;
|
|
691
|
+
/**
|
|
692
|
+
* Creates a ValueParser for TCP/UDP port numbers that returns `bigint` values.
|
|
693
|
+
*
|
|
694
|
+
* @param options Configuration options for the `bigint` port parser.
|
|
695
|
+
* @returns A {@link ValueParser} that parses strings into `bigint` port values.
|
|
696
|
+
* @since 0.10.0
|
|
697
|
+
*/
|
|
698
|
+
declare function port(options: PortOptionsBigInt): ValueParser<"sync", bigint>;
|
|
699
|
+
/**
|
|
700
|
+
* Options for the {@link ipv4} value parser.
|
|
701
|
+
*
|
|
702
|
+
* @since 0.10.0
|
|
703
|
+
*/
|
|
704
|
+
interface Ipv4Options {
|
|
705
|
+
/**
|
|
706
|
+
* The metavariable name for this parser.
|
|
707
|
+
*
|
|
708
|
+
* @default "IPV4"
|
|
709
|
+
*/
|
|
710
|
+
readonly metavar?: NonEmptyString;
|
|
711
|
+
/**
|
|
712
|
+
* If `true`, allows private IP ranges (10.0.0.0/8, 172.16.0.0/12,
|
|
713
|
+
* 192.168.0.0/16).
|
|
714
|
+
*
|
|
715
|
+
* @default true
|
|
716
|
+
*/
|
|
717
|
+
readonly allowPrivate?: boolean;
|
|
718
|
+
/**
|
|
719
|
+
* If `true`, allows loopback addresses (127.0.0.0/8).
|
|
720
|
+
*
|
|
721
|
+
* @default true
|
|
722
|
+
*/
|
|
723
|
+
readonly allowLoopback?: boolean;
|
|
724
|
+
/**
|
|
725
|
+
* If `true`, allows link-local addresses (169.254.0.0/16).
|
|
726
|
+
*
|
|
727
|
+
* @default true
|
|
728
|
+
*/
|
|
729
|
+
readonly allowLinkLocal?: boolean;
|
|
730
|
+
/**
|
|
731
|
+
* If `true`, allows multicast addresses (224.0.0.0/4).
|
|
732
|
+
*
|
|
733
|
+
* @default true
|
|
734
|
+
*/
|
|
735
|
+
readonly allowMulticast?: boolean;
|
|
736
|
+
/**
|
|
737
|
+
* If `true`, allows the broadcast address (255.255.255.255).
|
|
738
|
+
*
|
|
739
|
+
* @default true
|
|
740
|
+
*/
|
|
741
|
+
readonly allowBroadcast?: boolean;
|
|
742
|
+
/**
|
|
743
|
+
* If `true`, allows the zero address (0.0.0.0).
|
|
744
|
+
*
|
|
745
|
+
* @default true
|
|
746
|
+
*/
|
|
747
|
+
readonly allowZero?: boolean;
|
|
748
|
+
/**
|
|
749
|
+
* Custom error messages for IPv4 parsing failures.
|
|
750
|
+
*/
|
|
751
|
+
readonly errors?: {
|
|
752
|
+
/**
|
|
753
|
+
* Custom error message when input is not a valid IPv4 address.
|
|
754
|
+
* Can be a static message or a function that receives the input.
|
|
755
|
+
*/
|
|
756
|
+
invalidIpv4?: Message | ((input: string) => Message);
|
|
757
|
+
/**
|
|
758
|
+
* Custom error message when private IP is used but disallowed.
|
|
759
|
+
* Can be a static message or a function that receives the IP.
|
|
760
|
+
*/
|
|
761
|
+
privateNotAllowed?: Message | ((ip: string) => Message);
|
|
762
|
+
/**
|
|
763
|
+
* Custom error message when loopback IP is used but disallowed.
|
|
764
|
+
* Can be a static message or a function that receives the IP.
|
|
765
|
+
*/
|
|
766
|
+
loopbackNotAllowed?: Message | ((ip: string) => Message);
|
|
767
|
+
/**
|
|
768
|
+
* Custom error message when link-local IP is used but disallowed.
|
|
769
|
+
* Can be a static message or a function that receives the IP.
|
|
770
|
+
*/
|
|
771
|
+
linkLocalNotAllowed?: Message | ((ip: string) => Message);
|
|
772
|
+
/**
|
|
773
|
+
* Custom error message when multicast IP is used but disallowed.
|
|
774
|
+
* Can be a static message or a function that receives the IP.
|
|
775
|
+
*/
|
|
776
|
+
multicastNotAllowed?: Message | ((ip: string) => Message);
|
|
777
|
+
/**
|
|
778
|
+
* Custom error message when broadcast IP is used but disallowed.
|
|
779
|
+
* Can be a static message or a function that receives the IP.
|
|
780
|
+
*/
|
|
781
|
+
broadcastNotAllowed?: Message | ((ip: string) => Message);
|
|
782
|
+
/**
|
|
783
|
+
* Custom error message when zero IP is used but disallowed.
|
|
784
|
+
* Can be a static message or a function that receives the IP.
|
|
785
|
+
*/
|
|
786
|
+
zeroNotAllowed?: Message | ((ip: string) => Message);
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
/**
|
|
790
|
+
* Creates a value parser for IPv4 addresses.
|
|
791
|
+
*
|
|
792
|
+
* This parser validates IPv4 addresses in dotted-decimal notation (e.g.,
|
|
793
|
+
* "192.168.1.1") and provides options to filter specific IP address types
|
|
794
|
+
* such as private, loopback, link-local, multicast, broadcast, and zero
|
|
795
|
+
* addresses.
|
|
796
|
+
*
|
|
797
|
+
* @param options The parser options.
|
|
798
|
+
* @returns A value parser for IPv4 addresses.
|
|
799
|
+
* @throws {TypeError} If the metavar is an empty string.
|
|
800
|
+
* @since 0.10.0
|
|
801
|
+
* @example
|
|
802
|
+
* ```typescript
|
|
803
|
+
* import { ipv4 } from "@optique/core/valueparser";
|
|
804
|
+
*
|
|
805
|
+
* // Basic IPv4 parser (allows all types)
|
|
806
|
+
* const address = ipv4();
|
|
807
|
+
*
|
|
808
|
+
* // Public IPs only (no private/loopback)
|
|
809
|
+
* const publicIp = ipv4({
|
|
810
|
+
* allowPrivate: false,
|
|
811
|
+
* allowLoopback: false
|
|
812
|
+
* });
|
|
813
|
+
*
|
|
814
|
+
* // Server binding (allow 0.0.0.0 and private IPs)
|
|
815
|
+
* const bindAddress = ipv4({
|
|
816
|
+
* allowZero: true,
|
|
817
|
+
* allowPrivate: true
|
|
818
|
+
* });
|
|
819
|
+
* ```
|
|
820
|
+
*/
|
|
821
|
+
declare function ipv4(options?: Ipv4Options): ValueParser<"sync", string>;
|
|
822
|
+
/**
|
|
823
|
+
* Options for the {@link hostname} parser.
|
|
824
|
+
*
|
|
825
|
+
* @since 0.10.0
|
|
826
|
+
*/
|
|
827
|
+
interface HostnameOptions {
|
|
828
|
+
/**
|
|
829
|
+
* The metavariable name for this parser.
|
|
830
|
+
* @default "HOST"
|
|
831
|
+
*/
|
|
832
|
+
readonly metavar?: NonEmptyString;
|
|
833
|
+
/**
|
|
834
|
+
* If `true`, allows wildcard hostnames (e.g., "*.example.com").
|
|
835
|
+
* @default false
|
|
836
|
+
*/
|
|
837
|
+
readonly allowWildcard?: boolean;
|
|
838
|
+
/**
|
|
839
|
+
* If `true`, allows underscores in hostnames.
|
|
840
|
+
* Technically invalid per RFC 1123, but commonly used in some contexts
|
|
841
|
+
* (e.g., service discovery records like "_service.example.com").
|
|
842
|
+
* @default false
|
|
843
|
+
*/
|
|
844
|
+
readonly allowUnderscore?: boolean;
|
|
845
|
+
/**
|
|
846
|
+
* If `true`, allows "localhost" as a hostname.
|
|
847
|
+
* @default true
|
|
848
|
+
*/
|
|
849
|
+
readonly allowLocalhost?: boolean;
|
|
850
|
+
/**
|
|
851
|
+
* Maximum hostname length in characters.
|
|
852
|
+
* @default 253
|
|
853
|
+
*/
|
|
854
|
+
readonly maxLength?: number;
|
|
855
|
+
/**
|
|
856
|
+
* Custom error messages for hostname parsing failures.
|
|
857
|
+
*/
|
|
858
|
+
readonly errors?: {
|
|
859
|
+
/**
|
|
860
|
+
* Custom error message when input is not a valid hostname.
|
|
861
|
+
* Can be a static message or a function that receives the input.
|
|
862
|
+
*/
|
|
863
|
+
invalidHostname?: Message | ((input: string) => Message);
|
|
864
|
+
/**
|
|
865
|
+
* Custom error message when wildcard hostname is used but disallowed.
|
|
866
|
+
* Can be a static message or a function that receives the hostname.
|
|
867
|
+
*/
|
|
868
|
+
wildcardNotAllowed?: Message | ((hostname: string) => Message);
|
|
869
|
+
/**
|
|
870
|
+
* Custom error message when underscore is used but disallowed.
|
|
871
|
+
* Can be a static message or a function that receives the hostname.
|
|
872
|
+
*/
|
|
873
|
+
underscoreNotAllowed?: Message | ((hostname: string) => Message);
|
|
874
|
+
/**
|
|
875
|
+
* Custom error message when "localhost" is used but disallowed.
|
|
876
|
+
* Can be a static message or a function that receives the hostname.
|
|
877
|
+
*/
|
|
878
|
+
localhostNotAllowed?: Message | ((hostname: string) => Message);
|
|
879
|
+
/**
|
|
880
|
+
* Custom error message when hostname is too long.
|
|
881
|
+
* Can be a static message or a function that receives the hostname and max length.
|
|
882
|
+
*/
|
|
883
|
+
tooLong?: Message | ((hostname: string, maxLength: number) => Message);
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Creates a value parser for DNS hostnames.
|
|
888
|
+
*
|
|
889
|
+
* Validates hostnames according to RFC 1123:
|
|
890
|
+
* - Labels separated by dots
|
|
891
|
+
* - Each label: 1-63 characters
|
|
892
|
+
* - Labels can contain alphanumeric characters and hyphens
|
|
893
|
+
* - Labels cannot start or end with a hyphen
|
|
894
|
+
* - Total length ≤ 253 characters (default)
|
|
895
|
+
*
|
|
896
|
+
* @param options - Options for hostname validation.
|
|
897
|
+
* @returns A value parser for hostnames.
|
|
898
|
+
* @since 0.10.0
|
|
899
|
+
*
|
|
900
|
+
* @example
|
|
901
|
+
* ```typescript
|
|
902
|
+
* import { hostname } from "@optique/core/valueparser";
|
|
903
|
+
*
|
|
904
|
+
* // Basic hostname parser
|
|
905
|
+
* const host = hostname();
|
|
906
|
+
*
|
|
907
|
+
* // Allow wildcards for certificate validation
|
|
908
|
+
* const domain = hostname({ allowWildcard: true });
|
|
909
|
+
*
|
|
910
|
+
* // Reject localhost
|
|
911
|
+
* const remoteHost = hostname({ allowLocalhost: false });
|
|
912
|
+
* ```
|
|
913
|
+
*/
|
|
914
|
+
declare function hostname(options?: HostnameOptions): ValueParser<"sync", string>;
|
|
915
|
+
/**
|
|
916
|
+
* Options for the {@link email} parser.
|
|
917
|
+
*
|
|
918
|
+
* @since 0.10.0
|
|
919
|
+
*/
|
|
920
|
+
interface EmailOptions {
|
|
921
|
+
/**
|
|
922
|
+
* The metavariable name for this parser.
|
|
923
|
+
* @default "EMAIL"
|
|
924
|
+
*/
|
|
925
|
+
readonly metavar?: NonEmptyString;
|
|
926
|
+
/**
|
|
927
|
+
* If `true`, allows multiple email addresses separated by commas.
|
|
928
|
+
* Returns an array of email addresses.
|
|
929
|
+
* @default false
|
|
930
|
+
*/
|
|
931
|
+
readonly allowMultiple?: boolean;
|
|
932
|
+
/**
|
|
933
|
+
* If `true`, allows display names in format "Name <email@example.com>".
|
|
934
|
+
* When enabled, returns the email address only (strips display name).
|
|
935
|
+
* @default false
|
|
936
|
+
*/
|
|
937
|
+
readonly allowDisplayName?: boolean;
|
|
938
|
+
/**
|
|
939
|
+
* If `true`, converts email to lowercase.
|
|
940
|
+
* @default false
|
|
941
|
+
*/
|
|
942
|
+
readonly lowercase?: boolean;
|
|
943
|
+
/**
|
|
944
|
+
* List of allowed email domains (e.g., ["example.com", "test.org"]).
|
|
945
|
+
* If specified, only emails from these domains are accepted.
|
|
946
|
+
*/
|
|
947
|
+
readonly allowedDomains?: readonly string[];
|
|
948
|
+
/**
|
|
949
|
+
* Custom error messages for email parsing failures.
|
|
950
|
+
*/
|
|
951
|
+
readonly errors?: {
|
|
952
|
+
/**
|
|
953
|
+
* Custom error message when input is not a valid email address.
|
|
954
|
+
* Can be a static message or a function that receives the input.
|
|
955
|
+
*/
|
|
956
|
+
invalidEmail?: Message | ((input: string) => Message);
|
|
957
|
+
/**
|
|
958
|
+
* Custom error message when email domain is not allowed.
|
|
959
|
+
* Can be a static message or a function that receives the email and allowed domains.
|
|
960
|
+
*/
|
|
961
|
+
domainNotAllowed?: Message | ((email: string, allowedDomains: readonly string[]) => Message);
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Creates a value parser for email addresses according to RFC 5322 (simplified).
|
|
966
|
+
*
|
|
967
|
+
* Validates email addresses with support for:
|
|
968
|
+
* - Simplified RFC 5322 addr-spec format (local-part@domain)
|
|
969
|
+
* - Local part: alphanumeric, dots, hyphens, underscores, plus signs
|
|
970
|
+
* - Quoted strings in local part
|
|
971
|
+
* - Display names (when `allowDisplayName` is enabled)
|
|
972
|
+
* - Multiple addresses (when `allowMultiple` is enabled)
|
|
973
|
+
* - Domain filtering (when `allowedDomains` is specified)
|
|
974
|
+
*
|
|
975
|
+
* @param options - Options for email validation.
|
|
976
|
+
* @returns A value parser for email addresses.
|
|
977
|
+
* @since 0.10.0
|
|
978
|
+
*
|
|
979
|
+
* @example
|
|
980
|
+
* ```typescript
|
|
981
|
+
* import { email } from "@optique/core/valueparser";
|
|
982
|
+
*
|
|
983
|
+
* // Basic email parser
|
|
984
|
+
* const userEmail = email();
|
|
985
|
+
*
|
|
986
|
+
* // Multiple emails
|
|
987
|
+
* const recipients = email({ allowMultiple: true });
|
|
988
|
+
*
|
|
989
|
+
* // With display names
|
|
990
|
+
* const from = email({ allowDisplayName: true });
|
|
991
|
+
*
|
|
992
|
+
* // Restrict to company domains
|
|
993
|
+
* const workEmail = email({ allowedDomains: ["company.com"] });
|
|
994
|
+
* ```
|
|
995
|
+
*/
|
|
996
|
+
declare function email(options: EmailOptions & {
|
|
997
|
+
allowMultiple: true;
|
|
998
|
+
}): ValueParser<"sync", readonly string[]>;
|
|
999
|
+
declare function email(options?: EmailOptions): ValueParser<"sync", string>;
|
|
1000
|
+
/**
|
|
1001
|
+
* Socket address value containing host and port.
|
|
1002
|
+
*
|
|
1003
|
+
* @since 0.10.0
|
|
1004
|
+
*/
|
|
1005
|
+
interface SocketAddressValue {
|
|
1006
|
+
/**
|
|
1007
|
+
* The host portion (hostname or IP address).
|
|
1008
|
+
*/
|
|
1009
|
+
readonly host: string;
|
|
1010
|
+
/**
|
|
1011
|
+
* The port number.
|
|
1012
|
+
*/
|
|
1013
|
+
readonly port: number;
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Options for the {@link socketAddress} parser.
|
|
1017
|
+
*
|
|
1018
|
+
* @since 0.10.0
|
|
1019
|
+
*/
|
|
1020
|
+
interface SocketAddressOptions {
|
|
1021
|
+
/**
|
|
1022
|
+
* The metavariable name for this parser.
|
|
1023
|
+
* @default "HOST:PORT"
|
|
1024
|
+
*/
|
|
1025
|
+
readonly metavar?: NonEmptyString;
|
|
1026
|
+
/**
|
|
1027
|
+
* Separator character(s) between host and port.
|
|
1028
|
+
* @default ":"
|
|
1029
|
+
*/
|
|
1030
|
+
readonly separator?: string;
|
|
1031
|
+
/**
|
|
1032
|
+
* Default port number if omitted from input.
|
|
1033
|
+
* If not specified, port is required.
|
|
1034
|
+
*/
|
|
1035
|
+
readonly defaultPort?: number;
|
|
1036
|
+
/**
|
|
1037
|
+
* If `true`, requires port to be specified in input
|
|
1038
|
+
* (ignores `defaultPort`).
|
|
1039
|
+
* @default false
|
|
1040
|
+
*/
|
|
1041
|
+
readonly requirePort?: boolean;
|
|
1042
|
+
/**
|
|
1043
|
+
* Options for hostname/IP validation.
|
|
1044
|
+
*/
|
|
1045
|
+
readonly host?: {
|
|
1046
|
+
/**
|
|
1047
|
+
* Type of host to accept.
|
|
1048
|
+
* - `"hostname"`: Accept hostnames only
|
|
1049
|
+
* - `"ip"`: Accept IP addresses only
|
|
1050
|
+
* - `"both"`: Accept both hostnames and IP addresses
|
|
1051
|
+
* @default "both"
|
|
1052
|
+
*/
|
|
1053
|
+
readonly type?: "hostname" | "ip" | "both";
|
|
1054
|
+
/**
|
|
1055
|
+
* Options for hostname validation (when type is "hostname" or "both").
|
|
1056
|
+
*/
|
|
1057
|
+
readonly hostname?: Omit<HostnameOptions, "metavar" | "errors">;
|
|
1058
|
+
/**
|
|
1059
|
+
* Options for IP validation (when type is "ip" or "both").
|
|
1060
|
+
* Currently only supports IPv4.
|
|
1061
|
+
*/
|
|
1062
|
+
readonly ip?: Omit<Ipv4Options, "metavar" | "errors">;
|
|
1063
|
+
};
|
|
1064
|
+
/**
|
|
1065
|
+
* Options for port validation.
|
|
1066
|
+
*/
|
|
1067
|
+
readonly port?: Omit<PortOptionsNumber, "metavar" | "errors" | "type">;
|
|
1068
|
+
/**
|
|
1069
|
+
* Custom error messages for socket address parsing failures.
|
|
1070
|
+
*/
|
|
1071
|
+
readonly errors?: {
|
|
1072
|
+
/**
|
|
1073
|
+
* Custom error message when input format is invalid.
|
|
1074
|
+
* Can be a static message or a function that receives the input.
|
|
1075
|
+
*/
|
|
1076
|
+
invalidFormat?: Message | ((input: string) => Message);
|
|
1077
|
+
/**
|
|
1078
|
+
* Custom error message when port is missing but required.
|
|
1079
|
+
* Can be a static message or a function that receives the input.
|
|
1080
|
+
*/
|
|
1081
|
+
missingPort?: Message | ((input: string) => Message);
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Creates a value parser for socket addresses in "host:port" format.
|
|
1086
|
+
*
|
|
1087
|
+
* Validates socket addresses with support for:
|
|
1088
|
+
* - Hostnames and IPv4 addresses (IPv6 support coming in future versions)
|
|
1089
|
+
* - Configurable host:port separator
|
|
1090
|
+
* - Optional default port
|
|
1091
|
+
* - Host type filtering (hostname only, IP only, or both)
|
|
1092
|
+
* - Port range validation
|
|
1093
|
+
*
|
|
1094
|
+
* @param options - Options for socket address validation.
|
|
1095
|
+
* @returns A value parser for socket addresses.
|
|
1096
|
+
* @since 0.10.0
|
|
1097
|
+
*
|
|
1098
|
+
* @example
|
|
1099
|
+
* ```typescript
|
|
1100
|
+
* import { socketAddress } from "@optique/core/valueparser";
|
|
1101
|
+
*
|
|
1102
|
+
* // Basic socket address parser
|
|
1103
|
+
* const endpoint = socketAddress({ requirePort: true });
|
|
1104
|
+
*
|
|
1105
|
+
* // With default port
|
|
1106
|
+
* const server = socketAddress({ defaultPort: 80 });
|
|
1107
|
+
*
|
|
1108
|
+
* // IP addresses only
|
|
1109
|
+
* const bind = socketAddress({
|
|
1110
|
+
* defaultPort: 8080,
|
|
1111
|
+
* host: { type: "ip" }
|
|
1112
|
+
* });
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
declare function socketAddress(options?: SocketAddressOptions): ValueParser<"sync", SocketAddressValue>;
|
|
1116
|
+
/**
|
|
1117
|
+
* Port range value with number type.
|
|
1118
|
+
*
|
|
1119
|
+
* @since 0.10.0
|
|
1120
|
+
*/
|
|
1121
|
+
interface PortRangeValueNumber {
|
|
1122
|
+
/**
|
|
1123
|
+
* Starting port number (inclusive).
|
|
1124
|
+
*/
|
|
1125
|
+
readonly start: number;
|
|
1126
|
+
/**
|
|
1127
|
+
* Ending port number (inclusive).
|
|
1128
|
+
*/
|
|
1129
|
+
readonly end: number;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Port range value with bigint type.
|
|
1133
|
+
*
|
|
1134
|
+
* @since 0.10.0
|
|
1135
|
+
*/
|
|
1136
|
+
interface PortRangeValueBigInt {
|
|
1137
|
+
/**
|
|
1138
|
+
* Starting port number (inclusive).
|
|
1139
|
+
*/
|
|
1140
|
+
readonly start: bigint;
|
|
1141
|
+
/**
|
|
1142
|
+
* Ending port number (inclusive).
|
|
1143
|
+
*/
|
|
1144
|
+
readonly end: bigint;
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Options for the {@link portRange} parser that returns number values.
|
|
1148
|
+
*
|
|
1149
|
+
* @since 0.10.0
|
|
1150
|
+
*/
|
|
1151
|
+
interface PortRangeOptionsNumber {
|
|
1152
|
+
/**
|
|
1153
|
+
* The type of values to return.
|
|
1154
|
+
* @default "number"
|
|
1155
|
+
*/
|
|
1156
|
+
readonly type?: "number";
|
|
1157
|
+
/**
|
|
1158
|
+
* The metavariable name for this parser.
|
|
1159
|
+
* @default "PORT-PORT"
|
|
1160
|
+
*/
|
|
1161
|
+
readonly metavar?: NonEmptyString;
|
|
1162
|
+
/**
|
|
1163
|
+
* Separator character(s) between start and end ports.
|
|
1164
|
+
* @default "-"
|
|
1165
|
+
*/
|
|
1166
|
+
readonly separator?: string;
|
|
1167
|
+
/**
|
|
1168
|
+
* Minimum allowed port number (inclusive).
|
|
1169
|
+
* Applied to both start and end ports.
|
|
1170
|
+
* @default 1
|
|
1171
|
+
*/
|
|
1172
|
+
readonly min?: number;
|
|
1173
|
+
/**
|
|
1174
|
+
* Maximum allowed port number (inclusive).
|
|
1175
|
+
* Applied to both start and end ports.
|
|
1176
|
+
* @default 65535
|
|
1177
|
+
*/
|
|
1178
|
+
readonly max?: number;
|
|
1179
|
+
/**
|
|
1180
|
+
* If `true`, disallows well-known ports (1-1023).
|
|
1181
|
+
* Applied to both start and end ports.
|
|
1182
|
+
* @default false
|
|
1183
|
+
*/
|
|
1184
|
+
readonly disallowWellKnown?: boolean;
|
|
1185
|
+
/**
|
|
1186
|
+
* If `true`, allows single port without range (e.g., "8080").
|
|
1187
|
+
* The result will have `start === end`.
|
|
1188
|
+
* @default false
|
|
1189
|
+
*/
|
|
1190
|
+
readonly allowSingle?: boolean;
|
|
1191
|
+
/**
|
|
1192
|
+
* Custom error messages for port range parsing failures.
|
|
1193
|
+
*/
|
|
1194
|
+
readonly errors?: {
|
|
1195
|
+
/**
|
|
1196
|
+
* Custom error message when input format is invalid.
|
|
1197
|
+
* Can be a static message or a function that receives the input.
|
|
1198
|
+
*/
|
|
1199
|
+
invalidFormat?: Message | ((input: string) => Message);
|
|
1200
|
+
/**
|
|
1201
|
+
* Custom error message when start port is greater than end port.
|
|
1202
|
+
* Can be a static message or a function that receives start and end.
|
|
1203
|
+
*/
|
|
1204
|
+
invalidRange?: Message | ((start: number, end: number) => Message);
|
|
1205
|
+
/**
|
|
1206
|
+
* Custom error message when port is invalid.
|
|
1207
|
+
* Inherited from PortOptions.
|
|
1208
|
+
*/
|
|
1209
|
+
invalidPort?: Message | ((input: string) => Message);
|
|
1210
|
+
/**
|
|
1211
|
+
* Custom error message when port is below minimum.
|
|
1212
|
+
* Inherited from PortOptions.
|
|
1213
|
+
*/
|
|
1214
|
+
belowMinimum?: Message | ((port: number, min: number) => Message);
|
|
1215
|
+
/**
|
|
1216
|
+
* Custom error message when port is above maximum.
|
|
1217
|
+
* Inherited from PortOptions.
|
|
1218
|
+
*/
|
|
1219
|
+
aboveMaximum?: Message | ((port: number, max: number) => Message);
|
|
1220
|
+
/**
|
|
1221
|
+
* Custom error message when well-known port is not allowed.
|
|
1222
|
+
* Inherited from PortOptions.
|
|
1223
|
+
*/
|
|
1224
|
+
wellKnownNotAllowed?: Message | ((port: number) => Message);
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
/**
|
|
1228
|
+
* Options for the {@link portRange} parser that returns bigint values.
|
|
1229
|
+
*
|
|
1230
|
+
* @since 0.10.0
|
|
1231
|
+
*/
|
|
1232
|
+
interface PortRangeOptionsBigInt {
|
|
1233
|
+
/**
|
|
1234
|
+
* Must be set to "bigint" to create a bigint parser.
|
|
1235
|
+
*/
|
|
1236
|
+
readonly type: "bigint";
|
|
1237
|
+
/**
|
|
1238
|
+
* The metavariable name for this parser.
|
|
1239
|
+
* @default "PORT-PORT"
|
|
1240
|
+
*/
|
|
1241
|
+
readonly metavar?: NonEmptyString;
|
|
1242
|
+
/**
|
|
1243
|
+
* Separator character(s) between start and end ports.
|
|
1244
|
+
* @default "-"
|
|
1245
|
+
*/
|
|
1246
|
+
readonly separator?: string;
|
|
1247
|
+
/**
|
|
1248
|
+
* Minimum allowed port number (inclusive).
|
|
1249
|
+
* Applied to both start and end ports.
|
|
1250
|
+
* @default 1n
|
|
1251
|
+
*/
|
|
1252
|
+
readonly min?: bigint;
|
|
1253
|
+
/**
|
|
1254
|
+
* Maximum allowed port number (inclusive).
|
|
1255
|
+
* Applied to both start and end ports.
|
|
1256
|
+
* @default 65535n
|
|
1257
|
+
*/
|
|
1258
|
+
readonly max?: bigint;
|
|
1259
|
+
/**
|
|
1260
|
+
* If `true`, disallows well-known ports (1-1023).
|
|
1261
|
+
* Applied to both start and end ports.
|
|
1262
|
+
* @default false
|
|
1263
|
+
*/
|
|
1264
|
+
readonly disallowWellKnown?: boolean;
|
|
1265
|
+
/**
|
|
1266
|
+
* If `true`, allows single port without range (e.g., "8080").
|
|
1267
|
+
* The result will have `start === end`.
|
|
1268
|
+
* @default false
|
|
1269
|
+
*/
|
|
1270
|
+
readonly allowSingle?: boolean;
|
|
1271
|
+
/**
|
|
1272
|
+
* Custom error messages for port range parsing failures.
|
|
1273
|
+
*/
|
|
1274
|
+
readonly errors?: {
|
|
1275
|
+
/**
|
|
1276
|
+
* Custom error message when input format is invalid.
|
|
1277
|
+
* Can be a static message or a function that receives the input.
|
|
1278
|
+
*/
|
|
1279
|
+
invalidFormat?: Message | ((input: string) => Message);
|
|
1280
|
+
/**
|
|
1281
|
+
* Custom error message when start port is greater than end port.
|
|
1282
|
+
* Can be a static message or a function that receives start and end.
|
|
1283
|
+
*/
|
|
1284
|
+
invalidRange?: Message | ((start: bigint, end: bigint) => Message);
|
|
1285
|
+
/**
|
|
1286
|
+
* Custom error message when port is invalid.
|
|
1287
|
+
* Inherited from PortOptions.
|
|
1288
|
+
*/
|
|
1289
|
+
invalidPort?: Message | ((input: string) => Message);
|
|
1290
|
+
/**
|
|
1291
|
+
* Custom error message when port is below minimum.
|
|
1292
|
+
* Inherited from PortOptions.
|
|
1293
|
+
*/
|
|
1294
|
+
belowMinimum?: Message | ((port: bigint, min: bigint) => Message);
|
|
1295
|
+
/**
|
|
1296
|
+
* Custom error message when port is above maximum.
|
|
1297
|
+
* Inherited from PortOptions.
|
|
1298
|
+
*/
|
|
1299
|
+
aboveMaximum?: Message | ((port: bigint, max: bigint) => Message);
|
|
1300
|
+
/**
|
|
1301
|
+
* Custom error message when well-known port is not allowed.
|
|
1302
|
+
* Inherited from PortOptions.
|
|
1303
|
+
*/
|
|
1304
|
+
wellKnownNotAllowed?: Message | ((port: bigint) => Message);
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Creates a value parser for port ranges (e.g., "8000-8080").
|
|
1309
|
+
*
|
|
1310
|
+
* Validates port ranges with support for:
|
|
1311
|
+
* - Custom separator between start and end ports
|
|
1312
|
+
* - Single port mode (when `allowSingle` is enabled)
|
|
1313
|
+
* - Port number or bigint types
|
|
1314
|
+
* - Min/max constraints
|
|
1315
|
+
* - Well-known port restrictions
|
|
1316
|
+
*
|
|
1317
|
+
* @param options - Options for port range validation.
|
|
1318
|
+
* @returns A value parser for port ranges.
|
|
1319
|
+
* @since 0.10.0
|
|
1320
|
+
*
|
|
1321
|
+
* @example
|
|
1322
|
+
* ```typescript
|
|
1323
|
+
* import { portRange } from "@optique/core/valueparser";
|
|
1324
|
+
*
|
|
1325
|
+
* // Basic port range parser
|
|
1326
|
+
* const range = portRange();
|
|
1327
|
+
*
|
|
1328
|
+
* // Allow single port
|
|
1329
|
+
* const flexible = portRange({ allowSingle: true });
|
|
1330
|
+
*
|
|
1331
|
+
* // Non-privileged ports only
|
|
1332
|
+
* const safe = portRange({ min: 1024 });
|
|
1333
|
+
*
|
|
1334
|
+
* // Using bigint type
|
|
1335
|
+
* const bigRange = portRange({ type: "bigint" });
|
|
1336
|
+
* ```
|
|
1337
|
+
*/
|
|
1338
|
+
declare function portRange(options: PortRangeOptionsBigInt): ValueParser<"sync", PortRangeValueBigInt>;
|
|
1339
|
+
declare function portRange(options?: PortRangeOptionsNumber): ValueParser<"sync", PortRangeValueNumber>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Options for the {@link macAddress} parser.
|
|
1342
|
+
*
|
|
1343
|
+
* @since 0.10.0
|
|
1344
|
+
*/
|
|
1345
|
+
interface MacAddressOptions {
|
|
1346
|
+
/**
|
|
1347
|
+
* The metavariable name for this parser.
|
|
1348
|
+
* @default "MAC"
|
|
1349
|
+
*/
|
|
1350
|
+
readonly metavar?: NonEmptyString;
|
|
1351
|
+
/**
|
|
1352
|
+
* Separator format to accept.
|
|
1353
|
+
* - `":"`: Colon-separated (e.g., `00:1A:2B:3C:4D:5E`)
|
|
1354
|
+
* - `"-"`: Hyphen-separated (e.g., `00-1A-2B-3C-4D-5E`)
|
|
1355
|
+
* - `"."`: Dot-separated (e.g., `001A.2B3C.4D5E` - Cisco format)
|
|
1356
|
+
* - `"none"`: No separator (e.g., `001A2B3C4D5E`)
|
|
1357
|
+
* - `"any"`: Accept any of the above formats
|
|
1358
|
+
* @default "any"
|
|
1359
|
+
*/
|
|
1360
|
+
readonly separator?: ":" | "-" | "." | "none" | "any";
|
|
1361
|
+
/**
|
|
1362
|
+
* Case for the output.
|
|
1363
|
+
* - `"preserve"`: Keep input case
|
|
1364
|
+
* - `"upper"`: Convert to uppercase
|
|
1365
|
+
* - `"lower"`: Convert to lowercase
|
|
1366
|
+
* @default "preserve"
|
|
1367
|
+
*/
|
|
1368
|
+
readonly case?: "preserve" | "upper" | "lower";
|
|
1369
|
+
/**
|
|
1370
|
+
* Output separator format.
|
|
1371
|
+
* If not specified, uses the input separator (or ":" for "any").
|
|
1372
|
+
* @default undefined (uses input format)
|
|
1373
|
+
*/
|
|
1374
|
+
readonly outputSeparator?: ":" | "-" | "." | "none";
|
|
1375
|
+
/**
|
|
1376
|
+
* Custom error messages for MAC address parsing failures.
|
|
1377
|
+
*/
|
|
1378
|
+
readonly errors?: {
|
|
1379
|
+
/**
|
|
1380
|
+
* Custom error message when input is not a valid MAC address.
|
|
1381
|
+
* Can be a static message or a function that receives the input.
|
|
1382
|
+
*/
|
|
1383
|
+
invalidMacAddress?: Message | ((input: string) => Message);
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Creates a value parser for MAC (Media Access Control) addresses.
|
|
1388
|
+
*
|
|
1389
|
+
* Validates MAC-48 addresses (6 octets, 12 hex digits) in various formats:
|
|
1390
|
+
* - Colon-separated: `00:1A:2B:3C:4D:5E`
|
|
1391
|
+
* - Hyphen-separated: `00-1A-2B-3C-4D-5E`
|
|
1392
|
+
* - Dot-separated (Cisco): `001A.2B3C.4D5E`
|
|
1393
|
+
* - No separator: `001A2B3C4D5E`
|
|
1394
|
+
*
|
|
1395
|
+
* Returns the MAC address as a formatted string according to `case` and
|
|
1396
|
+
* `outputSeparator` options.
|
|
1397
|
+
*
|
|
1398
|
+
* @param options Configuration options for the MAC address parser.
|
|
1399
|
+
* @returns A parser that validates MAC addresses and returns formatted strings.
|
|
1400
|
+
* @since 0.10.0
|
|
1401
|
+
*
|
|
1402
|
+
* @example
|
|
1403
|
+
* ```typescript
|
|
1404
|
+
* import { macAddress } from "@optique/core/valueparser";
|
|
1405
|
+
*
|
|
1406
|
+
* // Accept any format
|
|
1407
|
+
* const mac = macAddress();
|
|
1408
|
+
*
|
|
1409
|
+
* // Normalize to uppercase colon-separated
|
|
1410
|
+
* const normalizedMac = macAddress({
|
|
1411
|
+
* outputSeparator: ":",
|
|
1412
|
+
* case: "upper"
|
|
1413
|
+
* });
|
|
1414
|
+
* ```
|
|
1415
|
+
*/
|
|
1416
|
+
declare function macAddress(options?: MacAddressOptions): ValueParser<"sync", string>;
|
|
1417
|
+
/**
|
|
1418
|
+
* Options for {@link domain} parser.
|
|
1419
|
+
*
|
|
1420
|
+
* @since 0.10.0
|
|
1421
|
+
*/
|
|
1422
|
+
interface DomainOptions {
|
|
1423
|
+
/**
|
|
1424
|
+
* The metavariable name for this parser.
|
|
1425
|
+
*
|
|
1426
|
+
* @default "DOMAIN"
|
|
1427
|
+
*/
|
|
1428
|
+
readonly metavar?: NonEmptyString;
|
|
1429
|
+
/**
|
|
1430
|
+
* If `true`, allows subdomains (e.g., "www.example.com").
|
|
1431
|
+
* If `false`, only accepts root domains (e.g., "example.com").
|
|
1432
|
+
*
|
|
1433
|
+
* @default true
|
|
1434
|
+
*/
|
|
1435
|
+
readonly allowSubdomains?: boolean;
|
|
1436
|
+
/**
|
|
1437
|
+
* List of allowed top-level domains (e.g., ["com", "org", "net"]).
|
|
1438
|
+
* If specified, only domains with these TLDs are accepted.
|
|
1439
|
+
*/
|
|
1440
|
+
readonly allowedTLDs?: readonly string[];
|
|
1441
|
+
/**
|
|
1442
|
+
* Minimum number of domain labels (parts separated by dots).
|
|
1443
|
+
*
|
|
1444
|
+
* @default 2
|
|
1445
|
+
*/
|
|
1446
|
+
readonly minLabels?: number;
|
|
1447
|
+
/**
|
|
1448
|
+
* If `true`, converts domain to lowercase.
|
|
1449
|
+
*
|
|
1450
|
+
* @default false
|
|
1451
|
+
*/
|
|
1452
|
+
readonly lowercase?: boolean;
|
|
1453
|
+
/**
|
|
1454
|
+
* Custom error messages for domain parsing failures.
|
|
1455
|
+
*/
|
|
1456
|
+
readonly errors?: {
|
|
1457
|
+
/**
|
|
1458
|
+
* Custom error message when input is not a valid domain.
|
|
1459
|
+
* Can be a static message or a function that receives the input.
|
|
1460
|
+
*/
|
|
1461
|
+
invalidDomain?: Message | ((input: string) => Message);
|
|
1462
|
+
/**
|
|
1463
|
+
* Custom error message when subdomains are not allowed.
|
|
1464
|
+
* Can be a static message or a function that receives the domain.
|
|
1465
|
+
*/
|
|
1466
|
+
subdomainsNotAllowed?: Message | ((domain: string) => Message);
|
|
1467
|
+
/**
|
|
1468
|
+
* Custom error message when TLD is not allowed.
|
|
1469
|
+
* Can be a static message or a function that receives the TLD
|
|
1470
|
+
* and allowed TLDs.
|
|
1471
|
+
*/
|
|
1472
|
+
tldNotAllowed?: Message | ((tld: string, allowedTLDs: readonly string[]) => Message);
|
|
1473
|
+
/**
|
|
1474
|
+
* Custom error message when domain has too few labels.
|
|
1475
|
+
* Can be a static message or a function that receives the domain
|
|
1476
|
+
* and minimum labels.
|
|
1477
|
+
*/
|
|
1478
|
+
tooFewLabels?: Message | ((domain: string, minLabels: number) => Message);
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
/**
|
|
1482
|
+
* Creates a value parser for domain names.
|
|
1483
|
+
*
|
|
1484
|
+
* Validates domain names according to RFC 1035 with configurable options for
|
|
1485
|
+
* subdomain filtering, TLD restrictions, minimum label requirements, and case
|
|
1486
|
+
* normalization.
|
|
1487
|
+
*
|
|
1488
|
+
* @param options Parser options for domain validation.
|
|
1489
|
+
* @returns A parser that accepts valid domain names as strings.
|
|
1490
|
+
*
|
|
1491
|
+
* @example
|
|
1492
|
+
* ``` typescript
|
|
1493
|
+
* import { option } from "@optique/core/primitives";
|
|
1494
|
+
* import { domain } from "@optique/core/valueparser";
|
|
1495
|
+
*
|
|
1496
|
+
* // Accept any valid domain
|
|
1497
|
+
* option("--domain", domain())
|
|
1498
|
+
*
|
|
1499
|
+
* // Root domains only (no subdomains)
|
|
1500
|
+
* option("--root", domain({ allowSubdomains: false }))
|
|
1501
|
+
*
|
|
1502
|
+
* // Restrict to specific TLDs
|
|
1503
|
+
* option("--domain", domain({ allowedTLDs: ["com", "org", "net"] }))
|
|
1504
|
+
*
|
|
1505
|
+
* // Normalize to lowercase
|
|
1506
|
+
* option("--domain", domain({ lowercase: true }))
|
|
1507
|
+
* ```
|
|
1508
|
+
*
|
|
1509
|
+
* @since 0.10.0
|
|
1510
|
+
*/
|
|
1511
|
+
declare function domain(options?: DomainOptions & {
|
|
1512
|
+
readonly metavar?: NonEmptyString;
|
|
1513
|
+
}): ValueParser<"sync", string>;
|
|
1514
|
+
/**
|
|
1515
|
+
* Options for configuring the IPv6 address value parser.
|
|
1516
|
+
*
|
|
1517
|
+
* @since 0.10.0
|
|
1518
|
+
*/
|
|
1519
|
+
interface Ipv6Options {
|
|
1520
|
+
/**
|
|
1521
|
+
* The metavariable name for this parser.
|
|
1522
|
+
*
|
|
1523
|
+
* @default `"IPV6"`
|
|
1524
|
+
*/
|
|
1525
|
+
readonly metavar?: NonEmptyString;
|
|
1526
|
+
/**
|
|
1527
|
+
* If `true`, allows loopback address (::1).
|
|
1528
|
+
*
|
|
1529
|
+
* @default `true`
|
|
1530
|
+
*/
|
|
1531
|
+
readonly allowLoopback?: boolean;
|
|
1532
|
+
/**
|
|
1533
|
+
* If `true`, allows link-local addresses (fe80::/10).
|
|
1534
|
+
*
|
|
1535
|
+
* @default `true`
|
|
1536
|
+
*/
|
|
1537
|
+
readonly allowLinkLocal?: boolean;
|
|
1538
|
+
/**
|
|
1539
|
+
* If `true`, allows unique local addresses (fc00::/7).
|
|
1540
|
+
*
|
|
1541
|
+
* @default `true`
|
|
1542
|
+
*/
|
|
1543
|
+
readonly allowUniqueLocal?: boolean;
|
|
1544
|
+
/**
|
|
1545
|
+
* If `true`, allows multicast addresses (ff00::/8).
|
|
1546
|
+
*
|
|
1547
|
+
* @default `true`
|
|
1548
|
+
*/
|
|
1549
|
+
readonly allowMulticast?: boolean;
|
|
1550
|
+
/**
|
|
1551
|
+
* If `true`, allows the zero address (::).
|
|
1552
|
+
*
|
|
1553
|
+
* @default `true`
|
|
1554
|
+
*/
|
|
1555
|
+
readonly allowZero?: boolean;
|
|
1556
|
+
/**
|
|
1557
|
+
* Custom error messages for IPv6 parsing failures.
|
|
1558
|
+
*/
|
|
1559
|
+
readonly errors?: {
|
|
1560
|
+
/**
|
|
1561
|
+
* Custom error message when input is not a valid IPv6 address.
|
|
1562
|
+
* Can be a static message or a function that receives the input.
|
|
1563
|
+
*/
|
|
1564
|
+
invalidIpv6?: Message | ((input: string) => Message);
|
|
1565
|
+
/**
|
|
1566
|
+
* Custom error message when loopback IP is used but disallowed.
|
|
1567
|
+
* Can be a static message or a function that receives the IP.
|
|
1568
|
+
*/
|
|
1569
|
+
loopbackNotAllowed?: Message | ((ip: string) => Message);
|
|
1570
|
+
/**
|
|
1571
|
+
* Custom error message when link-local IP is used but disallowed.
|
|
1572
|
+
* Can be a static message or a function that receives the IP.
|
|
1573
|
+
*/
|
|
1574
|
+
linkLocalNotAllowed?: Message | ((ip: string) => Message);
|
|
1575
|
+
/**
|
|
1576
|
+
* Custom error message when unique local IP is used but disallowed.
|
|
1577
|
+
* Can be a static message or a function that receives the IP.
|
|
1578
|
+
*/
|
|
1579
|
+
uniqueLocalNotAllowed?: Message | ((ip: string) => Message);
|
|
1580
|
+
/**
|
|
1581
|
+
* Custom error message when multicast IP is used but disallowed.
|
|
1582
|
+
* Can be a static message or a function that receives the IP.
|
|
1583
|
+
*/
|
|
1584
|
+
multicastNotAllowed?: Message | ((ip: string) => Message);
|
|
1585
|
+
/**
|
|
1586
|
+
* Custom error message when zero IP is used but disallowed.
|
|
1587
|
+
* Can be a static message or a function that receives the IP.
|
|
1588
|
+
*/
|
|
1589
|
+
zeroNotAllowed?: Message | ((ip: string) => Message);
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Creates a value parser for IPv6 addresses.
|
|
1594
|
+
*
|
|
1595
|
+
* Validates and normalizes IPv6 addresses to canonical form (lowercase,
|
|
1596
|
+
* compressed using `::` notation where appropriate).
|
|
1597
|
+
*
|
|
1598
|
+
* @param options Configuration options for IPv6 validation.
|
|
1599
|
+
* @returns A value parser that validates IPv6 addresses.
|
|
1600
|
+
*
|
|
1601
|
+
* @example
|
|
1602
|
+
* ```typescript
|
|
1603
|
+
* // Basic IPv6 parser
|
|
1604
|
+
* option("--ipv6", ipv6())
|
|
1605
|
+
*
|
|
1606
|
+
* // Global unicast only (no link-local, no unique local)
|
|
1607
|
+
* option("--public-ipv6", ipv6({
|
|
1608
|
+
* allowLinkLocal: false,
|
|
1609
|
+
* allowUniqueLocal: false
|
|
1610
|
+
* }))
|
|
1611
|
+
* ```
|
|
1612
|
+
*
|
|
1613
|
+
* @since 0.10.0
|
|
1614
|
+
*/
|
|
1615
|
+
declare function ipv6(options?: Ipv6Options): ValueParser<"sync", string>;
|
|
1616
|
+
/**
|
|
1617
|
+
* Options for configuring the universal IP address value parser.
|
|
1618
|
+
*
|
|
1619
|
+
* @since 0.10.0
|
|
1620
|
+
*/
|
|
1621
|
+
interface IpOptions {
|
|
1622
|
+
/**
|
|
1623
|
+
* The metavariable name for this parser.
|
|
1624
|
+
*
|
|
1625
|
+
* @default `"IP"`
|
|
1626
|
+
*/
|
|
1627
|
+
readonly metavar?: NonEmptyString;
|
|
1628
|
+
/**
|
|
1629
|
+
* IP version to accept.
|
|
1630
|
+
* - `4`: IPv4 only
|
|
1631
|
+
* - `6`: IPv6 only
|
|
1632
|
+
* - `"both"`: Accept both IPv4 and IPv6
|
|
1633
|
+
*
|
|
1634
|
+
* @default `"both"`
|
|
1635
|
+
*/
|
|
1636
|
+
readonly version?: 4 | 6 | "both";
|
|
1637
|
+
/**
|
|
1638
|
+
* Options for IPv4 validation (when version is 4 or "both").
|
|
1639
|
+
*/
|
|
1640
|
+
readonly ipv4?: Omit<Ipv4Options, "metavar" | "errors">;
|
|
1641
|
+
/**
|
|
1642
|
+
* Options for IPv6 validation (when version is 6 or "both").
|
|
1643
|
+
*/
|
|
1644
|
+
readonly ipv6?: Omit<Ipv6Options, "metavar" | "errors">;
|
|
1645
|
+
/**
|
|
1646
|
+
* Custom error messages for IP parsing failures.
|
|
1647
|
+
*/
|
|
1648
|
+
readonly errors?: {
|
|
1649
|
+
/**
|
|
1650
|
+
* Custom error message when input is not a valid IP address.
|
|
1651
|
+
* Can be a static message or a function that receives the input.
|
|
1652
|
+
*/
|
|
1653
|
+
invalidIP?: Message | ((input: string) => Message);
|
|
1654
|
+
/**
|
|
1655
|
+
* Custom error message when private IP is used but disallowed (IPv4).
|
|
1656
|
+
* Can be a static message or a function that receives the IP.
|
|
1657
|
+
*/
|
|
1658
|
+
privateNotAllowed?: Message | ((ip: string) => Message);
|
|
1659
|
+
/**
|
|
1660
|
+
* Custom error message when loopback IP is used but disallowed.
|
|
1661
|
+
* Can be a static message or a function that receives the IP.
|
|
1662
|
+
*/
|
|
1663
|
+
loopbackNotAllowed?: Message | ((ip: string) => Message);
|
|
1664
|
+
/**
|
|
1665
|
+
* Custom error message when link-local IP is used but disallowed.
|
|
1666
|
+
* Can be a static message or a function that receives the IP.
|
|
1667
|
+
*/
|
|
1668
|
+
linkLocalNotAllowed?: Message | ((ip: string) => Message);
|
|
1669
|
+
/**
|
|
1670
|
+
* Custom error message when multicast IP is used but disallowed.
|
|
1671
|
+
* Can be a static message or a function that receives the IP.
|
|
1672
|
+
*/
|
|
1673
|
+
multicastNotAllowed?: Message | ((ip: string) => Message);
|
|
1674
|
+
/**
|
|
1675
|
+
* Custom error message when broadcast IP is used but disallowed (IPv4).
|
|
1676
|
+
* Can be a static message or a function that receives the IP.
|
|
1677
|
+
*/
|
|
1678
|
+
broadcastNotAllowed?: Message | ((ip: string) => Message);
|
|
1679
|
+
/**
|
|
1680
|
+
* Custom error message when zero IP is used but disallowed.
|
|
1681
|
+
* Can be a static message or a function that receives the IP.
|
|
1682
|
+
*/
|
|
1683
|
+
zeroNotAllowed?: Message | ((ip: string) => Message);
|
|
1684
|
+
/**
|
|
1685
|
+
* Custom error message when unique local IP is used but disallowed (IPv6).
|
|
1686
|
+
* Can be a static message or a function that receives the IP.
|
|
1687
|
+
*/
|
|
1688
|
+
uniqueLocalNotAllowed?: Message | ((ip: string) => Message);
|
|
1689
|
+
};
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Creates a value parser that accepts both IPv4 and IPv6 addresses.
|
|
1693
|
+
*
|
|
1694
|
+
* By default, accepts both IPv4 and IPv6 addresses. Use the `version` option
|
|
1695
|
+
* to restrict to a specific IP version.
|
|
1696
|
+
*
|
|
1697
|
+
* @param options Configuration options for IP validation.
|
|
1698
|
+
* @returns A value parser that validates IP addresses.
|
|
1699
|
+
*
|
|
1700
|
+
* @example
|
|
1701
|
+
* ```typescript
|
|
1702
|
+
* // Accept both IPv4 and IPv6
|
|
1703
|
+
* option("--ip", ip())
|
|
1704
|
+
*
|
|
1705
|
+
* // IPv4 only
|
|
1706
|
+
* option("--ipv4", ip({ version: 4 }))
|
|
1707
|
+
*
|
|
1708
|
+
* // Public IPs only (both versions)
|
|
1709
|
+
* option("--public-ip", ip({
|
|
1710
|
+
* ipv4: { allowPrivate: false, allowLoopback: false },
|
|
1711
|
+
* ipv6: { allowLinkLocal: false, allowUniqueLocal: false }
|
|
1712
|
+
* }))
|
|
1713
|
+
* ```
|
|
1714
|
+
*
|
|
1715
|
+
* @since 0.10.0
|
|
1716
|
+
*/
|
|
1717
|
+
declare function ip(options?: IpOptions): ValueParser<"sync", string>;
|
|
1718
|
+
/**
|
|
1719
|
+
* Value representing a CIDR notation (IP address with prefix length).
|
|
1720
|
+
*
|
|
1721
|
+
* @since 0.10.0
|
|
1722
|
+
*/
|
|
1723
|
+
interface CidrValue {
|
|
1724
|
+
/**
|
|
1725
|
+
* The IP address portion (normalized).
|
|
1726
|
+
*/
|
|
1727
|
+
readonly address: string;
|
|
1728
|
+
/**
|
|
1729
|
+
* The prefix length (0-32 for IPv4, 0-128 for IPv6).
|
|
1730
|
+
*/
|
|
1731
|
+
readonly prefix: number;
|
|
1732
|
+
/**
|
|
1733
|
+
* IP version (4 or 6).
|
|
1734
|
+
*/
|
|
1735
|
+
readonly version: 4 | 6;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* Options for configuring the CIDR notation value parser.
|
|
1739
|
+
*
|
|
1740
|
+
* @since 0.10.0
|
|
1741
|
+
*/
|
|
1742
|
+
interface CidrOptions {
|
|
1743
|
+
/**
|
|
1744
|
+
* The metavariable name for this parser.
|
|
1745
|
+
*
|
|
1746
|
+
* @default `"CIDR"`
|
|
1747
|
+
*/
|
|
1748
|
+
readonly metavar?: NonEmptyString;
|
|
1749
|
+
/**
|
|
1750
|
+
* IP version to accept.
|
|
1751
|
+
* - `4`: IPv4 CIDR only
|
|
1752
|
+
* - `6`: IPv6 CIDR only
|
|
1753
|
+
* - `"both"`: Accept both IPv4 and IPv6 CIDR
|
|
1754
|
+
*
|
|
1755
|
+
* @default `"both"`
|
|
1756
|
+
*/
|
|
1757
|
+
readonly version?: 4 | 6 | "both";
|
|
1758
|
+
/**
|
|
1759
|
+
* Minimum allowed prefix length.
|
|
1760
|
+
* For IPv4: 0-32, for IPv6: 0-128.
|
|
1761
|
+
*/
|
|
1762
|
+
readonly minPrefix?: number;
|
|
1763
|
+
/**
|
|
1764
|
+
* Maximum allowed prefix length.
|
|
1765
|
+
* For IPv4: 0-32, for IPv6: 0-128.
|
|
1766
|
+
*/
|
|
1767
|
+
readonly maxPrefix?: number;
|
|
1768
|
+
/**
|
|
1769
|
+
* Options for IPv4 validation (when version is 4 or "both").
|
|
1770
|
+
*/
|
|
1771
|
+
readonly ipv4?: Omit<Ipv4Options, "metavar" | "errors">;
|
|
1772
|
+
/**
|
|
1773
|
+
* Options for IPv6 validation (when version is 6 or "both").
|
|
1774
|
+
*/
|
|
1775
|
+
readonly ipv6?: Omit<Ipv6Options, "metavar" | "errors">;
|
|
1776
|
+
/**
|
|
1777
|
+
* Custom error messages for CIDR parsing failures.
|
|
1778
|
+
*/
|
|
1779
|
+
readonly errors?: {
|
|
1780
|
+
/**
|
|
1781
|
+
* Custom error message when input is not a valid CIDR notation.
|
|
1782
|
+
* Can be a static message or a function that receives the input.
|
|
1783
|
+
*/
|
|
1784
|
+
invalidCidr?: Message | ((input: string) => Message);
|
|
1785
|
+
/**
|
|
1786
|
+
* Custom error message when prefix length is invalid.
|
|
1787
|
+
* Can be a static message or a function that receives the prefix and version.
|
|
1788
|
+
*/
|
|
1789
|
+
invalidPrefix?: Message | ((prefix: number, version: 4 | 6) => Message);
|
|
1790
|
+
/**
|
|
1791
|
+
* Custom error message when prefix is below minimum.
|
|
1792
|
+
* Can be a static message or a function that receives the prefix and minimum.
|
|
1793
|
+
*/
|
|
1794
|
+
prefixBelowMinimum?: Message | ((prefix: number, min: number) => Message);
|
|
1795
|
+
/**
|
|
1796
|
+
* Custom error message when prefix is above maximum.
|
|
1797
|
+
* Can be a static message or a function that receives the prefix and maximum.
|
|
1798
|
+
*/
|
|
1799
|
+
prefixAboveMaximum?: Message | ((prefix: number, max: number) => Message);
|
|
1800
|
+
};
|
|
1801
|
+
}
|
|
1802
|
+
/**
|
|
1803
|
+
* Creates a value parser for CIDR notation (IP address with prefix length).
|
|
1804
|
+
*
|
|
1805
|
+
* Parses and validates CIDR notation like `192.168.0.0/24` or `2001:db8::/32`.
|
|
1806
|
+
* Returns a structured object with the normalized IP address, prefix length,
|
|
1807
|
+
* and IP version.
|
|
1808
|
+
*
|
|
1809
|
+
* @param options Configuration options for CIDR validation.
|
|
1810
|
+
* @returns A value parser that validates CIDR notation.
|
|
1811
|
+
*
|
|
1812
|
+
* @example
|
|
1813
|
+
* ```typescript
|
|
1814
|
+
* // Accept both IPv4 and IPv6 CIDR
|
|
1815
|
+
* option("--network", cidr())
|
|
1816
|
+
*
|
|
1817
|
+
* // IPv4 CIDR only with prefix constraints
|
|
1818
|
+
* option("--subnet", cidr({
|
|
1819
|
+
* version: 4,
|
|
1820
|
+
* minPrefix: 16,
|
|
1821
|
+
* maxPrefix: 24
|
|
1822
|
+
* }))
|
|
1823
|
+
* ```
|
|
1824
|
+
*
|
|
1825
|
+
* @since 0.10.0
|
|
1826
|
+
*/
|
|
1827
|
+
declare function cidr(options?: CidrOptions): ValueParser<"sync", CidrValue>;
|
|
558
1828
|
//#endregion
|
|
559
|
-
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, FloatOptions, IntegerOptionsBigInt, IntegerOptionsNumber, LocaleOptions, type Mode, type ModeIterable, type ModeValue, type NonEmptyString, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, ensureNonEmptyString, float, integer, isNonEmptyString, isValueParser, locale, string, url, uuid };
|
|
1829
|
+
export { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, 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, choice, cidr, domain, email, ensureNonEmptyString, float, hostname, integer, ip, ipv4, ipv6, isNonEmptyString, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid };
|