xscrape 3.0.1 → 3.0.2

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/README.md CHANGED
@@ -1,6 +1,21 @@
1
- # xscrape
2
-
3
- `xscrape` is a powerful and flexible library designed for extracting and transforming data from HTML documents using user-defined schemas. It now supports any validation library that implements the **Standard Schema**, allowing you to bring your own schema for robust, type-safe data validation.
1
+ <p align="center">
2
+
3
+ <h1 align="center">🕷️<br/><code>xscrape</code></h1>
4
+ <p align="center">Extract and transform HTML with your own schema, powered by <code>Standard Schema</code> compatibility.
5
+ <br/>
6
+ by <a href="https://github.com/johnie">@johnie</a>
7
+ </p>
8
+ </p>
9
+ <br/>
10
+
11
+ <p align="center">
12
+ <a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/johnie/xscrape" alt="License"></a>
13
+ <a href="https://www.npmjs.com/package/xscrape" rel="nofollow"><img src="https://img.shields.io/npm/v/xscrape.svg" alt="npm"></a>
14
+ <a href="https://github.com/johnie/xscrape" rel="nofollow"><img src="https://img.shields.io/github/stars/johnie/xscrape" alt="stars"></a>
15
+ </p>
16
+
17
+ <br/>
18
+ <br/>
4
19
 
5
20
  ## Features
6
21
 
package/dist/index.d.cts CHANGED
@@ -7,13 +7,14 @@ interface ExtractDescriptor {
7
7
  value?: string | ExtractDescriptorFn | ExtractMap;
8
8
  }
9
9
  type ExtractValue = string | ExtractDescriptor | [string | ExtractDescriptor];
10
- interface ExtractMap {
11
- [key: string]: ExtractValue;
12
- }
10
+ type ExtractMap = Record<string, ExtractValue>;
13
11
 
12
+ type SchemaAwareExtractMap<T> = {
13
+ [K in keyof T]: ExtractMap[string];
14
+ };
14
15
  type ScraperConfig<S extends StandardSchemaV1, R extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>> = {
15
16
  schema: S;
16
- extract: ExtractMap;
17
+ extract: SchemaAwareExtractMap<StandardSchemaV1.InferOutput<S>>;
17
18
  transform?: (data: StandardSchemaV1.InferOutput<S>) => Promise<R> | R;
18
19
  };
19
20
  type ValidationResult<T> = {
@@ -26,6 +27,6 @@ type ScraperResult<T> = {
26
27
  error?: unknown;
27
28
  };
28
29
 
29
- declare function defineScraper<S extends StandardSchemaV1, R extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>>(config: ScraperConfig<S, R>): (html: string) => Promise<ScraperResult<R>>;
30
+ declare function defineScraper<S extends StandardSchemaV1, T extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>, R extends T = T>(config: ScraperConfig<S, R>): (html: string) => Promise<ScraperResult<R>>;
30
31
 
31
32
  export { type ScraperConfig, type ScraperResult, type ValidationResult, defineScraper };
package/dist/index.d.ts CHANGED
@@ -7,13 +7,14 @@ interface ExtractDescriptor {
7
7
  value?: string | ExtractDescriptorFn | ExtractMap;
8
8
  }
9
9
  type ExtractValue = string | ExtractDescriptor | [string | ExtractDescriptor];
10
- interface ExtractMap {
11
- [key: string]: ExtractValue;
12
- }
10
+ type ExtractMap = Record<string, ExtractValue>;
13
11
 
12
+ type SchemaAwareExtractMap<T> = {
13
+ [K in keyof T]: ExtractMap[string];
14
+ };
14
15
  type ScraperConfig<S extends StandardSchemaV1, R extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>> = {
15
16
  schema: S;
16
- extract: ExtractMap;
17
+ extract: SchemaAwareExtractMap<StandardSchemaV1.InferOutput<S>>;
17
18
  transform?: (data: StandardSchemaV1.InferOutput<S>) => Promise<R> | R;
18
19
  };
19
20
  type ValidationResult<T> = {
@@ -26,6 +27,6 @@ type ScraperResult<T> = {
26
27
  error?: unknown;
27
28
  };
28
29
 
29
- declare function defineScraper<S extends StandardSchemaV1, R extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>>(config: ScraperConfig<S, R>): (html: string) => Promise<ScraperResult<R>>;
30
+ declare function defineScraper<S extends StandardSchemaV1, T extends StandardSchemaV1.InferOutput<S> = StandardSchemaV1.InferOutput<S>, R extends T = T>(config: ScraperConfig<S, R>): (html: string) => Promise<ScraperResult<R>>;
30
31
 
31
32
  export { type ScraperConfig, type ScraperResult, type ValidationResult, defineScraper };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xscrape",
3
- "version": "3.0.1",
3
+ "version": "3.0.2",
4
4
  "description": "A flexible and powerful library designed to extract and transform data from HTML documents using user-defined schemas",
5
5
  "main": "dist/index.js",
6
6
  "exports": {
@@ -26,7 +26,8 @@
26
26
  "zod",
27
27
  "valibot",
28
28
  "arktype",
29
- "effect-schema"
29
+ "effect-schema",
30
+ "standard-schema"
30
31
  ],
31
32
  "author": "Johnie Hjelm <johnie@hjelm.im>",
32
33
  "license": "MIT",