UNPKG

counterfact

Version:

Generate a TypeScript-based mock server from an OpenAPI spec in seconds — with stateful routes, hot reload, and REPL support.

8 lines (7 loc) 402 B
export function convertFileExtensionsToCjs(code) { // Match require('...') or require("...") where the path starts with . // Replace .js or .ts extensions (or no extension) with .cjs return code.replace( // eslint-disable-next-line regexp/prefer-named-capture-group /require\((['"])(\.[^'"]*?)(\.(?:js|ts))?\1\)/g, (match, quote, path) => `require(${quote}${path}.cjs${quote})`); }