Socket
Socket
Sign inDemoInstall

s.color

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    s.color

Simple color library.


Version published
Weekly downloads
102K
increased by4.91%
Maintainers
1
Install size
32.5 kB
Created
Weekly downloads
 

Readme

Source

circleci Custom npmV min install githubLastCommit

Note: if you want a reliable library use something like color instead.

Docs

ColorConverters

RGBToHSV
/**
 * Takes an `RGBColor` and converts it to `HSVColor`
 */
function RGBToHSV(color: RGBColor, is255?: boolean): HSVColor;
HSVToRGB
/**
 * Takes an `HSVColor` and converts it to `RGBColor`
 */
function HSVToRGB(hsv: HSVColor, is100?: boolean): RGBColor;
StringToRGB
/**
 * Takes an `StringColor` and converts it to `RGBColor`,
 * If input string is invalid `null` will be returned.
 */
function StringToRGB(input: string, return255?: boolean, alpha255?: boolean): RGBColor;
StringToHVS
/**
 * Takes an `StringColor` and converts it to `HSVColor`,
 * If input string is invalid `null` will be returned.
 */
function StringToHVS(input: string, return255?: boolean, alpha255?: boolean): HSVColor;
HSVToHEX
/**
 * Takes an `HSVColor` and converts it to `String` (HEX Format)
 */
function HSVToHEX(hsv: HSVColor, options?: {
    type?: GetColorTypeHex;
    isLong?: boolean;
}
RGBToHEX
/**
 * Takes an `RGBColor` and converts it to `String` (HEX Format)
 */
function RGBToHEX(color: RGBColor, type?: GetColorTypeHex): string;

ColorTypes

RGBColor
/**
 * Represents a color in the rgb(a) format.
 *
 *
 * Range `[0 - 1]`
 */
class RGBColor {
    /**
     * Range [0-1]
     */
    r: number;
    /**
     * Range [0-1]
     */
    g: number;
    /**
     * Range [0-1]
     */
    b: number;
    /**
     * Range [0-1]
     */
    a: number;
    constructor(r: number, g: number, b: number, a?: number);
}
HSVColor
/**
 * Represents a color in the hsv(a) format.
 *
 *
 * Range `[h 0 - 360, v/s/a 0 - 1]`
 */
class HSVColor {
    /**
     * Range [0-360]
     */
    h: number;
    /**
     * Range [0-100]
     */
    s: number;
    /**
     * Range [0-100]
     */
    v: number;
    /**
     * Range [0-1]
     */
    a: number;
    constructor(h: number, s: number, v: number, a?: number);
}
StringColor
/**
 * Represents a color in a string format.
 * Valid strings are `#000 | #0000 | #000000 | #00000000`
 * Or `rgb(0, 0, 0, 0) | rgba(0, 0, 0, 0, 0)` Range [rgb 0-255, a: 0-1]
 *
 */
class StringColor {
    color: string;
    constructor(color: string);
}

HandleGet

HandleGetHex
function HandleGetHex(type: GetColorType, color: RGBColor, options?: GetColorOptions): string;

HandleSet

ConvertString
function ConvertString(input: string, return255?: boolean, alpha255?: boolean): RGBColor;
HandleConvertHexString
/**
 * **assumes that the input is valid**
 */
function HandleConvertHexString(text: string, return255?: boolean, alpha255?: boolean): RGBColor;

UtilityFunction

GetReadableTextColor
function GetReadableTextColor(color: RGBColor | HSVColor | StringColor | string): RGBColor | HSVColor | "#000" | "#fff";
ShiftHue
/**
 * Shifts the hue of the `HSVColor` by the Value
 */
function ShiftHue(hsv: HSVColor, value: number): HSVColor;

index

interfaces

GetColorTypeHex
type GetColorTypeHex = 'hex' | 'hex-short' | 'hex-without-alpha' | 'hex-without-alpha-short';
GetColorType
type GetColorType = 'rgb' | GetColorTypeHex | 'rgba' | 'object' | 'hsv';
GetColorOptions
interface GetColorOptions {
    /**
     * if true `#fff` will be output as `#FFF`
     */
    UpperCaseHex: boolean;
}

regex

isValidHex
function isValidHex(text: string): boolean;
isValidRGB
function isValidRGB(text: string): boolean;

utils

GetReadableTextColor
function GetReadableTextColor(color: RGBColor | HSVColor | StringColor | string): RGBColor | HSVColor | "#000" | "#fff";
ShiftHue
/**
 * Shifts the hue of the `HSVColor` by the Value
 */
function ShiftHue(hsv: HSVColor, value: number): HSVColor;
convertCssColorToHex
/**Returns the hex value of the color string or the input string */
function convertCssColorToHex(color: string): string;

validators

isValidStringColor
function isValidStringColor(input: string): string;

Generated with suf-cli

License

Copyright (c) 2020 Leonard Grosoli Licensed under the MIT license.

Keywords

FAQs

Last updated on 05 Nov 2020

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc