(width, options = {})
| 1 | const unitRegex = /[\d.,]*(\D*)$/ |
| 2 | |
| 3 | export default function widthParser(width, options = {}) { |
| 4 | const { parseFloatToInt = true } = options |
| 5 | |
| 6 | const widthUnit = unitRegex.exec(width.toString())[1] |
| 7 | const unitParsers = { |
| 8 | default: parseInt, |
| 9 | px: parseInt, |
| 10 | '%': parseFloatToInt ? parseInt : parseFloat, |
| 11 | } |
| 12 | const parser = unitParsers[widthUnit] || unitParsers.default |
| 13 | |
| 14 | return { |
| 15 | parsedWidth: parser(width), |
| 16 | unit: widthUnit || 'px', |
| 17 | } |
| 18 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…