aneka 0.3.0 → 0.4.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
@@ -3,6 +3,8 @@
3
3
  ## 2025-12-10
4
4
 
5
5
  - [0.3.0] Add ```filterIndex(inputs, matcher)```
6
+ - [0.4.0] Add ```filterDuplicate(inputs, key)```
7
+ - [0.4.0] Add some test with mocha & chai
6
8
 
7
9
  ## 2025-12-09
8
10
 
package/index.js CHANGED
@@ -2,6 +2,7 @@ import arrangeArray from './src/arrange-array.js'
2
2
  import defaultsDeep from './src/defaults-deep.js'
3
3
  import delay from './src/delay.js'
4
4
  import extractText from './src/extract-text.js'
5
+ import filterDuplicate from './src/filter-duplicate.js'
5
6
  import filterIndex from './src/filter-index.js'
6
7
  import getKeyByValue from './src/get-key-by-value.js'
7
8
  import getIndex from './src/get-index.js'
@@ -20,6 +21,7 @@ export default {
20
21
  defaultsDeep,
21
22
  delay,
22
23
  extractText,
24
+ filterDuplicate,
23
25
  filterIndex,
24
26
  getIndex,
25
27
  getKeyByValue,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "aneka",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Some usefull function helper for daily use",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "test": "jest"
8
+ "test": "mocha"
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
@@ -25,5 +25,9 @@
25
25
  "dependencies": {
26
26
  "lodash-es": "^4.17.21",
27
27
  "sprintf-js": "^1.1.3"
28
+ },
29
+ "devDependencies": {
30
+ "chai": "^6.2.1",
31
+ "mocha": "^11.7.5"
28
32
  }
29
33
  }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Filter array of duplicates
3
+ *
4
+ * @param {Array} inputs - Array to filter from. Must be an array of objects
5
+ * @param {string} key - Key's object
6
+ */
7
+
8
+ function filterDuplicate (inputs, key) {
9
+ const seen = new Set()
10
+ const dups = new Set()
11
+
12
+ inputs.forEach(item => {
13
+ const val = item[key]
14
+ if (seen.has(val)) {
15
+ dups.add(val)
16
+ } else {
17
+ seen.add(val)
18
+ }
19
+ })
20
+
21
+ return inputs.filter(item => {
22
+ return dups.has(item[key])
23
+ })
24
+ }
25
+
26
+ export default filterDuplicate
@@ -0,0 +1,24 @@
1
+ import { expect } from 'chai'
2
+ import fn from '../src/filter-duplicate.js'
3
+
4
+ describe('filterDuplicate', function () {
5
+ it('No duplication', function () {
6
+ const items = [
7
+ { id: 1, name: "one" },
8
+ { id: 2, name: "two" },
9
+ { id: 3, name: "three" }
10
+ ]
11
+ const dups = fn(items, 'name')
12
+ expect(dups).to.have.lengthOf(0)
13
+ })
14
+
15
+ it('Two duplications', function () {
16
+ const items = [
17
+ { id: 1, name: "one" },
18
+ { id: 2, name: "one" },
19
+ { id: 3, name: "three" }
20
+ ]
21
+ const dups = fn(items, 'name')
22
+ expect(dups).to.have.lengthOf(2)
23
+ })
24
+ })
@@ -0,0 +1,25 @@
1
+ import { expect } from 'chai'
2
+ import fn from '../src/filter-index.js'
3
+
4
+ describe('filterIndex', function () {
5
+ it('Nothing found', function () {
6
+ const items = [
7
+ { id: 1, name: "one" },
8
+ { id: 2, name: "two" },
9
+ { id: 3, name: "three" }
10
+ ]
11
+ const dups = fn(items, item => item.name === 'zero')
12
+ expect(dups).to.have.lengthOf(0)
13
+ })
14
+
15
+ it('Found 2 items', function () {
16
+ const items = [
17
+ { id: 1, name: "one" },
18
+ { id: 2, name: "two" },
19
+ { id: 3, name: "three" }
20
+ ]
21
+ const dups = fn(items, item => ['one', 'two'].includes(item.name))
22
+ expect(dups).to.eql([0, 1])
23
+ })
24
+
25
+ })