JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q36272F
  • License MIT

Tools for converting and typing colors

Package Exports

  • @guyn/tools

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@guyn/tools) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Guyn Tools

Convert, find, check and manipulate colors.

Guyn Tools is a collection of Javascript functions to deal with colors.

Convert

rgbToHex

Convert rgb color to hex

rgbToHex({ r: 0, g: 0, b: 0 }); // #000000

hexToRgb

Convert hex color to rgb

hexToRgb('#000000'); // {r: 0, g: 0, b: 0})

rgbToHsl

Convert rgb color to hsl

rgbToHsl({ r: 0, g: 0, b: 0 }); // {h: 0, s: 0, l: 100}

hexToHsl

Convert hex color to hsl

hexToHsl('#000000'); // {h: 0, s: 0, l: 100}

Checking

isHex

Is this string a hex color?

isHex('#000000'); // true
isHex('#00000'); // false
isHex('#000'); // false
isHex('#ff00gg'); // false

isObjectString

Check if a string could be a valid object.

isObjectString('something'); // false
isObjectString('"{"test":"test"}"'); // true

Hex Strings

toHexChars

Convert a possible hex color code to a valid hex color code

toHexChars(' #00aa 00'); // #00aa00
toHexChars('#fff'); // #ffffff;
toHexChars('#fffaabbaa'); // #fffaab;

toHexCharsGroup

Convert an array of possible hex color codes to valid color codes.

toHexChars([' #00aa 00', '#fff']); // ['#00aa00', '#ffffff']

findHex

Find all Hex colors in a string

findHex('#000#aaa#abcdef'); // ['#000000','#aaaaaa', '#abcdef']