UNPKG

@sequencemedia/css-purge

Version:

A CSS tool written in Node JS as a command line app or library for the purging, burning, reducing, shortening, compressing, cleaning, trimming and formatting of duplicate, extra, excess or bloated CSS.

55 lines (40 loc) 1.34 kB
import debug from 'debug' const log = debug('@sequencemedia/css-purge/process-zero') function getUnit (value) { return value.substring(1) } export default function processZero (rule, OPTIONS, SUMMARY) { const { declarations = [] } = rule const { zero_ignore_declaration: ZERO_IGNORE_DECLARATION, zero_units: ZERO_UNITS } = OPTIONS declarations .forEach((declaration) => { if (!ZERO_IGNORE_DECLARATION.includes(declaration.property)) { let value = declaration.value // leading zeros 000 if (value.match(/[^#]\b0+[^1-9a-zA-Z.,;%()\[\]\s\/\\!]/gm)) { // eslint-disable-line no-useless-escape // remove single duplicate 0 value = value.replace(/\b0+[^1-9a-zA-Z.,;%()\[\]\s\/\\!]/gm, '') // eslint-disable-line no-useless-escape SUMMARY.stats.summary.noZerosShortened += 1 const { selectors = [] } = rule log(selectors) // .join(', ').trim()) } // 0px, 0em, etc. if (value.startsWith('0') && ZERO_UNITS.includes(getUnit(value))) { value = '0' SUMMARY.stats.summary.noZerosShortened += 1 const { selectors = [] } = rule log(selectors) // .join(', ').trim()) } declaration.value = value } }) }