Skip to content

Commit dfee36e

Browse files
jonkoopsrolandjitsu
authored andcommitted
refactor!: drop UMD distribution from package
BREAKING CHANGE: removes the UMD distribution from the package Signed-off-by: Jon Koops <[email protected]>
1 parent a164ce8 commit dfee36e

File tree

4 files changed

+71
-653
lines changed

4 files changed

+71
-653
lines changed

README.md

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,71 +21,116 @@
2121

2222

2323
## Installation
24-
You can install this package from [NPM](https://www.npmjs.com):
24+
25+
You can install this package from [NPM](https://www.npmjs.com/package/file-selector):
26+
2527
```bash
2628
npm add file-selector
2729
```
2830

29-
### CDN
30-
For CDN, you can use [unpkg](https://unpkg.com):
31+
### Bundler
3132

32-
[https://unpkg.com/file-selector/dist/bundles/file-selector.umd.min.js](https://unpkg.com/file-selector/dist/bundles/file-selector.umd.min.js)
33+
If you are using a bundler such as [Vite](https://vite.dev/) or [Webpack](https://webpack.js.org/) you can import the package directly:
3334

34-
The global namespace for file-selector is `fileSelector`:
3535
```js
36-
const {fromEvent} = fileSelector;
37-
document.addEventListener('drop', async evt => {
38-
const files = await fromEvent(evt);
39-
console.log(files);
40-
});
36+
import {fromEvent} from 'file-selector';
37+
```
38+
39+
### Browser
40+
41+
To include the package directly in the browser without a bundling step you can choose to either use a CDN, or include the required files in your own project.
42+
43+
#### CDN
44+
45+
If you want to use a CDN, you can use [Skypack](https://www.skypack.dev/), or any other CDN of your choice. Make sure you are specifying a compatible version range to avoid unexpected breaking changes.
46+
47+
```html
48+
<script type="module">
49+
import {fromEvent} from 'https://cdn.skypack.dev/file-selector@^1.0.0';
50+
</script>
51+
```
52+
53+
#### Self-hosted
54+
55+
Self hosting is also possible, make sure to copy or link the contents of the NPM package into your project and import them as you would any other module.
56+
57+
```html
58+
<script type="module">
59+
import {fromEvent} from './path/to/file-selector.js';
60+
</script>
4161
```
4262

63+
#### Import maps
64+
65+
To avoid repeating the import path and get an experience similar to a bundler you can opt to use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap).
66+
67+
```html
68+
<script type="importmap">
69+
{
70+
"imports": {
71+
// Using the CDN
72+
"file-selector": "https://cdn.skypack.dev/file-selector@^1.0.0"
73+
// Or a path to your own self-hosted version.
74+
"file-selector": "./path/to/file-selector.js"
75+
}
76+
}
77+
</script>
78+
<script type="module">
79+
import {fromEvent} from 'file-selector';
80+
</script>
81+
```
4382

4483
## Usage
4584

46-
### ES6
4785
Convert a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) to File objects:
48-
```ts
86+
87+
```js
4988
import {fromEvent} from 'file-selector';
50-
document.addEventListener('drop', async evt => {
51-
const files = await fromEvent(evt);
89+
90+
document.addEventListener('drop', async (event) => {
91+
const files = await fromEvent(event);
5292
console.log(files);
5393
});
5494
```
5595

5696
Convert a [change event](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/change_event) for an input type file to File objects:
57-
```ts
97+
98+
```js
5899
import {fromEvent} from 'file-selector';
100+
59101
const input = document.getElementById('myInput');
60-
input.addEventListener('change', async evt => {
61-
const files = await fromEvent(evt);
102+
input.addEventListener('change', async (event) => {
103+
const files = await fromEvent(event);
62104
console.log(files);
63105
});
64106
```
65107

66108
Convert [FileSystemFileHandle](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle) items to File objects:
67-
```ts
109+
110+
```js
68111
import {fromEvent} from 'file-selector';
69112

70-
// Open file picker
71113
const handles = await window.showOpenFilePicker({multiple: true});
72-
// Get the files
73114
const files = await fromEvent(handles);
74115
console.log(files);
75116
```
76-
**NOTE** The above is experimental and subject to change.
117+
118+
> [!NOTE]
119+
> The above is experimental and subject to change.
77120
78121
### CommonJS
122+
79123
Convert a `DragEvent` to File objects:
80-
```ts
124+
125+
```js
81126
const {fromEvent} = require('file-selector');
82-
document.addEventListener('drop', async evt => {
83-
const files = await fromEvent(evt);
127+
128+
document.addEventListener('drop', async (event) => {
129+
const files = await fromEvent(event);
84130
console.log(files);
85131
});
86132
```
87133

88-
89134
## Browser Support
90135
Most browser support basic File selection with drag 'n' drop or file input:
91136
* [File API](https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility)

0 commit comments

Comments
 (0)