@antmove/wx-alipay
Version:
transform wechat miniprogram to alipay miniprogram tool.
35 lines (31 loc) • 686 B
JavaScript
/**
* 把props的data属性,处理成dataset
* { 'data-alpha-beta': 3 }
* { alphaBeta: 3 }
*/
function processDataSet(e, props = {}) {
if (e.timeStamp === undefined) {
e = {
...e,
target: {
dataset: {},
},
currentTarget: {
dataset: {},
},
}
}
Object.keys(props)
.forEach((prop) => {
const matched = prop.match(/^data-(.+)/)
if (matched) {
const key = matched[1].replace(/-(\w)/, ($0, $1) => {
return $1.toUpperCase()
})
e.target.dataset[key] = props[prop]
e.currentTarget.dataset[key] = props[prop]
}
})
return e
}
module.exports = processDataSet