querycomments

1.0.0 • Public • Published

queryComments.js

Node NPM Travis David Coverage Status NPM

A super lightweight fps meter, with near zero overhead

Installation

Yarn

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

Package Sidebar

Install

npm i querycomments

Weekly Downloads

12

Version

1.0.0

License

apache-2

Unpacked Size

31.3 kB

Total Files

10

Last publish

Collaborators

  • vitim