( options: Exposes | Remotes | Shared | undefined, normalizeSimple: (value: any, key: any) => ConfigTypeSet, normalizeOptions: (value: any, key: any) => ConfigTypeSet )
| 128 | } |
| 129 | |
| 130 | export function parseOptions( |
| 131 | options: Exposes | Remotes | Shared | undefined, |
| 132 | normalizeSimple: (value: any, key: any) => ConfigTypeSet, |
| 133 | normalizeOptions: (value: any, key: any) => ConfigTypeSet |
| 134 | ): (string | ConfigTypeSet)[] { |
| 135 | if (!options) { |
| 136 | return [] |
| 137 | } |
| 138 | const list: { |
| 139 | [index: number]: string | ConfigTypeSet |
| 140 | }[] = [] |
| 141 | const array = (items: (string | ConfigTypeSet)[]) => { |
| 142 | for (const item of items) { |
| 143 | if (typeof item === 'string') { |
| 144 | list.push([item, normalizeSimple(item, item)]) |
| 145 | } else if (item && typeof item === 'object') { |
| 146 | object(item) |
| 147 | } else { |
| 148 | throw new Error('Unexpected options format') |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | const object = (obj) => { |
| 153 | for (const [key, value] of Object.entries(obj)) { |
| 154 | if (typeof value === 'string' || Array.isArray(value)) { |
| 155 | list.push([key, normalizeSimple(value, key)]) |
| 156 | } else { |
| 157 | list.push([key, normalizeOptions(value, key)]) |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | if (Array.isArray(options)) { |
| 162 | array(options) |
| 163 | } else if (typeof options === 'object') { |
| 164 | object(options) |
| 165 | } else { |
| 166 | throw new Error('Unexpected options format') |
| 167 | } |
| 168 | return list |
| 169 | } |
| 170 | |
| 171 | const letterReg = new RegExp('[0-9a-zA-Z]+') |
| 172 |
no test coverage detected
searching dependent graphs…