diff --git a/Scripts/convertBulletToFileStructure.js b/Scripts/convertBulletToFileStructure.js new file mode 100644 index 00000000..76134df2 --- /dev/null +++ b/Scripts/convertBulletToFileStructure.js @@ -0,0 +1,65 @@ +/** +{ + "api":1, + "name":"Convert Bullet Points to File Structure", + "description":"Converts bullet point list to a file structure representation.", + "author":"funclosure", + "icon":"term", + "tags":"bullet,filestructure,convert" +} +**/ + +function main(input) { + input.text = convertBulletToFileStructure(input.text); +} + +function convertBulletToFileStructure(input) { + const lines = input.trim().split('\n'); + const result = ['']; + const structure = []; + const lastIndices = {}; + + // First pass: determine the structure and last indices + lines.forEach((line, index) => { + const indent = line.search(/\S|$/); + while (structure.length > 0 && indent <= structure[structure.length - 1]) { + structure.pop(); + } + structure.push(indent); + lastIndices[indent] = index; + }); + + // Second pass: generate the file structure + structure.length = 0; // Reset structure for second pass + lines.forEach((line, index) => { + const trimmedLine = line.trim(); + const indent = line.search(/\S|$/); + const name = trimmedLine.replace(/^[-•*]\s*/, ''); + + while (structure.length > 0 && indent <= structure[structure.length - 1]) { + structure.pop(); + } + + if (index === 0) { + result.push(`${name}/`); + } else { + const level = structure.length; + let prefix = ''; + for (let i = 0; i < level; i++) { + if (index > lastIndices[structure[i]]) { + prefix += ` `; + } else { + prefix += '│ '; + } + } + const isLast = index === lastIndices[indent]; + const connector = isLast ? '└── ' : '├── '; + const suffix = name.includes('.') ? '' : '/'; + result.push(`${prefix}${connector}${name}${suffix}`); + } + + structure.push(indent); + }); + + return result.join('\n'); +} \ No newline at end of file diff --git a/Scripts/convertFileStructureToBullet.js b/Scripts/convertFileStructureToBullet.js new file mode 100644 index 00000000..2bf453cf --- /dev/null +++ b/Scripts/convertFileStructureToBullet.js @@ -0,0 +1,43 @@ +/** +{ + "api":1, + "name":"Convert File Structure to Bullet Points", + "description":"Converts a file structure representation to a bullet point list.", + "author":"funclosure", + "icon":"term", + "tags":"filestructure,bullet,convert" +} +**/ + +function main(input) { + input.text = convertFileStructureToBullet(input.text); +} + +function convertFileStructureToBullet(input) { + const lines = input.trim().split('\n'); + const result = []; + let prevDepth = 0; + + lines.forEach((line, index) => { + if (index === 0) { + // Handle root directory + result.push(line.replace('/', '')); + return; + } + + const depth = (line.match(/(?:│ |\s{4})/g) || []).length; + const name = line.replace(/^(?:│ |\s{4})*[└├]── /, '').replace('/', ''); + const indent = ' '.repeat(depth); + + // Add empty lines for missing levels + while (depth > prevDepth + 1) { + result.push(`${' '.repeat(prevDepth + 1)}- `); + prevDepth++; + } + + result.push(`${indent}- ${name}`); + prevDepth = depth; + }); + + return result.join('\n'); +} \ No newline at end of file