UNPKG

1.18 kBJavaScriptView Raw
1import upstream from './upstream.js'
2import stylistic from './stylistic.js'
3import template from './template.js'
4import resolver from './resolver.js'
5
6// Use deep merge to avoid complications in overriding mechanisms.
7// But still export as an array for future extensibility.
8export default [
9 deepMerge(
10 {
11 name: 'vue-standard'
12 },
13 upstream,
14 stylistic,
15 template,
16 resolver
17 )
18]
19
20function deepMerge (target, ...sources) {
21 const seen = new WeakMap()
22
23 function merge (target, source) {
24 if (source instanceof Object && !Array.isArray(source)) {
25 if (seen.has(source)) {
26 return seen.get(source)
27 }
28 seen.set(source, target)
29
30 Object.keys(source).forEach((key) => {
31 if (
32 source[key] instanceof Object &&
33 !Array.isArray(source[key]) &&
34 typeof source[key] !== 'function'
35 ) {
36 if (!target[key]) Object.assign(target, { [key]: {} })
37 merge(target[key], source[key])
38 } else {
39 Object.assign(target, { [key]: source[key] })
40 }
41 })
42 }
43 return target
44 }
45
46 sources.forEach((source) => merge(target, source))
47 return target
48}