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

color2rgba

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

color2rgba

颜色转换工具

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

颜色转换工具

  • 可以将 3/4/6/8 位的十六进制或者RGB颜色值转换为 RGBA 对应的十进制数值。

示例

  • 接受两个参数

    • 第一个是颜色字符串,必填
    • 第二个是自定义透明度,非必填,支持 0-1 之间的小数,默认为 1
  • 废话少说直接上代码

import color2rgba from "color2rgba";
console.log(color2rgba("RGBA(223,123,0,0.45)")); // [223, 123, 0, 0.45]
console.log(color2rgba("RGB(123,223,0)")); // [123, 223, 0, 1]
console.log(color2rgba("RGB(0,123,223)", 0.3)); // [0, 123, 223, 0.3]
console.log(color2rgba("#FFF")); // [255, 255, 255, 1]
console.log(color2rgba("#FFF111")); // [255, 241, 17, 1]
console.log(color2rgba("#FFF111", 0.4)); // [255, 241, 17, 0.4]
console.log(color2rgba("#fff8")); // [255, 255, 255, 0.53]
console.log(color2rgba("#ffffff80")); // [255, 255, 255, 0.5]
console.log(color2rgba("#ffffff80", 0.3)); // [255, 255, 255, 0.3]

Keywords

FAQs

Package last updated on 20 Mar 2024

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