UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.56 kB
{"version":3,"file":"build-value.cjs","names":["getDigitParts"],"sources":["../../../src/components/RollingNumber/build-value.ts"],"sourcesContent":["import { getDigitParts } from './get-digit-parts';\n\nexport interface BuildValueInput {\n value: number;\n prefix?: string;\n suffix?: string;\n decimalSeparator?: string;\n thousandSeparator?: string | boolean;\n decimalScale?: number;\n fixedDecimalScale?: boolean;\n}\n\nexport function buildValue({\n value,\n prefix,\n suffix,\n decimalSeparator = '.',\n thousandSeparator,\n decimalScale,\n fixedDecimalScale,\n}: BuildValueInput): string {\n const parts = getDigitParts({ value, decimalScale, fixedDecimalScale });\n let intStr = parts.intDigits.join('');\n\n if (thousandSeparator) {\n const sep = typeof thousandSeparator === 'string' ? thousandSeparator : ',';\n intStr = intStr.replace(/\\B(?=(\\d{3})+(?!\\d))/g, sep);\n }\n\n let result = parts.negative ? `-${intStr}` : intStr;\n if (parts.fracDigits.length > 0) {\n result += `${decimalSeparator}${parts.fracDigits.join('')}`;\n }\n\n return `${prefix || ''}${result}${suffix || ''}`;\n}\n"],"mappings":";;;AAYA,SAAgB,WAAW,EACzB,OACA,QACA,QACA,mBAAmB,KACnB,mBACA,cACA,qBAC0B;CAC1B,MAAM,QAAQA,wBAAAA,cAAc;EAAE;EAAO;EAAc;CAAkB,CAAC;CACtE,IAAI,SAAS,MAAM,UAAU,KAAK,EAAE;CAEpC,IAAI,mBAAmB;EACrB,MAAM,MAAM,OAAO,sBAAsB,WAAW,oBAAoB;EACxE,SAAS,OAAO,QAAQ,yBAAyB,GAAG;CACtD;CAEA,IAAI,SAAS,MAAM,WAAW,IAAI,WAAW;CAC7C,IAAI,MAAM,WAAW,SAAS,GAC5B,UAAU,GAAG,mBAAmB,MAAM,WAAW,KAAK,EAAE;CAG1D,OAAO,GAAG,UAAU,KAAK,SAAS,UAAU;AAC9C"}