Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/victornpb/querycomments
querySelector like but for selecting HTML Comments like any other DOM Node
https://github.com/victornpb/querycomments
dom-node getcomments javascript javascript-library npm-package regex-pattern selector-engine
Last synced: 16 days ago
JSON representation
querySelector like but for selecting HTML Comments like any other DOM Node
- Host: GitHub
- URL: https://github.com/victornpb/querycomments
- Owner: victornpb
- License: apache-2.0
- Created: 2017-07-07T00:58:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-07-24T18:09:15.000Z (4 months ago)
- Last Synced: 2024-10-07T01:40:59.382Z (about 1 month ago)
- Topics: dom-node, getcomments, javascript, javascript-library, npm-package, regex-pattern, selector-engine
- Language: JavaScript
- Homepage:
- Size: 200 KB
- Stars: 3
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# queryComments.js
![Node](https://img.shields.io/node/v/querycomments.svg?style=flat-square)
[![NPM](https://img.shields.io/npm/v/querycomments.svg?style=flat-square)](https://www.npmjs.com/package/querycomments)
[![NPM](https://img.shields.io/npm/dt/querycomments.svg?style=flat-square)](https://www.npmjs.com/package/querycomments)Select HTML Comments like any other DOM Node, with this fast comment selector implementation.
## Installation
[Yarn](https://github.com/yarnpkg/yarn)
yarn add querycomments
NPM
npm install querycomments
If you don't use a package manager, you can [access `querycomments` via unpkg (CDN)](https://unpkg.com/querycomments/), download the source, or point your package manager to the url.
```html
```
JSFiddle Example [DEMO](https://jsfiddle.net/Victornpb/630garm8/)
## API
```ts
getComments(context:DOMNode, filter:function|RegExp):Array
```## Examples
get all comments
```js
getComments();
```get all comments inside a element
```js
getComments(document.getElementById('someDiv'));
```get the first comment that match a regex pattern
```js
getComments(document, /hey/i);
```get the first comment is filtered by a function
```js
getComments(document, (text, comment) => {
this.breakOnFirst = true; //I only need the first comment
return text.substring(0, 4) === 'Lorem'; //does it starts with "Lorem"
});
```get All comments that match a regex pattern
```js
getComments(document, /foo/g); // notice the global flag on the regex
```get all comments filtered by a function
```js
getComments(document, (text, comment) => {
const possibleValues = ['foo', 'bar', 'baz'];for (var i = 0; i < possibleValues.length; i++) {
if (text.indexOf(possibleValues[i]) > -1) return true;
}
return false;
});
```## Suggestions / Questions
File a [issue](https://github.com/victornpb/getComments.js/issues) on this repository