The attached file adapts some code for Javascript use. The result is the internal rate of return (IRR). The data is a set of consecutive annual payments. This is the same as the IRR function in Excel, so you can test against that for verification.
Not yet. We'd have to think about how we managed storage of such a library, the syntax for import, and how to manage dependency recalculation when the library was edited. In short, not entirely trivial. Please post as a separate idea.