-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.js
38 lines (31 loc) · 910 Bytes
/
utils.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
/*\
title: $:/plugins/FSpark/file-uploads-Aliyun-OSS/utils.js
type: application/javascript
module-type: library
\*/
const REGEXP_IMAGE_TYPE = /^image\/.+$/;
exports.bytesToSize = function (bytes) {
if (bytes === 0) return '0 B';
var k = 1024,
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
}
exports.isImageType=function (value) {
return REGEXP_IMAGE_TYPE.test(value);
}
exports.imageTypeToExtension=function (value) {
let extension = exports.isImageType(value) ? value.substr(6) : '';
if (extension === 'jpeg') {
extension = 'jpg';
}
return `.${extension}`;
}
exports.isInArray=function (arr,value){
for(var i = 0; i < arr.length; i++){
if(value === arr[i]){
return true;
}
}
return false;
}