source: node_modules/yaml/dist/stringify/stringifyComment.js

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

Initial commit

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