Skip to content

Instantly share code, notes, and snippets.

@levchenkod
Last active March 21, 2024 20:29
Show Gist options
  • Select an option

  • Save levchenkod/fa91600fb047f4d878db1a82bf01d75c to your computer and use it in GitHub Desktop.

Select an option

Save levchenkod/fa91600fb047f4d878db1a82bf01d75c to your computer and use it in GitHub Desktop.
RegExp to replace Nullish coalescing assignment with a custom logic. For old Node.js versions

RegExp Query:

([\(\)\._a-zA-Z]*)\s\?\?=\s([\._a-zA-Z\(\)]*)

RegExp Substitue With:

$1 = ($1 === null || $1 === undefined) ? $2 : $1

Example:

Line

boundary ??= parsedBoundary;

Turns into

boundary = (boundary === null || boundary === undefined) ? parsedBoundary : boundary;

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