xscrape 3.2.0 → 3.2.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/dist/index.cjs CHANGED
@@ -34,35 +34,30 @@ async function validateExtractedData(schema, extractedData) {
34
34
  };
35
35
  }
36
36
  function transformValidatedData(value, transform) {
37
- if (!transform) return Promise.resolve(value);
38
- return Promise.resolve(transform(value));
37
+ return Promise.resolve(transform ? transform(value) : value);
39
38
  }
40
39
  function compileExtractConfig($, extract) {
41
40
  return Object.fromEntries(Object.entries(extract).map(([key, value]) => [key, compileExtractField($, value)]));
42
41
  }
43
42
  function compileExtractField($, field) {
44
- if (Array.isArray(field)) return [compileArrayItem($, field[0])];
45
- if (typeof field === "string") return field;
46
- return compileExtractDescriptor($, field);
47
- }
48
- function compileArrayItem($, field) {
43
+ if (Array.isArray(field)) {
44
+ const item = field[0];
45
+ return [typeof item === "string" ? item : compileExtractDescriptor($, item)];
46
+ }
49
47
  if (typeof field === "string") return field;
50
48
  return compileExtractDescriptor($, field);
51
49
  }
52
50
  function compileExtractDescriptor($, descriptor) {
53
- const { value } = descriptor;
54
- const compiled = { selector: descriptor.selector };
55
- if (value === void 0) return compiled;
56
- if (typeof value === "string") {
57
- compiled.value = value;
58
- return compiled;
59
- }
60
- if (typeof value === "function") {
61
- compiled.value = (element, key, obj) => value(createExtractNode($, element), key, obj);
62
- return compiled;
63
- }
64
- compiled.value = compileExtractConfig($, value);
65
- return compiled;
51
+ const value = compileDescriptorValue($, descriptor.value);
52
+ return value === void 0 ? { selector: descriptor.selector } : {
53
+ selector: descriptor.selector,
54
+ value
55
+ };
56
+ }
57
+ function compileDescriptorValue($, value) {
58
+ if (value === void 0 || typeof value === "string") return value;
59
+ if (typeof value === "function") return (element, key, obj) => value(createExtractNode($, element), key, obj);
60
+ return compileExtractConfig($, value);
66
61
  }
67
62
  function createExtractNode($, element) {
68
63
  return {
package/dist/index.mjs CHANGED
@@ -33,35 +33,30 @@ async function validateExtractedData(schema, extractedData) {
33
33
  };
34
34
  }
35
35
  function transformValidatedData(value, transform) {
36
- if (!transform) return Promise.resolve(value);
37
- return Promise.resolve(transform(value));
36
+ return Promise.resolve(transform ? transform(value) : value);
38
37
  }
39
38
  function compileExtractConfig($, extract) {
40
39
  return Object.fromEntries(Object.entries(extract).map(([key, value]) => [key, compileExtractField($, value)]));
41
40
  }
42
41
  function compileExtractField($, field) {
43
- if (Array.isArray(field)) return [compileArrayItem($, field[0])];
44
- if (typeof field === "string") return field;
45
- return compileExtractDescriptor($, field);
46
- }
47
- function compileArrayItem($, field) {
42
+ if (Array.isArray(field)) {
43
+ const item = field[0];
44
+ return [typeof item === "string" ? item : compileExtractDescriptor($, item)];
45
+ }
48
46
  if (typeof field === "string") return field;
49
47
  return compileExtractDescriptor($, field);
50
48
  }
51
49
  function compileExtractDescriptor($, descriptor) {
52
- const { value } = descriptor;
53
- const compiled = { selector: descriptor.selector };
54
- if (value === void 0) return compiled;
55
- if (typeof value === "string") {
56
- compiled.value = value;
57
- return compiled;
58
- }
59
- if (typeof value === "function") {
60
- compiled.value = (element, key, obj) => value(createExtractNode($, element), key, obj);
61
- return compiled;
62
- }
63
- compiled.value = compileExtractConfig($, value);
64
- return compiled;
50
+ const value = compileDescriptorValue($, descriptor.value);
51
+ return value === void 0 ? { selector: descriptor.selector } : {
52
+ selector: descriptor.selector,
53
+ value
54
+ };
55
+ }
56
+ function compileDescriptorValue($, value) {
57
+ if (value === void 0 || typeof value === "string") return value;
58
+ if (typeof value === "function") return (element, key, obj) => value(createExtractNode($, element), key, obj);
59
+ return compileExtractConfig($, value);
65
60
  }
66
61
  function createExtractNode($, element) {
67
62
  return {
package/package.json CHANGED
@@ -14,18 +14,18 @@
14
14
  "effect": "^3.21.2",
15
15
  "jsdom": "^29.1.1",
16
16
  "lefthook": "^2.1.6",
17
- "tsdown": "^0.21.10",
17
+ "tsdown": "^0.22.0",
18
18
  "typescript": "^6.0.3",
19
19
  "ultracite": "7.6.3",
20
- "valibot": "^1.3.1",
21
- "vite": "^8.0.10",
20
+ "valibot": "^1.4.0",
21
+ "vite": "^8.0.11",
22
22
  "vitepress": "^1.6.4",
23
23
  "vitest": "^4.1.5",
24
24
  "zod": "^4.4.3"
25
25
  },
26
26
  "name": "xscrape",
27
27
  "type": "module",
28
- "version": "3.2.0",
28
+ "version": "3.2.1",
29
29
  "description": "A flexible and powerful library designed to extract and transform data from HTML documents using user-defined schemas",
30
30
  "main": "dist/index.cjs",
31
31
  "exports": {