@superutils/core 1.0.3 → 1.0.4
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/index.d.ts +4 -2
- package/dist/index.js +27 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1282,12 +1282,14 @@ declare const randomInt: (min?: number, max?: number) => number;
|
|
|
1282
1282
|
declare const clearClutter: (text: string, lineSeparator?: string) => string;
|
|
1283
1283
|
|
|
1284
1284
|
/**
|
|
1285
|
-
*
|
|
1285
|
+
* Copies text to browser clipboard.
|
|
1286
1286
|
*
|
|
1287
1287
|
* CAUTION:
|
|
1288
1288
|
* Based on browser security policy it may be required to invoke `copyToClipboard` from an user-generated event handler.
|
|
1289
1289
|
*
|
|
1290
|
-
*
|
|
1290
|
+
* Invoking from non-browser environment will already resolve with `0`.
|
|
1291
|
+
*
|
|
1292
|
+
* This function first attempts to use the modern, asynchronous Clipboard API (`navigator.clipboard.writeText`).
|
|
1291
1293
|
* If that fails or is unavailable, it falls back to the legacy `document.execCommand('copy')` method.
|
|
1292
1294
|
*
|
|
1293
1295
|
*
|
package/dist/index.js
CHANGED
|
@@ -102,17 +102,14 @@ var isEmptySafe = (x, numberableOnly = false) => {
|
|
|
102
102
|
var isEmpty_default = isEmpty;
|
|
103
103
|
|
|
104
104
|
// src/is/isEnv.ts
|
|
105
|
-
var isEnvBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
105
|
+
var isEnvBrowser = () => typeof window !== "undefined" && typeof (window == null ? void 0 : window.document) !== "undefined";
|
|
106
106
|
var isEnvNode = () => {
|
|
107
107
|
var _a;
|
|
108
108
|
return typeof process !== "undefined" && ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) != null;
|
|
109
109
|
};
|
|
110
110
|
var isEnvTouchable = () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
} catch (_) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
111
|
+
var _a, _b;
|
|
112
|
+
return typeof window !== "undefined" && "ontouchstart" in ((_b = (_a = window == null ? void 0 : window.document) == null ? void 0 : _a.documentElement) != null ? _b : {});
|
|
116
113
|
};
|
|
117
114
|
|
|
118
115
|
// src/noop.ts
|
|
@@ -198,17 +195,19 @@ var is = {
|
|
|
198
195
|
// src/fallbackIfFails.ts
|
|
199
196
|
var fallbackIfFails = (target, args, fallbackValue) => {
|
|
200
197
|
let result;
|
|
198
|
+
let asPromise = false;
|
|
201
199
|
try {
|
|
202
200
|
result = !isFn(target) ? target : target(...isFn(args) ? args() : args);
|
|
203
201
|
if (!isPromise(result)) return result;
|
|
204
|
-
|
|
202
|
+
asPromise = true;
|
|
203
|
+
return result.catch((err) => getAltValCb(err, fallbackValue));
|
|
205
204
|
} catch (error) {
|
|
206
|
-
result = getAltValCb(fallbackValue)
|
|
205
|
+
result = getAltValCb(error, fallbackValue);
|
|
206
|
+
return asPromise && !isPromise(result) ? Promise.resolve(result) : result;
|
|
207
207
|
}
|
|
208
|
-
return result;
|
|
209
208
|
};
|
|
210
209
|
var fallbackIfFails_default = fallbackIfFails;
|
|
211
|
-
var getAltValCb = (fallbackValue) =>
|
|
210
|
+
var getAltValCb = (error, fallbackValue) => isFn(fallbackValue) ? fallbackValue(error) : fallbackValue;
|
|
212
211
|
|
|
213
212
|
// src/deferred.ts
|
|
214
213
|
var deferred = (callback, delay = 50, config = {}) => {
|
|
@@ -783,22 +782,24 @@ var copyToClipboard = (str) => fallbackIfFails(
|
|
|
783
782
|
() => navigator.clipboard.writeText(str).then(() => 1),
|
|
784
783
|
[],
|
|
785
784
|
// If clipboard API is not available or fails, use the fallback method
|
|
786
|
-
() =>
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
785
|
+
() => Promise.resolve(copyLegacy(str))
|
|
786
|
+
);
|
|
787
|
+
var copyLegacy = (str) => fallbackIfFails(
|
|
788
|
+
() => {
|
|
789
|
+
const el = document.createElement("textarea");
|
|
790
|
+
el.value = str;
|
|
791
|
+
el.setAttribute("readonly", "");
|
|
792
|
+
el.style.position = "absolute";
|
|
793
|
+
el.style.left = "-9999px";
|
|
794
|
+
document.body.appendChild(el);
|
|
795
|
+
el.select();
|
|
796
|
+
const success = document.execCommand("copy");
|
|
797
|
+
document.body.removeChild(el);
|
|
798
|
+
return success ? 2 : 0;
|
|
799
|
+
},
|
|
800
|
+
[],
|
|
801
|
+
0
|
|
802
|
+
// On error, resolve with 0
|
|
802
803
|
);
|
|
803
804
|
|
|
804
805
|
// src/str/getUrlParam.ts
|
package/package.json
CHANGED