ngohao-package
v1.1.0
Published
Example package
Downloads
11
Maintainers
Readme
:sparkling_heart: Support the project
I open-source almost everything I can, and I try to reply to everyone needing help using these projects. Obviously, this takes time. You can use this service for free.
Color Convert & Unit Convert
A simple Color Convert & Unit Convert for front-end development.
Installation
npm install ngohao-package
Usage
Color Convert
import {convertHexToRgb, convertRgbToHex} from "ngohao-package"
convertHexToRgb("#ff0000"); // "rgb(255, 0, 0)"
convertRgbToHex("rgb(255, 0, 0)"); // "#ff0000"
Convert Unit
import { convertUnit } from "ngohao-package"
convertUnit('px-to-rem', 16); // "1rem"
convertUnit('rem-to-px', 1); // "16px"
Props
Color Convert
| Prop name | Description | Example |
| ------------- | ------------- | ------------- |
| convertHexToRgb | Converts a hex color code to its RGB format. | convertHexToRgb("#ff0000")
// Returns "rgb(255, 0, 0)" |
| convertRgbToHex | Converts an RGB color string to its hex format. | convertRgbToHex("rgb(255, 0, 0)")
// Returns "#ff0000" |
| convertHexToHsl | Converts a hex color code to its HSL format. | convertHexToHsl("#ff0000")
// Returns "hsl(0, 100%, 50%)" |
| convertHslToHex | Converts an HSL color string to its hex format. | convertHslToHex("hsl(0, 100%, 50%)")
// Returns "#ff0000" |
| lightenColor | Lightens a given color by a specified amount. | lightenColor("#ff0000", 10)
// Returns a lighter red color string |
| darkenColor | Darkens a given color by a specified amount. | darkenColor("#ff0000", 10)
// Returns a darker red color string |
| getContrastRatio | Calculates the contrast ratio between two colors. | getContrastRatio("#ff0000", "#0000ff")
// Returns a contrast ratio value |
Unit Convert
convertUnit(param, number)
param
"px-to-rem"
"rem-to-px"
"px-to-em"
"em-to-px"
"px-to-percent"
"percent-to-px"
Contributions are welcome! :heart:
Made with :heart: