Refactor repeated JS API code

The operation to convert a JSValueRef to a C string is repeated several
times throughout, so refactor it into its own function.
Refactor operation to read first line of file

This operation is currently only used once, but I am about to use it in
more than one place.
Refactor operations to search extensions tree

The operations to search the installed extensions tree for an author or
title are only used once, but I am about to use them more than once, so
remove them to their own functions.