@lowerdeck/unique 1.0.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/.turbo/turbo-build.log +11 -0
- package/.turbo/turbo-test.log +26 -0
- package/README.md +38 -0
- package/package.json +31 -0
- package/src/index.test.ts +40 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
[0m[2m[35m$[0m [2m[1mmicrobundle[0m
|
|
3
|
+
[34mBuild "@lowerdeck/unique" to dist:[39m
|
|
4
|
+
[32m77 B[39m: [37mindex.cjs[39m.gz
|
|
5
|
+
[32m58 B[39m: [37mindex.cjs[39m.br
|
|
6
|
+
[32m66 B[39m: [37mindex.modern.js[39m.gz
|
|
7
|
+
[32m50 B[39m: [37mindex.modern.js[39m.br
|
|
8
|
+
[32m88 B[39m: [37mindex.module.js[39m.gz
|
|
9
|
+
[32m72 B[39m: [37mindex.module.js[39m.br
|
|
10
|
+
[32m170 B[39m: [37mindex.umd.js[39m.gz
|
|
11
|
+
[32m137 B[39m: [37mindex.umd.js[39m.br
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
[0m[2m[35m$[0m [2m[1mvitest run --passWithNoTests[0m
|
|
3
|
+
[?25l
|
|
4
|
+
[1m[46m RUN [49m[22m [36mv3.2.4 [39m[90m/Users/tobias/code/metorial/metorial-enterprise/oss/src/packages/shared/unique[39m
|
|
5
|
+
|
|
6
|
+
[?2026h
|
|
7
|
+
[1m[33m ❯ [39m[22msrc/index.test.ts[2m [queued][22m
|
|
8
|
+
|
|
9
|
+
[2m Test Files [22m[1m[32m0 passed[39m[22m[90m (1)[39m
|
|
10
|
+
[2m Tests [22m[1m[32m0 passed[39m[22m[90m (0)[39m
|
|
11
|
+
[2m Start at [22m10:23:39
|
|
12
|
+
[2m Duration [22m101ms
|
|
13
|
+
[?2026l[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K[1A[K [32m✓[39m src/index.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
14
|
+
[32m✓[39m unique[2m > [22mshould return an array with unique elements[32m 1[2mms[22m[39m
|
|
15
|
+
[32m✓[39m unique[2m > [22mshould handle an empty array[32m 0[2mms[22m[39m
|
|
16
|
+
[32m✓[39m unique[2m > [22mshould handle an array with all unique elements[32m 0[2mms[22m[39m
|
|
17
|
+
[32m✓[39m unique[2m > [22mshould handle an array with all duplicate elements[32m 0[2mms[22m[39m
|
|
18
|
+
[32m✓[39m unique[2m > [22mshould work with strings[32m 0[2mms[22m[39m
|
|
19
|
+
[32m✓[39m unique[2m > [22mshould work with mixed types[32m 0[2mms[22m[39m
|
|
20
|
+
|
|
21
|
+
[2m Test Files [22m [1m[32m1 passed[39m[22m[90m (1)[39m
|
|
22
|
+
[2m Tests [22m [1m[32m6 passed[39m[22m[90m (6)[39m
|
|
23
|
+
[2m Start at [22m 10:23:39
|
|
24
|
+
[2m Duration [22m 218ms[2m (transform 29ms, setup 0ms, collect 28ms, tests 2ms, environment 0ms, prepare 40ms)[22m
|
|
25
|
+
|
|
26
|
+
[?25h
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# `@lowerdeck/unique`
|
|
2
|
+
|
|
3
|
+
Remove duplicate values from arrays using Set-based deduplication. Preserves the first occurrence of each unique value.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lowerdeck/unique
|
|
9
|
+
yarn add @lowerdeck/unique
|
|
10
|
+
bun add @lowerdeck/unique
|
|
11
|
+
pnpm add @lowerdeck/unique
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { unique } from '@lowerdeck/unique';
|
|
18
|
+
|
|
19
|
+
// Remove duplicate numbers
|
|
20
|
+
const numbers = unique([1, 2, 2, 3, 3, 3, 4]);
|
|
21
|
+
console.log(numbers); // [1, 2, 3, 4]
|
|
22
|
+
|
|
23
|
+
// Remove duplicate strings
|
|
24
|
+
const tags = unique(['javascript', 'typescript', 'javascript', 'react']);
|
|
25
|
+
console.log(tags); // ['javascript', 'typescript', 'react']
|
|
26
|
+
|
|
27
|
+
// Works with any value that can be compared with Set
|
|
28
|
+
const mixed = unique([1, '1', 2, '2', 1, 2]);
|
|
29
|
+
console.log(mixed); // [1, '1', 2, '2']
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## License
|
|
33
|
+
|
|
34
|
+
This project is licensed under the Apache License 2.0.
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
<sub>Built with ❤️ by <a href="https://metorial.com">Metorial</a></sub>
|
|
38
|
+
</div>
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lowerdeck/unique",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"author": "Tobias Herber",
|
|
8
|
+
"license": "Apache 2",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"source": "src/index.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"default": "./dist/index.modern.js"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.module.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"unpkg": "./dist/index.umd.js",
|
|
19
|
+
"scripts": {
|
|
20
|
+
"test": "vitest run --passWithNoTests",
|
|
21
|
+
"lint": "prettier src/**/*.ts --check",
|
|
22
|
+
"build": "microbundle"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"microbundle": "^0.15.1",
|
|
27
|
+
"@lowerdeck/tsconfig": "^1.0.0",
|
|
28
|
+
"typescript": "^5.8.3",
|
|
29
|
+
"vitest": "^3.1.2"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { unique } from './index';
|
|
3
|
+
|
|
4
|
+
describe('unique', () => {
|
|
5
|
+
it('should return an array with unique elements', () => {
|
|
6
|
+
const input = [1, 2, 2, 3, 4, 4, 5];
|
|
7
|
+
const output = unique(input);
|
|
8
|
+
expect(output).toEqual([1, 2, 3, 4, 5]);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it('should handle an empty array', () => {
|
|
12
|
+
const input: number[] = [];
|
|
13
|
+
const output = unique(input);
|
|
14
|
+
expect(output).toEqual([]);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should handle an array with all unique elements', () => {
|
|
18
|
+
const input = [1, 2, 3, 4, 5];
|
|
19
|
+
const output = unique(input);
|
|
20
|
+
expect(output).toEqual([1, 2, 3, 4, 5]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should handle an array with all duplicate elements', () => {
|
|
24
|
+
const input = [1, 1, 1, 1];
|
|
25
|
+
const output = unique(input);
|
|
26
|
+
expect(output).toEqual([1]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should work with strings', () => {
|
|
30
|
+
const input = ['a', 'b', 'b', 'c', 'a'];
|
|
31
|
+
const output = unique(input);
|
|
32
|
+
expect(output).toEqual(['a', 'b', 'c']);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should work with mixed types', () => {
|
|
36
|
+
const input = [1, '1', 2, '2', 1, '1'];
|
|
37
|
+
const output = unique(input);
|
|
38
|
+
expect(output).toEqual([1, '1', 2, '2']);
|
|
39
|
+
});
|
|
40
|
+
});
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export let unique = <T>(arr: T[]) => [...new Set(arr)];
|