mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-12-18 06:45:04 +01:00
[ADD] objectDeepMerge function
Recursively merges properties from source objects into a target object. If a property at the current level is an object, and both target and source have it, the property is merged. Otherwise, the source property overwrites the target property. This function does not modify the source objects and prevents prototype pollution by not allowing `__proto__`, `constructor`, and `prototype` property names.
This commit is contained in:
@@ -100,3 +100,25 @@ fetchPost({
|
||||
- `csrfToken`: The CSRF token to include in the request headers.
|
||||
- `payload`: The data as JS object to send with the request.
|
||||
- `responseIsJson`: Optional boolean indicating if the response should be parsed as JSON (default is `true`).
|
||||
|
||||
### objectDeepMerge()
|
||||
|
||||
Recursively merges properties from source objects into a target object. If a property at the current level is an object,
|
||||
and both target and source have it, the property is merged. Otherwise, the source property overwrites the target property.
|
||||
|
||||
This function does not modify the source objects and prevents prototype pollution by not allowing `__proto__`, `constructor`,
|
||||
and `prototype` property names.
|
||||
|
||||
Usage:
|
||||
|
||||
```javascript
|
||||
/* global objectDeepMerge */
|
||||
|
||||
const target = {a: 1, b: {c: 2}};
|
||||
const source1 = {b: {d: 3}, e: 4 };
|
||||
const source2 = {a: 5, b: {c: 6}};
|
||||
|
||||
const merged = objectDeepMerge(target, source1, source2);
|
||||
|
||||
console.log(merged); // {a: 5, b: {c: 6, d: 3}, e: 4}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user