@opentiny/vue-renderless 3.1.0-alpha.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/action-sheet/index.js +28 -0
- package/action-sheet/vue.js +29 -0
- package/alert/index.js +23 -0
- package/alert/vue.js +37 -0
- package/autocomplete/index.js +175 -0
- package/autocomplete/vue.js +171 -0
- package/avatar/index.js +29 -0
- package/avatar/vue.js +24 -0
- package/badge/index.js +16 -0
- package/badge/vue.js +30 -0
- package/breadcrumb/vue.js +4 -0
- package/breadcrumb-item/vue.js +24 -0
- package/bulletin-board/index.js +21 -0
- package/bulletin-board/vue.js +36 -0
- package/button/index.js +19 -0
- package/button/vue.js +43 -0
- package/button-group/index.js +25 -0
- package/button-group/vue.js +51 -0
- package/calendar/index.js +279 -0
- package/calendar/vue.js +124 -0
- package/card-template/index.js +39 -0
- package/card-template/vue.js +34 -0
- package/carousel/index.js +206 -0
- package/carousel/vue.js +222 -0
- package/carousel-item/index.js +93 -0
- package/carousel-item/vue.js +57 -0
- package/cascader/index.js +511 -0
- package/cascader/vue.js +342 -0
- package/cascader-menu/index.js +41 -0
- package/cascader-menu/vue.js +36 -0
- package/cascader-node/index.js +63 -0
- package/cascader-node/vue.js +62 -0
- package/cascader-panel/index.js +359 -0
- package/cascader-panel/node.js +199 -0
- package/cascader-panel/store.js +80 -0
- package/cascader-panel/vue.js +217 -0
- package/checkbox/index.js +145 -0
- package/checkbox/vue.js +139 -0
- package/checkbox-button/index.js +102 -0
- package/checkbox-button/vue.js +150 -0
- package/checkbox-group/index.js +12 -0
- package/checkbox-group/vue.js +33 -0
- package/col/index.js +132 -0
- package/col/vue.js +34 -0
- package/collapse/index.js +45 -0
- package/collapse/vue.js +35 -0
- package/collapse-item/index.js +38 -0
- package/collapse-item/vue.js +48 -0
- package/common/array.js +120 -0
- package/common/bigInt.js +352 -0
- package/common/browser.js +69 -0
- package/common/dataset/index.js +135 -0
- package/common/date.js +352 -0
- package/common/decimal.js +203 -0
- package/common/deps/ResizeObserver.js +474 -0
- package/common/deps/after-leave.js +25 -0
- package/common/deps/clickoutside.js +61 -0
- package/common/deps/date-util.js +262 -0
- package/common/deps/date.js +308 -0
- package/common/deps/debounce.js +4 -0
- package/common/deps/dom.js +190 -0
- package/common/deps/fullscreen/apis.js +157 -0
- package/common/deps/fullscreen/screenfull.js +106 -0
- package/common/deps/letter-only.js +15 -0
- package/common/deps/memorize.js +149 -0
- package/common/deps/number-only.js +16 -0
- package/common/deps/popper.js +713 -0
- package/common/deps/popup-manager.js +179 -0
- package/common/deps/repeat-click.js +24 -0
- package/common/deps/requestAnimationFrame.js +25 -0
- package/common/deps/resize-event.js +29 -0
- package/common/deps/scroll-into-view.js +29 -0
- package/common/deps/scrollbar-width.js +25 -0
- package/common/deps/throttle.js +34 -0
- package/common/deps/touch.js +33 -0
- package/common/deps/tree-model/node.js +586 -0
- package/common/deps/tree-model/tree-store.js +377 -0
- package/common/deps/tree-model/util.js +14 -0
- package/common/deps/upload-ajax.js +71 -0
- package/common/deps/vue-emitter.js +30 -0
- package/common/deps/vue-popper.js +291 -0
- package/common/deps/vue-popup.js +211 -0
- package/common/event.js +17 -0
- package/common/index.js +288 -0
- package/common/object.js +228 -0
- package/common/runtime.js +52 -0
- package/common/string.js +446 -0
- package/common/type.js +65 -0
- package/common/validate/index.js +6 -0
- package/common/validate/messages.js +68 -0
- package/common/validate/rules/enum.js +8 -0
- package/common/validate/rules/index.js +14 -0
- package/common/validate/rules/pattern.js +16 -0
- package/common/validate/rules/range.js +62 -0
- package/common/validate/rules/required.js +13 -0
- package/common/validate/rules/type.js +110 -0
- package/common/validate/rules/whitespace.js +6 -0
- package/common/validate/schema.js +323 -0
- package/common/validate/util.js +198 -0
- package/common/validate/validations/array.js +25 -0
- package/common/validate/validations/date.js +35 -0
- package/common/validate/validations/enum.js +24 -0
- package/common/validate/validations/float.js +24 -0
- package/common/validate/validations/index.js +42 -0
- package/common/validate/validations/integer.js +24 -0
- package/common/validate/validations/method.js +23 -0
- package/common/validate/validations/number.js +27 -0
- package/common/validate/validations/pattern.js +23 -0
- package/common/validate/validations/required.js +15 -0
- package/common/validate/validations/string.js +29 -0
- package/common/validate/validations/type.js +25 -0
- package/common/xss.js +325 -0
- package/container/index.js +110 -0
- package/container/vue.js +63 -0
- package/credit-card/index.js +107 -0
- package/credit-card/vue.js +117 -0
- package/credit-card-form/index.js +143 -0
- package/credit-card-form/vue.js +150 -0
- package/crop/index.js +297 -0
- package/crop/vue.js +191 -0
- package/date-panel/index.js +584 -0
- package/date-panel/vue.js +319 -0
- package/date-picker/index.js +301 -0
- package/date-picker/vue.js +169 -0
- package/date-range/index.js +463 -0
- package/date-range/vue.js +297 -0
- package/date-table/index.js +457 -0
- package/date-table/vue.js +151 -0
- package/detail-page/index.js +135 -0
- package/detail-page/vue.js +145 -0
- package/dialog-box/index.js +268 -0
- package/dialog-box/vue.js +226 -0
- package/drop-times/index.js +23 -0
- package/drop-times/vue.js +28 -0
- package/dropdown/index.js +259 -0
- package/dropdown/vue.js +107 -0
- package/dropdown-item/index.js +155 -0
- package/dropdown-item/vue.js +124 -0
- package/dropdown-menu/index.js +148 -0
- package/dropdown-menu/vue.js +44 -0
- package/exception/index.js +13 -0
- package/exception/vue.js +25 -0
- package/fall-menu/index.js +121 -0
- package/fall-menu/vue.js +90 -0
- package/file-upload/index.js +1940 -0
- package/file-upload/vue.js +458 -0
- package/floatbar/index.js +10 -0
- package/floatbar/vue.js +17 -0
- package/form/index.js +186 -0
- package/form/vue.js +69 -0
- package/form-item/index.js +364 -0
- package/form-item/vue.js +210 -0
- package/fullscreen/index.js +138 -0
- package/fullscreen/vue.js +77 -0
- package/grid/core/index.js +3 -0
- package/grid/core/interceptor.js +38 -0
- package/grid/core/storeMap.js +19 -0
- package/grid/plugins/export.js +169 -0
- package/grid/plugins/exportExcel.js +749 -0
- package/grid/plugins/header.js +58 -0
- package/grid/plugins/resize.js +82 -0
- package/grid/static/array/arrayEach.js +12 -0
- package/grid/static/array/arrayIndexOf.js +11 -0
- package/grid/static/array/eachTree.js +32 -0
- package/grid/static/array/every.js +2 -0
- package/grid/static/array/filterTree.js +16 -0
- package/grid/static/array/find.js +3 -0
- package/grid/static/array/findTree.js +46 -0
- package/grid/static/array/helperCreateIterateHandle.js +59 -0
- package/grid/static/array/helperCreateTreeFunc.js +18 -0
- package/grid/static/array/includes.js +5 -0
- package/grid/static/array/lastArrayEach.js +6 -0
- package/grid/static/array/map.js +23 -0
- package/grid/static/array/mapTree.js +33 -0
- package/grid/static/array/slice.js +10 -0
- package/grid/static/array/sortBy.js +69 -0
- package/grid/static/array/sum.js +28 -0
- package/grid/static/array/toArray.js +7 -0
- package/grid/static/array/toTreeArray.js +24 -0
- package/grid/static/base/clear.js +44 -0
- package/grid/static/base/clone.js +18 -0
- package/grid/static/base/destructuring.js +18 -0
- package/grid/static/base/each.js +9 -0
- package/grid/static/base/eqNull.js +6 -0
- package/grid/static/base/findIndexOf.js +10 -0
- package/grid/static/base/get.js +42 -0
- package/grid/static/base/has.js +60 -0
- package/grid/static/base/hasOwnProp.js +4 -0
- package/grid/static/base/helperCreateGetObjects.js +26 -0
- package/grid/static/base/helperCreateInInObjectString.js +7 -0
- package/grid/static/base/helperCreateInTypeof.js +6 -0
- package/grid/static/base/helperCreateIndexOf.js +21 -0
- package/grid/static/base/helperCreateiterateIndexOf.js +21 -0
- package/grid/static/base/helperDefaultCompare.js +4 -0
- package/grid/static/base/helperDeleteProperty.js +8 -0
- package/grid/static/base/helperEqualCompare.js +60 -0
- package/grid/static/base/helperGetHGSKeys.js +4 -0
- package/grid/static/base/indexOf.js +3 -0
- package/grid/static/base/isArray.js +3 -0
- package/grid/static/base/isBoolean.js +4 -0
- package/grid/static/base/isDate.js +3 -0
- package/grid/static/base/isEmpty.js +8 -0
- package/grid/static/base/isEqual.js +11 -0
- package/grid/static/base/isFunction.js +4 -0
- package/grid/static/base/isNaN.js +5 -0
- package/grid/static/base/isNull.js +4 -0
- package/grid/static/base/isNumber.js +4 -0
- package/grid/static/base/isObject.js +5 -0
- package/grid/static/base/isPlainObject.js +2 -0
- package/grid/static/base/isRegExp.js +3 -0
- package/grid/static/base/isSet.js +5 -0
- package/grid/static/base/isString.js +4 -0
- package/grid/static/base/isUndefined.js +4 -0
- package/grid/static/base/keys.js +3 -0
- package/grid/static/base/lastEach.js +9 -0
- package/grid/static/base/remove.js +44 -0
- package/grid/static/base/set.js +43 -0
- package/grid/static/base/toJSONString.js +4 -0
- package/grid/static/base/toStringJSON.js +13 -0
- package/grid/static/base/uniqueId.js +5 -0
- package/grid/static/browse/browse.js +54 -0
- package/grid/static/function/property.js +7 -0
- package/grid/static/function/throttle.js +43 -0
- package/grid/static/index.js +55 -0
- package/grid/static/number/helperCreateToNumber.js +12 -0
- package/grid/static/number/toNumber.js +3 -0
- package/grid/static/object/assign.js +41 -0
- package/grid/static/object/extend.js +3 -0
- package/grid/static/object/lastObjectEach.js +8 -0
- package/grid/static/object/objectEach.js +11 -0
- package/grid/static/object/objectMap.js +20 -0
- package/grid/static/object/values.js +9 -0
- package/grid/static/static/staticDocument.js +4 -0
- package/grid/static/static/staticHGKeyRE.js +2 -0
- package/grid/static/static/staticParseInt.js +2 -0
- package/grid/static/static/staticStrUndefined.js +2 -0
- package/grid/static/static/staticWindow.js +4 -0
- package/grid/static/string/template.js +12 -0
- package/grid/static/string/toString.js +12 -0
- package/grid/utils/column.js +72 -0
- package/grid/utils/common.js +155 -0
- package/grid/utils/dom.js +213 -0
- package/grid/utils/event.js +40 -0
- package/grid/utils/index.js +5 -0
- package/image/index.js +187 -0
- package/image/vue.js +142 -0
- package/image-viewer/index.js +469 -0
- package/image-viewer/vue.js +243 -0
- package/input/index.js +319 -0
- package/input/vue.js +319 -0
- package/ip-address/index.js +370 -0
- package/ip-address/vue.js +185 -0
- package/layout/vue.js +4 -0
- package/link/index.js +10 -0
- package/link/vue.js +26 -0
- package/link-menu/index.js +146 -0
- package/link-menu/vue.js +138 -0
- package/list/index.js +13 -0
- package/list/vue.js +17 -0
- package/loading/index.js +29 -0
- package/loading/vue.js +28 -0
- package/milestone/index.js +92 -0
- package/milestone/vue.js +31 -0
- package/mini-picker/index.js +227 -0
- package/mini-picker/vue.js +142 -0
- package/modal/index.js +866 -0
- package/modal/vue.js +130 -0
- package/month-range/index.js +169 -0
- package/month-range/vue.js +104 -0
- package/month-table/index.js +232 -0
- package/month-table/vue.js +72 -0
- package/nav-menu/index.js +457 -0
- package/nav-menu/vue.js +187 -0
- package/notify/index.js +91 -0
- package/notify/vue.js +67 -0
- package/numeric/index.js +419 -0
- package/numeric/vue.js +218 -0
- package/option/index.js +79 -0
- package/option/vue.js +219 -0
- package/option-group/index.js +18 -0
- package/option-group/vue.js +37 -0
- package/package.json +179 -0
- package/pager-item/index.js +122 -0
- package/pager-item/vue.js +52 -0
- package/panel/index.js +30 -0
- package/panel/vue.js +26 -0
- package/picker/index.js +1039 -0
- package/picker/timezone.js +974 -0
- package/picker/vue.js +415 -0
- package/picker-column/index.js +261 -0
- package/picker-column/vue.js +163 -0
- package/pop-upload/index.js +324 -0
- package/pop-upload/vue.js +292 -0
- package/popeditor/index.js +884 -0
- package/popeditor/vue.js +368 -0
- package/popover/index.js +203 -0
- package/popover/vue.js +174 -0
- package/popup/index.js +139 -0
- package/popup/vue.js +129 -0
- package/progress/index.js +174 -0
- package/progress/vue.js +118 -0
- package/pull-refresh/index.js +104 -0
- package/pull-refresh/vue.js +64 -0
- package/radio/index.js +83 -0
- package/radio/vue.js +99 -0
- package/radio-button/index.js +58 -0
- package/radio-button/vue.js +70 -0
- package/radio-group/index.js +51 -0
- package/radio-group/vue.js +34 -0
- package/rate/index.js +254 -0
- package/rate/vue.js +158 -0
- package/row/index.js +19 -0
- package/row/vue.js +24 -0
- package/scroll-text/index.js +24 -0
- package/scroll-text/vue.js +31 -0
- package/scrollbar/index.js +127 -0
- package/scrollbar/vue-bar.js +49 -0
- package/scrollbar/vue.js +43 -0
- package/search/index.js +110 -0
- package/search/vue.js +110 -0
- package/select/index.js +1766 -0
- package/select/vue.js +693 -0
- package/select-dropdown/index.js +23 -0
- package/select-dropdown/vue.js +122 -0
- package/slide-bar/index.js +94 -0
- package/slide-bar/vue.js +58 -0
- package/slider/index.js +434 -0
- package/slider/vue.js +172 -0
- package/split/index.js +122 -0
- package/split/vue.js +131 -0
- package/steps/vue.js +4 -0
- package/switch/index.js +45 -0
- package/switch/vue.js +62 -0
- package/tab-bar/index.js +51 -0
- package/tab-bar/vue.js +16 -0
- package/tab-dropdown/index.js +11 -0
- package/tab-dropdown/vue.js +17 -0
- package/tab-item/index.js +37 -0
- package/tab-item/vue.js +49 -0
- package/tab-nav/index.js +247 -0
- package/tab-nav/vue.js +106 -0
- package/tabbar/index.js +32 -0
- package/tabbar/vue.js +54 -0
- package/tabbar-item/index.js +55 -0
- package/tabbar-item/vue.js +53 -0
- package/table/index.js +111 -0
- package/table/vue.js +66 -0
- package/tabs/index.js +174 -0
- package/tabs/vue.js +141 -0
- package/tag/index.js +14 -0
- package/tag/vue.js +13 -0
- package/tall-storage/index.js +161 -0
- package/tall-storage/vue-storage-box.js +25 -0
- package/tall-storage/vue.js +38 -0
- package/text-popup/index.js +75 -0
- package/text-popup/vue.js +64 -0
- package/time/index.js +121 -0
- package/time/vue.js +124 -0
- package/time-line/index.js +60 -0
- package/time-line/vue.js +49 -0
- package/time-panel/index.js +189 -0
- package/time-panel/scrollIntoView.js +23 -0
- package/time-panel/vue.js +110 -0
- package/time-range/index.js +199 -0
- package/time-range/vue.js +129 -0
- package/time-spinner/index.js +175 -0
- package/time-spinner/vue.js +122 -0
- package/toggle-menu/index.js +104 -0
- package/toggle-menu/vue.js +74 -0
- package/tooltip/index.js +171 -0
- package/tooltip/vue.js +133 -0
- package/top-box/index.js +81 -0
- package/top-box/vue.js +77 -0
- package/transfer/index.js +296 -0
- package/transfer/vue.js +138 -0
- package/transfer-panel/index.js +364 -0
- package/transfer-panel/vue.js +258 -0
- package/tree/index.js +642 -0
- package/tree/vue.js +268 -0
- package/tree-menu/index.js +124 -0
- package/tree-menu/vue.js +60 -0
- package/tree-node/index.js +271 -0
- package/tree-node/vue.js +211 -0
- package/upload/index.js +324 -0
- package/upload/vue.js +93 -0
- package/upload-dragger/index.js +50 -0
- package/upload-dragger/vue.js +27 -0
- package/upload-list/index.js +55 -0
- package/upload-list/vue.js +48 -0
- package/user-contact/index.js +13 -0
- package/user-contact/vue.js +20 -0
- package/user-head/index.js +71 -0
- package/user-head/vue.js +47 -0
- package/wizard/index.js +123 -0
- package/wizard/vue.js +45 -0
- package/year-table/index.js +40 -0
- package/year-table/vue.js +23 -0
package/common/string.js
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { isPlainObject, isNumber, isNumeric, isNull } from '@opentiny/vue-renderless/common/type';
|
|
2
|
+
import { getObj, toJsonStr } from '@opentiny/vue-renderless/common/object';
|
|
3
|
+
import { toFixed } from '@opentiny/vue-renderless/common/decimal';
|
|
4
|
+
import { nanoid } from '@opentiny/vue-renderless/common/xss.js';
|
|
5
|
+
export var formatTypes = {
|
|
6
|
+
text: 'text',
|
|
7
|
+
url: 'url',
|
|
8
|
+
html: 'html',
|
|
9
|
+
tmpl: 'tmpl'
|
|
10
|
+
};
|
|
11
|
+
export var escapeChars = {
|
|
12
|
+
'&': '&',
|
|
13
|
+
'<': '<',
|
|
14
|
+
'>': '>',
|
|
15
|
+
'"': '"',
|
|
16
|
+
"'": ''',
|
|
17
|
+
'[': '[',
|
|
18
|
+
']': ']'
|
|
19
|
+
};
|
|
20
|
+
export var isNullOrEmpty = function isNullOrEmpty(value) {
|
|
21
|
+
return value === null || value === undefined || typeof value === 'string' && value.trim().length === 0;
|
|
22
|
+
};
|
|
23
|
+
function cached(fn) {
|
|
24
|
+
var cache = Object.create(null);
|
|
25
|
+
return function cachedFn(str) {
|
|
26
|
+
var hit = cache[str];
|
|
27
|
+
return hit || (cache[str] = fn(str));
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var camelizeRE = /-(\w)/g;
|
|
31
|
+
export var camelize = cached(function (str) {
|
|
32
|
+
return str.replace(camelizeRE, function (_, c) {
|
|
33
|
+
return c ? c.toUpperCase() : '';
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
export var capitalize = cached(function (str) {
|
|
37
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
38
|
+
});
|
|
39
|
+
var hyphenateRE = /\B([A-Z])/g;
|
|
40
|
+
export var hyphenate = cached(function (str) {
|
|
41
|
+
return str.replace(hyphenateRE, '-$1').toLowerCase();
|
|
42
|
+
});
|
|
43
|
+
export var toJson = function toJson(string) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(string);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function getLengthInUtf16(string) {
|
|
51
|
+
var len = string.length;
|
|
52
|
+
var count = 0;
|
|
53
|
+
for (var i = 0; i < len; i++) {
|
|
54
|
+
var charCode = string.charCodeAt(i);
|
|
55
|
+
if (charCode <= 0xffff) {
|
|
56
|
+
count += 2;
|
|
57
|
+
} else {
|
|
58
|
+
count += 4;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return count;
|
|
62
|
+
}
|
|
63
|
+
function getLengthInUtf8(string) {
|
|
64
|
+
var len = string.length;
|
|
65
|
+
var count = 0;
|
|
66
|
+
for (var i = 0; i < len; i++) {
|
|
67
|
+
var charCode = string.charCodeAt(i);
|
|
68
|
+
if (charCode <= 0x007f) {
|
|
69
|
+
count += 1;
|
|
70
|
+
} else if (charCode <= 0x07ff) {
|
|
71
|
+
count += 2;
|
|
72
|
+
} else if (charCode <= 0xffff) {
|
|
73
|
+
count += 3;
|
|
74
|
+
} else {
|
|
75
|
+
count += 4;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return count;
|
|
79
|
+
}
|
|
80
|
+
function getLengthDefault(string) {
|
|
81
|
+
var len = string.length;
|
|
82
|
+
var count = 0;
|
|
83
|
+
for (var i = 0; i < len; i++) {
|
|
84
|
+
count++;
|
|
85
|
+
if (string.charCodeAt(i) >> 8) {
|
|
86
|
+
count++;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return count;
|
|
90
|
+
}
|
|
91
|
+
export var getLength = function getLength(string, regular) {
|
|
92
|
+
if (!string || typeof string !== 'string') {
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
var count = 0;
|
|
96
|
+
if (typeof regular === 'string') {
|
|
97
|
+
regular = regular.toLowerCase();
|
|
98
|
+
if (regular === 'utf-16' || regular === 'utf16') {
|
|
99
|
+
count = getLengthInUtf16(string);
|
|
100
|
+
} else if (regular === 'utf-8' || regular === 'utf8') {
|
|
101
|
+
count = getLengthInUtf8(string);
|
|
102
|
+
} else {
|
|
103
|
+
count = string.replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g, '_').length;
|
|
104
|
+
}
|
|
105
|
+
} else if (typeof regular === 'function') {
|
|
106
|
+
return regular(string);
|
|
107
|
+
} else {
|
|
108
|
+
count = getLengthDefault(string);
|
|
109
|
+
}
|
|
110
|
+
return count;
|
|
111
|
+
};
|
|
112
|
+
export var fillChar = function fillChar(string, length, append) {
|
|
113
|
+
var chr = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '0';
|
|
114
|
+
if (typeof string === 'string' && typeof chr === 'string' && isNumber(length)) {
|
|
115
|
+
var len = string.length - length;
|
|
116
|
+
if (len > 0) {
|
|
117
|
+
return append ? string.substr(0, length) : string.substr(len, length);
|
|
118
|
+
} else {
|
|
119
|
+
var appendStr = [];
|
|
120
|
+
len = Math.abs(len) / chr.length;
|
|
121
|
+
for (; len > 0; len--) {
|
|
122
|
+
appendStr.push(chr);
|
|
123
|
+
}
|
|
124
|
+
var s = appendStr.join('');
|
|
125
|
+
return append ? string + s : s + string;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
export var random = nanoid.random;
|
|
130
|
+
export var guid = function guid() {
|
|
131
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
132
|
+
var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
|
|
133
|
+
return prefix + random().toString().substr(2, length);
|
|
134
|
+
};
|
|
135
|
+
export var escapeHtml = function escapeHtml(string, isReplaceSpace) {
|
|
136
|
+
if (!string || typeof string !== 'string') {
|
|
137
|
+
return string;
|
|
138
|
+
}
|
|
139
|
+
string = string.replace(/[&<>"']/g, function (chr) {
|
|
140
|
+
return escapeChars[chr];
|
|
141
|
+
});
|
|
142
|
+
return isReplaceSpace ? string.replace(/\s/g, ' ') : string;
|
|
143
|
+
};
|
|
144
|
+
export var escape = function escape(string, escapeType, isReplaceSpace) {
|
|
145
|
+
if (!string || typeof string !== 'string') {
|
|
146
|
+
return string;
|
|
147
|
+
}
|
|
148
|
+
if (typeof escapeType === 'boolean') {
|
|
149
|
+
isReplaceSpace = !!escapeType;
|
|
150
|
+
}
|
|
151
|
+
if (escapeType === 'uri') {
|
|
152
|
+
return encodeURIComponent(string);
|
|
153
|
+
} else if (escapeType === 'html') {
|
|
154
|
+
return escapeHtml(string, isReplaceSpace);
|
|
155
|
+
} else if (escapeType === 'prop') {
|
|
156
|
+
string = escapeHtml(string, isReplaceSpace);
|
|
157
|
+
return string.replace(/[[\]]/g, function (chr) {
|
|
158
|
+
return escapeChars[chr];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
string = string.replace(/[<>"]/g, function (chr) {
|
|
162
|
+
return escapeChars[chr];
|
|
163
|
+
});
|
|
164
|
+
return isReplaceSpace ? string.replace(/\s/g, ' ') : string;
|
|
165
|
+
};
|
|
166
|
+
var getFormat = function getFormat(_ref) {
|
|
167
|
+
var sign = _ref.sign,
|
|
168
|
+
format = _ref.format,
|
|
169
|
+
hasSign = _ref.hasSign;
|
|
170
|
+
switch (sign) {
|
|
171
|
+
case '#':
|
|
172
|
+
format = formatTypes.text;
|
|
173
|
+
break;
|
|
174
|
+
case '@':
|
|
175
|
+
format = formatTypes.url;
|
|
176
|
+
break;
|
|
177
|
+
case '$':
|
|
178
|
+
format = formatTypes.html;
|
|
179
|
+
break;
|
|
180
|
+
case '%':
|
|
181
|
+
format = formatTypes.tmpl;
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
hasSign = false;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
format: format,
|
|
189
|
+
hasSign: hasSign
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
export var fieldFormat = function fieldFormat(string, data) {
|
|
193
|
+
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'html';
|
|
194
|
+
if (typeof string === 'string') {
|
|
195
|
+
return string.replace(/(\/)?\{\{([\s\S]*?)}}/g, function (match) {
|
|
196
|
+
var slash = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
197
|
+
var offset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
198
|
+
var sign = offset.substr(0, 1);
|
|
199
|
+
var hasSign = true;
|
|
200
|
+
var format = formatTypes.html;
|
|
201
|
+
var ret = getFormat({
|
|
202
|
+
sign: sign,
|
|
203
|
+
format: format,
|
|
204
|
+
hasSign: hasSign
|
|
205
|
+
});
|
|
206
|
+
format = ret.format;
|
|
207
|
+
hasSign = ret.hasSign;
|
|
208
|
+
if (hasSign) {
|
|
209
|
+
offset = (offset || '').substring(1);
|
|
210
|
+
} else if (type) {
|
|
211
|
+
format = type;
|
|
212
|
+
}
|
|
213
|
+
var value = getObj(data, offset);
|
|
214
|
+
if (isNull(value)) {
|
|
215
|
+
value = '';
|
|
216
|
+
}
|
|
217
|
+
if (format === formatTypes.tmpl) {
|
|
218
|
+
value = "{{".concat(value, "}}");
|
|
219
|
+
} else {
|
|
220
|
+
if (format === formatTypes.url) {
|
|
221
|
+
value = encodeURIComponent(value);
|
|
222
|
+
} else {
|
|
223
|
+
value = format === formatTypes.html ? escapeHtml(value) : value;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return format === formatTypes.url && value.length === 0 ? '' : slash + value;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var getFormatText = function getFormatText() {
|
|
231
|
+
return function (str, reg, args, format) {
|
|
232
|
+
return str.replace(reg, function (m, i, j, k) {
|
|
233
|
+
if (!isNullOrEmpty(i) && !isNullOrEmpty(k)) {
|
|
234
|
+
return "{".concat(j, "}");
|
|
235
|
+
}
|
|
236
|
+
var value = args[j];
|
|
237
|
+
var string = isPlainObject(value) ? toJsonStr(value) : value;
|
|
238
|
+
if (isNullOrEmpty(value)) {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
return typeof value === 'string' && typeof format === 'function' ? format(string) : string;
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
var getResult = function getResult(_ref2) {
|
|
246
|
+
var type = _ref2.type,
|
|
247
|
+
res = _ref2.res,
|
|
248
|
+
formatText = _ref2.formatText,
|
|
249
|
+
string = _ref2.string,
|
|
250
|
+
reg = _ref2.reg,
|
|
251
|
+
args = _ref2.args;
|
|
252
|
+
if (type === formatTypes.url) {
|
|
253
|
+
res = formatText(string, reg, args, encodeURIComponent);
|
|
254
|
+
} else if (type === formatTypes.html) {
|
|
255
|
+
res = formatText(string, reg, args, escapeHtml);
|
|
256
|
+
} else {
|
|
257
|
+
res = formatText(string, reg, args);
|
|
258
|
+
}
|
|
259
|
+
return res;
|
|
260
|
+
};
|
|
261
|
+
var judgForFunc = function judgForFunc(args, formatTypes, type) {
|
|
262
|
+
var lastArg = args[args.length - 1];
|
|
263
|
+
if (lastArg !== formatTypes.text && lastArg !== formatTypes.url && lastArg !== formatTypes.html) {
|
|
264
|
+
args = Array.prototype.slice.call(args, 1);
|
|
265
|
+
} else {
|
|
266
|
+
args = Array.prototype.slice.call(args, 1, args.length - 1);
|
|
267
|
+
type = lastArg;
|
|
268
|
+
}
|
|
269
|
+
return {
|
|
270
|
+
args: args,
|
|
271
|
+
type: type
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
var checkParam = function checkParam(_ref3) {
|
|
275
|
+
var data = _ref3.data,
|
|
276
|
+
args = _ref3.args,
|
|
277
|
+
type = _ref3.type,
|
|
278
|
+
_arguments = _ref3._arguments;
|
|
279
|
+
if (Array.isArray(data)) {
|
|
280
|
+
args = data;
|
|
281
|
+
} else {
|
|
282
|
+
var judgObj = judgForFunc(_arguments, formatTypes, type);
|
|
283
|
+
args = judgObj.args;
|
|
284
|
+
type = judgObj.type;
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
args: args,
|
|
288
|
+
type: type
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
export var format = function format(string, data) {
|
|
292
|
+
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'text';
|
|
293
|
+
if (typeof string !== 'string' || arguments.length < 2) {
|
|
294
|
+
return string;
|
|
295
|
+
}
|
|
296
|
+
var args, res;
|
|
297
|
+
if (isPlainObject(data)) {
|
|
298
|
+
return fieldFormat(string, data, type);
|
|
299
|
+
}
|
|
300
|
+
var ret = checkParam({
|
|
301
|
+
data: data,
|
|
302
|
+
args: args,
|
|
303
|
+
type: type,
|
|
304
|
+
_arguments: arguments
|
|
305
|
+
});
|
|
306
|
+
args = ret.args;
|
|
307
|
+
type = ret.type;
|
|
308
|
+
var reg = /(\\)?\{(\d+)(\\)?}/g;
|
|
309
|
+
var formatText = getFormatText();
|
|
310
|
+
res = getResult({
|
|
311
|
+
type: type,
|
|
312
|
+
res: res,
|
|
313
|
+
formatText: formatText,
|
|
314
|
+
string: string,
|
|
315
|
+
reg: reg,
|
|
316
|
+
args: args
|
|
317
|
+
});
|
|
318
|
+
return res;
|
|
319
|
+
};
|
|
320
|
+
var getTruthyValue = function getTruthyValue(_ref4) {
|
|
321
|
+
var string = _ref4.string,
|
|
322
|
+
length = _ref4.length,
|
|
323
|
+
ellipsis = _ref4.ellipsis;
|
|
324
|
+
var flag = typeof string === 'string' && isNumber(length) && length < string.length;
|
|
325
|
+
var truthyValue = flag && format(ellipsis, string.substr(0, length));
|
|
326
|
+
return {
|
|
327
|
+
flag: flag,
|
|
328
|
+
truthyValue: truthyValue
|
|
329
|
+
};
|
|
330
|
+
};
|
|
331
|
+
export var truncate = function truncate(string, length) {
|
|
332
|
+
var ellipsis = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '{0}...';
|
|
333
|
+
var _getTruthyValue = getTruthyValue({
|
|
334
|
+
string: string,
|
|
335
|
+
length: length,
|
|
336
|
+
ellipsis: ellipsis
|
|
337
|
+
}),
|
|
338
|
+
flag = _getTruthyValue.flag,
|
|
339
|
+
truthyValue = _getTruthyValue.truthyValue;
|
|
340
|
+
return flag ? truthyValue : string;
|
|
341
|
+
};
|
|
342
|
+
export var tryToConvert = function tryToConvert(convert, defaultValue) {
|
|
343
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
344
|
+
args[_key - 2] = arguments[_key];
|
|
345
|
+
}
|
|
346
|
+
var result = convert.apply(null, args);
|
|
347
|
+
return isNaN(result) ? defaultValue : result;
|
|
348
|
+
};
|
|
349
|
+
export var toInt = function toInt(value) {
|
|
350
|
+
return isNumber(value) ? Number(value.toFixed(0)) : typeof value === 'string' ? parseInt(value, 10) : NaN;
|
|
351
|
+
};
|
|
352
|
+
export var tryToInt = function tryToInt(value, defaultValue) {
|
|
353
|
+
return tryToConvert(toInt, defaultValue, value);
|
|
354
|
+
};
|
|
355
|
+
export var toNumber = function toNumber(value) {
|
|
356
|
+
return isNumber(value) ? value : typeof value === 'string' ? parseFloat(value) : NaN;
|
|
357
|
+
};
|
|
358
|
+
export var tryToNumber = function tryToNumber(value, defaultValue) {
|
|
359
|
+
return tryToConvert(toNumber, defaultValue, value);
|
|
360
|
+
};
|
|
361
|
+
export var toDecimal = function toDecimal(value) {
|
|
362
|
+
var fraction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
363
|
+
var isTruncate = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
364
|
+
var result = NaN;
|
|
365
|
+
if (isNumber(value)) {
|
|
366
|
+
result = value;
|
|
367
|
+
}
|
|
368
|
+
if (typeof value === 'string') {
|
|
369
|
+
var val = parseFloat(value);
|
|
370
|
+
if (!isNaN(val)) {
|
|
371
|
+
result = val;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
if (isNumber(result)) {
|
|
375
|
+
if (isTruncate) {
|
|
376
|
+
result = toFixed(value.toString().split('.').slice(0, 2).map(function (str, index) {
|
|
377
|
+
return index ? str.slice(0, fraction) : str;
|
|
378
|
+
}).join('.'), fraction);
|
|
379
|
+
} else {
|
|
380
|
+
result = toFixed(result, fraction);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
return result;
|
|
384
|
+
};
|
|
385
|
+
export var tryToDecimal = function tryToDecimal(value, fraction, isTruncate, defaultValue) {
|
|
386
|
+
return tryToConvert(toDecimal, defaultValue, value, fraction, isTruncate);
|
|
387
|
+
};
|
|
388
|
+
export var toCurrency = function toCurrency(value, fraction, placeholder, isTruncate) {
|
|
389
|
+
if (isNumeric(value)) {
|
|
390
|
+
var val = toDecimal(Number(value), fraction, isTruncate);
|
|
391
|
+
val = String(val).replace(/(^|[^\w.])(\d{4,})/g, function ($0, $1, $2) {
|
|
392
|
+
return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, '$&,');
|
|
393
|
+
});
|
|
394
|
+
return placeholder ? format(placeholder, val) : val;
|
|
395
|
+
}
|
|
396
|
+
return NaN;
|
|
397
|
+
};
|
|
398
|
+
export var tryToCurrency = function tryToCurrency(value, fraction, placeholder, defaultValue) {
|
|
399
|
+
return isNaN(toNumber(value)) ? defaultValue : toCurrency(value, fraction, placeholder);
|
|
400
|
+
};
|
|
401
|
+
export var toBoolValue = function toBoolValue(value) {
|
|
402
|
+
if (isNumber(value)) {
|
|
403
|
+
return value ? 1 : 0;
|
|
404
|
+
} else if (isNull(value) || value === 'false') {
|
|
405
|
+
return false;
|
|
406
|
+
} else if (value === 'true') {
|
|
407
|
+
return true;
|
|
408
|
+
} else if (typeof value === 'boolean') {
|
|
409
|
+
return value;
|
|
410
|
+
}
|
|
411
|
+
return !!value;
|
|
412
|
+
};
|
|
413
|
+
export var toRate = function toRate(value) {
|
|
414
|
+
var total = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
415
|
+
var fraction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
|
416
|
+
return isNumber(value) && isNumber(total) ? "".concat(toDecimal(value * 100 / total, fraction), "%") : value;
|
|
417
|
+
};
|
|
418
|
+
export var toFileSize = function toFileSize(value, unit, currUnit) {
|
|
419
|
+
if (isNumeric(value)) {
|
|
420
|
+
value = Number(value);
|
|
421
|
+
if (value === 0) {
|
|
422
|
+
return "0".concat(currUnit || unit || 'B');
|
|
423
|
+
}
|
|
424
|
+
var fileSize = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
425
|
+
var index = fileSize.indexOf(currUnit);
|
|
426
|
+
if (index > -1) {
|
|
427
|
+
for (var i = 0; i < index; i++) {
|
|
428
|
+
value *= 1024;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
index = fileSize.indexOf(unit);
|
|
432
|
+
if (index < 0) {
|
|
433
|
+
index = fileSize.length - 1;
|
|
434
|
+
}
|
|
435
|
+
var level = 0;
|
|
436
|
+
for (var _i = 0; _i < index && (value <= -1024 || value >= 1024); _i++) {
|
|
437
|
+
value /= 1024.0;
|
|
438
|
+
level++;
|
|
439
|
+
}
|
|
440
|
+
return toDecimal(value, 2) + fileSize[level];
|
|
441
|
+
}
|
|
442
|
+
return value;
|
|
443
|
+
};
|
|
444
|
+
export var isKorean = function isKorean(text) {
|
|
445
|
+
return /([(\uAC00-\uD7AF)|(\u3130-\u318F)])+/gi.test(text);
|
|
446
|
+
};
|
package/common/type.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export var toString = Object.prototype.toString;
|
|
2
|
+
export var hasOwn = Object.prototype.hasOwnProperty;
|
|
3
|
+
var getProto = Object.getPrototypeOf;
|
|
4
|
+
var fnToString = hasOwn.toString;
|
|
5
|
+
var ObjectFunctionString = fnToString.call(Object);
|
|
6
|
+
var class2type = {
|
|
7
|
+
'[object Error]': 'error',
|
|
8
|
+
'[object Object]': 'object',
|
|
9
|
+
'[object RegExp]': 'regExp',
|
|
10
|
+
'[object Date]': 'date',
|
|
11
|
+
'[object Array]': 'array',
|
|
12
|
+
'[object Function]': 'function',
|
|
13
|
+
'[object String]': 'string',
|
|
14
|
+
'[object Number]': 'number',
|
|
15
|
+
'[object Boolean]': 'boolean'
|
|
16
|
+
};
|
|
17
|
+
export var isNull = function isNull(x) {
|
|
18
|
+
return x === null || x === undefined || x === 'undefined';
|
|
19
|
+
};
|
|
20
|
+
export var typeOf = function typeOf(obj) {
|
|
21
|
+
return isNull(obj) ? String(obj) : class2type[toString.call(obj)] || 'object';
|
|
22
|
+
};
|
|
23
|
+
export var isObject = function isObject(obj) {
|
|
24
|
+
return typeOf(obj) === 'object';
|
|
25
|
+
};
|
|
26
|
+
export var isFunction = function isFunction(fn) {
|
|
27
|
+
return typeOf(fn) === 'function';
|
|
28
|
+
};
|
|
29
|
+
export var isPlainObject = function isPlainObject(obj) {
|
|
30
|
+
if (!obj || toString.call(obj) !== '[object Object]') {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
var proto = getProto(obj);
|
|
34
|
+
if (!proto) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
var Ctor = hasOwn.call(proto, 'constructor') && proto.constructor;
|
|
38
|
+
return typeof Ctor === 'function' && fnToString.call(Ctor) === ObjectFunctionString;
|
|
39
|
+
};
|
|
40
|
+
export var isEmptyObject = function isEmptyObject(obj) {
|
|
41
|
+
var type = typeOf(obj);
|
|
42
|
+
if (type === 'object' || type === 'array') {
|
|
43
|
+
for (var name in obj) {
|
|
44
|
+
if (hasOwn.call(obj, name)) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
export var isNumber = function isNumber(value) {
|
|
52
|
+
return typeof value === 'number' && isFinite(value);
|
|
53
|
+
};
|
|
54
|
+
export var isNumeric = function isNumeric(value) {
|
|
55
|
+
return value - parseFloat(value) >= 0;
|
|
56
|
+
};
|
|
57
|
+
export var isDate = function isDate(value) {
|
|
58
|
+
return typeOf(value) === 'date';
|
|
59
|
+
};
|
|
60
|
+
export var isSame = function isSame(x, y) {
|
|
61
|
+
return x === y || typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y);
|
|
62
|
+
};
|
|
63
|
+
export var isRegExp = function isRegExp(value) {
|
|
64
|
+
return typeOf(value) === 'regExp';
|
|
65
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
var getTypesObj = function getTypesObj(translate) {
|
|
2
|
+
return {
|
|
3
|
+
string: translate('validation.types.string'),
|
|
4
|
+
method: translate('validation.types.method'),
|
|
5
|
+
array: translate('validation.types.array'),
|
|
6
|
+
object: translate('validation.types.object'),
|
|
7
|
+
number: translate('validation.types.number'),
|
|
8
|
+
date: translate('validation.types.date'),
|
|
9
|
+
"boolean": translate('validation.types.boolean'),
|
|
10
|
+
integer: translate('validation.types.integer'),
|
|
11
|
+
"float": translate('validation.types.float'),
|
|
12
|
+
regexp: translate('validation.types.regexp'),
|
|
13
|
+
email: translate('validation.types.email'),
|
|
14
|
+
url: translate('validation.types.url'),
|
|
15
|
+
hex: translate('validation.types.hex'),
|
|
16
|
+
digits: translate('validation.types.digits'),
|
|
17
|
+
time: translate('validation.types.time'),
|
|
18
|
+
dateYM: translate('validation.types.dateYM'),
|
|
19
|
+
dateYMD: translate('validation.types.dateYMD'),
|
|
20
|
+
dateTime: translate('validation.types.dateTime'),
|
|
21
|
+
longDateTime: translate('validation.types.longDateTime'),
|
|
22
|
+
version: translate('validation.types.version'),
|
|
23
|
+
speczh: translate('validation.types.speczh'),
|
|
24
|
+
specialch: translate('validation.types.specialch'),
|
|
25
|
+
specialch2: translate('validation.types.hex'),
|
|
26
|
+
acceptImg: translate('validation.types.acceptImg'),
|
|
27
|
+
acceptFile: translate('validation.types.acceptFile'),
|
|
28
|
+
fileSize: translate('validation.types.fileSize')
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default (function () {
|
|
32
|
+
var translate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function (value) {
|
|
33
|
+
return value;
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
"default": translate('validation.default'),
|
|
37
|
+
required: translate('validation.required'),
|
|
38
|
+
"enum": translate('validation.enum'),
|
|
39
|
+
whitespace: translate('validation.whitespace'),
|
|
40
|
+
date: {
|
|
41
|
+
format: translate('validation.date.format'),
|
|
42
|
+
parse: translate('validation.date.parse'),
|
|
43
|
+
invalid: translate('validation.date.invalid')
|
|
44
|
+
},
|
|
45
|
+
types: getTypesObj(translate),
|
|
46
|
+
string: {
|
|
47
|
+
len: translate('validation.string.len'),
|
|
48
|
+
min: translate('validation.string.min'),
|
|
49
|
+
max: translate('validation.string.max'),
|
|
50
|
+
range: translate('validation.string.range')
|
|
51
|
+
},
|
|
52
|
+
number: {
|
|
53
|
+
len: translate('validation.number.len'),
|
|
54
|
+
min: translate('validation.number.min'),
|
|
55
|
+
max: translate('validation.number.max'),
|
|
56
|
+
range: translate('validation.number.range')
|
|
57
|
+
},
|
|
58
|
+
array: {
|
|
59
|
+
len: translate('validation.array.len'),
|
|
60
|
+
min: translate('validation.array.min'),
|
|
61
|
+
max: translate('validation.array.max'),
|
|
62
|
+
range: translate('validation.array.range')
|
|
63
|
+
},
|
|
64
|
+
pattern: {
|
|
65
|
+
mismatch: translate('validation.pattern.mismatch')
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as util from '../util';
|
|
2
|
+
var ENUM = 'enum';
|
|
3
|
+
export default function (rule, checkValue, source, errors, options) {
|
|
4
|
+
rule[ENUM] = Array.isArray(rule[ENUM]) ? rule[ENUM] : [];
|
|
5
|
+
if (rule[ENUM].indexOf(checkValue) === -1) {
|
|
6
|
+
errors.push(util.format(options.messages[ENUM], rule.fullField, rule[ENUM].join(', ')));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type from './type';
|
|
2
|
+
import range from './range';
|
|
3
|
+
import enumRule from './enum';
|
|
4
|
+
import pattern from './pattern';
|
|
5
|
+
import required from './required';
|
|
6
|
+
import whitespace from './whitespace';
|
|
7
|
+
export default {
|
|
8
|
+
type: type,
|
|
9
|
+
range: range,
|
|
10
|
+
pattern: pattern,
|
|
11
|
+
required: required,
|
|
12
|
+
whitespace: whitespace,
|
|
13
|
+
"enum": enumRule
|
|
14
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as util from '../util';
|
|
2
|
+
export default function (rule, checkValue, source, errors, options) {
|
|
3
|
+
if (rule.pattern) {
|
|
4
|
+
if (rule.pattern instanceof RegExp) {
|
|
5
|
+
rule.pattern.lastIndex = 0;
|
|
6
|
+
if (!rule.pattern.test(checkValue)) {
|
|
7
|
+
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, checkValue, rule.pattern));
|
|
8
|
+
}
|
|
9
|
+
} else if (typeof rule.pattern === 'string') {
|
|
10
|
+
var _pattern = new RegExp(rule.pattern);
|
|
11
|
+
if (!_pattern.test(checkValue)) {
|
|
12
|
+
errors.push(util.format(options.messages.pattern.mismatch, rule.fullField, checkValue, rule.pattern));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as util from '../util';
|
|
2
|
+
import { isNumber } from '@opentiny/vue-renderless/common/type';
|
|
3
|
+
import { getLength } from '@opentiny/vue-renderless/common/string';
|
|
4
|
+
function getErro(_ref) {
|
|
5
|
+
var min = _ref.min,
|
|
6
|
+
max = _ref.max,
|
|
7
|
+
val = _ref.val,
|
|
8
|
+
key = _ref.key,
|
|
9
|
+
rule = _ref.rule,
|
|
10
|
+
errors = _ref.errors,
|
|
11
|
+
util = _ref.util,
|
|
12
|
+
options = _ref.options;
|
|
13
|
+
if (min && !max && val < rule.min) {
|
|
14
|
+
errors.push(util.format(options.messages[key].min, rule.fullField, rule.min));
|
|
15
|
+
} else if (max && !min && val > rule.max) {
|
|
16
|
+
errors.push(util.format(options.messages[key].max, rule.fullField, rule.max));
|
|
17
|
+
} else if (min && max && (val < rule.min || val > rule.max)) {
|
|
18
|
+
errors.push(util.format(options.messages[key].range, rule.fullField, rule.min, rule.max));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export default function (rule, checkValue, source, errors, options) {
|
|
22
|
+
var len = isNumber(rule.len);
|
|
23
|
+
var min = isNumber(rule.min);
|
|
24
|
+
var max = isNumber(rule.max);
|
|
25
|
+
var val = checkValue;
|
|
26
|
+
var key = null;
|
|
27
|
+
var num = isNumber(checkValue);
|
|
28
|
+
var str = typeof checkValue === 'string';
|
|
29
|
+
var arr = Array.isArray(checkValue);
|
|
30
|
+
if (num) {
|
|
31
|
+
key = 'number';
|
|
32
|
+
} else if (str) {
|
|
33
|
+
key = 'string';
|
|
34
|
+
} else if (arr) {
|
|
35
|
+
key = 'array';
|
|
36
|
+
}
|
|
37
|
+
if (!key) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (arr) {
|
|
41
|
+
val = checkValue.length;
|
|
42
|
+
}
|
|
43
|
+
if (str) {
|
|
44
|
+
val = getLength(checkValue, 'string');
|
|
45
|
+
}
|
|
46
|
+
if (len) {
|
|
47
|
+
if (val !== rule.len) {
|
|
48
|
+
errors.push(util.format(options.messages[key].len, rule.fullField, rule.len));
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
getErro({
|
|
52
|
+
min: min,
|
|
53
|
+
max: max,
|
|
54
|
+
val: val,
|
|
55
|
+
key: key,
|
|
56
|
+
rule: rule,
|
|
57
|
+
errors: errors,
|
|
58
|
+
util: util,
|
|
59
|
+
options: options
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|