结构调整

This commit is contained in:
fofolee
2022-04-08 10:26:32 +08:00
parent 001897ad48
commit cfd7f2f884
12 changed files with 23 additions and 12 deletions

View File

@@ -0,0 +1,15 @@
/**
* 快速导入同一目录下的所有脚本
*/
const importAll = context => {
const map = {}
for (const key of context.keys()) {
const keyArr = key.split('/')
keyArr.shift()
map[keyArr.join('.').replace(/\.\w+$/g, '')] = context(key)
}
return map
}
export default importAll

View File

@@ -0,0 +1,24 @@
/**
* 判断内容是否为 quickcommand 可导入格式
*/
// 是否含有 quickcommand 键值
let isJsonQc = (obj, strict = true) => {
var keys = strict ? ["features", "program", "cmd", "output"] : ["program", "cmd"]
if (keys.filter(x => typeof obj[x] == 'undefined').length) return false
return true
}
// 判断是否为可导入的快捷命令
let qcparser = (json, strict = true) => {
try {
var qc = JSON.parse(json)
} catch (error) {
return false
}
if (isJsonQc(qc, strict)) return { single: true, qc: qc }
else if (!Object.values(qc).filter(q => !isJsonQc(q, strict)).length) return { single: false, qc: qc }
else return false
}
export default qcparser