@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.
package/dist/src/index.js CHANGED
@@ -6764,6 +6764,42 @@ var NumberTransformer = class extends Transformer {
6764
6764
  }
6765
6765
  };
6766
6766
 
6767
+ // src/transformers/remove-url-query-param.ts
6768
+ var RemoveUrlQueryParam = class _RemoveUrlQueryParam extends Transformer {
6769
+ constructor(args) {
6770
+ super();
6771
+ this.args = args;
6772
+ }
6773
+ static transformerName = "removeUrlQueryParam";
6774
+ static getName() {
6775
+ return _RemoveUrlQueryParam.transformerName;
6776
+ }
6777
+ inputType() {
6778
+ return STRING;
6779
+ }
6780
+ outputType() {
6781
+ return STRING;
6782
+ }
6783
+ transform({
6784
+ val
6785
+ }) {
6786
+ const { args } = this;
6787
+ if (typeof val !== "string") {
6788
+ throw new Error(
6789
+ `${_RemoveUrlQueryParam.transformerName}: expected string. Got ${JSON.stringify(
6790
+ val
6791
+ )}`
6792
+ );
6793
+ }
6794
+ if (args.length === 0) return val;
6795
+ const url = new URL(val);
6796
+ for (const paramName of args) {
6797
+ url.searchParams.delete(paramName);
6798
+ }
6799
+ return url.toString();
6800
+ }
6801
+ };
6802
+
6767
6803
  // src/transformers/resolve.ts
6768
6804
  var ResolveTransformer = class extends Transformer {
6769
6805
  static getName() {
@@ -6844,15 +6880,18 @@ var UrlQueryParamTransformer = class _UrlQueryParamTransformer extends Transform
6844
6880
  if (args.length === 1) {
6845
6881
  return url.searchParams.get(args[0]);
6846
6882
  }
6847
- return args.reduce((acc, arg) => {
6848
- acc[arg] = url.searchParams.get(arg);
6849
- return acc;
6850
- }, {});
6883
+ return args.reduce(
6884
+ (acc, arg) => {
6885
+ acc[arg] = url.searchParams.get(arg);
6886
+ return acc;
6887
+ },
6888
+ {}
6889
+ );
6851
6890
  }
6852
6891
  };
6853
6892
 
6854
6893
  // src/transformers/transformers.ts
6855
- var Transformers = class {
6894
+ var Transformers = class _Transformers {
6856
6895
  static transformers = [
6857
6896
  AttributeTransformer,
6858
6897
  Exists,
@@ -6860,12 +6899,13 @@ var Transformers = class {
6860
6899
  JSONTransformer,
6861
6900
  Length,
6862
6901
  NumberTransformer,
6902
+ RemoveUrlQueryParam,
6863
6903
  ResolveTransformer,
6864
6904
  Trim,
6865
6905
  UrlQueryParamTransformer
6866
6906
  ];
6867
6907
  static getByName(name) {
6868
- return this.transformers.find((tr) => tr.getName() === name);
6908
+ return _Transformers.transformers.find((tr) => tr.getName() === name);
6869
6909
  }
6870
6910
  };
6871
6911
 
@@ -6985,21 +7025,20 @@ var UnionConfig = class _UnionConfig extends Config {
6985
7025
  const $parent = params.$el;
6986
7026
  for (const config of this.configs) {
6987
7027
  if (config instanceof ConfigWithSelector) {
6988
- const $el = config.getFirstMatch($parent, {
7028
+ const $matches = config.getAllMatches($parent, {
6989
7029
  alreadyMatched: false,
6990
7030
  includeRoot: true
6991
7031
  });
6992
- if (!$el) {
7032
+ if (!$matches || Array.isArray($matches) && $matches.length === 0)
6993
7033
  continue;
6994
- }
6995
7034
  return config.extract({
6996
7035
  ...params,
6997
- $el,
6998
- elementAlreadyMatched: true
7036
+ $el: Array.isArray($matches) ? $matches.length > 1 ? $parent : $matches[0] : $matches,
7037
+ // arrays must be matched again
7038
+ elementAlreadyMatched: !Array.isArray($matches) || $matches.length === 1
6999
7039
  });
7000
- } else {
7001
- return config.extract({ ...params, $el: params.$el });
7002
7040
  }
7041
+ return config.extract({ ...params, $el: params.$el });
7003
7042
  }
7004
7043
  return null;
7005
7044
  }