Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Firstname Lastname committed Sep 27, 2020
1 parent aedbf20 commit faca384
Show file tree
Hide file tree
Showing 190 changed files with 74 additions and 3,214 deletions.
20 changes: 20 additions & 0 deletions __tests__/frameworks/string/convertRgbaToHex.test.ts
@@ -0,0 +1,20 @@
import { convertRgbaToHex } from '../../../bin/frameworks/string/convertRgbaToHex';

describe('Failure cases', () => {
test('It should throw an error if no argument is provided', () => {
expect(() => {
// @ts-ignore
convertRgbaToHex();
}).toThrow();
});
});

describe('Success cases', () => {
test('It should correctly return a hexadecimal color value from an RGBA color value', () => {
expect(convertRgbaToHex('rgba(7,75,114,1)')).toBe('#074b72');
});

test('It should correctly return a hexadecimal color value from an RGB color value, defaulting to alpha 1', () => {
expect(convertRgbaToHex('rgba(7,75,114)')).toBe('#074b72');
});
});
14 changes: 13 additions & 1 deletion bin/entities/FigmagicElement/logic/getTokenMatch.ts
Expand Up @@ -3,6 +3,7 @@ import { Imports } from '../../../contracts/Imports';
import { TokenMatch } from '../../../contracts/TokenMatch';

import { normalizeUnits } from '../../../frameworks/string/normalizeUnits';
import { convertRgbaToHex } from '../../../frameworks/string/convertRgbaToHex';

import { MsgGetTokenMatchNoMatch } from '../../../frameworks/messages/messages';
import { ErrorGetTokenMatch, ErrorGetTokenMatchNoRemSize } from '../../../frameworks/errors/errors';
Expand Down Expand Up @@ -144,7 +145,12 @@ function matchOther(

// Write expected value as-is, since we couldn't match it to a token
if (!foundMatch) {
console.log(`${MsgGetTokenMatchNoMatch} ${property}: ${expectedValue}`);
let notFoundMessage = `${MsgGetTokenMatchNoMatch} ${property}: ${expectedValue}`;
if (property === 'color' || property === 'background-color')
notFoundMessage += ` (HEX: ${convertRgbaToHex(
expectedValue as string
)}, ${getAlphaInPercent(expectedValue as string)})`;
console.log(notFoundMessage);
css += `${property}: ${expectedValue};\n`;
}

Expand All @@ -153,3 +159,9 @@ function matchOther(
throw new Error(error);
}
}

const getAlphaInPercent = (color: string): string => {
const SECTIONED = color.split(',');
// @ts-ignore
return SECTIONED[SECTIONED.length - 1].replace(/ /gi, '').replace(')', '') * 100 + '%';
};
3 changes: 3 additions & 0 deletions bin/frameworks/errors/errors.ts
Expand Up @@ -14,6 +14,9 @@ export const ErrorCleanArrays = ErrorMessage(
export const ErrorConvertHexToRgba = ErrorMessage(
'Missing one or more of red, green, blue and alpha in convertHexToRgba()!'
);
export const ErrorConvertRgbaToHex = ErrorMessage(
'Missing color value (as string, like "rgba(123,123,123,0.05) when calling convertRgbaToHex()!'
);
export const ErrorCreateConfiguration = ErrorMessage('No path provided to createConfiguration()!');
export const ErrorCreateConfigurationNoDefault = ErrorMessage(
'No default configuration provided to createConfiguration()!'
Expand Down
25 changes: 25 additions & 0 deletions bin/frameworks/string/convertRgbaToHex.ts
@@ -0,0 +1,25 @@
import { ErrorConvertRgbaToHex } from '../../frameworks/errors/errors';

// @see https://stackoverflow.com/questions/15898740/how-to-convert-rgba-to-a-transparency-adjusted-hex

export function convertRgbaToHex(color: string): string {
if (!color) throw new Error(ErrorConvertRgbaToHex);

const VALUES: any = color
.replace(/rgba?\(/, '')
.replace(/\)/, '')
.replace(/[\s+]/g, '')
.split(',');

const A: number = parseFloat(VALUES[3] || 1),
R = Math.floor(A * parseInt(VALUES[0]) + (1 - A) * 255),
G = Math.floor(A * parseInt(VALUES[1]) + (1 - A) * 255),
B = Math.floor(A * parseInt(VALUES[2]) + (1 - A) * 255);

return (
'#' +
('0' + R.toString(16)).slice(-2) +
('0' + G.toString(16)).slice(-2) +
('0' + B.toString(16)).slice(-2)
);
}
3 changes: 0 additions & 3 deletions dist/bin/contracts/Config.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Config.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Css.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Css.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Figma.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Figma.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/FigmaData.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/FigmaData.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/FigmaElement.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/FigmaElement.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/FigmagicElement.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/FigmagicElement.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/FileList.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/FileList.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/ImageResponse.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/ImageResponse.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Imports.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Imports.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Metadata.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Metadata.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/ParsedElementMetadataInterface.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/ParsedElementMetadataInterface.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/PrepFile.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/PrepFile.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/ProcessedToken.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/ProcessedToken.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Templates.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Templates.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/TextElement.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/TextElement.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/TokenMatch.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/TokenMatch.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Tokens.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Tokens.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions dist/bin/contracts/Write.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/contracts/Write.js.map

This file was deleted.

27 changes: 0 additions & 27 deletions dist/bin/controllers/FigmagicController.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/controllers/FigmagicController.js.map

This file was deleted.

45 changes: 0 additions & 45 deletions dist/bin/entities/Config/baseConfig.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/entities/Config/baseConfig.js.map

This file was deleted.

40 changes: 0 additions & 40 deletions dist/bin/entities/Config/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/bin/entities/Config/index.js.map

This file was deleted.

0 comments on commit faca384

Please sign in to comment.