assui 3.1.56 → 3.1.58
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/es/index.d.ts +2 -0
- package/es/index.js +2 -1
- package/es/label-condition-select-input/index.js +0 -4
- package/es/label-select/index.js +6 -5
- package/es/label-select/style/index.css +1 -0
- package/es/label-select/style/index.less +1 -0
- package/es/multipart-upload/getMultipartUploadHandler.d.ts +2 -0
- package/es/multipart-upload/getMultipartUploadHandler.js +38 -0
- package/es/multipart-upload/index.d.ts +43 -0
- package/es/multipart-upload/index.js +220 -0
- package/es/multipart-upload/parse2RegexOption.d.ts +13 -0
- package/es/multipart-upload/parse2RegexOption.js +46 -0
- package/es/multipart-upload/style/index.css +1323 -0
- package/es/multipart-upload/style/index.d.ts +2 -0
- package/es/multipart-upload/style/index.js +2 -0
- package/es/multipart-upload/style/index.less +102 -0
- package/es/style/variables.less +6 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -1
- package/lib/label-condition-select-input/index.js +0 -4
- package/lib/label-select/index.js +6 -5
- package/lib/label-select/style/index.css +1 -0
- package/lib/label-select/style/index.less +1 -0
- package/lib/multipart-upload/getMultipartUploadHandler.d.ts +2 -0
- package/lib/multipart-upload/getMultipartUploadHandler.js +43 -0
- package/lib/multipart-upload/index.d.ts +43 -0
- package/lib/multipart-upload/index.js +263 -0
- package/lib/multipart-upload/parse2RegexOption.d.ts +13 -0
- package/lib/multipart-upload/parse2RegexOption.js +56 -0
- package/lib/multipart-upload/style/index.css +1323 -0
- package/lib/multipart-upload/style/index.d.ts +2 -0
- package/lib/multipart-upload/style/index.js +7 -0
- package/lib/multipart-upload/style/index.less +102 -0
- package/lib/style/variables.less +6 -0
- package/package.json +2 -2
package/es/index.d.ts
CHANGED
|
@@ -80,3 +80,5 @@ export type { FlexProps } from './flex';
|
|
|
80
80
|
export { default as Flex } from './flex';
|
|
81
81
|
export type { LabelConditionSelectInputProps } from './label-condition-select-input';
|
|
82
82
|
export { default as LabelConditionSelectInput } from './label-condition-select-input';
|
|
83
|
+
export type { MultipartUploadProps } from './multipart-upload';
|
|
84
|
+
export { default as MultipartUpload } from './multipart-upload';
|
package/es/index.js
CHANGED
|
@@ -40,4 +40,5 @@ export { default as RichTextEditor } from './rich-text-editor';
|
|
|
40
40
|
export { default as BeautifulDnd } from './beautiful-dnd';
|
|
41
41
|
export { default as Resizable } from './resizable';
|
|
42
42
|
export { default as Flex } from './flex';
|
|
43
|
-
export { default as LabelConditionSelectInput } from './label-condition-select-input';
|
|
43
|
+
export { default as LabelConditionSelectInput } from './label-condition-select-input';
|
|
44
|
+
export { default as MultipartUpload } from './multipart-upload';
|
|
@@ -177,10 +177,6 @@ var LabelConditionSelectInput = function LabelConditionSelectInput(props) {
|
|
|
177
177
|
onChange: onTypeSelectChange,
|
|
178
178
|
value: selectInputValue === null || selectInputValue === void 0 ? void 0 : selectInputValue.inputValue,
|
|
179
179
|
options: subSelectOptions,
|
|
180
|
-
onDeselect: function onDeselect() {
|
|
181
|
-
var _a;
|
|
182
|
-
(_a = subSelectRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
183
|
-
},
|
|
184
180
|
onBlur: function onBlur() {
|
|
185
181
|
return onLabelConditionSelectInputBlur(EntryTypeEnum.SECOND_ENTRY);
|
|
186
182
|
},
|
package/es/label-select/index.js
CHANGED
|
@@ -47,7 +47,8 @@ var Option = Select.Option;
|
|
|
47
47
|
export { Option };
|
|
48
48
|
var LabelSelect = function LabelSelect(props, ref) {
|
|
49
49
|
var className = props.className,
|
|
50
|
-
label = props.label
|
|
50
|
+
label = props.label,
|
|
51
|
+
onBlur = props.onBlur;
|
|
51
52
|
var selectRef = React.useRef(null);
|
|
52
53
|
var _a = __read(useControllableValue(props, {
|
|
53
54
|
valuePropName: 'open',
|
|
@@ -73,6 +74,9 @@ var LabelSelect = function LabelSelect(props, ref) {
|
|
|
73
74
|
var onDropdownVisibleChange = function onDropdownVisibleChange(nextOpen) {
|
|
74
75
|
setOpen(nextOpen);
|
|
75
76
|
};
|
|
77
|
+
var handleBlur = function handleBlur() {
|
|
78
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(value);
|
|
79
|
+
};
|
|
76
80
|
return /*#__PURE__*/React.createElement("div", {
|
|
77
81
|
className: classNames({
|
|
78
82
|
'label-select': true,
|
|
@@ -87,10 +91,7 @@ var LabelSelect = function LabelSelect(props, ref) {
|
|
|
87
91
|
size: "large",
|
|
88
92
|
className: "label-select-selector",
|
|
89
93
|
onChange: handleChange,
|
|
90
|
-
|
|
91
|
-
var _a;
|
|
92
|
-
(_a = selectRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
93
|
-
},
|
|
94
|
+
onBlur: handleBlur,
|
|
94
95
|
onDropdownVisibleChange: onDropdownVisibleChange,
|
|
95
96
|
suffixIcon: /*#__PURE__*/React.createElement(ArrowDropDownFilled, null)
|
|
96
97
|
})), /*#__PURE__*/React.createElement("label", {
|
|
@@ -1256,6 +1256,7 @@ html {
|
|
|
1256
1256
|
.label-select .ant-select-multiple .ant-select-selection-overflow {
|
|
1257
1257
|
display: flex;
|
|
1258
1258
|
width: 100%;
|
|
1259
|
+
height: 36px;
|
|
1259
1260
|
transform: translateY(8px);
|
|
1260
1261
|
}
|
|
1261
1262
|
.label-select .ant-select-multiple .ant-select-selection-overflow-item {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* eslint-disable prefer-promise-reject-errors */
|
|
2
|
+
import { localStorage } from 'aa-utils';
|
|
3
|
+
var getMultipartUploadHandler = function getMultipartUploadHandler(resultUrl) {
|
|
4
|
+
var multipartUploadHandler = function multipartUploadHandler(file, progress) {
|
|
5
|
+
return new Promise(function (resolve, reject) {
|
|
6
|
+
var xhr = new XMLHttpRequest();
|
|
7
|
+
xhr.open('POST', resultUrl);
|
|
8
|
+
xhr.setRequestHeader('token', localStorage.get('token') || '');
|
|
9
|
+
xhr.upload.onprogress = function (e) {
|
|
10
|
+
progress && progress(e.loaded / e.total * 100);
|
|
11
|
+
};
|
|
12
|
+
xhr.onload = function () {
|
|
13
|
+
if (xhr.status === 403) {
|
|
14
|
+
reject("HTTP Error: ".concat(xhr.status));
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
18
|
+
reject("HTTP Error: ".concat(xhr.status));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
var json = JSON.parse(xhr.responseText);
|
|
22
|
+
if (!json || json.header.code !== 200) {
|
|
23
|
+
reject("Invalid JSON: ".concat(xhr.responseText));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
resolve(json.body);
|
|
27
|
+
};
|
|
28
|
+
xhr.onerror = function () {
|
|
29
|
+
reject("Image upload failed due to a XHR Transport error. Code: ".concat(xhr.status));
|
|
30
|
+
};
|
|
31
|
+
var formData = new FormData();
|
|
32
|
+
formData.append('file', file);
|
|
33
|
+
xhr.send(formData);
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
return multipartUploadHandler;
|
|
37
|
+
};
|
|
38
|
+
export default getMultipartUploadHandler;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { UploadProps } from 'rc-upload';
|
|
3
|
+
export interface RcFile extends File {
|
|
4
|
+
uid: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UploadProgressEvent extends ProgressEvent {
|
|
7
|
+
percent: number;
|
|
8
|
+
}
|
|
9
|
+
export interface MultipartUploadProps extends Omit<UploadProps, 'onSuccess'> {
|
|
10
|
+
value?: string;
|
|
11
|
+
wrapperClassName?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
fileName?: string;
|
|
14
|
+
/** 上传文字 */
|
|
15
|
+
uploadText?: string;
|
|
16
|
+
onSuccess?: (res: string, fileName: string) => void;
|
|
17
|
+
uploadIcon: React.ReactElement;
|
|
18
|
+
cancelUpload?: () => void;
|
|
19
|
+
/** 分片大小 */
|
|
20
|
+
chunkSize?: number;
|
|
21
|
+
/** 第一步 获取ID */
|
|
22
|
+
getInitUploadIdAPI: ({ fileName }: {
|
|
23
|
+
fileName: string;
|
|
24
|
+
}) => Promise<string>;
|
|
25
|
+
/** 第二步 获取url 进行分片上传 */
|
|
26
|
+
getInProgressUploadUrl: ({ fileName, partNumber, uploadId, }: {
|
|
27
|
+
fileName: string;
|
|
28
|
+
partNumber: number;
|
|
29
|
+
uploadId: string;
|
|
30
|
+
}) => string;
|
|
31
|
+
/** 第三步 合并上传文件 完成上传 */
|
|
32
|
+
completeRequest: ({ fileName, uploadId, list, }: {
|
|
33
|
+
fileName: string;
|
|
34
|
+
uploadId: string;
|
|
35
|
+
list: string[];
|
|
36
|
+
}) => Promise<string>;
|
|
37
|
+
errorCatch?: (error: any) => void;
|
|
38
|
+
}
|
|
39
|
+
declare const MultipartUpload: {
|
|
40
|
+
(props: MultipartUploadProps): JSX.Element;
|
|
41
|
+
displayName: string;
|
|
42
|
+
};
|
|
43
|
+
export default MultipartUpload;
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
17
|
+
}
|
|
18
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
var __read = this && this.__read || function (o, n) {
|
|
24
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
25
|
+
if (!m) return o;
|
|
26
|
+
var i = m.call(o),
|
|
27
|
+
r,
|
|
28
|
+
ar = [],
|
|
29
|
+
e;
|
|
30
|
+
try {
|
|
31
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
|
|
32
|
+
ar.push(r.value);
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
e = {
|
|
36
|
+
error: error
|
|
37
|
+
};
|
|
38
|
+
} finally {
|
|
39
|
+
try {
|
|
40
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
41
|
+
} finally {
|
|
42
|
+
if (e) throw e.error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return ar;
|
|
46
|
+
};
|
|
47
|
+
import React, { useState, useRef } from 'react';
|
|
48
|
+
import Upload from 'rc-upload';
|
|
49
|
+
import { useMount, useUpdateEffect } from 'ahooks';
|
|
50
|
+
import classNames from 'classnames';
|
|
51
|
+
import { Progress } from 'antd';
|
|
52
|
+
import { CloseOutlined, CirclePlusFilled } from 'a-icons';
|
|
53
|
+
import getMultipartUploadHandler from './getMultipartUploadHandler';
|
|
54
|
+
var MultipartUpload = function MultipartUpload(props) {
|
|
55
|
+
var className = props.className,
|
|
56
|
+
wrapperClassName = props.wrapperClassName,
|
|
57
|
+
accept = props.accept,
|
|
58
|
+
method = props.method,
|
|
59
|
+
_a = props.fileName,
|
|
60
|
+
fileName = _a === void 0 ? '' : _a,
|
|
61
|
+
onSuccess = props.onSuccess,
|
|
62
|
+
onError = props.onError,
|
|
63
|
+
onStart = props.onStart,
|
|
64
|
+
cancelUpload = props.cancelUpload,
|
|
65
|
+
uploadIcon = props.uploadIcon,
|
|
66
|
+
disabled = props.disabled,
|
|
67
|
+
getInProgressUploadUrl = props.getInProgressUploadUrl,
|
|
68
|
+
getInitUploadIdAPI = props.getInitUploadIdAPI,
|
|
69
|
+
completeRequest = props.completeRequest,
|
|
70
|
+
chunkSize = props.chunkSize,
|
|
71
|
+
uploadText = props.uploadText,
|
|
72
|
+
customRequest = props.customRequest,
|
|
73
|
+
value = props.value,
|
|
74
|
+
errorCatch = props.errorCatch,
|
|
75
|
+
restProps = __rest(props, ["className", "wrapperClassName", "accept", "method", "fileName", "onSuccess", "onError", "onStart", "cancelUpload", "uploadIcon", "disabled", "getInProgressUploadUrl", "getInitUploadIdAPI", "completeRequest", "chunkSize", "uploadText", "customRequest", "value", "errorCatch"]);
|
|
76
|
+
var fileNameRef = useRef('');
|
|
77
|
+
var uploadRef = useRef();
|
|
78
|
+
var fileRef = useRef();
|
|
79
|
+
var uploadIdRef = useRef('');
|
|
80
|
+
var _b = __read(useState('init'), 2),
|
|
81
|
+
uploadStatus = _b[0],
|
|
82
|
+
setUploadStatus = _b[1];
|
|
83
|
+
var _c = __read(useState(0), 2),
|
|
84
|
+
uploadPercent = _c[0],
|
|
85
|
+
setUploadPercent = _c[1];
|
|
86
|
+
var resChunkSize = chunkSize || 1024 * 1024 * 50; // 50MB
|
|
87
|
+
var currentChunk = 0;
|
|
88
|
+
var totalChunks = 0;
|
|
89
|
+
var uploadList = [];
|
|
90
|
+
useUpdateEffect(function () {
|
|
91
|
+
if (value) {
|
|
92
|
+
setUploadStatus('done');
|
|
93
|
+
} else {
|
|
94
|
+
setUploadStatus('init');
|
|
95
|
+
}
|
|
96
|
+
}, [value]);
|
|
97
|
+
useMount(function () {
|
|
98
|
+
fileNameRef.current = fileName;
|
|
99
|
+
});
|
|
100
|
+
useUpdateEffect(function () {
|
|
101
|
+
fileNameRef.current = fileName;
|
|
102
|
+
}, [fileName]);
|
|
103
|
+
var handleStart = function handleStart(file) {
|
|
104
|
+
fileRef.current = file;
|
|
105
|
+
setUploadPercent(0);
|
|
106
|
+
fileNameRef.current = file.name;
|
|
107
|
+
totalChunks = Math.ceil(fileRef.current.size / resChunkSize);
|
|
108
|
+
setUploadStatus('uploading');
|
|
109
|
+
onStart && onStart(file);
|
|
110
|
+
};
|
|
111
|
+
var handleError = function handleError(error, ret, file) {
|
|
112
|
+
setUploadStatus('init');
|
|
113
|
+
onError && onError(error, ret, file);
|
|
114
|
+
};
|
|
115
|
+
var uploadCls = classNames(className, {
|
|
116
|
+
'not-upload-init': uploadStatus !== 'init'
|
|
117
|
+
});
|
|
118
|
+
var handleCancelUpload = function handleCancelUpload() {
|
|
119
|
+
var _a;
|
|
120
|
+
if (fileRef.current) {
|
|
121
|
+
(_a = uploadRef.current) === null || _a === void 0 ? void 0 : _a.abort(fileRef.current);
|
|
122
|
+
setUploadStatus('init');
|
|
123
|
+
cancelUpload && cancelUpload();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var progress = function progress(progressNumber) {
|
|
127
|
+
var currentProgressNumber = parseInt("".concat(progressNumber * (currentChunk + 1) / totalChunks), 10);
|
|
128
|
+
if (currentProgressNumber >= currentChunk / totalChunks * 100) {
|
|
129
|
+
setUploadPercent(currentProgressNumber);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var uploadNextChunk = function uploadNextChunk() {
|
|
133
|
+
/** 第二步 获取url 进行分片上传 */
|
|
134
|
+
if (fileRef.current) {
|
|
135
|
+
var resultUrl = getInProgressUploadUrl({
|
|
136
|
+
fileName: fileNameRef.current,
|
|
137
|
+
partNumber: currentChunk + 1,
|
|
138
|
+
uploadId: uploadIdRef.current
|
|
139
|
+
});
|
|
140
|
+
var multipartUploadHandler = getMultipartUploadHandler(resultUrl);
|
|
141
|
+
var start = currentChunk * resChunkSize;
|
|
142
|
+
var end = Math.min(fileRef.current.size, start + resChunkSize);
|
|
143
|
+
var chunk = fileRef.current.slice(start, end);
|
|
144
|
+
multipartUploadHandler(chunk, progress).then(function (res) {
|
|
145
|
+
uploadList.push(res);
|
|
146
|
+
currentChunk += 1;
|
|
147
|
+
if (currentChunk < totalChunks) {
|
|
148
|
+
uploadNextChunk();
|
|
149
|
+
} else {
|
|
150
|
+
/** 分片上传完成 进行文件合并 上传完成 */
|
|
151
|
+
completeRequest({
|
|
152
|
+
fileName: fileNameRef.current,
|
|
153
|
+
uploadId: uploadIdRef.current,
|
|
154
|
+
list: uploadList
|
|
155
|
+
}).then(function (fileUrl) {
|
|
156
|
+
setUploadStatus('done');
|
|
157
|
+
onSuccess && onSuccess(fileUrl, fileNameRef.current);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
})["catch"](function (error) {
|
|
161
|
+
errorCatch && errorCatch(error);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var customMultipartRequest = function customMultipartRequest() {
|
|
166
|
+
if (fileRef.current) {
|
|
167
|
+
totalChunks = Math.ceil(fileRef.current.size / resChunkSize);
|
|
168
|
+
/** 第一步 获取ID */
|
|
169
|
+
getInitUploadIdAPI({
|
|
170
|
+
fileName: fileNameRef.current
|
|
171
|
+
}).then(function (id) {
|
|
172
|
+
uploadIdRef.current = id;
|
|
173
|
+
uploadNextChunk();
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
178
|
+
className: classNames('multipart-upload-container', wrapperClassName)
|
|
179
|
+
}, uploadStatus === 'uploading' && /*#__PURE__*/React.createElement("div", {
|
|
180
|
+
className: "multipart-uploading-container"
|
|
181
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
182
|
+
className: "multipart-package-icon-files"
|
|
183
|
+
}, uploadIcon, /*#__PURE__*/React.createElement("div", {
|
|
184
|
+
className: "multipart-upload-file-name",
|
|
185
|
+
title: fileNameRef.current
|
|
186
|
+
}, fileNameRef.current)), /*#__PURE__*/React.createElement(Progress, {
|
|
187
|
+
className: "multipart-upload-progress",
|
|
188
|
+
percent: uploadPercent,
|
|
189
|
+
size: "small",
|
|
190
|
+
status: "active"
|
|
191
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
192
|
+
className: "multipart-package-upload-close-button",
|
|
193
|
+
onClick: handleCancelUpload
|
|
194
|
+
}, /*#__PURE__*/React.createElement(CloseOutlined, null))), uploadStatus === 'done' && /*#__PURE__*/React.createElement("div", {
|
|
195
|
+
className: "multipart-upload-container"
|
|
196
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
197
|
+
className: "multipart-upload-icon-files"
|
|
198
|
+
}, uploadIcon, /*#__PURE__*/React.createElement("div", {
|
|
199
|
+
className: "multipart-upload-file-name",
|
|
200
|
+
title: fileNameRef.current
|
|
201
|
+
}, fileNameRef.current))), /*#__PURE__*/React.createElement(Upload, __assign({
|
|
202
|
+
ref: function ref(uploader) {
|
|
203
|
+
uploadRef.current = uploader;
|
|
204
|
+
},
|
|
205
|
+
name: "file",
|
|
206
|
+
accept: accept,
|
|
207
|
+
disabled: disabled,
|
|
208
|
+
method: method,
|
|
209
|
+
className: uploadCls,
|
|
210
|
+
onStart: handleStart,
|
|
211
|
+
onError: handleError,
|
|
212
|
+
customRequest: customMultipartRequest
|
|
213
|
+
}, restProps), uploadStatus === 'init' && /*#__PURE__*/React.createElement("div", {
|
|
214
|
+
className: classNames('multipart-uploading-file-container', {
|
|
215
|
+
'multipart-uploading-file-container-disabled': disabled
|
|
216
|
+
})
|
|
217
|
+
}, /*#__PURE__*/React.createElement(CirclePlusFilled, null), /*#__PURE__*/React.createElement("span", null, uploadText))));
|
|
218
|
+
};
|
|
219
|
+
MultipartUpload.displayName = 'MultipartUpload';
|
|
220
|
+
export default MultipartUpload;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface RegexOptionType {
|
|
2
|
+
isValid: boolean;
|
|
3
|
+
replacement: string;
|
|
4
|
+
}
|
|
5
|
+
declare type regexParamsType = RegExp | string | {
|
|
6
|
+
pattern: RegExp;
|
|
7
|
+
replacement?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface ResultType extends RegexOptionType {
|
|
10
|
+
pattern: RegExp;
|
|
11
|
+
}
|
|
12
|
+
declare const parse2RegexOption: (regex: regexParamsType) => ResultType;
|
|
13
|
+
export default parse2RegexOption;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) {
|
|
6
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
import isRegExp from 'lodash/isRegExp';
|
|
14
|
+
import isString from 'lodash/isString';
|
|
15
|
+
import isObject from 'lodash/isObject';
|
|
16
|
+
var defaultOptionValues = {
|
|
17
|
+
isValid: true,
|
|
18
|
+
replacement: ''
|
|
19
|
+
};
|
|
20
|
+
var parseRegex2RegexOption = function parseRegex2RegexOption(regex, options) {
|
|
21
|
+
return __assign(__assign(__assign({}, defaultOptionValues), {
|
|
22
|
+
pattern: regex
|
|
23
|
+
}), options);
|
|
24
|
+
};
|
|
25
|
+
var parseString2RegexOption = function parseString2RegexOption(regexString, options) {
|
|
26
|
+
return parseRegex2RegexOption(new RegExp(regexString), options);
|
|
27
|
+
};
|
|
28
|
+
var parse2RegexOption = function parse2RegexOption(regex) {
|
|
29
|
+
if (isRegExp(regex)) {
|
|
30
|
+
return parseRegex2RegexOption(regex);
|
|
31
|
+
}
|
|
32
|
+
if (isString(regex)) {
|
|
33
|
+
return parseString2RegexOption(regex);
|
|
34
|
+
}
|
|
35
|
+
if (isObject(regex)) {
|
|
36
|
+
return __assign(__assign(__assign({}, defaultOptionValues), {
|
|
37
|
+
isValid: !!regex.pattern
|
|
38
|
+
}), regex);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
isValid: false,
|
|
42
|
+
replacement: '',
|
|
43
|
+
pattern: /./
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export default parse2RegexOption;
|