scripts/rangement/finders.mjs

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-06-29 17:09:18 +02:00
/**
* la classe qui repère des patterns
*/
2023-06-29 18:00:38 +02:00
import {tagSectionSeparator} from "./configs.mjs";
2023-06-29 17:09:18 +02:00
2023-06-29 18:00:38 +02:00
/**
* finds patterns for file name
*/
2023-06-29 17:09:18 +02:00
export default class finders{
patternsFiles = {
'downloaded_pic': /^\-\w{15}\.jpg/, // FyB8cZnWIAc21rw.jpg
'telegram_pic': /^\-\d{19}_\d{4}/, // -4900281569878475578_1109.jpg
'open_camera': /^IMG_OC_\d{8}/i, // IMG_OC_20230617_092120_3.jpg
'screenshot': /^Screenshot/i, // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png
}
static findScreenshot (inputString) {
return inputString.match(/screenshot/i) || inputString.match(/capture d'écran/i)
}
static findFormattedDate(filepath) {
2023-06-29 17:40:48 +02:00
let found = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig)
console.log('found', found)
return found
2023-06-29 17:09:18 +02:00
}
static findFileExtension (inputString) {
let match = inputString.match(/\.\w{3,4}$/i)
return match
}
/**
* find the section of file name which contains the free text to describe the picture
* @param fileName
* @returns {*|string}
*/
static findFileNameFreeTextPart(fileName) {
fileName = fileName.replace(this.findFileExtension(fileName), '')
let boom = fileName.split(tagSectionSeparator)
if (boom.length) {
let freeTextPart = boom[0].trim()
console.log('freeTextPart', freeTextPart)
return freeTextPart
}
return fileName.trim()
}
}