Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

color-detector

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color-detector

Easy access to all the color formats on the web.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-46.67%
Maintainers
1
Weekly downloads
 
Created
Source

color-detector

color-detector is an Javascript library to get all the HTML colors (256 colors) in standard formats. (hex, rgb, hsl and simple name).

This library helps you to filter through any type of standard color format and find you all other details of it.

npm install color-detector --save

Usage

// import the library
const {
    accessFromId,
    accessFromName,
    accessFromHexString,
    accessColorFromRGB,
    accessColorFromHSL
} = require('color-detector');

(async () => {
    try {

    // get color from name
    const resultFromName = await accessFromName('Green');
    console.log('result from name :', resultFromName);

    // get color from hex
    const resultFromHex = await accessFromHexString('#000000');
    console.log('result from Hex :', resultFromHex);

    // get color from RGB
    const resultFromRGB = await accessColorFromRGB({
        r: 128,
        g: 0,
        b: 128,
    });
    console.log('result from RGB :', resultFromRGB);

    // get color from HSL
    const resultFromHSL = await accessColorFromHSL({
        h: 0,
        s: 0,
        l: 75,
    });
    console.log('result from HSL :', resultFromHSL);

    // get color from ID
    const resultFromId = await accessFromId(10);
    console.log('result from Id :', resultFromId);

} catch (error) {
    console.log(error);
}
})();

Result :-

result from name : {
  colorId: 2,
  hexString: '#008000',
  rgb: { r: 0, g: 128, b: 0 },
  hsl: { h: 120, s: 100, l: 25 },
  name: 'Green'
}
result from Hex : {
  colorId: 0,
  hexString: '#000000',
  rgb: { r: 0, g: 0, b: 0 },
  hsl: { h: 0, s: 0, l: 0 },
  name: 'Black'
}
result from RGB : {
  colorId: 5,
  hexString: '#800080',
  rgb: { r: 128, g: 0, b: 128 },
  hsl: { h: 300, s: 100, l: 25 },
  name: 'Purple'
}
result from HSL : {
  colorId: 7,
  hexString: '#c0c0c0',
  rgb: { r: 192, g: 192, b: 192 },
  hsl: { h: 0, s: 0, l: 75 },
  name: 'Silver'
}
result from Id : {
  colorId: 10,
  hexString: '#00ff00',
  rgb: { r: 0, g: 255, b: 0 },
  hsl: { h: 120, s: 100, l: 50 },
  name: 'Lime'
}

Reference

The colors which are avaible in the library is refered from jonasjacek.github.io/colors

Licence

(The MIT License) Copyright (c) 2021 kmkasunmadushanka@gmail.com

Keywords

FAQs

Package last updated on 27 Aug 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc