MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / parseUnit

Function parseUnit

packages/core/css/parser.ts:174–185  ·  view source on GitHub ↗
(text: string, start = 0)

Source from the content-addressed store, hash-verified

172
173const unitRegEx = /\s*([+\-]?(?:\d+\.\d+|\d+|\.\d+)(?:[eE][+\-]?\d+)?)([a-zA-Z]+|%)?\s*/gy;
174export 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
187export function parsePercentageOrLength(text: string, start = 0): Parsed<LengthPercentage> {
188 const unitResult = parseUnit(text, start);

Callers 2

parsePercentageOrLengthFunction · 0.85
parseAngleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected