UNPKG

openapi-ts-json-schema

Version:

Generate TypeScript-first JSON schemas from OpenAPI definitions

13 lines (12 loc) 490 B
import path from 'node:path'; /** * Evaluate the relative import path from a directory to a module * Accepts posix and win32 absolute urls and returns a relative import path ("./foo/bar") */ export function makeRelativeImportPath({ fromDirectory, toModule, moduleSystem = 'esm', }) { if (moduleSystem === 'esm' && !toModule.endsWith('.js')) { toModule += '.js'; } return ('./' + path.relative(fromDirectory, toModule).replaceAll(path.sep, path.posix.sep)); }