Comparing version 1.0.0 to 2.0.0
19
index.js
'use strict'; | ||
module.exports = function (red, green, blue) { | ||
if ((typeof red !== 'number' || typeof green !== 'number' || typeof blue !== 'number') && | ||
(red > 255 || green > 255 || blue > 255)) { | ||
/* eslint-disable no-mixed-operators */ | ||
module.exports = (red, green, blue) => { | ||
if (typeof red === 'string') { | ||
const res = red.match(/\b\d{1,3}\b/g).map(Number); | ||
// TODO: use destructuring when targeting Node.js 6 | ||
red = res[0]; | ||
green = res[1]; | ||
blue = res[2]; | ||
} | ||
if (typeof red !== 'number' || | ||
typeof green !== 'number' || | ||
typeof blue !== 'number' || | ||
red > 255 || | ||
green > 255 || | ||
blue > 255) { | ||
throw new TypeError('Expected three numbers below 256'); | ||
@@ -6,0 +19,0 @@ } |
{ | ||
"name": "rgb-hex", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Convert RGB color to HEX", | ||
@@ -10,9 +10,9 @@ "license": "MIT", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "http://sindresorhus.com" | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "node test.js" | ||
"test": "xo && ava" | ||
}, | ||
@@ -32,4 +32,8 @@ "files": [ | ||
"devDependencies": { | ||
"ava": "0.0.3" | ||
"ava": "*", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
} |
@@ -8,3 +8,3 @@ # rgb-hex [![Build Status](https://travis-ci.org/sindresorhus/rgb-hex.svg?branch=master)](https://travis-ci.org/sindresorhus/rgb-hex) | ||
```sh | ||
``` | ||
$ npm install --save rgb-hex | ||
@@ -17,6 +17,9 @@ ``` | ||
```js | ||
var rgbHex = require('rgb-hex'); | ||
const rgbHex = require('rgb-hex'); | ||
rgbHex(65, 131, 196); | ||
//=> 4183c4 | ||
//=> '4183c4' | ||
rgbHex('rgb(40, 42, 54)'); | ||
//=> '282a36' | ||
``` | ||
@@ -27,3 +30,4 @@ | ||
See [hex-rgb](https://github.com/sindresorhus/hex-rgb) for the inverse. | ||
- [rgb-hex-cli](https://github.com/sindresorhus/rgb-hex-cli) - CLI for this module | ||
- [hex-rgb](https://github.com/sindresorhus/hex-rgb) - Convert HEX color to RGB | ||
@@ -33,2 +37,2 @@ | ||
MIT © [Sindre Sorhus](http://sindresorhus.com) | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
2873
4
20
35
0
2