Skip to main content

String.cooked

Less than 1 minutefeaturees-proposal

String.cookedopen in new window

Module

esnext.string.cookedopen in new window

Types

interface StringConstructor {
  cooked(template: Array<string>, ...substitutions: Array<string>): string;
}

Entry points

core-js/proposals/string-cooked
core-js(-pure)/full/string/cooked

Example

Exampleopen in new window:

function safePath(strings, ...subs) {
  return String.cooked(strings, ...subs.map((sub) => encodeURIComponent(sub)));
}

let id = "spottie?";

safePath`/cats/${id}`; // => /cats/spottie%3F