Find lightness of a HEX colour in JavaScript

Cool little snippet from Heydon Pickering, with some extra ideas in the comments:

https://twitter.com/heydonworks/status/1008983621468938240