hsu-utils 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/hsu-utils.js +12 -2
- package/dist/hsu-utils.min.js +1 -1
- package/dist/hsu-utils.min.js.LICENSE.txt +1 -1
- package/es/ConvertNumbers/index.d.ts +10 -0
- package/es/ConvertNumbers/index.js +71 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/lib/ConvertNumbers/index.d.ts +10 -0
- package/lib/ConvertNumbers/index.js +76 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/package.json +1 -1
package/dist/hsu-utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/*!
|
2
2
|
*
|
3
|
-
* hsu-utils v0.0.
|
3
|
+
* hsu-utils v0.0.8
|
4
4
|
*
|
5
5
|
* some front-end utils
|
6
6
|
*
|
@@ -59,6 +59,16 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nvar
|
|
59
59
|
|
60
60
|
/***/ }),
|
61
61
|
|
62
|
+
/***/ "./tools/ConvertNumbers/index.ts":
|
63
|
+
/*!***************************************!*\
|
64
|
+
!*** ./tools/ConvertNumbers/index.ts ***!
|
65
|
+
\***************************************/
|
66
|
+
/***/ ((__unused_webpack_module, exports) => {
|
67
|
+
|
68
|
+
eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.toChineseNum = void 0;\nfunction toChineseNum(num, options) {\n if (options === void 0) { options = {}; }\n var benchmark = options.benchmark, _a = options.textType, textType = _a === void 0 ? 'lowercase' : _a;\n var cnNums = {\n lowercase: ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'],\n uppercase: ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']\n };\n var cnIntRadice = {\n lowercase: ['', '十', '百', '千'],\n uppercase: ['', '拾', '佰', '仟']\n };\n var cnIntUnits = {\n lowercase: ['', '万', '亿', '兆'],\n uppercase: ['', '万', '亿', '兆']\n };\n var maxNum = 9999999999999999.9999999999999999;\n var integerNum = undefined;\n var decimalNum = undefined;\n var chineseStr = '';\n if (benchmark) {\n num *= benchmark;\n num = +num.toFixed(4);\n }\n if (num > maxNum) {\n return '超出转换范围';\n }\n var moneyStr = num.toString();\n integerNum = moneyStr.split('.')[0];\n decimalNum = moneyStr.split('.')[1];\n if (integerNum) {\n var zeroCount = 0;\n for (var i = 0; i < integerNum.length; i++) {\n var index = integerNum.length - i - 1;\n var num_1 = +integerNum[i];\n var units = Math.floor(index / 4);\n var radice = index % (4 * (units === 0 ? 1 : units));\n if (+integerNum[i] === 0) {\n zeroCount++;\n }\n else {\n if (zeroCount > 0) {\n chineseStr += cnNums[textType][0];\n zeroCount = 0;\n }\n chineseStr += \"\".concat(cnNums[textType][num_1] + cnIntRadice[textType][radice]);\n if (index % 4 === 0) {\n chineseStr += cnIntUnits[textType][units];\n }\n }\n }\n }\n if (decimalNum) {\n chineseStr += '点';\n for (var i = 0; i < decimalNum.length; i++) {\n var num_2 = +decimalNum[i];\n if (+decimalNum[i] === 0) {\n chineseStr += \"\".concat(cnNums[textType][0]);\n }\n else {\n chineseStr += \"\".concat(cnNums[textType][num_2]);\n }\n }\n }\n if (chineseStr === '') {\n chineseStr += cnNums[textType][0];\n }\n return chineseStr;\n}\nexports.toChineseNum = toChineseNum;\nvar ConvertNumbers = {\n toChineseNum: toChineseNum\n};\nexports[\"default\"] = ConvertNumbers;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/ConvertNumbers/index.ts?");
|
69
|
+
|
70
|
+
/***/ }),
|
71
|
+
|
62
72
|
/***/ "./tools/DeepCopy/index.ts":
|
63
73
|
/*!*********************************!*\
|
64
74
|
!*** ./tools/DeepCopy/index.ts ***!
|
@@ -105,7 +115,7 @@ eval("\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nfunc
|
|
105
115
|
\************************/
|
106
116
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
107
117
|
|
108
|
-
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\nvar GetStrWidth_1 = __importDefault(__webpack_require__(/*! ./GetStrWidth */ \"./tools/GetStrWidth/index.ts\"));\nexports.get_string_width = GetStrWidth_1.default;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/index.ts?");
|
118
|
+
eval("\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", ({ value: true }));\nexports.ConvertNumbers = exports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;\nvar ConsoleTable_1 = __importDefault(__webpack_require__(/*! ./ConsoleTable */ \"./tools/ConsoleTable/index.ts\"));\nexports.console_table = ConsoleTable_1.default;\nvar DeepCopy_1 = __importDefault(__webpack_require__(/*! ./DeepCopy */ \"./tools/DeepCopy/index.ts\"));\nexports.deepCopy = DeepCopy_1.default;\nvar Equal_1 = __importDefault(__webpack_require__(/*! ./Equal */ \"./tools/Equal/index.ts\"));\nexports.Equal = Equal_1.default;\nvar Typeof_1 = __importDefault(__webpack_require__(/*! ./Typeof */ \"./tools/Typeof/index.ts\"));\nexports.Typeof = Typeof_1.default;\nvar GetStrWidth_1 = __importDefault(__webpack_require__(/*! ./GetStrWidth */ \"./tools/GetStrWidth/index.ts\"));\nexports.get_string_width = GetStrWidth_1.default;\nvar ConvertNumbers_1 = __importDefault(__webpack_require__(/*! ./ConvertNumbers */ \"./tools/ConvertNumbers/index.ts\"));\nexports.ConvertNumbers = ConvertNumbers_1.default;\n\n\n//# sourceURL=webpack://hsu-utils/./tools/index.ts?");
|
109
119
|
|
110
120
|
/***/ })
|
111
121
|
|
package/dist/hsu-utils.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/*! For license information please see hsu-utils.min.js.LICENSE.txt */
|
2
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",a=" ",u="";function f(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?1:2}return t}function l(e,t){void 0===t&&(t=!1);var n=e.length,a="";return e.forEach((function(e,f){a+=r+function(e){for(var t="",r=0;r<=e;r++)t+=o;return t}(e+1),a+=f===n-1?r+(t?u:"\n"):u})),a}function i(e){for(var t="",r=0;r<=e;r++)t+=a;return t}t.default=function(e,t){var r=e.length,o=function(e){for(var t=Object.keys(e[0]).map((function(e){return+e})),r=0,o=e;r<o.length;r++)o[r].forEach((function(e,r){var o=f(e.toString());t[r]=Math.max(o,t[r])}));return t}(e),c="";e.forEach((function(e,t){t<=1&&(c+=l(o)),c+=function(e,t){var r=e.length,o="";return e.forEach((function(e,l){var c=t[l],p="";isNaN(+c)?p+=a+(null!=c?c:"")+i(e-f((null!=c?c:"").toString())):p+=i(e-f(c.toString()))+c+a,o+=n+p,o+=l===r-1?n+"\n":u})),o}(o,e),t===r-1&&(c+=l(o,!0))})),console.log(c),t&&t(c)}},819:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(243);t.default=function e(t){if("date"===(0,o.Typeof)(t))return new Date(t.toISOString());if("formdata"===(0,o.Typeof)(t)){var r=t,n=new FormData;return r.forEach((function(e,t){n.append(t,e)})),n}if(Array.isArray(t))return t.map((function(t){return"object"==typeof t?e(t):t}));if(t&&"object"===(0,o.Typeof)(t)){var a=t,u={};return Object.keys(a).forEach((function(t){var r=a[t];u[t]="object"==typeof r?e(r):r})),u}return t}},962:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjEqual=t.ValEqual=t.TypeEqual=void 0;var o=r(243);function n(e,t){return(0,o.Typeof)(e)===(0,o.Typeof)(t)}function a(e,t){return null===e&&void 0===t||void 0===e&&null===t||("object"==typeof e&&"object"==typeof t?u(e,t):"function"==typeof e&&"function"==typeof t?JSON.stringify(e)===JSON.stringify(t):e===t)}function u(e,t){var r=!1,n=(0,o.deepCopy)(e),u=(0,o.deepCopy)(t);if(null!==n&&null!==u){if(Array.isArray(n)&&Array.isArray(u))if(n.sort(),u.sort(),n.length!==u.length)r=!1;else{r=!0;for(var f=0;f<n.length&&(r=a(n[f],u[f]));f++);}else if("object"==typeof n&&"object"==typeof u)if(Object.keys(n).length!==Object.keys(u).length)r=!1;else for(var l in r=!0,n)if(!(r=a(n[l],u[l])))break}else null===n&&null===u&&(r=!0);return r}t.TypeEqual=n,t.ValEqual=a,t.ObjEqual=u;var f={ValEqual:a,TypeEqual:n,ObjEqual:u};t.default=f},285:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?.5:1}return t}},332:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=Object.prototype.toString.call(e),r=new RegExp(" (.+?)]");return t.match(r)[1].toLowerCase()}},243:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.get_string_width=t.Typeof=t.Equal=t.deepCopy=t.console_table=void 0;var n=o(r(442));t.console_table=n.default;var a=o(r(819));t.deepCopy=a.default;var u=o(r(962));t.Equal=u.default;var f=o(r(332));t.Typeof=f.default;var l=o(r(285));t.get_string_width=l.default}},t={};var r=function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,r),a.exports}(243);return r})()));
|
2
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["hsu-utils"]=t():e["hsu-utils"]=t()}(this,(()=>(()=>{"use strict";var e={442:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0});var r="+",o="-",n="|",a=" ",u="";function f(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?1:2}return t}function l(e,t){void 0===t&&(t=!1);var n=e.length,a="";return e.forEach((function(e,f){a+=r+function(e){for(var t="",r=0;r<=e;r++)t+=o;return t}(e+1),a+=f===n-1?r+(t?u:"\n"):u})),a}function i(e){for(var t="",r=0;r<=e;r++)t+=a;return t}t.default=function(e,t){var r=e.length,o=function(e){for(var t=Object.keys(e[0]).map((function(e){return+e})),r=0,o=e;r<o.length;r++)o[r].forEach((function(e,r){var o=f(e.toString());t[r]=Math.max(o,t[r])}));return t}(e),c="";e.forEach((function(e,t){t<=1&&(c+=l(o)),c+=function(e,t){var r=e.length,o="";return e.forEach((function(e,l){var c=t[l],p="";isNaN(+c)?p+=a+(null!=c?c:"")+i(e-f((null!=c?c:"").toString())):p+=i(e-f(c.toString()))+c+a,o+=n+p,o+=l===r-1?n+"\n":u})),o}(o,e),t===r-1&&(c+=l(o,!0))})),console.log(c),t&&t(c)}},84:(e,t)=>{function r(e,t){void 0===t&&(t={});var r,o,n=t.benchmark,a=t.textType,u=void 0===a?"lowercase":a,f={lowercase:["零","一","二","三","四","五","六","七","八","九"],uppercase:["零","壹","贰","叁","肆","伍","陆","柒","捌","玖"]},l={lowercase:["","十","百","千"],uppercase:["","拾","佰","仟"]},i={lowercase:["","万","亿","兆"],uppercase:["","万","亿","兆"]},c="";if(n&&(e=+(e*=n).toFixed(4)),e>1e16)return"超出转换范围";var p=e.toString();if(r=p.split(".")[0],o=p.split(".")[1],r)for(var s=0,v=0;v<r.length;v++){var d=r.length-v-1,y=+r[v],h=Math.floor(d/4),b=d%(4*(0===h?1:h));0==+r[v]?s++:(s>0&&(c+=f[u][0],s=0),c+="".concat(f[u][y]+l[u][b]),d%4==0&&(c+=i[u][h]))}if(o){c+="点";for(v=0;v<o.length;v++){var g=+o[v];0==+o[v]?c+="".concat(f[u][0]):c+="".concat(f[u][g])}}return""===c&&(c+=f[u][0]),c}Object.defineProperty(t,"__esModule",{value:!0}),t.toChineseNum=void 0,t.toChineseNum=r;var o={toChineseNum:r};t.default=o},819:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0});var o=r(243);t.default=function e(t){if("date"===(0,o.Typeof)(t))return new Date(t.toISOString());if("formdata"===(0,o.Typeof)(t)){var r=t,n=new FormData;return r.forEach((function(e,t){n.append(t,e)})),n}if(Array.isArray(t))return t.map((function(t){return"object"==typeof t?e(t):t}));if(t&&"object"===(0,o.Typeof)(t)){var a=t,u={};return Object.keys(a).forEach((function(t){var r=a[t];u[t]="object"==typeof r?e(r):r})),u}return t}},962:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ObjEqual=t.ValEqual=t.TypeEqual=void 0;var o=r(243);function n(e,t){return(0,o.Typeof)(e)===(0,o.Typeof)(t)}function a(e,t){return null===e&&void 0===t||void 0===e&&null===t||("object"==typeof e&&"object"==typeof t?u(e,t):"function"==typeof e&&"function"==typeof t?JSON.stringify(e)===JSON.stringify(t):e===t)}function u(e,t){var r=!1,n=(0,o.deepCopy)(e),u=(0,o.deepCopy)(t);if(null!==n&&null!==u){if(Array.isArray(n)&&Array.isArray(u))if(n.sort(),u.sort(),n.length!==u.length)r=!1;else{r=!0;for(var f=0;f<n.length&&(r=a(n[f],u[f]));f++);}else if("object"==typeof n&&"object"==typeof u)if(Object.keys(n).length!==Object.keys(u).length)r=!1;else for(var l in r=!0,n)if(!(r=a(n[l],u[l])))break}else null===n&&null===u&&(r=!0);return r}t.TypeEqual=n,t.ValEqual=a,t.ObjEqual=u;var f={ValEqual:a,TypeEqual:n,ObjEqual:u};t.default=f},285:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){for(var t=0,r=0,o=e;r<o.length;r++){var n=o[r];t+=n.charCodeAt(0)<128&&n.charCodeAt(0)>=0?.5:1}return t}},332:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=Object.prototype.toString.call(e),r=new RegExp(" (.+?)]");return t.match(r)[1].toLowerCase()}},243:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ConvertNumbers=t.get_string_width=t.Typeof=t.Equal=t.deepCopy=t.console_table=void 0;var n=o(r(442));t.console_table=n.default;var a=o(r(819));t.deepCopy=a.default;var u=o(r(962));t.Equal=u.default;var f=o(r(332));t.Typeof=f.default;var l=o(r(285));t.get_string_width=l.default;var i=o(r(84));t.ConvertNumbers=i.default}},t={};var r=function r(o){var n=t[o];if(void 0!==n)return n.exports;var a=t[o]={exports:{}};return e[o].call(a.exports,a,a.exports,r),a.exports}(243);return r})()));
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export type TextType = 'lowercase' | 'uppercase';
|
2
|
+
export interface C_Options {
|
3
|
+
benchmark?: number;
|
4
|
+
textType?: TextType;
|
5
|
+
}
|
6
|
+
export declare function toChineseNum(num: number, options?: C_Options): string;
|
7
|
+
declare const ConvertNumbers: {
|
8
|
+
toChineseNum: typeof toChineseNum;
|
9
|
+
};
|
10
|
+
export default ConvertNumbers;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
export function toChineseNum(num, options = {}) {
|
2
|
+
const { benchmark, textType = 'lowercase' } = options;
|
3
|
+
const cnNums = {
|
4
|
+
lowercase: ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'],
|
5
|
+
uppercase: ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
|
6
|
+
};
|
7
|
+
const cnIntRadice = {
|
8
|
+
lowercase: ['', '十', '百', '千'],
|
9
|
+
uppercase: ['', '拾', '佰', '仟']
|
10
|
+
};
|
11
|
+
const cnIntUnits = {
|
12
|
+
lowercase: ['', '万', '亿', '兆'],
|
13
|
+
uppercase: ['', '万', '亿', '兆']
|
14
|
+
};
|
15
|
+
const maxNum = 9999999999999999.9999999999999999;
|
16
|
+
let integerNum = undefined;
|
17
|
+
let decimalNum = undefined;
|
18
|
+
let chineseStr = '';
|
19
|
+
if (benchmark) {
|
20
|
+
num *= benchmark;
|
21
|
+
num = +num.toFixed(4);
|
22
|
+
}
|
23
|
+
if (num > maxNum) {
|
24
|
+
return '超出转换范围';
|
25
|
+
}
|
26
|
+
const moneyStr = num.toString();
|
27
|
+
integerNum = moneyStr.split('.')[0];
|
28
|
+
decimalNum = moneyStr.split('.')[1];
|
29
|
+
if (integerNum) {
|
30
|
+
let zeroCount = 0;
|
31
|
+
for (let i = 0; i < integerNum.length; i++) {
|
32
|
+
const index = integerNum.length - i - 1;
|
33
|
+
const num = +integerNum[i];
|
34
|
+
const units = Math.floor(index / 4);
|
35
|
+
const radice = index % (4 * (units === 0 ? 1 : units));
|
36
|
+
if (+integerNum[i] === 0) {
|
37
|
+
zeroCount++;
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
if (zeroCount > 0) {
|
41
|
+
chineseStr += cnNums[textType][0];
|
42
|
+
zeroCount = 0;
|
43
|
+
}
|
44
|
+
chineseStr += `${cnNums[textType][num] + cnIntRadice[textType][radice]}`;
|
45
|
+
if (index % 4 === 0) {
|
46
|
+
chineseStr += cnIntUnits[textType][units];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if (decimalNum) {
|
52
|
+
chineseStr += '点';
|
53
|
+
for (let i = 0; i < decimalNum.length; i++) {
|
54
|
+
const num = +decimalNum[i];
|
55
|
+
if (+decimalNum[i] === 0) {
|
56
|
+
chineseStr += `${cnNums[textType][0]}`;
|
57
|
+
}
|
58
|
+
else {
|
59
|
+
chineseStr += `${cnNums[textType][num]}`;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
if (chineseStr === '') {
|
64
|
+
chineseStr += cnNums[textType][0];
|
65
|
+
}
|
66
|
+
return chineseStr;
|
67
|
+
}
|
68
|
+
const ConvertNumbers = {
|
69
|
+
toChineseNum
|
70
|
+
};
|
71
|
+
export default ConvertNumbers;
|
package/es/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ import deepCopy from './DeepCopy';
|
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
5
|
import get_string_width from './GetStrWidth';
|
6
|
-
|
6
|
+
import ConvertNumbers from './ConvertNumbers';
|
7
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers };
|
7
8
|
import { ConsoleData } from './ConsoleTable';
|
8
9
|
export type { ConsoleData };
|
package/es/index.js
CHANGED
@@ -3,4 +3,5 @@ import deepCopy from './DeepCopy';
|
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
5
|
import get_string_width from './GetStrWidth';
|
6
|
-
|
6
|
+
import ConvertNumbers from './ConvertNumbers';
|
7
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export type TextType = 'lowercase' | 'uppercase';
|
2
|
+
export interface C_Options {
|
3
|
+
benchmark?: number;
|
4
|
+
textType?: TextType;
|
5
|
+
}
|
6
|
+
export declare function toChineseNum(num: number, options?: C_Options): string;
|
7
|
+
declare const ConvertNumbers: {
|
8
|
+
toChineseNum: typeof toChineseNum;
|
9
|
+
};
|
10
|
+
export default ConvertNumbers;
|
@@ -0,0 +1,76 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.toChineseNum = void 0;
|
4
|
+
function toChineseNum(num, options) {
|
5
|
+
if (options === void 0) { options = {}; }
|
6
|
+
var benchmark = options.benchmark, _a = options.textType, textType = _a === void 0 ? 'lowercase' : _a;
|
7
|
+
var cnNums = {
|
8
|
+
lowercase: ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'],
|
9
|
+
uppercase: ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
|
10
|
+
};
|
11
|
+
var cnIntRadice = {
|
12
|
+
lowercase: ['', '十', '百', '千'],
|
13
|
+
uppercase: ['', '拾', '佰', '仟']
|
14
|
+
};
|
15
|
+
var cnIntUnits = {
|
16
|
+
lowercase: ['', '万', '亿', '兆'],
|
17
|
+
uppercase: ['', '万', '亿', '兆']
|
18
|
+
};
|
19
|
+
var maxNum = 9999999999999999.9999999999999999;
|
20
|
+
var integerNum = undefined;
|
21
|
+
var decimalNum = undefined;
|
22
|
+
var chineseStr = '';
|
23
|
+
if (benchmark) {
|
24
|
+
num *= benchmark;
|
25
|
+
num = +num.toFixed(4);
|
26
|
+
}
|
27
|
+
if (num > maxNum) {
|
28
|
+
return '超出转换范围';
|
29
|
+
}
|
30
|
+
var moneyStr = num.toString();
|
31
|
+
integerNum = moneyStr.split('.')[0];
|
32
|
+
decimalNum = moneyStr.split('.')[1];
|
33
|
+
if (integerNum) {
|
34
|
+
var zeroCount = 0;
|
35
|
+
for (var i = 0; i < integerNum.length; i++) {
|
36
|
+
var index = integerNum.length - i - 1;
|
37
|
+
var num_1 = +integerNum[i];
|
38
|
+
var units = Math.floor(index / 4);
|
39
|
+
var radice = index % (4 * (units === 0 ? 1 : units));
|
40
|
+
if (+integerNum[i] === 0) {
|
41
|
+
zeroCount++;
|
42
|
+
}
|
43
|
+
else {
|
44
|
+
if (zeroCount > 0) {
|
45
|
+
chineseStr += cnNums[textType][0];
|
46
|
+
zeroCount = 0;
|
47
|
+
}
|
48
|
+
chineseStr += "".concat(cnNums[textType][num_1] + cnIntRadice[textType][radice]);
|
49
|
+
if (index % 4 === 0) {
|
50
|
+
chineseStr += cnIntUnits[textType][units];
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
}
|
55
|
+
if (decimalNum) {
|
56
|
+
chineseStr += '点';
|
57
|
+
for (var i = 0; i < decimalNum.length; i++) {
|
58
|
+
var num_2 = +decimalNum[i];
|
59
|
+
if (+decimalNum[i] === 0) {
|
60
|
+
chineseStr += "".concat(cnNums[textType][0]);
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
chineseStr += "".concat(cnNums[textType][num_2]);
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
if (chineseStr === '') {
|
68
|
+
chineseStr += cnNums[textType][0];
|
69
|
+
}
|
70
|
+
return chineseStr;
|
71
|
+
}
|
72
|
+
exports.toChineseNum = toChineseNum;
|
73
|
+
var ConvertNumbers = {
|
74
|
+
toChineseNum: toChineseNum
|
75
|
+
};
|
76
|
+
exports.default = ConvertNumbers;
|
package/lib/index.d.ts
CHANGED
@@ -3,6 +3,7 @@ import deepCopy from './DeepCopy';
|
|
3
3
|
import Equal from './Equal';
|
4
4
|
import Typeof from './Typeof';
|
5
5
|
import get_string_width from './GetStrWidth';
|
6
|
-
|
6
|
+
import ConvertNumbers from './ConvertNumbers';
|
7
|
+
export { console_table, deepCopy, Equal, Typeof, get_string_width, ConvertNumbers };
|
7
8
|
import { ConsoleData } from './ConsoleTable';
|
8
9
|
export type { ConsoleData };
|
package/lib/index.js
CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
4
|
};
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
|
6
|
+
exports.ConvertNumbers = exports.get_string_width = exports.Typeof = exports.Equal = exports.deepCopy = exports.console_table = void 0;
|
7
7
|
var ConsoleTable_1 = __importDefault(require("./ConsoleTable"));
|
8
8
|
exports.console_table = ConsoleTable_1.default;
|
9
9
|
var DeepCopy_1 = __importDefault(require("./DeepCopy"));
|
@@ -14,3 +14,5 @@ var Typeof_1 = __importDefault(require("./Typeof"));
|
|
14
14
|
exports.Typeof = Typeof_1.default;
|
15
15
|
var GetStrWidth_1 = __importDefault(require("./GetStrWidth"));
|
16
16
|
exports.get_string_width = GetStrWidth_1.default;
|
17
|
+
var ConvertNumbers_1 = __importDefault(require("./ConvertNumbers"));
|
18
|
+
exports.ConvertNumbers = ConvertNumbers_1.default;
|