(sizes, currentLength)
| 289 | * @returns {number[]} The sizes array with wildcard replaced. |
| 290 | */ |
| 291 | export function processSizesWildcard (sizes, currentLength) { |
| 292 | const newLength = product(sizes) |
| 293 | const processedSizes = sizes.slice() |
| 294 | const WILDCARD = -1 |
| 295 | const wildCardIndex = sizes.indexOf(WILDCARD) |
| 296 | |
| 297 | const isMoreThanOneWildcard = sizes.indexOf(WILDCARD, wildCardIndex + 1) >= 0 |
| 298 | if (isMoreThanOneWildcard) { |
| 299 | throw new Error('More than one wildcard in sizes') |
| 300 | } |
| 301 | |
| 302 | const hasWildcard = wildCardIndex >= 0 |
| 303 | const canReplaceWildcard = currentLength % newLength === 0 |
| 304 | |
| 305 | if (hasWildcard) { |
| 306 | if (canReplaceWildcard) { |
| 307 | processedSizes[wildCardIndex] = -currentLength / newLength |
| 308 | } else { |
| 309 | throw new Error('Could not replace wildcard, since ' + currentLength + ' is no multiple of ' + (-newLength)) |
| 310 | } |
| 311 | } |
| 312 | return processedSizes |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * Computes the product of all array elements. |
no test coverage detected
searching dependent graphs…