pure-md5 0.2.0 → 0.2.2
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/README.md +38 -24
- package/dist/adapters/ie11.cjs +1 -2
- package/dist/adapters/ie11.js +1 -2
- package/dist/adapters/node.cjs +1 -2
- package/dist/adapters/node.js +1 -2
- package/dist/adapters/webcrypto.cjs +1 -2
- package/dist/adapters/webcrypto.js +1 -2
- package/dist/index.cjs +1 -2
- package/dist/index.d.ts +149 -5
- package/dist/index.js +3 -2
- package/dist/md5.cjs +1 -0
- package/dist/md5.d.ts +20 -0
- package/dist/md5.js +1 -0
- package/dist/stream/md5-stream.cjs +1 -2
- package/dist/stream/md5-stream.js +1 -2
- package/dist/stream/whatwg-stream.cjs +1 -2
- package/dist/stream/whatwg-stream.js +1 -2
- package/dist/utils/detect.cjs +1 -2
- package/dist/utils/detect.js +3 -2
- package/package.json +10 -15
- package/pure-md5-0.2.1.tgz +0 -0
- package/test-tree-shake.mjs +12 -0
- package/.aliases +0 -19
- package/.bash_profile +0 -12
- package/.bash_prompt +0 -56
- package/.changeset/README.md +0 -32
- package/.changeset/config.json +0 -16
- package/.continue/mcpServers/new-mcp-server.yaml +0 -10
- package/.continue/rules +0 -29
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
- package/.github/ISSUE_TEMPLATE/documentation.md +0 -20
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -35
- package/.github/workflows/npm-publish.yml +0 -33
- package/.github/workflows/release.yml +0 -42
- package/CHANGELOG.md +0 -9
- package/CONTRIBUTING.md +0 -203
- package/MIGRATION_GUIDE_STREAMS.md +0 -374
- package/STREAM_API.md +0 -582
- package/STREAM_BENCHMARKS.md +0 -232
- package/STREAM_EXAMPLES.md +0 -669
- package/STREAM_OPTIMIZATION_REPORT.md +0 -136
- package/STREAM_TROUBLESHOOTING.md +0 -537
- package/WEB_CRYPTO_TESTS_SUMMARY.md +0 -140
- package/WHATWG_STREAMS.md +0 -191
- package/__tests__/adapters/node-crypto.test.ts +0 -167
- package/__tests__/adapters/web-crypto-node.test.ts +0 -73
- package/__tests__/adapters/web-crypto.test.ts +0 -195
- package/__tests__/add32.test.ts +0 -33
- package/__tests__/fallback.test.ts +0 -345
- package/__tests__/hex.test.ts +0 -38
- package/__tests__/hex_chr.test.ts +0 -20
- package/__tests__/index.test.ts +0 -87
- package/__tests__/integration/fixtures/test-file.txt +0 -1
- package/__tests__/integration/md5-stream-file.test.ts +0 -293
- package/__tests__/integration/node-crypto-file.test.ts +0 -86
- package/__tests__/integration/web-crypto.test.ts +0 -38
- package/__tests__/md51.test.ts +0 -73
- package/__tests__/md5block.test.ts +0 -61
- package/__tests__/md5cycle.test.ts +0 -48
- package/__tests__/round-functions.test.ts +0 -87
- package/__tests__/stream/fs-utils.test.ts +0 -209
- package/__tests__/stream/md5-stream-edge-cases.test.ts +0 -461
- package/__tests__/stream/md5-stream.test.ts +0 -418
- package/__tests__/stream/whatwg-stream.test.ts +0 -355
- package/__tests__/stream/whatwg-stream.test.ts.bak2 +0 -335
- package/benchmarks/md5-stream.bench.ts +0 -212
- package/benchmarks/whatwg-stream.bench.ts +0 -180
- package/dist/adapters/ie11.cjs.map +0 -1
- package/dist/adapters/ie11.js.map +0 -1
- package/dist/adapters/node.cjs.map +0 -1
- package/dist/adapters/node.js.map +0 -1
- package/dist/adapters/webcrypto.cjs.map +0 -1
- package/dist/adapters/webcrypto.js.map +0 -1
- package/dist/chunk-2YXXFGBV.js +0 -2
- package/dist/chunk-2YXXFGBV.js.map +0 -1
- package/dist/chunk-4KSCMS4Q.js +0 -2
- package/dist/chunk-4KSCMS4Q.js.map +0 -1
- package/dist/chunk-6P2QV5SR.js +0 -4
- package/dist/chunk-6P2QV5SR.js.map +0 -1
- package/dist/chunk-G5WHEAIQ.js +0 -2
- package/dist/chunk-G5WHEAIQ.js.map +0 -1
- package/dist/chunk-H2K353LR.js +0 -2
- package/dist/chunk-H2K353LR.js.map +0 -1
- package/dist/chunk-JKVD5LHZ.js +0 -2
- package/dist/chunk-JKVD5LHZ.js.map +0 -1
- package/dist/chunk-NWQ4N5RX.js +0 -2
- package/dist/chunk-NWQ4N5RX.js.map +0 -1
- package/dist/chunk-PHZ7FTYF.js +0 -2
- package/dist/chunk-PHZ7FTYF.js.map +0 -1
- package/dist/chunk-PNZTVQA7.js +0 -2
- package/dist/chunk-PNZTVQA7.js.map +0 -1
- package/dist/chunk-R4JB5MBR.js +0 -2
- package/dist/chunk-R4JB5MBR.js.map +0 -1
- package/dist/chunk-VFOAY6XI.js +0 -2
- package/dist/chunk-VFOAY6XI.js.map +0 -1
- package/dist/chunk-XB5BQIEX.js +0 -2
- package/dist/chunk-XB5BQIEX.js.map +0 -1
- package/dist/core/index.cjs +0 -2
- package/dist/core/index.cjs.map +0 -1
- package/dist/core/index.d.cts +0 -19
- package/dist/core/index.d.ts +0 -19
- package/dist/core/index.js +0 -2
- package/dist/core/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -84
- package/dist/index.js.map +0 -1
- package/dist/stream/adapter.cjs +0 -2
- package/dist/stream/adapter.cjs.map +0 -1
- package/dist/stream/adapter.d.cts +0 -63
- package/dist/stream/adapter.d.ts +0 -63
- package/dist/stream/adapter.js +0 -2
- package/dist/stream/adapter.js.map +0 -1
- package/dist/stream/fs-utils.cjs +0 -2
- package/dist/stream/fs-utils.cjs.map +0 -1
- package/dist/stream/fs-utils.d.cts +0 -137
- package/dist/stream/fs-utils.d.ts +0 -137
- package/dist/stream/fs-utils.js +0 -2
- package/dist/stream/fs-utils.js.map +0 -1
- package/dist/stream/index.cjs +0 -2
- package/dist/stream/index.cjs.map +0 -1
- package/dist/stream/index.d.cts +0 -4
- package/dist/stream/index.d.ts +0 -4
- package/dist/stream/index.js +0 -2
- package/dist/stream/index.js.map +0 -1
- package/dist/stream/light/index.cjs +0 -2
- package/dist/stream/light/index.cjs.map +0 -1
- package/dist/stream/light/index.d.cts +0 -4
- package/dist/stream/light/index.d.ts +0 -4
- package/dist/stream/light/index.js +0 -2
- package/dist/stream/light/index.js.map +0 -1
- package/dist/stream/md5-stream.cjs.map +0 -1
- package/dist/stream/md5-stream.js.map +0 -1
- package/dist/stream/whatwg-stream.cjs.map +0 -1
- package/dist/stream/whatwg-stream.js.map +0 -1
- package/dist/types-edGoGJ5V.d.cts +0 -42
- package/dist/types-edGoGJ5V.d.ts +0 -42
- package/dist/utils/detect.cjs.map +0 -1
- package/dist/utils/detect.js.map +0 -1
- package/planning/03-optimization-size-tree-shaking/01-es-modules-tree-shaking.md +0 -152
- package/planning/03-optimization-size-tree-shaking/02-consolidate-modules.md +0 -65
- package/planning/03-optimization-size-tree-shaking/03-remove-duplicate-add32.md +0 -93
- package/planning/03-optimization-size-tree-shaking/04-remove-runtime-check.md +0 -102
- package/planning/03-optimization-size-tree-shaking/05-optimize-loops-performance.md +0 -107
- package/planning/03-optimization-size-tree-shaking/06-tsup-formats-configuration.md +0 -227
- package/planning/03-optimization-size-tree-shaking/07-multiple-build-formats.md +0 -228
- package/planning/03-optimization-size-tree-shaking/08-benchmarks-metrics.md +0 -34
- package/planning/03-optimization-size-tree-shaking/MIGRATION_GUIDE.md +0 -260
- package/planning/03-optimization-size-tree-shaking/README.md +0 -173
- package/planning/03-optimization-size-tree-shaking/SUMMARY.md +0 -168
- package/planning/04-adapter-backend/03-backend-web-crypto.md +0 -149
- package/planning/04-adapter-backend/04-backend-node-crypto.md +0 -181
- package/planning/04-adapter-backend/05-backend-pure-js.md +0 -174
- package/planning/04-adapter-backend/06-backend-ie11.md +0 -158
- package/planning/04-adapter-backend/07-detection-environment.md +0 -232
- package/planning/04-adapter-backend/08-detection-backend.md +0 -210
- package/planning/04-adapter-backend/09-adapter-unified.md +0 -255
- package/planning/04-adapter-backend/10-fallback-mechanism.md +0 -333
- package/planning/04-adapter-backend/11-tests-backend-web-crypto.md +0 -191
- package/planning/04-adapter-backend/12-tests-backend-node-crypto.md +0 -222
- package/planning/04-adapter-backend/README.md +0 -45
- package/planning/05-documentation-publishing/01-README-optimization.md +0 -105
- package/planning/05-documentation-publishing/02-VitePress-site-evaluation.md +0 -136
- package/planning/05-documentation-publishing/03-Changeset-setup.md +0 -192
- package/planning/05-documentation-publishing/04-GitHub-templates.md +0 -252
- package/planning/05-documentation-publishing/README.md +0 -22
- package/planning/05-documentation-publishing/STATUS.md +0 -222
- package/planning/prd.md +0 -405
- package/planning/streams/01-create-md5stream-class.md +0 -69
- package/planning/streams/02-create-factory-api.md +0 -65
- package/planning/streams/03-fs-integration.md +0 -37
- package/planning/streams/04-whatwg-streams-support.md +0 -37
- package/planning/streams/05-audit-optimization.md +0 -121
- package/planning/streams/06-comprehensive-tests-docs.md +0 -137
- package/planning/streams/07-architecture-integration.md +0 -38
- package/planning/streams/README.md +0 -98
- package/tsup.config.ts +0 -24
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
# Task 11: Web Crypto Backend Tests
|
|
2
|
-
|
|
3
|
-
## Goal
|
|
4
|
-
|
|
5
|
-
Создать комплексные тесты для Web Crypto backend адаптера.
|
|
6
|
-
|
|
7
|
-
## Implementation
|
|
8
|
-
|
|
9
|
-
### 1. Создать файл `__tests__/adapters/web-crypto.test.ts`
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { WebCryptoBackend } from '../../src/adapters/web-crypto.js';
|
|
13
|
-
|
|
14
|
-
describe('WebCryptoBackend', () => {
|
|
15
|
-
let backend: WebCryptoBackend;
|
|
16
|
-
|
|
17
|
-
beforeAll(async () => {
|
|
18
|
-
const available = await WebCryptoBackend.isAvailable();
|
|
19
|
-
if (!available) {
|
|
20
|
-
console.log('Web Crypto API not available, skipping tests');
|
|
21
|
-
this.skip();
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
backend = new WebCryptoBackend();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe('Basic hashing', () => {
|
|
28
|
-
it('should hash string correctly', async () => {
|
|
29
|
-
const result = await backend.hash('hello');
|
|
30
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('should hash empty string', async () => {
|
|
34
|
-
const result = await backend.hash('');
|
|
35
|
-
expect(result).toBe('d41d8cd98f00b204e9800998ecf8427e');
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should hash special characters', async () => {
|
|
39
|
-
const result = await backend.hash('!@#$%^&*()');
|
|
40
|
-
expect(result).toBe('903246b67e6a702cbb3749e376397578');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should hash unicode characters', async () => {
|
|
44
|
-
const result = await backend.hash('Привет мир');
|
|
45
|
-
expect(result).toBe('8b7d1e6d8e6a702cbb3749e376397578'); // Expected hash
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should hash long string', async () => {
|
|
49
|
-
const longString = 'a'.repeat(10000);
|
|
50
|
-
const result = await backend.hash(longString);
|
|
51
|
-
expect(result.length).toBe(32); // MD5 always produces 32 char hex
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('Binary data', () => {
|
|
56
|
-
it('should hash Uint8Array', async () => {
|
|
57
|
-
const data = new Uint8Array([104, 101, 108, 108, 111]); // "hello"
|
|
58
|
-
const result = await backend.hashBinary(data);
|
|
59
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('should hash ArrayBuffer', async () => {
|
|
63
|
-
const data = new TextEncoder().encode('hello').buffer;
|
|
64
|
-
const result = await backend.hashBinary(data);
|
|
65
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should hash empty Uint8Array', async () => {
|
|
69
|
-
const data = new Uint8Array(0);
|
|
70
|
-
const result = await backend.hashBinary(data);
|
|
71
|
-
expect(result).toBe('d41d8cd98f00b204e9800998ecf8427e');
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('Availability', () => {
|
|
76
|
-
it('should be available in modern browsers', async () => {
|
|
77
|
-
const available = await WebCryptoBackend.isAvailable();
|
|
78
|
-
// May be true or false depending on test environment
|
|
79
|
-
expect(typeof available).toBe('boolean');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should throw error if not available', async () => {
|
|
83
|
-
// Mock isAvailable to return false
|
|
84
|
-
jest.spyOn(WebCryptoBackend, 'isAvailable').mockResolvedValue(false);
|
|
85
|
-
|
|
86
|
-
await expect(backend.hash('test')).rejects.toThrow('Web Crypto API is not available');
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe('Performance', () => {
|
|
91
|
-
it('should hash 1MB data efficiently', async () => {
|
|
92
|
-
const data = 'a'.repeat(1024 * 1024); // 1MB
|
|
93
|
-
|
|
94
|
-
const start = performance.now();
|
|
95
|
-
const result = await backend.hash(data);
|
|
96
|
-
const duration = performance.now() - start;
|
|
97
|
-
|
|
98
|
-
expect(result.length).toBe(32);
|
|
99
|
-
expect(duration).toBeLessThan(1000); // Should complete in under 1 second
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('Consistency', () => {
|
|
104
|
-
it('should produce same hash for same input', async () => {
|
|
105
|
-
const input = 'test input';
|
|
106
|
-
const result1 = await backend.hash(input);
|
|
107
|
-
const result2 = await backend.hash(input);
|
|
108
|
-
expect(result1).toBe(result2);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should produce different hash for different inputs', async () => {
|
|
112
|
-
const result1 = await backend.hash('hello');
|
|
113
|
-
const result2 = await backend.hash('world');
|
|
114
|
-
expect(result1).not.toBe(result2);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### 2. Tests интеграции
|
|
121
|
-
|
|
122
|
-
Создать файл `__tests__/integration/web-crypto.test.ts`:
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
import { md5 } from '../../src/adapters/unified.js';
|
|
126
|
-
|
|
127
|
-
describe('WebCrypto Backend Integration', () => {
|
|
128
|
-
describe('Unified adapter with WebCrypto', () => {
|
|
129
|
-
it('should use WebCrypto if available', async () => {
|
|
130
|
-
const available = await md5.isAvailable('webcrypto');
|
|
131
|
-
if (!available) {
|
|
132
|
-
console.log('WebCrypto not available, skipping');
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const result = await md5.hash('hello');
|
|
137
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should accept backend override', async () => {
|
|
141
|
-
const result = await md5.hash('hello', { backend: 'webcrypto' });
|
|
142
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### 3. Tests в Node.js с WebCrypto
|
|
149
|
-
|
|
150
|
-
Создать файл `__tests__/adapters/web-crypto-node.test.ts`:
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
// Only run in Node.js 15+ with WebCrypto
|
|
154
|
-
const { isNode } = require('../detection/environment.js');
|
|
155
|
-
|
|
156
|
-
if (!isNode()) {
|
|
157
|
-
console.log('Not in Node.js, skipping');
|
|
158
|
-
process.exit(0);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const nodeVersion = process.versions.node.split('.').map(Number);
|
|
162
|
-
if (nodeVersion[0] < 15) {
|
|
163
|
-
console.log('Node.js version too low, skipping');
|
|
164
|
-
process.exit(0);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
describe('WebCryptoBackend in Node.js', () => {
|
|
168
|
-
let backend: WebCryptoBackend;
|
|
169
|
-
|
|
170
|
-
beforeAll(async () => {
|
|
171
|
-
const available = await WebCryptoBackend.isAvailable();
|
|
172
|
-
if (!available) {
|
|
173
|
-
console.log('WebCrypto not available in Node.js, skipping');
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
backend = new WebCryptoBackend();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('should work in Node.js', async () => {
|
|
180
|
-
const result = await backend.hash('hello');
|
|
181
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## Ожидаемый результат
|
|
187
|
-
|
|
188
|
-
- ✅ Все тесты проходят успешно
|
|
189
|
-
- ✅ Покрытие кода >= 90%
|
|
190
|
-
- ✅ Tests работают в браузерах и Node.js
|
|
191
|
-
- ✅ Performance тесты включены
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
# Task 12: Node.js Backend Tests
|
|
2
|
-
|
|
3
|
-
## Goal
|
|
4
|
-
|
|
5
|
-
Создать комплексные тесты для Node.js Crypto backend адаптера.
|
|
6
|
-
|
|
7
|
-
## Implementation
|
|
8
|
-
|
|
9
|
-
### 1. Создать файл `__tests__/adapters/node-crypto.test.ts`
|
|
10
|
-
|
|
11
|
-
```typescript
|
|
12
|
-
import { NodeCryptoBackend } from '../../src/adapters/node-crypto.js';
|
|
13
|
-
|
|
14
|
-
describe('NodeCryptoBackend', () => {
|
|
15
|
-
let backend: NodeCryptoBackend;
|
|
16
|
-
|
|
17
|
-
beforeAll(() => {
|
|
18
|
-
if (!NodeCryptoBackend.isAvailable()) {
|
|
19
|
-
console.log('Node.js Crypto not available, skipping tests');
|
|
20
|
-
this.skip();
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
backend = new NodeCryptoBackend();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('Basic hashing', () => {
|
|
27
|
-
it('should hash string correctly', () => {
|
|
28
|
-
const result = backend.hash('hello');
|
|
29
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should hash empty string', () => {
|
|
33
|
-
const result = backend.hash('');
|
|
34
|
-
expect(result).toBe('d41d8cd98f00b204e9800998ecf8427e');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('should hash special characters', () => {
|
|
38
|
-
const result = backend.hash('!@#$%^&*()');
|
|
39
|
-
expect(result).toBe('903246b67e6a702cbb3749e376397578');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should hash unicode characters', () => {
|
|
43
|
-
const result = backend.hash('Привет мир');
|
|
44
|
-
expect(result).toBe('expected_hash_here'); // Replace with actual expected hash
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should hash long string', () => {
|
|
48
|
-
const longString = 'a'.repeat(10000);
|
|
49
|
-
const result = backend.hash(longString);
|
|
50
|
-
expect(result.length).toBe(32);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('Binary data', () => {
|
|
55
|
-
it('should hash Uint8Array', () => {
|
|
56
|
-
const data = new Uint8Array([104, 101, 108, 108, 111]); // "hello"
|
|
57
|
-
const result = backend.hashBinary(data);
|
|
58
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should hash ArrayBuffer', () => {
|
|
62
|
-
const data = new TextEncoder().encode('hello').buffer;
|
|
63
|
-
const result = backend.hashBinary(data);
|
|
64
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('should hash empty Uint8Array', () => {
|
|
68
|
-
const data = new Uint8Array(0);
|
|
69
|
-
const result = backend.hashBinary(data);
|
|
70
|
-
expect(result).toBe('d41d8cd98f00b204e9800998ecf8427e');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('Streaming', () => {
|
|
75
|
-
it('should support streaming via update/digest', () => {
|
|
76
|
-
backend.update('he');
|
|
77
|
-
backend.update('l');
|
|
78
|
-
backend.update('lo');
|
|
79
|
-
const result = backend.digest('hex');
|
|
80
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should support streaming with binary data', () => {
|
|
84
|
-
backend.update(new Uint8Array([104, 101]));
|
|
85
|
-
backend.update(new Uint8Array([108, 108, 111]));
|
|
86
|
-
const result = backend.digest('hex');
|
|
87
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should reset state', () => {
|
|
91
|
-
backend.update('hello');
|
|
92
|
-
backend.reset();
|
|
93
|
-
backend.update('world');
|
|
94
|
-
const result = backend.digest('hex');
|
|
95
|
-
expect(result).toBe('5d41402abc4b2a76b9719d911017c592');
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe('Availability', () => {
|
|
100
|
-
it('should be available in Node.js', () => {
|
|
101
|
-
const available = NodeCryptoBackend.isAvailable();
|
|
102
|
-
expect(available).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should throw error if not available', () => {
|
|
106
|
-
jest.spyOn(NodeCryptoBackend, 'isAvailable').mockReturnValue(false);
|
|
107
|
-
|
|
108
|
-
expect(() => backend.hash('test')).toThrow('Node.js Crypto is not available');
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
describe('Performance', () => {
|
|
113
|
-
it('should hash 1MB data efficiently', () => {
|
|
114
|
-
const data = 'a'.repeat(1024 * 1024); // 1MB
|
|
115
|
-
|
|
116
|
-
const start = Date.now();
|
|
117
|
-
const result = backend.hash(data);
|
|
118
|
-
const duration = Date.now() - start;
|
|
119
|
-
|
|
120
|
-
expect(result.length).toBe(32);
|
|
121
|
-
expect(duration).toBeLessThan(500); // Should complete in under 500ms
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('Consistency', () => {
|
|
126
|
-
it('should produce same hash for same input', () => {
|
|
127
|
-
const input = 'test input';
|
|
128
|
-
const result1 = backend.hash(input);
|
|
129
|
-
const result2 = backend.hash(input);
|
|
130
|
-
expect(result1).toBe(result2);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should produce different hash for different inputs', () => {
|
|
134
|
-
const result1 = backend.hash('hello');
|
|
135
|
-
const result2 = backend.hash('world');
|
|
136
|
-
expect(result1).not.toBe(result2);
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
### 2. Tests stream API
|
|
143
|
-
|
|
144
|
-
Создать файл `__tests__/adapters/node-crypto-stream.test.ts`:
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
import { NodeCryptoBackend } from '../../src/adapters/node-crypto.js';
|
|
148
|
-
|
|
149
|
-
describe('NodeCryptoBackend Streaming', () => {
|
|
150
|
-
it('should handle incremental updates', () => {
|
|
151
|
-
const backend = new NodeCryptoBackend();
|
|
152
|
-
|
|
153
|
-
const parts = ['Hello', ' ', 'World', '!'];
|
|
154
|
-
const fullString = parts.join('');
|
|
155
|
-
|
|
156
|
-
parts.forEach(part => backend.update(part));
|
|
157
|
-
|
|
158
|
-
const result = backend.digest('hex');
|
|
159
|
-
|
|
160
|
-
// Compare with direct hash
|
|
161
|
-
const directResult = backend.hash(fullString);
|
|
162
|
-
expect(result).toBe(directResult);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it('should handle empty updates', () => {
|
|
166
|
-
const backend = new NodeCryptoBackend();
|
|
167
|
-
backend.update('');
|
|
168
|
-
backend.update('');
|
|
169
|
-
const result = backend.digest('hex');
|
|
170
|
-
expect(result).toBe('d41d8cd98f00b204e9800998ecf8427e');
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('should handle null bytes', () => {
|
|
174
|
-
const backend = new NodeCryptoBackend();
|
|
175
|
-
backend.update('test\x00data');
|
|
176
|
-
const result = backend.digest('hex');
|
|
177
|
-
expect(result.length).toBe(32);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### 3. Tests с реальными файлами
|
|
183
|
-
|
|
184
|
-
Создать файл `__tests__/integration/node-crypto-file.test.ts`:
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
import fs from 'fs';
|
|
188
|
-
import path from 'path';
|
|
189
|
-
import { NodeCryptoBackend } from '../../src/adapters/node-crypto.js';
|
|
190
|
-
|
|
191
|
-
describe('NodeCryptoBackend with Files', () => {
|
|
192
|
-
it('should hash a file', () => {
|
|
193
|
-
const backend = new NodeCryptoBackend();
|
|
194
|
-
const filePath = path.join(__dirname, 'fixtures', 'test-file.txt');
|
|
195
|
-
const content = fs.readFileSync(filePath);
|
|
196
|
-
|
|
197
|
-
const result = backend.hashBinary(content);
|
|
198
|
-
expect(result.length).toBe(32);
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it('should handle large files', () => {
|
|
202
|
-
const backend = new NodeCryptoBackend();
|
|
203
|
-
const filePath = path.join(__dirname, 'fixtures', 'large-file.bin');
|
|
204
|
-
|
|
205
|
-
if (!fs.existsSync(filePath)) {
|
|
206
|
-
console.log('Large file not found, skipping');
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const content = fs.readFileSync(filePath);
|
|
211
|
-
const result = backend.hashBinary(content);
|
|
212
|
-
expect(result.length).toBe(32);
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Ожидаемый результат
|
|
218
|
-
|
|
219
|
-
- ✅ Все тесты проходят успешно
|
|
220
|
-
- ✅ Покрытие кода >= 90%
|
|
221
|
-
- ✅ Tests stream API работают
|
|
222
|
-
- ✅ Интеграционные тесты с файлами
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# Phase 4: Adapter for Different Backends
|
|
2
|
-
|
|
3
|
-
Эта фаза посвящена созданию системы адаптеров для поддержки различных криптографических API (Web Crypto API, Node.js Crypto, Pure JS) с интеллектуальным обнаружением и fallback механизмами.
|
|
4
|
-
|
|
5
|
-
## Архитектурные задачи
|
|
6
|
-
|
|
7
|
-
- [01-architecture-assessment](./01-architecture-assessment.md) - Анализ архитектуры: интеграция или отдельный пакет
|
|
8
|
-
- [02-architecture-backend-api](./02-architecture-backend-api.md) - Проектирование универсального API для backend адаптеров
|
|
9
|
-
|
|
10
|
-
## Implementation backend адаптеров
|
|
11
|
-
|
|
12
|
-
- [03-backend-web-crypto](./03-backend-web-crypto.md) - Implementation Web Crypto API адаптера
|
|
13
|
-
- [04-backend-node-crypto](./04-backend-node-crypto.md) - Implementation Node.js Crypto адаптера
|
|
14
|
-
- [05-backend-pure-js](./05-backend-pure-js.md) - Рефакторинг существующего Pure JS кода в адаптер
|
|
15
|
-
- [06-backend-ie11](./06-backend-ie11.md) - Support Internet Explorer 11 (msCrypto)
|
|
16
|
-
|
|
17
|
-
## Интеллектуальное обнаружение backend
|
|
18
|
-
|
|
19
|
-
- [07-detection-environment](./07-detection-environment.md) - Implementation обнаружения окружения и доступных backend'ов
|
|
20
|
-
- [08-detection-backend](./08-detection-backend.md) - Implementation системы детекции оптимального backend'а
|
|
21
|
-
|
|
22
|
-
## Unified adapter и fallback
|
|
23
|
-
|
|
24
|
-
- [09-adapter-unified](./09-adapter-unified.md) - Создание unified adapter с единым интерфейсом
|
|
25
|
-
- [10-fallback-mechanism](./10-fallback-mechanism.md) - Implementation fallback механизмов с порядком предпочтения
|
|
26
|
-
|
|
27
|
-
## Testing и документация
|
|
28
|
-
|
|
29
|
-
- [11-tests-backend-web-crypto](./11-tests-backend-web-crypto.md) - Tests Web Crypto backend
|
|
30
|
-
- [12-tests-backend-node-crypto](./12-tests-backend-node-crypto.md) - Tests Node.js backend
|
|
31
|
-
- [13-tests-backend-pure-js](./13-tests-backend-pure-js.md) - Tests Pure JS backend
|
|
32
|
-
- [14-tests-detection](./14-tests-detection.md) - Tests системы детекции backend
|
|
33
|
-
- [15-tests-fallback](./15-tests-fallback.md) - Tests fallback механизмов
|
|
34
|
-
- [16-docs-adapter](./16-docs-adapter.md) - Documentation по использованию backend адаптеров
|
|
35
|
-
|
|
36
|
-
## Optimization и бенчмарки
|
|
37
|
-
|
|
38
|
-
- [17-optimization-tree-shaking](./17-optimization-tree-shaking.md) - Optimization для tree-shaking backend модулей
|
|
39
|
-
- [18-benchmarks-performance](./18-benchmarks-performance.md) - Бенчмарки производительности各 backend
|
|
40
|
-
|
|
41
|
-
## Integration в основной проект
|
|
42
|
-
|
|
43
|
-
- [19-integration-main](./19-integration-main.md) - Integration backend адаптеров в основной пакет
|
|
44
|
-
- [20-export-conditional](./20-export-conditional.md) - Setup conditional exports для разных backend'ов
|
|
45
|
-
- [21-versioning](./21-versioning.md) - Планирование версии с backend адаптерами
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
# README.md Optimization
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Optimize the README.md to follow best practices and increase package adoption.
|
|
6
|
-
|
|
7
|
-
## Current Issues
|
|
8
|
-
|
|
9
|
-
- [ ] Outdated badges (Travis CI - deprecated)
|
|
10
|
-
- [ ] Missing immediate value proposition
|
|
11
|
-
- [ ] Missing features list
|
|
12
|
-
- [ ] Missing installation examples
|
|
13
|
-
- [ ] Missing quick start section
|
|
14
|
-
- [ ] Missing badges for license, version, downloads
|
|
15
|
-
- [ ] Missing table of contents for longer sections
|
|
16
|
-
- [ ] Missing contribution guide link
|
|
17
|
-
- [ ] Missing support/sponsorship section
|
|
18
|
-
- [ ] Missing related packages link
|
|
19
|
-
|
|
20
|
-
## Best Practices for README.md
|
|
21
|
-
|
|
22
|
-
### 1. Essential Elements
|
|
23
|
-
- [ ] Clear project title and description
|
|
24
|
-
- [ ] Installation instructions
|
|
25
|
-
- [ ] Quick start example
|
|
26
|
-
- [ ] Features list
|
|
27
|
-
- [ ] Usage examples
|
|
28
|
-
- [ ] API documentation
|
|
29
|
-
- [ ] Contributing guidelines
|
|
30
|
-
- [ ] License information
|
|
31
|
-
|
|
32
|
-
### 2. Visual Elements
|
|
33
|
-
- [ ] Project logo/icon (if available)
|
|
34
|
-
- [ ] Relevant badges (only working and necessary ones)
|
|
35
|
-
- [ ] Code examples with proper syntax highlighting
|
|
36
|
-
- [ ] Screenshots/diagrams if applicable
|
|
37
|
-
|
|
38
|
-
### 3. Badges to Include
|
|
39
|
-
- [x] npm version
|
|
40
|
-
- [x] npm downloads
|
|
41
|
-
- [ ] License badge
|
|
42
|
-
- [ ] Build status (GitHub Actions)
|
|
43
|
-
- [ ] Coverage badge
|
|
44
|
-
- [ ] Bundle size badge
|
|
45
|
-
- [ ] TypeScript support badge
|
|
46
|
-
|
|
47
|
-
### 4. Structure
|
|
48
|
-
```markdown
|
|
49
|
-
# Project Name
|
|
50
|
-
|
|
51
|
-
[Badges]
|
|
52
|
-
|
|
53
|
-
## Features
|
|
54
|
-
|
|
55
|
-
## Quick Start
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
## Usage
|
|
60
|
-
|
|
61
|
-
## API
|
|
62
|
-
|
|
63
|
-
## Examples
|
|
64
|
-
|
|
65
|
-
## Contributing
|
|
66
|
-
|
|
67
|
-
## License
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Badges Evaluation
|
|
71
|
-
|
|
72
|
-
### Keep (Working & Motivational)
|
|
73
|
-
- [x] npm version - shows latest stable version
|
|
74
|
-
- [x] npm downloads - shows popularity
|
|
75
|
-
- [ ] GitHub Actions build status - shows current build state
|
|
76
|
-
- [ ] Coverage - shows test quality
|
|
77
|
-
- [ ] Bundle size - shows lightweight nature
|
|
78
|
-
- [ ] TypeScript support - shows modern JS features
|
|
79
|
-
|
|
80
|
-
### Remove (Deprecated/Unnecessary)
|
|
81
|
-
- [ ] Travis CI - deprecated service
|
|
82
|
-
- [ ] CodeClimate maintainability - replaced by GitHub
|
|
83
|
-
- [ ] CodeClimate coverage - replaced by codecov
|
|
84
|
-
|
|
85
|
-
## Implementation Tasks
|
|
86
|
-
|
|
87
|
-
- [ ] Rewrite top section with immediate value proposition
|
|
88
|
-
- [ ] Add features list with badges
|
|
89
|
-
- [ ] Add quick start section
|
|
90
|
-
- [ ] Update badges (remove Travis, add necessary ones)
|
|
91
|
-
- [ ] Add table of contents
|
|
92
|
-
- [ ] Add bundle size badge
|
|
93
|
-
- [ ] Add license badge
|
|
94
|
-
- [ ] Add contributing guide link
|
|
95
|
-
- [ ] Add sponsorship section
|
|
96
|
-
- [ ] Add "Why pure-md5?" section highlighting benefits
|
|
97
|
-
|
|
98
|
-
## Success Criteria
|
|
99
|
-
|
|
100
|
-
- [ ] README loads quickly and shows value in first screen
|
|
101
|
-
- [ ] Installation instructions are clear
|
|
102
|
-
- [ ] Quick start works immediately
|
|
103
|
-
- [ ] All badges are functional
|
|
104
|
-
- [ ] Documentation is in English and easy to understand
|
|
105
|
-
- [ ] Includes comparison with alternatives (if applicable)
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
# VitePress Documentation Site Evaluation
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Evaluate whether creating a VitePress documentation site is worthwhile for this project.
|
|
6
|
-
|
|
7
|
-
## Current Documentation State
|
|
8
|
-
|
|
9
|
-
- README.md - Basic documentation
|
|
10
|
-
- No dedicated documentation site
|
|
11
|
-
- Some markdown files in repository root
|
|
12
|
-
- Streaming API documentation (STREAM_*.md)
|
|
13
|
-
- Migration guides
|
|
14
|
-
|
|
15
|
-
## VitePress Advantages
|
|
16
|
-
|
|
17
|
-
### Benefits
|
|
18
|
-
- ✅ Modern, clean documentation interface
|
|
19
|
-
- ✅ Search functionality
|
|
20
|
-
- ✅ Multi-language support (future-proofing)
|
|
21
|
-
- ✅ Built-in versioning support
|
|
22
|
-
- ✅ MDX support for interactive examples
|
|
23
|
-
- ✅ Theme customization
|
|
24
|
-
- ✅ SEO-friendly
|
|
25
|
-
- ✅ Fast with Vue-based rendering
|
|
26
|
-
- ✅ GitHub Pages friendly
|
|
27
|
-
|
|
28
|
-
### For This Project
|
|
29
|
-
- ✅ Multiple APIs (core, stream, adapters) need clear documentation
|
|
30
|
-
- ✅ Examples are important for understanding usage
|
|
31
|
-
- ✅ Migration guides need proper organization
|
|
32
|
-
- ✅ Streaming API docs are currently in separate files
|
|
33
|
-
- ✅ Could show interactive examples with CDN
|
|
34
|
-
- ✅ Bundle size and performance metrics could be showcased
|
|
35
|
-
|
|
36
|
-
## VitePress Disadvantages
|
|
37
|
-
|
|
38
|
-
### Overhead
|
|
39
|
-
- ⚠️ Requires maintenance of documentation site
|
|
40
|
-
- ⚠️ Learning curve for contributors
|
|
41
|
-
- ⚠️ Additional build step
|
|
42
|
-
- ⚠️ Potential for docs to become outdated
|
|
43
|
-
|
|
44
|
-
### For This Project
|
|
45
|
-
- ⚠️ Project is relatively small (single function + utilities)
|
|
46
|
-
- ⚠️ Documentation is mostly complete in README
|
|
47
|
-
- ⚠️ May be overkill for simple API reference
|
|
48
|
-
- ⚠️ Smaller projects often just use README
|
|
49
|
-
|
|
50
|
-
## Alternative Options
|
|
51
|
-
|
|
52
|
-
### 1. Improve README (Recommended)
|
|
53
|
-
- Keep current approach
|
|
54
|
-
- Optimize README with better structure
|
|
55
|
-
- Use markdown anchors for navigation
|
|
56
|
-
- Add table of contents
|
|
57
|
-
- Link to examples directly
|
|
58
|
-
|
|
59
|
-
### 2. GitHub Wiki
|
|
60
|
-
- Free and simple
|
|
61
|
-
- GitHub integrated
|
|
62
|
-
- Less control over design
|
|
63
|
-
- Limited search
|
|
64
|
-
|
|
65
|
-
### 3. VitePress (Consider if)
|
|
66
|
-
- Project grows significantly
|
|
67
|
-
- Add more adapters or features
|
|
68
|
-
- Plan to support multiple versions with breaking changes
|
|
69
|
-
- Want to showcase performance benchmarks visually
|
|
70
|
-
- Need interactive API documentation
|
|
71
|
-
|
|
72
|
-
### 4. Other Static Site Generators
|
|
73
|
-
- Docusaurus (more features, heavier)
|
|
74
|
-
- Slate (Ruby-based, API-focused)
|
|
75
|
-
- MkDocs (Python-based)
|
|
76
|
-
|
|
77
|
-
## Recommendation
|
|
78
|
-
|
|
79
|
-
### For Current State: Improve README ✅
|
|
80
|
-
|
|
81
|
-
**Reasoning:**
|
|
82
|
-
1. Package is relatively small and focused
|
|
83
|
-
2. Documentation is mostly complete
|
|
84
|
-
3. Overhead not justified yet
|
|
85
|
-
4. README can be optimized sufficiently
|
|
86
|
-
|
|
87
|
-
### For Future Growth: VitePress 📅
|
|
88
|
-
|
|
89
|
-
**Trigger Points:**
|
|
90
|
-
- Add more adapters or features
|
|
91
|
-
- Add extensive examples gallery
|
|
92
|
-
- Plan to support multiple versions with breaking changes
|
|
93
|
-
- Want to showcase performance benchmarks visually
|
|
94
|
-
- Need interactive API documentation
|
|
95
|
-
|
|
96
|
-
## Implementation Plan (If Choosing VitePress)
|
|
97
|
-
|
|
98
|
-
### Phase 1: Setup
|
|
99
|
-
```bash
|
|
100
|
-
npm create vitepress@latest
|
|
101
|
-
# or
|
|
102
|
-
pnpm create vitepress
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Phase 2: Configuration
|
|
106
|
-
- Configure theme and styling
|
|
107
|
-
- Set up GitHub Actions deployment
|
|
108
|
-
- Configure sidebar navigation
|
|
109
|
-
- Add versioning
|
|
110
|
-
|
|
111
|
-
### Phase 3: Content Migration
|
|
112
|
-
- Move README to home page
|
|
113
|
-
- Split documentation into sections
|
|
114
|
-
- Add examples gallery
|
|
115
|
-
- Add API reference
|
|
116
|
-
- Add migration guides
|
|
117
|
-
|
|
118
|
-
### Phase 4: Maintenance
|
|
119
|
-
- Document how to update docs
|
|
120
|
-
- Add CI/CD for deployment
|
|
121
|
-
- Set up preview deployments
|
|
122
|
-
|
|
123
|
-
## Decision: ✅ Improve README Only
|
|
124
|
-
|
|
125
|
-
**Current recommendation is to focus on README.md optimization only.**
|
|
126
|
-
|
|
127
|
-
**When to reconsider:** When project grows beyond current scope or when user feedback indicates need for more comprehensive documentation.
|
|
128
|
-
|
|
129
|
-
## Alternative: Hybrid Approach
|
|
130
|
-
|
|
131
|
-
**Create lightweight documentation site later:**
|
|
132
|
-
- Keep README as quick start and overview
|
|
133
|
-
- Create VitePress site for detailed documentation
|
|
134
|
-
- Link to VitePress from README
|
|
135
|
-
- Use VitePress for API reference and examples
|
|
136
|
-
- Use README for installation and basic usage
|