securityos/node_modules/stylelint/lib/utils/addEmptyLineBefore.js

24 lines
481 B
JavaScript
Raw Normal View History

2024-09-06 15:32:35 +00:00
'use strict';
/**
* Add an empty line before a node. Mutates the node.
*
* @template {import('postcss').ChildNode} T
* @param {T} node
* @param {string} newline
* @returns {T}
*/
module.exports = function addEmptyLineBefore(node, newline) {
const { raws } = node;
if (typeof raws.before !== 'string') {
return node;
}
raws.before = !/\r?\n/.test(raws.before)
? newline.repeat(2) + raws.before
: raws.before.replace(/(\r?\n)/, `${newline}$1`);
return node;
};