🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

ktk-color

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ktk-color

color format conventer for personal use

latest
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

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'); // [1, 0, 0, 1]
</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')                   // [1, 0, 0, 1]
Color.tovec4('rgb(100,75,50)')        // [0.39, 0.29, 0.19, 1]
Color.tovec4('rgba(100,75,50,0.5)')   // [0.39, 0.29, 0.19, 0.5]
Color.tovec4('#666666')               // [0.4, 0.4, 0.4, 1]
Color.tovec4([0, 0, 0, 1.5])          // [0, 0, 0, 1])
Color.tovec4([0, 0, 0, -0.5])         // [0, 0, 0, 0])
Color.tovec4([1, 100, 0, 0.5])        // [1, 1, 0, 0.5])
Color.tovec4('wrong')                 // [0, 0, 0, 1]
Color.tovec4(37374)                   // [0, 0, 0, 1]

# Color.tohex
Returns value in hex format.
Returns default value('#000000') if not in normal color format.

Color.tohex('red')                   // #ff0000
Color.tohex('rgb(100,100,100)')      // #646464
Color.tohex('rgba(100,100,100,0.5)') // #646464
Color.tohex('#666666')               // #666666
Color.tohex([1, 0, 0, 1])            // #ff0000
Color.tohex([1, 100, 0, 0.5])        // #ffff00
Color.tohex('wrong')                 // #000000
Color.tohex(37374)                   // #000000

# 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')                   // rgb(255,0,0)
Color.torgb('rgb(100,75,50)')        // rgb(100,75,50)
Color.torgb('rgba(100,100,100,1)')   // rgb(100,100,100)
Color.torgb('#646464')               // rgb(100,100,100)
Color.torgb('#cde')                  // rgb(204,221,238)
Color.torgb([1, 100, 0, 0.5])        // rgb(255,255,0)
Color.torgb('wrong')                 // rgb(0,0,0)
Color.torgb(37374)                   // rgb(0,0,0)

# Color.torgba
Returns value in rgba format.
Returns default value('rgba(0, 0, 0, 1)') if not in normal color format.

Color.torgba('red')                   // rgba(255,0,0,1)
Color.torgba('rgb(100,75,50)')        // rgba(100,75,50,1)
Color.torgba('rgba(100,100,100,1)')   // rgba(100,100,100,1)
Color.torgba('#646464')               // rgba(100,100,100,1)
Color.torgba('#cde')                  // rgba(204,221,238,1)
Color.torgba([1, 100, 0, 0.5])        // rgba(255,255,0,0.5)
Color.torgba('wrong')                 // rgba(0,0,0,1)
Color.torgba(37374)                   // rgba(0,0,0,1)

License

This project is licensed under License: MIT

Contact

FAQs

Package last updated on 21 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts