08-27-周三_17-09-29
This commit is contained in:
11
node_modules/nth-check/LICENSE
generated
vendored
Normal file
11
node_modules/nth-check/LICENSE
generated
vendored
Normal 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
node_modules/nth-check/README.md
generated
vendored
Normal file
51
node_modules/nth-check/README.md
generated
vendored
Normal 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
node_modules/nth-check/compile.js
generated
vendored
Normal file
40
node_modules/nth-check/compile.js
generated
vendored
Normal 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
node_modules/nth-check/index.js
generated
vendored
Normal file
9
node_modules/nth-check/index.js
generated
vendored
Normal 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;
|
95
node_modules/nth-check/package.json
generated
vendored
Normal file
95
node_modules/nth-check/package.json
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "nth-check",
|
||||
"raw": "nth-check@~1.0.1",
|
||||
"rawSpec": "~1.0.1",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.1 <1.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"F:\\tmp\\gitbook\\node_modules\\css-select"
|
||||
]
|
||||
],
|
||||
"_from": "nth-check@>=1.0.1 <1.1.0",
|
||||
"_hasShrinkwrap": false,
|
||||
"_id": "nth-check@1.0.2",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/nth-check",
|
||||
"_nodeVersion": "10.11.0",
|
||||
"_npmOperationalInternal": {
|
||||
"host": "s3://npm-registry-packages",
|
||||
"tmp": "tmp/nth-check_1.0.2_1540159926746_0.4517908661077017"
|
||||
},
|
||||
"_npmUser": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
},
|
||||
"_npmVersion": "6.4.1",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "nth-check",
|
||||
"raw": "nth-check@~1.0.1",
|
||||
"rawSpec": "~1.0.1",
|
||||
"scope": null,
|
||||
"spec": ">=1.0.1 <1.1.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/css-select"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz",
|
||||
"_shasum": "b2bd295c37e3dd58a3bf0700376663ba4d9cf05c",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "nth-check@~1.0.1",
|
||||
"_where": "F:\\tmp\\gitbook\\node_modules\\css-select",
|
||||
"author": {
|
||||
"email": "me@feedic.com",
|
||||
"name": "Felix Boehm"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/fb55/nth-check/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"boolbase": "~1.0.0"
|
||||
},
|
||||
"description": "performant nth-check parser & compiler",
|
||||
"devDependencies": {},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"fileCount": 6,
|
||||
"integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==",
|
||||
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbzPm3CRA9TVsSAnZWagAAhM4P/iS5h2NgtCybL1u9veDR\nECfbFBz60HsEQyqJtx3I2b4+cyQq5QnE71H2Hd4UsTmK/eQRaJO4LxWw5H1m\nX/k5+6Zn/UfsazAZQNKK4F+k2LJ90Fg6OuMJx6RTN18RLO7eqeecYKZHNxog\n8gR08VTytTCU6cK9kJvSv+kVOyYGZhd2LUo/uGonQcuUSvelc1rrHAbI0BrG\ncs1l71Oce33mTVkbnfZX6ffURLjoIp51OgBm+OqlXNEJnr99OG3GMOQAYJ3V\nv5wDLz0lDR6fxn5Q9humrBoIoFEsfIjQP3NzJpiFNCUo/27GrijzIO2H0mwf\n63nkfvNYlec6IQYCyZ3guQSNk6AMreZO97XZxbre6jIjUZD3yU8DxmX6WacH\nKEfOdDSL0P2zfszCgTexa4QLtvrSMpyMg1ZeKaOg68ZFIrtWnlAfQ3dCNNmb\nv9YT0xEpuJJ57Bi7iH9MSCLBYa+js11oxoIxivOw+fveNCna+6W6u9B916sc\ntN0Dvyrk3lS01I4AONu5zBStKtwo7/PYnuvdAz01GVaPEufZ93XSwGMdiTys\n1HNVu95I2c2B41Z4meKpIINF83r+16zu0i/+Vu9ocaPIcuxbl9GuBAf3NpRf\nK88HwaPBZAWPo035nohMs290iFliwlc300L7OsT5DbGIH4KVP4jivBQkbsGC\nbBzx\r\n=f9A8\r\n-----END PGP SIGNATURE-----\r\n",
|
||||
"shasum": "b2bd295c37e3dd58a3bf0700376663ba4d9cf05c",
|
||||
"tarball": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz",
|
||||
"unpackedSize": 5538
|
||||
},
|
||||
"gitHead": "03a02587bbd126fafc3d2331ffef6ea5cb2f9b66",
|
||||
"homepage": "https://github.com/fb55/nth-check",
|
||||
"keywords": [
|
||||
"nth-child",
|
||||
"nth",
|
||||
"css"
|
||||
],
|
||||
"license": "BSD-2-Clause",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "me@feedic.com",
|
||||
"name": "feedic"
|
||||
}
|
||||
],
|
||||
"name": "nth-check",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/fb55/nth-check.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
40
node_modules/nth-check/parse.js
generated
vendored
Normal file
40
node_modules/nth-check/parse.js
generated
vendored
Normal 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
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user