webring 1.0.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.1](https://github.com/shepherdjerred/webring/compare/v1.0.0...v1.0.1) (2024-06-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add tests, fix import ([3f811a1](https://github.com/shepherdjerred/webring/commit/3f811a18fae9186795f5d34cb0d4bbdd20f2a5df))
14
+
8
15
  ## [1.0.0](https://github.com/shepherdjerred/webring/compare/v0.3.0...v1.0.0) (2024-06-03)
9
16
 
10
17
 
package/dist/fetch.js CHANGED
@@ -3,6 +3,8 @@ import sanitizeHtml from "sanitize-html";
3
3
  import truncate from "truncate-html";
4
4
  import { FeedEntrySchema } from "./types.js";
5
5
  import * as R from "remeda";
6
+ // for some reason, TypeScript does not infer the type of the default export correctly
7
+ const truncateFn = truncate;
6
8
  export async function fetch(source, length) {
7
9
  const parser = new Parser();
8
10
  try {
@@ -17,7 +19,7 @@ export async function fetch(source, length) {
17
19
  url: firstItem.link,
18
20
  date: new Date(firstItem.date),
19
21
  source,
20
- preview: preview ? truncate.default(sanitizeHtml(preview), length) : undefined,
22
+ preview: preview ? truncateFn(sanitizeHtml(preview), length) : undefined,
21
23
  };
22
24
  }
23
25
  catch (e) {
package/dist/index.js CHANGED
@@ -4,6 +4,13 @@ import fs from "fs/promises";
4
4
  export async function run(config) {
5
5
  const cacheFilename = config.cache_file;
6
6
  let cacheObject = {};
7
+ // check if cache.json exists
8
+ try {
9
+ await fs.access(cacheFilename);
10
+ }
11
+ catch (e) {
12
+ await fs.writeFile(cacheFilename, JSON.stringify({}));
13
+ }
7
14
  try {
8
15
  const cacheFile = await fs.readFile(cacheFilename);
9
16
  cacheObject = CacheSchema.parse(JSON.parse(cacheFile.toString()));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ // sum.test.js
2
+ import { expect, test } from "vitest";
3
+ import { run } from "./index.js";
4
+ test("it should work", async () => {
5
+ const config = {
6
+ sources: [
7
+ {
8
+ title: "Jerred Shepherd",
9
+ url: "https://sjer.red/rss.xml",
10
+ },
11
+ ],
12
+ number: 1,
13
+ cache_duration_minutes: 0,
14
+ truncate: 300,
15
+ cache_file: "cache.json",
16
+ };
17
+ const result = await run(config);
18
+ expect(result).toMatchSnapshot();
19
+ });
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "webring",
3
3
  "type": "module",
4
- "version": "1.0.0",
4
+ "version": "1.0.1",
5
5
  "scripts": {
6
+ "prepare": "husky",
6
7
  "lint": "eslint src",
7
8
  "build": "tsc",
8
- "prepare": "husky"
9
+ "test": "vitest"
9
10
  },
10
11
  "main": "dist/index.js",
11
12
  "types": "dist/index.d.ts",
@@ -32,7 +33,8 @@
32
33
  "lint-staged": "^15.2.5",
33
34
  "prettier": "^3.3.0",
34
35
  "typescript": "^5.4.5",
35
- "typescript-eslint": "^7.11.0"
36
+ "typescript-eslint": "^7.11.0",
37
+ "vitest": "^1.6.0"
36
38
  },
37
39
  "lint-staged": {
38
40
  "*.{ts,tsx}": "eslint --cache --fix",