getImportantPosition.mjs 468 B

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