nth-check
Advanced tools
Comparing version 1.0.2 to 2.0.0
{ | ||
"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" | ||
} | ||
"name": "nth-check", | ||
"version": "2.0.0", | ||
"description": "Parses and compiles CSS nth-checks to highly optimized functions.", | ||
"author": "Felix Boehm <me@feedic.com>", | ||
"license": "BSD-2-Clause", | ||
"sideEffects": false, | ||
"funding": { | ||
"url": "https://github.com/fb55/nth-check?sponsor=1" | ||
}, | ||
"directories": { | ||
"lib": "lib/" | ||
}, | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib/**/*" | ||
], | ||
"scripts": { | ||
"test": "jest --coverage && npm run lint", | ||
"coverage": "cat coverage/lcov.info | coveralls", | ||
"lint": "npm run lint:es && npm run lint:prettier", | ||
"lint:es": "eslint .", | ||
"lint:prettier": "npm run prettier -- --check", | ||
"format": "npm run format:es && npm run format:prettier", | ||
"format:es": "npm run lint:es -- --fix", | ||
"format:prettier": "npm run prettier -- --write", | ||
"prettier": "prettier '**/*.{ts,md,json,yml}'", | ||
"build": "tsc", | ||
"prepare": "npm run build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fb55/nth-check" | ||
}, | ||
"keywords": [ | ||
"nth-child", | ||
"nth", | ||
"css" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/fb55/nth-check/issues" | ||
}, | ||
"homepage": "https://github.com/fb55/nth-check", | ||
"dependencies": { | ||
"boolbase": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^26.0.0", | ||
"@types/node": "^14.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.1.0", | ||
"@typescript-eslint/parser": "^4.1.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"jest": "^26.0.1", | ||
"prettier": "^2.1.1", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^4.0.2" | ||
}, | ||
"jest": { | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"prettier": { | ||
"tabWidth": 4 | ||
} | ||
} |
# nth-check [![Build Status](https://travis-ci.org/fb55/nth-check.svg)](https://travis-ci.org/fb55/nth-check) | ||
A performant nth-check parser & compiler. | ||
Parses and compiles CSS nth-checks to highly optimized functions. | ||
@@ -14,3 +14,3 @@ ### About | ||
```js | ||
var nthCheck = require("nth-check"); | ||
import nthCheck, { parse, compile } from "nth-check"; | ||
``` | ||
@@ -20,34 +20,63 @@ | ||
First parses, then compiles the formula. | ||
Parses and compiles a formula to a highly optimized function. Combination of `parse` and `compile`. | ||
##### `nthCheck.parse(formula)` | ||
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 the passed _index_ matches the formula. | ||
Parses the expression, throws a `SyntaxError` if it fails, otherwise returns an array containing two elements. | ||
**Note**: The nth-rule starts counting at `1`, the returned function at `0`. | ||
__Example:__ | ||
**Example:** | ||
```js | ||
nthCheck.parse("2n+3") //[2, 3] | ||
const check = nthCheck("2n+3"); | ||
check(0); // `false` | ||
check(1); // `false` | ||
check(2); // `true` | ||
check(3); // `false` | ||
check(4); // `true` | ||
check(5); // `false` | ||
check(6); // `true` | ||
``` | ||
##### `nthCheck.compile([a, b])` | ||
##### `parse(formula)` | ||
Parses the expression, throws an `Error` if it fails. Otherwise, returns an array containing the integer step size and the integer offset of the nth rule. | ||
**Example:** | ||
```js | ||
parse("2n+3"); // [2, 3] | ||
``` | ||
##### `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:** | ||
__Example:__ | ||
```js | ||
var check = nthCheck.compile([2, 3]); | ||
const check = compile([2, 3]); | ||
check(0) //false | ||
check(1) //false | ||
check(2) //true | ||
check(3) //false | ||
check(4) //true | ||
check(5) //false | ||
check(6) //true | ||
check(0); // `false` | ||
check(1); // `false` | ||
check(2); // `true` | ||
check(3); // `false` | ||
check(4); // `true` | ||
check(5); // `false` | ||
check(6); // `true` | ||
``` | ||
--- | ||
License: BSD | ||
License: BSD-2-Clause | ||
## Security contact information | ||
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). | ||
Tidelift will coordinate the fix and disclosure. | ||
## `nth-check` for enterprise | ||
Available as part of the Tidelift Subscription | ||
The maintainers of `nth-check` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-nth-check?utm_source=npm-nth-check&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12860
12
181
81
10
1
Updatedboolbase@^1.0.0