@optique/core 1.0.10 → 1.0.11-dev.2640
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/primitives.cjs +12 -2
- package/dist/primitives.js +12 -2
- package/dist/suggestion.cjs +3 -1
- package/dist/suggestion.js +3 -1
- package/package.json +1 -1
package/dist/primitives.cjs
CHANGED
|
@@ -570,10 +570,15 @@ function option(...args) {
|
|
|
570
570
|
}
|
|
571
571
|
const invalidOption = context.buffer[0];
|
|
572
572
|
if (options.errors?.noMatch) {
|
|
573
|
+
if (typeof options.errors.noMatch !== "function") return {
|
|
574
|
+
success: false,
|
|
575
|
+
consumed: 0,
|
|
576
|
+
error: options.errors.noMatch
|
|
577
|
+
};
|
|
573
578
|
const candidates = /* @__PURE__ */ new Set();
|
|
574
579
|
for (const name of require_usage.extractOptionNames(context.usage)) candidates.add(name);
|
|
575
580
|
const suggestions = require_suggestion.findSimilar(invalidOption, candidates, require_suggestion.DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
576
|
-
const errorMessage =
|
|
581
|
+
const errorMessage = options.errors.noMatch(invalidOption, suggestions);
|
|
577
582
|
return {
|
|
578
583
|
success: false,
|
|
579
584
|
consumed: 0,
|
|
@@ -854,10 +859,15 @@ function flag(...args) {
|
|
|
854
859
|
}
|
|
855
860
|
const invalidOption = context.buffer[0];
|
|
856
861
|
if (options.errors?.noMatch) {
|
|
862
|
+
if (typeof options.errors.noMatch !== "function") return {
|
|
863
|
+
success: false,
|
|
864
|
+
consumed: 0,
|
|
865
|
+
error: options.errors.noMatch
|
|
866
|
+
};
|
|
857
867
|
const candidates = /* @__PURE__ */ new Set();
|
|
858
868
|
for (const name of require_usage.extractOptionNames(context.usage)) candidates.add(name);
|
|
859
869
|
const suggestions = require_suggestion.findSimilar(invalidOption, candidates, require_suggestion.DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
860
|
-
const errorMessage =
|
|
870
|
+
const errorMessage = options.errors.noMatch(invalidOption, suggestions);
|
|
861
871
|
return {
|
|
862
872
|
success: false,
|
|
863
873
|
consumed: 0,
|
package/dist/primitives.js
CHANGED
|
@@ -570,10 +570,15 @@ function option(...args) {
|
|
|
570
570
|
}
|
|
571
571
|
const invalidOption = context.buffer[0];
|
|
572
572
|
if (options.errors?.noMatch) {
|
|
573
|
+
if (typeof options.errors.noMatch !== "function") return {
|
|
574
|
+
success: false,
|
|
575
|
+
consumed: 0,
|
|
576
|
+
error: options.errors.noMatch
|
|
577
|
+
};
|
|
573
578
|
const candidates = /* @__PURE__ */ new Set();
|
|
574
579
|
for (const name of extractOptionNames(context.usage)) candidates.add(name);
|
|
575
580
|
const suggestions = findSimilar(invalidOption, candidates, DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
576
|
-
const errorMessage =
|
|
581
|
+
const errorMessage = options.errors.noMatch(invalidOption, suggestions);
|
|
577
582
|
return {
|
|
578
583
|
success: false,
|
|
579
584
|
consumed: 0,
|
|
@@ -854,10 +859,15 @@ function flag(...args) {
|
|
|
854
859
|
}
|
|
855
860
|
const invalidOption = context.buffer[0];
|
|
856
861
|
if (options.errors?.noMatch) {
|
|
862
|
+
if (typeof options.errors.noMatch !== "function") return {
|
|
863
|
+
success: false,
|
|
864
|
+
consumed: 0,
|
|
865
|
+
error: options.errors.noMatch
|
|
866
|
+
};
|
|
857
867
|
const candidates = /* @__PURE__ */ new Set();
|
|
858
868
|
for (const name of extractOptionNames(context.usage)) candidates.add(name);
|
|
859
869
|
const suggestions = findSimilar(invalidOption, candidates, DEFAULT_FIND_SIMILAR_OPTIONS);
|
|
860
|
-
const errorMessage =
|
|
870
|
+
const errorMessage = options.errors.noMatch(invalidOption, suggestions);
|
|
861
871
|
return {
|
|
862
872
|
success: false,
|
|
863
873
|
consumed: 0,
|
package/dist/suggestion.cjs
CHANGED
|
@@ -86,8 +86,10 @@ function findSimilar(input, candidates, options = {}) {
|
|
|
86
86
|
const normalizedCandidate = caseSensitive ? candidate : candidate.toLowerCase();
|
|
87
87
|
if (seen.has(candidate)) continue;
|
|
88
88
|
seen.add(candidate);
|
|
89
|
+
if (normalizedInput === normalizedCandidate) return [candidate];
|
|
90
|
+
const minimumDistance = Math.abs(normalizedInput.length - normalizedCandidate.length);
|
|
91
|
+
if (minimumDistance > maxDistance || minimumDistance / input.length > maxDistanceRatio) continue;
|
|
89
92
|
const distance = levenshteinDistance(normalizedInput, normalizedCandidate);
|
|
90
|
-
if (distance === 0) return [candidate];
|
|
91
93
|
const distanceRatio = distance / input.length;
|
|
92
94
|
if (distance <= maxDistance && distanceRatio <= maxDistanceRatio) matches.push({
|
|
93
95
|
candidate,
|
package/dist/suggestion.js
CHANGED
|
@@ -86,8 +86,10 @@ function findSimilar(input, candidates, options = {}) {
|
|
|
86
86
|
const normalizedCandidate = caseSensitive ? candidate : candidate.toLowerCase();
|
|
87
87
|
if (seen.has(candidate)) continue;
|
|
88
88
|
seen.add(candidate);
|
|
89
|
+
if (normalizedInput === normalizedCandidate) return [candidate];
|
|
90
|
+
const minimumDistance = Math.abs(normalizedInput.length - normalizedCandidate.length);
|
|
91
|
+
if (minimumDistance > maxDistance || minimumDistance / input.length > maxDistanceRatio) continue;
|
|
89
92
|
const distance = levenshteinDistance(normalizedInput, normalizedCandidate);
|
|
90
|
-
if (distance === 0) return [candidate];
|
|
91
93
|
const distanceRatio = distance / input.length;
|
|
92
94
|
if (distance <= maxDistance && distanceRatio <= maxDistanceRatio) matches.push({
|
|
93
95
|
candidate,
|