mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-22 16:24:48 -06:00
fa9ae9437c
The gitbook install has been incredibly flaky due to it's dependency on npm. This commit simply vendors the node_modules so that each time we build the site the process doesn't have to re-run gitbook install. Signed-off-by: Torin Sandall <torinsandall@gmail.com>
41 lines
839 B
JavaScript
41 lines
839 B
JavaScript
module.exports = parse;
|
|
|
|
//following http://www.w3.org/TR/css3-selectors/#nth-child-pseudo
|
|
|
|
//[ ['-'|'+']? INTEGER? {N} [ S* ['-'|'+'] S* INTEGER ]?
|
|
var re_nthElement = /^([+\-]?\d*n)?\s*(?:([+\-]?)\s*(\d+))?$/;
|
|
|
|
/*
|
|
parses a nth-check formula, returns an array of two numbers
|
|
*/
|
|
function parse(formula){
|
|
formula = formula.trim().toLowerCase();
|
|
|
|
if(formula === "even"){
|
|
return [2, 0];
|
|
} else if(formula === "odd"){
|
|
return [2, 1];
|
|
} else {
|
|
var parsed = formula.match(re_nthElement);
|
|
|
|
if(!parsed){
|
|
throw new SyntaxError("n-th rule couldn't be parsed ('" + formula + "')");
|
|
}
|
|
|
|
var a;
|
|
|
|
if(parsed[1]){
|
|
a = parseInt(parsed[1], 10);
|
|
if(isNaN(a)){
|
|
if(parsed[1].charAt(0) === "-") a = -1;
|
|
else a = 1;
|
|
}
|
|
} else a = 0;
|
|
|
|
return [
|
|
a,
|
|
parsed[3] ? parseInt((parsed[2] || "") + parsed[3], 10) : 0
|
|
];
|
|
}
|
|
}
|