Skip to content

Commit

Permalink
feat: added helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Milfred committed Jun 10, 2024
1 parent 9fcbd2c commit 888f1a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions utils/objectExcept.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function objectExcept(obj, subset) {
if (!obj || !subset?.length) {
return {};
}

const subsetObject = { ...obj };
subset.forEach((key) => {
if (key in subsetObject) {
delete subsetObject[key];
}
});

return subsetObject;
}
14 changes: 14 additions & 0 deletions utils/objectSome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default function objectSome(obj, subset) {
if (!obj || !subset?.length) {
return {};
}

const subsetObject = {};
subset.forEach((key) => {
if (key in obj) {
subsetObject[key] = obj[key];
}
});

return subsetObject;
}

0 comments on commit 888f1a7

Please sign in to comment.