bredon-plugin-unit

1.0.0 • Public • Published

bredon-plugin-unit

npm version npm downloads

The unit plugin will convert, normalize and minify unit values.

Installation

yarn add bredon-plugin-unit

You may alternatively use npm i --save bredon-plugin-unit.

Usage

import { compile } from 'bredon'
import unitPlugin from 'bredon-plugin-unit'

const input = '12pt 0.25turn 3s 15px 2.53cm'

const output = compile(input, {
  plugins: [ 
    unitPlugin()
  ]
})

console.log(output)
// => 16px 90deg 3000ms 15px 95.622px

Configuration

By default the output precision is 4.
The default unit formats are:

  • length: px
  • time: ms
  • angle: deg
Options Value Default Description
precision number 4 The prefered precision
formats Object { length: 'px', time: 'ms', angle: 'deg' } The prefered unit formats
import { compile } from 'bredon'
import unitPlugin from 'bredon-plugin-unit'

const input = '12pt 0.25turn 3s 15px 2.53cm'

const output = compile(input, {
  plugins: [ 
    unitPlugin({
       precision: 2,
       formats: {
        length: 'mm',
        angle: 'grad',
        time: 's',
      }         
    })
  ]
})

console.log(output)
// => 4.23mm 100grad 3s 3.97mm 25.3mm

License

Bredon is licensed under the MIT License.
Documentation is licensed under Creative Common License.
Created with ♥ by @rofrischmann and all the great contributors.

Package Sidebar

Install

npm i bredon-plugin-unit

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • rofrischmann