Completely updated React, fixed #11, (hopefully)

This commit is contained in:
2018-03-04 19:11:49 -05:00
parent 6e0afd6e2a
commit 34e5f5139a
13674 changed files with 333464 additions and 473223 deletions

View File

@@ -1,4 +0,0 @@
{
"stage": 0,
"loose": "all"
}

View File

@@ -3,7 +3,7 @@ root = true
[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

View File

@@ -1,12 +1,7 @@
{
"extends": "airbnb",
"extends": "okonet",
"env": {
"browser": true,
"mocha": true,
"node": true
},
"rules": {
"indent": [2, 4],
"comma-dangle": [2, "never"]
"mocha": true
}
}

View File

@@ -1,5 +0,0 @@
javascript:
enabled: false
eslint:
enabled: true
config_file: .eslintrc

View File

@@ -1,4 +1,3 @@
sudo: false
language: node_js
cache:
directories:
@@ -6,23 +5,13 @@ cache:
notifications:
email: false
node_js:
- 'stable'
- '8'
- '6'
- '4'
- iojs-v3
- iojs-v2
- iojs-v1
- '0.12'
before_install:
- npm i -g npm@^2.0.0
before_script:
- npm prune
- npm i -g npm@^5.0.0
after_success:
- bash <(curl -s https://codecov.io/bash)
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
- python travis_after_all.py
- export $(cat .to_export_back) &> /dev/null
- npm run semantic-release
- travis-deploy-once "npm install -g semantic-release@13 && semantic-release"
branches:
except:
- /^v\d+\.\d+\.\d+$/

View File

@@ -2,6 +2,7 @@
JavaScript implementation of the "accept" attribute for HTML5 `<input type="file">`
[![Build Status](https://travis-ci.org/okonet/attr-accept.svg?branch=master)](https://travis-ci.org/okonet/attr-accept)
[![npm version](https://badge.fury.io/js/attr-accept.svg)](https://badge.fury.io/js/attr-accept)
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#Attributes for more information.

File diff suppressed because one or more lines are too long

View File

@@ -1,31 +1,31 @@
{
"_args": [
[
"attr-accept@1.1.0",
"attr-accept@1.1.2",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI"
]
],
"_from": "attr-accept@1.1.0",
"_id": "attr-accept@1.1.0",
"_from": "attr-accept@1.1.2",
"_id": "attr-accept@1.1.2",
"_inBundle": false,
"_integrity": "sha1-tc01In8WOTWo8d4Q7T66FpQfa+Y=",
"_integrity": "sha512-NUj0itVSnpFkUYCj3XKSRCZ7N9gPwWcyX/tF7HosqyDBPMSygALivvJIGI8VvlPcunns5khMkpxoNshvmhy/ZQ==",
"_location": "/attr-accept",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "attr-accept@1.1.0",
"raw": "attr-accept@1.1.2",
"name": "attr-accept",
"escapedName": "attr-accept",
"rawSpec": "1.1.0",
"rawSpec": "1.1.2",
"saveSpec": null,
"fetchSpec": "1.1.0"
"fetchSpec": "1.1.2"
},
"_requiredBy": [
"/"
],
"_resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-1.1.0.tgz",
"_spec": "1.1.0",
"_resolved": "https://registry.npmjs.org/attr-accept/-/attr-accept-1.1.2.tgz",
"_spec": "1.1.2",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\goTorrentWebUI",
"author": {
"name": "Andrey Okonetchnikov @okonetchnikov"
@@ -38,24 +38,36 @@
"path": "./node_modules/cz-conventional-changelog"
}
},
"dependencies": {
"core-js": "^2.5.0"
},
"description": "JavaScript implementation of the \"accept\" attribute for HTML5 <input type=\"file\">",
"devDependencies": {
"babel": "^5.8.23",
"babel-core": "5.8.25",
"babel-eslint": "^4.1.1",
"babel-loader": "5.3.2",
"core-js": "1.2.2",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"cz-conventional-changelog": "^1.2.0",
"eslint": "^1.3.1",
"eslint-config-airbnb": "0.0.8",
"eslint-plugin-react": "^3.3.1",
"expect": "^1.9.0",
"mocha": "^2.3.2",
"semantic-release": "^4.3.5",
"webpack": "1.12.2"
"eslint": "^4.6.1",
"eslint-config-airbnb": "^15.1.0",
"eslint-config-okonet": "^6.1.3",
"eslint-config-prettier": "^2.4.0",
"eslint-plugin-flowtype": "^2.35.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-jsx-a11y": "^5.1.1",
"eslint-plugin-node": "^5.1.1",
"eslint-plugin-prettier": "^2.2.0",
"eslint-plugin-react": "^7.3.0",
"expect": "^1.20.2",
"husky": "^0.14.3",
"lint-staged": "^4.1.3",
"mocha": "^3.5.0",
"prettier": "^1.6.1",
"travis-deploy-once": "^4.3.4",
"webpack": "^3.5.5"
},
"engines": {
"node": ">=0.10"
"node": ">=4"
},
"homepage": "https://github.com/okonet/attr-accept#readme",
"keywords": [
@@ -68,6 +80,12 @@
"file"
],
"license": "MIT",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
},
"main": "dist/index.js",
"name": "attr-accept",
"repository": {
@@ -76,12 +94,13 @@
},
"scripts": {
"build": "webpack -p",
"check": "npm run lint && npm test",
"lint": "eslint ./src",
"prepublish": "npm run check && npm run build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"test": "mocha --compilers js:babel/register --recursive",
"test:watch": "npm test -- --watch"
"lint": "eslint src/ test/",
"precommit": "lint-staged",
"prepublish": "npm test && npm run build",
"pretest": "npm run lint",
"test": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch",
"travis-deploy-once": "travis-deploy-once"
},
"version": "1.1.0"
"version": "1.1.2"
}

View File

@@ -9,28 +9,28 @@
* @returns {boolean}
*/
import 'core-js/fn/array/some';
import 'core-js/fn/string/ends-with';
import 'core-js/fn/array/some'
import 'core-js/fn/string/ends-with'
export default function(file, acceptedFiles) {
if (file && acceptedFiles) {
const acceptedFilesArray = (Array.isArray(acceptedFiles) ?
acceptedFiles :
acceptedFiles.split(','));
const fileName = file.name || '';
const mimeType = file.type || '';
const baseMimeType = mimeType.replace(/\/.*$/, '');
if (file && acceptedFiles) {
const acceptedFilesArray = Array.isArray(acceptedFiles)
? acceptedFiles
: acceptedFiles.split(',')
const fileName = file.name || ''
const mimeType = file.type || ''
const baseMimeType = mimeType.replace(/\/.*$/, '')
return acceptedFilesArray.some(type => {
const validType = type.trim();
if (validType.charAt(0) === '.') {
return fileName.toLowerCase().endsWith(validType.toLowerCase());
} else if (/\/\*$/.test(validType)) {
// This is something like a image/* mime type
return baseMimeType === validType.replace(/\/.*$/, '');
}
return mimeType === validType;
});
}
return true;
return acceptedFilesArray.some(type => {
const validType = type.trim()
if (validType.charAt(0) === '.') {
return fileName.toLowerCase().endsWith(validType.toLowerCase())
} else if (/\/\*$/.test(validType)) {
// This is something like a image/* mime type
return baseMimeType === validType.replace(/\/.*$/, '')
}
return mimeType === validType
})
}
return true
}

View File

@@ -1,154 +1,289 @@
/* eslint no-unused-expressions: 0 */
import expect from 'expect';
import accept from '../src/index';
import expect from 'expect'
import accept from '../src/index'
describe('accept', () => {
it('should return true if called without acceptedFiles', () => {
expect(accept({
name: 'testfile.png',
type: 'some/type'
}, undefined)).toBe(true);
});
it('should return true if called without acceptedFiles', () => {
expect(
accept(
{
name: 'testfile.png',
type: 'some/type'
},
undefined
)
).toBe(true)
})
it('should not throw and return true if file is empty or null', () => {
expect(() => {
accept({});
accept({}, 'text/html');
accept({}, '*.png');
accept({}, 'image/*');
it('should not throw and return true if file is empty or null', () => {
expect(() => {
accept({})
accept({}, 'text/html')
accept({}, '*.png')
accept({}, 'image/*')
accept(null);
accept(null, 'text/html');
accept(null, '*.png');
accept(null, 'image/*');
}).toNotThrow();
});
accept(null)
accept(null, 'text/html')
accept(null, '*.png')
accept(null, 'image/*')
}).toNotThrow()
})
it('should properly validate if called with concrete mime types', () => {
const acceptedMimeTypes = 'text/html,image/jpeg,application/json';
expect(accept({
name: 'testfile.png',
type: 'text/html'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/jpeg'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'application/json'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/bmp'
}, acceptedMimeTypes)).toBe(false);
expect(accept({
type: 'image/bmp'
}, acceptedMimeTypes)).toBe(false);
});
it('should properly validate if called with concrete mime types', () => {
const acceptedMimeTypes = 'text/html,image/jpeg,application/json'
expect(
accept(
{
name: 'testfile.png',
type: 'text/html'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'application/json'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/bmp'
},
acceptedMimeTypes
)
).toBe(false)
expect(
accept(
{
type: 'image/bmp'
},
acceptedMimeTypes
)
).toBe(false)
})
it('should properly validate if called with base mime types', () => {
const acceptedMimeTypes = 'text/*,image/*,application/*';
expect(accept({
name: 'testfile.png',
type: 'text/html'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/jpeg'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'application/json'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/bmp'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'some/type'
}, acceptedMimeTypes)).toBe(false);
});
it('should properly validate if called with base mime types', () => {
const acceptedMimeTypes = 'text/*,image/*,application/*'
expect(
accept(
{
name: 'testfile.png',
type: 'text/html'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'application/json'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/bmp'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'some/type'
},
acceptedMimeTypes
)
).toBe(false)
})
it('should properly validate if called with mixed mime types', () => {
const acceptedMimeTypes = 'text/*,image/jpeg,application/*';
expect(accept({
name: 'testfile.png',
type: 'text/html'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/jpeg'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/bmp'
}, acceptedMimeTypes)).toBe(false);
expect(accept({
name: 'testfile.png',
type: 'application/json'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'some/type'
}, acceptedMimeTypes)).toBe(false);
});
it('should properly validate if called with mixed mime types', () => {
const acceptedMimeTypes = 'text/*,image/jpeg,application/*'
expect(
accept(
{
name: 'testfile.png',
type: 'text/html'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/bmp'
},
acceptedMimeTypes
)
).toBe(false)
expect(
accept(
{
name: 'testfile.png',
type: 'application/json'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'some/type'
},
acceptedMimeTypes
)
).toBe(false)
})
it('should properly validate even with spaces in between', () => {
const acceptedMimeTypes = 'text/html , image/jpeg, application/json';
expect(accept({
name: 'testfile.png',
type: 'text/html'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.png',
type: 'image/jpeg'
}, acceptedMimeTypes)).toBe(true);
});
it('should properly validate even with spaces in between', () => {
const acceptedMimeTypes = 'text/html , image/jpeg, application/json'
expect(
accept(
{
name: 'testfile.png',
type: 'text/html'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.png',
type: 'image/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
})
it('should properly validate extensions', () => {
const acceptedMimeTypes = 'text/html , image/jpeg, .pdf ,.png';
expect(accept({
name: 'somxsfsd',
type: 'text/html'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'somesdfsdf',
type: 'image/jpeg'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'somesdfadfadf',
type: 'application/json'
}, acceptedMimeTypes)).toBe(false);
expect(accept({
name: 'some-file file.pdf',
type: 'random/type'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'some-file.pdf file.gif',
type: 'random/type'
}, acceptedMimeTypes)).toBe(false);
expect(accept({
name: 'some-FILEi File.PNG',
type: 'random/type'
}, acceptedMimeTypes)).toBe(true);
});
it('should properly validate extensions', () => {
const acceptedMimeTypes = 'text/html , image/jpeg, .pdf ,.png'
expect(
accept(
{
name: 'somxsfsd',
type: 'text/html'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'somesdfsdf',
type: 'image/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'somesdfadfadf',
type: 'application/json'
},
acceptedMimeTypes
)
).toBe(false)
expect(
accept(
{
name: 'some-file file.pdf',
type: 'random/type'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'some-file.pdf file.gif',
type: 'random/type'
},
acceptedMimeTypes
)
).toBe(false)
expect(
accept(
{
name: 'some-FILEi File.PNG',
type: 'random/type'
},
acceptedMimeTypes
)
).toBe(true)
})
it('should allow accepted files passed to be an array', () => {
const acceptedMimeTypes = ['img/jpeg', '.pdf'];
expect(accept({
name: 'testfile.pdf',
type: 'random/type'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile.jpg',
type: 'img/jpeg'
}, acceptedMimeTypes)).toBe(true);
expect(accept({
name: 'testfile',
type: 'application/json'
}, acceptedMimeTypes)).toBe(false);
});
});
it('should allow accepted files passed to be an array', () => {
const acceptedMimeTypes = ['img/jpeg', '.pdf']
expect(
accept(
{
name: 'testfile.pdf',
type: 'random/type'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile.jpg',
type: 'img/jpeg'
},
acceptedMimeTypes
)
).toBe(true)
expect(
accept(
{
name: 'testfile',
type: 'application/json'
},
acceptedMimeTypes
)
).toBe(false)
})
})

View File

@@ -1,20 +1,18 @@
{
module.exports = {
entry: "./src/index.js",
output: {
path: __dirname,
filename: "./dist/index.js",
libraryTarget: "commonjs2",
library: "react-attr"
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/
}
]
}
module.exports = {
entry: './src/index.js',
output: {
path: __dirname,
filename: './dist/index.js',
libraryTarget: 'commonjs2',
library: 'react-attr'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
}
]
}
};
}