remove usage of depreciated substr
This commit is contained in:
parent
5314e041e3
commit
1a93e73a5b
|
@ -187,19 +187,21 @@ export default function Upload(props: Props) {
|
||||||
paths.sort((path1, path2) => getCharCount(path1) - getCharCount(path2));
|
paths.sort((path1, path2) => getCharCount(path1) - getCharCount(path2));
|
||||||
const firstPath = paths[0];
|
const firstPath = paths[0];
|
||||||
const lastPath = paths[paths.length - 1];
|
const lastPath = paths[paths.length - 1];
|
||||||
|
|
||||||
const L = firstPath.length;
|
const L = firstPath.length;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const firstFileFolder = firstPath.substr(0, firstPath.lastIndexOf('/'));
|
const firstFileFolder = firstPath.slice(0, firstPath.lastIndexOf('/'));
|
||||||
const lastFileFolder = lastPath.substr(0, lastPath.lastIndexOf('/'));
|
const lastFileFolder = lastPath.slice(0, lastPath.lastIndexOf('/'));
|
||||||
while (i < L && firstPath.charAt(i) === lastPath.charAt(i)) i++;
|
while (i < L && firstPath.charAt(i) === lastPath.charAt(i)) i++;
|
||||||
let commonPathPrefix = firstPath.substring(0, i);
|
let commonPathPrefix = firstPath.slice(0, i);
|
||||||
|
|
||||||
if (commonPathPrefix) {
|
if (commonPathPrefix) {
|
||||||
commonPathPrefix = commonPathPrefix.substr(
|
commonPathPrefix = commonPathPrefix.slice(
|
||||||
1,
|
0,
|
||||||
commonPathPrefix.lastIndexOf('/') - 1
|
commonPathPrefix.lastIndexOf('/')
|
||||||
);
|
);
|
||||||
if (commonPathPrefix) {
|
if (commonPathPrefix) {
|
||||||
commonPathPrefix = commonPathPrefix.substr(
|
commonPathPrefix = commonPathPrefix.slice(
|
||||||
commonPathPrefix.lastIndexOf('/') + 1
|
commonPathPrefix.lastIndexOf('/') + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -214,11 +216,11 @@ export default function Upload(props: Props) {
|
||||||
for (const file of toUploadFiles.current) {
|
for (const file of toUploadFiles.current) {
|
||||||
const filePath = file['path'] as string;
|
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)) {
|
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
|
folderPath.lastIndexOf('/') + 1
|
||||||
);
|
);
|
||||||
if (!collectionWiseFiles.has(folderName)) {
|
if (!collectionWiseFiles.has(folderName)) {
|
||||||
|
|
|
@ -298,25 +298,25 @@ export const preservePhotoswipeProps =
|
||||||
return fileWithPreservedProperty;
|
return fileWithPreservedProperty;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function fileNameWithoutExtension(filename) {
|
export function fileNameWithoutExtension(filename: string) {
|
||||||
const lastDotPosition = filename.lastIndexOf('.');
|
const lastDotPosition = filename.lastIndexOf('.');
|
||||||
if (lastDotPosition === -1) return filename;
|
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('.');
|
const lastDotPosition = filename.lastIndexOf('.');
|
||||||
if (lastDotPosition === -1) return '';
|
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('.');
|
const lastDotPosition = filename.lastIndexOf('.');
|
||||||
if (lastDotPosition === -1) return [filename, null];
|
if (lastDotPosition === -1) return [filename, null];
|
||||||
else
|
else
|
||||||
return [
|
return [
|
||||||
filename.substr(0, lastDotPosition),
|
filename.slice(0, lastDotPosition),
|
||||||
filename.substr(lastDotPosition + 1),
|
filename.slice(lastDotPosition + 1),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue