@purescraps/purehtml 0.10.0 → 0.10.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.
Files changed (134) hide show
  1. package/dist/examples/simple.d.ts +1 -2
  2. package/dist/examples/simple.js +8 -7856
  3. package/dist/examples/simple.js.map +1 -1
  4. package/dist/src/backends/cheerio.d.ts +24 -0
  5. package/dist/src/backends/cheerio.js +59 -0
  6. package/dist/src/backends/cheerio.js.map +1 -0
  7. package/dist/src/config/config.d.ts +11 -0
  8. package/dist/src/config/config.js +7 -0
  9. package/dist/src/config/config.js.map +1 -0
  10. package/dist/src/config/factory.d.ts +15 -0
  11. package/dist/src/config/factory.js +123 -0
  12. package/dist/src/config/factory.js.map +1 -0
  13. package/dist/src/config/index.d.ts +6 -0
  14. package/dist/src/config/index.js +23 -0
  15. package/dist/src/config/index.js.map +1 -0
  16. package/dist/src/config/plain-config.d.ts +15 -0
  17. package/dist/src/config/plain-config.js +3 -0
  18. package/dist/src/config/plain-config.js.map +1 -0
  19. package/dist/src/config/types/array.d.ts +11 -0
  20. package/dist/src/config/types/array.js +53 -0
  21. package/dist/src/config/types/array.js.map +1 -0
  22. package/dist/src/config/types/constant.d.ts +8 -0
  23. package/dist/src/config/types/constant.js +32 -0
  24. package/dist/src/config/types/constant.js.map +1 -0
  25. package/dist/src/config/types/default.d.ts +14 -0
  26. package/dist/src/config/types/default.js +27 -0
  27. package/dist/src/config/types/default.js.map +1 -0
  28. package/dist/src/config/types/object.d.ts +11 -0
  29. package/dist/src/config/types/object.js +51 -0
  30. package/dist/src/config/types/object.js.map +1 -0
  31. package/dist/src/config/types/primitive.d.ts +10 -0
  32. package/dist/src/config/types/primitive.js +48 -0
  33. package/dist/src/config/types/primitive.js.map +1 -0
  34. package/dist/src/config/types/union.d.ts +7 -0
  35. package/dist/src/config/types/union.js +44 -0
  36. package/dist/src/config/types/union.js.map +1 -0
  37. package/dist/src/config/types/with-selector.d.ts +16 -0
  38. package/dist/src/config/types/with-selector.js +31 -0
  39. package/dist/src/config/types/with-selector.js.map +1 -0
  40. package/dist/src/config/validator.d.ts +6 -0
  41. package/dist/src/config/validator.js +54 -0
  42. package/dist/src/config/validator.js.map +1 -0
  43. package/dist/src/config-schema.json +154 -0
  44. package/dist/src/core/argument-types.d.ts +4 -0
  45. package/dist/src/core/argument-types.js +22 -0
  46. package/dist/src/core/argument-types.js.map +1 -0
  47. package/dist/src/core/backend.d.ts +19 -0
  48. package/dist/src/core/backend.js +16 -0
  49. package/dist/src/core/backend.js.map +1 -0
  50. package/dist/src/core/complex-types.d.ts +3 -0
  51. package/dist/src/core/complex-types.js +6 -0
  52. package/dist/src/core/complex-types.js.map +1 -0
  53. package/dist/src/core/primitive-types.d.ts +4 -0
  54. package/dist/src/core/primitive-types.js +7 -0
  55. package/dist/src/core/primitive-types.js.map +1 -0
  56. package/dist/src/core/property.d.ts +2 -0
  57. package/dist/src/core/property.js +5 -0
  58. package/dist/src/core/property.js.map +1 -0
  59. package/dist/src/core/transformer.d.ts +15 -0
  60. package/dist/src/core/transformer.js +10 -0
  61. package/dist/src/core/transformer.js.map +1 -0
  62. package/dist/src/errors/invalid-parse-input-error.d.ts +5 -0
  63. package/dist/src/errors/invalid-parse-input-error.js +12 -0
  64. package/dist/src/errors/invalid-parse-input-error.js.map +1 -0
  65. package/dist/src/index.d.ts +10 -75
  66. package/dist/src/index.js +29 -7865
  67. package/dist/src/index.js.map +1 -1
  68. package/dist/src/transformers/attr.d.ts +12 -0
  69. package/dist/src/transformers/attr.js +45 -0
  70. package/dist/src/transformers/attr.js.map +1 -0
  71. package/dist/src/transformers/boolean.d.ts +15 -0
  72. package/dist/src/transformers/boolean.js +33 -0
  73. package/dist/src/transformers/boolean.js.map +1 -0
  74. package/dist/src/transformers/capitalize.d.ts +12 -0
  75. package/dist/src/transformers/capitalize.js +35 -0
  76. package/dist/src/transformers/capitalize.js.map +1 -0
  77. package/dist/src/transformers/exists.d.ts +8 -0
  78. package/dist/src/transformers/exists.js +20 -0
  79. package/dist/src/transformers/exists.js.map +1 -0
  80. package/dist/src/transformers/factory.d.ts +19 -0
  81. package/dist/src/transformers/factory.js +100 -0
  82. package/dist/src/transformers/factory.js.map +1 -0
  83. package/dist/src/transformers/html.d.ts +8 -0
  84. package/dist/src/transformers/html.js +20 -0
  85. package/dist/src/transformers/html.js.map +1 -0
  86. package/dist/src/transformers/index.d.ts +16 -0
  87. package/dist/src/transformers/index.js +33 -0
  88. package/dist/src/transformers/index.js.map +1 -0
  89. package/dist/src/transformers/join.d.ts +18 -0
  90. package/dist/src/transformers/join.js +41 -0
  91. package/dist/src/transformers/join.js.map +1 -0
  92. package/dist/src/transformers/json.d.ts +8 -0
  93. package/dist/src/transformers/json.js +23 -0
  94. package/dist/src/transformers/json.js.map +1 -0
  95. package/dist/src/transformers/jsonpath.d.ts +20 -0
  96. package/dist/src/transformers/jsonpath.js +144 -0
  97. package/dist/src/transformers/jsonpath.js.map +1 -0
  98. package/dist/src/transformers/length.d.ts +8 -0
  99. package/dist/src/transformers/length.js +24 -0
  100. package/dist/src/transformers/length.js.map +1 -0
  101. package/dist/src/transformers/lower.d.ts +8 -0
  102. package/dist/src/transformers/lower.js +27 -0
  103. package/dist/src/transformers/lower.js.map +1 -0
  104. package/dist/src/transformers/number.d.ts +8 -0
  105. package/dist/src/transformers/number.js +27 -0
  106. package/dist/src/transformers/number.js.map +1 -0
  107. package/dist/src/transformers/remove-last-path-section.d.ts +9 -0
  108. package/dist/src/transformers/remove-last-path-section.js +31 -0
  109. package/dist/src/transformers/remove-last-path-section.js.map +1 -0
  110. package/dist/src/transformers/remove-url-query-param.d.ts +19 -0
  111. package/dist/src/transformers/remove-url-query-param.js +51 -0
  112. package/dist/src/transformers/remove-url-query-param.js.map +1 -0
  113. package/dist/src/transformers/replace.d.ts +18 -0
  114. package/dist/src/transformers/replace.js +44 -0
  115. package/dist/src/transformers/replace.js.map +1 -0
  116. package/dist/src/transformers/resolve.d.ts +8 -0
  117. package/dist/src/transformers/resolve.js +24 -0
  118. package/dist/src/transformers/resolve.js.map +1 -0
  119. package/dist/src/transformers/split.d.ts +18 -0
  120. package/dist/src/transformers/split.js +45 -0
  121. package/dist/src/transformers/split.js.map +1 -0
  122. package/dist/src/transformers/transformers.d.ts +15 -0
  123. package/dist/src/transformers/transformers.js +53 -0
  124. package/dist/src/transformers/transformers.js.map +1 -0
  125. package/dist/src/transformers/trim.d.ts +8 -0
  126. package/dist/src/transformers/trim.js +27 -0
  127. package/dist/src/transformers/trim.js.map +1 -0
  128. package/dist/src/transformers/upper.d.ts +8 -0
  129. package/dist/src/transformers/upper.js +27 -0
  130. package/dist/src/transformers/upper.js.map +1 -0
  131. package/dist/src/transformers/url-query-param.d.ts +10 -0
  132. package/dist/src/transformers/url-query-param.js +41 -0
  133. package/dist/src/transformers/url-query-param.js.map +1 -0
  134. package/package.json +12 -12
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const config_1 = require("../config");
7
+ const with_selector_1 = __importDefault(require("./with-selector"));
8
+ class UnionConfig extends config_1.Config {
9
+ configs;
10
+ constructor(configs) {
11
+ super();
12
+ this.configs = configs;
13
+ }
14
+ extract(params) {
15
+ const $parent = params.$el;
16
+ for (const config of this.configs) {
17
+ if (config instanceof with_selector_1.default) {
18
+ const $matches = config.getAllMatches($parent, {
19
+ alreadyMatched: false,
20
+ includeRoot: true,
21
+ });
22
+ if (!$matches || (Array.isArray($matches) && $matches.length === 0))
23
+ continue;
24
+ return config.extract({
25
+ ...params,
26
+ $el: Array.isArray($matches)
27
+ ? $matches.length > 1
28
+ ? $parent
29
+ : $matches[0]
30
+ : $matches,
31
+ // arrays must be matched again
32
+ elementAlreadyMatched: !Array.isArray($matches) || $matches.length === 1,
33
+ });
34
+ }
35
+ return config.extract({ ...params, $el: params.$el });
36
+ }
37
+ return null;
38
+ }
39
+ static generate(configs) {
40
+ return new UnionConfig(configs);
41
+ }
42
+ }
43
+ exports.default = UnionConfig;
44
+ //# sourceMappingURL=union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../../src/config/types/union.ts"],"names":[],"mappings":";;;;;AAAA,sCAAuD;AACvD,oEAAiD;AAEjD,iBAAiC,SAAQ,eAAM;IACR,OAAO;IAA5C,YAAqC,OAAiB;QACpD,KAAK,EAAE,CAAC;uBAD2B,OAAO;IAE5C,CAAC;IAED,OAAO,CAAC,MAAqB;QAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC;QAE3B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAClC,IAAI,MAAM,YAAY,uBAAkB,EAAE,CAAC;gBACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE;oBAC7C,cAAc,EAAE,KAAK;oBACrB,WAAW,EAAE,IAAI;iBAClB,CAAC,CAAC;gBAEH,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,CAAC;oBACjE,SAAS;gBAEX,OAAO,MAAM,CAAC,OAAO,CAAC;oBACpB,GAAG,MAAM;oBACT,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;wBAC1B,CAAC,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC;4BACnB,CAAC,CAAC,OAAO;4BACT,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;wBACf,CAAC,CAAC,QAAQ;oBAEZ,+BAA+B;oBAC/B,qBAAqB,EACnB,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;iBACpD,CAAC,CAAC;YACL,CAAC;YAED,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAiB;QAC/B,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { PureHTMLNode } from '../../core/backend';
2
+ import { Config, type ExtractParams } from '../config';
3
+ export interface ConfigWithSelectorExtractParams extends ExtractParams {
4
+ elementAlreadyMatched?: boolean;
5
+ }
6
+ export interface GetSelectorMatchesParams {
7
+ alreadyMatched: boolean;
8
+ includeRoot: boolean;
9
+ }
10
+ export default abstract class ConfigWithSelector extends Config {
11
+ selector: string | null;
12
+ abstract extract(params: ConfigWithSelectorExtractParams): unknown;
13
+ getAllMatches($: PureHTMLNode, { alreadyMatched, includeRoot }: GetSelectorMatchesParams): PureHTMLNode | PureHTMLNode[] | null;
14
+ getFirstMatch($: PureHTMLNode, params: GetSelectorMatchesParams): PureHTMLNode | null;
15
+ toString(): string;
16
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const config_1 = require("../config");
4
+ class ConfigWithSelector extends config_1.Config {
5
+ selector = null;
6
+ getAllMatches($, { alreadyMatched, includeRoot }) {
7
+ if (alreadyMatched) {
8
+ return $;
9
+ }
10
+ if (this.selector === null) {
11
+ return $;
12
+ }
13
+ // check if the element *itself* matches the given selector
14
+ if (includeRoot && $.is(this.selector)) {
15
+ return $;
16
+ }
17
+ return $.find(this.selector) ?? null;
18
+ }
19
+ getFirstMatch($, params) {
20
+ const matches = this.getAllMatches($, params);
21
+ if (Array.isArray(matches)) {
22
+ return matches[0] ?? null;
23
+ }
24
+ return matches;
25
+ }
26
+ toString() {
27
+ return `ConfigWithSelector(${this.selector})`;
28
+ }
29
+ }
30
+ exports.default = ConfigWithSelector;
31
+ //# sourceMappingURL=with-selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with-selector.js","sourceRoot":"","sources":["../../../../src/config/types/with-selector.ts"],"names":[],"mappings":";;AACA,sCAAuD;AAWvD,wBAAiD,SAAQ,eAAM;IACtD,QAAQ,GAAkB,IAAI,CAAC;IAItC,aAAa,CACX,CAAe,EACf,EAAE,cAAc,EAAE,WAAW,EAA4B;QAEzD,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,OAAO,CAAC,CAAC;QACX,CAAC;QAED,2DAA2D;QAC3D,IAAI,WAAW,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IAED,aAAa,CACX,CAAe,EACf,MAAgC;QAEhC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAE9C,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QAC5B,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,QAAQ;QACN,OAAO,sBAAsB,IAAI,CAAC,QAAQ,GAAG,CAAC;IAChD,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ import Ajv from 'ajv';
2
+ export declare class ConfigValidator {
3
+ private readonly plain;
4
+ constructor(plain: unknown);
5
+ validate(): Ajv['errors'];
6
+ }
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.ConfigValidator = void 0;
40
+ const ajv_1 = __importDefault(require("ajv"));
41
+ const schema = __importStar(require("../config-schema.json"));
42
+ const ajv = new ajv_1.default();
43
+ class ConfigValidator {
44
+ plain;
45
+ constructor(plain) {
46
+ this.plain = plain;
47
+ }
48
+ validate() {
49
+ ajv.validate(schema, this.plain);
50
+ return ajv.errors;
51
+ }
52
+ }
53
+ exports.ConfigValidator = ConfigValidator;
54
+ //# sourceMappingURL=validator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/config/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8CAAsB;AACtB,MAAY,MAAM,kDAA8B;AAEhD,MAAM,GAAG,GAAG,IAAI,aAAG,EAAE,CAAC;AAEtB;IAC+B,KAAK;IAAlC,YAA6B,KAAc;qBAAd,KAAK;IAAY,CAAC;IAE/C,QAAQ;QACN,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEjC,OAAO,GAAG,CAAC,MAAM,CAAC;IACpB,CAAC;CACF"}
@@ -0,0 +1,154 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "type": "object",
4
+ "required": [],
5
+ "$id": "config-schema.json",
6
+ "oneOf": [
7
+ {
8
+ "$comment": "WithSelector",
9
+ "properties": {
10
+ "selector": {
11
+ "oneOf": [
12
+ { "type": "string", "minLength": 1 },
13
+ {
14
+ "type": "array",
15
+ "items": {
16
+ "oneOf": [
17
+ { "type": "string" },
18
+ {
19
+ "type": "object",
20
+ "properties": {
21
+ "selector": { "type": "string" },
22
+ "sampleHTMLs": {
23
+ "type": "array",
24
+ "items": { "type": "string" }
25
+ }
26
+ },
27
+ "required": []
28
+ }
29
+ ]
30
+ },
31
+ "minItems": 1
32
+ },
33
+ {
34
+ "type": "object",
35
+ "properties": {
36
+ "selector": { "type": "string" },
37
+ "sampleHTMLs": {
38
+ "type": "array",
39
+ "items": { "type": "string" }
40
+ }
41
+ },
42
+ "required": []
43
+ }
44
+ ]
45
+ },
46
+ "type": {
47
+ "type": "string",
48
+ "enum": ["string", "number", "boolean", "object", "array", "union"]
49
+ },
50
+ "items": { "$ref": "config-schema.json" },
51
+ "properties": {
52
+ "type": "object",
53
+ "additionalProperties": { "$ref": "config-schema.json" }
54
+ },
55
+ "transform": {
56
+ "oneOf": [
57
+ {
58
+ "type": "string",
59
+ "pattern": "^[\\w-]+(\\((\\s*(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|[\\w-]+)\\s*(,\\s*(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|[\\w-]+)\\s*)*)?\\))?$"
60
+ },
61
+ {
62
+ "type": "array",
63
+ "items": {
64
+ "type": "string",
65
+ "pattern": "^[\\w-]+(\\((\\s*(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|[\\w-]+)\\s*(,\\s*(?:\"(?:[^\"\\\\]|\\\\.)*\"|'(?:[^'\\\\]|\\\\.)*'|[\\w-]+)\\s*)*)?\\))?$"
66
+ },
67
+ "minItems": 1
68
+ }
69
+ ]
70
+ },
71
+ "default": {
72
+ "$comment": "fallback value returned in place of null when the selector matches nothing"
73
+ }
74
+ },
75
+ "required": [],
76
+ "additionalProperties": false,
77
+ "allOf": [
78
+ {
79
+ "$comment": "when the \"properties\" present, \"type\" can only be \"object\" or not defined at all",
80
+ "if": { "required": ["properties"] },
81
+ "then": { "properties": { "type": { "const": "object" } } }
82
+ },
83
+ {
84
+ "$comment": "when the \"type\" is \"object\", then the \"properties\" MUST be defined.",
85
+ "if": {
86
+ "properties": { "type": { "const": "object" } },
87
+ "required": ["type"]
88
+ },
89
+ "then": { "required": ["properties"] }
90
+ },
91
+ {
92
+ "$comment": "objects cannot have transform",
93
+ "if": {
94
+ "anyOf": [
95
+ {
96
+ "properties": { "type": { "const": "object" } },
97
+ "required": ["type"]
98
+ },
99
+ { "required": ["properties"] }
100
+ ]
101
+ },
102
+ "then": {
103
+ "allOf": [
104
+ { "required": ["properties"] },
105
+ { "not": { "required": ["transform"] } }
106
+ ]
107
+ }
108
+ },
109
+ {
110
+ "$comment": "when the \"items\" present, \"type\" can only be \"array\" or not defined at all",
111
+ "if": { "required": ["items"] },
112
+ "then": { "properties": { "type": { "const": "array" } } }
113
+ },
114
+ {
115
+ "$comment": "when the \"type\" is \"array\", then the \"items\" MUST be defined.",
116
+ "if": {
117
+ "properties": { "type": { "const": "array" } },
118
+ "required": ["type"]
119
+ },
120
+ "then": { "required": ["items"] }
121
+ }
122
+ ]
123
+ },
124
+ {
125
+ "$comment": "Union",
126
+ "type": "object",
127
+ "properties": {
128
+ "union": {
129
+ "type": "array",
130
+ "items": { "$ref": "config-schema.json" },
131
+ "minItems": 1
132
+ },
133
+ "default": {
134
+ "$comment": "fallback value returned in place of null when no union member matches"
135
+ }
136
+ },
137
+ "required": ["union"],
138
+ "additionalProperties": false
139
+ },
140
+ {
141
+ "$comment": "Constant",
142
+ "type": "object",
143
+ "properties": {
144
+ "selector": { "type": "string" },
145
+ "constant": {},
146
+ "default": {
147
+ "$comment": "fallback value returned in place of null when the selector matches nothing"
148
+ }
149
+ },
150
+ "required": ["constant"],
151
+ "additionalProperties": false
152
+ }
153
+ ]
154
+ }
@@ -0,0 +1,4 @@
1
+ import { type ComplexTypes } from './complex-types';
2
+ import { type PrimitiveTypes } from './primitive-types';
3
+ export type ArgumentTypes = PrimitiveTypes | ComplexTypes;
4
+ export declare function argTypeToStr(typ: ArgumentTypes): "array" | "boolean" | "number" | "object" | "string";
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.argTypeToStr = argTypeToStr;
4
+ const complex_types_1 = require("./complex-types");
5
+ const primitive_types_1 = require("./primitive-types");
6
+ function argTypeToStr(typ) {
7
+ switch (typ) {
8
+ case primitive_types_1.STRING:
9
+ return 'string';
10
+ case primitive_types_1.NUMBER:
11
+ return 'number';
12
+ case primitive_types_1.BOOLEAN:
13
+ return 'boolean';
14
+ case complex_types_1.OBJECT:
15
+ return 'object';
16
+ case complex_types_1.ARRAY:
17
+ return 'array';
18
+ default:
19
+ throw new Error(`Unrecognized argument type: ${typ}`);
20
+ }
21
+ }
22
+ //# sourceMappingURL=argument-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argument-types.js","sourceRoot":"","sources":["../../../src/core/argument-types.ts"],"names":[],"mappings":";;;AAAA,mDAAmE;AACnE,uDAK2B;AAI3B,sBAA6B,GAAkB;IAC7C,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,wBAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,wBAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,yBAAO;YACV,OAAO,SAAS,CAAC;QACnB,KAAK,sBAAM;YACT,OAAO,QAAQ,CAAC;QAClB,KAAK,qBAAK;YACR,OAAO,OAAO,CAAC;QACjB;YACE,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * PureHTML backend class
3
+ */
4
+ export declare abstract class PureHTMLBackend {
5
+ abstract load(html: Buffer | string): PureHTMLDocument;
6
+ }
7
+ export declare abstract class PureHTMLDocument {
8
+ abstract root(): PureHTMLNode;
9
+ abstract $(selector: string): PureHTMLNode[];
10
+ }
11
+ export type PureHTMLNodeAttributes = Record<string, string | null>;
12
+ export declare abstract class PureHTMLNode {
13
+ abstract attr(name: string): string | null;
14
+ abstract attr(): PureHTMLNodeAttributes;
15
+ abstract find(selector: string): PureHTMLNode[];
16
+ abstract html(): string | null;
17
+ abstract is(selector: string): boolean;
18
+ abstract text(): string;
19
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PureHTMLNode = exports.PureHTMLDocument = exports.PureHTMLBackend = void 0;
4
+ /**
5
+ * PureHTML backend class
6
+ */
7
+ class PureHTMLBackend {
8
+ }
9
+ exports.PureHTMLBackend = PureHTMLBackend;
10
+ class PureHTMLDocument {
11
+ }
12
+ exports.PureHTMLDocument = PureHTMLDocument;
13
+ class PureHTMLNode {
14
+ }
15
+ exports.PureHTMLNode = PureHTMLNode;
16
+ //# sourceMappingURL=backend.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend.js","sourceRoot":"","sources":["../../../src/core/backend.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH;CAEC;;AAED;CAGC;;AAID;CAOC"}
@@ -0,0 +1,3 @@
1
+ export declare const OBJECT: unique symbol;
2
+ export declare const ARRAY: unique symbol;
3
+ export type ComplexTypes = typeof OBJECT | typeof ARRAY;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ARRAY = exports.OBJECT = void 0;
4
+ exports.OBJECT = Symbol('OBJECT');
5
+ exports.ARRAY = Symbol('ARRAY');
6
+ //# sourceMappingURL=complex-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complex-types.js","sourceRoot":"","sources":["../../../src/core/complex-types.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAkB,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,QAAA,KAAK,GAAkB,MAAM,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const STRING: unique symbol;
2
+ export declare const NUMBER: unique symbol;
3
+ export declare const BOOLEAN: unique symbol;
4
+ export type PrimitiveTypes = typeof STRING | typeof NUMBER | typeof BOOLEAN;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BOOLEAN = exports.NUMBER = exports.STRING = void 0;
4
+ exports.STRING = Symbol('STRING');
5
+ exports.NUMBER = Symbol('NUMBER');
6
+ exports.BOOLEAN = Symbol('BOOLEAN');
7
+ //# sourceMappingURL=primitive-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive-types.js","sourceRoot":"","sources":["../../../src/core/primitive-types.ts"],"names":[],"mappings":";;;AAAa,QAAA,MAAM,GAAkB,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,QAAA,MAAM,GAAkB,MAAM,CAAC,QAAQ,CAAC,CAAC;AACzC,QAAA,OAAO,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const rootProp: unique symbol;
2
+ export type Property = typeof rootProp | string;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rootProp = void 0;
4
+ exports.rootProp = Symbol('rootProp');
5
+ //# sourceMappingURL=property.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property.js","sourceRoot":"","sources":["../../../src/core/property.ts"],"names":[],"mappings":";;;AAAa,QAAA,QAAQ,GAAkB,MAAM,CAAC,UAAU,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ArgumentTypes } from './argument-types';
2
+ import type { PureHTMLNode } from './backend';
3
+ import type { Property } from './property';
4
+ export interface TransformParams {
5
+ val: unknown;
6
+ $el: PureHTMLNode | null;
7
+ url: string;
8
+ property: Property;
9
+ }
10
+ export declare abstract class Transformer {
11
+ static getName(): string;
12
+ abstract inputType(): ArgumentTypes;
13
+ abstract outputType(): ArgumentTypes;
14
+ abstract transform(params: TransformParams): unknown;
15
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Transformer = void 0;
4
+ class Transformer {
5
+ static getName() {
6
+ throw new Error('Not implemented');
7
+ }
8
+ }
9
+ exports.Transformer = Transformer;
10
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformer.js","sourceRoot":"","sources":["../../../src/core/transformer.ts"],"names":[],"mappings":";;;AAWA;IACE,MAAM,CAAC,OAAO;QACZ,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;CAOF"}
@@ -0,0 +1,5 @@
1
+ import type { Property } from '../core/property';
2
+ export declare class InvalidParseInputError extends Error {
3
+ readonly property: Property;
4
+ constructor(property: Property, message?: string);
5
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidParseInputError = void 0;
4
+ class InvalidParseInputError extends Error {
5
+ property;
6
+ constructor(property, message) {
7
+ super(message);
8
+ this.property = property;
9
+ }
10
+ }
11
+ exports.InvalidParseInputError = InvalidParseInputError;
12
+ //# sourceMappingURL=invalid-parse-input-error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"invalid-parse-input-error.js","sourceRoot":"","sources":["../../../src/errors/invalid-parse-input-error.ts"],"names":[],"mappings":";;;AAEA,4BAAoC,SAAQ,KAAK;IAEpC,QAAQ;IADnB,YACW,QAAkB,EAC3B,OAAgB;QAEhB,KAAK,CAAC,OAAO,CAAC,CAAC;wBAHN,QAAQ;IAInB,CAAC;CACF"}
@@ -1,77 +1,12 @@
1
- import { CheerioAPI, Cheerio } from 'cheerio';
2
- import { AnyNode } from 'domhandler';
3
-
1
+ import { PureHTMLCheerioBackend } from './backends/cheerio';
2
+ import { Config } from './config';
3
+ import type { PureHTMLBackend, PureHTMLDocument } from './core/backend';
4
+ declare const cheerio: PureHTMLCheerioBackend;
5
+ export { ConfigFactory } from './config';
4
6
  /**
5
- * PureHTML backend class
7
+ * For custom html parsing backend implementors
6
8
  */
7
- declare abstract class PureHTMLBackend {
8
- abstract load(html: Buffer | string): PureHTMLDocument;
9
- }
10
- declare abstract class PureHTMLDocument {
11
- abstract root(): PureHTMLNode;
12
- abstract $(selector: string): PureHTMLNode[];
13
- }
14
- type PureHTMLNodeAttributes = Record<string, string | null>;
15
- declare abstract class PureHTMLNode {
16
- abstract attr(name: string): string | null;
17
- abstract attr(): PureHTMLNodeAttributes;
18
- abstract find(selector: string): PureHTMLNode[];
19
- abstract html(): string | null;
20
- abstract is(selector: string): boolean;
21
- abstract text(): string;
22
- }
23
-
24
- type CheerioRoot = CheerioAPI;
25
- declare class PureHTMLCheerioBackend extends PureHTMLBackend {
26
- load(html: string | Buffer): PureHTMLCheerioDocument;
27
- }
28
- declare class PureHTMLCheerioDocument extends PureHTMLDocument {
29
- #private;
30
- constructor(root: CheerioRoot);
31
- $(selector: string): PureHTMLCheerioNode[];
32
- root(): PureHTMLCheerioNode;
33
- }
34
- declare class PureHTMLCheerioNode extends PureHTMLNode {
35
- #private;
36
- constructor($: CheerioRoot, el: Cheerio<AnyNode>);
37
- attr(name: string): string | null;
38
- attr(): PureHTMLNodeAttributes;
39
- find(selector: string): PureHTMLCheerioNode[];
40
- html(): string | null;
41
- is(selector: string): boolean;
42
- text(): string;
43
- }
44
-
45
- declare const rootProp: unique symbol;
46
- type Property = typeof rootProp | string;
47
-
48
- interface ExtractParams {
49
- $: PureHTMLDocument;
50
- $el: PureHTMLNode;
51
- url: string;
52
- property: Property;
53
- }
54
- declare abstract class Config<T = unknown> {
55
- abstract extract(params: ExtractParams): T;
56
- }
57
-
58
- declare class ConfigFactory {
59
- static fromYAML<T>(yaml: string): Config<T>;
60
- private static generate;
61
- /**
62
- * `type: number` / `type: boolean` on a primitive value are sugar for
63
- * appending the corresponding transformer to the end of the transform
64
- * chain, so the extracted value is coerced even when no explicit
65
- * `transform` is provided. `type: string` (or no type) is left as-is.
66
- */
67
- private static appendTypeCoercion;
68
- private static generateSelector;
69
- private static generateTransform;
70
- private static detectExpectedType;
71
- }
72
-
73
- declare const cheerio: PureHTMLCheerioBackend;
74
-
75
- declare function extract<T = unknown>(backend: PureHTMLBackend, $: PureHTMLDocument | string, config: Config<T>, url: string): T;
76
-
77
- export { Config, ConfigFactory, PureHTMLBackend, PureHTMLDocument, PureHTMLNode, type PureHTMLNodeAttributes, cheerio, extract };
9
+ export { PureHTMLBackend, PureHTMLDocument, PureHTMLNode, } from './core/backend';
10
+ export type { PureHTMLNodeAttributes } from './core/backend';
11
+ export { Config, cheerio };
12
+ export declare function extract<T = unknown>(backend: PureHTMLBackend, $: PureHTMLDocument | string, config: Config<T>, url: string): T;