2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-13 14:13:06 +00:00

refactor(eslint): refactored away mix type errors

@typescript-eslint/restrict-plus-operands
This commit is contained in:
Ramy Melo 2022-03-04 16:18:02 -05:00
parent e5e4ddf49e
commit fa01bbe962
4 changed files with 46 additions and 20 deletions

View File

@ -435,7 +435,11 @@ export function colorToString(color: Color): string {
}
case 'hsl': {
const list = [color.h, color.s + '%', color.l + '%'];
const list = [
color.h,
color.s.toString() + '%',
color.l.toString() + '%',
];
if (color.alpha !== 1) {
list.push(color.alpha);
}
@ -445,17 +449,17 @@ export function colorToString(color: Color): string {
}
case 'lab': {
const list = [color.l + '%', color.a, color.b];
const list = [color.l.toString() + '%', color.a, color.b];
if (color.alpha !== 1) {
list.push('/ ' + color.alpha);
list.push('/ ' + color.alpha.toString());
}
return 'lab(' + list.join(' ') + ')';
}
case 'lch': {
const list = [color.l + '%', color.c, color.h];
const list = [color.l.toString() + '%', color.c, color.h];
if (color.alpha !== 1) {
list.push('/ ' + color.alpha);
list.push('/ ' + color.alpha.toString());
}
return 'lch(' + list.join(' ') + ')';
}

View File

@ -102,9 +102,9 @@ export function iconToSVG(
// Horizontal flip
transformations.push(
'translate(' +
(box.width + box.left) +
(box.width + box.left).toString() +
' ' +
(0 - box.top) +
(0 - box.top).toString() +
')'
);
transformations.push('scale(-1 1)');
@ -114,9 +114,9 @@ export function iconToSVG(
// Vertical flip
transformations.push(
'translate(' +
(0 - box.left) +
(0 - box.left).toString() +
' ' +
(box.height + box.top) +
(box.height + box.top).toString() +
')'
);
transformations.push('scale(1 -1)');
@ -133,7 +133,11 @@ export function iconToSVG(
// 90deg
tempValue = box.height / 2 + box.top;
transformations.unshift(
'rotate(90 ' + tempValue + ' ' + tempValue + ')'
'rotate(90 ' +
tempValue.toString() +
' ' +
tempValue.toString() +
')'
);
break;
@ -141,9 +145,9 @@ export function iconToSVG(
// 180deg
transformations.unshift(
'rotate(180 ' +
(box.width / 2 + box.left) +
(box.width / 2 + box.left).toString() +
' ' +
(box.height / 2 + box.top) +
(box.height / 2 + box.top).toString() +
')'
);
break;
@ -152,7 +156,11 @@ export function iconToSVG(
// 270deg
tempValue = box.width / 2 + box.left;
transformations.unshift(
'rotate(-90 ' + tempValue + ' ' + tempValue + ')'
'rotate(-90 ' +
tempValue.toString() +
' ' +
tempValue.toString() +
')'
);
break;
}
@ -214,8 +222,8 @@ export function iconToSVG(
}
// Convert to string
width = typeof width === 'string' ? width : width + '';
height = typeof height === 'string' ? height : height + '';
width = typeof width === 'string' ? width : width.toString() + '';
height = typeof height === 'string' ? height : height.toString() + '';
// Result
const result: IconifyIconBuildResult = {
@ -224,7 +232,13 @@ export function iconToSVG(
height,
preserveAspectRatio: preserveAspectRatio(customisations),
viewBox:
box.left + ' ' + box.top + ' ' + box.width + ' ' + box.height,
box.left.toString() +
' ' +
box.top.toString() +
' ' +
box.width.toString() +
' ' +
box.height.toString(),
},
body,
};

View File

@ -52,7 +52,9 @@ export function replaceIDs(
// Replace with unique ids
ids.forEach((id) => {
const newID =
typeof prefix === 'function' ? prefix(id) : prefix + counter++;
typeof prefix === 'function'
? prefix(id)
: prefix + (counter++).toString();
const escapedID = id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

View File

@ -9,7 +9,9 @@ describe('Testing replaceIDs', () => {
// Using callback
let counter = 0;
expect(replaceIDs(body, () => 'callback' + counter++)).toBe(expected);
expect(
replaceIDs(body, () => 'callback' + (counter++).toString())
).toBe(expected);
});
test('Many IDs', () => {
@ -23,7 +25,9 @@ describe('Testing replaceIDs', () => {
// Using callback
let counter = 0;
expect(replaceIDs(body, () => 'callbackID' + counter++)).toBe(
expect(
replaceIDs(body, () => 'callbackID' + (counter++).toString())
).toBe(
body
.replace(/ssvg-id-1st-place-medala/g, 'callbackID0')
.replace(/ssvg-id-1st-place-medalb/g, 'callbackID7')
@ -70,7 +74,9 @@ describe('Testing replaceIDs', () => {
// To avoid messing up counter, using custom callback
let counter = 0;
expect(replaceIDs(body, () => 'callbackID' + counter++)).toBe(
expect(
replaceIDs(body, () => 'callbackID' + (counter++).toString())
).toBe(
body
.replace(/ssvg-id-compassa/g, 'callbackID2')
.replace(/ssvg-id-compassb/g, 'callbackID0')