Skip to content

Commit

Permalink
Updated opacity value type
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed May 27, 2018
1 parent 6d4bded commit 5fa8122
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@
"description": "%configuration.folders.color%"
},
"material-icon-theme.opacity": {
"type": "string",
"default": "1",
"type": "number",
"default": 1,
"minimum": 0,
"maximum": 1,
"description": "%configuration.opacity%"
},
"material-icon-theme.hidesExplorerArrows": {
Expand Down
10 changes: 5 additions & 5 deletions src/icons/generator/iconOpacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import * as path from 'path';
* Changes the opacity of all icons in the set.
* @param opacity Opacity value
*/
export const setIconOpacity = (opacity: string) => {
export const setIconOpacity = (opacity: number) => {
if (!validateOpacityValue(opacity)) {
return Promise.reject('Invalid opacity value! Opacity must be a decimal number between 0 and 1!');
return console.error('Invalid opacity value! Opacity must be a decimal number between 0 and 1!');
}

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -55,8 +55,8 @@ export const setIconOpacity = (opacity: string) => {
* Validate the opacity value.
* @param opacity Opacity value
*/
export const validateOpacityValue = (opacity: string) => {
return +opacity >= 0 && +opacity <= 1;
export const validateOpacityValue = (opacity: number) => {
return opacity <= 1 && opacity >= 0;
};

/**
Expand All @@ -77,7 +77,7 @@ const getSVGRootElement = (svg: string) => {
* @param svgRoot Root element of the SVG icon.
* @param opacity Opacity value.
*/
const addOpacityAttribute = (svgRoot: string, opacity: string) => {
const addOpacityAttribute = (svgRoot: string, opacity: number) => {
const pattern = new RegExp(/\sopacity="[\d.]+"/);
// if the opacity attribute already exists
if (pattern.test(svgRoot)) {
Expand Down
4 changes: 2 additions & 2 deletions src/icons/generator/jsonGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const generateIconConfigurationObject = (options: IconJsonOptions): IconC
*/
export const createIconFile = async (jsonOptions?: IconJsonOptions) => {
// override the default options with the new options
const options = merge({}, getDefaultIconOptions(), jsonOptions);
const options: IconJsonOptions = merge({}, getDefaultIconOptions(), jsonOptions);

const iconJSONPath = path.join(__dirname, '../../../', 'src', iconJsonName);
const json = generateIconConfigurationObject(options);
Expand Down Expand Up @@ -59,7 +59,7 @@ export const getDefaultIconOptions = (): IconJsonOptions => ({
},
activeIconPack: 'angular',
hidesExplorerArrows: false,
opacity: '1',
opacity: 1,
files: { associations: {} },
languages: { associations: {} },
});
2 changes: 1 addition & 1 deletion src/models/icons/iconJsonOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface IconJsonOptions {
activeIconPack?: string;
hidesExplorerArrows?: boolean;
opacity?: string;
opacity?: number;
folders?: {
theme?: string;
color?: string;
Expand Down

0 comments on commit 5fa8122

Please sign in to comment.