utiller 1.0.265 → 1.0.267
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/lib/utiller/index.js +20 -13
- package/package.json +1 -1
- package/template/sample.package.json +1 -1
package/lib/utiller/index.js
CHANGED
|
@@ -2948,10 +2948,11 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
2948
2948
|
key: "extractNumber",
|
|
2949
2949
|
value: function extractNumber(str) {
|
|
2950
2950
|
// 使用正則表達式提取數字部分
|
|
2951
|
+
if (this.isUndefinedNullEmpty(str)) return -1;
|
|
2951
2952
|
var match = str.match(/\d+/);
|
|
2952
2953
|
|
|
2953
2954
|
// 如果找到數字,轉換為數字型態並回傳
|
|
2954
|
-
return match ? Number(match[0]) :
|
|
2955
|
+
return match ? Number(match[0]) : -1;
|
|
2955
2956
|
}
|
|
2956
2957
|
|
|
2957
2958
|
/** puppeteer 的 fetch function
|
|
@@ -2961,7 +2962,8 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
2961
2962
|
key: "fetchElementAttributes",
|
|
2962
2963
|
value: (function () {
|
|
2963
2964
|
var _fetchElementAttributes = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee8(dom, stringOfTrait) {
|
|
2964
|
-
var
|
|
2965
|
+
var defaultValue,
|
|
2966
|
+
element,
|
|
2965
2967
|
_len25,
|
|
2966
2968
|
attributes,
|
|
2967
2969
|
_key27,
|
|
@@ -2969,33 +2971,38 @@ var Utiller = /*#__PURE__*/function () {
|
|
|
2969
2971
|
return _regenerator["default"].wrap(function _callee8$(_context9) {
|
|
2970
2972
|
while (1) switch (_context9.prev = _context9.next) {
|
|
2971
2973
|
case 0:
|
|
2972
|
-
|
|
2974
|
+
defaultValue = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : "";
|
|
2975
|
+
_context9.next = 3;
|
|
2973
2976
|
return dom.$(stringOfTrait);
|
|
2974
|
-
case
|
|
2977
|
+
case 3:
|
|
2975
2978
|
element = _context9.sent;
|
|
2976
|
-
for (_len25 = _args9.length, attributes = new Array(_len25 > 2 ? _len25 - 2 : 0), _key27 = 2; _key27 < _len25; _key27++) {
|
|
2977
|
-
attributes[_key27 - 2] = _args9[_key27];
|
|
2978
|
-
}
|
|
2979
2979
|
if (this.isUndefinedNullEmpty(element)) {
|
|
2980
|
-
_context9.next =
|
|
2980
|
+
_context9.next = 16;
|
|
2981
2981
|
break;
|
|
2982
2982
|
}
|
|
2983
|
-
|
|
2983
|
+
for (_len25 = _args9.length, attributes = new Array(_len25 > 3 ? _len25 - 3 : 0), _key27 = 3; _key27 < _len25; _key27++) {
|
|
2984
|
+
attributes[_key27 - 3] = _args9[_key27];
|
|
2985
|
+
}
|
|
2986
|
+
_context9.prev = 6;
|
|
2987
|
+
_context9.next = 9;
|
|
2984
2988
|
return element.evaluate(function (el, attributes) {
|
|
2985
2989
|
if (attributes.length === 1) return el[attributes.shift()];
|
|
2986
2990
|
return _objectSpread({}, attributes.map(function (attr) {
|
|
2987
2991
|
return el[attr];
|
|
2988
2992
|
})); //或者 el.getAttribute('src') 更精確!
|
|
2989
2993
|
}, attributes);
|
|
2990
|
-
case
|
|
2994
|
+
case 9:
|
|
2991
2995
|
return _context9.abrupt("return", _context9.sent);
|
|
2992
|
-
case
|
|
2996
|
+
case 12:
|
|
2997
|
+
_context9.prev = 12;
|
|
2998
|
+
_context9.t0 = _context9["catch"](6);
|
|
2993
2999
|
this.appendError("1581532 ".concat(stringOfTrait, " fetch ").concat(JSON.stringify(attributes), " fail, element is not found"));
|
|
2994
|
-
|
|
3000
|
+
return _context9.abrupt("return", defaultValue);
|
|
3001
|
+
case 16:
|
|
2995
3002
|
case "end":
|
|
2996
3003
|
return _context9.stop();
|
|
2997
3004
|
}
|
|
2998
|
-
}, _callee8, this);
|
|
3005
|
+
}, _callee8, this, [[6, 12]]);
|
|
2999
3006
|
}));
|
|
3000
3007
|
function fetchElementAttributes(_x5, _x6) {
|
|
3001
3008
|
return _fetchElementAttributes.apply(this, arguments);
|
package/package.json
CHANGED