@stylistic/stylelint-plugin
Version:
A collection of stylistic/formatting Stylelint rules
27 lines (23 loc) • 671 B
JavaScript
import { isObject, isString } from "./validateTypes.js"
/**
* Get the index of a declaration's value
*
* @param {import('postcss').Declaration} decl
* @returns {number}
*/
export default function declarationValueIndex (decl) {
let raws = decl.raws
let 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)
}