(text: string, start = 0)
| 172 | |
| 173 | const unitRegEx = /\s*([+\-]?(?:\d+\.\d+|\d+|\.\d+)(?:[eE][+\-]?\d+)?)([a-zA-Z]+|%)?\s*/gy; |
| 174 | export function parseUnit(text: string, start = 0): Parsed<Unit<string>> { |
| 175 | unitRegEx.lastIndex = start; |
| 176 | const result = unitRegEx.exec(text); |
| 177 | if (!result) { |
| 178 | return null; |
| 179 | } |
| 180 | const end = unitRegEx.lastIndex; |
| 181 | const value = parseFloat(result[1]); |
| 182 | const unit = <any>result[2] || 'dip'; |
| 183 | |
| 184 | return { start, end, value: { value, unit } }; |
| 185 | } |
| 186 | |
| 187 | export function parsePercentageOrLength(text: string, start = 0): Parsed<LengthPercentage> { |
| 188 | const unitResult = parseUnit(text, start); |
no outgoing calls
no test coverage detected