Installations
npm install @asamuzakjp/nwsapi
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
22.12.0
NPM Version
10.9.0
Score
77
Supply Chain
99
Quality
92.9
Maintenance
100
Vulnerability
100
License
Contributors
Languages
JavaScript (100%)
Developer
dperini
Download Statistics
Total Downloads
14,414
Last Day
9
Last Week
257
Last Month
2,146
Last Year
14,414
GitHub Statistics
109 Stars
344 Commits
39 Forks
4 Watching
1 Branches
18 Contributors
Package Meta Information
Latest Version
2.2.27
Package Id
@asamuzakjp/nwsapi@2.2.27
Unpacked Size
67.02 kB
Size
17.06 kB
File Count
4
NPM Version
10.9.0
Node Version
22.12.0
Publised On
14 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
14,414
Last day
-86.6%
9
Compared to previous day
Last week
-70.7%
257
Compared to previous week
Last month
-39.1%
2,146
Compared to previous month
Last year
0%
14,414
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
No dependencies detected.
NWSAPI
Fast CSS Selectors API Engine
NWSAPI is the development progress of NWMATCHER aiming at Selectors Level 4 conformance. It has been completely reworked to be easily extended and maintained. It is a right-to-left selector parser and compiler written in pure Javascript with no external dependencies. It was initially thought as a cross browser library to improve event delegation and web page scraping in various frameworks but it has become a popular replacement of the native CSS selection and matching functionality in newer browsers and headless environments.
It uses regular expressions to parse CSS selector strings and metaprogramming to transforms these selector strings into Javascript function resolvers. This process is executed only once for each selector string allowing memoization of the function resolvers and achieving unmatched performances.
Installation
To include NWSAPI in a standard web page:
1<script type="text/javascript" src="nwsapi.js"></script>
To include NWSAPI in a standard web page and automatically replace the native QSA:
1<script type="text/javascript" src="nwsapi.js" onload="NW.Dom.install()"></script>
To use NWSAPI with Node.js:
$ npm install nwsapi
NWSAPI currently supports browsers (as a global, NW.Dom
) and headless environments (as a CommonJS module).
Supported Selectors
Here is a list of all the CSS2/CSS3/CSS4 Supported selectors.
Features and Compliance
You can read more about NWSAPI features and compliance on the wiki.
API
DOM Selection
ancestor( selector, context, callback )
Returns a reference to the nearest ancestor element matching selector
, starting at context
. Returns null
if no element is found. If callback
is provided, it is invoked for the matched element.
first( selector, context, callback )
Returns a reference to the first element matching selector
, starting at context
. Returns null
if no element matches. If callback
is provided, it is invoked for the matched element.
match( selector, element, callback )
Returns true
if element
matches selector
, starting at context
; returns false
otherwise. If callback
is provided, it is invoked for the matched element.
select( selector, context, callback )
Returns an array of all the elements matching selector
, starting at context
; returns empty Array
otherwise. If callback
is provided, it is invoked for each matching element.
DOM Helpers
byId( id, from )
Returns a reference to the first element with ID id
, optionally filtered to descendants of the element from
.
byTag( tag, from )
Returns an array of elements having the specified tag name tag
, optionally filtered to descendants of the element from
.
byClass( class, from )
Returns an array of elements having the specified class name class
, optionally filtered to descendants of the element from
.
Engine Configuration
configure( options )
The following is the list of currently available configuration options, their default values and descriptions, they are boolean flags that can be set to true
or false
:
IDS_DUPES
: true - true to allow using multiple elements having the same id, false to disallowLIVECACHE
: true - true for caching both results and resolvers, false for caching only resolversMIXEDCASE
: true - true to match tag names case insensitive, false to match using case sensitiveLOGERRORS
: true - true to print errors and warnings to the console, false to mute both of them
Examples on extending the basic functionalities
configure( { <configuration-flag>: [ true | false ] } )
Disable logging errors/warnings to console, disallow duplicate ids. Example:
1NW.Dom.configure( { LOGERRORS: false, IDS_DUPES: false } );
NOTE: NW.Dom.configure() without parameters return the current configuration.
registerCombinator( symbol, resolver )
Registers a new symbol and its matching resolver in the combinators table. Example:
1NW.Dom.registerCombinator( '^', 'e.parentElement' );
registerOperator( symbol, resolver )
Registers a new symbol and its matching resolver in the attribute operators table. Example:
1NW.Dom.registerOperator( '!=', { p1: '^', p2: '$', p3: 'false' } );
registerSelector( name, rexp, func )
Registers a new selector, the matching RE and the resolver function, in the selectors table. Example:
1NW.Dom.registerSelector('Controls', /^\:(control)(.*)/i, 2 (function(global) { 3 return function(match, source, mode, callback) { 4 var status = true; 5 source = 'if(/^(button|input|select|textarea)/i.test(e.nodeName)){' + source + '}'; 6 return { 'source': source, 'status': status }; 7 }; 8 })(this));
No vulnerabilities found.
Reason
30 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 4/26 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
binaries present in source code
Details
- Warn: binary detected: bin/cygwin1.dll:1
- Warn: binary detected: bin/js.exe:1
- Warn: binary detected: bin/js_linux:1
- Warn: binary detected: bin/js_macos:1
- Warn: binary detected: bin/jsl.exe:1
- Warn: binary detected: bin/jsl_linux:1
- Warn: binary detected: bin/jsl_macos:1
- Warn: binary detected: bin/jsmin.exe:1
- Warn: binary detected: bin/jsmin_linux:1
- Warn: binary detected: bin/jsmin_macos:1
- Warn: binary detected: test/slick/Runner/JSTestDriver/JSTestDriver.jar:1
- Warn: binary detected: test/slick/Runner/JSTestDriver/plugins/coverage.jar:1
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 8 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More