Skip to content

Replacements for is-path-in-cwd ​

is-path-in-cwd is is-path-inside with process.cwd() as the parent, so use the is-path-inside replacement and pass the working directory yourself.

ts
import path from 'node:path'

const isPathInside = (childPath, parentPath) => {
  const relation = path.relative(parentPath, childPath)
  return Boolean(
    relation &&
    relation !== '..' &&
    !relation.startsWith(`..${path.sep}`) &&
    relation !== path.resolve(childPath)
  )
}

const isPathInCwd = (p) => isPathInside(p, process.cwd())

Released under the MIT License. (13757e3d)