getImportantPosition.js 486 B

1234567891011121314151617
  1. 'use strict';
  2. /**
  3. * Returns a position of `!important` (or `! important` including whitespaces)
  4. * from the specified CSS source code. If not found, returns `undefined`.
  5. *
  6. * @param {string} source
  7. * @returns {{ index: number, endIndex: number } | undefined}
  8. */
  9. module.exports = function getImportantPosition(source) {
  10. const pattern = /!\s*important\b/gi;
  11. const match = pattern.exec(source);
  12. if (!match) return;
  13. return { index: match.index, endIndex: pattern.lastIndex };
  14. };