template.js 487 B

12345678910111213141516
  1. import { reduce } from '@antv/util';
  2. /**
  3. * 简单的模板引擎,使用方式如下(空格自动忽略):
  4. * template('hello, {name}', { name: 'AntV' }); // hello, AntV
  5. * @param string
  6. * @param options
  7. */
  8. export function template(source, data) {
  9. if (!data) {
  10. return source;
  11. }
  12. return reduce(
  13. // @ts-ignore
  14. data, function (r, v, k) { return r.replace(new RegExp("{\\s*".concat(k, "\\s*}"), 'g'), v); }, source);
  15. }
  16. //# sourceMappingURL=template.js.map