Sha256: 2ad3afea904f4721a33100043325a5dc5e24bc355e94eab15126ab04ff571e11

Contents?: true

Size: 839 Bytes

Versions: 45

Compression:

Stored size: 839 Bytes

Contents

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
		];
	}
}

Version data entries

45 entries across 41 versions & 11 rubygems

Version Path
ezii-os-5.2.1 node_modules/nth-check/parse.js
ezii-os-2.0.1 node_modules/nth-check/parse.js
ezii-os-1.1.0 node_modules/nth-check/parse.js
ezii-os-1.0.0 node_modules/nth-check/parse.js
ezii-os-0.0.0.1.0 node_modules/nth-check/parse.js
ezii-os-0.0.0.0.1 node_modules/nth-check/parse.js
locomotivecms-4.0.0.alpha1 app/javascript/node_modules/nth-check/parse.js
locomotivecms-3.4.0 app/javascript/node_modules/nth-check/parse.js
lanes-0.8.0 node_modules/nth-check/parse.js
tck-lambdas-0.3.10 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.9 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.8 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.7 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.6 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.5 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.4 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.3 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.2 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.1 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js
tck-lambdas-0.3.0 lib/tck/lambdas/chistacojs/source/node_modules/cheerio/node_modules/css-select/node_modules/nth-check/parse.js