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.

370 lines
8.4 KiB

4 years ago
  1. # 4.18.8
  2. ## Bug fixes
  3. ## Methods
  4. #### ``shift()``
  5. - Calling `shift()` on an empty collection returns null in all cases
  6. #### ``sortKeysDesc()``
  7. - Now works correctly when collections is an object
  8. #### ``min()``
  9. - Passing an array of object where not every element contains the given key no longer causes an error
  10. #### ``max()``
  11. - Passing an array of object where not every element contains the given key no longer causes an error
  12. # 4.16.0
  13. ## Breaking changes
  14. ## Methods
  15. #### ``sortBy()``
  16. - Null values, ``null`` and ``undefined`` will be sorted last, like normal ``.sort()``
  17. # 4.14.0
  18. ## Breaking changes
  19. ## Methods
  20. #### ``values()``
  21. - Reverted change in `4.13.0`. Values method are no longer recursive.
  22. # 4.14.0
  23. ## Breaking changes
  24. ## Methods
  25. #### ``where()``
  26. - This method now supports one, two or three arguments. This may cause unexpected output if you're using this function with one or two arguments earlier.
  27. # 4.13.0
  28. ## Breaking changes
  29. ## Methods
  30. #### ``values()``
  31. - Values now iterates the collection recursively and collects values. Results that previously would return an object may now return an array.
  32. # 4.12.0
  33. ## Breaking changes
  34. ## Collection
  35. #### ``collect()``
  36. - A collection instance made from an empty string is no longer recognized as an empty collection ``collect('')``
  37. ```js
  38. // Before 4.12.0
  39. collect('').isEmpty();
  40. //=> true
  41. // After 4.12.0
  42. collect('').isEmpty();
  43. //=> false
  44. ```
  45. # 4.4.0
  46. ## Breaking changes
  47. ## Methods
  48. #### ``concat()``
  49. - Concat now returns a new collection instead of modifying the existing one
  50. # 4.3.0
  51. ## Breaking changes
  52. ## Methods
  53. #### ``random()``
  54. - Previously ``random()`` and ``random(1)`` would return an array, while passing an integer >1 would return a collection object.
  55. - ``random(1)`` now returns a collection object
  56. - Changed ``random()`` according to https://github.com/ecrmnn/collect.js/issues/202
  57. # 4.2.0
  58. - Added ``whenEmpty()`` method
  59. - Added ``whenNotEmpty()`` method
  60. - Added ``unlessEmpty()`` method
  61. - Added ``unlessNotEmpty()`` method
  62. # 4.1.0
  63. ## Breaking changes
  64. ## Methods
  65. #### ``flatMap()``
  66. - Changed ``flatMap()`` according to https://github.com/ecrmnn/collect.js/issues/195
  67. # 4.0.1
  68. - Added build files so it's no longer required to use npm for installation
  69. # 4.0.0
  70. ## Breaking changes
  71. - ``chunk()``
  72. - ``count()``
  73. - ``dump()``
  74. - ``flatMap()``
  75. - ``has()``
  76. - ``keys()``
  77. - ``groupBy()``
  78. - ``partition()``
  79. - ``pluck()``
  80. - ``split()``
  81. - ``toArray()``
  82. - ``toJson()``
  83. - ``wrap()``
  84. ## Node.js
  85. Skipped Node 4 support
  86. ## Methods
  87. #### ``chunk()``
  88. - Returns a new collection of smaller collections of the given size.
  89. This is done because ``collect.js`` should give the same result as Laravel Collections.
  90. - Also works when the collection is based on an object, a string, a number or boolean.
  91. #### ``combine()``
  92. - Also works when the collection is based on a string
  93. - Also works when combining with a string or an object
  94. - Also works when combining with another collection
  95. #### ``count()``
  96. - Also works when the collection is based on an object
  97. - Return the number of keys in the object
  98. #### ``dump()``
  99. - Console logs the entire collection object (``this``) instead of only the items (``this.items``).
  100. ```js
  101. const collection = collect([
  102. { product: 'Desk', manufacturer: 'IKEA' },
  103. { product: 'Chair', manufacturer: 'Herman Miller' },
  104. { product: 'Bookcase', manufacturer: 'IKEA' },
  105. { product: 'Door' },
  106. ]);
  107. collection.pluck('product', 'manufacturer').dump();
  108. // Prior to 4.0.0
  109. //=> {
  110. //=> IKEA: 'Bookcase',
  111. //=> 'Herman Miller': 'Chair',
  112. //=> '': 'Door'
  113. //=> }
  114. // After 4.0.0
  115. //=> Collection {
  116. //=> items: {
  117. //=> IKEA: 'Bookcase',
  118. //=> 'Herman Miller': 'Chair',
  119. //=> '': 'Door'
  120. //=> }
  121. //=> }
  122. ```
  123. #### ``except()``
  124. - Accepts an array or infinite number of arguments.
  125. #### ``first()``
  126. - Also works when the collection is based on an object.
  127. ```js
  128. const collection = collect({
  129. name: 'Sadio Mané',
  130. club: 'Liverpool FC',
  131. });
  132. collection.first();
  133. //=> Sadio Mané
  134. ```
  135. #### ``flatMap()``
  136. - Version prior to 4.0.0 did not work as expected
  137. - Rewritten with new functionality
  138. - See readme for further details
  139. #### ``flip()``
  140. - Also works when the collection is based on an object
  141. #### ``forget()``
  142. - Also works when the collection is based on an object
  143. #### ``forPage()``
  144. - Also works when the collection is based on an object
  145. #### ``groupBy()``
  146. - Objects that don't have the key that we're grouping by will be grouped into a group under the
  147. name of an empty string. This is changed from being grouped under ``undefined``.
  148. - Now returns a collection of collections instead of an array of objects.
  149. This is done because ``collect.js`` should give the same result as Laravel Collections.
  150. ```js
  151. ```
  152. #### ``has()``
  153. - Accepts an array of keys to check
  154. - Is now a variadic function and therefore accepts infinite number of arguments (keys) to check
  155. - No longer checks if any object in the given array has the specified key.
  156. This is done because ``collect.js`` should give the same result as Laravel Collections.
  157. ```js
  158. // Previously this would return true. It now returns false.
  159. const collection = collect([{
  160. animal: 'unicorn',
  161. ability: 'magical'
  162. }, {
  163. animal: 'pig',
  164. ability: 'filthy'
  165. }]);
  166. collection.has('ability');
  167. //=> true (Prior to 4.0.0)
  168. //=> false (After 4.0.0)
  169. ```
  170. #### ``keyBy()``
  171. - Uses an empty string as the key instead of ``undefined`` when passed an invalid key
  172. #### ``keys()``
  173. - Returns indexes as keys when based on an array. Indexes are mapped to ``Number``.
  174. ```js
  175. const collection = collect([{
  176. name: 'Sadio Mané',
  177. }, {
  178. name: 'Roberto Firmino',
  179. }]);
  180. const keys = collection.keys();
  181. // Prior to 4.0.0
  182. //=> ['name', 'name']
  183. // After 4.0.0
  184. //=> [0, 1]
  185. ```
  186. #### ``last()``
  187. - Also works when the collection is based on an object.
  188. ```js
  189. const collection = collect({
  190. name: 'Sadio Mané',
  191. club: 'Liverpool FC',
  192. });
  193. collection.last();
  194. //=> Liverpool FC
  195. ```
  196. #### ``merge()``
  197. - Can merge arrays and objects.
  198. - Also works when merging with a string.
  199. #### ``only()``
  200. - Accepts an array or infinite number of arguments.
  201. #### ``partition()``
  202. - Returns a collection of collections with the results instead of an array
  203. #### ``pluck()``
  204. - Returns ``null`` as the value instead of ``undefined``
  205. - Returns ``null`` when an item does not contain the specified key.
  206. ```js
  207. const collection = collect([
  208. { product: 'Desk', manufacturer: 'IKEA' },
  209. { product: 'Chair', manufacturer: 'Herman Miller' },
  210. { product: 'Bookcase', manufacturer: 'IKEA' },
  211. { product: 'Door' },
  212. ]);
  213. const pluck = collection.pluck('non-existing-key');
  214. pluck.all();
  215. //=> [null, null, null, null]
  216. const manufacturers = collection.pluck('manufacturer');
  217. manufacturers.all();
  218. //=> ['IKEA', 'Herman Miller', 'IKEA', null]
  219. ```
  220. - Objects that don't have the key that we're plucking by will get an empty string as its key.
  221. This is changed from being ``undefined``.
  222. ```js
  223. const collection = collect([
  224. { product: 'Desk', manufacturer: 'IKEA' },
  225. { product: 'Chair', manufacturer: 'Herman Miller' },
  226. { product: 'Bookcase', manufacturer: 'IKEA' },
  227. { product: 'Door' },
  228. ]);
  229. const pluck = collection.pluck('product', 'manufacturer');
  230. pluck.all();
  231. //=> {
  232. //=> IKEA: 'Bookcase',
  233. //=> 'Herman Miller': 'Chair',
  234. //=> '': 'Door',
  235. //=> }
  236. ```
  237. #### ``pop()``
  238. - Also works when collection is based on an object
  239. #### ``push()``
  240. - Accepts spread/rest operator ``collection.push(...values)``
  241. #### ``random()``
  242. - Also works when collection is based on an object
  243. #### ``shift()``
  244. - Also works when collection is based on an object
  245. #### ``shuffle()``
  246. - Also works when collection is based on an object
  247. #### ``split()``
  248. - Splits the collection into the given number of collections
  249. ```js
  250. const collection = collect([1, 2, 3, 4, 5]);
  251. collection.split(2).dump();
  252. // Prior to 4.0.0
  253. //=> [
  254. //=> [1, 2, 3],
  255. //=> [4, 5],
  256. //=> ]
  257. // After 4.0.0
  258. //=> Collection {
  259. //=> items: {
  260. //=> Collection {
  261. //=> items: [1, 2, 3]
  262. //=> },
  263. //=> Collection {
  264. //=> items: [4, 5]
  265. //=> },
  266. //=> }
  267. //=> }
  268. ```
  269. #### ``take()``
  270. - Also works when collection is based on an object
  271. #### ``toArray()``
  272. - Now works recursively like Laravel collections ``toArray()`` method
  273. - More information: https://github.com/ecrmnn/collect.js/issues/138
  274. #### ``toJson()``
  275. - Now works recursively like Laravel collections ``toArray()`` method
  276. - More information: https://github.com/ecrmnn/collect.js/issues/138
  277. #### ``wrap()``
  278. - Now wraps objects correctly. The key/values are places directly on the collection. Previously objects were wrapped in
  279. an array.
  280. ## Misc
  281. - Added ``CHANGELOG.md``