index.js 1.1 KB

123456789101112131415161718
  1. export default function buildLocalizeFn(args) {
  2. return function (dirtyIndex, options) {
  3. var context = options !== null && options !== void 0 && options.context ? String(options.context) : 'standalone';
  4. var valuesArray;
  5. if (context === 'formatting' && args.formattingValues) {
  6. var defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
  7. var width = options !== null && options !== void 0 && options.width ? String(options.width) : defaultWidth;
  8. valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
  9. } else {
  10. var _defaultWidth = args.defaultWidth;
  11. var _width = options !== null && options !== void 0 && options.width ? String(options.width) : args.defaultWidth;
  12. valuesArray = args.values[_width] || args.values[_defaultWidth];
  13. }
  14. var index = args.argumentCallback ? args.argumentCallback(dirtyIndex) : dirtyIndex;
  15. // @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!
  16. return valuesArray[index];
  17. };
  18. }