aneka 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-12-11
4
+
5
+ - [0.5.0] Add ```mergeObjectsByKey(inputs, key)```
6
+
3
7
  ## 2025-12-10
4
8
 
5
9
  - [0.3.0] Add ```filterIndex(inputs, matcher)```
package/index.js CHANGED
@@ -15,6 +15,7 @@ import pascalCase from './src/pascal-case.js'
15
15
  import round from './src/round.js'
16
16
  import secToHms from './src/sec-to-hms.js'
17
17
  import titleize from './src/titleize.js'
18
+ import mergeObjectsByKey from './src/merge-objects-by-key.js'
18
19
 
19
20
  export default {
20
21
  arrangeArray,
@@ -30,6 +31,7 @@ export default {
30
31
  isSet,
31
32
  log,
32
33
  logError,
34
+ mergeObjectsByKey,
33
35
  paginate,
34
36
  pascalCase,
35
37
  round,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,17 @@
1
+ function mergeObjectsByKey(inputs, key) {
2
+ const uniqueMap = new Map()
3
+
4
+ for (const item of inputs) {
5
+ const keyValue = item[key]
6
+ if (uniqueMap.has(keyValue)) {
7
+ const existingObject = uniqueMap.get(keyValue)
8
+ uniqueMap.set(keyValue, { ...existingObject, ...item })
9
+ } else {
10
+ uniqueMap.set(keyValue, item)
11
+ }
12
+ }
13
+
14
+ return Array.from(uniqueMap.values())
15
+ }
16
+
17
+ export default mergeObjectsByKey
@@ -0,0 +1,21 @@
1
+ import { expect } from 'chai'
2
+ import fn from '../src/merge-objects-by-key.js'
3
+
4
+ describe('mergeObjectsByKey', function () {
5
+ it('Should return the expected result', function () {
6
+ const items = [
7
+ { id: 1, name: 'Apple', count: 1 },
8
+ { id: 2, name: 'Banana', count: 2 },
9
+ { id: 1, color: 'Red', price: 0.99 },
10
+ { id: 3, name: 'Cherry', count: 5 },
11
+ { id: 2, color: 'Yellow', weight: '100g' }
12
+ ]
13
+ const expected = [
14
+ { id: 1, name: 'Apple', count: 1, color: 'Red', price: 0.99 },
15
+ { id: 2, name: 'Banana', count: 2, color: 'Yellow', weight: '100g' },
16
+ { id: 3, name: 'Cherry', count: 5 }
17
+ ]
18
+ const result = fn(items, 'id')
19
+ expect(result).to.eql(expected)
20
+ })
21
+ })