2025-07-15 00:15:28 -07:00
|
|
|
/**
|
|
|
|
* FSDB Organizer: By Character
|
|
|
|
*
|
|
|
|
* Organizes by splitting a string up and using the characters
|
|
|
|
* for folders, eg:
|
|
|
|
*
|
|
|
|
* abcdefg.json => /a/ab/abc/abcdefg.json
|
|
|
|
*
|
|
|
|
* @module
|
|
|
|
*/
|
|
|
|
|
2025-06-13 20:40:28 -07:00
|
|
|
import sanitize from '../utils/sanitize.ts';
|
|
|
|
|
|
|
|
export default function by_character(value: string): string[] {
|
|
|
|
const result: string[] = [];
|
|
|
|
|
|
|
|
// Replace invalid filename characters and leading dots
|
|
|
|
const sanitized_value = sanitize(value);
|
|
|
|
const characters_remaining = sanitized_value.split('');
|
|
|
|
|
|
|
|
let previous_characters = '';
|
|
|
|
while (characters_remaining.length) {
|
|
|
|
previous_characters += characters_remaining.shift();
|
|
|
|
result.push(previous_characters);
|
|
|
|
if (result.length >= 3) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result.push(`${sanitized_value}.json`);
|
|
|
|
return result;
|
|
|
|
}
|