Policy Name: policyName1 ……省略中间内容…… Policy Type: Standard (0) ……省略中间内容…… Client/HW/OS/Pri/CIT: Client1 Client/HW/OS/Pri/CIT: Client2 Client/HW/OS/Pri/CIT: Client3 Client/HW/OS/Pri/CIT: Client4 ……省略多个Client Include: /dir1 Include: /dir2 Include: /dir3 ……省略多个Include Schedule: Schedule1 Type: …… Schedule: Schedule2 Type: …… ……省略多个Schedule Policy Name: policyName2 ……省略中间内容…… ……
fs.readFile(filePath, 'UTF-8', function (err, data) {
if (err) throw err;
// 对文件读取的数据进行处理,首先用 policyName 进行切割
var policyLists = data.split(config.splitRules.policyName);
if (policyLists[0] === '\r\n') {
policyLists.shift();
};
policyLists.forEach(function (policy) {
var policyData = policyFormatter(config.splitRules.policyName + policy);
excelData.push(policyData);
});
/**
* 对每一个policy进行整理 使其符合表格插入的形式
* @param {*} policy
* {
* policyName: String
* client: []]
* policyType: String
* include: []
* schedule[]
* scheduleResidence: String
* }
*
*/
function policyFormatter(policy) {
var policyNameMatcher = new RegExp(config.splitRules.policyName + "([\\s\\w\\d\\-]*)\\r\\n"),
clientMatcher = new RegExp(config.splitRules.client + "([\\s\\w\\d\\?\\-\\.]*)\\r\\n", "g"),
policyTypeMatcher = new RegExp(config.splitRules.policyType + "([\\s\\w\\d\\(\\)\\-]*)\\r\\n"),
includeMatcher = new RegExp(config.splitRules.include + "([\\s/\\w\\.\\\\:_\\?=\\\"\\*]*)\\r\\n", "g");
var scheduleLists = policy.split(config.splitRules.schedule).slice(1),
scheduleFormatLists = [],
scheduleResidenceMatcher = new RegExp(config.splitRules.scheduleResidence + "([\\s\\w\\d\\-\\(\\)]*)\\r\\n");
scheduleLists.forEach(function (schedule) {
var scheduleFormat = config.splitRules.schedule + schedule;
scheduleFormatLists.push(scheduleFormat);
});
// console.log(scheduleFormatLists);
var results = {
policyName: policy.match(policyNameMatcher)[1].trim(),
client: policy.match(clientMatcher) ? policy.match(clientMatcher).join('').trim() : '',
policyType: policy.match(policyTypeMatcher)[1].trim(),
include: policy.match(includeMatcher).join('').trim(),
schedule: scheduleFormatLists.join('').trim(),
scheduleResidence: scheduleLists[0].match(scheduleResidenceMatcher)[1].trim()
};
// console.dir(results);
return results;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有