34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
/**
|
|
* Tiny helper to do the minimal amount of work in duplicating an object but omitting some
|
|
* props. This ends up faster than using object ...rest or reduce to filter.
|
|
*
|
|
* This behaves very much like filteredAssign, but does not merge many objects together,
|
|
* uses an exclusion object map, and avoids spreads all for optimal performance.
|
|
*
|
|
* See perf test for background:
|
|
* https://jsperf.com/omit-vs-rest-vs-reduce/1
|
|
*
|
|
* @param obj - The object to clone
|
|
* @param exclusions - The array of keys to exclude
|
|
*/ // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
"use strict";
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
Object.defineProperty(exports, "omit", {
|
|
enumerable: true,
|
|
get: function() {
|
|
return omit;
|
|
}
|
|
});
|
|
function omit(obj, exclusions) {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const result = {};
|
|
for(const key in obj){
|
|
if (exclusions.indexOf(key) === -1 && obj.hasOwnProperty(key)) {
|
|
result[key] = obj[key];
|
|
}
|
|
}
|
|
return result;
|
|
}
|