rsuite
Version:
A suite of react components
17 lines (16 loc) • 603 B
JavaScript
'use client';
import React from 'react';
const toJSX = (node, key) => typeof node !== 'undefined' ? /*#__PURE__*/React.createElement("span", {
key: key
}, node) : null;
/**
* Transforms a pattern string by replacing placeholders with corresponding data values.
*
* @example
* tplTransform('Show {0} data', <i>100</i>);
* // output: Show <span><i>100</i></span> data
*/
export function tplTransform(pattern, ...data) {
return pattern.split(/\{(\d+)\}/).map((item, index) => index % 2 ? toJSX(data[+item], index) : toJSX(item, index)).filter(item => item !== '');
}
export default tplTransform;