-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdndUtils.js
More file actions
27 lines (22 loc) · 758 Bytes
/
dndUtils.js
File metadata and controls
27 lines (22 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export const parseWallpaperName = (filename) => {
const nameWithoutExtension = filename.split('.')[0];
const dashes = nameWithoutExtension.match(/-/g) || [];
let parsedName = nameWithoutExtension;
if (dashes.length >= 2) {
const lastIndex = nameWithoutExtension.lastIndexOf('-');
const secondLastIndex = nameWithoutExtension.lastIndexOf(
'-',
lastIndex - 1,
);
parsedName = nameWithoutExtension.substring(0, secondLastIndex);
}
if (parsedName.endsWith('-')) {
parsedName = parsedName.slice(0, -1);
}
const withSpaces = parsedName.replace(/-/g, ' ');
const capitalized = withSpaces
.split(' ')
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');
return capitalized;
};