first commit
This commit is contained in:
34
frontend/node_modules/@rc-component/mini-decimal/es/BigIntDecimal.d.ts
generated
vendored
Normal file
34
frontend/node_modules/@rc-component/mini-decimal/es/BigIntDecimal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { DecimalClass, ValueType } from './interface';
|
||||
export default class BigIntDecimal implements DecimalClass {
|
||||
origin: string;
|
||||
negative: boolean;
|
||||
integer: bigint;
|
||||
decimal: bigint;
|
||||
/** BigInt will convert `0009` to `9`. We need record the len of decimal */
|
||||
decimalLen: number;
|
||||
empty: boolean;
|
||||
nan: boolean;
|
||||
constructor(value: string | number);
|
||||
private getMark;
|
||||
private getIntegerStr;
|
||||
/**
|
||||
* @private get decimal string
|
||||
*/
|
||||
getDecimalStr(): string;
|
||||
/**
|
||||
* @private Align BigIntDecimal with same decimal length. e.g. 12.3 + 5 = 1230000
|
||||
* This is used for add function only.
|
||||
*/
|
||||
alignDecimal(decimalLength: number): bigint;
|
||||
negate(): BigIntDecimal;
|
||||
private cal;
|
||||
add(value: ValueType): BigIntDecimal;
|
||||
multi(value: ValueType): BigIntDecimal;
|
||||
isEmpty(): boolean;
|
||||
isNaN(): boolean;
|
||||
isInvalidate(): boolean;
|
||||
equals(target: DecimalClass): boolean;
|
||||
lessEquals(target: DecimalClass): boolean;
|
||||
toNumber(): number;
|
||||
toString(safe?: boolean): string;
|
||||
}
|
||||
177
frontend/node_modules/@rc-component/mini-decimal/es/BigIntDecimal.js
generated
vendored
Normal file
177
frontend/node_modules/@rc-component/mini-decimal/es/BigIntDecimal.js
generated
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import { isE, isEmpty, num2str, trimNumber, validateNumber } from "./numberUtil";
|
||||
var BigIntDecimal = /*#__PURE__*/function () {
|
||||
/** BigInt will convert `0009` to `9`. We need record the len of decimal */
|
||||
|
||||
function BigIntDecimal(value) {
|
||||
_classCallCheck(this, BigIntDecimal);
|
||||
_defineProperty(this, "origin", '');
|
||||
_defineProperty(this, "negative", void 0);
|
||||
_defineProperty(this, "integer", void 0);
|
||||
_defineProperty(this, "decimal", void 0);
|
||||
_defineProperty(this, "decimalLen", void 0);
|
||||
_defineProperty(this, "empty", void 0);
|
||||
_defineProperty(this, "nan", void 0);
|
||||
if (isEmpty(value)) {
|
||||
this.empty = true;
|
||||
return;
|
||||
}
|
||||
this.origin = String(value);
|
||||
|
||||
// Act like Number convert
|
||||
if (value === '-' || Number.isNaN(value)) {
|
||||
this.nan = true;
|
||||
return;
|
||||
}
|
||||
var mergedValue = value;
|
||||
|
||||
// We need convert back to Number since it require `toFixed` to handle this
|
||||
if (isE(mergedValue)) {
|
||||
mergedValue = Number(mergedValue);
|
||||
}
|
||||
mergedValue = typeof mergedValue === 'string' ? mergedValue : num2str(mergedValue);
|
||||
if (validateNumber(mergedValue)) {
|
||||
var trimRet = trimNumber(mergedValue);
|
||||
this.negative = trimRet.negative;
|
||||
var numbers = trimRet.trimStr.split('.');
|
||||
this.integer = BigInt(numbers[0]);
|
||||
var decimalStr = numbers[1] || '0';
|
||||
this.decimal = BigInt(decimalStr);
|
||||
this.decimalLen = decimalStr.length;
|
||||
} else {
|
||||
this.nan = true;
|
||||
}
|
||||
}
|
||||
_createClass(BigIntDecimal, [{
|
||||
key: "getMark",
|
||||
value: function getMark() {
|
||||
return this.negative ? '-' : '';
|
||||
}
|
||||
}, {
|
||||
key: "getIntegerStr",
|
||||
value: function getIntegerStr() {
|
||||
return this.integer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private get decimal string
|
||||
*/
|
||||
}, {
|
||||
key: "getDecimalStr",
|
||||
value: function getDecimalStr() {
|
||||
return this.decimal.toString().padStart(this.decimalLen, '0');
|
||||
}
|
||||
|
||||
/**
|
||||
* @private Align BigIntDecimal with same decimal length. e.g. 12.3 + 5 = 1230000
|
||||
* This is used for add function only.
|
||||
*/
|
||||
}, {
|
||||
key: "alignDecimal",
|
||||
value: function alignDecimal(decimalLength) {
|
||||
var str = "".concat(this.getMark()).concat(this.getIntegerStr()).concat(this.getDecimalStr().padEnd(decimalLength, '0'));
|
||||
return BigInt(str);
|
||||
}
|
||||
}, {
|
||||
key: "negate",
|
||||
value: function negate() {
|
||||
var clone = new BigIntDecimal(this.toString());
|
||||
clone.negative = !clone.negative;
|
||||
return clone;
|
||||
}
|
||||
}, {
|
||||
key: "cal",
|
||||
value: function cal(offset, calculator, calDecimalLen) {
|
||||
var maxDecimalLength = Math.max(this.getDecimalStr().length, offset.getDecimalStr().length);
|
||||
var myAlignedDecimal = this.alignDecimal(maxDecimalLength);
|
||||
var offsetAlignedDecimal = offset.alignDecimal(maxDecimalLength);
|
||||
var valueStr = calculator(myAlignedDecimal, offsetAlignedDecimal).toString();
|
||||
var nextDecimalLength = calDecimalLen(maxDecimalLength);
|
||||
|
||||
// We need fill string length back to `maxDecimalLength` to avoid parser failed
|
||||
var _trimNumber = trimNumber(valueStr),
|
||||
negativeStr = _trimNumber.negativeStr,
|
||||
trimStr = _trimNumber.trimStr;
|
||||
var hydrateValueStr = "".concat(negativeStr).concat(trimStr.padStart(nextDecimalLength + 1, '0'));
|
||||
return new BigIntDecimal("".concat(hydrateValueStr.slice(0, -nextDecimalLength), ".").concat(hydrateValueStr.slice(-nextDecimalLength)));
|
||||
}
|
||||
}, {
|
||||
key: "add",
|
||||
value: function add(value) {
|
||||
if (this.isInvalidate()) {
|
||||
return new BigIntDecimal(value);
|
||||
}
|
||||
var offset = new BigIntDecimal(value);
|
||||
if (offset.isInvalidate()) {
|
||||
return this;
|
||||
}
|
||||
return this.cal(offset, function (num1, num2) {
|
||||
return num1 + num2;
|
||||
}, function (len) {
|
||||
return len;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "multi",
|
||||
value: function multi(value) {
|
||||
var target = new BigIntDecimal(value);
|
||||
if (this.isInvalidate() || target.isInvalidate()) {
|
||||
return new BigIntDecimal(NaN);
|
||||
}
|
||||
return this.cal(target, function (num1, num2) {
|
||||
return num1 * num2;
|
||||
}, function (len) {
|
||||
return len * 2;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "isEmpty",
|
||||
value: function isEmpty() {
|
||||
return this.empty;
|
||||
}
|
||||
}, {
|
||||
key: "isNaN",
|
||||
value: function isNaN() {
|
||||
return this.nan;
|
||||
}
|
||||
}, {
|
||||
key: "isInvalidate",
|
||||
value: function isInvalidate() {
|
||||
return this.isEmpty() || this.isNaN();
|
||||
}
|
||||
}, {
|
||||
key: "equals",
|
||||
value: function equals(target) {
|
||||
return this.toString() === (target === null || target === void 0 ? void 0 : target.toString());
|
||||
}
|
||||
}, {
|
||||
key: "lessEquals",
|
||||
value: function lessEquals(target) {
|
||||
return this.add(target.negate().toString()).toNumber() <= 0;
|
||||
}
|
||||
}, {
|
||||
key: "toNumber",
|
||||
value: function toNumber() {
|
||||
if (this.isNaN()) {
|
||||
return NaN;
|
||||
}
|
||||
return Number(this.toString());
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
var safe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
||||
if (!safe) {
|
||||
return this.origin;
|
||||
}
|
||||
if (this.isInvalidate()) {
|
||||
return '';
|
||||
}
|
||||
return trimNumber("".concat(this.getMark()).concat(this.getIntegerStr(), ".").concat(this.getDecimalStr())).fullStr;
|
||||
}
|
||||
}]);
|
||||
return BigIntDecimal;
|
||||
}();
|
||||
export { BigIntDecimal as default };
|
||||
11
frontend/node_modules/@rc-component/mini-decimal/es/MiniDecimal.d.ts
generated
vendored
Normal file
11
frontend/node_modules/@rc-component/mini-decimal/es/MiniDecimal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import BigIntDecimal from './BigIntDecimal';
|
||||
import NumberDecimal from './NumberDecimal';
|
||||
import type { DecimalClass, ValueType } from './interface';
|
||||
export { NumberDecimal, BigIntDecimal };
|
||||
export type { DecimalClass, ValueType };
|
||||
export default function getMiniDecimal(value: ValueType): DecimalClass;
|
||||
/**
|
||||
* Align the logic of toFixed to around like 1.5 => 2.
|
||||
* If set `cutOnly`, will just remove the over decimal part.
|
||||
*/
|
||||
export declare function toFixed(numStr: string, separatorStr: string, precision?: number, cutOnly?: boolean): any;
|
||||
50
frontend/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js
generated
vendored
Normal file
50
frontend/node_modules/@rc-component/mini-decimal/es/MiniDecimal.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/* eslint-disable max-classes-per-file */
|
||||
|
||||
import BigIntDecimal from "./BigIntDecimal";
|
||||
import NumberDecimal from "./NumberDecimal";
|
||||
import { trimNumber } from "./numberUtil";
|
||||
import { supportBigInt } from "./supportUtil";
|
||||
|
||||
// Still support origin export
|
||||
export { NumberDecimal, BigIntDecimal };
|
||||
export default function getMiniDecimal(value) {
|
||||
// We use BigInt here.
|
||||
// Will fallback to Number if not support.
|
||||
if (supportBigInt()) {
|
||||
return new BigIntDecimal(value);
|
||||
}
|
||||
return new NumberDecimal(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Align the logic of toFixed to around like 1.5 => 2.
|
||||
* If set `cutOnly`, will just remove the over decimal part.
|
||||
*/
|
||||
export function toFixed(numStr, separatorStr, precision) {
|
||||
var cutOnly = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
||||
if (numStr === '') {
|
||||
return '';
|
||||
}
|
||||
var _trimNumber = trimNumber(numStr),
|
||||
negativeStr = _trimNumber.negativeStr,
|
||||
integerStr = _trimNumber.integerStr,
|
||||
decimalStr = _trimNumber.decimalStr;
|
||||
var precisionDecimalStr = "".concat(separatorStr).concat(decimalStr);
|
||||
var numberWithoutDecimal = "".concat(negativeStr).concat(integerStr);
|
||||
if (precision >= 0) {
|
||||
// We will get last + 1 number to check if need advanced number
|
||||
var advancedNum = Number(decimalStr[precision]);
|
||||
if (advancedNum >= 5 && !cutOnly) {
|
||||
var advancedDecimal = getMiniDecimal(numStr).add("".concat(negativeStr, "0.").concat('0'.repeat(precision)).concat(10 - advancedNum));
|
||||
return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
|
||||
}
|
||||
if (precision === 0) {
|
||||
return numberWithoutDecimal;
|
||||
}
|
||||
return "".concat(numberWithoutDecimal).concat(separatorStr).concat(decimalStr.padEnd(precision, '0').slice(0, precision));
|
||||
}
|
||||
if (precisionDecimalStr === '.0') {
|
||||
return numberWithoutDecimal;
|
||||
}
|
||||
return "".concat(numberWithoutDecimal).concat(precisionDecimalStr);
|
||||
}
|
||||
20
frontend/node_modules/@rc-component/mini-decimal/es/NumberDecimal.d.ts
generated
vendored
Normal file
20
frontend/node_modules/@rc-component/mini-decimal/es/NumberDecimal.d.ts
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { DecimalClass, ValueType } from './interface';
|
||||
/**
|
||||
* We can remove this when IE not support anymore
|
||||
*/
|
||||
export default class NumberDecimal implements DecimalClass {
|
||||
origin: string;
|
||||
number: number;
|
||||
empty: boolean;
|
||||
constructor(value: ValueType);
|
||||
negate(): NumberDecimal;
|
||||
add(value: ValueType): NumberDecimal;
|
||||
multi(value: ValueType): NumberDecimal;
|
||||
isEmpty(): boolean;
|
||||
isNaN(): boolean;
|
||||
isInvalidate(): boolean;
|
||||
equals(target: DecimalClass): boolean;
|
||||
lessEquals(target: DecimalClass): boolean;
|
||||
toNumber(): number;
|
||||
toString(safe?: boolean): string;
|
||||
}
|
||||
113
frontend/node_modules/@rc-component/mini-decimal/es/NumberDecimal.js
generated
vendored
Normal file
113
frontend/node_modules/@rc-component/mini-decimal/es/NumberDecimal.js
generated
vendored
Normal file
@@ -0,0 +1,113 @@
|
||||
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
||||
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
||||
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||||
import { getNumberPrecision, isEmpty, num2str } from "./numberUtil";
|
||||
|
||||
/**
|
||||
* We can remove this when IE not support anymore
|
||||
*/
|
||||
var NumberDecimal = /*#__PURE__*/function () {
|
||||
function NumberDecimal(value) {
|
||||
_classCallCheck(this, NumberDecimal);
|
||||
_defineProperty(this, "origin", '');
|
||||
_defineProperty(this, "number", void 0);
|
||||
_defineProperty(this, "empty", void 0);
|
||||
if (isEmpty(value)) {
|
||||
this.empty = true;
|
||||
return;
|
||||
}
|
||||
this.origin = String(value);
|
||||
this.number = Number(value);
|
||||
}
|
||||
_createClass(NumberDecimal, [{
|
||||
key: "negate",
|
||||
value: function negate() {
|
||||
return new NumberDecimal(-this.toNumber());
|
||||
}
|
||||
}, {
|
||||
key: "add",
|
||||
value: function add(value) {
|
||||
if (this.isInvalidate()) {
|
||||
return new NumberDecimal(value);
|
||||
}
|
||||
var target = Number(value);
|
||||
if (Number.isNaN(target)) {
|
||||
return this;
|
||||
}
|
||||
var number = this.number + target;
|
||||
|
||||
// [Legacy] Back to safe integer
|
||||
if (number > Number.MAX_SAFE_INTEGER) {
|
||||
return new NumberDecimal(Number.MAX_SAFE_INTEGER);
|
||||
}
|
||||
if (number < Number.MIN_SAFE_INTEGER) {
|
||||
return new NumberDecimal(Number.MIN_SAFE_INTEGER);
|
||||
}
|
||||
var maxPrecision = Math.max(getNumberPrecision(this.number), getNumberPrecision(target));
|
||||
return new NumberDecimal(number.toFixed(maxPrecision));
|
||||
}
|
||||
}, {
|
||||
key: "multi",
|
||||
value: function multi(value) {
|
||||
var target = Number(value);
|
||||
if (this.isInvalidate() || Number.isNaN(target)) {
|
||||
return new NumberDecimal(NaN);
|
||||
}
|
||||
var number = this.number * target;
|
||||
|
||||
// [Legacy] Back to safe integer
|
||||
if (number > Number.MAX_SAFE_INTEGER) {
|
||||
return new NumberDecimal(Number.MAX_SAFE_INTEGER);
|
||||
}
|
||||
if (number < Number.MIN_SAFE_INTEGER) {
|
||||
return new NumberDecimal(Number.MIN_SAFE_INTEGER);
|
||||
}
|
||||
var maxPrecision = Math.max(getNumberPrecision(this.number), getNumberPrecision(target));
|
||||
return new NumberDecimal(number.toFixed(maxPrecision));
|
||||
}
|
||||
}, {
|
||||
key: "isEmpty",
|
||||
value: function isEmpty() {
|
||||
return this.empty;
|
||||
}
|
||||
}, {
|
||||
key: "isNaN",
|
||||
value: function isNaN() {
|
||||
return Number.isNaN(this.number);
|
||||
}
|
||||
}, {
|
||||
key: "isInvalidate",
|
||||
value: function isInvalidate() {
|
||||
return this.isEmpty() || this.isNaN();
|
||||
}
|
||||
}, {
|
||||
key: "equals",
|
||||
value: function equals(target) {
|
||||
return this.toNumber() === (target === null || target === void 0 ? void 0 : target.toNumber());
|
||||
}
|
||||
}, {
|
||||
key: "lessEquals",
|
||||
value: function lessEquals(target) {
|
||||
return this.add(target.negate().toString()).toNumber() <= 0;
|
||||
}
|
||||
}, {
|
||||
key: "toNumber",
|
||||
value: function toNumber() {
|
||||
return this.number;
|
||||
}
|
||||
}, {
|
||||
key: "toString",
|
||||
value: function toString() {
|
||||
var safe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
||||
if (!safe) {
|
||||
return this.origin;
|
||||
}
|
||||
if (this.isInvalidate()) {
|
||||
return '';
|
||||
}
|
||||
return num2str(this.number);
|
||||
}
|
||||
}]);
|
||||
return NumberDecimal;
|
||||
}();
|
||||
export { NumberDecimal as default };
|
||||
5
frontend/node_modules/@rc-component/mini-decimal/es/index.d.ts
generated
vendored
Normal file
5
frontend/node_modules/@rc-component/mini-decimal/es/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import getMiniDecimal from './MiniDecimal';
|
||||
export * from './MiniDecimal';
|
||||
import { trimNumber, getNumberPrecision, num2str, validateNumber } from './numberUtil';
|
||||
export { trimNumber, getNumberPrecision, num2str, validateNumber };
|
||||
export default getMiniDecimal;
|
||||
5
frontend/node_modules/@rc-component/mini-decimal/es/index.js
generated
vendored
Normal file
5
frontend/node_modules/@rc-component/mini-decimal/es/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import getMiniDecimal from "./MiniDecimal";
|
||||
export * from "./MiniDecimal";
|
||||
import { trimNumber, getNumberPrecision, num2str, validateNumber } from "./numberUtil";
|
||||
export { trimNumber, getNumberPrecision, num2str, validateNumber };
|
||||
export default getMiniDecimal;
|
||||
17
frontend/node_modules/@rc-component/mini-decimal/es/interface.d.ts
generated
vendored
Normal file
17
frontend/node_modules/@rc-component/mini-decimal/es/interface.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
export declare type ValueType = string | number;
|
||||
export interface DecimalClass {
|
||||
add: (value: ValueType) => DecimalClass;
|
||||
multi: (value: ValueType) => DecimalClass;
|
||||
isEmpty: () => boolean;
|
||||
isNaN: () => boolean;
|
||||
isInvalidate: () => boolean;
|
||||
toNumber: () => number;
|
||||
/**
|
||||
* Parse value as string. Will return empty string if `isInvalidate`.
|
||||
* You can set `safe=false` to get origin string content.
|
||||
*/
|
||||
toString: (safe?: boolean) => string;
|
||||
equals: (target: DecimalClass) => boolean;
|
||||
lessEquals: (target: DecimalClass) => boolean;
|
||||
negate: () => DecimalClass;
|
||||
}
|
||||
1
frontend/node_modules/@rc-component/mini-decimal/es/interface.js
generated
vendored
Normal file
1
frontend/node_modules/@rc-component/mini-decimal/es/interface.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
24
frontend/node_modules/@rc-component/mini-decimal/es/numberUtil.d.ts
generated
vendored
Normal file
24
frontend/node_modules/@rc-component/mini-decimal/es/numberUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { ValueType } from './interface';
|
||||
export declare function isEmpty(value: ValueType): boolean;
|
||||
/**
|
||||
* Format string number to readable number
|
||||
*/
|
||||
export declare function trimNumber(numStr: string): {
|
||||
negative: boolean;
|
||||
negativeStr: string;
|
||||
trimStr: string;
|
||||
integerStr: string;
|
||||
decimalStr: string;
|
||||
fullStr: string;
|
||||
};
|
||||
export declare function isE(number: string | number): boolean;
|
||||
/**
|
||||
* [Legacy] Convert 1e-9 to 0.000000001.
|
||||
* This may lose some precision if user really want 1e-9.
|
||||
*/
|
||||
export declare function getNumberPrecision(number: string | number): number;
|
||||
/**
|
||||
* Convert number (includes scientific notation) to -xxx.yyy format
|
||||
*/
|
||||
export declare function num2str(number: number): string;
|
||||
export declare function validateNumber(num: string | number): boolean;
|
||||
97
frontend/node_modules/@rc-component/mini-decimal/es/numberUtil.js
generated
vendored
Normal file
97
frontend/node_modules/@rc-component/mini-decimal/es/numberUtil.js
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
import { supportBigInt } from "./supportUtil";
|
||||
export function isEmpty(value) {
|
||||
return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format string number to readable number
|
||||
*/
|
||||
export function trimNumber(numStr) {
|
||||
var str = numStr.trim();
|
||||
var negative = str.startsWith('-');
|
||||
if (negative) {
|
||||
str = str.slice(1);
|
||||
}
|
||||
str = str
|
||||
// Remove decimal 0. `1.000` => `1.`, `1.100` => `1.1`
|
||||
.replace(/(\.\d*[^0])0*$/, '$1')
|
||||
// Remove useless decimal. `1.` => `1`
|
||||
.replace(/\.0*$/, '')
|
||||
// Remove integer 0. `0001` => `1`, 000.1' => `.1`
|
||||
.replace(/^0+/, '');
|
||||
if (str.startsWith('.')) {
|
||||
str = "0".concat(str);
|
||||
}
|
||||
var trimStr = str || '0';
|
||||
var splitNumber = trimStr.split('.');
|
||||
var integerStr = splitNumber[0] || '0';
|
||||
var decimalStr = splitNumber[1] || '0';
|
||||
if (integerStr === '0' && decimalStr === '0') {
|
||||
negative = false;
|
||||
}
|
||||
var negativeStr = negative ? '-' : '';
|
||||
return {
|
||||
negative: negative,
|
||||
negativeStr: negativeStr,
|
||||
trimStr: trimStr,
|
||||
integerStr: integerStr,
|
||||
decimalStr: decimalStr,
|
||||
fullStr: "".concat(negativeStr).concat(trimStr)
|
||||
};
|
||||
}
|
||||
export function isE(number) {
|
||||
var str = String(number);
|
||||
return !Number.isNaN(Number(str)) && str.includes('e');
|
||||
}
|
||||
|
||||
/**
|
||||
* [Legacy] Convert 1e-9 to 0.000000001.
|
||||
* This may lose some precision if user really want 1e-9.
|
||||
*/
|
||||
export function getNumberPrecision(number) {
|
||||
var numStr = String(number);
|
||||
if (isE(number)) {
|
||||
var precision = Number(numStr.slice(numStr.indexOf('e-') + 2));
|
||||
var decimalMatch = numStr.match(/\.(\d+)/);
|
||||
if (decimalMatch !== null && decimalMatch !== void 0 && decimalMatch[1]) {
|
||||
precision += decimalMatch[1].length;
|
||||
}
|
||||
return precision;
|
||||
}
|
||||
return numStr.includes('.') && validateNumber(numStr) ? numStr.length - numStr.indexOf('.') - 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert number (includes scientific notation) to -xxx.yyy format
|
||||
*/
|
||||
export function num2str(number) {
|
||||
var numStr = String(number);
|
||||
if (isE(number)) {
|
||||
if (number > Number.MAX_SAFE_INTEGER) {
|
||||
return String(supportBigInt() ? BigInt(number).toString() : Number.MAX_SAFE_INTEGER);
|
||||
}
|
||||
if (number < Number.MIN_SAFE_INTEGER) {
|
||||
return String(supportBigInt() ? BigInt(number).toString() : Number.MIN_SAFE_INTEGER);
|
||||
}
|
||||
numStr = number.toFixed(getNumberPrecision(numStr));
|
||||
}
|
||||
return trimNumber(numStr).fullStr;
|
||||
}
|
||||
export function validateNumber(num) {
|
||||
if (typeof num === 'number') {
|
||||
return !Number.isNaN(num);
|
||||
}
|
||||
|
||||
// Empty
|
||||
if (!num) {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
// Normal type: 11.28
|
||||
/^\s*-?\d+(\.\d+)?\s*$/.test(num) ||
|
||||
// Pre-number: 1.
|
||||
/^\s*-?\d+\.\s*$/.test(num) ||
|
||||
// Post-number: .1
|
||||
/^\s*-?\.\d+\s*$/.test(num)
|
||||
);
|
||||
}
|
||||
1
frontend/node_modules/@rc-component/mini-decimal/es/supportUtil.d.ts
generated
vendored
Normal file
1
frontend/node_modules/@rc-component/mini-decimal/es/supportUtil.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function supportBigInt(): boolean;
|
||||
3
frontend/node_modules/@rc-component/mini-decimal/es/supportUtil.js
generated
vendored
Normal file
3
frontend/node_modules/@rc-component/mini-decimal/es/supportUtil.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export function supportBigInt() {
|
||||
return typeof BigInt === 'function';
|
||||
}
|
||||
Reference in New Issue
Block a user