id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
46,200 | sergeyt/fetch-stream | lib/parser.js | makeDecoder | function makeDecoder(chunkType) {
if (chunkType === BUFFER) {
return function (buf) {
return buf.toString('utf8');
};
}
if (isnode) {
return function (a) {
return new Buffer(a).toString('utf8');
};
}
var decoder = null;
return function (buf) {
if (!decoder) {
decoder = new TextDecoder();
}
return decoder.decode(buf);
};
} | javascript | function makeDecoder(chunkType) {
if (chunkType === BUFFER) {
return function (buf) {
return buf.toString('utf8');
};
}
if (isnode) {
return function (a) {
return new Buffer(a).toString('utf8');
};
}
var decoder = null;
return function (buf) {
if (!decoder) {
decoder = new TextDecoder();
}
return decoder.decode(buf);
};
} | [
"function",
"makeDecoder",
"(",
"chunkType",
")",
"{",
"if",
"(",
"chunkType",
"===",
"BUFFER",
")",
"{",
"return",
"function",
"(",
"buf",
")",
"{",
"return",
"buf",
".",
"toString",
"(",
"'utf8'",
")",
";",
"}",
";",
"}",
"if",
"(",
"isnode",
")",
"{",
"return",
"function",
"(",
"a",
")",
"{",
"return",
"new",
"Buffer",
"(",
"a",
")",
".",
"toString",
"(",
"'utf8'",
")",
";",
"}",
";",
"}",
"var",
"decoder",
"=",
"null",
";",
"return",
"function",
"(",
"buf",
")",
"{",
"if",
"(",
"!",
"decoder",
")",
"{",
"decoder",
"=",
"new",
"TextDecoder",
"(",
")",
";",
"}",
"return",
"decoder",
".",
"decode",
"(",
"buf",
")",
";",
"}",
";",
"}"
]
| Makes UTF8 decoding function.
@param {Boolean} [chunkType] Specifies type of input chunks.
@return {Function} The function to decode byte chunks. | [
"Makes",
"UTF8",
"decoding",
"function",
"."
]
| eab91c059ce3b1d172fd44890769c761bb4b7aa3 | https://github.com/sergeyt/fetch-stream/blob/eab91c059ce3b1d172fd44890769c761bb4b7aa3/lib/parser.js#L32-L50 |
46,201 | LittleHelicase/frequencyjs | lib/processing.js | function(signal1, signal2, options){
options = options || {};
options = _.defaults(options, defaultOptions);
// ensure signal2 is not longer than signal2
if(signal1.length < signal2.length){
var tmp = signal1;
signal1 = signal2;
signal2 = tmp;
}
if(options.method == "cauchy"){
return cauchy(signal1,signal2,options);
} else {
return specConvolution(signal1, signal2,options);
}
} | javascript | function(signal1, signal2, options){
options = options || {};
options = _.defaults(options, defaultOptions);
// ensure signal2 is not longer than signal2
if(signal1.length < signal2.length){
var tmp = signal1;
signal1 = signal2;
signal2 = tmp;
}
if(options.method == "cauchy"){
return cauchy(signal1,signal2,options);
} else {
return specConvolution(signal1, signal2,options);
}
} | [
"function",
"(",
"signal1",
",",
"signal2",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
"=",
"_",
".",
"defaults",
"(",
"options",
",",
"defaultOptions",
")",
";",
"// ensure signal2 is not longer than signal2",
"if",
"(",
"signal1",
".",
"length",
"<",
"signal2",
".",
"length",
")",
"{",
"var",
"tmp",
"=",
"signal1",
";",
"signal1",
"=",
"signal2",
";",
"signal2",
"=",
"tmp",
";",
"}",
"if",
"(",
"options",
".",
"method",
"==",
"\"cauchy\"",
")",
"{",
"return",
"cauchy",
"(",
"signal1",
",",
"signal2",
",",
"options",
")",
";",
"}",
"else",
"{",
"return",
"specConvolution",
"(",
"signal1",
",",
"signal2",
",",
"options",
")",
";",
"}",
"}"
]
| the convolution function assumes two discrete signals
that have the same spacing | [
"the",
"convolution",
"function",
"assumes",
"two",
"discrete",
"signals",
"that",
"have",
"the",
"same",
"spacing"
]
| a3cf163ddfe77888ddefde77417f2ea192c05cc8 | https://github.com/LittleHelicase/frequencyjs/blob/a3cf163ddfe77888ddefde77417f2ea192c05cc8/lib/processing.js#L24-L40 |
|
46,202 | LittleHelicase/frequencyjs | lib/processing.js | function(signal1, signal2, options){
options = options || {};
options.epsilon = options.epsilon || 1E-08;
var sig1 = Signal(signal1);
var sig2 = Signal(signal2);
if(signal1.length != signal2.length) return false;
var diffSQ = _.reduce(_.range(signal1.length), function(d,idx){
var diff = (sig1[idx].value-sig2[idx].value);
return d + diff * diff;
},0);
return diffSQ/signal1.length < options.epsilon;
} | javascript | function(signal1, signal2, options){
options = options || {};
options.epsilon = options.epsilon || 1E-08;
var sig1 = Signal(signal1);
var sig2 = Signal(signal2);
if(signal1.length != signal2.length) return false;
var diffSQ = _.reduce(_.range(signal1.length), function(d,idx){
var diff = (sig1[idx].value-sig2[idx].value);
return d + diff * diff;
},0);
return diffSQ/signal1.length < options.epsilon;
} | [
"function",
"(",
"signal1",
",",
"signal2",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"epsilon",
"=",
"options",
".",
"epsilon",
"||",
"1E-08",
";",
"var",
"sig1",
"=",
"Signal",
"(",
"signal1",
")",
";",
"var",
"sig2",
"=",
"Signal",
"(",
"signal2",
")",
";",
"if",
"(",
"signal1",
".",
"length",
"!=",
"signal2",
".",
"length",
")",
"return",
"false",
";",
"var",
"diffSQ",
"=",
"_",
".",
"reduce",
"(",
"_",
".",
"range",
"(",
"signal1",
".",
"length",
")",
",",
"function",
"(",
"d",
",",
"idx",
")",
"{",
"var",
"diff",
"=",
"(",
"sig1",
"[",
"idx",
"]",
".",
"value",
"-",
"sig2",
"[",
"idx",
"]",
".",
"value",
")",
";",
"return",
"d",
"+",
"diff",
"*",
"diff",
";",
"}",
",",
"0",
")",
";",
"return",
"diffSQ",
"/",
"signal1",
".",
"length",
"<",
"options",
".",
"epsilon",
";",
"}"
]
| determines if two signals can be considered equal. | [
"determines",
"if",
"two",
"signals",
"can",
"be",
"considered",
"equal",
"."
]
| a3cf163ddfe77888ddefde77417f2ea192c05cc8 | https://github.com/LittleHelicase/frequencyjs/blob/a3cf163ddfe77888ddefde77417f2ea192c05cc8/lib/processing.js#L43-L54 |
|
46,203 | hectorcorrea/mongoConnect | index.js | function(callback) {
log('Connecting...');
MongoClient.connect(dbUrl, dbOptions, function(err, dbConn) {
if(err) {
log('Cannot connect: ' + err);
callback(err);
return;
}
log('Connected!');
isConnected = true;
db = dbConn;
// http://stackoverflow.com/a/18715857/446681
db.on('close', function() {
log('Connection was closed!!!');
isConnected = false;
});
log('Executing...');
callback(null, db);
});
} | javascript | function(callback) {
log('Connecting...');
MongoClient.connect(dbUrl, dbOptions, function(err, dbConn) {
if(err) {
log('Cannot connect: ' + err);
callback(err);
return;
}
log('Connected!');
isConnected = true;
db = dbConn;
// http://stackoverflow.com/a/18715857/446681
db.on('close', function() {
log('Connection was closed!!!');
isConnected = false;
});
log('Executing...');
callback(null, db);
});
} | [
"function",
"(",
"callback",
")",
"{",
"log",
"(",
"'Connecting...'",
")",
";",
"MongoClient",
".",
"connect",
"(",
"dbUrl",
",",
"dbOptions",
",",
"function",
"(",
"err",
",",
"dbConn",
")",
"{",
"if",
"(",
"err",
")",
"{",
"log",
"(",
"'Cannot connect: '",
"+",
"err",
")",
";",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"log",
"(",
"'Connected!'",
")",
";",
"isConnected",
"=",
"true",
";",
"db",
"=",
"dbConn",
";",
"// http://stackoverflow.com/a/18715857/446681",
"db",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"log",
"(",
"'Connection was closed!!!'",
")",
";",
"isConnected",
"=",
"false",
";",
"}",
")",
";",
"log",
"(",
"'Executing...'",
")",
";",
"callback",
"(",
"null",
",",
"db",
")",
";",
"}",
")",
";",
"}"
]
| by default don't log | [
"by",
"default",
"don",
"t",
"log"
]
| e96310f2910d27d3f813d4d0249d47a8456167ac | https://github.com/hectorcorrea/mongoConnect/blob/e96310f2910d27d3f813d4d0249d47a8456167ac/index.js#L23-L49 |
|
46,204 | jimbojw/node-red-contrib-json | util.js | function(node, msg) {
if (node.complete === "complete") {
return msg;
}
try {
return (node.prop||"payload").split(".").reduce(function (obj, i) {
return obj[i];
}, msg);
} catch (err) {
return; // undefined
}
} | javascript | function(node, msg) {
if (node.complete === "complete") {
return msg;
}
try {
return (node.prop||"payload").split(".").reduce(function (obj, i) {
return obj[i];
}, msg);
} catch (err) {
return; // undefined
}
} | [
"function",
"(",
"node",
",",
"msg",
")",
"{",
"if",
"(",
"node",
".",
"complete",
"===",
"\"complete\"",
")",
"{",
"return",
"msg",
";",
"}",
"try",
"{",
"return",
"(",
"node",
".",
"prop",
"||",
"\"payload\"",
")",
".",
"split",
"(",
"\".\"",
")",
".",
"reduce",
"(",
"function",
"(",
"obj",
",",
"i",
")",
"{",
"return",
"obj",
"[",
"i",
"]",
";",
"}",
",",
"msg",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"return",
";",
"// undefined",
"}",
"}"
]
| given a node and a message, extract the incoming object | [
"given",
"a",
"node",
"and",
"a",
"message",
"extract",
"the",
"incoming",
"object"
]
| 2097e296d4024802d24344d83305886fb1f322ed | https://github.com/jimbojw/node-red-contrib-json/blob/2097e296d4024802d24344d83305886fb1f322ed/util.js#L21-L32 |
|
46,205 | cognitom/riot-mixin-pack | dist/riot-mixin-pack.amd.js | hook | function hook(p, key) {
var h = function h(e) {
// update only when the argument is an Event object
if (e && e instanceof Event) {
// suppress updating on the inherit tag
e.preventUpdate = true;
// call original method
p[key](e);
// update automatically
p.update();
} else {
p[key](e);
}
};
h._inherited = true;
return h;
} | javascript | function hook(p, key) {
var h = function h(e) {
// update only when the argument is an Event object
if (e && e instanceof Event) {
// suppress updating on the inherit tag
e.preventUpdate = true;
// call original method
p[key](e);
// update automatically
p.update();
} else {
p[key](e);
}
};
h._inherited = true;
return h;
} | [
"function",
"hook",
"(",
"p",
",",
"key",
")",
"{",
"var",
"h",
"=",
"function",
"h",
"(",
"e",
")",
"{",
"// update only when the argument is an Event object",
"if",
"(",
"e",
"&&",
"e",
"instanceof",
"Event",
")",
"{",
"// suppress updating on the inherit tag",
"e",
".",
"preventUpdate",
"=",
"true",
";",
"// call original method",
"p",
"[",
"key",
"]",
"(",
"e",
")",
";",
"// update automatically",
"p",
".",
"update",
"(",
")",
";",
"}",
"else",
"{",
"p",
"[",
"key",
"]",
"(",
"e",
")",
";",
"}",
"}",
";",
"h",
".",
"_inherited",
"=",
"true",
";",
"return",
"h",
";",
"}"
]
| Call original method and update automatically | [
"Call",
"original",
"method",
"and",
"update",
"automatically"
]
| 903da842cccbccb853dc0c4f952145af35416c17 | https://github.com/cognitom/riot-mixin-pack/blob/903da842cccbccb853dc0c4f952145af35416c17/dist/riot-mixin-pack.amd.js#L56-L72 |
46,206 | cognitom/riot-mixin-pack | dist/riot-mixin-pack.amd.js | init | function init() {
var _this = this;
/** Store the keys originally belonging to the tag */
this.one('update', function () {
_this._ownPropKeys = getAllPropertyNames(_this);
_this._ownOptsKeys = getAllPropertyNames(_this.opts);
});
/** Inherit the properties from parents on each update */
this.on('update', function () {
var ignoreProps = ['root', 'triggerDomEvent'];
getAllPropertyNames(_this.parent)
// TODO:
// Skipping 'triggerDomEvent' is a temporal workaround.
// In some cases function on the child would be overriden.
// This issue needs more study...
.filter(function (key) {
return ! ~_this._ownPropKeys.concat(ignoreProps).indexOf(key);
}).forEach(function (key) {
_this[key] = typeof _this.parent[key] != 'function' || _this.parent[key]._inherited ? _this.parent[key] : hook(_this.parent, key);
});
getAllPropertyNames(_this.parent.opts).filter(function (key) {
return ! ~_this._ownOptsKeys.indexOf(key) && key != 'riotTag';
}).forEach(function (key) {
_this.opts[key] = typeof _this.parent.opts[key] != 'function' || _this.parent.opts[key]._inherited ? _this.parent.opts[key] : hook(_this.parent, key);
});
});
} | javascript | function init() {
var _this = this;
/** Store the keys originally belonging to the tag */
this.one('update', function () {
_this._ownPropKeys = getAllPropertyNames(_this);
_this._ownOptsKeys = getAllPropertyNames(_this.opts);
});
/** Inherit the properties from parents on each update */
this.on('update', function () {
var ignoreProps = ['root', 'triggerDomEvent'];
getAllPropertyNames(_this.parent)
// TODO:
// Skipping 'triggerDomEvent' is a temporal workaround.
// In some cases function on the child would be overriden.
// This issue needs more study...
.filter(function (key) {
return ! ~_this._ownPropKeys.concat(ignoreProps).indexOf(key);
}).forEach(function (key) {
_this[key] = typeof _this.parent[key] != 'function' || _this.parent[key]._inherited ? _this.parent[key] : hook(_this.parent, key);
});
getAllPropertyNames(_this.parent.opts).filter(function (key) {
return ! ~_this._ownOptsKeys.indexOf(key) && key != 'riotTag';
}).forEach(function (key) {
_this.opts[key] = typeof _this.parent.opts[key] != 'function' || _this.parent.opts[key]._inherited ? _this.parent.opts[key] : hook(_this.parent, key);
});
});
} | [
"function",
"init",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"/** Store the keys originally belonging to the tag */",
"this",
".",
"one",
"(",
"'update'",
",",
"function",
"(",
")",
"{",
"_this",
".",
"_ownPropKeys",
"=",
"getAllPropertyNames",
"(",
"_this",
")",
";",
"_this",
".",
"_ownOptsKeys",
"=",
"getAllPropertyNames",
"(",
"_this",
".",
"opts",
")",
";",
"}",
")",
";",
"/** Inherit the properties from parents on each update */",
"this",
".",
"on",
"(",
"'update'",
",",
"function",
"(",
")",
"{",
"var",
"ignoreProps",
"=",
"[",
"'root'",
",",
"'triggerDomEvent'",
"]",
";",
"getAllPropertyNames",
"(",
"_this",
".",
"parent",
")",
"// TODO:",
"// Skipping 'triggerDomEvent' is a temporal workaround.",
"// In some cases function on the child would be overriden.",
"// This issue needs more study...",
".",
"filter",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"!",
"~",
"_this",
".",
"_ownPropKeys",
".",
"concat",
"(",
"ignoreProps",
")",
".",
"indexOf",
"(",
"key",
")",
";",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"_this",
"[",
"key",
"]",
"=",
"typeof",
"_this",
".",
"parent",
"[",
"key",
"]",
"!=",
"'function'",
"||",
"_this",
".",
"parent",
"[",
"key",
"]",
".",
"_inherited",
"?",
"_this",
".",
"parent",
"[",
"key",
"]",
":",
"hook",
"(",
"_this",
".",
"parent",
",",
"key",
")",
";",
"}",
")",
";",
"getAllPropertyNames",
"(",
"_this",
".",
"parent",
".",
"opts",
")",
".",
"filter",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"!",
"~",
"_this",
".",
"_ownOptsKeys",
".",
"indexOf",
"(",
"key",
")",
"&&",
"key",
"!=",
"'riotTag'",
";",
"}",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"_this",
".",
"opts",
"[",
"key",
"]",
"=",
"typeof",
"_this",
".",
"parent",
".",
"opts",
"[",
"key",
"]",
"!=",
"'function'",
"||",
"_this",
".",
"parent",
".",
"opts",
"[",
"key",
"]",
".",
"_inherited",
"?",
"_this",
".",
"parent",
".",
"opts",
"[",
"key",
"]",
":",
"hook",
"(",
"_this",
".",
"parent",
",",
"key",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Inject properties from parents | [
"Inject",
"properties",
"from",
"parents"
]
| 903da842cccbccb853dc0c4f952145af35416c17 | https://github.com/cognitom/riot-mixin-pack/blob/903da842cccbccb853dc0c4f952145af35416c17/dist/riot-mixin-pack.amd.js#L78-L105 |
46,207 | cognitom/riot-mixin-pack | dist/riot-mixin-pack.amd.js | querySelector | function querySelector(sel, flag) {
var node = this.root.querySelector(normalize(sel));
return !flag ? node : node._tag || undefined;
} | javascript | function querySelector(sel, flag) {
var node = this.root.querySelector(normalize(sel));
return !flag ? node : node._tag || undefined;
} | [
"function",
"querySelector",
"(",
"sel",
",",
"flag",
")",
"{",
"var",
"node",
"=",
"this",
".",
"root",
".",
"querySelector",
"(",
"normalize",
"(",
"sel",
")",
")",
";",
"return",
"!",
"flag",
"?",
"node",
":",
"node",
".",
"_tag",
"||",
"undefined",
";",
"}"
]
| Gets Node or Tag by CSS selector
@param { string } sel - CSS selector
@param { boolean } flag - true for Tag | [
"Gets",
"Node",
"or",
"Tag",
"by",
"CSS",
"selector"
]
| 903da842cccbccb853dc0c4f952145af35416c17 | https://github.com/cognitom/riot-mixin-pack/blob/903da842cccbccb853dc0c4f952145af35416c17/dist/riot-mixin-pack.amd.js#L125-L128 |
46,208 | cognitom/riot-mixin-pack | dist/riot-mixin-pack.amd.js | querySelectorAll | function querySelectorAll(sel, flag) {
var nodes = this.root.querySelectorAll(normalize(sel));
return !flag ? nodes : Array.prototype.map.call(nodes, function (node) {
return node._tag || undefined;
});
} | javascript | function querySelectorAll(sel, flag) {
var nodes = this.root.querySelectorAll(normalize(sel));
return !flag ? nodes : Array.prototype.map.call(nodes, function (node) {
return node._tag || undefined;
});
} | [
"function",
"querySelectorAll",
"(",
"sel",
",",
"flag",
")",
"{",
"var",
"nodes",
"=",
"this",
".",
"root",
".",
"querySelectorAll",
"(",
"normalize",
"(",
"sel",
")",
")",
";",
"return",
"!",
"flag",
"?",
"nodes",
":",
"Array",
".",
"prototype",
".",
"map",
".",
"call",
"(",
"nodes",
",",
"function",
"(",
"node",
")",
"{",
"return",
"node",
".",
"_tag",
"||",
"undefined",
";",
"}",
")",
";",
"}"
]
| Gets Nodes or Tags by CSS selector
@param { string } sel - CSS selector
@param { boolean } flag - true for Tag | [
"Gets",
"Nodes",
"or",
"Tags",
"by",
"CSS",
"selector"
]
| 903da842cccbccb853dc0c4f952145af35416c17 | https://github.com/cognitom/riot-mixin-pack/blob/903da842cccbccb853dc0c4f952145af35416c17/dist/riot-mixin-pack.amd.js#L135-L140 |
46,209 | jldec/pub-pkg-editor | client/editor-ui.js | fragmentClick | function fragmentClick(e) {
var el = e.target;
var href;
while (el && el.nodeName !== 'HTML' && !el.getAttribute('data-render-html')) { el = el.parentNode };
if (el && (href = el.getAttribute('data-render-html'))) {
bindEditor(generator.fragment$[href]);
e.preventDefault(); // will also stop pager because it checks for e.defaultPrevented
}
} | javascript | function fragmentClick(e) {
var el = e.target;
var href;
while (el && el.nodeName !== 'HTML' && !el.getAttribute('data-render-html')) { el = el.parentNode };
if (el && (href = el.getAttribute('data-render-html'))) {
bindEditor(generator.fragment$[href]);
e.preventDefault(); // will also stop pager because it checks for e.defaultPrevented
}
} | [
"function",
"fragmentClick",
"(",
"e",
")",
"{",
"var",
"el",
"=",
"e",
".",
"target",
";",
"var",
"href",
";",
"while",
"(",
"el",
"&&",
"el",
".",
"nodeName",
"!==",
"'HTML'",
"&&",
"!",
"el",
".",
"getAttribute",
"(",
"'data-render-html'",
")",
")",
"{",
"el",
"=",
"el",
".",
"parentNode",
"}",
";",
"if",
"(",
"el",
"&&",
"(",
"href",
"=",
"el",
".",
"getAttribute",
"(",
"'data-render-html'",
")",
")",
")",
"{",
"bindEditor",
"(",
"generator",
".",
"fragment$",
"[",
"href",
"]",
")",
";",
"e",
".",
"preventDefault",
"(",
")",
";",
"// will also stop pager because it checks for e.defaultPrevented",
"}",
"}"
]
| fragment click handler | [
"fragment",
"click",
"handler"
]
| db148d04eeaf49e3278240fcb96bf4d9055f584b | https://github.com/jldec/pub-pkg-editor/blob/db148d04eeaf49e3278240fcb96bf4d9055f584b/client/editor-ui.js#L149-L157 |
46,210 | jldec/pub-pkg-editor | client/editor-ui.js | bindEditor | function bindEditor(fragment) {
saveBreakHold();
if (fragment) {
editor.$name.text(fragment._href);
if (fragment._holdUpdates) {
editText(fragment._holdText);
}
else {
editText(fragment._hdr + fragment._txt);
}
editor.binding = fragment._href;
}
else {
editor.$name.text('');
editText('');
editor.binding = '';
}
} | javascript | function bindEditor(fragment) {
saveBreakHold();
if (fragment) {
editor.$name.text(fragment._href);
if (fragment._holdUpdates) {
editText(fragment._holdText);
}
else {
editText(fragment._hdr + fragment._txt);
}
editor.binding = fragment._href;
}
else {
editor.$name.text('');
editText('');
editor.binding = '';
}
} | [
"function",
"bindEditor",
"(",
"fragment",
")",
"{",
"saveBreakHold",
"(",
")",
";",
"if",
"(",
"fragment",
")",
"{",
"editor",
".",
"$name",
".",
"text",
"(",
"fragment",
".",
"_href",
")",
";",
"if",
"(",
"fragment",
".",
"_holdUpdates",
")",
"{",
"editText",
"(",
"fragment",
".",
"_holdText",
")",
";",
"}",
"else",
"{",
"editText",
"(",
"fragment",
".",
"_hdr",
"+",
"fragment",
".",
"_txt",
")",
";",
"}",
"editor",
".",
"binding",
"=",
"fragment",
".",
"_href",
";",
"}",
"else",
"{",
"editor",
".",
"$name",
".",
"text",
"(",
"''",
")",
";",
"editText",
"(",
"''",
")",
";",
"editor",
".",
"binding",
"=",
"''",
";",
"}",
"}"
]
| change editingHref to a different fragment or page | [
"change",
"editingHref",
"to",
"a",
"different",
"fragment",
"or",
"page"
]
| db148d04eeaf49e3278240fcb96bf4d9055f584b | https://github.com/jldec/pub-pkg-editor/blob/db148d04eeaf49e3278240fcb96bf4d9055f584b/client/editor-ui.js#L173-L190 |
46,211 | jldec/pub-pkg-editor | client/editor-ui.js | editorUpdate | function editorUpdate() {
if (editor.binding) {
if ('hold' === generator.clientUpdateFragmentText(editor.binding, editor.$edit.val())) {
editor.holding = true;
}
}
} | javascript | function editorUpdate() {
if (editor.binding) {
if ('hold' === generator.clientUpdateFragmentText(editor.binding, editor.$edit.val())) {
editor.holding = true;
}
}
} | [
"function",
"editorUpdate",
"(",
")",
"{",
"if",
"(",
"editor",
".",
"binding",
")",
"{",
"if",
"(",
"'hold'",
"===",
"generator",
".",
"clientUpdateFragmentText",
"(",
"editor",
".",
"binding",
",",
"editor",
".",
"$edit",
".",
"val",
"(",
")",
")",
")",
"{",
"editor",
".",
"holding",
"=",
"true",
";",
"}",
"}",
"}"
]
| register updates from editor using editor.binding | [
"register",
"updates",
"from",
"editor",
"using",
"editor",
".",
"binding"
]
| db148d04eeaf49e3278240fcb96bf4d9055f584b | https://github.com/jldec/pub-pkg-editor/blob/db148d04eeaf49e3278240fcb96bf4d9055f584b/client/editor-ui.js#L203-L209 |
46,212 | jldec/pub-pkg-editor | client/editor-ui.js | saveBreakHold | function saveBreakHold() {
if (editor.binding && editor.holding) {
generator.clientUpdateFragmentText(editor.binding, editor.$edit.val(), true);
editor.holding = false;
}
} | javascript | function saveBreakHold() {
if (editor.binding && editor.holding) {
generator.clientUpdateFragmentText(editor.binding, editor.$edit.val(), true);
editor.holding = false;
}
} | [
"function",
"saveBreakHold",
"(",
")",
"{",
"if",
"(",
"editor",
".",
"binding",
"&&",
"editor",
".",
"holding",
")",
"{",
"generator",
".",
"clientUpdateFragmentText",
"(",
"editor",
".",
"binding",
",",
"editor",
".",
"$edit",
".",
"val",
"(",
")",
",",
"true",
")",
";",
"editor",
".",
"holding",
"=",
"false",
";",
"}",
"}"
]
| save with breakHold - may result in modified href ==> loss of binding context? | [
"save",
"with",
"breakHold",
"-",
"may",
"result",
"in",
"modified",
"href",
"==",
">",
"loss",
"of",
"binding",
"context?"
]
| db148d04eeaf49e3278240fcb96bf4d9055f584b | https://github.com/jldec/pub-pkg-editor/blob/db148d04eeaf49e3278240fcb96bf4d9055f584b/client/editor-ui.js#L212-L217 |
46,213 | denar90/marionette-cli | lib/commands.js | function(type) {
//define if put type is present in config
if (config.moduleTypes.indexOf(type) > -1) {
config.moduleType = type;
fs.writeFile(path.resolve(__dirname, 'config.json'), JSON.stringify(config, null, 4), 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
} else {
return console.log('Wrong type, available types: %j', config.moduleTypes);
}
} | javascript | function(type) {
//define if put type is present in config
if (config.moduleTypes.indexOf(type) > -1) {
config.moduleType = type;
fs.writeFile(path.resolve(__dirname, 'config.json'), JSON.stringify(config, null, 4), 'utf8', function (err) {
if (err) {
return console.log(err);
}
});
} else {
return console.log('Wrong type, available types: %j', config.moduleTypes);
}
} | [
"function",
"(",
"type",
")",
"{",
"//define if put type is present in config",
"if",
"(",
"config",
".",
"moduleTypes",
".",
"indexOf",
"(",
"type",
")",
">",
"-",
"1",
")",
"{",
"config",
".",
"moduleType",
"=",
"type",
";",
"fs",
".",
"writeFile",
"(",
"path",
".",
"resolve",
"(",
"__dirname",
",",
"'config.json'",
")",
",",
"JSON",
".",
"stringify",
"(",
"config",
",",
"null",
",",
"4",
")",
",",
"'utf8'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"return",
"console",
".",
"log",
"(",
"'Wrong type, available types: %j'",
",",
"config",
".",
"moduleTypes",
")",
";",
"}",
"}"
]
| Sets module type
@param {string} type | [
"Sets",
"module",
"type"
]
| fde5934ba7369b0c3356864512efee8dc8242fff | https://github.com/denar90/marionette-cli/blob/fde5934ba7369b0c3356864512efee8dc8242fff/lib/commands.js#L13-L25 |
|
46,214 | denar90/marionette-cli | lib/commands.js | function(folder) {
var type = config.moduleType;
var appPath;
if (folder) {
if (path.isAbsolute(folder)) {
appPath = path.join(folder);
} else {
appPath = path.join(process.cwd(), folder);
}
} else {
appPath = path.join(process.cwd());
}
var appSrc = config.apps[type];
helpers.gitClone(appSrc, appPath);
} | javascript | function(folder) {
var type = config.moduleType;
var appPath;
if (folder) {
if (path.isAbsolute(folder)) {
appPath = path.join(folder);
} else {
appPath = path.join(process.cwd(), folder);
}
} else {
appPath = path.join(process.cwd());
}
var appSrc = config.apps[type];
helpers.gitClone(appSrc, appPath);
} | [
"function",
"(",
"folder",
")",
"{",
"var",
"type",
"=",
"config",
".",
"moduleType",
";",
"var",
"appPath",
";",
"if",
"(",
"folder",
")",
"{",
"if",
"(",
"path",
".",
"isAbsolute",
"(",
"folder",
")",
")",
"{",
"appPath",
"=",
"path",
".",
"join",
"(",
"folder",
")",
";",
"}",
"else",
"{",
"appPath",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"folder",
")",
";",
"}",
"}",
"else",
"{",
"appPath",
"=",
"path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
")",
";",
"}",
"var",
"appSrc",
"=",
"config",
".",
"apps",
"[",
"type",
"]",
";",
"helpers",
".",
"gitClone",
"(",
"appSrc",
",",
"appPath",
")",
";",
"}"
]
| Generates new app
@param {string} folder | [
"Generates",
"new",
"app"
]
| fde5934ba7369b0c3356864512efee8dc8242fff | https://github.com/denar90/marionette-cli/blob/fde5934ba7369b0c3356864512efee8dc8242fff/lib/commands.js#L31-L45 |
|
46,215 | gsmcwhirter/node-zoneinfo | index.js | function (){
var offset = parseInt(self._utcoffset());
var minus = false;
if (offset < 0)
{
minus = true;
offset = -offset;
}
var minutes = offset % 60;
var hours = (offset - minutes) / 60;
offset = self._zeropad(hours) + self._zeropad(minutes);
if (minus) offset = "-"+offset;
else offset = "+"+offset;
return offset;
} | javascript | function (){
var offset = parseInt(self._utcoffset());
var minus = false;
if (offset < 0)
{
minus = true;
offset = -offset;
}
var minutes = offset % 60;
var hours = (offset - minutes) / 60;
offset = self._zeropad(hours) + self._zeropad(minutes);
if (minus) offset = "-"+offset;
else offset = "+"+offset;
return offset;
} | [
"function",
"(",
")",
"{",
"var",
"offset",
"=",
"parseInt",
"(",
"self",
".",
"_utcoffset",
"(",
")",
")",
";",
"var",
"minus",
"=",
"false",
";",
"if",
"(",
"offset",
"<",
"0",
")",
"{",
"minus",
"=",
"true",
";",
"offset",
"=",
"-",
"offset",
";",
"}",
"var",
"minutes",
"=",
"offset",
"%",
"60",
";",
"var",
"hours",
"=",
"(",
"offset",
"-",
"minutes",
")",
"/",
"60",
";",
"offset",
"=",
"self",
".",
"_zeropad",
"(",
"hours",
")",
"+",
"self",
".",
"_zeropad",
"(",
"minutes",
")",
";",
"if",
"(",
"minus",
")",
"offset",
"=",
"\"-\"",
"+",
"offset",
";",
"else",
"offset",
"=",
"\"+\"",
"+",
"offset",
";",
"return",
"offset",
";",
"}"
]
| O UTC offset | [
"O",
"UTC",
"offset"
]
| 2c350afa97ef6854d42f78f954ba3ab402808028 | https://github.com/gsmcwhirter/node-zoneinfo/blob/2c350afa97ef6854d42f78f954ba3ab402808028/index.js#L425-L441 |
|
46,216 | AndiDittrich/Node.fs-magic | lib/isFileOfType.js | isFileOfType | async function isFileOfType(filename, condition){
try{
// get stats
const stats = await _fs.stat(filename);
// is directory ?
return condition(stats);
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
throw e;
}
}
} | javascript | async function isFileOfType(filename, condition){
try{
// get stats
const stats = await _fs.stat(filename);
// is directory ?
return condition(stats);
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
throw e;
}
}
} | [
"async",
"function",
"isFileOfType",
"(",
"filename",
",",
"condition",
")",
"{",
"try",
"{",
"// get stats",
"const",
"stats",
"=",
"await",
"_fs",
".",
"stat",
"(",
"filename",
")",
";",
"// is directory ?",
"return",
"condition",
"(",
"stats",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// file not found error ?",
"if",
"(",
"e",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}"
]
| check if node is of specific type | [
"check",
"if",
"node",
"is",
"of",
"specific",
"type"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/isFileOfType.js#L4-L19 |
46,217 | AndiDittrich/Node.fs-magic | lib/bulkCopy.js | bulkCopy | async function bulkCopy(srcset, createDestinationDirs=true, defaultFilemode=0o750, defaultDirmode=0o777){
// create destination directories in advance ?
if (createDestinationDirs === true){
// get unique paths from filelist
const dstDirs = Array.from(new Set(srcset.map((set) => _path.dirname(set[1]))));
// create dirs
for (let i=0;i<dstDirs.length;i++){
await _mkdirp(dstDirs[i], defaultDirmode, true);
}
}
// create tasks
const tasks = srcset.map((set) => _async.PromiseResolver(_copy, set[0], set[1], set[2] || defaultFilemode));
// resolve tasks in parallel with task limit 100
await _async.parallel(tasks, 100);
} | javascript | async function bulkCopy(srcset, createDestinationDirs=true, defaultFilemode=0o750, defaultDirmode=0o777){
// create destination directories in advance ?
if (createDestinationDirs === true){
// get unique paths from filelist
const dstDirs = Array.from(new Set(srcset.map((set) => _path.dirname(set[1]))));
// create dirs
for (let i=0;i<dstDirs.length;i++){
await _mkdirp(dstDirs[i], defaultDirmode, true);
}
}
// create tasks
const tasks = srcset.map((set) => _async.PromiseResolver(_copy, set[0], set[1], set[2] || defaultFilemode));
// resolve tasks in parallel with task limit 100
await _async.parallel(tasks, 100);
} | [
"async",
"function",
"bulkCopy",
"(",
"srcset",
",",
"createDestinationDirs",
"=",
"true",
",",
"defaultFilemode",
"=",
"0o750",
",",
"defaultDirmode",
"=",
"0o777",
")",
"{",
"// create destination directories in advance ?",
"if",
"(",
"createDestinationDirs",
"===",
"true",
")",
"{",
"// get unique paths from filelist",
"const",
"dstDirs",
"=",
"Array",
".",
"from",
"(",
"new",
"Set",
"(",
"srcset",
".",
"map",
"(",
"(",
"set",
")",
"=>",
"_path",
".",
"dirname",
"(",
"set",
"[",
"1",
"]",
")",
")",
")",
")",
";",
"// create dirs",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"dstDirs",
".",
"length",
";",
"i",
"++",
")",
"{",
"await",
"_mkdirp",
"(",
"dstDirs",
"[",
"i",
"]",
",",
"defaultDirmode",
",",
"true",
")",
";",
"}",
"}",
"// create tasks",
"const",
"tasks",
"=",
"srcset",
".",
"map",
"(",
"(",
"set",
")",
"=>",
"_async",
".",
"PromiseResolver",
"(",
"_copy",
",",
"set",
"[",
"0",
"]",
",",
"set",
"[",
"1",
"]",
",",
"set",
"[",
"2",
"]",
"||",
"defaultFilemode",
")",
")",
";",
"// resolve tasks in parallel with task limit 100",
"await",
"_async",
".",
"parallel",
"(",
"tasks",
",",
"100",
")",
";",
"}"
]
| copy a set of files simultanous | [
"copy",
"a",
"set",
"of",
"files",
"simultanous"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/bulkCopy.js#L7-L24 |
46,218 | alekseykulikov/storage-emitter | src/index.js | isPrivateBrowsingMode | function isPrivateBrowsingMode () {
try {
localStorage.setItem(TEST_KEY, '1')
localStorage.removeItem(TEST_KEY)
return false
} catch (error) {
return true
}
} | javascript | function isPrivateBrowsingMode () {
try {
localStorage.setItem(TEST_KEY, '1')
localStorage.removeItem(TEST_KEY)
return false
} catch (error) {
return true
}
} | [
"function",
"isPrivateBrowsingMode",
"(",
")",
"{",
"try",
"{",
"localStorage",
".",
"setItem",
"(",
"TEST_KEY",
",",
"'1'",
")",
"localStorage",
".",
"removeItem",
"(",
"TEST_KEY",
")",
"return",
"false",
"}",
"catch",
"(",
"error",
")",
"{",
"return",
"true",
"}",
"}"
]
| Check browser is in private browsing mode or not
@return {Boolean} | [
"Check",
"browser",
"is",
"in",
"private",
"browsing",
"mode",
"or",
"not"
]
| 49c00eb546a25787dfcfd9485e02273868b14d52 | https://github.com/alekseykulikov/storage-emitter/blob/49c00eb546a25787dfcfd9485e02273868b14d52/src/index.js#L68-L76 |
46,219 | SerkanSipahi/app-decorators | src/helpers/extract-dom-properties.js | extractDomProperties | function extractDomProperties(domNode, regex, removeDomAttributes = false) {
if(regex && classof(regex) !== 'RegExp'){
throw Error('Second argument is passed but it must be a Regular-Expression');
}
let domViewAttributes = {};
let toBeRemovedAttributes = [];
for(let key in domNode.attributes) {
if(!domNode.attributes.hasOwnProperty(key)){
continue;
}
let node = domNode.attributes[key];
if(regex){
let matched = regex.exec(node.name);
if(matched !== null) {
let [ ,name ] = matched;
domViewAttributes[name] = node.value;
removeDomAttributes ? toBeRemovedAttributes.push(node.name) : null;
}
}
else if(!regex) {
domViewAttributes[node.name] = node.value;
}
}
if(removeDomAttributes){
for(let attribute of toBeRemovedAttributes){
domNode.removeAttribute(attribute);
}
}
return domViewAttributes;
} | javascript | function extractDomProperties(domNode, regex, removeDomAttributes = false) {
if(regex && classof(regex) !== 'RegExp'){
throw Error('Second argument is passed but it must be a Regular-Expression');
}
let domViewAttributes = {};
let toBeRemovedAttributes = [];
for(let key in domNode.attributes) {
if(!domNode.attributes.hasOwnProperty(key)){
continue;
}
let node = domNode.attributes[key];
if(regex){
let matched = regex.exec(node.name);
if(matched !== null) {
let [ ,name ] = matched;
domViewAttributes[name] = node.value;
removeDomAttributes ? toBeRemovedAttributes.push(node.name) : null;
}
}
else if(!regex) {
domViewAttributes[node.name] = node.value;
}
}
if(removeDomAttributes){
for(let attribute of toBeRemovedAttributes){
domNode.removeAttribute(attribute);
}
}
return domViewAttributes;
} | [
"function",
"extractDomProperties",
"(",
"domNode",
",",
"regex",
",",
"removeDomAttributes",
"=",
"false",
")",
"{",
"if",
"(",
"regex",
"&&",
"classof",
"(",
"regex",
")",
"!==",
"'RegExp'",
")",
"{",
"throw",
"Error",
"(",
"'Second argument is passed but it must be a Regular-Expression'",
")",
";",
"}",
"let",
"domViewAttributes",
"=",
"{",
"}",
";",
"let",
"toBeRemovedAttributes",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"key",
"in",
"domNode",
".",
"attributes",
")",
"{",
"if",
"(",
"!",
"domNode",
".",
"attributes",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"continue",
";",
"}",
"let",
"node",
"=",
"domNode",
".",
"attributes",
"[",
"key",
"]",
";",
"if",
"(",
"regex",
")",
"{",
"let",
"matched",
"=",
"regex",
".",
"exec",
"(",
"node",
".",
"name",
")",
";",
"if",
"(",
"matched",
"!==",
"null",
")",
"{",
"let",
"[",
",",
"name",
"]",
"=",
"matched",
";",
"domViewAttributes",
"[",
"name",
"]",
"=",
"node",
".",
"value",
";",
"removeDomAttributes",
"?",
"toBeRemovedAttributes",
".",
"push",
"(",
"node",
".",
"name",
")",
":",
"null",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"regex",
")",
"{",
"domViewAttributes",
"[",
"node",
".",
"name",
"]",
"=",
"node",
".",
"value",
";",
"}",
"}",
"if",
"(",
"removeDomAttributes",
")",
"{",
"for",
"(",
"let",
"attribute",
"of",
"toBeRemovedAttributes",
")",
"{",
"domNode",
".",
"removeAttribute",
"(",
"attribute",
")",
";",
"}",
"}",
"return",
"domViewAttributes",
";",
"}"
]
| Extract domnode attributes
@param {HTMLElement} domNode
@param {Regex} expression
@param {Boolean} removeDomAttributes
@return {Object} | [
"Extract",
"domnode",
"attributes"
]
| 15f046b1bbe56af0d45b4a1b45a6a4c5689e4763 | https://github.com/SerkanSipahi/app-decorators/blob/15f046b1bbe56af0d45b4a1b45a6a4c5689e4763/src/helpers/extract-dom-properties.js#L12-L50 |
46,220 | Zefau/nello.io | lib/nello.js | Nello | function Nello(token)
{
if (!(this instanceof Nello))
return new Nello(token);
_events.call(this);
this.token = token;
if (!this.token)
throw new Error('Please check the arguments!');
} | javascript | function Nello(token)
{
if (!(this instanceof Nello))
return new Nello(token);
_events.call(this);
this.token = token;
if (!this.token)
throw new Error('Please check the arguments!');
} | [
"function",
"Nello",
"(",
"token",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Nello",
")",
")",
"return",
"new",
"Nello",
"(",
"token",
")",
";",
"_events",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"token",
"=",
"token",
";",
"if",
"(",
"!",
"this",
".",
"token",
")",
"throw",
"new",
"Error",
"(",
"'Please check the arguments!'",
")",
";",
"}"
]
| The constructor for a connection to a nello.
@class Nello
@param {String} token Token for authentication
@returns {Nello}
@constructor | [
"The",
"constructor",
"for",
"a",
"connection",
"to",
"a",
"nello",
"."
]
| 5a2b2cc9b47ffe700c203d3a38435d94e532d8ec | https://github.com/Zefau/nello.io/blob/5a2b2cc9b47ffe700c203d3a38435d94e532d8ec/lib/nello.js#L18-L28 |
46,221 | pichfl/onoff-rotary | index.js | RotaryEncoder | function RotaryEncoder(pinA, pinB) {
this.gpioA = new Gpio(pinA, 'in', 'both');
this.gpioB = new Gpio(pinB, 'in', 'both');
this.a = 2;
this.b = 2;
this.gpioA.watch((err, value) => {
if (err) {
this.emit('error', err);
return;
}
this.a = value;
});
this.gpioB.watch((err, value) => {
if (err) {
this.emit('error', err);
return;
}
this.b = value;
this.tick();
});
} | javascript | function RotaryEncoder(pinA, pinB) {
this.gpioA = new Gpio(pinA, 'in', 'both');
this.gpioB = new Gpio(pinB, 'in', 'both');
this.a = 2;
this.b = 2;
this.gpioA.watch((err, value) => {
if (err) {
this.emit('error', err);
return;
}
this.a = value;
});
this.gpioB.watch((err, value) => {
if (err) {
this.emit('error', err);
return;
}
this.b = value;
this.tick();
});
} | [
"function",
"RotaryEncoder",
"(",
"pinA",
",",
"pinB",
")",
"{",
"this",
".",
"gpioA",
"=",
"new",
"Gpio",
"(",
"pinA",
",",
"'in'",
",",
"'both'",
")",
";",
"this",
".",
"gpioB",
"=",
"new",
"Gpio",
"(",
"pinB",
",",
"'in'",
",",
"'both'",
")",
";",
"this",
".",
"a",
"=",
"2",
";",
"this",
".",
"b",
"=",
"2",
";",
"this",
".",
"gpioA",
".",
"watch",
"(",
"(",
"err",
",",
"value",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"return",
";",
"}",
"this",
".",
"a",
"=",
"value",
";",
"}",
")",
";",
"this",
".",
"gpioB",
".",
"watch",
"(",
"(",
"err",
",",
"value",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"return",
";",
"}",
"this",
".",
"b",
"=",
"value",
";",
"this",
".",
"tick",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Creates a new Rotary Encoder using two GPIO pins
Expects the pins to be configured as pull-up
@param pinA GPIO # of the first pin
@param pinB GPIO # of the second pin
@returns EventEmitter | [
"Creates",
"a",
"new",
"Rotary",
"Encoder",
"using",
"two",
"GPIO",
"pins",
"Expects",
"the",
"pins",
"to",
"be",
"configured",
"as",
"pull",
"-",
"up"
]
| 339712696432b80274fb76aec557fced4eb56080 | https://github.com/pichfl/onoff-rotary/blob/339712696432b80274fb76aec557fced4eb56080/index.js#L13-L41 |
46,222 | cognitom/felt | lib/handler.js | serve | function serve(res, file, maxAge) {
log.debug(`Serving: ${ file }`)
res.status(200)
.set('Cache-Control', `max-age=${ maxAge }`)
.sendFile(file, err => {
if (err) {
log.error(err)
res.status(err.status).end()
return
}
})
} | javascript | function serve(res, file, maxAge) {
log.debug(`Serving: ${ file }`)
res.status(200)
.set('Cache-Control', `max-age=${ maxAge }`)
.sendFile(file, err => {
if (err) {
log.error(err)
res.status(err.status).end()
return
}
})
} | [
"function",
"serve",
"(",
"res",
",",
"file",
",",
"maxAge",
")",
"{",
"log",
".",
"debug",
"(",
"`",
"${",
"file",
"}",
"`",
")",
"res",
".",
"status",
"(",
"200",
")",
".",
"set",
"(",
"'Cache-Control'",
",",
"`",
"${",
"maxAge",
"}",
"`",
")",
".",
"sendFile",
"(",
"file",
",",
"err",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"log",
".",
"error",
"(",
"err",
")",
"res",
".",
"status",
"(",
"err",
".",
"status",
")",
".",
"end",
"(",
")",
"return",
"}",
"}",
")",
"}"
]
| serves a cache file | [
"serves",
"a",
"cache",
"file"
]
| e97218aef9876ebdb2e6047138afe64ed37a4c83 | https://github.com/cognitom/felt/blob/e97218aef9876ebdb2e6047138afe64ed37a4c83/lib/handler.js#L15-L26 |
46,223 | cognitom/felt | lib/handler.js | find | function find(pathname, patterns) {
for (const entry of patterns)
if (minimatch(pathname, entry.pattern))
return entry.handler
return null
} | javascript | function find(pathname, patterns) {
for (const entry of patterns)
if (minimatch(pathname, entry.pattern))
return entry.handler
return null
} | [
"function",
"find",
"(",
"pathname",
",",
"patterns",
")",
"{",
"for",
"(",
"const",
"entry",
"of",
"patterns",
")",
"if",
"(",
"minimatch",
"(",
"pathname",
",",
"entry",
".",
"pattern",
")",
")",
"return",
"entry",
".",
"handler",
"return",
"null",
"}"
]
| finds a handler matched with pathname | [
"finds",
"a",
"handler",
"matched",
"with",
"pathname"
]
| e97218aef9876ebdb2e6047138afe64ed37a4c83 | https://github.com/cognitom/felt/blob/e97218aef9876ebdb2e6047138afe64ed37a4c83/lib/handler.js#L31-L36 |
46,224 | AndiDittrich/Node.fs-magic | lib/FileInputStream.js | FileInputStream | function FileInputStream(src){
// wrap into Promise
return new Promise(function(resolve, reject){
// open read stream
const istream = _fs.createReadStream(src);
istream.on('error', reject);
istream.on('open', function(){
resolve(istream);
});
});
} | javascript | function FileInputStream(src){
// wrap into Promise
return new Promise(function(resolve, reject){
// open read stream
const istream = _fs.createReadStream(src);
istream.on('error', reject);
istream.on('open', function(){
resolve(istream);
});
});
} | [
"function",
"FileInputStream",
"(",
"src",
")",
"{",
"// wrap into Promise",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// open read stream",
"const",
"istream",
"=",
"_fs",
".",
"createReadStream",
"(",
"src",
")",
";",
"istream",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
";",
"istream",
".",
"on",
"(",
"'open'",
",",
"function",
"(",
")",
"{",
"resolve",
"(",
"istream",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| open read stream | [
"open",
"read",
"stream"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/FileInputStream.js#L4-L15 |
46,225 | Zefau/nello.io | lib/auth.js | Auth | function Auth(clientId, clientSecret)
{
if (!(this instanceof Auth))
return new Auth(clientId, clientSecret);
this.clientId = clientId;
this.clientSecret = clientSecret;
if (!this.clientId || !this.clientSecret)
throw new Error('No Client ID / Client Secret provided!');
} | javascript | function Auth(clientId, clientSecret)
{
if (!(this instanceof Auth))
return new Auth(clientId, clientSecret);
this.clientId = clientId;
this.clientSecret = clientSecret;
if (!this.clientId || !this.clientSecret)
throw new Error('No Client ID / Client Secret provided!');
} | [
"function",
"Auth",
"(",
"clientId",
",",
"clientSecret",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Auth",
")",
")",
"return",
"new",
"Auth",
"(",
"clientId",
",",
"clientSecret",
")",
";",
"this",
".",
"clientId",
"=",
"clientId",
";",
"this",
".",
"clientSecret",
"=",
"clientSecret",
";",
"if",
"(",
"!",
"this",
".",
"clientId",
"||",
"!",
"this",
".",
"clientSecret",
")",
"throw",
"new",
"Error",
"(",
"'No Client ID / Client Secret provided!'",
")",
";",
"}"
]
| The constructor for the authentication to a nello.
@class Auth
@param {String} clientId Client ID used for authentication
@param {String} clientSecret Client Secret used for authentication
@returns {Auth}
@constructor
@see https://nelloauth.docs.apiary.io/#reference/0/token/create-a-new-token-client-credentials | [
"The",
"constructor",
"for",
"the",
"authentication",
"to",
"a",
"nello",
"."
]
| 5a2b2cc9b47ffe700c203d3a38435d94e532d8ec | https://github.com/Zefau/nello.io/blob/5a2b2cc9b47ffe700c203d3a38435d94e532d8ec/lib/auth.js#L17-L27 |
46,226 | AndiDittrich/Node.fs-magic | lib/isSymlink.js | isSymlink | async function isSymlink(filename){
try{
// get stats
const stats = await _fs.lstat(filename);
// is symlink ?
return stats.isSymbolicLink();
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
throw e;
}
}
} | javascript | async function isSymlink(filename){
try{
// get stats
const stats = await _fs.lstat(filename);
// is symlink ?
return stats.isSymbolicLink();
}catch(e){
// file not found error ?
if (e.code === 'ENOENT'){
return false;
}else{
throw e;
}
}
} | [
"async",
"function",
"isSymlink",
"(",
"filename",
")",
"{",
"try",
"{",
"// get stats",
"const",
"stats",
"=",
"await",
"_fs",
".",
"lstat",
"(",
"filename",
")",
";",
"// is symlink ?",
"return",
"stats",
".",
"isSymbolicLink",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// file not found error ?",
"if",
"(",
"e",
".",
"code",
"===",
"'ENOENT'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"throw",
"e",
";",
"}",
"}",
"}"
]
| check if node is a symlink | [
"check",
"if",
"node",
"is",
"a",
"symlink"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/isSymlink.js#L4-L19 |
46,227 | denar90/marionette-cli | lib/helpers.js | function(file, targetPath) {
rigger(
file,
{ output: targetPath},
function(error, content) {
if (error) {
console.log(error);
return;
}
fs.writeFile(targetPath, content, 'utf8');
}
);
} | javascript | function(file, targetPath) {
rigger(
file,
{ output: targetPath},
function(error, content) {
if (error) {
console.log(error);
return;
}
fs.writeFile(targetPath, content, 'utf8');
}
);
} | [
"function",
"(",
"file",
",",
"targetPath",
")",
"{",
"rigger",
"(",
"file",
",",
"{",
"output",
":",
"targetPath",
"}",
",",
"function",
"(",
"error",
",",
"content",
")",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"log",
"(",
"error",
")",
";",
"return",
";",
"}",
"fs",
".",
"writeFile",
"(",
"targetPath",
",",
"content",
",",
"'utf8'",
")",
";",
"}",
")",
";",
"}"
]
| Creates new file including sources from original one
@param {string} file File
@param {string} targetPath New file name | [
"Creates",
"new",
"file",
"including",
"sources",
"from",
"original",
"one"
]
| fde5934ba7369b0c3356864512efee8dc8242fff | https://github.com/denar90/marionette-cli/blob/fde5934ba7369b0c3356864512efee8dc8242fff/lib/helpers.js#L11-L23 |
|
46,228 | glennjones/text-autolinker | lib/handlers.js | renderJSON | function renderJSON( request, reply, err, result ){
if(err){
if(err.code === 404){
reply(new hapi.error.notFound(err.message));
}else{
reply(new hapi.error.badRequest(err.message));
}
}else{
reply(result).type('application/json; charset=utf-8');
}
} | javascript | function renderJSON( request, reply, err, result ){
if(err){
if(err.code === 404){
reply(new hapi.error.notFound(err.message));
}else{
reply(new hapi.error.badRequest(err.message));
}
}else{
reply(result).type('application/json; charset=utf-8');
}
} | [
"function",
"renderJSON",
"(",
"request",
",",
"reply",
",",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"404",
")",
"{",
"reply",
"(",
"new",
"hapi",
".",
"error",
".",
"notFound",
"(",
"err",
".",
"message",
")",
")",
";",
"}",
"else",
"{",
"reply",
"(",
"new",
"hapi",
".",
"error",
".",
"badRequest",
"(",
"err",
".",
"message",
")",
")",
";",
"}",
"}",
"else",
"{",
"reply",
"(",
"result",
")",
".",
"type",
"(",
"'application/json; charset=utf-8'",
")",
";",
"}",
"}"
]
| render json out to http stream | [
"render",
"json",
"out",
"to",
"http",
"stream"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/handlers.js#L52-L62 |
46,229 | gluwer/azure-queue-node | index.js | _initDefaultConnection | function _initDefaultConnection() {
if ('CLOUD_STORAGE_ACCOUNT' in process.env) {
var accountSettings = utils.parseAccountString(process.env.CLOUD_STORAGE_ACCOUNT);
if (accountSettings !== null) {
_defaultClientSetting = _.defaults(_defaultClientSetting, accountSettings);
}
}
} | javascript | function _initDefaultConnection() {
if ('CLOUD_STORAGE_ACCOUNT' in process.env) {
var accountSettings = utils.parseAccountString(process.env.CLOUD_STORAGE_ACCOUNT);
if (accountSettings !== null) {
_defaultClientSetting = _.defaults(_defaultClientSetting, accountSettings);
}
}
} | [
"function",
"_initDefaultConnection",
"(",
")",
"{",
"if",
"(",
"'CLOUD_STORAGE_ACCOUNT'",
"in",
"process",
".",
"env",
")",
"{",
"var",
"accountSettings",
"=",
"utils",
".",
"parseAccountString",
"(",
"process",
".",
"env",
".",
"CLOUD_STORAGE_ACCOUNT",
")",
";",
"if",
"(",
"accountSettings",
"!==",
"null",
")",
"{",
"_defaultClientSetting",
"=",
"_",
".",
"defaults",
"(",
"_defaultClientSetting",
",",
"accountSettings",
")",
";",
"}",
"}",
"}"
]
| initializes default client using default settings and environment variable CLOUD_STORAGE_ACCOUNT | [
"initializes",
"default",
"client",
"using",
"default",
"settings",
"and",
"environment",
"variable",
"CLOUD_STORAGE_ACCOUNT"
]
| d3c3c8415fd65c8ad30779aba3c8c9a74cf0f206 | https://github.com/gluwer/azure-queue-node/blob/d3c3c8415fd65c8ad30779aba3c8c9a74cf0f206/index.js#L17-L24 |
46,230 | ablage/perceptualdiff | lib/lpyramid.js | function (a, b) {
var Kernel = [0.05, 0.25, 0.4, 0.25, 0.05];
var width = this.getWidth();
var weight = this.getWeight();
//#pragma omp parallel for
for (var y = 0; y < weight; y++) {
for (var x = 0; x < width; x++) {
var index = y * width + x;
a[index] = 0;
for (var i = -2; i <= 2; i++) {
for (var j = -2; j <= 2; j++) {
var nx = x + i;
var ny = y + j;
if (nx < 0) nx = -nx;
if (ny < 0) ny = -ny;
if (nx >= width) nx = (width << 1) - nx - 1;
if (ny >= weight) ny = (weight << 1) - ny - 1;
a[index] += Kernel[i + 2] * Kernel[j + 2] * b[ny * width + nx];
}
}
}
}
} | javascript | function (a, b) {
var Kernel = [0.05, 0.25, 0.4, 0.25, 0.05];
var width = this.getWidth();
var weight = this.getWeight();
//#pragma omp parallel for
for (var y = 0; y < weight; y++) {
for (var x = 0; x < width; x++) {
var index = y * width + x;
a[index] = 0;
for (var i = -2; i <= 2; i++) {
for (var j = -2; j <= 2; j++) {
var nx = x + i;
var ny = y + j;
if (nx < 0) nx = -nx;
if (ny < 0) ny = -ny;
if (nx >= width) nx = (width << 1) - nx - 1;
if (ny >= weight) ny = (weight << 1) - ny - 1;
a[index] += Kernel[i + 2] * Kernel[j + 2] * b[ny * width + nx];
}
}
}
}
} | [
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"Kernel",
"=",
"[",
"0.05",
",",
"0.25",
",",
"0.4",
",",
"0.25",
",",
"0.05",
"]",
";",
"var",
"width",
"=",
"this",
".",
"getWidth",
"(",
")",
";",
"var",
"weight",
"=",
"this",
".",
"getWeight",
"(",
")",
";",
"//#pragma omp parallel for",
"for",
"(",
"var",
"y",
"=",
"0",
";",
"y",
"<",
"weight",
";",
"y",
"++",
")",
"{",
"for",
"(",
"var",
"x",
"=",
"0",
";",
"x",
"<",
"width",
";",
"x",
"++",
")",
"{",
"var",
"index",
"=",
"y",
"*",
"width",
"+",
"x",
";",
"a",
"[",
"index",
"]",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"-",
"2",
";",
"i",
"<=",
"2",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"-",
"2",
";",
"j",
"<=",
"2",
";",
"j",
"++",
")",
"{",
"var",
"nx",
"=",
"x",
"+",
"i",
";",
"var",
"ny",
"=",
"y",
"+",
"j",
";",
"if",
"(",
"nx",
"<",
"0",
")",
"nx",
"=",
"-",
"nx",
";",
"if",
"(",
"ny",
"<",
"0",
")",
"ny",
"=",
"-",
"ny",
";",
"if",
"(",
"nx",
">=",
"width",
")",
"nx",
"=",
"(",
"width",
"<<",
"1",
")",
"-",
"nx",
"-",
"1",
";",
"if",
"(",
"ny",
">=",
"weight",
")",
"ny",
"=",
"(",
"weight",
"<<",
"1",
")",
"-",
"ny",
"-",
"1",
";",
"a",
"[",
"index",
"]",
"+=",
"Kernel",
"[",
"i",
"+",
"2",
"]",
"*",
"Kernel",
"[",
"j",
"+",
"2",
"]",
"*",
"b",
"[",
"ny",
"*",
"width",
"+",
"nx",
"]",
";",
"}",
"}",
"}",
"}",
"}"
]
| Convolves image b with the filter kernel and stores it in a. | [
"Convolves",
"image",
"b",
"with",
"the",
"filter",
"kernel",
"and",
"stores",
"it",
"in",
"a",
"."
]
| d91b1a7d2811fa78a6b4fe633b86ca6525a11314 | https://github.com/ablage/perceptualdiff/blob/d91b1a7d2811fa78a6b4fe633b86ca6525a11314/lib/lpyramid.js#L51-L80 |
|
46,231 | segmentio/canonical | lib/index.js | canonical | function canonical() {
var tags = document.getElementsByTagName('link');
// eslint-disable-next-line no-cond-assign
for (var i = 0, tag; tag = tags[i]; i++) {
if (tag.getAttribute('rel') === 'canonical') {
return tag.getAttribute('href');
}
}
} | javascript | function canonical() {
var tags = document.getElementsByTagName('link');
// eslint-disable-next-line no-cond-assign
for (var i = 0, tag; tag = tags[i]; i++) {
if (tag.getAttribute('rel') === 'canonical') {
return tag.getAttribute('href');
}
}
} | [
"function",
"canonical",
"(",
")",
"{",
"var",
"tags",
"=",
"document",
".",
"getElementsByTagName",
"(",
"'link'",
")",
";",
"// eslint-disable-next-line no-cond-assign",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"tag",
";",
"tag",
"=",
"tags",
"[",
"i",
"]",
";",
"i",
"++",
")",
"{",
"if",
"(",
"tag",
".",
"getAttribute",
"(",
"'rel'",
")",
"===",
"'canonical'",
")",
"{",
"return",
"tag",
".",
"getAttribute",
"(",
"'href'",
")",
";",
"}",
"}",
"}"
]
| Get the current page's canonical URL.
@return {string|undefined} | [
"Get",
"the",
"current",
"page",
"s",
"canonical",
"URL",
"."
]
| a5c3817a7bb60f04540883830b4e2db01c747a52 | https://github.com/segmentio/canonical/blob/a5c3817a7bb60f04540883830b4e2db01c747a52/lib/index.js#L8-L16 |
46,232 | doowb/computed-property | index.js | hasChanged | function hasChanged(depValues, current, dependencies) {
var len = dependencies.length;
var i = 0;
var result = false;
while (len--) {
var dep = dependencies[i++];
var value = get(current, dep);
if (get(depValues, dep) !== value) {
result = true;
set(depValues, dep, value);
}
}
return result;
} | javascript | function hasChanged(depValues, current, dependencies) {
var len = dependencies.length;
var i = 0;
var result = false;
while (len--) {
var dep = dependencies[i++];
var value = get(current, dep);
if (get(depValues, dep) !== value) {
result = true;
set(depValues, dep, value);
}
}
return result;
} | [
"function",
"hasChanged",
"(",
"depValues",
",",
"current",
",",
"dependencies",
")",
"{",
"var",
"len",
"=",
"dependencies",
".",
"length",
";",
"var",
"i",
"=",
"0",
";",
"var",
"result",
"=",
"false",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"dep",
"=",
"dependencies",
"[",
"i",
"++",
"]",
";",
"var",
"value",
"=",
"get",
"(",
"current",
",",
"dep",
")",
";",
"if",
"(",
"get",
"(",
"depValues",
",",
"dep",
")",
"!==",
"value",
")",
"{",
"result",
"=",
"true",
";",
"set",
"(",
"depValues",
",",
"dep",
",",
"value",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
]
| Determine if dependencies have changed.
@param {Object} `depValues` Stored dependency values
@param {Object} `current` Current object to check the dependencies.
@param {Array} `dependencies` Dependencies to check.
@return {Boolean} Did any dependencies change?
@api private | [
"Determine",
"if",
"dependencies",
"have",
"changed",
"."
]
| 011af1fa09456b3de356d0e6880fb5ad606239a7 | https://github.com/doowb/computed-property/blob/011af1fa09456b3de356d0e6880fb5ad606239a7/index.js#L24-L37 |
46,233 | doowb/computed-property | index.js | initWatch | function initWatch(obj, depValues, dependencies) {
var len = dependencies.length;
if (len === 0) {
return false;
}
var i = 0;
while (len--) {
var dep = dependencies[i++];
var value = clone(get(obj, dep));
set(depValues, dep, value);
}
return true;
} | javascript | function initWatch(obj, depValues, dependencies) {
var len = dependencies.length;
if (len === 0) {
return false;
}
var i = 0;
while (len--) {
var dep = dependencies[i++];
var value = clone(get(obj, dep));
set(depValues, dep, value);
}
return true;
} | [
"function",
"initWatch",
"(",
"obj",
",",
"depValues",
",",
"dependencies",
")",
"{",
"var",
"len",
"=",
"dependencies",
".",
"length",
";",
"if",
"(",
"len",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"var",
"i",
"=",
"0",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"dep",
"=",
"dependencies",
"[",
"i",
"++",
"]",
";",
"var",
"value",
"=",
"clone",
"(",
"get",
"(",
"obj",
",",
"dep",
")",
")",
";",
"set",
"(",
"depValues",
",",
"dep",
",",
"value",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Setup the storage object for watching dependencies.
@param {Object} `obj` Object property is being added to.
@param {Object} `depValues` Object used for storage.
@param {Array} `dependencies` Dependencies to watch
@return {Boolean} Return if watching or not.
@api private | [
"Setup",
"the",
"storage",
"object",
"for",
"watching",
"dependencies",
"."
]
| 011af1fa09456b3de356d0e6880fb5ad606239a7 | https://github.com/doowb/computed-property/blob/011af1fa09456b3de356d0e6880fb5ad606239a7/index.js#L49-L61 |
46,234 | hendrichbenjamin/mongoose-timestamp-plugin | lib/timestamp.js | timestamp | function timestamp(schema, options) {
options = options || {};
// Set defaults
options = Object.assign({
createdName: 'createdAt',
updatedName: 'updatedAt',
disableCreated: false,
disableUpdated: false
}, options);
// Add fields if not disabled
if (!options.disableCreated) {
addSchemaField(schema, options.createdName, {type: Date});
}
if (!options.disableUpdated) {
addSchemaField(schema, options.updatedName, {type: Date});
}
// Add pre-save hook to save dates of creation and modification
schema.pre('save', preSave);
/**
* Callback for the schema pre save
*
* @this mongoose.Schema
* @param {Function} next The next pre save callback in chain
* @returns {undefined}
*/
function preSave(next) {
const _ref = this.get(options.createdName);
if (!options.disableUpdated) {
this[options.updatedName] = new Date();
}
if (!options.disableCreated && (_ref === undefined || _ref === null)) {
this[options.createdName] = new Date();
}
next();
}
} | javascript | function timestamp(schema, options) {
options = options || {};
// Set defaults
options = Object.assign({
createdName: 'createdAt',
updatedName: 'updatedAt',
disableCreated: false,
disableUpdated: false
}, options);
// Add fields if not disabled
if (!options.disableCreated) {
addSchemaField(schema, options.createdName, {type: Date});
}
if (!options.disableUpdated) {
addSchemaField(schema, options.updatedName, {type: Date});
}
// Add pre-save hook to save dates of creation and modification
schema.pre('save', preSave);
/**
* Callback for the schema pre save
*
* @this mongoose.Schema
* @param {Function} next The next pre save callback in chain
* @returns {undefined}
*/
function preSave(next) {
const _ref = this.get(options.createdName);
if (!options.disableUpdated) {
this[options.updatedName] = new Date();
}
if (!options.disableCreated && (_ref === undefined || _ref === null)) {
this[options.createdName] = new Date();
}
next();
}
} | [
"function",
"timestamp",
"(",
"schema",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Set defaults",
"options",
"=",
"Object",
".",
"assign",
"(",
"{",
"createdName",
":",
"'createdAt'",
",",
"updatedName",
":",
"'updatedAt'",
",",
"disableCreated",
":",
"false",
",",
"disableUpdated",
":",
"false",
"}",
",",
"options",
")",
";",
"// Add fields if not disabled",
"if",
"(",
"!",
"options",
".",
"disableCreated",
")",
"{",
"addSchemaField",
"(",
"schema",
",",
"options",
".",
"createdName",
",",
"{",
"type",
":",
"Date",
"}",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"disableUpdated",
")",
"{",
"addSchemaField",
"(",
"schema",
",",
"options",
".",
"updatedName",
",",
"{",
"type",
":",
"Date",
"}",
")",
";",
"}",
"// Add pre-save hook to save dates of creation and modification",
"schema",
".",
"pre",
"(",
"'save'",
",",
"preSave",
")",
";",
"/**\n\t * Callback for the schema pre save\n\t *\n\t * @this mongoose.Schema\n\t * @param {Function} next The next pre save callback in chain\n\t * @returns {undefined}\n\t */",
"function",
"preSave",
"(",
"next",
")",
"{",
"const",
"_ref",
"=",
"this",
".",
"get",
"(",
"options",
".",
"createdName",
")",
";",
"if",
"(",
"!",
"options",
".",
"disableUpdated",
")",
"{",
"this",
"[",
"options",
".",
"updatedName",
"]",
"=",
"new",
"Date",
"(",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"disableCreated",
"&&",
"(",
"_ref",
"===",
"undefined",
"||",
"_ref",
"===",
"null",
")",
")",
"{",
"this",
"[",
"options",
".",
"createdName",
"]",
"=",
"new",
"Date",
"(",
")",
";",
"}",
"next",
"(",
")",
";",
"}",
"}"
]
| Mongoose plugin function which adds fields to track creation and modification dates
@param {Schema} schema the mongoose schema
@param {object} [options] the options object
@this mongoose.Schema
@access public
@returns {undefined} | [
"Mongoose",
"plugin",
"function",
"which",
"adds",
"fields",
"to",
"track",
"creation",
"and",
"modification",
"dates"
]
| 8a0a21b01287d88988717e1452e83012c2201756 | https://github.com/hendrichbenjamin/mongoose-timestamp-plugin/blob/8a0a21b01287d88988717e1452e83012c2201756/lib/timestamp.js#L30-L70 |
46,235 | hendrichbenjamin/mongoose-timestamp-plugin | lib/timestamp.js | preSave | function preSave(next) {
const _ref = this.get(options.createdName);
if (!options.disableUpdated) {
this[options.updatedName] = new Date();
}
if (!options.disableCreated && (_ref === undefined || _ref === null)) {
this[options.createdName] = new Date();
}
next();
} | javascript | function preSave(next) {
const _ref = this.get(options.createdName);
if (!options.disableUpdated) {
this[options.updatedName] = new Date();
}
if (!options.disableCreated && (_ref === undefined || _ref === null)) {
this[options.createdName] = new Date();
}
next();
} | [
"function",
"preSave",
"(",
"next",
")",
"{",
"const",
"_ref",
"=",
"this",
".",
"get",
"(",
"options",
".",
"createdName",
")",
";",
"if",
"(",
"!",
"options",
".",
"disableUpdated",
")",
"{",
"this",
"[",
"options",
".",
"updatedName",
"]",
"=",
"new",
"Date",
"(",
")",
";",
"}",
"if",
"(",
"!",
"options",
".",
"disableCreated",
"&&",
"(",
"_ref",
"===",
"undefined",
"||",
"_ref",
"===",
"null",
")",
")",
"{",
"this",
"[",
"options",
".",
"createdName",
"]",
"=",
"new",
"Date",
"(",
")",
";",
"}",
"next",
"(",
")",
";",
"}"
]
| Callback for the schema pre save
@this mongoose.Schema
@param {Function} next The next pre save callback in chain
@returns {undefined} | [
"Callback",
"for",
"the",
"schema",
"pre",
"save"
]
| 8a0a21b01287d88988717e1452e83012c2201756 | https://github.com/hendrichbenjamin/mongoose-timestamp-plugin/blob/8a0a21b01287d88988717e1452e83012c2201756/lib/timestamp.js#L58-L69 |
46,236 | ballantyne/node-paperclip | class.js | function(key, path, next) {
this.fileSystem.get(key, function(err, data) {
fs.writeFile(path, data, function(err) {
if (err) {
console.log(err);
}
next(err, data);
});
});
} | javascript | function(key, path, next) {
this.fileSystem.get(key, function(err, data) {
fs.writeFile(path, data, function(err) {
if (err) {
console.log(err);
}
next(err, data);
});
});
} | [
"function",
"(",
"key",
",",
"path",
",",
"next",
")",
"{",
"this",
".",
"fileSystem",
".",
"get",
"(",
"key",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"fs",
".",
"writeFile",
"(",
"path",
",",
"data",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
"next",
"(",
"err",
",",
"data",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| currently not used. was planning on using this function to download files from s3 to reprocess them if the sizes change, but I haven't rewritten that code yet. | [
"currently",
"not",
"used",
".",
"was",
"planning",
"on",
"using",
"this",
"function",
"to",
"download",
"files",
"from",
"s3",
"to",
"reprocess",
"them",
"if",
"the",
"sizes",
"change",
"but",
"I",
"haven",
"t",
"rewritten",
"that",
"code",
"yet",
"."
]
| 632020a5f5a3724385aee92d089ef3b55f6e639d | https://github.com/ballantyne/node-paperclip/blob/632020a5f5a3724385aee92d089ef3b55f6e639d/class.js#L139-L148 |
|
46,237 | ballantyne/node-paperclip | class.js | function(next) {
var self = this;
var obj = {};
obj.path = path.join(os.tmpdir, randomstring.generate());
obj.original_name = self.document[self.has_attached_file].original_url.split('/').pop();
this.downloadUrl(self.document[self.has_attached_file].original_url, obj.path, function() {
self.identify({input: obj.path}, function(err, identity) {
fs.stat(obj.path, function(err, stats) {
obj.file_size = stats.size;
obj.content_type = 'image/'+identity.format.toLowerCase();
next(err, obj);
})
})
});
} | javascript | function(next) {
var self = this;
var obj = {};
obj.path = path.join(os.tmpdir, randomstring.generate());
obj.original_name = self.document[self.has_attached_file].original_url.split('/').pop();
this.downloadUrl(self.document[self.has_attached_file].original_url, obj.path, function() {
self.identify({input: obj.path}, function(err, identity) {
fs.stat(obj.path, function(err, stats) {
obj.file_size = stats.size;
obj.content_type = 'image/'+identity.format.toLowerCase();
next(err, obj);
})
})
});
} | [
"function",
"(",
"next",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"obj",
"=",
"{",
"}",
";",
"obj",
".",
"path",
"=",
"path",
".",
"join",
"(",
"os",
".",
"tmpdir",
",",
"randomstring",
".",
"generate",
"(",
")",
")",
";",
"obj",
".",
"original_name",
"=",
"self",
".",
"document",
"[",
"self",
".",
"has_attached_file",
"]",
".",
"original_url",
".",
"split",
"(",
"'/'",
")",
".",
"pop",
"(",
")",
";",
"this",
".",
"downloadUrl",
"(",
"self",
".",
"document",
"[",
"self",
".",
"has_attached_file",
"]",
".",
"original_url",
",",
"obj",
".",
"path",
",",
"function",
"(",
")",
"{",
"self",
".",
"identify",
"(",
"{",
"input",
":",
"obj",
".",
"path",
"}",
",",
"function",
"(",
"err",
",",
"identity",
")",
"{",
"fs",
".",
"stat",
"(",
"obj",
".",
"path",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"obj",
".",
"file_size",
"=",
"stats",
".",
"size",
";",
"obj",
".",
"content_type",
"=",
"'image/'",
"+",
"identity",
".",
"format",
".",
"toLowerCase",
"(",
")",
";",
"next",
"(",
"err",
",",
"obj",
")",
";",
"}",
")",
"}",
")",
"}",
")",
";",
"}"
]
| this is currently not used. It is to download a url that is saved to a model and download that file and prepare the parameters to save. I am not sure where the best place to put this code, I was thinking of adding it to the middleware. | [
"this",
"is",
"currently",
"not",
"used",
".",
"It",
"is",
"to",
"download",
"a",
"url",
"that",
"is",
"saved",
"to",
"a",
"model",
"and",
"download",
"that",
"file",
"and",
"prepare",
"the",
"parameters",
"to",
"save",
".",
"I",
"am",
"not",
"sure",
"where",
"the",
"best",
"place",
"to",
"put",
"this",
"code",
"I",
"was",
"thinking",
"of",
"adding",
"it",
"to",
"the",
"middleware",
"."
]
| 632020a5f5a3724385aee92d089ef3b55f6e639d | https://github.com/ballantyne/node-paperclip/blob/632020a5f5a3724385aee92d089ef3b55f6e639d/class.js#L250-L265 |
|
46,238 | DoublePrecisionSoftware/jsontl | src/jsontl.js | function (data, trans, key) {
if (typeof data[key] !== "object") {
throw new SyntaxError('Cannot extend a scalar value. Transform: ' + util.getTransDescription(trans) + ' Data: ' + JSON.stringify(data));
}
for (var prop in trans) {
if (typeof data[prop] === "object") {
return extend(data[key], trans[prop], prop);
}
data[key][prop] = trans[prop];
}
} | javascript | function (data, trans, key) {
if (typeof data[key] !== "object") {
throw new SyntaxError('Cannot extend a scalar value. Transform: ' + util.getTransDescription(trans) + ' Data: ' + JSON.stringify(data));
}
for (var prop in trans) {
if (typeof data[prop] === "object") {
return extend(data[key], trans[prop], prop);
}
data[key][prop] = trans[prop];
}
} | [
"function",
"(",
"data",
",",
"trans",
",",
"key",
")",
"{",
"if",
"(",
"typeof",
"data",
"[",
"key",
"]",
"!==",
"\"object\"",
")",
"{",
"throw",
"new",
"SyntaxError",
"(",
"'Cannot extend a scalar value. Transform: '",
"+",
"util",
".",
"getTransDescription",
"(",
"trans",
")",
"+",
"' Data: '",
"+",
"JSON",
".",
"stringify",
"(",
"data",
")",
")",
";",
"}",
"for",
"(",
"var",
"prop",
"in",
"trans",
")",
"{",
"if",
"(",
"typeof",
"data",
"[",
"prop",
"]",
"===",
"\"object\"",
")",
"{",
"return",
"extend",
"(",
"data",
"[",
"key",
"]",
",",
"trans",
"[",
"prop",
"]",
",",
"prop",
")",
";",
"}",
"data",
"[",
"key",
"]",
"[",
"prop",
"]",
"=",
"trans",
"[",
"prop",
"]",
";",
"}",
"}"
]
| add the specified data to the object provided | [
"add",
"the",
"specified",
"data",
"to",
"the",
"object",
"provided"
]
| 13f6c2e52e6cc177aeda39f19b442835798556ad | https://github.com/DoublePrecisionSoftware/jsontl/blob/13f6c2e52e6cc177aeda39f19b442835798556ad/src/jsontl.js#L117-L129 |
|
46,239 | DoublePrecisionSoftware/jsontl | src/jsontl.js | function (data, transform) {
if (typeof transform.jsontl !== "undefined") {
if (typeof transform.jsontl.transform !== "undefined") {
return locators.in(data, transform.jsontl.transform);
}
}
throw new Error("Tranform definition invalid");
} | javascript | function (data, transform) {
if (typeof transform.jsontl !== "undefined") {
if (typeof transform.jsontl.transform !== "undefined") {
return locators.in(data, transform.jsontl.transform);
}
}
throw new Error("Tranform definition invalid");
} | [
"function",
"(",
"data",
",",
"transform",
")",
"{",
"if",
"(",
"typeof",
"transform",
".",
"jsontl",
"!==",
"\"undefined\"",
")",
"{",
"if",
"(",
"typeof",
"transform",
".",
"jsontl",
".",
"transform",
"!==",
"\"undefined\"",
")",
"{",
"return",
"locators",
".",
"in",
"(",
"data",
",",
"transform",
".",
"jsontl",
".",
"transform",
")",
";",
"}",
"}",
"throw",
"new",
"Error",
"(",
"\"Tranform definition invalid\"",
")",
";",
"}"
]
| Perform the provided transform on the data
@param {Object} data Data to transform
@param {Object} trans Transform definition
@returns {Object} The transformed data | [
"Perform",
"the",
"provided",
"transform",
"on",
"the",
"data"
]
| 13f6c2e52e6cc177aeda39f19b442835798556ad | https://github.com/DoublePrecisionSoftware/jsontl/blob/13f6c2e52e6cc177aeda39f19b442835798556ad/src/jsontl.js#L197-L204 |
|
46,240 | AndiDittrich/Node.fs-magic | lib/gunzip.js | gunzip | async function gunzip(input, dst){
// is input a filename or stream ?
if (typeof input === 'string'){
input = await _fileInputStream(input);
}
// decompress
const gzipStream = input.pipe(_zlib.createGunzip());
// write content to file
return _fileOutputStream(gzipStream, dst);
} | javascript | async function gunzip(input, dst){
// is input a filename or stream ?
if (typeof input === 'string'){
input = await _fileInputStream(input);
}
// decompress
const gzipStream = input.pipe(_zlib.createGunzip());
// write content to file
return _fileOutputStream(gzipStream, dst);
} | [
"async",
"function",
"gunzip",
"(",
"input",
",",
"dst",
")",
"{",
"// is input a filename or stream ?",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"input",
"=",
"await",
"_fileInputStream",
"(",
"input",
")",
";",
"}",
"// decompress",
"const",
"gzipStream",
"=",
"input",
".",
"pipe",
"(",
"_zlib",
".",
"createGunzip",
"(",
")",
")",
";",
"// write content to file",
"return",
"_fileOutputStream",
"(",
"gzipStream",
",",
"dst",
")",
";",
"}"
]
| decompress a file | [
"decompress",
"a",
"file"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/gunzip.js#L6-L17 |
46,241 | canguruhh/metaversejs | src/output.js | targetComplete | function targetComplete(target) {
let complete = true;
Object.values(target).forEach((value) => {
if (value > 0)
complete = false;
});
return complete;
} | javascript | function targetComplete(target) {
let complete = true;
Object.values(target).forEach((value) => {
if (value > 0)
complete = false;
});
return complete;
} | [
"function",
"targetComplete",
"(",
"target",
")",
"{",
"let",
"complete",
"=",
"true",
";",
"Object",
".",
"values",
"(",
"target",
")",
".",
"forEach",
"(",
"(",
"value",
")",
"=>",
"{",
"if",
"(",
"value",
">",
"0",
")",
"complete",
"=",
"false",
";",
"}",
")",
";",
"return",
"complete",
";",
"}"
]
| Helper function to check a target object if there are no more positive values.
@param {Object} targets
@returns {Boolean} | [
"Helper",
"function",
"to",
"check",
"a",
"target",
"object",
"if",
"there",
"are",
"no",
"more",
"positive",
"values",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/output.js#L371-L378 |
46,242 | SerkanSipahi/app-decorators | src/helpers/guid.js | guid | function guid() {
function _s4() {
return Math.floor(
(1 + Math.random()) * 0x10000
).toString(16).substring(1);
}
return _s4() + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + _s4() + _s4();
} | javascript | function guid() {
function _s4() {
return Math.floor(
(1 + Math.random()) * 0x10000
).toString(16).substring(1);
}
return _s4() + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + '-' + _s4() + _s4() + _s4();
} | [
"function",
"guid",
"(",
")",
"{",
"function",
"_s4",
"(",
")",
"{",
"return",
"Math",
".",
"floor",
"(",
"(",
"1",
"+",
"Math",
".",
"random",
"(",
")",
")",
"*",
"0x10000",
")",
".",
"toString",
"(",
"16",
")",
".",
"substring",
"(",
"1",
")",
";",
"}",
"return",
"_s4",
"(",
")",
"+",
"_s4",
"(",
")",
"+",
"'-'",
"+",
"_s4",
"(",
")",
"+",
"'-'",
"+",
"_s4",
"(",
")",
"+",
"'-'",
"+",
"_s4",
"(",
")",
"+",
"'-'",
"+",
"_s4",
"(",
")",
"+",
"_s4",
"(",
")",
"+",
"_s4",
"(",
")",
";",
"}"
]
| Generate unique id
@source http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript#105074
@returns {string} | [
"Generate",
"unique",
"id"
]
| 15f046b1bbe56af0d45b4a1b45a6a4c5689e4763 | https://github.com/SerkanSipahi/app-decorators/blob/15f046b1bbe56af0d45b4a1b45a6a4c5689e4763/src/helpers/guid.js#L6-L13 |
46,243 | tkqubo/conditional-decorator | dist/utils.js | getDecoratorTypeFromArguments | function getDecoratorTypeFromArguments(args) {
'use strict';
if (args.length === 0 || args.length > 3) {
return DecoratorType.None;
}
var kind = typeof (args.length === 1 ? args[0] : args[2]);
switch (kind) {
case 'function':
return DecoratorType.Class;
case 'number':
return DecoratorType.Parameter;
case 'undefined':
return DecoratorType.Property;
case 'object':
return DecoratorType.Method;
default:
return DecoratorType.None;
}
} | javascript | function getDecoratorTypeFromArguments(args) {
'use strict';
if (args.length === 0 || args.length > 3) {
return DecoratorType.None;
}
var kind = typeof (args.length === 1 ? args[0] : args[2]);
switch (kind) {
case 'function':
return DecoratorType.Class;
case 'number':
return DecoratorType.Parameter;
case 'undefined':
return DecoratorType.Property;
case 'object':
return DecoratorType.Method;
default:
return DecoratorType.None;
}
} | [
"function",
"getDecoratorTypeFromArguments",
"(",
"args",
")",
"{",
"'use strict'",
";",
"if",
"(",
"args",
".",
"length",
"===",
"0",
"||",
"args",
".",
"length",
">",
"3",
")",
"{",
"return",
"DecoratorType",
".",
"None",
";",
"}",
"var",
"kind",
"=",
"typeof",
"(",
"args",
".",
"length",
"===",
"1",
"?",
"args",
"[",
"0",
"]",
":",
"args",
"[",
"2",
"]",
")",
";",
"switch",
"(",
"kind",
")",
"{",
"case",
"'function'",
":",
"return",
"DecoratorType",
".",
"Class",
";",
"case",
"'number'",
":",
"return",
"DecoratorType",
".",
"Parameter",
";",
"case",
"'undefined'",
":",
"return",
"DecoratorType",
".",
"Property",
";",
"case",
"'object'",
":",
"return",
"DecoratorType",
".",
"Method",
";",
"default",
":",
"return",
"DecoratorType",
".",
"None",
";",
"}",
"}"
]
| Guesses which kind of decorator from its functional arguments
@param args
@returns {DecoratorType} | [
"Guesses",
"which",
"kind",
"of",
"decorator",
"from",
"its",
"functional",
"arguments"
]
| 9e19163d3c7bc5b0c9695a736ff8802c700b1ffc | https://github.com/tkqubo/conditional-decorator/blob/9e19163d3c7bc5b0c9695a736ff8802c700b1ffc/dist/utils.js#L18-L36 |
46,244 | mlewand/win-clipboard | lib/html.js | function( tagName, inputString ) {
let ret = inputString;
if ( ret.indexOf( '<' + tagName ) === -1 ) {
ret = `<${tagName}>${ret}`;
}
if ( ret.indexOf( '</' + tagName + '>' ) === -1 ) {
ret = `${ret}</${tagName}>`;
}
return ret;
} | javascript | function( tagName, inputString ) {
let ret = inputString;
if ( ret.indexOf( '<' + tagName ) === -1 ) {
ret = `<${tagName}>${ret}`;
}
if ( ret.indexOf( '</' + tagName + '>' ) === -1 ) {
ret = `${ret}</${tagName}>`;
}
return ret;
} | [
"function",
"(",
"tagName",
",",
"inputString",
")",
"{",
"let",
"ret",
"=",
"inputString",
";",
"if",
"(",
"ret",
".",
"indexOf",
"(",
"'<'",
"+",
"tagName",
")",
"===",
"-",
"1",
")",
"{",
"ret",
"=",
"`",
"${",
"tagName",
"}",
"${",
"ret",
"}",
"`",
";",
"}",
"if",
"(",
"ret",
".",
"indexOf",
"(",
"'</'",
"+",
"tagName",
"+",
"'>'",
")",
"===",
"-",
"1",
")",
"{",
"ret",
"=",
"`",
"${",
"ret",
"}",
"${",
"tagName",
"}",
"`",
";",
"}",
"return",
"ret",
";",
"}"
]
| Ensures that `string` is wrapped with an `tagName` element.
@param {string} tagName
@param {string} inputString
@returns {string} A copy of `inputString` that is guaranteed to be wrapped with `tagName` element. | [
"Ensures",
"that",
"string",
"is",
"wrapped",
"with",
"an",
"tagName",
"element",
"."
]
| 07fedc3f2a346ced39163dae75042884bde010e4 | https://github.com/mlewand/win-clipboard/blob/07fedc3f2a346ced39163dae75042884bde010e4/lib/html.js#L125-L137 |
|
46,245 | little-brother/outlier2 | stat-func.js | variance | function variance(values) {
let avg = mean(values);
return mean(values.map((e) => Math.pow(e - avg, 2)));
} | javascript | function variance(values) {
let avg = mean(values);
return mean(values.map((e) => Math.pow(e - avg, 2)));
} | [
"function",
"variance",
"(",
"values",
")",
"{",
"let",
"avg",
"=",
"mean",
"(",
"values",
")",
";",
"return",
"mean",
"(",
"values",
".",
"map",
"(",
"(",
"e",
")",
"=>",
"Math",
".",
"pow",
"(",
"e",
"-",
"avg",
",",
"2",
")",
")",
")",
";",
"}"
]
| Variance = average squared deviation from mean | [
"Variance",
"=",
"average",
"squared",
"deviation",
"from",
"mean"
]
| c6037b27b236e7d24aab81a1f925376f4ed8c03c | https://github.com/little-brother/outlier2/blob/c6037b27b236e7d24aab81a1f925376f4ed8c03c/stat-func.js#L21-L24 |
46,246 | ablage/perceptualdiff | index.js | function (path, image) {
if (image instanceof Buffer) {
return Promise.denodeify(PNGImage.loadImage)(image);
} else if ((typeof path === 'string') && !image) {
return Promise.denodeify(PNGImage.readImage)(path);
} else {
return image;
}
} | javascript | function (path, image) {
if (image instanceof Buffer) {
return Promise.denodeify(PNGImage.loadImage)(image);
} else if ((typeof path === 'string') && !image) {
return Promise.denodeify(PNGImage.readImage)(path);
} else {
return image;
}
} | [
"function",
"(",
"path",
",",
"image",
")",
"{",
"if",
"(",
"image",
"instanceof",
"Buffer",
")",
"{",
"return",
"Promise",
".",
"denodeify",
"(",
"PNGImage",
".",
"loadImage",
")",
"(",
"image",
")",
";",
"}",
"else",
"if",
"(",
"(",
"typeof",
"path",
"===",
"'string'",
")",
"&&",
"!",
"image",
")",
"{",
"return",
"Promise",
".",
"denodeify",
"(",
"PNGImage",
".",
"readImage",
")",
"(",
"path",
")",
";",
"}",
"else",
"{",
"return",
"image",
";",
"}",
"}"
]
| Loads the image or uses the already available image
@method _loadImage
@param {string} path
@param {PNGImage} image
@return {PNGImage|Promise}
@private | [
"Loads",
"the",
"image",
"or",
"uses",
"the",
"already",
"available",
"image"
]
| d91b1a7d2811fa78a6b4fe633b86ca6525a11314 | https://github.com/ablage/perceptualdiff/blob/d91b1a7d2811fa78a6b4fe633b86ca6525a11314/index.js#L151-L162 |
|
46,247 | tdzienniak/entropy | example/breakout/src/Breakout.js | fadeOutScreen | function fadeOutScreen(screen) {
var screenElement = document.querySelector(screen);
return Velocity(screenElement, {
opacity: 0,
}, {
display: "none",
duration: 500
});
} | javascript | function fadeOutScreen(screen) {
var screenElement = document.querySelector(screen);
return Velocity(screenElement, {
opacity: 0,
}, {
display: "none",
duration: 500
});
} | [
"function",
"fadeOutScreen",
"(",
"screen",
")",
"{",
"var",
"screenElement",
"=",
"document",
".",
"querySelector",
"(",
"screen",
")",
";",
"return",
"Velocity",
"(",
"screenElement",
",",
"{",
"opacity",
":",
"0",
",",
"}",
",",
"{",
"display",
":",
"\"none\"",
",",
"duration",
":",
"500",
"}",
")",
";",
"}"
]
| Some helper CSS animation functions | [
"Some",
"helper",
"CSS",
"animation",
"functions"
]
| c9c6460806c9dd3318caa690a0eaf463fecc2fd3 | https://github.com/tdzienniak/entropy/blob/c9c6460806c9dd3318caa690a0eaf463fecc2fd3/example/breakout/src/Breakout.js#L51-L60 |
46,248 | nicjansma/usertiming-compression.js | dist/usertiming-decompression.js | eat | function eat(expected) {
if (s[i] !== expected) {
throw new Error("bad JSURL syntax: expected " + expected + ", got " + (s && s[i]));
}
i++;
} | javascript | function eat(expected) {
if (s[i] !== expected) {
throw new Error("bad JSURL syntax: expected " + expected + ", got " + (s && s[i]));
}
i++;
} | [
"function",
"eat",
"(",
"expected",
")",
"{",
"if",
"(",
"s",
"[",
"i",
"]",
"!==",
"expected",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"bad JSURL syntax: expected \"",
"+",
"expected",
"+",
"\", got \"",
"+",
"(",
"s",
"&&",
"s",
"[",
"i",
"]",
")",
")",
";",
"}",
"i",
"++",
";",
"}"
]
| Eats the specified character, and throws an exception if another character
was found
@param {string} expected Expected string | [
"Eats",
"the",
"specified",
"character",
"and",
"throws",
"an",
"exception",
"if",
"another",
"character",
"was",
"found"
]
| 381c5d2ed832d128dd2291e130ade0fa7851630e | https://github.com/nicjansma/usertiming-compression.js/blob/381c5d2ed832d128dd2291e130ade0fa7851630e/dist/usertiming-decompression.js#L395-L401 |
46,249 | nicjansma/usertiming-compression.js | dist/usertiming-decompression.js | decode | function decode() {
var beg = i;
var ch;
var r = "";
// iterate until we reach the end of the string or "~" or ")"
while (i < len && (ch = s[i]) !== "~" && ch !== ")") {
switch (ch) {
case "*":
if (beg < i) {
r += s.substring(beg, i);
}
if (s[i + 1] === "*") {
// Unicode characters > 0xff (255), which are encoded as "**[4-digit code]"
r += String.fromCharCode(parseInt(s.substring(i + 2, i + 6), 16));
beg = (i += 6);
} else {
// Unicode characters <= 0xff (255), which are encoded as "*[2-digit code]"
r += String.fromCharCode(parseInt(s.substring(i + 1, i + 3), 16));
beg = (i += 3);
}
break;
case "!":
if (beg < i) {
r += s.substring(beg, i);
}
r += "$";
beg = ++i;
break;
default:
i++;
}
}
return r + s.substring(beg, i);
} | javascript | function decode() {
var beg = i;
var ch;
var r = "";
// iterate until we reach the end of the string or "~" or ")"
while (i < len && (ch = s[i]) !== "~" && ch !== ")") {
switch (ch) {
case "*":
if (beg < i) {
r += s.substring(beg, i);
}
if (s[i + 1] === "*") {
// Unicode characters > 0xff (255), which are encoded as "**[4-digit code]"
r += String.fromCharCode(parseInt(s.substring(i + 2, i + 6), 16));
beg = (i += 6);
} else {
// Unicode characters <= 0xff (255), which are encoded as "*[2-digit code]"
r += String.fromCharCode(parseInt(s.substring(i + 1, i + 3), 16));
beg = (i += 3);
}
break;
case "!":
if (beg < i) {
r += s.substring(beg, i);
}
r += "$";
beg = ++i;
break;
default:
i++;
}
}
return r + s.substring(beg, i);
} | [
"function",
"decode",
"(",
")",
"{",
"var",
"beg",
"=",
"i",
";",
"var",
"ch",
";",
"var",
"r",
"=",
"\"\"",
";",
"// iterate until we reach the end of the string or \"~\" or \")\"",
"while",
"(",
"i",
"<",
"len",
"&&",
"(",
"ch",
"=",
"s",
"[",
"i",
"]",
")",
"!==",
"\"~\"",
"&&",
"ch",
"!==",
"\")\"",
")",
"{",
"switch",
"(",
"ch",
")",
"{",
"case",
"\"*\"",
":",
"if",
"(",
"beg",
"<",
"i",
")",
"{",
"r",
"+=",
"s",
".",
"substring",
"(",
"beg",
",",
"i",
")",
";",
"}",
"if",
"(",
"s",
"[",
"i",
"+",
"1",
"]",
"===",
"\"*\"",
")",
"{",
"// Unicode characters > 0xff (255), which are encoded as \"**[4-digit code]\"",
"r",
"+=",
"String",
".",
"fromCharCode",
"(",
"parseInt",
"(",
"s",
".",
"substring",
"(",
"i",
"+",
"2",
",",
"i",
"+",
"6",
")",
",",
"16",
")",
")",
";",
"beg",
"=",
"(",
"i",
"+=",
"6",
")",
";",
"}",
"else",
"{",
"// Unicode characters <= 0xff (255), which are encoded as \"*[2-digit code]\"",
"r",
"+=",
"String",
".",
"fromCharCode",
"(",
"parseInt",
"(",
"s",
".",
"substring",
"(",
"i",
"+",
"1",
",",
"i",
"+",
"3",
")",
",",
"16",
")",
")",
";",
"beg",
"=",
"(",
"i",
"+=",
"3",
")",
";",
"}",
"break",
";",
"case",
"\"!\"",
":",
"if",
"(",
"beg",
"<",
"i",
")",
"{",
"r",
"+=",
"s",
".",
"substring",
"(",
"beg",
",",
"i",
")",
";",
"}",
"r",
"+=",
"\"$\"",
";",
"beg",
"=",
"++",
"i",
";",
"break",
";",
"default",
":",
"i",
"++",
";",
"}",
"}",
"return",
"r",
"+",
"s",
".",
"substring",
"(",
"beg",
",",
"i",
")",
";",
"}"
]
| Decodes the next value
@returns {string} Next value | [
"Decodes",
"the",
"next",
"value"
]
| 381c5d2ed832d128dd2291e130ade0fa7851630e | https://github.com/nicjansma/usertiming-compression.js/blob/381c5d2ed832d128dd2291e130ade0fa7851630e/dist/usertiming-decompression.js#L408-L447 |
46,250 | bang88/antd-local-icon-font | index.js | function (_a) {
var _b = _a === void 0 ? {} : _a, baseDir = _b.baseDir, _c = _b.fontsPathToSave, fontsPathToSave = _c === void 0 ? process.cwd() + "/build/static/fonts/" : _c, _d = _b.iconUrl, iconUrl = _d === void 0 ? "https://at.alicdn.com/t/" : _d, _e = _b.fontReg, fontReg = _e === void 0 ? /@font-face{font-family:anticon;src:url(.*)}$/g : _e, _f = _b.urlReg, urlReg = _f === void 0 ? reg : _f, _g = _b.cssPath, cssPath = _g === void 0 ? process.cwd() + "/build/static/css/" : _g, _h = _b.newFontsPath, newFontsPath = _h === void 0 ? "/static/fonts/" : _h;
if (baseDir !== "") {
fontsPathToSave = getPath(baseDir, fontsPathToSave);
cssPath = getPath(baseDir, cssPath);
}
return exports.finder(cssPath, function (content, filePath) {
var cssContents = content.toString();
var m = cssContents.match(urlReg);
if (m) {
// create fonts folder if not exists
if (!fs.existsSync(fontsPathToSave)) {
fs.mkdir(fontsPathToSave, function (err) {
if (err) {
throw err;
}
console.log("mkdir " + fontsPathToSave + " success");
});
}
m.forEach(function (item) {
var itemInfo = path.parse(item);
var shortname = itemInfo.base.replace(/((\?|#).*)/g, "");
exports.downloader(item, fontsPathToSave + "/" + shortname, function (err, c) {
if (err) {
throw err;
}
var replacedContents = cssContents.replace(new RegExp(iconUrl, "gi"), newFontsPath);
fs.writeFile(filePath, replacedContents, function (err) {
if (err) {
throw err;
}
console.log("replace " + shortname + " done.");
});
});
});
}
else {
console.log("no results founded.");
}
});
} | javascript | function (_a) {
var _b = _a === void 0 ? {} : _a, baseDir = _b.baseDir, _c = _b.fontsPathToSave, fontsPathToSave = _c === void 0 ? process.cwd() + "/build/static/fonts/" : _c, _d = _b.iconUrl, iconUrl = _d === void 0 ? "https://at.alicdn.com/t/" : _d, _e = _b.fontReg, fontReg = _e === void 0 ? /@font-face{font-family:anticon;src:url(.*)}$/g : _e, _f = _b.urlReg, urlReg = _f === void 0 ? reg : _f, _g = _b.cssPath, cssPath = _g === void 0 ? process.cwd() + "/build/static/css/" : _g, _h = _b.newFontsPath, newFontsPath = _h === void 0 ? "/static/fonts/" : _h;
if (baseDir !== "") {
fontsPathToSave = getPath(baseDir, fontsPathToSave);
cssPath = getPath(baseDir, cssPath);
}
return exports.finder(cssPath, function (content, filePath) {
var cssContents = content.toString();
var m = cssContents.match(urlReg);
if (m) {
// create fonts folder if not exists
if (!fs.existsSync(fontsPathToSave)) {
fs.mkdir(fontsPathToSave, function (err) {
if (err) {
throw err;
}
console.log("mkdir " + fontsPathToSave + " success");
});
}
m.forEach(function (item) {
var itemInfo = path.parse(item);
var shortname = itemInfo.base.replace(/((\?|#).*)/g, "");
exports.downloader(item, fontsPathToSave + "/" + shortname, function (err, c) {
if (err) {
throw err;
}
var replacedContents = cssContents.replace(new RegExp(iconUrl, "gi"), newFontsPath);
fs.writeFile(filePath, replacedContents, function (err) {
if (err) {
throw err;
}
console.log("replace " + shortname + " done.");
});
});
});
}
else {
console.log("no results founded.");
}
});
} | [
"function",
"(",
"_a",
")",
"{",
"var",
"_b",
"=",
"_a",
"===",
"void",
"0",
"?",
"{",
"}",
":",
"_a",
",",
"baseDir",
"=",
"_b",
".",
"baseDir",
",",
"_c",
"=",
"_b",
".",
"fontsPathToSave",
",",
"fontsPathToSave",
"=",
"_c",
"===",
"void",
"0",
"?",
"process",
".",
"cwd",
"(",
")",
"+",
"\"/build/static/fonts/\"",
":",
"_c",
",",
"_d",
"=",
"_b",
".",
"iconUrl",
",",
"iconUrl",
"=",
"_d",
"===",
"void",
"0",
"?",
"\"https://at.alicdn.com/t/\"",
":",
"_d",
",",
"_e",
"=",
"_b",
".",
"fontReg",
",",
"fontReg",
"=",
"_e",
"===",
"void",
"0",
"?",
"/",
"@font-face{font-family:anticon;src:url(.*)}$",
"/",
"g",
":",
"_e",
",",
"_f",
"=",
"_b",
".",
"urlReg",
",",
"urlReg",
"=",
"_f",
"===",
"void",
"0",
"?",
"reg",
":",
"_f",
",",
"_g",
"=",
"_b",
".",
"cssPath",
",",
"cssPath",
"=",
"_g",
"===",
"void",
"0",
"?",
"process",
".",
"cwd",
"(",
")",
"+",
"\"/build/static/css/\"",
":",
"_g",
",",
"_h",
"=",
"_b",
".",
"newFontsPath",
",",
"newFontsPath",
"=",
"_h",
"===",
"void",
"0",
"?",
"\"/static/fonts/\"",
":",
"_h",
";",
"if",
"(",
"baseDir",
"!==",
"\"\"",
")",
"{",
"fontsPathToSave",
"=",
"getPath",
"(",
"baseDir",
",",
"fontsPathToSave",
")",
";",
"cssPath",
"=",
"getPath",
"(",
"baseDir",
",",
"cssPath",
")",
";",
"}",
"return",
"exports",
".",
"finder",
"(",
"cssPath",
",",
"function",
"(",
"content",
",",
"filePath",
")",
"{",
"var",
"cssContents",
"=",
"content",
".",
"toString",
"(",
")",
";",
"var",
"m",
"=",
"cssContents",
".",
"match",
"(",
"urlReg",
")",
";",
"if",
"(",
"m",
")",
"{",
"// create fonts folder if not exists",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"fontsPathToSave",
")",
")",
"{",
"fs",
".",
"mkdir",
"(",
"fontsPathToSave",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"console",
".",
"log",
"(",
"\"mkdir \"",
"+",
"fontsPathToSave",
"+",
"\" success\"",
")",
";",
"}",
")",
";",
"}",
"m",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"itemInfo",
"=",
"path",
".",
"parse",
"(",
"item",
")",
";",
"var",
"shortname",
"=",
"itemInfo",
".",
"base",
".",
"replace",
"(",
"/",
"((\\?|#).*)",
"/",
"g",
",",
"\"\"",
")",
";",
"exports",
".",
"downloader",
"(",
"item",
",",
"fontsPathToSave",
"+",
"\"/\"",
"+",
"shortname",
",",
"function",
"(",
"err",
",",
"c",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"var",
"replacedContents",
"=",
"cssContents",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"iconUrl",
",",
"\"gi\"",
")",
",",
"newFontsPath",
")",
";",
"fs",
".",
"writeFile",
"(",
"filePath",
",",
"replacedContents",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"throw",
"err",
";",
"}",
"console",
".",
"log",
"(",
"\"replace \"",
"+",
"shortname",
"+",
"\" done.\"",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"\"no results founded.\"",
")",
";",
"}",
"}",
")",
";",
"}"
]
| finding files and replace it | [
"finding",
"files",
"and",
"replace",
"it"
]
| d9aed9c581efe32d941b8a2bfcca6492cc6a6e58 | https://github.com/bang88/antd-local-icon-font/blob/d9aed9c581efe32d941b8a2bfcca6492cc6a6e58/index.js#L58-L98 |
|
46,251 | AndiDittrich/Node.fs-magic | lib/untar.js | untar | async function untar(istream, dst){
// is destination a directory ?
if (!await _isDirectory(dst)){
throw Error('Destination is not a valid directory: ' + dst);
}
// get instance
const extract = _tar.extract();
// list of extracted files
const items = [];
// wrap into Promise
return new Promise(function(resolve, reject){
// process each tar entry!
extract.on('entry', async function(header, fstream, next){
// add item to list
items.push(header.name);
// directory entry ?
if (header.type == 'directory'){
// create subdirectory
await _mkdirp(_path.join(dst, header.name), header.mode, true);
// file entry ?
}else if (header.type == 'file'){
// redirect content to file
await _fileOutputStream(fstream, _path.join(dst, header.name), header.mode);
}
// next entry
next();
});
// listener
extract.on('finish', function(){
resolve(items);
});
extract.on('error', reject);
// pipe through extractor
istream.pipe(extract);
});
} | javascript | async function untar(istream, dst){
// is destination a directory ?
if (!await _isDirectory(dst)){
throw Error('Destination is not a valid directory: ' + dst);
}
// get instance
const extract = _tar.extract();
// list of extracted files
const items = [];
// wrap into Promise
return new Promise(function(resolve, reject){
// process each tar entry!
extract.on('entry', async function(header, fstream, next){
// add item to list
items.push(header.name);
// directory entry ?
if (header.type == 'directory'){
// create subdirectory
await _mkdirp(_path.join(dst, header.name), header.mode, true);
// file entry ?
}else if (header.type == 'file'){
// redirect content to file
await _fileOutputStream(fstream, _path.join(dst, header.name), header.mode);
}
// next entry
next();
});
// listener
extract.on('finish', function(){
resolve(items);
});
extract.on('error', reject);
// pipe through extractor
istream.pipe(extract);
});
} | [
"async",
"function",
"untar",
"(",
"istream",
",",
"dst",
")",
"{",
"// is destination a directory ?",
"if",
"(",
"!",
"await",
"_isDirectory",
"(",
"dst",
")",
")",
"{",
"throw",
"Error",
"(",
"'Destination is not a valid directory: '",
"+",
"dst",
")",
";",
"}",
"// get instance",
"const",
"extract",
"=",
"_tar",
".",
"extract",
"(",
")",
";",
"// list of extracted files",
"const",
"items",
"=",
"[",
"]",
";",
"// wrap into Promise",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// process each tar entry!",
"extract",
".",
"on",
"(",
"'entry'",
",",
"async",
"function",
"(",
"header",
",",
"fstream",
",",
"next",
")",
"{",
"// add item to list",
"items",
".",
"push",
"(",
"header",
".",
"name",
")",
";",
"// directory entry ?",
"if",
"(",
"header",
".",
"type",
"==",
"'directory'",
")",
"{",
"// create subdirectory",
"await",
"_mkdirp",
"(",
"_path",
".",
"join",
"(",
"dst",
",",
"header",
".",
"name",
")",
",",
"header",
".",
"mode",
",",
"true",
")",
";",
"// file entry ?",
"}",
"else",
"if",
"(",
"header",
".",
"type",
"==",
"'file'",
")",
"{",
"// redirect content to file",
"await",
"_fileOutputStream",
"(",
"fstream",
",",
"_path",
".",
"join",
"(",
"dst",
",",
"header",
".",
"name",
")",
",",
"header",
".",
"mode",
")",
";",
"}",
"// next entry",
"next",
"(",
")",
";",
"}",
")",
";",
"// listener",
"extract",
".",
"on",
"(",
"'finish'",
",",
"function",
"(",
")",
"{",
"resolve",
"(",
"items",
")",
";",
"}",
")",
";",
"extract",
".",
"on",
"(",
"'error'",
",",
"reject",
")",
";",
"// pipe through extractor",
"istream",
".",
"pipe",
"(",
"extract",
")",
";",
"}",
")",
";",
"}"
]
| decompress an archive | [
"decompress",
"an",
"archive"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/untar.js#L8-L53 |
46,252 | mickleroy/gulp-clientlibify | index.js | zipDirectory | function zipDirectory(directories, dest, callback) {
var archive = archiver.create('zip', {gzip: false});
// Where to write the file
var destStream = fs.createWriteStream(dest);
archive.on('error', function(err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Archiving failed', err));
});
archive.on('entry', function(file) {
// do nothing
});
destStream.on('error', function(err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'WriteStream failed', err));
});
destStream.on('close', function() {
var size = archive.pointer();
gutil.log(PLUGIN_NAME, gutil.colors.green('Created ' + dest + ' (' + size + ' bytes)'));
callback();
});
archive.pipe(destStream);
directories.forEach(function(directory) {
if (fs.lstatSync(directory.src).isDirectory()) {
archive.directory(directory.src, directory.dest);
} else {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, directory.src + ' is not a valid directory'));
return;
}
});
archive.finalize();
} | javascript | function zipDirectory(directories, dest, callback) {
var archive = archiver.create('zip', {gzip: false});
// Where to write the file
var destStream = fs.createWriteStream(dest);
archive.on('error', function(err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'Archiving failed', err));
});
archive.on('entry', function(file) {
// do nothing
});
destStream.on('error', function(err) {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, 'WriteStream failed', err));
});
destStream.on('close', function() {
var size = archive.pointer();
gutil.log(PLUGIN_NAME, gutil.colors.green('Created ' + dest + ' (' + size + ' bytes)'));
callback();
});
archive.pipe(destStream);
directories.forEach(function(directory) {
if (fs.lstatSync(directory.src).isDirectory()) {
archive.directory(directory.src, directory.dest);
} else {
this.emit('error', new gutil.PluginError(PLUGIN_NAME, directory.src + ' is not a valid directory'));
return;
}
});
archive.finalize();
} | [
"function",
"zipDirectory",
"(",
"directories",
",",
"dest",
",",
"callback",
")",
"{",
"var",
"archive",
"=",
"archiver",
".",
"create",
"(",
"'zip'",
",",
"{",
"gzip",
":",
"false",
"}",
")",
";",
"// Where to write the file",
"var",
"destStream",
"=",
"fs",
".",
"createWriteStream",
"(",
"dest",
")",
";",
"archive",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"gutil",
".",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"'Archiving failed'",
",",
"err",
")",
")",
";",
"}",
")",
";",
"archive",
".",
"on",
"(",
"'entry'",
",",
"function",
"(",
"file",
")",
"{",
"// do nothing",
"}",
")",
";",
"destStream",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"gutil",
".",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"'WriteStream failed'",
",",
"err",
")",
")",
";",
"}",
")",
";",
"destStream",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"var",
"size",
"=",
"archive",
".",
"pointer",
"(",
")",
";",
"gutil",
".",
"log",
"(",
"PLUGIN_NAME",
",",
"gutil",
".",
"colors",
".",
"green",
"(",
"'Created '",
"+",
"dest",
"+",
"' ('",
"+",
"size",
"+",
"' bytes)'",
")",
")",
";",
"callback",
"(",
")",
";",
"}",
")",
";",
"archive",
".",
"pipe",
"(",
"destStream",
")",
";",
"directories",
".",
"forEach",
"(",
"function",
"(",
"directory",
")",
"{",
"if",
"(",
"fs",
".",
"lstatSync",
"(",
"directory",
".",
"src",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"archive",
".",
"directory",
"(",
"directory",
".",
"src",
",",
"directory",
".",
"dest",
")",
";",
"}",
"else",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"gutil",
".",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"directory",
".",
"src",
"+",
"' is not a valid directory'",
")",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"archive",
".",
"finalize",
"(",
")",
";",
"}"
]
| Zips a set of directories and its contents using node-archiver.
@param directories
@param dest
@param zipCallback | [
"Zips",
"a",
"set",
"of",
"directories",
"and",
"its",
"contents",
"using",
"node",
"-",
"archiver",
"."
]
| 49869cc06ef37fe67b3490bd1be175814d2646aa | https://github.com/mickleroy/gulp-clientlibify/blob/49869cc06ef37fe67b3490bd1be175814d2646aa/index.js#L246-L282 |
46,253 | nicjansma/usertiming-compression.js | src/usertiming-compression.js | encode | function encode(s) {
if (!/[^\w-.]/.test(s)) {
// if the string is only made up of alpha-numeric, underscore,
// dash or period, we can use it directly.
return s;
}
// we need to escape other characters
s = s.replace(/[^\w-.]/g, function(ch) {
if (ch === "$") {
return "!";
}
// use the character code for this one
ch = ch.charCodeAt(0);
if (ch < 0x100) {
// if less than 256, use "*[2-char code]"
return "*" + ("00" + ch.toString(16)).slice(-2);
} else {
// use "**[4-char code]"
return "**" + ("0000" + ch.toString(16)).slice(-4);
}
});
return s;
} | javascript | function encode(s) {
if (!/[^\w-.]/.test(s)) {
// if the string is only made up of alpha-numeric, underscore,
// dash or period, we can use it directly.
return s;
}
// we need to escape other characters
s = s.replace(/[^\w-.]/g, function(ch) {
if (ch === "$") {
return "!";
}
// use the character code for this one
ch = ch.charCodeAt(0);
if (ch < 0x100) {
// if less than 256, use "*[2-char code]"
return "*" + ("00" + ch.toString(16)).slice(-2);
} else {
// use "**[4-char code]"
return "**" + ("0000" + ch.toString(16)).slice(-4);
}
});
return s;
} | [
"function",
"encode",
"(",
"s",
")",
"{",
"if",
"(",
"!",
"/",
"[^\\w-.]",
"/",
".",
"test",
"(",
"s",
")",
")",
"{",
"// if the string is only made up of alpha-numeric, underscore,\r",
"// dash or period, we can use it directly.\r",
"return",
"s",
";",
"}",
"// we need to escape other characters\r",
"s",
"=",
"s",
".",
"replace",
"(",
"/",
"[^\\w-.]",
"/",
"g",
",",
"function",
"(",
"ch",
")",
"{",
"if",
"(",
"ch",
"===",
"\"$\"",
")",
"{",
"return",
"\"!\"",
";",
"}",
"// use the character code for this one\r",
"ch",
"=",
"ch",
".",
"charCodeAt",
"(",
"0",
")",
";",
"if",
"(",
"ch",
"<",
"0x100",
")",
"{",
"// if less than 256, use \"*[2-char code]\"\r",
"return",
"\"*\"",
"+",
"(",
"\"00\"",
"+",
"ch",
".",
"toString",
"(",
"16",
")",
")",
".",
"slice",
"(",
"-",
"2",
")",
";",
"}",
"else",
"{",
"// use \"**[4-char code]\"\r",
"return",
"\"**\"",
"+",
"(",
"\"0000\"",
"+",
"ch",
".",
"toString",
"(",
"16",
")",
")",
".",
"slice",
"(",
"-",
"4",
")",
";",
"}",
"}",
")",
";",
"return",
"s",
";",
"}"
]
| Encodes the specified string
@param {string} s String
@returns {string} Encoded string | [
"Encodes",
"the",
"specified",
"string"
]
| 381c5d2ed832d128dd2291e130ade0fa7851630e | https://github.com/nicjansma/usertiming-compression.js/blob/381c5d2ed832d128dd2291e130ade0fa7851630e/src/usertiming-compression.js#L571-L597 |
46,254 | LittleHelicase/frequencyjs | dsp.js | setupTypedArray | function setupTypedArray(name, fallback) {
// check if TypedArray exists
// typeof on Minefield and Chrome return function, typeof on Webkit returns object.
if (typeof this[name] !== "function" && typeof this[name] !== "object") {
// nope.. check if WebGLArray exists
if (typeof this[fallback] === "function" && typeof this[fallback] !== "object") {
this[name] = this[fallback];
} else {
// nope.. set as Native JS array
this[name] = function(obj) {
if (obj instanceof Array) {
return obj;
} else if (typeof obj === "number") {
return new Array(obj);
}
};
}
}
} | javascript | function setupTypedArray(name, fallback) {
// check if TypedArray exists
// typeof on Minefield and Chrome return function, typeof on Webkit returns object.
if (typeof this[name] !== "function" && typeof this[name] !== "object") {
// nope.. check if WebGLArray exists
if (typeof this[fallback] === "function" && typeof this[fallback] !== "object") {
this[name] = this[fallback];
} else {
// nope.. set as Native JS array
this[name] = function(obj) {
if (obj instanceof Array) {
return obj;
} else if (typeof obj === "number") {
return new Array(obj);
}
};
}
}
} | [
"function",
"setupTypedArray",
"(",
"name",
",",
"fallback",
")",
"{",
"// check if TypedArray exists",
"// typeof on Minefield and Chrome return function, typeof on Webkit returns object.",
"if",
"(",
"typeof",
"this",
"[",
"name",
"]",
"!==",
"\"function\"",
"&&",
"typeof",
"this",
"[",
"name",
"]",
"!==",
"\"object\"",
")",
"{",
"// nope.. check if WebGLArray exists",
"if",
"(",
"typeof",
"this",
"[",
"fallback",
"]",
"===",
"\"function\"",
"&&",
"typeof",
"this",
"[",
"fallback",
"]",
"!==",
"\"object\"",
")",
"{",
"this",
"[",
"name",
"]",
"=",
"this",
"[",
"fallback",
"]",
";",
"}",
"else",
"{",
"// nope.. set as Native JS array",
"this",
"[",
"name",
"]",
"=",
"function",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
"instanceof",
"Array",
")",
"{",
"return",
"obj",
";",
"}",
"else",
"if",
"(",
"typeof",
"obj",
"===",
"\"number\"",
")",
"{",
"return",
"new",
"Array",
"(",
"obj",
")",
";",
"}",
"}",
";",
"}",
"}",
"}"
]
| Setup arrays for platforms which do not support byte arrays | [
"Setup",
"arrays",
"for",
"platforms",
"which",
"do",
"not",
"support",
"byte",
"arrays"
]
| a3cf163ddfe77888ddefde77417f2ea192c05cc8 | https://github.com/LittleHelicase/frequencyjs/blob/a3cf163ddfe77888ddefde77417f2ea192c05cc8/dsp.js#L57-L75 |
46,255 | LittleHelicase/frequencyjs | dsp.js | DFT | function DFT(bufferSize, sampleRate) {
FourierTransform.call(this, bufferSize, sampleRate);
var N = bufferSize/2 * bufferSize;
var TWO_PI = 2 * Math.PI;
this.sinTable = new Float32Array(N);
this.cosTable = new Float32Array(N);
for (var i = 0; i < N; i++) {
this.sinTable[i] = Math.sin(i * TWO_PI / bufferSize);
this.cosTable[i] = Math.cos(i * TWO_PI / bufferSize);
}
} | javascript | function DFT(bufferSize, sampleRate) {
FourierTransform.call(this, bufferSize, sampleRate);
var N = bufferSize/2 * bufferSize;
var TWO_PI = 2 * Math.PI;
this.sinTable = new Float32Array(N);
this.cosTable = new Float32Array(N);
for (var i = 0; i < N; i++) {
this.sinTable[i] = Math.sin(i * TWO_PI / bufferSize);
this.cosTable[i] = Math.cos(i * TWO_PI / bufferSize);
}
} | [
"function",
"DFT",
"(",
"bufferSize",
",",
"sampleRate",
")",
"{",
"FourierTransform",
".",
"call",
"(",
"this",
",",
"bufferSize",
",",
"sampleRate",
")",
";",
"var",
"N",
"=",
"bufferSize",
"/",
"2",
"*",
"bufferSize",
";",
"var",
"TWO_PI",
"=",
"2",
"*",
"Math",
".",
"PI",
";",
"this",
".",
"sinTable",
"=",
"new",
"Float32Array",
"(",
"N",
")",
";",
"this",
".",
"cosTable",
"=",
"new",
"Float32Array",
"(",
"N",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"N",
";",
"i",
"++",
")",
"{",
"this",
".",
"sinTable",
"[",
"i",
"]",
"=",
"Math",
".",
"sin",
"(",
"i",
"*",
"TWO_PI",
"/",
"bufferSize",
")",
";",
"this",
".",
"cosTable",
"[",
"i",
"]",
"=",
"Math",
".",
"cos",
"(",
"i",
"*",
"TWO_PI",
"/",
"bufferSize",
")",
";",
"}",
"}"
]
| DFT is a class for calculating the Discrete Fourier Transform of a signal.
@param {Number} bufferSize The size of the sample buffer to be computed
@param {Number} sampleRate The sampleRate of the buffer (eg. 44100)
@constructor | [
"DFT",
"is",
"a",
"class",
"for",
"calculating",
"the",
"Discrete",
"Fourier",
"Transform",
"of",
"a",
"signal",
"."
]
| a3cf163ddfe77888ddefde77417f2ea192c05cc8 | https://github.com/LittleHelicase/frequencyjs/blob/a3cf163ddfe77888ddefde77417f2ea192c05cc8/dsp.js#L298-L311 |
46,256 | LittleHelicase/frequencyjs | dsp.js | Oscillator | function Oscillator(type, frequency, amplitude, bufferSize, sampleRate) {
this.frequency = frequency;
this.amplitude = amplitude;
this.bufferSize = bufferSize;
this.sampleRate = sampleRate;
//this.pulseWidth = pulseWidth;
this.frameCount = 0;
this.waveTableLength = 2048;
this.cyclesPerSample = frequency / sampleRate;
this.signal = new Float32Array(bufferSize);
this.envelope = null;
switch(parseInt(type, 10)) {
case DSP.TRIANGLE:
this.func = Oscillator.Triangle;
break;
case DSP.SAW:
this.func = Oscillator.Saw;
break;
case DSP.SQUARE:
this.func = Oscillator.Square;
break;
default:
case DSP.SINE:
this.func = Oscillator.Sine;
break;
}
this.generateWaveTable = function() {
Oscillator.waveTable[this.func] = new Float32Array(2048);
var waveTableTime = this.waveTableLength / this.sampleRate;
var waveTableHz = 1 / waveTableTime;
for (var i = 0; i < this.waveTableLength; i++) {
Oscillator.waveTable[this.func][i] = this.func(i * waveTableHz/this.sampleRate);
}
};
if ( typeof Oscillator.waveTable === 'undefined' ) {
Oscillator.waveTable = {};
}
if ( typeof Oscillator.waveTable[this.func] === 'undefined' ) {
this.generateWaveTable();
}
this.waveTable = Oscillator.waveTable[this.func];
} | javascript | function Oscillator(type, frequency, amplitude, bufferSize, sampleRate) {
this.frequency = frequency;
this.amplitude = amplitude;
this.bufferSize = bufferSize;
this.sampleRate = sampleRate;
//this.pulseWidth = pulseWidth;
this.frameCount = 0;
this.waveTableLength = 2048;
this.cyclesPerSample = frequency / sampleRate;
this.signal = new Float32Array(bufferSize);
this.envelope = null;
switch(parseInt(type, 10)) {
case DSP.TRIANGLE:
this.func = Oscillator.Triangle;
break;
case DSP.SAW:
this.func = Oscillator.Saw;
break;
case DSP.SQUARE:
this.func = Oscillator.Square;
break;
default:
case DSP.SINE:
this.func = Oscillator.Sine;
break;
}
this.generateWaveTable = function() {
Oscillator.waveTable[this.func] = new Float32Array(2048);
var waveTableTime = this.waveTableLength / this.sampleRate;
var waveTableHz = 1 / waveTableTime;
for (var i = 0; i < this.waveTableLength; i++) {
Oscillator.waveTable[this.func][i] = this.func(i * waveTableHz/this.sampleRate);
}
};
if ( typeof Oscillator.waveTable === 'undefined' ) {
Oscillator.waveTable = {};
}
if ( typeof Oscillator.waveTable[this.func] === 'undefined' ) {
this.generateWaveTable();
}
this.waveTable = Oscillator.waveTable[this.func];
} | [
"function",
"Oscillator",
"(",
"type",
",",
"frequency",
",",
"amplitude",
",",
"bufferSize",
",",
"sampleRate",
")",
"{",
"this",
".",
"frequency",
"=",
"frequency",
";",
"this",
".",
"amplitude",
"=",
"amplitude",
";",
"this",
".",
"bufferSize",
"=",
"bufferSize",
";",
"this",
".",
"sampleRate",
"=",
"sampleRate",
";",
"//this.pulseWidth = pulseWidth;",
"this",
".",
"frameCount",
"=",
"0",
";",
"this",
".",
"waveTableLength",
"=",
"2048",
";",
"this",
".",
"cyclesPerSample",
"=",
"frequency",
"/",
"sampleRate",
";",
"this",
".",
"signal",
"=",
"new",
"Float32Array",
"(",
"bufferSize",
")",
";",
"this",
".",
"envelope",
"=",
"null",
";",
"switch",
"(",
"parseInt",
"(",
"type",
",",
"10",
")",
")",
"{",
"case",
"DSP",
".",
"TRIANGLE",
":",
"this",
".",
"func",
"=",
"Oscillator",
".",
"Triangle",
";",
"break",
";",
"case",
"DSP",
".",
"SAW",
":",
"this",
".",
"func",
"=",
"Oscillator",
".",
"Saw",
";",
"break",
";",
"case",
"DSP",
".",
"SQUARE",
":",
"this",
".",
"func",
"=",
"Oscillator",
".",
"Square",
";",
"break",
";",
"default",
":",
"case",
"DSP",
".",
"SINE",
":",
"this",
".",
"func",
"=",
"Oscillator",
".",
"Sine",
";",
"break",
";",
"}",
"this",
".",
"generateWaveTable",
"=",
"function",
"(",
")",
"{",
"Oscillator",
".",
"waveTable",
"[",
"this",
".",
"func",
"]",
"=",
"new",
"Float32Array",
"(",
"2048",
")",
";",
"var",
"waveTableTime",
"=",
"this",
".",
"waveTableLength",
"/",
"this",
".",
"sampleRate",
";",
"var",
"waveTableHz",
"=",
"1",
"/",
"waveTableTime",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"waveTableLength",
";",
"i",
"++",
")",
"{",
"Oscillator",
".",
"waveTable",
"[",
"this",
".",
"func",
"]",
"[",
"i",
"]",
"=",
"this",
".",
"func",
"(",
"i",
"*",
"waveTableHz",
"/",
"this",
".",
"sampleRate",
")",
";",
"}",
"}",
";",
"if",
"(",
"typeof",
"Oscillator",
".",
"waveTable",
"===",
"'undefined'",
")",
"{",
"Oscillator",
".",
"waveTable",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"typeof",
"Oscillator",
".",
"waveTable",
"[",
"this",
".",
"func",
"]",
"===",
"'undefined'",
")",
"{",
"this",
".",
"generateWaveTable",
"(",
")",
";",
"}",
"this",
".",
"waveTable",
"=",
"Oscillator",
".",
"waveTable",
"[",
"this",
".",
"func",
"]",
";",
"}"
]
| Oscillator class for generating and modifying signals
@param {Number} type A waveform constant (eg. DSP.SINE)
@param {Number} frequency Initial frequency of the signal
@param {Number} amplitude Initial amplitude of the signal
@param {Number} bufferSize Size of the sample buffer to generate
@param {Number} sampleRate The sample rate of the signal
@contructor | [
"Oscillator",
"class",
"for",
"generating",
"and",
"modifying",
"signals"
]
| a3cf163ddfe77888ddefde77417f2ea192c05cc8 | https://github.com/LittleHelicase/frequencyjs/blob/a3cf163ddfe77888ddefde77417f2ea192c05cc8/dsp.js#L960-L1013 |
46,257 | frapa/bs4-selectbox | src/bs4-selectbox.directive.js | checkLater | function checkLater() {
setTimeout(function () {
ctrl.options(ctrl.searchTerms, function (options) {
ctrl._options = options;
if (options.length === 0) checkLater();
$scope.$apply();
});
}, 1000);
} | javascript | function checkLater() {
setTimeout(function () {
ctrl.options(ctrl.searchTerms, function (options) {
ctrl._options = options;
if (options.length === 0) checkLater();
$scope.$apply();
});
}, 1000);
} | [
"function",
"checkLater",
"(",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"ctrl",
".",
"options",
"(",
"ctrl",
".",
"searchTerms",
",",
"function",
"(",
"options",
")",
"{",
"ctrl",
".",
"_options",
"=",
"options",
";",
"if",
"(",
"options",
".",
"length",
"===",
"0",
")",
"checkLater",
"(",
")",
";",
"$scope",
".",
"$apply",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"1000",
")",
";",
"}"
]
| Sometimes options cannot return before some other stuff has been initialized Loop and check periodically until there is some data. | [
"Sometimes",
"options",
"cannot",
"return",
"before",
"some",
"other",
"stuff",
"has",
"been",
"initialized",
"Loop",
"and",
"check",
"periodically",
"until",
"there",
"is",
"some",
"data",
"."
]
| 9216dcd702d23def5a9bbf944ec4a73f1ddf4051 | https://github.com/frapa/bs4-selectbox/blob/9216dcd702d23def5a9bbf944ec4a73f1ddf4051/src/bs4-selectbox.directive.js#L204-L212 |
46,258 | AndiDittrich/Node.fs-magic | lib/checksum.js | checksum | function checksum(src, algorithm='sha256', outputFormat='hex'){
return new Promise(async function(resolve, reject){
// hash engine
const hash = _crypto.createHash(algorithm);
// events
hash.on('readable', function(){
// get hashsum
const sum = hash.read();
// data available ?
if (!sum){
return;
}
// hex, base64 or buffer
switch (outputFormat){
case 'base64':
resolve(sum.toString('base64'));
break;
case 'raw':
case 'buffer':
resolve(sum);
break;
default:
resolve(sum.toString('hex'));
break;
}
});
hash.on('error', function(e){
reject(e);
})
try{
// open file input stream
const input = await _fInputStream(src);
// stream hashing
input.pipe(hash);
}catch(e){
reject(e);
}
});
} | javascript | function checksum(src, algorithm='sha256', outputFormat='hex'){
return new Promise(async function(resolve, reject){
// hash engine
const hash = _crypto.createHash(algorithm);
// events
hash.on('readable', function(){
// get hashsum
const sum = hash.read();
// data available ?
if (!sum){
return;
}
// hex, base64 or buffer
switch (outputFormat){
case 'base64':
resolve(sum.toString('base64'));
break;
case 'raw':
case 'buffer':
resolve(sum);
break;
default:
resolve(sum.toString('hex'));
break;
}
});
hash.on('error', function(e){
reject(e);
})
try{
// open file input stream
const input = await _fInputStream(src);
// stream hashing
input.pipe(hash);
}catch(e){
reject(e);
}
});
} | [
"function",
"checksum",
"(",
"src",
",",
"algorithm",
"=",
"'sha256'",
",",
"outputFormat",
"=",
"'hex'",
")",
"{",
"return",
"new",
"Promise",
"(",
"async",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// hash engine",
"const",
"hash",
"=",
"_crypto",
".",
"createHash",
"(",
"algorithm",
")",
";",
"// events",
"hash",
".",
"on",
"(",
"'readable'",
",",
"function",
"(",
")",
"{",
"// get hashsum",
"const",
"sum",
"=",
"hash",
".",
"read",
"(",
")",
";",
"// data available ?",
"if",
"(",
"!",
"sum",
")",
"{",
"return",
";",
"}",
"// hex, base64 or buffer",
"switch",
"(",
"outputFormat",
")",
"{",
"case",
"'base64'",
":",
"resolve",
"(",
"sum",
".",
"toString",
"(",
"'base64'",
")",
")",
";",
"break",
";",
"case",
"'raw'",
":",
"case",
"'buffer'",
":",
"resolve",
"(",
"sum",
")",
";",
"break",
";",
"default",
":",
"resolve",
"(",
"sum",
".",
"toString",
"(",
"'hex'",
")",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"hash",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"e",
")",
"{",
"reject",
"(",
"e",
")",
";",
"}",
")",
"try",
"{",
"// open file input stream",
"const",
"input",
"=",
"await",
"_fInputStream",
"(",
"src",
")",
";",
"// stream hashing",
"input",
".",
"pipe",
"(",
"hash",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"reject",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
]
| generic checksum hashing | [
"generic",
"checksum",
"hashing"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/checksum.js#L5-L48 |
46,259 | AndiDittrich/Node.fs-magic | lib/mkdirp.js | mkdirp | async function mkdirp(dir, mode=0o777, recursive=false){
// stats command executable ? dir/file exists
const stats = await _statx(dir);
// dir already exists ?
if (stats){
// check if its a directory
if (!stats.isDirectory()){
throw new Error('Requested directory <' + dir + '> already exists and is not of type directory');
}
// check mode
if (stats.mode !== mode){
await _fs.chmod(dir, mode);
}
// create it recursivly
}else if (recursive){
// absolute or relative path ? make it absolute
// split into components
const dirComponents = _path.parse(_path.resolve(dir));
// get root dir (posix + windows)
const rootDir = dirComponents.root;
// extract dir (without root)
const dirRelativePath = _path.join(dirComponents.dir, dirComponents.base).substring(rootDir.length);
// split into parts
const subdirs = dirRelativePath.split(_path.sep);
// minimum of 1 segement required - this function does not create directories within filesystem root
if (subdirs.length < 2){
throw new Error('Recursive mkdir does not create directories within filesystem root!');
}
// build initial directory
let dyndir = _path.join(rootDir, subdirs.shift());
// iterate over path
while (subdirs.length > 0){
// append part
dyndir = _path.join(dyndir, subdirs.shift());
// stats command executable ? dir/file exists
const cstats = await _statx(dyndir);
// dir already exists ?
if (cstats){
// check if its a directory
if (!cstats.isDirectory()){
throw new Error('Requested path <' + dyndir + '> already exists and not of type directory');
}
// create directory
}else{
await _fs.mkdir(dyndir, mode);
}
}
// just create top level
}else{
await _fs.mkdir(dir, mode);
}
} | javascript | async function mkdirp(dir, mode=0o777, recursive=false){
// stats command executable ? dir/file exists
const stats = await _statx(dir);
// dir already exists ?
if (stats){
// check if its a directory
if (!stats.isDirectory()){
throw new Error('Requested directory <' + dir + '> already exists and is not of type directory');
}
// check mode
if (stats.mode !== mode){
await _fs.chmod(dir, mode);
}
// create it recursivly
}else if (recursive){
// absolute or relative path ? make it absolute
// split into components
const dirComponents = _path.parse(_path.resolve(dir));
// get root dir (posix + windows)
const rootDir = dirComponents.root;
// extract dir (without root)
const dirRelativePath = _path.join(dirComponents.dir, dirComponents.base).substring(rootDir.length);
// split into parts
const subdirs = dirRelativePath.split(_path.sep);
// minimum of 1 segement required - this function does not create directories within filesystem root
if (subdirs.length < 2){
throw new Error('Recursive mkdir does not create directories within filesystem root!');
}
// build initial directory
let dyndir = _path.join(rootDir, subdirs.shift());
// iterate over path
while (subdirs.length > 0){
// append part
dyndir = _path.join(dyndir, subdirs.shift());
// stats command executable ? dir/file exists
const cstats = await _statx(dyndir);
// dir already exists ?
if (cstats){
// check if its a directory
if (!cstats.isDirectory()){
throw new Error('Requested path <' + dyndir + '> already exists and not of type directory');
}
// create directory
}else{
await _fs.mkdir(dyndir, mode);
}
}
// just create top level
}else{
await _fs.mkdir(dir, mode);
}
} | [
"async",
"function",
"mkdirp",
"(",
"dir",
",",
"mode",
"=",
"0o777",
",",
"recursive",
"=",
"false",
")",
"{",
"// stats command executable ? dir/file exists",
"const",
"stats",
"=",
"await",
"_statx",
"(",
"dir",
")",
";",
"// dir already exists ?",
"if",
"(",
"stats",
")",
"{",
"// check if its a directory",
"if",
"(",
"!",
"stats",
".",
"isDirectory",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Requested directory <'",
"+",
"dir",
"+",
"'> already exists and is not of type directory'",
")",
";",
"}",
"// check mode",
"if",
"(",
"stats",
".",
"mode",
"!==",
"mode",
")",
"{",
"await",
"_fs",
".",
"chmod",
"(",
"dir",
",",
"mode",
")",
";",
"}",
"// create it recursivly",
"}",
"else",
"if",
"(",
"recursive",
")",
"{",
"// absolute or relative path ? make it absolute",
"// split into components",
"const",
"dirComponents",
"=",
"_path",
".",
"parse",
"(",
"_path",
".",
"resolve",
"(",
"dir",
")",
")",
";",
"// get root dir (posix + windows)",
"const",
"rootDir",
"=",
"dirComponents",
".",
"root",
";",
"// extract dir (without root)",
"const",
"dirRelativePath",
"=",
"_path",
".",
"join",
"(",
"dirComponents",
".",
"dir",
",",
"dirComponents",
".",
"base",
")",
".",
"substring",
"(",
"rootDir",
".",
"length",
")",
";",
"// split into parts",
"const",
"subdirs",
"=",
"dirRelativePath",
".",
"split",
"(",
"_path",
".",
"sep",
")",
";",
"// minimum of 1 segement required - this function does not create directories within filesystem root",
"if",
"(",
"subdirs",
".",
"length",
"<",
"2",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Recursive mkdir does not create directories within filesystem root!'",
")",
";",
"}",
"// build initial directory",
"let",
"dyndir",
"=",
"_path",
".",
"join",
"(",
"rootDir",
",",
"subdirs",
".",
"shift",
"(",
")",
")",
";",
"// iterate over path",
"while",
"(",
"subdirs",
".",
"length",
">",
"0",
")",
"{",
"// append part",
"dyndir",
"=",
"_path",
".",
"join",
"(",
"dyndir",
",",
"subdirs",
".",
"shift",
"(",
")",
")",
";",
"// stats command executable ? dir/file exists",
"const",
"cstats",
"=",
"await",
"_statx",
"(",
"dyndir",
")",
";",
"// dir already exists ?",
"if",
"(",
"cstats",
")",
"{",
"// check if its a directory",
"if",
"(",
"!",
"cstats",
".",
"isDirectory",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Requested path <'",
"+",
"dyndir",
"+",
"'> already exists and not of type directory'",
")",
";",
"}",
"// create directory",
"}",
"else",
"{",
"await",
"_fs",
".",
"mkdir",
"(",
"dyndir",
",",
"mode",
")",
";",
"}",
"}",
"// just create top level",
"}",
"else",
"{",
"await",
"_fs",
".",
"mkdir",
"(",
"dir",
",",
"mode",
")",
";",
"}",
"}"
]
| helper function to create directory only if they don't exists | [
"helper",
"function",
"to",
"create",
"directory",
"only",
"if",
"they",
"don",
"t",
"exists"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/mkdirp.js#L6-L72 |
46,260 | Zefau/nello.io | lib/timewindow.js | TimeWindow | function TimeWindow(connection, locationId, twId)
{
this.connection = connection;
this.locationId = locationId;
this.twId = twId;
} | javascript | function TimeWindow(connection, locationId, twId)
{
this.connection = connection;
this.locationId = locationId;
this.twId = twId;
} | [
"function",
"TimeWindow",
"(",
"connection",
",",
"locationId",
",",
"twId",
")",
"{",
"this",
".",
"connection",
"=",
"connection",
";",
"this",
".",
"locationId",
"=",
"locationId",
";",
"this",
".",
"twId",
"=",
"twId",
";",
"}"
]
| The constructor for Nello time windows.
@class TimeWindow
@param {Nello} connection Nello instance
@param {String} locationId ID of the Nello location
@param {String} twId ID of the time window
@returns void
@constructor | [
"The",
"constructor",
"for",
"Nello",
"time",
"windows",
"."
]
| 5a2b2cc9b47ffe700c203d3a38435d94e532d8ec | https://github.com/Zefau/nello.io/blob/5a2b2cc9b47ffe700c203d3a38435d94e532d8ec/lib/timewindow.js#L16-L21 |
46,261 | dcodeIO/ascli | ascli.js | ascli | function ascli(title, appendix) {
title = title || ascli.appName;
appendix = appendix || "";
var lines = ["", "", ""], c, a, j, ac = "";
for (var i=0; i<title.length; i++) {
c = title.charAt(i);
if (c == '\x1B') {
while ((c=title.charAt(i)) != 'm') {
ac += c;
i++;
}
ac += c;
} else if ((a=alphabet[c])||(a=alphabet[c.toLowerCase()]))
for (j=0; j<3; j++)
lines[j] += ac+a[j];
}
for (i=0; i<lines.length; i++) lines[i] = lines[i]+"\x1B[0m";
lines[1] += " "+appendix;
if (lines[lines.length-1].strip.trim().length == 0) {
lines.pop();
}
return '\n'+lines.join('\n')+'\n';
} | javascript | function ascli(title, appendix) {
title = title || ascli.appName;
appendix = appendix || "";
var lines = ["", "", ""], c, a, j, ac = "";
for (var i=0; i<title.length; i++) {
c = title.charAt(i);
if (c == '\x1B') {
while ((c=title.charAt(i)) != 'm') {
ac += c;
i++;
}
ac += c;
} else if ((a=alphabet[c])||(a=alphabet[c.toLowerCase()]))
for (j=0; j<3; j++)
lines[j] += ac+a[j];
}
for (i=0; i<lines.length; i++) lines[i] = lines[i]+"\x1B[0m";
lines[1] += " "+appendix;
if (lines[lines.length-1].strip.trim().length == 0) {
lines.pop();
}
return '\n'+lines.join('\n')+'\n';
} | [
"function",
"ascli",
"(",
"title",
",",
"appendix",
")",
"{",
"title",
"=",
"title",
"||",
"ascli",
".",
"appName",
";",
"appendix",
"=",
"appendix",
"||",
"\"\"",
";",
"var",
"lines",
"=",
"[",
"\"\"",
",",
"\"\"",
",",
"\"\"",
"]",
",",
"c",
",",
"a",
",",
"j",
",",
"ac",
"=",
"\"\"",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"title",
".",
"length",
";",
"i",
"++",
")",
"{",
"c",
"=",
"title",
".",
"charAt",
"(",
"i",
")",
";",
"if",
"(",
"c",
"==",
"'\\x1B'",
")",
"{",
"while",
"(",
"(",
"c",
"=",
"title",
".",
"charAt",
"(",
"i",
")",
")",
"!=",
"'m'",
")",
"{",
"ac",
"+=",
"c",
";",
"i",
"++",
";",
"}",
"ac",
"+=",
"c",
";",
"}",
"else",
"if",
"(",
"(",
"a",
"=",
"alphabet",
"[",
"c",
"]",
")",
"||",
"(",
"a",
"=",
"alphabet",
"[",
"c",
".",
"toLowerCase",
"(",
")",
"]",
")",
")",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"3",
";",
"j",
"++",
")",
"lines",
"[",
"j",
"]",
"+=",
"ac",
"+",
"a",
"[",
"j",
"]",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"lines",
"[",
"i",
"]",
"=",
"lines",
"[",
"i",
"]",
"+",
"\"\\x1B[0m\"",
";",
"lines",
"[",
"1",
"]",
"+=",
"\" \"",
"+",
"appendix",
";",
"if",
"(",
"lines",
"[",
"lines",
".",
"length",
"-",
"1",
"]",
".",
"strip",
".",
"trim",
"(",
")",
".",
"length",
"==",
"0",
")",
"{",
"lines",
".",
"pop",
"(",
")",
";",
"}",
"return",
"'\\n'",
"+",
"lines",
".",
"join",
"(",
"'\\n'",
")",
"+",
"'\\n'",
";",
"}"
]
| For backward compatibility
Builds a banner.
@param {string=} title App name
@param {string=} appendix Appendix, e.g. version
@returns {string} | [
"For",
"backward",
"compatibility",
"Builds",
"a",
"banner",
"."
]
| 5972ea9baf6939fc0f47a3435cedd66bc6f66fe1 | https://github.com/dcodeIO/ascli/blob/5972ea9baf6939fc0f47a3435cedd66bc6f66fe1/ascli.js#L37-L59 |
46,262 | glennjones/text-autolinker | lib/utilities.js | function(config) {
// get the options for the right server setup
var out = {},
serverMode = (process.env.NODE_ENV) ? process.env.NODE_ENV : 'development';
// loop object properties and add them to root of out object
for (var key in config.environments[serverMode]) {
if (config.environments[serverMode].hasOwnProperty(key)) {
out[key] = config.environments[serverMode][key];
}
}
if (process.env.HOST) {
out.server.host = process.env.HOST;
}
if (process.env.PORT) {
out.server.port = parseInt(process.env.PORT, 10);
}
// add modulus information
if (process.env.SERVO_ID && process.env.CLOUD_DIR) {
this.host = this.host ? this.host : {};
this.host.clouddir = process.env.CLOUD_DIR;
this.host.servoid = process.env.SERVO_ID;
}
return out;
} | javascript | function(config) {
// get the options for the right server setup
var out = {},
serverMode = (process.env.NODE_ENV) ? process.env.NODE_ENV : 'development';
// loop object properties and add them to root of out object
for (var key in config.environments[serverMode]) {
if (config.environments[serverMode].hasOwnProperty(key)) {
out[key] = config.environments[serverMode][key];
}
}
if (process.env.HOST) {
out.server.host = process.env.HOST;
}
if (process.env.PORT) {
out.server.port = parseInt(process.env.PORT, 10);
}
// add modulus information
if (process.env.SERVO_ID && process.env.CLOUD_DIR) {
this.host = this.host ? this.host : {};
this.host.clouddir = process.env.CLOUD_DIR;
this.host.servoid = process.env.SERVO_ID;
}
return out;
} | [
"function",
"(",
"config",
")",
"{",
"// get the options for the right server setup",
"var",
"out",
"=",
"{",
"}",
",",
"serverMode",
"=",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
")",
"?",
"process",
".",
"env",
".",
"NODE_ENV",
":",
"'development'",
";",
"// loop object properties and add them to root of out object",
"for",
"(",
"var",
"key",
"in",
"config",
".",
"environments",
"[",
"serverMode",
"]",
")",
"{",
"if",
"(",
"config",
".",
"environments",
"[",
"serverMode",
"]",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"out",
"[",
"key",
"]",
"=",
"config",
".",
"environments",
"[",
"serverMode",
"]",
"[",
"key",
"]",
";",
"}",
"}",
"if",
"(",
"process",
".",
"env",
".",
"HOST",
")",
"{",
"out",
".",
"server",
".",
"host",
"=",
"process",
".",
"env",
".",
"HOST",
";",
"}",
"if",
"(",
"process",
".",
"env",
".",
"PORT",
")",
"{",
"out",
".",
"server",
".",
"port",
"=",
"parseInt",
"(",
"process",
".",
"env",
".",
"PORT",
",",
"10",
")",
";",
"}",
"// add modulus information",
"if",
"(",
"process",
".",
"env",
".",
"SERVO_ID",
"&&",
"process",
".",
"env",
".",
"CLOUD_DIR",
")",
"{",
"this",
".",
"host",
"=",
"this",
".",
"host",
"?",
"this",
".",
"host",
":",
"{",
"}",
";",
"this",
".",
"host",
".",
"clouddir",
"=",
"process",
".",
"env",
".",
"CLOUD_DIR",
";",
"this",
".",
"host",
".",
"servoid",
"=",
"process",
".",
"env",
".",
"SERVO_ID",
";",
"}",
"return",
"out",
";",
"}"
]
| refines configure using server context | [
"refines",
"configure",
"using",
"server",
"context"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/utilities.js#L11-L40 |
|
46,263 | glennjones/text-autolinker | lib/utilities.js | function(path, callback) {
fs.readFile(path, 'utf8', function(err, data) {
if (!err) {
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
langPrefix: 'language-',
highlight: function(code, lang) {
return code;
}
});
data = marked(data);
}
callback(err, data);
});
} | javascript | function(path, callback) {
fs.readFile(path, 'utf8', function(err, data) {
if (!err) {
marked.setOptions({
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false,
langPrefix: 'language-',
highlight: function(code, lang) {
return code;
}
});
data = marked(data);
}
callback(err, data);
});
} | [
"function",
"(",
"path",
",",
"callback",
")",
"{",
"fs",
".",
"readFile",
"(",
"path",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"marked",
".",
"setOptions",
"(",
"{",
"gfm",
":",
"true",
",",
"tables",
":",
"true",
",",
"breaks",
":",
"false",
",",
"pedantic",
":",
"false",
",",
"sanitize",
":",
"true",
",",
"smartLists",
":",
"true",
",",
"smartypants",
":",
"false",
",",
"langPrefix",
":",
"'language-'",
",",
"highlight",
":",
"function",
"(",
"code",
",",
"lang",
")",
"{",
"return",
"code",
";",
"}",
"}",
")",
";",
"data",
"=",
"marked",
"(",
"data",
")",
";",
"}",
"callback",
"(",
"err",
",",
"data",
")",
";",
"}",
")",
";",
"}"
]
| read a file and converts the markdown to HTML | [
"read",
"a",
"file",
"and",
"converts",
"the",
"markdown",
"to",
"HTML"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/utilities.js#L44-L64 |
|
46,264 | glennjones/text-autolinker | lib/utilities.js | function(code, err, message) {
code = (code || isNaN(code)) ? code : 500;
err = (err) ? err : '';
message = (message) ? message : '';
return {
'code': code,
'error': err,
'message': message
};
} | javascript | function(code, err, message) {
code = (code || isNaN(code)) ? code : 500;
err = (err) ? err : '';
message = (message) ? message : '';
return {
'code': code,
'error': err,
'message': message
};
} | [
"function",
"(",
"code",
",",
"err",
",",
"message",
")",
"{",
"code",
"=",
"(",
"code",
"||",
"isNaN",
"(",
"code",
")",
")",
"?",
"code",
":",
"500",
";",
"err",
"=",
"(",
"err",
")",
"?",
"err",
":",
"''",
";",
"message",
"=",
"(",
"message",
")",
"?",
"message",
":",
"''",
";",
"return",
"{",
"'code'",
":",
"code",
",",
"'error'",
":",
"err",
",",
"'message'",
":",
"message",
"}",
";",
"}"
]
| return error object | [
"return",
"error",
"object"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/utilities.js#L79-L89 |
|
46,265 | yanni4night/django | lib/index.js | checkEnv | function checkEnv() {
async.series([
function(cb) {
childProcess.exec(
'python -c "import django; print(django.get_version())"',
function(err, version) {
if (err || !/^1\.7/.test(version)) {
return cb(new Error(
'Django 1.7 environment is not working'
));
}
cb();
});
}
], function(err) {
if (err) {
console.error(chalk.red('\nFATAL: ' + err.message +
'\n'));
}
});
} | javascript | function checkEnv() {
async.series([
function(cb) {
childProcess.exec(
'python -c "import django; print(django.get_version())"',
function(err, version) {
if (err || !/^1\.7/.test(version)) {
return cb(new Error(
'Django 1.7 environment is not working'
));
}
cb();
});
}
], function(err) {
if (err) {
console.error(chalk.red('\nFATAL: ' + err.message +
'\n'));
}
});
} | [
"function",
"checkEnv",
"(",
")",
"{",
"async",
".",
"series",
"(",
"[",
"function",
"(",
"cb",
")",
"{",
"childProcess",
".",
"exec",
"(",
"'python -c \"import django; print(django.get_version())\"'",
",",
"function",
"(",
"err",
",",
"version",
")",
"{",
"if",
"(",
"err",
"||",
"!",
"/",
"^1\\.7",
"/",
".",
"test",
"(",
"version",
")",
")",
"{",
"return",
"cb",
"(",
"new",
"Error",
"(",
"'Django 1.7 environment is not working'",
")",
")",
";",
"}",
"cb",
"(",
")",
";",
"}",
")",
";",
"}",
"]",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"chalk",
".",
"red",
"(",
"'\\nFATAL: '",
"+",
"err",
".",
"message",
"+",
"'\\n'",
")",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Check dependencies.
@since 0.1.1
@throws {Error} If checking failed. | [
"Check",
"dependencies",
"."
]
| 0aff5cf948373969ed10335c587e0301f4ef18af | https://github.com/yanni4night/django/blob/0aff5cf948373969ed10335c587e0301f4ef18af/lib/index.js#L49-L69 |
46,266 | yanni4night/django | lib/index.js | innerRender | function innerRender(from, template, data, callback) {
var args, proc, out = '',
err = '',
base,
strData;
if (arguments.length < 4) {
callback = data;
data = {};
}
if (!template || template.constructor !== String) {
return callback(new Error('"template" requires a non-empty string'));
}
if ('function' !== typeof callback) {
throw new Error('"callback" requires a function');
}
try {
//Make sure mock data could be stringified
strData = JSON.stringify(data);
} catch (e) {
return callback(e);
}
base = gConfigurations.template_dirs;
//If no template_dirs defined and is rendering a file,
//we reset the template_dirs to the dirname of the file,
//and set template as its basename
//
//e.g,
//
//django.configure({
// template_dirs: null
// });
//django.renderFile('test/case/index.html');
//
//equals
//
//django.configure({
// template_dirs: 'test/case'
// });
//django.renderFile('index.html')
//
//That affects @include tag in Django,
//see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include
//
if (('file' === from) && !base) {
base = path.resolve(path.dirname(template));
template = path.basename(template);
}
args = (('source' === from) ? [PYTHON] : [PYTHON, base, template]).map(function(item, idx) {
return idx ? encodeURIComponent(item) : item;
});
proc = childProcess.spawn('python', args);
//We use stdin to pass the mock data to avoid long shell arguments
proc.stdin.write(('source' === from ? (encodeURIComponent(template) +
'\n') : '') + strData + '\n'); //For python reading a line.
proc.stdout.on('data', function(data) {
//Here we get no string but buffer
out += data.toString('utf-8');
});
proc.stderr.on('data', function(data) {
err += data.toString('utf-8');
});
//What if blocked? We ignored it because this is not for production.
proc.on('exit', function() {
if (err) {
return callback(new Error(err));
} else {
return callback(null, out.replace(/\r(?=\r\n)/mg, '')); //A \r will always be prepend to \r\n
}
});
} | javascript | function innerRender(from, template, data, callback) {
var args, proc, out = '',
err = '',
base,
strData;
if (arguments.length < 4) {
callback = data;
data = {};
}
if (!template || template.constructor !== String) {
return callback(new Error('"template" requires a non-empty string'));
}
if ('function' !== typeof callback) {
throw new Error('"callback" requires a function');
}
try {
//Make sure mock data could be stringified
strData = JSON.stringify(data);
} catch (e) {
return callback(e);
}
base = gConfigurations.template_dirs;
//If no template_dirs defined and is rendering a file,
//we reset the template_dirs to the dirname of the file,
//and set template as its basename
//
//e.g,
//
//django.configure({
// template_dirs: null
// });
//django.renderFile('test/case/index.html');
//
//equals
//
//django.configure({
// template_dirs: 'test/case'
// });
//django.renderFile('index.html')
//
//That affects @include tag in Django,
//see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include
//
if (('file' === from) && !base) {
base = path.resolve(path.dirname(template));
template = path.basename(template);
}
args = (('source' === from) ? [PYTHON] : [PYTHON, base, template]).map(function(item, idx) {
return idx ? encodeURIComponent(item) : item;
});
proc = childProcess.spawn('python', args);
//We use stdin to pass the mock data to avoid long shell arguments
proc.stdin.write(('source' === from ? (encodeURIComponent(template) +
'\n') : '') + strData + '\n'); //For python reading a line.
proc.stdout.on('data', function(data) {
//Here we get no string but buffer
out += data.toString('utf-8');
});
proc.stderr.on('data', function(data) {
err += data.toString('utf-8');
});
//What if blocked? We ignored it because this is not for production.
proc.on('exit', function() {
if (err) {
return callback(new Error(err));
} else {
return callback(null, out.replace(/\r(?=\r\n)/mg, '')); //A \r will always be prepend to \r\n
}
});
} | [
"function",
"innerRender",
"(",
"from",
",",
"template",
",",
"data",
",",
"callback",
")",
"{",
"var",
"args",
",",
"proc",
",",
"out",
"=",
"''",
",",
"err",
"=",
"''",
",",
"base",
",",
"strData",
";",
"if",
"(",
"arguments",
".",
"length",
"<",
"4",
")",
"{",
"callback",
"=",
"data",
";",
"data",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"!",
"template",
"||",
"template",
".",
"constructor",
"!==",
"String",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"'\"template\" requires a non-empty string'",
")",
")",
";",
"}",
"if",
"(",
"'function'",
"!==",
"typeof",
"callback",
")",
"{",
"throw",
"new",
"Error",
"(",
"'\"callback\" requires a function'",
")",
";",
"}",
"try",
"{",
"//Make sure mock data could be stringified",
"strData",
"=",
"JSON",
".",
"stringify",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"callback",
"(",
"e",
")",
";",
"}",
"base",
"=",
"gConfigurations",
".",
"template_dirs",
";",
"//If no template_dirs defined and is rendering a file,",
"//we reset the template_dirs to the dirname of the file,",
"//and set template as its basename",
"//",
"//e.g,",
"//",
"//django.configure({",
"// template_dirs: null",
"// });",
"//django.renderFile('test/case/index.html');",
"//",
"//equals",
"//",
"//django.configure({",
"// template_dirs: 'test/case'",
"// });",
"//django.renderFile('index.html')",
"//",
"//That affects @include tag in Django,",
"//see https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#include",
"//",
"if",
"(",
"(",
"'file'",
"===",
"from",
")",
"&&",
"!",
"base",
")",
"{",
"base",
"=",
"path",
".",
"resolve",
"(",
"path",
".",
"dirname",
"(",
"template",
")",
")",
";",
"template",
"=",
"path",
".",
"basename",
"(",
"template",
")",
";",
"}",
"args",
"=",
"(",
"(",
"'source'",
"===",
"from",
")",
"?",
"[",
"PYTHON",
"]",
":",
"[",
"PYTHON",
",",
"base",
",",
"template",
"]",
")",
".",
"map",
"(",
"function",
"(",
"item",
",",
"idx",
")",
"{",
"return",
"idx",
"?",
"encodeURIComponent",
"(",
"item",
")",
":",
"item",
";",
"}",
")",
";",
"proc",
"=",
"childProcess",
".",
"spawn",
"(",
"'python'",
",",
"args",
")",
";",
"//We use stdin to pass the mock data to avoid long shell arguments",
"proc",
".",
"stdin",
".",
"write",
"(",
"(",
"'source'",
"===",
"from",
"?",
"(",
"encodeURIComponent",
"(",
"template",
")",
"+",
"'\\n'",
")",
":",
"''",
")",
"+",
"strData",
"+",
"'\\n'",
")",
";",
"//For python reading a line.",
"proc",
".",
"stdout",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"//Here we get no string but buffer",
"out",
"+=",
"data",
".",
"toString",
"(",
"'utf-8'",
")",
";",
"}",
")",
";",
"proc",
".",
"stderr",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"err",
"+=",
"data",
".",
"toString",
"(",
"'utf-8'",
")",
";",
"}",
")",
";",
"//What if blocked? We ignored it because this is not for production.",
"proc",
".",
"on",
"(",
"'exit'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"new",
"Error",
"(",
"err",
")",
")",
";",
"}",
"else",
"{",
"return",
"callback",
"(",
"null",
",",
"out",
".",
"replace",
"(",
"/",
"\\r(?=\\r\\n)",
"/",
"mg",
",",
"''",
")",
")",
";",
"//A \\r will always be prepend to \\r\\n",
"}",
"}",
")",
";",
"}"
]
| Render from a file or source codes.
@param {String} from source|file
@param {String} template
@param {Object} data
@param {Function} callback
@since 0.1.4 | [
"Render",
"from",
"a",
"file",
"or",
"source",
"codes",
"."
]
| 0aff5cf948373969ed10335c587e0301f4ef18af | https://github.com/yanni4night/django/blob/0aff5cf948373969ed10335c587e0301f4ef18af/lib/index.js#L79-L157 |
46,267 | AndiDittrich/Node.fs-magic | lib/untgz.js | untgz | function untgz(istream, dst){
// decompress
const tarStream = istream.pipe(_zlib.createGunzip());
// unpack
return _untar(tarStream, dst);
} | javascript | function untgz(istream, dst){
// decompress
const tarStream = istream.pipe(_zlib.createGunzip());
// unpack
return _untar(tarStream, dst);
} | [
"function",
"untgz",
"(",
"istream",
",",
"dst",
")",
"{",
"// decompress",
"const",
"tarStream",
"=",
"istream",
".",
"pipe",
"(",
"_zlib",
".",
"createGunzip",
"(",
")",
")",
";",
"// unpack",
"return",
"_untar",
"(",
"tarStream",
",",
"dst",
")",
";",
"}"
]
| decompress a tar.gz archive | [
"decompress",
"a",
"tar",
".",
"gz",
"archive"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/untgz.js#L5-L11 |
46,268 | canguruhh/metaversejs | src/encoder.js | encodeInputs | function encodeInputs(inputs, add_address_to_previous_output_index) {
//Initialize buffer and offset
let offset = 0;
var buffer = Buffer.allocUnsafe(100000);
//Write number of inputs
offset += bufferutils.writeVarInt(buffer, inputs.length, offset);
inputs.forEach((input, index) => {
//Write reversed hash
offset += Buffer.from(input.previous_output.hash, 'hex').reverse().copy(buffer, offset);
//Index
offset = buffer.writeUInt32LE(input.previous_output.index, offset);
if (add_address_to_previous_output_index !== undefined) {
if (index == add_address_to_previous_output_index) {
let lockregex = /^\[\ ([a-f0-9]+)\ \]\ numequalverify dup\ hash160\ \[ [a-f0-9]+\ \]\ equalverify\ checksig$/gi;
if (input.previous_output.script && input.previous_output.script.match(lockregex)) {
let locktime = lockregex.exec(input.previous_output.script.match(lockregex)[0])[1];
offset = writeScriptLockedPayToPubKeyHash(input.previous_output.address, locktime, buffer, offset);
} else {
if (Script.hasAttenuationModel(input.previous_output.script)) {
let params = Script.getAttenuationParams(input.previous_output.script);
offset = writeAttenuationScript(params.model, (params.hash !== '0000000000000000000000000000000000000000000000000000000000000000') ? params.hash : undefined, (params.index >= 0) ? params.index : undefined, input.previous_output.address, buffer, offset);
} else {
if (Script.isP2SH(input.previous_output.script)) {
let script_buffer = Buffer.from(input.redeem, 'hex');
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
} else {
if (input.previous_output.script) {
let script_buffer = Script.fromASM(input.previous_output.script).toBuffer()
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
} else {
offset = writeScriptPayToPubKeyHash(input.previous_output.address, buffer, offset);
}
}
}
}
} else {
offset = buffer.writeUInt8(0, offset);
}
} else {
//input script
let script_buffer = encodeInputScript(input.script);
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
}
offset = buffer.writeUInt32LE(input.sequence, offset);
});
return buffer.slice(0, offset);
} | javascript | function encodeInputs(inputs, add_address_to_previous_output_index) {
//Initialize buffer and offset
let offset = 0;
var buffer = Buffer.allocUnsafe(100000);
//Write number of inputs
offset += bufferutils.writeVarInt(buffer, inputs.length, offset);
inputs.forEach((input, index) => {
//Write reversed hash
offset += Buffer.from(input.previous_output.hash, 'hex').reverse().copy(buffer, offset);
//Index
offset = buffer.writeUInt32LE(input.previous_output.index, offset);
if (add_address_to_previous_output_index !== undefined) {
if (index == add_address_to_previous_output_index) {
let lockregex = /^\[\ ([a-f0-9]+)\ \]\ numequalverify dup\ hash160\ \[ [a-f0-9]+\ \]\ equalverify\ checksig$/gi;
if (input.previous_output.script && input.previous_output.script.match(lockregex)) {
let locktime = lockregex.exec(input.previous_output.script.match(lockregex)[0])[1];
offset = writeScriptLockedPayToPubKeyHash(input.previous_output.address, locktime, buffer, offset);
} else {
if (Script.hasAttenuationModel(input.previous_output.script)) {
let params = Script.getAttenuationParams(input.previous_output.script);
offset = writeAttenuationScript(params.model, (params.hash !== '0000000000000000000000000000000000000000000000000000000000000000') ? params.hash : undefined, (params.index >= 0) ? params.index : undefined, input.previous_output.address, buffer, offset);
} else {
if (Script.isP2SH(input.previous_output.script)) {
let script_buffer = Buffer.from(input.redeem, 'hex');
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
} else {
if (input.previous_output.script) {
let script_buffer = Script.fromASM(input.previous_output.script).toBuffer()
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
} else {
offset = writeScriptPayToPubKeyHash(input.previous_output.address, buffer, offset);
}
}
}
}
} else {
offset = buffer.writeUInt8(0, offset);
}
} else {
//input script
let script_buffer = encodeInputScript(input.script);
offset += bufferutils.writeVarInt(buffer, script_buffer.length, offset);
offset += script_buffer.copy(buffer, offset);
}
offset = buffer.writeUInt32LE(input.sequence, offset);
});
return buffer.slice(0, offset);
} | [
"function",
"encodeInputs",
"(",
"inputs",
",",
"add_address_to_previous_output_index",
")",
"{",
"//Initialize buffer and offset",
"let",
"offset",
"=",
"0",
";",
"var",
"buffer",
"=",
"Buffer",
".",
"allocUnsafe",
"(",
"100000",
")",
";",
"//Write number of inputs",
"offset",
"+=",
"bufferutils",
".",
"writeVarInt",
"(",
"buffer",
",",
"inputs",
".",
"length",
",",
"offset",
")",
";",
"inputs",
".",
"forEach",
"(",
"(",
"input",
",",
"index",
")",
"=>",
"{",
"//Write reversed hash",
"offset",
"+=",
"Buffer",
".",
"from",
"(",
"input",
".",
"previous_output",
".",
"hash",
",",
"'hex'",
")",
".",
"reverse",
"(",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"//Index",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"input",
".",
"previous_output",
".",
"index",
",",
"offset",
")",
";",
"if",
"(",
"add_address_to_previous_output_index",
"!==",
"undefined",
")",
"{",
"if",
"(",
"index",
"==",
"add_address_to_previous_output_index",
")",
"{",
"let",
"lockregex",
"=",
"/",
"^\\[\\ ([a-f0-9]+)\\ \\]\\ numequalverify dup\\ hash160\\ \\[ [a-f0-9]+\\ \\]\\ equalverify\\ checksig$",
"/",
"gi",
";",
"if",
"(",
"input",
".",
"previous_output",
".",
"script",
"&&",
"input",
".",
"previous_output",
".",
"script",
".",
"match",
"(",
"lockregex",
")",
")",
"{",
"let",
"locktime",
"=",
"lockregex",
".",
"exec",
"(",
"input",
".",
"previous_output",
".",
"script",
".",
"match",
"(",
"lockregex",
")",
"[",
"0",
"]",
")",
"[",
"1",
"]",
";",
"offset",
"=",
"writeScriptLockedPayToPubKeyHash",
"(",
"input",
".",
"previous_output",
".",
"address",
",",
"locktime",
",",
"buffer",
",",
"offset",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Script",
".",
"hasAttenuationModel",
"(",
"input",
".",
"previous_output",
".",
"script",
")",
")",
"{",
"let",
"params",
"=",
"Script",
".",
"getAttenuationParams",
"(",
"input",
".",
"previous_output",
".",
"script",
")",
";",
"offset",
"=",
"writeAttenuationScript",
"(",
"params",
".",
"model",
",",
"(",
"params",
".",
"hash",
"!==",
"'0000000000000000000000000000000000000000000000000000000000000000'",
")",
"?",
"params",
".",
"hash",
":",
"undefined",
",",
"(",
"params",
".",
"index",
">=",
"0",
")",
"?",
"params",
".",
"index",
":",
"undefined",
",",
"input",
".",
"previous_output",
".",
"address",
",",
"buffer",
",",
"offset",
")",
";",
"}",
"else",
"{",
"if",
"(",
"Script",
".",
"isP2SH",
"(",
"input",
".",
"previous_output",
".",
"script",
")",
")",
"{",
"let",
"script_buffer",
"=",
"Buffer",
".",
"from",
"(",
"input",
".",
"redeem",
",",
"'hex'",
")",
";",
"offset",
"+=",
"bufferutils",
".",
"writeVarInt",
"(",
"buffer",
",",
"script_buffer",
".",
"length",
",",
"offset",
")",
";",
"offset",
"+=",
"script_buffer",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"}",
"else",
"{",
"if",
"(",
"input",
".",
"previous_output",
".",
"script",
")",
"{",
"let",
"script_buffer",
"=",
"Script",
".",
"fromASM",
"(",
"input",
".",
"previous_output",
".",
"script",
")",
".",
"toBuffer",
"(",
")",
"offset",
"+=",
"bufferutils",
".",
"writeVarInt",
"(",
"buffer",
",",
"script_buffer",
".",
"length",
",",
"offset",
")",
";",
"offset",
"+=",
"script_buffer",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"}",
"else",
"{",
"offset",
"=",
"writeScriptPayToPubKeyHash",
"(",
"input",
".",
"previous_output",
".",
"address",
",",
"buffer",
",",
"offset",
")",
";",
"}",
"}",
"}",
"}",
"}",
"else",
"{",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"0",
",",
"offset",
")",
";",
"}",
"}",
"else",
"{",
"//input script",
"let",
"script_buffer",
"=",
"encodeInputScript",
"(",
"input",
".",
"script",
")",
";",
"offset",
"+=",
"bufferutils",
".",
"writeVarInt",
"(",
"buffer",
",",
"script_buffer",
".",
"length",
",",
"offset",
")",
";",
"offset",
"+=",
"script_buffer",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"}",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"input",
".",
"sequence",
",",
"offset",
")",
";",
"}",
")",
";",
"return",
"buffer",
".",
"slice",
"(",
"0",
",",
"offset",
")",
";",
"}"
]
| Encode raw transactions inputs
@param {Array<input>} inputs
@param {Number} add_address_to_previous_output_index (optional) Index of an input thats previous output address should be added (needed for signing).
@returns {Buffer}
@throws {Error} | [
"Encode",
"raw",
"transactions",
"inputs"
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L53-L104 |
46,269 | canguruhh/metaversejs | src/encoder.js | encodeAttachmentMessage | function encodeAttachmentMessage(buffer, offset, message) {
if (message == undefined)
throw Error('Specify message');
offset += encodeString(buffer, message, offset);
return offset;
} | javascript | function encodeAttachmentMessage(buffer, offset, message) {
if (message == undefined)
throw Error('Specify message');
offset += encodeString(buffer, message, offset);
return offset;
} | [
"function",
"encodeAttachmentMessage",
"(",
"buffer",
",",
"offset",
",",
"message",
")",
"{",
"if",
"(",
"message",
"==",
"undefined",
")",
"throw",
"Error",
"(",
"'Specify message'",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"message",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Helper function to encode the attachment for a message.
@param {Buffer} buffer
@param {Number} offset
@param {string} message
@returns {Number} New offset
@throws {Error} | [
"Helper",
"function",
"to",
"encode",
"the",
"attachment",
"for",
"a",
"message",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L230-L235 |
46,270 | canguruhh/metaversejs | src/encoder.js | encodeAttachmentMSTTransfer | function encodeAttachmentMSTTransfer(buffer, offset, symbol, quantity) {
if (symbol == undefined)
throw Error('Specify output asset');
if (quantity == undefined)
throw Error('Specify output quanity');
offset = buffer.writeUInt32LE(Constants.MST.STATUS.TRANSFER, offset);
offset += encodeString(buffer, symbol, offset);
offset = bufferutils.writeUInt64LE(buffer, quantity, offset);
return offset;
} | javascript | function encodeAttachmentMSTTransfer(buffer, offset, symbol, quantity) {
if (symbol == undefined)
throw Error('Specify output asset');
if (quantity == undefined)
throw Error('Specify output quanity');
offset = buffer.writeUInt32LE(Constants.MST.STATUS.TRANSFER, offset);
offset += encodeString(buffer, symbol, offset);
offset = bufferutils.writeUInt64LE(buffer, quantity, offset);
return offset;
} | [
"function",
"encodeAttachmentMSTTransfer",
"(",
"buffer",
",",
"offset",
",",
"symbol",
",",
"quantity",
")",
"{",
"if",
"(",
"symbol",
"==",
"undefined",
")",
"throw",
"Error",
"(",
"'Specify output asset'",
")",
";",
"if",
"(",
"quantity",
"==",
"undefined",
")",
"throw",
"Error",
"(",
"'Specify output quanity'",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"Constants",
".",
"MST",
".",
"STATUS",
".",
"TRANSFER",
",",
"offset",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"symbol",
",",
"offset",
")",
";",
"offset",
"=",
"bufferutils",
".",
"writeUInt64LE",
"(",
"buffer",
",",
"quantity",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Helper function to encode the attachment for an asset transfer.
@param {Buffer} buffer
@param {Number} offset
@param {String} symbol
@param {Number} quantity
@returns {Number} New offset
@throws {Error} | [
"Helper",
"function",
"to",
"encode",
"the",
"attachment",
"for",
"an",
"asset",
"transfer",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L246-L255 |
46,271 | canguruhh/metaversejs | src/encoder.js | encodeAttachmentDid | function encodeAttachmentDid(buffer, offset, attachment_data) {
offset = buffer.writeUInt32LE(attachment_data.status, offset);
offset += encodeString(buffer, attachment_data.symbol, offset);
offset += encodeString(buffer, attachment_data.address, offset);
return offset;
} | javascript | function encodeAttachmentDid(buffer, offset, attachment_data) {
offset = buffer.writeUInt32LE(attachment_data.status, offset);
offset += encodeString(buffer, attachment_data.symbol, offset);
offset += encodeString(buffer, attachment_data.address, offset);
return offset;
} | [
"function",
"encodeAttachmentDid",
"(",
"buffer",
",",
"offset",
",",
"attachment_data",
")",
"{",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"attachment_data",
".",
"status",
",",
"offset",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"symbol",
",",
"offset",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"address",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Helper function to encode the attachment for a new did.
@param {Buffer} buffer
@param {Number} offset
@param {Number} attachment_data
@returns {Number} New offset
@throws {Error} | [
"Helper",
"function",
"to",
"encode",
"the",
"attachment",
"for",
"a",
"new",
"did",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L265-L270 |
46,272 | canguruhh/metaversejs | src/encoder.js | encodeAttachmentCert | function encodeAttachmentCert(buffer, offset, attachment_data) {
offset += encodeString(buffer, attachment_data.symbol, offset);
offset += encodeString(buffer, attachment_data.owner, offset);
offset += encodeString(buffer, attachment_data.address, offset);
offset = buffer.writeUInt32LE(attachment_data.cert, offset);
offset = buffer.writeUInt8(attachment_data.status, offset);
if (attachment_data.content) {
offset += encodeString(buffer, attachment_data.content, offset);
}
return offset;
} | javascript | function encodeAttachmentCert(buffer, offset, attachment_data) {
offset += encodeString(buffer, attachment_data.symbol, offset);
offset += encodeString(buffer, attachment_data.owner, offset);
offset += encodeString(buffer, attachment_data.address, offset);
offset = buffer.writeUInt32LE(attachment_data.cert, offset);
offset = buffer.writeUInt8(attachment_data.status, offset);
if (attachment_data.content) {
offset += encodeString(buffer, attachment_data.content, offset);
}
return offset;
} | [
"function",
"encodeAttachmentCert",
"(",
"buffer",
",",
"offset",
",",
"attachment_data",
")",
"{",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"symbol",
",",
"offset",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"owner",
",",
"offset",
")",
";",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"address",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"attachment_data",
".",
"cert",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"attachment_data",
".",
"status",
",",
"offset",
")",
";",
"if",
"(",
"attachment_data",
".",
"content",
")",
"{",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"content",
",",
"offset",
")",
";",
"}",
"return",
"offset",
";",
"}"
]
| Helper function to encode the attachment for a certificate.
@param {Buffer} buffer
@param {Number} offset
@param {Number} attachment_data
@returns {Number} New offset
@throws {Error} | [
"Helper",
"function",
"to",
"encode",
"the",
"attachment",
"for",
"a",
"certificate",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L280-L290 |
46,273 | canguruhh/metaversejs | src/encoder.js | encodeAttachmentAssetIssue | function encodeAttachmentAssetIssue(buffer, offset, attachment_data) {
offset = buffer.writeUInt32LE(attachment_data.status, offset);
//Encode symbol
offset += encodeString(buffer, attachment_data.symbol, offset);
//Encode maximum supply
offset = bufferutils.writeUInt64LE(buffer, attachment_data.max_supply, offset);
//Encode precision
offset = buffer.writeUInt8(attachment_data.precision, offset);
//Encode secondary issue threshold
offset = buffer.writeUInt8((attachment_data.secondaryissue_threshold) ? attachment_data.secondaryissue_threshold : 0, offset);
offset += buffer.write("0000", offset, 2, 'hex');
//Encode issuer
offset += encodeString(buffer, attachment_data.issuer, offset);
//Encode recipient address
offset += encodeString(buffer, attachment_data.address, offset);
//Encode description
offset += encodeString(buffer, attachment_data.description, offset);
return offset;
} | javascript | function encodeAttachmentAssetIssue(buffer, offset, attachment_data) {
offset = buffer.writeUInt32LE(attachment_data.status, offset);
//Encode symbol
offset += encodeString(buffer, attachment_data.symbol, offset);
//Encode maximum supply
offset = bufferutils.writeUInt64LE(buffer, attachment_data.max_supply, offset);
//Encode precision
offset = buffer.writeUInt8(attachment_data.precision, offset);
//Encode secondary issue threshold
offset = buffer.writeUInt8((attachment_data.secondaryissue_threshold) ? attachment_data.secondaryissue_threshold : 0, offset);
offset += buffer.write("0000", offset, 2, 'hex');
//Encode issuer
offset += encodeString(buffer, attachment_data.issuer, offset);
//Encode recipient address
offset += encodeString(buffer, attachment_data.address, offset);
//Encode description
offset += encodeString(buffer, attachment_data.description, offset);
return offset;
} | [
"function",
"encodeAttachmentAssetIssue",
"(",
"buffer",
",",
"offset",
",",
"attachment_data",
")",
"{",
"offset",
"=",
"buffer",
".",
"writeUInt32LE",
"(",
"attachment_data",
".",
"status",
",",
"offset",
")",
";",
"//Encode symbol",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"symbol",
",",
"offset",
")",
";",
"//Encode maximum supply",
"offset",
"=",
"bufferutils",
".",
"writeUInt64LE",
"(",
"buffer",
",",
"attachment_data",
".",
"max_supply",
",",
"offset",
")",
";",
"//Encode precision",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"attachment_data",
".",
"precision",
",",
"offset",
")",
";",
"//Encode secondary issue threshold",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"(",
"attachment_data",
".",
"secondaryissue_threshold",
")",
"?",
"attachment_data",
".",
"secondaryissue_threshold",
":",
"0",
",",
"offset",
")",
";",
"offset",
"+=",
"buffer",
".",
"write",
"(",
"\"0000\"",
",",
"offset",
",",
"2",
",",
"'hex'",
")",
";",
"//Encode issuer",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"issuer",
",",
"offset",
")",
";",
"//Encode recipient address",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"address",
",",
"offset",
")",
";",
"//Encode description",
"offset",
"+=",
"encodeString",
"(",
"buffer",
",",
"attachment_data",
".",
"description",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Helper function to encode the attachment for a new asset.
@param {Buffer} buffer
@param {Number} offset
@param {Number} attachment_data
@returns {Number} New offset
@throws {Error} | [
"Helper",
"function",
"to",
"encode",
"the",
"attachment",
"for",
"a",
"new",
"asset",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L300-L318 |
46,274 | canguruhh/metaversejs | src/encoder.js | writeScriptPayToScriptHash | function writeScriptPayToScriptHash(scripthash, buffer, offset) {
offset = buffer.writeUInt8(23, offset); //Script length
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(scripthash, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUAL, offset);
return offset;
} | javascript | function writeScriptPayToScriptHash(scripthash, buffer, offset) {
offset = buffer.writeUInt8(23, offset); //Script length
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(scripthash, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUAL, offset);
return offset;
} | [
"function",
"writeScriptPayToScriptHash",
"(",
"scripthash",
",",
"buffer",
",",
"offset",
")",
"{",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"23",
",",
"offset",
")",
";",
"//Script length",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_HASH160",
",",
"offset",
")",
";",
"//Write previous output address",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"20",
",",
"offset",
")",
";",
"//Address length",
"offset",
"+=",
"Buffer",
".",
"from",
"(",
"base58check",
".",
"decode",
"(",
"scripthash",
",",
"'hex'",
")",
".",
"data",
",",
"'hex'",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"//Static transfer stuff",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_EQUAL",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Write p2sh to the given buffer.
@param {String} scripthash For example multisig address
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset | [
"Write",
"p2sh",
"to",
"the",
"given",
"buffer",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L372-L381 |
46,275 | canguruhh/metaversejs | src/encoder.js | writeScriptPayToPubKeyHash | function writeScriptPayToPubKeyHash(address, buffer, offset) {
offset = buffer.writeUInt8(25, offset); //Script length
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | javascript | function writeScriptPayToPubKeyHash(address, buffer, offset) {
offset = buffer.writeUInt8(25, offset); //Script length
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | [
"function",
"writeScriptPayToPubKeyHash",
"(",
"address",
",",
"buffer",
",",
"offset",
")",
"{",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"25",
",",
"offset",
")",
";",
"//Script length",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_DUP",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_HASH160",
",",
"offset",
")",
";",
"//Write previous output address",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"20",
",",
"offset",
")",
";",
"//Address length",
"offset",
"+=",
"Buffer",
".",
"from",
"(",
"base58check",
".",
"decode",
"(",
"address",
",",
"'hex'",
")",
".",
"data",
",",
"'hex'",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"//Static transfer stuff",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_EQUALVERIFY",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_CHECKSIG",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Write p2pkh to the given buffer.
@param {String} address
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset | [
"Write",
"p2pkh",
"to",
"the",
"given",
"buffer",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L390-L401 |
46,276 | canguruhh/metaversejs | src/encoder.js | writeAttenuationScript | function writeAttenuationScript(attenuation_string, from_tx, from_index, address, buffer, offset) {
let attenuation_buffer = Buffer.from(attenuation_string.toString('hex'));
offset += bufferutils.writeVarInt(buffer, 26 + attenuation_string.length + 40, offset);
offset = buffer.writeUInt8(77, offset);
offset = buffer.writeInt16LE(attenuation_string.length, offset);
offset += attenuation_buffer.copy(buffer, offset);
offset = buffer.writeUInt8(36, offset);
let hash = Buffer.from((from_tx != undefined) ? from_tx : '0000000000000000000000000000000000000000000000000000000000000000', 'hex').reverse();
let index = Buffer.from('ffffffff', 'hex');
if (from_index != undefined)
index.writeInt32LE(from_index, 0);
offset += Buffer.concat([hash, index]).copy(buffer, offset);
offset = buffer.writeUInt8(178, offset);
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | javascript | function writeAttenuationScript(attenuation_string, from_tx, from_index, address, buffer, offset) {
let attenuation_buffer = Buffer.from(attenuation_string.toString('hex'));
offset += bufferutils.writeVarInt(buffer, 26 + attenuation_string.length + 40, offset);
offset = buffer.writeUInt8(77, offset);
offset = buffer.writeInt16LE(attenuation_string.length, offset);
offset += attenuation_buffer.copy(buffer, offset);
offset = buffer.writeUInt8(36, offset);
let hash = Buffer.from((from_tx != undefined) ? from_tx : '0000000000000000000000000000000000000000000000000000000000000000', 'hex').reverse();
let index = Buffer.from('ffffffff', 'hex');
if (from_index != undefined)
index.writeInt32LE(from_index, 0);
offset += Buffer.concat([hash, index]).copy(buffer, offset);
offset = buffer.writeUInt8(178, offset);
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
//Static transfer stuff
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | [
"function",
"writeAttenuationScript",
"(",
"attenuation_string",
",",
"from_tx",
",",
"from_index",
",",
"address",
",",
"buffer",
",",
"offset",
")",
"{",
"let",
"attenuation_buffer",
"=",
"Buffer",
".",
"from",
"(",
"attenuation_string",
".",
"toString",
"(",
"'hex'",
")",
")",
";",
"offset",
"+=",
"bufferutils",
".",
"writeVarInt",
"(",
"buffer",
",",
"26",
"+",
"attenuation_string",
".",
"length",
"+",
"40",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"77",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeInt16LE",
"(",
"attenuation_string",
".",
"length",
",",
"offset",
")",
";",
"offset",
"+=",
"attenuation_buffer",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"36",
",",
"offset",
")",
";",
"let",
"hash",
"=",
"Buffer",
".",
"from",
"(",
"(",
"from_tx",
"!=",
"undefined",
")",
"?",
"from_tx",
":",
"'0000000000000000000000000000000000000000000000000000000000000000'",
",",
"'hex'",
")",
".",
"reverse",
"(",
")",
";",
"let",
"index",
"=",
"Buffer",
".",
"from",
"(",
"'ffffffff'",
",",
"'hex'",
")",
";",
"if",
"(",
"from_index",
"!=",
"undefined",
")",
"index",
".",
"writeInt32LE",
"(",
"from_index",
",",
"0",
")",
";",
"offset",
"+=",
"Buffer",
".",
"concat",
"(",
"[",
"hash",
",",
"index",
"]",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"178",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_DUP",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_HASH160",
",",
"offset",
")",
";",
"//Write previous output address",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"20",
",",
"offset",
")",
";",
"//Address length",
"offset",
"+=",
"Buffer",
".",
"from",
"(",
"base58check",
".",
"decode",
"(",
"address",
",",
"'hex'",
")",
".",
"data",
",",
"'hex'",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"//Static transfer stuff",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_EQUALVERIFY",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_CHECKSIG",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Write p2pkh attenuation script to the given buffer.
@param {String} attenuation_string
@param {String} from_tx
@param {number} index
@param {String} address
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset | [
"Write",
"p2pkh",
"attenuation",
"script",
"to",
"the",
"given",
"buffer",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L413-L435 |
46,277 | canguruhh/metaversejs | src/encoder.js | writeScriptLockedPayToPubKeyHash | function writeScriptLockedPayToPubKeyHash(address, locktime, buffer, offset) {
let locktime_buffer = Buffer.from(locktime, 'hex');
offset = buffer.writeUInt8(27 + locktime_buffer.length, offset); //Script length
offset = buffer.writeUInt8(locktime_buffer.length, offset); //Length of locktime
offset += locktime_buffer.copy(buffer, offset);
offset = buffer.writeUInt8(OPS.OP_NUMEQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | javascript | function writeScriptLockedPayToPubKeyHash(address, locktime, buffer, offset) {
let locktime_buffer = Buffer.from(locktime, 'hex');
offset = buffer.writeUInt8(27 + locktime_buffer.length, offset); //Script length
offset = buffer.writeUInt8(locktime_buffer.length, offset); //Length of locktime
offset += locktime_buffer.copy(buffer, offset);
offset = buffer.writeUInt8(OPS.OP_NUMEQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_DUP, offset);
offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
//Write previous output address
offset = buffer.writeUInt8(20, offset); //Address length
offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
return offset;
} | [
"function",
"writeScriptLockedPayToPubKeyHash",
"(",
"address",
",",
"locktime",
",",
"buffer",
",",
"offset",
")",
"{",
"let",
"locktime_buffer",
"=",
"Buffer",
".",
"from",
"(",
"locktime",
",",
"'hex'",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"27",
"+",
"locktime_buffer",
".",
"length",
",",
"offset",
")",
";",
"//Script length",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"locktime_buffer",
".",
"length",
",",
"offset",
")",
";",
"//Length of locktime",
"offset",
"+=",
"locktime_buffer",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_NUMEQUALVERIFY",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_DUP",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_HASH160",
",",
"offset",
")",
";",
"//Write previous output address",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"20",
",",
"offset",
")",
";",
"//Address length",
"offset",
"+=",
"Buffer",
".",
"from",
"(",
"base58check",
".",
"decode",
"(",
"address",
",",
"'hex'",
")",
".",
"data",
",",
"'hex'",
")",
".",
"copy",
"(",
"buffer",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_EQUALVERIFY",
",",
"offset",
")",
";",
"offset",
"=",
"buffer",
".",
"writeUInt8",
"(",
"OPS",
".",
"OP_CHECKSIG",
",",
"offset",
")",
";",
"return",
"offset",
";",
"}"
]
| Write locked p2pkh to the given buffer.
@param {String} address
@param {String} locktime little endian hex
@param {Buffer} buffer
@param {Number} offset
@returns {Number} new offset | [
"Write",
"locked",
"p2pkh",
"to",
"the",
"given",
"buffer",
"."
]
| d79471978d9e4bed277d3c12918a0f0c2a14a498 | https://github.com/canguruhh/metaversejs/blob/d79471978d9e4bed277d3c12918a0f0c2a14a498/src/encoder.js#L445-L459 |
46,278 | gogoyqj/karma-event-driver-ext | src/event-driver-hooks.js | loadScript | async function loadScript(src) {
let script = document.createElement('script');
script.type = 'text/javascript';
let rs, rj, timer;
script.onload = () => {
script.onload = null;
clearTimeout(timer);
rs();
};
let prom = new Promise((resolve, reject) => {
rs = resolve;
rj = reject;
});
script.src = src;
document.head.appendChild(script);
timer = setTimeout(() => rj('load ' + src + ' time out'), 10000);
return prom;
} | javascript | async function loadScript(src) {
let script = document.createElement('script');
script.type = 'text/javascript';
let rs, rj, timer;
script.onload = () => {
script.onload = null;
clearTimeout(timer);
rs();
};
let prom = new Promise((resolve, reject) => {
rs = resolve;
rj = reject;
});
script.src = src;
document.head.appendChild(script);
timer = setTimeout(() => rj('load ' + src + ' time out'), 10000);
return prom;
} | [
"async",
"function",
"loadScript",
"(",
"src",
")",
"{",
"let",
"script",
"=",
"document",
".",
"createElement",
"(",
"'script'",
")",
";",
"script",
".",
"type",
"=",
"'text/javascript'",
";",
"let",
"rs",
",",
"rj",
",",
"timer",
";",
"script",
".",
"onload",
"=",
"(",
")",
"=>",
"{",
"script",
".",
"onload",
"=",
"null",
";",
"clearTimeout",
"(",
"timer",
")",
";",
"rs",
"(",
")",
";",
"}",
";",
"let",
"prom",
"=",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"rs",
"=",
"resolve",
";",
"rj",
"=",
"reject",
";",
"}",
")",
";",
"script",
".",
"src",
"=",
"src",
";",
"document",
".",
"head",
".",
"appendChild",
"(",
"script",
")",
";",
"timer",
"=",
"setTimeout",
"(",
"(",
")",
"=>",
"rj",
"(",
"'load '",
"+",
"src",
"+",
"' time out'",
")",
",",
"10000",
")",
";",
"return",
"prom",
";",
"}"
]
| load script async
@param {string} src
@return promise | [
"load",
"script",
"async"
]
| 82d550e2fe87400b70ea8f3dea33fa91a0b1c587 | https://github.com/gogoyqj/karma-event-driver-ext/blob/82d550e2fe87400b70ea8f3dea33fa91a0b1c587/src/event-driver-hooks.js#L203-L220 |
46,279 | gogoyqj/karma-event-driver-ext | src/event-driver-hooks.js | beforeEachHook | async function beforeEachHook(done) {
browser.__autoStart = browser.__prom = browser.__rejectSerial = browser.__resolveSerial = null;
done && done();
} | javascript | async function beforeEachHook(done) {
browser.__autoStart = browser.__prom = browser.__rejectSerial = browser.__resolveSerial = null;
done && done();
} | [
"async",
"function",
"beforeEachHook",
"(",
"done",
")",
"{",
"browser",
".",
"__autoStart",
"=",
"browser",
".",
"__prom",
"=",
"browser",
".",
"__rejectSerial",
"=",
"browser",
".",
"__resolveSerial",
"=",
"null",
";",
"done",
"&&",
"done",
"(",
")",
";",
"}"
]
| run before each test, reset browser status
@return promise | [
"run",
"before",
"each",
"test",
"reset",
"browser",
"status"
]
| 82d550e2fe87400b70ea8f3dea33fa91a0b1c587 | https://github.com/gogoyqj/karma-event-driver-ext/blob/82d550e2fe87400b70ea8f3dea33fa91a0b1c587/src/event-driver-hooks.js#L332-L335 |
46,280 | vfile/vfile-reporter-json | index.js | applicableMessages | function applicableMessages(messages, options) {
var length = messages.length
var index = -1
var result = []
if (options.silent) {
while (++index < length) {
if (messages[index].fatal) {
result.push(messages[index])
}
}
} else {
result = messages.concat()
}
return result
} | javascript | function applicableMessages(messages, options) {
var length = messages.length
var index = -1
var result = []
if (options.silent) {
while (++index < length) {
if (messages[index].fatal) {
result.push(messages[index])
}
}
} else {
result = messages.concat()
}
return result
} | [
"function",
"applicableMessages",
"(",
"messages",
",",
"options",
")",
"{",
"var",
"length",
"=",
"messages",
".",
"length",
"var",
"index",
"=",
"-",
"1",
"var",
"result",
"=",
"[",
"]",
"if",
"(",
"options",
".",
"silent",
")",
"{",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"messages",
"[",
"index",
"]",
".",
"fatal",
")",
"{",
"result",
".",
"push",
"(",
"messages",
"[",
"index",
"]",
")",
"}",
"}",
"}",
"else",
"{",
"result",
"=",
"messages",
".",
"concat",
"(",
")",
"}",
"return",
"result",
"}"
]
| Get applicable messages. | [
"Get",
"applicable",
"messages",
"."
]
| 26d843f681fb33ddf8b826e2908018f1cd82f8a1 | https://github.com/vfile/vfile-reporter-json/blob/26d843f681fb33ddf8b826e2908018f1cd82f8a1/index.js#L86-L102 |
46,281 | addaleax/remarkup | remarkup.js | copyAttributes | function copyAttributes (src, dst, ignored) {
ignored = ignored || [];
const srcAttribs = Object.keys(src.attribs || src.attributes);
for (let i = 0; i < srcAttribs.length; ++i) {
if (!ignored.test(srcAttribs[i], $(dst), $(src))) {
dst.attribs[srcAttribs[i]] = src.attribs[srcAttribs[i]];
}
}
} | javascript | function copyAttributes (src, dst, ignored) {
ignored = ignored || [];
const srcAttribs = Object.keys(src.attribs || src.attributes);
for (let i = 0; i < srcAttribs.length; ++i) {
if (!ignored.test(srcAttribs[i], $(dst), $(src))) {
dst.attribs[srcAttribs[i]] = src.attribs[srcAttribs[i]];
}
}
} | [
"function",
"copyAttributes",
"(",
"src",
",",
"dst",
",",
"ignored",
")",
"{",
"ignored",
"=",
"ignored",
"||",
"[",
"]",
";",
"const",
"srcAttribs",
"=",
"Object",
".",
"keys",
"(",
"src",
".",
"attribs",
"||",
"src",
".",
"attributes",
")",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"srcAttribs",
".",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"ignored",
".",
"test",
"(",
"srcAttribs",
"[",
"i",
"]",
",",
"$",
"(",
"dst",
")",
",",
"$",
"(",
"src",
")",
")",
")",
"{",
"dst",
".",
"attribs",
"[",
"srcAttribs",
"[",
"i",
"]",
"]",
"=",
"src",
".",
"attribs",
"[",
"srcAttribs",
"[",
"i",
"]",
"]",
";",
"}",
"}",
"}"
]
| copy all DOM attributes from src to dst | [
"copy",
"all",
"DOM",
"attributes",
"from",
"src",
"to",
"dst"
]
| 7a9a24881d593151bc65b9a851a00672a8e8060e | https://github.com/addaleax/remarkup/blob/7a9a24881d593151bc65b9a851a00672a8e8060e/remarkup.js#L426-L435 |
46,282 | laurent22/joplin-turndown-plugin-gfm | src/tables.js | tableShouldBeSkipped | function tableShouldBeSkipped(tableNode) {
if (!tableNode) return true;
if (!tableNode.rows) return true;
if (tableNode.rows.length <= 1 && tableNode.rows[0].childNodes.length <= 1) return true; // Table with only one cell
if (nodeContainsTable(tableNode)) return true;
return false;
} | javascript | function tableShouldBeSkipped(tableNode) {
if (!tableNode) return true;
if (!tableNode.rows) return true;
if (tableNode.rows.length <= 1 && tableNode.rows[0].childNodes.length <= 1) return true; // Table with only one cell
if (nodeContainsTable(tableNode)) return true;
return false;
} | [
"function",
"tableShouldBeSkipped",
"(",
"tableNode",
")",
"{",
"if",
"(",
"!",
"tableNode",
")",
"return",
"true",
";",
"if",
"(",
"!",
"tableNode",
".",
"rows",
")",
"return",
"true",
";",
"if",
"(",
"tableNode",
".",
"rows",
".",
"length",
"<=",
"1",
"&&",
"tableNode",
".",
"rows",
"[",
"0",
"]",
".",
"childNodes",
".",
"length",
"<=",
"1",
")",
"return",
"true",
";",
"// Table with only one cell",
"if",
"(",
"nodeContainsTable",
"(",
"tableNode",
")",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
]
| Various conditions under which a table should be skipped - i.e. each cell will be rendered one after the other as if they were paragraphs. | [
"Various",
"conditions",
"under",
"which",
"a",
"table",
"should",
"be",
"skipped",
"-",
"i",
".",
"e",
".",
"each",
"cell",
"will",
"be",
"rendered",
"one",
"after",
"the",
"other",
"as",
"if",
"they",
"were",
"paragraphs",
"."
]
| 54f84c12fd29cd4e773a77bec060d5d46bf0815b | https://github.com/laurent22/joplin-turndown-plugin-gfm/blob/54f84c12fd29cd4e773a77bec060d5d46bf0815b/src/tables.js#L126-L132 |
46,283 | AndiDittrich/Node.fs-magic | lib/gzip.js | gzip | async function gzip(input, dst, level=4){
// is input a filename or stream ?
if (typeof input === 'string'){
input = await _fileInputStream(input);
}
// compress
const gzipStream = input.pipe(_zlib.createGzip({
level: level
}));
// write content to file
return _fileOutputStream(gzipStream, dst);
} | javascript | async function gzip(input, dst, level=4){
// is input a filename or stream ?
if (typeof input === 'string'){
input = await _fileInputStream(input);
}
// compress
const gzipStream = input.pipe(_zlib.createGzip({
level: level
}));
// write content to file
return _fileOutputStream(gzipStream, dst);
} | [
"async",
"function",
"gzip",
"(",
"input",
",",
"dst",
",",
"level",
"=",
"4",
")",
"{",
"// is input a filename or stream ?",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
")",
"{",
"input",
"=",
"await",
"_fileInputStream",
"(",
"input",
")",
";",
"}",
"// compress",
"const",
"gzipStream",
"=",
"input",
".",
"pipe",
"(",
"_zlib",
".",
"createGzip",
"(",
"{",
"level",
":",
"level",
"}",
")",
")",
";",
"// write content to file",
"return",
"_fileOutputStream",
"(",
"gzipStream",
",",
"dst",
")",
";",
"}"
]
| compress a file | [
"compress",
"a",
"file"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/gzip.js#L6-L19 |
46,284 | brentertz/scapegoat | index.js | function(html) {
if (!html) {
return '';
}
var re = new RegExp('(' + Object.keys(chars).join('|') + ')', 'g');
return String(html).replace(re, function(match) {
return chars[match];
});
} | javascript | function(html) {
if (!html) {
return '';
}
var re = new RegExp('(' + Object.keys(chars).join('|') + ')', 'g');
return String(html).replace(re, function(match) {
return chars[match];
});
} | [
"function",
"(",
"html",
")",
"{",
"if",
"(",
"!",
"html",
")",
"{",
"return",
"''",
";",
"}",
"var",
"re",
"=",
"new",
"RegExp",
"(",
"'('",
"+",
"Object",
".",
"keys",
"(",
"chars",
")",
".",
"join",
"(",
"'|'",
")",
"+",
"')'",
",",
"'g'",
")",
";",
"return",
"String",
"(",
"html",
")",
".",
"replace",
"(",
"re",
",",
"function",
"(",
"match",
")",
"{",
"return",
"chars",
"[",
"match",
"]",
";",
"}",
")",
";",
"}"
]
| Unescape special characters in the given string of html.
@param {String} html
@return {String} | [
"Unescape",
"special",
"characters",
"in",
"the",
"given",
"string",
"of",
"html",
"."
]
| 671a59ecf01ce604a44bca0fc9b64f5dbe2f487d | https://github.com/brentertz/scapegoat/blob/671a59ecf01ce604a44bca0fc9b64f5dbe2f487d/index.js#L47-L57 |
|
46,285 | cognitom/felt | lib/config-builder.js | isInsideDir | function isInsideDir(dir, targetDir) {
if (targetDir == dir) return false
if (targetDir == '.') return dir
const relative = path.relative(targetDir, dir)
if (/^\.\./.test(relative)) return false
return relative
} | javascript | function isInsideDir(dir, targetDir) {
if (targetDir == dir) return false
if (targetDir == '.') return dir
const relative = path.relative(targetDir, dir)
if (/^\.\./.test(relative)) return false
return relative
} | [
"function",
"isInsideDir",
"(",
"dir",
",",
"targetDir",
")",
"{",
"if",
"(",
"targetDir",
"==",
"dir",
")",
"return",
"false",
"if",
"(",
"targetDir",
"==",
"'.'",
")",
"return",
"dir",
"const",
"relative",
"=",
"path",
".",
"relative",
"(",
"targetDir",
",",
"dir",
")",
"if",
"(",
"/",
"^\\.\\.",
"/",
".",
"test",
"(",
"relative",
")",
")",
"return",
"false",
"return",
"relative",
"}"
]
| If dir is inside targetDir, return the relative path
If else, return false | [
"If",
"dir",
"is",
"inside",
"targetDir",
"return",
"the",
"relative",
"path",
"If",
"else",
"return",
"false"
]
| e97218aef9876ebdb2e6047138afe64ed37a4c83 | https://github.com/cognitom/felt/blob/e97218aef9876ebdb2e6047138afe64ed37a4c83/lib/config-builder.js#L58-L64 |
46,286 | sir-dunxalot/ember-cli-modernizr | vendor/modernizr-development.js | injectElementWithStyles | function injectElementWithStyles( rule, callback, nodes, testnames ) {
var mod = 'modernizr';
var style;
var ret;
var node;
var docOverflow;
var div = createElement('div');
var body = getBody();
if ( parseInt(nodes, 10) ) {
// In order not to give false positives we create a node for each test
// This also allows the method to scale for unspecified uses
while ( nodes-- ) {
node = createElement('div');
node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
div.appendChild(node);
}
}
// <style> elements in IE6-9 are considered 'NoScope' elements and therefore will be removed
// when injected with innerHTML. To get around this you need to prepend the 'NoScope' element
// with a 'scoped' element, in our case the soft-hyphen entity as it won't mess with our measurements.
// msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx
// Documents served as xml will throw if using ­ so use xml friendly encoded version. See issue #277
style = ['­','<style id="s', mod, '">', rule, '</style>'].join('');
div.id = mod;
// IE6 will false positive on some tests due to the style element inside the test div somehow interfering offsetHeight, so insert it into body or fakebody.
// Opera will act all quirky when injecting elements in documentElement when page is served as xml, needs fakebody too. #270
(!body.fake ? div : body).innerHTML += style;
body.appendChild(div);
if ( body.fake ) {
//avoid crashing IE8, if background image is used
body.style.background = '';
//Safari 5.13/5.1.4 OSX stops loading if ::-webkit-scrollbar is used and scrollbars are visible
body.style.overflow = 'hidden';
docOverflow = docElement.style.overflow;
docElement.style.overflow = 'hidden';
docElement.appendChild(body);
}
ret = callback(div, rule);
// If this is done after page load we don't want to remove the body so check if body exists
if ( body.fake ) {
body.parentNode.removeChild(body);
docElement.style.overflow = docOverflow;
// Trigger layout so kinetic scrolling isn't disabled in iOS6+
docElement.offsetHeight;
} else {
div.parentNode.removeChild(div);
}
return !!ret;
} | javascript | function injectElementWithStyles( rule, callback, nodes, testnames ) {
var mod = 'modernizr';
var style;
var ret;
var node;
var docOverflow;
var div = createElement('div');
var body = getBody();
if ( parseInt(nodes, 10) ) {
// In order not to give false positives we create a node for each test
// This also allows the method to scale for unspecified uses
while ( nodes-- ) {
node = createElement('div');
node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
div.appendChild(node);
}
}
// <style> elements in IE6-9 are considered 'NoScope' elements and therefore will be removed
// when injected with innerHTML. To get around this you need to prepend the 'NoScope' element
// with a 'scoped' element, in our case the soft-hyphen entity as it won't mess with our measurements.
// msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx
// Documents served as xml will throw if using ­ so use xml friendly encoded version. See issue #277
style = ['­','<style id="s', mod, '">', rule, '</style>'].join('');
div.id = mod;
// IE6 will false positive on some tests due to the style element inside the test div somehow interfering offsetHeight, so insert it into body or fakebody.
// Opera will act all quirky when injecting elements in documentElement when page is served as xml, needs fakebody too. #270
(!body.fake ? div : body).innerHTML += style;
body.appendChild(div);
if ( body.fake ) {
//avoid crashing IE8, if background image is used
body.style.background = '';
//Safari 5.13/5.1.4 OSX stops loading if ::-webkit-scrollbar is used and scrollbars are visible
body.style.overflow = 'hidden';
docOverflow = docElement.style.overflow;
docElement.style.overflow = 'hidden';
docElement.appendChild(body);
}
ret = callback(div, rule);
// If this is done after page load we don't want to remove the body so check if body exists
if ( body.fake ) {
body.parentNode.removeChild(body);
docElement.style.overflow = docOverflow;
// Trigger layout so kinetic scrolling isn't disabled in iOS6+
docElement.offsetHeight;
} else {
div.parentNode.removeChild(div);
}
return !!ret;
} | [
"function",
"injectElementWithStyles",
"(",
"rule",
",",
"callback",
",",
"nodes",
",",
"testnames",
")",
"{",
"var",
"mod",
"=",
"'modernizr'",
";",
"var",
"style",
";",
"var",
"ret",
";",
"var",
"node",
";",
"var",
"docOverflow",
";",
"var",
"div",
"=",
"createElement",
"(",
"'div'",
")",
";",
"var",
"body",
"=",
"getBody",
"(",
")",
";",
"if",
"(",
"parseInt",
"(",
"nodes",
",",
"10",
")",
")",
"{",
"// In order not to give false positives we create a node for each test",
"// This also allows the method to scale for unspecified uses",
"while",
"(",
"nodes",
"--",
")",
"{",
"node",
"=",
"createElement",
"(",
"'div'",
")",
";",
"node",
".",
"id",
"=",
"testnames",
"?",
"testnames",
"[",
"nodes",
"]",
":",
"mod",
"+",
"(",
"nodes",
"+",
"1",
")",
";",
"div",
".",
"appendChild",
"(",
"node",
")",
";",
"}",
"}",
"// <style> elements in IE6-9 are considered 'NoScope' elements and therefore will be removed",
"// when injected with innerHTML. To get around this you need to prepend the 'NoScope' element",
"// with a 'scoped' element, in our case the soft-hyphen entity as it won't mess with our measurements.",
"// msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx",
"// Documents served as xml will throw if using ­ so use xml friendly encoded version. See issue #277",
"style",
"=",
"[",
"'­'",
",",
"'<style id=\"s'",
",",
"mod",
",",
"'\">'",
",",
"rule",
",",
"'</style>'",
"]",
".",
"join",
"(",
"''",
")",
";",
"div",
".",
"id",
"=",
"mod",
";",
"// IE6 will false positive on some tests due to the style element inside the test div somehow interfering offsetHeight, so insert it into body or fakebody.",
"// Opera will act all quirky when injecting elements in documentElement when page is served as xml, needs fakebody too. #270",
"(",
"!",
"body",
".",
"fake",
"?",
"div",
":",
"body",
")",
".",
"innerHTML",
"+=",
"style",
";",
"body",
".",
"appendChild",
"(",
"div",
")",
";",
"if",
"(",
"body",
".",
"fake",
")",
"{",
"//avoid crashing IE8, if background image is used",
"body",
".",
"style",
".",
"background",
"=",
"''",
";",
"//Safari 5.13/5.1.4 OSX stops loading if ::-webkit-scrollbar is used and scrollbars are visible",
"body",
".",
"style",
".",
"overflow",
"=",
"'hidden'",
";",
"docOverflow",
"=",
"docElement",
".",
"style",
".",
"overflow",
";",
"docElement",
".",
"style",
".",
"overflow",
"=",
"'hidden'",
";",
"docElement",
".",
"appendChild",
"(",
"body",
")",
";",
"}",
"ret",
"=",
"callback",
"(",
"div",
",",
"rule",
")",
";",
"// If this is done after page load we don't want to remove the body so check if body exists",
"if",
"(",
"body",
".",
"fake",
")",
"{",
"body",
".",
"parentNode",
".",
"removeChild",
"(",
"body",
")",
";",
"docElement",
".",
"style",
".",
"overflow",
"=",
"docOverflow",
";",
"// Trigger layout so kinetic scrolling isn't disabled in iOS6+",
"docElement",
".",
"offsetHeight",
";",
"}",
"else",
"{",
"div",
".",
"parentNode",
".",
"removeChild",
"(",
"div",
")",
";",
"}",
"return",
"!",
"!",
"ret",
";",
"}"
]
| Inject element with style element and some CSS rules | [
"Inject",
"element",
"with",
"style",
"element",
"and",
"some",
"CSS",
"rules"
]
| 264735b535bce1b31648eaf884c7b681606e7f9b | https://github.com/sir-dunxalot/ember-cli-modernizr/blob/264735b535bce1b31648eaf884c7b681606e7f9b/vendor/modernizr-development.js#L5303-L5356 |
46,287 | areslabs/react-native-withcss | src/styleutil.js | legalStyle | function legalStyle(localStyle, legalSet) {
//flatten array, easy for manipulating data
let tmp = flattenArray(localStyle)
let obj = {}
for (let k in tmp) {
//save legal declaration to output
if (legalSet.has(k))
obj[k] = tmp[k];
}
return obj;
} | javascript | function legalStyle(localStyle, legalSet) {
//flatten array, easy for manipulating data
let tmp = flattenArray(localStyle)
let obj = {}
for (let k in tmp) {
//save legal declaration to output
if (legalSet.has(k))
obj[k] = tmp[k];
}
return obj;
} | [
"function",
"legalStyle",
"(",
"localStyle",
",",
"legalSet",
")",
"{",
"//flatten array, easy for manipulating data",
"let",
"tmp",
"=",
"flattenArray",
"(",
"localStyle",
")",
"let",
"obj",
"=",
"{",
"}",
"for",
"(",
"let",
"k",
"in",
"tmp",
")",
"{",
"//save legal declaration to output",
"if",
"(",
"legalSet",
".",
"has",
"(",
"k",
")",
")",
"obj",
"[",
"k",
"]",
"=",
"tmp",
"[",
"k",
"]",
";",
"}",
"return",
"obj",
";",
"}"
]
| constrain style,to remove illegal style warning,for example,
setting fontSize for View may cause warning in debugger mode.
@param localStyle style waiting for constraining.
@param legalSet specify legal style set for specify React Native element,eg. View or Text | [
"constrain",
"style",
"to",
"remove",
"illegal",
"style",
"warning",
"for",
"example",
"setting",
"fontSize",
"for",
"View",
"may",
"cause",
"warning",
"in",
"debugger",
"mode",
"."
]
| ed8f1a376e269a3cc37d67accdf4aee16d6abd32 | https://github.com/areslabs/react-native-withcss/blob/ed8f1a376e269a3cc37d67accdf4aee16d6abd32/src/styleutil.js#L15-L25 |
46,288 | areslabs/react-native-withcss | src/styleutil.js | flattenArray | function flattenArray(input, ans = {}) {
if (!input || !Array.isArray(input)) return input || {}
for (let k in input) {
//recursive logic
if (Array.isArray(input[k])) {
ans = flattenArray(input[k], ans)
} else {
ans = Object.assign({}, ans, input[k])
}
}
return ans
} | javascript | function flattenArray(input, ans = {}) {
if (!input || !Array.isArray(input)) return input || {}
for (let k in input) {
//recursive logic
if (Array.isArray(input[k])) {
ans = flattenArray(input[k], ans)
} else {
ans = Object.assign({}, ans, input[k])
}
}
return ans
} | [
"function",
"flattenArray",
"(",
"input",
",",
"ans",
"=",
"{",
"}",
")",
"{",
"if",
"(",
"!",
"input",
"||",
"!",
"Array",
".",
"isArray",
"(",
"input",
")",
")",
"return",
"input",
"||",
"{",
"}",
"for",
"(",
"let",
"k",
"in",
"input",
")",
"{",
"//recursive logic",
"if",
"(",
"Array",
".",
"isArray",
"(",
"input",
"[",
"k",
"]",
")",
")",
"{",
"ans",
"=",
"flattenArray",
"(",
"input",
"[",
"k",
"]",
",",
"ans",
")",
"}",
"else",
"{",
"ans",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"ans",
",",
"input",
"[",
"k",
"]",
")",
"}",
"}",
"return",
"ans",
"}"
]
| flatten deep array to plain object
@param input may deep array,e.g. [{color:'red'},[{fontSize:11}]]
@param ans output plain object,e,g. {color:'red',fontSize:11}
@returns plain object mentioned above | [
"flatten",
"deep",
"array",
"to",
"plain",
"object"
]
| ed8f1a376e269a3cc37d67accdf4aee16d6abd32 | https://github.com/areslabs/react-native-withcss/blob/ed8f1a376e269a3cc37d67accdf4aee16d6abd32/src/styleutil.js#L33-L44 |
46,289 | areslabs/react-native-withcss | src/styleutil.js | countCharFromStr | function countCharFromStr(str, ch) {
let strArr = [...str];
let count = 0;
for (let k in strArr) {
if (strArr[k] === ch) {
count++
}
}
return count
} | javascript | function countCharFromStr(str, ch) {
let strArr = [...str];
let count = 0;
for (let k in strArr) {
if (strArr[k] === ch) {
count++
}
}
return count
} | [
"function",
"countCharFromStr",
"(",
"str",
",",
"ch",
")",
"{",
"let",
"strArr",
"=",
"[",
"...",
"str",
"]",
";",
"let",
"count",
"=",
"0",
";",
"for",
"(",
"let",
"k",
"in",
"strArr",
")",
"{",
"if",
"(",
"strArr",
"[",
"k",
"]",
"===",
"ch",
")",
"{",
"count",
"++",
"}",
"}",
"return",
"count",
"}"
]
| count specific character in string
@param str target string
@param ch specific character
@returns {number} characters count | [
"count",
"specific",
"character",
"in",
"string"
]
| ed8f1a376e269a3cc37d67accdf4aee16d6abd32 | https://github.com/areslabs/react-native-withcss/blob/ed8f1a376e269a3cc37d67accdf4aee16d6abd32/src/styleutil.js#L87-L96 |
46,290 | AntonioMA/swagger-boilerplate | lib/setup-process.js | setupProcess | function setupProcess(aLogger, aDaemonize, aLogFile) {
aLogger.log('Setting up process. Run as a daemon:', aDaemonize, 'Logfile:', aLogFile);
// Since we might need to open some files, and that's an asynchronous operation,
// we will return a promise here that will never resolve on the parent (process will die instead)
// and will resolve on the child
return new Promise((resolve) => {
if (!aDaemonize) {
return resolve();
}
if (!aLogFile) {
return resolve({ stdout: process.stdout, stderr: process.stderr });
}
const fs = require('fs');
const outputStream = fs.createWriteStream(aLogFile);
outputStream.on('open', () => resolve({
stdout: outputStream,
stderr: outputStream,
cwd: process.cwd(),
}));
return null;
}).then((daemonOpts) => {
// No need to continue, let's make ourselves a daemon.
if (daemonOpts) {
require('daemon')(daemonOpts);
}
const signals = [
'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS',
'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGALRM', 'SIGTERM',
];
process.on(
'uncaughtException', err => aLogger.error('Got an uncaught exception:', err, err.stack));
process.on('unhandledRejection', (aReason) => {
aLogger.error('Unhandled Rejection:', aReason);
if (aReason.message && aReason.message.startsWith('FATAL:')) {
aLogger.error('Exiting because of a fatal error:', aReason);
process.exit(1);
}
});
process.on('SIGHUP', () => {
if (sighup.handler && sighup.handler instanceof Function) {
aLogger.log('Got SIGHUP. Reloading config!');
sighup.handler();
} else {
aLogger.log('Got SIGHUP. Ignoring!');
}
});
// Sometime we get a SIGPIPE for some unknown reason. Just log and ignore it.
process.on('SIGPIPE', () => {
aLogger.log('Got SIGPIPE. Ignoring');
});
process.on('exit', () => {
aLogger.log('Node process exiting!');
});
const SIGNAL_TEMPLATE_FN = (aSignal) => {
aLogger.log(aSignal, 'captured! Exiting now.');
process.exit(1);
};
signals.forEach((aSignalName) => {
aLogger.trace('Setting handler', aSignalName);
process.on(aSignalName, SIGNAL_TEMPLATE_FN.bind(undefined, aSignalName));
});
});
} | javascript | function setupProcess(aLogger, aDaemonize, aLogFile) {
aLogger.log('Setting up process. Run as a daemon:', aDaemonize, 'Logfile:', aLogFile);
// Since we might need to open some files, and that's an asynchronous operation,
// we will return a promise here that will never resolve on the parent (process will die instead)
// and will resolve on the child
return new Promise((resolve) => {
if (!aDaemonize) {
return resolve();
}
if (!aLogFile) {
return resolve({ stdout: process.stdout, stderr: process.stderr });
}
const fs = require('fs');
const outputStream = fs.createWriteStream(aLogFile);
outputStream.on('open', () => resolve({
stdout: outputStream,
stderr: outputStream,
cwd: process.cwd(),
}));
return null;
}).then((daemonOpts) => {
// No need to continue, let's make ourselves a daemon.
if (daemonOpts) {
require('daemon')(daemonOpts);
}
const signals = [
'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS',
'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGALRM', 'SIGTERM',
];
process.on(
'uncaughtException', err => aLogger.error('Got an uncaught exception:', err, err.stack));
process.on('unhandledRejection', (aReason) => {
aLogger.error('Unhandled Rejection:', aReason);
if (aReason.message && aReason.message.startsWith('FATAL:')) {
aLogger.error('Exiting because of a fatal error:', aReason);
process.exit(1);
}
});
process.on('SIGHUP', () => {
if (sighup.handler && sighup.handler instanceof Function) {
aLogger.log('Got SIGHUP. Reloading config!');
sighup.handler();
} else {
aLogger.log('Got SIGHUP. Ignoring!');
}
});
// Sometime we get a SIGPIPE for some unknown reason. Just log and ignore it.
process.on('SIGPIPE', () => {
aLogger.log('Got SIGPIPE. Ignoring');
});
process.on('exit', () => {
aLogger.log('Node process exiting!');
});
const SIGNAL_TEMPLATE_FN = (aSignal) => {
aLogger.log(aSignal, 'captured! Exiting now.');
process.exit(1);
};
signals.forEach((aSignalName) => {
aLogger.trace('Setting handler', aSignalName);
process.on(aSignalName, SIGNAL_TEMPLATE_FN.bind(undefined, aSignalName));
});
});
} | [
"function",
"setupProcess",
"(",
"aLogger",
",",
"aDaemonize",
",",
"aLogFile",
")",
"{",
"aLogger",
".",
"log",
"(",
"'Setting up process. Run as a daemon:'",
",",
"aDaemonize",
",",
"'Logfile:'",
",",
"aLogFile",
")",
";",
"// Since we might need to open some files, and that's an asynchronous operation,",
"// we will return a promise here that will never resolve on the parent (process will die instead)",
"// and will resolve on the child",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
")",
"=>",
"{",
"if",
"(",
"!",
"aDaemonize",
")",
"{",
"return",
"resolve",
"(",
")",
";",
"}",
"if",
"(",
"!",
"aLogFile",
")",
"{",
"return",
"resolve",
"(",
"{",
"stdout",
":",
"process",
".",
"stdout",
",",
"stderr",
":",
"process",
".",
"stderr",
"}",
")",
";",
"}",
"const",
"fs",
"=",
"require",
"(",
"'fs'",
")",
";",
"const",
"outputStream",
"=",
"fs",
".",
"createWriteStream",
"(",
"aLogFile",
")",
";",
"outputStream",
".",
"on",
"(",
"'open'",
",",
"(",
")",
"=>",
"resolve",
"(",
"{",
"stdout",
":",
"outputStream",
",",
"stderr",
":",
"outputStream",
",",
"cwd",
":",
"process",
".",
"cwd",
"(",
")",
",",
"}",
")",
")",
";",
"return",
"null",
";",
"}",
")",
".",
"then",
"(",
"(",
"daemonOpts",
")",
"=>",
"{",
"// No need to continue, let's make ourselves a daemon.",
"if",
"(",
"daemonOpts",
")",
"{",
"require",
"(",
"'daemon'",
")",
"(",
"daemonOpts",
")",
";",
"}",
"const",
"signals",
"=",
"[",
"'SIGINT'",
",",
"'SIGQUIT'",
",",
"'SIGILL'",
",",
"'SIGTRAP'",
",",
"'SIGABRT'",
",",
"'SIGBUS'",
",",
"'SIGFPE'",
",",
"'SIGUSR1'",
",",
"'SIGSEGV'",
",",
"'SIGALRM'",
",",
"'SIGTERM'",
",",
"]",
";",
"process",
".",
"on",
"(",
"'uncaughtException'",
",",
"err",
"=>",
"aLogger",
".",
"error",
"(",
"'Got an uncaught exception:'",
",",
"err",
",",
"err",
".",
"stack",
")",
")",
";",
"process",
".",
"on",
"(",
"'unhandledRejection'",
",",
"(",
"aReason",
")",
"=>",
"{",
"aLogger",
".",
"error",
"(",
"'Unhandled Rejection:'",
",",
"aReason",
")",
";",
"if",
"(",
"aReason",
".",
"message",
"&&",
"aReason",
".",
"message",
".",
"startsWith",
"(",
"'FATAL:'",
")",
")",
"{",
"aLogger",
".",
"error",
"(",
"'Exiting because of a fatal error:'",
",",
"aReason",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}",
")",
";",
"process",
".",
"on",
"(",
"'SIGHUP'",
",",
"(",
")",
"=>",
"{",
"if",
"(",
"sighup",
".",
"handler",
"&&",
"sighup",
".",
"handler",
"instanceof",
"Function",
")",
"{",
"aLogger",
".",
"log",
"(",
"'Got SIGHUP. Reloading config!'",
")",
";",
"sighup",
".",
"handler",
"(",
")",
";",
"}",
"else",
"{",
"aLogger",
".",
"log",
"(",
"'Got SIGHUP. Ignoring!'",
")",
";",
"}",
"}",
")",
";",
"// Sometime we get a SIGPIPE for some unknown reason. Just log and ignore it.",
"process",
".",
"on",
"(",
"'SIGPIPE'",
",",
"(",
")",
"=>",
"{",
"aLogger",
".",
"log",
"(",
"'Got SIGPIPE. Ignoring'",
")",
";",
"}",
")",
";",
"process",
".",
"on",
"(",
"'exit'",
",",
"(",
")",
"=>",
"{",
"aLogger",
".",
"log",
"(",
"'Node process exiting!'",
")",
";",
"}",
")",
";",
"const",
"SIGNAL_TEMPLATE_FN",
"=",
"(",
"aSignal",
")",
"=>",
"{",
"aLogger",
".",
"log",
"(",
"aSignal",
",",
"'captured! Exiting now.'",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
";",
"signals",
".",
"forEach",
"(",
"(",
"aSignalName",
")",
"=>",
"{",
"aLogger",
".",
"trace",
"(",
"'Setting handler'",
",",
"aSignalName",
")",
";",
"process",
".",
"on",
"(",
"aSignalName",
",",
"SIGNAL_TEMPLATE_FN",
".",
"bind",
"(",
"undefined",
",",
"aSignalName",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Capture signals and optionally daemonize and change username | [
"Capture",
"signals",
"and",
"optionally",
"daemonize",
"and",
"change",
"username"
]
| ce6980060c8194b993b3ab3ed750a25d02e9d66a | https://github.com/AntonioMA/swagger-boilerplate/blob/ce6980060c8194b993b3ab3ed750a25d02e9d66a/lib/setup-process.js#L7-L81 |
46,291 | glennjones/text-autolinker | lib/autolinker.js | parseUrls | function parseUrls(text, options, callback) {
var urls = [],
words,
x = 0,
i;
// is a text string
if (text && utils.isString(text) && text !== '') {
// break texts into words
words = [text];
if (text.indexOf(' ') > -1) {
words = text.split(' ');
}
// finds urls in text
i = words.length;
while (x < i) {
var word = utils.trim(words[x]);
if (word.indexOf('http:') === 0 || word.indexOf('https:') === 0) {
urls.push({
match: word,
url: word
});
} else if (word.indexOf('pic.twitter.com/') === 0) {
urls.push({
match: word,
url: 'https://' + word
});
} else if (word.indexOf('vine.co/v/') === 0) {
urls.push({
match: word,
url: 'https://' + word
});
}
x++;
}
}
callback(null, urls);
} | javascript | function parseUrls(text, options, callback) {
var urls = [],
words,
x = 0,
i;
// is a text string
if (text && utils.isString(text) && text !== '') {
// break texts into words
words = [text];
if (text.indexOf(' ') > -1) {
words = text.split(' ');
}
// finds urls in text
i = words.length;
while (x < i) {
var word = utils.trim(words[x]);
if (word.indexOf('http:') === 0 || word.indexOf('https:') === 0) {
urls.push({
match: word,
url: word
});
} else if (word.indexOf('pic.twitter.com/') === 0) {
urls.push({
match: word,
url: 'https://' + word
});
} else if (word.indexOf('vine.co/v/') === 0) {
urls.push({
match: word,
url: 'https://' + word
});
}
x++;
}
}
callback(null, urls);
} | [
"function",
"parseUrls",
"(",
"text",
",",
"options",
",",
"callback",
")",
"{",
"var",
"urls",
"=",
"[",
"]",
",",
"words",
",",
"x",
"=",
"0",
",",
"i",
";",
"// is a text string",
"if",
"(",
"text",
"&&",
"utils",
".",
"isString",
"(",
"text",
")",
"&&",
"text",
"!==",
"''",
")",
"{",
"// break texts into words",
"words",
"=",
"[",
"text",
"]",
";",
"if",
"(",
"text",
".",
"indexOf",
"(",
"' '",
")",
">",
"-",
"1",
")",
"{",
"words",
"=",
"text",
".",
"split",
"(",
"' '",
")",
";",
"}",
"// finds urls in text",
"i",
"=",
"words",
".",
"length",
";",
"while",
"(",
"x",
"<",
"i",
")",
"{",
"var",
"word",
"=",
"utils",
".",
"trim",
"(",
"words",
"[",
"x",
"]",
")",
";",
"if",
"(",
"word",
".",
"indexOf",
"(",
"'http:'",
")",
"===",
"0",
"||",
"word",
".",
"indexOf",
"(",
"'https:'",
")",
"===",
"0",
")",
"{",
"urls",
".",
"push",
"(",
"{",
"match",
":",
"word",
",",
"url",
":",
"word",
"}",
")",
";",
"}",
"else",
"if",
"(",
"word",
".",
"indexOf",
"(",
"'pic.twitter.com/'",
")",
"===",
"0",
")",
"{",
"urls",
".",
"push",
"(",
"{",
"match",
":",
"word",
",",
"url",
":",
"'https://'",
"+",
"word",
"}",
")",
";",
"}",
"else",
"if",
"(",
"word",
".",
"indexOf",
"(",
"'vine.co/v/'",
")",
"===",
"0",
")",
"{",
"urls",
".",
"push",
"(",
"{",
"match",
":",
"word",
",",
"url",
":",
"'https://'",
"+",
"word",
"}",
")",
";",
"}",
"x",
"++",
";",
"}",
"}",
"callback",
"(",
"null",
",",
"urls",
")",
";",
"}"
]
| parse the text for urls | [
"parse",
"the",
"text",
"for",
"urls"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/autolinker.js#L229-L273 |
46,292 | glennjones/text-autolinker | lib/autolinker.js | getExpandedUrl | function getExpandedUrl(url, options) {
var x = 0,
i;
if (options.urls) {
i = options.urls.length;
while (x < i) {
if (options.urls[x].match === url) {
if (options.urls[x].expanded) {
return options.urls[x].expanded;
}
return null;
}
x++;
}
}
return null;
} | javascript | function getExpandedUrl(url, options) {
var x = 0,
i;
if (options.urls) {
i = options.urls.length;
while (x < i) {
if (options.urls[x].match === url) {
if (options.urls[x].expanded) {
return options.urls[x].expanded;
}
return null;
}
x++;
}
}
return null;
} | [
"function",
"getExpandedUrl",
"(",
"url",
",",
"options",
")",
"{",
"var",
"x",
"=",
"0",
",",
"i",
";",
"if",
"(",
"options",
".",
"urls",
")",
"{",
"i",
"=",
"options",
".",
"urls",
".",
"length",
";",
"while",
"(",
"x",
"<",
"i",
")",
"{",
"if",
"(",
"options",
".",
"urls",
"[",
"x",
"]",
".",
"match",
"===",
"url",
")",
"{",
"if",
"(",
"options",
".",
"urls",
"[",
"x",
"]",
".",
"expanded",
")",
"{",
"return",
"options",
".",
"urls",
"[",
"x",
"]",
".",
"expanded",
";",
"}",
"return",
"null",
";",
"}",
"x",
"++",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| gets exteneded urls from options.urls array | [
"gets",
"exteneded",
"urls",
"from",
"options",
".",
"urls",
"array"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/autolinker.js#L277-L293 |
46,293 | glennjones/text-autolinker | lib/autolinker.js | constainRestrictedWords | function constainRestrictedWords(text) {
var i,
restictedWords = ['today', 'tomorrow', 'yesterday', 'tonight'];
text = text.toLowerCase();
i = restictedWords.length;
while (i--) {
if (text.indexOf(restictedWords[i]) > -1) {
return true;
}
}
return false;
} | javascript | function constainRestrictedWords(text) {
var i,
restictedWords = ['today', 'tomorrow', 'yesterday', 'tonight'];
text = text.toLowerCase();
i = restictedWords.length;
while (i--) {
if (text.indexOf(restictedWords[i]) > -1) {
return true;
}
}
return false;
} | [
"function",
"constainRestrictedWords",
"(",
"text",
")",
"{",
"var",
"i",
",",
"restictedWords",
"=",
"[",
"'today'",
",",
"'tomorrow'",
",",
"'yesterday'",
",",
"'tonight'",
"]",
";",
"text",
"=",
"text",
".",
"toLowerCase",
"(",
")",
";",
"i",
"=",
"restictedWords",
".",
"length",
";",
"while",
"(",
"i",
"--",
")",
"{",
"if",
"(",
"text",
".",
"indexOf",
"(",
"restictedWords",
"[",
"i",
"]",
")",
">",
"-",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| list of words not to let the parser use stops praser returning implied dates against server local time | [
"list",
"of",
"words",
"not",
"to",
"let",
"the",
"parser",
"use",
"stops",
"praser",
"returning",
"implied",
"dates",
"against",
"server",
"local",
"time"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/autolinker.js#L413-L425 |
46,294 | glennjones/text-autolinker | lib/autolinker.js | buildISOLocalDate | function buildISOLocalDate (date) {
var out;
if (date.year !== undefined) {
out = date.year;
}
if (date.month !== undefined) {
out += '-' + pad(date.month + 1);
}
if (date.day !== undefined) {
out += '-' + pad(date.day);
}
if (date.hour !== undefined) {
out += 'T' + pad(date.hour);
}
if (date.minute !== undefined) {
out += ':' + pad(date.minute);
}
if (date.second !== undefined) {
out += ':' + pad(date.second);
}
return out;
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
} | javascript | function buildISOLocalDate (date) {
var out;
if (date.year !== undefined) {
out = date.year;
}
if (date.month !== undefined) {
out += '-' + pad(date.month + 1);
}
if (date.day !== undefined) {
out += '-' + pad(date.day);
}
if (date.hour !== undefined) {
out += 'T' + pad(date.hour);
}
if (date.minute !== undefined) {
out += ':' + pad(date.minute);
}
if (date.second !== undefined) {
out += ':' + pad(date.second);
}
return out;
function pad(number) {
if (number < 10) {
return '0' + number;
}
return number;
}
} | [
"function",
"buildISOLocalDate",
"(",
"date",
")",
"{",
"var",
"out",
";",
"if",
"(",
"date",
".",
"year",
"!==",
"undefined",
")",
"{",
"out",
"=",
"date",
".",
"year",
";",
"}",
"if",
"(",
"date",
".",
"month",
"!==",
"undefined",
")",
"{",
"out",
"+=",
"'-'",
"+",
"pad",
"(",
"date",
".",
"month",
"+",
"1",
")",
";",
"}",
"if",
"(",
"date",
".",
"day",
"!==",
"undefined",
")",
"{",
"out",
"+=",
"'-'",
"+",
"pad",
"(",
"date",
".",
"day",
")",
";",
"}",
"if",
"(",
"date",
".",
"hour",
"!==",
"undefined",
")",
"{",
"out",
"+=",
"'T'",
"+",
"pad",
"(",
"date",
".",
"hour",
")",
";",
"}",
"if",
"(",
"date",
".",
"minute",
"!==",
"undefined",
")",
"{",
"out",
"+=",
"':'",
"+",
"pad",
"(",
"date",
".",
"minute",
")",
";",
"}",
"if",
"(",
"date",
".",
"second",
"!==",
"undefined",
")",
"{",
"out",
"+=",
"':'",
"+",
"pad",
"(",
"date",
".",
"second",
")",
";",
"}",
"return",
"out",
";",
"function",
"pad",
"(",
"number",
")",
"{",
"if",
"(",
"number",
"<",
"10",
")",
"{",
"return",
"'0'",
"+",
"number",
";",
"}",
"return",
"number",
";",
"}",
"}"
]
| builds a local date parsed from text, with no ref to server time | [
"builds",
"a",
"local",
"date",
"parsed",
"from",
"text",
"with",
"no",
"ref",
"to",
"server",
"time"
]
| 1c873d4779d399bf7f2cb2ba72bccf647af659f0 | https://github.com/glennjones/text-autolinker/blob/1c873d4779d399bf7f2cb2ba72bccf647af659f0/lib/autolinker.js#L429-L458 |
46,295 | AndiDittrich/Node.fs-magic | lib/FileOutputStream.js | FileOutputStream | function FileOutputStream(istream, destinationFilename, mode=false){
// wrap into Promise
return new Promise(function(resolve, reject){
// file output stream
let ostream = null;
// on complete - chmod
const onComplete = function(){
// file mode defined ?
if (mode){
// set mode of destination file
_fs.chmod(destinationFilename, mode, function(err){
if (err){
reject(err);
}else{
resolve();
}
});
}else{
// finish
resolve();
}
}
// cleanup
const onError = function(e){
// detach finish listener!
if (ostream){
ostream.removeListener('finish', onComplete);
}
// close streams
if (istream){
istream.destroy();
}
if (ostream){
ostream.end();
}
// throw error
reject(e);
}
// add additional error listener to input stream
istream.on('error', onError);
// open write stream
ostream = _fs.createWriteStream(destinationFilename);
ostream.on('error', onError);
ostream.on('finish', onComplete);
// pipe in to out
istream.pipe(ostream);
});
} | javascript | function FileOutputStream(istream, destinationFilename, mode=false){
// wrap into Promise
return new Promise(function(resolve, reject){
// file output stream
let ostream = null;
// on complete - chmod
const onComplete = function(){
// file mode defined ?
if (mode){
// set mode of destination file
_fs.chmod(destinationFilename, mode, function(err){
if (err){
reject(err);
}else{
resolve();
}
});
}else{
// finish
resolve();
}
}
// cleanup
const onError = function(e){
// detach finish listener!
if (ostream){
ostream.removeListener('finish', onComplete);
}
// close streams
if (istream){
istream.destroy();
}
if (ostream){
ostream.end();
}
// throw error
reject(e);
}
// add additional error listener to input stream
istream.on('error', onError);
// open write stream
ostream = _fs.createWriteStream(destinationFilename);
ostream.on('error', onError);
ostream.on('finish', onComplete);
// pipe in to out
istream.pipe(ostream);
});
} | [
"function",
"FileOutputStream",
"(",
"istream",
",",
"destinationFilename",
",",
"mode",
"=",
"false",
")",
"{",
"// wrap into Promise",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"// file output stream",
"let",
"ostream",
"=",
"null",
";",
"// on complete - chmod",
"const",
"onComplete",
"=",
"function",
"(",
")",
"{",
"// file mode defined ?",
"if",
"(",
"mode",
")",
"{",
"// set mode of destination file",
"_fs",
".",
"chmod",
"(",
"destinationFilename",
",",
"mode",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"// finish",
"resolve",
"(",
")",
";",
"}",
"}",
"// cleanup",
"const",
"onError",
"=",
"function",
"(",
"e",
")",
"{",
"// detach finish listener!",
"if",
"(",
"ostream",
")",
"{",
"ostream",
".",
"removeListener",
"(",
"'finish'",
",",
"onComplete",
")",
";",
"}",
"// close streams",
"if",
"(",
"istream",
")",
"{",
"istream",
".",
"destroy",
"(",
")",
";",
"}",
"if",
"(",
"ostream",
")",
"{",
"ostream",
".",
"end",
"(",
")",
";",
"}",
"// throw error",
"reject",
"(",
"e",
")",
";",
"}",
"// add additional error listener to input stream",
"istream",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"// open write stream",
"ostream",
"=",
"_fs",
".",
"createWriteStream",
"(",
"destinationFilename",
")",
";",
"ostream",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"ostream",
".",
"on",
"(",
"'finish'",
",",
"onComplete",
")",
";",
"// pipe in to out",
"istream",
".",
"pipe",
"(",
"ostream",
")",
";",
"}",
")",
";",
"}"
]
| write a stream to destination file | [
"write",
"a",
"stream",
"to",
"destination",
"file"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/FileOutputStream.js#L4-L59 |
46,296 | AndiDittrich/Node.fs-magic | lib/FileOutputStream.js | function(){
// file mode defined ?
if (mode){
// set mode of destination file
_fs.chmod(destinationFilename, mode, function(err){
if (err){
reject(err);
}else{
resolve();
}
});
}else{
// finish
resolve();
}
} | javascript | function(){
// file mode defined ?
if (mode){
// set mode of destination file
_fs.chmod(destinationFilename, mode, function(err){
if (err){
reject(err);
}else{
resolve();
}
});
}else{
// finish
resolve();
}
} | [
"function",
"(",
")",
"{",
"// file mode defined ?",
"if",
"(",
"mode",
")",
"{",
"// set mode of destination file",
"_fs",
".",
"chmod",
"(",
"destinationFilename",
",",
"mode",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"// finish",
"resolve",
"(",
")",
";",
"}",
"}"
]
| on complete - chmod | [
"on",
"complete",
"-",
"chmod"
]
| 5e685a550fd956b5b422a0f21c359952e9be114b | https://github.com/AndiDittrich/Node.fs-magic/blob/5e685a550fd956b5b422a0f21c359952e9be114b/lib/FileOutputStream.js#L12-L27 |
|
46,297 | AntonioMA/swagger-boilerplate | lib/server.js | getServerConfig | function getServerConfig(aCertDir) {
const certFileRead = readFile(aCertDir + '/serverCert.pem');
const keyFileRead = readFile(aCertDir + '/serverKey.pem');
return Promise.all([certFileRead, keyFileRead]).
then(files => [{ cert: files[0], key: files[1] }]);
} | javascript | function getServerConfig(aCertDir) {
const certFileRead = readFile(aCertDir + '/serverCert.pem');
const keyFileRead = readFile(aCertDir + '/serverKey.pem');
return Promise.all([certFileRead, keyFileRead]).
then(files => [{ cert: files[0], key: files[1] }]);
} | [
"function",
"getServerConfig",
"(",
"aCertDir",
")",
"{",
"const",
"certFileRead",
"=",
"readFile",
"(",
"aCertDir",
"+",
"'/serverCert.pem'",
")",
";",
"const",
"keyFileRead",
"=",
"readFile",
"(",
"aCertDir",
"+",
"'/serverKey.pem'",
")",
";",
"return",
"Promise",
".",
"all",
"(",
"[",
"certFileRead",
",",
"keyFileRead",
"]",
")",
".",
"then",
"(",
"files",
"=>",
"[",
"{",
"cert",
":",
"files",
"[",
"0",
"]",
",",
"key",
":",
"files",
"[",
"1",
"]",
"}",
"]",
")",
";",
"}"
]
| At this moment reads the cert and key as serverKey and serverCert, without password, from aCertDir. | [
"At",
"this",
"moment",
"reads",
"the",
"cert",
"and",
"key",
"as",
"serverKey",
"and",
"serverCert",
"without",
"password",
"from",
"aCertDir",
"."
]
| ce6980060c8194b993b3ab3ed750a25d02e9d66a | https://github.com/AntonioMA/swagger-boilerplate/blob/ce6980060c8194b993b3ab3ed750a25d02e9d66a/lib/server.js#L26-L31 |
46,298 | plepers/nanogl-node | node.js | function( skipParents ){
skipParents = !!skipParents;
this.updateMatrix();
var invalidWorldMatrix = this._hasInvalidWorldMatrix( skipParents );
if( invalidWorldMatrix ) {
this._computeWorldMatrix( skipParents );
}
for (var i = 0; i < this._children.length; i++) {
var c = this._children[i];
c._invalidW = c._invalidW || invalidWorldMatrix;
c.updateWorldMatrix( true );
}
} | javascript | function( skipParents ){
skipParents = !!skipParents;
this.updateMatrix();
var invalidWorldMatrix = this._hasInvalidWorldMatrix( skipParents );
if( invalidWorldMatrix ) {
this._computeWorldMatrix( skipParents );
}
for (var i = 0; i < this._children.length; i++) {
var c = this._children[i];
c._invalidW = c._invalidW || invalidWorldMatrix;
c.updateWorldMatrix( true );
}
} | [
"function",
"(",
"skipParents",
")",
"{",
"skipParents",
"=",
"!",
"!",
"skipParents",
";",
"this",
".",
"updateMatrix",
"(",
")",
";",
"var",
"invalidWorldMatrix",
"=",
"this",
".",
"_hasInvalidWorldMatrix",
"(",
"skipParents",
")",
";",
"if",
"(",
"invalidWorldMatrix",
")",
"{",
"this",
".",
"_computeWorldMatrix",
"(",
"skipParents",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_children",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"c",
"=",
"this",
".",
"_children",
"[",
"i",
"]",
";",
"c",
".",
"_invalidW",
"=",
"c",
".",
"_invalidW",
"||",
"invalidWorldMatrix",
";",
"c",
".",
"updateWorldMatrix",
"(",
"true",
")",
";",
"}",
"}"
]
| update world matrix and descendants. | [
"update",
"world",
"matrix",
"and",
"descendants",
"."
]
| 5ca4c3261ae66f79cd6d520f082000af9c3a2ec2 | https://github.com/plepers/nanogl-node/blob/5ca4c3261ae66f79cd6d520f082000af9c3a2ec2/node.js#L125-L141 |
|
46,299 | jvictorsoto/tc-wrapper | src/helpers.js | execCmd | function execCmd(cmd, allowedErrors = []) {
debug(`About to execute cmd: ${cmd} with allowed errors: ${JSON.stringify(allowedErrors)}`);
return exec(cmd, {})
.then((result) => {
debug(`Executed successfully cmd: ${cmd}: `, result.stdout);
const { stdout } = result;
return stdout;
})
.catch((error) => {
debug(`Executed with error cmd: ${cmd}: `, error.stdout, error.stderr);
if (allowedErrors.some(allowedError => allowedError.test(error.stderr))) {
return Promise.resolve(error.stderr);
}
return Promise.reject(error);
});
} | javascript | function execCmd(cmd, allowedErrors = []) {
debug(`About to execute cmd: ${cmd} with allowed errors: ${JSON.stringify(allowedErrors)}`);
return exec(cmd, {})
.then((result) => {
debug(`Executed successfully cmd: ${cmd}: `, result.stdout);
const { stdout } = result;
return stdout;
})
.catch((error) => {
debug(`Executed with error cmd: ${cmd}: `, error.stdout, error.stderr);
if (allowedErrors.some(allowedError => allowedError.test(error.stderr))) {
return Promise.resolve(error.stderr);
}
return Promise.reject(error);
});
} | [
"function",
"execCmd",
"(",
"cmd",
",",
"allowedErrors",
"=",
"[",
"]",
")",
"{",
"debug",
"(",
"`",
"${",
"cmd",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"allowedErrors",
")",
"}",
"`",
")",
";",
"return",
"exec",
"(",
"cmd",
",",
"{",
"}",
")",
".",
"then",
"(",
"(",
"result",
")",
"=>",
"{",
"debug",
"(",
"`",
"${",
"cmd",
"}",
"`",
",",
"result",
".",
"stdout",
")",
";",
"const",
"{",
"stdout",
"}",
"=",
"result",
";",
"return",
"stdout",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"debug",
"(",
"`",
"${",
"cmd",
"}",
"`",
",",
"error",
".",
"stdout",
",",
"error",
".",
"stderr",
")",
";",
"if",
"(",
"allowedErrors",
".",
"some",
"(",
"allowedError",
"=>",
"allowedError",
".",
"test",
"(",
"error",
".",
"stderr",
")",
")",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"error",
".",
"stderr",
")",
";",
"}",
"return",
"Promise",
".",
"reject",
"(",
"error",
")",
";",
"}",
")",
";",
"}"
]
| Helper function to exec commands. | [
"Helper",
"function",
"to",
"exec",
"commands",
"."
]
| 06ff3def7e2125466f4dfdc7696cac9cc08f02d5 | https://github.com/jvictorsoto/tc-wrapper/blob/06ff3def7e2125466f4dfdc7696cac9cc08f02d5/src/helpers.js#L12-L27 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.