Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
match if does not include string

I'd like to append .js extension to all import statements where the file path to be imported starts with a .. For example:

import { LocalConf } from "./database/LocalConf";
import * as mariadb from "mariadb";
import { Errors } from "./util/Errors";

gets transformed to

import { LocalConf } from "./database/LocalConf.js";
import * as mariadb from "mariadb";
import { Errors } from "./util/Errors.js";

This is the js command I am running:

let newData = data.replace(/(import .*? from\s+['"])(\..*?[^\.js])(?=['"])/g, '$1$2.js')

Unfortunately [^\.js] matches a single character, and not a .js string. because of that,

import { Errors } from "./util/Errors";

never gets .js appeneded.

How can I match .js string instead of just single characters?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Could you do something like this?

function addExtension(path) {
  if (path.contains('from "./')) {
    return path + ".js";
  }

  return path;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!