@synstack/web 1.1.9 → 1.1.10
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/dist/web.index.cjs.map +1 -1
- package/dist/web.index.d.cts +6 -4
- package/dist/web.index.d.ts +6 -4
- package/dist/web.index.js.map +1 -1
- package/package.json +8 -9
- package/src/web.lib.ts +10 -4
package/dist/web.index.cjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/web.index.ts","../src/web.bundle.ts","../src/web.lib.ts"],"sourcesContent":["export * from \"./web.bundle.ts\";\nexport * as web from \"./web.bundle.ts\";\nexport { ArticleNotFoundException } from \"./web.lib.ts\";\n","export { fetchArticle, fetchJson, fetchText } from \"./web.lib.ts\";\n","import { Readability } from \"@mozilla/readability\";\nimport { parseHTML } from \"linkedom\";\nimport type {
|
1
|
+
{"version":3,"sources":["../src/web.index.ts","../src/web.bundle.ts","../src/web.lib.ts"],"sourcesContent":["export * from \"./web.bundle.ts\";\nexport * as web from \"./web.bundle.ts\";\nexport { ArticleNotFoundException } from \"./web.lib.ts\";\n","export { fetchArticle, fetchJson, fetchText } from \"./web.lib.ts\";\n","import { Readability } from \"@mozilla/readability\";\nimport { parseHTML } from \"linkedom\";\nimport type { ZodTypeDef as ZodTypeDefV3, ZodType as ZodTypeV3 } from \"zod/v3\";\nimport type { ZodType as ZodTypeV4 } from \"zod/v4\";\n\n// Union type to support both Zod v3 and v4 schemas\ntype ZodSchema<OUT = any, IN = any> =\n | ZodTypeV3<OUT, ZodTypeDefV3, IN>\n | ZodTypeV4<OUT, IN>;\n\n/**\n * Retrieves an URL as JSON\n * @param url\n * @param options.schema an optional Zod schema to validate the data against\n * @returns the JSON as a JS object\n */\nexport const fetchJson = <SHAPE>(\n url: string,\n options: { schema?: ZodSchema<SHAPE> } = {},\n): Promise<SHAPE> =>\n fetch(url)\n .then((response) => response.json())\n .then((data) => (options.schema ? options.schema.parse(data) : data));\n\n/**\n * Retrieves an URL as a string\n * @param url\n * @returns the plain text content of the URL\n */\nexport const fetchText = (url: string): Promise<string> =>\n fetch(url).then((response) => response.text());\n\n/**\n * Extract an article from a URL\n * @param url\n * @returns the article content as a JS object\n */\nexport const fetchArticle = async (url: string) => {\n const content = await fetchText(url);\n const doc = parseHTML(content, { url });\n const reader = new Readability(doc.window.document);\n const article = reader.parse();\n\n if (!article?.content) throw new ArticleNotFoundException(url);\n\n return {\n url,\n content: article.content,\n title: article.title,\n byline: article.byline,\n siteName: article.siteName,\n lang: article.lang,\n publishedTime: article.publishedTime,\n };\n};\n\nexport class ArticleNotFoundException extends Error {\n constructor(url: string) {\n super(\n `\nNo article found at the URL\nURL: ${url}\n`.trim(),\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,yBAA4B;AAC5B,sBAA0B;AAenB,IAAM,YAAY,CACvB,KACA,UAAyC,CAAC,MAE1C,MAAM,GAAG,EACN,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC,EAClC,KAAK,CAAC,SAAU,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI,IAAI,IAAK;AAOjE,IAAM,YAAY,CAAC,QACxB,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC;AAOxC,IAAM,eAAe,OAAO,QAAgB;AACjD,QAAM,UAAU,MAAM,UAAU,GAAG;AACnC,QAAM,UAAM,2BAAU,SAAS,EAAE,IAAI,CAAC;AACtC,QAAM,SAAS,IAAI,+BAAY,IAAI,OAAO,QAAQ;AAClD,QAAM,UAAU,OAAO,MAAM;AAE7B,MAAI,CAAC,SAAS,QAAS,OAAM,IAAI,yBAAyB,GAAG;AAE7D,SAAO;AAAA,IACL;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB,OAAO,QAAQ;AAAA,IACf,QAAQ,QAAQ;AAAA,IAChB,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,IACd,eAAe,QAAQ;AAAA,EACzB;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,KAAa;AACvB;AAAA,MACE;AAAA;AAAA,OAEC,GAAG;AAAA,EACR,KAAK;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
package/dist/web.index.d.cts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
import {
|
1
|
+
import { ZodType, ZodTypeDef } from 'zod/v3';
|
2
|
+
import { ZodType as ZodType$1 } from 'zod/v4';
|
2
3
|
|
4
|
+
type ZodSchema<OUT = any, IN = any> = ZodType<OUT, ZodTypeDef, IN> | ZodType$1<OUT, IN>;
|
3
5
|
/**
|
4
6
|
* Retrieves an URL as JSON
|
5
7
|
* @param url
|
6
8
|
* @param options.schema an optional Zod schema to validate the data against
|
7
9
|
* @returns the JSON as a JS object
|
8
10
|
*/
|
9
|
-
declare const fetchJson: <
|
10
|
-
schema?: ZodSchema<
|
11
|
-
}) => Promise<
|
11
|
+
declare const fetchJson: <SHAPE>(url: string, options?: {
|
12
|
+
schema?: ZodSchema<SHAPE>;
|
13
|
+
}) => Promise<SHAPE>;
|
12
14
|
/**
|
13
15
|
* Retrieves an URL as a string
|
14
16
|
* @param url
|
package/dist/web.index.d.ts
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
import {
|
1
|
+
import { ZodType, ZodTypeDef } from 'zod/v3';
|
2
|
+
import { ZodType as ZodType$1 } from 'zod/v4';
|
2
3
|
|
4
|
+
type ZodSchema<OUT = any, IN = any> = ZodType<OUT, ZodTypeDef, IN> | ZodType$1<OUT, IN>;
|
3
5
|
/**
|
4
6
|
* Retrieves an URL as JSON
|
5
7
|
* @param url
|
6
8
|
* @param options.schema an optional Zod schema to validate the data against
|
7
9
|
* @returns the JSON as a JS object
|
8
10
|
*/
|
9
|
-
declare const fetchJson: <
|
10
|
-
schema?: ZodSchema<
|
11
|
-
}) => Promise<
|
11
|
+
declare const fetchJson: <SHAPE>(url: string, options?: {
|
12
|
+
schema?: ZodSchema<SHAPE>;
|
13
|
+
}) => Promise<SHAPE>;
|
12
14
|
/**
|
13
15
|
* Retrieves an URL as a string
|
14
16
|
* @param url
|
package/dist/web.index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/web.bundle.ts","../src/web.lib.ts"],"sourcesContent":["export { fetchArticle, fetchJson, fetchText } from \"./web.lib.ts\";\n","import { Readability } from \"@mozilla/readability\";\nimport { parseHTML } from \"linkedom\";\nimport type {
|
1
|
+
{"version":3,"sources":["../src/web.bundle.ts","../src/web.lib.ts"],"sourcesContent":["export { fetchArticle, fetchJson, fetchText } from \"./web.lib.ts\";\n","import { Readability } from \"@mozilla/readability\";\nimport { parseHTML } from \"linkedom\";\nimport type { ZodTypeDef as ZodTypeDefV3, ZodType as ZodTypeV3 } from \"zod/v3\";\nimport type { ZodType as ZodTypeV4 } from \"zod/v4\";\n\n// Union type to support both Zod v3 and v4 schemas\ntype ZodSchema<OUT = any, IN = any> =\n | ZodTypeV3<OUT, ZodTypeDefV3, IN>\n | ZodTypeV4<OUT, IN>;\n\n/**\n * Retrieves an URL as JSON\n * @param url\n * @param options.schema an optional Zod schema to validate the data against\n * @returns the JSON as a JS object\n */\nexport const fetchJson = <SHAPE>(\n url: string,\n options: { schema?: ZodSchema<SHAPE> } = {},\n): Promise<SHAPE> =>\n fetch(url)\n .then((response) => response.json())\n .then((data) => (options.schema ? options.schema.parse(data) : data));\n\n/**\n * Retrieves an URL as a string\n * @param url\n * @returns the plain text content of the URL\n */\nexport const fetchText = (url: string): Promise<string> =>\n fetch(url).then((response) => response.text());\n\n/**\n * Extract an article from a URL\n * @param url\n * @returns the article content as a JS object\n */\nexport const fetchArticle = async (url: string) => {\n const content = await fetchText(url);\n const doc = parseHTML(content, { url });\n const reader = new Readability(doc.window.document);\n const article = reader.parse();\n\n if (!article?.content) throw new ArticleNotFoundException(url);\n\n return {\n url,\n content: article.content,\n title: article.title,\n byline: article.byline,\n siteName: article.siteName,\n lang: article.lang,\n publishedTime: article.publishedTime,\n };\n};\n\nexport class ArticleNotFoundException extends Error {\n constructor(url: string) {\n super(\n `\nNo article found at the URL\nURL: ${url}\n`.trim(),\n );\n }\n}\n"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,SAAS,mBAAmB;AAC5B,SAAS,iBAAiB;AAenB,IAAM,YAAY,CACvB,KACA,UAAyC,CAAC,MAE1C,MAAM,GAAG,EACN,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC,EAClC,KAAK,CAAC,SAAU,QAAQ,SAAS,QAAQ,OAAO,MAAM,IAAI,IAAI,IAAK;AAOjE,IAAM,YAAY,CAAC,QACxB,MAAM,GAAG,EAAE,KAAK,CAAC,aAAa,SAAS,KAAK,CAAC;AAOxC,IAAM,eAAe,OAAO,QAAgB;AACjD,QAAM,UAAU,MAAM,UAAU,GAAG;AACnC,QAAM,MAAM,UAAU,SAAS,EAAE,IAAI,CAAC;AACtC,QAAM,SAAS,IAAI,YAAY,IAAI,OAAO,QAAQ;AAClD,QAAM,UAAU,OAAO,MAAM;AAE7B,MAAI,CAAC,SAAS,QAAS,OAAM,IAAI,yBAAyB,GAAG;AAE7D,SAAO;AAAA,IACL;AAAA,IACA,SAAS,QAAQ;AAAA,IACjB,OAAO,QAAQ;AAAA,IACf,QAAQ,QAAQ;AAAA,IAChB,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,IACd,eAAe,QAAQ;AAAA,EACzB;AACF;AAEO,IAAM,2BAAN,cAAuC,MAAM;AAAA,EAClD,YAAY,KAAa;AACvB;AAAA,MACE;AAAA;AAAA,OAEC,GAAG;AAAA,EACR,KAAK;AAAA,IACH;AAAA,EACF;AACF;","names":[]}
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
"publishConfig": {
|
5
5
|
"access": "public"
|
6
6
|
},
|
7
|
-
"version": "1.1.
|
7
|
+
"version": "1.1.10",
|
8
8
|
"description": "Web scraping utilities",
|
9
9
|
"keywords": [
|
10
10
|
"web",
|
@@ -30,8 +30,7 @@
|
|
30
30
|
"test:types": "tsc --noEmit",
|
31
31
|
"test:unit": "node --experimental-strip-types --experimental-test-snapshots --no-warnings --test src/**/*.test.ts",
|
32
32
|
"test:unit:watch": "node --experimental-strip-types --experimental-test-snapshots --no-warnings --watch --test --watch src/**/*.test.ts",
|
33
|
-
"test": "
|
34
|
-
"prepare": "yarn test && yarn build"
|
33
|
+
"test": "pnpm test:types && pnpm test:unit"
|
35
34
|
},
|
36
35
|
"exports": {
|
37
36
|
".": {
|
@@ -47,21 +46,21 @@
|
|
47
46
|
},
|
48
47
|
"dependencies": {
|
49
48
|
"@mozilla/readability": "^0.6.0",
|
50
|
-
"linkedom": "^0.18.
|
49
|
+
"linkedom": "^0.18.11"
|
51
50
|
},
|
52
51
|
"devDependencies": {
|
53
|
-
"@types/node": "^22.15.
|
54
|
-
"tsup": "^8.
|
52
|
+
"@types/node": "^22.15.32",
|
53
|
+
"tsup": "^8.5.0",
|
55
54
|
"typescript": "^5.8.3",
|
56
|
-
"zod": "^3.
|
55
|
+
"zod": "^3.25.67"
|
57
56
|
},
|
58
57
|
"peerDependencies": {
|
59
|
-
"zod": "
|
58
|
+
"zod": "^3.25.0"
|
60
59
|
},
|
61
60
|
"files": [
|
62
61
|
"src/**/*.ts",
|
63
62
|
"!src/**/*.test.ts",
|
64
63
|
"dist/**/*"
|
65
64
|
],
|
66
|
-
"gitHead": "
|
65
|
+
"gitHead": "f0daeeb6dd582a265033f020ba5e4baef3ff2a94"
|
67
66
|
}
|
package/src/web.lib.ts
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import { Readability } from "@mozilla/readability";
|
2
2
|
import { parseHTML } from "linkedom";
|
3
|
-
import type {
|
3
|
+
import type { ZodTypeDef as ZodTypeDefV3, ZodType as ZodTypeV3 } from "zod/v3";
|
4
|
+
import type { ZodType as ZodTypeV4 } from "zod/v4";
|
5
|
+
|
6
|
+
// Union type to support both Zod v3 and v4 schemas
|
7
|
+
type ZodSchema<OUT = any, IN = any> =
|
8
|
+
| ZodTypeV3<OUT, ZodTypeDefV3, IN>
|
9
|
+
| ZodTypeV4<OUT, IN>;
|
4
10
|
|
5
11
|
/**
|
6
12
|
* Retrieves an URL as JSON
|
@@ -8,10 +14,10 @@ import type { ZodSchema } from "zod";
|
|
8
14
|
* @param options.schema an optional Zod schema to validate the data against
|
9
15
|
* @returns the JSON as a JS object
|
10
16
|
*/
|
11
|
-
export const fetchJson = <
|
17
|
+
export const fetchJson = <SHAPE>(
|
12
18
|
url: string,
|
13
|
-
options: { schema?: ZodSchema<
|
14
|
-
): Promise<
|
19
|
+
options: { schema?: ZodSchema<SHAPE> } = {},
|
20
|
+
): Promise<SHAPE> =>
|
15
21
|
fetch(url)
|
16
22
|
.then((response) => response.json())
|
17
23
|
.then((data) => (options.schema ? options.schema.parse(data) : data));
|