@ohbug/utils 1.0.11 → 2.0.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/README.md +0 -1
- package/dist/index.d.ts +28 -7
- package/dist/index.js +167 -0
- package/dist/index.mjs +128 -0
- package/package.json +22 -19
- package/src/dom.ts +44 -0
- package/src/get.ts +34 -0
- package/src/index.ts +7 -0
- package/src/logger.ts +20 -0
- package/src/mixin.ts +38 -0
- package/src/validators.ts +19 -0
- package/src/warning.ts +10 -0
- package/dist/dom.d.ts +0 -2
- package/dist/dom.d.ts.map +0 -1
- package/dist/get.d.ts +0 -6
- package/dist/get.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts +0 -3
- package/dist/logger.d.ts.map +0 -1
- package/dist/mixin.d.ts +0 -8
- package/dist/mixin.d.ts.map +0 -1
- package/dist/ohbug-utils.cjs.js +0 -223
- package/dist/ohbug-utils.esm.js +0 -205
- package/dist/ohbug-utils.esm.min.js +0 -15
- package/dist/ohbug-utils.umd.js +0 -229
- package/dist/ohbug-utils.umd.min.js +0 -15
- package/dist/validators.d.ts +0 -6
- package/dist/validators.d.ts.map +0 -1
- package/dist/warning.d.ts +0 -3
- package/dist/warning.d.ts.map +0 -1
package/dist/ohbug-utils.cjs.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
/*! *****************************************************************************
|
|
6
|
-
Copyright (c) Microsoft Corporation.
|
|
7
|
-
|
|
8
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
-
purpose with or without fee is hereby granted.
|
|
10
|
-
|
|
11
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
***************************************************************************** */
|
|
19
|
-
|
|
20
|
-
function __spreadArray(to, from) {
|
|
21
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
22
|
-
to[j] = from[i];
|
|
23
|
-
return to;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var prefix = 'Ohbug';
|
|
27
|
-
var logger = {
|
|
28
|
-
log: function () {
|
|
29
|
-
var args = [];
|
|
30
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
31
|
-
args[_i] = arguments[_i];
|
|
32
|
-
}
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.log.apply(console, __spreadArray([prefix], args));
|
|
35
|
-
},
|
|
36
|
-
info: function () {
|
|
37
|
-
var args = [];
|
|
38
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
39
|
-
args[_i] = arguments[_i];
|
|
40
|
-
}
|
|
41
|
-
// eslint-disable-next-line no-console
|
|
42
|
-
console.info.apply(console, __spreadArray([prefix], args));
|
|
43
|
-
},
|
|
44
|
-
warn: function () {
|
|
45
|
-
var args = [];
|
|
46
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
47
|
-
args[_i] = arguments[_i];
|
|
48
|
-
}
|
|
49
|
-
console.warn.apply(console, __spreadArray([prefix], args));
|
|
50
|
-
},
|
|
51
|
-
error: function () {
|
|
52
|
-
var args = [];
|
|
53
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
54
|
-
args[_i] = arguments[_i];
|
|
55
|
-
}
|
|
56
|
-
console.error.apply(console, __spreadArray([prefix], args));
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
function error(condition, format) {
|
|
61
|
-
var args = [];
|
|
62
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
63
|
-
args[_i - 2] = arguments[_i];
|
|
64
|
-
}
|
|
65
|
-
if (format === undefined) {
|
|
66
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
67
|
-
}
|
|
68
|
-
if (!condition) {
|
|
69
|
-
var argIndex_1 = 0;
|
|
70
|
-
// eslint-disable-next-line no-plusplus
|
|
71
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_1++]; });
|
|
72
|
-
throw new Error("Ohbug " + message);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
function warning(condition, format) {
|
|
76
|
-
var args = [];
|
|
77
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
78
|
-
args[_i - 2] = arguments[_i];
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
82
|
-
if (format === undefined) {
|
|
83
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
84
|
-
}
|
|
85
|
-
if (!condition) {
|
|
86
|
-
var argIndex_2 = 0;
|
|
87
|
-
// eslint-disable-next-line no-plusplus
|
|
88
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_2++]; });
|
|
89
|
-
logger.warn(message);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// eslint-disable-next-line no-empty
|
|
93
|
-
}
|
|
94
|
-
catch (e) { }
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function isString(value) {
|
|
98
|
-
return typeof value === 'string';
|
|
99
|
-
}
|
|
100
|
-
function isNumber(value) {
|
|
101
|
-
return typeof value === 'number' && parseInt("" + value, 10) === value;
|
|
102
|
-
}
|
|
103
|
-
function isFunction(value) {
|
|
104
|
-
return typeof value === 'function';
|
|
105
|
-
}
|
|
106
|
-
function isObject(value) {
|
|
107
|
-
return Object.prototype.toString.call(value) === '[object Object]';
|
|
108
|
-
}
|
|
109
|
-
function isPromise(value) {
|
|
110
|
-
return value instanceof Promise;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
var fallbackGlobalObject = {};
|
|
114
|
-
function getGlobal() {
|
|
115
|
-
return (typeof window !== 'undefined'
|
|
116
|
-
? window
|
|
117
|
-
: typeof global !== 'undefined'
|
|
118
|
-
? global
|
|
119
|
-
: typeof self !== 'undefined'
|
|
120
|
-
? self
|
|
121
|
-
: fallbackGlobalObject);
|
|
122
|
-
}
|
|
123
|
-
function getOhbugObject() {
|
|
124
|
-
var global = getGlobal();
|
|
125
|
-
error(Boolean(global.__OHBUG__), 'Failed to get `OhbugObject`, please confirm if `Ohbug.init`');
|
|
126
|
-
return global.__OHBUG__;
|
|
127
|
-
}
|
|
128
|
-
function isNode() {
|
|
129
|
-
return typeof global !== 'undefined';
|
|
130
|
-
}
|
|
131
|
-
function isBrowser() {
|
|
132
|
-
return typeof window !== 'undefined';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function replace(source, name, behavior) {
|
|
136
|
-
if (!(name in source)) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
var original = source[name];
|
|
140
|
-
var wrapped = behavior(original);
|
|
141
|
-
// eslint-disable-next-line no-param-reassign
|
|
142
|
-
source[name] = wrapped;
|
|
143
|
-
return original;
|
|
144
|
-
}
|
|
145
|
-
function parseUrl(url) {
|
|
146
|
-
if (typeof url !== 'string') {
|
|
147
|
-
return {};
|
|
148
|
-
}
|
|
149
|
-
// eslint-disable-next-line
|
|
150
|
-
var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
|
|
151
|
-
if (!match) {
|
|
152
|
-
return {};
|
|
153
|
-
}
|
|
154
|
-
var query = match[6] || '';
|
|
155
|
-
var fragment = match[8] || '';
|
|
156
|
-
return {
|
|
157
|
-
host: match[4],
|
|
158
|
-
path: match[5],
|
|
159
|
-
protocol: match[2],
|
|
160
|
-
relative: match[5] + query + fragment,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function getParentNode(node, path) {
|
|
165
|
-
if (node.parentNode) {
|
|
166
|
-
path.push(node.parentNode);
|
|
167
|
-
getParentNode(node.parentNode, path);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function getPath(node) {
|
|
171
|
-
var path = [];
|
|
172
|
-
path.push(node);
|
|
173
|
-
getParentNode(node, path);
|
|
174
|
-
return path;
|
|
175
|
-
}
|
|
176
|
-
var getSelector = function (event) {
|
|
177
|
-
var immutableTarget = (event.target || event.srcElement);
|
|
178
|
-
var target = (event.target || event.srcElement);
|
|
179
|
-
// 获取出错元素在同级元素的 index
|
|
180
|
-
// 储存错误元素前元素
|
|
181
|
-
var elements = [];
|
|
182
|
-
for (var i = 0; target &&
|
|
183
|
-
target.nodeType === Node.ELEMENT_NODE &&
|
|
184
|
-
target.nodeType !== Node.DOCUMENT_TYPE_NODE; target = target.previousSibling) {
|
|
185
|
-
if (i)
|
|
186
|
-
elements.push(target);
|
|
187
|
-
i += 1;
|
|
188
|
-
}
|
|
189
|
-
// error.path 只有 chrome 实现,需要 polyfill
|
|
190
|
-
var path =
|
|
191
|
-
// @ts-ignore
|
|
192
|
-
typeof event.path === 'undefined'
|
|
193
|
-
? getPath(event.target)
|
|
194
|
-
: // @ts-ignore
|
|
195
|
-
event.path;
|
|
196
|
-
var outerHTML = immutableTarget.outerHTML;
|
|
197
|
-
return path
|
|
198
|
-
.reverse()
|
|
199
|
-
.map(function (node) {
|
|
200
|
-
return (node.localName || '') +
|
|
201
|
-
(node.id ? "#" + node.id : '') +
|
|
202
|
-
(node.className ? "." + node.className : '') +
|
|
203
|
-
(node.outerHTML === outerHTML ? ":nth-child(" + elements.length + ")" : '');
|
|
204
|
-
})
|
|
205
|
-
.filter(function (v) { return Boolean(v); })
|
|
206
|
-
.join(' > ');
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
exports.error = error;
|
|
210
|
-
exports.getGlobal = getGlobal;
|
|
211
|
-
exports.getOhbugObject = getOhbugObject;
|
|
212
|
-
exports.getSelector = getSelector;
|
|
213
|
-
exports.isBrowser = isBrowser;
|
|
214
|
-
exports.isFunction = isFunction;
|
|
215
|
-
exports.isNode = isNode;
|
|
216
|
-
exports.isNumber = isNumber;
|
|
217
|
-
exports.isObject = isObject;
|
|
218
|
-
exports.isPromise = isPromise;
|
|
219
|
-
exports.isString = isString;
|
|
220
|
-
exports.logger = logger;
|
|
221
|
-
exports.parseUrl = parseUrl;
|
|
222
|
-
exports.replace = replace;
|
|
223
|
-
exports.warning = warning;
|
package/dist/ohbug-utils.esm.js
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
|
|
16
|
-
function __spreadArray(to, from) {
|
|
17
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
18
|
-
to[j] = from[i];
|
|
19
|
-
return to;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
var prefix = 'Ohbug';
|
|
23
|
-
var logger = {
|
|
24
|
-
log: function () {
|
|
25
|
-
var args = [];
|
|
26
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
27
|
-
args[_i] = arguments[_i];
|
|
28
|
-
}
|
|
29
|
-
// eslint-disable-next-line no-console
|
|
30
|
-
console.log.apply(console, __spreadArray([prefix], args));
|
|
31
|
-
},
|
|
32
|
-
info: function () {
|
|
33
|
-
var args = [];
|
|
34
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
35
|
-
args[_i] = arguments[_i];
|
|
36
|
-
}
|
|
37
|
-
// eslint-disable-next-line no-console
|
|
38
|
-
console.info.apply(console, __spreadArray([prefix], args));
|
|
39
|
-
},
|
|
40
|
-
warn: function () {
|
|
41
|
-
var args = [];
|
|
42
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
43
|
-
args[_i] = arguments[_i];
|
|
44
|
-
}
|
|
45
|
-
console.warn.apply(console, __spreadArray([prefix], args));
|
|
46
|
-
},
|
|
47
|
-
error: function () {
|
|
48
|
-
var args = [];
|
|
49
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
50
|
-
args[_i] = arguments[_i];
|
|
51
|
-
}
|
|
52
|
-
console.error.apply(console, __spreadArray([prefix], args));
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
function error(condition, format) {
|
|
57
|
-
var args = [];
|
|
58
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
59
|
-
args[_i - 2] = arguments[_i];
|
|
60
|
-
}
|
|
61
|
-
if (format === undefined) {
|
|
62
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
63
|
-
}
|
|
64
|
-
if (!condition) {
|
|
65
|
-
var argIndex_1 = 0;
|
|
66
|
-
// eslint-disable-next-line no-plusplus
|
|
67
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_1++]; });
|
|
68
|
-
throw new Error("Ohbug " + message);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function warning(condition, format) {
|
|
72
|
-
var args = [];
|
|
73
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
74
|
-
args[_i - 2] = arguments[_i];
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
78
|
-
if (format === undefined) {
|
|
79
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
80
|
-
}
|
|
81
|
-
if (!condition) {
|
|
82
|
-
var argIndex_2 = 0;
|
|
83
|
-
// eslint-disable-next-line no-plusplus
|
|
84
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_2++]; });
|
|
85
|
-
logger.warn(message);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// eslint-disable-next-line no-empty
|
|
89
|
-
}
|
|
90
|
-
catch (e) { }
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function isString(value) {
|
|
94
|
-
return typeof value === 'string';
|
|
95
|
-
}
|
|
96
|
-
function isNumber(value) {
|
|
97
|
-
return typeof value === 'number' && parseInt("" + value, 10) === value;
|
|
98
|
-
}
|
|
99
|
-
function isFunction(value) {
|
|
100
|
-
return typeof value === 'function';
|
|
101
|
-
}
|
|
102
|
-
function isObject(value) {
|
|
103
|
-
return Object.prototype.toString.call(value) === '[object Object]';
|
|
104
|
-
}
|
|
105
|
-
function isPromise(value) {
|
|
106
|
-
return value instanceof Promise;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
var fallbackGlobalObject = {};
|
|
110
|
-
function getGlobal() {
|
|
111
|
-
return (typeof window !== 'undefined'
|
|
112
|
-
? window
|
|
113
|
-
: typeof global !== 'undefined'
|
|
114
|
-
? global
|
|
115
|
-
: typeof self !== 'undefined'
|
|
116
|
-
? self
|
|
117
|
-
: fallbackGlobalObject);
|
|
118
|
-
}
|
|
119
|
-
function getOhbugObject() {
|
|
120
|
-
var global = getGlobal();
|
|
121
|
-
error(Boolean(global.__OHBUG__), 'Failed to get `OhbugObject`, please confirm if `Ohbug.init`');
|
|
122
|
-
return global.__OHBUG__;
|
|
123
|
-
}
|
|
124
|
-
function isNode() {
|
|
125
|
-
return typeof global !== 'undefined';
|
|
126
|
-
}
|
|
127
|
-
function isBrowser() {
|
|
128
|
-
return typeof window !== 'undefined';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function replace(source, name, behavior) {
|
|
132
|
-
if (!(name in source)) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
var original = source[name];
|
|
136
|
-
var wrapped = behavior(original);
|
|
137
|
-
// eslint-disable-next-line no-param-reassign
|
|
138
|
-
source[name] = wrapped;
|
|
139
|
-
return original;
|
|
140
|
-
}
|
|
141
|
-
function parseUrl(url) {
|
|
142
|
-
if (typeof url !== 'string') {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
// eslint-disable-next-line
|
|
146
|
-
var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
|
|
147
|
-
if (!match) {
|
|
148
|
-
return {};
|
|
149
|
-
}
|
|
150
|
-
var query = match[6] || '';
|
|
151
|
-
var fragment = match[8] || '';
|
|
152
|
-
return {
|
|
153
|
-
host: match[4],
|
|
154
|
-
path: match[5],
|
|
155
|
-
protocol: match[2],
|
|
156
|
-
relative: match[5] + query + fragment,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function getParentNode(node, path) {
|
|
161
|
-
if (node.parentNode) {
|
|
162
|
-
path.push(node.parentNode);
|
|
163
|
-
getParentNode(node.parentNode, path);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
function getPath(node) {
|
|
167
|
-
var path = [];
|
|
168
|
-
path.push(node);
|
|
169
|
-
getParentNode(node, path);
|
|
170
|
-
return path;
|
|
171
|
-
}
|
|
172
|
-
var getSelector = function (event) {
|
|
173
|
-
var immutableTarget = (event.target || event.srcElement);
|
|
174
|
-
var target = (event.target || event.srcElement);
|
|
175
|
-
// 获取出错元素在同级元素的 index
|
|
176
|
-
// 储存错误元素前元素
|
|
177
|
-
var elements = [];
|
|
178
|
-
for (var i = 0; target &&
|
|
179
|
-
target.nodeType === Node.ELEMENT_NODE &&
|
|
180
|
-
target.nodeType !== Node.DOCUMENT_TYPE_NODE; target = target.previousSibling) {
|
|
181
|
-
if (i)
|
|
182
|
-
elements.push(target);
|
|
183
|
-
i += 1;
|
|
184
|
-
}
|
|
185
|
-
// error.path 只有 chrome 实现,需要 polyfill
|
|
186
|
-
var path =
|
|
187
|
-
// @ts-ignore
|
|
188
|
-
typeof event.path === 'undefined'
|
|
189
|
-
? getPath(event.target)
|
|
190
|
-
: // @ts-ignore
|
|
191
|
-
event.path;
|
|
192
|
-
var outerHTML = immutableTarget.outerHTML;
|
|
193
|
-
return path
|
|
194
|
-
.reverse()
|
|
195
|
-
.map(function (node) {
|
|
196
|
-
return (node.localName || '') +
|
|
197
|
-
(node.id ? "#" + node.id : '') +
|
|
198
|
-
(node.className ? "." + node.className : '') +
|
|
199
|
-
(node.outerHTML === outerHTML ? ":nth-child(" + elements.length + ")" : '');
|
|
200
|
-
})
|
|
201
|
-
.filter(function (v) { return Boolean(v); })
|
|
202
|
-
.join(' > ');
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export { error, getGlobal, getOhbugObject, getSelector, isBrowser, isFunction, isNode, isNumber, isObject, isPromise, isString, logger, parseUrl, replace, warning };
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*! *****************************************************************************
|
|
2
|
-
Copyright (c) Microsoft Corporation.
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
-
***************************************************************************** */
|
|
15
|
-
function n(n,r){for(var e=0,o=r.length,t=n.length;e<o;e++,t++)n[t]=r[e];return n}var r={log:function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];console.log.apply(console,n(["Ohbug"],r))},info:function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];console.info.apply(console,n(["Ohbug"],r))},warn:function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];console.warn.apply(console,n(["Ohbug"],r))},error:function(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];console.error.apply(console,n(["Ohbug"],r))}};function e(n,r){for(var e=[],o=2;o<arguments.length;o++)e[o-2]=arguments[o];if(void 0===r)throw new Error("`Ohbug warning(condition, format, ...args)` requires a warning message argument");if(!n){var t=0,i=r.replace(/%s/g,(function(){return e[t++]}));throw new Error("Ohbug "+i)}}function o(n,e){for(var o=[],t=2;t<arguments.length;t++)o[t-2]=arguments[t];try{if("production"!==process.env.NODE_ENV){if(void 0===e)throw new Error("`Ohbug warning(condition, format, ...args)` requires a warning message argument");if(!n){var i=0,u=e.replace(/%s/g,(function(){return o[i++]}));r.warn(u)}}}catch(n){}}function t(n){return"string"==typeof n}function i(n){return"number"==typeof n&&parseInt(""+n,10)===n}function u(n){return"function"==typeof n}function a(n){return"[object Object]"===Object.prototype.toString.call(n)}function f(n){return n instanceof Promise}var c={};function l(){return"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:c}function g(){var n=l();return e(Boolean(n.__OHBUG__),"Failed to get `OhbugObject`, please confirm if `Ohbug.init`"),n.__OHBUG__}function p(){return"undefined"!=typeof global}function s(){return"undefined"!=typeof window}function h(n,r,e){if(r in n){var o=n[r],t=e(o);return n[r]=t,o}}function d(n){if("string"!=typeof n)return{};var r=n.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!r)return{};var e=r[6]||"",o=r[8]||"";return{host:r[4],path:r[5],protocol:r[2],relative:r[5]+e+o}}function v(n,r){n.parentNode&&(r.push(n.parentNode),v(n.parentNode,r))}function w(n){var r=[];return r.push(n),v(n,r),r}var b=function(n){for(var r=n.target||n.srcElement,e=n.target||n.srcElement,o=[],t=0;e&&e.nodeType===Node.ELEMENT_NODE&&e.nodeType!==Node.DOCUMENT_TYPE_NODE;e=e.previousSibling)t&&o.push(e),t+=1;var i=void 0===n.path?w(n.target):n.path,u=r.outerHTML;return i.reverse().map((function(n){return(n.localName||"")+(n.id?"#"+n.id:"")+(n.className?"."+n.className:"")+(n.outerHTML===u?":nth-child("+o.length+")":"")})).filter((function(n){return Boolean(n)})).join(" > ")};export{e as error,l as getGlobal,g as getOhbugObject,b as getSelector,s as isBrowser,u as isFunction,p as isNode,i as isNumber,a as isObject,f as isPromise,t as isString,r as logger,d as parseUrl,h as replace,o as warning};
|
package/dist/ohbug-utils.umd.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.OhbugUtils = {}));
|
|
5
|
-
}(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/*! *****************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
|
|
22
|
-
function __spreadArray(to, from) {
|
|
23
|
-
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
|
|
24
|
-
to[j] = from[i];
|
|
25
|
-
return to;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var prefix = 'Ohbug';
|
|
29
|
-
var logger = {
|
|
30
|
-
log: function () {
|
|
31
|
-
var args = [];
|
|
32
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
33
|
-
args[_i] = arguments[_i];
|
|
34
|
-
}
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
console.log.apply(console, __spreadArray([prefix], args));
|
|
37
|
-
},
|
|
38
|
-
info: function () {
|
|
39
|
-
var args = [];
|
|
40
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
41
|
-
args[_i] = arguments[_i];
|
|
42
|
-
}
|
|
43
|
-
// eslint-disable-next-line no-console
|
|
44
|
-
console.info.apply(console, __spreadArray([prefix], args));
|
|
45
|
-
},
|
|
46
|
-
warn: function () {
|
|
47
|
-
var args = [];
|
|
48
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
49
|
-
args[_i] = arguments[_i];
|
|
50
|
-
}
|
|
51
|
-
console.warn.apply(console, __spreadArray([prefix], args));
|
|
52
|
-
},
|
|
53
|
-
error: function () {
|
|
54
|
-
var args = [];
|
|
55
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
56
|
-
args[_i] = arguments[_i];
|
|
57
|
-
}
|
|
58
|
-
console.error.apply(console, __spreadArray([prefix], args));
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
function error(condition, format) {
|
|
63
|
-
var args = [];
|
|
64
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
65
|
-
args[_i - 2] = arguments[_i];
|
|
66
|
-
}
|
|
67
|
-
if (format === undefined) {
|
|
68
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
69
|
-
}
|
|
70
|
-
if (!condition) {
|
|
71
|
-
var argIndex_1 = 0;
|
|
72
|
-
// eslint-disable-next-line no-plusplus
|
|
73
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_1++]; });
|
|
74
|
-
throw new Error("Ohbug " + message);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function warning(condition, format) {
|
|
78
|
-
var args = [];
|
|
79
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
80
|
-
args[_i - 2] = arguments[_i];
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
84
|
-
if (format === undefined) {
|
|
85
|
-
throw new Error('`Ohbug warning(condition, format, ...args)` requires a warning message argument');
|
|
86
|
-
}
|
|
87
|
-
if (!condition) {
|
|
88
|
-
var argIndex_2 = 0;
|
|
89
|
-
// eslint-disable-next-line no-plusplus
|
|
90
|
-
var message = format.replace(/%s/g, function () { return args[argIndex_2++]; });
|
|
91
|
-
logger.warn(message);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
// eslint-disable-next-line no-empty
|
|
95
|
-
}
|
|
96
|
-
catch (e) { }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function isString(value) {
|
|
100
|
-
return typeof value === 'string';
|
|
101
|
-
}
|
|
102
|
-
function isNumber(value) {
|
|
103
|
-
return typeof value === 'number' && parseInt("" + value, 10) === value;
|
|
104
|
-
}
|
|
105
|
-
function isFunction(value) {
|
|
106
|
-
return typeof value === 'function';
|
|
107
|
-
}
|
|
108
|
-
function isObject(value) {
|
|
109
|
-
return Object.prototype.toString.call(value) === '[object Object]';
|
|
110
|
-
}
|
|
111
|
-
function isPromise(value) {
|
|
112
|
-
return value instanceof Promise;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
var fallbackGlobalObject = {};
|
|
116
|
-
function getGlobal() {
|
|
117
|
-
return (typeof window !== 'undefined'
|
|
118
|
-
? window
|
|
119
|
-
: typeof global !== 'undefined'
|
|
120
|
-
? global
|
|
121
|
-
: typeof self !== 'undefined'
|
|
122
|
-
? self
|
|
123
|
-
: fallbackGlobalObject);
|
|
124
|
-
}
|
|
125
|
-
function getOhbugObject() {
|
|
126
|
-
var global = getGlobal();
|
|
127
|
-
error(Boolean(global.__OHBUG__), 'Failed to get `OhbugObject`, please confirm if `Ohbug.init`');
|
|
128
|
-
return global.__OHBUG__;
|
|
129
|
-
}
|
|
130
|
-
function isNode() {
|
|
131
|
-
return typeof global !== 'undefined';
|
|
132
|
-
}
|
|
133
|
-
function isBrowser() {
|
|
134
|
-
return typeof window !== 'undefined';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function replace(source, name, behavior) {
|
|
138
|
-
if (!(name in source)) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
var original = source[name];
|
|
142
|
-
var wrapped = behavior(original);
|
|
143
|
-
// eslint-disable-next-line no-param-reassign
|
|
144
|
-
source[name] = wrapped;
|
|
145
|
-
return original;
|
|
146
|
-
}
|
|
147
|
-
function parseUrl(url) {
|
|
148
|
-
if (typeof url !== 'string') {
|
|
149
|
-
return {};
|
|
150
|
-
}
|
|
151
|
-
// eslint-disable-next-line
|
|
152
|
-
var match = url.match(/^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);
|
|
153
|
-
if (!match) {
|
|
154
|
-
return {};
|
|
155
|
-
}
|
|
156
|
-
var query = match[6] || '';
|
|
157
|
-
var fragment = match[8] || '';
|
|
158
|
-
return {
|
|
159
|
-
host: match[4],
|
|
160
|
-
path: match[5],
|
|
161
|
-
protocol: match[2],
|
|
162
|
-
relative: match[5] + query + fragment,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function getParentNode(node, path) {
|
|
167
|
-
if (node.parentNode) {
|
|
168
|
-
path.push(node.parentNode);
|
|
169
|
-
getParentNode(node.parentNode, path);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function getPath(node) {
|
|
173
|
-
var path = [];
|
|
174
|
-
path.push(node);
|
|
175
|
-
getParentNode(node, path);
|
|
176
|
-
return path;
|
|
177
|
-
}
|
|
178
|
-
var getSelector = function (event) {
|
|
179
|
-
var immutableTarget = (event.target || event.srcElement);
|
|
180
|
-
var target = (event.target || event.srcElement);
|
|
181
|
-
// 获取出错元素在同级元素的 index
|
|
182
|
-
// 储存错误元素前元素
|
|
183
|
-
var elements = [];
|
|
184
|
-
for (var i = 0; target &&
|
|
185
|
-
target.nodeType === Node.ELEMENT_NODE &&
|
|
186
|
-
target.nodeType !== Node.DOCUMENT_TYPE_NODE; target = target.previousSibling) {
|
|
187
|
-
if (i)
|
|
188
|
-
elements.push(target);
|
|
189
|
-
i += 1;
|
|
190
|
-
}
|
|
191
|
-
// error.path 只有 chrome 实现,需要 polyfill
|
|
192
|
-
var path =
|
|
193
|
-
// @ts-ignore
|
|
194
|
-
typeof event.path === 'undefined'
|
|
195
|
-
? getPath(event.target)
|
|
196
|
-
: // @ts-ignore
|
|
197
|
-
event.path;
|
|
198
|
-
var outerHTML = immutableTarget.outerHTML;
|
|
199
|
-
return path
|
|
200
|
-
.reverse()
|
|
201
|
-
.map(function (node) {
|
|
202
|
-
return (node.localName || '') +
|
|
203
|
-
(node.id ? "#" + node.id : '') +
|
|
204
|
-
(node.className ? "." + node.className : '') +
|
|
205
|
-
(node.outerHTML === outerHTML ? ":nth-child(" + elements.length + ")" : '');
|
|
206
|
-
})
|
|
207
|
-
.filter(function (v) { return Boolean(v); })
|
|
208
|
-
.join(' > ');
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
exports.error = error;
|
|
212
|
-
exports.getGlobal = getGlobal;
|
|
213
|
-
exports.getOhbugObject = getOhbugObject;
|
|
214
|
-
exports.getSelector = getSelector;
|
|
215
|
-
exports.isBrowser = isBrowser;
|
|
216
|
-
exports.isFunction = isFunction;
|
|
217
|
-
exports.isNode = isNode;
|
|
218
|
-
exports.isNumber = isNumber;
|
|
219
|
-
exports.isObject = isObject;
|
|
220
|
-
exports.isPromise = isPromise;
|
|
221
|
-
exports.isString = isString;
|
|
222
|
-
exports.logger = logger;
|
|
223
|
-
exports.parseUrl = parseUrl;
|
|
224
|
-
exports.replace = replace;
|
|
225
|
-
exports.warning = warning;
|
|
226
|
-
|
|
227
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
228
|
-
|
|
229
|
-
})));
|