openstack-uicore-foundation 4.2.20 → 4.2.21

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.
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={};(()=>{e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})}})(),(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var t={};e.r(t),e.d(t,{amountFromCents:()=>c,amountToCents:()=>u,parsePrice:()=>a});const r=100n,n=2,o=3,i=1n,s=0;function u(e){if(null==e)throw new Error("amount is required");let t=String(e).trim();if(t.includes(",")&&t.includes(".")?t=t.replace(/,/g,""):t.includes(",")&&!t.includes(".")&&(t=t.replace(",",".")),!/^\d+(\.\d+)?$/.test(t))throw new Error(`Invalid money format: "${e}"`);const[n,s=""]=t.split("."),u=`${s}000`,c=u[0]??"0",a=u[1]??"0",l=u[2]??"0",f=s.length>o?s.slice(o):"",d=/[1-9]/.test(f);let g=BigInt(n)*r+BigInt(c+a);return(l>"5"||"5"===l||"5"===l&&d)&&(g+=i),Number(g)}function c(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error("cents must be a safe integer Number (or pass BigInt/string).");t=BigInt(e)}else{if("string"!=typeof e)throw new Error("cents must be a bigint, number, or numeric string.");{const r=e.trim();if(!/^\d+$/.test(r))throw new Error("cents string must contain digits only (e.g., '1234').");t=BigInt(r)}}if(t<s)throw new Error("cents must be non-negative.");const o=t%r;return`${(t/r).toString()}.${o.toString().padStart(n,"0")}`}const a=e=>{if(null==e)throw new Error("priceString is required");let t=String(e).trim();if(t.includes("-"))throw new Error("Negative amounts are not allowed");if(t=t.replace(/[^\d.,]/g,""),!t)throw new Error(`Invalid price: "${e}"`);return u(t)};return t})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("openstack-uicore-foundation",[],t):"object"==typeof exports?exports["openstack-uicore-foundation"]=t():e["openstack-uicore-foundation"]=t()}(this,(()=>(()=>{"use strict";var e={};(()=>{e.d=(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})}})(),(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})(),(()=>{e.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}})();var t={};e.r(t),e.d(t,{amountFromCents:()=>a,amountToCents:()=>c,currencyAmountFromCents:()=>f,parsePrice:()=>l});const r=100n,n=2,o=3,i=1n,s=0,u={USD:"$",EUR:"€",GBP:"£",CAD:"C$",AUD:"A$",NZD:"NZ$",CHF:"CHF",ARS:"AR$",BRL:"R$",MXN:"MX$"};function c(e){if(null==e)throw new Error("amount is required");let t=String(e).trim();if(t.includes(",")&&t.includes(".")?t=t.replace(/,/g,""):t.includes(",")&&!t.includes(".")&&(t=t.replace(",",".")),!/^\d+(\.\d+)?$/.test(t))throw new Error(`Invalid money format: "${e}"`);const[n,s=""]=t.split("."),u=`${s}000`,c=u[0]??"0",a=u[1]??"0",f=u[2]??"0",l=s.length>o?s.slice(o):"",d=/[1-9]/.test(l);let m=BigInt(n)*r+BigInt(c+a);return(f>"5"||"5"===f||"5"===f&&d)&&(m+=i),Number(m)}function a(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e){if(!Number.isSafeInteger(e))throw new Error("cents must be a safe integer Number (or pass BigInt/string).");t=BigInt(e)}else{if("string"!=typeof e)throw new Error("cents must be a bigint, number, or numeric string.");{const r=e.trim();if(!/^\d+$/.test(r))throw new Error("cents string must contain digits only (e.g., '1234').");t=BigInt(r)}}if(t<s)throw new Error("cents must be non-negative.");const o=t%r;return`${(t/r).toString()}.${o.toString().padStart(n,"0")}`}function f(e,t="USD"){if("number"!=typeof e||!Number.isInteger(e))throw new Error("cents must be an integer number");const r=a(e);return`${u[t]??"$"}${r}`}const l=e=>{if(null==e)throw new Error("priceString is required");let t=String(e).trim();if(t.includes("-"))throw new Error("Negative amounts are not allowed");if(t=t.replace(/[^\d.,]/g,""),!t)throw new Error(`Invalid price: "${e}"`);return c(t)};return t})()));
2
2
  //# sourceMappingURL=money.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils/money.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,8BAA+B,GAAIH,GAChB,iBAAZC,QACdA,QAAQ,+BAAiCD,IAEzCD,EAAK,+BAAiCC,GACvC,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CAAC,E,MCA3BA,EAAoBC,EAAI,CAACN,EAASO,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAET,EAASQ,IAC5EE,OAAOC,eAAeX,EAASQ,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,C,WCNDH,EAAoBI,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,E,WCClFV,EAAoBc,EAAKnB,IACH,oBAAXoB,QAA0BA,OAAOC,aAC1CX,OAAOC,eAAeX,EAASoB,OAAOC,YAAa,CAAEC,MAAO,WAE7DZ,OAAOC,eAAeX,EAAS,aAAc,CAAEs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AYF,EAAI7B,EAGtB,MAAQ,IAJQ6B,EAAI7B,GAIFgC,cAAcD,EAAUC,WAAWC,SAAShC,EAAoB,MACrF,CAOM,MAAMiC,EAAcC,IACvB,GAAmB,MAAfA,EAAqB,MAAM,IAAI5B,MAAM,2BAEzC,IAAIC,EAAIC,OAAO0B,GAAazB,OAG5B,GAAIF,EAAEG,SAAS,KAAM,MAAM,IAAIJ,MAAM,oCAIrC,GADAC,EAAIA,EAAEI,QAAQ,WAAY,KACrBJ,EAAG,MAAM,IAAID,MAAO,mBAAkB4B,MAG3C,OAAO9B,EAAcG,EAArB,E","sources":["webpack://openstack-uicore-foundation/webpack/universalModuleDefinition","webpack://openstack-uicore-foundation/webpack/bootstrap","webpack://openstack-uicore-foundation/webpack/runtime/define property getters","webpack://openstack-uicore-foundation/webpack/runtime/hasOwnProperty shorthand","webpack://openstack-uicore-foundation/webpack/runtime/make namespace object","webpack://openstack-uicore-foundation/./src/utils/constants.js","webpack://openstack-uicore-foundation/./src/utils/money.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"openstack-uicore-foundation\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"openstack-uicore-foundation\"] = factory();\n\telse\n\t\troot[\"openstack-uicore-foundation\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const CENTS_FACTOR = 100n;\nexport const TWO_DECIMAL_PLACES = 2;\nexport const THREE_DECIMAL_PLACES = 3;\nexport const ONE_CENT = 1n;\nexport const ZERO_INT = 0;\n","/**\n * Copyright 2025 OpenStack Foundation\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n * */\n\nimport {\n CENTS_FACTOR,\n THREE_DECIMAL_PLACES,\n TWO_DECIMAL_PLACES,\n ZERO_INT,\n ONE_CENT\n} from \"./constants\";\n\n/**\n * Convert a decimal money amount to integer cents safely (no floating point math).\n *\n * Why this exists:\n * - `Math.round(parseFloat(x) * 100)` can be wrong due to IEEE-754 floating point errors\n * (e.g. 1.005 * 100 may become 100.499999..., rounding down unexpectedly).\n *\n * Input:\n * - number or string (recommended: string from API/UI)\n * - Examples: \"12.34\", \"1,234.56\", \"1234,56\", 12.34\n *\n * Output:\n * - Number cents (exact), e.g. \"12.34\" -> 1234\n *\n * Rounding:\n * - Half-up to 2 decimals (>= 0.005 USD rounds up by 1 cent).\n *\n * Notes:\n * - Amounts are assumed to be NON-negative (per your requirement).\n * - Throws on invalid formats (does not silently return 0).\n */\nexport function amountToCents(amount) {\n if (amount == null) throw new Error(\"amount is required\");\n\n let s = String(amount).trim();\n\n // Normalize common separators:\n // - \"1,234.56\" => \"1234.56\" (remove thousands separators)\n // - \"1234,56\" => \"1234.56\" (convert decimal comma to dot)\n if (s.includes(\",\") && s.includes(\".\")) {\n s = s.replace(/,/g, \"\");\n } else if (s.includes(\",\") && !s.includes(\".\")) {\n s = s.replace(\",\", \".\");\n }\n\n // Validate: digits optionally followed by '.' and more digits\n if (!/^\\d+(\\.\\d+)?$/.test(s)) {\n throw new Error(`Invalid money format: \"${amount}\"`);\n }\n\n const [intPart, fracRaw = \"\"] = s.split(\".\");\n\n // Pad at least 3 fractional digits so we can:\n // - take 2 digits for cents\n // - take the 3rd digit to decide rounding\n const fracPadded = (`${fracRaw }000`);\n\n const tenths = fracPadded[0] ?? \"0\"; // 1st decimal digit\n const hundredths = fracPadded[1] ?? \"0\"; // 2nd decimal digit (cents)\n const thousandths = fracPadded[2] ?? \"0\"; // 3rd decimal digit (rounding decision)\n\n // If there are more than 3 decimals, we track if any non-zero exists after the 3rd.\n // This can matter for policies like bankers rounding; here it's mainly informational.\n const trailing =\n fracRaw.length > THREE_DECIMAL_PLACES\n ? fracRaw.slice(THREE_DECIMAL_PLACES)\n : \"\";\n const hasTrailingNonZero = /[1-9]/.test(trailing);\n\n // Build cents as integer: (dollars * 100) + (first two decimal digits)\n let cents = BigInt(intPart) * CENTS_FACTOR + BigInt(tenths + hundredths);\n\n // Half-up rounding:\n // - If the 3rd digit is >= 5, round up by 1 cent.\n // - If there are more digits beyond the 3rd, \"5xxx\" should also round up.\n const roundUp = thousandths > \"5\" || thousandths === \"5\" || (thousandths === \"5\" && hasTrailingNonZero);\n\n if (roundUp) cents += ONE_CENT;\n\n return Number(cents);\n}\n\n/**\n * Convert an amount in cents to a decimal string (e.g. 1234 -> \"12.34\") safely.\n *\n * Why:\n * - Avoids floating point math (cents / 100) which can lose precision for large integers\n * or if cents is already imprecise as a JS Number.\n *\n * Input:\n * - Accepts: bigint | number | string (digits)\n * - Assumes NON-negative cents (per your requirement).\n *\n * Output:\n * - Always returns a string with exactly 2 decimal places.\n */\nexport function amountFromCents(cents) {\n let c;\n\n // Normalize input to BigInt safely\n if (typeof cents === \"bigint\") {\n c = cents;\n } else if (typeof cents === \"number\") {\n // Ensure it's a safe integer before converting to BigInt\n if (!Number.isSafeInteger(cents)) {\n throw new Error(\"cents must be a safe integer Number (or pass BigInt/string).\");\n }\n c = BigInt(cents);\n } else if (typeof cents === \"string\") {\n const s = cents.trim();\n if (!/^\\d+$/.test(s)) {\n throw new Error(\"cents string must contain digits only (e.g., '1234').\");\n }\n c = BigInt(s);\n } else {\n throw new Error(\"cents must be a bigint, number, or numeric string.\");\n }\n\n if (c < ZERO_INT) {\n throw new Error(\"cents must be non-negative.\");\n }\n\n const dollars = c / CENTS_FACTOR;\n const remainder = c % CENTS_FACTOR;\n\n // Always pad remainder to 2 digits\n return `${dollars.toString()}.${remainder.toString().padStart(TWO_DECIMAL_PLACES, \"0\")}`;\n}\n\n/**\n * Converts a price string into cents.\n * @param {string} priceString - The price (e.g., $0.30).\n * @returns {number} - The amount converted to cents (e.g., 30).\n */\nexport const parsePrice = (priceString) => {\n if (priceString == null) throw new Error(\"priceString is required\");\n\n let s = String(priceString).trim();\n\n // Reject negatives explicitly (per your requirement).\n if (s.includes(\"-\")) throw new Error(\"Negative amounts are not allowed\");\n\n // Keep only digits and separators. Remove currency symbols/letters/spaces.\n s = s.replace(/[^\\d.,]/g, \"\");\n if (!s) throw new Error(`Invalid price: \"${priceString}\"`);\n\n // Delegate exact cents conversion (no floats)\n return amountToCents(s); // <- your safe BigInt cents converter\n};\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","CENTS_FACTOR","TWO_DECIMAL_PLACES","THREE_DECIMAL_PLACES","ONE_CENT","ZERO_INT","amountToCents","amount","Error","s","String","trim","includes","replace","test","intPart","fracRaw","split","fracPadded","tenths","hundredths","thousandths","trailing","length","slice","hasTrailingNonZero","cents","BigInt","Number","amountFromCents","c","isSafeInteger","remainder","toString","padStart","parsePrice","priceString"],"sourceRoot":""}
1
+ {"version":3,"file":"utils/money.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD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AAEI,QAAQ,WAAY,KACrBJ,EAAG,MAAM,IAAID,MAAO,mBAAkB+B,MAG3C,OAAOjC,EAAcG,EAArB,E","sources":["webpack://openstack-uicore-foundation/webpack/universalModuleDefinition","webpack://openstack-uicore-foundation/webpack/bootstrap","webpack://openstack-uicore-foundation/webpack/runtime/define property getters","webpack://openstack-uicore-foundation/webpack/runtime/hasOwnProperty shorthand","webpack://openstack-uicore-foundation/webpack/runtime/make namespace object","webpack://openstack-uicore-foundation/./src/utils/constants.js","webpack://openstack-uicore-foundation/./src/utils/money.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"openstack-uicore-foundation\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"openstack-uicore-foundation\"] = factory();\n\telse\n\t\troot[\"openstack-uicore-foundation\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const CENTS_FACTOR = 100n;\nexport const TWO_DECIMAL_PLACES = 2;\nexport const THREE_DECIMAL_PLACES = 3;\nexport const ONE_CENT = 1n;\nexport const ZERO_INT = 0;\n","/**\n * Copyright 2025 OpenStack Foundation\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n * */\n\nimport {\n CENTS_FACTOR,\n THREE_DECIMAL_PLACES,\n TWO_DECIMAL_PLACES,\n ZERO_INT,\n ONE_CENT\n} from \"./constants\";\n\nconst CURRENCY_SYMBOL = {\n USD: \"$\",\n EUR: \"€\",\n GBP: \"£\",\n CAD: \"C$\",\n AUD: \"A$\",\n NZD: \"NZ$\",\n CHF: \"CHF\",\n ARS: \"AR$\",\n BRL: \"R$\",\n MXN: \"MX$\",\n};\n\n/**\n * Convert a decimal money amount to integer cents safely (no floating point math).\n *\n * Why this exists:\n * - `Math.round(parseFloat(x) * 100)` can be wrong due to IEEE-754 floating point errors\n * (e.g. 1.005 * 100 may become 100.499999..., rounding down unexpectedly).\n *\n * Input:\n * - number or string (recommended: string from API/UI)\n * - Examples: \"12.34\", \"1,234.56\", \"1234,56\", 12.34\n *\n * Output:\n * - Number cents (exact), e.g. \"12.34\" -> 1234\n *\n * Rounding:\n * - Half-up to 2 decimals (>= 0.005 USD rounds up by 1 cent).\n *\n * Notes:\n * - Amounts are assumed to be NON-negative (per your requirement).\n * - Throws on invalid formats (does not silently return 0).\n */\nexport function amountToCents(amount) {\n if (amount == null) throw new Error(\"amount is required\");\n\n let s = String(amount).trim();\n\n // Normalize common separators:\n // - \"1,234.56\" => \"1234.56\" (remove thousands separators)\n // - \"1234,56\" => \"1234.56\" (convert decimal comma to dot)\n if (s.includes(\",\") && s.includes(\".\")) {\n s = s.replace(/,/g, \"\");\n } else if (s.includes(\",\") && !s.includes(\".\")) {\n s = s.replace(\",\", \".\");\n }\n\n // Validate: digits optionally followed by '.' and more digits\n if (!/^\\d+(\\.\\d+)?$/.test(s)) {\n throw new Error(`Invalid money format: \"${amount}\"`);\n }\n\n const [intPart, fracRaw = \"\"] = s.split(\".\");\n\n // Pad at least 3 fractional digits so we can:\n // - take 2 digits for cents\n // - take the 3rd digit to decide rounding\n const fracPadded = (`${fracRaw }000`);\n\n const tenths = fracPadded[0] ?? \"0\"; // 1st decimal digit\n const hundredths = fracPadded[1] ?? \"0\"; // 2nd decimal digit (cents)\n const thousandths = fracPadded[2] ?? \"0\"; // 3rd decimal digit (rounding decision)\n\n // If there are more than 3 decimals, we track if any non-zero exists after the 3rd.\n // This can matter for policies like bankers rounding; here it's mainly informational.\n const trailing =\n fracRaw.length > THREE_DECIMAL_PLACES\n ? fracRaw.slice(THREE_DECIMAL_PLACES)\n : \"\";\n const hasTrailingNonZero = /[1-9]/.test(trailing);\n\n // Build cents as integer: (dollars * 100) + (first two decimal digits)\n let cents = BigInt(intPart) * CENTS_FACTOR + BigInt(tenths + hundredths);\n\n // Half-up rounding:\n // - If the 3rd digit is >= 5, round up by 1 cent.\n // - If there are more digits beyond the 3rd, \"5xxx\" should also round up.\n const roundUp = thousandths > \"5\" || thousandths === \"5\" || (thousandths === \"5\" && hasTrailingNonZero);\n\n if (roundUp) cents += ONE_CENT;\n\n return Number(cents);\n}\n\n/**\n * Convert an amount in cents to a decimal string (e.g. 1234 -> \"12.34\") safely.\n *\n * Why:\n * - Avoids floating point math (cents / 100) which can lose precision for large integers\n * or if cents is already imprecise as a JS Number.\n *\n * Input:\n * - Accepts: bigint | number | string (digits)\n * - Assumes NON-negative cents (per your requirement).\n *\n * Output:\n * - Always returns a string with exactly 2 decimal places.\n */\nexport function amountFromCents(cents) {\n let c;\n\n // Normalize input to BigInt safely\n if (typeof cents === \"bigint\") {\n c = cents;\n } else if (typeof cents === \"number\") {\n // Ensure it's a safe integer before converting to BigInt\n if (!Number.isSafeInteger(cents)) {\n throw new Error(\"cents must be a safe integer Number (or pass BigInt/string).\");\n }\n c = BigInt(cents);\n } else if (typeof cents === \"string\") {\n const s = cents.trim();\n if (!/^\\d+$/.test(s)) {\n throw new Error(\"cents string must contain digits only (e.g., '1234').\");\n }\n c = BigInt(s);\n } else {\n throw new Error(\"cents must be a bigint, number, or numeric string.\");\n }\n\n if (c < ZERO_INT) {\n throw new Error(\"cents must be non-negative.\");\n }\n\n const amount = c / CENTS_FACTOR;\n const remainder = c % CENTS_FACTOR;\n\n // Always pad remainder to 2 digits\n return `${amount.toString()}.${remainder.toString().padStart(TWO_DECIMAL_PLACES, \"0\")}`;\n}\n\n/**\n * @param cents\n * @param currency\n * @returns {string}\n */\nexport function currencyAmountFromCents(cents, currency = \"USD\"){\n if (typeof cents !== \"number\" || !Number.isInteger(cents)) {\n throw new Error(\"cents must be an integer number\");\n }\n\n const amount = amountFromCents(cents); // \"12.34\"\n const symbol = CURRENCY_SYMBOL[currency] ?? \"$\";\n return `${symbol}${amount}`;\n}\n\n/**\n * Converts a price string into cents.\n * @param {string} priceString - The price (e.g., $0.30).\n * @returns {number} - The amount converted to cents (e.g., 30).\n */\nexport const parsePrice = (priceString) => {\n if (priceString == null) throw new Error(\"priceString is required\");\n\n let s = String(priceString).trim();\n\n // Reject negatives explicitly (per your requirement).\n if (s.includes(\"-\")) throw new Error(\"Negative amounts are not allowed\");\n\n // Keep only digits and separators. Remove currency symbols/letters/spaces.\n s = s.replace(/[^\\d.,]/g, \"\");\n if (!s) throw new Error(`Invalid price: \"${priceString}\"`);\n\n // Delegate exact cents conversion (no floats)\n return amountToCents(s); // <- your safe BigInt cents converter\n};\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","d","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","CENTS_FACTOR","TWO_DECIMAL_PLACES","THREE_DECIMAL_PLACES","ONE_CENT","ZERO_INT","CURRENCY_SYMBOL","USD","EUR","GBP","CAD","AUD","NZD","CHF","ARS","BRL","MXN","amountToCents","amount","Error","s","String","trim","includes","replace","test","intPart","fracRaw","split","fracPadded","tenths","hundredths","thousandths","trailing","length","slice","hasTrailingNonZero","cents","BigInt","Number","amountFromCents","c","isSafeInteger","remainder","toString","padStart","currencyAmountFromCents","currency","isInteger","parsePrice","priceString"],"sourceRoot":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openstack-uicore-foundation",
3
- "version": "4.2.20",
3
+ "version": "4.2.21",
4
4
  "description": "ui reactjs components for openstack marketing site",
5
5
  "main": "lib/openstack-uicore-foundation.js",
6
6
  "scripts": {