index.js 1.2 KB

12345678910111213141516171819202122232425
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = buildLocalizeFn;
  6. function buildLocalizeFn(args) {
  7. return function (dirtyIndex, options) {
  8. var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
  9. var valuesArray;
  10. if (context === 'formatting' && args.formattingValues) {
  11. var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
  12. var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
  13. valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
  14. } else {
  15. var _defaultWidth = args.defaultWidth;
  16. var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
  17. valuesArray = args.values[_width] || args.values[_defaultWidth];
  18. }
  19. var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
  20. // @ts-ignore: For some reason TypeScript just don't want to match it, no matter how hard we try. I challenge you to try to remove it!
  21. return valuesArray[index];
  22. };
  23. }
  24. module.exports = exports.default;