| Server IP : 159.203.156.69 / Your IP : 216.73.216.37 Web Server : nginx/1.24.0 System : Linux main-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/tanviranik.com/node_modules/css-box-shadow/ |
Upload File : |
const VALUES_REG = /,(?![^\(]*\))/
const PARTS_REG = /\s(?![^(]*\))/
const LENGTH_REG = /^[0-9]+[a-zA-Z%]+?$/
const parseValue = str => {
const parts = str.split(PARTS_REG)
const inset = parts.includes('inset')
const last = parts.slice(-1)[0]
const color = !isLength(last) ? last : undefined
const nums = parts
.filter(n => n !== 'inset')
.filter(n => n !== color)
.map(toNum)
const [ offsetX, offsetY, blurRadius, spreadRadius ] = nums
return {
inset,
offsetX,
offsetY,
blurRadius,
spreadRadius,
color
}
}
const stringifyValue = obj => {
const {
inset,
offsetX = 0,
offsetY = 0,
blurRadius = 0,
spreadRadius,
color
} = obj || {}
return [
(inset ? 'inset' : null),
offsetX,
offsetY,
blurRadius ,
spreadRadius,
color
].filter(v => v !== null && v !== undefined)
.map(toPx)
.map(s => ('' + s).trim())
.join(' ')
}
const isLength = v => v === '0' || LENGTH_REG.test(v)
const toNum = v => {
if (!/px$/.test(v) && v !== '0') return v
const n = parseFloat(v)
return !isNaN(n) ? n : v
}
const toPx = n => typeof n === 'number' && n !== 0 ? (n + 'px') : n
const parse = str => str.split(VALUES_REG).map(s => s.trim()).map(parseValue)
const stringify = arr => arr.map(stringifyValue).join(', ')
module.exports = {
parse,
stringify
}