@optique/core 1.0.0-dev.511 → 1.0.0-dev.515

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.
@@ -838,6 +838,9 @@ type LongestMatchArityGuard<TParsers extends readonly unknown[]> = IsTuple<TPars
838
838
  * Creates a parser that selects the successful branch that consumed
839
839
  * the most input tokens.
840
840
  *
841
+ * The resulting parser tries every given parser and returns the
842
+ * successful result that consumed more input than the others.
843
+ *
841
844
  * @param parsers Parsers to evaluate and compare by consumed input.
842
845
  * @returns A parser that yields the best successful branch result.
843
846
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -848,6 +851,9 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
848
851
  * Creates a parser that selects the successful branch that consumed
849
852
  * the most input tokens.
850
853
  *
854
+ * The resulting parser tries every given parser and returns the
855
+ * successful result that consumed more input than the others.
856
+ *
851
857
  * @param parsers Parsers to evaluate and compare by consumed input.
852
858
  * @returns A parser that yields the best successful branch result.
853
859
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -858,6 +864,9 @@ declare function longestMatch<const TParsers extends readonly Parser<Mode, unkno
858
864
  * Creates a parser that selects the successful branch that consumed
859
865
  * the most input tokens, with custom error options.
860
866
  *
867
+ * The resulting parser tries every given parser and returns the
868
+ * successful result that consumed more input than the others.
869
+ *
861
870
  * @param rest Parsers to compare, followed by error customization options.
862
871
  * @returns A parser that yields the best successful branch result.
863
872
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1091,6 +1100,9 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1091
1100
  /**
1092
1101
  * Merges multiple object-like parsers into one parser.
1093
1102
  *
1103
+ * This is useful for combining separate object parsers into one
1104
+ * unified parser while keeping fields grouped by parser boundaries.
1105
+ *
1094
1106
  * @param parsers Parsers to merge in declaration order.
1095
1107
  * @returns A parser that merges parsed object fields from all parsers.
1096
1108
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1100,6 +1112,9 @@ declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMe
1100
1112
  /**
1101
1113
  * Merges multiple object-like parsers into one parser, with options.
1102
1114
  *
1115
+ * This is useful for combining separate object parsers into one
1116
+ * unified parser while keeping fields grouped by parser boundaries.
1117
+ *
1103
1118
  * @param rest Parsers to merge, followed by merge options.
1104
1119
  * @returns A parser that merges parsed object fields from all parsers.
1105
1120
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1109,6 +1124,9 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1109
1124
  /**
1110
1125
  * Merges multiple object-like parsers into one labeled parser.
1111
1126
  *
1127
+ * This is useful for combining separate object parsers into one
1128
+ * unified parser while keeping fields grouped by parser boundaries.
1129
+ *
1112
1130
  * @param label Label used in documentation output.
1113
1131
  * @param parsers Parsers to merge in declaration order.
1114
1132
  * @returns A parser that merges parsed object fields from all parsers.
@@ -1119,6 +1137,9 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1119
1137
  /**
1120
1138
  * Merges multiple object-like parsers into one labeled parser, with options.
1121
1139
  *
1140
+ * This is useful for combining separate object parsers into one
1141
+ * unified parser while keeping fields grouped by parser boundaries.
1142
+ *
1122
1143
  * @param label Label used in documentation output.
1123
1144
  * @param rest Parsers to merge, followed by merge options.
1124
1145
  * @returns A parser that merges parsed object fields from all parsers.
@@ -1138,6 +1159,35 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1138
1159
  /**
1139
1160
  * Concatenates tuple parsers into one parser with a flattened tuple value.
1140
1161
  *
1162
+ * Unlike {@link merge}, which combines object fields, this combines tuple
1163
+ * entries in order into one flattened tuple value.
1164
+ *
1165
+ * @example
1166
+ * ```typescript
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]
1189
+ * ```
1190
+ *
1141
1191
  * @param parsers Tuple parsers to concatenate.
1142
1192
  * @returns A parser with flattened tuple values from all parsers.
1143
1193
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -838,6 +838,9 @@ type LongestMatchArityGuard<TParsers extends readonly unknown[]> = IsTuple<TPars
838
838
  * Creates a parser that selects the successful branch that consumed
839
839
  * the most input tokens.
840
840
  *
841
+ * The resulting parser tries every given parser and returns the
842
+ * successful result that consumed more input than the others.
843
+ *
841
844
  * @param parsers Parsers to evaluate and compare by consumed input.
842
845
  * @returns A parser that yields the best successful branch result.
843
846
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -848,6 +851,9 @@ declare function longestMatch<const TParsers extends readonly Parser<"sync", unk
848
851
  * Creates a parser that selects the successful branch that consumed
849
852
  * the most input tokens.
850
853
  *
854
+ * The resulting parser tries every given parser and returns the
855
+ * successful result that consumed more input than the others.
856
+ *
851
857
  * @param parsers Parsers to evaluate and compare by consumed input.
852
858
  * @returns A parser that yields the best successful branch result.
853
859
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -858,6 +864,9 @@ declare function longestMatch<const TParsers extends readonly Parser<Mode, unkno
858
864
  * Creates a parser that selects the successful branch that consumed
859
865
  * the most input tokens, with custom error options.
860
866
  *
867
+ * The resulting parser tries every given parser and returns the
868
+ * successful result that consumed more input than the others.
869
+ *
861
870
  * @param rest Parsers to compare, followed by error customization options.
862
871
  * @returns A parser that yields the best successful branch result.
863
872
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1091,6 +1100,9 @@ type MergeReturnType<TParsers extends MergeParsers> = Parser<CombineModes<{ read
1091
1100
  /**
1092
1101
  * Merges multiple object-like parsers into one parser.
1093
1102
  *
1103
+ * This is useful for combining separate object parsers into one
1104
+ * unified parser while keeping fields grouped by parser boundaries.
1105
+ *
1094
1106
  * @param parsers Parsers to merge in declaration order.
1095
1107
  * @returns A parser that merges parsed object fields from all parsers.
1096
1108
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1100,6 +1112,9 @@ declare function merge<const TParsers extends MergeParsers>(...parsers: EnsureMe
1100
1112
  /**
1101
1113
  * Merges multiple object-like parsers into one parser, with options.
1102
1114
  *
1115
+ * This is useful for combining separate object parsers into one
1116
+ * unified parser while keeping fields grouped by parser boundaries.
1117
+ *
1103
1118
  * @param rest Parsers to merge, followed by merge options.
1104
1119
  * @returns A parser that merges parsed object fields from all parsers.
1105
1120
  * Type inference is precise for tuple calls up to 15 parser arguments.
@@ -1109,6 +1124,9 @@ declare function merge<const TParsers extends MergeParsers>(...rest: [...parsers
1109
1124
  /**
1110
1125
  * Merges multiple object-like parsers into one labeled parser.
1111
1126
  *
1127
+ * This is useful for combining separate object parsers into one
1128
+ * unified parser while keeping fields grouped by parser boundaries.
1129
+ *
1112
1130
  * @param label Label used in documentation output.
1113
1131
  * @param parsers Parsers to merge in declaration order.
1114
1132
  * @returns A parser that merges parsed object fields from all parsers.
@@ -1119,6 +1137,9 @@ declare function merge<const TParsers extends MergeParsers>(label: string, ...pa
1119
1137
  /**
1120
1138
  * Merges multiple object-like parsers into one labeled parser, with options.
1121
1139
  *
1140
+ * This is useful for combining separate object parsers into one
1141
+ * unified parser while keeping fields grouped by parser boundaries.
1142
+ *
1122
1143
  * @param label Label used in documentation output.
1123
1144
  * @param rest Parsers to merge, followed by merge options.
1124
1145
  * @returns A parser that merges parsed object fields from all parsers.
@@ -1138,6 +1159,35 @@ type ConcatValues<TParsers extends ConcatParsers> = IsTuple<TParsers> extends tr
1138
1159
  /**
1139
1160
  * Concatenates tuple parsers into one parser with a flattened tuple value.
1140
1161
  *
1162
+ * Unlike {@link merge}, which combines object fields, this combines tuple
1163
+ * entries in order into one flattened tuple value.
1164
+ *
1165
+ * @example
1166
+ * ```typescript
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]
1189
+ * ```
1190
+ *
1141
1191
  * @param parsers Tuple parsers to concatenate.
1142
1192
  * @returns A parser with flattened tuple values from all parsers.
1143
1193
  * Type inference is precise for tuple calls up to 15 parser arguments.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.511+2a5e3e40",
3
+ "version": "1.0.0-dev.515+abdd200c",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",