Skip to content

Instantly share code, notes, and snippets.

@chukonu
Created March 26, 2018 04:29
Show Gist options
  • Save chukonu/16d2d735f228442afb89875a69264a72 to your computer and use it in GitHub Desktop.
Save chukonu/16d2d735f228442afb89875a69264a72 to your computer and use it in GitHub Desktop.
Extracts x and y from a CSS polygon clip-path string
// 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