-
Notifications
You must be signed in to change notification settings - Fork 37
/
validators.js
56 lines (50 loc) · 1.48 KB
/
validators.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export const isObject = value => value !== null && typeof value === 'object'
export const isFileList = value =>
typeof FileList !== 'undefined' && value instanceof FileList
export const isUploadFile = value =>
(typeof File !== 'undefined' && value instanceof File) ||
(typeof Blob !== 'undefined' && value instanceof Blob) ||
value instanceof ReactNativeFile
/**
* A React Native FormData file object.
* @see {@link https://github.com/facebook/react-native/blob/v0.45.1/Libraries/Network/FormData.js#L34}
* @typedef {Object} ReactNativeFileObject
* @property {String} uri - File system path.
* @property {String} [type] - File content type.
* @property {String} [name] - File name.
*/
/**
* A React Native file.
*/
export class ReactNativeFile {
/**
* Constructs a new file.
* @param {ReactNativeFileObject} file
* @example
* const file = new ReactNativeFile({
* uri: uriFromCameraRoll,
* type: 'image/jpeg',
* name: 'photo.jpg'
* })
*/
constructor({ uri, type, name }) {
this.uri = uri
this.type = type
this.name = name
}
/**
* Creates an array of file instances.
* @param {ReactNativeFileObject[]} files
* @example
* const files = ReactNativeFile.list([{
* uri: uriFromCameraRoll1,
* type: 'image/jpeg',
* name: 'photo-1.jpg'
* }, {
* uri: uriFromCameraRoll2,
* type: 'image/jpeg',
* name: 'photo-2.jpg'
* }])
*/
}
ReactNativeFile.list = files => files.map(file => new ReactNativeFile(file))