@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.
- package/dist/examples/simple.js +68 -21
- package/dist/examples/simple.js.map +1 -1
- package/dist/src/index.d.ts +8 -4
- package/dist/src/index.js +68 -21
- package/dist/src/index.js.map +1 -1
- package/package.json +16 -14
package/dist/examples/simple.js
CHANGED
|
@@ -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
|
-
|
|
6786
|
-
url.searchParams.
|
|
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(
|
|
6990
|
-
|
|
6991
|
-
|
|
6992
|
-
|
|
6993
|
-
|
|
6994
|
-
|
|
6995
|
-
|
|
6996
|
-
|
|
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
|
|
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
|
|
7286
|
+
let propConfigs;
|
|
7244
7287
|
if (properties) {
|
|
7245
|
-
propConfigs = Object.keys(properties).reduce(
|
|
7246
|
-
acc
|
|
7247
|
-
|
|
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 &&
|
|
7301
|
+
items && _ConfigFactory.generate(items),
|
|
7256
7302
|
transform
|
|
7257
7303
|
);
|
|
7258
7304
|
case "union":
|
|
7259
7305
|
return UnionConfig.generate(
|
|
7260
|
-
union.
|
|
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);
|