File size: 402 Bytes
1e92f2d
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
const lengthUnits =
  "cm,mm,Q,in,pc,pt,px,em,ex,ch,rem,lh,rlh,vw,vh,vmin,vmax,vb,vi,svw,svh,lvw,lvh,dvw,dvh,cqw,cqh,cqi,cqb,cqmin,cqmax,%"
const lengthUnitsPattern = `(?:${lengthUnits.split(",").join("|")})`
const lengthRegExp = new RegExp(
  `^[+-]?[0-9]*.?[0-9]+(?:[eE][+-]?[0-9]+)?${lengthUnitsPattern}$`,
)

export const isCssUnit = (v: unknown) =>
  typeof v === "string" && lengthRegExp.test(v)