This release is 4 versions behind 0.1.4 — the latest version of @m234/path. Jump to latest
Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Built and signed on GitHub Actions
Sort, parse and format a path array/object.
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers




JSR Score
100%
Published
a month ago (0.1.0)
@m234/path
Sort, parse and format a path array/object.
Usage
Convert between string iterable and objects:
import { pathObjectFrom, pathRecordFilesSet } from "@m234/path"; const paths = [ "src/components/Button.tsx", "src/utils/helpers.ts", "public/index.html", ]; const obj = pathObjectFrom(paths); // { // "src": { // "components": { "Button.tsx": "" }, // "utils": { "helpers.ts": "" } // }, // "public": { "index.html": "" } // } const pathSet = pathRecordFilesSet(obj); // Set(3) { // "src/components/Button.tsx", // "src/utils/helpers.ts", // "public/index.html" // }
Iterate over paths using generator:
import { type PathRecord, pathRecordToGenerator } from "@m234/path"; const obj: PathRecord = { "src": { "components": { "Button.tsx": "" }, "utils": { "helpers.ts": "" }, }, "public": { "index.html": "" }, }; const iterator = pathRecordToGenerator(obj); for (const { parent, path } of iterator) { console.log(`path: ${path}`); } // Output: // path: src // path: src/components // path: src/components/Button.tsx // path: src/utils // path: src/utils/helpers.ts // path: public // path: public/index.html
Sort paths:
import { sortFirstFolders } from "@m234/path"; const paths = [ "z/file.txt", "a/deep/path/file.txt", "a/file.txt", ]; sortFirstFolders(paths); // paths == [ // "a/deep/path/file.txt", // "a/file.txt", // "z/file.txt" // ]
Built and signed on
GitHub Actions
Add Package
deno add jsr:@m234/path
Import symbol
import * as path from "@m234/path";
Import directly with a jsr specifier
import * as path from "jsr:@m234/path";
Add Package
pnpm i jsr:@m234/path
pnpm dlx jsr add @m234/path
Import symbol
import * as path from "@m234/path";
Add Package
yarn add jsr:@m234/path
yarn dlx jsr add @m234/path
Import symbol
import * as path from "@m234/path";
Add Package
vlt install jsr:@m234/path
Import symbol
import * as path from "@m234/path";
Add Package
npx jsr add @m234/path
Import symbol
import * as path from "@m234/path";
Add Package
bunx jsr add @m234/path
Import symbol
import * as path from "@m234/path";