Skip to content

Instantly share code, notes, and snippets.

@Hans5958
Created February 22, 2024 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hans5958/5e373f85183252ce5713b5151327eebd to your computer and use it in GitHub Desktop.
Save Hans5958/5e373f85183252ce5713b5151327eebd to your computer and use it in GitHub Desktop.
Converting from chalk-template to chalk with replace-all feature.
  1. Convert from template literal format.

    Find: chalk`(.*)\{([a-z]+) (.+)\}
    Replace: $1${chalk.$2(`$3`)}
    sed syntax: s/chalk`(.*)\{([a-z]+) (.+)\}/$1${chalk.$2(`$3`)}/g

  2. Convert chalk.foo(`${bar}`) to chalk.foo(bar).

    Find: \(`\$\{([^`{}]+)\}`\)
    Replace: ($1)
    sed syntax: s/\(`\$\{([^`{}]+)\}`\)/($1)/g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment