Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add in parser logic for utils #7

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
55 changes: 0 additions & 55 deletions out/extension.js

This file was deleted.

1 change: 0 additions & 1 deletion out/extension.js.map

This file was deleted.

22 changes: 0 additions & 22 deletions out/test/runTest.js

This file was deleted.

1 change: 0 additions & 1 deletion out/test/runTest.js.map

This file was deleted.

15 changes: 0 additions & 15 deletions out/test/suite/extension.test.js

This file was deleted.

1 change: 0 additions & 1 deletion out/test/suite/extension.test.js.map

This file was deleted.

40 changes: 0 additions & 40 deletions out/test/suite/index.js

This file was deleted.

1 change: 0 additions & 1 deletion out/test/suite/index.js.map

This file was deleted.

57 changes: 0 additions & 57 deletions out/workspaces.js

This file was deleted.

1 change: 0 additions & 1 deletion out/workspaces.js.map

This file was deleted.

43 changes: 43 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
*
* @param path
* @returns an extracted list of file paths to create
* @example 'path/{a.ts,b.ts}' -> ['path/a.ts','path/b.ts']
* @example 'path/{a.ts,subdir/b.ts}' -> ['path/a.ts', 'path/subdir/b.ts']
*/
export function expandPathString(path: string): string[] {
const paths: string[] = [];
// No commas or {} means nothing to expand.
if (!path.includes(',') && !path.includes('{')) return [path];
// We're going to do this the quick and dirty way for now

// If we don't have any brackets, then we just have commas,
// which means we can just return the paths from that
if (!path.includes('{')) {
return path.split(/\s?,\s?/);
}

// Okay, so now things get fucky

let base = '';
let match = '';
let matching = false;
for(let i = 0; i < path.length; i++) {
if(matching && path[i] !== '}') {
match += path[i];
} else if(!matching && path[i] !== '{' && path[i] !== '}') base += path[i]
else if (path[i] === '{') {
matching = true;
} else if (path[i] === '}') {
matching = false;
}
}

if(match.length) {
for(let p of match.split(/\s?,\s?/)) {
paths.push(`${base}${p}`);
}
}

return paths;
}
Loading