react-native-macos/packages/polyfills
Pranav Yadav 8a49754cda Refactor: JS `substr()` is deprecated, using `slice()` instead (#37136)
Summary:
Fixes: https://github.com/facebook/react-native/issues/37135

- `substr()` is not part of the core JS since ~2018
- No wonder why no one noticed this :)
- Though its supported by modern browsers, its deprecated
- Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr

### Why `slice()` and not `substring()`?
> Beacuse I like pizza ;) jk

The reason, that I'm not using the most obvious alternative `substring()` is;
- It _swaps the args_ passed, when; `startIndex > endIndex` —which I think is not a property of _good_ fn
  and also does not reflects the same in it's name.
- It _doesn't support negative args_, which I think reduces flexibility to work with it.
- It could lead to more bugs in most of the cases.

### Refecrences:
- Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring#differences_between_substring_and_slice
- Ref. for `slice()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
- Ref. for `substring()`: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring

## Changelog:

[GENERAL][FIXED] - Refactor: `substr()` is deprecated, using `slice()` instead across RN codebase

Pull Request resolved: https://github.com/facebook/react-native/pull/37136

Test Plan: - `yarn lint && yarn flow && yarn test-ci` --> _should be green_

Reviewed By: christophpurrer

Differential Revision: D45477910

Pulled By: jacdebug

fbshipit-source-id: 96a80893477599b9a549918924157627b9b0c3f4
2023-05-02 11:28:56 -07:00
..
__tests__ @emails -> @oncall (remaining ones) 2022-09-15 15:54:10 -07:00
.npmignore
Object.es8.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
README.md Add missing READMEs & Update package.json in all RN packages (#37090) 2023-04-28 04:26:20 -07:00
console.js Refactor: JS `substr()` is deprecated, using `slice()` instead (#37136) 2023-05-02 11:28:56 -07:00
error-guard.js Suppress missing 'this' annotations in xplat/js 2022-07-07 21:53:53 -07:00
index.js Update copyright headers from Facebook to Meta 2021-12-30 15:11:21 -08:00
package.json Add missing READMEs & Update package.json in all RN packages (#37090) 2023-04-28 04:26:20 -07:00

README.md

@react-native/js-polyfills

Version

Installation

yarn add @react-native/js-polyfills

Note: We're using yarn to install deps. Feel free to change commands to use npm 3+ and npx if you like

Testing

To run the tests in this package, run the following commands from the React Native root folder:

  1. yarn to install the dependencies. You just need to run this once
  2. yarn jest packages/polyfills.