build(deps): add eslint

This commit is contained in:
2024-03-12 19:42:00 +02:00
parent 85f365c528
commit ed72704c2f
14 changed files with 1287 additions and 244 deletions

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Capitalizes first character of the given string
@@ -23,6 +23,5 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
* @param string - string to modify
* @returns new string
*/
export const capitalizeFirstChar = (string: string) => {
return `${string[0].toUpperCase()}${string.slice(1)}`;
};
export const capitalizeFirstChar = (string: string) =>
`${string[0].toUpperCase()}${string.slice(1)}`;

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Conditionally joins given class strings

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Conditionally joins given strings

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Weakly compares two objects
@@ -26,6 +26,5 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
* @param obj2 - second object to compare with first
* @returns true if equal
*/
export const isDeepWeakEqual = (obj1: object, obj2: object) => {
return JSON.stringify(obj1) === JSON.stringify(obj2);
};
export const isDeepWeakEqual = (obj1: object, obj2: object) =>
JSON.stringify(obj1) === JSON.stringify(obj2);

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Returns a pseudo-random number in given range
@@ -28,6 +28,5 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
* @param max - maximum acceptable value
* @returns number [min; max]
*/
export const randomInRange = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min)) + min;
};
export const randomInRange = (min: number, max: number) =>
Math.floor(Math.random() * (max - min)) + min;

View File

@@ -1,27 +1,28 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Removes an object from an array by key value object.
*
* @remarks
* This method doesn't support deep comparements.
* Vulnerable to generic object injection sink
*
* @param array - array which shall be manipulated with
* @param keyValue - key-value object which defines which object shall be removed from the array
@@ -33,7 +34,8 @@ export const removeFromArrayByKeyValue = <T>(
) => {
const keys = Object.keys(keyValue) as Array<keyof T>;
return array.filter((item) => {
return !keys.every((key) => item[key] === keyValue[key]);
});
return array.filter(
// eslint-disable-next-line security/detect-object-injection -- warned at remarks
(item) => !keys.every((key) => item[key] === keyValue[key]),
);
};

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Removes an object property by provided key
@@ -24,7 +24,11 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
* @param key - key which should be used to remove a property from object
* @returns new object
*/
export const removeObjectProperty = <T>(object: T, key: keyof T) => {
export const removeObjectProperty = <T, K extends keyof T>(
object: T,
key: K,
): Omit<T, K> => {
// eslint-disable-next-line security/detect-object-injection -- delete operation is performed
delete object[key];
return object;
};

View File

@@ -1,27 +1,28 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Replaces an object from an array with key value object search
*
* @remarks
* This method doesn't support deep comparements.
* Vulnerable to generic object injection sink
*
* @param array - array which shall be manipulated with
* @param keyValue - key-value object which defines which object shall be removed from the array
@@ -35,11 +36,13 @@ export const replaceFromArrayByKeyValue = <T>(
) => {
const keys = Object.keys(keyValue) as Array<keyof T>;
const itemIndex = array.findIndex((item) => {
return !keys.every((key) => item[key] === keyValue[key]);
});
const itemIndex = array.findIndex(
(item) =>
// eslint-disable-next-line security/detect-object-injection -- warned at remarks
!keys.every((key) => item[key] === keyValue[key]),
);
array[itemIndex] = { ...array[itemIndex], ...newObject };
array[`${itemIndex}`] = { ...array[`${itemIndex}`], ...newObject };
return array;
};

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Splits an array into chunks
@@ -24,16 +24,15 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
* @param chunkSize - size of a single chunk
* @returns array of chunks
*/
export const splitIntoChunks = <T>(array: T[], chunkSize: number): T[][] => {
return array.reduce<T[][]>((splitArray, item, index) => {
export const splitIntoChunks = <T>(array: T[], chunkSize: number): T[][] =>
array.reduce<T[][]>((splitArray, item, index) => {
const chunkIndex = Math.floor(index / chunkSize);
if (!splitArray[chunkIndex]) {
splitArray[chunkIndex] = [];
if (!splitArray[`${chunkIndex}`]) {
splitArray[`${chunkIndex}`] = [];
}
splitArray[chunkIndex]?.push(item);
splitArray[`${chunkIndex}`]?.push(item);
return splitArray;
}, []);
};

View File

@@ -1,21 +1,21 @@
/*
Copyright 2024 Resultium LLC
This file is part of @resultium/utils.
@resultium/utils is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
@resultium/utils is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Copyright 2024 Resultium LLC
*
* This file is part of @resultium/utils.
*
* @resultium/utils is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* @resultium/utils is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RCZ. If not, see <https://www.gnu.org/licenses/>.
*/
export * from "./functions/capitalizeFirstChar";
export * from "./functions/classNames";