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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
51,600 | quantumpayments/media | bin/view.js | copyMedia | function copyMedia (path, to, cert, callback) {
var hookPath = __dirname + '/../data/buffer/hook.sh'
debug('copyMedia', path, to, cert)
if (/^http/.test(to)) {
debug('using http')
var parsed = url.parse(to)
debug('parsed', parsed)
var domain = url.parse(to).domain
var file = url.parse(to).path
debug(domain, file)
var a = parsed.pathname.split('/')
var uri = parsed.protocol + '//' + parsed.host
for (var i = 0; i < a.length - 1; i++) {
uri += a[i] + '/'
}
uri += urlencode(a[i])
debug('uri', uri)
// uri = 'https://phone.servehttp.com:8000/data/buffer/image/' + urlencode('file%3A%2F%2F%2Fmedia%2Fmelvin%2FElements%2Fpichunter.com%2F2443342_15_o.jpg')
var options = {
method: 'PUT',
url: uri,
key: fs.readFileSync(cert),
cert: fs.readFileSync(cert),
headers: { // We can define headers too
'Content-Type': 'image/jpg'
}
}
debug(options)
fs.createReadStream(path).pipe(request.put(options, function (err, response, body) {
if (err) {
debug(err)
callback(err)
} else {
debug('success')
callback(null)
setTimeout(function () {
exec(hookPath)
}, 0)
}
}))
} else {
fs.copy(path, to, function (err) {
if (err) {
callback(err)
} else {
callback(null, null)
setTimeout(function () {
exec(hookPath)
}, 0)
}
})
}
} | javascript | function copyMedia (path, to, cert, callback) {
var hookPath = __dirname + '/../data/buffer/hook.sh'
debug('copyMedia', path, to, cert)
if (/^http/.test(to)) {
debug('using http')
var parsed = url.parse(to)
debug('parsed', parsed)
var domain = url.parse(to).domain
var file = url.parse(to).path
debug(domain, file)
var a = parsed.pathname.split('/')
var uri = parsed.protocol + '//' + parsed.host
for (var i = 0; i < a.length - 1; i++) {
uri += a[i] + '/'
}
uri += urlencode(a[i])
debug('uri', uri)
// uri = 'https://phone.servehttp.com:8000/data/buffer/image/' + urlencode('file%3A%2F%2F%2Fmedia%2Fmelvin%2FElements%2Fpichunter.com%2F2443342_15_o.jpg')
var options = {
method: 'PUT',
url: uri,
key: fs.readFileSync(cert),
cert: fs.readFileSync(cert),
headers: { // We can define headers too
'Content-Type': 'image/jpg'
}
}
debug(options)
fs.createReadStream(path).pipe(request.put(options, function (err, response, body) {
if (err) {
debug(err)
callback(err)
} else {
debug('success')
callback(null)
setTimeout(function () {
exec(hookPath)
}, 0)
}
}))
} else {
fs.copy(path, to, function (err) {
if (err) {
callback(err)
} else {
callback(null, null)
setTimeout(function () {
exec(hookPath)
}, 0)
}
})
}
} | [
"function",
"copyMedia",
"(",
"path",
",",
"to",
",",
"cert",
",",
"callback",
")",
"{",
"var",
"hookPath",
"=",
"__dirname",
"+",
"'/../data/buffer/hook.sh'",
"debug",
"(",
"'copyMedia'",
",",
"path",
",",
"to",
",",
"cert",
")",
"if",
"(",
"/",
"^http",
"/",
".",
"test",
"(",
"to",
")",
")",
"{",
"debug",
"(",
"'using http'",
")",
"var",
"parsed",
"=",
"url",
".",
"parse",
"(",
"to",
")",
"debug",
"(",
"'parsed'",
",",
"parsed",
")",
"var",
"domain",
"=",
"url",
".",
"parse",
"(",
"to",
")",
".",
"domain",
"var",
"file",
"=",
"url",
".",
"parse",
"(",
"to",
")",
".",
"path",
"debug",
"(",
"domain",
",",
"file",
")",
"var",
"a",
"=",
"parsed",
".",
"pathname",
".",
"split",
"(",
"'/'",
")",
"var",
"uri",
"=",
"parsed",
".",
"protocol",
"+",
"'//'",
"+",
"parsed",
".",
"host",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"a",
".",
"length",
"-",
"1",
";",
"i",
"++",
")",
"{",
"uri",
"+=",
"a",
"[",
"i",
"]",
"+",
"'/'",
"}",
"uri",
"+=",
"urlencode",
"(",
"a",
"[",
"i",
"]",
")",
"debug",
"(",
"'uri'",
",",
"uri",
")",
"// uri = 'https://phone.servehttp.com:8000/data/buffer/image/' + urlencode('file%3A%2F%2F%2Fmedia%2Fmelvin%2FElements%2Fpichunter.com%2F2443342_15_o.jpg')",
"var",
"options",
"=",
"{",
"method",
":",
"'PUT'",
",",
"url",
":",
"uri",
",",
"key",
":",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
",",
"cert",
":",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
",",
"headers",
":",
"{",
"// We can define headers too",
"'Content-Type'",
":",
"'image/jpg'",
"}",
"}",
"debug",
"(",
"options",
")",
"fs",
".",
"createReadStream",
"(",
"path",
")",
".",
"pipe",
"(",
"request",
".",
"put",
"(",
"options",
",",
"function",
"(",
"err",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"err",
")",
"callback",
"(",
"err",
")",
"}",
"else",
"{",
"debug",
"(",
"'success'",
")",
"callback",
"(",
"null",
")",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"exec",
"(",
"hookPath",
")",
"}",
",",
"0",
")",
"}",
"}",
")",
")",
"}",
"else",
"{",
"fs",
".",
"copy",
"(",
"path",
",",
"to",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"null",
")",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"exec",
"(",
"hookPath",
")",
"}",
",",
"0",
")",
"}",
"}",
")",
"}",
"}"
] | copy media from one place to another
@param {string} path from where to copy
@param {string} to where to copy to
@param {string} cert path to certificate
@param {Function} callback callback | [
"copy",
"media",
"from",
"one",
"place",
"to",
"another"
] | b53034e6dd2a94dca950e60a49e403aceaa1cdf1 | https://github.com/quantumpayments/media/blob/b53034e6dd2a94dca950e60a49e403aceaa1cdf1/bin/view.js#L208-L266 |
51,601 | quantumpayments/media | bin/view.js | getMediaByAPI | function getMediaByAPI (uri, cert, mode, user, safe, bufferURI) {
return new Promise(function (resolve, reject) {
balance(user).then((ret) => {
return ret
}).then(function (ret) {
if (ret >= algos.getRandomUnseenImage.cost) {
qpm_media.getRandomUnseenImage().then(function (row) {
row.conn.close()
resolve(row.ret[0][0])
// pay
var credit = {}
credit['https://w3id.org/cc#source'] = user
credit['https://w3id.org/cc#amount'] = algos.getRandomUnseenImage.cost
credit['https://w3id.org/cc#currency'] = 'https://w3id.org/cc#bit'
credit['https://w3id.org/cc#destination'] = algos.getRandomUnseenImage.counterparty
pay(credit)
}).catch(function (err) {
row.conn.close()
reject(err)
})
} else {
reject(new Error('not enough funds'))
}
})
})
} | javascript | function getMediaByAPI (uri, cert, mode, user, safe, bufferURI) {
return new Promise(function (resolve, reject) {
balance(user).then((ret) => {
return ret
}).then(function (ret) {
if (ret >= algos.getRandomUnseenImage.cost) {
qpm_media.getRandomUnseenImage().then(function (row) {
row.conn.close()
resolve(row.ret[0][0])
// pay
var credit = {}
credit['https://w3id.org/cc#source'] = user
credit['https://w3id.org/cc#amount'] = algos.getRandomUnseenImage.cost
credit['https://w3id.org/cc#currency'] = 'https://w3id.org/cc#bit'
credit['https://w3id.org/cc#destination'] = algos.getRandomUnseenImage.counterparty
pay(credit)
}).catch(function (err) {
row.conn.close()
reject(err)
})
} else {
reject(new Error('not enough funds'))
}
})
})
} | [
"function",
"getMediaByAPI",
"(",
"uri",
",",
"cert",
",",
"mode",
",",
"user",
",",
"safe",
",",
"bufferURI",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"balance",
"(",
"user",
")",
".",
"then",
"(",
"(",
"ret",
")",
"=>",
"{",
"return",
"ret",
"}",
")",
".",
"then",
"(",
"function",
"(",
"ret",
")",
"{",
"if",
"(",
"ret",
">=",
"algos",
".",
"getRandomUnseenImage",
".",
"cost",
")",
"{",
"qpm_media",
".",
"getRandomUnseenImage",
"(",
")",
".",
"then",
"(",
"function",
"(",
"row",
")",
"{",
"row",
".",
"conn",
".",
"close",
"(",
")",
"resolve",
"(",
"row",
".",
"ret",
"[",
"0",
"]",
"[",
"0",
"]",
")",
"// pay",
"var",
"credit",
"=",
"{",
"}",
"credit",
"[",
"'https://w3id.org/cc#source'",
"]",
"=",
"user",
"credit",
"[",
"'https://w3id.org/cc#amount'",
"]",
"=",
"algos",
".",
"getRandomUnseenImage",
".",
"cost",
"credit",
"[",
"'https://w3id.org/cc#currency'",
"]",
"=",
"'https://w3id.org/cc#bit'",
"credit",
"[",
"'https://w3id.org/cc#destination'",
"]",
"=",
"algos",
".",
"getRandomUnseenImage",
".",
"counterparty",
"pay",
"(",
"credit",
")",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"err",
")",
"{",
"row",
".",
"conn",
".",
"close",
"(",
")",
"reject",
"(",
"err",
")",
"}",
")",
"}",
"else",
"{",
"reject",
"(",
"new",
"Error",
"(",
"'not enough funds'",
")",
")",
"}",
"}",
")",
"}",
")",
"}"
] | Get Media item from API
@param {string} uri The uri to get it from.
@param {string} cert Location of an X.509 cert.
@param {string} mode Mode api | http | buffer.
@param {string} user The WebID of the user.
@param {number} safe Whether safe search is on.
@param {string} bufferURI The URI of the buffer.
@return {object} Promise with the row. | [
"Get",
"Media",
"item",
"from",
"API"
] | b53034e6dd2a94dca950e60a49e403aceaa1cdf1 | https://github.com/quantumpayments/media/blob/b53034e6dd2a94dca950e60a49e403aceaa1cdf1/bin/view.js#L278-L304 |
51,602 | quantumpayments/media | bin/view.js | getMediaByHTTP | function getMediaByHTTP (uri, cert, mode, user, safe, bufferURI) {
return new Promise(function (resolve, reject) {
var cookiePath = __dirname + '/../data/cookie.json'
var cookies = readCookie(cookiePath)
if (cookies) {
options.headers['Set-Cookie'] = 'connect.sid=' + sid + '; Path=/; HttpOnly; Secure'
}
var options = {
url: uri,
key: fs.readFileSync(cert),
cert: fs.readFileSync(cert),
headers: { // We can define headers too
'Accept': 'application/json'
}
}
request.get(options, function (error, response, body) {
writeCookie(response, cookiePath)
if (!error && response.statusCode === 200) {
json = JSON.parse(body)
resolve(json)
} else {
reject(error)
}
})
})
} | javascript | function getMediaByHTTP (uri, cert, mode, user, safe, bufferURI) {
return new Promise(function (resolve, reject) {
var cookiePath = __dirname + '/../data/cookie.json'
var cookies = readCookie(cookiePath)
if (cookies) {
options.headers['Set-Cookie'] = 'connect.sid=' + sid + '; Path=/; HttpOnly; Secure'
}
var options = {
url: uri,
key: fs.readFileSync(cert),
cert: fs.readFileSync(cert),
headers: { // We can define headers too
'Accept': 'application/json'
}
}
request.get(options, function (error, response, body) {
writeCookie(response, cookiePath)
if (!error && response.statusCode === 200) {
json = JSON.parse(body)
resolve(json)
} else {
reject(error)
}
})
})
} | [
"function",
"getMediaByHTTP",
"(",
"uri",
",",
"cert",
",",
"mode",
",",
"user",
",",
"safe",
",",
"bufferURI",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"cookiePath",
"=",
"__dirname",
"+",
"'/../data/cookie.json'",
"var",
"cookies",
"=",
"readCookie",
"(",
"cookiePath",
")",
"if",
"(",
"cookies",
")",
"{",
"options",
".",
"headers",
"[",
"'Set-Cookie'",
"]",
"=",
"'connect.sid='",
"+",
"sid",
"+",
"'; Path=/; HttpOnly; Secure'",
"}",
"var",
"options",
"=",
"{",
"url",
":",
"uri",
",",
"key",
":",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
",",
"cert",
":",
"fs",
".",
"readFileSync",
"(",
"cert",
")",
",",
"headers",
":",
"{",
"// We can define headers too",
"'Accept'",
":",
"'application/json'",
"}",
"}",
"request",
".",
"get",
"(",
"options",
",",
"function",
"(",
"error",
",",
"response",
",",
"body",
")",
"{",
"writeCookie",
"(",
"response",
",",
"cookiePath",
")",
"if",
"(",
"!",
"error",
"&&",
"response",
".",
"statusCode",
"===",
"200",
")",
"{",
"json",
"=",
"JSON",
".",
"parse",
"(",
"body",
")",
"resolve",
"(",
"json",
")",
"}",
"else",
"{",
"reject",
"(",
"error",
")",
"}",
"}",
")",
"}",
")",
"}"
] | Get Media item from HTTP
@param {string} uri The uri to get it from.
@param {string} cert Location of an X.509 cert.
@param {string} mode Mode api | http | buffer.
@param {string} user The WebID of the user.
@param {number} safe Whether safe search is on.
@param {string} bufferURI The URI of the buffer.
@return {object} Promise with the row. | [
"Get",
"Media",
"item",
"from",
"HTTP"
] | b53034e6dd2a94dca950e60a49e403aceaa1cdf1 | https://github.com/quantumpayments/media/blob/b53034e6dd2a94dca950e60a49e403aceaa1cdf1/bin/view.js#L316-L346 |
51,603 | quantumpayments/media | bin/view.js | getNextFile | function getNextFile (files, type) {
for (var i = 0; i < files.length; i++) {
var file = files[i]
if (/.ttl$/.test(file)) {
continue
}
return file
}
} | javascript | function getNextFile (files, type) {
for (var i = 0; i < files.length; i++) {
var file = files[i]
if (/.ttl$/.test(file)) {
continue
}
return file
}
} | [
"function",
"getNextFile",
"(",
"files",
",",
"type",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"files",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"file",
"=",
"files",
"[",
"i",
"]",
"if",
"(",
"/",
".ttl$",
"/",
".",
"test",
"(",
"file",
")",
")",
"{",
"continue",
"}",
"return",
"file",
"}",
"}"
] | Gets the next file in a buffer
@param {array} files Array of files
@param {number} type Type of file to get
@return {string} Path to file | [
"Gets",
"the",
"next",
"file",
"in",
"a",
"buffer"
] | b53034e6dd2a94dca950e60a49e403aceaa1cdf1 | https://github.com/quantumpayments/media/blob/b53034e6dd2a94dca950e60a49e403aceaa1cdf1/bin/view.js#L470-L478 |
51,604 | cemtopkaya/kuark-db | src/db_uyariServisi.js | f_todo_secildi | function f_todo_secildi(_uyari) {
l.info("f_todo_secildi");
//bu uyarı için atanmış kullanıcı id lerini çek
var kullanici_idleri = f_uye_id_array(_uyari);
return _uyari.RENDER.Sonuc.Data.map(function (_elm) {
var detay = f_detay_olustur(schema.SABIT.UYARI.TODO, _uyari, _elm);
return f_uyari_sonucu_ekle(detay)
.then(function (_id) {
var db_gorev = require('./db_gorev');
//eklenen uyarı sonucunu görevlere ekliyoruz
return kullanici_idleri.mapX(null, db_gorev.f_db_gorev_ekle, _id).allX();
});
})
.allX();
} | javascript | function f_todo_secildi(_uyari) {
l.info("f_todo_secildi");
//bu uyarı için atanmış kullanıcı id lerini çek
var kullanici_idleri = f_uye_id_array(_uyari);
return _uyari.RENDER.Sonuc.Data.map(function (_elm) {
var detay = f_detay_olustur(schema.SABIT.UYARI.TODO, _uyari, _elm);
return f_uyari_sonucu_ekle(detay)
.then(function (_id) {
var db_gorev = require('./db_gorev');
//eklenen uyarı sonucunu görevlere ekliyoruz
return kullanici_idleri.mapX(null, db_gorev.f_db_gorev_ekle, _id).allX();
});
})
.allX();
} | [
"function",
"f_todo_secildi",
"(",
"_uyari",
")",
"{",
"l",
".",
"info",
"(",
"\"f_todo_secildi\"",
")",
";",
"//bu uyarı için atanmış kullanıcı id lerini çek\r",
"var",
"kullanici_idleri",
"=",
"f_uye_id_array",
"(",
"_uyari",
")",
";",
"return",
"_uyari",
".",
"RENDER",
".",
"Sonuc",
".",
"Data",
".",
"map",
"(",
"function",
"(",
"_elm",
")",
"{",
"var",
"detay",
"=",
"f_detay_olustur",
"(",
"schema",
".",
"SABIT",
".",
"UYARI",
".",
"TODO",
",",
"_uyari",
",",
"_elm",
")",
";",
"return",
"f_uyari_sonucu_ekle",
"(",
"detay",
")",
".",
"then",
"(",
"function",
"(",
"_id",
")",
"{",
"var",
"db_gorev",
"=",
"require",
"(",
"'./db_gorev'",
")",
";",
"//eklenen uyarı sonucunu görevlere ekliyoruz\r",
"return",
"kullanici_idleri",
".",
"mapX",
"(",
"null",
",",
"db_gorev",
".",
"f_db_gorev_ekle",
",",
"_id",
")",
".",
"allX",
"(",
")",
";",
"}",
")",
";",
"}",
")",
".",
"allX",
"(",
")",
";",
"}"
] | endregion region TO-DO | [
"endregion",
"region",
"TO",
"-",
"DO"
] | d584aaf51f65a013bec79220a05007bd70767ac2 | https://github.com/cemtopkaya/kuark-db/blob/d584aaf51f65a013bec79220a05007bd70767ac2/src/db_uyariServisi.js#L409-L430 |
51,605 | squirkle/dig-it | lib/dig.js | getProp | function getProp (obj, path, isArray) {
var next;
path = _.isString(path) ? path.split('.') : path;
// We have more traversing to do
if (path.length > 1) {
next = path.shift();
if (_.isArray(obj[next])) {
isArray = true;
var arr = _.compact(_.flatten(obj[next].map(function (el, i) {
return getProp(el, _.clone(path), isArray);
})));
return arr.length ? arr : undefined;
} else {
if (!obj[next]) { return; }
return getProp(obj[next], path, isArray);
}
// No more traversing. We can now target the final node with path[0]
} else {
next = path[0];
// if we are at the end of the path and `obj` is an array
if (_.isArray(obj)) {
return _.pluck(obj, next);
} else {
if (!obj[next]) { return; }
return isArray ? [obj[next]] : obj[next];
}
}
} | javascript | function getProp (obj, path, isArray) {
var next;
path = _.isString(path) ? path.split('.') : path;
// We have more traversing to do
if (path.length > 1) {
next = path.shift();
if (_.isArray(obj[next])) {
isArray = true;
var arr = _.compact(_.flatten(obj[next].map(function (el, i) {
return getProp(el, _.clone(path), isArray);
})));
return arr.length ? arr : undefined;
} else {
if (!obj[next]) { return; }
return getProp(obj[next], path, isArray);
}
// No more traversing. We can now target the final node with path[0]
} else {
next = path[0];
// if we are at the end of the path and `obj` is an array
if (_.isArray(obj)) {
return _.pluck(obj, next);
} else {
if (!obj[next]) { return; }
return isArray ? [obj[next]] : obj[next];
}
}
} | [
"function",
"getProp",
"(",
"obj",
",",
"path",
",",
"isArray",
")",
"{",
"var",
"next",
";",
"path",
"=",
"_",
".",
"isString",
"(",
"path",
")",
"?",
"path",
".",
"split",
"(",
"'.'",
")",
":",
"path",
";",
"// We have more traversing to do",
"if",
"(",
"path",
".",
"length",
">",
"1",
")",
"{",
"next",
"=",
"path",
".",
"shift",
"(",
")",
";",
"if",
"(",
"_",
".",
"isArray",
"(",
"obj",
"[",
"next",
"]",
")",
")",
"{",
"isArray",
"=",
"true",
";",
"var",
"arr",
"=",
"_",
".",
"compact",
"(",
"_",
".",
"flatten",
"(",
"obj",
"[",
"next",
"]",
".",
"map",
"(",
"function",
"(",
"el",
",",
"i",
")",
"{",
"return",
"getProp",
"(",
"el",
",",
"_",
".",
"clone",
"(",
"path",
")",
",",
"isArray",
")",
";",
"}",
")",
")",
")",
";",
"return",
"arr",
".",
"length",
"?",
"arr",
":",
"undefined",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"obj",
"[",
"next",
"]",
")",
"{",
"return",
";",
"}",
"return",
"getProp",
"(",
"obj",
"[",
"next",
"]",
",",
"path",
",",
"isArray",
")",
";",
"}",
"// No more traversing. We can now target the final node with path[0]",
"}",
"else",
"{",
"next",
"=",
"path",
"[",
"0",
"]",
";",
"// if we are at the end of the path and `obj` is an array",
"if",
"(",
"_",
".",
"isArray",
"(",
"obj",
")",
")",
"{",
"return",
"_",
".",
"pluck",
"(",
"obj",
",",
"next",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"obj",
"[",
"next",
"]",
")",
"{",
"return",
";",
"}",
"return",
"isArray",
"?",
"[",
"obj",
"[",
"next",
"]",
"]",
":",
"obj",
"[",
"next",
"]",
";",
"}",
"}",
"}"
] | returns value of property at path, or array of properties if there is an array in the path | [
"returns",
"value",
"of",
"property",
"at",
"path",
"or",
"array",
"of",
"properties",
"if",
"there",
"is",
"an",
"array",
"in",
"the",
"path"
] | 471a44ba7d3bd7f12b3977522234c740a9b76ada | https://github.com/squirkle/dig-it/blob/471a44ba7d3bd7f12b3977522234c740a9b76ada/lib/dig.js#L8-L37 |
51,606 | moov2/grunt-orchard-development | tasks/build-themes.js | function () {
var dest = path.join(options.dest, themes[count]);
// deletes theme is already exists.
if (fs.exists(dest)) {
fs.rmdir(dest);
}
mv(path.join(options.themes, themes[count], 'dist'), dest, {mkdirp: true}, function() {
buildNextTheme();
});
} | javascript | function () {
var dest = path.join(options.dest, themes[count]);
// deletes theme is already exists.
if (fs.exists(dest)) {
fs.rmdir(dest);
}
mv(path.join(options.themes, themes[count], 'dist'), dest, {mkdirp: true}, function() {
buildNextTheme();
});
} | [
"function",
"(",
")",
"{",
"var",
"dest",
"=",
"path",
".",
"join",
"(",
"options",
".",
"dest",
",",
"themes",
"[",
"count",
"]",
")",
";",
"// deletes theme is already exists.",
"if",
"(",
"fs",
".",
"exists",
"(",
"dest",
")",
")",
"{",
"fs",
".",
"rmdir",
"(",
"dest",
")",
";",
"}",
"mv",
"(",
"path",
".",
"join",
"(",
"options",
".",
"themes",
",",
"themes",
"[",
"count",
"]",
",",
"'dist'",
")",
",",
"dest",
",",
"{",
"mkdirp",
":",
"true",
"}",
",",
"function",
"(",
")",
"{",
"buildNextTheme",
"(",
")",
";",
"}",
")",
";",
"}"
] | Deletes the existing theme and copies the distributable ready theme
into position. | [
"Deletes",
"the",
"existing",
"theme",
"and",
"copies",
"the",
"distributable",
"ready",
"theme",
"into",
"position",
"."
] | 658c5bae73f894469d099a7c2d735f9cda08d0cc | https://github.com/moov2/grunt-orchard-development/blob/658c5bae73f894469d099a7c2d735f9cda08d0cc/tasks/build-themes.js#L111-L122 |
|
51,607 | vmarkdown/vremark-parse | packages/vremark-toc/mdast-util-toc/lib/search.js | search | function search(root, expression, maxDepth) {
var length = root.children.length;
var depth = null;
var lookingForToc = expression !== null;
var map = [];
var headingIndex;
var closingIndex;
if (!lookingForToc) {
headingIndex = -1;
}
slugs.reset();
/*
* Visit all headings in `root`.
* We `slug` all headings (to account for duplicates),
* but only create a TOC from top-level headings.
*/
visit(root, HEADING, function(child, index, parent) {
var value = toString(child);
var id =
child.data && child.data.hProperties && child.data.hProperties.id;
id = slugs.slug(id || value);
if (parent !== root) {
return;
}
if (lookingForToc) {
if (isClosingHeading(child, depth)) {
closingIndex = index;
lookingForToc = false;
}
if (isOpeningHeading(child, depth, expression)) {
headingIndex = index + 1;
depth = child.depth;
}
}
if (!lookingForToc && value && child.depth <= maxDepth) {
child.__id__ = id;
map.push({
depth: child.depth,
value: value,
id: id
});
}
});
if (headingIndex && !closingIndex) {
closingIndex = length + 1;
}
if (headingIndex === undefined) {
headingIndex = -1;
closingIndex = -1;
map = [];
}
return {
index: headingIndex,
endIndex: closingIndex,
map: map
};
} | javascript | function search(root, expression, maxDepth) {
var length = root.children.length;
var depth = null;
var lookingForToc = expression !== null;
var map = [];
var headingIndex;
var closingIndex;
if (!lookingForToc) {
headingIndex = -1;
}
slugs.reset();
/*
* Visit all headings in `root`.
* We `slug` all headings (to account for duplicates),
* but only create a TOC from top-level headings.
*/
visit(root, HEADING, function(child, index, parent) {
var value = toString(child);
var id =
child.data && child.data.hProperties && child.data.hProperties.id;
id = slugs.slug(id || value);
if (parent !== root) {
return;
}
if (lookingForToc) {
if (isClosingHeading(child, depth)) {
closingIndex = index;
lookingForToc = false;
}
if (isOpeningHeading(child, depth, expression)) {
headingIndex = index + 1;
depth = child.depth;
}
}
if (!lookingForToc && value && child.depth <= maxDepth) {
child.__id__ = id;
map.push({
depth: child.depth,
value: value,
id: id
});
}
});
if (headingIndex && !closingIndex) {
closingIndex = length + 1;
}
if (headingIndex === undefined) {
headingIndex = -1;
closingIndex = -1;
map = [];
}
return {
index: headingIndex,
endIndex: closingIndex,
map: map
};
} | [
"function",
"search",
"(",
"root",
",",
"expression",
",",
"maxDepth",
")",
"{",
"var",
"length",
"=",
"root",
".",
"children",
".",
"length",
";",
"var",
"depth",
"=",
"null",
";",
"var",
"lookingForToc",
"=",
"expression",
"!==",
"null",
";",
"var",
"map",
"=",
"[",
"]",
";",
"var",
"headingIndex",
";",
"var",
"closingIndex",
";",
"if",
"(",
"!",
"lookingForToc",
")",
"{",
"headingIndex",
"=",
"-",
"1",
";",
"}",
"slugs",
".",
"reset",
"(",
")",
";",
"/*\n * Visit all headings in `root`.\n * We `slug` all headings (to account for duplicates),\n * but only create a TOC from top-level headings.\n */",
"visit",
"(",
"root",
",",
"HEADING",
",",
"function",
"(",
"child",
",",
"index",
",",
"parent",
")",
"{",
"var",
"value",
"=",
"toString",
"(",
"child",
")",
";",
"var",
"id",
"=",
"child",
".",
"data",
"&&",
"child",
".",
"data",
".",
"hProperties",
"&&",
"child",
".",
"data",
".",
"hProperties",
".",
"id",
";",
"id",
"=",
"slugs",
".",
"slug",
"(",
"id",
"||",
"value",
")",
";",
"if",
"(",
"parent",
"!==",
"root",
")",
"{",
"return",
";",
"}",
"if",
"(",
"lookingForToc",
")",
"{",
"if",
"(",
"isClosingHeading",
"(",
"child",
",",
"depth",
")",
")",
"{",
"closingIndex",
"=",
"index",
";",
"lookingForToc",
"=",
"false",
";",
"}",
"if",
"(",
"isOpeningHeading",
"(",
"child",
",",
"depth",
",",
"expression",
")",
")",
"{",
"headingIndex",
"=",
"index",
"+",
"1",
";",
"depth",
"=",
"child",
".",
"depth",
";",
"}",
"}",
"if",
"(",
"!",
"lookingForToc",
"&&",
"value",
"&&",
"child",
".",
"depth",
"<=",
"maxDepth",
")",
"{",
"child",
".",
"__id__",
"=",
"id",
";",
"map",
".",
"push",
"(",
"{",
"depth",
":",
"child",
".",
"depth",
",",
"value",
":",
"value",
",",
"id",
":",
"id",
"}",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"headingIndex",
"&&",
"!",
"closingIndex",
")",
"{",
"closingIndex",
"=",
"length",
"+",
"1",
";",
"}",
"if",
"(",
"headingIndex",
"===",
"undefined",
")",
"{",
"headingIndex",
"=",
"-",
"1",
";",
"closingIndex",
"=",
"-",
"1",
";",
"map",
"=",
"[",
"]",
";",
"}",
"return",
"{",
"index",
":",
"headingIndex",
",",
"endIndex",
":",
"closingIndex",
",",
"map",
":",
"map",
"}",
";",
"}"
] | Search a node for a location.
@param {Node} root - Parent to search in.
@param {RegExp} expression - Heading-content to search
for.
@param {number} maxDepth - Maximum-depth to include.
@return {Object} - Results. | [
"Search",
"a",
"node",
"for",
"a",
"location",
"."
] | d7b353dcb5d021eeceb40f3c505ece893202db7a | https://github.com/vmarkdown/vremark-parse/blob/d7b353dcb5d021eeceb40f3c505ece893202db7a/packages/vremark-toc/mdast-util-toc/lib/search.js#L31-L98 |
51,608 | tcrowe/opti-node-watch | src/index.js | colorErrors | function colorErrors(stdLine) {
// lazy load chalk
if (chalk === undefined) {
chalk = require("chalk");
}
return colorErrorPatterns.reduce((op, pattern) => {
const matches = pattern.exec(op);
if (matches !== null && matches.length > 0) {
op = op.replace(pattern, chalk.red(matches[0]));
}
return op;
}, stdLine);
} | javascript | function colorErrors(stdLine) {
// lazy load chalk
if (chalk === undefined) {
chalk = require("chalk");
}
return colorErrorPatterns.reduce((op, pattern) => {
const matches = pattern.exec(op);
if (matches !== null && matches.length > 0) {
op = op.replace(pattern, chalk.red(matches[0]));
}
return op;
}, stdLine);
} | [
"function",
"colorErrors",
"(",
"stdLine",
")",
"{",
"// lazy load chalk",
"if",
"(",
"chalk",
"===",
"undefined",
")",
"{",
"chalk",
"=",
"require",
"(",
"\"chalk\"",
")",
";",
"}",
"return",
"colorErrorPatterns",
".",
"reduce",
"(",
"(",
"op",
",",
"pattern",
")",
"=>",
"{",
"const",
"matches",
"=",
"pattern",
".",
"exec",
"(",
"op",
")",
";",
"if",
"(",
"matches",
"!==",
"null",
"&&",
"matches",
".",
"length",
">",
"0",
")",
"{",
"op",
"=",
"op",
".",
"replace",
"(",
"pattern",
",",
"chalk",
".",
"red",
"(",
"matches",
"[",
"0",
"]",
")",
")",
";",
"}",
"return",
"op",
";",
"}",
",",
"stdLine",
")",
";",
"}"
] | Take a string from stderr and color error types
@private
@method colorErrors
@param {string} stdLine
@returns {string} | [
"Take",
"a",
"string",
"from",
"stderr",
"and",
"color",
"error",
"types"
] | 70fc10ebcf7bf307b3424127b01ad41480eb7501 | https://github.com/tcrowe/opti-node-watch/blob/70fc10ebcf7bf307b3424127b01ad41480eb7501/src/index.js#L101-L116 |
51,609 | tcrowe/opti-node-watch | src/index.js | writeError | function writeError(chunk) {
// in production give the output as-is
if (NODE_ENV === "production") {
return this.queue(chunk);
}
clearTimeout(errorTimer);
errorChunks.push(chunk.toString());
errorTimer = setTimeout(() => {
this.queue(formatErrors(errorChunks.join("")));
}, 10);
} | javascript | function writeError(chunk) {
// in production give the output as-is
if (NODE_ENV === "production") {
return this.queue(chunk);
}
clearTimeout(errorTimer);
errorChunks.push(chunk.toString());
errorTimer = setTimeout(() => {
this.queue(formatErrors(errorChunks.join("")));
}, 10);
} | [
"function",
"writeError",
"(",
"chunk",
")",
"{",
"// in production give the output as-is",
"if",
"(",
"NODE_ENV",
"===",
"\"production\"",
")",
"{",
"return",
"this",
".",
"queue",
"(",
"chunk",
")",
";",
"}",
"clearTimeout",
"(",
"errorTimer",
")",
";",
"errorChunks",
".",
"push",
"(",
"chunk",
".",
"toString",
"(",
")",
")",
";",
"errorTimer",
"=",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"this",
".",
"queue",
"(",
"formatErrors",
"(",
"errorChunks",
".",
"join",
"(",
"\"\"",
")",
")",
")",
";",
"}",
",",
"10",
")",
";",
"}"
] | Used with through module to help us format errors and proxy
stderr output
@private
@method writeError
@param {string|buffer} chunk | [
"Used",
"with",
"through",
"module",
"to",
"help",
"us",
"format",
"errors",
"and",
"proxy",
"stderr",
"output"
] | 70fc10ebcf7bf307b3424127b01ad41480eb7501 | https://github.com/tcrowe/opti-node-watch/blob/70fc10ebcf7bf307b3424127b01ad41480eb7501/src/index.js#L233-L244 |
51,610 | tcrowe/opti-node-watch | src/index.js | respawn | function respawn() {
if (isNil(proc) === false) {
proc.stderr.removeAllListeners();
proc.stderr.end();
proc.stderr.unpipe();
proc.stdout.removeAllListeners();
proc.stdout.end();
proc.stdout.unpipe();
proc.removeAllListeners();
proc.kill();
}
const { env } = process;
const opts = { env };
const args = [];
let cmd;
// run opti-node
// e.g. opti-node script.js
if (exec === "") {
args.push(script);
}
// execute something else
if (exec !== "") {
const [execCmd, ...execArgs] = exec
.trim()
.replace(leadingQuotesPattern, "")
.replace(trailingQuotesPattern)
.split(" ");
cmd = execCmd;
execArgs.forEach(item => args.push(item));
}
if (isNil(cmd) === false) {
// not running opti-node
proc = spawn(cmd, args, opts);
} else {
// running with opti-node
const optiNodeOpts = { args, opts };
optiNodeOpts.cmd = cmd;
proc = createProcess(optiNodeOpts);
}
proc.addListener("close", () => watcher.emit("proc-close"));
proc.addListener("disconnect", () => watcher.emit("proc-disconnect"));
proc.addListener("error", err => watcher.emit("proc-error", err));
proc.addListener("exit", () => watcher.emit("proc-exit"));
proc.stdout.pipe(watcher.stdout);
proc.stderr.pipe(watcher.stderr);
} | javascript | function respawn() {
if (isNil(proc) === false) {
proc.stderr.removeAllListeners();
proc.stderr.end();
proc.stderr.unpipe();
proc.stdout.removeAllListeners();
proc.stdout.end();
proc.stdout.unpipe();
proc.removeAllListeners();
proc.kill();
}
const { env } = process;
const opts = { env };
const args = [];
let cmd;
// run opti-node
// e.g. opti-node script.js
if (exec === "") {
args.push(script);
}
// execute something else
if (exec !== "") {
const [execCmd, ...execArgs] = exec
.trim()
.replace(leadingQuotesPattern, "")
.replace(trailingQuotesPattern)
.split(" ");
cmd = execCmd;
execArgs.forEach(item => args.push(item));
}
if (isNil(cmd) === false) {
// not running opti-node
proc = spawn(cmd, args, opts);
} else {
// running with opti-node
const optiNodeOpts = { args, opts };
optiNodeOpts.cmd = cmd;
proc = createProcess(optiNodeOpts);
}
proc.addListener("close", () => watcher.emit("proc-close"));
proc.addListener("disconnect", () => watcher.emit("proc-disconnect"));
proc.addListener("error", err => watcher.emit("proc-error", err));
proc.addListener("exit", () => watcher.emit("proc-exit"));
proc.stdout.pipe(watcher.stdout);
proc.stderr.pipe(watcher.stderr);
} | [
"function",
"respawn",
"(",
")",
"{",
"if",
"(",
"isNil",
"(",
"proc",
")",
"===",
"false",
")",
"{",
"proc",
".",
"stderr",
".",
"removeAllListeners",
"(",
")",
";",
"proc",
".",
"stderr",
".",
"end",
"(",
")",
";",
"proc",
".",
"stderr",
".",
"unpipe",
"(",
")",
";",
"proc",
".",
"stdout",
".",
"removeAllListeners",
"(",
")",
";",
"proc",
".",
"stdout",
".",
"end",
"(",
")",
";",
"proc",
".",
"stdout",
".",
"unpipe",
"(",
")",
";",
"proc",
".",
"removeAllListeners",
"(",
")",
";",
"proc",
".",
"kill",
"(",
")",
";",
"}",
"const",
"{",
"env",
"}",
"=",
"process",
";",
"const",
"opts",
"=",
"{",
"env",
"}",
";",
"const",
"args",
"=",
"[",
"]",
";",
"let",
"cmd",
";",
"// run opti-node",
"// e.g. opti-node script.js",
"if",
"(",
"exec",
"===",
"\"\"",
")",
"{",
"args",
".",
"push",
"(",
"script",
")",
";",
"}",
"// execute something else",
"if",
"(",
"exec",
"!==",
"\"\"",
")",
"{",
"const",
"[",
"execCmd",
",",
"...",
"execArgs",
"]",
"=",
"exec",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"leadingQuotesPattern",
",",
"\"\"",
")",
".",
"replace",
"(",
"trailingQuotesPattern",
")",
".",
"split",
"(",
"\" \"",
")",
";",
"cmd",
"=",
"execCmd",
";",
"execArgs",
".",
"forEach",
"(",
"item",
"=>",
"args",
".",
"push",
"(",
"item",
")",
")",
";",
"}",
"if",
"(",
"isNil",
"(",
"cmd",
")",
"===",
"false",
")",
"{",
"// not running opti-node",
"proc",
"=",
"spawn",
"(",
"cmd",
",",
"args",
",",
"opts",
")",
";",
"}",
"else",
"{",
"// running with opti-node",
"const",
"optiNodeOpts",
"=",
"{",
"args",
",",
"opts",
"}",
";",
"optiNodeOpts",
".",
"cmd",
"=",
"cmd",
";",
"proc",
"=",
"createProcess",
"(",
"optiNodeOpts",
")",
";",
"}",
"proc",
".",
"addListener",
"(",
"\"close\"",
",",
"(",
")",
"=>",
"watcher",
".",
"emit",
"(",
"\"proc-close\"",
")",
")",
";",
"proc",
".",
"addListener",
"(",
"\"disconnect\"",
",",
"(",
")",
"=>",
"watcher",
".",
"emit",
"(",
"\"proc-disconnect\"",
")",
")",
";",
"proc",
".",
"addListener",
"(",
"\"error\"",
",",
"err",
"=>",
"watcher",
".",
"emit",
"(",
"\"proc-error\"",
",",
"err",
")",
")",
";",
"proc",
".",
"addListener",
"(",
"\"exit\"",
",",
"(",
")",
"=>",
"watcher",
".",
"emit",
"(",
"\"proc-exit\"",
")",
")",
";",
"proc",
".",
"stdout",
".",
"pipe",
"(",
"watcher",
".",
"stdout",
")",
";",
"proc",
".",
"stderr",
".",
"pipe",
"(",
"watcher",
".",
"stderr",
")",
";",
"}"
] | Restart the child process
@private
@method respawn | [
"Restart",
"the",
"child",
"process"
] | 70fc10ebcf7bf307b3424127b01ad41480eb7501 | https://github.com/tcrowe/opti-node-watch/blob/70fc10ebcf7bf307b3424127b01ad41480eb7501/src/index.js#L278-L328 |
51,611 | jeandesravines/promisify | lib/helper/promisify.js | promisify | function promisify(data, prevent = false) {
let promisified;
if (typeof data === 'function') {
promisified = (...args) => new Promise((resolve, reject) => {
data.call(data, ...args.concat((error, ...args) => {
error ? reject(error) : resolve.call(data, ...args);
}));
});
} else if (typeof data === 'object' && false === prevent) {
promisified = new Proxy({}, {
get: (target, property) => promisify(data[property], true),
});
} else if (typeof data === 'string' && false === prevent) {
promisified = promisify(require(data));
} else {
promisified = data;
}
return promisified;
} | javascript | function promisify(data, prevent = false) {
let promisified;
if (typeof data === 'function') {
promisified = (...args) => new Promise((resolve, reject) => {
data.call(data, ...args.concat((error, ...args) => {
error ? reject(error) : resolve.call(data, ...args);
}));
});
} else if (typeof data === 'object' && false === prevent) {
promisified = new Proxy({}, {
get: (target, property) => promisify(data[property], true),
});
} else if (typeof data === 'string' && false === prevent) {
promisified = promisify(require(data));
} else {
promisified = data;
}
return promisified;
} | [
"function",
"promisify",
"(",
"data",
",",
"prevent",
"=",
"false",
")",
"{",
"let",
"promisified",
";",
"if",
"(",
"typeof",
"data",
"===",
"'function'",
")",
"{",
"promisified",
"=",
"(",
"...",
"args",
")",
"=>",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"data",
".",
"call",
"(",
"data",
",",
"...",
"args",
".",
"concat",
"(",
"(",
"error",
",",
"...",
"args",
")",
"=>",
"{",
"error",
"?",
"reject",
"(",
"error",
")",
":",
"resolve",
".",
"call",
"(",
"data",
",",
"...",
"args",
")",
";",
"}",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"data",
"===",
"'object'",
"&&",
"false",
"===",
"prevent",
")",
"{",
"promisified",
"=",
"new",
"Proxy",
"(",
"{",
"}",
",",
"{",
"get",
":",
"(",
"target",
",",
"property",
")",
"=>",
"promisify",
"(",
"data",
"[",
"property",
"]",
",",
"true",
")",
",",
"}",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"data",
"===",
"'string'",
"&&",
"false",
"===",
"prevent",
")",
"{",
"promisified",
"=",
"promisify",
"(",
"require",
"(",
"data",
")",
")",
";",
"}",
"else",
"{",
"promisified",
"=",
"data",
";",
"}",
"return",
"promisified",
";",
"}"
] | Promisify a function
@param {function|Object|string} data
@param {boolean} [prevent]
@return {function(...[*]): Promise} a function wich returns a Promise | [
"Promisify",
"a",
"function"
] | 62d09982d25d879c7d0aad57b13ebaa0a7b11723 | https://github.com/jeandesravines/promisify/blob/62d09982d25d879c7d0aad57b13ebaa0a7b11723/lib/helper/promisify.js#L13-L33 |
51,612 | redisjs/jsr-conf | lib/decoder.js | Decoder | function Decoder(conf, options, file) {
Transform.call(this);
this._writableState.objectMode = true;
this._readableState.objectMode = true;
this.eol = options.eol;
this.conf = conf;
this.file = file;
this.lineNumber = 0;
} | javascript | function Decoder(conf, options, file) {
Transform.call(this);
this._writableState.objectMode = true;
this._readableState.objectMode = true;
this.eol = options.eol;
this.conf = conf;
this.file = file;
this.lineNumber = 0;
} | [
"function",
"Decoder",
"(",
"conf",
",",
"options",
",",
"file",
")",
"{",
"Transform",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_writableState",
".",
"objectMode",
"=",
"true",
";",
"this",
".",
"_readableState",
".",
"objectMode",
"=",
"true",
";",
"this",
".",
"eol",
"=",
"options",
".",
"eol",
";",
"this",
".",
"conf",
"=",
"conf",
";",
"this",
".",
"file",
"=",
"file",
";",
"this",
".",
"lineNumber",
"=",
"0",
";",
"}"
] | Configuration file decoder. | [
"Configuration",
"file",
"decoder",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/decoder.js#L10-L20 |
51,613 | redisjs/jsr-conf | lib/decoder.js | _transform | function _transform(chunk, encoding, cb) {
this.emit('lines', chunk);
try {
this.parse(chunk);
}catch(e) {
this.emit('error', e);
}
cb();
} | javascript | function _transform(chunk, encoding, cb) {
this.emit('lines', chunk);
try {
this.parse(chunk);
}catch(e) {
this.emit('error', e);
}
cb();
} | [
"function",
"_transform",
"(",
"chunk",
",",
"encoding",
",",
"cb",
")",
"{",
"this",
".",
"emit",
"(",
"'lines'",
",",
"chunk",
")",
";",
"try",
"{",
"this",
".",
"parse",
"(",
"chunk",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"e",
")",
";",
"}",
"cb",
"(",
")",
";",
"}"
] | Transform function. | [
"Transform",
"function",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/decoder.js#L27-L38 |
51,614 | redisjs/jsr-conf | lib/decoder.js | parse | function parse(lines) {
var i, line, key, parts, values;
for(i = 0;i < lines.length;i++) {
line = lines[i];
this.lineNumber++;
// ignore comments and whitespace lines
if(COMMENT.test(line) || WHITESPACE.test(line)) {
continue;
// got something to parse
}else{
// strip empty entires, leading whitespace is allowed
parts = line.split(/\s+/).filter(function(p) {
return p;
})
// get the config key
key = parts[0];
// remaining parts to parse as values
values = parts.slice(1);
try {
this.conf.add(key, values, this.lineNumber);
}catch(e) {
throw new ConfigError(this.lineNumber, line, this.file, e);
}
}
}
} | javascript | function parse(lines) {
var i, line, key, parts, values;
for(i = 0;i < lines.length;i++) {
line = lines[i];
this.lineNumber++;
// ignore comments and whitespace lines
if(COMMENT.test(line) || WHITESPACE.test(line)) {
continue;
// got something to parse
}else{
// strip empty entires, leading whitespace is allowed
parts = line.split(/\s+/).filter(function(p) {
return p;
})
// get the config key
key = parts[0];
// remaining parts to parse as values
values = parts.slice(1);
try {
this.conf.add(key, values, this.lineNumber);
}catch(e) {
throw new ConfigError(this.lineNumber, line, this.file, e);
}
}
}
} | [
"function",
"parse",
"(",
"lines",
")",
"{",
"var",
"i",
",",
"line",
",",
"key",
",",
"parts",
",",
"values",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"line",
"=",
"lines",
"[",
"i",
"]",
";",
"this",
".",
"lineNumber",
"++",
";",
"// ignore comments and whitespace lines",
"if",
"(",
"COMMENT",
".",
"test",
"(",
"line",
")",
"||",
"WHITESPACE",
".",
"test",
"(",
"line",
")",
")",
"{",
"continue",
";",
"// got something to parse",
"}",
"else",
"{",
"// strip empty entires, leading whitespace is allowed",
"parts",
"=",
"line",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
".",
"filter",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
";",
"}",
")",
"// get the config key",
"key",
"=",
"parts",
"[",
"0",
"]",
";",
"// remaining parts to parse as values",
"values",
"=",
"parts",
".",
"slice",
"(",
"1",
")",
";",
"try",
"{",
"this",
".",
"conf",
".",
"add",
"(",
"key",
",",
"values",
",",
"this",
".",
"lineNumber",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"ConfigError",
"(",
"this",
".",
"lineNumber",
",",
"line",
",",
"this",
".",
"file",
",",
"e",
")",
";",
"}",
"}",
"}",
"}"
] | Synchronous line parser. | [
"Synchronous",
"line",
"parser",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/decoder.js#L43-L73 |
51,615 | tjmehta/mongooseware | lib/base-middleware.js | BaseMiddleware | function BaseMiddleware (Model, key) {
// constructor
var instance = function (req, res, next) {
return instance.exec()(req, res, next);
};
instance.Model = Model;
instance.methodChain = [];
instance.__proto__ = this.__proto__;
instance.setKey = function (key) {
key = key || Model.modelName.toLowerCase();
instance.modelKey = inflect.singularize(key);
instance.collectionKey = inflect.pluralize(key);
};
instance.setKey(key);
return instance;
} | javascript | function BaseMiddleware (Model, key) {
// constructor
var instance = function (req, res, next) {
return instance.exec()(req, res, next);
};
instance.Model = Model;
instance.methodChain = [];
instance.__proto__ = this.__proto__;
instance.setKey = function (key) {
key = key || Model.modelName.toLowerCase();
instance.modelKey = inflect.singularize(key);
instance.collectionKey = inflect.pluralize(key);
};
instance.setKey(key);
return instance;
} | [
"function",
"BaseMiddleware",
"(",
"Model",
",",
"key",
")",
"{",
"// constructor",
"var",
"instance",
"=",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"return",
"instance",
".",
"exec",
"(",
")",
"(",
"req",
",",
"res",
",",
"next",
")",
";",
"}",
";",
"instance",
".",
"Model",
"=",
"Model",
";",
"instance",
".",
"methodChain",
"=",
"[",
"]",
";",
"instance",
".",
"__proto__",
"=",
"this",
".",
"__proto__",
";",
"instance",
".",
"setKey",
"=",
"function",
"(",
"key",
")",
"{",
"key",
"=",
"key",
"||",
"Model",
".",
"modelName",
".",
"toLowerCase",
"(",
")",
";",
"instance",
".",
"modelKey",
"=",
"inflect",
".",
"singularize",
"(",
"key",
")",
";",
"instance",
".",
"collectionKey",
"=",
"inflect",
".",
"pluralize",
"(",
"key",
")",
";",
"}",
";",
"instance",
".",
"setKey",
"(",
"key",
")",
";",
"return",
"instance",
";",
"}"
] | uses Model and key from closure
@param {Object} Model
@param {String} key
@return {Object} | [
"uses",
"Model",
"and",
"key",
"from",
"closure"
] | c62ce0bac82880826b3528231e08f5e5b3efdb83 | https://github.com/tjmehta/mongooseware/blob/c62ce0bac82880826b3528231e08f5e5b3efdb83/lib/base-middleware.js#L18-L35 |
51,616 | xsolon/spexplorerjs | webapi/src/components/sp/api/sp.web.js | function (url, site, ctx, loadFunc) {
return $.Deferred(function (dfd) {
ctx = ctx || SP.ClientContext.get_current();
site = site || ctx.get_site();
var web = (url) ? (typeof url == "string") ? site.openWeb(url) : url : ctx.get_web();
var res = loadFunc && loadFunc(web) || ctx.load(web);
ctx.executeQueryAsync(
function (sender, args) {
dfd.resolve(web, res, sender, args);
},
function onError(sender, args) {
dfd.reject({ sender: sender, args: args });
//dfd.reject('Request failed ' + args.get_message() + '\n' + args.get_stackTrace());
});
}).promise();
} | javascript | function (url, site, ctx, loadFunc) {
return $.Deferred(function (dfd) {
ctx = ctx || SP.ClientContext.get_current();
site = site || ctx.get_site();
var web = (url) ? (typeof url == "string") ? site.openWeb(url) : url : ctx.get_web();
var res = loadFunc && loadFunc(web) || ctx.load(web);
ctx.executeQueryAsync(
function (sender, args) {
dfd.resolve(web, res, sender, args);
},
function onError(sender, args) {
dfd.reject({ sender: sender, args: args });
//dfd.reject('Request failed ' + args.get_message() + '\n' + args.get_stackTrace());
});
}).promise();
} | [
"function",
"(",
"url",
",",
"site",
",",
"ctx",
",",
"loadFunc",
")",
"{",
"return",
"$",
".",
"Deferred",
"(",
"function",
"(",
"dfd",
")",
"{",
"ctx",
"=",
"ctx",
"||",
"SP",
".",
"ClientContext",
".",
"get_current",
"(",
")",
";",
"site",
"=",
"site",
"||",
"ctx",
".",
"get_site",
"(",
")",
";",
"var",
"web",
"=",
"(",
"url",
")",
"?",
"(",
"typeof",
"url",
"==",
"\"string\"",
")",
"?",
"site",
".",
"openWeb",
"(",
"url",
")",
":",
"url",
":",
"ctx",
".",
"get_web",
"(",
")",
";",
"var",
"res",
"=",
"loadFunc",
"&&",
"loadFunc",
"(",
"web",
")",
"||",
"ctx",
".",
"load",
"(",
"web",
")",
";",
"ctx",
".",
"executeQueryAsync",
"(",
"function",
"(",
"sender",
",",
"args",
")",
"{",
"dfd",
".",
"resolve",
"(",
"web",
",",
"res",
",",
"sender",
",",
"args",
")",
";",
"}",
",",
"function",
"onError",
"(",
"sender",
",",
"args",
")",
"{",
"dfd",
".",
"reject",
"(",
"{",
"sender",
":",
"sender",
",",
"args",
":",
"args",
"}",
")",
";",
"//dfd.reject('Request failed ' + args.get_message() + '\\n' + args.get_stackTrace());",
"}",
")",
";",
"}",
")",
".",
"promise",
"(",
")",
";",
"}"
] | Load an existing site
fails if site doesn't exist
@param {string} url - site relative url of web
@param {spsite} site- site reference, if null will load from current context
@param {ClientContext} ctx - SharePoint client context, if null the current context will be used
@param {function} loadFunc - function run before the web is loaded (web will be passed as argument) | [
"Load",
"an",
"existing",
"site",
"fails",
"if",
"site",
"doesn",
"t",
"exist"
] | 4e9b410864afb731f88e84414984fa18ac5705f1 | https://github.com/xsolon/spexplorerjs/blob/4e9b410864afb731f88e84414984fa18ac5705f1/webapi/src/components/sp/api/sp.web.js#L40-L57 |
|
51,617 | redisjs/jsr-server | lib/command/transaction/watch.js | execute | function execute(req, res) {
req.conn.watch(req.args, req.db);
res.send(null, Constants.OK);
} | javascript | function execute(req, res) {
req.conn.watch(req.args, req.db);
res.send(null, Constants.OK);
} | [
"function",
"execute",
"(",
"req",
",",
"res",
")",
"{",
"req",
".",
"conn",
".",
"watch",
"(",
"req",
".",
"args",
",",
"req",
".",
"db",
")",
";",
"res",
".",
"send",
"(",
"null",
",",
"Constants",
".",
"OK",
")",
";",
"}"
] | Respond to the WATCH command. | [
"Respond",
"to",
"the",
"WATCH",
"command",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/transaction/watch.js#L19-L22 |
51,618 | vkiding/judpack-lib | src/cordova/platform.js | getPlatformDetailsFromDir | function getPlatformDetailsFromDir(dir, platformIfKnown){
var libDir = path.resolve(dir);
var platform;
var version;
try {
var pkg = require(path.join(libDir, 'package'));
platform = platformFromName(pkg.name);
version = pkg.version;
} catch(e) {
// Older platforms didn't have package.json.
platform = platformIfKnown || platformFromName(path.basename(dir));
var verFile = fs.existsSync(path.join(libDir, 'VERSION')) ? path.join(libDir, 'VERSION') :
fs.existsSync(path.join(libDir, 'CordovaLib', 'VERSION')) ? path.join(libDir, 'CordovaLib', 'VERSION') : null;
if (verFile) {
version = fs.readFileSync(verFile, 'UTF-8').trim();
}
}
// if (!version || !platform || !platforms[platform]) {
// return Q.reject(new CordovaError('The provided path does not seem to contain a ' +
// 'Cordova platform: ' + libDir));
// }
return Q({
libDir: libDir,
platform: platform || platformIfKnown,
version: version || '0.0.1'
});
} | javascript | function getPlatformDetailsFromDir(dir, platformIfKnown){
var libDir = path.resolve(dir);
var platform;
var version;
try {
var pkg = require(path.join(libDir, 'package'));
platform = platformFromName(pkg.name);
version = pkg.version;
} catch(e) {
// Older platforms didn't have package.json.
platform = platformIfKnown || platformFromName(path.basename(dir));
var verFile = fs.existsSync(path.join(libDir, 'VERSION')) ? path.join(libDir, 'VERSION') :
fs.existsSync(path.join(libDir, 'CordovaLib', 'VERSION')) ? path.join(libDir, 'CordovaLib', 'VERSION') : null;
if (verFile) {
version = fs.readFileSync(verFile, 'UTF-8').trim();
}
}
// if (!version || !platform || !platforms[platform]) {
// return Q.reject(new CordovaError('The provided path does not seem to contain a ' +
// 'Cordova platform: ' + libDir));
// }
return Q({
libDir: libDir,
platform: platform || platformIfKnown,
version: version || '0.0.1'
});
} | [
"function",
"getPlatformDetailsFromDir",
"(",
"dir",
",",
"platformIfKnown",
")",
"{",
"var",
"libDir",
"=",
"path",
".",
"resolve",
"(",
"dir",
")",
";",
"var",
"platform",
";",
"var",
"version",
";",
"try",
"{",
"var",
"pkg",
"=",
"require",
"(",
"path",
".",
"join",
"(",
"libDir",
",",
"'package'",
")",
")",
";",
"platform",
"=",
"platformFromName",
"(",
"pkg",
".",
"name",
")",
";",
"version",
"=",
"pkg",
".",
"version",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// Older platforms didn't have package.json.",
"platform",
"=",
"platformIfKnown",
"||",
"platformFromName",
"(",
"path",
".",
"basename",
"(",
"dir",
")",
")",
";",
"var",
"verFile",
"=",
"fs",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"libDir",
",",
"'VERSION'",
")",
")",
"?",
"path",
".",
"join",
"(",
"libDir",
",",
"'VERSION'",
")",
":",
"fs",
".",
"existsSync",
"(",
"path",
".",
"join",
"(",
"libDir",
",",
"'CordovaLib'",
",",
"'VERSION'",
")",
")",
"?",
"path",
".",
"join",
"(",
"libDir",
",",
"'CordovaLib'",
",",
"'VERSION'",
")",
":",
"null",
";",
"if",
"(",
"verFile",
")",
"{",
"version",
"=",
"fs",
".",
"readFileSync",
"(",
"verFile",
",",
"'UTF-8'",
")",
".",
"trim",
"(",
")",
";",
"}",
"}",
"// if (!version || !platform || !platforms[platform]) {",
"// return Q.reject(new CordovaError('The provided path does not seem to contain a ' +",
"// 'Cordova platform: ' + libDir));",
"// }",
"return",
"Q",
"(",
"{",
"libDir",
":",
"libDir",
",",
"platform",
":",
"platform",
"||",
"platformIfKnown",
",",
"version",
":",
"version",
"||",
"'0.0.1'",
"}",
")",
";",
"}"
] | Returns a Promise Gets platform details from a directory | [
"Returns",
"a",
"Promise",
"Gets",
"platform",
"details",
"from",
"a",
"directory"
] | 8657cecfec68221109279106adca8dbc81f430f4 | https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/cordova/platform.js#L333-L362 |
51,619 | vkiding/judpack-lib | src/cordova/platform.js | hostSupports | function hostSupports(platform) {
var p = platforms[platform] || {},
hostos = p.hostos || null;
if (!hostos)
return true;
if (hostos.indexOf('*') >= 0)
return true;
if (hostos.indexOf(process.platform) >= 0)
return true;
return false;
} | javascript | function hostSupports(platform) {
var p = platforms[platform] || {},
hostos = p.hostos || null;
if (!hostos)
return true;
if (hostos.indexOf('*') >= 0)
return true;
if (hostos.indexOf(process.platform) >= 0)
return true;
return false;
} | [
"function",
"hostSupports",
"(",
"platform",
")",
"{",
"var",
"p",
"=",
"platforms",
"[",
"platform",
"]",
"||",
"{",
"}",
",",
"hostos",
"=",
"p",
".",
"hostos",
"||",
"null",
";",
"if",
"(",
"!",
"hostos",
")",
"return",
"true",
";",
"if",
"(",
"hostos",
".",
"indexOf",
"(",
"'*'",
")",
">=",
"0",
")",
"return",
"true",
";",
"if",
"(",
"hostos",
".",
"indexOf",
"(",
"process",
".",
"platform",
")",
">=",
"0",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Used to prevent attempts of installing platforms that are not supported on the host OS. E.g. ios on linux. | [
"Used",
"to",
"prevent",
"attempts",
"of",
"installing",
"platforms",
"that",
"are",
"not",
"supported",
"on",
"the",
"host",
"OS",
".",
"E",
".",
"g",
".",
"ios",
"on",
"linux",
"."
] | 8657cecfec68221109279106adca8dbc81f430f4 | https://github.com/vkiding/judpack-lib/blob/8657cecfec68221109279106adca8dbc81f430f4/src/cordova/platform.js#L660-L670 |
51,620 | vivaxy/react-pianist | docs/js/common.js | mixSpecIntoComponent | function mixSpecIntoComponent(Constructor, spec) {
if (!spec) {
if (false) {
var typeofSpec = typeof spec;
var isMixinValid = typeofSpec === 'object' && spec !== null;
process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
}
return;
}
!(typeof spec !== 'function') ? false ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0;
!!ReactElement.isValidElement(spec) ? false ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0;
var proto = Constructor.prototype;
var autoBindPairs = proto.__reactAutoBindPairs;
// By handling mixins before any other properties, we ensure the same
// chaining order is applied to methods with DEFINE_MANY policy, whether
// mixins are listed before or after these methods in the spec.
if (spec.hasOwnProperty(MIXINS_KEY)) {
RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
}
for (var name in spec) {
if (!spec.hasOwnProperty(name)) {
continue;
}
if (name === MIXINS_KEY) {
// We have already handled mixins in a special case above.
continue;
}
var property = spec[name];
var isAlreadyDefined = proto.hasOwnProperty(name);
validateMethodOverride(isAlreadyDefined, name);
if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
RESERVED_SPEC_KEYS[name](Constructor, property);
} else {
// Setup methods on prototype:
// The following member methods should not be automatically bound:
// 1. Expected ReactClass methods (in the "interface").
// 2. Overridden methods (that were mixed in).
var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
var isFunction = typeof property === 'function';
var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
if (shouldAutoBind) {
autoBindPairs.push(name, property);
proto[name] = property;
} else {
if (isAlreadyDefined) {
var specPolicy = ReactClassInterface[name];
// These cases should already be caught by validateMethodOverride.
!(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? false ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0;
// For methods which are defined more than once, call the existing
// methods before calling the new property, merging if appropriate.
if (specPolicy === 'DEFINE_MANY_MERGED') {
proto[name] = createMergedResultFunction(proto[name], property);
} else if (specPolicy === 'DEFINE_MANY') {
proto[name] = createChainedFunction(proto[name], property);
}
} else {
proto[name] = property;
if (false) {
// Add verbose displayName to the function, which helps when looking
// at profiling tools.
if (typeof property === 'function' && spec.displayName) {
proto[name].displayName = spec.displayName + '_' + name;
}
}
}
}
}
}
} | javascript | function mixSpecIntoComponent(Constructor, spec) {
if (!spec) {
if (false) {
var typeofSpec = typeof spec;
var isMixinValid = typeofSpec === 'object' && spec !== null;
process.env.NODE_ENV !== 'production' ? warning(isMixinValid, '%s: You\'re attempting to include a mixin that is either null ' + 'or not an object. Check the mixins included by the component, ' + 'as well as any mixins they include themselves. ' + 'Expected object but got %s.', Constructor.displayName || 'ReactClass', spec === null ? null : typeofSpec) : void 0;
}
return;
}
!(typeof spec !== 'function') ? false ? invariant(false, 'ReactClass: You\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.') : _prodInvariant('75') : void 0;
!!ReactElement.isValidElement(spec) ? false ? invariant(false, 'ReactClass: You\'re attempting to use a component as a mixin. Instead, just use a regular object.') : _prodInvariant('76') : void 0;
var proto = Constructor.prototype;
var autoBindPairs = proto.__reactAutoBindPairs;
// By handling mixins before any other properties, we ensure the same
// chaining order is applied to methods with DEFINE_MANY policy, whether
// mixins are listed before or after these methods in the spec.
if (spec.hasOwnProperty(MIXINS_KEY)) {
RESERVED_SPEC_KEYS.mixins(Constructor, spec.mixins);
}
for (var name in spec) {
if (!spec.hasOwnProperty(name)) {
continue;
}
if (name === MIXINS_KEY) {
// We have already handled mixins in a special case above.
continue;
}
var property = spec[name];
var isAlreadyDefined = proto.hasOwnProperty(name);
validateMethodOverride(isAlreadyDefined, name);
if (RESERVED_SPEC_KEYS.hasOwnProperty(name)) {
RESERVED_SPEC_KEYS[name](Constructor, property);
} else {
// Setup methods on prototype:
// The following member methods should not be automatically bound:
// 1. Expected ReactClass methods (in the "interface").
// 2. Overridden methods (that were mixed in).
var isReactClassMethod = ReactClassInterface.hasOwnProperty(name);
var isFunction = typeof property === 'function';
var shouldAutoBind = isFunction && !isReactClassMethod && !isAlreadyDefined && spec.autobind !== false;
if (shouldAutoBind) {
autoBindPairs.push(name, property);
proto[name] = property;
} else {
if (isAlreadyDefined) {
var specPolicy = ReactClassInterface[name];
// These cases should already be caught by validateMethodOverride.
!(isReactClassMethod && (specPolicy === 'DEFINE_MANY_MERGED' || specPolicy === 'DEFINE_MANY')) ? false ? invariant(false, 'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.', specPolicy, name) : _prodInvariant('77', specPolicy, name) : void 0;
// For methods which are defined more than once, call the existing
// methods before calling the new property, merging if appropriate.
if (specPolicy === 'DEFINE_MANY_MERGED') {
proto[name] = createMergedResultFunction(proto[name], property);
} else if (specPolicy === 'DEFINE_MANY') {
proto[name] = createChainedFunction(proto[name], property);
}
} else {
proto[name] = property;
if (false) {
// Add verbose displayName to the function, which helps when looking
// at profiling tools.
if (typeof property === 'function' && spec.displayName) {
proto[name].displayName = spec.displayName + '_' + name;
}
}
}
}
}
}
} | [
"function",
"mixSpecIntoComponent",
"(",
"Constructor",
",",
"spec",
")",
"{",
"if",
"(",
"!",
"spec",
")",
"{",
"if",
"(",
"false",
")",
"{",
"var",
"typeofSpec",
"=",
"typeof",
"spec",
";",
"var",
"isMixinValid",
"=",
"typeofSpec",
"===",
"'object'",
"&&",
"spec",
"!==",
"null",
";",
"process",
".",
"env",
".",
"NODE_ENV",
"!==",
"'production'",
"?",
"warning",
"(",
"isMixinValid",
",",
"'%s: You\\'re attempting to include a mixin that is either null '",
"+",
"'or not an object. Check the mixins included by the component, '",
"+",
"'as well as any mixins they include themselves. '",
"+",
"'Expected object but got %s.'",
",",
"Constructor",
".",
"displayName",
"||",
"'ReactClass'",
",",
"spec",
"===",
"null",
"?",
"null",
":",
"typeofSpec",
")",
":",
"void",
"0",
";",
"}",
"return",
";",
"}",
"!",
"(",
"typeof",
"spec",
"!==",
"'function'",
")",
"?",
"false",
"?",
"invariant",
"(",
"false",
",",
"'ReactClass: You\\'re attempting to use a component class or function as a mixin. Instead, just use a regular object.'",
")",
":",
"_prodInvariant",
"(",
"'75'",
")",
":",
"void",
"0",
";",
"!",
"!",
"ReactElement",
".",
"isValidElement",
"(",
"spec",
")",
"?",
"false",
"?",
"invariant",
"(",
"false",
",",
"'ReactClass: You\\'re attempting to use a component as a mixin. Instead, just use a regular object.'",
")",
":",
"_prodInvariant",
"(",
"'76'",
")",
":",
"void",
"0",
";",
"var",
"proto",
"=",
"Constructor",
".",
"prototype",
";",
"var",
"autoBindPairs",
"=",
"proto",
".",
"__reactAutoBindPairs",
";",
"// By handling mixins before any other properties, we ensure the same",
"// chaining order is applied to methods with DEFINE_MANY policy, whether",
"// mixins are listed before or after these methods in the spec.",
"if",
"(",
"spec",
".",
"hasOwnProperty",
"(",
"MIXINS_KEY",
")",
")",
"{",
"RESERVED_SPEC_KEYS",
".",
"mixins",
"(",
"Constructor",
",",
"spec",
".",
"mixins",
")",
";",
"}",
"for",
"(",
"var",
"name",
"in",
"spec",
")",
"{",
"if",
"(",
"!",
"spec",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"name",
"===",
"MIXINS_KEY",
")",
"{",
"// We have already handled mixins in a special case above.",
"continue",
";",
"}",
"var",
"property",
"=",
"spec",
"[",
"name",
"]",
";",
"var",
"isAlreadyDefined",
"=",
"proto",
".",
"hasOwnProperty",
"(",
"name",
")",
";",
"validateMethodOverride",
"(",
"isAlreadyDefined",
",",
"name",
")",
";",
"if",
"(",
"RESERVED_SPEC_KEYS",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"RESERVED_SPEC_KEYS",
"[",
"name",
"]",
"(",
"Constructor",
",",
"property",
")",
";",
"}",
"else",
"{",
"// Setup methods on prototype:",
"// The following member methods should not be automatically bound:",
"// 1. Expected ReactClass methods (in the \"interface\").",
"// 2. Overridden methods (that were mixed in).",
"var",
"isReactClassMethod",
"=",
"ReactClassInterface",
".",
"hasOwnProperty",
"(",
"name",
")",
";",
"var",
"isFunction",
"=",
"typeof",
"property",
"===",
"'function'",
";",
"var",
"shouldAutoBind",
"=",
"isFunction",
"&&",
"!",
"isReactClassMethod",
"&&",
"!",
"isAlreadyDefined",
"&&",
"spec",
".",
"autobind",
"!==",
"false",
";",
"if",
"(",
"shouldAutoBind",
")",
"{",
"autoBindPairs",
".",
"push",
"(",
"name",
",",
"property",
")",
";",
"proto",
"[",
"name",
"]",
"=",
"property",
";",
"}",
"else",
"{",
"if",
"(",
"isAlreadyDefined",
")",
"{",
"var",
"specPolicy",
"=",
"ReactClassInterface",
"[",
"name",
"]",
";",
"// These cases should already be caught by validateMethodOverride.",
"!",
"(",
"isReactClassMethod",
"&&",
"(",
"specPolicy",
"===",
"'DEFINE_MANY_MERGED'",
"||",
"specPolicy",
"===",
"'DEFINE_MANY'",
")",
")",
"?",
"false",
"?",
"invariant",
"(",
"false",
",",
"'ReactClass: Unexpected spec policy %s for key %s when mixing in component specs.'",
",",
"specPolicy",
",",
"name",
")",
":",
"_prodInvariant",
"(",
"'77'",
",",
"specPolicy",
",",
"name",
")",
":",
"void",
"0",
";",
"// For methods which are defined more than once, call the existing",
"// methods before calling the new property, merging if appropriate.",
"if",
"(",
"specPolicy",
"===",
"'DEFINE_MANY_MERGED'",
")",
"{",
"proto",
"[",
"name",
"]",
"=",
"createMergedResultFunction",
"(",
"proto",
"[",
"name",
"]",
",",
"property",
")",
";",
"}",
"else",
"if",
"(",
"specPolicy",
"===",
"'DEFINE_MANY'",
")",
"{",
"proto",
"[",
"name",
"]",
"=",
"createChainedFunction",
"(",
"proto",
"[",
"name",
"]",
",",
"property",
")",
";",
"}",
"}",
"else",
"{",
"proto",
"[",
"name",
"]",
"=",
"property",
";",
"if",
"(",
"false",
")",
"{",
"// Add verbose displayName to the function, which helps when looking",
"// at profiling tools.",
"if",
"(",
"typeof",
"property",
"===",
"'function'",
"&&",
"spec",
".",
"displayName",
")",
"{",
"proto",
"[",
"name",
"]",
".",
"displayName",
"=",
"spec",
".",
"displayName",
"+",
"'_'",
"+",
"name",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}"
] | Mixin helper which handles policy validation and reserved
specification keys when building React classes. | [
"Mixin",
"helper",
"which",
"handles",
"policy",
"validation",
"and",
"reserved",
"specification",
"keys",
"when",
"building",
"React",
"classes",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L2214-L2294 |
51,621 | vivaxy/react-pianist | docs/js/common.js | function (event) {
var dispatchConfig = event.dispatchConfig;
if (dispatchConfig.registrationName) {
return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
}
if (dispatchConfig.phasedRegistrationNames !== undefined) {
// pulling phasedRegistrationNames out of dispatchConfig helps Flow see
// that it is not undefined.
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
for (var phase in phasedRegistrationNames) {
if (!phasedRegistrationNames.hasOwnProperty(phase)) {
continue;
}
var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]];
if (pluginModule) {
return pluginModule;
}
}
}
return null;
} | javascript | function (event) {
var dispatchConfig = event.dispatchConfig;
if (dispatchConfig.registrationName) {
return EventPluginRegistry.registrationNameModules[dispatchConfig.registrationName] || null;
}
if (dispatchConfig.phasedRegistrationNames !== undefined) {
// pulling phasedRegistrationNames out of dispatchConfig helps Flow see
// that it is not undefined.
var phasedRegistrationNames = dispatchConfig.phasedRegistrationNames;
for (var phase in phasedRegistrationNames) {
if (!phasedRegistrationNames.hasOwnProperty(phase)) {
continue;
}
var pluginModule = EventPluginRegistry.registrationNameModules[phasedRegistrationNames[phase]];
if (pluginModule) {
return pluginModule;
}
}
}
return null;
} | [
"function",
"(",
"event",
")",
"{",
"var",
"dispatchConfig",
"=",
"event",
".",
"dispatchConfig",
";",
"if",
"(",
"dispatchConfig",
".",
"registrationName",
")",
"{",
"return",
"EventPluginRegistry",
".",
"registrationNameModules",
"[",
"dispatchConfig",
".",
"registrationName",
"]",
"||",
"null",
";",
"}",
"if",
"(",
"dispatchConfig",
".",
"phasedRegistrationNames",
"!==",
"undefined",
")",
"{",
"// pulling phasedRegistrationNames out of dispatchConfig helps Flow see",
"// that it is not undefined.",
"var",
"phasedRegistrationNames",
"=",
"dispatchConfig",
".",
"phasedRegistrationNames",
";",
"for",
"(",
"var",
"phase",
"in",
"phasedRegistrationNames",
")",
"{",
"if",
"(",
"!",
"phasedRegistrationNames",
".",
"hasOwnProperty",
"(",
"phase",
")",
")",
"{",
"continue",
";",
"}",
"var",
"pluginModule",
"=",
"EventPluginRegistry",
".",
"registrationNameModules",
"[",
"phasedRegistrationNames",
"[",
"phase",
"]",
"]",
";",
"if",
"(",
"pluginModule",
")",
"{",
"return",
"pluginModule",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | Looks up the plugin for the supplied event.
@param {object} event A synthetic event.
@return {?object} The plugin that created the supplied event.
@internal | [
"Looks",
"up",
"the",
"plugin",
"for",
"the",
"supplied",
"event",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L5020-L5041 |
|
51,622 | vivaxy/react-pianist | docs/js/common.js | function () {
eventPluginOrder = null;
for (var pluginName in namesToPlugins) {
if (namesToPlugins.hasOwnProperty(pluginName)) {
delete namesToPlugins[pluginName];
}
}
EventPluginRegistry.plugins.length = 0;
var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
for (var eventName in eventNameDispatchConfigs) {
if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
delete eventNameDispatchConfigs[eventName];
}
}
var registrationNameModules = EventPluginRegistry.registrationNameModules;
for (var registrationName in registrationNameModules) {
if (registrationNameModules.hasOwnProperty(registrationName)) {
delete registrationNameModules[registrationName];
}
}
if (false) {
var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
for (var lowerCasedName in possibleRegistrationNames) {
if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
delete possibleRegistrationNames[lowerCasedName];
}
}
}
} | javascript | function () {
eventPluginOrder = null;
for (var pluginName in namesToPlugins) {
if (namesToPlugins.hasOwnProperty(pluginName)) {
delete namesToPlugins[pluginName];
}
}
EventPluginRegistry.plugins.length = 0;
var eventNameDispatchConfigs = EventPluginRegistry.eventNameDispatchConfigs;
for (var eventName in eventNameDispatchConfigs) {
if (eventNameDispatchConfigs.hasOwnProperty(eventName)) {
delete eventNameDispatchConfigs[eventName];
}
}
var registrationNameModules = EventPluginRegistry.registrationNameModules;
for (var registrationName in registrationNameModules) {
if (registrationNameModules.hasOwnProperty(registrationName)) {
delete registrationNameModules[registrationName];
}
}
if (false) {
var possibleRegistrationNames = EventPluginRegistry.possibleRegistrationNames;
for (var lowerCasedName in possibleRegistrationNames) {
if (possibleRegistrationNames.hasOwnProperty(lowerCasedName)) {
delete possibleRegistrationNames[lowerCasedName];
}
}
}
} | [
"function",
"(",
")",
"{",
"eventPluginOrder",
"=",
"null",
";",
"for",
"(",
"var",
"pluginName",
"in",
"namesToPlugins",
")",
"{",
"if",
"(",
"namesToPlugins",
".",
"hasOwnProperty",
"(",
"pluginName",
")",
")",
"{",
"delete",
"namesToPlugins",
"[",
"pluginName",
"]",
";",
"}",
"}",
"EventPluginRegistry",
".",
"plugins",
".",
"length",
"=",
"0",
";",
"var",
"eventNameDispatchConfigs",
"=",
"EventPluginRegistry",
".",
"eventNameDispatchConfigs",
";",
"for",
"(",
"var",
"eventName",
"in",
"eventNameDispatchConfigs",
")",
"{",
"if",
"(",
"eventNameDispatchConfigs",
".",
"hasOwnProperty",
"(",
"eventName",
")",
")",
"{",
"delete",
"eventNameDispatchConfigs",
"[",
"eventName",
"]",
";",
"}",
"}",
"var",
"registrationNameModules",
"=",
"EventPluginRegistry",
".",
"registrationNameModules",
";",
"for",
"(",
"var",
"registrationName",
"in",
"registrationNameModules",
")",
"{",
"if",
"(",
"registrationNameModules",
".",
"hasOwnProperty",
"(",
"registrationName",
")",
")",
"{",
"delete",
"registrationNameModules",
"[",
"registrationName",
"]",
";",
"}",
"}",
"if",
"(",
"false",
")",
"{",
"var",
"possibleRegistrationNames",
"=",
"EventPluginRegistry",
".",
"possibleRegistrationNames",
";",
"for",
"(",
"var",
"lowerCasedName",
"in",
"possibleRegistrationNames",
")",
"{",
"if",
"(",
"possibleRegistrationNames",
".",
"hasOwnProperty",
"(",
"lowerCasedName",
")",
")",
"{",
"delete",
"possibleRegistrationNames",
"[",
"lowerCasedName",
"]",
";",
"}",
"}",
"}",
"}"
] | Exposed for unit testing.
@private | [
"Exposed",
"for",
"unit",
"testing",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L5047-L5078 |
|
51,623 | vivaxy/react-pianist | docs/js/common.js | asap | function asap(callback, context) {
!batchingStrategy.isBatchingUpdates ? false ? invariant(false, 'ReactUpdates.asap: Can\'t enqueue an asap callback in a context whereupdates are not being batched.') : _prodInvariant('125') : void 0;
asapCallbackQueue.enqueue(callback, context);
asapEnqueued = true;
} | javascript | function asap(callback, context) {
!batchingStrategy.isBatchingUpdates ? false ? invariant(false, 'ReactUpdates.asap: Can\'t enqueue an asap callback in a context whereupdates are not being batched.') : _prodInvariant('125') : void 0;
asapCallbackQueue.enqueue(callback, context);
asapEnqueued = true;
} | [
"function",
"asap",
"(",
"callback",
",",
"context",
")",
"{",
"!",
"batchingStrategy",
".",
"isBatchingUpdates",
"?",
"false",
"?",
"invariant",
"(",
"false",
",",
"'ReactUpdates.asap: Can\\'t enqueue an asap callback in a context whereupdates are not being batched.'",
")",
":",
"_prodInvariant",
"(",
"'125'",
")",
":",
"void",
"0",
";",
"asapCallbackQueue",
".",
"enqueue",
"(",
"callback",
",",
"context",
")",
";",
"asapEnqueued",
"=",
"true",
";",
"}"
] | Enqueue a callback to be run at the end of the current batching cycle. Throws
if no updates are currently being performed. | [
"Enqueue",
"a",
"callback",
"to",
"be",
"run",
"at",
"the",
"end",
"of",
"the",
"current",
"batching",
"cycle",
".",
"Throws",
"if",
"no",
"updates",
"are",
"currently",
"being",
"performed",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L6565-L6569 |
51,624 | vivaxy/react-pianist | docs/js/common.js | unmountComponentFromNode | function unmountComponentFromNode(instance, container, safely) {
if (false) {
ReactInstrumentation.debugTool.onBeginFlush();
}
ReactReconciler.unmountComponent(instance, safely);
if (false) {
ReactInstrumentation.debugTool.onEndFlush();
}
if (container.nodeType === DOC_NODE_TYPE) {
container = container.documentElement;
}
// http://jsperf.com/emptying-a-node
while (container.lastChild) {
container.removeChild(container.lastChild);
}
} | javascript | function unmountComponentFromNode(instance, container, safely) {
if (false) {
ReactInstrumentation.debugTool.onBeginFlush();
}
ReactReconciler.unmountComponent(instance, safely);
if (false) {
ReactInstrumentation.debugTool.onEndFlush();
}
if (container.nodeType === DOC_NODE_TYPE) {
container = container.documentElement;
}
// http://jsperf.com/emptying-a-node
while (container.lastChild) {
container.removeChild(container.lastChild);
}
} | [
"function",
"unmountComponentFromNode",
"(",
"instance",
",",
"container",
",",
"safely",
")",
"{",
"if",
"(",
"false",
")",
"{",
"ReactInstrumentation",
".",
"debugTool",
".",
"onBeginFlush",
"(",
")",
";",
"}",
"ReactReconciler",
".",
"unmountComponent",
"(",
"instance",
",",
"safely",
")",
";",
"if",
"(",
"false",
")",
"{",
"ReactInstrumentation",
".",
"debugTool",
".",
"onEndFlush",
"(",
")",
";",
"}",
"if",
"(",
"container",
".",
"nodeType",
"===",
"DOC_NODE_TYPE",
")",
"{",
"container",
"=",
"container",
".",
"documentElement",
";",
"}",
"// http://jsperf.com/emptying-a-node",
"while",
"(",
"container",
".",
"lastChild",
")",
"{",
"container",
".",
"removeChild",
"(",
"container",
".",
"lastChild",
")",
";",
"}",
"}"
] | Unmounts a component and removes it from the DOM.
@param {ReactComponent} instance React component instance.
@param {DOMElement} container DOM element to unmount from.
@final
@internal
@see {ReactMount.unmountComponentAtNode} | [
"Unmounts",
"a",
"component",
"and",
"removes",
"it",
"from",
"the",
"DOM",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L19247-L19264 |
51,625 | vivaxy/react-pianist | docs/js/common.js | function (nextElement, container, shouldReuseMarkup, context) {
// Various parts of our code (such as ReactCompositeComponent's
// _renderValidatedComponent) assume that calls to render aren't nested;
// verify that that's the case.
false ? warning(ReactCurrentOwner.current == null, '_renderNewRootComponent(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
!isValidContainer(container) ? false ? invariant(false, '_registerComponent(...): Target container is not a DOM element.') : _prodInvariant('37') : void 0;
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
var componentInstance = instantiateReactComponent(nextElement, false);
// The initial render is synchronous but any updates that happen during
// rendering, in componentWillMount or componentDidMount, will be batched
// according to the current batching strategy.
ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, container, shouldReuseMarkup, context);
var wrapperID = componentInstance._instance.rootID;
instancesByReactRootID[wrapperID] = componentInstance;
return componentInstance;
} | javascript | function (nextElement, container, shouldReuseMarkup, context) {
// Various parts of our code (such as ReactCompositeComponent's
// _renderValidatedComponent) assume that calls to render aren't nested;
// verify that that's the case.
false ? warning(ReactCurrentOwner.current == null, '_renderNewRootComponent(): Render methods should be a pure function ' + 'of props and state; triggering nested component updates from ' + 'render is not allowed. If necessary, trigger nested updates in ' + 'componentDidUpdate. Check the render method of %s.', ReactCurrentOwner.current && ReactCurrentOwner.current.getName() || 'ReactCompositeComponent') : void 0;
!isValidContainer(container) ? false ? invariant(false, '_registerComponent(...): Target container is not a DOM element.') : _prodInvariant('37') : void 0;
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
var componentInstance = instantiateReactComponent(nextElement, false);
// The initial render is synchronous but any updates that happen during
// rendering, in componentWillMount or componentDidMount, will be batched
// according to the current batching strategy.
ReactUpdates.batchedUpdates(batchedMountComponentIntoNode, componentInstance, container, shouldReuseMarkup, context);
var wrapperID = componentInstance._instance.rootID;
instancesByReactRootID[wrapperID] = componentInstance;
return componentInstance;
} | [
"function",
"(",
"nextElement",
",",
"container",
",",
"shouldReuseMarkup",
",",
"context",
")",
"{",
"// Various parts of our code (such as ReactCompositeComponent's",
"// _renderValidatedComponent) assume that calls to render aren't nested;",
"// verify that that's the case.",
"false",
"?",
"warning",
"(",
"ReactCurrentOwner",
".",
"current",
"==",
"null",
",",
"'_renderNewRootComponent(): Render methods should be a pure function '",
"+",
"'of props and state; triggering nested component updates from '",
"+",
"'render is not allowed. If necessary, trigger nested updates in '",
"+",
"'componentDidUpdate. Check the render method of %s.'",
",",
"ReactCurrentOwner",
".",
"current",
"&&",
"ReactCurrentOwner",
".",
"current",
".",
"getName",
"(",
")",
"||",
"'ReactCompositeComponent'",
")",
":",
"void",
"0",
";",
"!",
"isValidContainer",
"(",
"container",
")",
"?",
"false",
"?",
"invariant",
"(",
"false",
",",
"'_registerComponent(...): Target container is not a DOM element.'",
")",
":",
"_prodInvariant",
"(",
"'37'",
")",
":",
"void",
"0",
";",
"ReactBrowserEventEmitter",
".",
"ensureScrollValueMonitoring",
"(",
")",
";",
"var",
"componentInstance",
"=",
"instantiateReactComponent",
"(",
"nextElement",
",",
"false",
")",
";",
"// The initial render is synchronous but any updates that happen during",
"// rendering, in componentWillMount or componentDidMount, will be batched",
"// according to the current batching strategy.",
"ReactUpdates",
".",
"batchedUpdates",
"(",
"batchedMountComponentIntoNode",
",",
"componentInstance",
",",
"container",
",",
"shouldReuseMarkup",
",",
"context",
")",
";",
"var",
"wrapperID",
"=",
"componentInstance",
".",
"_instance",
".",
"rootID",
";",
"instancesByReactRootID",
"[",
"wrapperID",
"]",
"=",
"componentInstance",
";",
"return",
"componentInstance",
";",
"}"
] | Render a new component into the DOM. Hooked by hooks!
@param {ReactElement} nextElement element to render
@param {DOMElement} container container to render into
@param {boolean} shouldReuseMarkup if we should skip the markup insertion
@return {ReactComponent} nextComponent | [
"Render",
"a",
"new",
"component",
"into",
"the",
"DOM",
".",
"Hooked",
"by",
"hooks!"
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L19413-L19434 |
|
51,626 | vivaxy/react-pianist | docs/js/common.js | dispatch | function dispatch(action) {
if (!(0, _isPlainObject2['default'])(action)) {
throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
}
if (typeof action.type === 'undefined') {
throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?');
}
if (isDispatching) {
throw new Error('Reducers may not dispatch actions.');
}
try {
isDispatching = true;
currentState = currentReducer(currentState, action);
} finally {
isDispatching = false;
}
var listeners = currentListeners = nextListeners;
for (var i = 0; i < listeners.length; i++) {
listeners[i]();
}
return action;
} | javascript | function dispatch(action) {
if (!(0, _isPlainObject2['default'])(action)) {
throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
}
if (typeof action.type === 'undefined') {
throw new Error('Actions may not have an undefined "type" property. ' + 'Have you misspelled a constant?');
}
if (isDispatching) {
throw new Error('Reducers may not dispatch actions.');
}
try {
isDispatching = true;
currentState = currentReducer(currentState, action);
} finally {
isDispatching = false;
}
var listeners = currentListeners = nextListeners;
for (var i = 0; i < listeners.length; i++) {
listeners[i]();
}
return action;
} | [
"function",
"dispatch",
"(",
"action",
")",
"{",
"if",
"(",
"!",
"(",
"0",
",",
"_isPlainObject2",
"[",
"'default'",
"]",
")",
"(",
"action",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Actions must be plain objects. '",
"+",
"'Use custom middleware for async actions.'",
")",
";",
"}",
"if",
"(",
"typeof",
"action",
".",
"type",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Actions may not have an undefined \"type\" property. '",
"+",
"'Have you misspelled a constant?'",
")",
";",
"}",
"if",
"(",
"isDispatching",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Reducers may not dispatch actions.'",
")",
";",
"}",
"try",
"{",
"isDispatching",
"=",
"true",
";",
"currentState",
"=",
"currentReducer",
"(",
"currentState",
",",
"action",
")",
";",
"}",
"finally",
"{",
"isDispatching",
"=",
"false",
";",
"}",
"var",
"listeners",
"=",
"currentListeners",
"=",
"nextListeners",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"listeners",
".",
"length",
";",
"i",
"++",
")",
"{",
"listeners",
"[",
"i",
"]",
"(",
")",
";",
"}",
"return",
"action",
";",
"}"
] | Dispatches an action. It is the only way to trigger a state change.
The `reducer` function, used to create the store, will be called with the
current state tree and the given `action`. Its return value will
be considered the **next** state of the tree, and the change listeners
will be notified.
The base implementation only supports plain object actions. If you want to
dispatch a Promise, an Observable, a thunk, or something else, you need to
wrap your store creating function into the corresponding middleware. For
example, see the documentation for the `redux-thunk` package. Even the
middleware will eventually dispatch plain object actions using this method.
@param {Object} action A plain object representing “what changed”. It is
a good idea to keep actions serializable so you can record and replay user
sessions, or use the time travelling `redux-devtools`. An action must have
a `type` property which may not be `undefined`. It is a good idea to use
string constants for action types.
@returns {Object} For convenience, the same action object you dispatched.
Note that, if you use a custom middleware, it may wrap `dispatch()` to
return something else (for example, a Promise you can await). | [
"Dispatches",
"an",
"action",
".",
"It",
"is",
"the",
"only",
"way",
"to",
"trigger",
"a",
"state",
"change",
"."
] | 5923bf5e67dfd011e6b034024b0b11ff8ef19300 | https://github.com/vivaxy/react-pianist/blob/5923bf5e67dfd011e6b034024b0b11ff8ef19300/docs/js/common.js#L20746-L20772 |
51,627 | redisjs/jsr-conf | lib/configuration.js | Configuration | function Configuration(options, parent) {
options = options || {};
this.options = options;
// delimiter used to split and join lines
this.options.eol = options.eol || EOL;
// parent reference - used by includes
this._parent = parent;
// file path to primary configuration file loaded
this._file = null;
// encapsulates the decoded data
this._data = {};
// keep track of modified keys
this._modified = {};
// keep track of keys that were added that were
// not present when the configuration file was parsed
// this will be appended on rewrite
this._added = {};
// map of files that were included
this._includes = {};
// current include file being processed
this._include = null;
// store all lines for REWRITE
this._lines = [];
// only the root needs defaults
if(!parent) {
this.set(Types.PORT, DEFAULTS.port, null, true);
}
} | javascript | function Configuration(options, parent) {
options = options || {};
this.options = options;
// delimiter used to split and join lines
this.options.eol = options.eol || EOL;
// parent reference - used by includes
this._parent = parent;
// file path to primary configuration file loaded
this._file = null;
// encapsulates the decoded data
this._data = {};
// keep track of modified keys
this._modified = {};
// keep track of keys that were added that were
// not present when the configuration file was parsed
// this will be appended on rewrite
this._added = {};
// map of files that were included
this._includes = {};
// current include file being processed
this._include = null;
// store all lines for REWRITE
this._lines = [];
// only the root needs defaults
if(!parent) {
this.set(Types.PORT, DEFAULTS.port, null, true);
}
} | [
"function",
"Configuration",
"(",
"options",
",",
"parent",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"options",
"=",
"options",
";",
"// delimiter used to split and join lines",
"this",
".",
"options",
".",
"eol",
"=",
"options",
".",
"eol",
"||",
"EOL",
";",
"// parent reference - used by includes",
"this",
".",
"_parent",
"=",
"parent",
";",
"// file path to primary configuration file loaded",
"this",
".",
"_file",
"=",
"null",
";",
"// encapsulates the decoded data",
"this",
".",
"_data",
"=",
"{",
"}",
";",
"// keep track of modified keys",
"this",
".",
"_modified",
"=",
"{",
"}",
";",
"// keep track of keys that were added that were",
"// not present when the configuration file was parsed",
"// this will be appended on rewrite",
"this",
".",
"_added",
"=",
"{",
"}",
";",
"// map of files that were included",
"this",
".",
"_includes",
"=",
"{",
"}",
";",
"// current include file being processed",
"this",
".",
"_include",
"=",
"null",
";",
"// store all lines for REWRITE",
"this",
".",
"_lines",
"=",
"[",
"]",
";",
"// only the root needs defaults",
"if",
"(",
"!",
"parent",
")",
"{",
"this",
".",
"set",
"(",
"Types",
".",
"PORT",
",",
"DEFAULTS",
".",
"port",
",",
"null",
",",
"true",
")",
";",
"}",
"}"
] | Encapsulates a configuration file.
Fields are exposed on this instance as public properties
for easy read access, however writing should be performed using
the set() method to ensure the document knows which config parameters
have been changed.
@param options Configuration options.
@param parent A parent configuration. | [
"Encapsulates",
"a",
"configuration",
"file",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L32-L69 |
51,628 | redisjs/jsr-conf | lib/configuration.js | get | function get(key, stringify) {
var val = this._data[key] ? this._data[key].value :
(DEFAULTS[key] !== undefined ? DEFAULTS[key] : undefined);
if(val === undefined) return null;
if(stringify) {
val = this.encode(key, val, true);
}
return val;
} | javascript | function get(key, stringify) {
var val = this._data[key] ? this._data[key].value :
(DEFAULTS[key] !== undefined ? DEFAULTS[key] : undefined);
if(val === undefined) return null;
if(stringify) {
val = this.encode(key, val, true);
}
return val;
} | [
"function",
"get",
"(",
"key",
",",
"stringify",
")",
"{",
"var",
"val",
"=",
"this",
".",
"_data",
"[",
"key",
"]",
"?",
"this",
".",
"_data",
"[",
"key",
"]",
".",
"value",
":",
"(",
"DEFAULTS",
"[",
"key",
"]",
"!==",
"undefined",
"?",
"DEFAULTS",
"[",
"key",
"]",
":",
"undefined",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"return",
"null",
";",
"if",
"(",
"stringify",
")",
"{",
"val",
"=",
"this",
".",
"encode",
"(",
"key",
",",
"val",
",",
"true",
")",
";",
"}",
"return",
"val",
";",
"}"
] | Get a configuration property.
@param key The configuration key.
@param stringify Whether to coerce the value to a string. | [
"Get",
"a",
"configuration",
"property",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L115-L124 |
51,629 | redisjs/jsr-conf | lib/configuration.js | validate | function validate(key, values) {
var typedef, value;
if(!~Keys.indexOf(key)) {
throw new Error('unknown configuration key: ' + key);
}
// retrieve the type definition
typedef = Types[key];
// validate on the typedef
try {
value = typedef.validate(key, values);
}catch(e) {
// got a more specific error message to throw
if(typeof validator[key] === 'object'
&& validator[key].error) {
throw validator[key].error;
}
throw e;
}
return value;
} | javascript | function validate(key, values) {
var typedef, value;
if(!~Keys.indexOf(key)) {
throw new Error('unknown configuration key: ' + key);
}
// retrieve the type definition
typedef = Types[key];
// validate on the typedef
try {
value = typedef.validate(key, values);
}catch(e) {
// got a more specific error message to throw
if(typeof validator[key] === 'object'
&& validator[key].error) {
throw validator[key].error;
}
throw e;
}
return value;
} | [
"function",
"validate",
"(",
"key",
",",
"values",
")",
"{",
"var",
"typedef",
",",
"value",
";",
"if",
"(",
"!",
"~",
"Keys",
".",
"indexOf",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'unknown configuration key: '",
"+",
"key",
")",
";",
"}",
"// retrieve the type definition",
"typedef",
"=",
"Types",
"[",
"key",
"]",
";",
"// validate on the typedef",
"try",
"{",
"value",
"=",
"typedef",
".",
"validate",
"(",
"key",
",",
"values",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// got a more specific error message to throw",
"if",
"(",
"typeof",
"validator",
"[",
"key",
"]",
"===",
"'object'",
"&&",
"validator",
"[",
"key",
"]",
".",
"error",
")",
"{",
"throw",
"validator",
"[",
"key",
"]",
".",
"error",
";",
"}",
"throw",
"e",
";",
"}",
"return",
"value",
";",
"}"
] | Validate a key and array of values.
@param key The configuration key.
@param values The array of string values. | [
"Validate",
"a",
"key",
"and",
"array",
"of",
"values",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L132-L155 |
51,630 | redisjs/jsr-conf | lib/configuration.js | onLoad | function onLoad() {
var k, o, v;
for(k in this._data) {
o = this._data[k];
v = o.value;
try {
this.verify(k, v);
if(k === Types.SLAVEOF) {
if(this.get(Types.CLUSTER_ENABLED) && v) {
throw new Error('slaveof directive not allowed in cluster mode');
}
}
}catch(e) {
//console.dir('got include error');
this.emit('error',
new ConfigError(
o.lineno, this._lines[o.lineno - 1] || null, this.getFile(), e));
}
}
} | javascript | function onLoad() {
var k, o, v;
for(k in this._data) {
o = this._data[k];
v = o.value;
try {
this.verify(k, v);
if(k === Types.SLAVEOF) {
if(this.get(Types.CLUSTER_ENABLED) && v) {
throw new Error('slaveof directive not allowed in cluster mode');
}
}
}catch(e) {
//console.dir('got include error');
this.emit('error',
new ConfigError(
o.lineno, this._lines[o.lineno - 1] || null, this.getFile(), e));
}
}
} | [
"function",
"onLoad",
"(",
")",
"{",
"var",
"k",
",",
"o",
",",
"v",
";",
"for",
"(",
"k",
"in",
"this",
".",
"_data",
")",
"{",
"o",
"=",
"this",
".",
"_data",
"[",
"k",
"]",
";",
"v",
"=",
"o",
".",
"value",
";",
"try",
"{",
"this",
".",
"verify",
"(",
"k",
",",
"v",
")",
";",
"if",
"(",
"k",
"===",
"Types",
".",
"SLAVEOF",
")",
"{",
"if",
"(",
"this",
".",
"get",
"(",
"Types",
".",
"CLUSTER_ENABLED",
")",
"&&",
"v",
")",
"{",
"throw",
"new",
"Error",
"(",
"'slaveof directive not allowed in cluster mode'",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"//console.dir('got include error');",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"ConfigError",
"(",
"o",
".",
"lineno",
",",
"this",
".",
"_lines",
"[",
"o",
".",
"lineno",
"-",
"1",
"]",
"||",
"null",
",",
"this",
".",
"getFile",
"(",
")",
",",
"e",
")",
")",
";",
"}",
"}",
"}"
] | Post load validation. | [
"Post",
"load",
"validation",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L180-L200 |
51,631 | redisjs/jsr-conf | lib/configuration.js | set | function set(key, value, lineno, child) {
// keys can be passed as buffers
// we need a string
key = '' + key;
//console.error('%s=%s', key, value);
var typedef = Types[key]
, exists = this._data[key]
, val = exists || {value: null, lineno: !child ? lineno : undefined}
, changed = false;
if(!lineno && !child) {
changed = !exists || exists && exists.value !== value;
}
if(typedef && typedef.repeats) {
// repeatable values always trigger a change
// as they are created or appended
if(!lineno && !child) changed = true;
if(!exists) {
val.value = [value];
this._data[key] = val;
}else{
exists.value.push(value);
}
}else{
val.value = value;
this._data[key] = val;
}
if(lineno === undefined && !child) {
// keep track of new keys, repeatable keys that are arrays
// are always appended to the end of the file
if(typedef.repeats || !exists) {
if(!Object.keys(this._added).length) {
this._lines.push(GENERATED);
}
this._added[key] = value;
// add a line with the encoded value
this._lines.push(this.encode(key, value));
}
// keep track of modified data for config rewrite (must come after added)
if(exists && !this._added[key]) {
this._modified[exists.lineno] = key;
// line numbers are one-based but the array is zero
this._lines[exists.lineno - 1] = this.encode(key, value);
}
}
if(changed) {
// emit change event with key, newval, oldval, newentry, oldentry
this.emit('change',
key, value, (exists ? exists.value : undefined), val, exists);
// emit by key also, easier to consume
this.emit(key,
key, value, (exists ? exists.value : undefined), val, exists);
}
// merge include files synchronously
// as we encounter them
if(key === Types.INCLUDE && value) {
this.emit('include', value, this._file, lineno);
}
} | javascript | function set(key, value, lineno, child) {
// keys can be passed as buffers
// we need a string
key = '' + key;
//console.error('%s=%s', key, value);
var typedef = Types[key]
, exists = this._data[key]
, val = exists || {value: null, lineno: !child ? lineno : undefined}
, changed = false;
if(!lineno && !child) {
changed = !exists || exists && exists.value !== value;
}
if(typedef && typedef.repeats) {
// repeatable values always trigger a change
// as they are created or appended
if(!lineno && !child) changed = true;
if(!exists) {
val.value = [value];
this._data[key] = val;
}else{
exists.value.push(value);
}
}else{
val.value = value;
this._data[key] = val;
}
if(lineno === undefined && !child) {
// keep track of new keys, repeatable keys that are arrays
// are always appended to the end of the file
if(typedef.repeats || !exists) {
if(!Object.keys(this._added).length) {
this._lines.push(GENERATED);
}
this._added[key] = value;
// add a line with the encoded value
this._lines.push(this.encode(key, value));
}
// keep track of modified data for config rewrite (must come after added)
if(exists && !this._added[key]) {
this._modified[exists.lineno] = key;
// line numbers are one-based but the array is zero
this._lines[exists.lineno - 1] = this.encode(key, value);
}
}
if(changed) {
// emit change event with key, newval, oldval, newentry, oldentry
this.emit('change',
key, value, (exists ? exists.value : undefined), val, exists);
// emit by key also, easier to consume
this.emit(key,
key, value, (exists ? exists.value : undefined), val, exists);
}
// merge include files synchronously
// as we encounter them
if(key === Types.INCLUDE && value) {
this.emit('include', value, this._file, lineno);
}
} | [
"function",
"set",
"(",
"key",
",",
"value",
",",
"lineno",
",",
"child",
")",
"{",
"// keys can be passed as buffers",
"// we need a string",
"key",
"=",
"''",
"+",
"key",
";",
"//console.error('%s=%s', key, value);",
"var",
"typedef",
"=",
"Types",
"[",
"key",
"]",
",",
"exists",
"=",
"this",
".",
"_data",
"[",
"key",
"]",
",",
"val",
"=",
"exists",
"||",
"{",
"value",
":",
"null",
",",
"lineno",
":",
"!",
"child",
"?",
"lineno",
":",
"undefined",
"}",
",",
"changed",
"=",
"false",
";",
"if",
"(",
"!",
"lineno",
"&&",
"!",
"child",
")",
"{",
"changed",
"=",
"!",
"exists",
"||",
"exists",
"&&",
"exists",
".",
"value",
"!==",
"value",
";",
"}",
"if",
"(",
"typedef",
"&&",
"typedef",
".",
"repeats",
")",
"{",
"// repeatable values always trigger a change",
"// as they are created or appended",
"if",
"(",
"!",
"lineno",
"&&",
"!",
"child",
")",
"changed",
"=",
"true",
";",
"if",
"(",
"!",
"exists",
")",
"{",
"val",
".",
"value",
"=",
"[",
"value",
"]",
";",
"this",
".",
"_data",
"[",
"key",
"]",
"=",
"val",
";",
"}",
"else",
"{",
"exists",
".",
"value",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"else",
"{",
"val",
".",
"value",
"=",
"value",
";",
"this",
".",
"_data",
"[",
"key",
"]",
"=",
"val",
";",
"}",
"if",
"(",
"lineno",
"===",
"undefined",
"&&",
"!",
"child",
")",
"{",
"// keep track of new keys, repeatable keys that are arrays",
"// are always appended to the end of the file",
"if",
"(",
"typedef",
".",
"repeats",
"||",
"!",
"exists",
")",
"{",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"this",
".",
"_added",
")",
".",
"length",
")",
"{",
"this",
".",
"_lines",
".",
"push",
"(",
"GENERATED",
")",
";",
"}",
"this",
".",
"_added",
"[",
"key",
"]",
"=",
"value",
";",
"// add a line with the encoded value",
"this",
".",
"_lines",
".",
"push",
"(",
"this",
".",
"encode",
"(",
"key",
",",
"value",
")",
")",
";",
"}",
"// keep track of modified data for config rewrite (must come after added)",
"if",
"(",
"exists",
"&&",
"!",
"this",
".",
"_added",
"[",
"key",
"]",
")",
"{",
"this",
".",
"_modified",
"[",
"exists",
".",
"lineno",
"]",
"=",
"key",
";",
"// line numbers are one-based but the array is zero",
"this",
".",
"_lines",
"[",
"exists",
".",
"lineno",
"-",
"1",
"]",
"=",
"this",
".",
"encode",
"(",
"key",
",",
"value",
")",
";",
"}",
"}",
"if",
"(",
"changed",
")",
"{",
"// emit change event with key, newval, oldval, newentry, oldentry",
"this",
".",
"emit",
"(",
"'change'",
",",
"key",
",",
"value",
",",
"(",
"exists",
"?",
"exists",
".",
"value",
":",
"undefined",
")",
",",
"val",
",",
"exists",
")",
";",
"// emit by key also, easier to consume",
"this",
".",
"emit",
"(",
"key",
",",
"key",
",",
"value",
",",
"(",
"exists",
"?",
"exists",
".",
"value",
":",
"undefined",
")",
",",
"val",
",",
"exists",
")",
";",
"}",
"// merge include files synchronously",
"// as we encounter them",
"if",
"(",
"key",
"===",
"Types",
".",
"INCLUDE",
"&&",
"value",
")",
"{",
"this",
".",
"emit",
"(",
"'include'",
",",
"value",
",",
"this",
".",
"_file",
",",
"lineno",
")",
";",
"}",
"}"
] | Update the in-memory configuration.
Designed to be used by CONFIG SET the key should already
have been validated.
Internally when adding keys first time around a lineno specifies
where in the file the declaration is, otherwise when modifying via
CONFIG SET a lineno should not be specified and the key is tracked
as having been modified if the value changes, in which case a *change*
event is dispatched which will allow other modules to react to
configuration changes.
The final *child* parameter is used internally to track config values
being set by child configurations. It is used so that we can pass a lineno
value down to circular reference error handling for better error messages
but ensure that the set value does not pick up a new lineno when coming from
a child. | [
"Update",
"the",
"in",
"-",
"memory",
"configuration",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L221-L287 |
51,632 | redisjs/jsr-conf | lib/configuration.js | directives | function directives(def) {
// mock line number for error messages
var lineno = 1
, k
, v
// inline directive, not from a file
, file = 'directive override (argv)';
function addDirective(k, v) {
// must be strings split into an array
// they are parsed and validated
v = ('' + v).split(/\s+/);
// mimic behaving as a child so source file
// line numbers are not overwritten
try {
this.add(k, v, lineno, true);
}catch(e) {
return this.emit('error', new ConfigError(lineno, k + ' ' + v, file, e));
}
lineno++;
}
addDirective = addDirective.bind(this);
for(k in def) {
v = def[k];
if(!Array.isArray(v)) {
addDirective(k, v);
}else{
v.forEach(function(item) {
addDirective(k, item);
})
}
}
} | javascript | function directives(def) {
// mock line number for error messages
var lineno = 1
, k
, v
// inline directive, not from a file
, file = 'directive override (argv)';
function addDirective(k, v) {
// must be strings split into an array
// they are parsed and validated
v = ('' + v).split(/\s+/);
// mimic behaving as a child so source file
// line numbers are not overwritten
try {
this.add(k, v, lineno, true);
}catch(e) {
return this.emit('error', new ConfigError(lineno, k + ' ' + v, file, e));
}
lineno++;
}
addDirective = addDirective.bind(this);
for(k in def) {
v = def[k];
if(!Array.isArray(v)) {
addDirective(k, v);
}else{
v.forEach(function(item) {
addDirective(k, item);
})
}
}
} | [
"function",
"directives",
"(",
"def",
")",
"{",
"// mock line number for error messages",
"var",
"lineno",
"=",
"1",
",",
"k",
",",
"v",
"// inline directive, not from a file",
",",
"file",
"=",
"'directive override (argv)'",
";",
"function",
"addDirective",
"(",
"k",
",",
"v",
")",
"{",
"// must be strings split into an array",
"// they are parsed and validated",
"v",
"=",
"(",
"''",
"+",
"v",
")",
".",
"split",
"(",
"/",
"\\s+",
"/",
")",
";",
"// mimic behaving as a child so source file",
"// line numbers are not overwritten",
"try",
"{",
"this",
".",
"add",
"(",
"k",
",",
"v",
",",
"lineno",
",",
"true",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"ConfigError",
"(",
"lineno",
",",
"k",
"+",
"' '",
"+",
"v",
",",
"file",
",",
"e",
")",
")",
";",
"}",
"lineno",
"++",
";",
"}",
"addDirective",
"=",
"addDirective",
".",
"bind",
"(",
"this",
")",
";",
"for",
"(",
"k",
"in",
"def",
")",
"{",
"v",
"=",
"def",
"[",
"k",
"]",
";",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"v",
")",
")",
"{",
"addDirective",
"(",
"k",
",",
"v",
")",
";",
"}",
"else",
"{",
"v",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"addDirective",
"(",
"k",
",",
"item",
")",
";",
"}",
")",
"}",
"}",
"}"
] | Merge configuration directive overrides into this instance.
Should be invoked after the file and all includes have been loaded
and parsed.
@param def An object containing key value configuration pairs. | [
"Merge",
"configuration",
"directive",
"overrides",
"into",
"this",
"instance",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L297-L331 |
51,633 | redisjs/jsr-conf | lib/configuration.js | load | function load(opts, cb) {
if(typeof opts === 'function') {
cb = opts;
opts = undefined;
}
if(typeof opts === 'string') {
file = opts;
}else if(typeof opts === 'object') {
file = opts.file;
}
if(file === undefined) file = DEFAULT_FILE;
var sync = typeof cb !== 'function'
, stream
, file
, reader
, decoder = new Decoder(this, this.options, file);
if(!file || typeof file !== 'string' && !(file instanceof Readable)){
return this.emit('error',
new Error('cannot load configuration, path or stream expected'));
}
// need absolute path to be able to
// correctly find circular references
if(typeof file === 'string') {
file = resolve(file);
}
this._file = file;
if(sync && file && typeof file === 'string') {
this._lines = (fs.readFileSync(file) + '').split(this.options.eol);
decoder.parse(this._lines);
if(opts && opts.directives) {
this.directives(opts.directives);
}
return decoder;
}
if(file instanceof Readable) {
stream = file;
}else{
/* istanbul ignore next: cannot mock stdin, readable only */
stream = opts && opts.stdin ? process.stdin
: fs.createReadStream(file, this.options.read)
}
reader = new LineReader(this.options);
this.once('load', cb);
function onEnd() {
if(opts && opts.directives) {
this.directives(opts.directives);
}
decoder.removeAllListeners('error');
reader.removeAllListeners('error');
stream.removeAllListeners('error');
//console.dir(opts);
//
this.onLoad();
this.emit('load', this);
}
function onLines(lines) {
this._lines = this._lines.concat(lines);
}
var onError = this.onError.bind(this);
decoder.on('error', onError);
stream.on('error', onError);
reader.on('error', onError);
// listen for includes
this.on('include', this.onInclude.bind(this))
// listen for lines on the primary configuration.
decoder.on('lines', onLines.bind(this));
stream.on('end', onEnd.bind(this));
stream.pipe(reader).pipe(decoder);
return reader;
} | javascript | function load(opts, cb) {
if(typeof opts === 'function') {
cb = opts;
opts = undefined;
}
if(typeof opts === 'string') {
file = opts;
}else if(typeof opts === 'object') {
file = opts.file;
}
if(file === undefined) file = DEFAULT_FILE;
var sync = typeof cb !== 'function'
, stream
, file
, reader
, decoder = new Decoder(this, this.options, file);
if(!file || typeof file !== 'string' && !(file instanceof Readable)){
return this.emit('error',
new Error('cannot load configuration, path or stream expected'));
}
// need absolute path to be able to
// correctly find circular references
if(typeof file === 'string') {
file = resolve(file);
}
this._file = file;
if(sync && file && typeof file === 'string') {
this._lines = (fs.readFileSync(file) + '').split(this.options.eol);
decoder.parse(this._lines);
if(opts && opts.directives) {
this.directives(opts.directives);
}
return decoder;
}
if(file instanceof Readable) {
stream = file;
}else{
/* istanbul ignore next: cannot mock stdin, readable only */
stream = opts && opts.stdin ? process.stdin
: fs.createReadStream(file, this.options.read)
}
reader = new LineReader(this.options);
this.once('load', cb);
function onEnd() {
if(opts && opts.directives) {
this.directives(opts.directives);
}
decoder.removeAllListeners('error');
reader.removeAllListeners('error');
stream.removeAllListeners('error');
//console.dir(opts);
//
this.onLoad();
this.emit('load', this);
}
function onLines(lines) {
this._lines = this._lines.concat(lines);
}
var onError = this.onError.bind(this);
decoder.on('error', onError);
stream.on('error', onError);
reader.on('error', onError);
// listen for includes
this.on('include', this.onInclude.bind(this))
// listen for lines on the primary configuration.
decoder.on('lines', onLines.bind(this));
stream.on('end', onEnd.bind(this));
stream.pipe(reader).pipe(decoder);
return reader;
} | [
"function",
"load",
"(",
"opts",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"opts",
"===",
"'function'",
")",
"{",
"cb",
"=",
"opts",
";",
"opts",
"=",
"undefined",
";",
"}",
"if",
"(",
"typeof",
"opts",
"===",
"'string'",
")",
"{",
"file",
"=",
"opts",
";",
"}",
"else",
"if",
"(",
"typeof",
"opts",
"===",
"'object'",
")",
"{",
"file",
"=",
"opts",
".",
"file",
";",
"}",
"if",
"(",
"file",
"===",
"undefined",
")",
"file",
"=",
"DEFAULT_FILE",
";",
"var",
"sync",
"=",
"typeof",
"cb",
"!==",
"'function'",
",",
"stream",
",",
"file",
",",
"reader",
",",
"decoder",
"=",
"new",
"Decoder",
"(",
"this",
",",
"this",
".",
"options",
",",
"file",
")",
";",
"if",
"(",
"!",
"file",
"||",
"typeof",
"file",
"!==",
"'string'",
"&&",
"!",
"(",
"file",
"instanceof",
"Readable",
")",
")",
"{",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"Error",
"(",
"'cannot load configuration, path or stream expected'",
")",
")",
";",
"}",
"// need absolute path to be able to",
"// correctly find circular references",
"if",
"(",
"typeof",
"file",
"===",
"'string'",
")",
"{",
"file",
"=",
"resolve",
"(",
"file",
")",
";",
"}",
"this",
".",
"_file",
"=",
"file",
";",
"if",
"(",
"sync",
"&&",
"file",
"&&",
"typeof",
"file",
"===",
"'string'",
")",
"{",
"this",
".",
"_lines",
"=",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
")",
"+",
"''",
")",
".",
"split",
"(",
"this",
".",
"options",
".",
"eol",
")",
";",
"decoder",
".",
"parse",
"(",
"this",
".",
"_lines",
")",
";",
"if",
"(",
"opts",
"&&",
"opts",
".",
"directives",
")",
"{",
"this",
".",
"directives",
"(",
"opts",
".",
"directives",
")",
";",
"}",
"return",
"decoder",
";",
"}",
"if",
"(",
"file",
"instanceof",
"Readable",
")",
"{",
"stream",
"=",
"file",
";",
"}",
"else",
"{",
"/* istanbul ignore next: cannot mock stdin, readable only */",
"stream",
"=",
"opts",
"&&",
"opts",
".",
"stdin",
"?",
"process",
".",
"stdin",
":",
"fs",
".",
"createReadStream",
"(",
"file",
",",
"this",
".",
"options",
".",
"read",
")",
"}",
"reader",
"=",
"new",
"LineReader",
"(",
"this",
".",
"options",
")",
";",
"this",
".",
"once",
"(",
"'load'",
",",
"cb",
")",
";",
"function",
"onEnd",
"(",
")",
"{",
"if",
"(",
"opts",
"&&",
"opts",
".",
"directives",
")",
"{",
"this",
".",
"directives",
"(",
"opts",
".",
"directives",
")",
";",
"}",
"decoder",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"reader",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"stream",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"//console.dir(opts);",
"//",
"this",
".",
"onLoad",
"(",
")",
";",
"this",
".",
"emit",
"(",
"'load'",
",",
"this",
")",
";",
"}",
"function",
"onLines",
"(",
"lines",
")",
"{",
"this",
".",
"_lines",
"=",
"this",
".",
"_lines",
".",
"concat",
"(",
"lines",
")",
";",
"}",
"var",
"onError",
"=",
"this",
".",
"onError",
".",
"bind",
"(",
"this",
")",
";",
"decoder",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"stream",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"reader",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"// listen for includes",
"this",
".",
"on",
"(",
"'include'",
",",
"this",
".",
"onInclude",
".",
"bind",
"(",
"this",
")",
")",
"// listen for lines on the primary configuration.",
"decoder",
".",
"on",
"(",
"'lines'",
",",
"onLines",
".",
"bind",
"(",
"this",
")",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"onEnd",
".",
"bind",
"(",
"this",
")",
")",
";",
"stream",
".",
"pipe",
"(",
"reader",
")",
".",
"pipe",
"(",
"decoder",
")",
";",
"return",
"reader",
";",
"}"
] | Read a file and pipe it to a decoder. | [
"Read",
"a",
"file",
"and",
"pipe",
"it",
"to",
"a",
"decoder",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L336-L425 |
51,634 | redisjs/jsr-conf | lib/configuration.js | write | function write(file, cb) {
if(file === undefined) file = this._file;
if(file === DEFAULT_FILE) {
return this.emit(
'error', new Error('cannot write to default configuration'));
}
var sync = typeof cb !== 'function'
, stream
, save
, encoder = new Encoder(this.options)
, lines = this._lines
, size = 32
, i = 0
, len = (lines.length / size);
if(!file || typeof file !== 'string' && !(file instanceof Writable)){
return this.emit('error',
new Error('cannot write configuration, path or stream expected'));
}
if(typeof file === 'string') {
file = resolve(file);
save = file + Constants.SAVE;
}
if(sync && file && typeof file === 'string') {
try {
fs.writeFileSync(save, encoder.parse(this._lines));
fs.renameSync(save, file);
}catch(e) {
/* istanbul ignore next: hard to mock a rename(2) error */
return this.emit('error', e);
}
return encoder;
}
if(file instanceof Writable) {
stream = file;
}else{
stream = fs.createWriteStream(save, this.options.read)
}
this.once('write', cb);
function onFinish() {
function onRename(err) {
encoder.removeAllListeners('error');
stream.removeAllListeners('error');
/* istanbul ignore next: hard to mock a rename(2) error */
if(err) return this.emit('error', err);
this.emit('write', this);
}
onRename = onRename.bind(this);
if(save) {
fs.rename(save, file, onRename);
}else{
onRename();
}
}
var onError = this.onError.bind(this);
encoder.on('error', onError);
stream.on('error', onError);
stream.on('finish', onFinish.bind(this));
encoder.pipe(stream);
if((lines.length % size) !== 0) len++;
// not a very large config
if(lines.length < size) {
encoder.end(lines);
return encoder;
}
// split the work for larger config files
function writeLines() {
var chunk = lines.slice(i * size, (i * size) + size);
// all done
if(!chunk.length) {
return encoder.end();
}
// ensure we get correct line break between
// line chunks, the encoder joins lines on EOL
// this means that the last line in the chunk array
// does not have an EOL, we need to ensure it does
if(i > 0) {
chunk.unshift('');
}
// write out the line chunk
encoder.write(chunk);
setImmediate(writeLines);
i++;
}
writeLines();
return encoder;
} | javascript | function write(file, cb) {
if(file === undefined) file = this._file;
if(file === DEFAULT_FILE) {
return this.emit(
'error', new Error('cannot write to default configuration'));
}
var sync = typeof cb !== 'function'
, stream
, save
, encoder = new Encoder(this.options)
, lines = this._lines
, size = 32
, i = 0
, len = (lines.length / size);
if(!file || typeof file !== 'string' && !(file instanceof Writable)){
return this.emit('error',
new Error('cannot write configuration, path or stream expected'));
}
if(typeof file === 'string') {
file = resolve(file);
save = file + Constants.SAVE;
}
if(sync && file && typeof file === 'string') {
try {
fs.writeFileSync(save, encoder.parse(this._lines));
fs.renameSync(save, file);
}catch(e) {
/* istanbul ignore next: hard to mock a rename(2) error */
return this.emit('error', e);
}
return encoder;
}
if(file instanceof Writable) {
stream = file;
}else{
stream = fs.createWriteStream(save, this.options.read)
}
this.once('write', cb);
function onFinish() {
function onRename(err) {
encoder.removeAllListeners('error');
stream.removeAllListeners('error');
/* istanbul ignore next: hard to mock a rename(2) error */
if(err) return this.emit('error', err);
this.emit('write', this);
}
onRename = onRename.bind(this);
if(save) {
fs.rename(save, file, onRename);
}else{
onRename();
}
}
var onError = this.onError.bind(this);
encoder.on('error', onError);
stream.on('error', onError);
stream.on('finish', onFinish.bind(this));
encoder.pipe(stream);
if((lines.length % size) !== 0) len++;
// not a very large config
if(lines.length < size) {
encoder.end(lines);
return encoder;
}
// split the work for larger config files
function writeLines() {
var chunk = lines.slice(i * size, (i * size) + size);
// all done
if(!chunk.length) {
return encoder.end();
}
// ensure we get correct line break between
// line chunks, the encoder joins lines on EOL
// this means that the last line in the chunk array
// does not have an EOL, we need to ensure it does
if(i > 0) {
chunk.unshift('');
}
// write out the line chunk
encoder.write(chunk);
setImmediate(writeLines);
i++;
}
writeLines();
return encoder;
} | [
"function",
"write",
"(",
"file",
",",
"cb",
")",
"{",
"if",
"(",
"file",
"===",
"undefined",
")",
"file",
"=",
"this",
".",
"_file",
";",
"if",
"(",
"file",
"===",
"DEFAULT_FILE",
")",
"{",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"Error",
"(",
"'cannot write to default configuration'",
")",
")",
";",
"}",
"var",
"sync",
"=",
"typeof",
"cb",
"!==",
"'function'",
",",
"stream",
",",
"save",
",",
"encoder",
"=",
"new",
"Encoder",
"(",
"this",
".",
"options",
")",
",",
"lines",
"=",
"this",
".",
"_lines",
",",
"size",
"=",
"32",
",",
"i",
"=",
"0",
",",
"len",
"=",
"(",
"lines",
".",
"length",
"/",
"size",
")",
";",
"if",
"(",
"!",
"file",
"||",
"typeof",
"file",
"!==",
"'string'",
"&&",
"!",
"(",
"file",
"instanceof",
"Writable",
")",
")",
"{",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"Error",
"(",
"'cannot write configuration, path or stream expected'",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"file",
"===",
"'string'",
")",
"{",
"file",
"=",
"resolve",
"(",
"file",
")",
";",
"save",
"=",
"file",
"+",
"Constants",
".",
"SAVE",
";",
"}",
"if",
"(",
"sync",
"&&",
"file",
"&&",
"typeof",
"file",
"===",
"'string'",
")",
"{",
"try",
"{",
"fs",
".",
"writeFileSync",
"(",
"save",
",",
"encoder",
".",
"parse",
"(",
"this",
".",
"_lines",
")",
")",
";",
"fs",
".",
"renameSync",
"(",
"save",
",",
"file",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"/* istanbul ignore next: hard to mock a rename(2) error */",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"e",
")",
";",
"}",
"return",
"encoder",
";",
"}",
"if",
"(",
"file",
"instanceof",
"Writable",
")",
"{",
"stream",
"=",
"file",
";",
"}",
"else",
"{",
"stream",
"=",
"fs",
".",
"createWriteStream",
"(",
"save",
",",
"this",
".",
"options",
".",
"read",
")",
"}",
"this",
".",
"once",
"(",
"'write'",
",",
"cb",
")",
";",
"function",
"onFinish",
"(",
")",
"{",
"function",
"onRename",
"(",
"err",
")",
"{",
"encoder",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"stream",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"/* istanbul ignore next: hard to mock a rename(2) error */",
"if",
"(",
"err",
")",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"this",
".",
"emit",
"(",
"'write'",
",",
"this",
")",
";",
"}",
"onRename",
"=",
"onRename",
".",
"bind",
"(",
"this",
")",
";",
"if",
"(",
"save",
")",
"{",
"fs",
".",
"rename",
"(",
"save",
",",
"file",
",",
"onRename",
")",
";",
"}",
"else",
"{",
"onRename",
"(",
")",
";",
"}",
"}",
"var",
"onError",
"=",
"this",
".",
"onError",
".",
"bind",
"(",
"this",
")",
";",
"encoder",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"stream",
".",
"on",
"(",
"'error'",
",",
"onError",
")",
";",
"stream",
".",
"on",
"(",
"'finish'",
",",
"onFinish",
".",
"bind",
"(",
"this",
")",
")",
";",
"encoder",
".",
"pipe",
"(",
"stream",
")",
";",
"if",
"(",
"(",
"lines",
".",
"length",
"%",
"size",
")",
"!==",
"0",
")",
"len",
"++",
";",
"// not a very large config",
"if",
"(",
"lines",
".",
"length",
"<",
"size",
")",
"{",
"encoder",
".",
"end",
"(",
"lines",
")",
";",
"return",
"encoder",
";",
"}",
"// split the work for larger config files",
"function",
"writeLines",
"(",
")",
"{",
"var",
"chunk",
"=",
"lines",
".",
"slice",
"(",
"i",
"*",
"size",
",",
"(",
"i",
"*",
"size",
")",
"+",
"size",
")",
";",
"// all done",
"if",
"(",
"!",
"chunk",
".",
"length",
")",
"{",
"return",
"encoder",
".",
"end",
"(",
")",
";",
"}",
"// ensure we get correct line break between",
"// line chunks, the encoder joins lines on EOL",
"// this means that the last line in the chunk array",
"// does not have an EOL, we need to ensure it does",
"if",
"(",
"i",
">",
"0",
")",
"{",
"chunk",
".",
"unshift",
"(",
"''",
")",
";",
"}",
"// write out the line chunk",
"encoder",
".",
"write",
"(",
"chunk",
")",
";",
"setImmediate",
"(",
"writeLines",
")",
";",
"i",
"++",
";",
"}",
"writeLines",
"(",
")",
";",
"return",
"encoder",
";",
"}"
] | Write the in-memory configuration to a file or stream. | [
"Write",
"the",
"in",
"-",
"memory",
"configuration",
"to",
"a",
"file",
"or",
"stream",
"."
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L430-L537 |
51,635 | redisjs/jsr-conf | lib/configuration.js | writeLines | function writeLines() {
var chunk = lines.slice(i * size, (i * size) + size);
// all done
if(!chunk.length) {
return encoder.end();
}
// ensure we get correct line break between
// line chunks, the encoder joins lines on EOL
// this means that the last line in the chunk array
// does not have an EOL, we need to ensure it does
if(i > 0) {
chunk.unshift('');
}
// write out the line chunk
encoder.write(chunk);
setImmediate(writeLines);
i++;
} | javascript | function writeLines() {
var chunk = lines.slice(i * size, (i * size) + size);
// all done
if(!chunk.length) {
return encoder.end();
}
// ensure we get correct line break between
// line chunks, the encoder joins lines on EOL
// this means that the last line in the chunk array
// does not have an EOL, we need to ensure it does
if(i > 0) {
chunk.unshift('');
}
// write out the line chunk
encoder.write(chunk);
setImmediate(writeLines);
i++;
} | [
"function",
"writeLines",
"(",
")",
"{",
"var",
"chunk",
"=",
"lines",
".",
"slice",
"(",
"i",
"*",
"size",
",",
"(",
"i",
"*",
"size",
")",
"+",
"size",
")",
";",
"// all done",
"if",
"(",
"!",
"chunk",
".",
"length",
")",
"{",
"return",
"encoder",
".",
"end",
"(",
")",
";",
"}",
"// ensure we get correct line break between",
"// line chunks, the encoder joins lines on EOL",
"// this means that the last line in the chunk array",
"// does not have an EOL, we need to ensure it does",
"if",
"(",
"i",
">",
"0",
")",
"{",
"chunk",
".",
"unshift",
"(",
"''",
")",
";",
"}",
"// write out the line chunk",
"encoder",
".",
"write",
"(",
"chunk",
")",
";",
"setImmediate",
"(",
"writeLines",
")",
";",
"i",
"++",
";",
"}"
] | split the work for larger config files | [
"split",
"the",
"work",
"for",
"larger",
"config",
"files"
] | 97c5e2e77e1601c879a62dfc2d500df537eaaddd | https://github.com/redisjs/jsr-conf/blob/97c5e2e77e1601c879a62dfc2d500df537eaaddd/lib/configuration.js#L513-L533 |
51,636 | meltmedia/node-usher | lib/decider/version.js | handleFailure | function handleFailure(err) {
// Respond back to SWF failing the workflow
winston.log('error', 'An problem occured in the execution of workflow: %s, failing due to: ', self.name, err.stack);
decisionTask.response.fail('Workflow failed', err, function (err) {
if (err) {
winston.log('error', 'Unable to mark workflow: %s as failed due to: %s', self.name, JSON.stringify(err));
return;
}
});
} | javascript | function handleFailure(err) {
// Respond back to SWF failing the workflow
winston.log('error', 'An problem occured in the execution of workflow: %s, failing due to: ', self.name, err.stack);
decisionTask.response.fail('Workflow failed', err, function (err) {
if (err) {
winston.log('error', 'Unable to mark workflow: %s as failed due to: %s', self.name, JSON.stringify(err));
return;
}
});
} | [
"function",
"handleFailure",
"(",
"err",
")",
"{",
"// Respond back to SWF failing the workflow",
"winston",
".",
"log",
"(",
"'error'",
",",
"'An problem occured in the execution of workflow: %s, failing due to: '",
",",
"self",
".",
"name",
",",
"err",
".",
"stack",
")",
";",
"decisionTask",
".",
"response",
".",
"fail",
"(",
"'Workflow failed'",
",",
"err",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"winston",
".",
"log",
"(",
"'error'",
",",
"'Unable to mark workflow: %s as failed due to: %s'",
",",
"self",
".",
"name",
",",
"JSON",
".",
"stringify",
"(",
"err",
")",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"}"
] | When something goes wrong and we can't make a decision | [
"When",
"something",
"goes",
"wrong",
"and",
"we",
"can",
"t",
"make",
"a",
"decision"
] | fe6183bf7097f84bef935e8d9c19463accc08ad6 | https://github.com/meltmedia/node-usher/blob/fe6183bf7097f84bef935e8d9c19463accc08ad6/lib/decider/version.js#L106-L115 |
51,637 | meltmedia/node-usher | lib/decider/version.js | handleSuccess | function handleSuccess() {
// If any activities failed, we need to fail the workflow
if (context.failed()) {
winston.log('warn', 'One of more activities failed in workflow: %s, marking workflow as failed', self.name);
// Respond back to SWF failing the workflow
decisionTask.response.fail('Activities failed', { failures: context.errorMessages }, function (err) {
if (err) {
winston.log('error', 'Unable to mark workflow: %s as failed due to: %s', self.name, JSON.stringify(err));
return;
}
});
} else {
// Check to see if we are done with the workflow
if (context.done()) {
winston.log('info', 'Workflow: %s has completed successfuly', self.name);
// Stop the workflow
decisionTask.response.stop({
result: JSON.stringify(context.results)
});
}
// If no decisions made this round, skip
if (!decisionTask.response.decisions) {
winston.log('debug', 'No decision can be made this round for workflow: %s', self.name);
// Record our state when we can't make a decision to help in debugging
// decisionTask.response.add_marker('current-state', JSON.stringify(context.currentStatus()));
decisionTask.response.wait();
}
// Respond back to SWF with all decisions
decisionTask.response.respondCompleted(decisionTask.response.decisions, function (err) {
if (err) {
winston.log('error', 'Unable to respond to workflow: %s with decisions due to: %s', self.name, JSON.stringify(err));
return;
}
});
}
} | javascript | function handleSuccess() {
// If any activities failed, we need to fail the workflow
if (context.failed()) {
winston.log('warn', 'One of more activities failed in workflow: %s, marking workflow as failed', self.name);
// Respond back to SWF failing the workflow
decisionTask.response.fail('Activities failed', { failures: context.errorMessages }, function (err) {
if (err) {
winston.log('error', 'Unable to mark workflow: %s as failed due to: %s', self.name, JSON.stringify(err));
return;
}
});
} else {
// Check to see if we are done with the workflow
if (context.done()) {
winston.log('info', 'Workflow: %s has completed successfuly', self.name);
// Stop the workflow
decisionTask.response.stop({
result: JSON.stringify(context.results)
});
}
// If no decisions made this round, skip
if (!decisionTask.response.decisions) {
winston.log('debug', 'No decision can be made this round for workflow: %s', self.name);
// Record our state when we can't make a decision to help in debugging
// decisionTask.response.add_marker('current-state', JSON.stringify(context.currentStatus()));
decisionTask.response.wait();
}
// Respond back to SWF with all decisions
decisionTask.response.respondCompleted(decisionTask.response.decisions, function (err) {
if (err) {
winston.log('error', 'Unable to respond to workflow: %s with decisions due to: %s', self.name, JSON.stringify(err));
return;
}
});
}
} | [
"function",
"handleSuccess",
"(",
")",
"{",
"// If any activities failed, we need to fail the workflow",
"if",
"(",
"context",
".",
"failed",
"(",
")",
")",
"{",
"winston",
".",
"log",
"(",
"'warn'",
",",
"'One of more activities failed in workflow: %s, marking workflow as failed'",
",",
"self",
".",
"name",
")",
";",
"// Respond back to SWF failing the workflow",
"decisionTask",
".",
"response",
".",
"fail",
"(",
"'Activities failed'",
",",
"{",
"failures",
":",
"context",
".",
"errorMessages",
"}",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"winston",
".",
"log",
"(",
"'error'",
",",
"'Unable to mark workflow: %s as failed due to: %s'",
",",
"self",
".",
"name",
",",
"JSON",
".",
"stringify",
"(",
"err",
")",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"// Check to see if we are done with the workflow",
"if",
"(",
"context",
".",
"done",
"(",
")",
")",
"{",
"winston",
".",
"log",
"(",
"'info'",
",",
"'Workflow: %s has completed successfuly'",
",",
"self",
".",
"name",
")",
";",
"// Stop the workflow",
"decisionTask",
".",
"response",
".",
"stop",
"(",
"{",
"result",
":",
"JSON",
".",
"stringify",
"(",
"context",
".",
"results",
")",
"}",
")",
";",
"}",
"// If no decisions made this round, skip",
"if",
"(",
"!",
"decisionTask",
".",
"response",
".",
"decisions",
")",
"{",
"winston",
".",
"log",
"(",
"'debug'",
",",
"'No decision can be made this round for workflow: %s'",
",",
"self",
".",
"name",
")",
";",
"// Record our state when we can't make a decision to help in debugging",
"// decisionTask.response.add_marker('current-state', JSON.stringify(context.currentStatus()));",
"decisionTask",
".",
"response",
".",
"wait",
"(",
")",
";",
"}",
"// Respond back to SWF with all decisions",
"decisionTask",
".",
"response",
".",
"respondCompleted",
"(",
"decisionTask",
".",
"response",
".",
"decisions",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"winston",
".",
"log",
"(",
"'error'",
",",
"'Unable to respond to workflow: %s with decisions due to: %s'",
",",
"self",
".",
"name",
",",
"JSON",
".",
"stringify",
"(",
"err",
")",
")",
";",
"return",
";",
"}",
"}",
")",
";",
"}",
"}"
] | When we have made a decision | [
"When",
"we",
"have",
"made",
"a",
"decision"
] | fe6183bf7097f84bef935e8d9c19463accc08ad6 | https://github.com/meltmedia/node-usher/blob/fe6183bf7097f84bef935e8d9c19463accc08ad6/lib/decider/version.js#L118-L160 |
51,638 | cdaringe/mock-package-install | src/index.js | function (opts) {
opts = opts || {}
opts = defaults(opts, {
nodeModulesDir: path.resolve(process.cwd(), 'node_modules'),
package: rpkg.gen(opts.package)
})
fs.mkdirpSync(path.resolve(opts.nodeModulesDir, opts.package.name))
fs.writeFileSync(
path.resolve(opts.nodeModulesDir, opts.package.name, 'package.json'),
JSON.stringify(opts.package, null, 2)
)
if (opts.targetPackage) {
var key = opts.isDev ? 'devDependencies' : 'dependencies'
var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
targetPackage[key] = targetPackage[key] || {}
targetPackage[key][opts.package.name] = opts.package.version
fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
}
return opts.package
} | javascript | function (opts) {
opts = opts || {}
opts = defaults(opts, {
nodeModulesDir: path.resolve(process.cwd(), 'node_modules'),
package: rpkg.gen(opts.package)
})
fs.mkdirpSync(path.resolve(opts.nodeModulesDir, opts.package.name))
fs.writeFileSync(
path.resolve(opts.nodeModulesDir, opts.package.name, 'package.json'),
JSON.stringify(opts.package, null, 2)
)
if (opts.targetPackage) {
var key = opts.isDev ? 'devDependencies' : 'dependencies'
var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
targetPackage[key] = targetPackage[key] || {}
targetPackage[key][opts.package.name] = opts.package.version
fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
}
return opts.package
} | [
"function",
"(",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
"opts",
"=",
"defaults",
"(",
"opts",
",",
"{",
"nodeModulesDir",
":",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"'node_modules'",
")",
",",
"package",
":",
"rpkg",
".",
"gen",
"(",
"opts",
".",
"package",
")",
"}",
")",
"fs",
".",
"mkdirpSync",
"(",
"path",
".",
"resolve",
"(",
"opts",
".",
"nodeModulesDir",
",",
"opts",
".",
"package",
".",
"name",
")",
")",
"fs",
".",
"writeFileSync",
"(",
"path",
".",
"resolve",
"(",
"opts",
".",
"nodeModulesDir",
",",
"opts",
".",
"package",
".",
"name",
",",
"'package.json'",
")",
",",
"JSON",
".",
"stringify",
"(",
"opts",
".",
"package",
",",
"null",
",",
"2",
")",
")",
"if",
"(",
"opts",
".",
"targetPackage",
")",
"{",
"var",
"key",
"=",
"opts",
".",
"isDev",
"?",
"'devDependencies'",
":",
"'dependencies'",
"var",
"targetPackage",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"opts",
".",
"targetPackage",
")",
")",
"targetPackage",
"[",
"key",
"]",
"=",
"targetPackage",
"[",
"key",
"]",
"||",
"{",
"}",
"targetPackage",
"[",
"key",
"]",
"[",
"opts",
".",
"package",
".",
"name",
"]",
"=",
"opts",
".",
"package",
".",
"version",
"fs",
".",
"writeFileSync",
"(",
"opts",
".",
"targetPackage",
",",
"JSON",
".",
"stringify",
"(",
"targetPackage",
",",
"null",
",",
"2",
")",
")",
"}",
"return",
"opts",
".",
"package",
"}"
] | Installs mock package into node_modules & updates the corresponding package.json file
@param {object} opts
@param {object} [opts.package] JS object package.json. random package used if none provided
@param {string} [opts.nodeModulesDir] path to node_modules dir to install mock package into. looks for cwd/node_modules by default
@param {string} [opts.targetPackage] path to package.json file to update with the newly installed dependency's metadata
@param {boolean} [opts.isDev] put into devDependencies vs dependencies. used only with targetPackage
@example
mock.install({
package: { name: 'TEST_NAME', version: 'TEST_VERSION' },
nodeModulesDir: '/path/to/target/node_modules',
targetPackage: '/path/to/target/package.json',
isDev: true
})
@return {object} JS object package.json | [
"Installs",
"mock",
"package",
"into",
"node_modules",
"&",
"updates",
"the",
"corresponding",
"package",
".",
"json",
"file"
] | a4c6561a6b2c538dd727447b11fdc3d18cdb3feb | https://github.com/cdaringe/mock-package-install/blob/a4c6561a6b2c538dd727447b11fdc3d18cdb3feb/src/index.js#L29-L48 |
|
51,639 | cdaringe/mock-package-install | src/index.js | function (opts) {
var name
if (opts && opts.name) name = opts.name
if (opts && opts.package && opts.package.name) name = opts.package.name
if (!name) throw new TypeError('package name missing')
opts = defaults(opts, {
nodeModulesDir: path.resolve(process.cwd(), 'node_modules')
})
fs.removeSync(path.resolve(opts.nodeModulesDir, name))
if (opts.targetPackage) {
var key = opts.isDev ? 'devDependencies' : 'dependencies'
var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
delete targetPackage[key][name]
fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
}
} | javascript | function (opts) {
var name
if (opts && opts.name) name = opts.name
if (opts && opts.package && opts.package.name) name = opts.package.name
if (!name) throw new TypeError('package name missing')
opts = defaults(opts, {
nodeModulesDir: path.resolve(process.cwd(), 'node_modules')
})
fs.removeSync(path.resolve(opts.nodeModulesDir, name))
if (opts.targetPackage) {
var key = opts.isDev ? 'devDependencies' : 'dependencies'
var targetPackage = JSON.parse(fs.readFileSync(opts.targetPackage))
delete targetPackage[key][name]
fs.writeFileSync(opts.targetPackage, JSON.stringify(targetPackage, null, 2))
}
} | [
"function",
"(",
"opts",
")",
"{",
"var",
"name",
"if",
"(",
"opts",
"&&",
"opts",
".",
"name",
")",
"name",
"=",
"opts",
".",
"name",
"if",
"(",
"opts",
"&&",
"opts",
".",
"package",
"&&",
"opts",
".",
"package",
".",
"name",
")",
"name",
"=",
"opts",
".",
"package",
".",
"name",
"if",
"(",
"!",
"name",
")",
"throw",
"new",
"TypeError",
"(",
"'package name missing'",
")",
"opts",
"=",
"defaults",
"(",
"opts",
",",
"{",
"nodeModulesDir",
":",
"path",
".",
"resolve",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"'node_modules'",
")",
"}",
")",
"fs",
".",
"removeSync",
"(",
"path",
".",
"resolve",
"(",
"opts",
".",
"nodeModulesDir",
",",
"name",
")",
")",
"if",
"(",
"opts",
".",
"targetPackage",
")",
"{",
"var",
"key",
"=",
"opts",
".",
"isDev",
"?",
"'devDependencies'",
":",
"'dependencies'",
"var",
"targetPackage",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"opts",
".",
"targetPackage",
")",
")",
"delete",
"targetPackage",
"[",
"key",
"]",
"[",
"name",
"]",
"fs",
".",
"writeFileSync",
"(",
"opts",
".",
"targetPackage",
",",
"JSON",
".",
"stringify",
"(",
"targetPackage",
",",
"null",
",",
"2",
")",
")",
"}",
"}"
] | remove mock package
@param {object} opts
@param {string} opts.name package name to remove
@param {string} [opts.package.name] may be used instead of opts.name for consistency w/ install API
@param {string} [opts.nodeModulesDir] path to node_modules dir
@param {string} [opts.targetPackage] path to package.json file to update with the newly installed dependency's metadata
@param {boolean} [opts.isDev] put into devDependencies vs dependencies. used only with targetPackage | [
"remove",
"mock",
"package"
] | a4c6561a6b2c538dd727447b11fdc3d18cdb3feb | https://github.com/cdaringe/mock-package-install/blob/a4c6561a6b2c538dd727447b11fdc3d18cdb3feb/src/index.js#L59-L74 |
|
51,640 | redisjs/jsr-store | lib/type/zset.js | SortedSet | function SortedSet(source) {
HashMap.call(this);
this._rtype = TYPE_NAMES.ZSET;
if(source) {
for(var k in source) {
this.setKey(k, source[k]);
}
}
} | javascript | function SortedSet(source) {
HashMap.call(this);
this._rtype = TYPE_NAMES.ZSET;
if(source) {
for(var k in source) {
this.setKey(k, source[k]);
}
}
} | [
"function",
"SortedSet",
"(",
"source",
")",
"{",
"HashMap",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"_rtype",
"=",
"TYPE_NAMES",
".",
"ZSET",
";",
"if",
"(",
"source",
")",
"{",
"for",
"(",
"var",
"k",
"in",
"source",
")",
"{",
"this",
".",
"setKey",
"(",
"k",
",",
"source",
"[",
"k",
"]",
")",
";",
"}",
"}",
"}"
] | Represents the sorted set type. | [
"Represents",
"the",
"sorted",
"set",
"type",
"."
] | b2b5c5b0347819f8a388b5d67e121ee8d73f328c | https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/type/zset.js#L11-L19 |
51,641 | redisjs/jsr-store | lib/type/zset.js | zadd | function zadd(members) {
var i
, c = 0
, score
, member;
for(i = 0;i < members.length;i+=2) {
score = members[i];
if(INFINITY[score] !== undefined) {
score = INFINITY[score];
}
member = members[i + 1];
if(this.zrank(member) === null) {
c++;
}
// this will add or update the score
this.setKey(member, score);
}
return c;
} | javascript | function zadd(members) {
var i
, c = 0
, score
, member;
for(i = 0;i < members.length;i+=2) {
score = members[i];
if(INFINITY[score] !== undefined) {
score = INFINITY[score];
}
member = members[i + 1];
if(this.zrank(member) === null) {
c++;
}
// this will add or update the score
this.setKey(member, score);
}
return c;
} | [
"function",
"zadd",
"(",
"members",
")",
"{",
"var",
"i",
",",
"c",
"=",
"0",
",",
"score",
",",
"member",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"members",
".",
"length",
";",
"i",
"+=",
"2",
")",
"{",
"score",
"=",
"members",
"[",
"i",
"]",
";",
"if",
"(",
"INFINITY",
"[",
"score",
"]",
"!==",
"undefined",
")",
"{",
"score",
"=",
"INFINITY",
"[",
"score",
"]",
";",
"}",
"member",
"=",
"members",
"[",
"i",
"+",
"1",
"]",
";",
"if",
"(",
"this",
".",
"zrank",
"(",
"member",
")",
"===",
"null",
")",
"{",
"c",
"++",
";",
"}",
"// this will add or update the score",
"this",
".",
"setKey",
"(",
"member",
",",
"score",
")",
";",
"}",
"return",
"c",
";",
"}"
] | Adds all the specified members with the specified
scores to the sorted set. | [
"Adds",
"all",
"the",
"specified",
"members",
"with",
"the",
"specified",
"scores",
"to",
"the",
"sorted",
"set",
"."
] | b2b5c5b0347819f8a388b5d67e121ee8d73f328c | https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/type/zset.js#L27-L45 |
51,642 | redisjs/jsr-store | lib/type/zset.js | zrem | function zrem(members) {
var i
, c = 0;
for(i = 0;i < members.length;i++) {
c += this.delKey(members[i]);
}
return c;
} | javascript | function zrem(members) {
var i
, c = 0;
for(i = 0;i < members.length;i++) {
c += this.delKey(members[i]);
}
return c;
} | [
"function",
"zrem",
"(",
"members",
")",
"{",
"var",
"i",
",",
"c",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"members",
".",
"length",
";",
"i",
"++",
")",
"{",
"c",
"+=",
"this",
".",
"delKey",
"(",
"members",
"[",
"i",
"]",
")",
";",
"}",
"return",
"c",
";",
"}"
] | Removes the specified members from the sorted set. | [
"Removes",
"the",
"specified",
"members",
"from",
"the",
"sorted",
"set",
"."
] | b2b5c5b0347819f8a388b5d67e121ee8d73f328c | https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/type/zset.js#L50-L57 |
51,643 | redisjs/jsr-store | lib/type/zset.js | zrank | function zrank(member) {
if(this._data[member] === undefined) return null;
for(var i = 0;i < this._keys.length;i++) {
if(this.memberEqual(member, this._keys[i].m)) {
return i;
}
}
return null;
} | javascript | function zrank(member) {
if(this._data[member] === undefined) return null;
for(var i = 0;i < this._keys.length;i++) {
if(this.memberEqual(member, this._keys[i].m)) {
return i;
}
}
return null;
} | [
"function",
"zrank",
"(",
"member",
")",
"{",
"if",
"(",
"this",
".",
"_data",
"[",
"member",
"]",
"===",
"undefined",
")",
"return",
"null",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"_keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"memberEqual",
"(",
"member",
",",
"this",
".",
"_keys",
"[",
"i",
"]",
".",
"m",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the rank of member in the sorted set. | [
"Returns",
"the",
"rank",
"of",
"member",
"in",
"the",
"sorted",
"set",
"."
] | b2b5c5b0347819f8a388b5d67e121ee8d73f328c | https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/type/zset.js#L69-L77 |
51,644 | redisjs/jsr-store | lib/type/zset.js | zincrby | function zincrby(increment, member) {
var score = parseFloat(this._data[member]) || 0;
score += parseFloat(increment);
this.setKey(member, score);
return score;
} | javascript | function zincrby(increment, member) {
var score = parseFloat(this._data[member]) || 0;
score += parseFloat(increment);
this.setKey(member, score);
return score;
} | [
"function",
"zincrby",
"(",
"increment",
",",
"member",
")",
"{",
"var",
"score",
"=",
"parseFloat",
"(",
"this",
".",
"_data",
"[",
"member",
"]",
")",
"||",
"0",
";",
"score",
"+=",
"parseFloat",
"(",
"increment",
")",
";",
"this",
".",
"setKey",
"(",
"member",
",",
"score",
")",
";",
"return",
"score",
";",
"}"
] | Increments the score of member by increment. | [
"Increments",
"the",
"score",
"of",
"member",
"by",
"increment",
"."
] | b2b5c5b0347819f8a388b5d67e121ee8d73f328c | https://github.com/redisjs/jsr-store/blob/b2b5c5b0347819f8a388b5d67e121ee8d73f328c/lib/type/zset.js#L105-L110 |
51,645 | redisjs/jsr-server | lib/command/server/config.js | set | function set(req, res) {
var key = '' + req.args[0]
, value = req.args[1];
// already validated the config key/value so should be ok
// to update the in-memory config, some config verification
// methods perform side-effects, eg: dir
this.conf.set(key, value);
res.send(null, Constants.OK);
if(key === ConfigKey.DIR) {
this.log.notice('cwd: %s', process.cwd());
}
} | javascript | function set(req, res) {
var key = '' + req.args[0]
, value = req.args[1];
// already validated the config key/value so should be ok
// to update the in-memory config, some config verification
// methods perform side-effects, eg: dir
this.conf.set(key, value);
res.send(null, Constants.OK);
if(key === ConfigKey.DIR) {
this.log.notice('cwd: %s', process.cwd());
}
} | [
"function",
"set",
"(",
"req",
",",
"res",
")",
"{",
"var",
"key",
"=",
"''",
"+",
"req",
".",
"args",
"[",
"0",
"]",
",",
"value",
"=",
"req",
".",
"args",
"[",
"1",
"]",
";",
"// already validated the config key/value so should be ok",
"// to update the in-memory config, some config verification",
"// methods perform side-effects, eg: dir",
"this",
".",
"conf",
".",
"set",
"(",
"key",
",",
"value",
")",
";",
"res",
".",
"send",
"(",
"null",
",",
"Constants",
".",
"OK",
")",
";",
"if",
"(",
"key",
"===",
"ConfigKey",
".",
"DIR",
")",
"{",
"this",
".",
"log",
".",
"notice",
"(",
"'cwd: %s'",
",",
"process",
".",
"cwd",
"(",
")",
")",
";",
"}",
"}"
] | Respond to the SET subcommand. | [
"Respond",
"to",
"the",
"SET",
"subcommand",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/config.js#L41-L53 |
51,646 | redisjs/jsr-server | lib/command/server/config.js | rewrite | function rewrite(req, res) {
/* istanbul ignore next: tough to mock fs write error */
function onError(err) {
this.conf.removeAllListeners('error');
this.conf.removeAllListeners('write');
res.send(err);
}
function onWrite() {
this.conf.removeAllListeners('error');
this.conf.removeAllListeners('write');
res.send(null, Constants.OK);
}
this.conf.once('error', onError.bind(this));
this.conf.write(this.conf.getFile(), onWrite.bind(this));
} | javascript | function rewrite(req, res) {
/* istanbul ignore next: tough to mock fs write error */
function onError(err) {
this.conf.removeAllListeners('error');
this.conf.removeAllListeners('write');
res.send(err);
}
function onWrite() {
this.conf.removeAllListeners('error');
this.conf.removeAllListeners('write');
res.send(null, Constants.OK);
}
this.conf.once('error', onError.bind(this));
this.conf.write(this.conf.getFile(), onWrite.bind(this));
} | [
"function",
"rewrite",
"(",
"req",
",",
"res",
")",
"{",
"/* istanbul ignore next: tough to mock fs write error */",
"function",
"onError",
"(",
"err",
")",
"{",
"this",
".",
"conf",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"this",
".",
"conf",
".",
"removeAllListeners",
"(",
"'write'",
")",
";",
"res",
".",
"send",
"(",
"err",
")",
";",
"}",
"function",
"onWrite",
"(",
")",
"{",
"this",
".",
"conf",
".",
"removeAllListeners",
"(",
"'error'",
")",
";",
"this",
".",
"conf",
".",
"removeAllListeners",
"(",
"'write'",
")",
";",
"res",
".",
"send",
"(",
"null",
",",
"Constants",
".",
"OK",
")",
";",
"}",
"this",
".",
"conf",
".",
"once",
"(",
"'error'",
",",
"onError",
".",
"bind",
"(",
"this",
")",
")",
";",
"this",
".",
"conf",
".",
"write",
"(",
"this",
".",
"conf",
".",
"getFile",
"(",
")",
",",
"onWrite",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Respond to the REWRITE subcommand. | [
"Respond",
"to",
"the",
"REWRITE",
"subcommand",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/config.js#L58-L75 |
51,647 | redisjs/jsr-server | lib/command/server/config.js | resetstat | function resetstat(req, res) {
this.stats.reset();
res.send(null, Constants.OK);
} | javascript | function resetstat(req, res) {
this.stats.reset();
res.send(null, Constants.OK);
} | [
"function",
"resetstat",
"(",
"req",
",",
"res",
")",
"{",
"this",
".",
"stats",
".",
"reset",
"(",
")",
";",
"res",
".",
"send",
"(",
"null",
",",
"Constants",
".",
"OK",
")",
";",
"}"
] | Respond to the RESETSTAT subcommand. | [
"Respond",
"to",
"the",
"RESETSTAT",
"subcommand",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/config.js#L80-L83 |
51,648 | redisjs/jsr-server | lib/command/server/config.js | validate | function validate(cmd, args, info) {
AbstractCommand.prototype.validate.apply(this, arguments);
var sub = info.command.sub
, cmd = '' + sub.cmd
, args = sub.args
, key
, val
, verified;
if(cmd === Constants.SUBCOMMAND.config.set.name) {
key = '' + args[0];
val = '' + args[1];
// test config key is allowed to be set at runtime
if(!~Runtime.indexOf(key)) {
throw new ConfigParameter(key);
}
// validate input value and coerce to native type
try {
val = this.conf.validate(key, [val]);
// additional validation after type coercion and
// basic checks, some methods modify the value (hz)
// although most just throw an error
verified = this.conf.verify(key, val);
if(verified !== undefined) {
val = verified;
}
args[1] = val;
}catch(e) {
throw new ConfigValue(key, val);
}
}else if(cmd === Constants.SUBCOMMAND.config.rewrite.name) {
if(this.conf.isDefault()) {
throw ConfigRewrite;
}
}
} | javascript | function validate(cmd, args, info) {
AbstractCommand.prototype.validate.apply(this, arguments);
var sub = info.command.sub
, cmd = '' + sub.cmd
, args = sub.args
, key
, val
, verified;
if(cmd === Constants.SUBCOMMAND.config.set.name) {
key = '' + args[0];
val = '' + args[1];
// test config key is allowed to be set at runtime
if(!~Runtime.indexOf(key)) {
throw new ConfigParameter(key);
}
// validate input value and coerce to native type
try {
val = this.conf.validate(key, [val]);
// additional validation after type coercion and
// basic checks, some methods modify the value (hz)
// although most just throw an error
verified = this.conf.verify(key, val);
if(verified !== undefined) {
val = verified;
}
args[1] = val;
}catch(e) {
throw new ConfigValue(key, val);
}
}else if(cmd === Constants.SUBCOMMAND.config.rewrite.name) {
if(this.conf.isDefault()) {
throw ConfigRewrite;
}
}
} | [
"function",
"validate",
"(",
"cmd",
",",
"args",
",",
"info",
")",
"{",
"AbstractCommand",
".",
"prototype",
".",
"validate",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"var",
"sub",
"=",
"info",
".",
"command",
".",
"sub",
",",
"cmd",
"=",
"''",
"+",
"sub",
".",
"cmd",
",",
"args",
"=",
"sub",
".",
"args",
",",
"key",
",",
"val",
",",
"verified",
";",
"if",
"(",
"cmd",
"===",
"Constants",
".",
"SUBCOMMAND",
".",
"config",
".",
"set",
".",
"name",
")",
"{",
"key",
"=",
"''",
"+",
"args",
"[",
"0",
"]",
";",
"val",
"=",
"''",
"+",
"args",
"[",
"1",
"]",
";",
"// test config key is allowed to be set at runtime",
"if",
"(",
"!",
"~",
"Runtime",
".",
"indexOf",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"ConfigParameter",
"(",
"key",
")",
";",
"}",
"// validate input value and coerce to native type",
"try",
"{",
"val",
"=",
"this",
".",
"conf",
".",
"validate",
"(",
"key",
",",
"[",
"val",
"]",
")",
";",
"// additional validation after type coercion and",
"// basic checks, some methods modify the value (hz)",
"// although most just throw an error",
"verified",
"=",
"this",
".",
"conf",
".",
"verify",
"(",
"key",
",",
"val",
")",
";",
"if",
"(",
"verified",
"!==",
"undefined",
")",
"{",
"val",
"=",
"verified",
";",
"}",
"args",
"[",
"1",
"]",
"=",
"val",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"throw",
"new",
"ConfigValue",
"(",
"key",
",",
"val",
")",
";",
"}",
"}",
"else",
"if",
"(",
"cmd",
"===",
"Constants",
".",
"SUBCOMMAND",
".",
"config",
".",
"rewrite",
".",
"name",
")",
"{",
"if",
"(",
"this",
".",
"conf",
".",
"isDefault",
"(",
")",
")",
"{",
"throw",
"ConfigRewrite",
";",
"}",
"}",
"}"
] | Validate the CONFIG subcommands. | [
"Validate",
"the",
"CONFIG",
"subcommands",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/server/config.js#L88-L126 |
51,649 | psnider/tv4-via-typenames | amd/tv4-via-typenames.js | registerSchema | function registerSchema(schema) {
var typename = getTypenameFromSchemaID(schema.id);
var registered_schema = tv4.getSchema(schema.id);
if (registered_schema == null) {
var is_draft_schema = (schema.id === exports.DRAFT_SCHEMA_ID);
if (!is_draft_schema) {
if (typename == null) {
// error typename not available from id
return false;
}
}
else {
typename = exports.DRAFT_SCHEMA_TYPENAME;
}
var result = tv4_validateSchema(schema);
if (result.errors.length === 0) {
// some docs indicate addSchema() returns boolean, but the source code returns nothing
tv4.addSchema(schema);
schemas[typename] = schema;
return true;
}
else {
return false;
}
}
else {
// schema is already registered, don't re-register
return true;
}
} | javascript | function registerSchema(schema) {
var typename = getTypenameFromSchemaID(schema.id);
var registered_schema = tv4.getSchema(schema.id);
if (registered_schema == null) {
var is_draft_schema = (schema.id === exports.DRAFT_SCHEMA_ID);
if (!is_draft_schema) {
if (typename == null) {
// error typename not available from id
return false;
}
}
else {
typename = exports.DRAFT_SCHEMA_TYPENAME;
}
var result = tv4_validateSchema(schema);
if (result.errors.length === 0) {
// some docs indicate addSchema() returns boolean, but the source code returns nothing
tv4.addSchema(schema);
schemas[typename] = schema;
return true;
}
else {
return false;
}
}
else {
// schema is already registered, don't re-register
return true;
}
} | [
"function",
"registerSchema",
"(",
"schema",
")",
"{",
"var",
"typename",
"=",
"getTypenameFromSchemaID",
"(",
"schema",
".",
"id",
")",
";",
"var",
"registered_schema",
"=",
"tv4",
".",
"getSchema",
"(",
"schema",
".",
"id",
")",
";",
"if",
"(",
"registered_schema",
"==",
"null",
")",
"{",
"var",
"is_draft_schema",
"=",
"(",
"schema",
".",
"id",
"===",
"exports",
".",
"DRAFT_SCHEMA_ID",
")",
";",
"if",
"(",
"!",
"is_draft_schema",
")",
"{",
"if",
"(",
"typename",
"==",
"null",
")",
"{",
"// error typename not available from id",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"typename",
"=",
"exports",
".",
"DRAFT_SCHEMA_TYPENAME",
";",
"}",
"var",
"result",
"=",
"tv4_validateSchema",
"(",
"schema",
")",
";",
"if",
"(",
"result",
".",
"errors",
".",
"length",
"===",
"0",
")",
"{",
"// some docs indicate addSchema() returns boolean, but the source code returns nothing",
"tv4",
".",
"addSchema",
"(",
"schema",
")",
";",
"schemas",
"[",
"typename",
"]",
"=",
"schema",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"// schema is already registered, don't re-register",
"return",
"true",
";",
"}",
"}"
] | Regisiter the schema with the schema validation system. The schema is validated by this function, and registered only if it is valid. If a schema with this schema's typename has already been registered, then this returns true with no other action. @return true if successful, or if the schema had already been registered. false if either the schema.id doesn't contain the typename or if the schema is invalid. | [
"Regisiter",
"the",
"schema",
"with",
"the",
"schema",
"validation",
"system",
".",
"The",
"schema",
"is",
"validated",
"by",
"this",
"function",
"and",
"registered",
"only",
"if",
"it",
"is",
"valid",
".",
"If",
"a",
"schema",
"with",
"this",
"schema",
"s",
"typename",
"has",
"already",
"been",
"registered",
"then",
"this",
"returns",
"true",
"with",
"no",
"other",
"action",
"."
] | 15a19de0a0fd2adf9f8a31d15103fbe28efa83c9 | https://github.com/psnider/tv4-via-typenames/blob/15a19de0a0fd2adf9f8a31d15103fbe28efa83c9/amd/tv4-via-typenames.js#L60-L89 |
51,650 | psnider/tv4-via-typenames | amd/tv4-via-typenames.js | tv4_validate | function tv4_validate(typename, query) {
var id = getSchemaIDFromTypename(typename);
var schema = tv4.getSchema(id);
if (schema == null) {
var error = { code: 0, message: 'Schema not found', dataPath: '', schemaPath: id };
return { valid: false, missing: [], errors: [error] };
}
var report = tv4.validateMultiple(query, schema);
return report;
} | javascript | function tv4_validate(typename, query) {
var id = getSchemaIDFromTypename(typename);
var schema = tv4.getSchema(id);
if (schema == null) {
var error = { code: 0, message: 'Schema not found', dataPath: '', schemaPath: id };
return { valid: false, missing: [], errors: [error] };
}
var report = tv4.validateMultiple(query, schema);
return report;
} | [
"function",
"tv4_validate",
"(",
"typename",
",",
"query",
")",
"{",
"var",
"id",
"=",
"getSchemaIDFromTypename",
"(",
"typename",
")",
";",
"var",
"schema",
"=",
"tv4",
".",
"getSchema",
"(",
"id",
")",
";",
"if",
"(",
"schema",
"==",
"null",
")",
"{",
"var",
"error",
"=",
"{",
"code",
":",
"0",
",",
"message",
":",
"'Schema not found'",
",",
"dataPath",
":",
"''",
",",
"schemaPath",
":",
"id",
"}",
";",
"return",
"{",
"valid",
":",
"false",
",",
"missing",
":",
"[",
"]",
",",
"errors",
":",
"[",
"error",
"]",
"}",
";",
"}",
"var",
"report",
"=",
"tv4",
".",
"validateMultiple",
"(",
"query",
",",
"schema",
")",
";",
"return",
"report",
";",
"}"
] | Validate the given JSON against the schema for typename. | [
"Validate",
"the",
"given",
"JSON",
"against",
"the",
"schema",
"for",
"typename",
"."
] | 15a19de0a0fd2adf9f8a31d15103fbe28efa83c9 | https://github.com/psnider/tv4-via-typenames/blob/15a19de0a0fd2adf9f8a31d15103fbe28efa83c9/amd/tv4-via-typenames.js#L91-L100 |
51,651 | psnider/tv4-via-typenames | amd/tv4-via-typenames.js | tv4_validateSchema | function tv4_validateSchema(schema) {
var is_draft_schema = (schema.id === exports.DRAFT_SCHEMA_ID);
var draft_schema = (is_draft_schema) ? schema : tv4.getSchema(exports.DRAFT_SCHEMA_ID);
var report = tv4.validateMultiple(schema, draft_schema);
return report;
} | javascript | function tv4_validateSchema(schema) {
var is_draft_schema = (schema.id === exports.DRAFT_SCHEMA_ID);
var draft_schema = (is_draft_schema) ? schema : tv4.getSchema(exports.DRAFT_SCHEMA_ID);
var report = tv4.validateMultiple(schema, draft_schema);
return report;
} | [
"function",
"tv4_validateSchema",
"(",
"schema",
")",
"{",
"var",
"is_draft_schema",
"=",
"(",
"schema",
".",
"id",
"===",
"exports",
".",
"DRAFT_SCHEMA_ID",
")",
";",
"var",
"draft_schema",
"=",
"(",
"is_draft_schema",
")",
"?",
"schema",
":",
"tv4",
".",
"getSchema",
"(",
"exports",
".",
"DRAFT_SCHEMA_ID",
")",
";",
"var",
"report",
"=",
"tv4",
".",
"validateMultiple",
"(",
"schema",
",",
"draft_schema",
")",
";",
"return",
"report",
";",
"}"
] | Validate the given schema. | [
"Validate",
"the",
"given",
"schema",
"."
] | 15a19de0a0fd2adf9f8a31d15103fbe28efa83c9 | https://github.com/psnider/tv4-via-typenames/blob/15a19de0a0fd2adf9f8a31d15103fbe28efa83c9/amd/tv4-via-typenames.js#L102-L107 |
51,652 | kristianmandrup/ai-core | lib/utils/io.js | mutateJsonFile | function mutateJsonFile(targetPath, source, mutator) {
if (!mutator) {
mutator = source;
source = null;
}
let sourceConfig = source;
try {
// console.log('targetPath', targetPath);
let targetConfig = readJson(targetPath);
// console.log('source', source);
if (typeof source === 'string') {
sourceConfig = readJson(source);
}
// console.log('sourceConfig', targetPath, sourceConfig)
sourceConfig = sourceConfig ? sourceConfig : targetConfig;
let newConfig = mutator(targetConfig, sourceConfig);
writeJson(targetPath, newConfig, {spaces: 2});
} catch (e) {
log.error('Error: operating on aurelia.json. Reverting to previous version ;{}', e);
writeJson(targetPath, sourceConfig, {spaces: 2});
}
} | javascript | function mutateJsonFile(targetPath, source, mutator) {
if (!mutator) {
mutator = source;
source = null;
}
let sourceConfig = source;
try {
// console.log('targetPath', targetPath);
let targetConfig = readJson(targetPath);
// console.log('source', source);
if (typeof source === 'string') {
sourceConfig = readJson(source);
}
// console.log('sourceConfig', targetPath, sourceConfig)
sourceConfig = sourceConfig ? sourceConfig : targetConfig;
let newConfig = mutator(targetConfig, sourceConfig);
writeJson(targetPath, newConfig, {spaces: 2});
} catch (e) {
log.error('Error: operating on aurelia.json. Reverting to previous version ;{}', e);
writeJson(targetPath, sourceConfig, {spaces: 2});
}
} | [
"function",
"mutateJsonFile",
"(",
"targetPath",
",",
"source",
",",
"mutator",
")",
"{",
"if",
"(",
"!",
"mutator",
")",
"{",
"mutator",
"=",
"source",
";",
"source",
"=",
"null",
";",
"}",
"let",
"sourceConfig",
"=",
"source",
";",
"try",
"{",
"// console.log('targetPath', targetPath);",
"let",
"targetConfig",
"=",
"readJson",
"(",
"targetPath",
")",
";",
"// console.log('source', source);",
"if",
"(",
"typeof",
"source",
"===",
"'string'",
")",
"{",
"sourceConfig",
"=",
"readJson",
"(",
"source",
")",
";",
"}",
"// console.log('sourceConfig', targetPath, sourceConfig)",
"sourceConfig",
"=",
"sourceConfig",
"?",
"sourceConfig",
":",
"targetConfig",
";",
"let",
"newConfig",
"=",
"mutator",
"(",
"targetConfig",
",",
"sourceConfig",
")",
";",
"writeJson",
"(",
"targetPath",
",",
"newConfig",
",",
"{",
"spaces",
":",
"2",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"log",
".",
"error",
"(",
"'Error: operating on aurelia.json. Reverting to previous version ;{}'",
",",
"e",
")",
";",
"writeJson",
"(",
"targetPath",
",",
"sourceConfig",
",",
"{",
"spaces",
":",
"2",
"}",
")",
";",
"}",
"}"
] | source must be a filePath to a json file or an Object | [
"source",
"must",
"be",
"a",
"filePath",
"to",
"a",
"json",
"file",
"or",
"an",
"Object"
] | c8968c44b4149a157f2e47c7051805ffc7bd99ed | https://github.com/kristianmandrup/ai-core/blob/c8968c44b4149a157f2e47c7051805ffc7bd99ed/lib/utils/io.js#L101-L127 |
51,653 | skerit/alchemy-menu | assets/scripts/menu/menu_manager.js | detree | function detree(items, children, parent_id) {
var item,
i;
for (i = 0; i < children.length; i++) {
item = children[i];
if (parent_id) {
item.parent = parent_id;
}
items.push(item);
if (item.children) {
detree(items, item.children, item.id);
}
delete item.children;
}
} | javascript | function detree(items, children, parent_id) {
var item,
i;
for (i = 0; i < children.length; i++) {
item = children[i];
if (parent_id) {
item.parent = parent_id;
}
items.push(item);
if (item.children) {
detree(items, item.children, item.id);
}
delete item.children;
}
} | [
"function",
"detree",
"(",
"items",
",",
"children",
",",
"parent_id",
")",
"{",
"var",
"item",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"children",
".",
"length",
";",
"i",
"++",
")",
"{",
"item",
"=",
"children",
"[",
"i",
"]",
";",
"if",
"(",
"parent_id",
")",
"{",
"item",
".",
"parent",
"=",
"parent_id",
";",
"}",
"items",
".",
"push",
"(",
"item",
")",
";",
"if",
"(",
"item",
".",
"children",
")",
"{",
"detree",
"(",
"items",
",",
"item",
".",
"children",
",",
"item",
".",
"id",
")",
";",
"}",
"delete",
"item",
".",
"children",
";",
"}",
"}"
] | Convert a nestable source data tree into a simple list
@author Jelle De Loecker <[email protected]>
@since 0.0.1
@version 0.0.1
@param {Array} items
@param {Object} children
@param {String} parent_id | [
"Convert",
"a",
"nestable",
"source",
"data",
"tree",
"into",
"a",
"simple",
"list"
] | 9614241a63f40fdbf81b6bd1dc96e9bed8334c33 | https://github.com/skerit/alchemy-menu/blob/9614241a63f40fdbf81b6bd1dc96e9bed8334c33/assets/scripts/menu/menu_manager.js#L282-L303 |
51,654 | vkiding/judpack-common | src/PluginInfo/PluginInfo.js | _getTags | function _getTags(pelem, tag, platform, transform) {
var platformTag = pelem.find('./platform[@name="' + platform + '"]');
var tagsInRoot = pelem.findall(tag);
tagsInRoot = tagsInRoot || [];
var tagsInPlatform = platformTag ? platformTag.findall(tag) : [];
var tags = tagsInRoot.concat(tagsInPlatform);
if ( typeof transform === 'function' ) {
tags = tags.map(transform);
}
return tags;
} | javascript | function _getTags(pelem, tag, platform, transform) {
var platformTag = pelem.find('./platform[@name="' + platform + '"]');
var tagsInRoot = pelem.findall(tag);
tagsInRoot = tagsInRoot || [];
var tagsInPlatform = platformTag ? platformTag.findall(tag) : [];
var tags = tagsInRoot.concat(tagsInPlatform);
if ( typeof transform === 'function' ) {
tags = tags.map(transform);
}
return tags;
} | [
"function",
"_getTags",
"(",
"pelem",
",",
"tag",
",",
"platform",
",",
"transform",
")",
"{",
"var",
"platformTag",
"=",
"pelem",
".",
"find",
"(",
"'./platform[@name=\"'",
"+",
"platform",
"+",
"'\"]'",
")",
";",
"var",
"tagsInRoot",
"=",
"pelem",
".",
"findall",
"(",
"tag",
")",
";",
"tagsInRoot",
"=",
"tagsInRoot",
"||",
"[",
"]",
";",
"var",
"tagsInPlatform",
"=",
"platformTag",
"?",
"platformTag",
".",
"findall",
"(",
"tag",
")",
":",
"[",
"]",
";",
"var",
"tags",
"=",
"tagsInRoot",
".",
"concat",
"(",
"tagsInPlatform",
")",
";",
"if",
"(",
"typeof",
"transform",
"===",
"'function'",
")",
"{",
"tags",
"=",
"tags",
".",
"map",
"(",
"transform",
")",
";",
"}",
"return",
"tags",
";",
"}"
] | Helper function used by most of the getSomething methods of PluginInfo. Get all elements of a given name. Both in root and in platform sections for the given platform. If transform is given and is a function, it is applied to each element. | [
"Helper",
"function",
"used",
"by",
"most",
"of",
"the",
"getSomething",
"methods",
"of",
"PluginInfo",
".",
"Get",
"all",
"elements",
"of",
"a",
"given",
"name",
".",
"Both",
"in",
"root",
"and",
"in",
"platform",
"sections",
"for",
"the",
"given",
"platform",
".",
"If",
"transform",
"is",
"given",
"and",
"is",
"a",
"function",
"it",
"is",
"applied",
"to",
"each",
"element",
"."
] | 5b87d3f1cb10c2c867243e3a692d39b4bb189dd4 | https://github.com/vkiding/judpack-common/blob/5b87d3f1cb10c2c867243e3a692d39b4bb189dd4/src/PluginInfo/PluginInfo.js#L390-L400 |
51,655 | andrewscwei/requiem | src/helpers/hasOwnValue.js | hasOwnValue | function hasOwnValue(object, value) {
assertType(object, 'object', false, 'Invalid object specified');
for (let k in object) {
if (object.hasOwnProperty(k) && (object[k] === value)) return true;
}
return false;
} | javascript | function hasOwnValue(object, value) {
assertType(object, 'object', false, 'Invalid object specified');
for (let k in object) {
if (object.hasOwnProperty(k) && (object[k] === value)) return true;
}
return false;
} | [
"function",
"hasOwnValue",
"(",
"object",
",",
"value",
")",
"{",
"assertType",
"(",
"object",
",",
"'object'",
",",
"false",
",",
"'Invalid object specified'",
")",
";",
"for",
"(",
"let",
"k",
"in",
"object",
")",
"{",
"if",
"(",
"object",
".",
"hasOwnProperty",
"(",
"k",
")",
"&&",
"(",
"object",
"[",
"k",
"]",
"===",
"value",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if an object literal has the specified value in one of its keys.
@param {Object} object - Target object literal.
@param {*} value - Value to check.
@return {boolean} True if value is found, false otherwise.
@alias module:requiem~helpers.hasOwnValue | [
"Checks",
"if",
"an",
"object",
"literal",
"has",
"the",
"specified",
"value",
"in",
"one",
"of",
"its",
"keys",
"."
] | c4182bfffc9841c6de5718f689ad3c2060511777 | https://github.com/andrewscwei/requiem/blob/c4182bfffc9841c6de5718f689ad3c2060511777/src/helpers/hasOwnValue.js#L17-L25 |
51,656 | bigpipe/bootstrap-pagelet | index.js | render | function render() {
var framework = this._bigpipe._framework
, bootstrap = this
, data;
data = this.keys.reduce(function reduce(memo, key) {
memo[key] = bootstrap[key];
return memo;
}, {});
//
// Adds initial HTML headers to the queue. The first flush will
// push out these headers immediately. If the render mode is sync
// the headers will be injected with the other content. Since each
// front-end framework might require custom bootstrapping, data is
// passed to fittings, which will return valid bootstrap content.
//
this.debug('Queueing initial headers');
this._queue.push({
name: this.name,
view: framework.get('bootstrap', {
name: this.name,
template: '',
id: this.id,
data: data,
state: {}
})
});
return this;
} | javascript | function render() {
var framework = this._bigpipe._framework
, bootstrap = this
, data;
data = this.keys.reduce(function reduce(memo, key) {
memo[key] = bootstrap[key];
return memo;
}, {});
//
// Adds initial HTML headers to the queue. The first flush will
// push out these headers immediately. If the render mode is sync
// the headers will be injected with the other content. Since each
// front-end framework might require custom bootstrapping, data is
// passed to fittings, which will return valid bootstrap content.
//
this.debug('Queueing initial headers');
this._queue.push({
name: this.name,
view: framework.get('bootstrap', {
name: this.name,
template: '',
id: this.id,
data: data,
state: {}
})
});
return this;
} | [
"function",
"render",
"(",
")",
"{",
"var",
"framework",
"=",
"this",
".",
"_bigpipe",
".",
"_framework",
",",
"bootstrap",
"=",
"this",
",",
"data",
";",
"data",
"=",
"this",
".",
"keys",
".",
"reduce",
"(",
"function",
"reduce",
"(",
"memo",
",",
"key",
")",
"{",
"memo",
"[",
"key",
"]",
"=",
"bootstrap",
"[",
"key",
"]",
";",
"return",
"memo",
";",
"}",
",",
"{",
"}",
")",
";",
"//",
"// Adds initial HTML headers to the queue. The first flush will",
"// push out these headers immediately. If the render mode is sync",
"// the headers will be injected with the other content. Since each",
"// front-end framework might require custom bootstrapping, data is",
"// passed to fittings, which will return valid bootstrap content.",
"//",
"this",
".",
"debug",
"(",
"'Queueing initial headers'",
")",
";",
"this",
".",
"_queue",
".",
"push",
"(",
"{",
"name",
":",
"this",
".",
"name",
",",
"view",
":",
"framework",
".",
"get",
"(",
"'bootstrap'",
",",
"{",
"name",
":",
"this",
".",
"name",
",",
"template",
":",
"''",
",",
"id",
":",
"this",
".",
"id",
",",
"data",
":",
"data",
",",
"state",
":",
"{",
"}",
"}",
")",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Render the HTML template with the data provided. Temper provides a minimal
templater to handle data in HTML templates. Data has to be specifically
provided, properties of `this` are not enumerable and would not be included.
@returns {Pagelet} this
@api public | [
"Render",
"the",
"HTML",
"template",
"with",
"the",
"data",
"provided",
".",
"Temper",
"provides",
"a",
"minimal",
"templater",
"to",
"handle",
"data",
"in",
"HTML",
"templates",
".",
"Data",
"has",
"to",
"be",
"specifically",
"provided",
"properties",
"of",
"this",
"are",
"not",
"enumerable",
"and",
"would",
"not",
"be",
"included",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L109-L139 |
51,657 | bigpipe/bootstrap-pagelet | index.js | contentTypeHeader | function contentTypeHeader(type) {
if (this._res.headersSent) return this.debug(
'Headers already sent, ignoring content type change: %s', contentTypes[type]
);
this.contentType = contentTypes[type];
this._res.setHeader('Content-Type', this.contentType);
} | javascript | function contentTypeHeader(type) {
if (this._res.headersSent) return this.debug(
'Headers already sent, ignoring content type change: %s', contentTypes[type]
);
this.contentType = contentTypes[type];
this._res.setHeader('Content-Type', this.contentType);
} | [
"function",
"contentTypeHeader",
"(",
"type",
")",
"{",
"if",
"(",
"this",
".",
"_res",
".",
"headersSent",
")",
"return",
"this",
".",
"debug",
"(",
"'Headers already sent, ignoring content type change: %s'",
",",
"contentTypes",
"[",
"type",
"]",
")",
";",
"this",
".",
"contentType",
"=",
"contentTypes",
"[",
"type",
"]",
";",
"this",
".",
"_res",
".",
"setHeader",
"(",
"'Content-Type'",
",",
"this",
".",
"contentType",
")",
";",
"}"
] | Change the contentType header if possible.
@param {String} type html|json
@api private | [
"Change",
"the",
"contentType",
"header",
"if",
"possible",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L147-L154 |
51,658 | bigpipe/bootstrap-pagelet | index.js | queue | function queue(name, parent, data) {
this.length--;
//
// Object was queued, transform the response type to application/json.
//
if ('object' === typeof data && this._contentType !== contentTypes.json) {
this.emit('contentType', 'json');
}
this._queue.push({
parent: parent,
name: name,
view: data
});
return this;
} | javascript | function queue(name, parent, data) {
this.length--;
//
// Object was queued, transform the response type to application/json.
//
if ('object' === typeof data && this._contentType !== contentTypes.json) {
this.emit('contentType', 'json');
}
this._queue.push({
parent: parent,
name: name,
view: data
});
return this;
} | [
"function",
"queue",
"(",
"name",
",",
"parent",
",",
"data",
")",
"{",
"this",
".",
"length",
"--",
";",
"//",
"// Object was queued, transform the response type to application/json.",
"//",
"if",
"(",
"'object'",
"===",
"typeof",
"data",
"&&",
"this",
".",
"_contentType",
"!==",
"contentTypes",
".",
"json",
")",
"{",
"this",
".",
"emit",
"(",
"'contentType'",
",",
"'json'",
")",
";",
"}",
"this",
".",
"_queue",
".",
"push",
"(",
"{",
"parent",
":",
"parent",
",",
"name",
":",
"name",
",",
"view",
":",
"data",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Add fragment of data to the queue.
@param {String} name Pagelet name that queued the content.
@param {String} parent Pagelet parent that queued the content.
@param {Mixed} data Output to be send to the response
@returns {Pagelet} this
@api public | [
"Add",
"fragment",
"of",
"data",
"to",
"the",
"queue",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L165-L182 |
51,659 | bigpipe/bootstrap-pagelet | index.js | join | function join() {
var pagelet = this
, result = this._queue.map(function flatten(fragment) {
if (!fragment.name || !fragment.view) return '';
return fragment.view;
});
try {
result = this._contentType === contentTypes.json
? JSON.stringify(result.shift())
: result.join('');
} catch (error) {
this.emit('done', error);
return this.debug('Captured error while stringifying JSON data %s', error);
}
this._queue.length = 0;
return result;
} | javascript | function join() {
var pagelet = this
, result = this._queue.map(function flatten(fragment) {
if (!fragment.name || !fragment.view) return '';
return fragment.view;
});
try {
result = this._contentType === contentTypes.json
? JSON.stringify(result.shift())
: result.join('');
} catch (error) {
this.emit('done', error);
return this.debug('Captured error while stringifying JSON data %s', error);
}
this._queue.length = 0;
return result;
} | [
"function",
"join",
"(",
")",
"{",
"var",
"pagelet",
"=",
"this",
",",
"result",
"=",
"this",
".",
"_queue",
".",
"map",
"(",
"function",
"flatten",
"(",
"fragment",
")",
"{",
"if",
"(",
"!",
"fragment",
".",
"name",
"||",
"!",
"fragment",
".",
"view",
")",
"return",
"''",
";",
"return",
"fragment",
".",
"view",
";",
"}",
")",
";",
"try",
"{",
"result",
"=",
"this",
".",
"_contentType",
"===",
"contentTypes",
".",
"json",
"?",
"JSON",
".",
"stringify",
"(",
"result",
".",
"shift",
"(",
")",
")",
":",
"result",
".",
"join",
"(",
"''",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"this",
".",
"emit",
"(",
"'done'",
",",
"error",
")",
";",
"return",
"this",
".",
"debug",
"(",
"'Captured error while stringifying JSON data %s'",
",",
"error",
")",
";",
"}",
"this",
".",
"_queue",
".",
"length",
"=",
"0",
";",
"return",
"result",
";",
"}"
] | Joins all the data fragments in the queue.
@return {Mixed} Object by pagelet name or HTML string
@api private | [
"Joins",
"all",
"the",
"data",
"fragments",
"in",
"the",
"queue",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L190-L208 |
51,660 | bigpipe/bootstrap-pagelet | index.js | flush | function flush(done) {
this.once('done', done);
if (this._res.finished) {
this.emit('done', new Error('Response was closed, unable to flush content'));
}
if (!this._queue.length) this.emit('done');
var data = new Buffer(this.join(), this.charset);
if (data.length) {
this.debug('Writing %d bytes of %s to response', data.length, this.charset);
this._res.write(data, this.emits('done'));
}
//
// Optional write confirmation, it got added in more recent versions of
// node, so if it's not supported we're just going to call the callback
// our selfs.
//
if (this._res.write.length !== 3 || !data.length) this.emit('done');
} | javascript | function flush(done) {
this.once('done', done);
if (this._res.finished) {
this.emit('done', new Error('Response was closed, unable to flush content'));
}
if (!this._queue.length) this.emit('done');
var data = new Buffer(this.join(), this.charset);
if (data.length) {
this.debug('Writing %d bytes of %s to response', data.length, this.charset);
this._res.write(data, this.emits('done'));
}
//
// Optional write confirmation, it got added in more recent versions of
// node, so if it's not supported we're just going to call the callback
// our selfs.
//
if (this._res.write.length !== 3 || !data.length) this.emit('done');
} | [
"function",
"flush",
"(",
"done",
")",
"{",
"this",
".",
"once",
"(",
"'done'",
",",
"done",
")",
";",
"if",
"(",
"this",
".",
"_res",
".",
"finished",
")",
"{",
"this",
".",
"emit",
"(",
"'done'",
",",
"new",
"Error",
"(",
"'Response was closed, unable to flush content'",
")",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"_queue",
".",
"length",
")",
"this",
".",
"emit",
"(",
"'done'",
")",
";",
"var",
"data",
"=",
"new",
"Buffer",
"(",
"this",
".",
"join",
"(",
")",
",",
"this",
".",
"charset",
")",
";",
"if",
"(",
"data",
".",
"length",
")",
"{",
"this",
".",
"debug",
"(",
"'Writing %d bytes of %s to response'",
",",
"data",
".",
"length",
",",
"this",
".",
"charset",
")",
";",
"this",
".",
"_res",
".",
"write",
"(",
"data",
",",
"this",
".",
"emits",
"(",
"'done'",
")",
")",
";",
"}",
"//",
"// Optional write confirmation, it got added in more recent versions of",
"// node, so if it's not supported we're just going to call the callback",
"// our selfs.",
"//",
"if",
"(",
"this",
".",
"_res",
".",
"write",
".",
"length",
"!==",
"3",
"||",
"!",
"data",
".",
"length",
")",
"this",
".",
"emit",
"(",
"'done'",
")",
";",
"}"
] | Flush all queued rendered pagelets to the request object.
@returns {Pagelet} this
@api private | [
"Flush",
"all",
"queued",
"rendered",
"pagelets",
"to",
"the",
"request",
"object",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L216-L237 |
51,661 | bigpipe/bootstrap-pagelet | index.js | constructor | function constructor(options) {
Pagelet.prototype.constructor.call(this, options = options || {});
//
// Store the provided global dependencies.
//
this.dependencies = this._bigpipe._compiler.page(this).concat(
options.dependencies
);
var req = options.req || {}
, uri = req.uri || {}
, query = req.query || {};
//
// Set a number of properties on the response as it is available to all pagelets.
// This will ensure the correct amount of pagelets are processed and that the
// entire queue is written to the client.
//
this._queue = [];
//
// Prepare several properties that are used to render the HTML fragment.
//
this.length = options.length || 0;
this.child = options.child || 'root';
this.once('contentType', this.contentTypeHeader, this);
//
// Set the default fallback script, see explanation above.
//
this.debug('Initialized in %s mode', options.mode);
this.fallback = 'sync' === options.mode ? script : noscript.replace(
'{path}',
uri.pathname || 'http://localhost/'
).replace(
'{query}',
qs.stringify(this.merge({ no_pagelet_js: 1 }, query))
);
} | javascript | function constructor(options) {
Pagelet.prototype.constructor.call(this, options = options || {});
//
// Store the provided global dependencies.
//
this.dependencies = this._bigpipe._compiler.page(this).concat(
options.dependencies
);
var req = options.req || {}
, uri = req.uri || {}
, query = req.query || {};
//
// Set a number of properties on the response as it is available to all pagelets.
// This will ensure the correct amount of pagelets are processed and that the
// entire queue is written to the client.
//
this._queue = [];
//
// Prepare several properties that are used to render the HTML fragment.
//
this.length = options.length || 0;
this.child = options.child || 'root';
this.once('contentType', this.contentTypeHeader, this);
//
// Set the default fallback script, see explanation above.
//
this.debug('Initialized in %s mode', options.mode);
this.fallback = 'sync' === options.mode ? script : noscript.replace(
'{path}',
uri.pathname || 'http://localhost/'
).replace(
'{query}',
qs.stringify(this.merge({ no_pagelet_js: 1 }, query))
);
} | [
"function",
"constructor",
"(",
"options",
")",
"{",
"Pagelet",
".",
"prototype",
".",
"constructor",
".",
"call",
"(",
"this",
",",
"options",
"=",
"options",
"||",
"{",
"}",
")",
";",
"//",
"// Store the provided global dependencies.",
"//",
"this",
".",
"dependencies",
"=",
"this",
".",
"_bigpipe",
".",
"_compiler",
".",
"page",
"(",
"this",
")",
".",
"concat",
"(",
"options",
".",
"dependencies",
")",
";",
"var",
"req",
"=",
"options",
".",
"req",
"||",
"{",
"}",
",",
"uri",
"=",
"req",
".",
"uri",
"||",
"{",
"}",
",",
"query",
"=",
"req",
".",
"query",
"||",
"{",
"}",
";",
"//",
"// Set a number of properties on the response as it is available to all pagelets.",
"// This will ensure the correct amount of pagelets are processed and that the",
"// entire queue is written to the client.",
"//",
"this",
".",
"_queue",
"=",
"[",
"]",
";",
"//",
"// Prepare several properties that are used to render the HTML fragment.",
"//",
"this",
".",
"length",
"=",
"options",
".",
"length",
"||",
"0",
";",
"this",
".",
"child",
"=",
"options",
".",
"child",
"||",
"'root'",
";",
"this",
".",
"once",
"(",
"'contentType'",
",",
"this",
".",
"contentTypeHeader",
",",
"this",
")",
";",
"//",
"// Set the default fallback script, see explanation above.",
"//",
"this",
".",
"debug",
"(",
"'Initialized in %s mode'",
",",
"options",
".",
"mode",
")",
";",
"this",
".",
"fallback",
"=",
"'sync'",
"===",
"options",
".",
"mode",
"?",
"script",
":",
"noscript",
".",
"replace",
"(",
"'{path}'",
",",
"uri",
".",
"pathname",
"||",
"'http://localhost/'",
")",
".",
"replace",
"(",
"'{query}'",
",",
"qs",
".",
"stringify",
"(",
"this",
".",
"merge",
"(",
"{",
"no_pagelet_js",
":",
"1",
"}",
",",
"query",
")",
")",
")",
";",
"}"
] | Extend the default constructor of the pagelet to set additional defaults
based on the provided options.
@param {Object} options Optional options.
@api public | [
"Extend",
"the",
"default",
"constructor",
"of",
"the",
"pagelet",
"to",
"set",
"additional",
"defaults",
"based",
"on",
"the",
"provided",
"options",
"."
] | cf03e008aca36e413edd067ff8d83e2f1f59ed9f | https://github.com/bigpipe/bootstrap-pagelet/blob/cf03e008aca36e413edd067ff8d83e2f1f59ed9f/index.js#L315-L354 |
51,662 | vkiding/jud-vue-render | src/render/browser/bridge/sender.js | function (callbackId, data, keepAlive) {
const args = [callbackId]
data && args.push(data)
keepAlive && args.push(keepAlive)
_send(this.instanceId, {
method: 'callback',
args: args
})
} | javascript | function (callbackId, data, keepAlive) {
const args = [callbackId]
data && args.push(data)
keepAlive && args.push(keepAlive)
_send(this.instanceId, {
method: 'callback',
args: args
})
} | [
"function",
"(",
"callbackId",
",",
"data",
",",
"keepAlive",
")",
"{",
"const",
"args",
"=",
"[",
"callbackId",
"]",
"data",
"&&",
"args",
".",
"push",
"(",
"data",
")",
"keepAlive",
"&&",
"args",
".",
"push",
"(",
"keepAlive",
")",
"_send",
"(",
"this",
".",
"instanceId",
",",
"{",
"method",
":",
"'callback'",
",",
"args",
":",
"args",
"}",
")",
"}"
] | perform a callback to jsframework. | [
"perform",
"a",
"callback",
"to",
"jsframework",
"."
] | 07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47 | https://github.com/vkiding/jud-vue-render/blob/07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47/src/render/browser/bridge/sender.js#L27-L35 |
|
51,663 | benderjs/benderjs-jasmine | lib/adapter.js | BenderReporter | function BenderReporter() {
var timer = new jasmine.Timer(),
current = new Suite(),
passed = 0,
failed = 0,
errors = 0,
ignored = 0,
total = 0;
function buildError( result ) {
var pattern = /\n.*jasmine.js.*/gi,
error = [],
exp,
i;
for ( i = 0; i < result.failedExpectations.length; i++ ) {
errors++;
exp = result.failedExpectations[ i ];
if ( exp.stack ) {
if ( exp.stack.indexOf( exp.message ) === -1 ) {
error.push( exp.message );
}
error.push(
exp.stack
.replace( pattern, '' )
);
} else {
error.push( exp.message );
}
}
return error.join( '\n' );
}
this.jasmineStarted = function() {
timer.start();
};
this.jasmineDone = function() {
bender.next( {
duration: timer.elapsed(),
passed: passed,
failed: failed,
errors: errors,
ignored: ignored,
total: total,
coverage: window.__coverage__
} );
};
this.suiteStarted = function( suite ) {
current = new Suite( suite.description, current );
};
this.suiteDone = function() {
current = current.parent;
};
this.specStarted = function( result ) {
total++;
result.startTime = +new Date();
};
this.specDone = function( result ) {
var modules = [], p = current;
while ( p ) {
if ( p.name ) {
modules.push( p.name );
}
p = p.parent;
}
result.module = modules.reverse().join( ' / ' );
result.name = result.description;
result.success = true;
result.duration = +new Date() - result.startTime;
if ( result.status === 'passed' ) {
passed++;
} else if ( result.status === 'disabled' || result.status === 'pending' ) {
result.ignored = true;
ignored++;
} else {
result.success = false;
result.error = buildError( result );
result.errors = errors;
failed++;
}
bender.result( result );
};
} | javascript | function BenderReporter() {
var timer = new jasmine.Timer(),
current = new Suite(),
passed = 0,
failed = 0,
errors = 0,
ignored = 0,
total = 0;
function buildError( result ) {
var pattern = /\n.*jasmine.js.*/gi,
error = [],
exp,
i;
for ( i = 0; i < result.failedExpectations.length; i++ ) {
errors++;
exp = result.failedExpectations[ i ];
if ( exp.stack ) {
if ( exp.stack.indexOf( exp.message ) === -1 ) {
error.push( exp.message );
}
error.push(
exp.stack
.replace( pattern, '' )
);
} else {
error.push( exp.message );
}
}
return error.join( '\n' );
}
this.jasmineStarted = function() {
timer.start();
};
this.jasmineDone = function() {
bender.next( {
duration: timer.elapsed(),
passed: passed,
failed: failed,
errors: errors,
ignored: ignored,
total: total,
coverage: window.__coverage__
} );
};
this.suiteStarted = function( suite ) {
current = new Suite( suite.description, current );
};
this.suiteDone = function() {
current = current.parent;
};
this.specStarted = function( result ) {
total++;
result.startTime = +new Date();
};
this.specDone = function( result ) {
var modules = [], p = current;
while ( p ) {
if ( p.name ) {
modules.push( p.name );
}
p = p.parent;
}
result.module = modules.reverse().join( ' / ' );
result.name = result.description;
result.success = true;
result.duration = +new Date() - result.startTime;
if ( result.status === 'passed' ) {
passed++;
} else if ( result.status === 'disabled' || result.status === 'pending' ) {
result.ignored = true;
ignored++;
} else {
result.success = false;
result.error = buildError( result );
result.errors = errors;
failed++;
}
bender.result( result );
};
} | [
"function",
"BenderReporter",
"(",
")",
"{",
"var",
"timer",
"=",
"new",
"jasmine",
".",
"Timer",
"(",
")",
",",
"current",
"=",
"new",
"Suite",
"(",
")",
",",
"passed",
"=",
"0",
",",
"failed",
"=",
"0",
",",
"errors",
"=",
"0",
",",
"ignored",
"=",
"0",
",",
"total",
"=",
"0",
";",
"function",
"buildError",
"(",
"result",
")",
"{",
"var",
"pattern",
"=",
"/",
"\\n.*jasmine.js.*",
"/",
"gi",
",",
"error",
"=",
"[",
"]",
",",
"exp",
",",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"result",
".",
"failedExpectations",
".",
"length",
";",
"i",
"++",
")",
"{",
"errors",
"++",
";",
"exp",
"=",
"result",
".",
"failedExpectations",
"[",
"i",
"]",
";",
"if",
"(",
"exp",
".",
"stack",
")",
"{",
"if",
"(",
"exp",
".",
"stack",
".",
"indexOf",
"(",
"exp",
".",
"message",
")",
"===",
"-",
"1",
")",
"{",
"error",
".",
"push",
"(",
"exp",
".",
"message",
")",
";",
"}",
"error",
".",
"push",
"(",
"exp",
".",
"stack",
".",
"replace",
"(",
"pattern",
",",
"''",
")",
")",
";",
"}",
"else",
"{",
"error",
".",
"push",
"(",
"exp",
".",
"message",
")",
";",
"}",
"}",
"return",
"error",
".",
"join",
"(",
"'\\n'",
")",
";",
"}",
"this",
".",
"jasmineStarted",
"=",
"function",
"(",
")",
"{",
"timer",
".",
"start",
"(",
")",
";",
"}",
";",
"this",
".",
"jasmineDone",
"=",
"function",
"(",
")",
"{",
"bender",
".",
"next",
"(",
"{",
"duration",
":",
"timer",
".",
"elapsed",
"(",
")",
",",
"passed",
":",
"passed",
",",
"failed",
":",
"failed",
",",
"errors",
":",
"errors",
",",
"ignored",
":",
"ignored",
",",
"total",
":",
"total",
",",
"coverage",
":",
"window",
".",
"__coverage__",
"}",
")",
";",
"}",
";",
"this",
".",
"suiteStarted",
"=",
"function",
"(",
"suite",
")",
"{",
"current",
"=",
"new",
"Suite",
"(",
"suite",
".",
"description",
",",
"current",
")",
";",
"}",
";",
"this",
".",
"suiteDone",
"=",
"function",
"(",
")",
"{",
"current",
"=",
"current",
".",
"parent",
";",
"}",
";",
"this",
".",
"specStarted",
"=",
"function",
"(",
"result",
")",
"{",
"total",
"++",
";",
"result",
".",
"startTime",
"=",
"+",
"new",
"Date",
"(",
")",
";",
"}",
";",
"this",
".",
"specDone",
"=",
"function",
"(",
"result",
")",
"{",
"var",
"modules",
"=",
"[",
"]",
",",
"p",
"=",
"current",
";",
"while",
"(",
"p",
")",
"{",
"if",
"(",
"p",
".",
"name",
")",
"{",
"modules",
".",
"push",
"(",
"p",
".",
"name",
")",
";",
"}",
"p",
"=",
"p",
".",
"parent",
";",
"}",
"result",
".",
"module",
"=",
"modules",
".",
"reverse",
"(",
")",
".",
"join",
"(",
"' / '",
")",
";",
"result",
".",
"name",
"=",
"result",
".",
"description",
";",
"result",
".",
"success",
"=",
"true",
";",
"result",
".",
"duration",
"=",
"+",
"new",
"Date",
"(",
")",
"-",
"result",
".",
"startTime",
";",
"if",
"(",
"result",
".",
"status",
"===",
"'passed'",
")",
"{",
"passed",
"++",
";",
"}",
"else",
"if",
"(",
"result",
".",
"status",
"===",
"'disabled'",
"||",
"result",
".",
"status",
"===",
"'pending'",
")",
"{",
"result",
".",
"ignored",
"=",
"true",
";",
"ignored",
"++",
";",
"}",
"else",
"{",
"result",
".",
"success",
"=",
"false",
";",
"result",
".",
"error",
"=",
"buildError",
"(",
"result",
")",
";",
"result",
".",
"errors",
"=",
"errors",
";",
"failed",
"++",
";",
"}",
"bender",
".",
"result",
"(",
"result",
")",
";",
"}",
";",
"}"
] | custom reporter that will pass the results to bender | [
"custom",
"reporter",
"that",
"will",
"pass",
"the",
"results",
"to",
"bender"
] | d02ffb927e1e3be3f7ec57c7cd37546fcbb6d162 | https://github.com/benderjs/benderjs-jasmine/blob/d02ffb927e1e3be3f7ec57c7cd37546fcbb6d162/lib/adapter.js#L66-L162 |
51,664 | intesso/hidden-server | lib/hidden.js | HiddenServer | function HiddenServer(opts) {
if (!(this instanceof HiddenServer)) return new HiddenServer(opts);
this.set(require('../settings.json'));
this.set(opts);
this.uri = this.get('publicServer') + this.get('pingUri').replace(':hiddenServerName', this.get('hiddenServerName'));
debug('uri', this.uri);
this.init();
} | javascript | function HiddenServer(opts) {
if (!(this instanceof HiddenServer)) return new HiddenServer(opts);
this.set(require('../settings.json'));
this.set(opts);
this.uri = this.get('publicServer') + this.get('pingUri').replace(':hiddenServerName', this.get('hiddenServerName'));
debug('uri', this.uri);
this.init();
} | [
"function",
"HiddenServer",
"(",
"opts",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"HiddenServer",
")",
")",
"return",
"new",
"HiddenServer",
"(",
"opts",
")",
";",
"this",
".",
"set",
"(",
"require",
"(",
"'../settings.json'",
")",
")",
";",
"this",
".",
"set",
"(",
"opts",
")",
";",
"this",
".",
"uri",
"=",
"this",
".",
"get",
"(",
"'publicServer'",
")",
"+",
"this",
".",
"get",
"(",
"'pingUri'",
")",
".",
"replace",
"(",
"':hiddenServerName'",
",",
"this",
".",
"get",
"(",
"'hiddenServerName'",
")",
")",
";",
"debug",
"(",
"'uri'",
",",
"this",
".",
"uri",
")",
";",
"this",
".",
"init",
"(",
")",
";",
"}"
] | `HiddenServer` Constructor function. | [
"HiddenServer",
"Constructor",
"function",
"."
] | 827336a77f43555b14bc204aa542e91e7296e0cf | https://github.com/intesso/hidden-server/blob/827336a77f43555b14bc204aa542e91e7296e0cf/lib/hidden.js#L16-L24 |
51,665 | NicolaOrritos/progenic | lib/utils.js | function(options)
{
return new Promise( (resolve, reject) =>
{
if (options)
{
options.logger.info('[PROGENIC] Starting "%s" daemon with %s workers...', options.name, options.workers);
options.logger.info('[PROGENIC] [from "%s"]', options.main);
// Write the PID file:
helpers.writePidFile(options.name, options.devMode, options.logger);
cluster.setupMaster(
{
exec: path.join(__dirname, 'worker.js'),
args: [options.main, process.env.INSTANCE_NAME],
silent: true
});
const promises = [];
let count = options.workers;
while (count-- > 0)
{
options.logger.info('[PROGENIC] Creating worker #%s...', (options.workers - count));
promises.push(helpers.forkWorker(options.name, options.devMode, options.logger, options.logsBasePath, options.checkPingsEnabled));
}
Promise.all(promises)
.then(resolve)
.catch(reject);
}
else
{
reject(new Error('Missing options'));
}
});
} | javascript | function(options)
{
return new Promise( (resolve, reject) =>
{
if (options)
{
options.logger.info('[PROGENIC] Starting "%s" daemon with %s workers...', options.name, options.workers);
options.logger.info('[PROGENIC] [from "%s"]', options.main);
// Write the PID file:
helpers.writePidFile(options.name, options.devMode, options.logger);
cluster.setupMaster(
{
exec: path.join(__dirname, 'worker.js'),
args: [options.main, process.env.INSTANCE_NAME],
silent: true
});
const promises = [];
let count = options.workers;
while (count-- > 0)
{
options.logger.info('[PROGENIC] Creating worker #%s...', (options.workers - count));
promises.push(helpers.forkWorker(options.name, options.devMode, options.logger, options.logsBasePath, options.checkPingsEnabled));
}
Promise.all(promises)
.then(resolve)
.catch(reject);
}
else
{
reject(new Error('Missing options'));
}
});
} | [
"function",
"(",
"options",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"if",
"(",
"options",
")",
"{",
"options",
".",
"logger",
".",
"info",
"(",
"'[PROGENIC] Starting \"%s\" daemon with %s workers...'",
",",
"options",
".",
"name",
",",
"options",
".",
"workers",
")",
";",
"options",
".",
"logger",
".",
"info",
"(",
"'[PROGENIC] [from \"%s\"]'",
",",
"options",
".",
"main",
")",
";",
"// Write the PID file:",
"helpers",
".",
"writePidFile",
"(",
"options",
".",
"name",
",",
"options",
".",
"devMode",
",",
"options",
".",
"logger",
")",
";",
"cluster",
".",
"setupMaster",
"(",
"{",
"exec",
":",
"path",
".",
"join",
"(",
"__dirname",
",",
"'worker.js'",
")",
",",
"args",
":",
"[",
"options",
".",
"main",
",",
"process",
".",
"env",
".",
"INSTANCE_NAME",
"]",
",",
"silent",
":",
"true",
"}",
")",
";",
"const",
"promises",
"=",
"[",
"]",
";",
"let",
"count",
"=",
"options",
".",
"workers",
";",
"while",
"(",
"count",
"--",
">",
"0",
")",
"{",
"options",
".",
"logger",
".",
"info",
"(",
"'[PROGENIC] Creating worker #%s...'",
",",
"(",
"options",
".",
"workers",
"-",
"count",
")",
")",
";",
"promises",
".",
"push",
"(",
"helpers",
".",
"forkWorker",
"(",
"options",
".",
"name",
",",
"options",
".",
"devMode",
",",
"options",
".",
"logger",
",",
"options",
".",
"logsBasePath",
",",
"options",
".",
"checkPingsEnabled",
")",
")",
";",
"}",
"Promise",
".",
"all",
"(",
"promises",
")",
".",
"then",
"(",
"resolve",
")",
".",
"catch",
"(",
"reject",
")",
";",
"}",
"else",
"{",
"reject",
"(",
"new",
"Error",
"(",
"'Missing options'",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] | Creates the children workers when running as cluster master.
Runs the HTTP server otherwise.
@param {Number} count Number of workers to create. | [
"Creates",
"the",
"children",
"workers",
"when",
"running",
"as",
"cluster",
"master",
".",
"Runs",
"the",
"HTTP",
"server",
"otherwise",
"."
] | eee85a2d9375a2930216ccbb7f03d254fb35a2e7 | https://github.com/NicolaOrritos/progenic/blob/eee85a2d9375a2930216ccbb7f03d254fb35a2e7/lib/utils.js#L404-L443 |
|
51,666 | NicolaOrritos/progenic | lib/utils.js | function(signal)
{
return new Promise( resolve =>
{
for (let uniqueID in cluster.workers)
{
if (cluster.workers.hasOwnProperty(uniqueID))
{
const worker = cluster.workers[uniqueID];
worker.kill(signal);
}
}
resolve();
});
} | javascript | function(signal)
{
return new Promise( resolve =>
{
for (let uniqueID in cluster.workers)
{
if (cluster.workers.hasOwnProperty(uniqueID))
{
const worker = cluster.workers[uniqueID];
worker.kill(signal);
}
}
resolve();
});
} | [
"function",
"(",
"signal",
")",
"{",
"return",
"new",
"Promise",
"(",
"resolve",
"=>",
"{",
"for",
"(",
"let",
"uniqueID",
"in",
"cluster",
".",
"workers",
")",
"{",
"if",
"(",
"cluster",
".",
"workers",
".",
"hasOwnProperty",
"(",
"uniqueID",
")",
")",
"{",
"const",
"worker",
"=",
"cluster",
".",
"workers",
"[",
"uniqueID",
"]",
";",
"worker",
".",
"kill",
"(",
"signal",
")",
";",
"}",
"}",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}"
] | Kills all workers with the given signal.
@param {Number} signal | [
"Kills",
"all",
"workers",
"with",
"the",
"given",
"signal",
"."
] | eee85a2d9375a2930216ccbb7f03d254fb35a2e7 | https://github.com/NicolaOrritos/progenic/blob/eee85a2d9375a2930216ccbb7f03d254fb35a2e7/lib/utils.js#L449-L465 |
|
51,667 | aureooms/js-grammar | lib/ast/map.js | map | function map(callable, children) {
var iterator = (0, _cmap.default)(callable, children)[Symbol.asyncIterator]();
return new _Children.default(iterator, undefined);
} | javascript | function map(callable, children) {
var iterator = (0, _cmap.default)(callable, children)[Symbol.asyncIterator]();
return new _Children.default(iterator, undefined);
} | [
"function",
"map",
"(",
"callable",
",",
"children",
")",
"{",
"var",
"iterator",
"=",
"(",
"0",
",",
"_cmap",
".",
"default",
")",
"(",
"callable",
",",
"children",
")",
"[",
"Symbol",
".",
"asyncIterator",
"]",
"(",
")",
";",
"return",
"new",
"_Children",
".",
"default",
"(",
"iterator",
",",
"undefined",
")",
";",
"}"
] | Applies a given callable to each of the child of a given children async iterable.
@param {Function} callable - The callable to use.
@param {AsyncIterable} children - The input children.
@returns {AsyncIterator} | [
"Applies",
"a",
"given",
"callable",
"to",
"each",
"of",
"the",
"child",
"of",
"a",
"given",
"children",
"async",
"iterable",
"."
] | 28c4d1a3175327b33766c34539eab317303e26c5 | https://github.com/aureooms/js-grammar/blob/28c4d1a3175327b33766c34539eab317303e26c5/lib/ast/map.js#L21-L24 |
51,668 | gethuman/pancakes-recipe | batch/reactor.cleanup/reactor.cleanup.batch.js | cleanupPrep | function cleanupPrep(options) {
var sourceResource = options.source;
var targetResource = options.target;
var targetReactor = options.reactor;
var reactor;
// if there is a target reactor, just use that cleanupPrep
if (targetReactor) {
reactor = reactors[targetReactor];
if (reactor && reactor.cleanupPrep) {
log.info('Running cleanupPrep for ' + targetReactor);
return reactors[targetReactor].cleanupPrep();
}
}
// else if source and target resources don't exist (i.e. we are doing everything) the try to call all
else if (!sourceResource && !targetResource) {
return Q.all(reactors.map(function (rctr) {
log.info('Running cleanupPrep for ' + rctr);
return rctr.cleanupPrep ? rctr.cleanupPrep() : true;
}));
}
// else just return a resolved promise
return new Q();
} | javascript | function cleanupPrep(options) {
var sourceResource = options.source;
var targetResource = options.target;
var targetReactor = options.reactor;
var reactor;
// if there is a target reactor, just use that cleanupPrep
if (targetReactor) {
reactor = reactors[targetReactor];
if (reactor && reactor.cleanupPrep) {
log.info('Running cleanupPrep for ' + targetReactor);
return reactors[targetReactor].cleanupPrep();
}
}
// else if source and target resources don't exist (i.e. we are doing everything) the try to call all
else if (!sourceResource && !targetResource) {
return Q.all(reactors.map(function (rctr) {
log.info('Running cleanupPrep for ' + rctr);
return rctr.cleanupPrep ? rctr.cleanupPrep() : true;
}));
}
// else just return a resolved promise
return new Q();
} | [
"function",
"cleanupPrep",
"(",
"options",
")",
"{",
"var",
"sourceResource",
"=",
"options",
".",
"source",
";",
"var",
"targetResource",
"=",
"options",
".",
"target",
";",
"var",
"targetReactor",
"=",
"options",
".",
"reactor",
";",
"var",
"reactor",
";",
"// if there is a target reactor, just use that cleanupPrep",
"if",
"(",
"targetReactor",
")",
"{",
"reactor",
"=",
"reactors",
"[",
"targetReactor",
"]",
";",
"if",
"(",
"reactor",
"&&",
"reactor",
".",
"cleanupPrep",
")",
"{",
"log",
".",
"info",
"(",
"'Running cleanupPrep for '",
"+",
"targetReactor",
")",
";",
"return",
"reactors",
"[",
"targetReactor",
"]",
".",
"cleanupPrep",
"(",
")",
";",
"}",
"}",
"// else if source and target resources don't exist (i.e. we are doing everything) the try to call all",
"else",
"if",
"(",
"!",
"sourceResource",
"&&",
"!",
"targetResource",
")",
"{",
"return",
"Q",
".",
"all",
"(",
"reactors",
".",
"map",
"(",
"function",
"(",
"rctr",
")",
"{",
"log",
".",
"info",
"(",
"'Running cleanupPrep for '",
"+",
"rctr",
")",
";",
"return",
"rctr",
".",
"cleanupPrep",
"?",
"rctr",
".",
"cleanupPrep",
"(",
")",
":",
"true",
";",
"}",
")",
")",
";",
"}",
"// else just return a resolved promise",
"return",
"new",
"Q",
"(",
")",
";",
"}"
] | Loop through reactors and clean them up
@param options
@returns {*} | [
"Loop",
"through",
"reactors",
"and",
"clean",
"them",
"up"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/batch/reactor.cleanup/reactor.cleanup.batch.js#L54-L78 |
51,669 | gethuman/pancakes-recipe | batch/reactor.cleanup/reactor.cleanup.batch.js | getCleanupData | function getCleanupData(options) {
var sourceResource = options.source;
var targetResource = options.target === 'all' ? null : options.target;
var targetReactor = options.reactor;
var targetField = options.field;
var cleanupData = [];
// if source resource an option, we only use that, else we look at all resources
var srcs = sourceResource === 'all' ? resources : [resources[sourceResource]];
// loop through all resources
_.each(srcs, function (resource) {
// loop through all reactors in each resource
_.each(resource.reactors, function (reactData) {
// apply the options filters to determine if we are adding this resource and reactData
if ((!targetReactor || reactData.type === targetReactor) &&
(!targetResource || reactData.target === targetResource ||
reactData.parent === targetResource || reactData.child === targetResource) &&
(!targetField || reactData.targetField === targetField)) {
cleanupData.push({ resource: resource, reactData: reactData });
}
});
});
return cleanupData;
} | javascript | function getCleanupData(options) {
var sourceResource = options.source;
var targetResource = options.target === 'all' ? null : options.target;
var targetReactor = options.reactor;
var targetField = options.field;
var cleanupData = [];
// if source resource an option, we only use that, else we look at all resources
var srcs = sourceResource === 'all' ? resources : [resources[sourceResource]];
// loop through all resources
_.each(srcs, function (resource) {
// loop through all reactors in each resource
_.each(resource.reactors, function (reactData) {
// apply the options filters to determine if we are adding this resource and reactData
if ((!targetReactor || reactData.type === targetReactor) &&
(!targetResource || reactData.target === targetResource ||
reactData.parent === targetResource || reactData.child === targetResource) &&
(!targetField || reactData.targetField === targetField)) {
cleanupData.push({ resource: resource, reactData: reactData });
}
});
});
return cleanupData;
} | [
"function",
"getCleanupData",
"(",
"options",
")",
"{",
"var",
"sourceResource",
"=",
"options",
".",
"source",
";",
"var",
"targetResource",
"=",
"options",
".",
"target",
"===",
"'all'",
"?",
"null",
":",
"options",
".",
"target",
";",
"var",
"targetReactor",
"=",
"options",
".",
"reactor",
";",
"var",
"targetField",
"=",
"options",
".",
"field",
";",
"var",
"cleanupData",
"=",
"[",
"]",
";",
"// if source resource an option, we only use that, else we look at all resources",
"var",
"srcs",
"=",
"sourceResource",
"===",
"'all'",
"?",
"resources",
":",
"[",
"resources",
"[",
"sourceResource",
"]",
"]",
";",
"// loop through all resources",
"_",
".",
"each",
"(",
"srcs",
",",
"function",
"(",
"resource",
")",
"{",
"// loop through all reactors in each resource",
"_",
".",
"each",
"(",
"resource",
".",
"reactors",
",",
"function",
"(",
"reactData",
")",
"{",
"// apply the options filters to determine if we are adding this resource and reactData",
"if",
"(",
"(",
"!",
"targetReactor",
"||",
"reactData",
".",
"type",
"===",
"targetReactor",
")",
"&&",
"(",
"!",
"targetResource",
"||",
"reactData",
".",
"target",
"===",
"targetResource",
"||",
"reactData",
".",
"parent",
"===",
"targetResource",
"||",
"reactData",
".",
"child",
"===",
"targetResource",
")",
"&&",
"(",
"!",
"targetField",
"||",
"reactData",
".",
"targetField",
"===",
"targetField",
")",
")",
"{",
"cleanupData",
".",
"push",
"(",
"{",
"resource",
":",
"resource",
",",
"reactData",
":",
"reactData",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"cleanupData",
";",
"}"
] | Get the cleanup data based on the batch options
@param options | [
"Get",
"the",
"cleanup",
"data",
"based",
"on",
"the",
"batch",
"options"
] | ea3feb8839e2edaf1b4577c052b8958953db4498 | https://github.com/gethuman/pancakes-recipe/blob/ea3feb8839e2edaf1b4577c052b8958953db4498/batch/reactor.cleanup/reactor.cleanup.batch.js#L84-L112 |
51,670 | alexpods/ClazzJS | src/components/meta/Property/Default.js | function(object, defaultValue, property) {
if (!_.isUndefined(defaultValue)) {
object.__setPropertyParam(property, 'default', defaultValue);
}
} | javascript | function(object, defaultValue, property) {
if (!_.isUndefined(defaultValue)) {
object.__setPropertyParam(property, 'default', defaultValue);
}
} | [
"function",
"(",
"object",
",",
"defaultValue",
",",
"property",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isUndefined",
"(",
"defaultValue",
")",
")",
"{",
"object",
".",
"__setPropertyParam",
"(",
"property",
",",
"'default'",
",",
"defaultValue",
")",
";",
"}",
"}"
] | Set default value for object property
@param {object} object Some object
@param {*} defaultValue Default value
@param {string} property Property name
@this {metaProcessor} | [
"Set",
"default",
"value",
"for",
"object",
"property"
] | 2f94496019669813c8246d48fcceb12a3e68a870 | https://github.com/alexpods/ClazzJS/blob/2f94496019669813c8246d48fcceb12a3e68a870/src/components/meta/Property/Default.js#L16-L20 |
|
51,671 | JavaScriptDude/ps-sync | lib/main.js | function(psRec,sProcId){
if(!sProcId){throw new Error("No Proc Id found in data");}
var iFind,sArgs
iFind=psRec.CommandLine.indexOf(psRec.Name);
sArgs = psRec.CommandLine.substring(iFind+psRec.Name.length+1);
psRecs[sProcId]={
pid: psRec.ProcessId
,ppid: psRec.ParentProcessId
,commandPath: psRec.ExecutablePath
,command: psRec.Name
,args: sArgs
}
} | javascript | function(psRec,sProcId){
if(!sProcId){throw new Error("No Proc Id found in data");}
var iFind,sArgs
iFind=psRec.CommandLine.indexOf(psRec.Name);
sArgs = psRec.CommandLine.substring(iFind+psRec.Name.length+1);
psRecs[sProcId]={
pid: psRec.ProcessId
,ppid: psRec.ParentProcessId
,commandPath: psRec.ExecutablePath
,command: psRec.Name
,args: sArgs
}
} | [
"function",
"(",
"psRec",
",",
"sProcId",
")",
"{",
"if",
"(",
"!",
"sProcId",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"No Proc Id found in data\"",
")",
";",
"}",
"var",
"iFind",
",",
"sArgs",
"iFind",
"=",
"psRec",
".",
"CommandLine",
".",
"indexOf",
"(",
"psRec",
".",
"Name",
")",
";",
"sArgs",
"=",
"psRec",
".",
"CommandLine",
".",
"substring",
"(",
"iFind",
"+",
"psRec",
".",
"Name",
".",
"length",
"+",
"1",
")",
";",
"psRecs",
"[",
"sProcId",
"]",
"=",
"{",
"pid",
":",
"psRec",
".",
"ProcessId",
",",
"ppid",
":",
"psRec",
".",
"ParentProcessId",
",",
"commandPath",
":",
"psRec",
".",
"ExecutablePath",
",",
"command",
":",
"psRec",
".",
"Name",
",",
"args",
":",
"sArgs",
"}",
"}"
] | Now parse the WMIC return | [
"Now",
"parse",
"the",
"WMIC",
"return"
] | 0e909e50d1555bdaa567cccd27ced6b69aec7c4c | https://github.com/JavaScriptDude/ps-sync/blob/0e909e50d1555bdaa567cccd27ced6b69aec7c4c/lib/main.js#L50-L62 |
|
51,672 | inviqa/deck-task-registry | src/other/watch.js | watch | function watch(conf, undertaker) {
const root = conf.themeConfig.root;
/**
* STYLE WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.sass.src, '**', '*.scss'),
undertaker.series(
require('../styles/lintStyles').bind(null, conf, undertaker),
require('../styles/buildStyles').bind(null, conf, undertaker),
require('../styles/holograph').bind(null, conf, undertaker)
)
);
/**
* SCRIPT WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.js.src, '**', '*.js'),
undertaker.series(
require('../scripts/lintScripts').bind(null, conf, undertaker),
require('../scripts/buildScripts').bind(null, conf, undertaker)
)
);
/**
* IMAGE WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.images.src, '**', '*'),
undertaker.series(
require('../assets/buildImages').bind(null, conf, undertaker)
)
);
/**
* FONT WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.fonts.src, '**', '*'),
undertaker.series(
require('../assets/buildFonts').bind(null, conf, undertaker)
)
);
} | javascript | function watch(conf, undertaker) {
const root = conf.themeConfig.root;
/**
* STYLE WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.sass.src, '**', '*.scss'),
undertaker.series(
require('../styles/lintStyles').bind(null, conf, undertaker),
require('../styles/buildStyles').bind(null, conf, undertaker),
require('../styles/holograph').bind(null, conf, undertaker)
)
);
/**
* SCRIPT WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.js.src, '**', '*.js'),
undertaker.series(
require('../scripts/lintScripts').bind(null, conf, undertaker),
require('../scripts/buildScripts').bind(null, conf, undertaker)
)
);
/**
* IMAGE WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.images.src, '**', '*'),
undertaker.series(
require('../assets/buildImages').bind(null, conf, undertaker)
)
);
/**
* FONT WATCHING.
*/
undertaker.watch(
path.join(root, conf.themeConfig.fonts.src, '**', '*'),
undertaker.series(
require('../assets/buildFonts').bind(null, conf, undertaker)
)
);
} | [
"function",
"watch",
"(",
"conf",
",",
"undertaker",
")",
"{",
"const",
"root",
"=",
"conf",
".",
"themeConfig",
".",
"root",
";",
"/**\n * STYLE WATCHING.\n */",
"undertaker",
".",
"watch",
"(",
"path",
".",
"join",
"(",
"root",
",",
"conf",
".",
"themeConfig",
".",
"sass",
".",
"src",
",",
"'**'",
",",
"'*.scss'",
")",
",",
"undertaker",
".",
"series",
"(",
"require",
"(",
"'../styles/lintStyles'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
",",
"require",
"(",
"'../styles/buildStyles'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
",",
"require",
"(",
"'../styles/holograph'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
")",
")",
";",
"/**\n * SCRIPT WATCHING.\n */",
"undertaker",
".",
"watch",
"(",
"path",
".",
"join",
"(",
"root",
",",
"conf",
".",
"themeConfig",
".",
"js",
".",
"src",
",",
"'**'",
",",
"'*.js'",
")",
",",
"undertaker",
".",
"series",
"(",
"require",
"(",
"'../scripts/lintScripts'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
",",
"require",
"(",
"'../scripts/buildScripts'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
")",
")",
";",
"/**\n * IMAGE WATCHING.\n */",
"undertaker",
".",
"watch",
"(",
"path",
".",
"join",
"(",
"root",
",",
"conf",
".",
"themeConfig",
".",
"images",
".",
"src",
",",
"'**'",
",",
"'*'",
")",
",",
"undertaker",
".",
"series",
"(",
"require",
"(",
"'../assets/buildImages'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
")",
")",
";",
"/**\n * FONT WATCHING.\n */",
"undertaker",
".",
"watch",
"(",
"path",
".",
"join",
"(",
"root",
",",
"conf",
".",
"themeConfig",
".",
"fonts",
".",
"src",
",",
"'**'",
",",
"'*'",
")",
",",
"undertaker",
".",
"series",
"(",
"require",
"(",
"'../assets/buildFonts'",
")",
".",
"bind",
"(",
"null",
",",
"conf",
",",
"undertaker",
")",
")",
")",
";",
"}"
] | Watch project files.
@param {ConfigParser} conf A configuration parser object.
@param {Undertaker} undertaker An Undertaker instance. | [
"Watch",
"project",
"files",
"."
] | 4c31787b978e9d99a47052e090d4589a50cd3015 | https://github.com/inviqa/deck-task-registry/blob/4c31787b978e9d99a47052e090d4589a50cd3015/src/other/watch.js#L11-L58 |
51,673 | fullstackers/bus.io-common | lib/builder.js | Builder | function Builder (data) {
if (!(this instanceof Builder)) return new Builder(data);
debug('new builder', data);
events.EventEmitter.call(this);
this.message = Message(data);
} | javascript | function Builder (data) {
if (!(this instanceof Builder)) return new Builder(data);
debug('new builder', data);
events.EventEmitter.call(this);
this.message = Message(data);
} | [
"function",
"Builder",
"(",
"data",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Builder",
")",
")",
"return",
"new",
"Builder",
"(",
"data",
")",
";",
"debug",
"(",
"'new builder'",
",",
"data",
")",
";",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"message",
"=",
"Message",
"(",
"data",
")",
";",
"}"
] | Builds a Message instance and provides a way to deliver the built message
@param {object} data | [
"Builds",
"a",
"Message",
"instance",
"and",
"provides",
"a",
"way",
"to",
"deliver",
"the",
"built",
"message"
] | 9e081a15ba40c4233a936d4105465277da8578fd | https://github.com/fullstackers/bus.io-common/blob/9e081a15ba40c4233a936d4105465277da8578fd/lib/builder.js#L16-L26 |
51,674 | TheOrbitals/angle-functions | dist/index.js | rounddeg | function rounddeg(angle) {
var result = 360.0 * (angle / 360.0 - Math.floor(angle / 360.0));
if (result < 0.0) {
result += 360.0;
}
if (result >= 360.0) {
result -= 360.0;
}
return result;
} | javascript | function rounddeg(angle) {
var result = 360.0 * (angle / 360.0 - Math.floor(angle / 360.0));
if (result < 0.0) {
result += 360.0;
}
if (result >= 360.0) {
result -= 360.0;
}
return result;
} | [
"function",
"rounddeg",
"(",
"angle",
")",
"{",
"var",
"result",
"=",
"360.0",
"*",
"(",
"angle",
"/",
"360.0",
"-",
"Math",
".",
"floor",
"(",
"angle",
"/",
"360.0",
")",
")",
";",
"if",
"(",
"result",
"<",
"0.0",
")",
"{",
"result",
"+=",
"360.0",
";",
"}",
"if",
"(",
"result",
">=",
"360.0",
")",
"{",
"result",
"-=",
"360.0",
";",
"}",
"return",
"result",
";",
"}"
] | Rounds the degree angle between 0 and 360
@param {number} angle
@return {number} | [
"Rounds",
"the",
"degree",
"angle",
"between",
"0",
"and",
"360"
] | dee45ac051a1c245639718cb8936cccfd94d325f | https://github.com/TheOrbitals/angle-functions/blob/dee45ac051a1c245639718cb8936cccfd94d325f/dist/index.js#L54-L63 |
51,675 | ionut-botizan/external-jsx-loader | index.js | getViewRoot | function getViewRoot(source) {
const tokens = parse(source);
let position = tokens.length;
let tagDepth = 0;
let tagName;
let token;
/**
* Loop backwards through the view's source and find the last closing tag
* and its matching opening tag to determine the view's root node position.
*/
while (token = tokens[--position]) {
if (token.type !== TokenTypes.TagStart) {
continue;
}
let tag = parseTag(position, tokens);
// the last node in the source is a self-closing tag; use that
if (!tagName && tag.self) {
break;
}
// this is the last tag in the source; save the name and find its pair
if (!tagName) {
tagName = tag.name;
tagDepth++;
continue;
}
// ignore any tags with a different name
if (tag.name !== tagName) {
continue;
}
// increase tags' depth in the tree for closing tags
if (!tag.open) {
tagDepth++;
}
// decrease tags' depth in the tree for opening (not self-closing) tags
if (tag.open && !tag.self) {
tagDepth--;
}
// if the tag's depth reached 0, it means this is the opening tag
if (tagDepth === 0) {
break;
}
}
token = tokens[position];
return token ? token.start : 0;
} | javascript | function getViewRoot(source) {
const tokens = parse(source);
let position = tokens.length;
let tagDepth = 0;
let tagName;
let token;
/**
* Loop backwards through the view's source and find the last closing tag
* and its matching opening tag to determine the view's root node position.
*/
while (token = tokens[--position]) {
if (token.type !== TokenTypes.TagStart) {
continue;
}
let tag = parseTag(position, tokens);
// the last node in the source is a self-closing tag; use that
if (!tagName && tag.self) {
break;
}
// this is the last tag in the source; save the name and find its pair
if (!tagName) {
tagName = tag.name;
tagDepth++;
continue;
}
// ignore any tags with a different name
if (tag.name !== tagName) {
continue;
}
// increase tags' depth in the tree for closing tags
if (!tag.open) {
tagDepth++;
}
// decrease tags' depth in the tree for opening (not self-closing) tags
if (tag.open && !tag.self) {
tagDepth--;
}
// if the tag's depth reached 0, it means this is the opening tag
if (tagDepth === 0) {
break;
}
}
token = tokens[position];
return token ? token.start : 0;
} | [
"function",
"getViewRoot",
"(",
"source",
")",
"{",
"const",
"tokens",
"=",
"parse",
"(",
"source",
")",
";",
"let",
"position",
"=",
"tokens",
".",
"length",
";",
"let",
"tagDepth",
"=",
"0",
";",
"let",
"tagName",
";",
"let",
"token",
";",
"/**\n\t * Loop backwards through the view's source and find the last closing tag\n\t * and its matching opening tag to determine the view's root node position.\n\t */",
"while",
"(",
"token",
"=",
"tokens",
"[",
"--",
"position",
"]",
")",
"{",
"if",
"(",
"token",
".",
"type",
"!==",
"TokenTypes",
".",
"TagStart",
")",
"{",
"continue",
";",
"}",
"let",
"tag",
"=",
"parseTag",
"(",
"position",
",",
"tokens",
")",
";",
"// the last node in the source is a self-closing tag; use that",
"if",
"(",
"!",
"tagName",
"&&",
"tag",
".",
"self",
")",
"{",
"break",
";",
"}",
"// this is the last tag in the source; save the name and find its pair",
"if",
"(",
"!",
"tagName",
")",
"{",
"tagName",
"=",
"tag",
".",
"name",
";",
"tagDepth",
"++",
";",
"continue",
";",
"}",
"// ignore any tags with a different name",
"if",
"(",
"tag",
".",
"name",
"!==",
"tagName",
")",
"{",
"continue",
";",
"}",
"// increase tags' depth in the tree for closing tags",
"if",
"(",
"!",
"tag",
".",
"open",
")",
"{",
"tagDepth",
"++",
";",
"}",
"// decrease tags' depth in the tree for opening (not self-closing) tags",
"if",
"(",
"tag",
".",
"open",
"&&",
"!",
"tag",
".",
"self",
")",
"{",
"tagDepth",
"--",
";",
"}",
"// if the tag's depth reached 0, it means this is the opening tag",
"if",
"(",
"tagDepth",
"===",
"0",
")",
"{",
"break",
";",
"}",
"}",
"token",
"=",
"tokens",
"[",
"position",
"]",
";",
"return",
"token",
"?",
"token",
".",
"start",
":",
"0",
";",
"}"
] | Finds the position of the opening JSX tag in the source code. | [
"Finds",
"the",
"position",
"of",
"the",
"opening",
"JSX",
"tag",
"in",
"the",
"source",
"code",
"."
] | 6d9a9044c7a38fa1bb98710b8a381083ab7ece8f | https://github.com/ionut-botizan/external-jsx-loader/blob/6d9a9044c7a38fa1bb98710b8a381083ab7ece8f/index.js#L93-L148 |
51,676 | seelang2/imapper-storage-s3ses | lib/storage.js | function(next) {
S3.getObject({
Bucket: S3Handler.options.S3BucketName,
Key: S3Handler.options.mboxName + S3Handler.options.S3MessageListKeySuffix
},
next
);
} | javascript | function(next) {
S3.getObject({
Bucket: S3Handler.options.S3BucketName,
Key: S3Handler.options.mboxName + S3Handler.options.S3MessageListKeySuffix
},
next
);
} | [
"function",
"(",
"next",
")",
"{",
"S3",
".",
"getObject",
"(",
"{",
"Bucket",
":",
"S3Handler",
".",
"options",
".",
"S3BucketName",
",",
"Key",
":",
"S3Handler",
".",
"options",
".",
"mboxName",
"+",
"S3Handler",
".",
"options",
".",
"S3MessageListKeySuffix",
"}",
",",
"next",
")",
";",
"}"
] | get the messagelist data | [
"get",
"the",
"messagelist",
"data"
] | 1755b12f84744b8d45aff123ac17ead5fbc3f09c | https://github.com/seelang2/imapper-storage-s3ses/blob/1755b12f84744b8d45aff123ac17ead5fbc3f09c/lib/storage.js#L60-L67 |
|
51,677 | seelang2/imapper-storage-s3ses | lib/storage.js | function(messagelist, next) {
var keyList = JSON.parse(messagelist.Body);
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Raw messageList object:',keyList);
// update last modified timestamp
// also reset message list count
// not using yet so don't modify and save
//keyList.last_checked = new Date().getTime();
keyList.messages.forEach(function(item, index) {
//if (item.key.search('.json') > -1) return; // skip non-message files
data.INBOX.messages.push({
key: item.key,
raw: '',
flags: [],
internaldate: formatInternalDate(new Date(item.created))
}); // push
//data.INBOX.marker = item.Key; // update marker
}); // forEach
indexFolders();
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Refreshed INBOX:',data);
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'INBOX message detail:',data.INBOX.messages);
// should save data here
next(null);
} | javascript | function(messagelist, next) {
var keyList = JSON.parse(messagelist.Body);
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Raw messageList object:',keyList);
// update last modified timestamp
// also reset message list count
// not using yet so don't modify and save
//keyList.last_checked = new Date().getTime();
keyList.messages.forEach(function(item, index) {
//if (item.key.search('.json') > -1) return; // skip non-message files
data.INBOX.messages.push({
key: item.key,
raw: '',
flags: [],
internaldate: formatInternalDate(new Date(item.created))
}); // push
//data.INBOX.marker = item.Key; // update marker
}); // forEach
indexFolders();
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Refreshed INBOX:',data);
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'INBOX message detail:',data.INBOX.messages);
// should save data here
next(null);
} | [
"function",
"(",
"messagelist",
",",
"next",
")",
"{",
"var",
"keyList",
"=",
"JSON",
".",
"parse",
"(",
"messagelist",
".",
"Body",
")",
";",
"if",
"(",
"CONSOLE_MESSAGES",
")",
"console",
".",
"log",
"(",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
",",
"'Raw messageList object:'",
",",
"keyList",
")",
";",
"// update last modified timestamp",
"// also reset message list count",
"// not using yet so don't modify and save",
"//keyList.last_checked = new Date().getTime();",
"keyList",
".",
"messages",
".",
"forEach",
"(",
"function",
"(",
"item",
",",
"index",
")",
"{",
"//if (item.key.search('.json') > -1) return; // skip non-message files",
"data",
".",
"INBOX",
".",
"messages",
".",
"push",
"(",
"{",
"key",
":",
"item",
".",
"key",
",",
"raw",
":",
"''",
",",
"flags",
":",
"[",
"]",
",",
"internaldate",
":",
"formatInternalDate",
"(",
"new",
"Date",
"(",
"item",
".",
"created",
")",
")",
"}",
")",
";",
"// push",
"//data.INBOX.marker = item.Key; // update marker",
"}",
")",
";",
"// forEach",
"indexFolders",
"(",
")",
";",
"if",
"(",
"CONSOLE_MESSAGES",
")",
"console",
".",
"log",
"(",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
",",
"'Refreshed INBOX:'",
",",
"data",
")",
";",
"if",
"(",
"CONSOLE_MESSAGES",
")",
"console",
".",
"log",
"(",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
",",
"'INBOX message detail:'",
",",
"data",
".",
"INBOX",
".",
"messages",
")",
";",
"// should save data here",
"next",
"(",
"null",
")",
";",
"}"
] | process messagelist data | [
"process",
"messagelist",
"data"
] | 1755b12f84744b8d45aff123ac17ead5fbc3f09c | https://github.com/seelang2/imapper-storage-s3ses/blob/1755b12f84744b8d45aff123ac17ead5fbc3f09c/lib/storage.js#L69-L95 |
|
51,678 | seelang2/imapper-storage-s3ses | lib/storage.js | function(callback) {
var params = {
Bucket: S3Handler.options.S3BucketName,
Key: S3Handler.options.mboxName + S3Handler.options.S3MboxKeySuffix,
Body: JSON.stringify(data)
};
s3.upload(params, function(err, response) {
if (err) {
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Error saving Mbox:',err);
}
callback(err, response);
});
} | javascript | function(callback) {
var params = {
Bucket: S3Handler.options.S3BucketName,
Key: S3Handler.options.mboxName + S3Handler.options.S3MboxKeySuffix,
Body: JSON.stringify(data)
};
s3.upload(params, function(err, response) {
if (err) {
if (CONSOLE_MESSAGES) console.log(new Date().toISOString(),'Error saving Mbox:',err);
}
callback(err, response);
});
} | [
"function",
"(",
"callback",
")",
"{",
"var",
"params",
"=",
"{",
"Bucket",
":",
"S3Handler",
".",
"options",
".",
"S3BucketName",
",",
"Key",
":",
"S3Handler",
".",
"options",
".",
"mboxName",
"+",
"S3Handler",
".",
"options",
".",
"S3MboxKeySuffix",
",",
"Body",
":",
"JSON",
".",
"stringify",
"(",
"data",
")",
"}",
";",
"s3",
".",
"upload",
"(",
"params",
",",
"function",
"(",
"err",
",",
"response",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"CONSOLE_MESSAGES",
")",
"console",
".",
"log",
"(",
"new",
"Date",
"(",
")",
".",
"toISOString",
"(",
")",
",",
"'Error saving Mbox:'",
",",
"err",
")",
";",
"}",
"callback",
"(",
"err",
",",
"response",
")",
";",
"}",
")",
";",
"}"
] | listObjects
Saves the data file to the user mailbox | [
"listObjects",
"Saves",
"the",
"data",
"file",
"to",
"the",
"user",
"mailbox"
] | 1755b12f84744b8d45aff123ac17ead5fbc3f09c | https://github.com/seelang2/imapper-storage-s3ses/blob/1755b12f84744b8d45aff123ac17ead5fbc3f09c/lib/storage.js#L163-L176 |
|
51,679 | cconstantine/NoDevent | assets/js/eventemitter.js | Event | function Event(type, listener, scope, once, instance) {
// Store arguments
this.type = type;
this.listener = listener;
this.scope = scope;
this.once = once;
this.instance = instance;
} | javascript | function Event(type, listener, scope, once, instance) {
// Store arguments
this.type = type;
this.listener = listener;
this.scope = scope;
this.once = once;
this.instance = instance;
} | [
"function",
"Event",
"(",
"type",
",",
"listener",
",",
"scope",
",",
"once",
",",
"instance",
")",
"{",
"// Store arguments",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"listener",
"=",
"listener",
";",
"this",
".",
"scope",
"=",
"scope",
";",
"this",
".",
"once",
"=",
"once",
";",
"this",
".",
"instance",
"=",
"instance",
";",
"}"
] | Event class
Contains Event methods and property storage
@param {String} type Event type name
@param {Function} listener Function to be called when the event is fired
@param {Object} scope Object that this should be set to when the listener is called
@param {Boolean} once If true then the listener will be removed after the first call
@param {Object} instance The parent EventEmitter instance | [
"Event",
"class",
"Contains",
"Event",
"methods",
"and",
"property",
"storage"
] | d17e5bdad2a6bf7006dc4291b44a705ce5b08c47 | https://github.com/cconstantine/NoDevent/blob/d17e5bdad2a6bf7006dc4291b44a705ce5b08c47/assets/js/eventemitter.js#L36-L43 |
51,680 | iteam-consulting/graphql-form-handler | src/index.js | render | function render(form, template) {
const compiledRowTemplate = handlebars.compile(
'<tr class="form-element">' +
'<td class="key">{{key}}</td>' +
'<td class="value">{{value}}</td>' +
'</tr>');
const compiledTable = handlebars.compile(
'<table><tbody>{{{rows}}}</tbody></table>');
const compiledTemplate = handlebars.compile(template);
const formElements = form.map(({key, value}) => {
if (key !== 'File') {
return compiledRowTemplate({key, value: unescape(value)});
}
return null;
});
const formData = compiledTable({rows: formElements.join(' ')});
return compiledTemplate({formData});
} | javascript | function render(form, template) {
const compiledRowTemplate = handlebars.compile(
'<tr class="form-element">' +
'<td class="key">{{key}}</td>' +
'<td class="value">{{value}}</td>' +
'</tr>');
const compiledTable = handlebars.compile(
'<table><tbody>{{{rows}}}</tbody></table>');
const compiledTemplate = handlebars.compile(template);
const formElements = form.map(({key, value}) => {
if (key !== 'File') {
return compiledRowTemplate({key, value: unescape(value)});
}
return null;
});
const formData = compiledTable({rows: formElements.join(' ')});
return compiledTemplate({formData});
} | [
"function",
"render",
"(",
"form",
",",
"template",
")",
"{",
"const",
"compiledRowTemplate",
"=",
"handlebars",
".",
"compile",
"(",
"'<tr class=\"form-element\">'",
"+",
"'<td class=\"key\">{{key}}</td>'",
"+",
"'<td class=\"value\">{{value}}</td>'",
"+",
"'</tr>'",
")",
";",
"const",
"compiledTable",
"=",
"handlebars",
".",
"compile",
"(",
"'<table><tbody>{{{rows}}}</tbody></table>'",
")",
";",
"const",
"compiledTemplate",
"=",
"handlebars",
".",
"compile",
"(",
"template",
")",
";",
"const",
"formElements",
"=",
"form",
".",
"map",
"(",
"(",
"{",
"key",
",",
"value",
"}",
")",
"=>",
"{",
"if",
"(",
"key",
"!==",
"'File'",
")",
"{",
"return",
"compiledRowTemplate",
"(",
"{",
"key",
",",
"value",
":",
"unescape",
"(",
"value",
")",
"}",
")",
";",
"}",
"return",
"null",
";",
"}",
")",
";",
"const",
"formData",
"=",
"compiledTable",
"(",
"{",
"rows",
":",
"formElements",
".",
"join",
"(",
"' '",
")",
"}",
")",
";",
"return",
"compiledTemplate",
"(",
"{",
"formData",
"}",
")",
";",
"}"
] | Function that returns the html to be rendered in the email
@param {array} form an array of key value pairs
@param {string} template The template to compile.
@return {string} The rendered template. | [
"Function",
"that",
"returns",
"the",
"html",
"to",
"be",
"rendered",
"in",
"the",
"email"
] | 56e11599b1872ae9d6c95b2d8ea1125f858c06f6 | https://github.com/iteam-consulting/graphql-form-handler/blob/56e11599b1872ae9d6c95b2d8ea1125f858c06f6/src/index.js#L50-L71 |
51,681 | hypergroup/hyper-uri-format | index.js | encode | function encode(cache, API_URL, obj) {
if (!obj) return null;
if (!obj.href) return obj;
var href = API_URL ?
pack(obj.href, API_URL) :
obj.href;
var cached = cache.get(href);
if (cached) return cached;
var encoded = base64.encode(new Buffer(href)).toString();
cache.set(href, encoded);
return encoded;
} | javascript | function encode(cache, API_URL, obj) {
if (!obj) return null;
if (!obj.href) return obj;
var href = API_URL ?
pack(obj.href, API_URL) :
obj.href;
var cached = cache.get(href);
if (cached) return cached;
var encoded = base64.encode(new Buffer(href)).toString();
cache.set(href, encoded);
return encoded;
} | [
"function",
"encode",
"(",
"cache",
",",
"API_URL",
",",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"return",
"null",
";",
"if",
"(",
"!",
"obj",
".",
"href",
")",
"return",
"obj",
";",
"var",
"href",
"=",
"API_URL",
"?",
"pack",
"(",
"obj",
".",
"href",
",",
"API_URL",
")",
":",
"obj",
".",
"href",
";",
"var",
"cached",
"=",
"cache",
".",
"get",
"(",
"href",
")",
";",
"if",
"(",
"cached",
")",
"return",
"cached",
";",
"var",
"encoded",
"=",
"base64",
".",
"encode",
"(",
"new",
"Buffer",
"(",
"href",
")",
")",
".",
"toString",
"(",
")",
";",
"cache",
".",
"set",
"(",
"href",
",",
"encoded",
")",
";",
"return",
"encoded",
";",
"}"
] | Encode an href object | [
"Encode",
"an",
"href",
"object"
] | e2d56f205604684bd5805ae6c460fe50f41c0dfe | https://github.com/hypergroup/hyper-uri-format/blob/e2d56f205604684bd5805ae6c460fe50f41c0dfe/index.js#L63-L77 |
51,682 | hypergroup/hyper-uri-format | index.js | encodeParams | function encodeParams(cache, API_URL, params) {
var obj = {}, v;
for (var k in params) {
if (!params.hasOwnProperty(k)) continue;
v = obj[k] = encode(cache, API_URL, params[k]);
if (!v) return;
}
return obj;
} | javascript | function encodeParams(cache, API_URL, params) {
var obj = {}, v;
for (var k in params) {
if (!params.hasOwnProperty(k)) continue;
v = obj[k] = encode(cache, API_URL, params[k]);
if (!v) return;
}
return obj;
} | [
"function",
"encodeParams",
"(",
"cache",
",",
"API_URL",
",",
"params",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
",",
"v",
";",
"for",
"(",
"var",
"k",
"in",
"params",
")",
"{",
"if",
"(",
"!",
"params",
".",
"hasOwnProperty",
"(",
"k",
")",
")",
"continue",
";",
"v",
"=",
"obj",
"[",
"k",
"]",
"=",
"encode",
"(",
"cache",
",",
"API_URL",
",",
"params",
"[",
"k",
"]",
")",
";",
"if",
"(",
"!",
"v",
")",
"return",
";",
"}",
"return",
"obj",
";",
"}"
] | Encode a set of params | [
"Encode",
"a",
"set",
"of",
"params"
] | e2d56f205604684bd5805ae6c460fe50f41c0dfe | https://github.com/hypergroup/hyper-uri-format/blob/e2d56f205604684bd5805ae6c460fe50f41c0dfe/index.js#L83-L91 |
51,683 | hypergroup/hyper-uri-format | index.js | decode | function decode(cache, API_URL, str) {
var cached = cache.get(str);
if (typeof cached !== 'undefined') return cached;
if (typeof str !== 'string') return null;
var decoded = base64.decode(str).toString().replace(/\0/g, '');
var out = validate(decoded) ?
{href: unpack(decoded, API_URL)} :
str;
// cache the decoded value since this ends up being pretty expensive
cache.set(str, out);
return out;
} | javascript | function decode(cache, API_URL, str) {
var cached = cache.get(str);
if (typeof cached !== 'undefined') return cached;
if (typeof str !== 'string') return null;
var decoded = base64.decode(str).toString().replace(/\0/g, '');
var out = validate(decoded) ?
{href: unpack(decoded, API_URL)} :
str;
// cache the decoded value since this ends up being pretty expensive
cache.set(str, out);
return out;
} | [
"function",
"decode",
"(",
"cache",
",",
"API_URL",
",",
"str",
")",
"{",
"var",
"cached",
"=",
"cache",
".",
"get",
"(",
"str",
")",
";",
"if",
"(",
"typeof",
"cached",
"!==",
"'undefined'",
")",
"return",
"cached",
";",
"if",
"(",
"typeof",
"str",
"!==",
"'string'",
")",
"return",
"null",
";",
"var",
"decoded",
"=",
"base64",
".",
"decode",
"(",
"str",
")",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"\\0",
"/",
"g",
",",
"''",
")",
";",
"var",
"out",
"=",
"validate",
"(",
"decoded",
")",
"?",
"{",
"href",
":",
"unpack",
"(",
"decoded",
",",
"API_URL",
")",
"}",
":",
"str",
";",
"// cache the decoded value since this ends up being pretty expensive",
"cache",
".",
"set",
"(",
"str",
",",
"out",
")",
";",
"return",
"out",
";",
"}"
] | Decode an encoded uri component | [
"Decode",
"an",
"encoded",
"uri",
"component"
] | e2d56f205604684bd5805ae6c460fe50f41c0dfe | https://github.com/hypergroup/hyper-uri-format/blob/e2d56f205604684bd5805ae6c460fe50f41c0dfe/index.js#L97-L112 |
51,684 | hypergroup/hyper-uri-format | index.js | decodeParams | function decodeParams(cache, API_URL, params) {
var obj = {}, v;
for (var k in params) {
if (!params.hasOwnProperty(k)) continue;
obj[k] = decode(cache, API_URL, params[k]);
}
return obj;
} | javascript | function decodeParams(cache, API_URL, params) {
var obj = {}, v;
for (var k in params) {
if (!params.hasOwnProperty(k)) continue;
obj[k] = decode(cache, API_URL, params[k]);
}
return obj;
} | [
"function",
"decodeParams",
"(",
"cache",
",",
"API_URL",
",",
"params",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
",",
"v",
";",
"for",
"(",
"var",
"k",
"in",
"params",
")",
"{",
"if",
"(",
"!",
"params",
".",
"hasOwnProperty",
"(",
"k",
")",
")",
"continue",
";",
"obj",
"[",
"k",
"]",
"=",
"decode",
"(",
"cache",
",",
"API_URL",
",",
"params",
"[",
"k",
"]",
")",
";",
"}",
"return",
"obj",
";",
"}"
] | Decode a set of params | [
"Decode",
"a",
"set",
"of",
"params"
] | e2d56f205604684bd5805ae6c460fe50f41c0dfe | https://github.com/hypergroup/hyper-uri-format/blob/e2d56f205604684bd5805ae6c460fe50f41c0dfe/index.js#L118-L125 |
51,685 | hypergroup/hyper-uri-format | index.js | pack | function pack(href, API_URL) {
var parts = url.parse(href);
var pn = API_URL.pathname || '/';
if (parts.host !== API_URL.host || parts.pathname.indexOf(pn) !== 0) return href;
if (pn === '/') pn = '';
return parts.pathname.replace(pn, '~') + (parts.search || '');
} | javascript | function pack(href, API_URL) {
var parts = url.parse(href);
var pn = API_URL.pathname || '/';
if (parts.host !== API_URL.host || parts.pathname.indexOf(pn) !== 0) return href;
if (pn === '/') pn = '';
return parts.pathname.replace(pn, '~') + (parts.search || '');
} | [
"function",
"pack",
"(",
"href",
",",
"API_URL",
")",
"{",
"var",
"parts",
"=",
"url",
".",
"parse",
"(",
"href",
")",
";",
"var",
"pn",
"=",
"API_URL",
".",
"pathname",
"||",
"'/'",
";",
"if",
"(",
"parts",
".",
"host",
"!==",
"API_URL",
".",
"host",
"||",
"parts",
".",
"pathname",
".",
"indexOf",
"(",
"pn",
")",
"!==",
"0",
")",
"return",
"href",
";",
"if",
"(",
"pn",
"===",
"'/'",
")",
"pn",
"=",
"''",
";",
"return",
"parts",
".",
"pathname",
".",
"replace",
"(",
"pn",
",",
"'~'",
")",
"+",
"(",
"parts",
".",
"search",
"||",
"''",
")",
";",
"}"
] | replace the API_URL with ~ | [
"replace",
"the",
"API_URL",
"with",
"~"
] | e2d56f205604684bd5805ae6c460fe50f41c0dfe | https://github.com/hypergroup/hyper-uri-format/blob/e2d56f205604684bd5805ae6c460fe50f41c0dfe/index.js#L142-L148 |
51,686 | vkiding/jud-vue-render | src/render/browser/bridge/receiver.js | callNativeComponent | function callNativeComponent (instanceId, ref, method, args, options) {
return processCall(instanceId, {
component: options.component,
ref,
method,
args
})
} | javascript | function callNativeComponent (instanceId, ref, method, args, options) {
return processCall(instanceId, {
component: options.component,
ref,
method,
args
})
} | [
"function",
"callNativeComponent",
"(",
"instanceId",
",",
"ref",
",",
"method",
",",
"args",
",",
"options",
")",
"{",
"return",
"processCall",
"(",
"instanceId",
",",
"{",
"component",
":",
"options",
".",
"component",
",",
"ref",
",",
"method",
",",
"args",
"}",
")",
"}"
] | sync call native component method. | [
"sync",
"call",
"native",
"component",
"method",
"."
] | 07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47 | https://github.com/vkiding/jud-vue-render/blob/07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47/src/render/browser/bridge/receiver.js#L9-L16 |
51,687 | vkiding/jud-vue-render | src/render/browser/bridge/receiver.js | callNativeModule | function callNativeModule (instanceId, module, method, args, options) {
return processCall(instanceId, { module, method, args })
} | javascript | function callNativeModule (instanceId, module, method, args, options) {
return processCall(instanceId, { module, method, args })
} | [
"function",
"callNativeModule",
"(",
"instanceId",
",",
"module",
",",
"method",
",",
"args",
",",
"options",
")",
"{",
"return",
"processCall",
"(",
"instanceId",
",",
"{",
"module",
",",
"method",
",",
"args",
"}",
")",
"}"
] | sync call native module api. | [
"sync",
"call",
"native",
"module",
"api",
"."
] | 07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47 | https://github.com/vkiding/jud-vue-render/blob/07d8ab08d0ef86cf2819e5f2bf1f4b06381f4d47/src/render/browser/bridge/receiver.js#L19-L21 |
51,688 | nanowizard/vec23 | src/Vec2.js | function(v) {
if(v instanceof Vec3){
return this.toVec3()._cross(v);
}
return new Vec3(0,0, this.x * v.y - this.y * v.x);
} | javascript | function(v) {
if(v instanceof Vec3){
return this.toVec3()._cross(v);
}
return new Vec3(0,0, this.x * v.y - this.y * v.x);
} | [
"function",
"(",
"v",
")",
"{",
"if",
"(",
"v",
"instanceof",
"Vec3",
")",
"{",
"return",
"this",
".",
"toVec3",
"(",
")",
".",
"_cross",
"(",
"v",
")",
";",
"}",
"return",
"new",
"Vec3",
"(",
"0",
",",
"0",
",",
"this",
".",
"x",
"*",
"v",
".",
"y",
"-",
"this",
".",
"y",
"*",
"v",
".",
"x",
")",
";",
"}"
] | Computes the cross product with a Vec2 or Vec3. Note that by definition the cross product of two 2D vectors is a 3D vector with x = y = 0
@memberof Vec2#
@param {Vec2|Vec3} v
@returns {Vec3} | [
"Computes",
"the",
"cross",
"product",
"with",
"a",
"Vec2",
"or",
"Vec3",
".",
"Note",
"that",
"by",
"definition",
"the",
"cross",
"product",
"of",
"two",
"2D",
"vectors",
"is",
"a",
"3D",
"vector",
"with",
"x",
"=",
"y",
"=",
"0"
] | e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364 | https://github.com/nanowizard/vec23/blob/e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364/src/Vec2.js#L239-L244 |
|
51,689 | nanowizard/vec23 | src/Vec2.js | function(m){
return new Vec2(
this.x*m[0][0]+this.y*m[0][1],
this.x*m[1][0]+this.y*m[1][1]
);
} | javascript | function(m){
return new Vec2(
this.x*m[0][0]+this.y*m[0][1],
this.x*m[1][0]+this.y*m[1][1]
);
} | [
"function",
"(",
"m",
")",
"{",
"return",
"new",
"Vec2",
"(",
"this",
".",
"x",
"*",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
"+",
"this",
".",
"y",
"*",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"this",
".",
"x",
"*",
"m",
"[",
"1",
"]",
"[",
"0",
"]",
"+",
"this",
".",
"y",
"*",
"m",
"[",
"1",
"]",
"[",
"1",
"]",
")",
";",
"}"
] | Creates a new vector converting the vector to a new coordinate frame at the same origin.
@memberof Vec2#
@param {Array} m - Coordinate system matrix of the form [[Xx,Xy],[Yx,Yy]]
@returns {Vec2} | [
"Creates",
"a",
"new",
"vector",
"converting",
"the",
"vector",
"to",
"a",
"new",
"coordinate",
"frame",
"at",
"the",
"same",
"origin",
"."
] | e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364 | https://github.com/nanowizard/vec23/blob/e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364/src/Vec2.js#L391-L396 |
|
51,690 | nanowizard/vec23 | src/Vec2.js | function(theta){
return new Vec2(
this.x*Math.cos(theta)-this.y*Math.sin(theta),
this.x*Math.sin(theta)+this.y*Math.cos(theta)
);
} | javascript | function(theta){
return new Vec2(
this.x*Math.cos(theta)-this.y*Math.sin(theta),
this.x*Math.sin(theta)+this.y*Math.cos(theta)
);
} | [
"function",
"(",
"theta",
")",
"{",
"return",
"new",
"Vec2",
"(",
"this",
".",
"x",
"*",
"Math",
".",
"cos",
"(",
"theta",
")",
"-",
"this",
".",
"y",
"*",
"Math",
".",
"sin",
"(",
"theta",
")",
",",
"this",
".",
"x",
"*",
"Math",
".",
"sin",
"(",
"theta",
")",
"+",
"this",
".",
"y",
"*",
"Math",
".",
"cos",
"(",
"theta",
")",
")",
";",
"}"
] | Rotates the vector in radians counterclockwise and returns a new vector.
@memberof Vec2#
@param {Number} theta - rotation angle (in radians)
@returns {Vec2} | [
"Rotates",
"the",
"vector",
"in",
"radians",
"counterclockwise",
"and",
"returns",
"a",
"new",
"vector",
"."
] | e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364 | https://github.com/nanowizard/vec23/blob/e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364/src/Vec2.js#L416-L421 |
|
51,691 | nanowizard/vec23 | src/Vec2.js | function(p){
this.x = Math.pow(this.x, p);
this.y = Math.pow(this.y, p);
return this;
} | javascript | function(p){
this.x = Math.pow(this.x, p);
this.y = Math.pow(this.y, p);
return this;
} | [
"function",
"(",
"p",
")",
"{",
"this",
".",
"x",
"=",
"Math",
".",
"pow",
"(",
"this",
".",
"x",
",",
"p",
")",
";",
"this",
".",
"y",
"=",
"Math",
".",
"pow",
"(",
"this",
".",
"y",
",",
"p",
")",
";",
"return",
"this",
";",
"}"
] | Raises each component of the vector to the power p.
@memberof Vec2#
@returns {Vec2} | [
"Raises",
"each",
"component",
"of",
"the",
"vector",
"to",
"the",
"power",
"p",
"."
] | e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364 | https://github.com/nanowizard/vec23/blob/e9ac7698d7cf96aeabd3d67cb48b8b1e5b6e8364/src/Vec2.js#L448-L452 |
|
51,692 | scijs/ndarray-select | select.js | permuteOrder | function permuteOrder(order) {
var norder = order.slice()
norder.splice(order.indexOf(0), 1)
norder.unshift(0)
return norder
} | javascript | function permuteOrder(order) {
var norder = order.slice()
norder.splice(order.indexOf(0), 1)
norder.unshift(0)
return norder
} | [
"function",
"permuteOrder",
"(",
"order",
")",
"{",
"var",
"norder",
"=",
"order",
".",
"slice",
"(",
")",
"norder",
".",
"splice",
"(",
"order",
".",
"indexOf",
"(",
"0",
")",
",",
"1",
")",
"norder",
".",
"unshift",
"(",
"0",
")",
"return",
"norder",
"}"
] | Create new order where index 0 is slowest index | [
"Create",
"new",
"order",
"where",
"index",
"0",
"is",
"slowest",
"index"
] | 1e6eacb5d8ef8f40e11638f9d494f20e5856c526 | https://github.com/scijs/ndarray-select/blob/1e6eacb5d8ef8f40e11638f9d494f20e5856c526/select.js#L40-L45 |
51,693 | perfectapi/node-paas-machine-proxy | bin/proxy.js | function() {
var config = {}
registry.listServices(config, function(err, result) {
if (err) return console.log(err);
main.poll(registry, result, function(err) {
if (err) return console.log(err);
});
})
} | javascript | function() {
var config = {}
registry.listServices(config, function(err, result) {
if (err) return console.log(err);
main.poll(registry, result, function(err) {
if (err) return console.log(err);
});
})
} | [
"function",
"(",
")",
"{",
"var",
"config",
"=",
"{",
"}",
"registry",
".",
"listServices",
"(",
"config",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"return",
"console",
".",
"log",
"(",
"err",
")",
";",
"main",
".",
"poll",
"(",
"registry",
",",
"result",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"console",
".",
"log",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
")",
"}"
] | now we have a reference to the registry running on the same machine | [
"now",
"we",
"have",
"a",
"reference",
"to",
"the",
"registry",
"running",
"on",
"the",
"same",
"machine"
] | ad286fe05ef11ac060a4303ce07b664fad8155bf | https://github.com/perfectapi/node-paas-machine-proxy/blob/ad286fe05ef11ac060a4303ce07b664fad8155bf/bin/proxy.js#L32-L41 |
|
51,694 | jeswin-unmaintained/isotropy-koa-context-in-browser | lib/context.js | function(){
return {
request: this.request.toJSON(),
response: this.response.toJSON(),
app: this.app.toJSON(),
originalUrl: this.originalUrl,
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>',
};
} | javascript | function(){
return {
request: this.request.toJSON(),
response: this.response.toJSON(),
app: this.app.toJSON(),
originalUrl: this.originalUrl,
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>',
};
} | [
"function",
"(",
")",
"{",
"return",
"{",
"request",
":",
"this",
".",
"request",
".",
"toJSON",
"(",
")",
",",
"response",
":",
"this",
".",
"response",
".",
"toJSON",
"(",
")",
",",
"app",
":",
"this",
".",
"app",
".",
"toJSON",
"(",
")",
",",
"originalUrl",
":",
"this",
".",
"originalUrl",
",",
"req",
":",
"'<original node req>'",
",",
"res",
":",
"'<original node res>'",
",",
"socket",
":",
"'<original node socket>'",
",",
"}",
";",
"}"
] | Return JSON representation.
Here we explicitly invoke .toJSON() on each
object, as iteration will otherwise fail due
to the getters and cause utilities such as
clone() to fail.
@return {Object}
@api public | [
"Return",
"JSON",
"representation",
"."
] | 033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f | https://github.com/jeswin-unmaintained/isotropy-koa-context-in-browser/blob/033a3ac0fd65ba6ac2b4ce715b3da54f873eed6f/lib/context.js#L40-L50 |
|
51,695 | K15t/webpack-build | webpack-build.js | mergeDefaultConfig | function mergeDefaultConfig(opts) {
let devModeEnabled = isDevelopMode();
let debugModeEnabled = isDebugMode();
console.log('------------------------------------------------------------------------------------');
console.log(`Executing build for ` + (devModeEnabled ? ENV_DEVELOPMENT : ENV_PROD));
console.log('------------------------------------------------------------------------------------');
let config = {
metadata: {
ENV: devModeEnabled ? ENV_DEVELOPMENT : ENV_PROD
},
devtool: 'source-map',
debug: debugModeEnabled,
entry: {},
output: {
filename: devModeEnabled ? '[name].bundle.js' : '[name].[chunkhash].bundle.js',
sourceMapFilename: devModeEnabled ? '[name].bundle.map' : '[name].[chunkhash].bundle.map',
chunkFilename: devModeEnabled ? '[id].chunk.js' : '[id].[chunkhash].chunk.js'
},
resolve: {
cache: false,
extensions: ['', '.ts', '.tsx', '.js', '.json', '.css', '.html']
},
module: {
preLoaders: [],
loaders: []
},
plugins: [],
// we need this due to problems with es6-shim
node: {
global: 'window',
progress: false,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
if (debugModeEnabled) {
console.log(merge(config, opts));
console.log('------------------------------------------------------------------------------------');
}
return merge(config, opts);
} | javascript | function mergeDefaultConfig(opts) {
let devModeEnabled = isDevelopMode();
let debugModeEnabled = isDebugMode();
console.log('------------------------------------------------------------------------------------');
console.log(`Executing build for ` + (devModeEnabled ? ENV_DEVELOPMENT : ENV_PROD));
console.log('------------------------------------------------------------------------------------');
let config = {
metadata: {
ENV: devModeEnabled ? ENV_DEVELOPMENT : ENV_PROD
},
devtool: 'source-map',
debug: debugModeEnabled,
entry: {},
output: {
filename: devModeEnabled ? '[name].bundle.js' : '[name].[chunkhash].bundle.js',
sourceMapFilename: devModeEnabled ? '[name].bundle.map' : '[name].[chunkhash].bundle.map',
chunkFilename: devModeEnabled ? '[id].chunk.js' : '[id].[chunkhash].chunk.js'
},
resolve: {
cache: false,
extensions: ['', '.ts', '.tsx', '.js', '.json', '.css', '.html']
},
module: {
preLoaders: [],
loaders: []
},
plugins: [],
// we need this due to problems with es6-shim
node: {
global: 'window',
progress: false,
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
};
if (debugModeEnabled) {
console.log(merge(config, opts));
console.log('------------------------------------------------------------------------------------');
}
return merge(config, opts);
} | [
"function",
"mergeDefaultConfig",
"(",
"opts",
")",
"{",
"let",
"devModeEnabled",
"=",
"isDevelopMode",
"(",
")",
";",
"let",
"debugModeEnabled",
"=",
"isDebugMode",
"(",
")",
";",
"console",
".",
"log",
"(",
"'------------------------------------------------------------------------------------'",
")",
";",
"console",
".",
"log",
"(",
"`",
"`",
"+",
"(",
"devModeEnabled",
"?",
"ENV_DEVELOPMENT",
":",
"ENV_PROD",
")",
")",
";",
"console",
".",
"log",
"(",
"'------------------------------------------------------------------------------------'",
")",
";",
"let",
"config",
"=",
"{",
"metadata",
":",
"{",
"ENV",
":",
"devModeEnabled",
"?",
"ENV_DEVELOPMENT",
":",
"ENV_PROD",
"}",
",",
"devtool",
":",
"'source-map'",
",",
"debug",
":",
"debugModeEnabled",
",",
"entry",
":",
"{",
"}",
",",
"output",
":",
"{",
"filename",
":",
"devModeEnabled",
"?",
"'[name].bundle.js'",
":",
"'[name].[chunkhash].bundle.js'",
",",
"sourceMapFilename",
":",
"devModeEnabled",
"?",
"'[name].bundle.map'",
":",
"'[name].[chunkhash].bundle.map'",
",",
"chunkFilename",
":",
"devModeEnabled",
"?",
"'[id].chunk.js'",
":",
"'[id].[chunkhash].chunk.js'",
"}",
",",
"resolve",
":",
"{",
"cache",
":",
"false",
",",
"extensions",
":",
"[",
"''",
",",
"'.ts'",
",",
"'.tsx'",
",",
"'.js'",
",",
"'.json'",
",",
"'.css'",
",",
"'.html'",
"]",
"}",
",",
"module",
":",
"{",
"preLoaders",
":",
"[",
"]",
",",
"loaders",
":",
"[",
"]",
"}",
",",
"plugins",
":",
"[",
"]",
",",
"// we need this due to problems with es6-shim",
"node",
":",
"{",
"global",
":",
"'window'",
",",
"progress",
":",
"false",
",",
"crypto",
":",
"'empty'",
",",
"module",
":",
"false",
",",
"clearImmediate",
":",
"false",
",",
"setImmediate",
":",
"false",
"}",
"}",
";",
"if",
"(",
"debugModeEnabled",
")",
"{",
"console",
".",
"log",
"(",
"merge",
"(",
"config",
",",
"opts",
")",
")",
";",
"console",
".",
"log",
"(",
"'------------------------------------------------------------------------------------'",
")",
";",
"}",
"return",
"merge",
"(",
"config",
",",
"opts",
")",
";",
"}"
] | Module defining the common build configuration for webpack-based projects.
@param opts Customized options which allows to override the defaults configuration. | [
"Module",
"defining",
"the",
"common",
"build",
"configuration",
"for",
"webpack",
"-",
"based",
"projects",
"."
] | d5921b8c5abbc92159aabd6379c7c2b1a9d7fe27 | https://github.com/K15t/webpack-build/blob/d5921b8c5abbc92159aabd6379c7c2b1a9d7fe27/webpack-build.js#L23-L77 |
51,696 | Lindurion/closure-pro-build | lib/file-matcher.js | resolveAnyGlobPatternsAsync | function resolveAnyGlobPatternsAsync(filesAndPatterns, rootSrcDir) {
return resolveGlobsAsync(filesAndPatterns, rootSrcDir)
.then(function(resolvedFiles) {
var allFiles = insertResolvedFiles(filesAndPatterns, resolvedFiles);
return allFiles.map(convertBackslashes);
});
} | javascript | function resolveAnyGlobPatternsAsync(filesAndPatterns, rootSrcDir) {
return resolveGlobsAsync(filesAndPatterns, rootSrcDir)
.then(function(resolvedFiles) {
var allFiles = insertResolvedFiles(filesAndPatterns, resolvedFiles);
return allFiles.map(convertBackslashes);
});
} | [
"function",
"resolveAnyGlobPatternsAsync",
"(",
"filesAndPatterns",
",",
"rootSrcDir",
")",
"{",
"return",
"resolveGlobsAsync",
"(",
"filesAndPatterns",
",",
"rootSrcDir",
")",
".",
"then",
"(",
"function",
"(",
"resolvedFiles",
")",
"{",
"var",
"allFiles",
"=",
"insertResolvedFiles",
"(",
"filesAndPatterns",
",",
"resolvedFiles",
")",
";",
"return",
"allFiles",
".",
"map",
"(",
"convertBackslashes",
")",
";",
"}",
")",
";",
"}"
] | Uses glob library to resolve any file patterns in input list. Removes any
duplicate file paths and converts any path backslashes into forward slashes.
@param {!Array.<string>} filesAndPatterns List of files and file patterns,
e.g. ['my/single/file.js', 'dir/of/*.js'].
@param {string} rootSrcDir Root source directory that filesAndPatterns are
relative to.
@return {!Promise.<!Array.<string>>} Async result that will be called with
the list of resolved filenames on success. | [
"Uses",
"glob",
"library",
"to",
"resolve",
"any",
"file",
"patterns",
"in",
"input",
"list",
".",
"Removes",
"any",
"duplicate",
"file",
"paths",
"and",
"converts",
"any",
"path",
"backslashes",
"into",
"forward",
"slashes",
"."
] | c279d0fcc3a65969d2fe965f55e627b074792f1a | https://github.com/Lindurion/closure-pro-build/blob/c279d0fcc3a65969d2fe965f55e627b074792f1a/lib/file-matcher.js#L36-L42 |
51,697 | Lindurion/closure-pro-build | lib/file-matcher.js | resolveGlobsAsync | function resolveGlobsAsync(filesAndPatterns, rootSrcDir) {
var options = {cwd: rootSrcDir};
var tasks = {};
filesAndPatterns.forEach(function(fileOrPattern) {
if (isGlobPattern(fileOrPattern)) {
tasks[fileOrPattern] =
underscore.partial(resolveGlobAsync, fileOrPattern, options);
}
});
// TODO: Add kew.nfcall() and use that instead.
// https://github.com/Obvious/kew/pull/21
var deferred = kew.defer();
async.parallel(tasks, deferred.makeNodeResolver());
return deferred.promise;
} | javascript | function resolveGlobsAsync(filesAndPatterns, rootSrcDir) {
var options = {cwd: rootSrcDir};
var tasks = {};
filesAndPatterns.forEach(function(fileOrPattern) {
if (isGlobPattern(fileOrPattern)) {
tasks[fileOrPattern] =
underscore.partial(resolveGlobAsync, fileOrPattern, options);
}
});
// TODO: Add kew.nfcall() and use that instead.
// https://github.com/Obvious/kew/pull/21
var deferred = kew.defer();
async.parallel(tasks, deferred.makeNodeResolver());
return deferred.promise;
} | [
"function",
"resolveGlobsAsync",
"(",
"filesAndPatterns",
",",
"rootSrcDir",
")",
"{",
"var",
"options",
"=",
"{",
"cwd",
":",
"rootSrcDir",
"}",
";",
"var",
"tasks",
"=",
"{",
"}",
";",
"filesAndPatterns",
".",
"forEach",
"(",
"function",
"(",
"fileOrPattern",
")",
"{",
"if",
"(",
"isGlobPattern",
"(",
"fileOrPattern",
")",
")",
"{",
"tasks",
"[",
"fileOrPattern",
"]",
"=",
"underscore",
".",
"partial",
"(",
"resolveGlobAsync",
",",
"fileOrPattern",
",",
"options",
")",
";",
"}",
"}",
")",
";",
"// TODO: Add kew.nfcall() and use that instead.",
"// https://github.com/Obvious/kew/pull/21",
"var",
"deferred",
"=",
"kew",
".",
"defer",
"(",
")",
";",
"async",
".",
"parallel",
"(",
"tasks",
",",
"deferred",
".",
"makeNodeResolver",
"(",
")",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Does the glob resolution for all glob file patterns in input.
@param {!Array.<string>} filesAndPatterns
@param {string} rootSrcDir
@return {!Promise.<!Object.<string, !Array.<string>>>} A future map from
file pattern to list of resolved files (on success). | [
"Does",
"the",
"glob",
"resolution",
"for",
"all",
"glob",
"file",
"patterns",
"in",
"input",
"."
] | c279d0fcc3a65969d2fe965f55e627b074792f1a | https://github.com/Lindurion/closure-pro-build/blob/c279d0fcc3a65969d2fe965f55e627b074792f1a/lib/file-matcher.js#L52-L68 |
51,698 | JosePedroDias/level1 | libClient/level1_http.js | function() {
if (xhr.readyState === 4 && xhr.status === 200) {
return cb(null, JSON.parse(xhr.response));
}
cb('error requesting ' + uri);
} | javascript | function() {
if (xhr.readyState === 4 && xhr.status === 200) {
return cb(null, JSON.parse(xhr.response));
}
cb('error requesting ' + uri);
} | [
"function",
"(",
")",
"{",
"if",
"(",
"xhr",
".",
"readyState",
"===",
"4",
"&&",
"xhr",
".",
"status",
"===",
"200",
")",
"{",
"return",
"cb",
"(",
"null",
",",
"JSON",
".",
"parse",
"(",
"xhr",
".",
"response",
")",
")",
";",
"}",
"cb",
"(",
"'error requesting '",
"+",
"uri",
")",
";",
"}"
] | setup callback to handle result | [
"setup",
"callback",
"to",
"handle",
"result"
] | cabd26c85e4c4e3131863c1bb1eaac8e17d1ec22 | https://github.com/JosePedroDias/level1/blob/cabd26c85e4c4e3131863c1bb1eaac8e17d1ec22/libClient/level1_http.js#L68-L73 |
|
51,699 | espadrine/travel-scrapper | uk.js | extractTravelPlan | function extractTravelPlan(data) {
let tickets = data.fullJourneys[0].cheapestTickets
if (!tickets || tickets.length === 0) { return [] }
let secondClass = tickets[0].tickets
let firstClass = tickets[1].tickets
let journeys = data.fullJourneys[0].journeys
let date = data.fullJourneys[0].date // "25 Sep 2016"
let journeyFromId = []
journeys.forEach(journey => journeyFromId[journey.id] = journey)
let plans = []
let getPlan = (from, to, departure, arrival) => {
return plans.find(plan =>
(plan.legs[0].from === from) && (plan.legs[0].to === to) &&
(plan.legs[0].departure === departure) && (plan.legs[0].arrival === arrival))
}
let mkticket = (ticket, travelClass) => {
let journey = journeyFromId[ticket.journeyId]
let price = ticket.price // "81.40"
if (!journey || !price) { return }
let origin = station.name(journey.departureName)
let destination = station.name(journey.arrivalName)
let from = origin ? origin.id : journey.departureName
let to = destination ? destination.id : journey.arrivalName
let departure = String(parseTime(date, journey.departureTime))
let arrival = String(parseTime(date, journey.arrivalTime))
let plan = getPlan(from, to, departure, arrival)
if (plan === undefined) {
plan = {
fares: [],
legs: [{from, to, departure, arrival}],
}
plans.push(plan)
}
plan.fares.push({
class: travelClass,
flexibility: 1,
price: [{ cents: parsePrice(ticket.price), currency: 'GBP' }],
})
}
secondClass.map(ticket => mkticket(ticket, 2))
firstClass.map(ticket => mkticket(ticket, 1))
return plans
} | javascript | function extractTravelPlan(data) {
let tickets = data.fullJourneys[0].cheapestTickets
if (!tickets || tickets.length === 0) { return [] }
let secondClass = tickets[0].tickets
let firstClass = tickets[1].tickets
let journeys = data.fullJourneys[0].journeys
let date = data.fullJourneys[0].date // "25 Sep 2016"
let journeyFromId = []
journeys.forEach(journey => journeyFromId[journey.id] = journey)
let plans = []
let getPlan = (from, to, departure, arrival) => {
return plans.find(plan =>
(plan.legs[0].from === from) && (plan.legs[0].to === to) &&
(plan.legs[0].departure === departure) && (plan.legs[0].arrival === arrival))
}
let mkticket = (ticket, travelClass) => {
let journey = journeyFromId[ticket.journeyId]
let price = ticket.price // "81.40"
if (!journey || !price) { return }
let origin = station.name(journey.departureName)
let destination = station.name(journey.arrivalName)
let from = origin ? origin.id : journey.departureName
let to = destination ? destination.id : journey.arrivalName
let departure = String(parseTime(date, journey.departureTime))
let arrival = String(parseTime(date, journey.arrivalTime))
let plan = getPlan(from, to, departure, arrival)
if (plan === undefined) {
plan = {
fares: [],
legs: [{from, to, departure, arrival}],
}
plans.push(plan)
}
plan.fares.push({
class: travelClass,
flexibility: 1,
price: [{ cents: parsePrice(ticket.price), currency: 'GBP' }],
})
}
secondClass.map(ticket => mkticket(ticket, 2))
firstClass.map(ticket => mkticket(ticket, 1))
return plans
} | [
"function",
"extractTravelPlan",
"(",
"data",
")",
"{",
"let",
"tickets",
"=",
"data",
".",
"fullJourneys",
"[",
"0",
"]",
".",
"cheapestTickets",
"if",
"(",
"!",
"tickets",
"||",
"tickets",
".",
"length",
"===",
"0",
")",
"{",
"return",
"[",
"]",
"}",
"let",
"secondClass",
"=",
"tickets",
"[",
"0",
"]",
".",
"tickets",
"let",
"firstClass",
"=",
"tickets",
"[",
"1",
"]",
".",
"tickets",
"let",
"journeys",
"=",
"data",
".",
"fullJourneys",
"[",
"0",
"]",
".",
"journeys",
"let",
"date",
"=",
"data",
".",
"fullJourneys",
"[",
"0",
"]",
".",
"date",
"// \"25 Sep 2016\"",
"let",
"journeyFromId",
"=",
"[",
"]",
"journeys",
".",
"forEach",
"(",
"journey",
"=>",
"journeyFromId",
"[",
"journey",
".",
"id",
"]",
"=",
"journey",
")",
"let",
"plans",
"=",
"[",
"]",
"let",
"getPlan",
"=",
"(",
"from",
",",
"to",
",",
"departure",
",",
"arrival",
")",
"=>",
"{",
"return",
"plans",
".",
"find",
"(",
"plan",
"=>",
"(",
"plan",
".",
"legs",
"[",
"0",
"]",
".",
"from",
"===",
"from",
")",
"&&",
"(",
"plan",
".",
"legs",
"[",
"0",
"]",
".",
"to",
"===",
"to",
")",
"&&",
"(",
"plan",
".",
"legs",
"[",
"0",
"]",
".",
"departure",
"===",
"departure",
")",
"&&",
"(",
"plan",
".",
"legs",
"[",
"0",
"]",
".",
"arrival",
"===",
"arrival",
")",
")",
"}",
"let",
"mkticket",
"=",
"(",
"ticket",
",",
"travelClass",
")",
"=>",
"{",
"let",
"journey",
"=",
"journeyFromId",
"[",
"ticket",
".",
"journeyId",
"]",
"let",
"price",
"=",
"ticket",
".",
"price",
"// \"81.40\"",
"if",
"(",
"!",
"journey",
"||",
"!",
"price",
")",
"{",
"return",
"}",
"let",
"origin",
"=",
"station",
".",
"name",
"(",
"journey",
".",
"departureName",
")",
"let",
"destination",
"=",
"station",
".",
"name",
"(",
"journey",
".",
"arrivalName",
")",
"let",
"from",
"=",
"origin",
"?",
"origin",
".",
"id",
":",
"journey",
".",
"departureName",
"let",
"to",
"=",
"destination",
"?",
"destination",
".",
"id",
":",
"journey",
".",
"arrivalName",
"let",
"departure",
"=",
"String",
"(",
"parseTime",
"(",
"date",
",",
"journey",
".",
"departureTime",
")",
")",
"let",
"arrival",
"=",
"String",
"(",
"parseTime",
"(",
"date",
",",
"journey",
".",
"arrivalTime",
")",
")",
"let",
"plan",
"=",
"getPlan",
"(",
"from",
",",
"to",
",",
"departure",
",",
"arrival",
")",
"if",
"(",
"plan",
"===",
"undefined",
")",
"{",
"plan",
"=",
"{",
"fares",
":",
"[",
"]",
",",
"legs",
":",
"[",
"{",
"from",
",",
"to",
",",
"departure",
",",
"arrival",
"}",
"]",
",",
"}",
"plans",
".",
"push",
"(",
"plan",
")",
"}",
"plan",
".",
"fares",
".",
"push",
"(",
"{",
"class",
":",
"travelClass",
",",
"flexibility",
":",
"1",
",",
"price",
":",
"[",
"{",
"cents",
":",
"parsePrice",
"(",
"ticket",
".",
"price",
")",
",",
"currency",
":",
"'GBP'",
"}",
"]",
",",
"}",
")",
"}",
"secondClass",
".",
"map",
"(",
"ticket",
"=>",
"mkticket",
"(",
"ticket",
",",
"2",
")",
")",
"firstClass",
".",
"map",
"(",
"ticket",
"=>",
"mkticket",
"(",
"ticket",
",",
"1",
")",
")",
"return",
"plans",
"}"
] | Get raw scrapping data Return data conforming to the common travel plan format. | [
"Get",
"raw",
"scrapping",
"data",
"Return",
"data",
"conforming",
"to",
"the",
"common",
"travel",
"plan",
"format",
"."
] | 5ed137e967a8a2de67f988922ec66222f464ea96 | https://github.com/espadrine/travel-scrapper/blob/5ed137e967a8a2de67f988922ec66222f464ea96/uk.js#L81-L128 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.