docs(typedoc): document function examples
This commit is contained in:
@@ -24,6 +24,16 @@
|
||||
* This method doesn't support deep comparements.
|
||||
* Vulnerable to generic object injection sink
|
||||
*
|
||||
* @example
|
||||
* ```ts
|
||||
* // prints [{ a: "1", b: "0" }, { a: "2", b: "0" }, { a: "3", b: "lorem" }]
|
||||
* console.log(replaceFromArrayByKeyValue([{ a: "1", b: "0" }, { a: "2", b: "0" }, { a: "3", b: "0" }], { a: "3" }, { b: "lorem" }))
|
||||
*
|
||||
* // prints [{ a: "lorem", b: "0" }, { a: "2", b: "0" }, { a: "3", b: "0" }]
|
||||
* // replaces only the first occurance
|
||||
* console.log(replaceFromArrayByKeyValue([{ a: "1", b: "0" }, { a: "2", b: "0" }, { a: "3", b: "0" }], { b: "0" }, { a: "lorem" }))
|
||||
* ```
|
||||
*
|
||||
* @param array - array which shall be manipulated with
|
||||
* @param keyValue - key-value object which defines which object shall be removed from the array
|
||||
* @param newObject - object or values to replace within the searched object
|
||||
@@ -36,10 +46,9 @@ export const replaceFromArrayByKeyValue = <T>(
|
||||
) => {
|
||||
const keys = Object.keys(keyValue) as Array<keyof T>;
|
||||
|
||||
const itemIndex = array.findIndex(
|
||||
(item) =>
|
||||
// eslint-disable-next-line security/detect-object-injection -- warned at remarks
|
||||
!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 };
|
||||
|
||||
Reference in New Issue
Block a user