@bigbinary/neeto-commons-frontend 2.1.26 → 2.1.27

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/utils.d.ts CHANGED
@@ -421,4 +421,48 @@ export function getFromLocalStorage<T extends object>(key: string): T | null;
421
421
  * setToLocalStorage("token", "1234-5678-9101-1213");
422
422
  * @endexample
423
423
  */
424
- export function setToLocalStorage(key: string, value: any): void;
424
+ export function setToLocalStorage(key: string, value: any): void;
425
+ type CurrencyFormatterFunction = (amount: number | string, currency: string, options?: Intl.NumberFormatOptions) => string;
426
+ /**
427
+ *
428
+ * currencyFormat is a utility which provides functions which formats a given
429
+ *
430
+ * number in currency formats based on the current user locale. Current user locale
431
+ *
432
+ * is based on dayjs.locale().
433
+ *
434
+ * withAmount accepts two arguments:
435
+ *
436
+ * All other functions accept three arguments:
437
+ *
438
+ * @example
439
+ *
440
+ * import { currencyFormat } from "neetocommons/utils";
441
+ *
442
+ * currencyFormat.withAmount(1000); // In `en` locale, returns "1,000.00"
443
+ * currencyFormat.withAmount(125, { maximumFractionDigits: 1 }); // In `en` locale, returns "125.0"
444
+ *
445
+ * currencyFormat.withSymbol(1000, "USD"); // In `en` locale, returns "$1,000.00"
446
+ * currencyFormat.withSymbol(125, "USD", { maximumFractionDigits: 1 }); // In `en` locale, returns "$125.0"
447
+ *
448
+ * currencyFormat.withCode(1000, "USD"); // In `en` locale, returns "1,000.00 USD"
449
+ * currencyFormat.withCode(125, "USD", { maximumFractionDigits: 1 }); // In `en` locale, returns "125.0 USD"
450
+ *
451
+ * currencyFormat.withSymbolAndCode(1000, "INR"); // In `en` locale, returns "₹1,000.00 INR"
452
+ * currencyFormat.withSymbolAndCode(125, "INR", {
453
+ * maximumFractionDigits: 1,
454
+ * }); // In `en` locale, returns "₹125.0 INR"
455
+ *
456
+ * // `fr`
457
+ * currencyFormat.withSymbolAndCode(1000, "EUR"); // In `fr` locale, returns "1 000 € EUR"
458
+ * currencyFormat.withSymbolAndCode(125, "INR", {
459
+ * maximumFractionDigits: 1,
460
+ * }); // In `fr` locale, returns "125,00 ₹ INR""
461
+ * @endexample
462
+ */
463
+ export const currencyFormat: {
464
+ withAmount: (amount: number | string, options?: Intl.NumberFormatOptions) => string;
465
+ withSymbol: CurrencyFormatterFunction;
466
+ withCode: CurrencyFormatterFunction;
467
+ withSymbolAndCode: CurrencyFormatterFunction;
468
+ };
package/utils.js CHANGED
@@ -2519,8 +2519,8 @@ var lib = {
2519
2519
  };
2520
2520
 
2521
2521
  var _this = undefined;
2522
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2523
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2522
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2523
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2524
2524
  var withEventTargetValue = /*#__PURE__*/curry(function (func, event) {
2525
2525
  return func(event.target.value);
2526
2526
  });
@@ -2538,7 +2538,7 @@ var simulateApiCall = function simulateApiCall(result, error) {
2538
2538
  success: false,
2539
2539
  notice: i18next.t("neetoCommons.notice.errorOccurred")
2540
2540
  };
2541
- Math.random() < errorProbability ? reject(_objectSpread(_objectSpread({}, defaultErrorObj), error)) : resolve(result);
2541
+ Math.random() < errorProbability ? reject(_objectSpread$1(_objectSpread$1({}, defaultErrorObj), error)) : resolve(result);
2542
2542
  }, delay);
2543
2543
  });
2544
2544
  };
@@ -2615,7 +2615,7 @@ var toLocale = function toLocale(number) {
2615
2615
  };
2616
2616
  var getQueryParams = function getQueryParams() {
2617
2617
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
2618
- return lib.parse(location.search, _objectSpread({
2618
+ return lib.parse(location.search, _objectSpread$1({
2619
2619
  ignoreQueryPrefix: true
2620
2620
  }, options));
2621
2621
  };
@@ -3225,5 +3225,45 @@ var createSubscription = function createSubscription(channelName, callbacks) {
3225
3225
  return subscription;
3226
3226
  };
3227
3227
 
3228
- export { buildUrl, copyToClipboard, createSubscription, dateFormat, debounce, getFromLocalStorage, getQueryParams, getSubdomain, hasAllPermissions, hasAnyPermission, hasPermission, joinHyphenCase, resetAuthTokens, setToLocalStorage, simulateApiCall, timeFormat, toLocale, withEventTargetValue };
3228
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3229
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3230
+ var getAmountWithSymbol = function getAmountWithSymbol(amount, options) {
3231
+ var formatter = new Intl.NumberFormat(dayjs.locale(), _objectSpread({}, options));
3232
+ return formatter.format(Number(amount));
3233
+ };
3234
+ var currencyFormat = {
3235
+ withAmount: function withAmount(amount) {
3236
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
3237
+ minimumFractionDigits: 2
3238
+ };
3239
+ return getAmountWithSymbol(amount, _objectSpread({
3240
+ style: undefined
3241
+ }, options));
3242
+ },
3243
+ // 1000, { maximumFractionDigits: 1 } => 1,000.0
3244
+ withSymbol: function withSymbol(amount, currency, options) {
3245
+ return getAmountWithSymbol(amount, _objectSpread(_objectSpread({}, options), {}, {
3246
+ style: "currency",
3247
+ currency: currency
3248
+ }));
3249
+ },
3250
+ // 1000, "INR", { maximumFractionDigits: 0 } => ₹1,000
3251
+ withCode: function withCode(amount, currency) {
3252
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
3253
+ minimumFractionDigits: 2
3254
+ };
3255
+ return "".concat(getAmountWithSymbol(amount, _objectSpread(_objectSpread({}, options), {}, {
3256
+ style: undefined
3257
+ })), " ").concat(currency);
3258
+ },
3259
+ // 1000, "USD" => 1,000.00 USD
3260
+ withSymbolAndCode: function withSymbolAndCode(amount, currency, options) {
3261
+ return "".concat(getAmountWithSymbol(amount, _objectSpread(_objectSpread({}, options), {}, {
3262
+ style: "currency",
3263
+ currency: currency
3264
+ })), " ").concat(currency);
3265
+ } // 1000, "INR", { maximumFractionDigits: 0 } => ₹1,000 INR
3266
+ };
3267
+
3268
+ export { buildUrl, copyToClipboard, createSubscription, currencyFormat, dateFormat, debounce, getFromLocalStorage, getQueryParams, getSubdomain, hasAllPermissions, hasAnyPermission, hasPermission, joinHyphenCase, resetAuthTokens, setToLocalStorage, simulateApiCall, timeFormat, toLocale, withEventTargetValue };
3229
3269
  //# sourceMappingURL=utils.js.map