update to v0.9.1.
add npm package link prep for jsr support (I hope) add favicon update installation instructions
This commit is contained in:
21
README.md
21
README.md
@@ -14,25 +14,28 @@ These functions include:
|
||||
|
||||
## Installation
|
||||
|
||||
Browser
|
||||
This library can be installed in several different ways:
|
||||
|
||||
- Download [library](/dist-browser/twtxt-lib.js) (or [minified version](/dist-browser/twtxt-lib.min.js)).
|
||||
- Import desired function(s) into your project: `import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js"`
|
||||
### For the Browser
|
||||
|
||||
NPM
|
||||
1. Grab the latest copy of the `twtxt-lib.js` file, either by downloading it from the [git repo](https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.js), the [website](https://twtxt-lib.itsericwoodward.com/dist-browser/twtxt-lib.js), or doing a `git clone https://git.itsericwoodward.com/eric/twtxt-lib.git` and pulling it out of the `dist-browser` folder.
|
||||
- Alternatively, you can grab the minified version from the [same](https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.min.js) [sources](https://twtxt-lib.itsericwoodward.com/dist-browser/twtxt-lib.min.js).
|
||||
2. Add the newly acquired file to your static site / progressive web app / over-engineered blog.
|
||||
3. Import the desired function(s) via ESM: `import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js";`
|
||||
|
||||
- Coming soon
|
||||
### For Node
|
||||
|
||||
JSR
|
||||
|
||||
- Coming soon
|
||||
1. Add the package to your project.
|
||||
- Via [NPM](https://www.npmjs.com/package/twtxt-lib): `yarn add twtxt-lib`
|
||||
- Via [JSR](https://jsr.io/@itsericwoodward/twtxt-lib): `yarn add jsr:@itsericwoodward/twtxt-lib`
|
||||
2. Import the desired function(s) into your code: `import { hashTwt, loadAndParseTwtxtFile } from "twtxt-lib";`
|
||||
|
||||
## Features
|
||||
|
||||
- Isomorphic, available as an ([optionally minified](/dist-browser/twtxt-lib.min.js))
|
||||
[ES6+ library for the browser](/dist-browser/twtxt-lib.js), with NPM and JSR versions coming soon.
|
||||
- Fully typed and source-mapped.
|
||||
- [ESM](https://caniuse.com/es6-module) (and [ESM only](https://antfu.me/posts/move-on-to-esm-only)).
|
||||
- [ES6 Module](https://caniuse.com/es6-module) (and [ESM only](https://antfu.me/posts/move-on-to-esm-only)).
|
||||
- Includes sample files and an [interactive demo page](https://twtxt-lib.itsericwoodward.com/).
|
||||
|
||||
## Usage
|
||||
|
||||
16
dist-browser/loadAndParseTwtxt.d.ts
vendored
16
dist-browser/loadAndParseTwtxt.d.ts
vendored
@@ -1,14 +1,2 @@
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<{
|
||||
lastModified: string;
|
||||
following: import('./types.ts').Twttr[];
|
||||
metadata: import('./types.ts').Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
}>;
|
||||
import { Twtxt } from './types.ts';
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<Twtxt>;
|
||||
|
||||
16
dist-browser/parseTwtxt.d.ts
vendored
16
dist-browser/parseTwtxt.d.ts
vendored
@@ -1,18 +1,6 @@
|
||||
import { Metadata, Twttr } from './types.ts';
|
||||
import { Twtxt } from './types.ts';
|
||||
/**
|
||||
* @param twtxt
|
||||
* @returns object containing: following, metadata, twts
|
||||
*/
|
||||
export default function parseTwtxt(twtxt: string): {
|
||||
following: Twttr[];
|
||||
metadata: Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
};
|
||||
export default function parseTwtxt(twtxt: string): Twtxt;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
dist-browser/types.d.ts
vendored
1
dist-browser/types.d.ts
vendored
@@ -26,6 +26,7 @@ export interface Twttr {
|
||||
}
|
||||
export interface Twtxt {
|
||||
following: Twttr[];
|
||||
lastModified?: string;
|
||||
metadata: Metadata;
|
||||
twts: Twt[];
|
||||
}
|
||||
|
||||
2
dist-browser/utils.d.ts
vendored
2
dist-browser/utils.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => any;
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => string;
|
||||
export declare const getValueOrFirstEntry: (value: unknown | unknown[]) => any;
|
||||
|
||||
@@ -68,6 +68,15 @@ button {
|
||||
background-color: var(--link-active);
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: var(--bg-dark);
|
||||
color: var(--fg-main);
|
||||
font-size: smaller;
|
||||
padding: 0 .5rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
border: none;
|
||||
@@ -182,6 +191,7 @@ summary {
|
||||
bottom: 0;
|
||||
display: none;
|
||||
left: 0;
|
||||
line-height: 1.5rem;
|
||||
overflow: auto;
|
||||
padding: 0 1rem 1rem;
|
||||
right: 0;
|
||||
|
||||
16
dist-demo/dist-browser/loadAndParseTwtxt.d.ts
vendored
16
dist-demo/dist-browser/loadAndParseTwtxt.d.ts
vendored
@@ -1,14 +1,2 @@
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<{
|
||||
lastModified: string;
|
||||
following: import('./types.ts').Twttr[];
|
||||
metadata: import('./types.ts').Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
}>;
|
||||
import { Twtxt } from './types.ts';
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<Twtxt>;
|
||||
|
||||
16
dist-demo/dist-browser/parseTwtxt.d.ts
vendored
16
dist-demo/dist-browser/parseTwtxt.d.ts
vendored
@@ -1,18 +1,6 @@
|
||||
import { Metadata, Twttr } from './types.ts';
|
||||
import { Twtxt } from './types.ts';
|
||||
/**
|
||||
* @param twtxt
|
||||
* @returns object containing: following, metadata, twts
|
||||
*/
|
||||
export default function parseTwtxt(twtxt: string): {
|
||||
following: Twttr[];
|
||||
metadata: Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
};
|
||||
export default function parseTwtxt(twtxt: string): Twtxt;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
dist-demo/dist-browser/types.d.ts
vendored
1
dist-demo/dist-browser/types.d.ts
vendored
@@ -26,6 +26,7 @@ export interface Twttr {
|
||||
}
|
||||
export interface Twtxt {
|
||||
following: Twttr[];
|
||||
lastModified?: string;
|
||||
metadata: Metadata;
|
||||
twts: Twt[];
|
||||
}
|
||||
|
||||
2
dist-demo/dist-browser/utils.d.ts
vendored
2
dist-demo/dist-browser/utils.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => any;
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => string;
|
||||
export declare const getValueOrFirstEntry: (value: unknown | unknown[]) => any;
|
||||
|
||||
BIN
dist-demo/favicon-16x16.png
Normal file
BIN
dist-demo/favicon-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
BIN
dist-demo/favicon-32x32.png
Normal file
BIN
dist-demo/favicon-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 909 B |
BIN
dist-demo/favicon.ico
Normal file
BIN
dist-demo/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
@@ -4,6 +4,9 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>twtxt-lib Demo</title>
|
||||
<link rel="shortcut icon" href="favicon.ico"/>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="stylesheet" href="/demo/styles.css" />
|
||||
</head>
|
||||
|
||||
@@ -47,32 +50,65 @@
|
||||
<a href="/dist-browser/twtxt-lib.js">ES6+ library for the browser</a>,
|
||||
with NPM and JSR versions coming soon.
|
||||
<li>Fully typed and source-mapped.</li>
|
||||
<li><a href="https://caniuse.com/es6-module">ESM</a> (and <a href="https://antfu.me/posts/move-on-to-esm-only">ESM only</a>)</li>
|
||||
<li>Built as an <a href="https://caniuse.com/es6-module">ES6 module</a> (and <a href="https://antfu.me/posts/move-on-to-esm-only">ESM only</a>)</li>
|
||||
<li>Includes an interactive demo <em>(you're looking at it)</em>.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Installation</h2>
|
||||
|
||||
<p>
|
||||
Browser
|
||||
<ul>
|
||||
<li>Download <a href="/dist-browser/twtxt-lib.js">library</a> (or
|
||||
<a href="/dist-browser/twtxt-lib.min.js">minified version</a>).</li>
|
||||
<li>Import desired function(s) into your project: `import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js"`</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
JSR
|
||||
<ul>
|
||||
<li>Coming soon</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
NPM
|
||||
<ul>
|
||||
<li>Coming soon</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>This library can be installed in several different ways:</p>
|
||||
|
||||
<h3>For the Browser</h3>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Grab the latest copy of the <code>twtxt-lib.js</code> file, either by
|
||||
downloading it from the
|
||||
<a href="https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.js">git
|
||||
repo</a>, the
|
||||
<a href="/dist-browser/twtxt-lib.js">website</a>, or doing a
|
||||
<code>git clone https://git.itsericwoodward.com/eric/twtxt-lib.git</code>
|
||||
and pulling it out of the <code>dist-browser</code> folder.
|
||||
<ul>
|
||||
<li>
|
||||
Alternatively, you can grab the minified version from the
|
||||
<a href="https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.min.js">same</a>
|
||||
<a href="https://twtxt-lib.itsericwoodward.com/dist-browser/twtxt-lib.min.js">sources</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
Add the newly acquired file to your static site / progressive web app /
|
||||
over-engineered blog.
|
||||
</li>
|
||||
<li>
|
||||
Import the desired function(s) via ESM:
|
||||
<code>import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js";</code>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h3>For Node</h3>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Add the package to your project.
|
||||
<ul>
|
||||
<li>
|
||||
Via <a href="https://www.npmjs.com/package/twtxt-lib">NPM</a>:
|
||||
<code>yarn add twtxt-lib</code>
|
||||
</li>
|
||||
<li>
|
||||
Via <a href="https://jsr.io/@itsericwoodward/twtxt-lib">JSR</a>:
|
||||
<code>yarn add jsr:@itsericwoodward/twtxt-lib</code>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
Import the desired function(s) into your code:
|
||||
<code>import { hashTwt, loadAndParseTwtxtFile } from "twtxt-lib";</code>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p>Use the tabs to learn more.</p>
|
||||
|
||||
|
||||
16
dist-node/loadAndParseTwtxt.d.ts
vendored
16
dist-node/loadAndParseTwtxt.d.ts
vendored
@@ -1,14 +1,2 @@
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<{
|
||||
lastModified: string;
|
||||
following: import('./types.ts').Twttr[];
|
||||
metadata: import('./types.ts').Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
}>;
|
||||
import { Twtxt } from './types.ts';
|
||||
export default function loadAndParseTwtxtFile(url?: string): Promise<Twtxt>;
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"loadAndParseTwtxt.js","sources":["../src/loadAndParseTwtxt.ts"],"sourcesContent":["import dayjs from \"dayjs\";\n\nimport parseTwtxt from \"./parseTwtxt.js\";\n\nexport default async function loadAndParseTwtxtFile(url = \"\") {\n\tif (!url) throw new Error(\"URL is required\");\n\n\ttry {\n\t\tconst response = await fetch(url);\n\t\tconst twtxtFile = await response.text();\n\t\tconst lastModified = dayjs(\n\t\t\tresponse.headers.get(\"Last-Modified\"),\n\t\t).toISOString();\n\n\t\treturn {\n\t\t\t...parseTwtxt(twtxtFile),\n\t\t\tlastModified,\n\t\t};\n\t} catch (err) {\n\t\tconsole.error(err);\n\t\tthrow err;\n\t}\n}\n"],"names":[],"mappings":";;AAIA,eAA8B,sBAAsB,MAAM,IAAI;AAC7D,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,iBAAiB;AAE3C,MAAI;AACH,UAAM,WAAW,MAAM,MAAM,GAAG;AAChC,UAAM,YAAY,MAAM,SAAS,KAAA;AACjC,UAAM,eAAe;AAAA,MACpB,SAAS,QAAQ,IAAI,eAAe;AAAA,IAAA,EACnC,YAAA;AAEF,WAAO;AAAA,MACN,GAAG,WAAW,SAAS;AAAA,MACvB;AAAA,IAAA;AAAA,EAEF,SAAS,KAAK;AACb,YAAQ,MAAM,GAAG;AACjB,UAAM;AAAA,EACP;AACD;"}
|
||||
{"version":3,"file":"loadAndParseTwtxt.js","sources":["../src/loadAndParseTwtxt.ts"],"sourcesContent":["import dayjs from \"dayjs\";\n\nimport parseTwtxt from \"./parseTwtxt.js\";\nimport type { Twtxt } from \"./types.ts\";\n\nexport default async function loadAndParseTwtxtFile(url = \"\"): Promise<Twtxt> {\n\tif (!url) throw new Error(\"URL is required\");\n\n\ttry {\n\t\tconst response = await fetch(url);\n\t\tconst twtxtFile = await response.text();\n\t\tconst lastModified = dayjs(\n\t\t\tresponse.headers.get(\"Last-Modified\"),\n\t\t).toISOString();\n\n\t\treturn {\n\t\t\t...parseTwtxt(twtxtFile),\n\t\t\tlastModified,\n\t\t};\n\t} catch (err) {\n\t\tconsole.error(err);\n\t\tthrow err;\n\t}\n}\n"],"names":[],"mappings":";;AAKA,eAA8B,sBAAsB,MAAM,IAAoB;AAC7E,MAAI,CAAC,IAAK,OAAM,IAAI,MAAM,iBAAiB;AAE3C,MAAI;AACH,UAAM,WAAW,MAAM,MAAM,GAAG;AAChC,UAAM,YAAY,MAAM,SAAS,KAAA;AACjC,UAAM,eAAe;AAAA,MACpB,SAAS,QAAQ,IAAI,eAAe;AAAA,IAAA,EACnC,YAAA;AAEF,WAAO;AAAA,MACN,GAAG,WAAW,SAAS;AAAA,MACvB;AAAA,IAAA;AAAA,EAEF,SAAS,KAAK;AACb,YAAQ,MAAM,GAAG;AACjB,UAAM;AAAA,EACP;AACD;"}
|
||||
16
dist-node/parseTwtxt.d.ts
vendored
16
dist-node/parseTwtxt.d.ts
vendored
@@ -1,18 +1,6 @@
|
||||
import { Metadata, Twttr } from './types.ts';
|
||||
import { Twtxt } from './types.ts';
|
||||
/**
|
||||
* @param twtxt
|
||||
* @returns object containing: following, metadata, twts
|
||||
*/
|
||||
export default function parseTwtxt(twtxt: string): {
|
||||
following: Twttr[];
|
||||
metadata: Metadata;
|
||||
twts: {
|
||||
content: string;
|
||||
created: string;
|
||||
createdUTC: string;
|
||||
hash: string;
|
||||
replyHash: string | undefined;
|
||||
replyNick: string | undefined;
|
||||
replyUrl: string | undefined;
|
||||
}[];
|
||||
};
|
||||
export default function parseTwtxt(twtxt: string): Twtxt;
|
||||
|
||||
File diff suppressed because one or more lines are too long
1
dist-node/types.d.ts
vendored
1
dist-node/types.d.ts
vendored
@@ -26,6 +26,7 @@ export interface Twttr {
|
||||
}
|
||||
export interface Twtxt {
|
||||
following: Twttr[];
|
||||
lastModified?: string;
|
||||
metadata: Metadata;
|
||||
twts: Twt[];
|
||||
}
|
||||
|
||||
2
dist-node/utils.d.ts
vendored
2
dist-node/utils.d.ts
vendored
@@ -1,2 +1,2 @@
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => any;
|
||||
export declare const base32Encode: (payload: string | Uint8Array<ArrayBufferLike>) => string;
|
||||
export declare const getValueOrFirstEntry: (value: unknown | unknown[]) => any;
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import base32 from \"base32.js\";\n\nexport const base32Encode = (payload: string | Uint8Array<ArrayBufferLike>) => {\n\tconst encoder = new base32.Encoder({ type: \"rfc4648\" });\n\treturn encoder.write(payload).finalize();\n};\n\nexport const getValueOrFirstEntry = (value: unknown | unknown[]) =>\n\tArray.isArray(value) && value.length ? value[0] : value;\n"],"names":[],"mappings":";AAEO,MAAM,eAAe,CAAC,YAAkD;AAC9E,QAAM,UAAU,IAAI,OAAO,QAAQ,EAAE,MAAM,WAAW;AACtD,SAAO,QAAQ,MAAM,OAAO,EAAE,SAAA;AAC/B;AAEO,MAAM,uBAAuB,CAAC,UACpC,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC,IAAI;"}
|
||||
{"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import base32 from \"base32.js\";\n\nexport const base32Encode = (\n\tpayload: string | Uint8Array<ArrayBufferLike>,\n): string => {\n\tconst encoder = new base32.Encoder({ type: \"rfc4648\" });\n\treturn encoder.write(payload).finalize();\n};\n\nexport const getValueOrFirstEntry = (value: unknown | unknown[]) =>\n\tArray.isArray(value) && value.length ? value[0] : value;\n"],"names":[],"mappings":";AAEO,MAAM,eAAe,CAC3B,YACY;AACZ,QAAM,UAAU,IAAI,OAAO,QAAQ,EAAE,MAAM,WAAW;AACtD,SAAO,QAAQ,MAAM,OAAO,EAAE,SAAA;AAC/B;AAEO,MAAM,uBAAuB,CAAC,UACpC,MAAM,QAAQ,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC,IAAI;"}
|
||||
78
index.html
78
index.html
@@ -4,6 +4,9 @@
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>twtxt-lib Demo</title>
|
||||
<link rel="shortcut icon" href="favicon.ico"/>
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="stylesheet" href="/demo/styles.css" />
|
||||
</head>
|
||||
|
||||
@@ -47,32 +50,65 @@
|
||||
<a href="/dist-browser/twtxt-lib.js">ES6+ library for the browser</a>,
|
||||
with NPM and JSR versions coming soon.
|
||||
<li>Fully typed and source-mapped.</li>
|
||||
<li><a href="https://caniuse.com/es6-module">ESM</a> (and <a href="https://antfu.me/posts/move-on-to-esm-only">ESM only</a>)</li>
|
||||
<li>Built as an <a href="https://caniuse.com/es6-module">ES6 module</a> (and <a href="https://antfu.me/posts/move-on-to-esm-only">ESM only</a>)</li>
|
||||
<li>Includes an interactive demo <em>(you're looking at it)</em>.</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Installation</h2>
|
||||
|
||||
<p>
|
||||
Browser
|
||||
<ul>
|
||||
<li>Download <a href="/dist-browser/twtxt-lib.js">library</a> (or
|
||||
<a href="/dist-browser/twtxt-lib.min.js">minified version</a>).</li>
|
||||
<li>Import desired function(s) into your project: `import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js"`</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
JSR
|
||||
<ul>
|
||||
<li>Coming soon</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>
|
||||
NPM
|
||||
<ul>
|
||||
<li>Coming soon</li>
|
||||
</ul>
|
||||
</p>
|
||||
<p>This library can be installed in several different ways:</p>
|
||||
|
||||
<h3>For the Browser</h3>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Grab the latest copy of the <code>twtxt-lib.js</code> file, either by
|
||||
downloading it from the
|
||||
<a href="https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.js">git
|
||||
repo</a>, the
|
||||
<a href="/dist-browser/twtxt-lib.js">website</a>, or doing a
|
||||
<code>git clone https://git.itsericwoodward.com/eric/twtxt-lib.git</code>
|
||||
and pulling it out of the <code>dist-browser</code> folder.
|
||||
<ul>
|
||||
<li>
|
||||
Alternatively, you can grab the minified version from the
|
||||
<a href="https://git.itsericwoodward.com/eric/twtxt-lib/raw/branch/main/dist-browser/twtxt-lib.min.js">same</a>
|
||||
<a href="https://twtxt-lib.itsericwoodward.com/dist-browser/twtxt-lib.min.js">sources</a>.
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
Add the newly acquired file to your static site / progressive web app /
|
||||
over-engineered blog.
|
||||
</li>
|
||||
<li>
|
||||
Import the desired function(s) via ESM:
|
||||
<code>import { hashTwt, loadAndParseTwtxtFile } from "./twtxt-lib.js";</code>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h3>For Node</h3>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Add the package to your project.
|
||||
<ul>
|
||||
<li>
|
||||
Via <a href="https://www.npmjs.com/package/twtxt-lib">NPM</a>:
|
||||
<code>yarn add twtxt-lib</code>
|
||||
</li>
|
||||
<li>
|
||||
Via <a href="https://jsr.io/@itsericwoodward/twtxt-lib">JSR</a>:
|
||||
<code>yarn add jsr:@itsericwoodward/twtxt-lib</code>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>
|
||||
Import the desired function(s) into your code:
|
||||
<code>import { hashTwt, loadAndParseTwtxtFile } from "twtxt-lib";</code>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<p>Use the tabs to learn more.</p>
|
||||
|
||||
|
||||
6
jsr.json
Normal file
6
jsr.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "@itsericwoodward/twtxt-lib",
|
||||
"version": "0.9.1",
|
||||
"license": "MIT",
|
||||
"exports": "./src/index.ts"
|
||||
}
|
||||
36
package.json
36
package.json
@@ -1,30 +1,45 @@
|
||||
{
|
||||
"name": "twtxt-lib",
|
||||
"version": "0.9.0",
|
||||
"description": "",
|
||||
"version": "0.9.1",
|
||||
"description": "An isomorphic TypeScript library of utility functions for parsing and interacting with twtxt.txt files.",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Eric Woodward",
|
||||
"email": "hey@itsericwoodward.com",
|
||||
"url": "https://www.itsericwoodward.com"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": ""
|
||||
},
|
||||
"keywords": [],
|
||||
"type": "module",
|
||||
"module": "./dist-node/index.js",
|
||||
"types": "./dist-node/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist-node/index.js"
|
||||
}
|
||||
},
|
||||
"type": "module",
|
||||
"files": [
|
||||
"dist-node"
|
||||
],
|
||||
"module": "./dist-node/index.js",
|
||||
"types": "./dist-node/index.d.ts",
|
||||
"scripts": {
|
||||
"build:dev": "BUILD_ENV=development node ./build.js",
|
||||
"build": "BUILD_ENV=production node ./build.js",
|
||||
"build:dev": "BUILD_ENV=development node ./build.js",
|
||||
"build-tsc": "tsc",
|
||||
"ci": "yarn build:release",
|
||||
"ci": "yarn build",
|
||||
"dev": "vite",
|
||||
"preview": "vite preview",
|
||||
"prepublishOnly": "yarn build",
|
||||
"postpublish": "git push && git push --tags",
|
||||
"test": "vitest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@exodus/blakejs": "^1.1.1-exodus.0",
|
||||
"base32.js": "^0.1.0",
|
||||
"dayjs": "^1.11.19"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^25.3.0",
|
||||
"prettier": "^3.8.1",
|
||||
@@ -35,10 +50,5 @@
|
||||
"vite-plugin-node-polyfills": "^0.25.0",
|
||||
"vitest": "^4.0.18"
|
||||
},
|
||||
"packageManager": "yarn@4.12.0",
|
||||
"dependencies": {
|
||||
"@exodus/blakejs": "^1.1.1-exodus.0",
|
||||
"base32.js": "^0.1.0",
|
||||
"dayjs": "^1.11.19"
|
||||
}
|
||||
"packageManager": "yarn@4.12.0"
|
||||
}
|
||||
|
||||
@@ -68,6 +68,15 @@ button {
|
||||
background-color: var(--link-active);
|
||||
}
|
||||
|
||||
code {
|
||||
background-color: var(--bg-dark);
|
||||
color: var(--fg-main);
|
||||
font-size: smaller;
|
||||
padding: 0 .5rem;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
border: none;
|
||||
@@ -182,6 +191,7 @@ summary {
|
||||
bottom: 0;
|
||||
display: none;
|
||||
left: 0;
|
||||
line-height: 1.5rem;
|
||||
overflow: auto;
|
||||
padding: 0 1rem 1rem;
|
||||
right: 0;
|
||||
|
||||
BIN
public/favicon-16x16.png
Normal file
BIN
public/favicon-16x16.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
BIN
public/favicon-32x32.png
Normal file
BIN
public/favicon-32x32.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 909 B |
BIN
public/favicon.ico
Normal file
BIN
public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
@@ -1,8 +1,9 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import parseTwtxt from "./parseTwtxt.js";
|
||||
import type { Twtxt } from "./types.ts";
|
||||
|
||||
export default async function loadAndParseTwtxtFile(url = "") {
|
||||
export default async function loadAndParseTwtxtFile(url = ""): Promise<Twtxt> {
|
||||
if (!url) throw new Error("URL is required");
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc.js";
|
||||
|
||||
import type { Metadata, Twttr } from "./types.ts";
|
||||
import type { Metadata, Twttr, Twtxt } from "./types.ts";
|
||||
|
||||
import hashTwt from "./hashTwt.js";
|
||||
import { getValueOrFirstEntry } from "./utils.ts";
|
||||
@@ -12,7 +12,7 @@ dayjs.extend(utc);
|
||||
* @param twtxt
|
||||
* @returns object containing: following, metadata, twts
|
||||
*/
|
||||
export default function parseTwtxt(twtxt: string) {
|
||||
export default function parseTwtxt(twtxt: string): Twtxt {
|
||||
const allLines = twtxt.split("\n");
|
||||
|
||||
const { commentLines = [], contentLines = [] } = allLines.reduce(
|
||||
|
||||
@@ -30,6 +30,7 @@ export interface Twttr {
|
||||
|
||||
export interface Twtxt {
|
||||
following: Twttr[];
|
||||
lastModified?: string;
|
||||
metadata: Metadata;
|
||||
twts: Twt[];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import base32 from "base32.js";
|
||||
|
||||
export const base32Encode = (payload: string | Uint8Array<ArrayBufferLike>) => {
|
||||
export const base32Encode = (
|
||||
payload: string | Uint8Array<ArrayBufferLike>,
|
||||
): string => {
|
||||
const encoder = new base32.Encoder({ type: "rfc4648" });
|
||||
return encoder.write(payload).finalize();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user