@universal-uploader/core 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +126 -0
  2. package/package.json +15 -4
package/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # @usu/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@usu/core.svg)](https://www.npmjs.com/package/@usu/core)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@usu/core.svg)](https://www.npmjs.com/package/@usu/core)
5
+
6
+ **[📦 NPM](https://www.npmjs.com/package/@usu/core)** | **[🔗 Main README](../README.md)** | **[⚛️ React](./packages/react)**
7
+
8
+ Core file upload orchestrator. Three adaptive strategies, one unified API.
9
+
10
+ ## Three Upload Methods
11
+
12
+ ### 1. Fetch Stream (1 request, O(1) memory)
13
+ Perfect for small/medium files on modern browsers.
14
+ ```typescript
15
+ await upload('/api/upload', file, { method: 'stream' });
16
+ ```
17
+
18
+ ### 2. Fetch Chunked (N requests, resumable)
19
+ Best for large files with precise progress and resumption.
20
+ ```typescript
21
+ await upload('/api/upload', file, {
22
+ method: 'stream chunked',
23
+ chunkSize: 1024 * 1024, // 1MB
24
+ onProgress: (p) => console.log(p.percentage)
25
+ });
26
+ ```
27
+
28
+ ### 3. XHR Chunked (N requests, legacy support)
29
+ Broadest compatibility with byte-level progress.
30
+ ```typescript
31
+ await upload('/api/upload', file, {
32
+ method: 'xhr chunked',
33
+ chunkSize: 512 * 1024
34
+ });
35
+ ```
36
+
37
+ ### Auto-Select (Default)
38
+ ```typescript
39
+ await upload('/api/upload', file, {
40
+ method: 'auto' // Fetch Stream → Fetch Chunked → XHR Chunked
41
+ });
42
+ ```
43
+
44
+ ## Installation
45
+
46
+ ```bash
47
+ npm install @usu/core
48
+ yarn add @usu/core
49
+ pnpm add @usu/core
50
+ ```
51
+
52
+ NPM: https://www.npmjs.com/package/@usu/core
53
+
54
+ ## Upload Control
55
+
56
+ ```typescript
57
+ const { upload, pause, resume, abort, refresh, retry } = await upload(url, file, options);
58
+
59
+ pause(); // Status: "paused" (resumable)
60
+ resume(); // Continue from offset
61
+ abort(); // Status: "aborted" (terminal)
62
+ refresh(); // Full restart from initial options
63
+ retry(file); // Manual retry
64
+ ```
65
+
66
+ ## Configuration
67
+
68
+ ```typescript
69
+ interface UploadOptions {
70
+ method?: 'stream' | 'stream chunked' | 'xhr chunked' | 'auto';
71
+ chunkSize?: number; // 512KB default
72
+ retryCount?: number; // 3 default
73
+ retryDelay?: number | ((attempt: number) => number);
74
+ customHeaders?: Record<string, string>;
75
+ withCredentials?: boolean;
76
+ onProgress?: (p: { loaded: number; total: number; percentage: number }) => void;
77
+ onError?: (error: Error) => void;
78
+ onRetry?: () => void;
79
+ throwOnError?: boolean; // false default
80
+ }
81
+ ```
82
+
83
+ ## Types
84
+
85
+ ```typescript
86
+ import type {
87
+ UploadResult, // { ok: boolean; total: number; status: 'success' | 'error' | ... }
88
+ UploadStatus, // 'idle' | 'uploading' | 'paused' | 'success' | 'error' | 'aborted'
89
+ UploadOptions,
90
+ UploadParams
91
+ } from '@usu/core';
92
+ ```
93
+
94
+ ## Error Handling
95
+
96
+ ```typescript
97
+ // Automatic retry with exponential backoff
98
+ await upload('/api/upload', file, {
99
+ retryCount: 5,
100
+ retryDelay: (attempt) => Math.pow(2, attempt) * 1000
101
+ });
102
+
103
+ // Throw on error
104
+ try {
105
+ await upload('/api/upload', file, { throwOnError: true });
106
+ } catch (err) {
107
+ console.error(err);
108
+ }
109
+ ```
110
+
111
+ ## Browser Support
112
+
113
+ - Chrome/Edge: Fetch Stream ✅
114
+ - Firefox: Fetch Stream ✅
115
+ - Safari/IE: XHR Fallback (auto-detected) ✅
116
+
117
+ ## Performance
118
+
119
+ - < 5 kB gzipped
120
+ - Zero dependencies
121
+ - 100% TypeScript
122
+ - Constant memory (Stream) or bounded (Chunked)
123
+
124
+ ## License
125
+
126
+ MIT
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@universal-uploader/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
- "description": "Core streaming upload logic.",
5
+ "description": "Zero-dependency browser file upload library with Web Streams, Fetch Duplex, XHR fallback, progress tracking, chunked uploads, and automatic retries.",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -22,9 +22,20 @@
22
22
  },
23
23
  "keywords": [
24
24
  "upload",
25
- "stream",
25
+ "file-upload",
26
+ "streaming",
27
+ "web-streams",
26
28
  "fetch",
27
- "xhr"
29
+ "xhr",
30
+ "progress",
31
+ "chunked-upload",
32
+ "multipart",
33
+ "large-files",
34
+ "browser",
35
+ "duplex",
36
+ "retry",
37
+ "resumable",
38
+ "universal-uploader"
28
39
  ],
29
40
  "license": "MIT",
30
41
  "scripts": {