(opt, key, val)
| 779 | }; |
| 780 | |
| 781 | const validateOptions = async (opt, key, val) => { |
| 782 | let opts = opt.options; |
| 783 | if (typeof opts === 'function') { |
| 784 | try { |
| 785 | const result = await opts(val); |
| 786 | if (!result && result != null) { |
| 787 | throw opt.error || `Validation failed. Invalid value for ${key}.`; |
| 788 | } |
| 789 | } catch (e) { |
| 790 | if (!e) { |
| 791 | throw opt.error || `Validation failed. Invalid value for ${key}.`; |
| 792 | } |
| 793 | |
| 794 | throw opt.error || e.message || e; |
| 795 | } |
| 796 | return; |
| 797 | } |
| 798 | if (!Array.isArray(opts)) { |
| 799 | opts = [opt.options]; |
| 800 | } |
| 801 | |
| 802 | if (!opts.includes(val)) { |
| 803 | throw ( |
| 804 | opt.error || `Validation failed. Invalid option for ${key}. Expected: ${opts.join(', ')}` |
| 805 | ); |
| 806 | } |
| 807 | }; |
| 808 | |
| 809 | const getType = fn => { |
| 810 | const match = fn && fn.toString().match(/^\s*function (\w+)/); |
no outgoing calls
no test coverage detected