1 line
9.2 KiB
JSON
1 line
9.2 KiB
JSON
{"ast":null,"code":"import { supportBigInt } from \"./supportUtil\";\nexport function isEmpty(value) {\n return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();\n}\n\n/**\n * Format string number to readable number\n */\nexport function trimNumber(numStr) {\n var str = numStr.trim();\n var negative = str.startsWith('-');\n if (negative) {\n str = str.slice(1);\n }\n str = str\n // Remove decimal 0. `1.000` => `1.`, `1.100` => `1.1`\n .replace(/(\\.\\d*[^0])0*$/, '$1')\n // Remove useless decimal. `1.` => `1`\n .replace(/\\.0*$/, '')\n // Remove integer 0. `0001` => `1`, 000.1' => `.1`\n .replace(/^0+/, '');\n if (str.startsWith('.')) {\n str = \"0\".concat(str);\n }\n var trimStr = str || '0';\n var splitNumber = trimStr.split('.');\n var integerStr = splitNumber[0] || '0';\n var decimalStr = splitNumber[1] || '0';\n if (integerStr === '0' && decimalStr === '0') {\n negative = false;\n }\n var negativeStr = negative ? '-' : '';\n return {\n negative: negative,\n negativeStr: negativeStr,\n trimStr: trimStr,\n integerStr: integerStr,\n decimalStr: decimalStr,\n fullStr: \"\".concat(negativeStr).concat(trimStr)\n };\n}\nexport function isE(number) {\n var str = String(number);\n return !Number.isNaN(Number(str)) && str.includes('e');\n}\n\n/**\n * [Legacy] Convert 1e-9 to 0.000000001.\n * This may lose some precision if user really want 1e-9.\n */\nexport function getNumberPrecision(number) {\n var numStr = String(number);\n if (isE(number)) {\n var precision = Number(numStr.slice(numStr.indexOf('e-') + 2));\n var decimalMatch = numStr.match(/\\.(\\d+)/);\n if (decimalMatch !== null && decimalMatch !== void 0 && decimalMatch[1]) {\n precision += decimalMatch[1].length;\n }\n return precision;\n }\n return numStr.includes('.') && validateNumber(numStr) ? numStr.length - numStr.indexOf('.') - 1 : 0;\n}\n\n/**\n * Convert number (includes scientific notation) to -xxx.yyy format\n */\nexport function num2str(number) {\n var numStr = String(number);\n if (isE(number)) {\n if (number > Number.MAX_SAFE_INTEGER) {\n return String(supportBigInt() ? BigInt(number).toString() : Number.MAX_SAFE_INTEGER);\n }\n if (number < Number.MIN_SAFE_INTEGER) {\n return String(supportBigInt() ? BigInt(number).toString() : Number.MIN_SAFE_INTEGER);\n }\n numStr = number.toFixed(getNumberPrecision(numStr));\n }\n return trimNumber(numStr).fullStr;\n}\nexport function validateNumber(num) {\n if (typeof num === 'number') {\n return !Number.isNaN(num);\n }\n\n // Empty\n if (!num) {\n return false;\n }\n return (\n // Normal type: 11.28\n /^\\s*-?\\d+(\\.\\d+)?\\s*$/.test(num) ||\n // Pre-number: 1.\n /^\\s*-?\\d+\\.\\s*$/.test(num) ||\n // Post-number: .1\n /^\\s*-?\\.\\d+\\s*$/.test(num)\n );\n}","map":{"version":3,"names":["supportBigInt","isEmpty","value","Number","isNaN","String","trim","trimNumber","numStr","str","negative","startsWith","slice","replace","concat","trimStr","splitNumber","split","integerStr","decimalStr","negativeStr","fullStr","isE","number","includes","getNumberPrecision","precision","indexOf","decimalMatch","match","length","validateNumber","num2str","MAX_SAFE_INTEGER","BigInt","toString","MIN_SAFE_INTEGER","toFixed","num","test"],"sources":["C:/Users/Аришина)/source/repos/PromoCursed/node_modules/@rc-component/mini-decimal/es/numberUtil.js"],"sourcesContent":["import { supportBigInt } from \"./supportUtil\";\nexport function isEmpty(value) {\n return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();\n}\n\n/**\n * Format string number to readable number\n */\nexport function trimNumber(numStr) {\n var str = numStr.trim();\n var negative = str.startsWith('-');\n if (negative) {\n str = str.slice(1);\n }\n str = str\n // Remove decimal 0. `1.000` => `1.`, `1.100` => `1.1`\n .replace(/(\\.\\d*[^0])0*$/, '$1')\n // Remove useless decimal. `1.` => `1`\n .replace(/\\.0*$/, '')\n // Remove integer 0. `0001` => `1`, 000.1' => `.1`\n .replace(/^0+/, '');\n if (str.startsWith('.')) {\n str = \"0\".concat(str);\n }\n var trimStr = str || '0';\n var splitNumber = trimStr.split('.');\n var integerStr = splitNumber[0] || '0';\n var decimalStr = splitNumber[1] || '0';\n if (integerStr === '0' && decimalStr === '0') {\n negative = false;\n }\n var negativeStr = negative ? '-' : '';\n return {\n negative: negative,\n negativeStr: negativeStr,\n trimStr: trimStr,\n integerStr: integerStr,\n decimalStr: decimalStr,\n fullStr: \"\".concat(negativeStr).concat(trimStr)\n };\n}\nexport function isE(number) {\n var str = String(number);\n return !Number.isNaN(Number(str)) && str.includes('e');\n}\n\n/**\n * [Legacy] Convert 1e-9 to 0.000000001.\n * This may lose some precision if user really want 1e-9.\n */\nexport function getNumberPrecision(number) {\n var numStr = String(number);\n if (isE(number)) {\n var precision = Number(numStr.slice(numStr.indexOf('e-') + 2));\n var decimalMatch = numStr.match(/\\.(\\d+)/);\n if (decimalMatch !== null && decimalMatch !== void 0 && decimalMatch[1]) {\n precision += decimalMatch[1].length;\n }\n return precision;\n }\n return numStr.includes('.') && validateNumber(numStr) ? numStr.length - numStr.indexOf('.') - 1 : 0;\n}\n\n/**\n * Convert number (includes scientific notation) to -xxx.yyy format\n */\nexport function num2str(number) {\n var numStr = String(number);\n if (isE(number)) {\n if (number > Number.MAX_SAFE_INTEGER) {\n return String(supportBigInt() ? BigInt(number).toString() : Number.MAX_SAFE_INTEGER);\n }\n if (number < Number.MIN_SAFE_INTEGER) {\n return String(supportBigInt() ? BigInt(number).toString() : Number.MIN_SAFE_INTEGER);\n }\n numStr = number.toFixed(getNumberPrecision(numStr));\n }\n return trimNumber(numStr).fullStr;\n}\nexport function validateNumber(num) {\n if (typeof num === 'number') {\n return !Number.isNaN(num);\n }\n\n // Empty\n if (!num) {\n return false;\n }\n return (\n // Normal type: 11.28\n /^\\s*-?\\d+(\\.\\d+)?\\s*$/.test(num) ||\n // Pre-number: 1.\n /^\\s*-?\\d+\\.\\s*$/.test(num) ||\n // Post-number: .1\n /^\\s*-?\\.\\d+\\s*$/.test(num)\n );\n}"],"mappings":"AAAA,SAASA,aAAa,QAAQ,eAAe;AAC7C,OAAO,SAASC,OAAOA,CAACC,KAAK,E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