mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 09:47:56 +08:00
These packages will be used to dynamically optimize SVG images during the build. R=jacktfranklin@chromium.org Bug: 1216402 Change-Id: I04e95aa7d79c9d67beaf8a7861182c52b16b7d0f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2939992 Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
"use strict";
|
|
// Following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.parse = void 0;
|
|
// [ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
|
|
var RE_NTH_ELEMENT = /^([+-]?\d*n)?\s*(?:([+-]?)\s*(\d+))?$/;
|
|
/**
|
|
* Parses an expression.
|
|
*
|
|
* @throws An `Error` if parsing fails.
|
|
* @returns An array containing the integer step size and the integer offset of the nth rule.
|
|
* @example nthCheck.parse("2n+3"); // returns [2, 3]
|
|
*/
|
|
function parse(formula) {
|
|
formula = formula.trim().toLowerCase();
|
|
if (formula === "even") {
|
|
return [2, 0];
|
|
}
|
|
else if (formula === "odd") {
|
|
return [2, 1];
|
|
}
|
|
var parsed = formula.match(RE_NTH_ELEMENT);
|
|
if (!parsed) {
|
|
throw new Error("n-th rule couldn't be parsed ('" + formula + "')");
|
|
}
|
|
var a;
|
|
if (parsed[1]) {
|
|
a = parseInt(parsed[1], 10);
|
|
if (isNaN(a)) {
|
|
a = parsed[1].startsWith("-") ? -1 : 1;
|
|
}
|
|
}
|
|
else
|
|
a = 0;
|
|
var b = (parsed[2] === "-" ? -1 : 1) *
|
|
(parsed[3] ? parseInt(parsed[3], 10) : 0);
|
|
return [a, b];
|
|
}
|
|
exports.parse = parse;
|