DEV Community

JanselLopez
JanselLopez

Posted on

Get random color by a name or any string

npm i material-colors-utils
Enter fullscreen mode Exit fullscreen mode

Get random palette by string

import { getRandomPaletteByString } from "material-colors-utils";
console.log({palette:getRandomPaletteByString("janselALB")});
//{
//    palette:{
//      50: "#E3F2FD",
//      100: "#BBDEFB",
//      200: "#90CAF9",
//      300: "#64B5F6",
//      400: "#42A5F5",
//      500: "#2196F3",
//      600: "#1E88E5",
//      700: "#1976D2",
//      800: "#1565C0",
//      900: "#0D47A1",
//      A100: "#82B1FF",
//      A200: "#448AFF",
//      A400: "#2979FF",
//      A700: "#2962FF"
//    }
//}
Enter fullscreen mode Exit fullscreen mode

Get random color by string

import { getRandomColorByString } from "material-colors-utils";
//Param: Color variant
getRandomColorByString("janselALB",300)//Ex: #64B5F6
//Default is 500
getRandomColorByString("janselALB")//Ex: #2196F3
Enter fullscreen mode Exit fullscreen mode

Support

material-colors-utils

Top comments (0)