@okfit/core 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Actor.js +3 -3
- package/Bundle.js +3 -4
- package/ConceptId.js +2 -2
- package/Derive.js +7 -3
- package/internal/fence.js +7 -8
- package/internal/links.js +6 -6
- package/internal/lintRules.js +31 -29
- package/internal/position.js +6 -12
- package/internal/walk.js +1 -1
- package/package.json +6 -6
- package/internal/posixPath.js +0 -52
package/Actor.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Wildcard, WildcardOptions } from "@effected/glob";
|
|
1
2
|
import { Schema } from "effect";
|
|
2
3
|
|
|
3
4
|
// src/Actor.ts
|
|
@@ -11,11 +12,10 @@ const form = (actor) => {
|
|
|
11
12
|
return prefix === "human" ? "human" : prefix === "process" ? "process" : "other";
|
|
12
13
|
};
|
|
13
14
|
const GLOB_RE = /[*?]/u;
|
|
14
|
-
const ESCAPE_RE = /[.+^${}()|[\]\\/]/gu;
|
|
15
15
|
/** `*` is any run of non-whitespace, `?` one non-whitespace character; everything else is literal. */
|
|
16
|
-
const
|
|
16
|
+
const NOCASE = WildcardOptions.make({ nocase: true });
|
|
17
17
|
const isPattern = (value) => GLOB_RE.test(value);
|
|
18
|
-
const matches = (actor, pattern) =>
|
|
18
|
+
const matches = (actor, pattern) => Wildcard.matches(pattern, actor, NOCASE);
|
|
19
19
|
const allowed = (actor, humans) => humans.length === 0 || humans.some((pattern) => matches(actor, pattern));
|
|
20
20
|
/**
|
|
21
21
|
* Branded, pattern-checked actor codec with prefix classification statics.
|
package/Bundle.js
CHANGED
|
@@ -5,13 +5,12 @@ import { IndexDocument } from "./IndexDocument.js";
|
|
|
5
5
|
import { detectFence } from "./internal/fence.js";
|
|
6
6
|
import { decodeConcept } from "./internal/frontmatter.js";
|
|
7
7
|
import { toFileOffset } from "./internal/position.js";
|
|
8
|
-
import { basename, dirname } from "./internal/posixPath.js";
|
|
9
8
|
import { OPTIONS, parseIndex, parseLog } from "./internal/reserved.js";
|
|
10
9
|
import { DEFAULT_PRUNE, walk } from "./internal/walk.js";
|
|
11
10
|
import { LogDocument } from "./LogDocument.js";
|
|
12
11
|
import { Effect, FileSystem, Option, Path, Result, Schema } from "effect";
|
|
13
12
|
import { FrontmatterDecodeError, MarkdownDocument, YamlFrontmatter } from "@effected/markdown";
|
|
14
|
-
import { DescendError } from "@effected/walker";
|
|
13
|
+
import { DescendError, PosixPath } from "@effected/walker";
|
|
15
14
|
import { YamlParseError } from "@effected/yaml";
|
|
16
15
|
|
|
17
16
|
// src/Bundle.ts
|
|
@@ -101,7 +100,7 @@ const diagnostic = (file, code, severity, message, range) => Diagnostic.make(ran
|
|
|
101
100
|
const blockRange = (text, node) => DiagnosticRange.fromOffset(text, node.position.start.offset, node.position.end.offset - node.position.start.offset);
|
|
102
101
|
/** Group A's `dirname` returns `"."` for a bundle-root file; `LoadedBundle` keys the root `""`. */
|
|
103
102
|
const directoryKey = (relativePath) => {
|
|
104
|
-
const dir = dirname(relativePath);
|
|
103
|
+
const dir = PosixPath.dirname(relativePath);
|
|
105
104
|
return dir === "." ? "" : dir;
|
|
106
105
|
};
|
|
107
106
|
/** Decode a captured YAML block; a failure is one `frontmatter-unparseable` with a file-mapped range (D-14). */
|
|
@@ -130,7 +129,7 @@ const loadMarkdown = (file, text) => Effect.gen(function* () {
|
|
|
130
129
|
}
|
|
131
130
|
const document = parsed.success;
|
|
132
131
|
const dir = directoryKey(file);
|
|
133
|
-
if (reserved && basename(file) === "log.md") {
|
|
132
|
+
if (reserved && PosixPath.basename(file) === "log.md") {
|
|
134
133
|
const result = parseLog({
|
|
135
134
|
file,
|
|
136
135
|
dir,
|
package/ConceptId.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { basename } from "./internal/posixPath.js";
|
|
2
1
|
import { Option, Schema } from "effect";
|
|
2
|
+
import { PosixPath } from "@effected/walker";
|
|
3
3
|
|
|
4
4
|
// src/ConceptId.ts
|
|
5
5
|
const RESERVED_BASENAMES = /* @__PURE__ */ new Set(["index.md", "log.md"]);
|
|
6
|
-
const isReservedFile = (path) => RESERVED_BASENAMES.has(basename(path));
|
|
6
|
+
const isReservedFile = (path) => RESERVED_BASENAMES.has(PosixPath.basename(path));
|
|
7
7
|
const fromPath = (path) => {
|
|
8
8
|
if (isReservedFile(path) || !path.endsWith(".md")) return Option.none();
|
|
9
9
|
return Option.some(path.slice(0, -3));
|
package/Derive.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Actor } from "./Actor.js";
|
|
2
2
|
import { indexDocument, logEntry } from "./internal/templates.js";
|
|
3
3
|
import { DateTime, Schema } from "effect";
|
|
4
|
+
import { PosixPath } from "@effected/walker";
|
|
4
5
|
|
|
5
6
|
// src/Derive.ts
|
|
6
7
|
/** Trust tier from `verified` (OKF 0.2 §5.3): none maps to unverified; only non-human maps to machine-confirmed; any `human:` maps to human-reviewed. @public */
|
|
@@ -17,8 +18,11 @@ const Staleness = Schema.Literals([
|
|
|
17
18
|
]);
|
|
18
19
|
const compare = (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
19
20
|
const oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
20
|
-
|
|
21
|
-
const dirnameOf = (path) =>
|
|
21
|
+
/** The bundle-relative directory of `path`; `""` for a file at the bundle root. */
|
|
22
|
+
const dirnameOf = (path) => {
|
|
23
|
+
const dir = PosixPath.dirname(path);
|
|
24
|
+
return dir === "." ? "" : dir;
|
|
25
|
+
};
|
|
22
26
|
const relativeTarget = (dir, path) => dir !== "" && path.startsWith(`${dir}/`) ? path.slice(dir.length + 1) : path;
|
|
23
27
|
/** Pure derivations (D-10, D-36): trust tier, status, staleness against a supplied instant, index/log rendering. @public */
|
|
24
28
|
var Derive = class Derive {
|
|
@@ -59,7 +63,7 @@ var Derive = class Derive {
|
|
|
59
63
|
return out.sort((a, b) => compare(a.id, b.id));
|
|
60
64
|
};
|
|
61
65
|
/** Frontmatter `title`, else the file name without `.md` (OKF 0.2 §4.1). */
|
|
62
|
-
static title = (concept) => concept.frontmatter.title ?? basename(concept.path).replace(/\.md$/, "");
|
|
66
|
+
static title = (concept) => concept.frontmatter.title ?? PosixPath.basename(concept.path).replace(/\.md$/, "");
|
|
63
67
|
/** One H1 per `type` (sorted), entries sorted by title, then `# Subdirectories` (D-36; spec §8). */
|
|
64
68
|
static renderIndex = (dir, concepts, options = {}) => {
|
|
65
69
|
const groups = /* @__PURE__ */ new Map();
|
package/internal/fence.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
+
import { FrontmatterSource } from "@effected/markdown";
|
|
2
|
+
|
|
1
3
|
// src/internal/fence.ts
|
|
2
|
-
const LINE_BREAK = /\r\n|\r|\n/;
|
|
3
4
|
/**
|
|
4
|
-
* Core's
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Core's fence check, run before the markdown parser because the parser treats an unclosed fence as
|
|
6
|
+
* no frontmatter (effected-markdown.md section 2). The fence state is `FrontmatterSource.split`'s;
|
|
7
|
+
* core recognizes only the `---` YAML fence (D-13), so a `+++` or `---json` fence reads as absent.
|
|
7
8
|
*
|
|
8
9
|
* @public
|
|
9
10
|
*/
|
|
10
11
|
const detectFence = (text) => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
for (let index = 1; index < lines.length; index += 1) if (lines[index] === "---") return "closed";
|
|
14
|
-
return "unclosed";
|
|
12
|
+
const split = FrontmatterSource.split(text);
|
|
13
|
+
return split.fenceFormat === void 0 || split.fenceFormat === "yaml" ? split.fence ?? "absent" : "absent";
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
export { detectFence };
|
package/internal/links.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { basename, dirname, join, normalize } from "./posixPath.js";
|
|
2
1
|
import { findFrontmatterPathSpan } from "./yamlPathSpan.js";
|
|
3
2
|
import { Option } from "effect";
|
|
3
|
+
import { PosixPath } from "@effected/walker";
|
|
4
4
|
|
|
5
5
|
// src/internal/links.ts
|
|
6
6
|
const SCHEME_RE = /^[a-z][a-z0-9+.-]+:/i;
|
|
@@ -20,7 +20,7 @@ const percentDecode = (raw) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
const isReserved = (path) => {
|
|
23
|
-
const name = basename(path);
|
|
23
|
+
const name = PosixPath.basename(path);
|
|
24
24
|
return name === "index.md" || name === "log.md";
|
|
25
25
|
};
|
|
26
26
|
const escapes = (path) => path === ".." || path.startsWith("../");
|
|
@@ -48,7 +48,7 @@ const lookup = (candidate, index, via) => {
|
|
|
48
48
|
if (path === "." || path === "") return void 0;
|
|
49
49
|
const direct = existing(path, index, via);
|
|
50
50
|
if (direct !== void 0) return direct;
|
|
51
|
-
return basename(path).includes(".") ? void 0 : existing(`${path}.md`, index, via);
|
|
51
|
+
return PosixPath.basename(path).includes(".") ? void 0 : existing(`${path}.md`, index, via);
|
|
52
52
|
};
|
|
53
53
|
const missing = (candidate, via) => ({
|
|
54
54
|
_tag: "node",
|
|
@@ -64,17 +64,17 @@ const resolveTarget = (from, raw, index) => {
|
|
|
64
64
|
if (target === "") return { _tag: "self" };
|
|
65
65
|
if (target.startsWith("/")) {
|
|
66
66
|
const rooted = target.slice(1);
|
|
67
|
-
const candidate = rooted === "" ? "index.md" : normalize(rooted);
|
|
67
|
+
const candidate = rooted === "" ? "index.md" : PosixPath.normalize(rooted);
|
|
68
68
|
if (escapes(candidate)) return { _tag: "external" };
|
|
69
69
|
return lookup(candidate, index, "rooted") ?? missing(candidate, "rooted");
|
|
70
70
|
}
|
|
71
71
|
const relative = target.startsWith("./") || target.startsWith("../");
|
|
72
|
-
const fileRelative = join(dirname(from), target);
|
|
72
|
+
const fileRelative = PosixPath.join(PosixPath.dirname(from), target);
|
|
73
73
|
if (escapes(fileRelative)) return { _tag: "external" };
|
|
74
74
|
const hitB = lookup(fileRelative, index, "file");
|
|
75
75
|
if (hitB !== void 0) return hitB;
|
|
76
76
|
if (!relative) {
|
|
77
|
-
const rootRelative = normalize(target);
|
|
77
|
+
const rootRelative = PosixPath.normalize(target);
|
|
78
78
|
if (escapes(rootRelative)) return { _tag: "external" };
|
|
79
79
|
const hitC = lookup(rootRelative, index, "root");
|
|
80
80
|
if (hitC !== void 0) return hitC;
|
package/internal/lintRules.js
CHANGED
|
@@ -2,20 +2,11 @@ import { Actor } from "../Actor.js";
|
|
|
2
2
|
import { Derive } from "../Derive.js";
|
|
3
3
|
import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
|
|
4
4
|
import { frontmatterPathRange } from "./frontmatter.js";
|
|
5
|
-
import { DateTime
|
|
5
|
+
import { DateTime } from "effect";
|
|
6
6
|
import { EditDistance } from "@effected/source";
|
|
7
7
|
|
|
8
8
|
// src/internal/lintRules.ts
|
|
9
|
-
const FOOTNOTE_RE = /\[\^([^\]\s]+)\]/g;
|
|
10
|
-
/** A footnote definition: the label at a line start, followed by a colon. */
|
|
11
|
-
const FOOTNOTE_DEFINITION_RE = /^\[\^([^\]\s]+)\]:/gm;
|
|
12
9
|
const present = (raw, key) => Object.hasOwn(raw, key) && raw[key] !== null;
|
|
13
|
-
/**
|
|
14
|
-
* Source spans of every inline code span and code block, so a footnote-shaped
|
|
15
|
-
* token inside backticks is read as literal text (issue #67).
|
|
16
|
-
*/
|
|
17
|
-
const codeSpansOf = (concept) => concept.document.findAll((node) => node.type === "inlineCode" || node.type === "code").map((node) => [node.position.start.offset, node.position.end.offset]);
|
|
18
|
-
const insideAny = (spans, offset) => spans.some(([start, end]) => offset >= start && offset < end);
|
|
19
10
|
const diagnostic = (file, code, severity, message, range) => Diagnostic.make({
|
|
20
11
|
file,
|
|
21
12
|
code,
|
|
@@ -127,20 +118,36 @@ const stale = perConcept("stale", (concept, context) => context.now !== void 0 &
|
|
|
127
118
|
message: `Concept is stale since ${DateTime.formatIso(concept.frontmatter.stale_after)}`,
|
|
128
119
|
path: ["stale_after"]
|
|
129
120
|
}] : []);
|
|
121
|
+
/**
|
|
122
|
+
* Every footnote label a concept uses, once each in source order, with the offset of its first
|
|
123
|
+
* `[^label]` marker: resolved references, definitions and the markers the parser rejected for want
|
|
124
|
+
* of a definition. A marker in a code span or block, or an escaped one, is literal text and absent.
|
|
125
|
+
*/
|
|
126
|
+
const footnoteLabelsOf = (concept) => {
|
|
127
|
+
const markers = [...concept.document.findAll((node) => node.type === "footnoteReference" || node.type === "footnoteDefinition").flatMap((node) => node.type === "footnoteReference" || node.type === "footnoteDefinition" ? [{
|
|
128
|
+
label: node.label ?? node.identifier,
|
|
129
|
+
offset: node.position.start.offset
|
|
130
|
+
}] : []), ...concept.document.unresolvedFootnoteReferences.map((marker) => ({
|
|
131
|
+
label: marker.label,
|
|
132
|
+
offset: marker.position.start.offset
|
|
133
|
+
}))].sort((left, right) => left.offset - right.offset);
|
|
134
|
+
const seen = /* @__PURE__ */ new Set();
|
|
135
|
+
const first = [];
|
|
136
|
+
for (const marker of markers) {
|
|
137
|
+
if (seen.has(marker.label)) continue;
|
|
138
|
+
seen.add(marker.label);
|
|
139
|
+
first.push(marker);
|
|
140
|
+
}
|
|
141
|
+
return first;
|
|
142
|
+
};
|
|
130
143
|
const footnoteSourceUnknown = rule("footnote-source-unknown", (context, severity) => {
|
|
131
144
|
const out = [];
|
|
132
145
|
for (const concept of context.bundle.concepts.values()) {
|
|
133
146
|
const ids = new Set((concept.frontmatter.sources ?? []).flatMap((s) => s.id === void 0 ? [] : [s.id]));
|
|
134
147
|
if (ids.size === 0) continue;
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const seen = /* @__PURE__ */ new Set();
|
|
139
|
-
for (const match of source.slice(start).matchAll(FOOTNOTE_RE)) {
|
|
140
|
-
const label = match[1];
|
|
141
|
-
if (label === void 0 || ids.has(label) || seen.has(label) || insideAny(code, start + match.index)) continue;
|
|
142
|
-
seen.add(label);
|
|
143
|
-
const range = DiagnosticRange.fromOffset(source, start + match.index, match[0].length);
|
|
148
|
+
for (const { label, offset } of footnoteLabelsOf(concept)) {
|
|
149
|
+
if (ids.has(label)) continue;
|
|
150
|
+
const range = DiagnosticRange.fromOffset(concept.document.source, offset, label.length + 3);
|
|
144
151
|
out.push(diagnostic(concept.path, "footnote-source-unknown", severity, `Footnote label "${label}" must equal a sources[].id exactly (declared: ${[...ids].join(", ")})`, range));
|
|
145
152
|
}
|
|
146
153
|
}
|
|
@@ -150,17 +157,12 @@ const footnoteUndefined = rule("footnote-undefined", (context, severity) => {
|
|
|
150
157
|
const out = [];
|
|
151
158
|
for (const concept of context.bundle.concepts.values()) {
|
|
152
159
|
const source = concept.document.source;
|
|
153
|
-
const start = Option.getOrUndefined(concept.document.frontmatter)?.position.end.offset ?? 0;
|
|
154
|
-
const body = source.slice(start);
|
|
155
|
-
const code = codeSpansOf(concept);
|
|
156
|
-
const defined = new Set([...body.matchAll(FOOTNOTE_DEFINITION_RE)].flatMap((m) => m[1] === void 0 || insideAny(code, start + m.index) ? [] : [m[1]]));
|
|
157
160
|
const seen = /* @__PURE__ */ new Set();
|
|
158
|
-
for (const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
out.push(diagnostic(concept.path, "footnote-undefined", severity, `Footnote "${label}" is referenced but has no [^${label}]: definition`, range));
|
|
161
|
+
for (const marker of concept.document.unresolvedFootnoteReferences) {
|
|
162
|
+
if (seen.has(marker.label)) continue;
|
|
163
|
+
seen.add(marker.label);
|
|
164
|
+
const { start, end } = marker.position;
|
|
165
|
+
out.push(diagnostic(concept.path, "footnote-undefined", severity, `Footnote "${marker.label}" is referenced but has no [^${marker.label}]: definition`, DiagnosticRange.fromOffset(source, start.offset, end.offset - start.offset)));
|
|
164
166
|
}
|
|
165
167
|
}
|
|
166
168
|
return out;
|
package/internal/position.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
+
import { FrontmatterSource } from "@effected/markdown";
|
|
2
|
+
|
|
1
3
|
// src/internal/position.ts
|
|
2
|
-
const LF = 10;
|
|
3
|
-
const CR = 13;
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* when `text` starts with the fence.
|
|
5
|
+
* Map a `YamlDiagnostic.offset` or `YamlNode.offset` inside the frontmatter value to a whole-file
|
|
6
|
+
* offset. Only meaningful when `text` opens a closed frontmatter block.
|
|
8
7
|
*
|
|
9
8
|
* @public
|
|
10
9
|
*/
|
|
11
|
-
const
|
|
12
|
-
const afterFence = 3;
|
|
13
|
-
return afterFence + (text.charCodeAt(afterFence) === CR && text.charCodeAt(4) === LF ? 2 : 1);
|
|
14
|
-
};
|
|
15
|
-
/** Map a `YamlDiagnostic.offset` or `YamlNode.offset` inside the frontmatter value to a whole-file offset. @public */
|
|
16
|
-
const toFileOffset = (text, yamlOffset) => frontmatterValueStart(text) + yamlOffset;
|
|
10
|
+
const toFileOffset = (text, yamlOffset) => (FrontmatterSource.split(text).frontmatter?.valueStart ?? 0) + yamlOffset;
|
|
17
11
|
|
|
18
|
-
export {
|
|
12
|
+
export { toFileOffset };
|
package/internal/walk.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/core",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Spec-level Open Knowledge Format (OKF) v0.2 schemas, bundle loading, graph, derivation, and validation for Effect.",
|
|
6
6
|
"keywords": [
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@effected/config-file": "^0.
|
|
41
|
-
"@effected/glob": "^0.
|
|
40
|
+
"@effected/config-file": "^0.26.0",
|
|
41
|
+
"@effected/glob": "^0.20.0",
|
|
42
42
|
"@effected/jsonc": "^0.24.0",
|
|
43
|
-
"@effected/markdown": "^0.
|
|
44
|
-
"@effected/schemastore": "^0.
|
|
43
|
+
"@effected/markdown": "^0.28.0",
|
|
44
|
+
"@effected/schemastore": "^0.31.0",
|
|
45
45
|
"@effected/source": "^0.4.0",
|
|
46
46
|
"@effected/toml": "^0.19.1",
|
|
47
|
-
"@effected/walker": "^0.
|
|
47
|
+
"@effected/walker": "^0.26.0",
|
|
48
48
|
"@effected/yaml": "^0.29.0",
|
|
49
49
|
"effect": "~4.1.2"
|
|
50
50
|
},
|
package/internal/posixPath.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
// src/internal/posixPath.ts
|
|
2
|
-
const SLASH = 47;
|
|
3
|
-
/**
|
|
4
|
-
* Collapse `.`/`..` and repeated slashes. Relative input keeps leading `..`
|
|
5
|
-
* (the caller classifies bundle escapes); absolute input clamps at the root.
|
|
6
|
-
* A trailing slash survives; `""` is `"."`.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
|
-
const normalize = (path) => {
|
|
11
|
-
if (path.length === 0) return ".";
|
|
12
|
-
const isAbsolute = path.charCodeAt(0) === SLASH;
|
|
13
|
-
const trailingSeparator = path.charCodeAt(path.length - 1) === SLASH;
|
|
14
|
-
const segments = [];
|
|
15
|
-
for (const segment of path.split("/")) {
|
|
16
|
-
if (segment.length === 0 || segment === ".") continue;
|
|
17
|
-
if (segment === "..") {
|
|
18
|
-
if (segments.length > 0 && segments[segments.length - 1] !== "..") segments.pop();
|
|
19
|
-
else if (!isAbsolute) segments.push("..");
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
segments.push(segment);
|
|
23
|
-
}
|
|
24
|
-
let result = segments.join("/");
|
|
25
|
-
if (result.length === 0 && !isAbsolute) result = ".";
|
|
26
|
-
if (result.length > 0 && trailingSeparator) result += "/";
|
|
27
|
-
return isAbsolute ? `/${result}` : result;
|
|
28
|
-
};
|
|
29
|
-
/** Join non-empty segments with `/` and normalize; no segments is `"."`. @public */
|
|
30
|
-
const join = (...paths) => {
|
|
31
|
-
const joined = paths.filter((segment) => segment.length > 0).join("/");
|
|
32
|
-
return joined.length === 0 ? "." : normalize(joined);
|
|
33
|
-
};
|
|
34
|
-
/** Directory part of `path`: `"."` for a bare name, `"/"` for a root-level absolute path. @public */
|
|
35
|
-
const dirname = (path) => {
|
|
36
|
-
let end = path.length;
|
|
37
|
-
while (end > 1 && path.charCodeAt(end - 1) === SLASH) end--;
|
|
38
|
-
const trimmed = path.slice(0, end);
|
|
39
|
-
const index = trimmed.lastIndexOf("/");
|
|
40
|
-
if (index === -1) return ".";
|
|
41
|
-
if (index === 0) return "/";
|
|
42
|
-
return trimmed.slice(0, index);
|
|
43
|
-
};
|
|
44
|
-
/** Last segment of `path` with trailing slashes stripped; `""` for `""` or `"/"`. @public */
|
|
45
|
-
const basename = (path) => {
|
|
46
|
-
let end = path.length;
|
|
47
|
-
while (end > 0 && path.charCodeAt(end - 1) === SLASH) end--;
|
|
48
|
-
const trimmed = path.slice(0, end);
|
|
49
|
-
return trimmed.slice(trimmed.lastIndexOf("/") + 1);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export { basename, dirname, join, normalize };
|