benjycui / omit.js Goto Github PK
View Code? Open in Web Editor NEWUtility function to create a shallow copy of an object which had dropped some fields.
License: MIT License
Utility function to create a shallow copy of an object which had dropped some fields.
License: MIT License
When bundling with webpack.
// import omit from 'omit.js'; <== works
// const omit = require('omit.js').default; <== works
// const omit = require('omit.js'); <== does NOT work
console.log(omit({ foo: 'foo', bar: 'bar' }, ['bar']));
May just want to better support commonjs - if a library uses this package internally and requires it via require('omit.js') - and then webpack is used to bundle the lib omit will always be undefined.
I ran into this issue when trying to bundle cabin with webpack and omit would always be undefined. The author switched to lodash/omit to remedy the issue.
May be could use the code blow to delete nested objects' key
function omit(obj, fields) {
const keySet = new Set(fields);
const shallowCopy = Object.assign({}, obj);
deleteKey(shallowCopy);
return shallowCopy;
function deleteKey(obj) {
Object.keys(obj).forEach((key) => {
if (keySet.has(key)) {
delete obj[key];
} else if (
Object.prototype.toString.call(obj[key]) === "[object Object]"
) {
deleteKey(obj[key]);
}
});
}
}
随手一看测试用例,还以为自己理解错了。
This package should be pre-compiled with babel
when it is published to npm.
https://github.com/benjycui/omit.js/blob/master/package.json#L41
Also there is a deprecation warning due to omit.js
using babel-runtime
versus @babel/runtime
:
omit.js > babel-runtime > [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.