The string-dedent spec is the longest AO I've ever seen for a single API. I wrote a faithful TS implementation which is a 1-1 translation from the spec text:
dedent.ts
declare global {
interface StringConstructor {
dedent<A extends unknown[], R>(tag: (template: TemplateStringsArray, ...substitutions: A) => R): (template: TemplateStringsArray, ...substitutions: A) => string;
dedent(template: TemplateStringsArray, ...substitutions: unknown[]): string;
}
}
// @ts-expect-error: deliberate narrow
String.dedent = (() => {
const GlobalDedentRegistry = new WeakMap<object, TemplateStringsArray>();
This file has been truncated. show original
Hope that could be useful for testing
2 Likes
ljharb
August 4, 2022, 4:48am
2
Sounds like a great PR to https://npmjs.com/es-abstract once itβs stage 4 :-D
1 Like