Async/Await with Ternary Operators
Griffin Michl
1421

One can await at another order of magnitude, building off of the above!:

const Shareability = { ofURI() { return Promise.resolve(location.href) }}
const canShare = ({ canonical = false } = { }) => {
if (!navigator.share)
return Promise.resolve(false)
  return Shareability.ofURI(canonical?document.querySelector('link[rel="canonical"]'):location.href)
}
const beSelfish = () =>
Promise.reject(new Error('Sharing unavailable'))
const shareAttempt = async ({ title, text }, url) =>
await (url = await canShare({ canonical: true }) ?
navigator.share({ title, text, url }) :
beSelfish())
//  async () => { try { await shareAttempt({ title:'Async/Await', text: 'They\'re so cool!' }) } catch (e) { console.error(e) // Internal error: could not connect to Web Share interface. } }
Like what you read? Give James Womack a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.