Created
March 26, 2018 04:29
-
-
Save chukonu/16d2d735f228442afb89875a69264a72 to your computer and use it in GitHub Desktop.
Extracts x and y from a CSS polygon clip-path string
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
// extracts x and y from a CSS polygon clip-path string | |
function extractPoints(str) { | |
// 'polygon(' - starts from index 8 | |
// ends at length-1 | |
let s = str.substring(8, str.length - 1) | |
let pointStrs = s.split(',').map(p => p.trim()) | |
return pointStrs.map(str => { | |
let percentages = str.split(' ') | |
return { | |
x: excludePercentSign(percentages[0]), | |
y: excludePercentSign(percentages[1]) | |
} | |
}) | |
} | |
function excludePercentSign(percentage) { | |
return parseFloat(percentage.substring(0, percentage.length - 1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment