revamp template
This commit is contained in:
26
src/utils/Object.ts
Normal file
26
src/utils/Object.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export const excludeKeys = (obj: any, keysToExclude: any) => {
|
||||
return Object.keys(obj).reduce((filteredObj: any, key) => {
|
||||
if (!keysToExclude.includes(key)) {
|
||||
filteredObj[key] = obj[key];
|
||||
}
|
||||
return filteredObj;
|
||||
}, {});
|
||||
};
|
||||
|
||||
export const changeValueImmutable = (obj: any, targetKey: any, sourceKey: any) => {
|
||||
if (obj.hasOwnProperty(sourceKey)) {
|
||||
return { ...obj, [targetKey]: obj[sourceKey] };
|
||||
}
|
||||
return obj;
|
||||
// Example usage:
|
||||
// const updatedImmutable = changeValueImmutable(original, 'name', 'location');
|
||||
};
|
||||
|
||||
export const updateKeyValueInArray = (arr: [], targetKey: any, sourceKey: any) => {
|
||||
return arr.map((obj: any) => {
|
||||
if (obj.hasOwnProperty(sourceKey)) {
|
||||
return { ...obj, [targetKey]: obj[sourceKey] };
|
||||
}
|
||||
return obj; // If sourceKey doesn't exist, return the object unchanged
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user