build(deps): add eslint
This commit is contained in:
68
.eslintrc.cjs
Normal file
68
.eslintrc.cjs
Normal file
@@ -0,0 +1,68 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
parser: "@typescript-eslint/parser",
|
||||
parserOptions: {
|
||||
project: ["./tsconfig.json"],
|
||||
ecmaVersion: 2016,
|
||||
},
|
||||
plugins: ["@typescript-eslint", "prefer-arrow"],
|
||||
extends: [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
||||
"plugin:security/recommended-legacy",
|
||||
"prettier",
|
||||
],
|
||||
ignorePatterns: ["*.js"],
|
||||
env: {
|
||||
browser: true,
|
||||
es2016: true,
|
||||
node: true,
|
||||
},
|
||||
rules: {
|
||||
"@typescript-eslint/no-misused-promises": [
|
||||
"error",
|
||||
{ checksVoidReturn: false },
|
||||
],
|
||||
"@typescript-eslint/no-unsafe-argument": "off",
|
||||
"@typescript-eslint/naming-convention": [
|
||||
"error",
|
||||
{
|
||||
selector: "interface",
|
||||
format: ["PascalCase"],
|
||||
prefix: ["I"],
|
||||
},
|
||||
{
|
||||
selector: "typeLike",
|
||||
format: ["PascalCase"],
|
||||
},
|
||||
{
|
||||
selector: "variableLike",
|
||||
format: ["camelCase", "UPPER_CASE"],
|
||||
leadingUnderscore: "allow",
|
||||
},
|
||||
],
|
||||
"@typescript-eslint/prefer-ts-expect-error": "error",
|
||||
"prefer-arrow/prefer-arrow-functions": [
|
||||
"error",
|
||||
{
|
||||
disallowPrototype: true,
|
||||
singleReturnOnly: false,
|
||||
classPropertiesAllowed: false,
|
||||
},
|
||||
],
|
||||
eqeqeq: "error",
|
||||
curly: ["error", "all"],
|
||||
"no-console": ["warn", { allow: ["warn", "error"] }],
|
||||
"no-eval": "error",
|
||||
"brace-style": ["error", "1tbs"],
|
||||
"arrow-body-style": ["error", "as-needed"],
|
||||
"object-shorthand": ["error", "always"],
|
||||
"no-lonely-if": "error",
|
||||
"prefer-const": "error",
|
||||
"prefer-arrow-callback": "error",
|
||||
"no-var": "error",
|
||||
"default-case-last": "warn",
|
||||
"no-nested-ternary": "warn",
|
||||
},
|
||||
};
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
### Functions
|
||||
|
||||
- [SplitIntoChunks](modules.md#splitintochunks)
|
||||
- [capitalizeFirstChar](modules.md#capitalizefirstchar)
|
||||
- [classNames](modules.md#classnames)
|
||||
- [conditionalJoin](modules.md#conditionaljoin)
|
||||
@@ -15,40 +14,10 @@
|
||||
- [removeFromArrayByKeyValue](modules.md#removefromarraybykeyvalue)
|
||||
- [removeObjectProperty](modules.md#removeobjectproperty)
|
||||
- [replaceFromArrayByKeyValue](modules.md#replacefromarraybykeyvalue)
|
||||
- [splitIntoChunks](modules.md#splitintochunks)
|
||||
|
||||
## Functions
|
||||
|
||||
### SplitIntoChunks
|
||||
|
||||
▸ **SplitIntoChunks**\<`T`\>(`array`, `chunkSize`): `T`[][]
|
||||
|
||||
Splits an array into chunks
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name |
|
||||
| :------ |
|
||||
| `T` |
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `array` | `T`[] | array which shall be split into chunks |
|
||||
| `chunkSize` | `number` | size of a single chunk |
|
||||
|
||||
#### Returns
|
||||
|
||||
`T`[][]
|
||||
|
||||
array of chunks
|
||||
|
||||
#### Defined in
|
||||
|
||||
functions/splitIntoChuks.ts:27
|
||||
|
||||
___
|
||||
|
||||
### capitalizeFirstChar
|
||||
|
||||
▸ **capitalizeFirstChar**(`string`): `string`
|
||||
@@ -209,35 +178,37 @@ modified array
|
||||
**`Remarks`**
|
||||
|
||||
This method doesn't support deep comparements.
|
||||
Vulnerable to generic object injection sink
|
||||
|
||||
#### Defined in
|
||||
|
||||
functions/removeFromArrayByKeyValue.ts:30
|
||||
functions/removeFromArrayByKeyValue.ts:31
|
||||
|
||||
___
|
||||
|
||||
### removeObjectProperty
|
||||
|
||||
▸ **removeObjectProperty**\<`T`\>(`object`, `key`): `T`
|
||||
▸ **removeObjectProperty**\<`T`, `K`\>(`object`, `key`): `Omit`\<`T`, `K`\>
|
||||
|
||||
Removes an object property by provided key
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name |
|
||||
| :------ |
|
||||
| `T` |
|
||||
| Name | Type |
|
||||
| :------ | :------ |
|
||||
| `T` | `T` |
|
||||
| `K` | extends `string` \| `number` \| `symbol` |
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `object` | `T` | object which shall be manipulated |
|
||||
| `key` | keyof `T` | key which should be used to remove a property from object |
|
||||
| `key` | `K` | key which should be used to remove a property from object |
|
||||
|
||||
#### Returns
|
||||
|
||||
`T`
|
||||
`Omit`\<`T`, `K`\>
|
||||
|
||||
new object
|
||||
|
||||
@@ -276,7 +247,39 @@ modified array
|
||||
**`Remarks`**
|
||||
|
||||
This method doesn't support deep comparements.
|
||||
Vulnerable to generic object injection sink
|
||||
|
||||
#### Defined in
|
||||
|
||||
functions/replaceFromArrayByKeyValue.ts:31
|
||||
functions/replaceFromArrayByKeyValue.ts:32
|
||||
|
||||
___
|
||||
|
||||
### splitIntoChunks
|
||||
|
||||
▸ **splitIntoChunks**\<`T`\>(`array`, `chunkSize`): `T`[][]
|
||||
|
||||
Splits an array into chunks
|
||||
|
||||
#### Type parameters
|
||||
|
||||
| Name |
|
||||
| :------ |
|
||||
| `T` |
|
||||
|
||||
#### Parameters
|
||||
|
||||
| Name | Type | Description |
|
||||
| :------ | :------ | :------ |
|
||||
| `array` | `T`[] | array which shall be split into chunks |
|
||||
| `chunkSize` | `number` | size of a single chunk |
|
||||
|
||||
#### Returns
|
||||
|
||||
`T`[][]
|
||||
|
||||
array of chunks
|
||||
|
||||
#### Defined in
|
||||
|
||||
functions/splitIntoChuks.ts:27
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
"build": "pnpm run build:package && pnpm run build:docs",
|
||||
"build:package": "rm -rf dist && tsc --module ESNext --outdir dist/esm && tsc --module commonjs --outdir dist/cjs",
|
||||
"build:docs": "typedoc --plugin typedoc-plugin-markdown src",
|
||||
"prepublish": "pnpm run build"
|
||||
"prepublish": "pnpm run build",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -29,6 +30,12 @@
|
||||
"license": "GPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.25",
|
||||
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
||||
"@typescript-eslint/parser": "^7.2.0",
|
||||
"eslint": "^8.57.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-prefer-arrow": "^1.2.3",
|
||||
"eslint-plugin-security": "^2.1.1",
|
||||
"prettier": "^3.2.5",
|
||||
"typedoc": "^0.25.12",
|
||||
"typedoc-plugin-markdown": "^3.17.1",
|
||||
|
||||
960
pnpm-lock.yaml
generated
960
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -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)}`;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -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);
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -22,6 +22,7 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @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]),
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -22,6 +22,7 @@ along with RCZ. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @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;
|
||||
};
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -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;
|
||||
}, []);
|
||||
};
|
||||
|
||||
34
src/index.ts
34
src/index.ts
@@ -1,20 +1,20 @@
|
||||
/*
|
||||
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";
|
||||
|
||||
Reference in New Issue
Block a user