Skip to content

Commit

Permalink
Allow rgb and rgba colour definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gruntfuggly committed Oct 5, 2020
1 parent 07f3572 commit 1e1edf1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add context menu options to toggle badges and item counts
- Fix counts in tree when hideFromStatusBar is enabled
- kill ripgrep on deactivate
- Allow rgb and rgba colour definitions

## v0.0.182 - 2020-10-03

Expand Down
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var config;
var commentPatterns = require( 'comment-patterns' );

var envRegex = new RegExp( "\\$\\{(.*?)\\}", "g" );
var rgbRegex = new RegExp( "^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$", "gi" );

function init( configuration )
{
Expand All @@ -26,6 +27,11 @@ function isHexColour( colour )
return ( typeof colour === "string" ) && hex.length === withoutHash.length && ( hex.length === 3 || hex.length === 4 || hex.length === 6 || hex.length === 8 ) && !isNaN( parseInt( hex, 16 ) );
}

function isRgbColour( colour )
{
return colour.match( rgbRegex ) !== null;
}

function hexToRgba( hex, opacity )
{
function toComponent( digits )
Expand Down Expand Up @@ -322,6 +328,7 @@ function formatExportPath( template, dateTime )

module.exports.init = init;
module.exports.isHexColour = isHexColour;
module.exports.isRgbColour = isRgbColour;
module.exports.hexToRgba = hexToRgba;
module.exports.removeBlockComments = removeBlockComments;
module.exports.removeLineComments = removeLineComments;
Expand Down
13 changes: 13 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ QUnit.test( "utils.isHexColour strips non RGB values", function( assert )
assert.ok( utils.isHexColour( "ace" ) === true );
} );

QUnit.test( "utils.isRgbColour", function( assert )
{
assert.ok( utils.isRgbColour( "" ) == false );
assert.ok( utils.isRgbColour( "rgb(0,0,0)" ) == true );
assert.ok( utils.isRgbColour( "rgba(0,0,0)" ) == true );
assert.ok( utils.isRgbColour( "rgb(255,255,255)" ) == true );
assert.ok( utils.isRgbColour( "rgb(x,0,0)" ) == false );
assert.ok( utils.isRgbColour( "rgba(0,0,0,0.5)" ) == true );
assert.ok( utils.isRgbColour( "rgba(0, 0, 0, 0.5)" ) == true );
assert.ok( utils.isRgbColour( "rgba(0,0.5,0,0.5)" ) == false );
assert.ok( utils.isRgbColour( "rgxba(0,0,0,0.5)" ) == false );
} );

QUnit.test( "utils.removeBlockComments strips block comments based on filename", function( assert )
{
assert.equal( utils.removeBlockComments( "/* a */", "x.cpp" ), " a " );
Expand Down

0 comments on commit 1e1edf1

Please sign in to comment.