querycomments
v1.0.0
Published
A querycomments library
Downloads
23
Maintainers
Readme
queryComments.js
A super lightweight fps meter, with near zero overhead
Installation
yarn add querycomments
NPM
npm install querycomments
If you don't use a package manager, you can access querycomments
via unpkg (CDN), download the source, or point your package manager to the url.
Select HTML Comments like any other DOM Node, with this fast comment selector implementation.
<!-- This is a comment -->
JSFiddle Example DEMO
API
getComments(context:DOMNode, filter:function|RegExp):Array
Examples
get all comments
getComments();
get all comments inside a element
getComments(document.getElementById('someDiv'));
get the first comment that match a regex pattern
getComments(document, /hey/i);
get the first comment is filtered by a function
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
getComments(document, /foo/g); // notice the global flag on the regex
get all comments filtered by a function
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 on this repository