Skip to content

Commit

Permalink
chore: minor syntax changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberalien committed Nov 29, 2023
1 parent 637a11f commit ae960d7
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 53 deletions.
8 changes: 4 additions & 4 deletions @iconify/tools/src/colors/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function detectIconSetPalette(iconSet: IconSet): boolean | null {

// Check color
const isColor = color.type !== 'current';
if (iconPalette === void 0) {
if (iconPalette === undefined) {
// First entry: assign it
iconPalette = isColor;
return color;
Expand All @@ -51,12 +51,12 @@ export function detectIconSetPalette(iconSet: IconSet): boolean | null {
},
});

if (iconPalette === void 0) {
if (iconPalette === undefined) {
// No colors found
iconPalette = null;
}

if (palette === void 0) {
if (palette === undefined) {
// First icon
palette = iconPalette;
} else if (palette !== iconPalette) {
Expand All @@ -67,5 +67,5 @@ export function detectIconSetPalette(iconSet: IconSet): boolean | null {
['icon']
);

return palette === void 0 ? null : palette;
return palette ?? null;
}
16 changes: 8 additions & 8 deletions @iconify/tools/src/colors/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function parseColors(
) as ExtendedTagElementWithColors;

const color = element._colors?.[prop];
if (color !== void 0) {
if (color !== undefined) {
return color;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ export function parseColors(
// Remove entry
switch (callbackResult) {
case 'remove': {
return item ? callbackResult : void 0;
return item ? callbackResult : undefined;
}

case 'unset':
Expand Down Expand Up @@ -305,14 +305,14 @@ export function parseColors(
parseSVGStyle(svg, (item) => {
const prop = item.prop;
const value = item.value;
if (propsToCheck.indexOf(prop) === -1) {
if (!propsToCheck.includes(prop)) {
return value;
}

// Color
const attr = prop as ColorAttributes;
const newValue = checkColor(attr, value);
if (newValue === void 0) {
if (newValue === undefined) {
return newValue;
}

Expand Down Expand Up @@ -396,10 +396,10 @@ export function parseColors(
}

const value = attribs[prop];
if (value !== void 0) {
if (value !== undefined) {
const newValue = checkColor(prop, value, element);
if (newValue !== value) {
if (newValue === void 0) {
if (newValue === undefined) {
// Unset
cheerio(element).removeAttr(prop);
if (element._colors) {
Expand All @@ -421,7 +421,7 @@ export function parseColors(
// Check animations
if (animateTags.has(tagName)) {
const attr = attribs.attributeName as ColorAttributes;
if (propsToCheck.indexOf(attr) !== -1) {
if (propsToCheck.includes(attr)) {
// Valid property
for (let i = 0; i < animatePropsToCheck.length; i++) {
const elementProp = animatePropsToCheck[i];
Expand All @@ -435,7 +435,7 @@ export function parseColors(
let updatedValues = false;
for (let j = 0; j < splitValues.length; j++) {
const value = splitValues[j];
if (value !== void 0) {
if (value !== undefined) {
const newValue = checkColor(
elementProp as ColorAttributes,
value
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/download/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function downloadGitRepo(
const { remote, branch } = options;

// Check for last commit
const hasHashInTarget = options.target.indexOf('{hash}') !== -1;
const hasHashInTarget = options.target.includes('{hash}');
const ifModifiedSince = options.ifModifiedSince;
if (ifModifiedSince || hasHashInTarget) {
// Get actual hash
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/export/icon-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function exportIconPackage(
description ||
`Iconify icon components for ${info ? info.name : iconSet.prefix}`,
version,
type: esm ? 'module' : void 0,
type: esm ? 'module' : undefined,
iconSetInfo: info,
...customPackageProps,
dependencies: dependencies || {
Expand Down
8 changes: 4 additions & 4 deletions @iconify/tools/src/export/json-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export async function exportJSONPackage(
icons: exportedJSON.icons,
};
iconsKeys.forEach((attr) => {
if (exportedJSON[attr] !== void 0) {
if (exportedJSON[attr] !== undefined) {
icons[attr as 'aliases'] = exportedJSON[attr as 'aliases'];
}
});
Expand All @@ -97,11 +97,11 @@ export async function exportJSONPackage(
prefix: iconSet.prefix,
...exportedJSON.info,
}
: void 0;
: undefined;
const contents: ExportContents = {
icons,
info,
metadata: hasMetadata ? metadata : void 0,
metadata: hasMetadata ? metadata : undefined,
chars: exportedJSON.chars,
};

Expand Down Expand Up @@ -160,7 +160,7 @@ export async function exportJSONPackage(
cjsExports.push(`exports.${attr} = ${attr};`);
mjsExports.push(attr);

if (data !== void 0) {
if (data !== undefined) {
// Save JSON file
await writeJSONFile(`${dir}/${jsonFilename}`, data);

Expand Down
11 changes: 5 additions & 6 deletions @iconify/tools/src/icon-set/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class IconSet {

// Info
const info = data.info && convertIconSetInfo(data.info);
this.info = info || void 0;
this.info = info || undefined;

// Characters map
if (data.chars) {
Expand Down Expand Up @@ -242,10 +242,9 @@ export class IconSet {
* List icons
*/
list(types: IconSetIconType[] = ['icon', 'variation']): string[] {
return Object.keys(this.entries).filter((name) => {
const type = this.entries[name].type;
return types.indexOf(type) !== -1;
});
return Object.keys(this.entries).filter((name) =>
types.includes(this.entries[name].type)
);
}

/**
Expand Down Expand Up @@ -323,7 +322,7 @@ export class IconSet {
return (resolved[name] = []);
}

if (resolved[name] === void 0) {
if (resolved[name] === undefined) {
// Mark as failed if parent alias points to this icon to avoid infinite loop
resolved[name] = null;

Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/icon-set/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function addTagsToIconSet(
if (iconNames.length) {
// Palette
let hasPalette: boolean | null | undefined = info?.palette;
if (hasPalette === void 0) {
if (hasPalette === undefined) {
hasPalette = detectIconSetPalette(iconSet);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ export function addTagsToIconSet(
}

// Check grid
if (height === void 0) {
if (height === undefined) {
height = iconHeight;
} else if (height && iconHeight !== height) {
// Failed
Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/import/figma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ export async function importFromFigma(
ttl: options.cacheAPITTL || 60 * 60 * 24,
dir: options.cacheDir,
}
: void 0;
: undefined;

const cacheSVGOptions: APICacheOptions | undefined = options.cacheDir
? {
// 30 days
ttl: options.cacheSVGTTL || 60 * 60 * 24 * 30,
dir: options.cacheDir,
}
: void 0;
: undefined;

// Get document
const document = await figmaFilesQuery(
Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/import/figma/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export function getFigmaIconNodes(
// Check page against allowed pages list
const allowedPages = options.pages;
if (
allowedPages.indexOf(node.id) === -1 &&
allowedPages.indexOf(node.name.trim()) === -1
!allowedPages.includes(node.id) &&
!allowedPages.includes(node.name.trim())
) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions @iconify/tools/src/misc/compare-dirs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export async function compareDirectories(
// Check all files
for (let i = 0; i < files1.length; i++) {
const file = files1[i];
if (files2.indexOf(file) === -1) {
if (!files2.includes(file)) {
return false;
}

Expand All @@ -85,8 +85,8 @@ export async function compareDirectories(
}
if (ignoreNewLine) {
// Remove space before new line (\r\n -> \n), remove new line at the end
content1 = content1.replace(/\s+\n/g, '\n').trimRight();
content2 = content2.replace(/\s+\n/g, '\n').trimRight();
content1 = content1.replace(/\s+\n/g, '\n').trimEnd();
content2 = content2.replace(/\s+\n/g, '\n').trimEnd();
}
if (ignoreVersions && file.split('/').pop() === 'package.json') {
// Ignore versions in package.json
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/misc/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function split(filename: string): SplitResult {
}

function isIgnoredResult(result: unknown) {
return result === void 0 || result === false || result === null;
return result === undefined || result === false || result === null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/optimise/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function cleanPath(path: string): string {
}

// No space if previous entry had dot
if (item.params[index - 1].indexOf('.') !== -1) {
if (item.params[index - 1].includes('.')) {
break;
}

Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/optimise/global-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function cleanupGlobalStyle(svg: SVG) {
const className = $element.attr('class');
if (
className &&
getClassList(className).indexOf(value) !== -1
getClassList(className).includes(value)
) {
return true;
}
Expand All @@ -148,7 +148,7 @@ export function cleanupGlobalStyle(svg: SVG) {
);

const prop = styleItem.prop;
if ($element.attr(prop) !== void 0) {
if ($element.attr(prop) !== undefined) {
// Previously added attribute?
if (addedAttributes.has(prop)) {
// Two CSS rules are applied to same element: abort parsing and restore content from backup.
Expand Down
5 changes: 2 additions & 3 deletions @iconify/tools/src/optimise/svgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export function runSVGO(svg: SVG, options: SVGOOptions = {}) {
plugins = options.plugins;
} else {
// Check for animations: convertShapeToPath and removeHiddenElems plugins currently might ruin animations
const animated =
code.indexOf('<animate') !== -1 || code.indexOf('<set') !== -1;
const animated = code.includes('<animate') || code.includes('<set');

plugins = getSVGOPlugins({
...options,
Expand Down Expand Up @@ -154,7 +153,7 @@ export function runSVGO(svg: SVG, options: SVGOOptions = {}) {
// Replace IDs, but only if plugins list is not set
if (!options.plugins) {
const prefix =
options.cleanupIDs !== void 0 ? options.cleanupIDs : 'svgID';
options.cleanupIDs !== undefined ? options.cleanupIDs : 'svgID';
if (prefix !== false) {
let counter = 0;
content = replaceIDs(
Expand Down
4 changes: 2 additions & 2 deletions @iconify/tools/src/svg/analyse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export function analyseSVGStructure(
}

// Check if element has its own id
if (element._id === void 0) {
if (element._id === undefined) {
const id = attribs['id'];
if (typeof id === 'string') {
if (ids[id] && fixErrors) {
Expand Down Expand Up @@ -404,7 +404,7 @@ export function analyseSVGStructure(

// Add all child elements
element._childElements?.forEach((childIndex) => {
if (usedItems.indexOf(childIndex) !== -1) {
if (usedItems.includes(childIndex)) {
throw new Error('Recursion');
}
const childItem: ElementsTreeItem = {
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/svg/cleanup/attribs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function removeBadAttributes(svg: SVG): void {
switch (namespace) {
case 'xlink': {
// Deprecated: use without namespace
if (attribs[newAttr] === void 0) {
if (attribs[newAttr] === undefined) {
$element.attr(newAttr, attribs[attr]);
}
break;
Expand Down
2 changes: 1 addition & 1 deletion @iconify/tools/src/svg/cleanup/svgo-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function convertStyleToAttrs(svg: SVG): void {
badSoftwareAttributes.has(prop) ||
badAttributePrefixes.has(prop.split('-').shift() as string)
) {
return void 0;
return;
}

hasStyle = true;
Expand Down
10 changes: 5 additions & 5 deletions @iconify/tools/src/svg/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class SVG {

// Generate SVG
let svgAttributes = ' xmlns="http://www.w3.org/2000/svg"';
if (data.body.indexOf('xlink:') !== -1) {
if (data.body.includes('xlink:')) {
svgAttributes += ' xmlns:xlink="http://www.w3.org/1999/xlink"';
}
for (const key in data.attributes) {
Expand All @@ -60,18 +60,18 @@ export class SVG {
const box = this.viewBox;

// Add missing viewBox attribute
if ($root.attr('viewBox') === void 0) {
if ($root.attr('viewBox') === undefined) {
$root.attr(
'viewBox',
`${box.left} ${box.top} ${box.width} ${box.height}`
);
}

// Add missing width/height
if ($root.attr('width') === void 0) {
if ($root.attr('width') === undefined) {
$root.attr('width', box.width.toString());
}
if ($root.attr('height') === void 0) {
if ($root.attr('height') === undefined) {
$root.attr('height', box.height.toString());
}

Expand Down Expand Up @@ -176,7 +176,7 @@ export class SVG {

// Get dimensions and origin
const viewBox = $root.attr('viewBox');
if (viewBox !== void 0) {
if (viewBox !== undefined) {
const list = viewBox.split(' ');

this.viewBox = {
Expand Down
Loading

0 comments on commit ae960d7

Please sign in to comment.