blockString.js 603 B

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