Use third-party libraries in Apps

Every developer learns one of the most important principles of software engineering early in their career: DRY (Don’t Repeat Yourself). Using third-party libraries can save you time as you do not need to develop the functionality that the library provides. Lowcoder provides some built-in third-party libraries for common uses, and you can manually import other libraries on demand.

Built-in libraries

Lowcoder provides some JavaScript built-in libraries for use.

Library
What for
Docs
Version

lodash

Powerful utility functions for Arrays, Collections, JS Functions, JS Objects, Strings, Numbers, Math, Sequences

4.17.21

uuid

9.0.0(Support v1/v3/v4/v5)

numbro

Powerful Number formatting helper

2.3.6

papaparse

Parser for CSV to JSON

5.3.2

Built-in Libraries can be used directly everywhere where you can use JavaScript.

// loadash
return _.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

// uuid
return uuid.v4();
// => 3965f3d4-8dd8-4785-9756-0ee98d91238d

// numbro
return numbro(1000).format({thousandSeparated: true});
// => 1,000

// Papaparse
return Papa.parse("name|age\nJohn Doe|30\nJane Doe|25", {delimiter: "|"})
// => {"data":[["name","age"],["John Doe","30"],["Jane Doe","25"]],"errors":[],"meta":{"delimiter":"|","linebreak":"\n","aborted":false,"truncated":false,"cursor":32}}

Import third-party libraries

Lowcoder supports setting up preloaded JavaScript and libraries, which can either be imported for individual apps or the whole workspace.

Only libraries using the UMD (Universal Module Definition) approach are supported.

As soon as imported/bound to an App or workspace, Lowcoder manages the pre-loading of these libraries automatically in the editor and app view.

  • App-level libraries get loaded only in the app where they were defined. This means a library imported to app A is not loaded for app B. The reverse is also true. A library imported for app B is not available to app A unless it is explicitly imported to app A as well.

  • Workspace-level libraries will be loaded when you open any application in your workspace. All apps can access (and will load automatically) those libraries.

importing third-party libraries can impact app performance, especially when you have complex JavaScript functions. Decide carefully to import on the App-level or on Workspace-level

Tips you should know before setting up libraries:

  • External libraries are loaded and run in the browser.

  • NodeJS-only libraries are not supported now.

  • URLs of external libraries need to support cross-domain.

  • The export of the library must be set directly on the window object, global variables like var xxx = xxx do not take effect.

  • The external libraries run in a restricted sandbox environment and the following global variables are not available:

    parent

    document

    location

    chrome

    setTimeout

    fetch

    setInterval

    clearInterval

    setImmediate

    XMLHttpRequest

    importScripts

    Navigator

    MutationObserver

Now let's take cowsay as an example and import it at the app level and the workspace level.

You can check popular CDNs if they host your desired library as a minified package.

https://jsdelivr.com

https://cdnjs.com

https://unpkg.com

Import / bind at the app level

Navigate to the settings page and then click the plus sign + under the JavaScript library tab. Paste the library link and click Add New. Lowcoder will now check, if the external library will be compatible and securely usable.

You can also click the download icon to quickly download any recommended JS library.

Now, you can create a JS query and insert code.


return window.cowsay.say({
    text : "Lowcoder is cool", e : "oO", T : "U "
})

Note that the cowsay library is imported in our example at app-level and you can not use it in any other app within your workspace.

You should see something similar to the image below after successfully importing the cowsay library. Note that you see what global variable you can use to access the library.

Imported external libraries are bound to the window object. cowsay.say(...) will not work window.cowsay.say(...) - does the job.

Import/bind at the workspace level

Go to Lowcoder's homepage, select Settings > Advanced, and click Add under the JavaScript library tab. Paste the link of the third-party JS library and click Add New to add it to your workspace. You can also click the download icon to add any recommended JS library quickly. The installed libraries are accessible from any app within your workspace.

Last updated

Logo

© Lowcoder Software LTD