Get html comments and their details from a string
npm install 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
``sh
npm install parse-html-comments
yarn add parse-html-comments
`
May be imported with ES6 import or Node require syntax.
`javascript`
import parseComments from 'parse-html-comments'
/ or /
const parseComments = require('parse-html-comments')
Function, accepts a string - the text to be searched - as its only parameter.
Returns CommentData
`javascript
const parseComments = require('parse-html-comments')
parseComments(/ some string ... /) // => CommentData
`
Configure the function to use a different delimiter for line splitting and counting.
Default is \n
`javascript
const parseComments = require('parse-html-comments')
parseComments.setNewline('\r\n')
console.log(parseComments.newline) // => '\r\n'
parseComments(/ some string ... /) // => CommentData
`
Retrieve the newline character that will be used.
`typescript
interface CommentData {
input: string
newlineChar: string
lineCount: number
charCount: number
matches: Array
}
`
#### 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 )length
- charCount : Value of the property of the input string
- matches : The match data. See below.
`typescript
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 textwhole
- lines
- : 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.start
- column.
- : Inclusive start index of whole match.end
- column.
- : Non-inclusive end index of whole match.start
- line.
- : Line number the match begins on (1-based)end
- line.
- : Line number the match ends on.null
- inline : If no text precedes the comment on the starting line or follows the comment on the end line, this property is . 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.
None