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

postcss-hexrgba

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

postcss-hexrgba - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.travis.yml

55

CHANGELOG.md
# Change Log
## [Unreleased](https://github.com/seaneking/postcss-hexrgba/tree/HEAD)
## [v1.0.0](https://github.com/seaneking/postcss-hexrgba/tree/v1.0.0) (2017-07-26)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.1...v1.0.0)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.1...HEAD)
**Closed issues:**

@@ -22,48 +21,2 @@

# Change Log
## [Unreleased](https://github.com/seaneking/postcss-hexrgba/tree/HEAD)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.1...HEAD)
**Closed issues:**
- Plugin is not working in Postcss ember [\#7](https://github.com/seaneking/postcss-hexrgba/issues/7)
**Merged pull requests:**
- Upgrade to postcss@6 and dev deps [\#8](https://github.com/seaneking/postcss-hexrgba/pull/8) ([perrin4869](https://github.com/perrin4869))
## [v0.2.1](https://github.com/seaneking/postcss-hexrgba/tree/v0.2.1) (2016-09-19)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.0...v0.2.1)
TEST
**Merged pull requests:**
- BUGFIX: hexrgba breaks on undefined values [\#5](https://github.com/seaneking/postcss-hexrgba/pull/5) ([dimaip](https://github.com/dimaip))
# Change Log
## [Unreleased](https://github.com/seaneking/postcss-hexrgba/tree/HEAD)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.1...HEAD)
**Closed issues:**
- Plugin is not working in Postcss ember [\#7](https://github.com/seaneking/postcss-hexrgba/issues/7)
**Merged pull requests:**
- Upgrade to postcss@6 and dev deps [\#8](https://github.com/seaneking/postcss-hexrgba/pull/8) ([perrin4869](https://github.com/perrin4869))
## [v0.2.1](https://github.com/seaneking/postcss-hexrgba/tree/v0.2.1) (2016-09-19)
[Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.2.0...v0.2.1)
TEST STUFF HERE
**Merged pull requests:**
- BUGFIX: hexrgba breaks on undefined values [\#5](https://github.com/seaneking/postcss-hexrgba/pull/5) ([dimaip](https://github.com/dimaip))
## [v0.2.0](https://github.com/seaneking/postcss-hexrgba/tree/v0.2.0) (2015-09-06)

@@ -93,6 +46,2 @@ [Full Changelog](https://github.com/seaneking/postcss-hexrgba/compare/v0.1.2...v0.2.0)

\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

@@ -1,90 +0,70 @@

var postcss = require('postcss');
'use strict';
module.exports = postcss.plugin('postcss-hexrgba', function () {
const postcss = require('postcss');
/**
* Hex to RGB converter
* @param {string} hex hexidecimal string without #
* @return {array} RGB values
*/
var hexRgb = function(hex){
module.exports = postcss.plugin('postcss-hexrgba', () => {
// If given shorthand, expand it
var shorthandCheck = /^([a-f\d])([a-f\d])([a-f\d])$/i;
hex = hex.replace(shorthandCheck, function(m, r, g, b) {
return r + r + g + g + b + b;
});
/**
* Hex to RGB converter
* @param {string} hex hexidecimal string without #
* @return {array} RGB values
*/
function hexRgb(hex){
let shorthandCheck = /^([a-f\d])([a-f\d])([a-f\d])$/i,
rgbRegex = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,
rgb;
// Extract full hex into an array
var rgbRegex = /^([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
var rgb = hex
.replace(/^\s+|\s+$/g, '')
.match(rgbRegex);
hex = hex.replace(shorthandCheck, function(m, r, g, b) {
return r + r + g + g + b + b;
});
// Convert it
return rgb ? [
parseInt(rgb[1], 16),
parseInt(rgb[2], 16),
parseInt(rgb[3], 16)
] : false;
rgb = hex.replace(/^\s+|\s+$/g, '').match(rgbRegex);
};
// Convert it
return rgb ? [
parseInt(rgb[1], 16),
parseInt(rgb[2], 16),
parseInt(rgb[3], 16)
] : false;
}
/**
* CSS rule handler
* @param {string} decl CSS delcaration
*/
var ruleHandler = function(decl, result) {
/**
* CSS rule handler
* @param {string} decl CSS delcaration
*/
function ruleHandler(decl, result) {
let input = decl.value;
var input = decl.value,
output = input,
hexes = [];
// Get the raw hex values and replace them
let output = input.replace(/rgba\(#(.*?),/g, (match, hex) => {
let rgb = hexRgb(hex),
matchHex = new RegExp('#' + hex);
// If conversion fails, emit a warning
if (!rgb) {
result.warn('not a valid hex', { node: decl });
return match;
}
// Get the raw hex values out of the decl value and put them in an array
input.replace(/rgba\(\#(.*?)\,/g, function(a, b){
hexes.push(b);
});
rgb = rgb.toString();
return match.replace(matchHex, rgb);
});
// If there are no hexes in the value, exit
if (!hexes.length) {
decl.replaceWith({
prop: decl.prop,
value: output,
important: decl.important
});
}
return function(css, result) {
css.walkDecls(decl => {
if (typeof decl.value === 'undefined' || decl.value.indexOf('rgba') === -1) {
return;
}
// Convert each hex to RGB
hexes.forEach(function(hex) {
var rgb = hexRgb(hex);
// If conversion fails, warn and exit
if (!rgb) {
result.warn('not a valid hex', { node: decl });
return;
}
rgb = rgb.toString();
// Replace hex values in output string
var matchHex = new RegExp('#' + hex);
output = output.replace(matchHex, rgb);
});
decl.replaceWith({prop: decl.prop, value: output });
};
// Do it!
return function(css, result) {
css.walkDecls(function(decl) {
// Only process rgba declaration values
if (typeof decl.value === 'undefined' || decl.value.indexOf('rgba') === -1) {
return;
}
ruleHandler(decl, result);
});
ruleHandler(decl, result);
});
};
});
{
"name": "postcss-hexrgba",
"version": "1.0.0",
"version": "1.0.1",
"description": "PostCSS plugin that adds shorthand hex methods to rgba() values",

@@ -33,10 +33,10 @@ "keywords": [

"devDependencies": {
"gulp-eslint": "^4.0.0",
"gulp-mocha": "^4.3.1",
"chai": "^4.1.0",
"gulp": "^3.9.1"
"chai": "^4.0.2",
"eslint": "^4.1.1",
"mocha": "^3.4.2"
},
"scripts": {
"test": "gulp check"
"test": "mocha test",
"posttest": "eslint ."
}
}
# PostCSS HexRGBA
[![NPM version][npm-badge]][npm-url] [![Build Status][travis-badge]][travis-url] [![Dependency Status][daviddm-badge]][daviddm-url]
[![NPM version][npm-badge]][npm-url] [![Downloads][downloads-badge]][npm-url] [![Build Status][travis-badge]][travis-url]
[PostCSS][PostCSS] plugin that adds shorthand hex methods to rbga() values.
Part of [Rucksack - CSS Superpowers](http://simplaio.github.io/rucksack).
_Part of [Rucksack - CSS Superpowers](http://simplaio.github.io/rucksack)_
**Input**
```css

@@ -18,2 +20,4 @@ .foo {

**Output**
```css

@@ -43,6 +47,5 @@ .foo {

[npm-url]: https://npmjs.org/package/postcss-hexrgba
[downloads-badge]: https://img.shields.io/npm/dm/postcss-hexrgba.svg
[travis-badge]: https://travis-ci.org/seaneking/postcss-hexrgba.svg?branch=master
[travis-url]: https://travis-ci.org/seaneking/postcss-hexrgba
[daviddm-badge]: https://david-dm.org/seaneking/postcss-hexrgba.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/seaneking/postcss-hexrgba
[PostCSS]: https://github.com/postcss/postcss

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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