blockString.mjs 582 B

12345678910111213141516171819
  1. import beforeBlockString from './beforeBlockString.mjs';
  2. import hasBlock from './hasBlock.mjs';
  3. import rawNodeString from './rawNodeString.mjs';
  4. /**
  5. * Return a CSS statement's block -- the string that starts and `{` and ends with `}`.
  6. *
  7. * If the statement has no block (e.g. `@import url(foo.css);`), returns an empty string.
  8. *
  9. * @param {import('postcss').Container} statement
  10. * @returns {string}
  11. */
  12. export default function blockString(statement) {
  13. if (!hasBlock(statement)) {
  14. return '';
  15. }
  16. return rawNodeString(statement).slice(beforeBlockString(statement).length);
  17. }