Created
January 23, 2020 09:54
-
-
Save frank-dspeed/a309b0ae4c81816c33a83731898e5b86 to your computer and use it in GitHub Desktop.
Method to get Current File Path inside ESM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//import.meta.url | |
function getPath(url) { | |
let result = new URL(import.meta.url) | |
let pathname = result.pathname | |
let pathArray = pathname.split('/') | |
let basename = pathArray.pop() | |
let dirname = pathArray.join('/') | |
return { pathname, dirname,basename} | |
} | |
console.log(getPath(import.meta.url)) | |
const currentFile = import.meta.url; | |
const currentDirectory = new URL(import.meta.url).pathname.split('/').slice(0,-1).join('/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment