|
1 |
| -export const noop = () => { }; |
| 1 | +export const noop = () => {}; |
2 | 2 |
|
3 | 3 | export const objectToString = Object.prototype.toString;
|
4 | 4 |
|
@@ -113,11 +113,11 @@ export function error(error: string | Error) {
|
113 | 113 | export function validURL(str) {
|
114 | 114 | const pattern = new RegExp(
|
115 | 115 | '^(https?:\\/\\/)?' + // protocol
|
116 |
| - '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name |
117 |
| - '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address |
118 |
| - '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path |
119 |
| - '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string |
120 |
| - '(\\#[-a-z\\d_]*)?$', |
| 116 | + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name |
| 117 | + '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address |
| 118 | + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path |
| 119 | + '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string |
| 120 | + '(\\#[-a-z\\d_]*)?$', |
121 | 121 | 'i',
|
122 | 122 | ); // fragment locator
|
123 | 123 | return !!pattern.test(str);
|
@@ -164,7 +164,10 @@ export function evalWithEnv(
|
164 | 164 | }
|
165 | 165 | }
|
166 | 166 |
|
167 |
| -export function safeWrapper(callback: (...args: Array<any>) => any, disableWarn?: boolean) { |
| 167 | +export function safeWrapper( |
| 168 | + callback: (...args: Array<any>) => any, |
| 169 | + disableWarn?: boolean, |
| 170 | +) { |
168 | 171 | try {
|
169 | 172 | callback();
|
170 | 173 | } catch (e) {
|
@@ -407,9 +410,10 @@ export function setDocCurrentScript(
|
407 | 410 | el.textContent = code;
|
408 | 411 | }
|
409 | 412 |
|
410 |
| - originScript && originScript.getAttributeNames().forEach((attribute) => { |
411 |
| - el.setAttribute(attribute, originScript.getAttribute(attribute) || ''); |
412 |
| - }); |
| 413 | + originScript && |
| 414 | + originScript.getAttributeNames().forEach((attribute) => { |
| 415 | + el.setAttribute(attribute, originScript.getAttribute(attribute) || ''); |
| 416 | + }); |
413 | 417 |
|
414 | 418 | if (async) {
|
415 | 419 | el.setAttribute('async', 'true');
|
@@ -583,3 +587,9 @@ export function getSourceURL(url: string | URL | Request): string {
|
583 | 587 | if (url instanceof Request) return url.url;
|
584 | 588 | return url.startsWith('/') ? `${location.origin}${url}` : url;
|
585 | 589 | }
|
| 590 | + |
| 591 | +export function macroTask<T extends any>(value: T) { |
| 592 | + return new Promise<T>((resolve) => { |
| 593 | + setTimeout(() => resolve(value)); |
| 594 | + }); |
| 595 | +} |
0 commit comments