Comments (3)
Mhm, doesn't concatArrays
work for you?
const result = mergeOptions.call({concatArrays: true}, {}, {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.
Can you elaborate this and give some examples? Maybe you are on the track of something.
from merge-options.
@schnittstabil man, I completely missed that option, thanks for pointing it out.
So in scenarios where options need to be passed to a method that typically operates on all ...args
, it's typically easier on users and sanity checking to provide a factory method which accepts only an options argument and returns an instance of the method which is scope-configured according to the options passed to the factory. In that way, mergeOptions.set({ concatArray: true })
would return an instance of mergeOptions
which could then be called such like mergeOptions(obj1, obj2, ...)
without having to remember to have the first object be an options object. It also provides reuse of that configured instance without having to manually wrap mergeOptions
.
from merge-options.
If I understand you correctly, you can already accomplish that via Function.prototype.bind():
const mergeOptions = require('merge-options');
const merge = mergeOptions.bind({concatArrays: true})
merge({}, {a:[3]}, {a:[1,2]});
// { a: [ 3, 1, 2 ] }
from merge-options.
Related Issues (15)
- Is this different in results than lodash.merge? HOT 1
- CVE HOT 1
- [Request] Keep first param reactive like Object.assign HOT 1
- npm audit reports this package as problematic for prototype pollution HOT 6
- undefined values are merged HOT 4
- Can a stable release be published? HOT 1
- TypeScript is not supported HOT 5
- node 12 support? HOT 2
- cjs/esm support breaks IntelliSense of VSCode HOT 1
- Rollup complains
- Breaking in webpack when ignore node_modules HOT 9
- Fails to build on create-react-app: Publish ES5 to NPM HOT 6
- [production build] Unexpected token: operator (>) [scripts/main_d82bc1a8.js:7487,44] HOT 1
- Snyk vulnerability report HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from merge-options.