zent
Version:
一套前端设计语言和基于React的实现
41 lines (35 loc) • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var getValue = exports.getValue = function getValue(value, max, min) {
return min + (max - min) * value;
};
var getDecimal = exports.getDecimal = function getDecimal(step) {
var fixed = String(step).split('.')[1];
return fixed ? fixed.length : 0;
};
var toFixed = exports.toFixed = function toFixed(value, step) {
var length = getDecimal(step);
return Number(Number(value).toFixed(length));
};
var getLeft = exports.getLeft = function getLeft(value, max, min) {
return (value - min) * 100 / (max - min);
};
var getClosest = exports.getClosest = function getClosest(value, pointValue) {
var newValue = void 0;
if (Math.abs(value[0] - pointValue) <= Math.abs(value[1] - pointValue)) {
newValue = [pointValue, value[1]];
} else {
newValue = [value[0], pointValue];
}
return newValue;
};
var checkValueInRange = exports.checkValueInRange = function checkValueInRange(newValue, max, min) {
if (newValue > max) {
newValue = max;
} else if (newValue < min) {
newValue = min;
}
return newValue;
};