source: node_modules/yaml/browser/dist/stringify/stringifyComment.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 724 bytes
Line 
1/**
2 * Stringifies a comment.
3 *
4 * Empty comment lines are left empty,
5 * lines consisting of a single space are replaced by `#`,
6 * and all other lines are prefixed with a `#`.
7 */
8const stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, '#');
9function indentComment(comment, indent) {
10 if (/^\n+$/.test(comment))
11 return comment.substring(1);
12 return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;
13}
14const lineComment = (str, indent, comment) => str.endsWith('\n')
15 ? indentComment(comment, indent)
16 : comment.includes('\n')
17 ? '\n' + indentComment(comment, indent)
18 : (str.endsWith(' ') ? '' : ' ') + comment;
19
20export { indentComment, lineComment, stringifyComment };
Note: See TracBrowser for help on using the repository browser.