b23-lib 1.7.24 → 1.7.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Classes/Cart.js +1 -1
- package/dist/Classes/Cart.js.map +1 -1
- package/dist/Classes/Cart.mjs +1 -1
- package/dist/Classes/Cart.mjs.map +1 -1
- package/dist/Classes/Order.d.mts +30 -3
- package/dist/Classes/Order.d.ts +30 -3
- package/dist/Classes/Order.js +1 -1
- package/dist/Classes/Order.js.map +1 -1
- package/dist/Classes/Order.mjs +1 -1
- package/dist/Classes/Order.mjs.map +1 -1
- package/dist/Classes/Price.d.mts +12 -3
- package/dist/Classes/Price.d.ts +12 -3
- package/dist/Classes/Price.js +1 -1
- package/dist/Classes/Price.js.map +1 -1
- package/dist/Classes/Price.mjs +1 -1
- package/dist/Classes/ShoppingContainer.js +1 -1
- package/dist/Classes/ShoppingContainer.js.map +1 -1
- package/dist/Classes/ShoppingContainer.mjs +1 -1
- package/dist/{chunk-JMO7QKIT.mjs → chunk-ADECAEML.mjs} +2 -2
- package/dist/{chunk-JMO7QKIT.mjs.map → chunk-ADECAEML.mjs.map} +1 -1
- package/dist/chunk-GCT7VOSM.mjs +2 -0
- package/dist/chunk-GCT7VOSM.mjs.map +1 -0
- package/dist/chunk-Z6YNOEGK.mjs +2 -0
- package/dist/chunk-Z6YNOEGK.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-VJ64OPJY.mjs +0 -2
- package/dist/chunk-VJ64OPJY.mjs.map +0 -1
package/dist/chunk-VJ64OPJY.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {d,e}from'./chunk-65X54TKF.mjs';var u=class c{price;country;constructor(r,e){if(this.country=e,r<0)throw new Error("InvalidPrice: Price cannot be negative.");this.price=r;}getCountry(){return this.country}getRoundedPrice(){return c.getRoundedPrice(this.price,this.country)}getFormattedString(r,e$1={}){let n=e$1.displayAsInteger??!1,t=d[this.country];if(t===void 0)throw new Error("Currency mapping not found for CountryCode");let o=this.price,i=n?0:c.getDecimalPlaces(t),s={style:"currency",currency:t,signDisplay:"never",currencyDisplay:e$1.currencyDisplay,minimumFractionDigits:i,maximumFractionDigits:i};n&&(o=Math.round(o));try{return new Intl.NumberFormat(r,s).format(o)}catch(l){return console.error(`Error formatting price for locale "${r}" and currency "${t}":`,l),`${e[t]??t} ${c.addThousandSeparators(o.toFixed(i))}`}}static getDecimalPlaces(r){switch(r){case"INR":default:return 2}}static addThousandSeparators(r){let e=r.split("."),n=e[0],t=e.length>1?"."+e[1]:"";return n.replace(/\B(?=(\d{3})+(?!\d))/g,",")+t}static getRoundedPrice(r,e){if(r<0)throw new Error("Price cannot be negative for rounding.");let n=d[e];if(n===void 0)throw new Error(`Currency mapping not found for CountryCode: ${e}`);let t=c.getDecimalPlaces(n),o=Math.pow(10,t);return Math.round(r*o)/o}static getCurrency(r){return d[r]}static getFormattedStringToDisplay(r,e,n){return new c(r,e).getFormattedString(n)}};export{u as a};//# sourceMappingURL=chunk-VJ64OPJY.mjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-VJ64OPJY.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Classes/Price.ts"],"names":["PriceModel","_PriceModel","price","country","locale","options","displayAsInteger","currency","CountryCurrencyMap","valueToFormat","fractionDigits","formattingOptions","error","CurrencySymbolMap","numStr","parts","integerPart","decimalPart","decimalPlaces","multiplier"],"mappings":"uCAGA,IAAqBA,CAArB,CAAA,MAAqBC,CAAW,CACpB,KACA,CAAA,OAAA,CAQV,WAAYC,CAAAA,CAAAA,CAAeC,CAAsB,CAAA,CAG/C,GAFA,IAAA,CAAK,OAAUA,CAAAA,CAAAA,CAEZD,CAAQ,CAAA,CAAA,CACT,MAAM,IAAI,KAAM,CAAA,yCAAyC,CAG3D,CAAA,IAAA,CAAK,KAAQA,CAAAA,EACf,CAOO,UAAA,EAA0B,CAC/B,OAAO,IAAK,CAAA,OACd,C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AM,CACjE,CAEF","file":"chunk-VJ64OPJY.mjs","sourcesContent":["import { CountryCode, CurrencyCode, LocaleCode } from \"./Common\"; // Assuming these are in Common.ts\r\nimport { CountryCurrencyMap, CurrencySymbolMap } from \"./Enum\"; // Ensure these maps exist\r\n\r\nexport default class PriceModel {\r\n protected price: number;\r\n protected country: CountryCode;\r\n\r\n /**\r\n * Creates an instance of PriceModel, storing the currency-correct rounded price.\r\n * @param price - The initial price value.\r\n * @param country - The country code used for rounding and determining the currency symbol.\r\n * @throws {Error} If price is negative or country/currency mapping is missing.\r\n */\r\n constructor(price: number, country: CountryCode) {\r\n this.country = country;\r\n\r\n if(price < 0) {\r\n throw new Error(\"InvalidPrice: Price cannot be negative.\");\r\n }\r\n\r\n this.price = price\r\n }\r\n\r\n /**\r\n * Gets the country code associated with this price instance.\r\n * The country code is used for determining currency and formatting rules.\r\n * @returns The CountryCode enum value.\r\n */\r\n public getCountry(): CountryCode {\r\n return this.country;\r\n }\r\n\r\n /**\r\n * Gets the rounded price value based on standard currency rules.\r\n * @returns The numeric price, rounded according to its currency's typical decimal places.\r\n */\r\n public getRoundedPrice(): number {\r\n return PriceModel.getRoundedPrice(this.price, this.country);\r\n }\r\n\r\n /**\r\n * Gets a locale-aware formatted display string for the price.\r\n * Uses Intl.NumberFormat for accurate formatting based on locale and currency.\r\n * @param locale - The locale code (e.g., 'en-US', 'de-DE', 'en-IN') to use for formatting rules.\r\n * @param options - Configuration options for formatting.\r\n * @param options.displayAsInteger - If true, the formatted string will show the price rounded to the nearest integer (no decimals). Defaults to false.\r\n * @returns The formatted price string according to locale rules.\r\n */\r\n public getFormattedString(locale: LocaleCode, options: { displayAsInteger?: boolean, currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code' | 'name' } = {}): string {\r\n const displayAsInteger = options.displayAsInteger ?? false;\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[this.country];\r\n\r\n if (currency === undefined) {\r\n throw new Error('Currency mapping not found for CountryCode');\r\n }\r\n\r\n let valueToFormat = this.price;\r\n const fractionDigits = displayAsInteger ? 0 : PriceModel.getDecimalPlaces(currency);\r\n\r\n let formattingOptions: Intl.NumberFormatOptions = {\r\n style: 'currency',\r\n currency: currency,\r\n signDisplay: 'never',\r\n currencyDisplay: options.currencyDisplay,\r\n minimumFractionDigits: fractionDigits,\r\n maximumFractionDigits: fractionDigits,\r\n };\r\n\r\n if (displayAsInteger) {\r\n valueToFormat = Math.round(valueToFormat);\r\n }\r\n\r\n try {\r\n return new Intl.NumberFormat(locale, formattingOptions).format(valueToFormat);\r\n } catch (error) {\r\n console.error(`Error formatting price for locale \"${locale}\" and currency \"${currency}\":`, error);\r\n // Basic fallback without symbol if Intl fails completely\r\n return `${CurrencySymbolMap[currency] ?? currency} ${PriceModel.addThousandSeparators(valueToFormat.toFixed(fractionDigits))}`;\r\n }\r\n }\r\n\r\n /**\r\n * Helper method to determine standard decimal places for a currency.\r\n * @param currency - The currency code.\r\n * @returns The number of decimal places (0, 2, or 3 based on common rules).\r\n */\r\n private static getDecimalPlaces(currency: CurrencyCode): number {\r\n switch (currency) {\r\n case 'INR':\r\n default:\r\n return 2;\r\n }\r\n }\r\n\r\n /**\r\n * Adds basic thousand separators (commas) to a number string.\r\n * Does not handle different locale separators (e.g., periods, spaces).\r\n * @param numStr - The number string (potentially with decimals).\r\n * @returns The number string with commas added.\r\n */\r\n private static addThousandSeparators(numStr: string): string {\r\n const parts = numStr.split('.');\r\n const integerPart = parts[0];\r\n const decimalPart = parts.length > 1 ? '.' + parts[1] : '';\r\n\r\n const formattedInteger = integerPart.replace(/\\B(?=(\\d{3})+(?!\\d))/g, ',');\r\n return formattedInteger + decimalPart;\r\n }\r\n\r\n /**\r\n * Rounds a price value according to the standard decimal places\r\n * for the currency associated with the given country.\r\n *\r\n * @param price - The price value to round. Must be a non-negative number.\r\n * @param country - The country code to determine the currency and rounding rules.\r\n * @returns The rounded price as a number.\r\n * @throws {Error} If the country code is not found in the CountryCurrencyMap or price is negative.\r\n */\r\n static getRoundedPrice(price: number, country: CountryCode): number {\r\n if (price < 0) {\r\n throw new Error(\"Price cannot be negative for rounding.\");\r\n }\r\n\r\n const currency: CurrencyCode | undefined = CountryCurrencyMap[country];\r\n if (currency === undefined) {\r\n throw new Error(`Currency mapping not found for CountryCode: ${country}`);\r\n }\r\n\r\n const decimalPlaces = PriceModel.getDecimalPlaces(currency);\r\n const multiplier = Math.pow(10, decimalPlaces);\r\n const roundedValue = Math.round(price * multiplier) / multiplier;\r\n\r\n return roundedValue;\r\n }\r\n\r\n /**\r\n * Static method to retrieve the currency code associated with a given country code.\r\n * Uses the `CountryCurrencyMap` to find the corresponding currency.\r\n *\r\n * @param country - The country code (e.g., 'IN') for which to find the currency.\r\n * @returns The currency code (e.g., 'INR') as a string, or undefined if the mapping doesn't exist.\r\n */\r\n static getCurrency(country: CountryCode): string {\r\n return CountryCurrencyMap[country];\r\n }\r\n\r\n static getFormattedStringToDisplay(price: number, country: CountryCode, locale: LocaleCode){\r\n return new PriceModel(price, country).getFormattedString(locale);\r\n }\r\n\r\n}"]}
|