schnittstabil / merge-options Goto Github PK
View Code? Open in Web Editor NEWMerge Option Objects
License: MIT License
Merge Option Objects
License: MIT License
v3 of this module refactored to use esm modules and set the engines field to require node >= 14, yet this module is published transpiled to common js so does run on node 12 at least.
If a user has engine-strict = true or is running yarn, it'll fail to install on node 12 even though it will run.
Can the engines field be relaxed? Node 12 is active LTS for another few months and maintenance LTS until spring 2022 so dropping support seems premature.
Refs: ipfs/js-ipfs#3270
Hello,
I'd like to use this package with TypeScript, but it's actually impossible, because there isn't any .d.ts
file... It would be nice to add them!
Based on the following code:
const merge = require('merge-options');
const result = merge({value: 10}, {value: undefined});
result.value
should be '10', but it is 'undefined'.
Whether it really should return 10 is arguable, so my argument is that {}
is functionally equivalent to {value: undefined}
when getting a value from on object, so as inputs to merge they should both provide equivalent output. Where they are not functionally equivalent is when iterating the objects keys, but when dealing with options (and being mindful if the distinction between undefined and null) the rule of least surprise (for me at least) is to completely ignore undefined values (but still allow null values to supersede values of lower precedence).
The practical application of this is putting environment variables (which may or may not be defined) as the highest precedence item in the merge, but only if it has been defined.
const port = merge(defaults, {port: process.env.PORT});
Hey,
Thanks for the package. I noticed that your es6 in 1.0.0 is not transpiled down to es5. I would suggest using babel to output a dist because most people (like me) ignore node_modules for the transpilation process. Ignoring node_modules helps speed up the build by orders of magnitude.
Cheers!
I would say this module is pretty stable now, perhaps could you release 1.0.0?
Thanks <3
Has this been brought to your attention? https://snyk.io/test/npm/merge-options?severity=high&severity=medium&severity=low
I received in my inbox this morning since I depend on this for my nixconfig
package. It does not look like any activity has taken place in this repository around this report, so I can't tell if anyone even told you about it.
Note: since it is published, I didn't see any reason to use a more private form of communication.
I'm looking for a "deep" Object.assign() that just like object assign will merge things onto the first Param. However, I need this first param (the target) to "be modified" (just like Object.assign) and not become a hard-clone.
Is this possible with your library?
I'd like to propose a method to handle array values differently. It's something that I find lacking in every single merge/deep-copy/extend/assign library I can find; none of them provide a means to concat array values rather than simple overriding them.
It could be possible to create a factory pattern that accepted options for determining behavior. e.g.
const merge = mergeOptions.set({ arrays: 'concat' });
const result = merge({}, {a:[3]}, {a:[1,2]});
// { a: [3, 1, 2] }
That could support multiple different methods (which could even be user-extendible), with the default being the current behavior of right-most replacement as an object value.
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ merge-options │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ No patch available │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ webpack-command [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ webpack-command > @webpack-contrib/config-loader > │
│ │ merge-options │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/717 │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low │ Prototype pollution │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package │ merge-options │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in │ No patch available │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ webpack-command [dev] │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path │ webpack-command > merge-options │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info │ https://nodesecurity.io/advisories/717 │
└───────────────┴──────────────────────────────────────────────────────────────┘
I've checked the dependency in that webpack-command
package, it's
"merge-options": "^1.0.0",
import mergeOptions from 'merge-options';
mergeOption({}, {...}, arguments[0]);
Builds well with dev webpack build, but fails with webpack production build:
Unexpected token: operator (>) [scripts/main_d82bc1a8.js:7487,44]
Using rollup when trying to bundle this dep I'm getting:
[!] Error: 'default' is not exported by ../../../node_modules/merge-options/index.js, imported by src/example.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
Update:
Never mind. It was a misconfiguration 😃
When building a project using merge-options on create-react-app, react-scripts build
will give the following error:
> react-scripts build
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/merge-options/index.js:11
Read more here: http://bit.ly/2tRViJ9
This link to the create-react-app documentation explains the problem in more detail:
Some third-party packages don't compile their code to ES5 before publishing to npm. This often causes problems in the ecosystem because neither browsers (except for most modern versions) nor some tools currently support all ES6 features. We recommend to publish code on npm as ES5 at least for a few more years.
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.