flow like the river
This commit is contained in:
commit
013fe673f3
42435 changed files with 5764238 additions and 0 deletions
11
BACK_BACK/node_modules/nth-check/LICENSE
generated
vendored
Executable file
11
BACK_BACK/node_modules/nth-check/LICENSE
generated
vendored
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
Copyright (c) Felix Böhm
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
51
BACK_BACK/node_modules/nth-check/README.md
generated
vendored
Executable file
51
BACK_BACK/node_modules/nth-check/README.md
generated
vendored
Executable file
|
|
@ -0,0 +1,51 @@
|
|||
# nth-check [](https://travis-ci.org/fb55/nth-check)
|
||||
|
||||
A performant nth-check parser & compiler.
|
||||
|
||||
### About
|
||||
|
||||
This module can be used to parse & compile nth-checks, as they are found in CSS 3's `nth-child()` and `nth-last-of-type()`.
|
||||
|
||||
`nth-check` focusses on speed, providing optimized functions for different kinds of nth-child formulas, while still following the [spec](http://www.w3.org/TR/css3-selectors/#nth-child-pseudo).
|
||||
|
||||
### API
|
||||
|
||||
```js
|
||||
var nthCheck = require("nth-check");
|
||||
```
|
||||
|
||||
##### `nthCheck(formula)`
|
||||
|
||||
First parses, then compiles the formula.
|
||||
|
||||
##### `nthCheck.parse(formula)`
|
||||
|
||||
Parses the expression, throws a `SyntaxError` if it fails, otherwise returns an array containing two elements.
|
||||
|
||||
__Example:__
|
||||
|
||||
```js
|
||||
nthCheck.parse("2n+3") //[2, 3]
|
||||
```
|
||||
|
||||
##### `nthCheck.compile([a, b])`
|
||||
|
||||
Takes an array with two elements (as returned by `.parse`) and returns a highly optimized function.
|
||||
|
||||
If the formula doesn't match any elements, it returns [`boolbase`](https://github.com/fb55/boolbase)'s `falseFunc`, otherwise, a function accepting an _index_ is returned, which returns whether or not a passed _index_ matches the formula. (Note: The spec starts counting at `1`, the returned function at `0`).
|
||||
|
||||
__Example:__
|
||||
```js
|
||||
var check = nthCheck.compile([2, 3]);
|
||||
|
||||
check(0) //false
|
||||
check(1) //false
|
||||
check(2) //true
|
||||
check(3) //false
|
||||
check(4) //true
|
||||
check(5) //false
|
||||
check(6) //true
|
||||
```
|
||||
|
||||
---
|
||||
License: BSD
|
||||
40
BACK_BACK/node_modules/nth-check/compile.js
generated
vendored
Executable file
40
BACK_BACK/node_modules/nth-check/compile.js
generated
vendored
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
module.exports = compile;
|
||||
|
||||
var BaseFuncs = require("boolbase"),
|
||||
trueFunc = BaseFuncs.trueFunc,
|
||||
falseFunc = BaseFuncs.falseFunc;
|
||||
|
||||
/*
|
||||
returns a function that checks if an elements index matches the given rule
|
||||
highly optimized to return the fastest solution
|
||||
*/
|
||||
function compile(parsed){
|
||||
var a = parsed[0],
|
||||
b = parsed[1] - 1;
|
||||
|
||||
//when b <= 0, a*n won't be possible for any matches when a < 0
|
||||
//besides, the specification says that no element is matched when a and b are 0
|
||||
if(b < 0 && a <= 0) return falseFunc;
|
||||
|
||||
//when a is in the range -1..1, it matches any element (so only b is checked)
|
||||
if(a ===-1) return function(pos){ return pos <= b; };
|
||||
if(a === 0) return function(pos){ return pos === b; };
|
||||
//when b <= 0 and a === 1, they match any element
|
||||
if(a === 1) return b < 0 ? trueFunc : function(pos){ return pos >= b; };
|
||||
|
||||
//when a > 0, modulo can be used to check if there is a match
|
||||
var bMod = b % a;
|
||||
if(bMod < 0) bMod += a;
|
||||
|
||||
if(a > 1){
|
||||
return function(pos){
|
||||
return pos >= b && pos % a === bMod;
|
||||
};
|
||||
}
|
||||
|
||||
a *= -1; //make `a` positive
|
||||
|
||||
return function(pos){
|
||||
return pos <= b && pos % a === bMod;
|
||||
};
|
||||
}
|
||||
9
BACK_BACK/node_modules/nth-check/index.js
generated
vendored
Executable file
9
BACK_BACK/node_modules/nth-check/index.js
generated
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
var parse = require("./parse.js"),
|
||||
compile = require("./compile.js");
|
||||
|
||||
module.exports = function nthCheck(formula){
|
||||
return compile(parse(formula));
|
||||
};
|
||||
|
||||
module.exports.parse = parse;
|
||||
module.exports.compile = compile;
|
||||
32
BACK_BACK/node_modules/nth-check/package.json
generated
vendored
Executable file
32
BACK_BACK/node_modules/nth-check/package.json
generated
vendored
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "nth-check",
|
||||
"version": "1.0.2",
|
||||
"description": "performant nth-check parser & compiler",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/fb55/nth-check"
|
||||
},
|
||||
"files": [
|
||||
"compile.js",
|
||||
"index.js",
|
||||
"parse.js"
|
||||
],
|
||||
"keywords": [
|
||||
"nth-child",
|
||||
"nth",
|
||||
"css"
|
||||
],
|
||||
"author": "Felix Boehm <me@feedic.com>",
|
||||
"license": "BSD-2-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/fb55/nth-check/issues"
|
||||
},
|
||||
"homepage": "https://github.com/fb55/nth-check",
|
||||
"dependencies": {
|
||||
"boolbase": "~1.0.0"
|
||||
}
|
||||
}
|
||||
40
BACK_BACK/node_modules/nth-check/parse.js
generated
vendored
Executable file
40
BACK_BACK/node_modules/nth-check/parse.js
generated
vendored
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue