Created
November 29, 2022 19:14
-
-
Save aashreys/fb3e623992f821d7d3165badc1c059e4 to your computer and use it in GitHub Desktop.
Get Figma Node ID from URL
This file contains 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
export function getNodeIdFromUrl(url: string): string | null { | |
url = url.toLowerCase() | |
let startIndex: number = url.indexOf('node-id=') + 8 | |
let endIndex: number = url.indexOf('&', startIndex) | |
if (startIndex) { | |
if (endIndex > 0) { | |
return url.substring(startIndex, endIndex).replace('%3a', ':') | |
} else { | |
return url.substring(startIndex).replace('%3a', ':') | |
} | |
} else { | |
return null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment