(argConfig, value)
| 719 | * @returns {ParsedValue | undefined} parsed value |
| 720 | */ |
| 721 | const parseValueForArgumentConfig = (argConfig, value) => { |
| 722 | switch (argConfig.type) { |
| 723 | case class="st">"string": |
| 724 | if (typeof value === class="st">"string") { |
| 725 | return value; |
| 726 | } |
| 727 | break; |
| 728 | case class="st">"path": |
| 729 | if (typeof value === class="st">"string") { |
| 730 | return path.resolve(value); |
| 731 | } |
| 732 | break; |
| 733 | case class="st">"number": |
| 734 | if (typeof value === class="st">"number") return value; |
| 735 | if (typeof value === class="st">"string" && DECIMAL_NUMBER_REGEXP.test(value)) { |
| 736 | const n = Number(value); |
| 737 | if (!Number.isNaN(n)) return n; |
| 738 | } |
| 739 | break; |
| 740 | case class="st">"boolean": |
| 741 | if (typeof value === class="st">"boolean") return value; |
| 742 | if (value === class="st">"true") return true; |
| 743 | if (value === class="st">"false") return false; |
| 744 | break; |
| 745 | case class="st">"RegExp": |
| 746 | if (value instanceof RegExp) return value; |
| 747 | if (typeof value === class="st">"string") { |
| 748 | class="cm">// cspell:word yugi |
| 749 | const match = /^\/(.*)\/([yugi]*)$/.exec(value); |
| 750 | if (match && !/[^\\]\class="cm">//.test(match[1])) { |
| 751 | return new RegExp(match[1], match[2]); |
| 752 | } |
| 753 | } |
| 754 | break; |
| 755 | case class="st">"enum": { |
| 756 | const values = |
| 757 | /** @type {EnumValue[]} */ |
| 758 | (argConfig.values); |
| 759 | if (values.includes(/** @type {Exclude<Value, RegExp>} */ (value))) { |
| 760 | return value; |
| 761 | } |
| 762 | for (const item of values) { |
| 763 | if (`${item}` === value) return item; |
| 764 | } |
| 765 | break; |
| 766 | } |
| 767 | case class="st">"reset": |
| 768 | if (value === true) return []; |
| 769 | break; |
| 770 | } |
| 771 | }; |
| 772 | |
| 773 | /** @typedef {Record<string, Value[]>} Values */ |
| 774 |
no test coverage detected