Scripting Helpers

Learn about available helper modules available in server-side JavaScript.

URL Parameters

Access URL query parameters via the '&' module. If your query parameter contains a dash (or any other incompatible identifier character), such as this-that, then import it with an underscore instead: this_that.


/* import all at a prefix */

import * as Params from '&';

/* or, individual parameters */

import {specific, param, here as Other} from '&';
            

Form Parameters

Access form parameters via the 'form' module. If your form parameter contains a dash (or any other incompatible identifier character), such as this-that, then import it with an underscore instead: this_that.


/* import all at a prefix */

import * as Form from 'form';

/* or, individual parameters */

import {specific, param, here as Other} from 'form';
            

Redirect

The Redirect object is already imported. The following examples show the available methods and their result.


Redirect.home(); // Result: /
Redirect.dir('accounts').dir(accountId); // Result: /accounts/1234/
Redirect.dir('accounts').dir(accountId).name('settings'); // Result: /accounts/1234/settings
Redirect.home().name('place').params({this:'that');  // Result: /place?this=that
        

Redirects may also be used as JSON values:


({redirect: Redirect.home().success('Going Home')});
        

Resulting in:


{"redirect": {"path":"/", "messages":[{"type":"success", "value": "Going Home"}]}
        

Messages

As convenience to using the Messages object directly, messages may "go with" the redirect being built. For example, after adding a new Article:


import {Article} from '📦';

let article = new Article().title('New');

Redirect.dir('articles')
        .dir(article.id)
        .success('New Article successfully created');
        

See Messages for more information.

Utilities

The utilities module is named 'util' and exports the following objects and methods. All utilities are safe and efficient to use during any HTTP method.

Encoding


import {Encoding} from 'util';

Encoding.base64Url().encode('string');
Encoding.base64Url().encodeNum(1234);
Encoding.html().escape('<p>html</p>');