char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
83ff6f3
main
1import { op_path_platform } from "ext:core/ops" ; 2import { posix as posixNamespace , win32 as win32Namespace } from "./api.js" ; 3 4export interface ParsedPath { 5root :string ; 6dir :string ; 7base :string ; 8name :string ; 9ext :string ; 10} 11 12export interface PathObject { 13dir ?:string ; 14root ?:string ; 15base ?:string ; 16name ?:string ; 17ext ?:string ; 18} 19 20/** Lexical path operations with one fixed separator flavor, plus file URL conversion for that flavor. */ 21export interface Path { 22join ( ...paths :string []) :string ; 23resolve ( ...paths :string []) :string ; 24normalize ( path :string ) :string ; 25relative ( from :string , to :string ) :string ; 26dirname ( path :string ) :string ; 27basename ( path :string , suffix ?:string ) :string ; 28extname ( path :string ) :string ; 29isAbsolute ( path :string ) :boolean ; 30parse ( path :string ) :ParsedPath ; 31format ( pathObject :PathObject ) :string ; 32toNamespacedPath ( path :string ) :string ; 33readonly sep :string ; 34readonly delimiter :string ; 35fromFileUrl ( url :URL | string ) :string ; 36toFileUrl ( path :string ) :URL ; 37} 38 39/** Explicit POSIX semantics on any host. */ 40export const posix :Path = posixNamespace ; 41 42/** Explicit Windows semantics on any host. */ 43export const win32 :Path = win32Namespace ; 44 45const native = op_path_platform () === "win32" ?win32 :posix ; 46 47/** Joins segments with the native separator, then normalizes; `""` segments are skipped. */ 48export const join :( ...paths :string []) => string = native . join ; 49 50/** Resolves segments right to left, consulting the working directory only for relative, root-relative, or drive-relative input; fully qualified inputs need no read grant. */ 51export const resolve :( ...paths :string []) => string = native . resolve ; 52 53export const normalize :( path :string ) => string = native . normalize ; 54 55/** Lexical path from `from` to `to`; fully qualified pairs need no read grant. */ 56export const relative :( from :string , to :string ) => string = native . relative ; 57 58export const dirname :( path :string ) => string = native . dirname ; 59 60export const basename :( path :string , suffix ?:string ) => string = native . basename ; 61 62export const extname :( path :string ) => string = native . extname ; 63 64export const isAbsolute :( path :string ) => boolean = native . isAbsolute ; 65 66export const parse :( path :string ) => ParsedPath = native . parse ; 67 68export const format :( pathObject :PathObject ) => string = native . format ; 69 70export const toNamespacedPath :( path :string ) => string = native . toNamespacedPath ; 71 72export const sep :string = native . sep ; 73 74export const delimiter :string = native . delimiter ; 75 76/** Converts an absolute `file:` URL to a path; rejects queries, fragments, and encoded separators. Needs no permissions. */ 77export const fromFileUrl :( url :URL | string ) => string = native . fromFileUrl ; 78 79/** Converts an absolute path to a `file:` URL; never consults the working directory. Needs no permissions. */ 80export const toFileUrl :( path :string ) => URL = native . toFileUrl ;