@purescraps/purehtml 0.5.0 → 0.7.0

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.
@@ -6417,7 +6417,7 @@ var require_ajv = __commonJS({
6417
6417
  });
6418
6418
 
6419
6419
  // examples/simple.ts
6420
- var import_fs = require("fs");
6420
+ var import_node_fs = require("fs");
6421
6421
 
6422
6422
  // src/backends/cheerio.ts
6423
6423
  var import_cheerio = require("cheerio");
@@ -6753,6 +6753,42 @@ var NumberTransformer = class extends Transformer {
6753
6753
  }
6754
6754
  };
6755
6755
 
6756
+ // src/transformers/remove-url-query-param.ts
6757
+ var RemoveUrlQueryParam = class _RemoveUrlQueryParam extends Transformer {
6758
+ constructor(args) {
6759
+ super();
6760
+ this.args = args;
6761
+ }
6762
+ static transformerName = "removeUrlQueryParam";
6763
+ static getName() {
6764
+ return _RemoveUrlQueryParam.transformerName;
6765
+ }
6766
+ inputType() {
6767
+ return STRING;
6768
+ }
6769
+ outputType() {
6770
+ return STRING;
6771
+ }
6772
+ transform({
6773
+ val
6774
+ }) {
6775
+ const { args } = this;
6776
+ if (typeof val !== "string") {
6777
+ throw new Error(
6778
+ `${_RemoveUrlQueryParam.transformerName}: expected string. Got ${JSON.stringify(
6779
+ val
6780
+ )}`
6781
+ );
6782
+ }
6783
+ if (args.length === 0) return val;
6784
+ const url = new URL(val);
6785
+ for (const paramName of args) {
6786
+ url.searchParams.delete(paramName);
6787
+ }
6788
+ return url.toString();
6789
+ }
6790
+ };
6791
+
6756
6792
  // src/transformers/resolve.ts
6757
6793
  var ResolveTransformer = class extends Transformer {
6758
6794
  static getName() {
@@ -6833,15 +6869,18 @@ var UrlQueryParamTransformer = class _UrlQueryParamTransformer extends Transform
6833
6869
  if (args.length === 1) {
6834
6870
  return url.searchParams.get(args[0]);
6835
6871
  }
6836
- return args.reduce((acc, arg) => {
6837
- acc[arg] = url.searchParams.get(arg);
6838
- return acc;
6839
- }, {});
6872
+ return args.reduce(
6873
+ (acc, arg) => {
6874
+ acc[arg] = url.searchParams.get(arg);
6875
+ return acc;
6876
+ },
6877
+ {}
6878
+ );
6840
6879
  }
6841
6880
  };
6842
6881
 
6843
6882
  // src/transformers/transformers.ts
6844
- var Transformers = class {
6883
+ var Transformers = class _Transformers {
6845
6884
  static transformers = [
6846
6885
  AttributeTransformer,
6847
6886
  Exists,
@@ -6849,12 +6888,13 @@ var Transformers = class {
6849
6888
  JSONTransformer,
6850
6889
  Length,
6851
6890
  NumberTransformer,
6891
+ RemoveUrlQueryParam,
6852
6892
  ResolveTransformer,
6853
6893
  Trim,
6854
6894
  UrlQueryParamTransformer
6855
6895
  ];
6856
6896
  static getByName(name) {
6857
- return this.transformers.find((tr) => tr.getName() === name);
6897
+ return _Transformers.transformers.find((tr) => tr.getName() === name);
6858
6898
  }
6859
6899
  };
6860
6900
 
@@ -6974,21 +7014,20 @@ var UnionConfig = class _UnionConfig extends Config {
6974
7014
  const $parent = params.$el;
6975
7015
  for (const config2 of this.configs) {
6976
7016
  if (config2 instanceof ConfigWithSelector) {
6977
- const $el = config2.getFirstMatch($parent, {
7017
+ const $matches = config2.getAllMatches($parent, {
6978
7018
  alreadyMatched: false,
6979
7019
  includeRoot: true
6980
7020
  });
6981
- if (!$el) {
7021
+ if (!$matches || Array.isArray($matches) && $matches.length === 0)
6982
7022
  continue;
6983
- }
6984
7023
  return config2.extract({
6985
7024
  ...params,
6986
- $el,
6987
- elementAlreadyMatched: true
7025
+ $el: Array.isArray($matches) ? $matches.length > 1 ? $parent : $matches[0] : $matches,
7026
+ // arrays must be matched again
7027
+ elementAlreadyMatched: !Array.isArray($matches) || $matches.length === 1
6988
7028
  });
6989
- } else {
6990
- return config2.extract({ ...params, $el: params.$el });
6991
7029
  }
7030
+ return config2.extract({ ...params, $el: params.$el });
6992
7031
  }
6993
7032
  return null;
6994
7033
  }
@@ -7286,9 +7325,9 @@ function extract(backend, $, config2, url) {
7286
7325
  }
7287
7326
 
7288
7327
  // examples/simple.ts
7289
- var html = (0, import_fs.readFileSync)("examples/simple.html").toString();
7328
+ var html = (0, import_node_fs.readFileSync)("examples/simple.html").toString();
7290
7329
  var config = ConfigFactory.fromYAML(
7291
- (0, import_fs.readFileSync)("examples/simple.yaml").toString()
7330
+ (0, import_node_fs.readFileSync)("examples/simple.yaml").toString()
7292
7331
  );
7293
7332
  console.log(
7294
7333
  "Simple parse result:",