This app contains a set of independent libraries that offer various extended functionality that are useful and not trivial to replicate.

Javascript API Enhancer

Adds useful functions to the existing Javascript standard APIs, such as:

String

Here is how to use it:

acre.require("/freebase/apps/libraries/api_enhancer");
var s = " blah ";
s = s.trim();
// s now is "blah"

Deep Copy

Adds a deep-copy function to the Acre APIs to allow to obtain an exactly copy of a javascript object.

Here is how to use it:

acre.require("/freebase/apps/libraries/deepcopy");
var obj1 = [{
  "foo" : [ 1 , 2 , { a : "b" } ],
  "bar" : {}
}];
var obj2 = acre.deepcopy(obj1);
// now obj2 is an exact copy of obj2 but are two different objects

DOM Element Serializer

Contains a function that serializes a DOM element (and all its content) to its XML string representation.

Here is how to use it:

var dom = acre.xml.parse("<a><b><c/></b></a>");
var serialize = acre.require("/freebase/apps/libraries/xml_tostring").elementToString;
var str = serialize(dom.documentElement.firstChild);
// 'str' is now "<b><c/></b>"

Graph Switching Freebase API Enhancer

Enables the ability to have scripts running on freebase.com to read/write against sandbox-freebase.com

Here is how to use it:

acre.require("/freebase/apps/libraries/run_on_api_extender");
acre.freebase.run_on("http://sandbox-freebase.com", function() { 
  acre.freebase.mqlread(...); // this will work against sandbox now
});

Freebase API Enhancer

Adds useful functions to the acre.freebase APIs:

Here is how to use it:

acre.require("/freebase/apps/libraries/freebase_api_enhancer");
var query = { ... };
var result = acre.freebase.reconcile(q);

DateJS

An open source javascript library that provides advanced data manipulation capabilities.

var Date = acre.require("/freebase/apps/libraries/date").Date;
var date = Date.parse("August 26, 1998");
var str = date.toString("yyyy-MM-dd");
// str will be "1998-08-26"

See its own documentation for more.

Rison

Encode and decode JSON objects in URI-compatible strings.

var rison = acre.require("/freebase/apps/libraries/rison").rison;
var obj = { 'a' : 'b' };
var str = rison.encode(obj);
var url = "http://blah.com?data=" + str;
// do something with the URL
var obj2 = rison.decode(str);
// obj2 is a copy of obj1

See the documentation for more.

JSONPath

An open source javascript library that provides the ability to select parts of a javascript object using an XPath-like language.

var jsonPath = acre.require("/freebase/apps/libraries/json_path").jsonPath;
var o = { /*...*/ },  // whatever js object you want to select data from
var result = jsonPath(o, "$..author").toJSONString(); // select all 'author' parts

See its own documentation for more.

Showdown

An open source javascript library that provides the ability to render Markdown wikitext as HTML.

var Showdown = acre.require("/freebase/apps/libraries/showdown").Showdown;
var text = "Markdown *rocks*.";
var converter = new Showdown.converter();
var html = converter.makeHtml(text);

See the Markdown documentation for more.