1.3.1 • Published 6 years ago
parse-html-comments v1.3.1
parse-html-comments
Get html-formatted comments and some associated metadata from a string
Installation
npm install parse-html-comments
yarn add parse-html-commentsInclude 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 ... */) // => CommentDatasetNewline: 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 ... */) // => CommentDatanewline (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
lengthproperty 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 ofgroups.whole, split along the newline character into a string array.commentOnly: The value ofgroups.commentOnly, split along the newline character into a string array.
- column.
start: Inclusive start index ofwholematch.
- column.
end: Non-inclusive end index ofwholematch.
- 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:preEithernull, or a string of text corresponding to the pre-comment text.postEithernull, or a string of text corresponding to the post-comment text.
Dependencies
None