neo-neo-bblessed
Version:
A fork of neo-blessed (which is a fork of blessed) with bug fixes and maintenance.
3 lines (2 loc) • 1.92 kB
JavaScript
const g=require("fs"),u=require("./unicode"),t={};t.merge=function(e,i){return Object.keys(i).forEach(function(s){e[s]=i[s]}),e},t.asort=function(e){return e.sort(function(i,s){let n=i.name.toLowerCase(),r=s.name.toLowerCase();return n[0]==="."&&r[0]==="."?(n=n[1],r=r[1]):(n=n[0],r=r[0]),n>r?1:n<r?-1:0})},t.hsort=function(e){return e.sort(function(i,s){return s.index-i.index})},t.findFile=function(e,i){return function s(n){let r,a,l,o;if(n==="/dev"||n==="/sys"||n==="/proc"||n==="/net")return null;try{r=g.readdirSync(n)}catch(c){r=[]}for(let c=0;c<r.length;c++){if(a=r[c],a===i)return(n==="/"?"":n)+"/"+a;try{l=g.lstatSync((n==="/"?"":n)+"/"+a)}catch(f){l=null}if(l&&l.isDirectory()&&!l.isSymbolicLink()&&(o=s((n==="/"?"":n)+"/"+a),o))return o}return null}(e)},t.escape=function(e){return e.replace(/[{}]/g,function(i){return i==="{"?"{open}":"{close}"})},t.parseTags=function(e,i){return t.Element.prototype._parseTags.call({parseTags:!0,screen:i||t.Screen.global},e)},t.generateTags=function(e,i){let s="",n="";return Object.keys(e||{}).forEach(function(r){let a=e[r];typeof a=="string"?(a=a.replace(/^light(?!-)/,"light-"),a=a.replace(/^bright(?!-)/,"bright-"),s="{"+a+"-"+r+"}"+s,n+="{/"+a+"-"+r+"}"):a===!0&&(s="{"+r+"}"+s,n+="{/"+r+"}")}),i!=null?s+i+n:{open:s,close:n}},t.attrToBinary=function(e,i){return t.Element.prototype.sattr.call(i||{},e)},t.stripTags=function(e){return e?e.replace(/{(\/?)([\w\-,;!#]*)}/g,"").replace(/\x1b\[[\d;]*m/g,""):""},t.cleanTags=function(e){return t.stripTags(e).trim()},t.dropUnicode=function(e){return e?e.replace(u.chars.all,"??").replace(u.chars.combining,"").replace(u.chars.surrogate,"?"):""},t.__defineGetter__("Screen",function(){return t._screen||(t._screen=require("./widgets/screen")),t._screen}),t.__defineGetter__("Element",function(){return t._element||(t._element=require("./widgets/element")),t._element}),module.exports=t;
//# sourceMappingURL=helpers.js.map