Skip to content
mgh edited this page Jul 20, 2012 · 10 revisions

js.io, a module system for the client and browser

js.io is a package management and module system for JavaScript. js.io modules can be evaluated in a JavaScript runtime (e.g. node.js) or precompiled into a single package for use on the client side.

js.io provides the following:

  • A module system.
  • Dependency graph that works in the client and the browser.
  • Support and networking libraries that can be used on either platform.

See also:

Usage

js.io can be invoked as a compiler or a runtime.

To compile a js.io module, invoke from the command line:

jsio_compile module.path

Module system

import statements

Imports are preprocessed when the script is first compiled. Imports are located at the top of your scripts.

import path.module
import .relative.module

__imports__.js

Gets evaluated at compilation time to resolve dynamic imports. Any folder that contains a non-dynamic import is checked at compile time for an __imports__.js module, and, if found, the compiler runs the resolve function.

exports.resolve = function (env, opts) { ... };

resolve returns an array of imports (strings) to be compiled by the compiler. env is the environment passed into jsio_compile and opts contains the full compiler options.

Reference

The following packages are provided by default in js.io:

(top-level)

base

index

jsio

logging

net

lib

lib.Callback

lib.Enum

lib.Hash

lib.Iterator

lib.LogClass

lib.PubSub

lib.Sortable

lib.sort

net

net.buffer

net.env

net.errors

net.interfaces

net.later

net.protocols

net.protocols.buffered

net.protocols.Cuppa

net.protocols.delimited

net.protocols.echo

net.protocols.mspp

net.protocols.rtjp

net.protocols.stomp

net.scp

net.scp.client

net.scp.transports

std

std.JSON

std.XML

std.js

std.base64

std.uri

std.utf8

std.uuid

string

string.pad

string.timeAgo

util

util.Animation

util.ajax

util.browser

util.browser.$

  • $(string selector[, window]) — Selects an array of objects that match the given selector.

  • $(HTMLElement element) — Alias for $.remove(element).

  • $(object spec) — Alias for $.create(spec).

  • $(window window) — Alias for $.size(window).

  • $.id(string id[, window]) — Returns an element matching the given id.

  • $.id(HTMLElement element) — Identity function. Useful for accepting an id or element as an argument.

  • $.apply(HTMLElement element, object spec) — From the spec object, the following options can be applied:

    • id
    • style
    • src
    • class/className
    • parent/parentNode, and optionally first, before, after for its position
    • html
    • text
    • children
    • first
  • $.isElement(object element) — Returns true if the given object is an element.

  • $.insertBefore(HTMLElement parentNode, HTMLElement element[, HTMLElement nextSibling]) — Inserts an element, before an optional element.

  • $.insertAfter(HTMLElement parentNode, HTMLElement element[, HTMLElement previousSibling]) — Inserts an element, after an optional element.

  • $.create(object spec) — Creates an element of the tag name tag, then calls $.apply() on the element with the given spec.

  • $.show(HTMLElement element[, string display = "block"]) — Unhides an element, setting its display style to the optional display property.

  • $.hide(HTMLElement element) — Hides an element by setting its display property to none.

  • $.addClass(HTMLElement, (array classNames|string classNames)) — Sets a class or classes on an element.

  • $.getTag(HTMLElement ancestor, string tagName) — Gets all elements with the given tagName which descend from the ancestor.

  • $.removeClass(HTMLElement element, (array classNames|string classNames)) — Removes the classNames from the element.

  • $.style(HTMLElement element, object css) — Sets the style of the element according to the given css object.

  • $.onEvent(HTMLElement element, string name, function callback) — Attaches an event listener to the element for the given event. The this property of the callback will be assigned to the global context.

  • $.removeEvent(HTMLElement element, string name, function callback) — Removes an event listener from an element.

  • $.stopEvent(Event event) — Stops an event object from propagating or performing the default action in the document.

  • $.setText(HTMLElement element, string text) — Sets the text of the given element.

  • $.setValue(HTMLElement element, string value) — Sets the value of the given element or the first child of the element.

  • $.remove(HTMLElement element) — Removes the element from its parent node.

  • $.cursorPos(ClickEvent event, HTMLElement element) — Returns the cursor position relative to the origin coordinate of the page for the given click event.

  • $.pos(HTMLElement element) — Returns the offset of the element from the origin coordinate of the page.

  • $.size(HTMLElement element) — Returns an object with the dimensions of the element.

  • $.size(Window window) — Returns an object with the dimensions and position of the window relative to the document origin.

  • $.insertCSSFile(string url) — Inserts a new stylesheet to the page with the given URL.

util.browserdetect

util.formatNumber

util.jslint

util.jsonSchema

util.optparse

util.path

util.setProperty

util.sizzle

util.sprintf

util.syntax

util.underscore

util.wordWrap

License

MIT licensed.