数通智联化工云平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
700 B

2 years ago
'use strict';
const { isObject, isString } = require('./validateTypes');
/**
* Get the index of a declaration's value
*
* @param {import('postcss').Declaration} decl
* @returns {number}
*/
module.exports = function declarationValueIndex(decl) {
const raws = decl.raws;
const prop = raws.prop;
return [
isObject(prop) && 'prefix' in prop && prop.prefix,
(isObject(prop) && 'raw' in prop && prop.raw) || decl.prop,
isObject(prop) && 'suffix' in prop && prop.suffix,
raws.between || ':',
raws.value && 'prefix' in raws.value && raws.value.prefix,
].reduce((/** @type {number} */ count, str) => {
if (isString(str)) {
return count + str.length;
}
return count;
}, 0);
};