Managing a Script library

When Google Apps Script first came out it was rather tedious (and kind of ridiculous for a cloud based environment) having to copy shared code between projects. Things soon got out of hand and you didnt know what version was what.

However, At last we can now create a library of useful stuff in GAS and access it (or share it) from other sheets.

Using this new library management capability in GAS, I can now make all this code available across future projects and to anyone else who want to use it just by referencing the projects key (my shared libraries can be accessed using key MEQ3tE5y5_cTOAgUbUKSIAiz3TLx7pV4j ). If you are sharing your code, remember to set up the containing documents level of sharing (private, public with everyone etc)

How to create a library that can be shared

Go to the manage versions menu item of the file menu in the script editor

Save a version of your library

Take a note of the projects Key from the File/Project Properties dialog

How to Use a shared library

Create a new document that is going to access this library, and bring up the Manage Libraries dialog in the script editor.

Add a reference to the shared library.

You'll see whichever versions are available. If you leave development mode off, then your usage will be frozen to the version you select. You can change the Identifier to something else if you like. Its purpose is to nominate the namespace you will use to reference the shared functions. In this library shown all calls will be prefixed with the Mcpher namespace identifier - for example Mcpher.isEmpty().

Look at the documentation

If the library has been commented using jsDoc, then usage documentation will have been automatically generated and is accessible by clicking on the Title link for each included library. jsDoc also enables autocomplete when you call up the functions in the code you write using the library.