index.js
1.21 KB
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
/**
* Handlebars helpers
* dongjinhu jinhu.dong@yoho.cn
* 2016-07-14
*/
'use strict';
/**
* 乘法
* @param {[Number]} num1
* @param {[Number]} num2
* @return {[boolen]}
*/
exports.multiple = (num1, num2) => {
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
if (num1 && num2) {
return num1 * num2;
}
};
/**
* 小于等于
* @param {[Number]} num1
* @param {[Number]} num2
* @param {[object]} options 上下文环境,一般不手动传
* @return {[boolen]}
*/
exports.lte = (num1, num2, options) => {
num1 = typeof num1 === 'number' ? num1 : parseFloat(num1, 10);
num2 = typeof num2 === 'number' ? num2 : parseFloat(num2, 10);
if (num1 <= num2) {
return options.fn(this);
}
return options.inverse(this);
};
/**
* 显示剩余库存
* @param {[Number]} leftNumber
* @return {[boolen]}
*/
exports.showStorage = (leftNumber) => {
leftNumber = typeof num1 === 'number' ? leftNumber : parseFloat(leftNumber, 10);
if (leftNumber <= 3 && leftNumber >= 0) {
return '仅剩' + leftNumber + '件';
} else if (leftNumber < 0) {
return '库存不足';
}
};