Skip to content

editorGlobalsUnitParser

Class: UnitParser

Hierarchy

  • UnitParser

Index

Properties

Methods

Properties

Static lengthUnits

lengthUnits: ReadonlyArray‹keyof typeof LengthUnit› = [ "mm", "cm", "m", "inch", "foot", "feet", '"', "'", ]

Defined in src/util/UnitParser.ts:5

Methods

Static Private _buildRegex

_buildRegex(expectedUnits: readonly string[]): RegExp

Defined in src/util/UnitParser.ts:86

Parameters:

Name Type
expectedUnits readonly string[]

Returns: RegExp


Static getLengthIn

getLengthIn(input: string, unit: LengthUnit, fallbackUnit: LengthUnit): number | null

Defined in src/util/UnitParser.ts:25

Parameters:

Name Type Default Description
input string - the string that should be parsed and converted into unit, e.g. "5cm", "2inch", "10"
unit LengthUnit - the unit the result should be in, e.g. ("5cm", LengthUnit.mm) → 50
fallbackUnit LengthUnit unit Unit to interpret inputs without unit in, e.g. ("5", LengthUnit.mm, LengthUnit.cm) → 50

Returns: number | null


Static parse

parse(text: string, expectedUnits: readonly string[], unitOptional: boolean): object | null

Defined in src/util/UnitParser.ts:43

Parses a string with a numeric value and a unit.

Parameters:

Name Type Default Description
text string - The string to parse
expectedUnits readonly string[] [".*"] A string of possible units. These may be RegExp strings themselves, e.g. to allow all units that end with "Byte", use [".*Byte"]
unitOptional boolean true If true, this method may return null as the unit, if no unit could be found. Note: Regardless of this parameter, if a different unit than the searched ones is present in the string, this method will return null.

Returns: object | null


Static parseLength

parseLength(text: string): object

Defined in src/util/UnitParser.ts:16

Parameters:

Name Type
text string

Returns: object

  • humanreadable: string

  • unit: string

  • value: number