Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions Scripts/convertBulletToFileStructure.js
Original file line number Diff line number Diff line change
@@ -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');
}
43 changes: 43 additions & 0 deletions Scripts/convertFileStructureToBullet.js
Original file line number Diff line number Diff line change
@@ -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');
}