Skip to content

Commit beb1a06

Browse files
author
Roland Groza
committed
chore: initial commit
0 parents  commit beb1a06

21 files changed

+5030
-0
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs
2+
# http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*{.yml}]
14+
indent_size = 2
15+
16+
[*.md]
17+
trim_trailing_whitespace = false
18+
max_line_length = off

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
## Node
4+
# Logs
5+
*.log
6+
npm-debug.log*
7+
8+
# Dependency directory
9+
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
10+
node_modules
11+
12+
13+
## OS X
14+
.DS_Store
15+
.AppleDouble
16+
.LSOverride
17+
18+
# Icon must end with two \r
19+
Icon
20+
21+
# Thumbnails
22+
._*
23+
24+
25+
## Direnv
26+
.envrc
27+
28+
29+
## Dist
30+
coverage
31+
build
32+
docs
33+
dist
34+
out-tsc
35+
tmp

.npmignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
coverage
2+
node_modules
3+
out-tsc
4+
src/*.spec.ts
5+
test
6+
.editorconfig
7+
.travis.yml
8+
jest.config.js
9+
rollup.config.js
10+
tsconfig.cjs.json
11+
tsconfig.es5.json
12+
tsconfig.es2015.json
13+
tsconfig.json
14+
tsconfig.spec.json
15+
tsconfig.types.json
16+
tslint.json
17+
yarn.lock

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: node_js
2+
node_js:
3+
- '8'
4+
5+
script:
6+
- yarn test:cov
7+
- yarn build
8+
9+
deploy:
10+
provider: npm
11+
12+
api_key:
13+
secure: SIMajitPIq2/9TtRGi+hhcWAy3EGY+FrpkvjsG4pfuRn92/NweqYa91yKlmgGQdte1LALToWT1uVPNABoP3IZToRe2au268MIaNCrEHo7yspHorGC1JvDDcLXAnqXz+ILxNODwmodMqVvM0xORXsUCXUu7y6HCLztiEJLwqTQKD846m3zK25AQ8Xvl8Vx8EKcAy3Uwqhw5s+GGcpp6fqo/gifvnQwHx9VEuke4ta4Weh59Qa6kyJdXcJ74IZtp5uKxDaoyM2mkZ0bFu+672nZE4QedhaCbBADhsKuzmJt4smEZIItN2DO7hwNXjlFT4mFwMe2KSq3G6DMNtAGS56omPDm1geArYSrYoBvUrUnGBJpRfRxJnT6ftIUd1vzTrwyS0UQuoU4DqhmHO/Tr7/AamKznhQk0p4iBcxZfUzP+uadtcN07+7ncWDj/YyobzvR7dWoZulSEjKp4AGDbe0rMxlBYTRO3lMTp96nHC6+hp9B5oMRmEol+hnxQYyh3LcBjfOh5ll//SbfzwO1Gx3+c3lwKbCheEFWWctlZ10VDHD2jQvr4UdAbWDT0scDghDkKtQWDCevnq+/0TEI1sF9IYs8DL66Rq3h4t+t+E0OsRKXGUI4fga5VpLl5/PcWe9WWbanDvZcAGJ3GA4TlH6jcUM2xoAzRQvUpMFQxQld9g=
14+
skip_cleanup: true
15+
on:
16+
tags: true
17+
18+
notifications:
19+
email:
20+
on_success: change

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# File Selector
2+
3+
> A small package for converting a [DragEvent](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent) or [file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file) to a list of File objects.
4+
5+
[![Travis (.org) branch](https://img.shields.io/travis/rolandjitsu/file-selector/master.svg?style=flat-square)](https://github.com/rolandjitsu/file-selector)
6+
7+
8+
# Table of Contents
9+
10+
* [Installation](#installation)
11+
* [Usage](#usage)
12+
* [Browser Support](#browser-support)
13+
* [Contribute](#contribute)
14+
* [Credits](#credits)
15+
16+
17+
### Installation
18+
----------------
19+
You can install this package from [NPM](https://www.npmjs.com):
20+
```bash
21+
npm add file-selector
22+
```
23+
24+
Or with [Yarn](https://yarnpkg.com/en):
25+
```bash
26+
yarn add file-selector
27+
```
28+
29+
#### CDN
30+
For CDN, you can use [unpkg](https://unpkg.com):
31+
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+
34+
The global namespace for file-selector is `fileSelector`:
35+
```js
36+
const {fromEvent} = fileSelector;
37+
document.addEventListener('drop', evt => {
38+
const files = fromEvent(evt);
39+
console.log(files);
40+
});
41+
```
42+
43+
44+
### Usage
45+
---------
46+
47+
#### ES6
48+
Convert a `DragEvent` to File objects:
49+
```ts
50+
import {fromEvent} from 'file-selector';
51+
document.addEventListener('drop', evt => {
52+
const files = fromEvent(evt);
53+
console.log(files);
54+
});
55+
```
56+
57+
Convert a file input to File objects:
58+
```ts
59+
import {fromEvent} from 'file-selector';
60+
const input = document.getElementById('myInput');
61+
input.addEventListener('change', evt => {
62+
const files = fromEvent(evt);
63+
console.log(files);
64+
});
65+
```
66+
67+
#### CommonJS
68+
Convert a `DragEvent` to File objects:
69+
```ts
70+
const {fromEvent} = require('file-selector');
71+
document.addEventListener('drop', evt => {
72+
const files = fromEvent(evt);
73+
console.log(files);
74+
});
75+
```
76+
77+
78+
### Browser Support
79+
-------------------
80+
Most browser support basic File selection with drag 'n' drop or file input:
81+
* [File API](https://developer.mozilla.org/en-US/docs/Web/API/File#Browser_compatibility)
82+
* [Drag Event](https://developer.mozilla.org/en-US/docs/Web/API/DragEvent#Browser_compatibility)
83+
* [DataTransfer](https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer#Browser_compatibility)
84+
* [`<input type="file">`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#Browser_compatibility)
85+
86+
For folder drop we use the [FileSystem API](https://developer.mozilla.org/en-US/docs/Web/API/FileSystem) which has very limited support:
87+
* [DataTransferItem.getAsFile()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/getAsFile#Browser_compatibility)
88+
* [DataTransferItem.webkitGetAsEntry()](https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry#Browser_compatibility)
89+
* [FileSystemEntry](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry#Browser_compatibility)
90+
* [FileSystemFileEntry.file()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileEntry/file#Browser_compatibility)
91+
* [FileSystemDirectoryEntry.createReader()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryEntry/createReader#Browser_compatibility)
92+
* [FileSystemDirectoryReader.readEntries()](https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryReader/readEntries#Browser_compatibility)
93+
94+
95+
### Contribute
96+
--------------
97+
If you wish to contribute, please use the following guidelines:
98+
* Use [Conventional Commits](https://conventionalcommits.org)
99+
* Use `[ci skip]` in commit messages to skip a build
100+
101+
102+
### Credits
103+
-----------
104+
* [html5-file-selector](https://github.com/quarklemotion/html5-file-selector)

jest.config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
globals: {
3+
'ts-jest': {
4+
tsConfig: './tsconfig.spec.json',
5+
diagnostics: true
6+
}
7+
},
8+
transform: {
9+
'^.+\\.tsx?$': 'ts-jest'
10+
},
11+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
12+
coveragePathIgnorePatterns: [
13+
'<rootDir>/dist/',
14+
'<rootDir>/node_modules/',
15+
'<rootDir>/out-tsc/',
16+
'<rootDir>/test/'
17+
],
18+
moduleFileExtensions: [
19+
'ts',
20+
'tsx',
21+
'js',
22+
'jsx',
23+
'json',
24+
'node'
25+
]
26+
};

package.json

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"name": "file-selector",
3+
"version": "0.1.0",
4+
"description": "Convert DataTransfer object to a list of File objects",
5+
"main": "./dist/index.js",
6+
"module": "./dist/es5/index.js",
7+
"es2015": "./dist/es2015/index.js",
8+
"typings": "./dist/index.d.ts",
9+
"keywords": [
10+
"drag-and-drop",
11+
"html5",
12+
"file-api",
13+
"DataTransfer",
14+
"File"
15+
],
16+
"homepage": "https://github.com/rolandjitsu/file-selector",
17+
"license": "MIT",
18+
"author": {
19+
"name": "Roland Groza",
20+
"email": "[email protected]"
21+
},
22+
"repository": {
23+
"type": "git",
24+
"url": ""
25+
},
26+
"scripts": {
27+
"prebuild": "yarn run clean",
28+
"build": "npm-run-all -s compile build:umd",
29+
"build:umd": "rollup -c ./rollup.config.js",
30+
"compile": "npm-run-all -p compile:es2015 compile:es5 compile:cjs compile:types",
31+
"compile:es2015": "tsc -p ./tsconfig.es2015.json",
32+
"compile:es5": "tsc -p ./tsconfig.es5.json",
33+
"compile:cjs": "tsc -p ./tsconfig.cjs.json",
34+
"compile:types": "tsc -p ./tsconfig.types.json",
35+
"clean": "rm -rf dist/*",
36+
"lint": "tslint -c tslint.json -p ./tsconfig.spec.json -t stylish",
37+
"lint:fix": "yarn run lint -- --fix",
38+
"pretest:cov": "yarn run lint",
39+
"test:cov": "jest --coverage",
40+
"test": "jest --watch",
41+
"release": "standard-version"
42+
},
43+
"standard-version": {
44+
"scripts": {
45+
"prerelease": "yarn test:cov"
46+
}
47+
},
48+
"dependencies": {
49+
"tslib": "^1.9.0"
50+
},
51+
"devDependencies": {
52+
"@babel/core": "^7.0.0-beta.54",
53+
"@types/jest": "^23.3.3",
54+
"@types/node": "^9.4.5",
55+
"babel-core": "^7.0.0-0",
56+
"babel-jest": "^23.4.0",
57+
"camelcase": "^4.1.0",
58+
"jest": "^23.6.0",
59+
"jest-environment-jsdom": "^23.4.0",
60+
"npm-run-all": "^4.1.3",
61+
"rollup": "^0.65.0",
62+
"rollup-plugin-commonjs": "^9.1.6",
63+
"rollup-plugin-node-resolve": "^3.3.0",
64+
"rollup-plugin-sourcemaps": "^0.4.2",
65+
"rollup-plugin-uglify": "^4.0.0",
66+
"standard-version": "^4.4.0",
67+
"ts-jest": "^23.10.3",
68+
"tslint": "^5.9.1",
69+
"typescript": "^3.0.3"
70+
},
71+
"engines": {
72+
"node": ">= 8"
73+
}
74+
}

rollup.config.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
const camelCase = require('camelcase');
2+
const commonjs = require('rollup-plugin-commonjs');
3+
const resolve = require('rollup-plugin-node-resolve');
4+
const sourcemaps = require('rollup-plugin-sourcemaps');
5+
const {uglify} = require('rollup-plugin-uglify');
6+
7+
const pckg = require('./package.json');
8+
const name = pckg.name;
9+
const input = pckg.module;
10+
11+
const plugins = [
12+
resolve(),
13+
commonjs(),
14+
sourcemaps()
15+
];
16+
17+
const output = {
18+
format: 'umd',
19+
name: camelCase(name),
20+
// The key here is library name,and the value is the the name of the global variable name the window object.
21+
// See https://github.com/rollup/rollup/wiki/JavaScript-API#globals for more.
22+
globals: {
23+
// TS
24+
// 'tslib': 'tslib'
25+
},
26+
sourcemap: true
27+
};
28+
29+
// List of dependencies
30+
// See https://github.com/rollup/rollup/wiki/JavaScript-API#external for more.
31+
const external = [
32+
// TS
33+
// 'tslib'
34+
];
35+
36+
export default [{
37+
input,
38+
plugins,
39+
external,
40+
output: {
41+
...output,
42+
file: distPath(`${name}.umd.js`)
43+
}
44+
},
45+
{
46+
input,
47+
plugins: [
48+
...plugins,
49+
uglify()
50+
],
51+
external,
52+
output: {
53+
...output,
54+
file: distPath(`${name}.umd.min.js`)
55+
}
56+
}];
57+
58+
function distPath(file) {
59+
return `./dist/bundles/${file}`;
60+
}

0 commit comments

Comments
 (0)