es-toolkit icon indicating copy to clipboard operation
es-toolkit copied to clipboard

feat(template): add `template` in compat layer

Open dayongkr opened this issue 1 year ago • 2 comments

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 ? '' : __t was 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

Screenshot 2024-10-08 at 2 29 05 PM

Copilot Summary

Template Functionality:

  • src/compat/string/template.ts: Implemented the template function 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 the template function, including escape, evaluate, and interpolate delimiters, and imported functions.

Miscellaneous:

  • src/compat/_internal/numberTag.ts: Added a constant numberTag for internal use.
  • src/compat/index.ts: Exported the template function and templateSettings from the string utilities module.

close #672

dayongkr avatar Oct 07 '24 13:10 dayongkr