Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including lively.lang with all npm packages installed. Try it out:

var livelyLang = require("lively.lang")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

lively.lang v1.0.25

JavaScript utils providing useful abstractions for working with collections, functions, objects.

lively.lang Build Status

What? This project packages abstractions for JavaScript that proved to be useful in the Lively Web project. On first glance it might seem to be just another underscore.js library but apart from extensions to existing JavaScript objects and classes it also provides abstractions for asynchronous code, new object representations, and functions for inspecting JavaScript objects.

Why? Make it easy to reuse abstractions we found helpful in all kinds of contexts. All features can be used in browser environments and in node.js. Actually, one motivation for this library was to have unified interfaces across JavaScript environments.

How? By default the library is non-invasive, i.e. no global objects are modified. To use provided functions you can either

  1. call them directly,
  2. use underscore.js-like chain/value wrapping,
  3. or install extension methods explicitly in global objects.


Utility functions for default JavaScript objects:

  • Array
  • String
  • Number
  • Object
  • Function
  • Date

Abstractions usually not included by default in JavaScript runtimes:

  • node.js-like event emitter interface (uses event module on node.js)
  • Path (deep property access)
  • Interval
  • Grid
  • Tree
  • array projection
  • Closure
  • Messengers (generic interface for remote-messaging)
  • Workers based on messengers

Please see the individual doc files for detailed information.


String utility methods for printing, parsing, and converting strings.


  • Utility functions for JS Numbers.


  • Utility functions that help to inspect, enumerate, and create JS objects


-=-=-=-=-=-=-=-=-=-=-=-=-=- js object path accessor -=-=-=-=-=-=-=-=-=-=-=-=-=-


  • Methods to make working with arrays more convenient and collection-like
  • abstractions for groups, intervals, grids.


Accessor to sub-ranges of arrays. This is used, for example, for rendering large lists or tables in which only a part of the items should be used for processing or rendering. An array projection provides convenient access and can apply operations to sub-ranges.


A Grouping is created by arr.groupBy and maps keys to Arrays.


Computation over graphs. Unless otherwise specified a graph is a simple JS object whose properties are interpreted as nodes that refer to arrays whose elements describe edges. Example:

var testGraph = {
  "a": ["b", "c"],
  "b": ["c", "d", "e", "f"],
  "d": ["c", "f"],
  "e": ["a", "f"],
  "f": []


A grid is a two-dimaensional array, representing a table-like data


Intervals are arrays whose first two elements are numbers and the first element should be less or equal the second element, see interval.isInterval. This abstraction is useful when working with text ranges in rich text, for example.


  • Methods for traversing and transforming tree structures.


  • Abstractions around first class functions like augmenting and inspecting
  • functions as well as to control function calls like dealing with asynchronous
  • control flows.


A Closure is a representation of a JavaScript function that controls what values are bound to out-of-scope variables. By default JavaScript has no reflection capabilities over closed values in functions. When needing to serialize execution or when behavior should become part of the state of a system it is often necessary to have first-class control over this language aspect.

Typically closures aren't created directly but with the help of asScriptOf

Example: function func(a) { return a + b; } var closureFunc = Closure.fromFunction(func, {b: 3}).recreateFunc(); closureFunc(4) // => 7 var closure = closureFunc.livelyClosure // => { // varMapping: { b: 3 }, // originalFunc: function func(a) {/.../} // } closure.lookup("b") // => 3 closure.getFuncSource() // => "function func(a) { return a + b; }"


  • Methods helping with promises (Promise/A+ model). Not a promise shim.


  • Util functions to print and work with JS date objects.


  • A pluggable interface to provide asynchronous, actor-like message
  • communication between JavaScript systems. Provides a unified message protocol
  • and send / receive methods.


  • A simple node.js-like cross-platform event emitter implementation that can
  • be used as a mixin. Emitters support the methods: on(eventName, handlerFunc),
  • once(eventName, handlerFunc), emit(eventName, eventData),
  • removeListener(eventName, handlerFunc), removeAllListeners(eventName)
  • Example:
  • var emitter = events.makeEmitter({});
  • var log = [];
  • emitter.on("test", function() { log.push("listener1"); });
  • emitter.once("test", function() { log.push("listener2"); });
  • emitter.emit("test");
  • emitter.emit("test");
  • log // => ["listener1","listener2","listener1"]
  • emitter.removeAllListeners("test");
  • emitter.emit("test");
  • log // => is still ["listener1","listener2","listener1"]


  • A platform-independent worker interface that will spawn new processes per
  • worker (if the platform you use it on supports it).
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free