getImportantPosition.cjs 651 B

123456789101112131415161718192021
  1. // NOTICE: This file is generated by Rollup. To modify it,
  2. // please instead edit the ESM counterpart and rebuild with Rollup (npm run build).
  3. 'use strict';
  4. /**
  5. * Returns a position of `!important` (or `! important` including whitespaces)
  6. * from the specified CSS source code. If not found, returns `undefined`.
  7. *
  8. * @param {string} source
  9. * @returns {{ index: number, endIndex: number } | undefined}
  10. */
  11. function getImportantPosition(source) {
  12. const pattern = /!\s*important\b/gi;
  13. const match = pattern.exec(source);
  14. if (!match) return;
  15. return { index: match.index, endIndex: pattern.lastIndex };
  16. }
  17. module.exports = getImportantPosition;