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 Data object to that includes data-related utility functions.
This is modeled after the functions with the same name provided by the Protovis
library (see their documentation for more info).
Data.map(array, f,o) - Returns a new array with the results of calling a provided function on every element of the given arrayData.reduce(array, f, v) - Apply a function against an accumulator and each value of the given array (from left-to-right) as to reduce it to a single valueData.range(start, stop, step) - Returns an array of numbers, starting at start, incrementing by step, until stop is reachedData.cross(a, b) - Given two arrays a and b, returns an array of all possible pairs of elements [ai, bj]Data.keys(map) - Returns all of the property names (keys) of the specified object (a map). The order of the returned array is not definedData.entries(map) - Returns all of the entries (key-value pairs) of the specified object (a map). The order of the returned array is not definedData.values(map) - Returns all of the values (attribute values) of the specified object (a map). The order of the returned array is not definedData.dict(keys, f) - Returns a map constructed from the specified keys, using the function f to compute the value for each keyData.uniq(array, f) - Returns the unique elements in the specified array, in the order they appearData.uniq_counts(array) - Return a map of the unique values of an array and their respective countsData.permute(array, indexes, f) - Returns a permutation of the specified array, using the specified array of indexesData.numerate(keys, f) - Returns a map from key to index for the specified keys arrayData.size(obj) - Return the size of the argument, either an array or an objectData.sum(array, f) - Returns the sum of the specified array.Data.max(array, f) - Returns the maximum value of the specified arrayData.max.index(array, f) - Returns the index of the maximum value of the specified arrayData.min(array, f) - Returns the minimum value of the specified array of numbersData.min.index(array, f) - Returns the index of the minimum value of the specified arrayData.mean(array, f) - Returns the arithmetic mean, or average, of the specified arrayData.median(array, f) - Returns the median of the specified arrayData.variance(array, f) - Returns the unweighted variance of the specified arrayData.deviation(array, f) - Returns an unbiased estimation of the standard deviation of a population, given the specified random sampleHere is how to use it:
acre.require("/freebase/apps/libraries/collections");
var array = [ 0 , 1 , 2 ];
var min = Data.min(array);
// min is 0
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.