Skip to main content
Home
This release is 4 versions behind 0.1.4 — the latest version of @m234/path. Jump to latest

@m234/path@0.1.0
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
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a month ago (0.1.0)

@m234/path

JSR Tests Tests coverage

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

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@m234/path

Import symbol

import * as path from "@m234/path";
or

Import directly with a jsr specifier

import * as path from "jsr:@m234/path";

Add Package

pnpm i jsr:@m234/path
or (using pnpm 10.8 or older)
pnpm dlx jsr add @m234/path

Import symbol

import * as path from "@m234/path";

Add Package

yarn add jsr:@m234/path
or (using Yarn 4.8 or older)
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";