Skip to content

Latest commit

 

History

History
90 lines (60 loc) · 2.29 KB

path_readme.md

File metadata and controls

90 lines (60 loc) · 2.29 KB

Overview

path.mjs provides functions for FS paths. Features:

  • Various common operations such as path joining, relativity, getting dirname/filename/extension, and more.
  • Only string operations, no IO.
  • OS-unaware. Provides separate implementations for Posix and Windows.
  • Tiny, no external dependencies.

Known limitations:

  • Insufficient documentation.
  • Immature. Tests may be incomplete.
  • Performance has not been optimized.

TOC

Usage

Using a specific implementation:

import * as p from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/path.mjs'

console.log(p.posix.join(`one`, `two`))
// 'one/two'

console.log(p.windows.join(`one`, `two`))
// 'one\\two'

Using the default implementation for the current OS:

import {paths as p} from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/io_deno.mjs'

console.log(p.join(`one`, `two`))
// 'one/two' or 'one\\two' depending on your OS

API

function toPosix

Links: source; test/example.

Idempotently converts a path from Windows-style to Posix-style. Useful in some edge case scenarios.

import * as p from 'https://cdn.jsdelivr.net/npm/@mitranim/[email protected]/path.mjs'

console.log(p.toPosix(`one\\two\\three`))
// 'one/two/three'

console.log(p.toPosix(`one/two/three`))
// 'one/two/three'

const posix

Links: source; test/example.

Implements various functions for Posix-style FS paths.

const windows

Links: source; test/example.

Implements various functions for Windows-style FS paths.

Undocumented

The following APIs are exported but undocumented. Check path.mjs.