The implementations below uses the following Node dependencies.
Fetching Clipboard Links
I made a conscious effort to try and break up the problem as much as I could, so as to create smaller, more concise functions.
The first problem to solve was fetching the links from the clipboard and then parsing this input into an array.
You will notice that I am wrapping the callback-based
paste asynchronous approach with a Promise so I can interact with it in the same way as the rest of the application functions.
Fetching and Extracting Link Titles
Now that we have the desired input we can fetch and extract the titles for each of the links.
Notice how I have created functions which handle an individual link transformation, and then used a
Promise.all invocation to handle the array provided.
Copying the Markdown List to the Clipboard
Finally, we need to ‘zip’ up the links and their associated titles and then transform this list into Markdown, which is subsequently copied to the clipboard.
Putting it Together
The functions we have created are very small, and as a result very descriptive/composable in their nature. Below is a basic Promise based approach to stitching the functions together to solve the problem laid out.