@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.
@@ -0,0 +1,11 @@
1
+
2
+ $ microbundle
3
+ Build "@lowerdeck/unique" to dist:
4
+ 77 B: index.cjs.gz
5
+ 58 B: index.cjs.br
6
+ 66 B: index.modern.js.gz
7
+ 50 B: index.modern.js.br
8
+ 88 B: index.module.js.gz
9
+ 72 B: index.module.js.br
10
+ 170 B: index.umd.js.gz
11
+ 137 B: index.umd.js.br
@@ -0,0 +1,26 @@
1
+
2
+ $ vitest run --passWithNoTests
3
+ [?25l
4
+  RUN  v3.2.4 /Users/tobias/code/metorial/metorial-enterprise/oss/src/packages/shared/unique
5
+
6
+ [?2026h
7
+  ❯ src/index.test.ts [queued]
8
+
9
+  Test Files 0 passed (1)
10
+  Tests 0 passed (0)
11
+  Start at 10:23:39
12
+  Duration 101ms
13
+ [?2026l ✓ src/index.test.ts (6 tests) 2ms
14
+ ✓ unique > should return an array with unique elements 1ms
15
+ ✓ unique > should handle an empty array 0ms
16
+ ✓ unique > should handle an array with all unique elements 0ms
17
+ ✓ unique > should handle an array with all duplicate elements 0ms
18
+ ✓ unique > should work with strings 0ms
19
+ ✓ unique > should work with mixed types 0ms
20
+
21
+  Test Files  1 passed (1)
22
+  Tests  6 passed (6)
23
+  Start at  10:23:39
24
+  Duration  218ms (transform 29ms, setup 0ms, collect 28ms, tests 2ms, environment 0ms, prepare 40ms)
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)];
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "extends": "@lowerdeck/tsconfig/base.json",
4
+ "exclude": [
5
+ "dist"
6
+ ],
7
+ "include": [
8
+ "src"
9
+ ],
10
+ "compilerOptions": {
11
+ "outDir": "dist"
12
+ }
13
+ }