template.js 524 B

1234567891011121314151617181920
  1. var setupDefaults = require('./setupDefaults')
  2. var toValueString = require('./toValueString')
  3. var trim = require('./trim')
  4. var get = require('./get')
  5. /**
  6. * 解析动态字符串模板
  7. * @param {atring} str 字符串模板
  8. * @param {any | any[]} args 对象
  9. * @param {any} options
  10. */
  11. function template (str, args, options) {
  12. return toValueString(str).replace((options || setupDefaults).tmplRE || /\{{2}([.\w[\]\s]+)\}{2}/g, function (match, key) {
  13. return get(args, trim(key))
  14. })
  15. }
  16. module.exports = template