ktk-color
ktk-color is used to transfer format of different kinds of color.
Installing
npm install ktk-color
Usage
<script>
import Color from 'ktk-color';
const color = Color.tovec4('red');
</script>
API Reference
# Color.tovec4
Returns value in vec4 format.
The value will be clamped between 0 and 1 if exceeds limit.
Returns default value([0, 0, 0, 1]) if not in normal color format.
Color.tovec4('red')
Color.tovec4('rgb(100,75,50)')
Color.tovec4('rgba(100,75,50,0.5)')
Color.tovec4('#666666')
Color.tovec4([0, 0, 0, 1.5])
Color.tovec4([0, 0, 0, -0.5])
Color.tovec4([1, 100, 0, 0.5])
Color.tovec4('wrong')
Color.tovec4(37374)
# Color.tohex
Returns value in hex format.
Returns default value('#000000') if not in normal color format.
Color.tohex('red')
Color.tohex('rgb(100,100,100)')
Color.tohex('rgba(100,100,100,0.5)')
Color.tohex('#666666')
Color.tohex([1, 0, 0, 1])
Color.tohex([1, 100, 0, 0.5])
Color.tohex('wrong')
Color.tohex(37374)
# Color.torgb
Returns value in rgb format.
The value will be clamped between 0 and 1 if exceeds limit.
Returns default value('rgb(0, 0, 0)') if not in normal color format.
Color.torgb('red')
Color.torgb('rgb(100,75,50)')
Color.torgb('rgba(100,100,100,1)')
Color.torgb('#646464')
Color.torgb('#cde')
Color.torgb([1, 100, 0, 0.5])
Color.torgb('wrong')
Color.torgb(37374)
# Color.torgba
Returns value in rgba format.
Returns default value('rgba(0, 0, 0, 1)') if not in normal color format.
Color.torgba('red')
Color.torgba('rgb(100,75,50)')
Color.torgba('rgba(100,100,100,1)')
Color.torgba('#646464')
Color.torgba('#cde')
Color.torgba([1, 100, 0, 0.5])
Color.torgba('wrong')
Color.torgba(37374)
License
This project is licensed under ![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
Contact