Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # deepmerge
  2. Merges the enumerable properties of two or more objects deeply.
  3. > UMD bundle is 723B minified+gzipped
  4. ## Getting Started
  5. ### Example Usage
  6. <!--js
  7. const merge = require('./')
  8. -->
  9. ```js
  10. const x = {
  11. foo: { bar: 3 },
  12. array: [{
  13. does: 'work',
  14. too: [ 1, 2, 3 ]
  15. }]
  16. }
  17. const y = {
  18. foo: { baz: 4 },
  19. quux: 5,
  20. array: [{
  21. does: 'work',
  22. too: [ 4, 5, 6 ]
  23. }, {
  24. really: 'yes'
  25. }]
  26. }
  27. const output = {
  28. foo: {
  29. bar: 3,
  30. baz: 4
  31. },
  32. array: [{
  33. does: 'work',
  34. too: [ 1, 2, 3 ]
  35. }, {
  36. does: 'work',
  37. too: [ 4, 5, 6 ]
  38. }, {
  39. really: 'yes'
  40. }],
  41. quux: 5
  42. }
  43. merge(x, y) // => output
  44. ```
  45. ### Installation
  46. With [npm](http://npmjs.org) do:
  47. ```sh
  48. npm install deepmerge
  49. ```
  50. deepmerge can be used directly in the browser without the use of package managers/bundlers as well: [UMD version from unpkg.com](https://unpkg.com/deepmerge/dist/umd.js).
  51. ### Include
  52. deepmerge exposes a CommonJS entry point:
  53. ```
  54. const merge = require('deepmerge')
  55. ```
  56. The ESM entry point was dropped due to a [Webpack bug](https://github.com/webpack/webpack/issues/6584).
  57. # API
  58. ## `merge(x, y, [options])`
  59. Merge two objects `x` and `y` deeply, returning a new merged object with the
  60. elements from both `x` and `y`.
  61. If an element at the same key is present for both `x` and `y`, the value from
  62. `y` will appear in the result.
  63. Merging creates a new object, so that neither `x` or `y` is modified.
  64. **Note:** By default, arrays are merged by concatenating them.
  65. ## `merge.all(arrayOfObjects, [options])`
  66. Merges any number of objects into a single result object.
  67. ```js
  68. const foobar = { foo: { bar: 3 } }
  69. const foobaz = { foo: { baz: 4 } }
  70. const bar = { bar: 'yay!' }
  71. merge.all([ foobar, foobaz, bar ]) // => { foo: { bar: 3, baz: 4 }, bar: 'yay!' }
  72. ```
  73. ## Options
  74. ### `arrayMerge`
  75. There are multiple ways to merge two arrays, below are a few examples but you can also create your own custom function.
  76. Your `arrayMerge` function will be called with three arguments: a `target` array, the `source` array, and an `options` object with these properties:
  77. - `isMergeableObject(value)`
  78. - `cloneUnlessOtherwiseSpecified(value, options)`
  79. #### `arrayMerge` example: overwrite target array
  80. Overwrites the existing array values completely rather than concatenating them:
  81. ```js
  82. const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray
  83. merge(
  84. [1, 2, 3],
  85. [3, 2, 1],
  86. { arrayMerge: overwriteMerge }
  87. ) // => [3, 2, 1]
  88. ```
  89. #### `arrayMerge` example: combine arrays
  90. Combines objects at the same index in the two arrays.
  91. This was the default array merging algorithm pre-version-2.0.0.
  92. ```js
  93. const combineMerge = (target, source, options) => {
  94. const destination = target.slice()
  95. source.forEach((item, index) => {
  96. if (typeof destination[index] === 'undefined') {
  97. destination[index] = options.cloneUnlessOtherwiseSpecified(item, options)
  98. } else if (options.isMergeableObject(item)) {
  99. destination[index] = merge(target[index], item, options)
  100. } else if (target.indexOf(item) === -1) {
  101. destination.push(item)
  102. }
  103. })
  104. return destination
  105. }
  106. merge(
  107. [{ a: true }],
  108. [{ b: true }, 'ah yup'],
  109. { arrayMerge: combineMerge }
  110. ) // => [{ a: true, b: true }, 'ah yup']
  111. ```
  112. ### `isMergeableObject`
  113. By default, deepmerge clones every property from almost every kind of object.
  114. You may not want this, if your objects are of special types, and you want to copy the whole object instead of just copying its properties.
  115. You can accomplish this by passing in a function for the `isMergeableObject` option.
  116. If you only want to clone properties of plain objects, and ignore all "special" kinds of instantiated objects, you probably want to drop in [`is-plain-object`](https://github.com/jonschlinkert/is-plain-object).
  117. ```js
  118. const isPlainObject = require('is-plain-object')
  119. function SuperSpecial() {
  120. this.special = 'oh yeah man totally'
  121. }
  122. const instantiatedSpecialObject = new SuperSpecial()
  123. const target = {
  124. someProperty: {
  125. cool: 'oh for sure'
  126. }
  127. }
  128. const source = {
  129. someProperty: instantiatedSpecialObject
  130. }
  131. const defaultOutput = merge(target, source)
  132. defaultOutput.someProperty.cool // => 'oh for sure'
  133. defaultOutput.someProperty.special // => 'oh yeah man totally'
  134. defaultOutput.someProperty instanceof SuperSpecial // => false
  135. const customMergeOutput = merge(target, source, {
  136. isMergeableObject: isPlainObject
  137. })
  138. customMergeOutput.someProperty.cool // => undefined
  139. customMergeOutput.someProperty.special // => 'oh yeah man totally'
  140. customMergeOutput.someProperty instanceof SuperSpecial // => true
  141. ```
  142. ### `customMerge`
  143. Specifies a function which can be used to override the default merge behavior for a property, based on the property name.
  144. The `customMerge` function will be passed the key for each property, and should return the function which should be used to merge the values for that property.
  145. It may also return undefined, in which case the default merge behaviour will be used.
  146. ```js
  147. const alex = {
  148. name: {
  149. first: 'Alex',
  150. last: 'Alexson'
  151. },
  152. pets: ['Cat', 'Parrot']
  153. }
  154. const tony = {
  155. name: {
  156. first: 'Tony',
  157. last: 'Tonison'
  158. },
  159. pets: ['Dog']
  160. }
  161. const mergeNames = (nameA, nameB) => `${nameA.first} and ${nameB.first}`
  162. const options = {
  163. customMerge: (key) => {
  164. if (key === 'name') {
  165. return mergeNames
  166. }
  167. }
  168. }
  169. const result = merge(alex, tony, options)
  170. result.name // => 'Alex and Tony'
  171. result.pets // => ['Cat', 'Parrot', 'Dog']
  172. ```
  173. ### `clone`
  174. *Deprecated.*
  175. Defaults to `true`.
  176. If `clone` is `false` then child objects will be copied directly instead of being cloned. This was the default behavior before version 2.x.
  177. # Testing
  178. With [npm](http://npmjs.org) do:
  179. ```sh
  180. npm test
  181. ```
  182. # License
  183. MIT