@purescraps/purehtml 0.7.0 → 0.8.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.
@@ -6461,7 +6461,7 @@ var PureHTMLCheerioNode = class _PureHTMLCheerioNode extends PureHTMLNode {
6461
6461
  if (name) {
6462
6462
  return this.#el.attr(name) ?? null;
6463
6463
  }
6464
- return this.#el.attr();
6464
+ return this.#el.attr() ?? {};
6465
6465
  }
6466
6466
  find(selector) {
6467
6467
  return this.#el.find(selector).toArray().map((el) => new _PureHTMLCheerioNode(this.#$, this.#$(el)));
@@ -6513,6 +6513,9 @@ var ConfigWithSelector = class extends Config {
6513
6513
  }
6514
6514
  return matches;
6515
6515
  }
6516
+ toString() {
6517
+ return `ConfigWithSelector(${this.selector})`;
6518
+ }
6516
6519
  };
6517
6520
 
6518
6521
  // src/config/types/primitive.ts
@@ -6578,6 +6581,7 @@ var ArrayConfig = class _ArrayConfig extends ConfigWithSelector {
6578
6581
  alreadyMatched: params.elementAlreadyMatched ?? false,
6579
6582
  includeRoot: false
6580
6583
  });
6584
+ if (!$el) return null;
6581
6585
  const matches = Array.isArray($el) ? $el : [$el];
6582
6586
  const conf = this.items || PrimitiveValueConfig.generate(null, this.transform);
6583
6587
  const extractOpts = { ...params };
@@ -6753,6 +6757,35 @@ var NumberTransformer = class extends Transformer {
6753
6757
  }
6754
6758
  };
6755
6759
 
6760
+ // src/transformers/remove-last-path-section.ts
6761
+ var RemoveLastPathSection = class _RemoveLastPathSection extends Transformer {
6762
+ static transformerName = "removeLastPathSection";
6763
+ static getName() {
6764
+ return _RemoveLastPathSection.transformerName;
6765
+ }
6766
+ inputType() {
6767
+ return STRING;
6768
+ }
6769
+ outputType() {
6770
+ return STRING;
6771
+ }
6772
+ transform({ val }) {
6773
+ if (val === null) return null;
6774
+ if (typeof val !== "string") {
6775
+ throw new Error(
6776
+ `${_RemoveLastPathSection.transformerName}: expects string. Got ${JSON.stringify(
6777
+ val
6778
+ )}`
6779
+ );
6780
+ }
6781
+ const url = new URL(val);
6782
+ const sections = url.pathname.split("/");
6783
+ sections.pop();
6784
+ url.pathname = sections.join("/");
6785
+ return url.toString();
6786
+ }
6787
+ };
6788
+
6756
6789
  // src/transformers/remove-url-query-param.ts
6757
6790
  var RemoveUrlQueryParam = class _RemoveUrlQueryParam extends Transformer {
6758
6791
  constructor(args) {
@@ -6780,10 +6813,16 @@ var RemoveUrlQueryParam = class _RemoveUrlQueryParam extends Transformer {
6780
6813
  )}`
6781
6814
  );
6782
6815
  }
6783
- if (args.length === 0) return val;
6784
6816
  const url = new URL(val);
6785
- for (const paramName of args) {
6786
- url.searchParams.delete(paramName);
6817
+ if (args.length === 0) {
6818
+ const keys = Array.from(url.searchParams.keys());
6819
+ keys.forEach((key) => {
6820
+ url.searchParams.delete(key);
6821
+ });
6822
+ } else {
6823
+ for (const paramName of args) {
6824
+ url.searchParams.delete(paramName);
6825
+ }
6787
6826
  }
6788
6827
  return url.toString();
6789
6828
  }
@@ -6888,6 +6927,7 @@ var Transformers = class _Transformers {
6888
6927
  JSONTransformer,
6889
6928
  Length,
6890
6929
  NumberTransformer,
6930
+ RemoveLastPathSection,
6891
6931
  RemoveUrlQueryParam,
6892
6932
  ResolveTransformer,
6893
6933
  Trim,
@@ -6986,15 +7026,18 @@ var ObjectConfig = class _ObjectConfig extends ConfigWithSelector {
6986
7026
  }
6987
7027
  const props = this.properties;
6988
7028
  const keys = Object.keys(props);
6989
- return keys.reduce((acc, key) => {
6990
- const config2 = props[key];
6991
- acc[key] = config2.extract({
6992
- ...params,
6993
- $el,
6994
- property: this.makeProperty(params.property, key)
6995
- });
6996
- return acc;
6997
- }, {});
7029
+ return keys.reduce(
7030
+ (acc, key) => {
7031
+ const config2 = props[key];
7032
+ acc[key] = config2.extract({
7033
+ ...params,
7034
+ $el,
7035
+ property: this.makeProperty(params.property, key)
7036
+ });
7037
+ return acc;
7038
+ },
7039
+ {}
7040
+ );
6998
7041
  }
6999
7042
  makeProperty(property, prop) {
7000
7043
  if (property === rootProp) {
@@ -7213,7 +7256,7 @@ var ConfigValidator = class {
7213
7256
  var ConfigFactory = class _ConfigFactory {
7214
7257
  static fromYAML(yaml) {
7215
7258
  const plain = (0, import_yaml.parse)(yaml);
7216
- return this.generate(plain);
7259
+ return _ConfigFactory.generate(plain);
7217
7260
  }
7218
7261
  static generate(plain) {
7219
7262
  const validator = new ConfigValidator(plain);
@@ -7240,24 +7283,28 @@ var ConfigFactory = class _ConfigFactory {
7240
7283
  case "constant":
7241
7284
  return ConstantConfig.generate(constant, selector);
7242
7285
  case "object": {
7243
- let propConfigs = void 0;
7286
+ let propConfigs;
7244
7287
  if (properties) {
7245
- propConfigs = Object.keys(properties).reduce((acc, key) => {
7246
- acc[key] = this.generate(properties[key]);
7247
- return acc;
7248
- }, {});
7288
+ propConfigs = Object.keys(properties).reduce(
7289
+ (acc, key) => {
7290
+ acc[key] = _ConfigFactory.generate(properties[key]);
7291
+ return acc;
7292
+ },
7293
+ {}
7294
+ );
7249
7295
  }
7250
7296
  return ObjectConfig.generate(selector, propConfigs);
7251
7297
  }
7252
7298
  case "array":
7253
7299
  return ArrayConfig.generate(
7254
7300
  selector,
7255
- items && this.generate(items),
7301
+ items && _ConfigFactory.generate(items),
7256
7302
  transform
7257
7303
  );
7258
7304
  case "union":
7259
7305
  return UnionConfig.generate(
7260
- union.map((cfg) => this.generate(cfg))
7306
+ // biome-ignore lint/style/noNonNullAssertion: union will be present here. because our schema already validated the input
7307
+ union.map((cfg) => _ConfigFactory.generate(cfg))
7261
7308
  );
7262
7309
  default:
7263
7310
  return PrimitiveValueConfig.generate(selector, transform);