A small library of functions for efficiently manipulating HTML.
This module contains the critical functions used by Moovweb projects to
transform the web. It provides the
fns object used to organize the DOM within
the Moovweb Node Environment. A version of moov_stdlib is required for MoovJS
projects to run, and the version to be used by a given project can be specified
in that project's package.json file.
Documentation examples will reference method calls as part of the
namespace, and any associated HTML input and output is explicitly specified in
the examples' comments.
After entering your project's directory, you can install your required dependencies locally with:
$ cp .npmrc.example .npmrc $ npm install
You will not need to instantiate the moov_stdlib module in your MoovJS projects directly; this is done at the sandbox level inside the Node server that will be running your project code. For running the module locally or in a terminal, a context object can be passed to the constructor to simulate the environment and headers of an incoming http request. See test/fixed_job.json for an example context file.
const moov_stdlib = require("moov_stdlib")(ctx);
This is currently done at the sandbox level and exposed as the
fns object when
running code on the Moovweb Cloud.
The following examples will refer to
fns, which is effectively an interface to
module.exports of the moov_stdlib module.
init$ exposes the global $ function, which can be used to select nodes from
the root scope, no matter where you are in your code. You'll generally want to
avoid this (since it signifies traversal from the root) - you should instead
An interface for adding and removing headers from the current request.
headers.header(key, val); headers.addHeader(key, val); headers.removeHeader(key);
Within your MoovJS project, stdlib methods are invoked using the
To run the test suite, enter the following command in your Terminal:
$ npm test
Run Locally via Node CLI
Optionally, to run this module from inside the node CLI on its own, you can require the main.js file explicitly via:
$ node --harmony ... > var moov_stdlib = require("./main.js");