1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 07:17:59 +01:00

Generally niftier :mkv

This commit is contained in:
Kris Maglione
2008-10-30 03:31:19 +00:00
parent bfe0530209
commit a53b702200
8 changed files with 155 additions and 123 deletions

View File

@@ -29,6 +29,15 @@ the terms of any one of the MPL, the GPL or the LGPL.
const util = { //{{{
Array: {
// [["a", "b"], ["c", "d"]] -> {a: "b", c: "d"}
// From Common Lisp, more or less
assocToObj: function (assoc)
{
let obj = {};
assoc.forEach(function ([k, v]) { obj[k] = v });
return obj;
},
// flatten an array: [["foo", "bar"], ["baz"]] -> ["foo", "bar", "baz"]
flatten: function (ary)
{
@@ -165,7 +174,7 @@ const util = { //{{{
{
if (delimiter == undefined)
delimiter = '"';
return delimiter + str.replace(/([\\'"])/g, "\\$1").replace("\n", "\\n").replace("\t", "\\t") + delimiter;
return delimiter + str.replace(/([\\'"])/g, "\\$1").replace("\n", "\\n", "g").replace("\t", "\\t", "g") + delimiter;
},
formatBytes: function (num, decimalPlaces, humanReadable)
@@ -254,6 +263,14 @@ const util = { //{{{
return ret;
},
map: function (obj, fn)
{
let ary = [];
for (let i in Iterator(obj))
ary.push(fn(i));
return ary;
},
// if color = true it uses HTML markup to color certain items
objectToString: function (object, color)
{