@superutils/core 1.0.1 → 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/README.md +10 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +27 -26
- package/package.json +4 -6
package/README.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
A collection of lightweight, dependency-free utility functions and types.
|
|
4
4
|
|
|
5
|
+
<div v-if="false">
|
|
6
|
+
|
|
7
|
+
For full API reference check out the [docs page](https://alien45.github.io/superutils/packages/@superutils/core/).
|
|
8
|
+
|
|
9
|
+
</div>
|
|
10
|
+
|
|
5
11
|
## Table of Contents
|
|
6
12
|
|
|
7
13
|
- [Installation](#installation)
|
|
@@ -9,8 +15,8 @@ A collection of lightweight, dependency-free utility functions and types.
|
|
|
9
15
|
- [`is`](#is): Type checkers
|
|
10
16
|
- [`deferred()`](#deferred): Debounce callbacks
|
|
11
17
|
- [`throttle()`](#throttle): Throttle callbacks
|
|
12
|
-
- [`fallbackIfFails()`](#
|
|
13
|
-
- [`objCopy()`](#
|
|
18
|
+
- [`fallbackIfFails()`](#fallback-if-fails): Gracefully invoke functions
|
|
19
|
+
- [`objCopy()`](#obj-copy): Deep-copy objects
|
|
14
20
|
- [`search()`](#search): Search iterable collections
|
|
15
21
|
|
|
16
22
|
## Installation
|
|
@@ -102,7 +108,7 @@ handleChange({ target: { value 2 } }) // will be ignored
|
|
|
102
108
|
handleChange({ target: { value 3 } }) // will be ignored
|
|
103
109
|
```
|
|
104
110
|
|
|
105
|
-
<div id="
|
|
111
|
+
<div id="fallback-if-fails"></div>
|
|
106
112
|
|
|
107
113
|
### `fallbackIfFails(fn, args, fallback)`: gracefully invoke functions
|
|
108
114
|
|
|
@@ -145,7 +151,7 @@ fallbackIfFails(
|
|
|
145
151
|
// Prints the result when request is successful or fallback value when request fails
|
|
146
152
|
```
|
|
147
153
|
|
|
148
|
-
<div id="
|
|
154
|
+
<div id="obj-copy"></div>
|
|
149
155
|
|
|
150
156
|
### `objCopy(source, dest, ignoreKeys, override)`: deep-copy objects
|
|
151
157
|
|
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
|
@@ -3,14 +3,13 @@
|
|
|
3
3
|
"bugs": {
|
|
4
4
|
"url": "https://github.com/alien45/superutils/issues"
|
|
5
5
|
},
|
|
6
|
-
"description": "
|
|
7
|
-
"devDependencies": {},
|
|
6
|
+
"description": "A collection of lightweight, dependency-free utility functions and types for Javascript/Typescript",
|
|
8
7
|
"files": [
|
|
9
8
|
"dist",
|
|
10
9
|
"README.md",
|
|
11
10
|
"LICENSE"
|
|
12
11
|
],
|
|
13
|
-
"homepage": "https://github.
|
|
12
|
+
"homepage": "https://alien45.github.io/superutils/packages/@superutils/core/",
|
|
14
13
|
"keywords": [
|
|
15
14
|
"javascript",
|
|
16
15
|
"rxjs",
|
|
@@ -25,7 +24,6 @@
|
|
|
25
24
|
"license": "MIT",
|
|
26
25
|
"main": "dist/index.js",
|
|
27
26
|
"name": "@superutils/core",
|
|
28
|
-
"peerDependencies": {},
|
|
29
27
|
"publishConfig": {
|
|
30
28
|
"access": "public"
|
|
31
29
|
},
|
|
@@ -38,10 +36,10 @@
|
|
|
38
36
|
"_watch": "tsc -p tsconfig.json --watch",
|
|
39
37
|
"build": "tsup src/index.ts --format esm --dts --clean --config ../../tsup.config.js",
|
|
40
38
|
"dev": "npm run build -- --watch",
|
|
41
|
-
"test": "
|
|
39
|
+
"test": "cd ../../ && npm run test promise"
|
|
42
40
|
},
|
|
43
41
|
"sideEffects": false,
|
|
44
42
|
"type": "module",
|
|
45
43
|
"types": "dist/index.d.ts",
|
|
46
|
-
"version": "1.0.
|
|
44
|
+
"version": "1.0.4"
|
|
47
45
|
}
|