Skip to content

Commit

Permalink
removeLeadingDot option added (#24)
Browse files Browse the repository at this point in the history
* config prop prefixPathWithCurrentDirectory implemented, _workspacePath fixed

* prefixPathWithCurrentDirectory reanemed to removeLeadingDot as it as previosly called
  • Loading branch information
gecharo authored and Jakob Werner committed Feb 6, 2018
1 parent b83dd74 commit a571731
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
".js"
],
"description": "An array of extensions to exclude from the relative path url (Useful for used with Webpack or when importing files of mixed types)"
},
"relativePath.removeLeadingDot": {
"type": "boolean",
"default": true,
"description": "Removes the leading ./ character when the path is pointing to a parent folder."
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ class RelativePath {
const editor = window.activeTextEditor;
if (editor) {
const res = editor.document.uri;
const folder = workspace.getWorkspaceFolder(res)
return folder.uri.fsPath;
const folder = workspace.getWorkspaceFolder(res);
return folder.uri.fsPath.replace(/\\/g, "/");
}
}
// Purely updates the files
Expand Down Expand Up @@ -203,13 +203,11 @@ class RelativePath {
const currentItemPath = editor.document.fileName.replace(/\\/g, "/").replace(this._workspacePath, "");
let relativeUrl: string = path.relative(currentItemPath, targetPath).replace(".", "").replace(/\\/g, "/");

if (this._configuration.removeExtension) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
} else if (this.excludeExtensionsFor(relativeUrl)) {
if (this._configuration.removeExtension || this.excludeExtensionsFor(relativeUrl)) {
relativeUrl = relativeUrl.substring(0, relativeUrl.lastIndexOf("."));
}

if (relativeUrl.startsWith("./../")) {
if (this._configuration.removeLeadingDot && relativeUrl.startsWith("./../")) {
relativeUrl = relativeUrl.substring(2, relativeUrl.length);
}

Expand Down

0 comments on commit a571731

Please sign in to comment.