All files / src/utils general.js

93.75% Statements 15/16
75% Branches 3/4
100% Functions 4/4
92.31% Lines 12/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 343x             3x 142x 142x   142x             399x 142x   142x           132x   10x   3x 3x  
const getTaggedTemplateLiteralContent = require('./tagged-template-literal').getTaggedTemplateLiteralContent
 
/**
 * Based on https://github.com/mapbox/stylelint-processor-markdown
 * @author @davidtheclark
 * @author @sindresorhus
 */
const fixIndentation = (str) => {
  const match = str.match(/^[ \t]*(?=\S|$)/gm)
  match.splice(0, 1)
 
  Iif (!match) {
    return {
      text: str,
      indentColumns: 0,
    }
  }
 
  const indent = Math.min(...match.map((x) => x.length))
  const re = new RegExp(`^[ \\t]{${indent}}`, 'gm')
 
  return {
    text: indent > 0 ? str.replace(re, '') : str,
    indentColumns: indent,
  }
}
 
const getCSS = (node) => `.selector {${fixIndentation(getTaggedTemplateLiteralContent(node)).text}}\n`
 
const getKeyframes = (node) => `@keyframes {${fixIndentation(getTaggedTemplateLiteralContent(node)).text}}\n`
 
exports.getKeyframes = getKeyframes
exports.getCSS = getCSS