Skip to content

Commit

Permalink
Refactor code with nullish coalescing and optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
PKief committed Mar 15, 2020
1 parent 734b079 commit e4920f5
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/commands/folderColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ const validateColorInput = (colorInput: string) => {
export const checkFolderColorStatus = (): string => {
const defaultOptions = getDefaultIconOptions();
const config = helpers.getMaterialIconsJSON();
return config.options.folders.color === undefined ?
defaultOptions.folders.color : config.options.folders.color;
return config.options.folders.color ?? defaultOptions.folders.color;
};

const setColorConfig = (value: string) => {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/opacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const validateOpacityInput = (opacityInput: string) => {
export const getCurrentOpacityValue = (): number => {
const defaultOptions = getDefaultIconOptions();
const config = helpers.getMaterialIconsJSON();
return config.options.opacity === undefined ?
defaultOptions.opacity : config.options.opacity;
return config.options.opacity ?? defaultOptions.opacity;
};

const setOpacityConfig = (opacity: number) => {
Expand Down
3 changes: 1 addition & 2 deletions src/commands/saturation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const validateSaturationInput = (saturationInput: string) => {
export const getCurrentSaturationValue = (): number => {
const defaultOptions = getDefaultIconOptions();
const config = helpers.getMaterialIconsJSON();
return config.options.saturation === undefined ?
defaultOptions.saturation : config.options.saturation;
return config.options.saturation ?? defaultOptions.saturation;
};

const setSaturationConfig = (saturation: number) => {
Expand Down
4 changes: 2 additions & 2 deletions src/icons/generator/iconOpacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const setIconOpacity = (opacity: number, fileNames?: string[]) => {
* @param opacity Opacity value
*/
export const validateOpacityValue = (opacity: number) => {
return opacity !== null && opacity <= 1 && opacity >= 0;
return opacity !== undefined && opacity <= 1 && opacity >= 0;
};

/**
Expand All @@ -61,7 +61,7 @@ export const validateOpacityValue = (opacity: number) => {
*/
const getSVGRootElement = (svg: string) => {
const result = new RegExp(/<svg[^>]*>/).exec(svg);
return result.length > 0 ? result[0] : undefined;
return result?.[0];
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/icons/generator/iconSaturation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const setIconSaturation = (saturation: number, fileNames?: string[]) => {
*/
const getSVGRootElement = (svg: string) => {
const result = new RegExp(/<svg[^>]*>/).exec(svg);
return result.length > 0 ? result[0] : undefined;
return result?.[0];
};

/**
Expand Down Expand Up @@ -114,5 +114,5 @@ const removeFilterElement = (svg: string) => {
* @param saturation Saturation value
*/
export const validateSaturationValue = (saturation: number) => {
return saturation !== null && saturation <= 1 && saturation >= 0;
return saturation !== undefined && saturation <= 1 && saturation >= 0;
};
2 changes: 1 addition & 1 deletion src/scripts/contributors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const fetchContributors = (page: string): Promise<{ contributorsOfPage: Contribu
const buffer = Buffer.concat(result);
const bufferAsString = buffer.toString('utf8');
const contributorsOfPage = JSON.parse(bufferAsString);
resolve({ contributorsOfPage, nextPage: nextPage ? nextPage[1] : undefined });
resolve({ contributorsOfPage, nextPage: nextPage?.[1] });
} catch (error) {
reject(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/icons/checks/checkIconUsage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const getAllUsedFolderIcons = (): string[] => {
};

const getAllFolderIcons = (theme: FolderTheme): (FolderIcon | DefaultIcon)[] => {
const icons = theme.icons ? theme.icons : [];
const icons = theme.icons || [];
return [
theme.defaultIcon,
theme.rootFolder,
Expand Down

0 comments on commit e4920f5

Please sign in to comment.