niram
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

Niram

A javascript library to convert between various css colour formats.

Installation

Install niram using any of the command below

  • yarn add niram
  • npm install niram

Usage

To convert colours:

import { convertColor } from 'niram'

const color = convertColor('hsl(120deg, 100%, 25%)')

console.log(color)

Above code will log the converted colour details to console as:

{
    "name": "green",
    "decimal": 8388863,
    "hex": "#008000",
    "rgb": "rgb(0, 128, 0)",
    "rgba": "rgba(0, 128, 0, 1)",
    "hsl": "hsl(120deg, 100%, 25%)",
    "hsla": "hsla(120deg, 100%, 25%, 1)",
    "opacity": 1
}

To validate colours:

import { validateColor } from 'niram'

const isColorValid = validateColor('hwb(120deg 0% 50% / 1)')

console.log(isColorValid)

// Outputs: true

Supported Formats

Following are the supported colour formats (given with example)

  • Colour Keywords - green

  • HEX - #008000 or #0f0

  • RGB - rgb(0, 128, 0) or rgb(0 128 0)

  • RGBA - rgba(0, 128, 0, 1) or rgba(0 128 0 / 1)

  • HSL* - hsl(120deg, 100%, 25%) or hsl(120deg 100% 25%)

  • HSLA* - hsla(120deg, 100%, 25%, 1) or hsla(120deg 100% 25% / 1)

  • HWB*# - hwb(120deg 0% 50% / 1)

  • LAB# - lab(46.23 -51.7 49.9 / 1)

  • LCH# - lch(46.28% 67.98 134.38 / 1)

* You can also use rad instead of deg

# Support is only available for Validation

Unsupported Formats

Following are currently unsupported for conversion, but support will be added soon.

  • hwb()
  • lab()
  • lch()

Package Sidebar

Install

npm i niram

Weekly Downloads

9

Version

0.1.6

License

LGPL-3.0

Unpacked Size

36.1 kB

Total Files

27

Last publish

Collaborators

  • mhmdaz