1 Star 0 Fork 0

fastutils/excel-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
number.js 4.78 KB
一键复制 编辑 原始数据 按行查看 历史
wangmiao 提交于 2020-05-27 22:34 . fixed bugs
const utils = require('./utils');
const PropertyInfo = require('./property');
const forNumberByIndexAndSetter = (column, setter) => forNumberByIndexAndSetterAndRequired(column, setter, utils.DEFAULT_REQUIRED);
const forNumberByIndexAndSetterAndRequired = (column, setter, required) => forNumberByIndexAndSetterAndValidator(column, setter, utils.defaultPropertyRequiredValidator(required));
const forNumberByIndexAndSetterAndValidator = (column, setter, validator) => forNumberByRangeAndCreatorAndReaderAndSetterAndValidator(column, column, utils.defaultCreator, utils.defaultPropertySetter(setter), utils.defaultSetter, utils.defaultPropertyValidator(validator));
const forNumberByRangeAndSetter = (minColumn, maxColumn, setter) => forNumberByRangeAndSetterAndRequired(minColumn, maxColumn, setter, utils.DEFAULT_REQUIRED);
const forNumberByRangeAndSetterAndRequired = (minColumn, maxColumn, setter, required) => forNumberByRangeAndSetterAndValidator(minColumn, maxColumn, setter, utils.defaultPropertyRequiredValidator(required));
const forNumberByRangeAndSetterAndValidator = (minColumn, maxColumn, setter, validator) => forNumberByRangeAndCreatorAndReaderAndSetterAndValidator(minColumn, maxColumn, utils.defaultCreator, utils.defaultPropertySetter(setter), utils.defaultSetter, utils.defaultPropertyValidator(validator));
const forNumberByIndexAndCreatorAndReaderAndSetter = (column, creator, reader, setter) => forNumberByIndexAndCreatorAndReaderAndSetterAndRequired(column, creator, reader, setter, utils.DEFAULT_REQUIRED);
const forNumberByIndexAndCreatorAndReaderAndSetterAndRequired = (column, creator, reader, setter, required) => forNumberByIndexAndCreatorAndReaderAndSetterAndValidator(column, creator, reader, setter, utils.defaultRequiredValidator(required));
const forNumberByIndexAndCreatorAndReaderAndSetterAndValidator = (column, creator, reader, setter, validator) => forNumberByRangeAndCreatorAndReaderAndSetterAndValidator(column, column, creator, reader, setter, validator);
const forNumberByRangeAndCreatorAndReaderAndSetter = (minColumn, maxColumn, creator, reader, setter) => forNumberByRangeAndCreatorAndReaderAndSetterAndRequired(minColumn, maxColumn, creator, reader, setter, utils.DEFAULT_REQUIRED);
const forNumberByRangeAndCreatorAndReaderAndSetterAndRequired = (minColumn, maxColumn, creator, reader, setter, required) => forNumberByRangeAndCreatorAndReaderAndSetterAndValidator(minColumn, maxColumn, creator, reader, setter, utils.defaultRequiredValidator(required));
const forNumberByRangeAndCreatorAndReaderAndSetterAndValidator = (minColumn, maxColumn, creator, reader, setter, validator) => {
return new PropertyInfo(minColumn, maxColumn, cell => {
if (cell.value === 'NaN') {
return NaN;
} else if (isNaN(cell.value)) {
throw new utils.ExcelValueFormatError(cell.rowIndex, cell.columnIndex, cell.value, 'value is not a number:' + cell.value);
} else {
return parseFloat(cell.value);
}
}, creator, reader, setter, validator);
};
const forNumber = (...args) => {
let lastBoolean = utils.isBoolean(args[args.length - 1]);
if (utils.isFunction(args[1])) {
if (args.length === 2) {
return forNumberByIndexAndSetter(...args);
} else if (args.length === 3) {
if (lastBoolean) {
return forNumberByIndexAndSetterAndRequired(...args);
} else {
return forNumberByIndexAndSetterAndValidator(...args);
}
} else if (args.length === 4) {
return forNumberByIndexAndCreatorAndReaderAndSetter(...args);
} else if (args.length === 5) {
if (lastBoolean) {
return forNumberByIndexAndCreatorAndReaderAndSetterAndRequired(...args);
} else {
return forNumberByIndexAndCreatorAndReaderAndSetterAndValidator(...args);
}
}
} else {
if (args.length === 3) {
return forNumberByRangeAndSetter(...args);
} else if (args.length === 4) {
if (lastBoolean) {
return forNumberByRangeAndSetterAndRequired(...args);
} else {
return forNumberByRangeAndSetterAndValidator(...args);
}
} else if (args.length === 5) {
return forNumberByRangeAndCreatorAndReaderAndSetter(...args);
} else if (args.length === 6) {
if (lastBoolean) {
return forNumberByRangeAndCreatorAndReaderAndSetterAndRequired(...args);
} else {
return forNumberByRangeAndCreatorAndReaderAndSetterAndValidator(...args);
}
}
}
}
module.exports = forNumber;
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fastutils/excel-js.git
git@gitee.com:fastutils/excel-js.git
fastutils
excel-js
excel-js
master

搜索帮助