{"version":3,"file":"seniorsistemas-angular-components-numeric.mjs","sources":["../../projects/angular-components/numeric/src/lib/numeric.service.ts","../../projects/angular-components/numeric/src/lib/numeric.pipe.ts","../../projects/angular-components/numeric/src/lib/numeric.module.ts","../../projects/angular-components/numeric/src/seniorsistemas-angular-components-numeric.ts"],"sourcesContent":["import { Injectable, inject } from '@angular/core';\nimport { currencies, Currency } from '@seniorsistemas/angular-components/currency';\nimport { LocaleService } from '@seniorsistemas/angular-components/locale';\nimport { isNullOrUndefined } from '@seniorsistemas/angular-components/utils';\nimport BigNumber from 'bignumber.js';\n\n/**\n * @description Service for formatting numeric values using the browser's `Intl.NumberFormat` API.\n * Automatically uses the locale configured in `LocaleService` unless explicitly overridden.\n * Supports `BigNumber`, plain numbers, and numeric strings, as well as currency display styles.\n *\n * @example\n * ```typescript\n * // Inject the service\n * const numericService = inject(NumericService);\n *\n * // Format a number with the active locale\n * const formatted = numericService.instant(1234567.89);\n *\n * // Format as currency\n * const currency = numericService.instant(1234.5, {\n *   numberFormatOptions: { style: 'currency', currency: 'BRL' }\n * });\n * ```\n * @category Numeric\n */\n@Injectable({\n    providedIn: 'root',\n})\nexport class NumericService {\n    private readonly localeService = inject(LocaleService);\n\n\n    /**\n     * Wrapper around Intl.NumberFormat that returns the localized value using the user's locale by default(platform's preferential language).\n     * This method should only be used after the localeService has been initialized by the host application, either by a resolver or a manual call.\n     * Can be overwritten by the provided Intl.NumberFormatOptions.\n     * Documentation is available at {@link https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat Intl.NumberFormatOptions}.\n     * @param {number | string | BigNumber} value The value to be formatted.\n     * @param options Locale and numberFormatOptions that overwrites the default Intl.NumberFormatOptions.\n     * @return `string` The formatted value.\n     */\n    instant(\n        value: number | string | BigNumber,\n        options?: {\n            locale?: string;\n            numberFormatOptions?: Intl.NumberFormatOptions;\n        },\n    ): string | null {\n        if (isNullOrUndefined(value)) return null;\n\n        options = {\n            ...options,\n            locale: options?.locale ?? this.localeService.getLocaleOptions()?.locale ?? 'pt-BR',\n            numberFormatOptions: {\n                useGrouping: true,\n                ...options?.numberFormatOptions,\n                currency:\n                    options?.numberFormatOptions?.style === 'currency'\n                        ? (options?.numberFormatOptions?.currency ?? 'BRL')\n                        : undefined,\n                currencyDisplay:\n                    options?.numberFormatOptions?.style === 'currency'\n                        ? (options?.numberFormatOptions?.currencyDisplay ?? 'narrowSymbol')\n                        : undefined,\n                minimumFractionDigits:\n                    (options?.numberFormatOptions?.minimumFractionDigits ?? options?.numberFormatOptions?.currency)\n                        ? (this.getCurrencyMinimumFractionDigits(options?.numberFormatOptions?.currency! as Currency) ??\n                          undefined)\n                        : undefined,\n                roundingMode: 'trunc',\n            },\n        };\n\n        // From https://developer.mozilla.org/pt-BR/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat\n        return new Intl.NumberFormat(options.locale, options.numberFormatOptions).format(\n            this.getType(value) === 'number' || this.getType(value) === 'string'\n                ? value\n                : ((value as BigNumber).toString() as any),\n        );\n    }\n\n    private getCurrencyMinimumFractionDigits(currency: Currency): number | null {\n        if (!currency) return null;\n\n        return currencies[currency]?.scale;\n    }\n\n    private getType(value: any): string {\n        // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof\n\n        if (value === null) return 'null';\n        if (value === undefined) return 'undefined';\n\n        const baseType = typeof value;\n\n        // Primitive types\n        if (baseType !== 'object' && baseType !== 'function') {\n            return baseType;\n        }\n\n        // Symbol.toStringTag often specifies the \"display name\" of the\n        // object's class. It's used in Object.prototype.toString().\n        const tag = value[Symbol.toStringTag];\n\n        if (typeof tag === 'string') {\n            return tag;\n        }\n\n        // If it's a function whose source code starts with the \"class\" keyword\n        if (baseType === 'function' && Function.prototype.toString.call(value).startsWith('class')) {\n            return 'class';\n        }\n\n        // The name of the constructor; for example `Array`, `GeneratorFunction`,\n        // `Number`, `String`, `Boolean` or `MyCustomClass`\n        const className = value.constructor.name;\n\n        if (typeof className === 'string' && className !== '') {\n            return className;\n        }\n\n        // At this point there's no robust way to get the type of value,\n        // so we use the base implementation.\n        return baseType;\n    }\n}\n\n","import { Pipe, PipeTransform, inject } from '@angular/core';\nimport { LocaleService } from '@seniorsistemas/angular-components/locale';\nimport BigNumber from 'bignumber.js';\nimport { of } from 'rxjs';\nimport { map } from 'rxjs/operators';\nimport { NumericService } from './numeric.service';\n\n/**\n * @description Angular pipe for formatting numeric values according to the active locale.\n * Wraps `NumericService.instant()` and reactively responds to locale changes via `LocaleService`.\n * Accepts an optional `locale` override and `Intl.NumberFormatOptions` for fine-grained control.\n *\n * @example\n * ```html\n * <!-- Basic usage -->\n * {{ 1234.56 | numeric | async }}\n *\n * <!-- With locale override and fraction digits -->\n * {{ 1234.56 | numeric:{ locale: 'en-US', numberFormatOptions: { minimumFractionDigits: 2 } } | async }}\n * ```\n * @category Numeric\n */\n@Pipe({ name: 'numeric' })\nexport class NumericPipe implements PipeTransform {\n    private readonly numericService = inject(NumericService);\n    private readonly localeService = inject(LocaleService);\n\n\n    transform(\n        value: number | string | BigNumber,\n        options?: {\n            locale?: string;\n            numberFormatOptions?: Intl.NumberFormatOptions;\n        },\n    ) {\n        return options?.locale\n            ? of(this.numericService.instant(value, options))\n            : this.localeService.getLocale().pipe(\n                  map((locale) =>\n                      this.numericService.instant(value, {\n                          locale,\n                          numberFormatOptions: options?.numberFormatOptions,\n                      }),\n                  ),\n              );\n    }\n}\n\n","import { CommonModule } from '@angular/common';\r\nimport { NgModule } from '@angular/core';\r\nimport { NumericPipe } from '../lib/numeric.pipe';\r\n\r\n@NgModule({\r\n    imports: [CommonModule],\r\n    declarations: [NumericPipe],\r\n    exports: [NumericPipe],\r\n})\r\nexport class NumericModule {}\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;;;AAMA;;;;;;;;;;;;;;;;;;;AAmBG;MAIU,cAAc,CAAA;AACN,IAAA,aAAa,GAAG,MAAM,CAAC,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