Browse Source

refactor: replace deprecated String.prototype.substr() (#34498)

String.prototype.substr() is deprecated (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) so we replace it with functions which aren't.
Signed-off-by: Tobias Speicher <rootcommander@gmail.com>
pull/34506/head
CommanderRoot 3 years ago
committed by GitHub
parent
commit
7c34addf57
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      components/_util/getDataOrAriaProps.ts
  2. 4
      components/tree/demo/search.md
  3. 2
      components/upload/demo/file-type.md
  4. 2
      site/theme/template/Layout/Header/index.tsx

4
components/_util/getDataOrAriaProps.ts

@ -1,8 +1,8 @@
export default function getDataOrAriaProps(props: any) {
return Object.keys(props).reduce((prev: any, key: string) => {
if (
(key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-' || key === 'role') &&
key.substr(0, 7) !== 'data-__'
(key.startsWith('data-') || key.startsWith('aria-') || key === 'role') &&
!key.startsWith('data-__')
) {
prev[key] = props[key];
}

4
components/tree/demo/search.md

@ -110,8 +110,8 @@ class SearchTree extends React.Component {
const loop = data =>
data.map(item => {
const index = item.title.indexOf(searchValue);
const beforeStr = item.title.substr(0, index);
const afterStr = item.title.substr(index + searchValue.length);
const beforeStr = item.title.substring(0, index);
const afterStr = item.title.slice(index + searchValue.length);
const title =
index > -1 ? (
<span>

2
components/upload/demo/file-type.md

@ -102,7 +102,7 @@ class PicturesWall extends React.Component {
icon = <LoadingOutlined />; // or icon = 'uploading...';
} else {
fileSufIconList.forEach(item => {
if (item.suf.includes(file.name.substr(file.name.lastIndexOf('.')))) {
if (item.suf.includes(file.name.slice(file.name.lastIndexOf('.')))) {
icon = item.type;
}
});

2
site/theme/template/Layout/Header/index.tsx

@ -192,7 +192,7 @@ class Header extends React.Component<HeaderProps, HeaderState> {
location: { pathname, query },
} = this.props;
const currentProtocol = `${window.location.protocol}//`;
const currentHref = window.location.href.substr(currentProtocol.length);
const currentHref = window.location.href.slice(currentProtocol.length);
if (utils.isLocalStorageNameSupported()) {
localStorage.setItem('locale', utils.isZhCN(pathname) ? 'en-US' : 'zh-CN');

Loading…
Cancel
Save