npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

parse-html-comments

v1.3.1

Published

Get html comments and their details from a string

Downloads

141

Readme

parse-html-comments

Get html-formatted comments and some associated metadata from a string

npm: version CircleCI: build Types included npm dependencies Package Phobia: install size

Installation

npm install parse-html-comments

yarn add parse-html-comments

Include Module

May be imported with ES6 import or Node require syntax.

import parseComments from 'parse-html-comments'
/* or */
const parseComments = require('parse-html-comments')

API

(input: string) => CommentData

Function, accepts a string - the text to be searched - as its only parameter.

Returns CommentData

const parseComments = require('parse-html-comments')

parseComments(/* some string ... */) // => CommentData

setNewline: Function (char: string) => void

Configure the function to use a different delimiter for line splitting and counting.

Default is \n

const parseComments = require('parse-html-comments')

parseComments.setNewline('\r\n')
console.log(parseComments.newline) // => '\r\n'

parseComments(/* some string ... */) // => CommentData

newline (property: string)

Retrieve the newline character that will be used.

Types

CommentData: Object


interface CommentData {
  input: string
  newlineChar: string
  lineCount: number
  charCount: number
  matches: Array<CommentDescriptor>
}

CommentData Properties

  • input : The full JSON-escaped text content passed to the function
  • newlineChar : The newline character used during execution
  • lineCount : Total number of \ns in the input string ( + 1 )
  • charCount : Value of the length property of the input string
  • matches : The match data. See below.

CommentDescriptor: Object


interface CommentDescriptor {
  groups: {
    whole: string
    commentOnly: string
    lines: {
      whole: string[]
      commentOnly: string[]
    }
  }
  column: {
    start: number
    end: number
  }
  line: {
    start: number
    end: number
  }
  inline: null|{
    pre: string|null
    post: string|null
  }
}

CommentDescriptor Properties

  • groups.
    • whole : The entire matched text, including preceding and following non-comment text one the start or end lines (if any).
    • commentOnly : Only the comment text
    • lines
      • whole : The value of groups.whole, split along the newline character into a string array.
      • commentOnly : The value of groups.commentOnly, split along the newline character into a string array.
  • column.
    • start: Inclusive start index of whole match.
  • column.
    • end : Non-inclusive end index of whole match.
  • line.
    • start : Line number the match begins on (1-based)
  • line.
    • end : Line number the match ends on.
  • inline : If no text precedes the comment on the starting line or follows the comment on the end line, this property is null. If one of those conditions are true, then the value is an object with properties:
    • pre Either null, or a string of text corresponding to the pre-comment text.
    • post Either null, or a string of text corresponding to the post-comment text.

Dependencies

None

License

MIT