Options
All
  • Public
  • Public/Protected
  • All
Menu

Module source/colors

Index

Variables

Variables

Const colors

colors: { hexToHsl: (str: string) => IHsl | null; hexToRgb: (hex: string) => number[] | null; isHex: (color: string) => boolean; luminance: (color: string, percent: number) => string | null; rgbToHex: (r: number | string, g: number | string, b: number | string) => string; rgbToHsl: (r: number, g: number, b: number) => IHsl | null } = ...

Type declaration

  • hexToHsl: (str: string) => IHsl | null
      • (str: string): IHsl | null
      • Takes a hex color string and returns a string array with hex color converted to HSL [H, S, L]

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const toHsl = colors.hexToHSL('#63C6FF');
        console.log(toHsl); // {h: 201.9, s: '100%', l: '69.4%'}
        

        Parameters

        • str: string

        Returns IHsl | null

  • hexToRgb: (hex: string) => number[] | null
      • (hex: string): number[] | null
      • Takes a hexidecimal color string and returns the rgb value

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const test = colors.hexToRgb('#16212c');
        console.log(test); // [22, 33, 44]
        

        Parameters

        • hex: string

        Returns number[] | null

  • isHex: (color: string) => boolean
      • (color: string): boolean
      • Takes a string and returns boolean indicating whether it is a valid hexidecimal color

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const valid = colors.isHex('16212c');
        const invalid = colors.isHex('nope');
        console.log(valid); // true
        console.log(invalid); // false
        

        Parameters

        • color: string

        Returns boolean

  • luminance: (color: string, percent: number) => string | null
      • (color: string, percent: number): string | null
      • Takes a hex color value and a percentage and returns a hex color string that is the result of lightening or darkening the original color by the percentage NOTE: this does not work on black or white!

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const lightened = colors.luminance('#63C6FF', 40);
        const darkened = colors.luminance('#63C6FF', -40);
        console.log(lightened); // '#8affff'
        console.log(darkened); // '#3b7699'
        

        Parameters

        • color: string
        • percent: number

        Returns string | null

  • rgbToHex: (r: number | string, g: number | string, b: number | string) => string
      • (r: number | string, g: number | string, b: number | string): string
      • Takes rgb color values and returns hexidecimal equivalent

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const test = colors.rgbToHex(22, 33, 44);
        console.log(test); // '#16212C'
        

        Parameters

        • r: number | string
        • g: number | string
        • b: number | string

        Returns string

  • rgbToHsl: (r: number, g: number, b: number) => IHsl | null
      • (r: number, g: number, b: number): IHsl | null
      • Takes r, g, and b and numbers in 3 separate agurments, convert to hsl, and returns in object with h, s, and l as keys

        Basic usage example:

        const colors = require('stringman').colors; // or `import {colors} from 'stringman'`;
        const toHsl = colors.rgbToHSL(99, 198, 255);
        console.log(toHsl); // {h: 201.9, s: '100%', l: '69.4%'}
        

        Parameters

        • r: number
        • g: number
        • b: number

        Returns IHsl | null

Generated using TypeDoc