PromoCursed/node_modules/.cache/babel-loader/f82384fdce1864e8c2f41e1634e941ab13a60ca2d9f4abaf0efb350f9ef13340.json

1 line
9.2 KiB
JSON
Raw Normal View History

2024-08-20 23:25:37 +04:00
{"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/Аришина)/Desktop/promo/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