declarationValueIndex.js 795 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. /**
  3. * Get the index of a declaration's value
  4. *
  5. * @param {import('postcss').Declaration} decl
  6. * @returns {number}
  7. */
  8. module.exports = function declarationValueIndex(decl) {
  9. const raws = decl.raws;
  10. return [
  11. // @ts-expect-error -- TS2571: Object is of type 'unknown'.
  12. raws.prop && raws.prop.prefix,
  13. // @ts-expect-error -- TS2571: Object is of type 'unknown'.
  14. (raws.prop && raws.prop.raw) || decl.prop,
  15. // @ts-expect-error -- TS2571: Object is of type 'unknown'.
  16. raws.prop && raws.prop.suffix,
  17. raws.between || ':',
  18. // @ts-expect-error -- TS2339: Property 'prefix' does not exist on type '{ value: string; raw: string; }'.
  19. raws.value && raws.value.prefix,
  20. ].reduce((count, str) => {
  21. if (str) {
  22. return count + str.length;
  23. }
  24. return count;
  25. }, 0);
  26. };