@lacspace/llms-txt 1.0.0
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/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/index.cjs +57 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +57 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lacspace
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @lacspace/llms-txt
|
|
4
|
+
|
|
5
|
+
**Generate & parse `llms.txt` and `llms-full.txt` — the [llmstxt.org](https://llmstxt.org) standard.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@lacspace/llms-txt)
|
|
8
|
+
[](https://packagephobia.com/result?p=@lacspace/llms-txt)
|
|
9
|
+
[](https://bundlephobia.com/package/@lacspace/llms-txt)
|
|
10
|
+
[](https://www.npmjs.com/package/@lacspace/llms-txt)
|
|
11
|
+
[](https://github.com/lacspace/npm-packages/blob/main/LICENSE)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
> `llms.txt` is a Markdown file at your site root that gives LLMs a curated map of your most useful pages; `llms-full.txt` inlines the full content so a model can read everything in one request. This builds (and parses) both — the SEO layer for the AI era.
|
|
16
|
+
|
|
17
|
+
- 📄 `llmsTxt()` — H1 title, blockquote summary, linked sections
|
|
18
|
+
- 📚 `llmsFullTxt()` — full content inlined for one-shot ingestion
|
|
19
|
+
- 🔁 `parseLlmsTxt()` — read an existing file back into structured data
|
|
20
|
+
- ⚡ Zero dependencies · 🌍 isomorphic · 📦 ESM + CJS · fully typed
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @lacspace/llms-txt # or pnpm add / yarn add / bun add
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Generate `llms.txt`
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { llmsTxt } from "@lacspace/llms-txt";
|
|
32
|
+
|
|
33
|
+
const txt = llmsTxt({
|
|
34
|
+
title: "Lacspace",
|
|
35
|
+
summary: "Open-source TypeScript packages and products.",
|
|
36
|
+
details: "Zero-dependency, isomorphic, MIT-licensed.",
|
|
37
|
+
sections: [
|
|
38
|
+
{
|
|
39
|
+
title: "Docs",
|
|
40
|
+
links: [
|
|
41
|
+
{ title: "npm Packages", url: "https://lacspace.com/packages", notes: "20 packages" },
|
|
42
|
+
{ title: "SDK", url: "https://www.npmjs.com/package/@lacspace/sdk" },
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```markdown
|
|
50
|
+
# Lacspace
|
|
51
|
+
|
|
52
|
+
> Open-source TypeScript packages and products.
|
|
53
|
+
|
|
54
|
+
Zero-dependency, isomorphic, MIT-licensed.
|
|
55
|
+
|
|
56
|
+
## Docs
|
|
57
|
+
|
|
58
|
+
- [npm Packages](https://lacspace.com/packages): 20 packages
|
|
59
|
+
- [SDK](https://www.npmjs.com/package/@lacspace/sdk)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Generate `llms-full.txt`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { llmsFullTxt } from "@lacspace/llms-txt";
|
|
66
|
+
|
|
67
|
+
llmsFullTxt({
|
|
68
|
+
title: "Lacspace Docs",
|
|
69
|
+
sections: [
|
|
70
|
+
{ title: "Getting started", url: "https://lacspace.com/docs", content: "# Getting started\n\nInstall with npm…" },
|
|
71
|
+
],
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Parse
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { parseLlmsTxt } from "@lacspace/llms-txt";
|
|
79
|
+
|
|
80
|
+
const doc = parseLlmsTxt(existing); // { title, summary, details, sections: [{ title, links }] }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> Serve `llmsTxt(...)` at `/llms.txt` and `llmsFullTxt(...)` at `/llms-full.txt` (e.g. from a Next.js Route Handler or any static build step).
|
|
84
|
+
|
|
85
|
+
## The Lacspace SEO Kit
|
|
86
|
+
|
|
87
|
+
| Package | For |
|
|
88
|
+
| --- | --- |
|
|
89
|
+
| [`@lacspace/seo`](https://www.npmjs.com/package/@lacspace/seo) | Metadata & JSON-LD |
|
|
90
|
+
| [`@lacspace/sitemap`](https://www.npmjs.com/package/@lacspace/sitemap) | sitemap.xml |
|
|
91
|
+
| [`@lacspace/robots`](https://www.npmjs.com/package/@lacspace/robots) | robots.txt |
|
|
92
|
+
| **`@lacspace/llms-txt`** | llms.txt / llms-full.txt (this package) |
|
|
93
|
+
| [`@lacspace/site-verify`](https://www.npmjs.com/package/@lacspace/site-verify) | Search-engine verification |
|
|
94
|
+
| [`@lacspace/rss`](https://www.npmjs.com/package/@lacspace/rss) | RSS / Atom / JSON feeds |
|
|
95
|
+
| [`@lacspace/slugify`](https://www.npmjs.com/package/@lacspace/slugify) | SEO URL slugs |
|
|
96
|
+
|
|
97
|
+
<div align="center"><sub>Built with care by <a href="https://lacspace.com">Lacspace</a> · MIT licensed · <a href="https://github.com/lacspace/npm-packages">source</a></sub></div>
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
function llmsTxt(doc) {
|
|
5
|
+
const out = [`# ${doc.title}`];
|
|
6
|
+
if (doc.summary) out.push("", `> ${doc.summary}`);
|
|
7
|
+
if (doc.details) out.push("", doc.details.trim());
|
|
8
|
+
for (const section of doc.sections) {
|
|
9
|
+
out.push("", `## ${section.title}`, "");
|
|
10
|
+
for (const l of section.links) {
|
|
11
|
+
out.push(`- [${l.title}](${l.url})${l.notes ? `: ${l.notes}` : ""}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return out.join("\n") + "\n";
|
|
15
|
+
}
|
|
16
|
+
function llmsFullTxt(doc) {
|
|
17
|
+
const out = [`# ${doc.title}`];
|
|
18
|
+
if (doc.summary) out.push("", `> ${doc.summary}`);
|
|
19
|
+
for (const section of doc.sections) {
|
|
20
|
+
out.push("", "---", "", `## ${section.title}`);
|
|
21
|
+
if (section.url) out.push("", `Source: ${section.url}`);
|
|
22
|
+
out.push("", section.content.trim());
|
|
23
|
+
}
|
|
24
|
+
return out.join("\n") + "\n";
|
|
25
|
+
}
|
|
26
|
+
function parseLlmsTxt(txt) {
|
|
27
|
+
const lines = txt.split(/\r?\n/);
|
|
28
|
+
const doc = { title: "", sections: [] };
|
|
29
|
+
let current = null;
|
|
30
|
+
const detailBuf = [];
|
|
31
|
+
const linkRe = /^-\s*\[([^\]]+)\]\(([^)]+)\)\s*(?::\s*(.*))?$/;
|
|
32
|
+
for (const raw of lines) {
|
|
33
|
+
const line = raw.trimEnd();
|
|
34
|
+
if (line.startsWith("# ")) {
|
|
35
|
+
doc.title = line.slice(2).trim();
|
|
36
|
+
} else if (line.startsWith("> ")) {
|
|
37
|
+
doc.summary = (doc.summary ? doc.summary + " " : "") + line.slice(2).trim();
|
|
38
|
+
} else if (line.startsWith("## ")) {
|
|
39
|
+
current = { title: line.slice(3).trim(), links: [] };
|
|
40
|
+
doc.sections.push(current);
|
|
41
|
+
} else if (current && linkRe.test(line)) {
|
|
42
|
+
const m = line.match(linkRe);
|
|
43
|
+
current.links.push({ title: m[1], url: m[2], notes: m[3]?.trim() || void 0 });
|
|
44
|
+
} else if (!current && line && !line.startsWith("#")) {
|
|
45
|
+
detailBuf.push(line);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const details = detailBuf.join("\n").trim();
|
|
49
|
+
if (details) doc.details = details;
|
|
50
|
+
return doc;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
exports.llmsFullTxt = llmsFullTxt;
|
|
54
|
+
exports.llmsTxt = llmsTxt;
|
|
55
|
+
exports.parseLlmsTxt = parseLlmsTxt;
|
|
56
|
+
//# sourceMappingURL=index.cjs.map
|
|
57
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;AA0CO,SAAS,QAAQ,GAAA,EAAsB;AAC5C,EAAA,MAAM,GAAA,GAAgB,CAAC,CAAA,EAAA,EAAK,GAAA,CAAI,KAAK,CAAA,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,CAAA;AAAA,IAC3B,CAAA,MAAA,IAAW,OAAA,IAAW,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,EAAG;AACvC,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAC3B,MAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,EAAE,OAAO,CAAA,CAAE,CAAC,GAAI,GAAA,EAAK,CAAA,CAAE,CAAC,CAAA,EAAI,OAAO,CAAA,CAAE,CAAC,GAAG,IAAA,EAAK,IAAK,QAAW,CAAA;AAAA,IACnF,CAAA,MAAA,IAAW,CAAC,OAAA,IAAW,IAAA,IAAQ,CAAC,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EAAG;AACpD,MAAA,SAAA,CAAU,KAAK,IAAI,CAAA;AAAA,IACrB;AAAA,EACF;AACA,EAAA,MAAM,OAAA,GAAU,SAAA,CAAU,IAAA,CAAK,IAAI,EAAE,IAAA,EAAK;AAC1C,EAAA,IAAI,OAAA,MAAa,OAAA,GAAU,OAAA;AAC3B,EAAA,OAAO,GAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * @lacspace/llms-txt\n * Generate and parse llms.txt and llms-full.txt (the llmstxt.org standard).\n *\n * llms.txt is a Markdown file at your site root that gives LLMs a curated map of\n * your most useful content; llms-full.txt inlines the full text so a model can\n * read everything in one request.\n *\n * Zero dependencies · isomorphic · fully typed.\n */\n\nexport interface LlmsLink {\n title: string;\n url: string;\n /** Short note shown after the link. */\n notes?: string;\n}\n\nexport interface LlmsSection {\n title: string;\n links: LlmsLink[];\n}\n\nexport interface LlmsDoc {\n /** The site / project name (rendered as the H1). */\n title: string;\n /** One-line summary (rendered as a blockquote). */\n summary?: string;\n /** Free-form Markdown shown before the sections. */\n details?: string;\n sections: LlmsSection[];\n}\n\n/**\n * Render an `llms.txt` document.\n * @example\n * llmsTxt({\n * title: \"Lacspace\",\n * summary: \"Open-source TypeScript packages and products.\",\n * sections: [{ title: \"Docs\", links: [{ title: \"Packages\", url: \"https://lacspace.com/packages\" }] }],\n * });\n */\nexport function llmsTxt(doc: LlmsDoc): string {\n const out: string[] = [`# ${doc.title}`];\n if (doc.summary) out.push(\"\", `> ${doc.summary}`);\n if (doc.details) out.push(\"\", doc.details.trim());\n for (const section of doc.sections) {\n out.push(\"\", `## ${section.title}`, \"\");\n for (const l of section.links) {\n out.push(`- [${l.title}](${l.url})${l.notes ? `: ${l.notes}` : \"\"}`);\n }\n }\n return out.join(\"\\n\") + \"\\n\";\n}\n\nexport interface LlmsFullSection {\n title: string;\n /** Full Markdown content for this section. */\n content: string;\n /** Optional source URL, added as a heading link. */\n url?: string;\n}\n\nexport interface LlmsFullDoc {\n title: string;\n summary?: string;\n sections: LlmsFullSection[];\n}\n\n/** Render an `llms-full.txt` document with the full content inlined. */\nexport function llmsFullTxt(doc: LlmsFullDoc): string {\n const out: string[] = [`# ${doc.title}`];\n if (doc.summary) out.push(\"\", `> ${doc.summary}`);\n for (const section of doc.sections) {\n out.push(\"\", \"---\", \"\", `## ${section.title}`);\n if (section.url) out.push(\"\", `Source: ${section.url}`);\n out.push(\"\", section.content.trim());\n }\n return out.join(\"\\n\") + \"\\n\";\n}\n\n/** Parse an `llms.txt` string back into a structured document. */\nexport function parseLlmsTxt(txt: string): LlmsDoc {\n const lines = txt.split(/\\r?\\n/);\n const doc: LlmsDoc = { title: \"\", sections: [] };\n let current: LlmsSection | null = null;\n const detailBuf: string[] = [];\n const linkRe = /^-\\s*\\[([^\\]]+)\\]\\(([^)]+)\\)\\s*(?::\\s*(.*))?$/;\n\n for (const raw of lines) {\n const line = raw.trimEnd();\n if (line.startsWith(\"# \")) {\n doc.title = line.slice(2).trim();\n } else if (line.startsWith(\"> \")) {\n doc.summary = (doc.summary ? doc.summary + \" \" : \"\") + line.slice(2).trim();\n } else if (line.startsWith(\"## \")) {\n current = { title: line.slice(3).trim(), links: [] };\n doc.sections.push(current);\n } else if (current && linkRe.test(line)) {\n const m = line.match(linkRe)!;\n current.links.push({ title: m[1]!, url: m[2]!, notes: m[3]?.trim() || undefined });\n } else if (!current && line && !line.startsWith(\"#\")) {\n detailBuf.push(line);\n }\n }\n const details = detailBuf.join(\"\\n\").trim();\n if (details) doc.details = details;\n return doc;\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lacspace/llms-txt
|
|
3
|
+
* Generate and parse llms.txt and llms-full.txt (the llmstxt.org standard).
|
|
4
|
+
*
|
|
5
|
+
* llms.txt is a Markdown file at your site root that gives LLMs a curated map of
|
|
6
|
+
* your most useful content; llms-full.txt inlines the full text so a model can
|
|
7
|
+
* read everything in one request.
|
|
8
|
+
*
|
|
9
|
+
* Zero dependencies · isomorphic · fully typed.
|
|
10
|
+
*/
|
|
11
|
+
interface LlmsLink {
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
/** Short note shown after the link. */
|
|
15
|
+
notes?: string;
|
|
16
|
+
}
|
|
17
|
+
interface LlmsSection {
|
|
18
|
+
title: string;
|
|
19
|
+
links: LlmsLink[];
|
|
20
|
+
}
|
|
21
|
+
interface LlmsDoc {
|
|
22
|
+
/** The site / project name (rendered as the H1). */
|
|
23
|
+
title: string;
|
|
24
|
+
/** One-line summary (rendered as a blockquote). */
|
|
25
|
+
summary?: string;
|
|
26
|
+
/** Free-form Markdown shown before the sections. */
|
|
27
|
+
details?: string;
|
|
28
|
+
sections: LlmsSection[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Render an `llms.txt` document.
|
|
32
|
+
* @example
|
|
33
|
+
* llmsTxt({
|
|
34
|
+
* title: "Lacspace",
|
|
35
|
+
* summary: "Open-source TypeScript packages and products.",
|
|
36
|
+
* sections: [{ title: "Docs", links: [{ title: "Packages", url: "https://lacspace.com/packages" }] }],
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
declare function llmsTxt(doc: LlmsDoc): string;
|
|
40
|
+
interface LlmsFullSection {
|
|
41
|
+
title: string;
|
|
42
|
+
/** Full Markdown content for this section. */
|
|
43
|
+
content: string;
|
|
44
|
+
/** Optional source URL, added as a heading link. */
|
|
45
|
+
url?: string;
|
|
46
|
+
}
|
|
47
|
+
interface LlmsFullDoc {
|
|
48
|
+
title: string;
|
|
49
|
+
summary?: string;
|
|
50
|
+
sections: LlmsFullSection[];
|
|
51
|
+
}
|
|
52
|
+
/** Render an `llms-full.txt` document with the full content inlined. */
|
|
53
|
+
declare function llmsFullTxt(doc: LlmsFullDoc): string;
|
|
54
|
+
/** Parse an `llms.txt` string back into a structured document. */
|
|
55
|
+
declare function parseLlmsTxt(txt: string): LlmsDoc;
|
|
56
|
+
|
|
57
|
+
export { type LlmsDoc, type LlmsFullDoc, type LlmsFullSection, type LlmsLink, type LlmsSection, llmsFullTxt, llmsTxt, parseLlmsTxt };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @lacspace/llms-txt
|
|
3
|
+
* Generate and parse llms.txt and llms-full.txt (the llmstxt.org standard).
|
|
4
|
+
*
|
|
5
|
+
* llms.txt is a Markdown file at your site root that gives LLMs a curated map of
|
|
6
|
+
* your most useful content; llms-full.txt inlines the full text so a model can
|
|
7
|
+
* read everything in one request.
|
|
8
|
+
*
|
|
9
|
+
* Zero dependencies · isomorphic · fully typed.
|
|
10
|
+
*/
|
|
11
|
+
interface LlmsLink {
|
|
12
|
+
title: string;
|
|
13
|
+
url: string;
|
|
14
|
+
/** Short note shown after the link. */
|
|
15
|
+
notes?: string;
|
|
16
|
+
}
|
|
17
|
+
interface LlmsSection {
|
|
18
|
+
title: string;
|
|
19
|
+
links: LlmsLink[];
|
|
20
|
+
}
|
|
21
|
+
interface LlmsDoc {
|
|
22
|
+
/** The site / project name (rendered as the H1). */
|
|
23
|
+
title: string;
|
|
24
|
+
/** One-line summary (rendered as a blockquote). */
|
|
25
|
+
summary?: string;
|
|
26
|
+
/** Free-form Markdown shown before the sections. */
|
|
27
|
+
details?: string;
|
|
28
|
+
sections: LlmsSection[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Render an `llms.txt` document.
|
|
32
|
+
* @example
|
|
33
|
+
* llmsTxt({
|
|
34
|
+
* title: "Lacspace",
|
|
35
|
+
* summary: "Open-source TypeScript packages and products.",
|
|
36
|
+
* sections: [{ title: "Docs", links: [{ title: "Packages", url: "https://lacspace.com/packages" }] }],
|
|
37
|
+
* });
|
|
38
|
+
*/
|
|
39
|
+
declare function llmsTxt(doc: LlmsDoc): string;
|
|
40
|
+
interface LlmsFullSection {
|
|
41
|
+
title: string;
|
|
42
|
+
/** Full Markdown content for this section. */
|
|
43
|
+
content: string;
|
|
44
|
+
/** Optional source URL, added as a heading link. */
|
|
45
|
+
url?: string;
|
|
46
|
+
}
|
|
47
|
+
interface LlmsFullDoc {
|
|
48
|
+
title: string;
|
|
49
|
+
summary?: string;
|
|
50
|
+
sections: LlmsFullSection[];
|
|
51
|
+
}
|
|
52
|
+
/** Render an `llms-full.txt` document with the full content inlined. */
|
|
53
|
+
declare function llmsFullTxt(doc: LlmsFullDoc): string;
|
|
54
|
+
/** Parse an `llms.txt` string back into a structured document. */
|
|
55
|
+
declare function parseLlmsTxt(txt: string): LlmsDoc;
|
|
56
|
+
|
|
57
|
+
export { type LlmsDoc, type LlmsFullDoc, type LlmsFullSection, type LlmsLink, type LlmsSection, llmsFullTxt, llmsTxt, parseLlmsTxt };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function llmsTxt(doc) {
|
|
3
|
+
const out = [`# ${doc.title}`];
|
|
4
|
+
if (doc.summary) out.push("", `> ${doc.summary}`);
|
|
5
|
+
if (doc.details) out.push("", doc.details.trim());
|
|
6
|
+
for (const section of doc.sections) {
|
|
7
|
+
out.push("", `## ${section.title}`, "");
|
|
8
|
+
for (const l of section.links) {
|
|
9
|
+
out.push(`- [${l.title}](${l.url})${l.notes ? `: ${l.notes}` : ""}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return out.join("\n") + "\n";
|
|
13
|
+
}
|
|
14
|
+
function llmsFullTxt(doc) {
|
|
15
|
+
const out = [`# ${doc.title}`];
|
|
16
|
+
if (doc.summary) out.push("", `> ${doc.summary}`);
|
|
17
|
+
for (const section of doc.sections) {
|
|
18
|
+
out.push("", "---", "", `## ${section.title}`);
|
|
19
|
+
if (section.url) out.push("", `Source: ${section.url}`);
|
|
20
|
+
out.push("", section.content.trim());
|
|
21
|
+
}
|
|
22
|
+
return out.join("\n") + "\n";
|
|
23
|
+
}
|
|
24
|
+
function parseLlmsTxt(txt) {
|
|
25
|
+
const lines = txt.split(/\r?\n/);
|
|
26
|
+
const doc = { title: "", sections: [] };
|
|
27
|
+
let current = null;
|
|
28
|
+
const detailBuf = [];
|
|
29
|
+
const linkRe = /^-\s*\[([^\]]+)\]\(([^)]+)\)\s*(?::\s*(.*))?$/;
|
|
30
|
+
for (const raw of lines) {
|
|
31
|
+
const line = raw.trimEnd();
|
|
32
|
+
if (line.startsWith("# ")) {
|
|
33
|
+
doc.title = line.slice(2).trim();
|
|
34
|
+
} else if (line.startsWith("> ")) {
|
|
35
|
+
doc.summary = (doc.summary ? doc.summary + " " : "") + line.slice(2).trim();
|
|
36
|
+
} else if (line.startsWith("## ")) {
|
|
37
|
+
current = { title: line.slice(3).trim(), links: [] };
|
|
38
|
+
doc.sections.push(current);
|
|
39
|
+
} else if (current && linkRe.test(line)) {
|
|
40
|
+
const m = line.match(linkRe);
|
|
41
|
+
current.links.push({ title: m[1], url: m[2], notes: m[3]?.trim() || void 0 });
|
|
42
|
+
} else if (!current && line && !line.startsWith("#")) {
|
|
43
|
+
detailBuf.push(line);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const details = detailBuf.join("\n").trim();
|
|
47
|
+
if (details) doc.details = details;
|
|
48
|
+
return doc;
|
|
49
|
+
}
|
|
50
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AA,IAAM,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA,CAAE,IAAA,EAAK;AAAA,IAC5E,CAAA,MAAA,IAAW,IAAA,CAAK,UAAA,CAAW,KAAK,CAAA,EAAG;AACjC,MAAA,OAAA,GAAU,EAAE,KAAA,EAAO,IAAA,CAAK,KAAA,CAAM,CAAC,EAAE,IAAA,EAAK,EAAG,KAAA,EAAO,EAAC,EAAE;AACnD,MAAA,GAAA,CAAI,QAAA,CAAS,KAAK,OAAO,CAAA;AAAA,IAC3B,CAAA,MAAA,IAAW,OAAA,IAAW,MAAA,CAAO,IAAA,CAAK,IAAI,CAAA,EAAG;AACvC,MAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,MAAM,CAAA;AAC3B,MAAA,OAAA,CAAQ,MAAM,IAAA,CAAK,EAAE,OAAO,CAAA,CAAE,CAAC,GAAI,GAAA,EAAK,CAAA,CAAE,CAAC,CAAA,EAAI,OAAO,CAAA,CAAE,CAAC,GAAG,IAAA,EAAK,IAAK,QAAW,CAAA;AAAA,IACnF,CAAA,MAAA,IAAW,CAAC,OAAA,IAAW,IAAA,IAAQ,CAAC,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,EAAG;AACpD,MAAA,SAAA,CAAU,KAAK,IAAI,CAAA;AAAA,IACrB;AAAA,EACF;AACA,EAAA,MAAM,OAAA,GAAU,SAAA,CAAU,IAAA,CAAK,IAAI,EAAE,IAAA,EAAK;AAC1C,EAAA,IAAI,OAAA,MAAa,OAAA,GAAU,OAAA;AAC3B,EAAA,OAAO,GAAA;AACT","file":"index.js","sourcesContent":["/**\n * @lacspace/llms-txt\n * Generate and parse llms.txt and llms-full.txt (the llmstxt.org standard).\n *\n * llms.txt is a Markdown file at your site root that gives LLMs a curated map of\n * your most useful content; llms-full.txt inlines the full text so a model can\n * read everything in one request.\n *\n * Zero dependencies · isomorphic · fully typed.\n */\n\nexport interface LlmsLink {\n title: string;\n url: string;\n /** Short note shown after the link. */\n notes?: string;\n}\n\nexport interface LlmsSection {\n title: string;\n links: LlmsLink[];\n}\n\nexport interface LlmsDoc {\n /** The site / project name (rendered as the H1). */\n title: string;\n /** One-line summary (rendered as a blockquote). */\n summary?: string;\n /** Free-form Markdown shown before the sections. */\n details?: string;\n sections: LlmsSection[];\n}\n\n/**\n * Render an `llms.txt` document.\n * @example\n * llmsTxt({\n * title: \"Lacspace\",\n * summary: \"Open-source TypeScript packages and products.\",\n * sections: [{ title: \"Docs\", links: [{ title: \"Packages\", url: \"https://lacspace.com/packages\" }] }],\n * });\n */\nexport function llmsTxt(doc: LlmsDoc): string {\n const out: string[] = [`# ${doc.title}`];\n if (doc.summary) out.push(\"\", `> ${doc.summary}`);\n if (doc.details) out.push(\"\", doc.details.trim());\n for (const section of doc.sections) {\n out.push(\"\", `## ${section.title}`, \"\");\n for (const l of section.links) {\n out.push(`- [${l.title}](${l.url})${l.notes ? `: ${l.notes}` : \"\"}`);\n }\n }\n return out.join(\"\\n\") + \"\\n\";\n}\n\nexport interface LlmsFullSection {\n title: string;\n /** Full Markdown content for this section. */\n content: string;\n /** Optional source URL, added as a heading link. */\n url?: string;\n}\n\nexport interface LlmsFullDoc {\n title: string;\n summary?: string;\n sections: LlmsFullSection[];\n}\n\n/** Render an `llms-full.txt` document with the full content inlined. */\nexport function llmsFullTxt(doc: LlmsFullDoc): string {\n const out: string[] = [`# ${doc.title}`];\n if (doc.summary) out.push(\"\", `> ${doc.summary}`);\n for (const section of doc.sections) {\n out.push(\"\", \"---\", \"\", `## ${section.title}`);\n if (section.url) out.push(\"\", `Source: ${section.url}`);\n out.push(\"\", section.content.trim());\n }\n return out.join(\"\\n\") + \"\\n\";\n}\n\n/** Parse an `llms.txt` string back into a structured document. */\nexport function parseLlmsTxt(txt: string): LlmsDoc {\n const lines = txt.split(/\\r?\\n/);\n const doc: LlmsDoc = { title: \"\", sections: [] };\n let current: LlmsSection | null = null;\n const detailBuf: string[] = [];\n const linkRe = /^-\\s*\\[([^\\]]+)\\]\\(([^)]+)\\)\\s*(?::\\s*(.*))?$/;\n\n for (const raw of lines) {\n const line = raw.trimEnd();\n if (line.startsWith(\"# \")) {\n doc.title = line.slice(2).trim();\n } else if (line.startsWith(\"> \")) {\n doc.summary = (doc.summary ? doc.summary + \" \" : \"\") + line.slice(2).trim();\n } else if (line.startsWith(\"## \")) {\n current = { title: line.slice(3).trim(), links: [] };\n doc.sections.push(current);\n } else if (current && linkRe.test(line)) {\n const m = line.match(linkRe)!;\n current.links.push({ title: m[1]!, url: m[2]!, notes: m[3]?.trim() || undefined });\n } else if (!current && line && !line.startsWith(\"#\")) {\n detailBuf.push(line);\n }\n }\n const details = detailBuf.join(\"\\n\").trim();\n if (details) doc.details = details;\n return doc;\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lacspace/llms-txt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Generate and parse llms.txt and llms-full.txt (the llmstxt.org standard) — a Markdown map of your site for LLMs. Zero-dependency, isomorphic.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
12
|
+
"require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": ["dist"],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"scripts": { "build": "tsup", "prepublishOnly": "npm run build" },
|
|
18
|
+
"keywords": ["llms-txt", "llms-full-txt", "llmstxt", "ai-seo", "llm", "generative-engine-optimization", "geo", "seo", "typescript"],
|
|
19
|
+
"author": "Lacspace <contact@lacspace.com>",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://lacspace.com/packages",
|
|
22
|
+
"repository": { "type": "git", "url": "git+https://github.com/lacspace/npm-packages.git", "directory": "llms-txt" },
|
|
23
|
+
"bugs": { "url": "https://github.com/lacspace/npm-packages/issues" },
|
|
24
|
+
"engines": { "node": ">=18" }
|
|
25
|
+
}
|