remove usage of depreciated substr

This commit is contained in:
Abhinav 2022-04-20 19:04:41 +05:30
parent 5314e041e3
commit 1a93e73a5b
2 changed files with 19 additions and 17 deletions

View file

@ -187,19 +187,21 @@ export default function Upload(props: Props) {
paths.sort((path1, path2) => getCharCount(path1) - getCharCount(path2));
const firstPath = paths[0];
const lastPath = paths[paths.length - 1];
const L = firstPath.length;
let i = 0;
const firstFileFolder = firstPath.substr(0, firstPath.lastIndexOf('/'));
const lastFileFolder = lastPath.substr(0, lastPath.lastIndexOf('/'));
const firstFileFolder = firstPath.slice(0, firstPath.lastIndexOf('/'));
const lastFileFolder = lastPath.slice(0, lastPath.lastIndexOf('/'));
while (i < L && firstPath.charAt(i) === lastPath.charAt(i)) i++;
let commonPathPrefix = firstPath.substring(0, i);
let commonPathPrefix = firstPath.slice(0, i);
if (commonPathPrefix) {
commonPathPrefix = commonPathPrefix.substr(
1,
commonPathPrefix.lastIndexOf('/') - 1
commonPathPrefix = commonPathPrefix.slice(
0,
commonPathPrefix.lastIndexOf('/')
);
if (commonPathPrefix) {
commonPathPrefix = commonPathPrefix.substr(
commonPathPrefix = commonPathPrefix.slice(
commonPathPrefix.lastIndexOf('/') + 1
);
}
@ -214,11 +216,11 @@ export default function Upload(props: Props) {
for (const file of toUploadFiles.current) {
const filePath = file['path'] as string;
let folderPath = filePath.substr(0, filePath.lastIndexOf('/'));
let folderPath = filePath.slice(0, filePath.lastIndexOf('/'));
if (folderPath.endsWith(METADATA_FOLDER_NAME)) {
folderPath = folderPath.substr(0, folderPath.lastIndexOf('/'));
folderPath = folderPath.slice(0, folderPath.lastIndexOf('/'));
}
const folderName = folderPath.substr(
const folderName = folderPath.slice(
folderPath.lastIndexOf('/') + 1
);
if (!collectionWiseFiles.has(folderName)) {

View file

@ -298,25 +298,25 @@ export const preservePhotoswipeProps =
return fileWithPreservedProperty;
};
export function fileNameWithoutExtension(filename) {
export function fileNameWithoutExtension(filename: string) {
const lastDotPosition = filename.lastIndexOf('.');
if (lastDotPosition === -1) return filename;
else return filename.substr(0, lastDotPosition);
else return filename.slice(0, lastDotPosition);
}
export function fileExtensionWithDot(filename) {
export function fileExtensionWithDot(filename: string) {
const lastDotPosition = filename.lastIndexOf('.');
if (lastDotPosition === -1) return '';
else return filename.substr(lastDotPosition);
else return filename.slice(lastDotPosition);
}
export function splitFilenameAndExtension(filename): [string, string] {
export function splitFilenameAndExtension(filename: string): [string, string] {
const lastDotPosition = filename.lastIndexOf('.');
if (lastDotPosition === -1) return [filename, null];
else
return [
filename.substr(0, lastDotPosition),
filename.substr(lastDotPosition + 1),
filename.slice(0, lastDotPosition),
filename.slice(lastDotPosition + 1),
];
}