dtable-ui-component 0.1.74 → 0.1.75-beta3
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/AutoNumberFormatter/index.css +1 -0
- package/es/{components/cell-formatter/auto-number-formatter.js → AutoNumberFormatter/index.js} +1 -0
- package/es/ButtonFormatter/index.css +13 -0
- package/es/{components/cell-formatter/button-formatter.js → ButtonFormatter/index.js} +1 -0
- package/es/CTimeFormatter/index.css +1 -0
- package/es/{components/cell-formatter/ctime-formatter.js → CTimeFormatter/index.js} +1 -0
- package/es/CheckboxFormatter/index.css +1 -0
- package/es/{components/cell-formatter/checkbox-formatter.js → CheckboxFormatter/index.js} +1 -0
- package/es/CollaboratorFormatter/index.css +1 -0
- package/es/{components/cell-formatter/collaborator-formatter.js → CollaboratorFormatter/index.js} +3 -2
- package/es/CollaboratorItem/index.css +49 -0
- package/es/CollaboratorItem/index.js +64 -0
- package/es/CreatorFormatter/index.css +1 -0
- package/es/{components/cell-formatter/creator-formatter.js → CreatorFormatter/index.js} +3 -2
- package/es/DateFormatter/index.css +1 -0
- package/es/{components/cell-formatter/date-formatter.js → DateFormatter/index.js} +2 -1
- package/es/DurationFormatter/index.css +1 -0
- package/es/{components/cell-formatter/duration-formatter.js → DurationFormatter/index.js} +2 -1
- package/es/EmailFormatter/index.css +5 -0
- package/es/{components/cell-formatter/email-formatter.js → EmailFormatter/index.js} +1 -0
- package/es/FileFormatter/index.css +29 -0
- package/es/{components/cell-formatter/file-formatter.js → FileFormatter/index.js} +2 -1
- package/es/{components/cell-formatter/widgets/file-item-formatter.js → FileItemFormatter/index.js} +2 -2
- package/es/{components/file-uploader → FileUploader}/index.js +0 -0
- package/es/FormulaFormatter/index.css +19 -0
- package/es/{components/cell-formatter/formula-formatter.js → FormulaFormatter/index.js} +8 -8
- package/es/GeolocationFormatter/index.css +1 -0
- package/es/{components/cell-formatter/geolocation-formatter.js → GeolocationFormatter/index.js} +2 -1
- package/es/{components/common → ImageFormatter}/images-lazy-load.js +2 -2
- package/es/ImageFormatter/index.css +34 -0
- package/es/{components/cell-formatter/image-formatter.js → ImageFormatter/index.js} +4 -3
- package/es/{css/image-previewer-ligntbox.css → ImagePreviewerLightbox/index.css} +0 -0
- package/es/{components/cell-formatter/widgets/image-previewer-lightbox.js → ImagePreviewerLightbox/index.js} +3 -3
- package/es/LastModifierFormatter/index.css +1 -0
- package/es/{components/cell-formatter/last-modifier-formatter.js → LastModifierFormatter/index.js} +5 -4
- package/es/LinkFormatter/index.css +27 -0
- package/es/{components/cell-formatter/link-formatter.js → LinkFormatter/index.js} +2 -2
- package/es/{css/loading.css → Loading/index.css} +0 -0
- package/es/{components/loading.js → Loading/index.js} +1 -1
- package/es/{components/cell-formatter/widgets/long-text-formatter → LongTextFormatter}/html-long-text-formatter.js +1 -1
- package/es/LongTextFormatter/index.css +63 -0
- package/es/{components/cell-formatter/long-text-formatter.js → LongTextFormatter/index.js} +3 -2
- package/es/{components/cell-formatter/widgets/long-text-formatter → LongTextFormatter}/simple-long-text-formatter.js +1 -1
- package/es/MTimeFormatter/index.css +1 -0
- package/es/{components/cell-formatter/mtime-formatter.js → MTimeFormatter/index.js} +1 -0
- package/es/{components/common/modal-portal.js → ModalPortal/index.js} +0 -0
- package/es/MultipleSelectFormatter/index.css +1 -0
- package/es/{components/cell-formatter/multiple-select-formatter.js → MultipleSelectFormatter/index.js} +2 -1
- package/es/NumberFormatter/index.css +1 -0
- package/es/{components/cell-formatter/number-formatter.js → NumberFormatter/index.js} +2 -1
- package/es/RateFormatter/index.css +1 -0
- package/es/{components/cell-formatter/rate-formatter.js → RateFormatter/index.js} +1 -0
- package/es/{components/common/select-item.js → SelectItem/index.js} +0 -0
- package/es/SingleSelectFormatter/index.css +1 -0
- package/es/{components/cell-formatter/single-select-formatter.js → SingleSelectFormatter/index.js} +2 -1
- package/es/TextFormatter/index.css +1 -0
- package/es/{components/cell-formatter/text-formatter.js → TextFormatter/index.js} +1 -0
- package/es/UrlFormatter/index.css +5 -0
- package/es/{components/cell-formatter/url-formatter.js → UrlFormatter/index.js} +1 -0
- package/es/app.js +1 -1
- package/es/{components/cell-factory/cell-formatter-factory.js → cellFormatterFactory/index.js} +3 -3
- package/es/components/cell-editor/checkbox-editor.js +104 -0
- package/es/components/cell-editor/collaborator-editor.js +236 -0
- package/es/components/cell-editor/date-editor.js +151 -0
- package/es/components/cell-editor/index.js +9 -0
- package/es/components/cell-editor/link-editor.js +303 -0
- package/es/components/cell-editor/multiple-select-editor.js +237 -0
- package/es/components/cell-editor/number-editor.js +154 -0
- package/es/components/cell-editor/single-select-editor.js +202 -0
- package/es/components/cell-editor/text-editor.js +122 -0
- package/es/components/cell-editor-dialog/pc-file-editor-dialog.js +46 -0
- package/es/components/cell-editor-dialog/pc-files-addition/index.js +0 -0
- package/es/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +0 -0
- package/es/components/cell-editor-dialog/pc-files-preview/index.js +0 -0
- package/es/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +0 -0
- package/es/components/cell-editor-popover/mb-collaborator-editor-popover.js +177 -0
- package/es/components/cell-editor-popover/mb-date-editor-popover.js +245 -0
- package/es/components/cell-editor-popover/mb-link-editor-popover.js +170 -0
- package/es/components/cell-editor-popover/mb-select-editor-popover.js +230 -0
- package/es/components/cell-editor-popover/pc-collaborator-editor-popover.js +109 -0
- package/es/components/cell-editor-popover/pc-date-editor-popover.js +142 -0
- package/es/components/cell-editor-popover/pc-link-editor-popover.js +114 -0
- package/es/components/cell-editor-popover/pc-select-editor-popover.js +143 -0
- package/es/constants/index.js +15 -14
- package/es/css/cell-formatter.css +0 -243
- package/es/formatterConfig/index.js +31 -0
- package/es/index.js +29 -3
- package/es/{components/toast → toaster}/alert.js +0 -0
- package/es/{components/toast → toaster}/index.js +0 -0
- package/es/{components/toast → toaster}/toast.js +0 -0
- package/es/{components/toast → toaster}/toastManager.js +0 -0
- package/es/{components/toast → toaster}/toaster.js +0 -0
- package/es/utils/cell-value-validator.js +1 -2
- package/es/utils/editor-utils.js +71 -0
- package/es/utils/normalize-long-text-value.js +2 -2
- package/es/utils/number-precision.js +1 -0
- package/es/utils/value-format-utils.js +2 -0
- package/lib/AutoNumberFormatter/index.css +1 -0
- package/lib/AutoNumberFormatter/index.js +47 -0
- package/lib/ButtonFormatter/index.css +13 -0
- package/lib/ButtonFormatter/index.js +68 -0
- package/lib/CTimeFormatter/index.css +1 -0
- package/lib/CTimeFormatter/index.js +72 -0
- package/lib/CheckboxFormatter/index.css +1 -0
- package/lib/CheckboxFormatter/index.js +58 -0
- package/lib/CollaboratorFormatter/index.css +1 -0
- package/lib/CollaboratorFormatter/index.js +113 -0
- package/lib/CollaboratorItem/index.css +49 -0
- package/lib/CollaboratorItem/index.js +81 -0
- package/lib/CreatorFormatter/index.css +1 -0
- package/lib/CreatorFormatter/index.js +107 -0
- package/lib/DateFormatter/index.css +1 -0
- package/lib/DateFormatter/index.js +75 -0
- package/lib/DurationFormatter/index.css +1 -0
- package/lib/DurationFormatter/index.js +51 -0
- package/lib/EmailFormatter/index.css +5 -0
- package/lib/EmailFormatter/index.js +47 -0
- package/lib/FileFormatter/index.css +29 -0
- package/lib/FileFormatter/index.js +79 -0
- package/lib/FileItemFormatter/index.js +63 -0
- package/lib/FileUploader/index.js +63 -0
- package/lib/FormulaFormatter/index.css +19 -0
- package/lib/FormulaFormatter/index.js +185 -0
- package/lib/GeolocationFormatter/index.css +1 -0
- package/lib/GeolocationFormatter/index.js +68 -0
- package/lib/ImageFormatter/images-lazy-load.js +158 -0
- package/lib/ImageFormatter/index.css +34 -0
- package/lib/ImageFormatter/index.js +173 -0
- package/lib/ImagePreviewerLightbox/index.css +87 -0
- package/lib/ImagePreviewerLightbox/index.js +152 -0
- package/lib/LastModifierFormatter/index.css +1 -0
- package/lib/LastModifierFormatter/index.js +107 -0
- package/lib/LinkFormatter/index.css +27 -0
- package/lib/LinkFormatter/index.js +165 -0
- package/lib/Loading/index.css +54 -0
- package/lib/Loading/index.js +16 -0
- package/lib/LongTextFormatter/html-long-text-formatter.js +107 -0
- package/lib/LongTextFormatter/index.css +63 -0
- package/lib/LongTextFormatter/index.js +48 -0
- package/lib/LongTextFormatter/simple-long-text-formatter.js +110 -0
- package/lib/MTimeFormatter/index.css +1 -0
- package/lib/MTimeFormatter/index.js +72 -0
- package/lib/ModalPortal/index.js +51 -0
- package/lib/MultipleSelectFormatter/index.css +1 -0
- package/lib/MultipleSelectFormatter/index.js +86 -0
- package/lib/NumberFormatter/index.css +1 -0
- package/lib/NumberFormatter/index.js +62 -0
- package/lib/RateFormatter/index.css +1 -0
- package/lib/RateFormatter/index.js +95 -0
- package/lib/SelectItem/index.js +73 -0
- package/lib/SingleSelectFormatter/index.css +1 -0
- package/lib/SingleSelectFormatter/index.js +86 -0
- package/lib/TextFormatter/index.css +1 -0
- package/lib/TextFormatter/index.js +69 -0
- package/lib/UrlFormatter/index.css +5 -0
- package/lib/UrlFormatter/index.js +47 -0
- package/lib/app.css +20 -0
- package/lib/app.js +96 -0
- package/lib/assets/images/avatar/default_avatar.png +0 -0
- package/lib/assets/images/file/192/excel.png +0 -0
- package/lib/assets/images/file/192/file.png +0 -0
- package/lib/assets/images/file/192/music.png +0 -0
- package/lib/assets/images/file/192/pdf.png +0 -0
- package/lib/assets/images/file/192/pic.png +0 -0
- package/lib/assets/images/file/192/ppt.png +0 -0
- package/lib/assets/images/file/192/txt.png +0 -0
- package/lib/assets/images/file/192/video.png +0 -0
- package/lib/assets/images/file/192/word.png +0 -0
- package/lib/assets/images/file/24/excel.png +0 -0
- package/lib/assets/images/file/24/file.png +0 -0
- package/lib/assets/images/file/24/music.png +0 -0
- package/lib/assets/images/file/24/pdf.png +0 -0
- package/lib/assets/images/file/24/pic.png +0 -0
- package/lib/assets/images/file/24/ppt.png +0 -0
- package/lib/assets/images/file/24/txt.png +0 -0
- package/lib/assets/images/file/24/video.png +0 -0
- package/lib/assets/images/file/24/word.png +0 -0
- package/lib/assets/images/folder/folder-192.png +0 -0
- package/lib/assets/images/folder/folder-24.png +0 -0
- package/lib/cellFormatterFactory/index.js +28 -0
- package/lib/components/cell-editor/checkbox-editor.js +111 -0
- package/lib/components/cell-editor/collaborator-editor.js +249 -0
- package/lib/components/cell-editor/date-editor.js +171 -0
- package/lib/components/cell-editor/index.js +40 -0
- package/lib/components/cell-editor/link-editor.js +321 -0
- package/lib/components/cell-editor/multiple-select-editor.js +250 -0
- package/lib/components/cell-editor/number-editor.js +162 -0
- package/lib/components/cell-editor/single-select-editor.js +216 -0
- package/lib/components/cell-editor/text-editor.js +129 -0
- package/lib/components/cell-editor-dialog/pc-file-editor-dialog.js +66 -0
- package/lib/components/cell-editor-dialog/pc-files-addition/index.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-addition/pc-file-uploaded-item.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-preview/index.js +1 -0
- package/lib/components/cell-editor-dialog/pc-files-preview/pc-file-item-preview.js +1 -0
- package/lib/components/cell-editor-popover/mb-collaborator-editor-popover.js +183 -0
- package/lib/components/cell-editor-popover/mb-date-editor-popover.js +262 -0
- package/lib/components/cell-editor-popover/mb-link-editor-popover.js +176 -0
- package/lib/components/cell-editor-popover/mb-select-editor-popover.js +243 -0
- package/lib/components/cell-editor-popover/pc-collaborator-editor-popover.js +124 -0
- package/lib/components/cell-editor-popover/pc-date-editor-popover.js +156 -0
- package/lib/components/cell-editor-popover/pc-link-editor-popover.js +128 -0
- package/lib/components/cell-editor-popover/pc-select-editor-popover.js +157 -0
- package/lib/components/common/collaborator-item.js +79 -0
- package/lib/components/common/edit-editor-button.js +67 -0
- package/lib/components/common/link-editor-option.js +121 -0
- package/lib/components/common/mobile/mb-editor-header.js +61 -0
- package/lib/components/common/select-editor-option.js +122 -0
- package/lib/constants/cell-types.js +54 -0
- package/lib/constants/index.js +72 -0
- package/lib/css/cell-editor.css +614 -0
- package/lib/css/cell-formatter.css +4 -0
- package/lib/css/custom-rc-calendar.css +118 -0
- package/lib/formatterConfig/index.js +62 -0
- package/lib/index.js +139 -0
- package/lib/lang/index.js +66 -0
- package/lib/locals/de.js +7 -0
- package/lib/locals/en.js +22 -0
- package/lib/locals/fr.js +7 -0
- package/lib/locals/zh-CN.js +22 -0
- package/lib/toaster/alert.js +164 -0
- package/lib/toaster/index.js +12 -0
- package/lib/toaster/toast.js +223 -0
- package/lib/toaster/toastManager.js +189 -0
- package/lib/toaster/toaster.js +92 -0
- package/lib/utils/cell-value-validator.js +35 -0
- package/lib/utils/column-utils.js +15 -0
- package/lib/utils/editor-utils.js +81 -0
- package/lib/utils/markdown2html.js +68 -0
- package/lib/utils/normalize-long-text-value.js +74 -0
- package/lib/utils/number-precision.js +182 -0
- package/lib/utils/unified/index.js +470 -0
- package/lib/utils/utils.js +141 -0
- package/lib/utils/value-format-utils.js +547 -0
- package/lib/utils/vfile/core.js +172 -0
- package/lib/utils/vfile/index.js +48 -0
- package/package.json +5 -3
- package/es/components/cell-formatter/formatter-config.js +0 -31
- package/es/components/cell-formatter/index.js +0 -27
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.processorGetAST = exports.processor = void 0;
|
|
5
|
+
|
|
6
|
+
var unified = require('./unified');
|
|
7
|
+
|
|
8
|
+
var markdown = require('remark-parse');
|
|
9
|
+
|
|
10
|
+
var slug = require('remark-slug');
|
|
11
|
+
|
|
12
|
+
var breaks = require('remark-breaks');
|
|
13
|
+
|
|
14
|
+
var remark2rehype = require('remark-rehype');
|
|
15
|
+
|
|
16
|
+
var format = require('rehype-format');
|
|
17
|
+
|
|
18
|
+
var raw = require('rehype-raw');
|
|
19
|
+
|
|
20
|
+
var xtend = require('xtend');
|
|
21
|
+
|
|
22
|
+
var toHTML = require('hast-util-to-html');
|
|
23
|
+
|
|
24
|
+
var sanitize = require('hast-util-sanitize');
|
|
25
|
+
|
|
26
|
+
var gh = require('hast-util-sanitize/lib/github');
|
|
27
|
+
|
|
28
|
+
var deepmerge = require('deepmerge').default;
|
|
29
|
+
|
|
30
|
+
var mathjax = require('rehype-mathjax/browser');
|
|
31
|
+
|
|
32
|
+
var math = require('remark-math/block');
|
|
33
|
+
|
|
34
|
+
function stringify(config) {
|
|
35
|
+
var settings = xtend(config, this.data('settings'));
|
|
36
|
+
var schema = deepmerge(gh, {
|
|
37
|
+
'attributes': {
|
|
38
|
+
'input': ['type'],
|
|
39
|
+
'li': ['className'],
|
|
40
|
+
'code': ['className'],
|
|
41
|
+
'span': ['className'],
|
|
42
|
+
'div': ['className']
|
|
43
|
+
},
|
|
44
|
+
'tagNames': ['input', 'code', 'span', 'div']
|
|
45
|
+
});
|
|
46
|
+
this.Compiler = compiler;
|
|
47
|
+
|
|
48
|
+
function compiler(tree) {
|
|
49
|
+
// use sanity to remove dangerous html, the default is
|
|
50
|
+
// GitHub style sanitation
|
|
51
|
+
var hast = sanitize(tree, schema);
|
|
52
|
+
return toHTML(hast, settings);
|
|
53
|
+
}
|
|
54
|
+
} // markdown -> mdast -> html AST -> html
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
var processor = unified().use(markdown, {
|
|
58
|
+
commonmark: true
|
|
59
|
+
}).use(math).use(breaks).use(slug).use(remark2rehype, {
|
|
60
|
+
allowDangerousHTML: true
|
|
61
|
+
}).use(mathjax, {
|
|
62
|
+
displayMath: ['$$', '$$']
|
|
63
|
+
}).use(raw).use(format).use(stringify);
|
|
64
|
+
exports.processor = processor;
|
|
65
|
+
var processorGetAST = unified().use(markdown, {
|
|
66
|
+
commonmark: true
|
|
67
|
+
}).use(slug);
|
|
68
|
+
exports.processorGetAST = processorGetAST;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
var hrefReg = /\[.+\]\(\S+\)|<img src=(\S+).+\/>|!\[\]\(\S+\)|<\S+>/g;
|
|
6
|
+
var imageReg1 = /^<img( width=[\\|/|"](\d)+[\\|/|"])? src="(\S+)" .?\/>/;
|
|
7
|
+
var imageReg2 = /^!\[\]\((\S+)\)/;
|
|
8
|
+
var linkReg1 = /^\[.+\]\(\S+\)/;
|
|
9
|
+
var linkReg2 = /^<\S+>$/;
|
|
10
|
+
|
|
11
|
+
var getLinks = function getLinks(hrefList) {
|
|
12
|
+
var hrefObj = {
|
|
13
|
+
links: [],
|
|
14
|
+
images: []
|
|
15
|
+
};
|
|
16
|
+
hrefList.forEach(function (href) {
|
|
17
|
+
if (href.search(linkReg1) >= 0 || href.search(linkReg2) >= 0) {
|
|
18
|
+
hrefObj.links.push(href);
|
|
19
|
+
} else {
|
|
20
|
+
var imageSrcList = href.match(imageReg1);
|
|
21
|
+
var imageSrcList1 = href.match(imageReg2);
|
|
22
|
+
|
|
23
|
+
if (imageSrcList) {
|
|
24
|
+
hrefObj.images.push(imageSrcList[1]);
|
|
25
|
+
} else if (imageSrcList1) {
|
|
26
|
+
hrefObj.images.push(imageSrcList1[1]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return hrefObj;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
var getPreviewContent = function getPreviewContent(markdownContent) {
|
|
34
|
+
var preview = '';
|
|
35
|
+
var newMarkdownContent = markdownContent.replace(hrefReg, '');
|
|
36
|
+
|
|
37
|
+
for (var index = 0; index < newMarkdownContent.length; index++) {
|
|
38
|
+
if (newMarkdownContent[index] === '#') {
|
|
39
|
+
continue;
|
|
40
|
+
} else if (newMarkdownContent[index] === '\n') {
|
|
41
|
+
preview += ' ';
|
|
42
|
+
} else {
|
|
43
|
+
preview += newMarkdownContent[index];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (preview.length === 150) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var hrefList = markdownContent.match(hrefReg);
|
|
52
|
+
|
|
53
|
+
if (hrefList) {
|
|
54
|
+
var _getLinks = getLinks(hrefList),
|
|
55
|
+
images = _getLinks.images,
|
|
56
|
+
links = _getLinks.links;
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
preview: preview,
|
|
60
|
+
images: images,
|
|
61
|
+
links: links
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
preview: preview,
|
|
67
|
+
images: [],
|
|
68
|
+
links: [],
|
|
69
|
+
text: markdownContent
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var _default = getPreviewContent;
|
|
74
|
+
exports.default = _default;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = void 0;
|
|
5
|
+
exports.digitLength = digitLength;
|
|
6
|
+
exports.divide = divide;
|
|
7
|
+
exports.enableBoundaryChecking = enableBoundaryChecking;
|
|
8
|
+
exports.float2Fixed = float2Fixed;
|
|
9
|
+
exports.minus = minus;
|
|
10
|
+
exports.plus = plus;
|
|
11
|
+
exports.round = round;
|
|
12
|
+
exports.strip = strip;
|
|
13
|
+
exports.times = times;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @desc Solve the problem of floating calculation, avoid multiple digits after the decimal point and loss of calculation accuracy.
|
|
17
|
+
* example: 3 + 2.4 = 4.699999999999999,1.0 - 0.9 = 0.09999999999999998
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Correct wrong data
|
|
22
|
+
* strip(0.09999999999999998)=0.1
|
|
23
|
+
*/
|
|
24
|
+
function strip(num, precision) {
|
|
25
|
+
if (precision === void 0) {
|
|
26
|
+
precision = 12;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return +parseFloat(num.toPrecision(precision));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Return digits length of a number
|
|
33
|
+
* @param {*number} num Input number
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function digitLength(num) {
|
|
38
|
+
// Get digit length of e
|
|
39
|
+
var eSplit = num.toString().split(/[eE]/);
|
|
40
|
+
var len = (eSplit[0].split('.')[1] || '').length - +(eSplit[1] || 0);
|
|
41
|
+
return len > 0 ? len : 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert decimals to integers and support scientific notation. If it is a decimal, it is enlarged to an integer
|
|
45
|
+
* @param {*number} num Number of inputs
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function float2Fixed(num) {
|
|
50
|
+
if (num.toString().indexOf('e') === -1) {
|
|
51
|
+
return Number(num.toString().replace('.', ''));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var dLen = digitLength(num);
|
|
55
|
+
return dLen > 0 ? strip(num * Math.pow(10, dLen)) : num;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check whether the number is out of range, and give a prompt if it is out of range
|
|
59
|
+
* @param {*number} num Number of inputs
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
function checkBoundary(num) {
|
|
64
|
+
if (_boundaryCheckingState) {
|
|
65
|
+
if (num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) {
|
|
66
|
+
// eslint-disable-next-line no-console
|
|
67
|
+
console.warn(num + " is beyond boundary when transfer to integer, the results may not be accurate");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Exact multiplication
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function times(num1, num2) {
|
|
77
|
+
for (var _len = arguments.length, others = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
78
|
+
others[_key - 2] = arguments[_key];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (others.length > 0) {
|
|
82
|
+
return times.apply(void 0, [times(num1, num2), others[0]].concat(others.slice(1)));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
var num1Changed = float2Fixed(num1);
|
|
86
|
+
var num2Changed = float2Fixed(num2);
|
|
87
|
+
var baseNum = digitLength(num1) + digitLength(num2);
|
|
88
|
+
var leftValue = num1Changed * num2Changed;
|
|
89
|
+
checkBoundary(leftValue);
|
|
90
|
+
return leftValue / Math.pow(10, baseNum);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Exact addition
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function plus(num1, num2) {
|
|
98
|
+
for (var _len2 = arguments.length, others = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
99
|
+
others[_key2 - 2] = arguments[_key2];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (others.length > 0) {
|
|
103
|
+
return plus.apply(void 0, [plus(num1, num2), others[0]].concat(others.slice(1)));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
107
|
+
return (times(num1, baseNum) + times(num2, baseNum)) / baseNum;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Exact subtraction
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
function minus(num1, num2) {
|
|
115
|
+
for (var _len3 = arguments.length, others = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
116
|
+
others[_key3 - 2] = arguments[_key3];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (others.length > 0) {
|
|
120
|
+
return minus.apply(void 0, [minus(num1, num2), others[0]].concat(others.slice(1)));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var baseNum = Math.pow(10, Math.max(digitLength(num1), digitLength(num2)));
|
|
124
|
+
return (times(num1, baseNum) - times(num2, baseNum)) / baseNum;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Exact division
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
function divide(num1, num2) {
|
|
132
|
+
for (var _len4 = arguments.length, others = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
|
|
133
|
+
others[_key4 - 2] = arguments[_key4];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (others.length > 0) {
|
|
137
|
+
return divide.apply(void 0, [divide(num1, num2), others[0]].concat(others.slice(1)));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
var num1Changed = float2Fixed(num1);
|
|
141
|
+
var num2Changed = float2Fixed(num2);
|
|
142
|
+
checkBoundary(num1Changed);
|
|
143
|
+
checkBoundary(num2Changed); // fix: Similar to 10 ** -4 is 0.00009999999999999999, strip correction
|
|
144
|
+
|
|
145
|
+
return times(num1Changed / num2Changed, strip(Math.pow(10, digitLength(num2) - digitLength(num1))));
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* rounding
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function round(num, ratio) {
|
|
153
|
+
var base = Math.pow(10, ratio);
|
|
154
|
+
return divide(Math.round(times(num, base)), base);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var _boundaryCheckingState = true;
|
|
158
|
+
/**
|
|
159
|
+
* Whether to perform boundary check, default true
|
|
160
|
+
* @param flag Mark switch, true is on, false is off, default is true
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
function enableBoundaryChecking(flag) {
|
|
164
|
+
if (flag === void 0) {
|
|
165
|
+
flag = true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
_boundaryCheckingState = flag;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var _default = {
|
|
172
|
+
strip: strip,
|
|
173
|
+
plus: plus,
|
|
174
|
+
minus: minus,
|
|
175
|
+
times: times,
|
|
176
|
+
divide: divide,
|
|
177
|
+
round: round,
|
|
178
|
+
digitLength: digitLength,
|
|
179
|
+
float2Fixed: float2Fixed,
|
|
180
|
+
enableBoundaryChecking: enableBoundaryChecking
|
|
181
|
+
};
|
|
182
|
+
exports.default = _default;
|