refactor: move helpers around.

This commit is contained in:
Christopher Jeffrey 2015-05-01 00:27:33 -07:00
parent 797d8de45f
commit 8eb57e919e
1 changed files with 106 additions and 97 deletions

View File

@ -8853,105 +8853,9 @@ Image.prototype.displayImage = function(callback) {
};
/**
* Helpers
* Angles
*/
function generateTags(style, text) {
var open = ''
, close = '';
Object.keys(style || {}).forEach(function(key) {
var val = style[key];
if (typeof val === 'string') {
val = val.replace(/^light(?!-)/, 'light-');
open = '{' + val + '-' + key + '}' + open;
close += '{/' + val + '-' + key + '}';
} else {
if (val === true) {
open = '{' + key + '}' + open;
close += '{/' + key + '}';
}
}
});
if (text != null) {
return open + text + close;
}
return {
open: open,
close: close
};
}
function merge(a, b) {
Object.keys(b).forEach(function(key) {
a[key] = b[key];
});
return a;
}
function asort(obj) {
return obj.sort(function(a, b) {
a = a.name.toLowerCase();
b = b.name.toLowerCase();
if (a[0] === '.' && b[0] === '.') {
a = a[1];
b = b[1];
} else {
a = a[0];
b = b[0];
}
return a > b ? 1 : (a < b ? -1 : 0);
});
}
function hsort(obj) {
return obj.sort(function(a, b) {
return b.index - a.index;
});
}
function findFile(start, target) {
return (function read(dir) {
var files, file, stat, out;
if (dir === '/dev' || dir === '/sys'
|| dir === '/proc' || dir === '/net') {
return null;
}
try {
files = fs.readdirSync(dir);
} catch (e) {
files = [];
}
for (var i = 0; i < files.length; i++) {
file = files[i];
if (file === target) {
return (dir === '/' ? '' : dir) + '/' + file;
}
try {
stat = fs.lstatSync((dir === '/' ? '' : dir) + '/' + file);
} catch (e) {
stat = null;
}
if (stat && stat.isDirectory() && !stat.isSymbolicLink()) {
out = read((dir === '/' ? '' : dir) + '/' + file);
if (out) return out;
}
}
return null;
})(start);
}
var angles = {
'\u2518': true, // '┘'
'\u2510': true, // '┐'
@ -9061,6 +8965,10 @@ function getAngle(lines, x, y) {
return angleTable[angle] || ch;
}
/**
* Blending and Shadows
*/
function blend(attr, attr2) {
var bg = attr & 0x1ff;
if (attr2 != null) {
@ -9141,6 +9049,107 @@ function blend(attr, attr2) {
blend._cache = {};
/**
* Helpers
*/
function generateTags(style, text) {
var open = ''
, close = '';
Object.keys(style || {}).forEach(function(key) {
var val = style[key];
if (typeof val === 'string') {
val = val.replace(/^light(?!-)/, 'light-');
open = '{' + val + '-' + key + '}' + open;
close += '{/' + val + '-' + key + '}';
} else {
if (val === true) {
open = '{' + key + '}' + open;
close += '{/' + key + '}';
}
}
});
if (text != null) {
return open + text + close;
}
return {
open: open,
close: close
};
}
function merge(a, b) {
Object.keys(b).forEach(function(key) {
a[key] = b[key];
});
return a;
}
function asort(obj) {
return obj.sort(function(a, b) {
a = a.name.toLowerCase();
b = b.name.toLowerCase();
if (a[0] === '.' && b[0] === '.') {
a = a[1];
b = b[1];
} else {
a = a[0];
b = b[0];
}
return a > b ? 1 : (a < b ? -1 : 0);
});
}
function hsort(obj) {
return obj.sort(function(a, b) {
return b.index - a.index;
});
}
function findFile(start, target) {
return (function read(dir) {
var files, file, stat, out;
if (dir === '/dev' || dir === '/sys'
|| dir === '/proc' || dir === '/net') {
return null;
}
try {
files = fs.readdirSync(dir);
} catch (e) {
files = [];
}
for (var i = 0; i < files.length; i++) {
file = files[i];
if (file === target) {
return (dir === '/' ? '' : dir) + '/' + file;
}
try {
stat = fs.lstatSync((dir === '/' ? '' : dir) + '/' + file);
} catch (e) {
stat = null;
}
if (stat && stat.isDirectory() && !stat.isSymbolicLink()) {
out = read((dir === '/' ? '' : dir) + '/' + file);
if (out) return out;
}
}
return null;
})(start);
}
/**
* Helpers
*/