@optique/core 1.0.0-dev.513 → 1.0.0-dev.517
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/constructs.d.cts +46 -26
- package/dist/constructs.d.ts +46 -26
- package/package.json +1 -1
package/dist/constructs.d.cts
CHANGED
|
@@ -849,40 +849,40 @@ type LongestMatchArityGuard<TParsers extends readonly unknown[]> = IsTuple<TPars
|
|
|
849
849
|
declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...parsers: TParsers & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
850
850
|
/**
|
|
851
851
|
* Creates a parser that selects the successful branch that consumed
|
|
852
|
-
* the most input tokens.
|
|
852
|
+
* the most input tokens, with custom error options.
|
|
853
853
|
*
|
|
854
854
|
* The resulting parser tries every given parser and returns the
|
|
855
855
|
* successful result that consumed more input than the others.
|
|
856
856
|
*
|
|
857
|
-
* @param
|
|
857
|
+
* @param rest Parsers to compare, followed by error customization options.
|
|
858
858
|
* @returns A parser that yields the best successful branch result.
|
|
859
859
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
860
|
-
* @since 0.
|
|
860
|
+
* @since 0.5.0
|
|
861
861
|
*/
|
|
862
|
-
declare function longestMatch<const TParsers extends readonly Parser<
|
|
862
|
+
declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
863
863
|
/**
|
|
864
864
|
* Creates a parser that selects the successful branch that consumed
|
|
865
865
|
* the most input tokens, with custom error options.
|
|
866
866
|
*
|
|
867
|
-
* The resulting parser tries every given parser and returns the
|
|
868
|
-
* successful result that consumed more input than the others.
|
|
869
|
-
*
|
|
870
867
|
* @param rest Parsers to compare, followed by error customization options.
|
|
871
868
|
* @returns A parser that yields the best successful branch result.
|
|
872
869
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
873
870
|
* @since 0.5.0
|
|
874
871
|
*/
|
|
875
|
-
declare function longestMatch<const TParsers extends readonly Parser<
|
|
872
|
+
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
876
873
|
/**
|
|
877
874
|
* Creates a parser that selects the successful branch that consumed
|
|
878
|
-
* the most input tokens
|
|
875
|
+
* the most input tokens.
|
|
879
876
|
*
|
|
880
|
-
*
|
|
877
|
+
* The resulting parser tries every given parser and returns the
|
|
878
|
+
* successful result that consumed more input than the others.
|
|
879
|
+
*
|
|
880
|
+
* @param parsers Parsers to evaluate and compare by consumed input.
|
|
881
881
|
* @returns A parser that yields the best successful branch result.
|
|
882
882
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
883
|
-
* @since 0.
|
|
883
|
+
* @since 0.3.0
|
|
884
884
|
*/
|
|
885
|
-
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...
|
|
885
|
+
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
886
886
|
/**
|
|
887
887
|
* Options for the {@link object} parser.
|
|
888
888
|
* @since 0.5.0
|
|
@@ -1097,18 +1097,6 @@ type EnsureMergeParsers<TParsers extends MergeParsers> = { readonly [K in keyof
|
|
|
1097
1097
|
type IntersectMergeValues<TParsers extends MergeParsers> = TParsers extends readonly [infer THead extends Parser<Mode, unknown, unknown>, ...infer TRest extends MergeParsers] ? ExtractObjectTypes<THead> & IntersectMergeValues<TRest> : unknown;
|
|
1098
1098
|
type MergeValues<TParsers extends MergeParsers> = IsTuple<TParsers> extends true ? IntersectMergeValues<TParsers> : Record<string | symbol, unknown>;
|
|
1099
1099
|
type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, MergeValues<TParsers>, Record<string | symbol, unknown>>;
|
|
1100
|
-
/**
|
|
1101
|
-
* Merges multiple object-like parsers into one parser.
|
|
1102
|
-
*
|
|
1103
|
-
* This is useful for combining separate object parsers into one
|
|
1104
|
-
* unified parser while keeping fields grouped by parser boundaries.
|
|
1105
|
-
*
|
|
1106
|
-
* @param parsers Parsers to merge in declaration order.
|
|
1107
|
-
* @returns A parser that merges parsed object fields from all parsers.
|
|
1108
|
-
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
1109
|
-
* @since 0.4.0
|
|
1110
|
-
*/
|
|
1111
|
-
declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1112
1100
|
/**
|
|
1113
1101
|
* Merges multiple object-like parsers into one parser, with options.
|
|
1114
1102
|
*
|
|
@@ -1147,6 +1135,18 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
|
|
|
1147
1135
|
* @since 0.7.0
|
|
1148
1136
|
*/
|
|
1149
1137
|
declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Merges multiple object-like parsers into one parser.
|
|
1140
|
+
*
|
|
1141
|
+
* This is useful for combining separate object parsers into one
|
|
1142
|
+
* unified parser while keeping fields grouped by parser boundaries.
|
|
1143
|
+
*
|
|
1144
|
+
* @param parsers Parsers to merge in declaration order.
|
|
1145
|
+
* @returns A parser that merges parsed object fields from all parsers.
|
|
1146
|
+
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
1147
|
+
* @since 0.4.0
|
|
1148
|
+
*/
|
|
1149
|
+
declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1150
1150
|
type ConcatParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
1151
1151
|
type ConcatArityLimitError = {
|
|
1152
1152
|
readonly __optiqueConcatArityLimit: "concat() requires between 1 and 15 parser arguments. Nest concat() to combine more.";
|
|
@@ -1164,8 +1164,28 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
|
|
|
1164
1164
|
*
|
|
1165
1165
|
* @example
|
|
1166
1166
|
* ```typescript
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1167
|
+
* import { parse } from "@optique/core/parser";
|
|
1168
|
+
* import { option } from "@optique/core/primitives";
|
|
1169
|
+
* import { integer, string } from "@optique/core/valueparser";
|
|
1170
|
+
*
|
|
1171
|
+
* const basicTuple = tuple([
|
|
1172
|
+
* option("-v", "--verbose"),
|
|
1173
|
+
* option("-p", "--port", integer()),
|
|
1174
|
+
* ]);
|
|
1175
|
+
*
|
|
1176
|
+
* const serverTuple = tuple([
|
|
1177
|
+
* option("-h", "--host", string()),
|
|
1178
|
+
* option("-d", "--debug"),
|
|
1179
|
+
* ]);
|
|
1180
|
+
*
|
|
1181
|
+
* const combined = concat(basicTuple, serverTuple);
|
|
1182
|
+
* // Inferred type: Parser<..., [boolean, number, string, boolean], ...>
|
|
1183
|
+
*
|
|
1184
|
+
* const result = parse(
|
|
1185
|
+
* combined,
|
|
1186
|
+
* ["-v", "-p", "8080", "-h", "localhost", "-d"],
|
|
1187
|
+
* );
|
|
1188
|
+
* // result.value: [true, 8080, "localhost", true]
|
|
1169
1189
|
* ```
|
|
1170
1190
|
*
|
|
1171
1191
|
* @param parsers Tuple parsers to concatenate.
|
package/dist/constructs.d.ts
CHANGED
|
@@ -849,40 +849,40 @@ type LongestMatchArityGuard<TParsers extends readonly unknown[]> = IsTuple<TPars
|
|
|
849
849
|
declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...parsers: TParsers & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
850
850
|
/**
|
|
851
851
|
* Creates a parser that selects the successful branch that consumed
|
|
852
|
-
* the most input tokens.
|
|
852
|
+
* the most input tokens, with custom error options.
|
|
853
853
|
*
|
|
854
854
|
* The resulting parser tries every given parser and returns the
|
|
855
855
|
* successful result that consumed more input than the others.
|
|
856
856
|
*
|
|
857
|
-
* @param
|
|
857
|
+
* @param rest Parsers to compare, followed by error customization options.
|
|
858
858
|
* @returns A parser that yields the best successful branch result.
|
|
859
859
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
860
|
-
* @since 0.
|
|
860
|
+
* @since 0.5.0
|
|
861
861
|
*/
|
|
862
|
-
declare function longestMatch<const TParsers extends readonly Parser<
|
|
862
|
+
declare function longestMatch<const TParsers extends readonly Parser<"sync", unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<"sync", InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
863
863
|
/**
|
|
864
864
|
* Creates a parser that selects the successful branch that consumed
|
|
865
865
|
* the most input tokens, with custom error options.
|
|
866
866
|
*
|
|
867
|
-
* The resulting parser tries every given parser and returns the
|
|
868
|
-
* successful result that consumed more input than the others.
|
|
869
|
-
*
|
|
870
867
|
* @param rest Parsers to compare, followed by error customization options.
|
|
871
868
|
* @returns A parser that yields the best successful branch result.
|
|
872
869
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
873
870
|
* @since 0.5.0
|
|
874
871
|
*/
|
|
875
|
-
declare function longestMatch<const TParsers extends readonly Parser<
|
|
872
|
+
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...rest: [...parsers: TParsers, options: LongestMatchTailOptions] & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
876
873
|
/**
|
|
877
874
|
* Creates a parser that selects the successful branch that consumed
|
|
878
|
-
* the most input tokens
|
|
875
|
+
* the most input tokens.
|
|
879
876
|
*
|
|
880
|
-
*
|
|
877
|
+
* The resulting parser tries every given parser and returns the
|
|
878
|
+
* successful result that consumed more input than the others.
|
|
879
|
+
*
|
|
880
|
+
* @param parsers Parsers to evaluate and compare by consumed input.
|
|
881
881
|
* @returns A parser that yields the best successful branch result.
|
|
882
882
|
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
883
|
-
* @since 0.
|
|
883
|
+
* @since 0.3.0
|
|
884
884
|
*/
|
|
885
|
-
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...
|
|
885
|
+
declare function longestMatch<const TParsers extends readonly Parser<Mode, unknown, unknown>[]>(...parsers: TParsers & LongestMatchArityGuard<TParsers>): Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, InferValue<TParsers[number]>, LongestMatchState<TParsers>>;
|
|
886
886
|
/**
|
|
887
887
|
* Options for the {@link object} parser.
|
|
888
888
|
* @since 0.5.0
|
|
@@ -1097,18 +1097,6 @@ type EnsureMergeParsers<TParsers extends MergeParsers> = { readonly [K in keyof
|
|
|
1097
1097
|
type IntersectMergeValues<TParsers extends MergeParsers> = TParsers extends readonly [infer THead extends Parser<Mode, unknown, unknown>, ...infer TRest extends MergeParsers] ? ExtractObjectTypes<THead> & IntersectMergeValues<TRest> : unknown;
|
|
1098
1098
|
type MergeValues<TParsers extends MergeParsers> = IsTuple<TParsers> extends true ? IntersectMergeValues<TParsers> : Record<string | symbol, unknown>;
|
|
1099
1099
|
type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ readonly [K in keyof TParsers]: ExtractMode<TParsers[K]> }>, MergeValues<TParsers>, Record<string | symbol, unknown>>;
|
|
1100
|
-
/**
|
|
1101
|
-
* Merges multiple object-like parsers into one parser.
|
|
1102
|
-
*
|
|
1103
|
-
* This is useful for combining separate object parsers into one
|
|
1104
|
-
* unified parser while keeping fields grouped by parser boundaries.
|
|
1105
|
-
*
|
|
1106
|
-
* @param parsers Parsers to merge in declaration order.
|
|
1107
|
-
* @returns A parser that merges parsed object fields from all parsers.
|
|
1108
|
-
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
1109
|
-
* @since 0.4.0
|
|
1110
|
-
*/
|
|
1111
|
-
declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1112
1100
|
/**
|
|
1113
1101
|
* Merges multiple object-like parsers into one parser, with options.
|
|
1114
1102
|
*
|
|
@@ -1147,6 +1135,18 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
|
|
|
1147
1135
|
* @since 0.7.0
|
|
1148
1136
|
*/
|
|
1149
1137
|
declare function merge<const TParsers extends MergeParsers>(label: string, ...rest: [...parsers: EnsureMergeParsers<TParsers>, options: MergeTailOptions] & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1138
|
+
/**
|
|
1139
|
+
* Merges multiple object-like parsers into one parser.
|
|
1140
|
+
*
|
|
1141
|
+
* This is useful for combining separate object parsers into one
|
|
1142
|
+
* unified parser while keeping fields grouped by parser boundaries.
|
|
1143
|
+
*
|
|
1144
|
+
* @param parsers Parsers to merge in declaration order.
|
|
1145
|
+
* @returns A parser that merges parsed object fields from all parsers.
|
|
1146
|
+
* Type inference is precise for tuple calls up to 15 parser arguments.
|
|
1147
|
+
* @since 0.4.0
|
|
1148
|
+
*/
|
|
1149
|
+
declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMergeParsers<TParsers> & MergeArityGuard<TParsers>): MergeReturnType<TParsers>;
|
|
1150
1150
|
type ConcatParserArity = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15;
|
|
1151
1151
|
type ConcatArityLimitError = {
|
|
1152
1152
|
readonly __optiqueConcatArityLimit: "concat() requires between 1 and 15 parser arguments. Nest concat() to combine more.";
|
|
@@ -1164,8 +1164,28 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
|
|
|
1164
1164
|
*
|
|
1165
1165
|
* @example
|
|
1166
1166
|
* ```typescript
|
|
1167
|
-
*
|
|
1168
|
-
*
|
|
1167
|
+
* import { parse } from "@optique/core/parser";
|
|
1168
|
+
* import { option } from "@optique/core/primitives";
|
|
1169
|
+
* import { integer, string } from "@optique/core/valueparser";
|
|
1170
|
+
*
|
|
1171
|
+
* const basicTuple = tuple([
|
|
1172
|
+
* option("-v", "--verbose"),
|
|
1173
|
+
* option("-p", "--port", integer()),
|
|
1174
|
+
* ]);
|
|
1175
|
+
*
|
|
1176
|
+
* const serverTuple = tuple([
|
|
1177
|
+
* option("-h", "--host", string()),
|
|
1178
|
+
* option("-d", "--debug"),
|
|
1179
|
+
* ]);
|
|
1180
|
+
*
|
|
1181
|
+
* const combined = concat(basicTuple, serverTuple);
|
|
1182
|
+
* // Inferred type: Parser<..., [boolean, number, string, boolean], ...>
|
|
1183
|
+
*
|
|
1184
|
+
* const result = parse(
|
|
1185
|
+
* combined,
|
|
1186
|
+
* ["-v", "-p", "8080", "-h", "localhost", "-d"],
|
|
1187
|
+
* );
|
|
1188
|
+
* // result.value: [true, 8080, "localhost", true]
|
|
1169
1189
|
* ```
|
|
1170
1190
|
*
|
|
1171
1191
|
* @param parsers Tuple parsers to concatenate.
|