@opentiny/vue-renderless 3.21.2 → 3.23.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/amount/index.js +4 -4
- package/anchor/index.js +1 -1
- package/async-flowchart/index.js +1 -1
- package/autocomplete/index.js +4 -1
- package/autocomplete/vue.js +3 -3
- package/base-select/index.js +20 -21
- package/base-select/vue.js +2 -2
- package/calendar/index.js +2 -2
- package/calendar-bar/index.js +2 -2
- package/calendar-bar/vue.js +1 -1
- package/calendar-view/index.js +91 -25
- package/calendar-view/vue.js +6 -4
- package/card/index.js +1 -1
- package/card-template/index.js +1 -1
- package/carousel/index.js +4 -4
- package/carousel/vue.js +1 -1
- package/cascader/index.js +21 -11
- package/cascader/vue.js +6 -5
- package/cascader-menu/vue.js +2 -2
- package/cascader-mobile/index.js +1 -1
- package/cascader-node/vue.js +11 -1
- package/cascader-panel/index.js +4 -4
- package/cascader-panel/node.js +3 -4
- package/cascader-panel/vue.js +1 -1
- package/cascader-select/column-index.js +2 -2
- package/cascader-view/index.js +1 -1
- package/chart-bar/index.js +1 -1
- package/chart-candle/index.js +1 -1
- package/chart-core/deps/utils.js +6 -6
- package/chart-core/index.js +1 -1
- package/chart-funnel/index.js +1 -1
- package/chart-gauge/index.js +1 -1
- package/chart-line/index.js +1 -1
- package/chart-map/index.js +1 -1
- package/chart-pie/index.js +1 -1
- package/chart-radar/index.js +1 -1
- package/chart-sankey/index.js +1 -1
- package/chart-scatter/index.js +1 -1
- package/chart-waterfall/index.js +1 -1
- package/chart-wordcloud/index.js +1 -1
- package/checkbox/index.js +1 -1
- package/collapse-item/vue.js +1 -1
- package/column-list-item/index.js +1 -1
- package/common/deps/dom.js +20 -196
- package/common/deps/infinite-scroll.js +4 -43
- package/common/deps/popup-manager.js +1 -200
- package/container/index.js +2 -2
- package/crop/index.js +3 -3
- package/currency/index.js +2 -2
- package/date-panel/index.js +82 -26
- package/date-panel/vue.js +53 -21
- package/date-picker/vue.js +1 -1
- package/date-picker-mobile/index.js +1 -1
- package/date-range/index.js +74 -37
- package/date-range/vue.js +27 -23
- package/date-table/index.js +8 -5
- package/date-table/vue.js +1 -1
- package/dialog-box/index.js +3 -3
- package/dialog-box/vue.js +1 -1
- package/dialog-select/index.js +15 -4
- package/dialog-select/vue.js +7 -4
- package/drawer/index.js +2 -2
- package/drop-times/index.js +1 -1
- package/dropdown/index.js +11 -3
- package/dropdown/vue.js +2 -2
- package/dropdown-item/index.js +1 -1
- package/dropdown-item/mf.js +1 -1
- package/dropdown-menu/index.js +1 -1
- package/espace/vue.js +2 -2
- package/fall-menu/index.js +3 -3
- package/file-upload/index.js +16 -13
- package/file-upload/vue.js +2 -2
- package/filter/vue.js +1 -1
- package/filter-panel/vue.js +1 -2
- package/floating-button/index.js +1 -1
- package/flowchart/index.js +3 -3
- package/flowchart/vue.js +1 -1
- package/fluent-editor/index.js +5 -7
- package/fluent-editor/options.js +2 -2
- package/form/index.js +20 -2
- package/form-item/index.js +6 -6
- package/fullscreen/index.js +1 -1
- package/fullscreen/vue.js +1 -1
- package/grid/plugins/export.js +8 -2
- package/grid/plugins/exportExcel.js +3 -3
- package/grid/plugins/resize.js +2 -2
- package/grid/static/base/helperEqualCompare.js +1 -1
- package/grid/static/base/isPlainObject.js +1 -1
- package/grid/utils/common.js +2 -2
- package/grid/utils/dom.js +12 -7
- package/grid/utils/event.js +4 -4
- package/hrapprover/index.js +1 -1
- package/image/index.js +3 -3
- package/image-viewer/index.js +4 -6
- package/image-viewer/vue.js +1 -1
- package/input/index.js +2 -2
- package/input/vue.js +1 -1
- package/ip-address/index.js +17 -21
- package/ip-address/vue.js +1 -1
- package/link-menu/index.js +1 -1
- package/link-menu/vue.js +1 -1
- package/load-list/index.js +1 -1
- package/load-list/vue.js +4 -4
- package/loading/index.js +2 -2
- package/menu/vue.js +1 -1
- package/milestone/index.js +6 -45
- package/modal/index.js +5 -5
- package/month-range/index.js +48 -5
- package/month-range/vue.js +19 -15
- package/month-table/index.js +5 -5
- package/month-table/vue.js +1 -1
- package/nav-menu/index.js +7 -7
- package/notify/index.js +3 -3
- package/number-animation/index.js +53 -0
- package/number-animation/vue.js +27 -0
- package/numeric/index.js +5 -5
- package/option/index.js +1 -1
- package/option/vue.js +2 -1
- package/package.json +3 -2
- package/pager/index.js +28 -16
- package/pager/vue.js +27 -16
- package/panel/index.js +1 -1
- package/picker/index.js +28 -23
- package/picker/vue.js +6 -6
- package/picker-column/index.js +1 -1
- package/pop-upload/vue.js +1 -1
- package/popconfirm/vue.js +1 -1
- package/popeditor/index.js +6 -6
- package/popeditor/vue.js +2 -2
- package/popover/index.js +3 -3
- package/popover/vue.js +1 -1
- package/popup/index.js +3 -3
- package/pull-refresh/index.js +1 -1
- package/pull-refresh-mobile-first/index.js +1 -1
- package/pull-refresh-mobile-first/vue.js +4 -4
- package/quarter-panel/index.js +2 -2
- package/quarter-panel/vue.js +1 -1
- package/radio-group/index.js +1 -1
- package/rate/index.js +1 -1
- package/rate/vue.js +1 -1
- package/recycle-scroller/index.js +2 -2
- package/recycle-scroller/vue.js +1 -1
- package/rich-text/index.js +1 -1
- package/rich-text/table-module.js +2 -2
- package/river/river.js +1 -1
- package/river/vue.js +1 -1
- package/scrollbar/vue-bar.js +1 -1
- package/scrollbar/vue.js +1 -1
- package/search/index.js +3 -3
- package/select/index.js +26 -22
- package/select/vue.js +8 -7
- package/select-dropdown/vue.js +5 -5
- package/selected-box/index.js +1 -1
- package/signature/index.js +1 -1
- package/signature/vue.js +2 -2
- package/skeleton/index.js +1 -1
- package/slider/index.js +4 -4
- package/slider-button-group/slide-button.js +2 -2
- package/split/index.js +2 -2
- package/split/vue.js +1 -1
- package/statistic/index.js +1 -1
- package/steps/index.js +2 -3
- package/steps/slide-bar.js +2 -2
- package/sticky/vue.js +4 -4
- package/tab-bar/index.js +2 -2
- package/tab-item-mf/vue.js +1 -1
- package/tab-nav/index.js +4 -4
- package/tabbar/index.js +1 -1
- package/tabbar/vue.js +1 -1
- package/tabbar-item/index.js +1 -1
- package/tabs-mf/index.js +9 -5
- package/tabs-mf/vue-bar.js +5 -4
- package/tabs-mf/vue-swipe.js +1 -1
- package/tabs-mf/vue.js +2 -2
- package/tabs-mf/wheel.js +3 -3
- package/tag-group/vue.js +2 -2
- package/tall-storage/index.js +1 -1
- package/tall-storage/vue.js +1 -1
- package/time/index.js +1 -1
- package/time/vue.js +1 -1
- package/time-line/index.js +1 -1
- package/time-line-new/index.js +1 -1
- package/time-panel/index.js +2 -2
- package/time-panel/vue.js +1 -1
- package/time-range/index.js +1 -1
- package/time-range/vue.js +1 -1
- package/time-spinner/index.js +4 -4
- package/time-spinner/vue.js +1 -1
- package/timeline-item/index.js +1 -1
- package/toggle-menu/index.js +1 -1
- package/tooltip/index.js +2 -2
- package/tooltip/vue.js +2 -2
- package/top-box/index.js +3 -3
- package/transfer/index.js +42 -1
- package/transfer/vue.js +64 -24
- package/transfer-panel/index.js +6 -1
- package/tree/index.js +9 -9
- package/tree/vue.js +2 -2
- package/tree-node/index.js +1 -1
- package/tree-node/vue.js +1 -1
- package/tree-select/index.js +68 -22
- package/tree-select/vue.js +27 -3
- package/types/async-flowchart.type.d.ts +2 -14
- package/types/breadcrumb-item.type.d.ts +5 -1
- package/types/breadcrumb.type.d.ts +5 -1
- package/types/button-group.type.d.ts +5 -1
- package/types/button.type.d.ts +2 -2
- package/types/cascader.type.d.ts +6 -1
- package/types/date-table.type.d.ts +1 -120
- package/types/dropdown.type.d.ts +1 -1
- package/types/label.type.d.ts +1 -53
- package/types/loading.type.d.ts +12 -0
- package/types/numeric.type.d.ts +3 -22
- package/types/pager.type.d.ts +12 -7
- package/types/popconfirm.type.d.ts +2 -0
- package/types/steps.type.d.ts +1 -0
- package/types/tag-group.type.d.ts +2 -14
- package/types/tag.type.d.ts +4 -4
- package/types/tooltip.type.d.ts +3 -13
- package/types/transfer.type.d.ts +3 -0
- package/types/user-head.type.d.ts +0 -4
- package/upload/index.js +1 -1
- package/upload-list/index.js +1 -1
- package/upload-list/vue.js +4 -4
- package/user/index.js +7 -7
- package/user/vue.js +15 -2
- package/user-contact/vue.js +2 -2
- package/virtual-scroll-box/index.js +2 -2
- package/wizard/index.js +3 -3
- package/year-range/index.js +61 -11
- package/year-range/vue.js +33 -20
- package/year-table/index.js +10 -5
- package/avatar/index.js +0 -30
- package/avatar/vue.js +0 -22
- package/common/array.js +0 -115
- package/common/bigInt.js +0 -315
- package/common/browser.js +0 -81
- package/common/calendar/calendar.js +0 -97
- package/common/dataset/index.js +0 -99
- package/common/date.js +0 -354
- package/common/decimal.js +0 -155
- package/common/deps/ResizeObserver.js +0 -456
- package/common/deps/after-leave.js +0 -27
- package/common/deps/clickoutside.js +0 -75
- package/common/deps/date-util.js +0 -255
- package/common/deps/date.js +0 -286
- package/common/deps/debounce.js +0 -8
- package/common/deps/eSpaceCtrl.js +0 -304
- package/common/deps/fastdom/async.js +0 -41
- package/common/deps/fastdom/index.js +0 -9
- package/common/deps/fastdom/sandbox.js +0 -53
- package/common/deps/fastdom/singleton.js +0 -88
- package/common/deps/fullscreen/apis.js +0 -143
- package/common/deps/fullscreen/screenfull.js +0 -165
- package/common/deps/memorize.js +0 -124
- package/common/deps/observe-visibility.js +0 -106
- package/common/deps/popper.js +0 -616
- package/common/deps/repeat-click.js +0 -29
- package/common/deps/resize-event.js +0 -39
- package/common/deps/scroll-into-view.js +0 -29
- package/common/deps/scrollbar-width.js +0 -33
- package/common/deps/throttle.js +0 -45
- package/common/deps/touch-emulator.js +0 -103
- package/common/deps/touch.js +0 -37
- package/common/deps/tree-model/node.js +0 -475
- package/common/deps/tree-model/tree-store.js +0 -312
- package/common/deps/tree-model/util.js +0 -24
- package/common/deps/upload-ajax.js +0 -81
- package/common/deps/useEventListener.js +0 -54
- package/common/deps/useInstanceSlots.js +0 -22
- package/common/deps/useRect.js +0 -25
- package/common/deps/useRelation.js +0 -89
- package/common/deps/useTouch.js +0 -68
- package/common/deps/useUserAgent.js +0 -16
- package/common/deps/useWindowSize.js +0 -23
- package/common/deps/vue-emitter.js +0 -34
- package/common/deps/vue-popper.js +0 -180
- package/common/deps/vue-popup.js +0 -138
- package/common/event.js +0 -46
- package/common/form/const.js +0 -10
- package/common/function.js +0 -28
- package/common/global.js +0 -11
- package/common/index.js +0 -259
- package/common/object.js +0 -227
- package/common/prop-util.js +0 -43
- package/common/runtime.js +0 -79
- package/common/string.js +0 -417
- package/common/type.js +0 -66
- package/common/validate/index.js +0 -10
- package/common/validate/messages.js +0 -65
- package/common/validate/rules/enum.js +0 -12
- package/common/validate/rules/index.js +0 -18
- package/common/validate/rules/pattern.js +0 -20
- package/common/validate/rules/range.js +0 -52
- package/common/validate/rules/required.js +0 -11
- package/common/validate/rules/type.js +0 -100
- package/common/validate/rules/whitespace.js +0 -10
- package/common/validate/schema.js +0 -290
- package/common/validate/util.js +0 -211
- package/common/validate/validations/array.js +0 -22
- package/common/validate/validations/date.js +0 -31
- package/common/validate/validations/enum.js +0 -22
- package/common/validate/validations/float.js +0 -22
- package/common/validate/validations/index.js +0 -46
- package/common/validate/validations/integer.js +0 -22
- package/common/validate/validations/method.js +0 -21
- package/common/validate/validations/number.js +0 -25
- package/common/validate/validations/pattern.js +0 -21
- package/common/validate/validations/required.js +0 -11
- package/common/validate/validations/string.js +0 -33
- package/common/validate/validations/type.js +0 -29
- package/index-bar/index.js +0 -66
- package/index-bar/vue.js +0 -73
- package/index-bar-anchor/vue.js +0 -16
- package/label/index.js +0 -56
- package/label/vue.js +0 -26
- package/list/index.js +0 -13
- package/list/vue.js +0 -17
- package/mask/index.js +0 -13
- package/mask/vue.js +0 -18
- package/mini-picker/index.js +0 -165
- package/mini-picker/vue.js +0 -122
- package/multi-select/index.js +0 -394
- package/multi-select/vue.js +0 -113
- package/multi-select-item/index.js +0 -23
- package/multi-select-item/vue.js +0 -31
- package/toast/index.js +0 -7
- package/toast/vue.js +0 -19
- package/types/toast.type.d.ts +0 -63
- package/wheel/index.js +0 -165
- package/wheel/vue.js +0 -79
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import "../../chunk-G2ADBYYC.js";
|
|
2
|
-
import { isLeapYear } from "../date";
|
|
3
|
-
const getDays = (year, month) => {
|
|
4
|
-
return [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1];
|
|
5
|
-
};
|
|
6
|
-
const getWeek = (year, month, day) => (/* @__PURE__ */ new Date(`${year}/${month}/${day}`)).getDay();
|
|
7
|
-
const lastMonth = (year, month) => {
|
|
8
|
-
year = +year;
|
|
9
|
-
month = +month;
|
|
10
|
-
if (month === 1) {
|
|
11
|
-
year--;
|
|
12
|
-
month = 12;
|
|
13
|
-
} else {
|
|
14
|
-
month--;
|
|
15
|
-
}
|
|
16
|
-
return { year, month };
|
|
17
|
-
};
|
|
18
|
-
const nextMonth = (year, month) => {
|
|
19
|
-
year = +year;
|
|
20
|
-
month = +month;
|
|
21
|
-
if (month === 12) {
|
|
22
|
-
year++;
|
|
23
|
-
month = 1;
|
|
24
|
-
} else {
|
|
25
|
-
month++;
|
|
26
|
-
}
|
|
27
|
-
return { year, month };
|
|
28
|
-
};
|
|
29
|
-
const getCalendar = (year, month) => {
|
|
30
|
-
if (year && month && month <= 12) {
|
|
31
|
-
const days = getDays(year, month);
|
|
32
|
-
const firstWeek = getWeek(year, month, 1);
|
|
33
|
-
const lastWeek = getWeek(year, month, days);
|
|
34
|
-
const last = lastMonth(year, month);
|
|
35
|
-
const next = nextMonth(year, month);
|
|
36
|
-
const lastDays = getDays(last.year, last.month);
|
|
37
|
-
let remainDays = 0;
|
|
38
|
-
const totalDays = days + firstWeek + 7 - lastWeek - 1;
|
|
39
|
-
if (totalDays / 7 < 6 && totalDays / 7 >= 5) {
|
|
40
|
-
remainDays = 6 * 7 - totalDays;
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
last: {
|
|
44
|
-
year: last.year,
|
|
45
|
-
month: last.month,
|
|
46
|
-
start: lastDays - (firstWeek - 1),
|
|
47
|
-
end: lastDays
|
|
48
|
-
},
|
|
49
|
-
current: {
|
|
50
|
-
year,
|
|
51
|
-
month,
|
|
52
|
-
start: 1,
|
|
53
|
-
end: days
|
|
54
|
-
},
|
|
55
|
-
next: {
|
|
56
|
-
year: next.year,
|
|
57
|
-
month: next.month,
|
|
58
|
-
start: 1,
|
|
59
|
-
end: 7 - lastWeek - 1 + remainDays
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
const transformArray = (array) => {
|
|
65
|
-
const result = [];
|
|
66
|
-
let index = 0;
|
|
67
|
-
if (array && array.length) {
|
|
68
|
-
const length = array.length / 7;
|
|
69
|
-
for (let i = 0; i < length; i++) {
|
|
70
|
-
result[i] = [];
|
|
71
|
-
for (let j = 0; j < 7; j++) {
|
|
72
|
-
result[i][j] = array[index++];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
};
|
|
78
|
-
const parseDate = (time) => {
|
|
79
|
-
const date = new Date(time && typeof time === "number" ? time : 0);
|
|
80
|
-
return {
|
|
81
|
-
year: date.getFullYear(),
|
|
82
|
-
month: date.getMonth() + 1,
|
|
83
|
-
day: date.getDate(),
|
|
84
|
-
hours: date.getHours(),
|
|
85
|
-
minutes: date.getMinutes(),
|
|
86
|
-
seconds: date.getSeconds()
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
export {
|
|
90
|
-
getCalendar,
|
|
91
|
-
getDays,
|
|
92
|
-
getWeek,
|
|
93
|
-
lastMonth,
|
|
94
|
-
nextMonth,
|
|
95
|
-
parseDate,
|
|
96
|
-
transformArray
|
|
97
|
-
};
|
package/common/dataset/index.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__objRest,
|
|
3
|
-
__spreadValues
|
|
4
|
-
} from "../../chunk-G2ADBYYC.js";
|
|
5
|
-
import { format } from "../string";
|
|
6
|
-
import { isObject } from "../type";
|
|
7
|
-
import { transformTreeData } from "../array";
|
|
8
|
-
const getFilterStr = (filters) => {
|
|
9
|
-
const filterArr = {};
|
|
10
|
-
Object.keys(filters).forEach((property) => {
|
|
11
|
-
const { type, value } = filters[property];
|
|
12
|
-
if (type === "enum") {
|
|
13
|
-
filterArr[property] = { type: value.map(() => 0), value };
|
|
14
|
-
if (value.length > 1) {
|
|
15
|
-
filters[property].relation = "or";
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (type === "input") {
|
|
19
|
-
const { relation, text } = value;
|
|
20
|
-
filterArr[property] = {
|
|
21
|
-
type: [relation === "startwith" ? 8 : relation === "equals" ? 0 : 6],
|
|
22
|
-
value: text
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
return JSON.stringify(filterArr);
|
|
27
|
-
};
|
|
28
|
-
const getNsObj = (obj, names) => {
|
|
29
|
-
const arr = Array.isArray(names) ? names : names.split(".");
|
|
30
|
-
const curkey = arr.shift();
|
|
31
|
-
const curObj = obj[curkey];
|
|
32
|
-
if (isObject(curObj) && arr.length) {
|
|
33
|
-
return getNsObj(curObj, arr);
|
|
34
|
-
}
|
|
35
|
-
return curObj;
|
|
36
|
-
};
|
|
37
|
-
const handlerArgs = (options, args) => {
|
|
38
|
-
if (args) {
|
|
39
|
-
const { page, sort, filters } = args;
|
|
40
|
-
const { currentPage, pageSize } = page || {};
|
|
41
|
-
const filterStr = getFilterStr(filters || {});
|
|
42
|
-
const orderBy = sort && sort.property ? sort.property + " " + sort.order : "";
|
|
43
|
-
options.url = format(options.url, {
|
|
44
|
-
curPage: currentPage,
|
|
45
|
-
pageSize,
|
|
46
|
-
filterStr,
|
|
47
|
-
orderBy
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const transForm = (response, tree) => {
|
|
52
|
-
const { result, pageVO } = response;
|
|
53
|
-
const { key = "id", parentKey } = tree || {};
|
|
54
|
-
let data = result || response;
|
|
55
|
-
if (parentKey) {
|
|
56
|
-
data = transformTreeData(data, key, parentKey);
|
|
57
|
-
}
|
|
58
|
-
return pageVO ? { result: data, page: { total: pageVO.totalRows } } : data;
|
|
59
|
-
};
|
|
60
|
-
const getDataset = ({ dataset, service, tree }, args) => new Promise((resolve, reject) => {
|
|
61
|
-
const { source, value, api } = dataset || {};
|
|
62
|
-
const $service = service || dataset && dataset.service;
|
|
63
|
-
if (Array.isArray(dataset)) {
|
|
64
|
-
return resolve(transForm(dataset, tree));
|
|
65
|
-
}
|
|
66
|
-
if (Array.isArray(value)) {
|
|
67
|
-
return resolve(transForm(value, tree));
|
|
68
|
-
}
|
|
69
|
-
if (!$service) {
|
|
70
|
-
return resolve([]);
|
|
71
|
-
}
|
|
72
|
-
if (isObject(source) && source.url) {
|
|
73
|
-
const _a = source, { type = "GET", data, beforeRequest, afterRequest, success, hideErr, url, method } = _a, options = __objRest(_a, ["type", "data", "beforeRequest", "afterRequest", "success", "hideErr", "url", "method"]);
|
|
74
|
-
options.url = url;
|
|
75
|
-
options.method = method || type.toLocaleLowerCase();
|
|
76
|
-
const mergeTarget = options.method === "get" ? "params" : "data";
|
|
77
|
-
options[mergeTarget] = data || {};
|
|
78
|
-
const afterRequestFn = afterRequest || success;
|
|
79
|
-
const config = __spreadValues({}, options);
|
|
80
|
-
handlerArgs(config, args);
|
|
81
|
-
beforeRequest && beforeRequest(config, args);
|
|
82
|
-
$service.network.request(config).then((response) => {
|
|
83
|
-
afterRequestFn && afterRequestFn(response.data);
|
|
84
|
-
resolve(transForm(response.data, tree));
|
|
85
|
-
}).catch((error) => {
|
|
86
|
-
hideErr || reject(error);
|
|
87
|
-
});
|
|
88
|
-
} else if (api) {
|
|
89
|
-
const fetchFn = getNsObj($service, api.name);
|
|
90
|
-
fetchFn && fetchFn(__spreadValues(__spreadValues({}, api.data), args)).then((response) => {
|
|
91
|
-
resolve(transForm(response, tree));
|
|
92
|
-
}).catch((error) => {
|
|
93
|
-
reject(error);
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
export {
|
|
98
|
-
getDataset
|
|
99
|
-
};
|
package/common/date.js
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import "../chunk-G2ADBYYC.js";
|
|
2
|
-
import { isDate, isNumber, isNumeric } from "./type";
|
|
3
|
-
import { fillChar } from "./string";
|
|
4
|
-
const daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
5
|
-
const yyyymmddReg = new RegExp(
|
|
6
|
-
"^(\\d{4})(/|-)(((0)?[1-9])|(1[0-2]))((/|-)(((0)?[1-9])|([1-2][0-9])|(3[0-1])))?( ((0)?[0-9]|1[0-9]|20|21|22|23):([0-5]?[0-9])((:([0-5]?[0-9]))?(.([0-9]{1,6}))?)?)?$"
|
|
7
|
-
);
|
|
8
|
-
const mmddyyyyReg = new RegExp(
|
|
9
|
-
"^(((0)?[1-9])|(1[0-2]))(/|-)(((0)?[1-9])|([1-2][0-9])|(3[0-1]))?(/|-)?(\\d{4})( ((0)?[0-9]|1[0-9]|20|21|22|23):([0-5]?[0-9])((:([0-5]?[0-9]))?(.([0-9]{1,6}))?)?)?$"
|
|
10
|
-
);
|
|
11
|
-
const iso8601Reg = new RegExp(
|
|
12
|
-
"^(\\d{4})-(((0)?[1-9])|(1[0-2]))-(((0)?[1-9])|([1-2][0-9])|(3[0-1]))T(((0)?[0-9]|1[0-9]|20|21|22|23):([0-5]?[0-9])((:([0-5]?[0-9]))?(.([0-9]{1,6}))?)?)?(Z|([+-])((0)?[0-9]|1[0-9]|20|21|22|23):?([0-5]?[0-9]))$"
|
|
13
|
-
);
|
|
14
|
-
const dateFormatRegs = {
|
|
15
|
-
"y{1,4}": /y{1,4}/,
|
|
16
|
-
"M{1,2}": /M{1,2}/,
|
|
17
|
-
"d{1,2}": /d{1,2}/,
|
|
18
|
-
"h{1,2}": /h{1,2}/,
|
|
19
|
-
"H{1,2}": /H{1,2}/,
|
|
20
|
-
"m{1,2}": /m{1,2}/,
|
|
21
|
-
"s{1,2}": /s{1,2}/,
|
|
22
|
-
"S{1,3}": /S{1,3}/,
|
|
23
|
-
"Z{1,1}": /Z{1,1}/
|
|
24
|
-
};
|
|
25
|
-
const maxDateValues = {
|
|
26
|
-
YEAR: 9999,
|
|
27
|
-
MONTH: 11,
|
|
28
|
-
DATE: 31,
|
|
29
|
-
HOUR: 23,
|
|
30
|
-
MINUTE: 59,
|
|
31
|
-
SECOND: 59,
|
|
32
|
-
MILLISECOND: 999
|
|
33
|
-
};
|
|
34
|
-
const timezone1 = "-12:00,-11:00,-10:00,-09:30,-08:00,-07:00,-06:00,-05:00,-04:30,-04:00,-03:30,-02:00,-01:00";
|
|
35
|
-
const timezone2 = "-00:00,+00:00,+01:00,+02:00,+03:00,+03:30,+04:00,+04:30,+05:00,+05:30,+05:45,+06:00";
|
|
36
|
-
const timezone3 = "+06:30,+07:00,+08:00,+09:00,+10:00,+10:30,+11:00,+11:30,+12:00,+12:45,+13:00,+14:00";
|
|
37
|
-
const timezones = [].concat(timezone1.split(","), timezone2.split(","), timezone3.split(","));
|
|
38
|
-
const getTimezone = (date) => {
|
|
39
|
-
const timezoneoffset = 0 - date.getTimezoneOffset() / 60;
|
|
40
|
-
let timezone;
|
|
41
|
-
if (timezoneoffset === 0) {
|
|
42
|
-
timezone = "Z";
|
|
43
|
-
} else if (timezoneoffset > 0) {
|
|
44
|
-
timezone = "+" + (timezoneoffset > 10 ? timezoneoffset : "0" + timezoneoffset) + "00";
|
|
45
|
-
} else {
|
|
46
|
-
timezone = (timezoneoffset < -10 ? timezoneoffset : "-0" + -timezoneoffset) + "00";
|
|
47
|
-
}
|
|
48
|
-
return timezone;
|
|
49
|
-
};
|
|
50
|
-
const isLeapYear = (year) => year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
51
|
-
const getMilliseconds = (milliseconds) => milliseconds > maxDateValues.MILLISECOND ? Number(String(milliseconds).substring(0, 3)) : milliseconds;
|
|
52
|
-
const getDateFromData = ({ year, month, date, hours, minutes, seconds, milliseconds }) => {
|
|
53
|
-
let daysInMonth = daysInMonths[month];
|
|
54
|
-
if (isLeapYear(year) && month === 1) {
|
|
55
|
-
daysInMonth += 1;
|
|
56
|
-
}
|
|
57
|
-
if (date <= daysInMonth) {
|
|
58
|
-
return new Date(year, month, date, hours, minutes, seconds, getMilliseconds(milliseconds));
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
const yyyymmddDateParser = (m) => {
|
|
62
|
-
if (m.length === 23) {
|
|
63
|
-
const year = Number(m[1]);
|
|
64
|
-
const month = m[3] - 1;
|
|
65
|
-
const date = Number(m[9] || 1);
|
|
66
|
-
const hours = m[15] || 0;
|
|
67
|
-
const minutes = m[17] || 0;
|
|
68
|
-
const seconds = m[20] || 0;
|
|
69
|
-
const milliseconds = m[22] || 0;
|
|
70
|
-
return getDateFromData({
|
|
71
|
-
date,
|
|
72
|
-
year,
|
|
73
|
-
hours,
|
|
74
|
-
month,
|
|
75
|
-
seconds,
|
|
76
|
-
minutes,
|
|
77
|
-
milliseconds
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const mmddyyyyDateParser = (m) => {
|
|
82
|
-
if (m.length === 22) {
|
|
83
|
-
const year = Number(m[12]);
|
|
84
|
-
const month = m[1] - 1;
|
|
85
|
-
const date = Number(m[6] || 1);
|
|
86
|
-
const hours = m[14] || 0;
|
|
87
|
-
const minutes = m[16] || 0;
|
|
88
|
-
const seconds = m[19] || 0;
|
|
89
|
-
const milliseconds = m[21] || 0;
|
|
90
|
-
return getDateFromData({
|
|
91
|
-
year,
|
|
92
|
-
month,
|
|
93
|
-
date,
|
|
94
|
-
hours,
|
|
95
|
-
minutes,
|
|
96
|
-
seconds,
|
|
97
|
-
milliseconds
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const iso8601DateParser = (m) => {
|
|
102
|
-
if (m.length !== 25) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const year = Number(m[1]);
|
|
106
|
-
const month = m[2] - 1;
|
|
107
|
-
const date = Number(m[6]);
|
|
108
|
-
const offset = new Date(year, month, date).getTimezoneOffset();
|
|
109
|
-
const hours = m[12] || 0;
|
|
110
|
-
const minutes = m[14] || 0;
|
|
111
|
-
const seconds = m[17] || 0;
|
|
112
|
-
const milliseconds = m[19] || 0;
|
|
113
|
-
let timeZone = m[20];
|
|
114
|
-
const sign = m[21];
|
|
115
|
-
const offsetHours = m[22] || 0;
|
|
116
|
-
const offsetMinutes = m[24] || 0;
|
|
117
|
-
let daysInMonth = daysInMonths[month];
|
|
118
|
-
let actHours;
|
|
119
|
-
let actMinutes;
|
|
120
|
-
if (isLeapYear(year) && month === 1) {
|
|
121
|
-
daysInMonth += 1;
|
|
122
|
-
}
|
|
123
|
-
if (date <= daysInMonth) {
|
|
124
|
-
if (timeZone === "Z") {
|
|
125
|
-
actHours = hours - offset / 60;
|
|
126
|
-
actMinutes = minutes;
|
|
127
|
-
} else {
|
|
128
|
-
if (!timeZone.includes(":")) {
|
|
129
|
-
timeZone = timeZone.substr(0, 3) + ":" + timeZone.substr(3);
|
|
130
|
-
}
|
|
131
|
-
if (!timezones.includes(timeZone)) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
actHours = sign === "+" ? hours - offsetHours - offset / 60 : Number(hours) + Number(offsetHours) - offset / 60;
|
|
135
|
-
actMinutes = sign === "+" ? minutes - offsetMinutes : Number(minutes) + Number(offsetMinutes);
|
|
136
|
-
}
|
|
137
|
-
return new Date(year, month, date, actHours, actMinutes, seconds, getMilliseconds(milliseconds));
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
const dateParsers = [
|
|
141
|
-
[yyyymmddReg, yyyymmddDateParser],
|
|
142
|
-
[mmddyyyyReg, mmddyyyyDateParser],
|
|
143
|
-
[iso8601Reg, iso8601DateParser]
|
|
144
|
-
];
|
|
145
|
-
const parseDate = (str) => {
|
|
146
|
-
for (let i = 0, len = dateParsers.length; i < len; i++) {
|
|
147
|
-
const m = dateParsers[i][0].exec(str);
|
|
148
|
-
if (m && m.length > 0) {
|
|
149
|
-
return dateParsers[i][1](m);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const matchDateArray = (arr, value, text) => {
|
|
154
|
-
if (text) {
|
|
155
|
-
switch (text) {
|
|
156
|
-
case "yyyy":
|
|
157
|
-
case "yy":
|
|
158
|
-
arr[0] = value;
|
|
159
|
-
break;
|
|
160
|
-
case "M":
|
|
161
|
-
case "MM":
|
|
162
|
-
arr[1] = value - 1;
|
|
163
|
-
break;
|
|
164
|
-
case "d":
|
|
165
|
-
case "dd":
|
|
166
|
-
arr[2] = value;
|
|
167
|
-
break;
|
|
168
|
-
case "h":
|
|
169
|
-
case "hh":
|
|
170
|
-
arr[3] = value;
|
|
171
|
-
break;
|
|
172
|
-
case "m":
|
|
173
|
-
case "mm":
|
|
174
|
-
arr[4] = value;
|
|
175
|
-
break;
|
|
176
|
-
case "s":
|
|
177
|
-
case "ss":
|
|
178
|
-
arr[5] = value;
|
|
179
|
-
break;
|
|
180
|
-
case "S":
|
|
181
|
-
case "SS":
|
|
182
|
-
case "SSS":
|
|
183
|
-
arr[6] = value;
|
|
184
|
-
break;
|
|
185
|
-
default:
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
const getDateArray = (str, dateFormat) => {
|
|
191
|
-
const arr = [0, -1, 0, 0, 0, 0];
|
|
192
|
-
if (str.length !== dateFormat.length) {
|
|
193
|
-
return arr;
|
|
194
|
-
}
|
|
195
|
-
let valuePos = 0;
|
|
196
|
-
let textPos = 0;
|
|
197
|
-
for (let i = 0, len = str.length; i < len; i++) {
|
|
198
|
-
const charValue = str.substr(i, 1);
|
|
199
|
-
const notNum = isNaN(Number(charValue)) || charValue.trim() === "";
|
|
200
|
-
if (notNum && charValue === dateFormat.substr(i, 1) || i === len - 1) {
|
|
201
|
-
let value;
|
|
202
|
-
let text;
|
|
203
|
-
if (notNum) {
|
|
204
|
-
value = str.substring(valuePos, i);
|
|
205
|
-
valuePos = i + 1;
|
|
206
|
-
const end = dateFormat.indexOf(charValue, textPos);
|
|
207
|
-
text = dateFormat.substring(textPos, end === -1 ? dateFormat.length : end);
|
|
208
|
-
textPos = end + 1;
|
|
209
|
-
} else {
|
|
210
|
-
value = str.substring(valuePos, len);
|
|
211
|
-
text = dateFormat.substring(textPos, len);
|
|
212
|
-
}
|
|
213
|
-
if (value.length === text.length || value) {
|
|
214
|
-
matchDateArray(arr, value, text);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return arr;
|
|
219
|
-
};
|
|
220
|
-
const invalideTime = (time, min, max) => isNaN(time) || time < min || time > max;
|
|
221
|
-
const invalideValue = ({ year, month, date, hours, minutes, seconds, milliseconds }) => invalideTime(year, 0, maxDateValues.YEAR) || invalideTime(month, 0, maxDateValues.MONTH) || invalideTime(date, 0, maxDateValues.DATE) || invalideTime(hours, 0, maxDateValues.HOUR) || invalideTime(minutes, 0, maxDateValues.MINUTE) || invalideTime(seconds, 0, maxDateValues.SECOND) || invalideTime(milliseconds, 0, maxDateValues.MILLISECOND);
|
|
222
|
-
const innerParse = (value, dateFormat) => {
|
|
223
|
-
if (typeof dateFormat === "string") {
|
|
224
|
-
const arr = getDateArray(value, dateFormat);
|
|
225
|
-
const year = Number(arr[0]);
|
|
226
|
-
const month = Number(arr[1]);
|
|
227
|
-
const date = Number(arr[2] || 1);
|
|
228
|
-
const hours = Number(arr[3] || 0);
|
|
229
|
-
const minutes = Number(arr[4] || 0);
|
|
230
|
-
const seconds = Number(arr[5] || 0);
|
|
231
|
-
const milliseconds = Number(arr[6] || 0);
|
|
232
|
-
if (invalideValue({
|
|
233
|
-
year,
|
|
234
|
-
month,
|
|
235
|
-
date,
|
|
236
|
-
hours,
|
|
237
|
-
minutes,
|
|
238
|
-
seconds,
|
|
239
|
-
milliseconds
|
|
240
|
-
})) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
return getDateFromData({
|
|
244
|
-
year,
|
|
245
|
-
date,
|
|
246
|
-
month,
|
|
247
|
-
minutes,
|
|
248
|
-
hours,
|
|
249
|
-
milliseconds,
|
|
250
|
-
seconds
|
|
251
|
-
});
|
|
252
|
-
} else {
|
|
253
|
-
return parseDate(value);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
const toDate = (value, dateFormat, minDate) => {
|
|
257
|
-
let date;
|
|
258
|
-
if (isNumber(value)) {
|
|
259
|
-
date = new Date(value);
|
|
260
|
-
} else if (typeof value === "string") {
|
|
261
|
-
date = innerParse(value, dateFormat);
|
|
262
|
-
}
|
|
263
|
-
if (minDate) {
|
|
264
|
-
const min = minDate && toDate(minDate) || new Date(1, 1, 1, 0, 0, 0);
|
|
265
|
-
return date && date < min ? min : date;
|
|
266
|
-
}
|
|
267
|
-
return date;
|
|
268
|
-
};
|
|
269
|
-
const format = function(date, dateFormat = "yyyy/MM/dd hh:mm:ss") {
|
|
270
|
-
if (isDate(date)) {
|
|
271
|
-
if (typeof dateFormat === "string") {
|
|
272
|
-
const o = {
|
|
273
|
-
"y{1,4}": date.getFullYear(),
|
|
274
|
-
"M{1,2}": date.getMonth() + 1,
|
|
275
|
-
"d{1,2}": date.getDate(),
|
|
276
|
-
"h{1,2}": date.getHours(),
|
|
277
|
-
"H{1,2}": date.getHours(),
|
|
278
|
-
"m{1,2}": date.getMinutes(),
|
|
279
|
-
"s{1,2}": date.getSeconds(),
|
|
280
|
-
"S{1,3}": date.getMilliseconds(),
|
|
281
|
-
"Z{1,1}": getTimezone(date)
|
|
282
|
-
};
|
|
283
|
-
Object.keys(o).forEach((k) => {
|
|
284
|
-
const m = dateFormat.match(dateFormatRegs[k]);
|
|
285
|
-
if (k && m && m.length) {
|
|
286
|
-
dateFormat = dateFormat.replace(m[0], k === "Z{1,1}" ? o[k] : fillChar(o[k].toString(), m[0].length));
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
return dateFormat;
|
|
290
|
-
}
|
|
291
|
-
} else if (typeof date === "string" && arguments.length >= 2) {
|
|
292
|
-
let afterFormat = dateFormat;
|
|
293
|
-
if (arguments.length === 2) {
|
|
294
|
-
dateFormat = void 0;
|
|
295
|
-
} else {
|
|
296
|
-
afterFormat = arguments[2];
|
|
297
|
-
}
|
|
298
|
-
const dateValue = toDate(date, dateFormat);
|
|
299
|
-
return dateValue ? format(dateValue, afterFormat) : "";
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
const getDateWithNewTimezone = (date, otz, ntz, timezoneOffset = 0) => {
|
|
303
|
-
if (!isDate(date) || !isNumeric(otz) || !isNumeric(ntz) || !isNumeric(timezoneOffset)) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const otzOffset = -otz * 60;
|
|
307
|
-
const ntzOffset = -ntz * 60;
|
|
308
|
-
const dstOffeset = timezoneOffset * 60;
|
|
309
|
-
const utc = date.getTime() + otzOffset * 6e4;
|
|
310
|
-
return new Date(utc - (ntzOffset - dstOffeset) * 6e4);
|
|
311
|
-
};
|
|
312
|
-
const toDateStr = (date, dateFormat, timezone) => {
|
|
313
|
-
if (date && isNumeric(timezone)) {
|
|
314
|
-
timezone = parseFloat(parseFloat(timezone).toFixed(2));
|
|
315
|
-
date = getDateWithNewTimezone(isDate(date) ? date : new Date(toDate(date)), 0, timezone);
|
|
316
|
-
}
|
|
317
|
-
return format(date, dateFormat);
|
|
318
|
-
};
|
|
319
|
-
const getWeekOfFirstDay = (date, isSunFirst) => {
|
|
320
|
-
typeof date === "boolean" && (isSunFirst = date);
|
|
321
|
-
isDate(date) || (date = /* @__PURE__ */ new Date());
|
|
322
|
-
const day = date.getDay();
|
|
323
|
-
let dayOfMonth = date.getDate();
|
|
324
|
-
if (day === 0) {
|
|
325
|
-
!isSunFirst && (dayOfMonth -= 6);
|
|
326
|
-
} else {
|
|
327
|
-
dayOfMonth = dayOfMonth - day + (!isSunFirst && 1);
|
|
328
|
-
}
|
|
329
|
-
return new Date(date.getFullYear(), date.getMonth(), dayOfMonth);
|
|
330
|
-
};
|
|
331
|
-
const TZRE = /(-|\+)(\d{2}):?(\d{2})$/;
|
|
332
|
-
const getLocalTimezone = () => 0 - (/* @__PURE__ */ new Date()).getTimezoneOffset() / 60;
|
|
333
|
-
const getStrTimezone = (value) => {
|
|
334
|
-
const localTimeZone = getLocalTimezone();
|
|
335
|
-
const match = typeof value === "string" && value.match(TZRE);
|
|
336
|
-
if (match) {
|
|
337
|
-
const minoffset = Number(match[2]) + Number(match[3]) / 60;
|
|
338
|
-
value = minoffset * `${match[1]}1`;
|
|
339
|
-
}
|
|
340
|
-
if (isNumber(value) && value >= -12 && value <= 12) {
|
|
341
|
-
return value;
|
|
342
|
-
}
|
|
343
|
-
return localTimeZone;
|
|
344
|
-
};
|
|
345
|
-
export {
|
|
346
|
-
format,
|
|
347
|
-
getDateWithNewTimezone,
|
|
348
|
-
getLocalTimezone,
|
|
349
|
-
getStrTimezone,
|
|
350
|
-
getWeekOfFirstDay,
|
|
351
|
-
isLeapYear,
|
|
352
|
-
toDate,
|
|
353
|
-
toDateStr
|
|
354
|
-
};
|
package/common/decimal.js
DELETED
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import "../chunk-G2ADBYYC.js";
|
|
2
|
-
import { getMiniDecimal, toFixed as roundFixed } from "./bigInt";
|
|
3
|
-
const DECIMAL_SEPARATOR = ".";
|
|
4
|
-
const asInteger = (number) => {
|
|
5
|
-
const tokens = number.split(DECIMAL_SEPARATOR);
|
|
6
|
-
const integer = tokens[0];
|
|
7
|
-
const fractional = tokens[1];
|
|
8
|
-
let value;
|
|
9
|
-
let exp;
|
|
10
|
-
if (fractional) {
|
|
11
|
-
value = parseInt(number.split(DECIMAL_SEPARATOR).join(""), 10);
|
|
12
|
-
exp = fractional.length * -1;
|
|
13
|
-
} else {
|
|
14
|
-
const trailingZeros = integer.match(/0+$/);
|
|
15
|
-
if (trailingZeros) {
|
|
16
|
-
const length = trailingZeros[0].length;
|
|
17
|
-
value = integer.substr(0, integer.length - length);
|
|
18
|
-
exp = length;
|
|
19
|
-
} else {
|
|
20
|
-
value = integer;
|
|
21
|
-
exp = 0;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
return { value, exp };
|
|
25
|
-
};
|
|
26
|
-
const zero = (exp) => {
|
|
27
|
-
let result;
|
|
28
|
-
if (exp <= 0) {
|
|
29
|
-
result = "";
|
|
30
|
-
} else if (String.prototype.repeat) {
|
|
31
|
-
result = "0".repeat(exp);
|
|
32
|
-
} else {
|
|
33
|
-
result = ((times) => {
|
|
34
|
-
const zeros = [];
|
|
35
|
-
for (let i = 0; i < times; i++) {
|
|
36
|
-
zeros.push(0);
|
|
37
|
-
}
|
|
38
|
-
return zeros.join("");
|
|
39
|
-
})(exp);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
|
-
const negExp = (str, position) => {
|
|
44
|
-
position = Math.abs(position);
|
|
45
|
-
const offset = position - str.length;
|
|
46
|
-
let sep = DECIMAL_SEPARATOR;
|
|
47
|
-
if (offset >= 0) {
|
|
48
|
-
str = zero(offset) + str;
|
|
49
|
-
sep = "0.";
|
|
50
|
-
}
|
|
51
|
-
const length = str.length;
|
|
52
|
-
const dif = length - position;
|
|
53
|
-
const head = str.substr(0, dif);
|
|
54
|
-
const tail = str.substring(dif, length);
|
|
55
|
-
return head + sep + tail;
|
|
56
|
-
};
|
|
57
|
-
const posExp = (str, exp) => String(str + zero(exp));
|
|
58
|
-
const format = (num, exp) => (exp >= 0 ? posExp : negExp)(String(num), exp);
|
|
59
|
-
function Decimal(num) {
|
|
60
|
-
if (!this || this.constructor !== Decimal) {
|
|
61
|
-
return new Decimal(num);
|
|
62
|
-
}
|
|
63
|
-
if (num instanceof Decimal) {
|
|
64
|
-
return num;
|
|
65
|
-
}
|
|
66
|
-
this.internal = String(num);
|
|
67
|
-
this.asInt = asInteger(this.internal);
|
|
68
|
-
this.add = (target) => {
|
|
69
|
-
const operands = [this, new Decimal(target)];
|
|
70
|
-
operands.sort((x2, y2) => x2.asInt.exp - y2.asInt.exp);
|
|
71
|
-
const smallest = operands[0].asInt.exp;
|
|
72
|
-
const biggest = operands[1].asInt.exp;
|
|
73
|
-
const x = Number(format(operands[1].asInt.value, biggest - smallest));
|
|
74
|
-
const y = Number(operands[0].asInt.value);
|
|
75
|
-
return new Decimal(format(String(x + y), smallest));
|
|
76
|
-
};
|
|
77
|
-
this.sub = (target) => new Decimal(this.add(target * -1));
|
|
78
|
-
this.mul = (target) => {
|
|
79
|
-
target = new Decimal(target);
|
|
80
|
-
const result = String(this.asInt.value * target.asInt.value);
|
|
81
|
-
const exp = this.asInt.exp + target.asInt.exp;
|
|
82
|
-
return new Decimal(format(result, exp));
|
|
83
|
-
};
|
|
84
|
-
this.div = (target) => {
|
|
85
|
-
target = new Decimal(target);
|
|
86
|
-
const smallest = Math.min(this.asInt.exp, target.asInt.exp);
|
|
87
|
-
const absSmallest = 10 ** Math.abs(smallest);
|
|
88
|
-
const x = Decimal.mul(absSmallest, this);
|
|
89
|
-
const y = Decimal.mul(absSmallest, target);
|
|
90
|
-
return new Decimal(x / y);
|
|
91
|
-
};
|
|
92
|
-
this.toString = () => this.internal;
|
|
93
|
-
this.toNumber = () => Number(this.internal);
|
|
94
|
-
}
|
|
95
|
-
Decimal.add = (a, b) => new Decimal(a).add(b);
|
|
96
|
-
Decimal.mul = (a, b) => new Decimal(a).mul(b);
|
|
97
|
-
Decimal.sub = (a, b) => new Decimal(a).sub(b);
|
|
98
|
-
Decimal.div = (a, b) => new Decimal(a).div(b);
|
|
99
|
-
const toFixed = (num, fraction = 0) => {
|
|
100
|
-
const sign = num < 0 ? "-" : "";
|
|
101
|
-
num = Math.abs(num);
|
|
102
|
-
const npmPow = num.toString().length < (2 ** 53).toString().length - 1 ? 10 ** fraction : 10 ** (fraction - 1);
|
|
103
|
-
const result = new Decimal(Math.round(new Decimal(num).mul(npmPow))).div(npmPow).toString();
|
|
104
|
-
const numResult = Number(result);
|
|
105
|
-
return numResult ? sign + numResult.toFixed(fraction) : numResult.toFixed(fraction);
|
|
106
|
-
};
|
|
107
|
-
const formatInteger = (value, { secondaryGroupSize = 3, groupSize = 0, groupSeparator = "," }) => {
|
|
108
|
-
const negative = /^-\d+/.test(value);
|
|
109
|
-
let result = negative ? value.slice(1) : value;
|
|
110
|
-
const secSize = secondaryGroupSize || groupSize;
|
|
111
|
-
if (groupSize && result.length > groupSize) {
|
|
112
|
-
let left = result.slice(0, 0 - groupSize);
|
|
113
|
-
const right = result.slice(0 - groupSize);
|
|
114
|
-
left = left.replace(new RegExp(`\\B(?=(\\d{${secSize}})+(?!\\d))`, "g"), groupSeparator);
|
|
115
|
-
result = `${left}${groupSeparator}${right}`;
|
|
116
|
-
}
|
|
117
|
-
return `${negative ? "-" : ""}${result}`;
|
|
118
|
-
};
|
|
119
|
-
const reverseString = (str) => {
|
|
120
|
-
const arr = [];
|
|
121
|
-
for (let i = 0; i < str.length; i++) {
|
|
122
|
-
arr.push(str[i]);
|
|
123
|
-
}
|
|
124
|
-
return arr.reverse().join("");
|
|
125
|
-
};
|
|
126
|
-
const formatDecimal = (num, { fractionGroupSize = 0, fractionGroupSeparator = "\xA0" }) => {
|
|
127
|
-
const RE = new RegExp(`\\B(?=(\\d{${fractionGroupSize}})+(?!\\d))`, "g");
|
|
128
|
-
return reverseString(reverseString(num).replace(RE, fractionGroupSeparator));
|
|
129
|
-
};
|
|
130
|
-
const formatNumber = (value, format2 = {}) => {
|
|
131
|
-
const { fraction, rounding, prefix = "", decimalSeparator = ".", suffix = "" } = format2;
|
|
132
|
-
let reslut = getMiniDecimal(value);
|
|
133
|
-
if (reslut.isNaN() || !reslut.toString()) {
|
|
134
|
-
return value;
|
|
135
|
-
}
|
|
136
|
-
reslut = roundFixed(reslut.toString(), fraction, rounding);
|
|
137
|
-
format2.zeroize === false && reslut.match(/\./) && (reslut = reslut.replace(/\.?0+$/g, ""));
|
|
138
|
-
const number = reslut.toString().split(".").slice(0, 2).map((str, index) => index ? formatDecimal(str, format2) : formatInteger(str, format2)).join(decimalSeparator);
|
|
139
|
-
return `${prefix}${number}${suffix}`;
|
|
140
|
-
};
|
|
141
|
-
const recoverNumber = (number, format2 = {}) => {
|
|
142
|
-
const { prefix = "", suffix = "", decimalSeparator = "." } = format2;
|
|
143
|
-
let result = number;
|
|
144
|
-
if (typeof number === "string") {
|
|
145
|
-
result = number.replace(new RegExp(`^${prefix}(.+)${suffix}$`), ($1, $2) => $2).split(decimalSeparator).map((s) => s.replace(/[^\d]/g, "")).join(".");
|
|
146
|
-
}
|
|
147
|
-
return Number(result);
|
|
148
|
-
};
|
|
149
|
-
export {
|
|
150
|
-
Decimal,
|
|
151
|
-
formatNumber,
|
|
152
|
-
recoverNumber,
|
|
153
|
-
roundFixed,
|
|
154
|
-
toFixed
|
|
155
|
-
};
|