Skip to content

Latest commit

 

History

History
137 lines (92 loc) · 3.08 KB

Builders.md

File metadata and controls

137 lines (92 loc) · 3.08 KB

Builders

For every AST node, the bredon-types package also ships a builder function which safely creates AST nodes manually.

dimension(value: Integer | Float, unit: Unit)

where Unit refers to one of the valid units:
%, em, ex , ch , rem , vw , vh , vmin , vmax , cm , mm , q , in , pt , pc , px , deg , grad , rad , turn , s , ms , Hz , kHz , dpi , dpcm , dppx

import { dimension } from 'bredon-types'

dimension(integer(300), 'px') // => 30px
dimension(float(33, 33, true), '%') // => -33.33%

expression(body: Array<node>)

import { expression } from 'bredon-types'

expression([ /* child nodes */ ])

float(integer: number, fractional: number, isNegative?: boolean = false)

import { float } from 'bredon-types'

float(0, 55) // => .55
float(1, 10, true) // => -1.10

functionExpression(callee: string, params: Array<node>)

import { functionExpression } from 'bredon-types'

functionExpression('rgba', [ /* param nodes */ ]) // => rgba(...)

hexColor(color: string)

import { hexColor } from 'bredon-types'

hexColor('FFF') // => #FFF

identifier(name: string)

import { identifier } from 'bredon-types'

identifier('solid') // => solid

integer(value: number, isNegative?: boolean = false)

import { integer } from 'bredon-types'

integer(55) // => 55
integer(55, true) // => -55

operator(sign: '+' | '-' | '/' | '*')

import { operator } from 'bredon-types'

operator('+') // => +

parenthesis(paren: '(' | ')')

import { parenthesis } from 'bredon-types'

parenthesis('(') // => (

seperator()

import { seperator } from 'bredon-types'

seperator() // => /

stringLiteral(str: string, quote?: '"' | "'" = "'")

import { stringLiteral } from 'bredon-types'

stringLiteral("Hello, I am a string.", '"') // => "Hello, I am a string."

url(uri: string)

import { url } from 'bredon-types'

url("https://www.github.com/") // => url("https://www.github.com/") 

value(body: Array<node>, isImportant?: boolean = false)

import { cssValue } from 'bredon-types'

value([ /* child nodes */ ])
value([ /* child nodes */ ], true)

valueList(body: Array<value>)

import { valueList } from 'bredon-types'

valueList([ /* value nodes */])