MCPcopy
hub / github.com/mjmlio/mjml / widthParser

Function widthParser

packages/mjml-core/src/helpers/widthParser.js:3–18  ·  view source on GitHub ↗
(width, options = {})

Source from the content-addressed store, hash-verified

1const unitRegex = /[\d.,]*(\D*)$/
2
3export default function widthParser(width, options = {}) {
4 const { parseFloatToInt = true } = options
5
6 const widthUnit = unitRegex.exec(width.toString())[1]
7 const unitParsers = {
8 default: parseInt,
9 px: parseInt,
10 '%': parseFloatToInt ? parseInt : parseFloat,
11 }
12 const parser = unitParsers[widthUnit] || unitParsers.default
13
14 return {
15 parsedWidth: parser(width),
16 unit: widthUnit || 'px',
17 }
18}

Callers 14

getChildContextMethod · 0.85
getMobileWidthMethod · 0.85
getWidthAsPixelMethod · 0.85
getParsedWidthMethod · 0.85
getWidthMethod · 0.85
getStylesMethod · 0.85
getOutlookWidthMethod · 0.85
getChildContextMethod · 0.85
getParsedWidthMethod · 0.85
getWidthAsPixelMethod · 0.85
getElementWidthMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…