Code Monkey home page Code Monkey logo

nth-check's Introduction

nth-check Build Status

Parses and compiles CSS nth-checks to highly optimized functions.

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(). It can be used to check if a given index matches a given nth-rule, or to generate a sequence of indices matching a given nth-rule.

nth-check focusses on speed, providing optimized functions for different kinds of nth-child formulas, while still following the spec.

API

import nthCheck, { parse, compile } from "nth-check";
nthCheck(formula)

Parses and compiles a formula to a highly optimized function. Combination of parse and compile.

If the formula doesn't match any elements, it returns boolbase's falseFunc. Otherwise, a function accepting an index is returned, which returns whether or not the passed index matches the formula.

Note: The nth-rule starts counting at 1, the returned function at 0.

Example:

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`
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:

parse("2n+3"); // [2, 3]
compile([a, b])

Takes an array with two elements (as returned by .parse) and returns a highly optimized function.

Example:

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`
generate([a, b])

Returns a function that produces a monotonously increasing sequence of indices.

If the sequence has an end, the returned function will return null after the last index in the sequence.

Example: An always increasing sequence

const gen = nthCheck.generate([2, 3]);

gen(); // `1`
gen(); // `3`
gen(); // `5`
gen(); // `8`
gen(); // `11`

Example: With an end value

const gen = nthCheck.generate([-2, 5]);

gen(); // 0
gen(); // 2
gen(); // 4
gen(); // null
sequence(formula)

Parses and compiles a formula to a generator that produces a sequence of indices. Combination of parse and generate.

Example: An always increasing sequence

const gen = nthCheck.sequence("2n+3");

gen(); // `1`
gen(); // `3`
gen(); // `5`
gen(); // `8`
gen(); // `11`

Example: With an end value

const gen = nthCheck.sequence("-2n+5");

gen(); // 0
gen(); // 2
gen(); // 4
gen(); // null

License: BSD-2-Clause

Security contact information

To report a security vulnerability, please use the Tidelift security contact. 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.

nth-check's People

Contributors

dependabot[bot] avatar fb55 avatar greenkeeperio-bot avatar maennchen avatar nageshlop avatar phated avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nth-check's Issues

License file missing in npm package

Hello, is is possible to incorporate the LICENSE file inside the npm package. Now it's missing. It's implied by MIT license that if licensed under the MIT the source code must be accompanied by full license text. If the license file is not in the npm package a lot of people cannot use it.

Thank you

Inefficient Regular Expression Complexity in nth-check - https://github.com/advisories/GHSA-rp65-9cf3-cjxr

npm audit report

nth-check <2.0.1
Severity: high
Inefficient Regular Expression Complexity in nth-check - GHSA-rp65-9cf3-cjxr
fix available via npm audit fix --force
Will install [email protected], which is a breaking change
node_modules/svgo/node_modules/nth-check
css-select <=3.1.0
Depends on vulnerable versions of nth-check
node_modules/svgo/node_modules/css-select
svgo 1.0.0 - 1.3.2
Depends on vulnerable versions of css-select
node_modules/svgo
@svgr/plugin-svgo <=5.5.0
Depends on vulnerable versions of svgo
node_modules/@svgr/plugin-svgo
@svgr/webpack 4.0.0 - 5.5.0
Depends on vulnerable versions of @svgr/plugin-svgo
node_modules/@svgr/webpack
react-scripts >=2.1.4
Depends on vulnerable versions of @svgr/webpack
node_modules/react-scripts

6 high severity vulnerabilities
nth-check issue

How to fix these vulnerabilities ? I am using the below dependencies

"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/free-regular-svg-icons": "^6.2.1",
"@fortawesome/free-solid-svg-icons": "^6.2.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@reduxjs/toolkit": "^1.9.1",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.27.2",
"base-64": "^1.0.0",
"bootstrap": "^5.2.1",
"canada": "^0.1.0",
"clientjs": "^0.2.1",
"encode-utf8": "^2.0.0",
"env-cmd": "^10.1.0",
"formik": "^2.2.9",
"i18next": "^22.4.6",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"papaparse": "^5.3.2",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-bootstrap": "^2.5.0",
"react-datepicker": "^4.11.0",
"react-datetime-picker": "^5.0.3",
"react-dom": "^18.2.0",
"react-i18next": "^12.1.1",
"react-modal": "^3.16.1",
"react-paginate": "^8.1.4",
"react-redux": "^8.0.5",
"react-router-dom": "^6.3.0",
"react-scripts": "^5.0.1",
"react-search-autocomplete": "^8.3.1",
"react-switch": "^7.0.0",
"reactstrap": "^9.1.5",
"redux": "^4.2.0",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"redux-thunk": "^2.4.1",
"styled-components": "^5.3.6",
"utf8": "^3.0.0",
"web-vitals": "^2.1.4",
"webfontloader": "^1.6.28",
"yup": "^0.32.11"
},

Upgrade to react-scripts 5.0.0 and react 17.0.2

I'm trying to upgrade react on my app and I'm getting this warning from npm:
nth-check <2.0.1
Severity: moderate
Inefficient Regular Expression Complexity in nth-check - GHSA-rp65-9cf3-cjxr
fix available via npm audit fix --force
Will install [email protected], which is a breaking change
node_modules/svgo/node_modules/nth-check
css-select <=3.1.0
Depends on vulnerable versions of nth-check
node_modules/svgo/node_modules/css-select
svgo 1.0.0 - 1.3.2
Depends on vulnerable versions of css-select
node_modules/svgo
@svgr/plugin-svgo <=5.5.0
Depends on vulnerable versions of svgo
node_modules/@svgr/plugin-svgo
@svgr/webpack 4.0.0 - 5.5.0
Depends on vulnerable versions of @svgr/plugin-svgo
node_modules/@svgr/webpack
react-scripts >=2.1.4
Depends on vulnerable versions of @svgr/webpack
Depends on vulnerable versions of resolve-url-loader
node_modules/react-scripts

Any solutions would be greatly appreciated!

Trying to get in touch regarding a security issue

Hey there!

I'd like to report a security issue but cannot find contact instructions on your repository.

If not a hassle, might you kindly add a SECURITY.md file with an email, or another contact method? GitHub recommends this best practice to ensure security issues are responsibly disclosed, and it would serve as a simple instruction for security researchers in the future.

Thank you for your consideration, and I look forward to hearing from you!

(cc @huntr-helper)

getting issue with nth check while doing an npm audit can some anybudday help me with solving this issue

nth-check <2.0.1
Severity: high
Inefficient Regular Expression Complexity in nth-check - github repo
fix available via npm audit fix --force
Will install [email protected], which is a breaking change
node_modules/svgo/node_modules/nth-check
css-select <=3.1.0
Depends on vulnerable versions of nth-check
node_modules/svgo/node_modules/css-select
svgo 1.0.0 - 1.3.2
Depends on vulnerable versions of css-select
node_modules/svgo
@svgr/plugin-svgo <=5.5.0
Depends on vulnerable versions of svgo
node_modules/@svgr/plugin-svgo
@svgr/webpack 4.0.0 - 5.5.0
Depends on vulnerable versions of @svgr/plugin-svgo
node_modules/@svgr/webpack
react-scripts >=2.1.4
Depends on vulnerable versions of @svgr/webpack
node_modules/react-scripts

found 1 high severity vulnerability

=== npm audit security report ===

                             Manual Review                                  
         Some vulnerabilities require your attention to resolve             
                                                                            
      Visit https://go.npm.me/audit-guide for additional guidance           

High Inefficient Regular Expression Complexity in nth-check

Package nth-check

Patched in >=2.0.1

Dependency of react-scripts

Path react-scripts > @svgr/webpack > @svgr/plugin-svgo > svgo >
css-select > nth-check

More info GHSA-rp65-9cf3-cjxr

Experiencing security issue with nth-check

This is what I'm receiving and I tried updating nth-check.

nth-check  <2.0.1
Severity: high
Inefficient Regular Expression Complexity in nth-check - https://github.com/advisories/GHSA-rp65-9cf3-cjxr
fix available via `npm audit fix --force`
Will install [email protected], which is a breaking change
node_modules/svgo/node_modules/nth-check
  css-select  <=3.1.0
  Depends on vulnerable versions of nth-check
  node_modules/svgo/node_modules/css-select
    svgo  1.0.0 - 1.3.2
    Depends on vulnerable versions of css-select
    node_modules/svgo
      @svgr/plugin-svgo  <=5.5.0
      Depends on vulnerable versions of svgo
      node_modules/@svgr/plugin-svgo
        @svgr/webpack  4.0.0 - 5.5.0
        Depends on vulnerable versions of @svgr/plugin-svgo
        node_modules/@svgr/webpack
          react-scripts  >=2.1.4
          Depends on vulnerable versions of @svgr/webpack
          node_modules/react-scripts

6 high severity vulnerabilities

I'm wondering if this is an issue or if I'm handling it incorrectly. I also tried
( npm audit fix --force)

SyntaxError: Named export 'falseFunc' not found.

nth-check is a dependency of cheerio. I just updated all my packages and now I'm receiving the below error:

file:///path/to/my-module/node_modules/nth-check/lib/esm/compile.js:1
import { trueFunc, falseFunc } from "boolbase";
                   ^^^^^^^^^
SyntaxError: Named export 'falseFunc' not found. The requested module 'boolbase' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'boolbase';
const { trueFunc, falseFunc } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:127:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:191:5)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Error: Can't resolve './https://raw.githubusercontent.com/fb55/nth-check/639fd2a4000b69f82350aad8c34cb43f77e483ba/src//index.ts'

I have a Karma test suite that seems to be running into this error:

(Emitted value instead of an instance of Error) Cannot find source file 'https://raw.githubusercontent.com/fb55/nth-check/639fd2a4000b69f82350aad8c34cb43f77e483ba/src//compile.ts': Error: Can't resolve './https://raw.githubusercontent.com/fb55/nth-check/639fd2a4000b69f82350aad8c34cb43f77e483ba/src//compile.ts' in '/home/runner/work/Titan/Titan/node_modules/nth-check/lib/esm'
 @ /home/runner/work/Titan/Titan/node_modules/nth-check/lib/esm/index.js 2:0-49 3:0-36 3:0-36 28:9-16 61:9-17
 @ /home/runner/work/Titan/Titan/node_modules/css-select/lib/pseudo-selectors/filters.js
 @ /home/runner/work/Titan/Titan/node_modules/css-select/lib/pseudo-selectors/index.js
 @ /home/runner/work/Titan/Titan/node_modules/css-select/lib/index.js
 @ /home/runner/work/Titan/Titan/node_modules/cheerio-select/lib/index.js
 @ /home/runner/work/Titan/Titan/node_modules/cheerio/lib/static.js
 @ /home/runner/work/Titan/Titan/node_modules/cheerio/lib/index.js
 @ /home/runner/work/Titan/Titan/node_modules/enzyme/build/Utils.js
 @ /home/runner/work/Titan/Titan/node_modules/enzyme/build/ShallowWrapper.js
 @ /home/runner/work/Titan/Titan/node_modules/enzyme/build/index.js
 @ ./src/components/AddRemoveList/AddRemoveList_spec.js
 @ ./src sync _spec\.js$
 @ ./src/karma-config/spec_bundle.js

Does this ring any bells to the nth-check devs? Thanks!

Getting ERR_MODULE_NOT_FOUND error with latest nth-check version 2.1.0 when using ESM

Getting the following error with latest nth-check 2.1.0 when running with ESM and Node v14.13.3...

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'test\node_modules\nth-check\lib\esm\parse' imported from test\node_modules\nth-check\lib\esm\index.js
    at new NodeError (internal/errors.js:322:7)←[39m
    at finalizeResolution (internal/modules/esm/resolve.js:318:11)←[39m
    at moduleResolve (internal/modules/esm/resolve.js:776:10)←[39m
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11)←[39m
    at Loader.resolve (internal/modules/esm/loader.js:89:40)←[39m
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)←[39m
    at ModuleWrap.<anonymous> (internal/modules/esm/module_job.js:76:40)←[39m
    at link (internal/modules/esm/module_job.js:75:36)←[39m {
  code: 'ERR_MODULE_NOT_FOUND'
}

For my case nth-check is a dependency brought in via cheerio ^1.0.0-rc.10

Current contents of node_modules\nth-check\lib\esm\index.js in version 2.1.0...

import { parse } from "./parse";
import { compile, generate } from "./compile";
export { parse, compile, generate };

Don't parse and compile imports need to explicitly specify the .js extension to work under ESM? (correct me if wrong)

Previous contents of node_modules\nth-check\lib\index.js in version 2.0.1...

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compile = exports.parse = void 0;
var parse_1 = require("./parse");
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
var compile_1 = require("./compile");
Object.defineProperty(exports, "compile", { enumerable: true, get: function () { return compile_1.compile; } });

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.