@hairy/utils 1.30.0 → 1.31.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/dist/index.cjs +97 -2
- package/dist/index.d.ts +111 -60
- package/dist/index.global.js +77 -2
- package/dist/index.js +87 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -49,7 +49,10 @@ __export(index_exports, {
|
|
|
49
49
|
debounce: () => debounce_default,
|
|
50
50
|
decimal: () => decimal,
|
|
51
51
|
delay: () => delay,
|
|
52
|
+
dialsPhone: () => dialsPhone,
|
|
52
53
|
dotCase: () => dotCase,
|
|
54
|
+
downloadBlobFile: () => downloadBlobFile,
|
|
55
|
+
downloadNetworkFile: () => downloadNetworkFile,
|
|
53
56
|
find: () => find_default,
|
|
54
57
|
formToObject: () => formToObject,
|
|
55
58
|
formatNumeric: () => formatNumeric,
|
|
@@ -104,6 +107,8 @@ __export(index_exports, {
|
|
|
104
107
|
noop: () => noop2,
|
|
105
108
|
numerfix: () => numerfix,
|
|
106
109
|
objectToForm: () => objectToForm,
|
|
110
|
+
off: () => off,
|
|
111
|
+
on: () => on,
|
|
107
112
|
parseNumeric: () => parseNumeric,
|
|
108
113
|
pascalCase: () => pascalCase,
|
|
109
114
|
pascalSnakeCase: () => pascalSnakeCase,
|
|
@@ -114,8 +119,13 @@ __export(index_exports, {
|
|
|
114
119
|
proxy: () => proxy,
|
|
115
120
|
randomArray: () => randomArray,
|
|
116
121
|
randomNumer: () => randomNumer,
|
|
122
|
+
readFileReader: () => readFileReader,
|
|
123
|
+
redirectTo: () => redirectTo,
|
|
117
124
|
riposte: () => riposte,
|
|
125
|
+
selectImages: () => selectImages,
|
|
118
126
|
sentenceCase: () => sentenceCase,
|
|
127
|
+
showOpenFilePicker: () => showOpenFilePicker,
|
|
128
|
+
showOpenImagePicker: () => showOpenImagePicker,
|
|
119
129
|
snakeCase: () => snakeCase,
|
|
120
130
|
to: () => to,
|
|
121
131
|
trainCase: () => trainCase,
|
|
@@ -131,6 +141,81 @@ __export(index_exports, {
|
|
|
131
141
|
});
|
|
132
142
|
module.exports = __toCommonJS(index_exports);
|
|
133
143
|
|
|
144
|
+
// src/browser/file.ts
|
|
145
|
+
function showOpenFilePicker(option = {}) {
|
|
146
|
+
const { multiple = true, accept } = option;
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
const inputElement = document.createElement("input");
|
|
149
|
+
inputElement.type = "file";
|
|
150
|
+
inputElement.multiple = multiple;
|
|
151
|
+
accept && (inputElement.accept = accept);
|
|
152
|
+
inputElement.click();
|
|
153
|
+
const timer = setTimeout(reject, 20 * 1e3);
|
|
154
|
+
inputElement.addEventListener("change", (event) => {
|
|
155
|
+
const files = event.target.files;
|
|
156
|
+
if (files) {
|
|
157
|
+
resolve(Object.values(files));
|
|
158
|
+
clearTimeout(timer);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function showOpenImagePicker(options = {}) {
|
|
164
|
+
const { multiple = true } = options;
|
|
165
|
+
return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
|
|
166
|
+
}
|
|
167
|
+
var selectImages = showOpenImagePicker;
|
|
168
|
+
function downloadBlobFile(data, name) {
|
|
169
|
+
const blob = new Blob([data]);
|
|
170
|
+
const link = document.createElement("a");
|
|
171
|
+
const url = window.URL.createObjectURL(blob);
|
|
172
|
+
link.href = url;
|
|
173
|
+
link.download = name;
|
|
174
|
+
link.click();
|
|
175
|
+
}
|
|
176
|
+
function downloadNetworkFile(url, name) {
|
|
177
|
+
const a = document.createElement("a");
|
|
178
|
+
name && (a.download = name);
|
|
179
|
+
a.href = url;
|
|
180
|
+
a.click();
|
|
181
|
+
}
|
|
182
|
+
function readFileReader(formType, file) {
|
|
183
|
+
return new Promise((resolve, reject) => {
|
|
184
|
+
if (typeof FileReader === "undefined") {
|
|
185
|
+
console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
|
|
186
|
+
reject();
|
|
187
|
+
}
|
|
188
|
+
const reader = new FileReader();
|
|
189
|
+
reader[formType](file);
|
|
190
|
+
reader.onloadend = function() {
|
|
191
|
+
isNull(this.result) ? reject() : resolve(this.result);
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/browser/util.ts
|
|
197
|
+
function redirectTo(url, target = "_blank") {
|
|
198
|
+
const link = document.createElement("a");
|
|
199
|
+
link.href = url;
|
|
200
|
+
link.target = target;
|
|
201
|
+
link.click();
|
|
202
|
+
link.remove();
|
|
203
|
+
}
|
|
204
|
+
function dialsPhone(phoneNumber) {
|
|
205
|
+
const aTag = document.createElement("a");
|
|
206
|
+
aTag.setAttribute("href", `tel:${phoneNumber}`);
|
|
207
|
+
aTag.setAttribute("target", "_blank");
|
|
208
|
+
aTag.click();
|
|
209
|
+
}
|
|
210
|
+
function on(obj, ...args) {
|
|
211
|
+
if (obj && obj.addEventListener)
|
|
212
|
+
obj.addEventListener(...args);
|
|
213
|
+
}
|
|
214
|
+
function off(obj, ...args) {
|
|
215
|
+
if (obj && obj.removeEventListener)
|
|
216
|
+
obj.removeEventListener(...args);
|
|
217
|
+
}
|
|
218
|
+
|
|
134
219
|
// ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
|
|
135
220
|
var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
136
221
|
var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
@@ -2808,10 +2893,10 @@ function isNative(value) {
|
|
|
2808
2893
|
var isNative_default = isNative;
|
|
2809
2894
|
|
|
2810
2895
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
|
|
2811
|
-
function
|
|
2896
|
+
function isNull2(value) {
|
|
2812
2897
|
return value === null;
|
|
2813
2898
|
}
|
|
2814
|
-
var isNull_default =
|
|
2899
|
+
var isNull_default = isNull2;
|
|
2815
2900
|
|
|
2816
2901
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
|
|
2817
2902
|
var regexpTag5 = "[object RegExp]";
|
|
@@ -3370,7 +3455,10 @@ function whenever(value, callback) {
|
|
|
3370
3455
|
debounce,
|
|
3371
3456
|
decimal,
|
|
3372
3457
|
delay,
|
|
3458
|
+
dialsPhone,
|
|
3373
3459
|
dotCase,
|
|
3460
|
+
downloadBlobFile,
|
|
3461
|
+
downloadNetworkFile,
|
|
3374
3462
|
find,
|
|
3375
3463
|
formToObject,
|
|
3376
3464
|
formatNumeric,
|
|
@@ -3425,6 +3513,8 @@ function whenever(value, callback) {
|
|
|
3425
3513
|
noop,
|
|
3426
3514
|
numerfix,
|
|
3427
3515
|
objectToForm,
|
|
3516
|
+
off,
|
|
3517
|
+
on,
|
|
3428
3518
|
parseNumeric,
|
|
3429
3519
|
pascalCase,
|
|
3430
3520
|
pascalSnakeCase,
|
|
@@ -3435,8 +3525,13 @@ function whenever(value, callback) {
|
|
|
3435
3525
|
proxy,
|
|
3436
3526
|
randomArray,
|
|
3437
3527
|
randomNumer,
|
|
3528
|
+
readFileReader,
|
|
3529
|
+
redirectTo,
|
|
3438
3530
|
riposte,
|
|
3531
|
+
selectImages,
|
|
3439
3532
|
sentenceCase,
|
|
3533
|
+
showOpenFilePicker,
|
|
3534
|
+
showOpenImagePicker,
|
|
3440
3535
|
snakeCase,
|
|
3441
3536
|
to,
|
|
3442
3537
|
trainCase,
|
package/dist/index.d.ts
CHANGED
|
@@ -2,77 +2,51 @@ export { clone, cloneDeep, cloneDeepWith, cloneWith, concat, debounce, find, isA
|
|
|
2
2
|
import Bignumber from 'bignumber.js';
|
|
3
3
|
export { default as Bignumber } from 'bignumber.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
mergeAmbiguousCharacters?: boolean;
|
|
5
|
+
interface OpenFilePickerOptions {
|
|
6
|
+
/**
|
|
7
|
+
* select multiple files
|
|
8
|
+
*/
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Choose the default format for the file
|
|
12
|
+
*/
|
|
13
|
+
accept?: string;
|
|
15
14
|
}
|
|
16
15
|
/**
|
|
17
|
-
*
|
|
16
|
+
* Select multiple files
|
|
18
17
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
prefixCharacters?: string;
|
|
26
|
-
suffixCharacters?: string;
|
|
18
|
+
declare function showOpenFilePicker(option?: OpenFilePickerOptions): Promise<File[]>;
|
|
19
|
+
interface OpenImagePickerOptions {
|
|
20
|
+
/**
|
|
21
|
+
* select multiple images
|
|
22
|
+
*/
|
|
23
|
+
multiple?: boolean;
|
|
27
24
|
}
|
|
28
25
|
/**
|
|
29
|
-
*
|
|
30
|
-
*/
|
|
31
|
-
declare function noCase(input: string, options?: Options): string;
|
|
32
|
-
/**
|
|
33
|
-
* Convert a string to camel case (`fooBar`).
|
|
34
|
-
*/
|
|
35
|
-
declare function camelCase(input: string, options?: PascalCaseOptions): string;
|
|
36
|
-
/**
|
|
37
|
-
* Convert a string to pascal case (`FooBar`).
|
|
38
|
-
*/
|
|
39
|
-
declare function pascalCase(input: string, options?: PascalCaseOptions): string;
|
|
40
|
-
/**
|
|
41
|
-
* Convert a string to pascal snake case (`Foo_Bar`).
|
|
42
|
-
*/
|
|
43
|
-
declare function pascalSnakeCase(input: string, options?: Options): string;
|
|
44
|
-
/**
|
|
45
|
-
* Convert a string to capital case (`Foo Bar`).
|
|
26
|
+
* Select multiple images
|
|
46
27
|
*/
|
|
47
|
-
declare function
|
|
28
|
+
declare function showOpenImagePicker(options?: OpenImagePickerOptions): Promise<File[]>;
|
|
29
|
+
/** @deprecated use chooseFile */
|
|
30
|
+
declare const selectImages: typeof showOpenImagePicker;
|
|
48
31
|
/**
|
|
49
|
-
*
|
|
32
|
+
* Generate Blob | string file and download it
|
|
33
|
+
* @param data Blob data, or string
|
|
34
|
+
* @param name file name
|
|
50
35
|
*/
|
|
51
|
-
declare function
|
|
36
|
+
declare function downloadBlobFile(data: Blob | string, name: string): void;
|
|
52
37
|
/**
|
|
53
|
-
*
|
|
38
|
+
* Download network files
|
|
39
|
+
* @param url Download link
|
|
40
|
+
* @param name file name
|
|
54
41
|
*/
|
|
55
|
-
declare function
|
|
42
|
+
declare function downloadNetworkFile(url: string, name?: string): void;
|
|
43
|
+
type ReaderType = 'readAsArrayBuffer' | 'readAsBinaryString' | 'readAsDataURL' | 'readAsText';
|
|
56
44
|
/**
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Convert a string to path case (`foo/bar`).
|
|
62
|
-
*/
|
|
63
|
-
declare function pathCase(input: string, options?: Options): string;
|
|
64
|
-
/**
|
|
65
|
-
* Convert a string to path case (`Foo bar`).
|
|
45
|
+
* Read File file
|
|
46
|
+
* @param formType Transform type
|
|
47
|
+
* @param file file object
|
|
66
48
|
*/
|
|
67
|
-
declare function
|
|
68
|
-
/**
|
|
69
|
-
* Convert a string to snake case (`foo_bar`).
|
|
70
|
-
*/
|
|
71
|
-
declare function snakeCase(input: string, options?: Options): string;
|
|
72
|
-
/**
|
|
73
|
-
* Convert a string to header case (`Foo-Bar`).
|
|
74
|
-
*/
|
|
75
|
-
declare function trainCase(input: string, options?: Options): string;
|
|
49
|
+
declare function readFileReader<T extends ReaderType>(formType: T, file: File): Promise<T extends "readAsArrayBuffer" ? ArrayBuffer : string>;
|
|
76
50
|
|
|
77
51
|
type Numeric = string | number | bigint;
|
|
78
52
|
interface DynamicObject {
|
|
@@ -135,6 +109,83 @@ type Option<L extends Key = 'label', V extends Key = 'value', C extends Key = 'c
|
|
|
135
109
|
[P in C]?: Option<L, V, C>[];
|
|
136
110
|
};
|
|
137
111
|
|
|
112
|
+
declare function redirectTo(url: string, target?: string): void;
|
|
113
|
+
declare function dialsPhone(phoneNumber: string): void;
|
|
114
|
+
declare function on<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['addEventListener']> | [string, Fn$1 | null, ...any]): void;
|
|
115
|
+
declare function off<T extends Window | Document | HTMLElement | EventTarget>(obj: T | null, ...args: Parameters<T['removeEventListener']> | [string, Fn$1 | null, ...any]): void;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Supported locale values. Use `false` to ignore locale.
|
|
119
|
+
* Defaults to `undefined`, which uses the host environment.
|
|
120
|
+
*/
|
|
121
|
+
type Locale = string[] | string | false | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Options used for converting strings to pascal/camel case.
|
|
124
|
+
*/
|
|
125
|
+
interface PascalCaseOptions extends Options {
|
|
126
|
+
mergeAmbiguousCharacters?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Options used for converting strings to any case.
|
|
130
|
+
*/
|
|
131
|
+
interface Options {
|
|
132
|
+
locale?: Locale;
|
|
133
|
+
split?: (value: string) => string[];
|
|
134
|
+
/** @deprecated Pass `split: splitSeparateNumbers` instead. */
|
|
135
|
+
separateNumbers?: boolean;
|
|
136
|
+
delimiter?: string;
|
|
137
|
+
prefixCharacters?: string;
|
|
138
|
+
suffixCharacters?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Convert a string to space separated lower case (`foo bar`).
|
|
142
|
+
*/
|
|
143
|
+
declare function noCase(input: string, options?: Options): string;
|
|
144
|
+
/**
|
|
145
|
+
* Convert a string to camel case (`fooBar`).
|
|
146
|
+
*/
|
|
147
|
+
declare function camelCase(input: string, options?: PascalCaseOptions): string;
|
|
148
|
+
/**
|
|
149
|
+
* Convert a string to pascal case (`FooBar`).
|
|
150
|
+
*/
|
|
151
|
+
declare function pascalCase(input: string, options?: PascalCaseOptions): string;
|
|
152
|
+
/**
|
|
153
|
+
* Convert a string to pascal snake case (`Foo_Bar`).
|
|
154
|
+
*/
|
|
155
|
+
declare function pascalSnakeCase(input: string, options?: Options): string;
|
|
156
|
+
/**
|
|
157
|
+
* Convert a string to capital case (`Foo Bar`).
|
|
158
|
+
*/
|
|
159
|
+
declare function capitalCase(input: string, options?: Options): string;
|
|
160
|
+
/**
|
|
161
|
+
* Convert a string to constant case (`FOO_BAR`).
|
|
162
|
+
*/
|
|
163
|
+
declare function constantCase(input: string, options?: Options): string;
|
|
164
|
+
/**
|
|
165
|
+
* Convert a string to dot case (`foo.bar`).
|
|
166
|
+
*/
|
|
167
|
+
declare function dotCase(input: string, options?: Options): string;
|
|
168
|
+
/**
|
|
169
|
+
* Convert a string to kebab case (`foo-bar`).
|
|
170
|
+
*/
|
|
171
|
+
declare function kebabCase(input: string, options?: Options): string;
|
|
172
|
+
/**
|
|
173
|
+
* Convert a string to path case (`foo/bar`).
|
|
174
|
+
*/
|
|
175
|
+
declare function pathCase(input: string, options?: Options): string;
|
|
176
|
+
/**
|
|
177
|
+
* Convert a string to path case (`Foo bar`).
|
|
178
|
+
*/
|
|
179
|
+
declare function sentenceCase(input: string, options?: Options): string;
|
|
180
|
+
/**
|
|
181
|
+
* Convert a string to snake case (`foo_bar`).
|
|
182
|
+
*/
|
|
183
|
+
declare function snakeCase(input: string, options?: Options): string;
|
|
184
|
+
/**
|
|
185
|
+
* Convert a string to header case (`Foo-Bar`).
|
|
186
|
+
*/
|
|
187
|
+
declare function trainCase(input: string, options?: Options): string;
|
|
188
|
+
|
|
138
189
|
declare const BIG_INTS: {
|
|
139
190
|
t: {
|
|
140
191
|
v: number;
|
|
@@ -477,4 +528,4 @@ declare function riposte<T>(...args: [cond: boolean, value: T][]): T;
|
|
|
477
528
|
declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
478
529
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
479
530
|
|
|
480
|
-
export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, BigNum, type BooleanLike, type ConstructorType, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type Option, type PromiseFn, type PromiseType, type Promisify, type StringObject, type SymbolObject, type Typeof, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dotCase, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumer, riposte, sentenceCase, snakeCase, to, trainCase, unwrap, whenever, zerofill, zeromove };
|
|
531
|
+
export { type AnyFn, type ArgumentsType, type Arrayable, type Awaitable, BIG_INTS, BigNum, type BooleanLike, type ConstructorType, type DecimalOptions, type DeepKeyof, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type PromiseFn, type PromiseType, type Promisify, type ReaderType, type StringObject, type SymbolObject, type Typeof, arange, average, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, dotCase, downloadBlobFile, downloadNetworkFile, formToObject, formatNumeric, formatSize, formatUnit, getTypeof, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isTypeof, isWeex, isWindow, jsonTryParse, kebabCase, loop, lt, lte, noCase, noop, numerfix, objectToForm, off, on, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomArray, randomNumer, readFileReader, redirectTo, riposte, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, snakeCase, to, trainCase, unwrap, whenever, zerofill, zeromove };
|
package/dist/index.global.js
CHANGED
|
@@ -1,5 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
+
// src/browser/file.ts
|
|
4
|
+
function showOpenFilePicker(option = {}) {
|
|
5
|
+
const { multiple = true, accept } = option;
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const inputElement = document.createElement("input");
|
|
8
|
+
inputElement.type = "file";
|
|
9
|
+
inputElement.multiple = multiple;
|
|
10
|
+
accept && (inputElement.accept = accept);
|
|
11
|
+
inputElement.click();
|
|
12
|
+
const timer = setTimeout(reject, 20 * 1e3);
|
|
13
|
+
inputElement.addEventListener("change", (event) => {
|
|
14
|
+
const files = event.target.files;
|
|
15
|
+
if (files) {
|
|
16
|
+
resolve(Object.values(files));
|
|
17
|
+
clearTimeout(timer);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function showOpenImagePicker(options = {}) {
|
|
23
|
+
const { multiple = true } = options;
|
|
24
|
+
return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
|
|
25
|
+
}
|
|
26
|
+
var selectImages = showOpenImagePicker;
|
|
27
|
+
function downloadBlobFile(data, name) {
|
|
28
|
+
const blob = new Blob([data]);
|
|
29
|
+
const link = document.createElement("a");
|
|
30
|
+
const url = window.URL.createObjectURL(blob);
|
|
31
|
+
link.href = url;
|
|
32
|
+
link.download = name;
|
|
33
|
+
link.click();
|
|
34
|
+
}
|
|
35
|
+
function downloadNetworkFile(url, name) {
|
|
36
|
+
const a = document.createElement("a");
|
|
37
|
+
name && (a.download = name);
|
|
38
|
+
a.href = url;
|
|
39
|
+
a.click();
|
|
40
|
+
}
|
|
41
|
+
function readFileReader(formType, file) {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
if (typeof FileReader === "undefined") {
|
|
44
|
+
console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
|
|
45
|
+
reject();
|
|
46
|
+
}
|
|
47
|
+
const reader = new FileReader();
|
|
48
|
+
reader[formType](file);
|
|
49
|
+
reader.onloadend = function() {
|
|
50
|
+
isNull(this.result) ? reject() : resolve(this.result);
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// src/browser/util.ts
|
|
56
|
+
function redirectTo(url, target = "_blank") {
|
|
57
|
+
const link = document.createElement("a");
|
|
58
|
+
link.href = url;
|
|
59
|
+
link.target = target;
|
|
60
|
+
link.click();
|
|
61
|
+
link.remove();
|
|
62
|
+
}
|
|
63
|
+
function dialsPhone(phoneNumber) {
|
|
64
|
+
const aTag = document.createElement("a");
|
|
65
|
+
aTag.setAttribute("href", `tel:${phoneNumber}`);
|
|
66
|
+
aTag.setAttribute("target", "_blank");
|
|
67
|
+
aTag.click();
|
|
68
|
+
}
|
|
69
|
+
function on(obj, ...args) {
|
|
70
|
+
if (obj && obj.addEventListener)
|
|
71
|
+
obj.addEventListener(...args);
|
|
72
|
+
}
|
|
73
|
+
function off(obj, ...args) {
|
|
74
|
+
if (obj && obj.removeEventListener)
|
|
75
|
+
obj.removeEventListener(...args);
|
|
76
|
+
}
|
|
77
|
+
|
|
3
78
|
// ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
|
|
4
79
|
var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
5
80
|
var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
@@ -2677,10 +2752,10 @@
|
|
|
2677
2752
|
var isNative_default = isNative;
|
|
2678
2753
|
|
|
2679
2754
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
|
|
2680
|
-
function
|
|
2755
|
+
function isNull2(value) {
|
|
2681
2756
|
return value === null;
|
|
2682
2757
|
}
|
|
2683
|
-
var isNull_default =
|
|
2758
|
+
var isNull_default = isNull2;
|
|
2684
2759
|
|
|
2685
2760
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
|
|
2686
2761
|
var regexpTag5 = "[object RegExp]";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
+
// src/browser/file.ts
|
|
2
|
+
function showOpenFilePicker(option = {}) {
|
|
3
|
+
const { multiple = true, accept } = option;
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const inputElement = document.createElement("input");
|
|
6
|
+
inputElement.type = "file";
|
|
7
|
+
inputElement.multiple = multiple;
|
|
8
|
+
accept && (inputElement.accept = accept);
|
|
9
|
+
inputElement.click();
|
|
10
|
+
const timer = setTimeout(reject, 20 * 1e3);
|
|
11
|
+
inputElement.addEventListener("change", (event) => {
|
|
12
|
+
const files = event.target.files;
|
|
13
|
+
if (files) {
|
|
14
|
+
resolve(Object.values(files));
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function showOpenImagePicker(options = {}) {
|
|
21
|
+
const { multiple = true } = options;
|
|
22
|
+
return showOpenFilePicker({ multiple, accept: "image/jpeg,image/x-png,image/gif" });
|
|
23
|
+
}
|
|
24
|
+
var selectImages = showOpenImagePicker;
|
|
25
|
+
function downloadBlobFile(data, name) {
|
|
26
|
+
const blob = new Blob([data]);
|
|
27
|
+
const link = document.createElement("a");
|
|
28
|
+
const url = window.URL.createObjectURL(blob);
|
|
29
|
+
link.href = url;
|
|
30
|
+
link.download = name;
|
|
31
|
+
link.click();
|
|
32
|
+
}
|
|
33
|
+
function downloadNetworkFile(url, name) {
|
|
34
|
+
const a = document.createElement("a");
|
|
35
|
+
name && (a.download = name);
|
|
36
|
+
a.href = url;
|
|
37
|
+
a.click();
|
|
38
|
+
}
|
|
39
|
+
function readFileReader(formType, file) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
if (typeof FileReader === "undefined") {
|
|
42
|
+
console.warn("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301\u4F7F\u7528 FileReader Api");
|
|
43
|
+
reject();
|
|
44
|
+
}
|
|
45
|
+
const reader = new FileReader();
|
|
46
|
+
reader[formType](file);
|
|
47
|
+
reader.onloadend = function() {
|
|
48
|
+
isNull(this.result) ? reject() : resolve(this.result);
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/browser/util.ts
|
|
54
|
+
function redirectTo(url, target = "_blank") {
|
|
55
|
+
const link = document.createElement("a");
|
|
56
|
+
link.href = url;
|
|
57
|
+
link.target = target;
|
|
58
|
+
link.click();
|
|
59
|
+
link.remove();
|
|
60
|
+
}
|
|
61
|
+
function dialsPhone(phoneNumber) {
|
|
62
|
+
const aTag = document.createElement("a");
|
|
63
|
+
aTag.setAttribute("href", `tel:${phoneNumber}`);
|
|
64
|
+
aTag.setAttribute("target", "_blank");
|
|
65
|
+
aTag.click();
|
|
66
|
+
}
|
|
67
|
+
function on(obj, ...args) {
|
|
68
|
+
if (obj && obj.addEventListener)
|
|
69
|
+
obj.addEventListener(...args);
|
|
70
|
+
}
|
|
71
|
+
function off(obj, ...args) {
|
|
72
|
+
if (obj && obj.removeEventListener)
|
|
73
|
+
obj.removeEventListener(...args);
|
|
74
|
+
}
|
|
75
|
+
|
|
1
76
|
// ../../node_modules/.pnpm/change-case@5.4.4/node_modules/change-case/dist/index.js
|
|
2
77
|
var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
|
|
3
78
|
var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
|
|
@@ -2675,10 +2750,10 @@ function isNative(value) {
|
|
|
2675
2750
|
var isNative_default = isNative;
|
|
2676
2751
|
|
|
2677
2752
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isNull.js
|
|
2678
|
-
function
|
|
2753
|
+
function isNull2(value) {
|
|
2679
2754
|
return value === null;
|
|
2680
2755
|
}
|
|
2681
|
-
var isNull_default =
|
|
2756
|
+
var isNull_default = isNull2;
|
|
2682
2757
|
|
|
2683
2758
|
// ../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_baseIsRegExp.js
|
|
2684
2759
|
var regexpTag5 = "[object RegExp]";
|
|
@@ -3236,7 +3311,10 @@ export {
|
|
|
3236
3311
|
debounce_default as debounce,
|
|
3237
3312
|
decimal,
|
|
3238
3313
|
delay,
|
|
3314
|
+
dialsPhone,
|
|
3239
3315
|
dotCase,
|
|
3316
|
+
downloadBlobFile,
|
|
3317
|
+
downloadNetworkFile,
|
|
3240
3318
|
find_default as find,
|
|
3241
3319
|
formToObject,
|
|
3242
3320
|
formatNumeric,
|
|
@@ -3291,6 +3369,8 @@ export {
|
|
|
3291
3369
|
noop2 as noop,
|
|
3292
3370
|
numerfix,
|
|
3293
3371
|
objectToForm,
|
|
3372
|
+
off,
|
|
3373
|
+
on,
|
|
3294
3374
|
parseNumeric,
|
|
3295
3375
|
pascalCase,
|
|
3296
3376
|
pascalSnakeCase,
|
|
@@ -3301,8 +3381,13 @@ export {
|
|
|
3301
3381
|
proxy,
|
|
3302
3382
|
randomArray,
|
|
3303
3383
|
randomNumer,
|
|
3384
|
+
readFileReader,
|
|
3385
|
+
redirectTo,
|
|
3304
3386
|
riposte,
|
|
3387
|
+
selectImages,
|
|
3305
3388
|
sentenceCase,
|
|
3389
|
+
showOpenFilePicker,
|
|
3390
|
+
showOpenImagePicker,
|
|
3306
3391
|
snakeCase,
|
|
3307
3392
|
to,
|
|
3308
3393
|
trainCase,
|