You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
canteen/uniCloud-aliyun/cloudfunctions/uni-sms-co/utils.js

42 lines
864 B

exports.chunk = function (arr, num) {
const list = []
let current = []
for (const item of arr) {
current.push(item);
if (current.length === num) {
list.push(current)
current = []
}
}
if (current.length) list.push(current)
return list
}
exports.checkIsStaticTemplate = function (data = []) {
let isStatic = data.length <= 0
for (const template of data) {
if (template.type === 'static') {
isStatic = true
break
}
}
return isStatic
}
exports.parserDynamicField = function (templateData) {
return templateData.reduce((res, template) => {
if (/\{.*?\}/.test(template.value)) {
const [collection, field] = template.value.replace(/\{|\}/g, '').split('.')
if (!res[collection]) {
res[collection] = []
}
res[collection].push(field)
}
return res
}, {})
}