This app contains a set of independent libraries that offer various extended functionality that are useful and not trivial to replicate.
Adds useful functions to the existing Javascript standard APIs, such as:
str.trim() - returns a string without leading and ending whitespacestr.strip() - same as str.trim()str.startsWith(s) - returns True if str starts with sstr.endsWith(s) - returns True if str ends with sstr.contains(s) - returns True if str contains sstr.partition(s) - returns an array of 3 strings [before,s,after], using the first occurrence of s in strstr.partition(s) - returns an array of 3 strings [before,s,after], using the last occurrence of s in strHere is how to use it:
acre.require("/freebase/apps/libraries/api_enhancer");
var s = " blah ";
s = s.trim();
// s now is "blah"
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
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>"
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
});
Adds useful functions to the acre.freebase APIs:
acre.freebase.reconcile(query, options) - calls the experimental Freebase reconciliation serviceHere is how to use it:
acre.require("/freebase/apps/libraries/freebase_api_enhancer");
var query = { ... };
var result = acre.freebase.reconcile(q);
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.
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.
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.
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.