MCPcopy Create free account
hub / github.com/circircir-circle/human_exist_device / formatTpl

Method formatTpl

mini_program/common/Validate.js:326–350  ·  view source on GitHub ↗

* 格式化提示信息模板

(source, params)

Source from the content-addressed store, hash-verified

324 * 格式化提示信息模板
325 */
326 formatTpl(source, params) {
327 const that = this
328 if (arguments.length === 1) {
329 return function() {
330 let args = Array.from(arguments)
331 args.unshift(source)
332 return that.formatTpl.apply(this, args)
333 }
334 }
335 if (params === undefined) {
336 return source
337 }
338 if (arguments.length > 2 && params.constructor !== Array) {
339 params = Array.from(arguments).slice(1)
340 }
341 if (params.constructor !== Array) {
342 params = [params]
343 }
344 params.forEach(function(n, i) {
345 source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function() {
346 return n
347 })
348 })
349 return source
350 }
351
352 /**
353 * 判断规则依赖是否存在

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected