UNPKG

@loom-io/node-filesystem-adapter

Version:

A file system wrapper for Node.js and Bun

26 lines (25 loc) 799 B
import { addPrecedingAndTailingSlash } from '@loom-io/common'; export class ObjectDirent { _dirent; _rootPath; constructor(_dirent, _rootPath) { this._dirent = _dirent; this._rootPath = _rootPath; } isDirectory() { return this._dirent.isDirectory(); } isFile() { return this._dirent.isFile(); } get name() { return this._dirent.name; } get path() { const pathFromRelativeRoot = this._dirent.parentPath.slice(this._rootPath.length); if (process.version.startsWith('v18') && pathFromRelativeRoot.endsWith(this.name)) { return addPrecedingAndTailingSlash(pathFromRelativeRoot.slice(0, -this.name.length)); } return addPrecedingAndTailingSlash(pathFromRelativeRoot); } }