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
optimacms-0.1.61 spec/dummy/node_modules/nth-check/parse.js
disco_app-0.18.0 test/dummy/node_modules/nth-check/parse.js
disco_app-0.18.2 test/dummy/node_modules/nth-check/parse.js
disco_app-0.16.1 test/dummy/node_modules/nth-check/parse.js
disco_app-0.15.2 test/dummy/node_modules/nth-check/parse.js
disco_app-0.18.4 test/dummy/node_modules/nth-check/parse.js
disco_app-0.18.1 test/dummy/node_modules/nth-check/parse.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/nth-check/parse.js
disco_app-0.14.0 test/dummy/node_modules/nth-check/parse.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/nth-check/parse.js
tang-0.2.1 spec/tang_app/node_modules/nth-check/parse.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/nth-check/parse.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/nth-check/parse.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/nth-check/parse.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/nth-check/parse.js
tang-0.2.0 spec/tang_app/node_modules/nth-check/parse.js
tang-0.1.0 spec/tang_app/node_modules/nth-check/parse.js
tang-0.0.9 spec/tang_app/node_modules/nth-check/parse.js
enju_library-0.3.8 spec/dummy/node_modules/nth-check/parse.js
jester-data-8.0.0 node_modules/nth-check/parse.js