0

At the time of this question String.prototype.at is not implemented in all browsers.

I would like to use the at function on the String prototype within a React app that uses babel to transform modern ecmascript into older more browser compatible versions of javascript.

I have been unsuccessful in finding a babel plugin that would do this for me.

Is there a @babel/plugin that will transform the String prototype at function down to more browser compatible ES5 javascript?

SuperStormer
  • 4,997
  • 5
  • 25
  • 35
skellertor
  • 916
  • 1
  • 9
  • 26

1 Answers1

0

Babel is for syntax-level transformations, not browser API polyfills.

You can consider using a polyfill service like Polyfill.io, or alternatively, simply use the polyfill code from the relevant proposal.

Lionel Rowe
  • 5,164
  • 1
  • 14
  • 27
  • what about `@babel/polyfill`? Will this one work? https://babeljs.io/docs/en/babel-polyfill/ It seems to suggest that it polyfills native prototypes and instance methods – skellertor Oct 14 '21 at 15:34
  • 1
    @skellertor Given that there's a big notice up the top saying "deprecated in favor of core.js", it may or may not have newer features like `String#at`. I'm assuming core.js would have it, though. – Lionel Rowe Oct 14 '21 at 16:21