garyvv /
node-sharp
| 1 | module.exports = { |
||
| 2 | |||
| 3 | isEmpty: async function(value) { |
||
| 4 | return (Array.isArray(value) && value.length === 0) || |
||
| 5 | (Object.prototype.isPrototypeOf(value) && Object.keys(value).length === 0) |
||
| 6 | }, |
||
| 7 | |||
| 8 | /** |
||
| 9 | * 二进制转十进制 |
||
| 10 | */ |
||
| 11 | bindec: async function(binNum) { |
||
| 12 | let result = 0 |
||
| 13 | let total = binNum.length |
||
| 14 | for (let index = 1; index <= total; index++) { |
||
| 15 | let tmp = binNum.slice(total - index, total - index + 1) |
||
| 16 | let tmpAdd = parseInt(tmp) * parseInt(Math.pow(2, index - 1)) |
||
| 17 | result += tmpAdd |
||
| 18 | } |
||
| 19 | |||
| 20 | return result |
||
| 21 | }, |
||
| 22 | |||
| 23 | /** |
||
| 24 | * |
||
| 25 | */ |
||
| 26 | today: async function(symbol = '') { |
||
| 27 | let date = new Date() |
||
| 28 | return date.getFullYear() + symbol + (date.getMonth() < 10 ? '0' + (date.getMonth() + 1) : (date.getMonth() + 1)) + symbol + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) |
||
| 29 | }, |
||
| 30 | |||
| 31 | versionCompare: function(v1, v2) { |
||
| 32 | let version1pre = parseFloat(v1) |
||
| 33 | let version2pre = parseFloat(v2) |
||
| 34 | let version1next = v1.replace(version1pre + ".", "") |
||
| 35 | let version2next = v2.replace(version2pre + ".", "") |
||
| 36 | if (version1pre > version2pre) { |
||
| 37 | return true; |
||
| 38 | } else if (version1pre < version2pre) { |
||
| 39 | return false; |
||
| 40 | } else { |
||
| 41 | if (version1next >= version2next) { |
||
| 42 | return true; |
||
| 43 | } else { |
||
|
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
| 44 | return false; |
||
| 45 | } |
||
| 46 | } |
||
| 47 | }, |
||
| 48 | |||
| 49 | checkObject: function(object, fields, tips) { |
||
| 50 | let result = {} |
||
| 51 | if (!UnderScore.isObject(object)) { |
||
|
0 ignored issues
–
show
The variable
UnderScore seems to be never declared. If this is a global, consider adding a /** global: UnderScore */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 52 | console.log('not object') |
||
|
0 ignored issues
–
show
|
|||
| 53 | object = JSON.parse(object) |
||
| 54 | } |
||
| 55 | |||
| 56 | fields.forEach(element => { |
||
| 57 | if (UnderScore.has(object, element) !== true) { |
||
|
0 ignored issues
–
show
The variable
UnderScore seems to be never declared. If this is a global, consider adding a /** global: UnderScore */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 58 | throw new ApiError('validate.error', tips + ' 对象缺 ' + element + ' 属性') |
||
|
0 ignored issues
–
show
The variable
ApiError seems to be never declared. If this is a global, consider adding a /** global: ApiError */ comment.
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed. To learn more about declaring variables in Javascript, see the MDN. Loading history...
|
|||
| 59 | } |
||
| 60 | result[element] = object[element] |
||
| 61 | }) |
||
| 62 | |||
| 63 | return result |
||
| 64 | }, |
||
| 65 | |||
| 66 | } |