@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 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
- * @summary Copies text to browser clipboard.
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
- * This function first attempts to use the modern, asynchronous Clipboard API (`window.navigator.clipboard.writeText`).
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
- try {
112
- return "ontouchstart" in window.document.documentElement;
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
- result = result.catch(getAltValCb(fallbackValue));
202
+ asPromise = true;
203
+ return result.catch((err) => getAltValCb(err, fallbackValue));
205
204
  } catch (error) {
206
- result = getAltValCb(fallbackValue)(error);
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) => (error) => isFn(fallbackValue) ? fallbackValue(error) : 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
- () => fallbackIfFails(
787
- () => {
788
- const el = document.createElement("textarea");
789
- el.value = str;
790
- el.setAttribute("readonly", "");
791
- el.style.position = "absolute";
792
- el.style.left = "-9999px";
793
- document.body.appendChild(el);
794
- el.select();
795
- const result = document.execCommand("copy");
796
- document.body.removeChild(el);
797
- return Promise.resolve(result ? 2 : 0);
798
- },
799
- [],
800
- () => Promise.resolve(0)
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
@@ -41,5 +41,5 @@
41
41
  "sideEffects": false,
42
42
  "type": "module",
43
43
  "types": "dist/index.d.ts",
44
- "version": "1.0.3"
44
+ "version": "1.0.4"
45
45
  }