es-toolkit
es-toolkit copied to clipboard
feat(template): add `template` in compat layer
Description
- The source of the function compiled using the template function has been updated to use ES6+ syntax for greater clarity. For example,
+\n((__t = (" + interpolateValue + ")) == null ? '' : __twas replaced with+ (${interpolateValue} ?? '').- However, with the use of ES6+ syntax, runtime environments that do not support these features may encounter errors.
- We ensure that modules remain unmodifiable when bundled as both CJS and ESM. However, there were some test cases that modified these modules. Therefore, those parts have been commented out.
Benchmarks
Copilot Summary
Template Functionality:
src/compat/string/template.ts: Implemented thetemplatefunction to create compiled template functions that can interpolate, evaluate, and escape data properties based on provided options.src/compat/string/templateSettings.ts: Defined default settings for thetemplatefunction, including escape, evaluate, and interpolate delimiters, and imported functions.
Miscellaneous:
src/compat/_internal/numberTag.ts: Added a constantnumberTagfor internal use.src/compat/index.ts: Exported thetemplatefunction andtemplateSettingsfrom the string utilities module.
close #672