repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
biancojs/events | index.next.js | manageEvents | function manageEvents(els, evList, cb, method, options) {
els = domToArray(els)
split(evList).forEach((e) => {
els.forEach(el => el[method](e, cb, options || false))
})
} | javascript | function manageEvents(els, evList, cb, method, options) {
els = domToArray(els)
split(evList).forEach((e) => {
els.forEach(el => el[method](e, cb, options || false))
})
} | [
"function",
"manageEvents",
"(",
"els",
",",
"evList",
",",
"cb",
",",
"method",
",",
"options",
")",
"{",
"els",
"=",
"domToArray",
"(",
"els",
")",
"split",
"(",
"evList",
")",
".",
"forEach",
"(",
"(",
"e",
")",
"=>",
"{",
"els",
".",
"forEach",
"(",
"el",
"=>",
"el",
"[",
"method",
"]",
"(",
"e",
",",
"cb",
",",
"options",
"||",
"false",
")",
")",
"}",
")",
"}"
]
| Set a listener for all the events received separated by spaces
@param { HTMLElement|NodeList|Array } els - DOM node/s where the listeners will be bound
@param { string } evList - list of events we want to bind or unbind space separated
@param { Function } cb - listeners callback
@param { string } method - either 'addEventListener' or 'removeEventListener'
@param { Object } options - event options (capture, once and passive)
@returns { undefined }
@private | [
"Set",
"a",
"listener",
"for",
"all",
"the",
"events",
"received",
"separated",
"by",
"spaces"
]
| 5f7f23932676b4349102dc41fff565a727cd97dc | https://github.com/biancojs/events/blob/5f7f23932676b4349102dc41fff565a727cd97dc/index.next.js#L21-L27 | train |
seattleacademy/mcp9808 | index.js | WriteData | function WriteData(Register, ByteArray, Callback)
{
i2cdevice.writeBytes(Register, ByteArray, function(err)
{
Callback(err);
});
} | javascript | function WriteData(Register, ByteArray, Callback)
{
i2cdevice.writeBytes(Register, ByteArray, function(err)
{
Callback(err);
});
} | [
"function",
"WriteData",
"(",
"Register",
",",
"ByteArray",
",",
"Callback",
")",
"{",
"i2cdevice",
".",
"writeBytes",
"(",
"Register",
",",
"ByteArray",
",",
"function",
"(",
"err",
")",
"{",
"Callback",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
]
| sends the LSB first. The device wants the MSB first. | [
"sends",
"the",
"LSB",
"first",
".",
"The",
"device",
"wants",
"the",
"MSB",
"first",
"."
]
| 211c07158e0585dfc3c2149b1e5e93d105d89723 | https://github.com/seattleacademy/mcp9808/blob/211c07158e0585dfc3c2149b1e5e93d105d89723/index.js#L69-L75 | train |
mangojuicejs/mangojuice | packages/mangojuice-lazy/src/createLazyBlock.js | createLazyBlock | function createLazyBlock(
{ resolver, chunkName, initModel, loadingView, messages } = {}
) {
const resolveState = { resolver: null, block: null, msgs: [], chunkName };
resolveState.resolver = createBlockResolver(resolver, resolveState);
const lazyLogic = createLazyLogic(resolveState, initModel);
const lazyView = createLazyView(resolveState, loadingView);
const lazyMessages = createLazyMessages(resolveState, messages);
return {
resolver: resolveState.resolver,
Logic: lazyLogic,
View: lazyView,
Messages: lazyMessages
};
} | javascript | function createLazyBlock(
{ resolver, chunkName, initModel, loadingView, messages } = {}
) {
const resolveState = { resolver: null, block: null, msgs: [], chunkName };
resolveState.resolver = createBlockResolver(resolver, resolveState);
const lazyLogic = createLazyLogic(resolveState, initModel);
const lazyView = createLazyView(resolveState, loadingView);
const lazyMessages = createLazyMessages(resolveState, messages);
return {
resolver: resolveState.resolver,
Logic: lazyLogic,
View: lazyView,
Messages: lazyMessages
};
} | [
"function",
"createLazyBlock",
"(",
"{",
"resolver",
",",
"chunkName",
",",
"initModel",
",",
"loadingView",
",",
"messages",
"}",
"=",
"{",
"}",
")",
"{",
"const",
"resolveState",
"=",
"{",
"resolver",
":",
"null",
",",
"block",
":",
"null",
",",
"msgs",
":",
"[",
"]",
",",
"chunkName",
"}",
";",
"resolveState",
".",
"resolver",
"=",
"createBlockResolver",
"(",
"resolver",
",",
"resolveState",
")",
";",
"const",
"lazyLogic",
"=",
"createLazyLogic",
"(",
"resolveState",
",",
"initModel",
")",
";",
"const",
"lazyView",
"=",
"createLazyView",
"(",
"resolveState",
",",
"loadingView",
")",
";",
"const",
"lazyMessages",
"=",
"createLazyMessages",
"(",
"resolveState",
",",
"messages",
")",
";",
"return",
"{",
"resolver",
":",
"resolveState",
".",
"resolver",
",",
"Logic",
":",
"lazyLogic",
",",
"View",
":",
"lazyView",
",",
"Messages",
":",
"lazyMessages",
"}",
";",
"}"
]
| Creates a Block which works as a proxy for some other block,
which will be returned by `resolver` function provided in the
options object. `resolver` can also return a promise which should
resolve and actual block.
@param {function} options.resolver
@param {string} options.chunkName
@param {string} options.initModel
@param {function} options.loadingView
@param {Object} options.lazyCommands
@return {Object} | [
"Creates",
"a",
"Block",
"which",
"works",
"as",
"a",
"proxy",
"for",
"some",
"other",
"block",
"which",
"will",
"be",
"returned",
"by",
"resolver",
"function",
"provided",
"in",
"the",
"options",
"object",
".",
"resolver",
"can",
"also",
"return",
"a",
"promise",
"which",
"should",
"resolve",
"and",
"actual",
"block",
"."
]
| 15bda5648462c171cc8e2dd0f8f15696655ce11a | https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-lazy/src/createLazyBlock.js#L129-L144 | train |
landau/fscache | lib/cache.js | function(arg) {
var hash = crypto.createHash('md5')
.update(JSON.stringify(arg))
.digest('hex');
return path.join(this.dir, hash);
} | javascript | function(arg) {
var hash = crypto.createHash('md5')
.update(JSON.stringify(arg))
.digest('hex');
return path.join(this.dir, hash);
} | [
"function",
"(",
"arg",
")",
"{",
"var",
"hash",
"=",
"crypto",
".",
"createHash",
"(",
"'md5'",
")",
".",
"update",
"(",
"JSON",
".",
"stringify",
"(",
"arg",
")",
")",
".",
"digest",
"(",
"'hex'",
")",
";",
"return",
"path",
".",
"join",
"(",
"this",
".",
"dir",
",",
"hash",
")",
";",
"}"
]
| Creates a md5 hash based on the stringified arg | [
"Creates",
"a",
"md5",
"hash",
"based",
"on",
"the",
"stringified",
"arg"
]
| 18d0127c06c4da6b2ac03701f8e136ee19ac722c | https://github.com/landau/fscache/blob/18d0127c06c4da6b2ac03701f8e136ee19ac722c/lib/cache.js#L24-L29 | train |
|
gusnips/koa-error-ejs | index.js | error | function error(opts) {
//define your custom views
opts = opts || {};
//custom views
if(!opts.custom)
opts.custom={};
// better to disable layout in not explicity set, in case there are error in it
if(!opts.layout)
opts.layout= false;
// @todo to be easier to install, should render from this module path
if(!opts.view)
opts.view= 'error';
return function *error(next){
var env= this.app.env;
try {
yield next;
if (this.response.status==404 && !this.response.body)
this.throw(404);
} catch (err) {
this.status = err.status || 500;
// application
this.app.emit('error', err, this);
// accepted types
switch (this.accepts('html', 'text', 'json')) {
case 'text':
if (env==='development')
this.body= err.message
else if (err.expose)
this.body= err.message
else
this.body= http.STATUS_CODES[this.status];
break;
case 'json':
if (env==='development')
this.body= {error: err.message}
else if (err.expose)
this.body= {error: err.message}
else
this.body= {error: http.STATUS_CODES[this.status]}
break;
case 'html':
var view= typeof opts.custom[this.status]!=='undefined' ? opts.custom[this.status] : opts.view;
var options= {
layout: opts.layout,
env: env,
ctx: this,
request: this.request,
response: this.response,
error: err.message,
stack: err.stack,
status: this.status,
code: err.code
};
//in case of any error view error
try{
yield this.render(view, options);
}catch(e){
this.body= '<h1>'+e.code+'</h1><h3>'+e.message+'</h3><pre><code>'+e.stack+'</code></pre>'
}
break;
}
}
}
} | javascript | function error(opts) {
//define your custom views
opts = opts || {};
//custom views
if(!opts.custom)
opts.custom={};
// better to disable layout in not explicity set, in case there are error in it
if(!opts.layout)
opts.layout= false;
// @todo to be easier to install, should render from this module path
if(!opts.view)
opts.view= 'error';
return function *error(next){
var env= this.app.env;
try {
yield next;
if (this.response.status==404 && !this.response.body)
this.throw(404);
} catch (err) {
this.status = err.status || 500;
// application
this.app.emit('error', err, this);
// accepted types
switch (this.accepts('html', 'text', 'json')) {
case 'text':
if (env==='development')
this.body= err.message
else if (err.expose)
this.body= err.message
else
this.body= http.STATUS_CODES[this.status];
break;
case 'json':
if (env==='development')
this.body= {error: err.message}
else if (err.expose)
this.body= {error: err.message}
else
this.body= {error: http.STATUS_CODES[this.status]}
break;
case 'html':
var view= typeof opts.custom[this.status]!=='undefined' ? opts.custom[this.status] : opts.view;
var options= {
layout: opts.layout,
env: env,
ctx: this,
request: this.request,
response: this.response,
error: err.message,
stack: err.stack,
status: this.status,
code: err.code
};
//in case of any error view error
try{
yield this.render(view, options);
}catch(e){
this.body= '<h1>'+e.code+'</h1><h3>'+e.message+'</h3><pre><code>'+e.stack+'</code></pre>'
}
break;
}
}
}
} | [
"function",
"error",
"(",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"custom",
")",
"opts",
".",
"custom",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"opts",
".",
"layout",
")",
"opts",
".",
"layout",
"=",
"false",
";",
"if",
"(",
"!",
"opts",
".",
"view",
")",
"opts",
".",
"view",
"=",
"'error'",
";",
"return",
"function",
"*",
"error",
"(",
"next",
")",
"{",
"var",
"env",
"=",
"this",
".",
"app",
".",
"env",
";",
"try",
"{",
"yield",
"next",
";",
"if",
"(",
"this",
".",
"response",
".",
"status",
"==",
"404",
"&&",
"!",
"this",
".",
"response",
".",
"body",
")",
"this",
".",
"throw",
"(",
"404",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"this",
".",
"status",
"=",
"err",
".",
"status",
"||",
"500",
";",
"this",
".",
"app",
".",
"emit",
"(",
"'error'",
",",
"err",
",",
"this",
")",
";",
"switch",
"(",
"this",
".",
"accepts",
"(",
"'html'",
",",
"'text'",
",",
"'json'",
")",
")",
"{",
"case",
"'text'",
":",
"if",
"(",
"env",
"===",
"'development'",
")",
"this",
".",
"body",
"=",
"err",
".",
"message",
"else",
"if",
"(",
"err",
".",
"expose",
")",
"this",
".",
"body",
"=",
"err",
".",
"message",
"else",
"this",
".",
"body",
"=",
"http",
".",
"STATUS_CODES",
"[",
"this",
".",
"status",
"]",
";",
"break",
";",
"case",
"'json'",
":",
"if",
"(",
"env",
"===",
"'development'",
")",
"this",
".",
"body",
"=",
"{",
"error",
":",
"err",
".",
"message",
"}",
"else",
"if",
"(",
"err",
".",
"expose",
")",
"this",
".",
"body",
"=",
"{",
"error",
":",
"err",
".",
"message",
"}",
"else",
"this",
".",
"body",
"=",
"{",
"error",
":",
"http",
".",
"STATUS_CODES",
"[",
"this",
".",
"status",
"]",
"}",
"break",
";",
"case",
"'html'",
":",
"var",
"view",
"=",
"typeof",
"opts",
".",
"custom",
"[",
"this",
".",
"status",
"]",
"!==",
"'undefined'",
"?",
"opts",
".",
"custom",
"[",
"this",
".",
"status",
"]",
":",
"opts",
".",
"view",
";",
"var",
"options",
"=",
"{",
"layout",
":",
"opts",
".",
"layout",
",",
"env",
":",
"env",
",",
"ctx",
":",
"this",
",",
"request",
":",
"this",
".",
"request",
",",
"response",
":",
"this",
".",
"response",
",",
"error",
":",
"err",
".",
"message",
",",
"stack",
":",
"err",
".",
"stack",
",",
"status",
":",
"this",
".",
"status",
",",
"code",
":",
"err",
".",
"code",
"}",
";",
"try",
"{",
"yield",
"this",
".",
"render",
"(",
"view",
",",
"options",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"this",
".",
"body",
"=",
"'<h1>'",
"+",
"e",
".",
"code",
"+",
"'</h1><h3>'",
"+",
"e",
".",
"message",
"+",
"'</h3><pre><code>'",
"+",
"e",
".",
"stack",
"+",
"'</code></pre>'",
"}",
"break",
";",
"}",
"}",
"}",
"}"
]
| Error middleware for EJS.
@param {Object} opts
`custom` Object views for a status, for example:
{
404: 'error/not-found'
}
`view` String default error view. Defaults to {view.root}/error
`layout` String|Boolean layout to use on error view, or false if none. False by default. | [
"Error",
"middleware",
"for",
"EJS",
"."
]
| 177ff9d13f0d95151961106f43d97ade0fa4e0aa | https://github.com/gusnips/koa-error-ejs/blob/177ff9d13f0d95151961106f43d97ade0fa4e0aa/index.js#L24-L92 | train |
chrisJohn404/ljswitchboard-ljm_device_curator | lib/device_curator.js | function(addresses) {
var defered = q.defer();
var currentStep = 0;
var numSteps = addresses.length;
var results = [];
var handleReadSuccess = function(res) {
results.push({'address': addresses[currentStep], 'isErr': false, 'data': res});
if(currentStep < numSteps) {
currentStep += 1;
performRead();
} else {
defered.resolve(results);
}
};
var handleReadError = function(err) {
results.push({'address': addresses[currentStep], 'isErr': true, 'data': err});
if(currentStep < numSteps) {
currentStep += 1;
performRead();
} else {
defered.resolve(results);
}
};
var performRead = function() {
self.qRead(addresses[currentStep])
.then(handleReadSuccess, handleReadError);
};
performRead();
return defered.promise;
} | javascript | function(addresses) {
var defered = q.defer();
var currentStep = 0;
var numSteps = addresses.length;
var results = [];
var handleReadSuccess = function(res) {
results.push({'address': addresses[currentStep], 'isErr': false, 'data': res});
if(currentStep < numSteps) {
currentStep += 1;
performRead();
} else {
defered.resolve(results);
}
};
var handleReadError = function(err) {
results.push({'address': addresses[currentStep], 'isErr': true, 'data': err});
if(currentStep < numSteps) {
currentStep += 1;
performRead();
} else {
defered.resolve(results);
}
};
var performRead = function() {
self.qRead(addresses[currentStep])
.then(handleReadSuccess, handleReadError);
};
performRead();
return defered.promise;
} | [
"function",
"(",
"addresses",
")",
"{",
"var",
"defered",
"=",
"q",
".",
"defer",
"(",
")",
";",
"var",
"currentStep",
"=",
"0",
";",
"var",
"numSteps",
"=",
"addresses",
".",
"length",
";",
"var",
"results",
"=",
"[",
"]",
";",
"var",
"handleReadSuccess",
"=",
"function",
"(",
"res",
")",
"{",
"results",
".",
"push",
"(",
"{",
"'address'",
":",
"addresses",
"[",
"currentStep",
"]",
",",
"'isErr'",
":",
"false",
",",
"'data'",
":",
"res",
"}",
")",
";",
"if",
"(",
"currentStep",
"<",
"numSteps",
")",
"{",
"currentStep",
"+=",
"1",
";",
"performRead",
"(",
")",
";",
"}",
"else",
"{",
"defered",
".",
"resolve",
"(",
"results",
")",
";",
"}",
"}",
";",
"var",
"handleReadError",
"=",
"function",
"(",
"err",
")",
"{",
"results",
".",
"push",
"(",
"{",
"'address'",
":",
"addresses",
"[",
"currentStep",
"]",
",",
"'isErr'",
":",
"true",
",",
"'data'",
":",
"err",
"}",
")",
";",
"if",
"(",
"currentStep",
"<",
"numSteps",
")",
"{",
"currentStep",
"+=",
"1",
";",
"performRead",
"(",
")",
";",
"}",
"else",
"{",
"defered",
".",
"resolve",
"(",
"results",
")",
";",
"}",
"}",
";",
"var",
"performRead",
"=",
"function",
"(",
")",
"{",
"self",
".",
"qRead",
"(",
"addresses",
"[",
"currentStep",
"]",
")",
".",
"then",
"(",
"handleReadSuccess",
",",
"handleReadError",
")",
";",
"}",
";",
"performRead",
"(",
")",
";",
"return",
"defered",
".",
"promise",
";",
"}"
]
| An experimental implementation of the readMultiple function that doesn't use the async library. | [
"An",
"experimental",
"implementation",
"of",
"the",
"readMultiple",
"function",
"that",
"doesn",
"t",
"use",
"the",
"async",
"library",
"."
]
| 36cb25645dfa0a68e906d5ec43e5514391947257 | https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/device_curator.js#L1226-L1258 | train |
|
sorellabs/black | src/core.js | unpack | function unpack(kind, root, target, proto, source){
if (ownp(kind)) do_unpack(proto, source, methodize)
if (genericp(kind)) do_unpack(target, source)
if (utilsp(kind)) do_unpack(root, source.$black_utils)
} | javascript | function unpack(kind, root, target, proto, source){
if (ownp(kind)) do_unpack(proto, source, methodize)
if (genericp(kind)) do_unpack(target, source)
if (utilsp(kind)) do_unpack(root, source.$black_utils)
} | [
"function",
"unpack",
"(",
"kind",
",",
"root",
",",
"target",
",",
"proto",
",",
"source",
")",
"{",
"if",
"(",
"ownp",
"(",
"kind",
")",
")",
"do_unpack",
"(",
"proto",
",",
"source",
",",
"methodize",
")",
"if",
"(",
"genericp",
"(",
"kind",
")",
")",
"do_unpack",
"(",
"target",
",",
"source",
")",
"if",
"(",
"utilsp",
"(",
"kind",
")",
")",
"do_unpack",
"(",
"root",
",",
"source",
".",
"$black_utils",
")",
"}"
]
| Unpacks a black module so it's used in a sane way | [
"Unpacks",
"a",
"black",
"module",
"so",
"it",
"s",
"used",
"in",
"a",
"sane",
"way"
]
| 713a5ac396c4b8d5d501f5370272c20713839fc1 | https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L24-L28 | train |
sorellabs/black | src/core.js | unpack_all | function unpack_all(kind, global) {
keys(this).forEach(function(module) {
module = this[module]
if (!fnp(module)) unpack( kind
, global || top
, module.$black_box
, module.$black_proto
, module) }, this)
} | javascript | function unpack_all(kind, global) {
keys(this).forEach(function(module) {
module = this[module]
if (!fnp(module)) unpack( kind
, global || top
, module.$black_box
, module.$black_proto
, module) }, this)
} | [
"function",
"unpack_all",
"(",
"kind",
",",
"global",
")",
"{",
"keys",
"(",
"this",
")",
".",
"forEach",
"(",
"function",
"(",
"module",
")",
"{",
"module",
"=",
"this",
"[",
"module",
"]",
"if",
"(",
"!",
"fnp",
"(",
"module",
")",
")",
"unpack",
"(",
"kind",
",",
"global",
"||",
"top",
",",
"module",
".",
"$black_box",
",",
"module",
".",
"$black_proto",
",",
"module",
")",
"}",
",",
"this",
")",
"}"
]
| Unpacks all modules in black. Utils go in `target` or the global obj | [
"Unpacks",
"all",
"modules",
"in",
"black",
".",
"Utils",
"go",
"in",
"target",
"or",
"the",
"global",
"obj"
]
| 713a5ac396c4b8d5d501f5370272c20713839fc1 | https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L41-L49 | train |
sorellabs/black | src/core.js | methodize | function methodize(fn) {
return function() { var args
args = slice.call(arguments)
return fn.apply(this, [this].concat(args)) }
} | javascript | function methodize(fn) {
return function() { var args
args = slice.call(arguments)
return fn.apply(this, [this].concat(args)) }
} | [
"function",
"methodize",
"(",
"fn",
")",
"{",
"return",
"function",
"(",
")",
"{",
"var",
"args",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
")",
"return",
"fn",
".",
"apply",
"(",
"this",
",",
"[",
"this",
"]",
".",
"concat",
"(",
"args",
")",
")",
"}",
"}"
]
| Transforms a generic method into a SLOOOOOOOOOOOW instance method. | [
"Transforms",
"a",
"generic",
"method",
"into",
"a",
"SLOOOOOOOOOOOW",
"instance",
"method",
"."
]
| 713a5ac396c4b8d5d501f5370272c20713839fc1 | https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L52-L56 | train |
chrisJohn404/ljswitchboard-ljm_device_curator | lib/manufacturing_info_operations.js | createReadManufacturingInfoBundle | function createReadManufacturingInfoBundle() {
debugRMIOps('in createReadManufacturingInfoBundle');
// Initialize the bundle object with some basic data.
var bundle = {
'info': {},
'infoString': '',
'manufacturingData': manufacturingData,
'isError': false,
'errorStep': '',
'error': undefined,
'errorCode': 0,
};
// Initialize the manufacturing info object with dummy data.
manufacturingData.forEach(function(manData) {
if(manData.type === 'str') {
bundle.info[manData.key] = '';
} else if(manData.type === 'fl4') {
bundle.info[manData.key] = 0.000;
} else if(manData.type === 'int') {
bundle.info[manData.key] = 0;
} else {
bundle.info[manData.key] = '';
}
});
return bundle;
} | javascript | function createReadManufacturingInfoBundle() {
debugRMIOps('in createReadManufacturingInfoBundle');
// Initialize the bundle object with some basic data.
var bundle = {
'info': {},
'infoString': '',
'manufacturingData': manufacturingData,
'isError': false,
'errorStep': '',
'error': undefined,
'errorCode': 0,
};
// Initialize the manufacturing info object with dummy data.
manufacturingData.forEach(function(manData) {
if(manData.type === 'str') {
bundle.info[manData.key] = '';
} else if(manData.type === 'fl4') {
bundle.info[manData.key] = 0.000;
} else if(manData.type === 'int') {
bundle.info[manData.key] = 0;
} else {
bundle.info[manData.key] = '';
}
});
return bundle;
} | [
"function",
"createReadManufacturingInfoBundle",
"(",
")",
"{",
"debugRMIOps",
"(",
"'in createReadManufacturingInfoBundle'",
")",
";",
"var",
"bundle",
"=",
"{",
"'info'",
":",
"{",
"}",
",",
"'infoString'",
":",
"''",
",",
"'manufacturingData'",
":",
"manufacturingData",
",",
"'isError'",
":",
"false",
",",
"'errorStep'",
":",
"''",
",",
"'error'",
":",
"undefined",
",",
"'errorCode'",
":",
"0",
",",
"}",
";",
"manufacturingData",
".",
"forEach",
"(",
"function",
"(",
"manData",
")",
"{",
"if",
"(",
"manData",
".",
"type",
"===",
"'str'",
")",
"{",
"bundle",
".",
"info",
"[",
"manData",
".",
"key",
"]",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"manData",
".",
"type",
"===",
"'fl4'",
")",
"{",
"bundle",
".",
"info",
"[",
"manData",
".",
"key",
"]",
"=",
"0.000",
";",
"}",
"else",
"if",
"(",
"manData",
".",
"type",
"===",
"'int'",
")",
"{",
"bundle",
".",
"info",
"[",
"manData",
".",
"key",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"bundle",
".",
"info",
"[",
"manData",
".",
"key",
"]",
"=",
"''",
";",
"}",
"}",
")",
";",
"return",
"bundle",
";",
"}"
]
| Define a function that is used to initialize the data object built up during the process of reading the manufacturing data from a T7. | [
"Define",
"a",
"function",
"that",
"is",
"used",
"to",
"initialize",
"the",
"data",
"object",
"built",
"up",
"during",
"the",
"process",
"of",
"reading",
"the",
"manufacturing",
"data",
"from",
"a",
"T7",
"."
]
| 36cb25645dfa0a68e906d5ec43e5514391947257 | https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/manufacturing_info_operations.js#L145-L172 | train |
chrisJohn404/ljswitchboard-ljm_device_curator | lib/manufacturing_info_operations.js | readManufacturingInfoFlashData | function readManufacturingInfoFlashData(bundle) {
debugRMIOps('in readManufacturingInfoFlashData');
var defered = q.defer();
var startingAddress = 0x3C6000;
var numIntsToRead = 8*8;
self.readFlash(startingAddress, numIntsToRead)
.then(function(res) {
// res is an object with an attribute "results" that is an array
// of bytes. Therefore this debug call outputs a lot of data:
// debugRMIOps('in readManufacturingInfoFlashData res', res);
var str = '';
var rawData = [];
res.results.forEach(function(val) {
var bA = (val >> 24) & 0xFF;
rawData.push(bA);
var bB = (val >> 16) & 0xFF;
rawData.push(bB);
var bC = (val >> 8) & 0xFF;
rawData.push(bC);
var bD = (val >> 0) & 0xFF;
rawData.push(bD);
});
function isASCII(str, extended) {
return (extended ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str);
}
// debugRMIOps('in readManufacturingInfoFlashData', rawData);
rawData.forEach(function(raw) {
var newStrPartial = String.fromCharCode(raw);
if(isASCII(newStrPartial)) {
str += newStrPartial;
}
});
debugRMIOps('in readManufacturingInfoFlashData', str);
// console.log('Data:');
// console.log(str);
var noReturnChars = str.split('\r').join('');
strPartials = noReturnChars.split('\n');
var manufacturingInfoStr = '';
// console.log('Processing partials');
strPartials.forEach(function(strPartial) {
try {
// console.log('Checking partial', strPartial);
if(isData.test(strPartial)) {
// console.log('Parsing partial', strPartial);
var parsedInfo = parseManufacturingInfo(strPartial);
// console.log('Saving partial', strPartial, parsedInfo);
manufacturingInfoStr += parsedInfo.str;
manufacturingInfoStr += ': ';
manufacturingInfoStr += parsedInfo.rawData;
manufacturingInfoStr += '\n';
bundle = saveParsedDataToBundle(bundle, parsedInfo);
} else {
// console.log('Not Checking partial', strPartial);
}
} catch(err) {
errorLog('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial);
errorLog(err.stack);
console.error('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial);
}
});
// console.log(noReturnChars);
bundle.infoString = manufacturingInfoStr;
// console.log(bundle.info);
defered.resolve(bundle);
}, function(err) {
debugRMIOps('in readManufacturingInfoFlashData err', err);
bundle.isError = true;
bundle.errorStep = 'readManufacturingInfoFlashData';
bundle.error = modbusMap.getErrorInfo(err);
bundle.errorCode = err;
defered.reject(bundle);
});
return defered.promise;
} | javascript | function readManufacturingInfoFlashData(bundle) {
debugRMIOps('in readManufacturingInfoFlashData');
var defered = q.defer();
var startingAddress = 0x3C6000;
var numIntsToRead = 8*8;
self.readFlash(startingAddress, numIntsToRead)
.then(function(res) {
// res is an object with an attribute "results" that is an array
// of bytes. Therefore this debug call outputs a lot of data:
// debugRMIOps('in readManufacturingInfoFlashData res', res);
var str = '';
var rawData = [];
res.results.forEach(function(val) {
var bA = (val >> 24) & 0xFF;
rawData.push(bA);
var bB = (val >> 16) & 0xFF;
rawData.push(bB);
var bC = (val >> 8) & 0xFF;
rawData.push(bC);
var bD = (val >> 0) & 0xFF;
rawData.push(bD);
});
function isASCII(str, extended) {
return (extended ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str);
}
// debugRMIOps('in readManufacturingInfoFlashData', rawData);
rawData.forEach(function(raw) {
var newStrPartial = String.fromCharCode(raw);
if(isASCII(newStrPartial)) {
str += newStrPartial;
}
});
debugRMIOps('in readManufacturingInfoFlashData', str);
// console.log('Data:');
// console.log(str);
var noReturnChars = str.split('\r').join('');
strPartials = noReturnChars.split('\n');
var manufacturingInfoStr = '';
// console.log('Processing partials');
strPartials.forEach(function(strPartial) {
try {
// console.log('Checking partial', strPartial);
if(isData.test(strPartial)) {
// console.log('Parsing partial', strPartial);
var parsedInfo = parseManufacturingInfo(strPartial);
// console.log('Saving partial', strPartial, parsedInfo);
manufacturingInfoStr += parsedInfo.str;
manufacturingInfoStr += ': ';
manufacturingInfoStr += parsedInfo.rawData;
manufacturingInfoStr += '\n';
bundle = saveParsedDataToBundle(bundle, parsedInfo);
} else {
// console.log('Not Checking partial', strPartial);
}
} catch(err) {
errorLog('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial);
errorLog(err.stack);
console.error('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial);
}
});
// console.log(noReturnChars);
bundle.infoString = manufacturingInfoStr;
// console.log(bundle.info);
defered.resolve(bundle);
}, function(err) {
debugRMIOps('in readManufacturingInfoFlashData err', err);
bundle.isError = true;
bundle.errorStep = 'readManufacturingInfoFlashData';
bundle.error = modbusMap.getErrorInfo(err);
bundle.errorCode = err;
defered.reject(bundle);
});
return defered.promise;
} | [
"function",
"readManufacturingInfoFlashData",
"(",
"bundle",
")",
"{",
"debugRMIOps",
"(",
"'in readManufacturingInfoFlashData'",
")",
";",
"var",
"defered",
"=",
"q",
".",
"defer",
"(",
")",
";",
"var",
"startingAddress",
"=",
"0x3C6000",
";",
"var",
"numIntsToRead",
"=",
"8",
"*",
"8",
";",
"self",
".",
"readFlash",
"(",
"startingAddress",
",",
"numIntsToRead",
")",
".",
"then",
"(",
"function",
"(",
"res",
")",
"{",
"var",
"str",
"=",
"''",
";",
"var",
"rawData",
"=",
"[",
"]",
";",
"res",
".",
"results",
".",
"forEach",
"(",
"function",
"(",
"val",
")",
"{",
"var",
"bA",
"=",
"(",
"val",
">>",
"24",
")",
"&",
"0xFF",
";",
"rawData",
".",
"push",
"(",
"bA",
")",
";",
"var",
"bB",
"=",
"(",
"val",
">>",
"16",
")",
"&",
"0xFF",
";",
"rawData",
".",
"push",
"(",
"bB",
")",
";",
"var",
"bC",
"=",
"(",
"val",
">>",
"8",
")",
"&",
"0xFF",
";",
"rawData",
".",
"push",
"(",
"bC",
")",
";",
"var",
"bD",
"=",
"(",
"val",
">>",
"0",
")",
"&",
"0xFF",
";",
"rawData",
".",
"push",
"(",
"bD",
")",
";",
"}",
")",
";",
"function",
"isASCII",
"(",
"str",
",",
"extended",
")",
"{",
"return",
"(",
"extended",
"?",
"/",
"^[\\x00-\\xFF]*$",
"/",
":",
"/",
"^[\\x00-\\x7F]*$",
"/",
")",
".",
"test",
"(",
"str",
")",
";",
"}",
"rawData",
".",
"forEach",
"(",
"function",
"(",
"raw",
")",
"{",
"var",
"newStrPartial",
"=",
"String",
".",
"fromCharCode",
"(",
"raw",
")",
";",
"if",
"(",
"isASCII",
"(",
"newStrPartial",
")",
")",
"{",
"str",
"+=",
"newStrPartial",
";",
"}",
"}",
")",
";",
"debugRMIOps",
"(",
"'in readManufacturingInfoFlashData'",
",",
"str",
")",
";",
"var",
"noReturnChars",
"=",
"str",
".",
"split",
"(",
"'\\r'",
")",
".",
"\\r",
"join",
";",
"(",
"''",
")",
"strPartials",
"=",
"noReturnChars",
".",
"split",
"(",
"'\\n'",
")",
";",
"\\n",
"var",
"manufacturingInfoStr",
"=",
"''",
";",
"strPartials",
".",
"forEach",
"(",
"function",
"(",
"strPartial",
")",
"{",
"try",
"{",
"if",
"(",
"isData",
".",
"test",
"(",
"strPartial",
")",
")",
"{",
"var",
"parsedInfo",
"=",
"parseManufacturingInfo",
"(",
"strPartial",
")",
";",
"manufacturingInfoStr",
"+=",
"parsedInfo",
".",
"str",
";",
"manufacturingInfoStr",
"+=",
"': '",
";",
"manufacturingInfoStr",
"+=",
"parsedInfo",
".",
"rawData",
";",
"manufacturingInfoStr",
"+=",
"'\\n'",
";",
"\\n",
"}",
"else",
"bundle",
"=",
"saveParsedDataToBundle",
"(",
"bundle",
",",
"parsedInfo",
")",
";",
"}",
"{",
"}",
"}",
")",
";",
"}",
",",
"catch",
"(",
"err",
")",
"{",
"errorLog",
"(",
"'Error parsing partial (t7_manufacturing_info_ops.js)'",
",",
"err",
",",
"strPartial",
")",
";",
"errorLog",
"(",
"err",
".",
"stack",
")",
";",
"console",
".",
"error",
"(",
"'Error parsing partial (t7_manufacturing_info_ops.js)'",
",",
"err",
",",
"strPartial",
")",
";",
"}",
")",
";",
"bundle",
".",
"infoString",
"=",
"manufacturingInfoStr",
";",
"}"
]
| Read the manufacturing data from a T7. | [
"Read",
"the",
"manufacturing",
"data",
"from",
"a",
"T7",
"."
]
| 36cb25645dfa0a68e906d5ec43e5514391947257 | https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/manufacturing_info_operations.js#L175-L249 | train |
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(element, rule){
var elementClassName = element.className,
elementID = element.id,
elementTagName = element.tagName,
elementDisplayName = element.constructor.displayName;
if(rule.tagName && !this.tagName(rule.tagName, elementTagName, elementDisplayName)){
return false;
}
if(rule.id && !this.id(rule.id, elementID)){
return false;
}
if(rule.classNames && !this.className(rule.classNames, elementClassName)){
return false;
}
if(rule.pseudos && !this.pseudoMatcher(rule.pseudos, element, elementTagName)){
return false;
}
if(rule.attrs && !this.attributeMatcher(rule.attrs, element)){
return false;
}
return true;
} | javascript | function(element, rule){
var elementClassName = element.className,
elementID = element.id,
elementTagName = element.tagName,
elementDisplayName = element.constructor.displayName;
if(rule.tagName && !this.tagName(rule.tagName, elementTagName, elementDisplayName)){
return false;
}
if(rule.id && !this.id(rule.id, elementID)){
return false;
}
if(rule.classNames && !this.className(rule.classNames, elementClassName)){
return false;
}
if(rule.pseudos && !this.pseudoMatcher(rule.pseudos, element, elementTagName)){
return false;
}
if(rule.attrs && !this.attributeMatcher(rule.attrs, element)){
return false;
}
return true;
} | [
"function",
"(",
"element",
",",
"rule",
")",
"{",
"var",
"elementClassName",
"=",
"element",
".",
"className",
",",
"elementID",
"=",
"element",
".",
"id",
",",
"elementTagName",
"=",
"element",
".",
"tagName",
",",
"elementDisplayName",
"=",
"element",
".",
"constructor",
".",
"displayName",
";",
"if",
"(",
"rule",
".",
"tagName",
"&&",
"!",
"this",
".",
"tagName",
"(",
"rule",
".",
"tagName",
",",
"elementTagName",
",",
"elementDisplayName",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"rule",
".",
"id",
"&&",
"!",
"this",
".",
"id",
"(",
"rule",
".",
"id",
",",
"elementID",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"rule",
".",
"classNames",
"&&",
"!",
"this",
".",
"className",
"(",
"rule",
".",
"classNames",
",",
"elementClassName",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"rule",
".",
"pseudos",
"&&",
"!",
"this",
".",
"pseudoMatcher",
"(",
"rule",
".",
"pseudos",
",",
"element",
",",
"elementTagName",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"rule",
".",
"attrs",
"&&",
"!",
"this",
".",
"attributeMatcher",
"(",
"rule",
".",
"attrs",
",",
"element",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Given an array, reduces the items based on the provided parsed CSS pseudo selector.
@param {Object} element Element to test
@param {Object} rule Parsed pseudo CSS selector
@return {Array} Reduced matches based on selector processing | [
"Given",
"an",
"array",
"reduces",
"the",
"items",
"based",
"on",
"the",
"provided",
"parsed",
"CSS",
"pseudo",
"selector",
"."
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L10-L34 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(pseudoRule, element, elementTagName){
if(pseudoRule.name === 'checked'){
return this.checked(element, elementTagName);
}
if(pseudoRule.name === 'empty'){
return this.empty(element);
}
} | javascript | function(pseudoRule, element, elementTagName){
if(pseudoRule.name === 'checked'){
return this.checked(element, elementTagName);
}
if(pseudoRule.name === 'empty'){
return this.empty(element);
}
} | [
"function",
"(",
"pseudoRule",
",",
"element",
",",
"elementTagName",
")",
"{",
"if",
"(",
"pseudoRule",
".",
"name",
"===",
"'checked'",
")",
"{",
"return",
"this",
".",
"checked",
"(",
"element",
",",
"elementTagName",
")",
";",
"}",
"if",
"(",
"pseudoRule",
".",
"name",
"===",
"'empty'",
")",
"{",
"return",
"this",
".",
"empty",
"(",
"element",
")",
";",
"}",
"}"
]
| Routes pseudo selector to proper handler
@param {Object} pseudoRule Parsed CSS pseudo rule
@param {Object} element Element to check against pseudo rule
@param {String} elementTagName Tag name of the element
@return {Bool} Whether element matches pseudo rule | [
"Routes",
"pseudo",
"selector",
"to",
"proper",
"handler"
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L43-L50 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(attributeRules, element){
for(var i = 0; i < attributeRules.length; i++){
var attributeName = attributeRules[i].name,
objectToCheck = element;
if(typeof element.context === 'undefined'){
//Native DOM node
if(_.startsWith(attributeName, 'data-')){
objectToCheck = element.dataset;
attributeName = attributeName.split('-')[1];
}
}
else{
//React component instance
objectToCheck = element.props;
}
var elementProperty = objectToCheck[attributeName],
operator = attributeRules[i].operator,
value = attributeRules[i].value;
//Only checking for existance, don't care about the value
if(!operator && elementProperty === undefined){
return false;
}
var doesValueMatch = this.compareElementProperty(elementProperty, operator, value);
if(!doesValueMatch){
return false;
}
}
return true;
} | javascript | function(attributeRules, element){
for(var i = 0; i < attributeRules.length; i++){
var attributeName = attributeRules[i].name,
objectToCheck = element;
if(typeof element.context === 'undefined'){
//Native DOM node
if(_.startsWith(attributeName, 'data-')){
objectToCheck = element.dataset;
attributeName = attributeName.split('-')[1];
}
}
else{
//React component instance
objectToCheck = element.props;
}
var elementProperty = objectToCheck[attributeName],
operator = attributeRules[i].operator,
value = attributeRules[i].value;
//Only checking for existance, don't care about the value
if(!operator && elementProperty === undefined){
return false;
}
var doesValueMatch = this.compareElementProperty(elementProperty, operator, value);
if(!doesValueMatch){
return false;
}
}
return true;
} | [
"function",
"(",
"attributeRules",
",",
"element",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"attributeRules",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"attributeName",
"=",
"attributeRules",
"[",
"i",
"]",
".",
"name",
",",
"objectToCheck",
"=",
"element",
";",
"if",
"(",
"typeof",
"element",
".",
"context",
"===",
"'undefined'",
")",
"{",
"if",
"(",
"_",
".",
"startsWith",
"(",
"attributeName",
",",
"'data-'",
")",
")",
"{",
"objectToCheck",
"=",
"element",
".",
"dataset",
";",
"attributeName",
"=",
"attributeName",
".",
"split",
"(",
"'-'",
")",
"[",
"1",
"]",
";",
"}",
"}",
"else",
"{",
"objectToCheck",
"=",
"element",
".",
"props",
";",
"}",
"var",
"elementProperty",
"=",
"objectToCheck",
"[",
"attributeName",
"]",
",",
"operator",
"=",
"attributeRules",
"[",
"i",
"]",
".",
"operator",
",",
"value",
"=",
"attributeRules",
"[",
"i",
"]",
".",
"value",
";",
"if",
"(",
"!",
"operator",
"&&",
"elementProperty",
"===",
"undefined",
")",
"{",
"return",
"false",
";",
"}",
"var",
"doesValueMatch",
"=",
"this",
".",
"compareElementProperty",
"(",
"elementProperty",
",",
"operator",
",",
"value",
")",
";",
"if",
"(",
"!",
"doesValueMatch",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Validates if the provided element matches the provided array of
attribute CSS selectors.
@param {Array} attributeRules Array of attribute rules to check
@param {Object} element Element to check
@return {Bool} Whether element matches all attribute rules | [
"Validates",
"if",
"the",
"provided",
"element",
"matches",
"the",
"provided",
"array",
"of",
"attribute",
"CSS",
"selectors",
"."
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L59-L91 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(ruleClassName, elementClassName){
if(!elementClassName){
return false;
}
for(var i = 0; i < ruleClassName.length; i++){
if((' ' + elementClassName + ' ').indexOf(' ' + ruleClassName[i] + ' ') === -1){
return false;
}
}
return true;
} | javascript | function(ruleClassName, elementClassName){
if(!elementClassName){
return false;
}
for(var i = 0; i < ruleClassName.length; i++){
if((' ' + elementClassName + ' ').indexOf(' ' + ruleClassName[i] + ' ') === -1){
return false;
}
}
return true;
} | [
"function",
"(",
"ruleClassName",
",",
"elementClassName",
")",
"{",
"if",
"(",
"!",
"elementClassName",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ruleClassName",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"(",
"' '",
"+",
"elementClassName",
"+",
"' '",
")",
".",
"indexOf",
"(",
"' '",
"+",
"ruleClassName",
"[",
"i",
"]",
"+",
"' '",
")",
"===",
"-",
"1",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Checks if the element class names match the provided CSS selector names
@param {Array} ruleClassName Class name of CSS selector
@param {String} elementClassName Class name of element
@return {Bool} Whether element class names CSS selectors | [
"Checks",
"if",
"the",
"element",
"class",
"names",
"match",
"the",
"provided",
"CSS",
"selector",
"names"
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L128-L138 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(element, tagName){
if(!tagName || tagName.toLowerCase() !== 'input'){
return false;
}
var inputType = element.type.toLowerCase();
if(inputType !== 'checkbox' && inputType !== 'radio'){
return false;
}
return element.checked !== false;
} | javascript | function(element, tagName){
if(!tagName || tagName.toLowerCase() !== 'input'){
return false;
}
var inputType = element.type.toLowerCase();
if(inputType !== 'checkbox' && inputType !== 'radio'){
return false;
}
return element.checked !== false;
} | [
"function",
"(",
"element",
",",
"tagName",
")",
"{",
"if",
"(",
"!",
"tagName",
"||",
"tagName",
".",
"toLowerCase",
"(",
")",
"!==",
"'input'",
")",
"{",
"return",
"false",
";",
"}",
"var",
"inputType",
"=",
"element",
".",
"type",
".",
"toLowerCase",
"(",
")",
";",
"if",
"(",
"inputType",
"!==",
"'checkbox'",
"&&",
"inputType",
"!==",
"'radio'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"element",
".",
"checked",
"!==",
"false",
";",
"}"
]
| Checks if the provided element is "checked". Only applies to inputs of type radio
and checkbox. Checks for both the checked property and defaultChecked property.
@param {Object} element Element to test
@param {String} tagName Tag name of the element
@return {Bool} Whether element is the correct input type and is checked | [
"Checks",
"if",
"the",
"provided",
"element",
"is",
"checked",
".",
"Only",
"applies",
"to",
"inputs",
"of",
"type",
"radio",
"and",
"checkbox",
".",
"Checks",
"for",
"both",
"the",
"checked",
"property",
"and",
"defaultChecked",
"property",
"."
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L156-L167 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(property, operator, value){
if(operator === '='){
return this.compareElementPropertyEquality(property, value);
}
if(operator === '~='){
return String(property).split(" ").indexOf(value) !== -1;
}
if(operator === '^='){
return _.startsWith(property, value);
}
if(operator === '$='){
return _.endsWith(property, value);
}
if(operator === '*='){
return property && property.indexOf(value) !== -1;
}
return true;
} | javascript | function(property, operator, value){
if(operator === '='){
return this.compareElementPropertyEquality(property, value);
}
if(operator === '~='){
return String(property).split(" ").indexOf(value) !== -1;
}
if(operator === '^='){
return _.startsWith(property, value);
}
if(operator === '$='){
return _.endsWith(property, value);
}
if(operator === '*='){
return property && property.indexOf(value) !== -1;
}
return true;
} | [
"function",
"(",
"property",
",",
"operator",
",",
"value",
")",
"{",
"if",
"(",
"operator",
"===",
"'='",
")",
"{",
"return",
"this",
".",
"compareElementPropertyEquality",
"(",
"property",
",",
"value",
")",
";",
"}",
"if",
"(",
"operator",
"===",
"'~='",
")",
"{",
"return",
"String",
"(",
"property",
")",
".",
"split",
"(",
"\" \"",
")",
".",
"indexOf",
"(",
"value",
")",
"!==",
"-",
"1",
";",
"}",
"if",
"(",
"operator",
"===",
"'^='",
")",
"{",
"return",
"_",
".",
"startsWith",
"(",
"property",
",",
"value",
")",
";",
"}",
"if",
"(",
"operator",
"===",
"'$='",
")",
"{",
"return",
"_",
".",
"endsWith",
"(",
"property",
",",
"value",
")",
";",
"}",
"if",
"(",
"operator",
"===",
"'*='",
")",
"{",
"return",
"property",
"&&",
"property",
".",
"indexOf",
"(",
"value",
")",
"!==",
"-",
"1",
";",
"}",
"return",
"true",
";",
"}"
]
| Function to parse attribute CSS queries for the various types of comparitor functions supported
in attribute queries and then performs the specific comparison of property and value
@param {Mixed} property Value of component prop to compare against
@param {String} operator Comparison operator
@param {String} value Value to compare
@return {Bool} Whether property matches value with the given operator check | [
"Function",
"to",
"parse",
"attribute",
"CSS",
"queries",
"for",
"the",
"various",
"types",
"of",
"comparitor",
"functions",
"supported",
"in",
"attribute",
"queries",
"and",
"then",
"performs",
"the",
"specific",
"comparison",
"of",
"property",
"and",
"value"
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L177-L194 | train |
|
dataminr/expanded-react-test-utils | lib/SelectorMatchers.js | function(property, value){
//When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since
//the value in the selector always comes through as a string
if(_.isNumber(property)){
return property === parseInt(value);
}
else if(_.isBoolean(property)){
return property === (value === 'true' ? true : false);
}
else if(value === "null"){
return property === null;
}
return property === value;
} | javascript | function(property, value){
//When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since
//the value in the selector always comes through as a string
if(_.isNumber(property)){
return property === parseInt(value);
}
else if(_.isBoolean(property)){
return property === (value === 'true' ? true : false);
}
else if(value === "null"){
return property === null;
}
return property === value;
} | [
"function",
"(",
"property",
",",
"value",
")",
"{",
"if",
"(",
"_",
".",
"isNumber",
"(",
"property",
")",
")",
"{",
"return",
"property",
"===",
"parseInt",
"(",
"value",
")",
";",
"}",
"else",
"if",
"(",
"_",
".",
"isBoolean",
"(",
"property",
")",
")",
"{",
"return",
"property",
"===",
"(",
"value",
"===",
"'true'",
"?",
"true",
":",
"false",
")",
";",
"}",
"else",
"if",
"(",
"value",
"===",
"\"null\"",
")",
"{",
"return",
"property",
"===",
"null",
";",
"}",
"return",
"property",
"===",
"value",
";",
"}"
]
| Does a equality comparison, handling for the fact that value is always a string. Supports casting
of values into numbers, booleans, and null.
@param {Mixed} property Element prop value to check
@param {String} value CSS selector value to compare
@return {Bool} Whether property and value match | [
"Does",
"a",
"equality",
"comparison",
"handling",
"for",
"the",
"fact",
"that",
"value",
"is",
"always",
"a",
"string",
".",
"Supports",
"casting",
"of",
"values",
"into",
"numbers",
"booleans",
"and",
"null",
"."
]
| cb23cd10cd29839401939561ee0081a49235b358 | https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L203-L216 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | isVersionAtLeast | function isVersionAtLeast(dottedVersion, major, minor, patch){
var i, v, t,
verParts = $.map($.trim(dottedVersion).split("."), function(e){ return parseInt(e, 10); }),
testParts = $.map(Array.prototype.slice.call(arguments, 1), function(e){ return parseInt(e, 10); });
for( i = 0; i < testParts.length; i++ ){
v = verParts[i] || 0;
t = testParts[i] || 0;
if( v !== t ){
return ( v > t );
}
}
return true;
} | javascript | function isVersionAtLeast(dottedVersion, major, minor, patch){
var i, v, t,
verParts = $.map($.trim(dottedVersion).split("."), function(e){ return parseInt(e, 10); }),
testParts = $.map(Array.prototype.slice.call(arguments, 1), function(e){ return parseInt(e, 10); });
for( i = 0; i < testParts.length; i++ ){
v = verParts[i] || 0;
t = testParts[i] || 0;
if( v !== t ){
return ( v > t );
}
}
return true;
} | [
"function",
"isVersionAtLeast",
"(",
"dottedVersion",
",",
"major",
",",
"minor",
",",
"patch",
")",
"{",
"var",
"i",
",",
"v",
",",
"t",
",",
"verParts",
"=",
"$",
".",
"map",
"(",
"$",
".",
"trim",
"(",
"dottedVersion",
")",
".",
"split",
"(",
"\".\"",
")",
",",
"function",
"(",
"e",
")",
"{",
"return",
"parseInt",
"(",
"e",
",",
"10",
")",
";",
"}",
")",
",",
"testParts",
"=",
"$",
".",
"map",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
",",
"function",
"(",
"e",
")",
"{",
"return",
"parseInt",
"(",
"e",
",",
"10",
")",
";",
"}",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"testParts",
".",
"length",
";",
"i",
"++",
")",
"{",
"v",
"=",
"verParts",
"[",
"i",
"]",
"||",
"0",
";",
"t",
"=",
"testParts",
"[",
"i",
"]",
"||",
"0",
";",
"if",
"(",
"v",
"!==",
"t",
")",
"{",
"return",
"(",
"v",
">",
"t",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Return true if dotted version string is equal or higher than requested version.
See http://jsfiddle.net/mar10/FjSAN/ | [
"Return",
"true",
"if",
"dotted",
"version",
"string",
"is",
"equal",
"or",
"higher",
"than",
"requested",
"version",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L73-L86 | train |
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(targetNode, mode, map) {
if(mode === undefined || mode === "over"){
mode = "child";
}
var pos,
prevParent = this.parent,
targetParent = (mode === "child") ? targetNode : targetNode.parent;
if(this === targetNode){
return;
}else if( !this.parent ){
throw "Cannot move system root";
}else if( targetParent.isDescendantOf(this) ){
throw "Cannot move a node to its own descendant";
}
// Unlink this node from current parent
if( this.parent.children.length === 1 ) {
if( this.parent === targetParent ){
return; // #258
}
this.parent.children = this.parent.lazy ? [] : null;
this.parent.expanded = false;
} else {
pos = $.inArray(this, this.parent.children);
_assert(pos >= 0);
this.parent.children.splice(pos, 1);
}
// Remove from source DOM parent
// if(this.parent.ul){
// this.parent.ul.removeChild(this.li);
// }
// Insert this node to target parent's child list
this.parent = targetParent;
if( targetParent.hasChildren() ) {
switch(mode) {
case "child":
// Append to existing target children
targetParent.children.push(this);
break;
case "before":
// Insert this node before target node
pos = $.inArray(targetNode, targetParent.children);
_assert(pos >= 0);
targetParent.children.splice(pos, 0, this);
break;
case "after":
// Insert this node after target node
pos = $.inArray(targetNode, targetParent.children);
_assert(pos >= 0);
targetParent.children.splice(pos+1, 0, this);
break;
default:
throw "Invalid mode " + mode;
}
} else {
targetParent.children = [ this ];
}
// Parent has no <ul> tag yet:
// if( !targetParent.ul ) {
// // This is the parent's first child: create UL tag
// // (Hidden, because it will be
// targetParent.ul = document.createElement("ul");
// targetParent.ul.style.display = "none";
// targetParent.li.appendChild(targetParent.ul);
// }
// // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
// if(this.li){
// targetParent.ul.appendChild(this.li);
// }^
// Let caller modify the nodes
if( map ){
targetNode.visit(map, true);
}
// Handle cross-tree moves
if( this.tree !== targetNode.tree ) {
// Fix node.tree for all source nodes
// _assert(false, "Cross-tree move is not yet implemented.");
this.warn("Cross-tree moveTo is experimantal!");
this.visit(function(n){
// TODO: fix selection state and activation, ...
n.tree = targetNode.tree;
}, true);
}
// A collaposed node won't re-render children, so we have to remove it manually
// if( !targetParent.expanded ){
// prevParent.ul.removeChild(this.li);
// }
// Update HTML markup
if( !prevParent.isDescendantOf(targetParent)) {
prevParent.render();
}
if( !targetParent.isDescendantOf(prevParent) && targetParent !== prevParent) {
targetParent.render();
}
// TODO: fix selection state
// TODO: fix active state
/*
var tree = this.tree;
var opts = tree.options;
var pers = tree.persistence;
// Always expand, if it's below minExpandLevel
// tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
if ( opts.minExpandLevel >= ftnode.getLevel() ) {
// tree.logDebug ("Force expand for %o", ftnode);
this.bExpanded = true;
}
// In multi-hier mode, update the parents selection state
// DT issue #82: only if not initializing, because the children may not exist yet
// if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
// ftnode._fixSelectionState();
// In multi-hier mode, update the parents selection state
if( ftnode.bSelected && opts.selectMode==3 ) {
var p = this;
while( p ) {
if( !p.hasSubSel )
p._setSubSel(true);
p = p.parent;
}
}
// render this node and the new child
if ( tree.bEnableUpdate )
this.render();
return ftnode;
*/
} | javascript | function(targetNode, mode, map) {
if(mode === undefined || mode === "over"){
mode = "child";
}
var pos,
prevParent = this.parent,
targetParent = (mode === "child") ? targetNode : targetNode.parent;
if(this === targetNode){
return;
}else if( !this.parent ){
throw "Cannot move system root";
}else if( targetParent.isDescendantOf(this) ){
throw "Cannot move a node to its own descendant";
}
// Unlink this node from current parent
if( this.parent.children.length === 1 ) {
if( this.parent === targetParent ){
return; // #258
}
this.parent.children = this.parent.lazy ? [] : null;
this.parent.expanded = false;
} else {
pos = $.inArray(this, this.parent.children);
_assert(pos >= 0);
this.parent.children.splice(pos, 1);
}
// Remove from source DOM parent
// if(this.parent.ul){
// this.parent.ul.removeChild(this.li);
// }
// Insert this node to target parent's child list
this.parent = targetParent;
if( targetParent.hasChildren() ) {
switch(mode) {
case "child":
// Append to existing target children
targetParent.children.push(this);
break;
case "before":
// Insert this node before target node
pos = $.inArray(targetNode, targetParent.children);
_assert(pos >= 0);
targetParent.children.splice(pos, 0, this);
break;
case "after":
// Insert this node after target node
pos = $.inArray(targetNode, targetParent.children);
_assert(pos >= 0);
targetParent.children.splice(pos+1, 0, this);
break;
default:
throw "Invalid mode " + mode;
}
} else {
targetParent.children = [ this ];
}
// Parent has no <ul> tag yet:
// if( !targetParent.ul ) {
// // This is the parent's first child: create UL tag
// // (Hidden, because it will be
// targetParent.ul = document.createElement("ul");
// targetParent.ul.style.display = "none";
// targetParent.li.appendChild(targetParent.ul);
// }
// // Issue 319: Add to target DOM parent (only if node was already rendered(expanded))
// if(this.li){
// targetParent.ul.appendChild(this.li);
// }^
// Let caller modify the nodes
if( map ){
targetNode.visit(map, true);
}
// Handle cross-tree moves
if( this.tree !== targetNode.tree ) {
// Fix node.tree for all source nodes
// _assert(false, "Cross-tree move is not yet implemented.");
this.warn("Cross-tree moveTo is experimantal!");
this.visit(function(n){
// TODO: fix selection state and activation, ...
n.tree = targetNode.tree;
}, true);
}
// A collaposed node won't re-render children, so we have to remove it manually
// if( !targetParent.expanded ){
// prevParent.ul.removeChild(this.li);
// }
// Update HTML markup
if( !prevParent.isDescendantOf(targetParent)) {
prevParent.render();
}
if( !targetParent.isDescendantOf(prevParent) && targetParent !== prevParent) {
targetParent.render();
}
// TODO: fix selection state
// TODO: fix active state
/*
var tree = this.tree;
var opts = tree.options;
var pers = tree.persistence;
// Always expand, if it's below minExpandLevel
// tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel());
if ( opts.minExpandLevel >= ftnode.getLevel() ) {
// tree.logDebug ("Force expand for %o", ftnode);
this.bExpanded = true;
}
// In multi-hier mode, update the parents selection state
// DT issue #82: only if not initializing, because the children may not exist yet
// if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )
// ftnode._fixSelectionState();
// In multi-hier mode, update the parents selection state
if( ftnode.bSelected && opts.selectMode==3 ) {
var p = this;
while( p ) {
if( !p.hasSubSel )
p._setSubSel(true);
p = p.parent;
}
}
// render this node and the new child
if ( tree.bEnableUpdate )
this.render();
return ftnode;
*/
} | [
"function",
"(",
"targetNode",
",",
"mode",
",",
"map",
")",
"{",
"if",
"(",
"mode",
"===",
"undefined",
"||",
"mode",
"===",
"\"over\"",
")",
"{",
"mode",
"=",
"\"child\"",
";",
"}",
"var",
"pos",
",",
"prevParent",
"=",
"this",
".",
"parent",
",",
"targetParent",
"=",
"(",
"mode",
"===",
"\"child\"",
")",
"?",
"targetNode",
":",
"targetNode",
".",
"parent",
";",
"if",
"(",
"this",
"===",
"targetNode",
")",
"{",
"return",
";",
"}",
"else",
"if",
"(",
"!",
"this",
".",
"parent",
")",
"{",
"throw",
"\"Cannot move system root\"",
";",
"}",
"else",
"if",
"(",
"targetParent",
".",
"isDescendantOf",
"(",
"this",
")",
")",
"{",
"throw",
"\"Cannot move a node to its own descendant\"",
";",
"}",
"if",
"(",
"this",
".",
"parent",
".",
"children",
".",
"length",
"===",
"1",
")",
"{",
"if",
"(",
"this",
".",
"parent",
"===",
"targetParent",
")",
"{",
"return",
";",
"}",
"this",
".",
"parent",
".",
"children",
"=",
"this",
".",
"parent",
".",
"lazy",
"?",
"[",
"]",
":",
"null",
";",
"this",
".",
"parent",
".",
"expanded",
"=",
"false",
";",
"}",
"else",
"{",
"pos",
"=",
"$",
".",
"inArray",
"(",
"this",
",",
"this",
".",
"parent",
".",
"children",
")",
";",
"_assert",
"(",
"pos",
">=",
"0",
")",
";",
"this",
".",
"parent",
".",
"children",
".",
"splice",
"(",
"pos",
",",
"1",
")",
";",
"}",
"this",
".",
"parent",
"=",
"targetParent",
";",
"if",
"(",
"targetParent",
".",
"hasChildren",
"(",
")",
")",
"{",
"switch",
"(",
"mode",
")",
"{",
"case",
"\"child\"",
":",
"targetParent",
".",
"children",
".",
"push",
"(",
"this",
")",
";",
"break",
";",
"case",
"\"before\"",
":",
"pos",
"=",
"$",
".",
"inArray",
"(",
"targetNode",
",",
"targetParent",
".",
"children",
")",
";",
"_assert",
"(",
"pos",
">=",
"0",
")",
";",
"targetParent",
".",
"children",
".",
"splice",
"(",
"pos",
",",
"0",
",",
"this",
")",
";",
"break",
";",
"case",
"\"after\"",
":",
"pos",
"=",
"$",
".",
"inArray",
"(",
"targetNode",
",",
"targetParent",
".",
"children",
")",
";",
"_assert",
"(",
"pos",
">=",
"0",
")",
";",
"targetParent",
".",
"children",
".",
"splice",
"(",
"pos",
"+",
"1",
",",
"0",
",",
"this",
")",
";",
"break",
";",
"default",
":",
"throw",
"\"Invalid mode \"",
"+",
"mode",
";",
"}",
"}",
"else",
"{",
"targetParent",
".",
"children",
"=",
"[",
"this",
"]",
";",
"}",
"if",
"(",
"map",
")",
"{",
"targetNode",
".",
"visit",
"(",
"map",
",",
"true",
")",
";",
"}",
"if",
"(",
"this",
".",
"tree",
"!==",
"targetNode",
".",
"tree",
")",
"{",
"this",
".",
"warn",
"(",
"\"Cross-tree moveTo is experimantal!\"",
")",
";",
"this",
".",
"visit",
"(",
"function",
"(",
"n",
")",
"{",
"n",
".",
"tree",
"=",
"targetNode",
".",
"tree",
";",
"}",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"prevParent",
".",
"isDescendantOf",
"(",
"targetParent",
")",
")",
"{",
"prevParent",
".",
"render",
"(",
")",
";",
"}",
"if",
"(",
"!",
"targetParent",
".",
"isDescendantOf",
"(",
"prevParent",
")",
"&&",
"targetParent",
"!==",
"prevParent",
")",
"{",
"targetParent",
".",
"render",
"(",
")",
";",
"}",
"}"
]
| Move this node to targetNode.
@param {FancytreeNode} targetNode
@param {string} mode <pre>
'child': append this node as last child of targetNode.
This is the default. To be compatble with the D'n'd
hitMode, we also accept 'over'.
'before': add this node as sibling before targetNode.
'after': add this node as sibling after targetNode.</pre>
@param {function} [map] optional callback(FancytreeNode) to allow modifcations | [
"Move",
"this",
"node",
"to",
"targetNode",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L1073-L1208 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(stopOnParents) {
var nodeList = [];
this.rootNode.visit(function(node){
if( node.selected ) {
nodeList.push(node);
if( stopOnParents === true ){
return "skip"; // stop processing this branch
}
}
});
return nodeList;
} | javascript | function(stopOnParents) {
var nodeList = [];
this.rootNode.visit(function(node){
if( node.selected ) {
nodeList.push(node);
if( stopOnParents === true ){
return "skip"; // stop processing this branch
}
}
});
return nodeList;
} | [
"function",
"(",
"stopOnParents",
")",
"{",
"var",
"nodeList",
"=",
"[",
"]",
";",
"this",
".",
"rootNode",
".",
"visit",
"(",
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"selected",
")",
"{",
"nodeList",
".",
"push",
"(",
"node",
")",
";",
"if",
"(",
"stopOnParents",
"===",
"true",
")",
"{",
"return",
"\"skip\"",
";",
"}",
"}",
"}",
")",
";",
"return",
"nodeList",
";",
"}"
]
| Return an array of selected nodes.
@param {boolean} [stopOnParents=false] only return the topmost selected
node (useful with selectMode 3)
@returns {FancytreeNode[]} | [
"Return",
"an",
"array",
"of",
"selected",
"nodes",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2067-L2078 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(setFocus) {
var node = this.activeNode;
if( node ) {
this.activeNode = null; // Force re-activating
node.setActive();
if( setFocus ){
node.setFocus();
}
}
} | javascript | function(setFocus) {
var node = this.activeNode;
if( node ) {
this.activeNode = null; // Force re-activating
node.setActive();
if( setFocus ){
node.setFocus();
}
}
} | [
"function",
"(",
"setFocus",
")",
"{",
"var",
"node",
"=",
"this",
".",
"activeNode",
";",
"if",
"(",
"node",
")",
"{",
"this",
".",
"activeNode",
"=",
"null",
";",
"node",
".",
"setActive",
"(",
")",
";",
"if",
"(",
"setFocus",
")",
"{",
"node",
".",
"setFocus",
"(",
")",
";",
"}",
"}",
"}"
]
| Re-fire beforeActivate and activate events. | [
"Re",
"-",
"fire",
"beforeActivate",
"and",
"activate",
"events",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2195-L2204 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(ctx) {
// TODO: return promise?
if( ctx.targetType === "title" && ctx.options.clickFolderMode === 4) {
// this.nodeSetFocus(ctx);
// this._callHook("nodeSetActive", ctx, true);
this._callHook("nodeToggleExpanded", ctx);
}
// TODO: prevent text selection on dblclicks
if( ctx.targetType === "title" ) {
ctx.originalEvent.preventDefault();
}
} | javascript | function(ctx) {
// TODO: return promise?
if( ctx.targetType === "title" && ctx.options.clickFolderMode === 4) {
// this.nodeSetFocus(ctx);
// this._callHook("nodeSetActive", ctx, true);
this._callHook("nodeToggleExpanded", ctx);
}
// TODO: prevent text selection on dblclicks
if( ctx.targetType === "title" ) {
ctx.originalEvent.preventDefault();
}
} | [
"function",
"(",
"ctx",
")",
"{",
"if",
"(",
"ctx",
".",
"targetType",
"===",
"\"title\"",
"&&",
"ctx",
".",
"options",
".",
"clickFolderMode",
"===",
"4",
")",
"{",
"this",
".",
"_callHook",
"(",
"\"nodeToggleExpanded\"",
",",
"ctx",
")",
";",
"}",
"if",
"(",
"ctx",
".",
"targetType",
"===",
"\"title\"",
")",
"{",
"ctx",
".",
"originalEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"}"
]
| Default handling for mouse douleclick events.
@param {EventData} ctx | [
"Default",
"handling",
"for",
"mouse",
"douleclick",
"events",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2375-L2386 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(ctx) {
var node = ctx.node;
// FT.debug("nodeRemoveChildMarkup()", node.toString());
// TODO: Unlink attr.ftnode to support GC
if(node.ul){
if( node.isRoot() ) {
$(node.ul).empty();
} else {
$(node.ul).remove();
node.ul = null;
}
node.visit(function(n){
n.li = n.ul = null;
});
}
} | javascript | function(ctx) {
var node = ctx.node;
// FT.debug("nodeRemoveChildMarkup()", node.toString());
// TODO: Unlink attr.ftnode to support GC
if(node.ul){
if( node.isRoot() ) {
$(node.ul).empty();
} else {
$(node.ul).remove();
node.ul = null;
}
node.visit(function(n){
n.li = n.ul = null;
});
}
} | [
"function",
"(",
"ctx",
")",
"{",
"var",
"node",
"=",
"ctx",
".",
"node",
";",
"if",
"(",
"node",
".",
"ul",
")",
"{",
"if",
"(",
"node",
".",
"isRoot",
"(",
")",
")",
"{",
"$",
"(",
"node",
".",
"ul",
")",
".",
"empty",
"(",
")",
";",
"}",
"else",
"{",
"$",
"(",
"node",
".",
"ul",
")",
".",
"remove",
"(",
")",
";",
"node",
".",
"ul",
"=",
"null",
";",
"}",
"node",
".",
"visit",
"(",
"function",
"(",
"n",
")",
"{",
"n",
".",
"li",
"=",
"n",
".",
"ul",
"=",
"null",
";",
"}",
")",
";",
"}",
"}"
]
| Remove HTML markup for all descendents of ctx.node.
@param {EventData} ctx | [
"Remove",
"HTML",
"markup",
"for",
"all",
"descendents",
"of",
"ctx",
".",
"node",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2628-L2644 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(ctx, flag) {
// ctx.node.debug("nodeSetFocus(" + flag + ")");
var ctx2,
tree = ctx.tree,
node = ctx.node;
flag = (flag !== false);
// Blur previous node if any
if(tree.focusNode){
if(tree.focusNode === node && flag){
// node.debug("nodeSetFocus(" + flag + "): nothing to do");
return;
}
ctx2 = $.extend({}, ctx, {node: tree.focusNode});
tree.focusNode = null;
this._triggerNodeEvent("blur", ctx2);
this._callHook("nodeRenderStatus", ctx2);
}
// Set focus to container and node
if(flag){
if( !this.hasFocus() ){
node.debug("nodeSetFocus: forcing container focus");
// Note: we pass _calledByNodeSetFocus=true
this._callHook("treeSetFocus", ctx, true, true);
}
// this.nodeMakeVisible(ctx);
node.makeVisible({scrollIntoView: false});
tree.focusNode = node;
// node.debug("FOCUS...");
// $(node.span).find(".fancytree-title").focus();
this._triggerNodeEvent("focus", ctx);
// if(ctx.options.autoActivate){
// tree.nodeSetActive(ctx, true);
// }
if(ctx.options.autoScroll){
node.scrollIntoView();
}
this._callHook("nodeRenderStatus", ctx);
}
} | javascript | function(ctx, flag) {
// ctx.node.debug("nodeSetFocus(" + flag + ")");
var ctx2,
tree = ctx.tree,
node = ctx.node;
flag = (flag !== false);
// Blur previous node if any
if(tree.focusNode){
if(tree.focusNode === node && flag){
// node.debug("nodeSetFocus(" + flag + "): nothing to do");
return;
}
ctx2 = $.extend({}, ctx, {node: tree.focusNode});
tree.focusNode = null;
this._triggerNodeEvent("blur", ctx2);
this._callHook("nodeRenderStatus", ctx2);
}
// Set focus to container and node
if(flag){
if( !this.hasFocus() ){
node.debug("nodeSetFocus: forcing container focus");
// Note: we pass _calledByNodeSetFocus=true
this._callHook("treeSetFocus", ctx, true, true);
}
// this.nodeMakeVisible(ctx);
node.makeVisible({scrollIntoView: false});
tree.focusNode = node;
// node.debug("FOCUS...");
// $(node.span).find(".fancytree-title").focus();
this._triggerNodeEvent("focus", ctx);
// if(ctx.options.autoActivate){
// tree.nodeSetActive(ctx, true);
// }
if(ctx.options.autoScroll){
node.scrollIntoView();
}
this._callHook("nodeRenderStatus", ctx);
}
} | [
"function",
"(",
"ctx",
",",
"flag",
")",
"{",
"var",
"ctx2",
",",
"tree",
"=",
"ctx",
".",
"tree",
",",
"node",
"=",
"ctx",
".",
"node",
";",
"flag",
"=",
"(",
"flag",
"!==",
"false",
")",
";",
"if",
"(",
"tree",
".",
"focusNode",
")",
"{",
"if",
"(",
"tree",
".",
"focusNode",
"===",
"node",
"&&",
"flag",
")",
"{",
"return",
";",
"}",
"ctx2",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"ctx",
",",
"{",
"node",
":",
"tree",
".",
"focusNode",
"}",
")",
";",
"tree",
".",
"focusNode",
"=",
"null",
";",
"this",
".",
"_triggerNodeEvent",
"(",
"\"blur\"",
",",
"ctx2",
")",
";",
"this",
".",
"_callHook",
"(",
"\"nodeRenderStatus\"",
",",
"ctx2",
")",
";",
"}",
"if",
"(",
"flag",
")",
"{",
"if",
"(",
"!",
"this",
".",
"hasFocus",
"(",
")",
")",
"{",
"node",
".",
"debug",
"(",
"\"nodeSetFocus: forcing container focus\"",
")",
";",
"this",
".",
"_callHook",
"(",
"\"treeSetFocus\"",
",",
"ctx",
",",
"true",
",",
"true",
")",
";",
"}",
"node",
".",
"makeVisible",
"(",
"{",
"scrollIntoView",
":",
"false",
"}",
")",
";",
"tree",
".",
"focusNode",
"=",
"node",
";",
"this",
".",
"_triggerNodeEvent",
"(",
"\"focus\"",
",",
"ctx",
")",
";",
"if",
"(",
"ctx",
".",
"options",
".",
"autoScroll",
")",
"{",
"node",
".",
"scrollIntoView",
"(",
")",
";",
"}",
"this",
".",
"_callHook",
"(",
"\"nodeRenderStatus\"",
",",
"ctx",
")",
";",
"}",
"}"
]
| Focus ot blur this node.
@param {EventData} ctx
@param {boolean} [flag=true] | [
"Focus",
"ot",
"blur",
"this",
"node",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L3302-L3342 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(el){
if(el instanceof FancytreeNode){
return el; // el already was a FancytreeNode
}else if(el.selector !== undefined){
el = el[0]; // el was a jQuery object: use the DOM element
}else if(el.originalEvent !== undefined){
el = el.target; // el was an Event
}
while( el ) {
if(el.ftnode) {
return el.ftnode;
}
el = el.parentNode;
}
return null;
} | javascript | function(el){
if(el instanceof FancytreeNode){
return el; // el already was a FancytreeNode
}else if(el.selector !== undefined){
el = el[0]; // el was a jQuery object: use the DOM element
}else if(el.originalEvent !== undefined){
el = el.target; // el was an Event
}
while( el ) {
if(el.ftnode) {
return el.ftnode;
}
el = el.parentNode;
}
return null;
} | [
"function",
"(",
"el",
")",
"{",
"if",
"(",
"el",
"instanceof",
"FancytreeNode",
")",
"{",
"return",
"el",
";",
"}",
"else",
"if",
"(",
"el",
".",
"selector",
"!==",
"undefined",
")",
"{",
"el",
"=",
"el",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"el",
".",
"originalEvent",
"!==",
"undefined",
")",
"{",
"el",
"=",
"el",
".",
"target",
";",
"}",
"while",
"(",
"el",
")",
"{",
"if",
"(",
"el",
".",
"ftnode",
")",
"{",
"return",
"el",
".",
"ftnode",
";",
"}",
"el",
"=",
"el",
".",
"parentNode",
";",
"}",
"return",
"null",
";",
"}"
]
| Return a FancytreeNode instance from element.
@param {Element | jQueryObject | Event} el
@returns {FancytreeNode} matching node or null | [
"Return",
"a",
"FancytreeNode",
"instance",
"from",
"element",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4033-L4048 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(ctx, title) {
var node = ctx.node,
extOpts = ctx.options.childcounter,
count = (node.data.childCounter == null) ? node.countChildren(extOpts.deep) : +node.data.childCounter;
// Let the base implementation render the title
this._super(ctx, title);
// Append a counter badge
if( (count || ! extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ){
$("span.fancytree-icon", node.span).append($("<span class='fancytree-childcounter'/>").text(count));
}
} | javascript | function(ctx, title) {
var node = ctx.node,
extOpts = ctx.options.childcounter,
count = (node.data.childCounter == null) ? node.countChildren(extOpts.deep) : +node.data.childCounter;
// Let the base implementation render the title
this._super(ctx, title);
// Append a counter badge
if( (count || ! extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ){
$("span.fancytree-icon", node.span).append($("<span class='fancytree-childcounter'/>").text(count));
}
} | [
"function",
"(",
"ctx",
",",
"title",
")",
"{",
"var",
"node",
"=",
"ctx",
".",
"node",
",",
"extOpts",
"=",
"ctx",
".",
"options",
".",
"childcounter",
",",
"count",
"=",
"(",
"node",
".",
"data",
".",
"childCounter",
"==",
"null",
")",
"?",
"node",
".",
"countChildren",
"(",
"extOpts",
".",
"deep",
")",
":",
"+",
"node",
".",
"data",
".",
"childCounter",
";",
"this",
".",
"_super",
"(",
"ctx",
",",
"title",
")",
";",
"if",
"(",
"(",
"count",
"||",
"!",
"extOpts",
".",
"hideZeros",
")",
"&&",
"(",
"!",
"node",
".",
"isExpanded",
"(",
")",
"||",
"!",
"extOpts",
".",
"hideExpanded",
")",
")",
"{",
"$",
"(",
"\"span.fancytree-icon\"",
",",
"node",
".",
"span",
")",
".",
"append",
"(",
"$",
"(",
"\"<span class='fancytree-childcounter'/>\"",
")",
".",
"text",
"(",
"count",
")",
")",
";",
"}",
"}"
]
| Overload the `renderTitle` hook, to append a counter badge | [
"Overload",
"the",
"renderTitle",
"hook",
"to",
"append",
"a",
"counter",
"badge"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4345-L4355 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js | function(event) {
var sourceNode = $.ui.fancytree.getNode(event.target);
if(!sourceNode){ // Dynatree issue 211
// might happen, if dragging a table *header*
return "<div>ERROR?: helper requested but sourceNode not found</div>";
}
return sourceNode.tree.ext.dnd._onDragEvent("helper", sourceNode, null, event, null, null);
} | javascript | function(event) {
var sourceNode = $.ui.fancytree.getNode(event.target);
if(!sourceNode){ // Dynatree issue 211
// might happen, if dragging a table *header*
return "<div>ERROR?: helper requested but sourceNode not found</div>";
}
return sourceNode.tree.ext.dnd._onDragEvent("helper", sourceNode, null, event, null, null);
} | [
"function",
"(",
"event",
")",
"{",
"var",
"sourceNode",
"=",
"$",
".",
"ui",
".",
"fancytree",
".",
"getNode",
"(",
"event",
".",
"target",
")",
";",
"if",
"(",
"!",
"sourceNode",
")",
"{",
"return",
"\"<div>ERROR?: helper requested but sourceNode not found</div>\"",
";",
"}",
"return",
"sourceNode",
".",
"tree",
".",
"ext",
".",
"dnd",
".",
"_onDragEvent",
"(",
"\"helper\"",
",",
"sourceNode",
",",
"null",
",",
"event",
",",
"null",
",",
"null",
")",
";",
"}"
]
| Let source tree create the helper element | [
"Let",
"source",
"tree",
"create",
"the",
"helper",
"element"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4872-L4879 | train |
|
lemonde/knex-schema | lib/resolver.js | isResolved | function isResolved(schema, schemas) {
return (schema.deps || []).every(_.partial(function (tableNames, tableName) {
return tableNames.indexOf(tableName) > -1;
}, _.pluck(schemas, 'tableName')));
} | javascript | function isResolved(schema, schemas) {
return (schema.deps || []).every(_.partial(function (tableNames, tableName) {
return tableNames.indexOf(tableName) > -1;
}, _.pluck(schemas, 'tableName')));
} | [
"function",
"isResolved",
"(",
"schema",
",",
"schemas",
")",
"{",
"return",
"(",
"schema",
".",
"deps",
"||",
"[",
"]",
")",
".",
"every",
"(",
"_",
".",
"partial",
"(",
"function",
"(",
"tableNames",
",",
"tableName",
")",
"{",
"return",
"tableNames",
".",
"indexOf",
"(",
"tableName",
")",
">",
"-",
"1",
";",
"}",
",",
"_",
".",
"pluck",
"(",
"schemas",
",",
"'tableName'",
")",
")",
")",
";",
"}"
]
| Return true if given schema.deps meet
schemas entries.
@param Schema schema
@param [Schema] schemas
@return {Boolean} | [
"Return",
"true",
"if",
"given",
"schema",
".",
"deps",
"meet",
"schemas",
"entries",
"."
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/resolver.js#L55-L59 | train |
vadimdemedes/list-dir | index.js | listDir | function listDir (path, originalPath) {
if (!originalPath) {
originalPath = path + separator;
}
// promises for sub listDir calls
var dirs = [];
return Promise.resolve(fs.readdir(path))
// include only files
.filter(function (item) {
var absolutePath = join(path, item);
return fs.stat(absolutePath).then(function (stat) {
var isDirectory = stat.isDirectory();
// if directory, read it
if (isDirectory) {
var list = listDir(absolutePath, originalPath);
dirs.push(list);
}
return !isDirectory;
});
})
// return relative paths
.map(function (file) {
var absolutePath = join(path, file);
var relativePath = absolutePath.replace(originalPath, '');
return relativePath;
})
// add files from sub-directories
.then(function (files) {
// wait for all listDir() to complete
// and merge their results
return Promise
.all(dirs)
.then(function () {
dirs.forEach(function (promise) {
var subFiles = promise.value();
files = files.concat(subFiles);
});
return files;
});
});
} | javascript | function listDir (path, originalPath) {
if (!originalPath) {
originalPath = path + separator;
}
// promises for sub listDir calls
var dirs = [];
return Promise.resolve(fs.readdir(path))
// include only files
.filter(function (item) {
var absolutePath = join(path, item);
return fs.stat(absolutePath).then(function (stat) {
var isDirectory = stat.isDirectory();
// if directory, read it
if (isDirectory) {
var list = listDir(absolutePath, originalPath);
dirs.push(list);
}
return !isDirectory;
});
})
// return relative paths
.map(function (file) {
var absolutePath = join(path, file);
var relativePath = absolutePath.replace(originalPath, '');
return relativePath;
})
// add files from sub-directories
.then(function (files) {
// wait for all listDir() to complete
// and merge their results
return Promise
.all(dirs)
.then(function () {
dirs.forEach(function (promise) {
var subFiles = promise.value();
files = files.concat(subFiles);
});
return files;
});
});
} | [
"function",
"listDir",
"(",
"path",
",",
"originalPath",
")",
"{",
"if",
"(",
"!",
"originalPath",
")",
"{",
"originalPath",
"=",
"path",
"+",
"separator",
";",
"}",
"var",
"dirs",
"=",
"[",
"]",
";",
"return",
"Promise",
".",
"resolve",
"(",
"fs",
".",
"readdir",
"(",
"path",
")",
")",
".",
"filter",
"(",
"function",
"(",
"item",
")",
"{",
"var",
"absolutePath",
"=",
"join",
"(",
"path",
",",
"item",
")",
";",
"return",
"fs",
".",
"stat",
"(",
"absolutePath",
")",
".",
"then",
"(",
"function",
"(",
"stat",
")",
"{",
"var",
"isDirectory",
"=",
"stat",
".",
"isDirectory",
"(",
")",
";",
"if",
"(",
"isDirectory",
")",
"{",
"var",
"list",
"=",
"listDir",
"(",
"absolutePath",
",",
"originalPath",
")",
";",
"dirs",
".",
"push",
"(",
"list",
")",
";",
"}",
"return",
"!",
"isDirectory",
";",
"}",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"absolutePath",
"=",
"join",
"(",
"path",
",",
"file",
")",
";",
"var",
"relativePath",
"=",
"absolutePath",
".",
"replace",
"(",
"originalPath",
",",
"''",
")",
";",
"return",
"relativePath",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"files",
")",
"{",
"return",
"Promise",
".",
"all",
"(",
"dirs",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"dirs",
".",
"forEach",
"(",
"function",
"(",
"promise",
")",
"{",
"var",
"subFiles",
"=",
"promise",
".",
"value",
"(",
")",
";",
"files",
"=",
"files",
".",
"concat",
"(",
"subFiles",
")",
";",
"}",
")",
";",
"return",
"files",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| List directory recursively
@param {String} path
@return {Promise} | [
"List",
"directory",
"recursively"
]
| 4efce85e42e7e6f0eca7f22bbc5abf0af282596d | https://github.com/vadimdemedes/list-dir/blob/4efce85e42e7e6f0eca7f22bbc5abf0af282596d/index.js#L29-L78 | train |
jxson/haiku | lib/page.js | read | function read(src, basedir, callback){
var page = new Page(src, basedir)
page.read(callback)
} | javascript | function read(src, basedir, callback){
var page = new Page(src, basedir)
page.read(callback)
} | [
"function",
"read",
"(",
"src",
",",
"basedir",
",",
"callback",
")",
"{",
"var",
"page",
"=",
"new",
"Page",
"(",
"src",
",",
"basedir",
")",
"page",
".",
"read",
"(",
"callback",
")",
"}"
]
| Async read and instantiate a page from a file | [
"Async",
"read",
"and",
"instantiate",
"a",
"page",
"from",
"a",
"file"
]
| d7dcb3c3b39012082277cf0ed1bcb5c91440c76e | https://github.com/jxson/haiku/blob/d7dcb3c3b39012082277cf0ed1bcb5c91440c76e/lib/page.js#L13-L17 | train |
Knorcedger/apier | index.js | apier | function apier(config) {
// on server start..
db.connect(config.mongoUrl);
accessVerifier.init(config.access);
schemaExtender.handleErrors = true;
reqlog.info('apier initialized!!');
var app = function(req, res) {
// this is the final handler if no match found
router(req, res, function(error) {
if (error) {
reqlog.error(error);
responseBuilder.error(req, res, 'INTERNAL_SERVER_ERROR');
} else {
reqlog.info('NOT_FOUND:', req.method + ' ' + req.url);
responseBuilder.error(req, res, 'NOT_FOUND');
}
});
};
app.endpoint = endpoint;
return app;
} | javascript | function apier(config) {
// on server start..
db.connect(config.mongoUrl);
accessVerifier.init(config.access);
schemaExtender.handleErrors = true;
reqlog.info('apier initialized!!');
var app = function(req, res) {
// this is the final handler if no match found
router(req, res, function(error) {
if (error) {
reqlog.error(error);
responseBuilder.error(req, res, 'INTERNAL_SERVER_ERROR');
} else {
reqlog.info('NOT_FOUND:', req.method + ' ' + req.url);
responseBuilder.error(req, res, 'NOT_FOUND');
}
});
};
app.endpoint = endpoint;
return app;
} | [
"function",
"apier",
"(",
"config",
")",
"{",
"db",
".",
"connect",
"(",
"config",
".",
"mongoUrl",
")",
";",
"accessVerifier",
".",
"init",
"(",
"config",
".",
"access",
")",
";",
"schemaExtender",
".",
"handleErrors",
"=",
"true",
";",
"reqlog",
".",
"info",
"(",
"'apier initialized!!'",
")",
";",
"var",
"app",
"=",
"function",
"(",
"req",
",",
"res",
")",
"{",
"router",
"(",
"req",
",",
"res",
",",
"function",
"(",
"error",
")",
"{",
"if",
"(",
"error",
")",
"{",
"reqlog",
".",
"error",
"(",
"error",
")",
";",
"responseBuilder",
".",
"error",
"(",
"req",
",",
"res",
",",
"'INTERNAL_SERVER_ERROR'",
")",
";",
"}",
"else",
"{",
"reqlog",
".",
"info",
"(",
"'NOT_FOUND:'",
",",
"req",
".",
"method",
"+",
"' '",
"+",
"req",
".",
"url",
")",
";",
"responseBuilder",
".",
"error",
"(",
"req",
",",
"res",
",",
"'NOT_FOUND'",
")",
";",
"}",
"}",
")",
";",
"}",
";",
"app",
".",
"endpoint",
"=",
"endpoint",
";",
"return",
"app",
";",
"}"
]
| Create an apier app
@method apier
@param {object} config The app configuration
It must contain the following options
mongoUrl: String. The mongo url to connect to
handleErrors: Boolean. Define if the schemaExtender will handle the db errors
@return {Function} The app to use as server | [
"Create",
"an",
"apier",
"app"
]
| de980ebc7656459656d0c850f6584e4da3761b53 | https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L26-L49 | train |
Knorcedger/apier | index.js | endpoint | function endpoint(options) {
// find the middlewares
options.permissions = options.permissions || ['null'];
options.middlewares = options.middlewares || [];
options.middlewares.unshift([permissioner(options.permissions)]);
for (var i = 0, length = options.methods.length; i < length; i++) {
var method = options.methods[i].toLowerCase();
reqlog.log('setup endpoint', method + ' ' + options.url);
router[method](options.url, options.middlewares,
function(req, res) {
routerCallback(req, res, options.callback);
});
}
} | javascript | function endpoint(options) {
// find the middlewares
options.permissions = options.permissions || ['null'];
options.middlewares = options.middlewares || [];
options.middlewares.unshift([permissioner(options.permissions)]);
for (var i = 0, length = options.methods.length; i < length; i++) {
var method = options.methods[i].toLowerCase();
reqlog.log('setup endpoint', method + ' ' + options.url);
router[method](options.url, options.middlewares,
function(req, res) {
routerCallback(req, res, options.callback);
});
}
} | [
"function",
"endpoint",
"(",
"options",
")",
"{",
"options",
".",
"permissions",
"=",
"options",
".",
"permissions",
"||",
"[",
"'null'",
"]",
";",
"options",
".",
"middlewares",
"=",
"options",
".",
"middlewares",
"||",
"[",
"]",
";",
"options",
".",
"middlewares",
".",
"unshift",
"(",
"[",
"permissioner",
"(",
"options",
".",
"permissions",
")",
"]",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"length",
"=",
"options",
".",
"methods",
".",
"length",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"var",
"method",
"=",
"options",
".",
"methods",
"[",
"i",
"]",
".",
"toLowerCase",
"(",
")",
";",
"reqlog",
".",
"log",
"(",
"'setup endpoint'",
",",
"method",
"+",
"' '",
"+",
"options",
".",
"url",
")",
";",
"router",
"[",
"method",
"]",
"(",
"options",
".",
"url",
",",
"options",
".",
"middlewares",
",",
"function",
"(",
"req",
",",
"res",
")",
"{",
"routerCallback",
"(",
"req",
",",
"res",
",",
"options",
".",
"callback",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Create an endpoint
@method endpoint
@param {object} options It contains the following options
methods: Array. Can contain 'post', 'get', 'delete', 'put'
url: String. The matching url e.g. /users, /users/:id/update
middlewares: Array. The middlewares (functions) that will be called before the callback
permissions: Array (optional). Docs: https://github.com/Knorcedger/apier-permissioner
if no permissions given, 'null' (public service) is assumed
callback: Function. The callback function to execute | [
"Create",
"an",
"endpoint"
]
| de980ebc7656459656d0c850f6584e4da3761b53 | https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L80-L95 | train |
Knorcedger/apier | index.js | routerCallback | function routerCallback(req, res, callback) {
var innerSelf = {
req: req,
res: res,
send: function(data) {
send.call(this, data);
},
setStatusCode: function(statusCode) {
setStatusCode.call(this, statusCode);
}
};
reqlog.info('inside routerCallback for endpoint: ', req.url);
callback.call(innerSelf, req, res);
} | javascript | function routerCallback(req, res, callback) {
var innerSelf = {
req: req,
res: res,
send: function(data) {
send.call(this, data);
},
setStatusCode: function(statusCode) {
setStatusCode.call(this, statusCode);
}
};
reqlog.info('inside routerCallback for endpoint: ', req.url);
callback.call(innerSelf, req, res);
} | [
"function",
"routerCallback",
"(",
"req",
",",
"res",
",",
"callback",
")",
"{",
"var",
"innerSelf",
"=",
"{",
"req",
":",
"req",
",",
"res",
":",
"res",
",",
"send",
":",
"function",
"(",
"data",
")",
"{",
"send",
".",
"call",
"(",
"this",
",",
"data",
")",
";",
"}",
",",
"setStatusCode",
":",
"function",
"(",
"statusCode",
")",
"{",
"setStatusCode",
".",
"call",
"(",
"this",
",",
"statusCode",
")",
";",
"}",
"}",
";",
"reqlog",
".",
"info",
"(",
"'inside routerCallback for endpoint: '",
",",
"req",
".",
"url",
")",
";",
"callback",
".",
"call",
"(",
"innerSelf",
",",
"req",
",",
"res",
")",
";",
"}"
]
| Defines the endpoint callback passed into the router
create an object to apply as this in the callback
its used to be able to call the send function inside the callback
without having to also pass the req and res
@method routerCallback
@param {object} req A request object
@param {object} res A response object
@param {Function} callback The user defined endpoint callback | [
"Defines",
"the",
"endpoint",
"callback",
"passed",
"into",
"the",
"router"
]
| de980ebc7656459656d0c850f6584e4da3761b53 | https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L128-L141 | train |
lemonde/knex-schema | lib/sync.js | sync | function sync(schemas) {
var resolver = new Resolver(schemas);
// Reduce force sequential execution.
return Promise.resolve(Promise.reduce(resolver.resolve(), syncSchema.bind(this), []))
.tap(function () {
var knex = this.knex;
return Promise.map(schemas || [], function(schema) {
return (schema.postBuild || _.noop)(knex);
});
}.bind(this));
} | javascript | function sync(schemas) {
var resolver = new Resolver(schemas);
// Reduce force sequential execution.
return Promise.resolve(Promise.reduce(resolver.resolve(), syncSchema.bind(this), []))
.tap(function () {
var knex = this.knex;
return Promise.map(schemas || [], function(schema) {
return (schema.postBuild || _.noop)(knex);
});
}.bind(this));
} | [
"function",
"sync",
"(",
"schemas",
")",
"{",
"var",
"resolver",
"=",
"new",
"Resolver",
"(",
"schemas",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
"Promise",
".",
"reduce",
"(",
"resolver",
".",
"resolve",
"(",
")",
",",
"syncSchema",
".",
"bind",
"(",
"this",
")",
",",
"[",
"]",
")",
")",
".",
"tap",
"(",
"function",
"(",
")",
"{",
"var",
"knex",
"=",
"this",
".",
"knex",
";",
"return",
"Promise",
".",
"map",
"(",
"schemas",
"||",
"[",
"]",
",",
"function",
"(",
"schema",
")",
"{",
"return",
"(",
"schema",
".",
"postBuild",
"||",
"_",
".",
"noop",
")",
"(",
"knex",
")",
";",
"}",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
]
| Synchronize given schemas with database. If it exists, it calls `postBuild` afterwards
@param {[Schemas]} schemas
@return {Promise} | [
"Synchronize",
"given",
"schemas",
"with",
"database",
".",
"If",
"it",
"exists",
"it",
"calls",
"postBuild",
"afterwards"
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L20-L30 | train |
lemonde/knex-schema | lib/sync.js | syncSchema | function syncSchema(result, schema) {
var knex = this.knex;
return knex.schema.hasTable(schema.tableName)
.then(function (exists) {
if (exists) return result;
return knex.schema.createTable(schema.tableName, defineSchemaTable(schema))
.then(function () {
return result.concat([schema]);
});
});
} | javascript | function syncSchema(result, schema) {
var knex = this.knex;
return knex.schema.hasTable(schema.tableName)
.then(function (exists) {
if (exists) return result;
return knex.schema.createTable(schema.tableName, defineSchemaTable(schema))
.then(function () {
return result.concat([schema]);
});
});
} | [
"function",
"syncSchema",
"(",
"result",
",",
"schema",
")",
"{",
"var",
"knex",
"=",
"this",
".",
"knex",
";",
"return",
"knex",
".",
"schema",
".",
"hasTable",
"(",
"schema",
".",
"tableName",
")",
".",
"then",
"(",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"exists",
")",
"return",
"result",
";",
"return",
"knex",
".",
"schema",
".",
"createTable",
"(",
"schema",
".",
"tableName",
",",
"defineSchemaTable",
"(",
"schema",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"result",
".",
"concat",
"(",
"[",
"schema",
"]",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Synchronize given schema with database.
@param {[Schema]} result - reduce accumulator
@param {Schema} schema
@return {Promise} | [
"Synchronize",
"given",
"schema",
"with",
"database",
"."
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L40-L50 | train |
lemonde/knex-schema | lib/sync.js | defineSchemaTable | function defineSchemaTable(schema) {
return function (table) {
table.timestamps();
(schema.build || _.noop)(table);
};
} | javascript | function defineSchemaTable(schema) {
return function (table) {
table.timestamps();
(schema.build || _.noop)(table);
};
} | [
"function",
"defineSchemaTable",
"(",
"schema",
")",
"{",
"return",
"function",
"(",
"table",
")",
"{",
"table",
".",
"timestamps",
"(",
")",
";",
"(",
"schema",
".",
"build",
"||",
"_",
".",
"noop",
")",
"(",
"table",
")",
";",
"}",
";",
"}"
]
| Define default properties on the given schema.
@param {Schema} schema
@return {Function} | [
"Define",
"default",
"properties",
"on",
"the",
"given",
"schema",
"."
]
| 3e0f6cde374d240552eb08e50e123a513fda44ae | https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L59-L64 | train |
gflarity/response | lib/graphite.js | function( data ) {
var read_buffer = read_buffers_by_connection[tcp_connection];
read_buffer += data;
//split by new lines,
var messages = read_buffer.split('\n');
//last element is either a partial message, or ''
read_buffer = messages.pop();
for ( var i = 0; i < messages.length; i++ ) {
//TODO error handling
var message = messages[i];
var components = message.split( ' ' );
var path = components[0];
var value = components[1];
var timestamp = components[2];
that.emit( path, value, timestamp );
}
} | javascript | function( data ) {
var read_buffer = read_buffers_by_connection[tcp_connection];
read_buffer += data;
//split by new lines,
var messages = read_buffer.split('\n');
//last element is either a partial message, or ''
read_buffer = messages.pop();
for ( var i = 0; i < messages.length; i++ ) {
//TODO error handling
var message = messages[i];
var components = message.split( ' ' );
var path = components[0];
var value = components[1];
var timestamp = components[2];
that.emit( path, value, timestamp );
}
} | [
"function",
"(",
"data",
")",
"{",
"var",
"read_buffer",
"=",
"read_buffers_by_connection",
"[",
"tcp_connection",
"]",
";",
"read_buffer",
"+=",
"data",
";",
"var",
"messages",
"=",
"read_buffer",
".",
"split",
"(",
"'\\n'",
")",
";",
"\\n",
"read_buffer",
"=",
"messages",
".",
"pop",
"(",
")",
";",
"}"
]
| setup our handlers for this connection data | [
"setup",
"our",
"handlers",
"for",
"this",
"connection",
"data"
]
| bf1f7342afbdf460970935e61abda14d8ef947fe | https://github.com/gflarity/response/blob/bf1f7342afbdf460970935e61abda14d8ef947fe/lib/graphite.js#L34-L57 | train |
|
kaelzhang/make-array | index.js | isArrayLikeObject | function isArrayLikeObject (subject) {
var length = subject.length
if (
typeof subject === 'function'
|| Object(subject) !== subject
|| typeof length !== 'number'
// `window` already has a property `length`
|| 'setInterval' in subject
) {
return false
}
return length === 0
|| length > 0 && (length - 1) in subject
} | javascript | function isArrayLikeObject (subject) {
var length = subject.length
if (
typeof subject === 'function'
|| Object(subject) !== subject
|| typeof length !== 'number'
// `window` already has a property `length`
|| 'setInterval' in subject
) {
return false
}
return length === 0
|| length > 0 && (length - 1) in subject
} | [
"function",
"isArrayLikeObject",
"(",
"subject",
")",
"{",
"var",
"length",
"=",
"subject",
".",
"length",
"if",
"(",
"typeof",
"subject",
"===",
"'function'",
"||",
"Object",
"(",
"subject",
")",
"!==",
"subject",
"||",
"typeof",
"length",
"!==",
"'number'",
"||",
"'setInterval'",
"in",
"subject",
")",
"{",
"return",
"false",
"}",
"return",
"length",
"===",
"0",
"||",
"length",
">",
"0",
"&&",
"(",
"length",
"-",
"1",
")",
"in",
"subject",
"}"
]
| altered from jQuery | [
"altered",
"from",
"jQuery"
]
| 4e04c3fe7586ccb3fe1e96d06aa694df0c656327 | https://github.com/kaelzhang/make-array/blob/4e04c3fe7586ccb3fe1e96d06aa694df0c656327/index.js#L40-L55 | train |
kaelzhang/make-array | index.js | clonePureArray | function clonePureArray (subject, host) {
var i = subject.length
var start = host.length
while (i --) {
host[start + i] = subject[i]
}
return host
} | javascript | function clonePureArray (subject, host) {
var i = subject.length
var start = host.length
while (i --) {
host[start + i] = subject[i]
}
return host
} | [
"function",
"clonePureArray",
"(",
"subject",
",",
"host",
")",
"{",
"var",
"i",
"=",
"subject",
".",
"length",
"var",
"start",
"=",
"host",
".",
"length",
"while",
"(",
"i",
"--",
")",
"{",
"host",
"[",
"start",
"+",
"i",
"]",
"=",
"subject",
"[",
"i",
"]",
"}",
"return",
"host",
"}"
]
| clone an object as a pure subject, and ignore non-number properties
@param {Array} subject
@param {Array|Object} host required, receiver which the subject be cloned to | [
"clone",
"an",
"object",
"as",
"a",
"pure",
"subject",
"and",
"ignore",
"non",
"-",
"number",
"properties"
]
| 4e04c3fe7586ccb3fe1e96d06aa694df0c656327 | https://github.com/kaelzhang/make-array/blob/4e04c3fe7586ccb3fe1e96d06aa694df0c656327/index.js#L62-L71 | train |
emeryrose/mtree | lib/tree.js | MerkleTree | function MerkleTree(leaves, hasher) {
if (!(this instanceof MerkleTree)) {
return new MerkleTree(leaves, hasher);
}
this._hasher = hasher || this._hasher;
this._leaves = [];
this._depth = 0;
this._rows = [];
this._count = 0;
assert(Array.isArray(leaves), 'Invalid leaves array supplied');
assert(typeof this._hasher === 'function', 'Invalid hash function supplied');
for (var i = 0; i < leaves.length; i++) {
this._feed(leaves[i]);
}
this._compute();
} | javascript | function MerkleTree(leaves, hasher) {
if (!(this instanceof MerkleTree)) {
return new MerkleTree(leaves, hasher);
}
this._hasher = hasher || this._hasher;
this._leaves = [];
this._depth = 0;
this._rows = [];
this._count = 0;
assert(Array.isArray(leaves), 'Invalid leaves array supplied');
assert(typeof this._hasher === 'function', 'Invalid hash function supplied');
for (var i = 0; i < leaves.length; i++) {
this._feed(leaves[i]);
}
this._compute();
} | [
"function",
"MerkleTree",
"(",
"leaves",
",",
"hasher",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"MerkleTree",
")",
")",
"{",
"return",
"new",
"MerkleTree",
"(",
"leaves",
",",
"hasher",
")",
";",
"}",
"this",
".",
"_hasher",
"=",
"hasher",
"||",
"this",
".",
"_hasher",
";",
"this",
".",
"_leaves",
"=",
"[",
"]",
";",
"this",
".",
"_depth",
"=",
"0",
";",
"this",
".",
"_rows",
"=",
"[",
"]",
";",
"this",
".",
"_count",
"=",
"0",
";",
"assert",
"(",
"Array",
".",
"isArray",
"(",
"leaves",
")",
",",
"'Invalid leaves array supplied'",
")",
";",
"assert",
"(",
"typeof",
"this",
".",
"_hasher",
"===",
"'function'",
",",
"'Invalid hash function supplied'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"leaves",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"_feed",
"(",
"leaves",
"[",
"i",
"]",
")",
";",
"}",
"this",
".",
"_compute",
"(",
")",
";",
"}"
]
| Implements a merkle hash tree
@constructor
@param {Array} leaves - Initial tree input
@param {Function} hasher - Hash function for building tree | [
"Implements",
"a",
"merkle",
"hash",
"tree"
]
| 21428212a4955d0498f1272c7df17645dcc379f6 | https://github.com/emeryrose/mtree/blob/21428212a4955d0498f1272c7df17645dcc379f6/lib/tree.js#L12-L31 | train |
ofzza/enTT | tasks/index.js | queueTasks | function queueTasks (testTasks, buildTasks) {
// Queue up test tasks, removing them if already queued up
_.forEach({ test: testTasks, build: buildTasks }, (queuingTasks, type) => {
_.forEach(queuingTasks, (task) => {
// Remove if already queued
const removed = _.remove(queue[type], (queuedTask) => { return (queuedTask === task); });
// Queue task ...
queue[type].push(task);
// Reorder tasks by original configuration ordering
queue[type] = _.sortBy(queue[type], (queuedTask) => {
return _.findIndex(orderedTasks, (originalTask) => {
return (originalTask === queuedTask);
});
});
// Prompt queued task
console.log(`> ${removed.length ? 'Requeued' : 'Queued'} ${ type } task for execution: "${ task.blue }"`);
console.log(` Queue: ${ [...queue.test, ...queue.build].join(', ').gray }`);
});
});
// Execute tasks from the queue
executeQueuedTasks();
} | javascript | function queueTasks (testTasks, buildTasks) {
// Queue up test tasks, removing them if already queued up
_.forEach({ test: testTasks, build: buildTasks }, (queuingTasks, type) => {
_.forEach(queuingTasks, (task) => {
// Remove if already queued
const removed = _.remove(queue[type], (queuedTask) => { return (queuedTask === task); });
// Queue task ...
queue[type].push(task);
// Reorder tasks by original configuration ordering
queue[type] = _.sortBy(queue[type], (queuedTask) => {
return _.findIndex(orderedTasks, (originalTask) => {
return (originalTask === queuedTask);
});
});
// Prompt queued task
console.log(`> ${removed.length ? 'Requeued' : 'Queued'} ${ type } task for execution: "${ task.blue }"`);
console.log(` Queue: ${ [...queue.test, ...queue.build].join(', ').gray }`);
});
});
// Execute tasks from the queue
executeQueuedTasks();
} | [
"function",
"queueTasks",
"(",
"testTasks",
",",
"buildTasks",
")",
"{",
"_",
".",
"forEach",
"(",
"{",
"test",
":",
"testTasks",
",",
"build",
":",
"buildTasks",
"}",
",",
"(",
"queuingTasks",
",",
"type",
")",
"=>",
"{",
"_",
".",
"forEach",
"(",
"queuingTasks",
",",
"(",
"task",
")",
"=>",
"{",
"const",
"removed",
"=",
"_",
".",
"remove",
"(",
"queue",
"[",
"type",
"]",
",",
"(",
"queuedTask",
")",
"=>",
"{",
"return",
"(",
"queuedTask",
"===",
"task",
")",
";",
"}",
")",
";",
"queue",
"[",
"type",
"]",
".",
"push",
"(",
"task",
")",
";",
"queue",
"[",
"type",
"]",
"=",
"_",
".",
"sortBy",
"(",
"queue",
"[",
"type",
"]",
",",
"(",
"queuedTask",
")",
"=>",
"{",
"return",
"_",
".",
"findIndex",
"(",
"orderedTasks",
",",
"(",
"originalTask",
")",
"=>",
"{",
"return",
"(",
"originalTask",
"===",
"queuedTask",
")",
";",
"}",
")",
";",
"}",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"removed",
".",
"length",
"?",
"'Requeued'",
":",
"'Queued'",
"}",
"${",
"type",
"}",
"${",
"task",
".",
"blue",
"}",
"`",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"[",
"...",
"queue",
".",
"test",
",",
"...",
"queue",
".",
"build",
"]",
".",
"join",
"(",
"', '",
")",
".",
"gray",
"}",
"`",
")",
";",
"}",
")",
";",
"}",
")",
";",
"executeQueuedTasks",
"(",
")",
";",
"}"
]
| Queues up tasks for execution
@param {any} testTasks Array of test tasks names
@param {any} buildTasks Array of build task names | [
"Queues",
"up",
"tasks",
"for",
"execution"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/tasks/index.js#L81-L102 | train |
ofzza/enTT | tasks/index.js | executeQueuedTasks | function executeQueuedTasks () {
// Delay execution to allow for more tasks to queue up
setTimeout(() => {
// Check if already executing and if any tasks ready for execution
if (!executing && (queue.test.length || queue.build.length)) {
// Flag executing status
executing = true;
// Pop a task from the execution queue
const task = (queue.test.length ? queue.test.splice(0, 1)[0] : queue.build.splice(0, 1)[0]);
// Execute task
gulp.series([task])(() => {
// Flag executing status
executing = false;
// Execute next task from the queue
executeQueuedTasks();
});
}
}, 250);
// If no tasks queued up, prompt watcher done
if (!executing && !(queue.test.length || queue.build.length)) {
console.log();
console.log(`> WATCHER(S) DONE PROCESSING - WAITING FOR CHANGES ...`.green);
console.log();
}
} | javascript | function executeQueuedTasks () {
// Delay execution to allow for more tasks to queue up
setTimeout(() => {
// Check if already executing and if any tasks ready for execution
if (!executing && (queue.test.length || queue.build.length)) {
// Flag executing status
executing = true;
// Pop a task from the execution queue
const task = (queue.test.length ? queue.test.splice(0, 1)[0] : queue.build.splice(0, 1)[0]);
// Execute task
gulp.series([task])(() => {
// Flag executing status
executing = false;
// Execute next task from the queue
executeQueuedTasks();
});
}
}, 250);
// If no tasks queued up, prompt watcher done
if (!executing && !(queue.test.length || queue.build.length)) {
console.log();
console.log(`> WATCHER(S) DONE PROCESSING - WAITING FOR CHANGES ...`.green);
console.log();
}
} | [
"function",
"executeQueuedTasks",
"(",
")",
"{",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"!",
"executing",
"&&",
"(",
"queue",
".",
"test",
".",
"length",
"||",
"queue",
".",
"build",
".",
"length",
")",
")",
"{",
"executing",
"=",
"true",
";",
"const",
"task",
"=",
"(",
"queue",
".",
"test",
".",
"length",
"?",
"queue",
".",
"test",
".",
"splice",
"(",
"0",
",",
"1",
")",
"[",
"0",
"]",
":",
"queue",
".",
"build",
".",
"splice",
"(",
"0",
",",
"1",
")",
"[",
"0",
"]",
")",
";",
"gulp",
".",
"series",
"(",
"[",
"task",
"]",
")",
"(",
"(",
")",
"=>",
"{",
"executing",
"=",
"false",
";",
"executeQueuedTasks",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
",",
"250",
")",
";",
"if",
"(",
"!",
"executing",
"&&",
"!",
"(",
"queue",
".",
"test",
".",
"length",
"||",
"queue",
".",
"build",
".",
"length",
")",
")",
"{",
"console",
".",
"log",
"(",
")",
";",
"console",
".",
"log",
"(",
"`",
"`",
".",
"green",
")",
";",
"console",
".",
"log",
"(",
")",
";",
"}",
"}"
]
| Executes previously queued up tasks, one-by-one | [
"Executes",
"previously",
"queued",
"up",
"tasks",
"one",
"-",
"by",
"-",
"one"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/tasks/index.js#L107-L131 | train |
ecomfe/jformatter | jformatter.js | function () {
return {
lineSeparator: '\n', // done
maxLength: 120, // TODO
wrapIfLong: false, // TODO
indent: 4, // done
useTabIndent: false, // done
spaces: {
around: {
unaryOperators: false, // TODO
binaryOperators: true, // done
ternaryOperators: true // done
},
before: {
functionDeclarationParentheses: false, // done function foo() {
functionExpressionParentheses: true, // done var foo = function () {
parentheses: true, // done if (), for (), while (), ...
leftBrace: true, // done function () {, if () {, do {, try { ...
keywords: true // done if {} else {}, do {} while (), try {} catch () {} finally
},
within: {
// function call, function declaration, if, for, while, switch, catch
parentheses: false // done
},
other: {
beforePropertyNameValueSeparator: false, // done {key: value} {key : value} {key:value}
afterPropertyNameValueSeparator: true // done
}
},
bracesPlacement: { // 1. same line 2. next line
functionDeclaration: 1, // TODO
other: 1 // TODO
},
blankLines: {
keepMaxBlankLines: 1, // done
atEndOfFile: true // done
},
other: {
keepArraySingleLine: false // TODO default formatted array multi line
},
fix: {
prefixSpaceToLineComment: false, // done
alterCommonBlockCommentToLineComment: false, // done
singleVariableDeclarator: false, // done
fixInvalidTypeof: false, // done
removeEmptyStatement: false, // done
autoSemicolon: false, // done
singleQuotes: false, // done
eqeqeq: false, // done
invalidConstructor: false, // done
addCurly: false, // done
removeDebugger: false, // done
noElseReturn: false
}
};
} | javascript | function () {
return {
lineSeparator: '\n', // done
maxLength: 120, // TODO
wrapIfLong: false, // TODO
indent: 4, // done
useTabIndent: false, // done
spaces: {
around: {
unaryOperators: false, // TODO
binaryOperators: true, // done
ternaryOperators: true // done
},
before: {
functionDeclarationParentheses: false, // done function foo() {
functionExpressionParentheses: true, // done var foo = function () {
parentheses: true, // done if (), for (), while (), ...
leftBrace: true, // done function () {, if () {, do {, try { ...
keywords: true // done if {} else {}, do {} while (), try {} catch () {} finally
},
within: {
// function call, function declaration, if, for, while, switch, catch
parentheses: false // done
},
other: {
beforePropertyNameValueSeparator: false, // done {key: value} {key : value} {key:value}
afterPropertyNameValueSeparator: true // done
}
},
bracesPlacement: { // 1. same line 2. next line
functionDeclaration: 1, // TODO
other: 1 // TODO
},
blankLines: {
keepMaxBlankLines: 1, // done
atEndOfFile: true // done
},
other: {
keepArraySingleLine: false // TODO default formatted array multi line
},
fix: {
prefixSpaceToLineComment: false, // done
alterCommonBlockCommentToLineComment: false, // done
singleVariableDeclarator: false, // done
fixInvalidTypeof: false, // done
removeEmptyStatement: false, // done
autoSemicolon: false, // done
singleQuotes: false, // done
eqeqeq: false, // done
invalidConstructor: false, // done
addCurly: false, // done
removeDebugger: false, // done
noElseReturn: false
}
};
} | [
"function",
"(",
")",
"{",
"return",
"{",
"lineSeparator",
":",
"'\\n'",
",",
"\\n",
",",
"maxLength",
":",
"120",
",",
"wrapIfLong",
":",
"false",
",",
"indent",
":",
"4",
",",
"useTabIndent",
":",
"false",
",",
"spaces",
":",
"{",
"around",
":",
"{",
"unaryOperators",
":",
"false",
",",
"binaryOperators",
":",
"true",
",",
"ternaryOperators",
":",
"true",
"}",
",",
"before",
":",
"{",
"functionDeclarationParentheses",
":",
"false",
",",
"functionExpressionParentheses",
":",
"true",
",",
"parentheses",
":",
"true",
",",
"leftBrace",
":",
"true",
",",
"keywords",
":",
"true",
"}",
",",
"within",
":",
"{",
"parentheses",
":",
"false",
"}",
",",
"other",
":",
"{",
"beforePropertyNameValueSeparator",
":",
"false",
",",
"afterPropertyNameValueSeparator",
":",
"true",
"}",
"}",
",",
"bracesPlacement",
":",
"{",
"functionDeclaration",
":",
"1",
",",
"other",
":",
"1",
"}",
",",
"blankLines",
":",
"{",
"keepMaxBlankLines",
":",
"1",
",",
"atEndOfFile",
":",
"true",
"}",
",",
"other",
":",
"{",
"keepArraySingleLine",
":",
"false",
"}",
"}",
";",
"}"
]
| returns default config
@returns {Object} | [
"returns",
"default",
"config"
]
| fce4c775a54362a7dc67cab71f8dc8f54d809b3d | https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L11-L66 | train |
|
ecomfe/jformatter | jformatter.js | function (defaults, configure) {
for (var key in defaults) {
if (defaults.hasOwnProperty(key)) {
if (typeof defaults[key] === 'object') {
// recursive
if (typeof configure[key] === 'object') {
overwriteConfig(defaults[key], configure[key]);
}
} else {
// copy directly
if (typeof configure[key] !== 'undefined') {
defaults[key] = configure[key];
}
}
}
}
} | javascript | function (defaults, configure) {
for (var key in defaults) {
if (defaults.hasOwnProperty(key)) {
if (typeof defaults[key] === 'object') {
// recursive
if (typeof configure[key] === 'object') {
overwriteConfig(defaults[key], configure[key]);
}
} else {
// copy directly
if (typeof configure[key] !== 'undefined') {
defaults[key] = configure[key];
}
}
}
}
} | [
"function",
"(",
"defaults",
",",
"configure",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"defaults",
")",
"{",
"if",
"(",
"defaults",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"if",
"(",
"typeof",
"defaults",
"[",
"key",
"]",
"===",
"'object'",
")",
"{",
"if",
"(",
"typeof",
"configure",
"[",
"key",
"]",
"===",
"'object'",
")",
"{",
"overwriteConfig",
"(",
"defaults",
"[",
"key",
"]",
",",
"configure",
"[",
"key",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"typeof",
"configure",
"[",
"key",
"]",
"!==",
"'undefined'",
")",
"{",
"defaults",
"[",
"key",
"]",
"=",
"configure",
"[",
"key",
"]",
";",
"}",
"}",
"}",
"}",
"}"
]
| defaults the config | [
"defaults",
"the",
"config"
]
| fce4c775a54362a7dc67cab71f8dc8f54d809b3d | https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L71-L87 | train |
|
ecomfe/jformatter | jformatter.js | function () {
var indentStr = '';
for (var i = 0; i < indentLevel; i++) {
indentStr += INDENT;
}
return {
type: 'WhiteSpace',
value: indentStr
};
} | javascript | function () {
var indentStr = '';
for (var i = 0; i < indentLevel; i++) {
indentStr += INDENT;
}
return {
type: 'WhiteSpace',
value: indentStr
};
} | [
"function",
"(",
")",
"{",
"var",
"indentStr",
"=",
"''",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"indentLevel",
";",
"i",
"++",
")",
"{",
"indentStr",
"+=",
"INDENT",
";",
"}",
"return",
"{",
"type",
":",
"'WhiteSpace'",
",",
"value",
":",
"indentStr",
"}",
";",
"}"
]
| create a indent token with indent level
@returns {Object} | [
"create",
"a",
"indent",
"token",
"with",
"indent",
"level"
]
| fce4c775a54362a7dc67cab71f8dc8f54d809b3d | https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L135-L144 | train |
|
ecomfe/jformatter | jformatter.js | function (token) {
var inline = false;
if (token) {
if (token.type === 'LineComment') {
inline = true;
} else if (token.type === 'BlockComment') {
inline = (token.value.indexOf('\n') === -1);
}
}
return inline;
} | javascript | function (token) {
var inline = false;
if (token) {
if (token.type === 'LineComment') {
inline = true;
} else if (token.type === 'BlockComment') {
inline = (token.value.indexOf('\n') === -1);
}
}
return inline;
} | [
"function",
"(",
"token",
")",
"{",
"var",
"inline",
"=",
"false",
";",
"if",
"(",
"token",
")",
"{",
"if",
"(",
"token",
".",
"type",
"===",
"'LineComment'",
")",
"{",
"inline",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"token",
".",
"type",
"===",
"'BlockComment'",
")",
"{",
"inline",
"=",
"(",
"token",
".",
"value",
".",
"indexOf",
"(",
"'\\n'",
")",
"===",
"\\n",
")",
";",
"}",
"}",
"-",
"1",
"}"
]
| check if a token is comment in one line
@param {Object} token - the token to check
@returns {boolean} | [
"check",
"if",
"a",
"token",
"is",
"comment",
"in",
"one",
"line"
]
| fce4c775a54362a7dc67cab71f8dc8f54d809b3d | https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L226-L236 | train |
|
ecomfe/jformatter | jformatter.js | function (startToken, endToken, types) {
var is = true;
var token = startToken;
while (token.next && token.next !== endToken) {
token = token.next;
if (types.indexOf(token.type) === -1) {
is = false;
break;
}
}
return is;
} | javascript | function (startToken, endToken, types) {
var is = true;
var token = startToken;
while (token.next && token.next !== endToken) {
token = token.next;
if (types.indexOf(token.type) === -1) {
is = false;
break;
}
}
return is;
} | [
"function",
"(",
"startToken",
",",
"endToken",
",",
"types",
")",
"{",
"var",
"is",
"=",
"true",
";",
"var",
"token",
"=",
"startToken",
";",
"while",
"(",
"token",
".",
"next",
"&&",
"token",
".",
"next",
"!==",
"endToken",
")",
"{",
"token",
"=",
"token",
".",
"next",
";",
"if",
"(",
"types",
".",
"indexOf",
"(",
"token",
".",
"type",
")",
"===",
"-",
"1",
")",
"{",
"is",
"=",
"false",
";",
"break",
";",
"}",
"}",
"return",
"is",
";",
"}"
]
| check if only types between startToken and endToken
@param {Object} startToken - the token to start check
@param {Object} endToken - the token to end check
@param {Array} types - allow types array
@returns {boolean} | [
"check",
"if",
"only",
"types",
"between",
"startToken",
"and",
"endToken"
]
| fce4c775a54362a7dc67cab71f8dc8f54d809b3d | https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L246-L257 | train |
|
sithmel/obj-path-expression-parser | lib/parser/grammar.js | pathExpression | function pathExpression (token, tokens) {
const expression = []
while (true) {
if (!token) {
break
}
if (token === ')') {
tokens.unshift(token)
break
}
if (includes('}]', token)) {
throw new Error(`A fragment can't contain "${token}"`)
}
if (token === ',') {
break
}
if (token === '[') {
expression.push(escapedFragment(token, tokens))
} else if (token === '(') {
expression.push(pathExpressions(token, tokens))
} else if (token === '{') {
expression.push(customFragment(token, tokens))
} else {
expression.push(unescapedFragment(token, tokens))
}
token = tokens.shift()
}
return { _type: pathExpression.name, expression }
} | javascript | function pathExpression (token, tokens) {
const expression = []
while (true) {
if (!token) {
break
}
if (token === ')') {
tokens.unshift(token)
break
}
if (includes('}]', token)) {
throw new Error(`A fragment can't contain "${token}"`)
}
if (token === ',') {
break
}
if (token === '[') {
expression.push(escapedFragment(token, tokens))
} else if (token === '(') {
expression.push(pathExpressions(token, tokens))
} else if (token === '{') {
expression.push(customFragment(token, tokens))
} else {
expression.push(unescapedFragment(token, tokens))
}
token = tokens.shift()
}
return { _type: pathExpression.name, expression }
} | [
"function",
"pathExpression",
"(",
"token",
",",
"tokens",
")",
"{",
"const",
"expression",
"=",
"[",
"]",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"!",
"token",
")",
"{",
"break",
"}",
"if",
"(",
"token",
"===",
"')'",
")",
"{",
"tokens",
".",
"unshift",
"(",
"token",
")",
"break",
"}",
"if",
"(",
"includes",
"(",
"'}]'",
",",
"token",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"token",
"}",
"`",
")",
"}",
"if",
"(",
"token",
"===",
"','",
")",
"{",
"break",
"}",
"if",
"(",
"token",
"===",
"'['",
")",
"{",
"expression",
".",
"push",
"(",
"escapedFragment",
"(",
"token",
",",
"tokens",
")",
")",
"}",
"else",
"if",
"(",
"token",
"===",
"'('",
")",
"{",
"expression",
".",
"push",
"(",
"pathExpressions",
"(",
"token",
",",
"tokens",
")",
")",
"}",
"else",
"if",
"(",
"token",
"===",
"'{'",
")",
"{",
"expression",
".",
"push",
"(",
"customFragment",
"(",
"token",
",",
"tokens",
")",
")",
"}",
"else",
"{",
"expression",
".",
"push",
"(",
"unescapedFragment",
"(",
"token",
",",
"tokens",
")",
")",
"}",
"token",
"=",
"tokens",
".",
"shift",
"(",
")",
"}",
"return",
"{",
"_type",
":",
"pathExpression",
".",
"name",
",",
"expression",
"}",
"}"
]
| ends with "," or with "end of string" | [
"ends",
"with",
"or",
"with",
"end",
"of",
"string"
]
| ba942086d98f42d01ea34592328630179c4bde80 | https://github.com/sithmel/obj-path-expression-parser/blob/ba942086d98f42d01ea34592328630179c4bde80/lib/parser/grammar.js#L91-L121 | train |
jonschlinkert/api-toc | index.js | context | function context(str) {
var arr = code(str);
var len = arr.length, i = 0;
var res = {};
while (len--) {
var ele = arr[i++];
if (ele.type !== 'comment') {
res[ele.name] = ele.begin;
}
}
return res;
} | javascript | function context(str) {
var arr = code(str);
var len = arr.length, i = 0;
var res = {};
while (len--) {
var ele = arr[i++];
if (ele.type !== 'comment') {
res[ele.name] = ele.begin;
}
}
return res;
} | [
"function",
"context",
"(",
"str",
")",
"{",
"var",
"arr",
"=",
"code",
"(",
"str",
")",
";",
"var",
"len",
"=",
"arr",
".",
"length",
",",
"i",
"=",
"0",
";",
"var",
"res",
"=",
"{",
"}",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"ele",
"=",
"arr",
"[",
"i",
"++",
"]",
";",
"if",
"(",
"ele",
".",
"type",
"!==",
"'comment'",
")",
"{",
"res",
"[",
"ele",
".",
"name",
"]",
"=",
"ele",
".",
"begin",
";",
"}",
"}",
"return",
"res",
";",
"}"
]
| Get the code context for a JavaScript file. | [
"Get",
"the",
"code",
"context",
"for",
"a",
"JavaScript",
"file",
"."
]
| 2723a7b597a1a9629309396e0e613591783f841b | https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L67-L79 | train |
jonschlinkert/api-toc | index.js | format | function format(obj, opts, fn) {
if (typeof opts === 'function') {
fn = opts; opts = {};
}
opts = opts || {};
if (Array.isArray(opts.filter) || typeof opts.filter === 'string') {
obj = filter(obj, opts.filter);
}
var keys = Object.keys(obj);
var len = keys.length, i = 0;
var str = '';
var total = len;
while (len--) {
var fp = keys[i++];
var ctx = context(read(fp), fn);
var name = basename(fp);
str += heading(name, fp);
var list = obj[fp];
var methods = Object.keys(list);
total += methods.length;
str += listify(fp, methods, ctx);
}
var res = {};
res.list = str;
res.total = total;
return res;
} | javascript | function format(obj, opts, fn) {
if (typeof opts === 'function') {
fn = opts; opts = {};
}
opts = opts || {};
if (Array.isArray(opts.filter) || typeof opts.filter === 'string') {
obj = filter(obj, opts.filter);
}
var keys = Object.keys(obj);
var len = keys.length, i = 0;
var str = '';
var total = len;
while (len--) {
var fp = keys[i++];
var ctx = context(read(fp), fn);
var name = basename(fp);
str += heading(name, fp);
var list = obj[fp];
var methods = Object.keys(list);
total += methods.length;
str += listify(fp, methods, ctx);
}
var res = {};
res.list = str;
res.total = total;
return res;
} | [
"function",
"format",
"(",
"obj",
",",
"opts",
",",
"fn",
")",
"{",
"if",
"(",
"typeof",
"opts",
"===",
"'function'",
")",
"{",
"fn",
"=",
"opts",
";",
"opts",
"=",
"{",
"}",
";",
"}",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"opts",
".",
"filter",
")",
"||",
"typeof",
"opts",
".",
"filter",
"===",
"'string'",
")",
"{",
"obj",
"=",
"filter",
"(",
"obj",
",",
"opts",
".",
"filter",
")",
";",
"}",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"obj",
")",
";",
"var",
"len",
"=",
"keys",
".",
"length",
",",
"i",
"=",
"0",
";",
"var",
"str",
"=",
"''",
";",
"var",
"total",
"=",
"len",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"fp",
"=",
"keys",
"[",
"i",
"++",
"]",
";",
"var",
"ctx",
"=",
"context",
"(",
"read",
"(",
"fp",
")",
",",
"fn",
")",
";",
"var",
"name",
"=",
"basename",
"(",
"fp",
")",
";",
"str",
"+=",
"heading",
"(",
"name",
",",
"fp",
")",
";",
"var",
"list",
"=",
"obj",
"[",
"fp",
"]",
";",
"var",
"methods",
"=",
"Object",
".",
"keys",
"(",
"list",
")",
";",
"total",
"+=",
"methods",
".",
"length",
";",
"str",
"+=",
"listify",
"(",
"fp",
",",
"methods",
",",
"ctx",
")",
";",
"}",
"var",
"res",
"=",
"{",
"}",
";",
"res",
".",
"list",
"=",
"str",
";",
"res",
".",
"total",
"=",
"total",
";",
"return",
"res",
";",
"}"
]
| Generate a formatted list that includes the given files,
and their respective methods. Uses code context to build
the list.
@param {Object} `obj` Object, The key is a file name and the properties are the methods.
@return {Object} | [
"Generate",
"a",
"formatted",
"list",
"that",
"includes",
"the",
"given",
"files",
"and",
"their",
"respective",
"methods",
".",
"Uses",
"code",
"context",
"to",
"build",
"the",
"list",
"."
]
| 2723a7b597a1a9629309396e0e613591783f841b | https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L90-L122 | train |
jonschlinkert/api-toc | index.js | listify | function listify(fp, methods, ctx) {
var len = methods.length, i = 0;
var res = [''];
while (len--) {
var method = methods[i++];
var line = ctx[method];
var item = line ? linkify('.' + method, fp, '#L' + line) : method;
item = ' - ' + item;
res.push(item);
}
return res.sort().join('\n');
} | javascript | function listify(fp, methods, ctx) {
var len = methods.length, i = 0;
var res = [''];
while (len--) {
var method = methods[i++];
var line = ctx[method];
var item = line ? linkify('.' + method, fp, '#L' + line) : method;
item = ' - ' + item;
res.push(item);
}
return res.sort().join('\n');
} | [
"function",
"listify",
"(",
"fp",
",",
"methods",
",",
"ctx",
")",
"{",
"var",
"len",
"=",
"methods",
".",
"length",
",",
"i",
"=",
"0",
";",
"var",
"res",
"=",
"[",
"''",
"]",
";",
"while",
"(",
"len",
"--",
")",
"{",
"var",
"method",
"=",
"methods",
"[",
"i",
"++",
"]",
";",
"var",
"line",
"=",
"ctx",
"[",
"method",
"]",
";",
"var",
"item",
"=",
"line",
"?",
"linkify",
"(",
"'.'",
"+",
"method",
",",
"fp",
",",
"'#L'",
"+",
"line",
")",
":",
"method",
";",
"item",
"=",
"' - '",
"+",
"item",
";",
"res",
".",
"push",
"(",
"item",
")",
";",
"}",
"return",
"res",
".",
"sort",
"(",
")",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
]
| Create a formatted list for a file and it methods.
@param {String} `fp` File path
@param {Array} `items` Array of items to format.
@param {Object} `ctx` Code context, mainly for getting line numbers to create links.
@return {Array} | [
"Create",
"a",
"formatted",
"list",
"for",
"a",
"file",
"and",
"it",
"methods",
"."
]
| 2723a7b597a1a9629309396e0e613591783f841b | https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L133-L144 | train |
EricCrosson/coinmarketcap-cli | index.js | tableize | function tableize(tableData) {
var table = new Table({
head: Object.keys(tableData[0]),
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
style: { 'padding-left': 0, 'padding-right': 0 }
});
_.each(tableData, function(row, index) {
table.push(_.values(row));
});
return table;
} | javascript | function tableize(tableData) {
var table = new Table({
head: Object.keys(tableData[0]),
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
style: { 'padding-left': 0, 'padding-right': 0 }
});
_.each(tableData, function(row, index) {
table.push(_.values(row));
});
return table;
} | [
"function",
"tableize",
"(",
"tableData",
")",
"{",
"var",
"table",
"=",
"new",
"Table",
"(",
"{",
"head",
":",
"Object",
".",
"keys",
"(",
"tableData",
"[",
"0",
"]",
")",
",",
"chars",
":",
"{",
"'mid'",
":",
"''",
",",
"'left-mid'",
":",
"''",
",",
"'mid-mid'",
":",
"''",
",",
"'right-mid'",
":",
"''",
"}",
",",
"style",
":",
"{",
"'padding-left'",
":",
"0",
",",
"'padding-right'",
":",
"0",
"}",
"}",
")",
";",
"_",
".",
"each",
"(",
"tableData",
",",
"function",
"(",
"row",
",",
"index",
")",
"{",
"table",
".",
"push",
"(",
"_",
".",
"values",
"(",
"row",
")",
")",
";",
"}",
")",
";",
"return",
"table",
";",
"}"
]
| returns a table object | [
"returns",
"a",
"table",
"object"
]
| bdf4fbf28f8706d80415905d90b9458bd37f905d | https://github.com/EricCrosson/coinmarketcap-cli/blob/bdf4fbf28f8706d80415905d90b9458bd37f905d/index.js#L13-L24 | train |
CandleFW/wick | build/wick.node.js | CreateSchemedProperty | function CreateSchemedProperty(object, scheme, schema_name, index) {
if (object[schema_name])
return;
Object.defineProperty(object, schema_name, {
configurable: false,
enumerable: true,
get: function() {
return this.getHook(schema_name, this.prop_array[index]);
},
set: function(value) {
let result = { valid: false };
let val = scheme.parse(value);
scheme.verify(val, result);
if (result.valid && this.prop_array[index] != val) {
this.prop_array[index] = this.setHook(schema_name, val);
this.scheduleUpdate(schema_name);
this._changed_ = true;
}
}
});
} | javascript | function CreateSchemedProperty(object, scheme, schema_name, index) {
if (object[schema_name])
return;
Object.defineProperty(object, schema_name, {
configurable: false,
enumerable: true,
get: function() {
return this.getHook(schema_name, this.prop_array[index]);
},
set: function(value) {
let result = { valid: false };
let val = scheme.parse(value);
scheme.verify(val, result);
if (result.valid && this.prop_array[index] != val) {
this.prop_array[index] = this.setHook(schema_name, val);
this.scheduleUpdate(schema_name);
this._changed_ = true;
}
}
});
} | [
"function",
"CreateSchemedProperty",
"(",
"object",
",",
"scheme",
",",
"schema_name",
",",
"index",
")",
"{",
"if",
"(",
"object",
"[",
"schema_name",
"]",
")",
"return",
";",
"Object",
".",
"defineProperty",
"(",
"object",
",",
"schema_name",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"true",
",",
"get",
":",
"function",
"(",
")",
"{",
"return",
"this",
".",
"getHook",
"(",
"schema_name",
",",
"this",
".",
"prop_array",
"[",
"index",
"]",
")",
";",
"}",
",",
"set",
":",
"function",
"(",
"value",
")",
"{",
"let",
"result",
"=",
"{",
"valid",
":",
"false",
"}",
";",
"let",
"val",
"=",
"scheme",
".",
"parse",
"(",
"value",
")",
";",
"scheme",
".",
"verify",
"(",
"val",
",",
"result",
")",
";",
"if",
"(",
"result",
".",
"valid",
"&&",
"this",
".",
"prop_array",
"[",
"index",
"]",
"!=",
"val",
")",
"{",
"this",
".",
"prop_array",
"[",
"index",
"]",
"=",
"this",
".",
"setHook",
"(",
"schema_name",
",",
"val",
")",
";",
"this",
".",
"scheduleUpdate",
"(",
"schema_name",
")",
";",
"this",
".",
"_changed_",
"=",
"true",
";",
"}",
"}",
"}",
")",
";",
"}"
]
| This is used by Model to create custom property getter and setters on non-ModelContainerBase and non-Model properties of the Model constructor.
@protected
@memberof module:wick~internals.model | [
"This",
"is",
"used",
"by",
"Model",
"to",
"create",
"custom",
"property",
"getter",
"and",
"setters",
"on",
"non",
"-",
"ModelContainerBase",
"and",
"non",
"-",
"Model",
"properties",
"of",
"the",
"Model",
"constructor",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L3628-L3653 | train |
CandleFW/wick | build/wick.node.js | CreateModelProperty | function CreateModelProperty(object, model, schema_name, index) {
Object.defineProperty(object, schema_name, {
configurable: false,
enumerable: true,
get: function() {
let m = this.prop_array[index];
if (!m) {
let address = this.address.slice();
address.push(index);
m = new model(null, this.root, address);
m.par = this;
m.prop_name = schema_name;
m.MUTATION_ID = this.MUTATION_ID;
this.prop_array[index] = m;
}
return this.getHook(schema_name, m);
}
});
} | javascript | function CreateModelProperty(object, model, schema_name, index) {
Object.defineProperty(object, schema_name, {
configurable: false,
enumerable: true,
get: function() {
let m = this.prop_array[index];
if (!m) {
let address = this.address.slice();
address.push(index);
m = new model(null, this.root, address);
m.par = this;
m.prop_name = schema_name;
m.MUTATION_ID = this.MUTATION_ID;
this.prop_array[index] = m;
}
return this.getHook(schema_name, m);
}
});
} | [
"function",
"CreateModelProperty",
"(",
"object",
",",
"model",
",",
"schema_name",
",",
"index",
")",
"{",
"Object",
".",
"defineProperty",
"(",
"object",
",",
"schema_name",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"true",
",",
"get",
":",
"function",
"(",
")",
"{",
"let",
"m",
"=",
"this",
".",
"prop_array",
"[",
"index",
"]",
";",
"if",
"(",
"!",
"m",
")",
"{",
"let",
"address",
"=",
"this",
".",
"address",
".",
"slice",
"(",
")",
";",
"address",
".",
"push",
"(",
"index",
")",
";",
"m",
"=",
"new",
"model",
"(",
"null",
",",
"this",
".",
"root",
",",
"address",
")",
";",
"m",
".",
"par",
"=",
"this",
";",
"m",
".",
"prop_name",
"=",
"schema_name",
";",
"m",
".",
"MUTATION_ID",
"=",
"this",
".",
"MUTATION_ID",
";",
"this",
".",
"prop_array",
"[",
"index",
"]",
"=",
"m",
";",
"}",
"return",
"this",
".",
"getHook",
"(",
"schema_name",
",",
"m",
")",
";",
"}",
"}",
")",
";",
"}"
]
| This is used by Model to create custom property getter and setters on Model properties of the Model constructor.
@protected
@memberof module:wick~internals.model | [
"This",
"is",
"used",
"by",
"Model",
"to",
"create",
"custom",
"property",
"getter",
"and",
"setters",
"on",
"Model",
"properties",
"of",
"the",
"Model",
"constructor",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L3660-L3682 | train |
CandleFW/wick | build/wick.node.js | function(node = this.fch) {
if (node && node.nxt != this.fch && this.fch)
return node.nxt;
return null;
} | javascript | function(node = this.fch) {
if (node && node.nxt != this.fch && this.fch)
return node.nxt;
return null;
} | [
"function",
"(",
"node",
"=",
"this",
".",
"fch",
")",
"{",
"if",
"(",
"node",
"&&",
"node",
".",
"nxt",
"!=",
"this",
".",
"fch",
"&&",
"this",
".",
"fch",
")",
"return",
"node",
".",
"nxt",
";",
"return",
"null",
";",
"}"
]
| Gets the next node.
@param {HTMLNode} node The node to get the sibling of.
@return {HTMLNode | TextNode | undefined} | [
"Gets",
"the",
"next",
"node",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L4881-L4885 | train |
|
CandleFW/wick | build/wick.node.js | function(index, node = this.fch) {
if(node.par !== this)
node = this.fch;
let first = node;
let i = 0;
while (node && node != first) {
if (i++ == index)
return node;
node = node.nxt;
}
return null;
} | javascript | function(index, node = this.fch) {
if(node.par !== this)
node = this.fch;
let first = node;
let i = 0;
while (node && node != first) {
if (i++ == index)
return node;
node = node.nxt;
}
return null;
} | [
"function",
"(",
"index",
",",
"node",
"=",
"this",
".",
"fch",
")",
"{",
"if",
"(",
"node",
".",
"par",
"!==",
"this",
")",
"node",
"=",
"this",
".",
"fch",
";",
"let",
"first",
"=",
"node",
";",
"let",
"i",
"=",
"0",
";",
"while",
"(",
"node",
"&&",
"node",
"!=",
"first",
")",
"{",
"if",
"(",
"i",
"++",
"==",
"index",
")",
"return",
"node",
";",
"node",
"=",
"node",
".",
"nxt",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets the child at index.
@param {number} index The index | [
"Gets",
"the",
"child",
"at",
"index",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L4892-L4905 | train |
|
CandleFW/wick | build/wick.node.js | JSExpressionIdentifiers | function JSExpressionIdentifiers(lex) {
let _identifiers_ = [];
let model_cache = {};
let IN_OBJ = false,
CAN_BE_ID = true;
while (!lex.END) {
switch (lex.ty) {
case lex.types.id:
if (!IN_OBJ || CAN_BE_ID) {
let id = lex.tx;
if (!model_cache[id]) {
_identifiers_.push(lex.tx);
model_cache[id] = true;
}
}
break;
case lex.types.op:
case lex.types.sym:
case lex.types.ob:
case lex.types.cb:
switch (lex.ch) {
case "+":
case ">":
case "<":
case "/":
case "*":
case "-":
CAN_BE_ID = true;
break;
case "[":
IN_OBJ = false;
CAN_BE_ID = true;
break;
case "{":
case ".": //Property Getters
CAN_BE_ID = false;
IN_OBJ = true;
break;
case "]":
case ";":
case "=":
case "}":
case "(":
IN_OBJ = false;
break;
case ",":
if (IN_OBJ)
CAN_BE_ID = false;
else
IN_OBJ = false;
break;
case ":":
case "=":
CAN_BE_ID = true;
}
break;
}
lex.n;
}
return _identifiers_;
} | javascript | function JSExpressionIdentifiers(lex) {
let _identifiers_ = [];
let model_cache = {};
let IN_OBJ = false,
CAN_BE_ID = true;
while (!lex.END) {
switch (lex.ty) {
case lex.types.id:
if (!IN_OBJ || CAN_BE_ID) {
let id = lex.tx;
if (!model_cache[id]) {
_identifiers_.push(lex.tx);
model_cache[id] = true;
}
}
break;
case lex.types.op:
case lex.types.sym:
case lex.types.ob:
case lex.types.cb:
switch (lex.ch) {
case "+":
case ">":
case "<":
case "/":
case "*":
case "-":
CAN_BE_ID = true;
break;
case "[":
IN_OBJ = false;
CAN_BE_ID = true;
break;
case "{":
case ".": //Property Getters
CAN_BE_ID = false;
IN_OBJ = true;
break;
case "]":
case ";":
case "=":
case "}":
case "(":
IN_OBJ = false;
break;
case ",":
if (IN_OBJ)
CAN_BE_ID = false;
else
IN_OBJ = false;
break;
case ":":
case "=":
CAN_BE_ID = true;
}
break;
}
lex.n;
}
return _identifiers_;
} | [
"function",
"JSExpressionIdentifiers",
"(",
"lex",
")",
"{",
"let",
"_identifiers_",
"=",
"[",
"]",
";",
"let",
"model_cache",
"=",
"{",
"}",
";",
"let",
"IN_OBJ",
"=",
"false",
",",
"CAN_BE_ID",
"=",
"true",
";",
"while",
"(",
"!",
"lex",
".",
"END",
")",
"{",
"switch",
"(",
"lex",
".",
"ty",
")",
"{",
"case",
"lex",
".",
"types",
".",
"id",
":",
"if",
"(",
"!",
"IN_OBJ",
"||",
"CAN_BE_ID",
")",
"{",
"let",
"id",
"=",
"lex",
".",
"tx",
";",
"if",
"(",
"!",
"model_cache",
"[",
"id",
"]",
")",
"{",
"_identifiers_",
".",
"push",
"(",
"lex",
".",
"tx",
")",
";",
"model_cache",
"[",
"id",
"]",
"=",
"true",
";",
"}",
"}",
"break",
";",
"case",
"lex",
".",
"types",
".",
"op",
":",
"case",
"lex",
".",
"types",
".",
"sym",
":",
"case",
"lex",
".",
"types",
".",
"ob",
":",
"case",
"lex",
".",
"types",
".",
"cb",
":",
"switch",
"(",
"lex",
".",
"ch",
")",
"{",
"case",
"\"+\"",
":",
"case",
"\">\"",
":",
"case",
"\"<\"",
":",
"case",
"\"/\"",
":",
"case",
"\"*\"",
":",
"case",
"\"-\"",
":",
"CAN_BE_ID",
"=",
"true",
";",
"break",
";",
"case",
"\"[\"",
":",
"IN_OBJ",
"=",
"false",
";",
"CAN_BE_ID",
"=",
"true",
";",
"break",
";",
"case",
"\"{\"",
":",
"case",
"\".\"",
":",
"CAN_BE_ID",
"=",
"false",
";",
"IN_OBJ",
"=",
"true",
";",
"break",
";",
"case",
"\"]\"",
":",
"case",
"\";\"",
":",
"case",
"\"=\"",
":",
"case",
"\"}\"",
":",
"case",
"\"(\"",
":",
"IN_OBJ",
"=",
"false",
";",
"break",
";",
"case",
"\",\"",
":",
"if",
"(",
"IN_OBJ",
")",
"CAN_BE_ID",
"=",
"false",
";",
"else",
"IN_OBJ",
"=",
"false",
";",
"break",
";",
"case",
"\":\"",
":",
"case",
"\"=\"",
":",
"CAN_BE_ID",
"=",
"true",
";",
"}",
"break",
";",
"}",
"lex",
".",
"n",
";",
"}",
"return",
"_identifiers_",
";",
"}"
]
| Basic JS Parser Kludge to get legitimate foreign identifiers from expressions.
This could later be expanded into a full JS parser to generate proper JS ASTs.
@class JSExpressionIdentifiers
@param {Lexer} lex The lex
@return {Object} { description_of_the_return_value } | [
"Basic",
"JS",
"Parser",
"Kludge",
"to",
"get",
"legitimate",
"foreign",
"identifiers",
"from",
"expressions",
".",
"This",
"could",
"later",
"be",
"expanded",
"into",
"a",
"full",
"JS",
"parser",
"to",
"generate",
"proper",
"JS",
"ASTs",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L10247-L10311 | train |
CandleFW/wick | build/wick.node.js | TransformTo | function TransformTo(element_from, element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER) {
let rect = element_from.getBoundingClientRect();
let cs = window.getComputedStyle(element_from, null);
let margin_left = parseFloat(cs.getPropertyValue("margin"));
let seq = Animation.createSequence({
obj: element_from,
width: { value: "0px"},
height: { value: "0px"},
backgroundColor: { value: "rgb(1,1,1)"},
left: [{value:rect.left+"px"},{ value: "0px"}],
top: [{value:rect.top+"px"},{ value: "0px"}]
});
if (!element_to) {
let a = (seq) => (element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER = false) => {
setTo(element_to, seq, duration, easing);
seq.duration = duration;
return seq;
};
return a(seq);
}
setTo(element_to, duration, easing);
seq.duration = duration;
return seq;
} | javascript | function TransformTo(element_from, element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER) {
let rect = element_from.getBoundingClientRect();
let cs = window.getComputedStyle(element_from, null);
let margin_left = parseFloat(cs.getPropertyValue("margin"));
let seq = Animation.createSequence({
obj: element_from,
width: { value: "0px"},
height: { value: "0px"},
backgroundColor: { value: "rgb(1,1,1)"},
left: [{value:rect.left+"px"},{ value: "0px"}],
top: [{value:rect.top+"px"},{ value: "0px"}]
});
if (!element_to) {
let a = (seq) => (element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER = false) => {
setTo(element_to, seq, duration, easing);
seq.duration = duration;
return seq;
};
return a(seq);
}
setTo(element_to, duration, easing);
seq.duration = duration;
return seq;
} | [
"function",
"TransformTo",
"(",
"element_from",
",",
"element_to",
",",
"duration",
"=",
"500",
",",
"easing",
"=",
"Animation",
".",
"easing",
".",
"linear",
",",
"HIDE_OTHER",
")",
"{",
"let",
"rect",
"=",
"element_from",
".",
"getBoundingClientRect",
"(",
")",
";",
"let",
"cs",
"=",
"window",
".",
"getComputedStyle",
"(",
"element_from",
",",
"null",
")",
";",
"let",
"margin_left",
"=",
"parseFloat",
"(",
"cs",
".",
"getPropertyValue",
"(",
"\"margin\"",
")",
")",
";",
"let",
"seq",
"=",
"Animation",
".",
"createSequence",
"(",
"{",
"obj",
":",
"element_from",
",",
"width",
":",
"{",
"value",
":",
"\"0px\"",
"}",
",",
"height",
":",
"{",
"value",
":",
"\"0px\"",
"}",
",",
"backgroundColor",
":",
"{",
"value",
":",
"\"rgb(1,1,1)\"",
"}",
",",
"left",
":",
"[",
"{",
"value",
":",
"rect",
".",
"left",
"+",
"\"px\"",
"}",
",",
"{",
"value",
":",
"\"0px\"",
"}",
"]",
",",
"top",
":",
"[",
"{",
"value",
":",
"rect",
".",
"top",
"+",
"\"px\"",
"}",
",",
"{",
"value",
":",
"\"0px\"",
"}",
"]",
"}",
")",
";",
"if",
"(",
"!",
"element_to",
")",
"{",
"let",
"a",
"=",
"(",
"seq",
")",
"=>",
"(",
"element_to",
",",
"duration",
"=",
"500",
",",
"easing",
"=",
"Animation",
".",
"easing",
".",
"linear",
",",
"HIDE_OTHER",
"=",
"false",
")",
"=>",
"{",
"setTo",
"(",
"element_to",
",",
"seq",
",",
"duration",
",",
"easing",
")",
";",
"seq",
".",
"duration",
"=",
"duration",
";",
"return",
"seq",
";",
"}",
";",
"return",
"a",
"(",
"seq",
")",
";",
"}",
"setTo",
"(",
"element_to",
",",
"duration",
",",
"easing",
")",
";",
"seq",
".",
"duration",
"=",
"duration",
";",
"return",
"seq",
";",
"}"
]
| Transform one element from another back to itself
@alias module:wick~internals.TransformTo | [
"Transform",
"one",
"element",
"from",
"another",
"back",
"to",
"itself"
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L11928-L11956 | train |
CandleFW/wick | build/wick.node.js | CreateHTMLNode | function CreateHTMLNode(tag) {
//jump table.
switch (tag[0]) {
case "w":
switch (tag) {
case "w-s":
return new SourceNode$1(); //This node is used to
case "w-c":
return new SourceTemplateNode$1(); //This node is used to
}
break;
default:
switch (tag) {
case "a":
return new LinkNode$1();
/** void elements **/
case "template":
return new VoidNode$1();
case "style":
return new StyleNode$1();
case "script":
return new ScriptNode$1();
case "svg":
case "path":
return new SVGNode();
}
}
return new RootNode();
} | javascript | function CreateHTMLNode(tag) {
//jump table.
switch (tag[0]) {
case "w":
switch (tag) {
case "w-s":
return new SourceNode$1(); //This node is used to
case "w-c":
return new SourceTemplateNode$1(); //This node is used to
}
break;
default:
switch (tag) {
case "a":
return new LinkNode$1();
/** void elements **/
case "template":
return new VoidNode$1();
case "style":
return new StyleNode$1();
case "script":
return new ScriptNode$1();
case "svg":
case "path":
return new SVGNode();
}
}
return new RootNode();
} | [
"function",
"CreateHTMLNode",
"(",
"tag",
")",
"{",
"switch",
"(",
"tag",
"[",
"0",
"]",
")",
"{",
"case",
"\"w\"",
":",
"switch",
"(",
"tag",
")",
"{",
"case",
"\"w-s\"",
":",
"return",
"new",
"SourceNode$1",
"(",
")",
";",
"case",
"\"w-c\"",
":",
"return",
"new",
"SourceTemplateNode$1",
"(",
")",
";",
"}",
"break",
";",
"default",
":",
"switch",
"(",
"tag",
")",
"{",
"case",
"\"a\"",
":",
"return",
"new",
"LinkNode$1",
"(",
")",
";",
"case",
"\"template\"",
":",
"return",
"new",
"VoidNode$1",
"(",
")",
";",
"case",
"\"style\"",
":",
"return",
"new",
"StyleNode$1",
"(",
")",
";",
"case",
"\"script\"",
":",
"return",
"new",
"ScriptNode$1",
"(",
")",
";",
"case",
"\"svg\"",
":",
"case",
"\"path\"",
":",
"return",
"new",
"SVGNode",
"(",
")",
";",
"}",
"}",
"return",
"new",
"RootNode",
"(",
")",
";",
"}"
]
| Since all nodes extend the RootNode, this needs to be declared here to prevent module cycles. | [
"Since",
"all",
"nodes",
"extend",
"the",
"RootNode",
"this",
"needs",
"to",
"be",
"declared",
"here",
"to",
"prevent",
"module",
"cycles",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L13092-L13121 | train |
CandleFW/wick | build/wick.node.js | CompileSource | function CompileSource(SourcePackage, presets, element, url, win = window) {
let lex;
if (element instanceof whind$1.constructor) {
lex = element;
} else if (typeof(element) == "string")
lex = whind$1(element);
else if (element instanceof EL) {
if (element.tagName == "TEMPLATE") {
let temp = document.createElement("div");
temp.appendChild(element.content);
element = temp;
}
lex = whind$1(element.innerHTML);
} else {
let e = new Error("Cannot compile component");
SourcePackage._addError_(e);
SourcePackage._complete_();
}
return parseText(lex, SourcePackage, presets, url, win);
} | javascript | function CompileSource(SourcePackage, presets, element, url, win = window) {
let lex;
if (element instanceof whind$1.constructor) {
lex = element;
} else if (typeof(element) == "string")
lex = whind$1(element);
else if (element instanceof EL) {
if (element.tagName == "TEMPLATE") {
let temp = document.createElement("div");
temp.appendChild(element.content);
element = temp;
}
lex = whind$1(element.innerHTML);
} else {
let e = new Error("Cannot compile component");
SourcePackage._addError_(e);
SourcePackage._complete_();
}
return parseText(lex, SourcePackage, presets, url, win);
} | [
"function",
"CompileSource",
"(",
"SourcePackage",
",",
"presets",
",",
"element",
",",
"url",
",",
"win",
"=",
"window",
")",
"{",
"let",
"lex",
";",
"if",
"(",
"element",
"instanceof",
"whind$1",
".",
"constructor",
")",
"{",
"lex",
"=",
"element",
";",
"}",
"else",
"if",
"(",
"typeof",
"(",
"element",
")",
"==",
"\"string\"",
")",
"lex",
"=",
"whind$1",
"(",
"element",
")",
";",
"else",
"if",
"(",
"element",
"instanceof",
"EL",
")",
"{",
"if",
"(",
"element",
".",
"tagName",
"==",
"\"TEMPLATE\"",
")",
"{",
"let",
"temp",
"=",
"document",
".",
"createElement",
"(",
"\"div\"",
")",
";",
"temp",
".",
"appendChild",
"(",
"element",
".",
"content",
")",
";",
"element",
"=",
"temp",
";",
"}",
"lex",
"=",
"whind$1",
"(",
"element",
".",
"innerHTML",
")",
";",
"}",
"else",
"{",
"let",
"e",
"=",
"new",
"Error",
"(",
"\"Cannot compile component\"",
")",
";",
"SourcePackage",
".",
"_addError_",
"(",
"e",
")",
";",
"SourcePackage",
".",
"_complete_",
"(",
")",
";",
"}",
"return",
"parseText",
"(",
"lex",
",",
"SourcePackage",
",",
"presets",
",",
"url",
",",
"win",
")",
";",
"}"
]
| Compiles an object graph based input into a SourcePackage.
@param {SourcePackage} SourcePackage The source package
@param {Presets} presets The global Presets instance
@param {HTMLElement | Lexer | string} element The element
@memberof module:wick~internals.templateCompiler
@alias CompileSource | [
"Compiles",
"an",
"object",
"graph",
"based",
"input",
"into",
"a",
"SourcePackage",
"."
]
| 139861e3696598db5b1e5c809ce36691ae61c633 | https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L13267-L13286 | train |
wikimedia/web-html-stream | lib/cssSelectorParser.js | parseCSSSelector | function parseCSSSelector(selector) {
const match = SELECTOR_RE.exec(selector);
if (!match) {
throw new Error("Unsupported or invalid CSS selector: " + selector);
}
const res = { nodeName: match[1].trim() };
if (match[2]) {
const attr = [match[2]];
if (match[3]) { attr.push(match[3]); }
// Decode the attribute value
if(match[4]) {
attr.push(match[4].replace(/\\([nrtf"\\])/g, function(_, k) {
return valueDecodeTable[k];
}));
}
res.attributes = [attr];
}
return res;
} | javascript | function parseCSSSelector(selector) {
const match = SELECTOR_RE.exec(selector);
if (!match) {
throw new Error("Unsupported or invalid CSS selector: " + selector);
}
const res = { nodeName: match[1].trim() };
if (match[2]) {
const attr = [match[2]];
if (match[3]) { attr.push(match[3]); }
// Decode the attribute value
if(match[4]) {
attr.push(match[4].replace(/\\([nrtf"\\])/g, function(_, k) {
return valueDecodeTable[k];
}));
}
res.attributes = [attr];
}
return res;
} | [
"function",
"parseCSSSelector",
"(",
"selector",
")",
"{",
"const",
"match",
"=",
"SELECTOR_RE",
".",
"exec",
"(",
"selector",
")",
";",
"if",
"(",
"!",
"match",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Unsupported or invalid CSS selector: \"",
"+",
"selector",
")",
";",
"}",
"const",
"res",
"=",
"{",
"nodeName",
":",
"match",
"[",
"1",
"]",
".",
"trim",
"(",
")",
"}",
";",
"if",
"(",
"match",
"[",
"2",
"]",
")",
"{",
"const",
"attr",
"=",
"[",
"match",
"[",
"2",
"]",
"]",
";",
"if",
"(",
"match",
"[",
"3",
"]",
")",
"{",
"attr",
".",
"push",
"(",
"match",
"[",
"3",
"]",
")",
";",
"}",
"if",
"(",
"match",
"[",
"4",
"]",
")",
"{",
"attr",
".",
"push",
"(",
"match",
"[",
"4",
"]",
".",
"replace",
"(",
"/",
"\\\\([nrtf\"\\\\])",
"/",
"g",
",",
"function",
"(",
"_",
",",
"k",
")",
"{",
"return",
"valueDecodeTable",
"[",
"k",
"]",
";",
"}",
")",
")",
";",
"}",
"res",
".",
"attributes",
"=",
"[",
"attr",
"]",
";",
"}",
"return",
"res",
";",
"}"
]
| Simple CSS selector parser.
Limitations:
- Only supports single attribute selector. | [
"Simple",
"CSS",
"selector",
"parser",
"."
]
| 21a42a0dc6769dfbb8e9430ae41c323512bb762b | https://github.com/wikimedia/web-html-stream/blob/21a42a0dc6769dfbb8e9430ae41c323512bb762b/lib/cssSelectorParser.js#L21-L39 | train |
patrick-steele-idem/events-light | src/index.js | function(type, listener) {
checkListener(listener);
var events = this.$e;
var listeners;
if (events && (listeners = events[type])) {
if (isFunction(listeners)) {
if (listeners === listener) {
delete events[type];
}
} else {
for (var i=listeners.length-1; i>=0; i--) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
}
}
}
}
return this;
} | javascript | function(type, listener) {
checkListener(listener);
var events = this.$e;
var listeners;
if (events && (listeners = events[type])) {
if (isFunction(listeners)) {
if (listeners === listener) {
delete events[type];
}
} else {
for (var i=listeners.length-1; i>=0; i--) {
if (listeners[i] === listener) {
listeners.splice(i, 1);
}
}
}
}
return this;
} | [
"function",
"(",
"type",
",",
"listener",
")",
"{",
"checkListener",
"(",
"listener",
")",
";",
"var",
"events",
"=",
"this",
".",
"$e",
";",
"var",
"listeners",
";",
"if",
"(",
"events",
"&&",
"(",
"listeners",
"=",
"events",
"[",
"type",
"]",
")",
")",
"{",
"if",
"(",
"isFunction",
"(",
"listeners",
")",
")",
"{",
"if",
"(",
"listeners",
"===",
"listener",
")",
"{",
"delete",
"events",
"[",
"type",
"]",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"listeners",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"listeners",
"[",
"i",
"]",
"===",
"listener",
")",
"{",
"listeners",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"}",
"}",
"}",
"}",
"return",
"this",
";",
"}"
]
| emits a 'removeListener' event iff the listener was removed | [
"emits",
"a",
"removeListener",
"event",
"iff",
"the",
"listener",
"was",
"removed"
]
| eb1081346caf33f0f4c6f66e2d988984d379d40c | https://github.com/patrick-steele-idem/events-light/blob/eb1081346caf33f0f4c6f66e2d988984d379d40c/src/index.js#L129-L150 | train |
|
imwtr/find-free-port-sync | find-free-port-sync.js | FindFreePortSync | function FindFreePortSync(options = {}) {
this.defaultOptions = {
// port start for scan
start: 1,
// port end for scan
end: 65534,
// ports number for scan
num: 1,
// specify ip for scan
ip: '0.0.0.0|127.0.0.1',
// for inner usage, some platforms like darkwin shows commom address 0.0.0.0:10000 as *.10000
_ipSpecial: '\\*|127.0.0.1',
// scan this port
port: null
};
this.msg = {
error: 'Cannot find free port'
}
this.adjustOptions(options);
} | javascript | function FindFreePortSync(options = {}) {
this.defaultOptions = {
// port start for scan
start: 1,
// port end for scan
end: 65534,
// ports number for scan
num: 1,
// specify ip for scan
ip: '0.0.0.0|127.0.0.1',
// for inner usage, some platforms like darkwin shows commom address 0.0.0.0:10000 as *.10000
_ipSpecial: '\\*|127.0.0.1',
// scan this port
port: null
};
this.msg = {
error: 'Cannot find free port'
}
this.adjustOptions(options);
} | [
"function",
"FindFreePortSync",
"(",
"options",
"=",
"{",
"}",
")",
"{",
"this",
".",
"defaultOptions",
"=",
"{",
"start",
":",
"1",
",",
"end",
":",
"65534",
",",
"num",
":",
"1",
",",
"ip",
":",
"'0.0.0.0|127.0.0.1'",
",",
"_ipSpecial",
":",
"'\\\\*|127.0.0.1'",
",",
"\\\\",
"}",
";",
"port",
":",
"null",
"this",
".",
"msg",
"=",
"{",
"error",
":",
"'Cannot find free port'",
"}",
"}"
]
| Finding free port synchronously
@param {Object} options [description] | [
"Finding",
"free",
"port",
"synchronously"
]
| 6eb36867d80072cf4b20b1d5a878ab02170b6198 | https://github.com/imwtr/find-free-port-sync/blob/6eb36867d80072cf4b20b1d5a878ab02170b6198/find-free-port-sync.js#L8-L29 | train |
base/base-generators | index.js | function(name, val, options) {
debug('.generator', name, val);
if (this.hasGenerator(name)) {
return this.getGenerator(name);
}
this.setGenerator.apply(this, arguments);
return this.getGenerator(name);
} | javascript | function(name, val, options) {
debug('.generator', name, val);
if (this.hasGenerator(name)) {
return this.getGenerator(name);
}
this.setGenerator.apply(this, arguments);
return this.getGenerator(name);
} | [
"function",
"(",
"name",
",",
"val",
",",
"options",
")",
"{",
"debug",
"(",
"'.generator'",
",",
"name",
",",
"val",
")",
";",
"if",
"(",
"this",
".",
"hasGenerator",
"(",
"name",
")",
")",
"{",
"return",
"this",
".",
"getGenerator",
"(",
"name",
")",
";",
"}",
"this",
".",
"setGenerator",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"return",
"this",
".",
"getGenerator",
"(",
"name",
")",
";",
"}"
]
| Get and invoke generator `name`, or register generator `name` with
the given `val` and `options`, then invoke and return the generator
instance. This method differs from `.register`, which lazily invokes
generator functions when `.generate` is called.
```js
app.generator('foo', function(app, base, env, options) {
// "app" - private instance created for generator "foo"
// "base" - instance shared by all generators
// "env" - environment object for the generator
// "options" - options passed to the generator
});
```
@name .generator
@param {String} `name`
@param {Function|Object} `fn` Generator function, instance or filepath.
@return {Object} Returns the generator instance or undefined if not resolved.
@api public | [
"Get",
"and",
"invoke",
"generator",
"name",
"or",
"register",
"generator",
"name",
"with",
"the",
"given",
"val",
"and",
"options",
"then",
"invoke",
"and",
"return",
"the",
"generator",
"instance",
".",
"This",
"method",
"differs",
"from",
".",
"register",
"which",
"lazily",
"invokes",
"generator",
"functions",
"when",
".",
"generate",
"is",
"called",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L85-L94 | train |
|
base/base-generators | index.js | function(name, val, options) {
debug('.setGenerator', name);
if (this.hasGenerator(name)) {
return this.findGenerator(name);
}
// ensure local sub-generator paths are resolved
if (typeof val === 'string' && val.charAt(0) === '.' && this.env) {
val = path.resolve(this.env.dirname, val);
}
return generator(name, val, options, this);
} | javascript | function(name, val, options) {
debug('.setGenerator', name);
if (this.hasGenerator(name)) {
return this.findGenerator(name);
}
// ensure local sub-generator paths are resolved
if (typeof val === 'string' && val.charAt(0) === '.' && this.env) {
val = path.resolve(this.env.dirname, val);
}
return generator(name, val, options, this);
} | [
"function",
"(",
"name",
",",
"val",
",",
"options",
")",
"{",
"debug",
"(",
"'.setGenerator'",
",",
"name",
")",
";",
"if",
"(",
"this",
".",
"hasGenerator",
"(",
"name",
")",
")",
"{",
"return",
"this",
".",
"findGenerator",
"(",
"name",
")",
";",
"}",
"if",
"(",
"typeof",
"val",
"===",
"'string'",
"&&",
"val",
".",
"charAt",
"(",
"0",
")",
"===",
"'.'",
"&&",
"this",
".",
"env",
")",
"{",
"val",
"=",
"path",
".",
"resolve",
"(",
"this",
".",
"env",
".",
"dirname",
",",
"val",
")",
";",
"}",
"return",
"generator",
"(",
"name",
",",
"val",
",",
"options",
",",
"this",
")",
";",
"}"
]
| Store a generator by file path or instance with the given
`name` and `options`.
```js
app.setGenerator('foo', function(app, base) {
// "app" - private instance created for generator "foo"
// "base" - instance shared by all generators
// "env" - environment object for the generator
// "options" - options passed to the generator
});
```
@name .setGenerator
@param {String} `name` The generator's name
@param {Object|Function|String} `options` or generator
@param {Object|Function|String} `generator` Generator function, instance or filepath.
@return {Object} Returns the generator instance.
@api public | [
"Store",
"a",
"generator",
"by",
"file",
"path",
"or",
"instance",
"with",
"the",
"given",
"name",
"and",
"options",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L116-L129 | train |
|
base/base-generators | index.js | fn | function fn(name, options) {
debug('.findGenerator', name);
if (utils.isObject(name)) {
return name;
}
if (Array.isArray(name)) {
name = name.join('.');
}
if (typeof name !== 'string') {
throw new TypeError('expected name to be a string');
}
if (cache.hasOwnProperty(name)) {
return cache[name];
}
var app = this.generators[name]
|| this.base.generators[name]
|| this._findGenerator(name, options);
// if no app, check the `base` instance
if (typeof app === 'undefined' && this.hasOwnProperty('parent')) {
app = this.base._findGenerator(name, options);
}
if (app) {
cache[app.name] = app;
cache[app.alias] = app;
cache[name] = app;
return app;
}
var search = {name, options};
this.base.emit('unresolved', search, this);
if (search.app) {
cache[search.app.name] = search.app;
cache[search.app.alias] = search.app;
return search.app;
}
cache[name] = null;
} | javascript | function fn(name, options) {
debug('.findGenerator', name);
if (utils.isObject(name)) {
return name;
}
if (Array.isArray(name)) {
name = name.join('.');
}
if (typeof name !== 'string') {
throw new TypeError('expected name to be a string');
}
if (cache.hasOwnProperty(name)) {
return cache[name];
}
var app = this.generators[name]
|| this.base.generators[name]
|| this._findGenerator(name, options);
// if no app, check the `base` instance
if (typeof app === 'undefined' && this.hasOwnProperty('parent')) {
app = this.base._findGenerator(name, options);
}
if (app) {
cache[app.name] = app;
cache[app.alias] = app;
cache[name] = app;
return app;
}
var search = {name, options};
this.base.emit('unresolved', search, this);
if (search.app) {
cache[search.app.name] = search.app;
cache[search.app.alias] = search.app;
return search.app;
}
cache[name] = null;
} | [
"function",
"fn",
"(",
"name",
",",
"options",
")",
"{",
"debug",
"(",
"'.findGenerator'",
",",
"name",
")",
";",
"if",
"(",
"utils",
".",
"isObject",
"(",
"name",
")",
")",
"{",
"return",
"name",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"name",
")",
")",
"{",
"name",
"=",
"name",
".",
"join",
"(",
"'.'",
")",
";",
"}",
"if",
"(",
"typeof",
"name",
"!==",
"'string'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected name to be a string'",
")",
";",
"}",
"if",
"(",
"cache",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"return",
"cache",
"[",
"name",
"]",
";",
"}",
"var",
"app",
"=",
"this",
".",
"generators",
"[",
"name",
"]",
"||",
"this",
".",
"base",
".",
"generators",
"[",
"name",
"]",
"||",
"this",
".",
"_findGenerator",
"(",
"name",
",",
"options",
")",
";",
"if",
"(",
"typeof",
"app",
"===",
"'undefined'",
"&&",
"this",
".",
"hasOwnProperty",
"(",
"'parent'",
")",
")",
"{",
"app",
"=",
"this",
".",
"base",
".",
"_findGenerator",
"(",
"name",
",",
"options",
")",
";",
"}",
"if",
"(",
"app",
")",
"{",
"cache",
"[",
"app",
".",
"name",
"]",
"=",
"app",
";",
"cache",
"[",
"app",
".",
"alias",
"]",
"=",
"app",
";",
"cache",
"[",
"name",
"]",
"=",
"app",
";",
"return",
"app",
";",
"}",
"var",
"search",
"=",
"{",
"name",
",",
"options",
"}",
";",
"this",
".",
"base",
".",
"emit",
"(",
"'unresolved'",
",",
"search",
",",
"this",
")",
";",
"if",
"(",
"search",
".",
"app",
")",
"{",
"cache",
"[",
"search",
".",
"app",
".",
"name",
"]",
"=",
"search",
".",
"app",
";",
"cache",
"[",
"search",
".",
"app",
".",
"alias",
"]",
"=",
"search",
".",
"app",
";",
"return",
"search",
".",
"app",
";",
"}",
"cache",
"[",
"name",
"]",
"=",
"null",
";",
"}"
]
| Find generator `name`, by first searching the cache, then searching the
cache of the `base` generator. Use this to get a generator without invoking it.
```js
// search by "alias"
var foo = app.findGenerator('foo');
// search by "full name"
var foo = app.findGenerator('generate-foo');
```
@name .findGenerator
@param {String} `name`
@param {Function} `options` Optionally supply a rename function on `options.toAlias`
@return {Object|undefined} Returns the generator instance if found, or undefined.
@api public | [
"Find",
"generator",
"name",
"by",
"first",
"searching",
"the",
"cache",
"then",
"searching",
"the",
"cache",
"of",
"the",
"base",
"generator",
".",
"Use",
"this",
"to",
"get",
"a",
"generator",
"without",
"invoking",
"it",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L179-L222 | train |
base/base-generators | index.js | function(name, options) {
if (this.generators.hasOwnProperty(name)) {
return this.generators[name];
}
if (~name.indexOf('.')) {
return this.getSubGenerator.apply(this, arguments);
}
var opts = utils.extend({}, this.options, options);
if (typeof opts.lookup === 'function') {
var app = this.lookupGenerator(name, opts, opts.lookup);
if (app) {
return app;
}
}
return this.matchGenerator(name);
} | javascript | function(name, options) {
if (this.generators.hasOwnProperty(name)) {
return this.generators[name];
}
if (~name.indexOf('.')) {
return this.getSubGenerator.apply(this, arguments);
}
var opts = utils.extend({}, this.options, options);
if (typeof opts.lookup === 'function') {
var app = this.lookupGenerator(name, opts, opts.lookup);
if (app) {
return app;
}
}
return this.matchGenerator(name);
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"if",
"(",
"this",
".",
"generators",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"return",
"this",
".",
"generators",
"[",
"name",
"]",
";",
"}",
"if",
"(",
"~",
"name",
".",
"indexOf",
"(",
"'.'",
")",
")",
"{",
"return",
"this",
".",
"getSubGenerator",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}",
"var",
"opts",
"=",
"utils",
".",
"extend",
"(",
"{",
"}",
",",
"this",
".",
"options",
",",
"options",
")",
";",
"if",
"(",
"typeof",
"opts",
".",
"lookup",
"===",
"'function'",
")",
"{",
"var",
"app",
"=",
"this",
".",
"lookupGenerator",
"(",
"name",
",",
"opts",
",",
"opts",
".",
"lookup",
")",
";",
"if",
"(",
"app",
")",
"{",
"return",
"app",
";",
"}",
"}",
"return",
"this",
".",
"matchGenerator",
"(",
"name",
")",
";",
"}"
]
| Private method used by `.findGenerator`. | [
"Private",
"method",
"used",
"by",
".",
"findGenerator",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L228-L245 | train |
|
base/base-generators | index.js | function(name, options) {
debug('.getSubGenerator', name);
var segs = name.split('.');
var len = segs.length;
var idx = -1;
var app = this;
while (++idx < len) {
var key = segs[idx];
app = app.getGenerator(key, options);
if (!app) {
break;
}
}
return app;
} | javascript | function(name, options) {
debug('.getSubGenerator', name);
var segs = name.split('.');
var len = segs.length;
var idx = -1;
var app = this;
while (++idx < len) {
var key = segs[idx];
app = app.getGenerator(key, options);
if (!app) {
break;
}
}
return app;
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"debug",
"(",
"'.getSubGenerator'",
",",
"name",
")",
";",
"var",
"segs",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"len",
"=",
"segs",
".",
"length",
";",
"var",
"idx",
"=",
"-",
"1",
";",
"var",
"app",
"=",
"this",
";",
"while",
"(",
"++",
"idx",
"<",
"len",
")",
"{",
"var",
"key",
"=",
"segs",
"[",
"idx",
"]",
";",
"app",
"=",
"app",
".",
"getGenerator",
"(",
"key",
",",
"options",
")",
";",
"if",
"(",
"!",
"app",
")",
"{",
"break",
";",
"}",
"}",
"return",
"app",
";",
"}"
]
| Get sub-generator `name`, optionally using dot-notation for nested generators.
```js
app.getSubGenerator('foo.bar.baz');
```
@name .getSubGenerator
@param {String} `name` The property-path of the generator to get
@param {Object} `options`
@api public | [
"Get",
"sub",
"-",
"generator",
"name",
"optionally",
"using",
"dot",
"-",
"notation",
"for",
"nested",
"generators",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L259-L274 | train |
|
base/base-generators | index.js | function(name, options, fn) {
debug('.lookupGenerator', name);
if (typeof options === 'function') {
fn = options;
options = {};
}
if (typeof fn !== 'function') {
throw new TypeError('expected `fn` to be a lookup function');
}
options = options || {};
// remove `lookup` fn from options to prevent self-recursion
delete this.options.lookup;
delete options.lookup;
var names = fn(name);
debug('looking up generator "%s" with "%j"', name, names);
var len = names.length;
var idx = -1;
while (++idx < len) {
var gen = this.findGenerator(names[idx], options);
if (gen) {
this.options.lookup = fn;
return gen;
}
}
this.options.lookup = fn;
} | javascript | function(name, options, fn) {
debug('.lookupGenerator', name);
if (typeof options === 'function') {
fn = options;
options = {};
}
if (typeof fn !== 'function') {
throw new TypeError('expected `fn` to be a lookup function');
}
options = options || {};
// remove `lookup` fn from options to prevent self-recursion
delete this.options.lookup;
delete options.lookup;
var names = fn(name);
debug('looking up generator "%s" with "%j"', name, names);
var len = names.length;
var idx = -1;
while (++idx < len) {
var gen = this.findGenerator(names[idx], options);
if (gen) {
this.options.lookup = fn;
return gen;
}
}
this.options.lookup = fn;
} | [
"function",
"(",
"name",
",",
"options",
",",
"fn",
")",
"{",
"debug",
"(",
"'.lookupGenerator'",
",",
"name",
")",
";",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"fn",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"typeof",
"fn",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected `fn` to be a lookup function'",
")",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"delete",
"this",
".",
"options",
".",
"lookup",
";",
"delete",
"options",
".",
"lookup",
";",
"var",
"names",
"=",
"fn",
"(",
"name",
")",
";",
"debug",
"(",
"'looking up generator \"%s\" with \"%j\"'",
",",
"name",
",",
"names",
")",
";",
"var",
"len",
"=",
"names",
".",
"length",
";",
"var",
"idx",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"idx",
"<",
"len",
")",
"{",
"var",
"gen",
"=",
"this",
".",
"findGenerator",
"(",
"names",
"[",
"idx",
"]",
",",
"options",
")",
";",
"if",
"(",
"gen",
")",
"{",
"this",
".",
"options",
".",
"lookup",
"=",
"fn",
";",
"return",
"gen",
";",
"}",
"}",
"this",
".",
"options",
".",
"lookup",
"=",
"fn",
";",
"}"
]
| Tries to find a registered generator that matches `name`
by iterating over the `generators` object, and doing a strict
comparison of each name returned by the given lookup `fn`.
The lookup function receives `name` and must return an array
of names to use for the lookup.
For example, if the lookup `name` is `foo`, the function might
return `["generator-foo", "foo"]`, to ensure that the lookup happens
in that order.
@param {String} `name` Generator name to search for
@param {Object} `options`
@param {Function} `fn` Lookup function that must return an array of names.
@return {Object}
@api public | [
"Tries",
"to",
"find",
"a",
"registered",
"generator",
"that",
"matches",
"name",
"by",
"iterating",
"over",
"the",
"generators",
"object",
"and",
"doing",
"a",
"strict",
"comparison",
"of",
"each",
"name",
"returned",
"by",
"the",
"given",
"lookup",
"fn",
".",
"The",
"lookup",
"function",
"receives",
"name",
"and",
"must",
"return",
"an",
"array",
"of",
"names",
"to",
"use",
"for",
"the",
"lookup",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L329-L361 | train |
|
base/base-generators | index.js | function(name, options) {
if (typeof name === 'function') {
this.use(name, options);
return this;
}
if (Array.isArray(name)) {
var len = name.length;
var idx = -1;
while (++idx < len) {
this.extendWith(name[idx], options);
}
return this;
}
var app = name;
if (typeof name === 'string') {
app = this.generators[name] || this.findGenerator(name, options);
if (!app && utils.exists(name)) {
var fn = utils.tryRequire(name, this.cwd);
if (typeof fn === 'function') {
app = this.register(name, fn);
}
}
}
if (!utils.isValidInstance(app)) {
throw new Error('cannot find generator: "' + name + '"');
}
var alias = app.env ? app.env.alias : 'default';
debug('extending "%s" with "%s"', alias, name);
app.run(this);
app.invoke(options, this);
return this;
} | javascript | function(name, options) {
if (typeof name === 'function') {
this.use(name, options);
return this;
}
if (Array.isArray(name)) {
var len = name.length;
var idx = -1;
while (++idx < len) {
this.extendWith(name[idx], options);
}
return this;
}
var app = name;
if (typeof name === 'string') {
app = this.generators[name] || this.findGenerator(name, options);
if (!app && utils.exists(name)) {
var fn = utils.tryRequire(name, this.cwd);
if (typeof fn === 'function') {
app = this.register(name, fn);
}
}
}
if (!utils.isValidInstance(app)) {
throw new Error('cannot find generator: "' + name + '"');
}
var alias = app.env ? app.env.alias : 'default';
debug('extending "%s" with "%s"', alias, name);
app.run(this);
app.invoke(options, this);
return this;
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"name",
"===",
"'function'",
")",
"{",
"this",
".",
"use",
"(",
"name",
",",
"options",
")",
";",
"return",
"this",
";",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"name",
")",
")",
"{",
"var",
"len",
"=",
"name",
".",
"length",
";",
"var",
"idx",
"=",
"-",
"1",
";",
"while",
"(",
"++",
"idx",
"<",
"len",
")",
"{",
"this",
".",
"extendWith",
"(",
"name",
"[",
"idx",
"]",
",",
"options",
")",
";",
"}",
"return",
"this",
";",
"}",
"var",
"app",
"=",
"name",
";",
"if",
"(",
"typeof",
"name",
"===",
"'string'",
")",
"{",
"app",
"=",
"this",
".",
"generators",
"[",
"name",
"]",
"||",
"this",
".",
"findGenerator",
"(",
"name",
",",
"options",
")",
";",
"if",
"(",
"!",
"app",
"&&",
"utils",
".",
"exists",
"(",
"name",
")",
")",
"{",
"var",
"fn",
"=",
"utils",
".",
"tryRequire",
"(",
"name",
",",
"this",
".",
"cwd",
")",
";",
"if",
"(",
"typeof",
"fn",
"===",
"'function'",
")",
"{",
"app",
"=",
"this",
".",
"register",
"(",
"name",
",",
"fn",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"utils",
".",
"isValidInstance",
"(",
"app",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'cannot find generator: \"'",
"+",
"name",
"+",
"'\"'",
")",
";",
"}",
"var",
"alias",
"=",
"app",
".",
"env",
"?",
"app",
".",
"env",
".",
"alias",
":",
"'default'",
";",
"debug",
"(",
"'extending \"%s\" with \"%s\"'",
",",
"alias",
",",
"name",
")",
";",
"app",
".",
"run",
"(",
"this",
")",
";",
"app",
".",
"invoke",
"(",
"options",
",",
"this",
")",
";",
"return",
"this",
";",
"}"
]
| Extend the generator instance with settings and features
of another generator.
```js
var foo = base.generator('foo');
app.extendWith(foo);
// or
app.extendWith('foo');
// or
app.extendWith(['foo', 'bar', 'baz']);
app.extendWith(require('generate-defaults'));
```
@name .extendWith
@param {String|Object} `app`
@return {Object} Returns the instance for chaining.
@api public | [
"Extend",
"the",
"generator",
"instance",
"with",
"settings",
"and",
"features",
"of",
"another",
"generator",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L384-L419 | train |
|
base/base-generators | index.js | function(name, options) {
if (typeof options === 'function') {
return options(name);
}
if (options && typeof options.toAlias === 'function') {
return options.toAlias(name);
}
if (typeof app.options.toAlias === 'function') {
return app.options.toAlias(name);
}
return name;
} | javascript | function(name, options) {
if (typeof options === 'function') {
return options(name);
}
if (options && typeof options.toAlias === 'function') {
return options.toAlias(name);
}
if (typeof app.options.toAlias === 'function') {
return app.options.toAlias(name);
}
return name;
} | [
"function",
"(",
"name",
",",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"return",
"options",
"(",
"name",
")",
";",
"}",
"if",
"(",
"options",
"&&",
"typeof",
"options",
".",
"toAlias",
"===",
"'function'",
")",
"{",
"return",
"options",
".",
"toAlias",
"(",
"name",
")",
";",
"}",
"if",
"(",
"typeof",
"app",
".",
"options",
".",
"toAlias",
"===",
"'function'",
")",
"{",
"return",
"app",
".",
"options",
".",
"toAlias",
"(",
"name",
")",
";",
"}",
"return",
"name",
";",
"}"
]
| Create a generator alias from the given `name`. By default the alias
is the string after the last dash. Or the whole string if no dash exists.
```js
var camelcase = require('camel-case');
var alias = app.toAlias('foo-bar-baz');
//=> 'baz'
// custom `toAlias` function
app.option('toAlias', function(name) {
return camelcase(name);
});
var alias = app.toAlias('foo-bar-baz');
//=> 'fooBarBaz'
```
@name .toAlias
@param {String} `name`
@param {Object} `options`
@return {String} Returns the alias.
@api public | [
"Create",
"a",
"generator",
"alias",
"from",
"the",
"given",
"name",
".",
"By",
"default",
"the",
"alias",
"is",
"the",
"string",
"after",
"the",
"last",
"dash",
".",
"Or",
"the",
"whole",
"string",
"if",
"no",
"dash",
"exists",
"."
]
| 9a741117b80ed19b281177169c0f98059cb97c90 | https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L554-L565 | train |
|
jonschlinkert/lang-map | index.js | map | function map() {
var cache = {};
if (!cache.extensions) cache.extensions = require('./lib/exts.json');
if (!cache.languages) cache.languages = require('./lib/lang.json');
return cache;
} | javascript | function map() {
var cache = {};
if (!cache.extensions) cache.extensions = require('./lib/exts.json');
if (!cache.languages) cache.languages = require('./lib/lang.json');
return cache;
} | [
"function",
"map",
"(",
")",
"{",
"var",
"cache",
"=",
"{",
"}",
";",
"if",
"(",
"!",
"cache",
".",
"extensions",
")",
"cache",
".",
"extensions",
"=",
"require",
"(",
"'./lib/exts.json'",
")",
";",
"if",
"(",
"!",
"cache",
".",
"languages",
")",
"cache",
".",
"languages",
"=",
"require",
"(",
"'./lib/lang.json'",
")",
";",
"return",
"cache",
";",
"}"
]
| Lazy-load and cache extensions and languages | [
"Lazy",
"-",
"load",
"and",
"cache",
"extensions",
"and",
"languages"
]
| d12ec51ffda3a4bffee9e7cfb49c1e400af145a6 | https://github.com/jonschlinkert/lang-map/blob/d12ec51ffda3a4bffee9e7cfb49c1e400af145a6/index.js#L11-L16 | train |
presort/pre-toast | lib/utils/Assertions.js | isUrl | function isUrl(url, error) {
if (!Assertions.urlPattern.test(url)) {
if (error) {
throw new Error("Given url is not valid ! URL :" + url);
}
return false;
}
return true;
} | javascript | function isUrl(url, error) {
if (!Assertions.urlPattern.test(url)) {
if (error) {
throw new Error("Given url is not valid ! URL :" + url);
}
return false;
}
return true;
} | [
"function",
"isUrl",
"(",
"url",
",",
"error",
")",
"{",
"if",
"(",
"!",
"Assertions",
".",
"urlPattern",
".",
"test",
"(",
"url",
")",
")",
"{",
"if",
"(",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Given url is not valid ! URL :\"",
"+",
"url",
")",
";",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks if the string is a valid URL.
@param {String} url string to check.
@param {boolean} error defines the return type of method. If it is true it will throw in case of error , else it will return false.
@returns {boolean} "true": is url , "false": is not url.
@throws exception if error is true and url provided is not valid. | [
"Checks",
"if",
"the",
"string",
"is",
"a",
"valid",
"URL",
"."
]
| 0a6b329dd37cd68c70735b8703869b8c03800a71 | https://github.com/presort/pre-toast/blob/0a6b329dd37cd68c70735b8703869b8c03800a71/lib/utils/Assertions.js#L66-L74 | train |
presort/pre-toast | lib/utils/Assertions.js | isReactComponent | function isReactComponent(instance, error) {
/* disable-eslint no-underscore-dangle */
if (!(instance && instance.$$typeof)) {
if (error) {
throw new Error("Given component is not a react component ! Component :" + instance);
}
return false;
}
return true;
} | javascript | function isReactComponent(instance, error) {
/* disable-eslint no-underscore-dangle */
if (!(instance && instance.$$typeof)) {
if (error) {
throw new Error("Given component is not a react component ! Component :" + instance);
}
return false;
}
return true;
} | [
"function",
"isReactComponent",
"(",
"instance",
",",
"error",
")",
"{",
"if",
"(",
"!",
"(",
"instance",
"&&",
"instance",
".",
"$$typeof",
")",
")",
"{",
"if",
"(",
"error",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Given component is not a react component ! Component :\"",
"+",
"instance",
")",
";",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks instance is React Component or not.
@param {Object} instance
@param {boolean} error
@returns {boolean} | [
"Checks",
"instance",
"is",
"React",
"Component",
"or",
"not",
"."
]
| 0a6b329dd37cd68c70735b8703869b8c03800a71 | https://github.com/presort/pre-toast/blob/0a6b329dd37cd68c70735b8703869b8c03800a71/lib/utils/Assertions.js#L314-L323 | train |
MaximilianBuegler/node-kinetics | src/kinetics.js | extractVerticalComponent | function extractVerticalComponent(accelerometerData, attitudeData) {
var res=[];
var rm;
for (var i=0;i<accelerometerData.length;i++){
rm=new Matrix(module.exports.composeRotation(attitudeData[i][0],attitudeData[i][1],0));
res[i]=new Matrix([accelerometerData[i][0],accelerometerData[i][1],accelerometerData[i][2]]).dot(rm).data[0][2];
}
return res;
} | javascript | function extractVerticalComponent(accelerometerData, attitudeData) {
var res=[];
var rm;
for (var i=0;i<accelerometerData.length;i++){
rm=new Matrix(module.exports.composeRotation(attitudeData[i][0],attitudeData[i][1],0));
res[i]=new Matrix([accelerometerData[i][0],accelerometerData[i][1],accelerometerData[i][2]]).dot(rm).data[0][2];
}
return res;
} | [
"function",
"extractVerticalComponent",
"(",
"accelerometerData",
",",
"attitudeData",
")",
"{",
"var",
"res",
"=",
"[",
"]",
";",
"var",
"rm",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"accelerometerData",
".",
"length",
";",
"i",
"++",
")",
"{",
"rm",
"=",
"new",
"Matrix",
"(",
"module",
".",
"exports",
".",
"composeRotation",
"(",
"attitudeData",
"[",
"i",
"]",
"[",
"0",
"]",
",",
"attitudeData",
"[",
"i",
"]",
"[",
"1",
"]",
",",
"0",
")",
")",
";",
"res",
"[",
"i",
"]",
"=",
"new",
"Matrix",
"(",
"[",
"accelerometerData",
"[",
"i",
"]",
"[",
"0",
"]",
",",
"accelerometerData",
"[",
"i",
"]",
"[",
"1",
"]",
",",
"accelerometerData",
"[",
"i",
"]",
"[",
"2",
"]",
"]",
")",
".",
"dot",
"(",
"rm",
")",
".",
"data",
"[",
"0",
"]",
"[",
"2",
"]",
";",
"}",
"return",
"res",
";",
"}"
]
| Rotate accelerometer signal using attitude data and extract vertical component.
Useful for instance for implementing a pedometer
@param {2D array} (linear) accelerometerData 2D array containing time series of acceleration values [[x1, y1, z1],[x2, y2, z2],...]
@param {2D array} attitudeData 2D array containing time series of attitude values [[pitch1, roll1, yaw1]. [pitch2, roll2, yaw2],... ] (in Radians)
@returns {1D array} of vertical acceleration values [z1, z2,...] | [
"Rotate",
"accelerometer",
"signal",
"using",
"attitude",
"data",
"and",
"extract",
"vertical",
"component",
".",
"Useful",
"for",
"instance",
"for",
"implementing",
"a",
"pedometer"
]
| fdaea742843014227e42e12bea40827b7fc3d516 | https://github.com/MaximilianBuegler/node-kinetics/blob/fdaea742843014227e42e12bea40827b7fc3d516/src/kinetics.js#L34-L42 | train |
observing/mongo-query-filter | index.js | Filter | function Filter(options) {
this.options = options || {};
for (var group in operators) {
var prop = group.toLowerCase();
this[prop] = this.mask(group, this.options[prop]);
}
} | javascript | function Filter(options) {
this.options = options || {};
for (var group in operators) {
var prop = group.toLowerCase();
this[prop] = this.mask(group, this.options[prop]);
}
} | [
"function",
"Filter",
"(",
"options",
")",
"{",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"for",
"(",
"var",
"group",
"in",
"operators",
")",
"{",
"var",
"prop",
"=",
"group",
".",
"toLowerCase",
"(",
")",
";",
"this",
"[",
"prop",
"]",
"=",
"this",
".",
"mask",
"(",
"group",
",",
"this",
".",
"options",
"[",
"prop",
"]",
")",
";",
"}",
"}"
]
| Strip MongoDB operators from user provided objects.
@Constructor
@param {Object} options
@api public | [
"Strip",
"MongoDB",
"operators",
"from",
"user",
"provided",
"objects",
"."
]
| 32bcb4b2cbce3c84022bba449f67cc048978b52e | https://github.com/observing/mongo-query-filter/blob/32bcb4b2cbce3c84022bba449f67cc048978b52e/index.js#L12-L19 | train |
worldline/easydoc | lib/easydoc.js | errorPage | function errorPage(res, err) {
if (err) {
console.error(err.message);
res.send(err, {'Content-Type': 'text/plain'}, 500);
} else {
res.send(404);
}
} | javascript | function errorPage(res, err) {
if (err) {
console.error(err.message);
res.send(err, {'Content-Type': 'text/plain'}, 500);
} else {
res.send(404);
}
} | [
"function",
"errorPage",
"(",
"res",
",",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"err",
".",
"message",
")",
";",
"res",
".",
"send",
"(",
"err",
",",
"{",
"'Content-Type'",
":",
"'text/plain'",
"}",
",",
"500",
")",
";",
"}",
"else",
"{",
"res",
".",
"send",
"(",
"404",
")",
";",
"}",
"}"
]
| Displays an HTTP error response. If an error is provided, the error is displayed with a 500 error code, otherwise it's a empty 404 error. @param res [Object] Http response @param err [String] Error message. Facultative. | [
"Displays",
"an",
"HTTP",
"error",
"response",
".",
"If",
"an",
"error",
"is",
"provided",
"the",
"error",
"is",
"displayed",
"with",
"a",
"500",
"error",
"code",
"otherwise",
"it",
"s",
"a",
"empty",
"404",
"error",
"."
]
| c055d5aa99be460fef38ac629909ea4a653aaaaf | https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L61-L68 | train |
worldline/easydoc | lib/easydoc.js | compileAndRender | function compileAndRender(templatePath, content, callback) {
if (templatePath in templates) {
return callback(null, templates[templatePath].render(content));
}
fs.readFile(templatePath, 'utf8', function(err, template) {
if (err) {
return callback(err)
}
templates[templatePath] = hogan.compile(template);
callback(null, templates[templatePath].render(content));
})
} | javascript | function compileAndRender(templatePath, content, callback) {
if (templatePath in templates) {
return callback(null, templates[templatePath].render(content));
}
fs.readFile(templatePath, 'utf8', function(err, template) {
if (err) {
return callback(err)
}
templates[templatePath] = hogan.compile(template);
callback(null, templates[templatePath].render(content));
})
} | [
"function",
"compileAndRender",
"(",
"templatePath",
",",
"content",
",",
"callback",
")",
"{",
"if",
"(",
"templatePath",
"in",
"templates",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"templates",
"[",
"templatePath",
"]",
".",
"render",
"(",
"content",
")",
")",
";",
"}",
"fs",
".",
"readFile",
"(",
"templatePath",
",",
"'utf8'",
",",
"function",
"(",
"err",
",",
"template",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
"}",
"templates",
"[",
"templatePath",
"]",
"=",
"hogan",
".",
"compile",
"(",
"template",
")",
";",
"callback",
"(",
"null",
",",
"templates",
"[",
"templatePath",
"]",
".",
"render",
"(",
"content",
")",
")",
";",
"}",
")",
"}"
]
| Render a given template with appropriate content. Use cached pre-compiled template if possible, and populate cache for new templates. @param templatePath [String] path to rendered template, used as key in cache @param content [Object] object used to be rendered inside the template @param callback [Function] end processing callback, invoked with arguments: @option callback err [Error] an error object, or null if no error occured @option callback html [String] Html rendering for this template | [
"Render",
"a",
"given",
"template",
"with",
"appropriate",
"content",
".",
"Use",
"cached",
"pre",
"-",
"compiled",
"template",
"if",
"possible",
"and",
"populate",
"cache",
"for",
"new",
"templates",
"."
]
| c055d5aa99be460fef38ac629909ea4a653aaaaf | https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L78-L89 | train |
worldline/easydoc | lib/easydoc.js | search | function search(searched, callback) {
var root = pathUtils.resolve(options.root);
// search command is platform dependant: use grep on linux, and findstr on windaube.
var command = os.platform() === 'win32' ?
'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') :
'grep -rin "'+searched+'" '+root;
// exec the command line.
exec(command, function (err, stdout, stderr) {
if (err) {
// a 1 error code means no results.
if (err.code === 1) {
err = null;
}
return callback(err, []);
}
// each line an occurence.
var lines = stdout.toString().split(root);
// remove files that are not markdown.
lines = _.filter(lines, function(val) {
return val.trim().length > 0;
});
// regroups by files
var grouped = {};
for(var i = 0; i < lines.length; i++) {
var numStart = lines[i].indexOf(':');
var numEnd = lines[i].indexOf(':', numStart+1);
// remove leading \
var fileName = lines[i].substring(1, numStart);
// ignore assets files
if (/^_assets/.test(fileName)) {
continue
}
if (!(fileName in grouped)) {
grouped[fileName] = [];
}
grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')});
}
// sort by relevance
var files = [];
for(var key in grouped) {
files.push({
path: key,
hits: grouped[key]
});
}
callback(null, files.sort(function(a, b) {
return b.hits.length - a.hits.length;
}));
});
} | javascript | function search(searched, callback) {
var root = pathUtils.resolve(options.root);
// search command is platform dependant: use grep on linux, and findstr on windaube.
var command = os.platform() === 'win32' ?
'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') :
'grep -rin "'+searched+'" '+root;
// exec the command line.
exec(command, function (err, stdout, stderr) {
if (err) {
// a 1 error code means no results.
if (err.code === 1) {
err = null;
}
return callback(err, []);
}
// each line an occurence.
var lines = stdout.toString().split(root);
// remove files that are not markdown.
lines = _.filter(lines, function(val) {
return val.trim().length > 0;
});
// regroups by files
var grouped = {};
for(var i = 0; i < lines.length; i++) {
var numStart = lines[i].indexOf(':');
var numEnd = lines[i].indexOf(':', numStart+1);
// remove leading \
var fileName = lines[i].substring(1, numStart);
// ignore assets files
if (/^_assets/.test(fileName)) {
continue
}
if (!(fileName in grouped)) {
grouped[fileName] = [];
}
grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')});
}
// sort by relevance
var files = [];
for(var key in grouped) {
files.push({
path: key,
hits: grouped[key]
});
}
callback(null, files.sort(function(a, b) {
return b.hits.length - a.hits.length;
}));
});
} | [
"function",
"search",
"(",
"searched",
",",
"callback",
")",
"{",
"var",
"root",
"=",
"pathUtils",
".",
"resolve",
"(",
"options",
".",
"root",
")",
";",
"var",
"command",
"=",
"os",
".",
"platform",
"(",
")",
"===",
"'win32'",
"?",
"'findstr /spin /c:\"'",
"+",
"searched",
"+",
"'\" '",
"+",
"pathUtils",
".",
"join",
"(",
"root",
",",
"'*.*'",
")",
":",
"'grep -rin \"'",
"+",
"searched",
"+",
"'\" '",
"+",
"root",
";",
"exec",
"(",
"command",
",",
"function",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"{",
"if",
"(",
"err",
")",
"{",
"if",
"(",
"err",
".",
"code",
"===",
"1",
")",
"{",
"err",
"=",
"null",
";",
"}",
"return",
"callback",
"(",
"err",
",",
"[",
"]",
")",
";",
"}",
"var",
"lines",
"=",
"stdout",
".",
"toString",
"(",
")",
".",
"split",
"(",
"root",
")",
";",
"lines",
"=",
"_",
".",
"filter",
"(",
"lines",
",",
"function",
"(",
"val",
")",
"{",
"return",
"val",
".",
"trim",
"(",
")",
".",
"length",
">",
"0",
";",
"}",
")",
";",
"var",
"grouped",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"numStart",
"=",
"lines",
"[",
"i",
"]",
".",
"indexOf",
"(",
"':'",
")",
";",
"var",
"numEnd",
"=",
"lines",
"[",
"i",
"]",
".",
"indexOf",
"(",
"':'",
",",
"numStart",
"+",
"1",
")",
";",
"var",
"fileName",
"=",
"lines",
"[",
"i",
"]",
".",
"substring",
"(",
"1",
",",
"numStart",
")",
";",
"if",
"(",
"/",
"^_assets",
"/",
".",
"test",
"(",
"fileName",
")",
")",
"{",
"continue",
"}",
"if",
"(",
"!",
"(",
"fileName",
"in",
"grouped",
")",
")",
"{",
"grouped",
"[",
"fileName",
"]",
"=",
"[",
"]",
";",
"}",
"grouped",
"[",
"fileName",
"]",
".",
"push",
"(",
"{",
"hit",
":",
"lines",
"[",
"i",
"]",
".",
"substring",
"(",
"numEnd",
"+",
"1",
")",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"searched",
",",
"'gi'",
")",
",",
"'<b>$&</b>'",
")",
"}",
")",
";",
"}",
"var",
"files",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"key",
"in",
"grouped",
")",
"{",
"files",
".",
"push",
"(",
"{",
"path",
":",
"key",
",",
"hits",
":",
"grouped",
"[",
"key",
"]",
"}",
")",
";",
"}",
"callback",
"(",
"null",
",",
"files",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"b",
".",
"hits",
".",
"length",
"-",
"a",
".",
"hits",
".",
"length",
";",
"}",
")",
")",
";",
"}",
")",
";",
"}"
]
| Performs a local-drive search by executing an os-specific command. Uses grep on linux, and findstr on windaube. @param callback [Function] A callback function that will received following arguments: @option callback err [String] an error if somthing goes wrong, null otherwise @option callback results [Array] an array (that may be empty) containing object with the following properties - path [String] file path, relative to root folder. - hits [Array] array of search occurence (strings). | [
"Performs",
"a",
"local",
"-",
"drive",
"search",
"by",
"executing",
"an",
"os",
"-",
"specific",
"command",
".",
"Uses",
"grep",
"on",
"linux",
"and",
"findstr",
"on",
"windaube",
"."
]
| c055d5aa99be460fef38ac629909ea4a653aaaaf | https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L162-L213 | train |
adrai/node-cqs | lib/domain/bases/commandHandlerBase.js | function(aggregate, vm, callback) {
if(aggregate.get('destroyed')) {
var reason = {
name: 'AggregateDestroyed',
message: 'Aggregate has already been destroyed!',
aggregateRevision: aggregate.get('revision'),
aggregateId: aggregate.id
};
return callback(reason);
}
callback(null, aggregate, vm);
} | javascript | function(aggregate, vm, callback) {
if(aggregate.get('destroyed')) {
var reason = {
name: 'AggregateDestroyed',
message: 'Aggregate has already been destroyed!',
aggregateRevision: aggregate.get('revision'),
aggregateId: aggregate.id
};
return callback(reason);
}
callback(null, aggregate, vm);
} | [
"function",
"(",
"aggregate",
",",
"vm",
",",
"callback",
")",
"{",
"if",
"(",
"aggregate",
".",
"get",
"(",
"'destroyed'",
")",
")",
"{",
"var",
"reason",
"=",
"{",
"name",
":",
"'AggregateDestroyed'",
",",
"message",
":",
"'Aggregate has already been destroyed!'",
",",
"aggregateRevision",
":",
"aggregate",
".",
"get",
"(",
"'revision'",
")",
",",
"aggregateId",
":",
"aggregate",
".",
"id",
"}",
";",
"return",
"callback",
"(",
"reason",
")",
";",
"}",
"callback",
"(",
"null",
",",
"aggregate",
",",
"vm",
")",
";",
"}"
]
| reject command if aggregate has already been destroyed | [
"reject",
"command",
"if",
"aggregate",
"has",
"already",
"been",
"destroyed"
]
| 1691670a6e35d0b20904a5bd1b74adbe92f496eb | https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L33-L45 | train |
|
adrai/node-cqs | lib/domain/bases/commandHandlerBase.js | function(aggregate, vm, callback) {
self.validate(cmd.command, cmd.payload, function(err) {
callback(err, aggregate, vm);
});
} | javascript | function(aggregate, vm, callback) {
self.validate(cmd.command, cmd.payload, function(err) {
callback(err, aggregate, vm);
});
} | [
"function",
"(",
"aggregate",
",",
"vm",
",",
"callback",
")",
"{",
"self",
".",
"validate",
"(",
"cmd",
".",
"command",
",",
"cmd",
".",
"payload",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"aggregate",
",",
"vm",
")",
";",
"}",
")",
";",
"}"
]
| call validate command | [
"call",
"validate",
"command"
]
| 1691670a6e35d0b20904a5bd1b74adbe92f496eb | https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L55-L59 | train |
|
adrai/node-cqs | lib/domain/bases/commandHandlerBase.js | function(aggregate, vm, callback) {
aggregate[cmd.command](cmd.payload, function(err) {
callback(err, aggregate, vm);
});
} | javascript | function(aggregate, vm, callback) {
aggregate[cmd.command](cmd.payload, function(err) {
callback(err, aggregate, vm);
});
} | [
"function",
"(",
"aggregate",
",",
"vm",
",",
"callback",
")",
"{",
"aggregate",
"[",
"cmd",
".",
"command",
"]",
"(",
"cmd",
".",
"payload",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"aggregate",
",",
"vm",
")",
";",
"}",
")",
";",
"}"
]
| call command function on aggregate | [
"call",
"command",
"function",
"on",
"aggregate"
]
| 1691670a6e35d0b20904a5bd1b74adbe92f496eb | https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L62-L66 | train |
|
adrai/node-cqs | lib/domain/bases/commandHandlerBase.js | function(aggregate, vm, callback) {
vm.set(aggregate.toJSON());
self.commit(vm, function(err) {
callback(err, aggregate, cmd);
});
} | javascript | function(aggregate, vm, callback) {
vm.set(aggregate.toJSON());
self.commit(vm, function(err) {
callback(err, aggregate, cmd);
});
} | [
"function",
"(",
"aggregate",
",",
"vm",
",",
"callback",
")",
"{",
"vm",
".",
"set",
"(",
"aggregate",
".",
"toJSON",
"(",
")",
")",
";",
"self",
".",
"commit",
"(",
"vm",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"aggregate",
",",
"cmd",
")",
";",
"}",
")",
";",
"}"
]
| commit the new events | [
"commit",
"the",
"new",
"events"
]
| 1691670a6e35d0b20904a5bd1b74adbe92f496eb | https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L69-L74 | train |
|
salesforce/refocus-collector-eval | src/RefocusCollectorEval.js | acceptMatcher | function acceptMatcher(acc, actual) {
/* Exact match or full wildcard match on both type and subtype */
if (actual.contentType === acc.item || acc.item === '*/*') return true;
/* Otherwise check for "*" wildcard matches */
const a = acc.item.split(MIME_SUBTYPE_SEPARATOR);
const accepted = {
type: a[0],
subtype: a[1],
};
/* Exact match type, wildcard subtype */
if (actual.type === accepted.type && accepted.subtype === '*') {
return true;
}
/* Wildcard type, exact match subtype */
if (accepted.type === '*' && accepted.subtype === actual.subtype) {
return true;
}
} | javascript | function acceptMatcher(acc, actual) {
/* Exact match or full wildcard match on both type and subtype */
if (actual.contentType === acc.item || acc.item === '*/*') return true;
/* Otherwise check for "*" wildcard matches */
const a = acc.item.split(MIME_SUBTYPE_SEPARATOR);
const accepted = {
type: a[0],
subtype: a[1],
};
/* Exact match type, wildcard subtype */
if (actual.type === accepted.type && accepted.subtype === '*') {
return true;
}
/* Wildcard type, exact match subtype */
if (accepted.type === '*' && accepted.subtype === actual.subtype) {
return true;
}
} | [
"function",
"acceptMatcher",
"(",
"acc",
",",
"actual",
")",
"{",
"if",
"(",
"actual",
".",
"contentType",
"===",
"acc",
".",
"item",
"||",
"acc",
".",
"item",
"===",
"'*/*'",
")",
"return",
"true",
";",
"const",
"a",
"=",
"acc",
".",
"item",
".",
"split",
"(",
"MIME_SUBTYPE_SEPARATOR",
")",
";",
"const",
"accepted",
"=",
"{",
"type",
":",
"a",
"[",
"0",
"]",
",",
"subtype",
":",
"a",
"[",
"1",
"]",
",",
"}",
";",
"if",
"(",
"actual",
".",
"type",
"===",
"accepted",
".",
"type",
"&&",
"accepted",
".",
"subtype",
"===",
"'*'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"accepted",
".",
"type",
"===",
"'*'",
"&&",
"accepted",
".",
"subtype",
"===",
"actual",
".",
"subtype",
")",
"{",
"return",
"true",
";",
"}",
"}"
]
| Checks whether the actual content type matches this particular accepted
type.
@param {Object} acc - one of the array elements returned by parsing the
Accept headers using "accept-parser"
@param {Object} actual - An object representing the actual content type
received, with attributes ["contentType", "type", "subtype"]
@returns {Boolean} true if the actual content type matches this particular
"Accept" entry, either an exact match or a wildcard match | [
"Checks",
"whether",
"the",
"actual",
"content",
"type",
"matches",
"this",
"particular",
"accepted",
"type",
"."
]
| 9d657a7e1627775ef44e84d532f9d50bb52d24e1 | https://github.com/salesforce/refocus-collector-eval/blob/9d657a7e1627775ef44e84d532f9d50bb52d24e1/src/RefocusCollectorEval.js#L39-L59 | train |
crcn/bindable.js | lib/object/index.js | function (property) {
var isString;
// optimal
if ((isString = (typeof property === "string")) && !~property.indexOf(".")) {
return this[property];
}
// avoid split if possible
var chain = isString ? property.split(".") : property,
currentValue = this,
currentProperty;
// go through all the properties
for (var i = 0, n = chain.length - 1; i < n; i++) {
currentValue = currentValue[chain[i]];
if (!currentValue) return;
}
// might be a bindable object
if(currentValue) return currentValue[chain[i]];
} | javascript | function (property) {
var isString;
// optimal
if ((isString = (typeof property === "string")) && !~property.indexOf(".")) {
return this[property];
}
// avoid split if possible
var chain = isString ? property.split(".") : property,
currentValue = this,
currentProperty;
// go through all the properties
for (var i = 0, n = chain.length - 1; i < n; i++) {
currentValue = currentValue[chain[i]];
if (!currentValue) return;
}
// might be a bindable object
if(currentValue) return currentValue[chain[i]];
} | [
"function",
"(",
"property",
")",
"{",
"var",
"isString",
";",
"if",
"(",
"(",
"isString",
"=",
"(",
"typeof",
"property",
"===",
"\"string\"",
")",
")",
"&&",
"!",
"~",
"property",
".",
"indexOf",
"(",
"\".\"",
")",
")",
"{",
"return",
"this",
"[",
"property",
"]",
";",
"}",
"var",
"chain",
"=",
"isString",
"?",
"property",
".",
"split",
"(",
"\".\"",
")",
":",
"property",
",",
"currentValue",
"=",
"this",
",",
"currentProperty",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"chain",
".",
"length",
"-",
"1",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"currentValue",
"=",
"currentValue",
"[",
"chain",
"[",
"i",
"]",
"]",
";",
"if",
"(",
"!",
"currentValue",
")",
"return",
";",
"}",
"if",
"(",
"currentValue",
")",
"return",
"currentValue",
"[",
"chain",
"[",
"i",
"]",
"]",
";",
"}"
]
| Returns a property stored in the bindable object context
@method get
@param {String} path path to the value. Can be something like `person.city.name`. | [
"Returns",
"a",
"property",
"stored",
"in",
"the",
"bindable",
"object",
"context"
]
| 562dcd4a0e208e2a11ac7613654b32b01c7d92ac | https://github.com/crcn/bindable.js/blob/562dcd4a0e208e2a11ac7613654b32b01c7d92ac/lib/object/index.js#L130-L154 | train |
|
crcn/bindable.js | lib/object/index.js | function (property, value) {
var isString, hasChanged, oldValue, chain;
// optimal
if ((isString = (typeof property === "string")) && !~property.indexOf(".")) {
hasChanged = (oldValue = this[property]) !== value;
if (hasChanged) this[property] = value;
} else {
// avoid split if possible
chain = isString ? property.split(".") : property;
var currentValue = this,
previousValue,
currentProperty,
newChain;
for (var i = 0, n = chain.length - 1; i < n; i++) {
currentProperty = chain[i];
previousValue = currentValue;
currentValue = currentValue[currentProperty];
// need to take into account functions - easier not to check
// if value exists
if (!currentValue /* || (typeof currentValue !== "object")*/) {
currentValue = previousValue[currentProperty] = {};
}
// is the previous value bindable? pass it on
if (currentValue.__isBindable) {
newChain = chain.slice(i + 1);
// check if the value has changed
hasChanged = (oldValue = currentValue.get(newChain)) !== value;
currentValue.set(newChain, value);
currentValue = oldValue;
break;
}
}
if (!newChain && (hasChanged = (currentValue !== value))) {
currentProperty = chain[i];
oldValue = currentValue[currentProperty];
currentValue[currentProperty] = value;
}
}
if (!hasChanged) return value;
var prop = chain ? chain.join(".") : property;
this.emit("change:" + prop, value, oldValue);
this.emit("change", prop, value, oldValue);
return value;
} | javascript | function (property, value) {
var isString, hasChanged, oldValue, chain;
// optimal
if ((isString = (typeof property === "string")) && !~property.indexOf(".")) {
hasChanged = (oldValue = this[property]) !== value;
if (hasChanged) this[property] = value;
} else {
// avoid split if possible
chain = isString ? property.split(".") : property;
var currentValue = this,
previousValue,
currentProperty,
newChain;
for (var i = 0, n = chain.length - 1; i < n; i++) {
currentProperty = chain[i];
previousValue = currentValue;
currentValue = currentValue[currentProperty];
// need to take into account functions - easier not to check
// if value exists
if (!currentValue /* || (typeof currentValue !== "object")*/) {
currentValue = previousValue[currentProperty] = {};
}
// is the previous value bindable? pass it on
if (currentValue.__isBindable) {
newChain = chain.slice(i + 1);
// check if the value has changed
hasChanged = (oldValue = currentValue.get(newChain)) !== value;
currentValue.set(newChain, value);
currentValue = oldValue;
break;
}
}
if (!newChain && (hasChanged = (currentValue !== value))) {
currentProperty = chain[i];
oldValue = currentValue[currentProperty];
currentValue[currentProperty] = value;
}
}
if (!hasChanged) return value;
var prop = chain ? chain.join(".") : property;
this.emit("change:" + prop, value, oldValue);
this.emit("change", prop, value, oldValue);
return value;
} | [
"function",
"(",
"property",
",",
"value",
")",
"{",
"var",
"isString",
",",
"hasChanged",
",",
"oldValue",
",",
"chain",
";",
"if",
"(",
"(",
"isString",
"=",
"(",
"typeof",
"property",
"===",
"\"string\"",
")",
")",
"&&",
"!",
"~",
"property",
".",
"indexOf",
"(",
"\".\"",
")",
")",
"{",
"hasChanged",
"=",
"(",
"oldValue",
"=",
"this",
"[",
"property",
"]",
")",
"!==",
"value",
";",
"if",
"(",
"hasChanged",
")",
"this",
"[",
"property",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"chain",
"=",
"isString",
"?",
"property",
".",
"split",
"(",
"\".\"",
")",
":",
"property",
";",
"var",
"currentValue",
"=",
"this",
",",
"previousValue",
",",
"currentProperty",
",",
"newChain",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"chain",
".",
"length",
"-",
"1",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"currentProperty",
"=",
"chain",
"[",
"i",
"]",
";",
"previousValue",
"=",
"currentValue",
";",
"currentValue",
"=",
"currentValue",
"[",
"currentProperty",
"]",
";",
"if",
"(",
"!",
"currentValue",
")",
"{",
"currentValue",
"=",
"previousValue",
"[",
"currentProperty",
"]",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"currentValue",
".",
"__isBindable",
")",
"{",
"newChain",
"=",
"chain",
".",
"slice",
"(",
"i",
"+",
"1",
")",
";",
"hasChanged",
"=",
"(",
"oldValue",
"=",
"currentValue",
".",
"get",
"(",
"newChain",
")",
")",
"!==",
"value",
";",
"currentValue",
".",
"set",
"(",
"newChain",
",",
"value",
")",
";",
"currentValue",
"=",
"oldValue",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"newChain",
"&&",
"(",
"hasChanged",
"=",
"(",
"currentValue",
"!==",
"value",
")",
")",
")",
"{",
"currentProperty",
"=",
"chain",
"[",
"i",
"]",
";",
"oldValue",
"=",
"currentValue",
"[",
"currentProperty",
"]",
";",
"currentValue",
"[",
"currentProperty",
"]",
"=",
"value",
";",
"}",
"}",
"if",
"(",
"!",
"hasChanged",
")",
"return",
"value",
";",
"var",
"prop",
"=",
"chain",
"?",
"chain",
".",
"join",
"(",
"\".\"",
")",
":",
"property",
";",
"this",
".",
"emit",
"(",
"\"change:\"",
"+",
"prop",
",",
"value",
",",
"oldValue",
")",
";",
"this",
".",
"emit",
"(",
"\"change\"",
",",
"prop",
",",
"value",
",",
"oldValue",
")",
";",
"return",
"value",
";",
"}"
]
| Sets a property on the bindable object's context
@method set
@param {String} path path to the value. Can be something like `person.city.name`. | [
"Sets",
"a",
"property",
"on",
"the",
"bindable",
"object",
"s",
"context"
]
| 562dcd4a0e208e2a11ac7613654b32b01c7d92ac | https://github.com/crcn/bindable.js/blob/562dcd4a0e208e2a11ac7613654b32b01c7d92ac/lib/object/index.js#L176-L235 | train |
|
crcn/bindable.js | lib/object/index.js | function () {
var obj = {}, value;
var keys = Object.keys(this);
for (var i = 0, n = keys.length; i < n; i++) {
var key = keys[i];
if (key.substr(0, 2) === "__") continue;
value = this[key];
if(value && value.__isBindable) {
value = value.toJSON();
}
obj[key] = value;
}
return obj;
} | javascript | function () {
var obj = {}, value;
var keys = Object.keys(this);
for (var i = 0, n = keys.length; i < n; i++) {
var key = keys[i];
if (key.substr(0, 2) === "__") continue;
value = this[key];
if(value && value.__isBindable) {
value = value.toJSON();
}
obj[key] = value;
}
return obj;
} | [
"function",
"(",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
",",
"value",
";",
"var",
"keys",
"=",
"Object",
".",
"keys",
"(",
"this",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"key",
".",
"substr",
"(",
"0",
",",
"2",
")",
"===",
"\"__\"",
")",
"continue",
";",
"value",
"=",
"this",
"[",
"key",
"]",
";",
"if",
"(",
"value",
"&&",
"value",
".",
"__isBindable",
")",
"{",
"value",
"=",
"value",
".",
"toJSON",
"(",
")",
";",
"}",
"obj",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"return",
"obj",
";",
"}"
]
| Converts the context to a JSON object
@method toJSON | [
"Converts",
"the",
"context",
"to",
"a",
"JSON",
"object"
]
| 562dcd4a0e208e2a11ac7613654b32b01c7d92ac | https://github.com/crcn/bindable.js/blob/562dcd4a0e208e2a11ac7613654b32b01c7d92ac/lib/object/index.js#L264-L282 | train |
|
ofzza/enTT | dist/entt.js | cast | function cast(data, EntityClass) {
// Check if/how EntityClass is defined or implied
if (!EntityClass && !_lodash2.default.isArray(data)) {
// No explicit class definition, casting data not array
return _dataManagement2.default.cast(data, this);
} else if (!EntityClass && _lodash2.default.isArray(data)) {
// No explicit class definition, casting data is array
return _dataManagement2.default.cast(data, [this]);
} else if (_lodash2.default.isArray(EntityClass) && EntityClass.length === 0) {
// Explicit class definition as array with implicit members
return _dataManagement2.default.cast(data, [this]);
} else if (_lodash2.default.isObject(EntityClass) && !_lodash2.default.isFunction(EntityClass) && _lodash2.default.values(EntityClass).length === 0) {
// Explicit class definition as hashmap with implicit members
return _dataManagement2.default.cast(data, _defineProperty({}, this.name, this));
} else {
// Explicit class definition
return _dataManagement2.default.cast(data, EntityClass);
}
} | javascript | function cast(data, EntityClass) {
// Check if/how EntityClass is defined or implied
if (!EntityClass && !_lodash2.default.isArray(data)) {
// No explicit class definition, casting data not array
return _dataManagement2.default.cast(data, this);
} else if (!EntityClass && _lodash2.default.isArray(data)) {
// No explicit class definition, casting data is array
return _dataManagement2.default.cast(data, [this]);
} else if (_lodash2.default.isArray(EntityClass) && EntityClass.length === 0) {
// Explicit class definition as array with implicit members
return _dataManagement2.default.cast(data, [this]);
} else if (_lodash2.default.isObject(EntityClass) && !_lodash2.default.isFunction(EntityClass) && _lodash2.default.values(EntityClass).length === 0) {
// Explicit class definition as hashmap with implicit members
return _dataManagement2.default.cast(data, _defineProperty({}, this.name, this));
} else {
// Explicit class definition
return _dataManagement2.default.cast(data, EntityClass);
}
} | [
"function",
"cast",
"(",
"data",
",",
"EntityClass",
")",
"{",
"if",
"(",
"!",
"EntityClass",
"&&",
"!",
"_lodash2",
".",
"default",
".",
"isArray",
"(",
"data",
")",
")",
"{",
"return",
"_dataManagement2",
".",
"default",
".",
"cast",
"(",
"data",
",",
"this",
")",
";",
"}",
"else",
"if",
"(",
"!",
"EntityClass",
"&&",
"_lodash2",
".",
"default",
".",
"isArray",
"(",
"data",
")",
")",
"{",
"return",
"_dataManagement2",
".",
"default",
".",
"cast",
"(",
"data",
",",
"[",
"this",
"]",
")",
";",
"}",
"else",
"if",
"(",
"_lodash2",
".",
"default",
".",
"isArray",
"(",
"EntityClass",
")",
"&&",
"EntityClass",
".",
"length",
"===",
"0",
")",
"{",
"return",
"_dataManagement2",
".",
"default",
".",
"cast",
"(",
"data",
",",
"[",
"this",
"]",
")",
";",
"}",
"else",
"if",
"(",
"_lodash2",
".",
"default",
".",
"isObject",
"(",
"EntityClass",
")",
"&&",
"!",
"_lodash2",
".",
"default",
".",
"isFunction",
"(",
"EntityClass",
")",
"&&",
"_lodash2",
".",
"default",
".",
"values",
"(",
"EntityClass",
")",
".",
"length",
"===",
"0",
")",
"{",
"return",
"_dataManagement2",
".",
"default",
".",
"cast",
"(",
"data",
",",
"_defineProperty",
"(",
"{",
"}",
",",
"this",
".",
"name",
",",
"this",
")",
")",
";",
"}",
"else",
"{",
"return",
"_dataManagement2",
".",
"default",
".",
"cast",
"(",
"data",
",",
"EntityClass",
")",
";",
"}",
"}"
]
| Casts provided data as a EnTT instance of given type
@export
@param {any} data Data to cast
@param {any} EntityClass Extended EnTT class to cast as
- if not provided, will cast to EnTT class this static method is being called from
- if empty array provided, will cast to array of instances of EnTT class this static method is being called from
- if empty hashmap provided, will cast to array of instances of EnTT class this static method is being called from
@returns {any} Instance of required EnTT class with provided data cast into it | [
"Casts",
"provided",
"data",
"as",
"a",
"EnTT",
"instance",
"of",
"given",
"type"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/dist/entt.js#L74-L92 | train |
ofzza/enTT | dist/entt.js | getClassExtensions | function getClassExtensions(classes) {
// Extract property definitions from all inherited classes' static ".props" property
var extensions = _lodash2.default.reduceRight(classes, function (extensions, current) {
var extensionsArray = current.includes ? _lodash2.default.isArray(current.includes) ? current.includes : [current.includes] : [];
_lodash2.default.forEach(extensionsArray, function (extension) {
extensions.push(extension);
});
return extensions;
}, []);
// Return extracted properties
return extensions;
} | javascript | function getClassExtensions(classes) {
// Extract property definitions from all inherited classes' static ".props" property
var extensions = _lodash2.default.reduceRight(classes, function (extensions, current) {
var extensionsArray = current.includes ? _lodash2.default.isArray(current.includes) ? current.includes : [current.includes] : [];
_lodash2.default.forEach(extensionsArray, function (extension) {
extensions.push(extension);
});
return extensions;
}, []);
// Return extracted properties
return extensions;
} | [
"function",
"getClassExtensions",
"(",
"classes",
")",
"{",
"var",
"extensions",
"=",
"_lodash2",
".",
"default",
".",
"reduceRight",
"(",
"classes",
",",
"function",
"(",
"extensions",
",",
"current",
")",
"{",
"var",
"extensionsArray",
"=",
"current",
".",
"includes",
"?",
"_lodash2",
".",
"default",
".",
"isArray",
"(",
"current",
".",
"includes",
")",
"?",
"current",
".",
"includes",
":",
"[",
"current",
".",
"includes",
"]",
":",
"[",
"]",
";",
"_lodash2",
".",
"default",
".",
"forEach",
"(",
"extensionsArray",
",",
"function",
"(",
"extension",
")",
"{",
"extensions",
".",
"push",
"(",
"extension",
")",
";",
"}",
")",
";",
"return",
"extensions",
";",
"}",
",",
"[",
"]",
")",
";",
"return",
"extensions",
";",
"}"
]
| Gets class extensions by traversing and merging static ".includes" property of the instance's class and it's inherited classes
@param {any} classes Array of inherited from classes
@returns {any} Array of extensions applied to the class | [
"Gets",
"class",
"extensions",
"by",
"traversing",
"and",
"merging",
"static",
".",
"includes",
"property",
"of",
"the",
"instance",
"s",
"class",
"and",
"it",
"s",
"inherited",
"classes"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/dist/entt.js#L229-L242 | train |
ofzza/enTT | dist/entt.js | getClassProperties | function getClassProperties(classes) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
extensionsManager = _ref.extensionsManager;
// Define checks for shorthand casting configurations
var isPropertyShorthandCastAsSingleEntity = function isPropertyShorthandCastAsSingleEntity(propertyConfiguration) {
if (propertyConfiguration
// Check if class extending EnTT
&& propertyConfiguration.prototype instanceof EnTT) {
return propertyConfiguration;
}
};
var isPropertyShorthandCastAsEntityArray = function isPropertyShorthandCastAsEntityArray(propertyConfiguration) {
if (propertyConfiguration
// Check if array
&& _lodash2.default.isArray(propertyConfiguration)
// Check if array has a single member
&& propertyConfiguration.length === 1
// Check if single array memeber is a class extending EnTT
&& propertyConfiguration[0].prototype instanceof EnTT) {
return propertyConfiguration[0];
}
};
var isPropertyShorthandCastAsEntityHashmap = function isPropertyShorthandCastAsEntityHashmap(propertyConfiguration) {
if (propertyConfiguration
// Check if object
&& _lodash2.default.isObject(propertyConfiguration)
// Check if object has a single member
&& _lodash2.default.values(propertyConfiguration).length
// Check if single object member is a class extending EnTT
&& _lodash2.default.values(propertyConfiguration)[0].prototype instanceof EnTT
// Check if single object member's property key equals class name
&& _lodash2.default.keys(propertyConfiguration)[0] === _lodash2.default.values(propertyConfiguration)[0].name) {
return _lodash2.default.values(propertyConfiguration)[0];
}
};
// Extract property definitions from all inherited classes' static ".props" property
var properties = _lodash2.default.reduceRight(classes, function (properties, current) {
// Extract currentProperties
var currentProperties = current.props,
CastClass = void 0;
// Edit short-hand configuration syntax where possible
_lodash2.default.forEach(currentProperties, function (propertyConfiguration, propertyName) {
// Replace "casting properties" short-hand configuration syntax for single entity
CastClass = isPropertyShorthandCastAsSingleEntity(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-single-entity syntax
currentProperties[propertyName] = { cast: propertyConfiguration };
return;
}
// Replace "casting properties" short-hand configuration syntax for entity array
CastClass = isPropertyShorthandCastAsEntityArray(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-entity-array syntax
currentProperties[propertyName] = { cast: [CastClass] };
return;
}
// Replace "casting properties" short-hand configuration syntax for entity array
CastClass = isPropertyShorthandCastAsEntityHashmap(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-entity-hashmap syntax
currentProperties[propertyName] = { cast: _defineProperty({}, new CastClass().constructor.name, CastClass) };
return;
}
// EXTENSIONS HOOK: .processShorthandPropertyConfiguration(...)
// Lets extensions process short-hand property configuration
currentProperties[propertyName] = extensionsManager.processShorthandPropertyConfiguration(propertyConfiguration);
});
// Merge with existing properties
return _lodash2.default.merge(properties, currentProperties || {});
}, {});
// Update property configuration with default configuration values
_lodash2.default.forEach(properties, function (propertyConfiguration, key) {
properties[key] = _lodash2.default.merge({}, EnTT.default, propertyConfiguration);
});
// Return extracted properties
return properties;
} | javascript | function getClassProperties(classes) {
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
extensionsManager = _ref.extensionsManager;
// Define checks for shorthand casting configurations
var isPropertyShorthandCastAsSingleEntity = function isPropertyShorthandCastAsSingleEntity(propertyConfiguration) {
if (propertyConfiguration
// Check if class extending EnTT
&& propertyConfiguration.prototype instanceof EnTT) {
return propertyConfiguration;
}
};
var isPropertyShorthandCastAsEntityArray = function isPropertyShorthandCastAsEntityArray(propertyConfiguration) {
if (propertyConfiguration
// Check if array
&& _lodash2.default.isArray(propertyConfiguration)
// Check if array has a single member
&& propertyConfiguration.length === 1
// Check if single array memeber is a class extending EnTT
&& propertyConfiguration[0].prototype instanceof EnTT) {
return propertyConfiguration[0];
}
};
var isPropertyShorthandCastAsEntityHashmap = function isPropertyShorthandCastAsEntityHashmap(propertyConfiguration) {
if (propertyConfiguration
// Check if object
&& _lodash2.default.isObject(propertyConfiguration)
// Check if object has a single member
&& _lodash2.default.values(propertyConfiguration).length
// Check if single object member is a class extending EnTT
&& _lodash2.default.values(propertyConfiguration)[0].prototype instanceof EnTT
// Check if single object member's property key equals class name
&& _lodash2.default.keys(propertyConfiguration)[0] === _lodash2.default.values(propertyConfiguration)[0].name) {
return _lodash2.default.values(propertyConfiguration)[0];
}
};
// Extract property definitions from all inherited classes' static ".props" property
var properties = _lodash2.default.reduceRight(classes, function (properties, current) {
// Extract currentProperties
var currentProperties = current.props,
CastClass = void 0;
// Edit short-hand configuration syntax where possible
_lodash2.default.forEach(currentProperties, function (propertyConfiguration, propertyName) {
// Replace "casting properties" short-hand configuration syntax for single entity
CastClass = isPropertyShorthandCastAsSingleEntity(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-single-entity syntax
currentProperties[propertyName] = { cast: propertyConfiguration };
return;
}
// Replace "casting properties" short-hand configuration syntax for entity array
CastClass = isPropertyShorthandCastAsEntityArray(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-entity-array syntax
currentProperties[propertyName] = { cast: [CastClass] };
return;
}
// Replace "casting properties" short-hand configuration syntax for entity array
CastClass = isPropertyShorthandCastAsEntityHashmap(propertyConfiguration);
if (CastClass) {
// Replace shorthand cast-as-entity-hashmap syntax
currentProperties[propertyName] = { cast: _defineProperty({}, new CastClass().constructor.name, CastClass) };
return;
}
// EXTENSIONS HOOK: .processShorthandPropertyConfiguration(...)
// Lets extensions process short-hand property configuration
currentProperties[propertyName] = extensionsManager.processShorthandPropertyConfiguration(propertyConfiguration);
});
// Merge with existing properties
return _lodash2.default.merge(properties, currentProperties || {});
}, {});
// Update property configuration with default configuration values
_lodash2.default.forEach(properties, function (propertyConfiguration, key) {
properties[key] = _lodash2.default.merge({}, EnTT.default, propertyConfiguration);
});
// Return extracted properties
return properties;
} | [
"function",
"getClassProperties",
"(",
"classes",
")",
"{",
"var",
"_ref",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
",",
"extensionsManager",
"=",
"_ref",
".",
"extensionsManager",
";",
"var",
"isPropertyShorthandCastAsSingleEntity",
"=",
"function",
"isPropertyShorthandCastAsSingleEntity",
"(",
"propertyConfiguration",
")",
"{",
"if",
"(",
"propertyConfiguration",
"&&",
"propertyConfiguration",
".",
"prototype",
"instanceof",
"EnTT",
")",
"{",
"return",
"propertyConfiguration",
";",
"}",
"}",
";",
"var",
"isPropertyShorthandCastAsEntityArray",
"=",
"function",
"isPropertyShorthandCastAsEntityArray",
"(",
"propertyConfiguration",
")",
"{",
"if",
"(",
"propertyConfiguration",
"&&",
"_lodash2",
".",
"default",
".",
"isArray",
"(",
"propertyConfiguration",
")",
"&&",
"propertyConfiguration",
".",
"length",
"===",
"1",
"&&",
"propertyConfiguration",
"[",
"0",
"]",
".",
"prototype",
"instanceof",
"EnTT",
")",
"{",
"return",
"propertyConfiguration",
"[",
"0",
"]",
";",
"}",
"}",
";",
"var",
"isPropertyShorthandCastAsEntityHashmap",
"=",
"function",
"isPropertyShorthandCastAsEntityHashmap",
"(",
"propertyConfiguration",
")",
"{",
"if",
"(",
"propertyConfiguration",
"&&",
"_lodash2",
".",
"default",
".",
"isObject",
"(",
"propertyConfiguration",
")",
"&&",
"_lodash2",
".",
"default",
".",
"values",
"(",
"propertyConfiguration",
")",
".",
"length",
"&&",
"_lodash2",
".",
"default",
".",
"values",
"(",
"propertyConfiguration",
")",
"[",
"0",
"]",
".",
"prototype",
"instanceof",
"EnTT",
"&&",
"_lodash2",
".",
"default",
".",
"keys",
"(",
"propertyConfiguration",
")",
"[",
"0",
"]",
"===",
"_lodash2",
".",
"default",
".",
"values",
"(",
"propertyConfiguration",
")",
"[",
"0",
"]",
".",
"name",
")",
"{",
"return",
"_lodash2",
".",
"default",
".",
"values",
"(",
"propertyConfiguration",
")",
"[",
"0",
"]",
";",
"}",
"}",
";",
"var",
"properties",
"=",
"_lodash2",
".",
"default",
".",
"reduceRight",
"(",
"classes",
",",
"function",
"(",
"properties",
",",
"current",
")",
"{",
"var",
"currentProperties",
"=",
"current",
".",
"props",
",",
"CastClass",
"=",
"void",
"0",
";",
"_lodash2",
".",
"default",
".",
"forEach",
"(",
"currentProperties",
",",
"function",
"(",
"propertyConfiguration",
",",
"propertyName",
")",
"{",
"CastClass",
"=",
"isPropertyShorthandCastAsSingleEntity",
"(",
"propertyConfiguration",
")",
";",
"if",
"(",
"CastClass",
")",
"{",
"currentProperties",
"[",
"propertyName",
"]",
"=",
"{",
"cast",
":",
"propertyConfiguration",
"}",
";",
"return",
";",
"}",
"CastClass",
"=",
"isPropertyShorthandCastAsEntityArray",
"(",
"propertyConfiguration",
")",
";",
"if",
"(",
"CastClass",
")",
"{",
"currentProperties",
"[",
"propertyName",
"]",
"=",
"{",
"cast",
":",
"[",
"CastClass",
"]",
"}",
";",
"return",
";",
"}",
"CastClass",
"=",
"isPropertyShorthandCastAsEntityHashmap",
"(",
"propertyConfiguration",
")",
";",
"if",
"(",
"CastClass",
")",
"{",
"currentProperties",
"[",
"propertyName",
"]",
"=",
"{",
"cast",
":",
"_defineProperty",
"(",
"{",
"}",
",",
"new",
"CastClass",
"(",
")",
".",
"constructor",
".",
"name",
",",
"CastClass",
")",
"}",
";",
"return",
";",
"}",
"currentProperties",
"[",
"propertyName",
"]",
"=",
"extensionsManager",
".",
"processShorthandPropertyConfiguration",
"(",
"propertyConfiguration",
")",
";",
"}",
")",
";",
"return",
"_lodash2",
".",
"default",
".",
"merge",
"(",
"properties",
",",
"currentProperties",
"||",
"{",
"}",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"_lodash2",
".",
"default",
".",
"forEach",
"(",
"properties",
",",
"function",
"(",
"propertyConfiguration",
",",
"key",
")",
"{",
"properties",
"[",
"key",
"]",
"=",
"_lodash2",
".",
"default",
".",
"merge",
"(",
"{",
"}",
",",
"EnTT",
".",
"default",
",",
"propertyConfiguration",
")",
";",
"}",
")",
";",
"return",
"properties",
";",
"}"
]
| Gets class properties configuration by traversing and merging static ".props" property of the instance's class and all it's inherited classes
@param {any} classes Array of inherited from classes
@param {any} extensionsManager Extensions manager
@returns {any} Property configuration for all class' properties | [
"Gets",
"class",
"properties",
"configuration",
"by",
"traversing",
"and",
"merging",
"static",
".",
"props",
"property",
"of",
"the",
"instance",
"s",
"class",
"and",
"all",
"it",
"s",
"inherited",
"classes"
]
| fdf27de4142b3c65a3e51dee70e0d7625dff897c | https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/dist/entt.js#L250-L335 | train |
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ( settings, opts ) {
// Sanity check that we are using DataTables 1.10 or newer
if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.1' ) ) {
throw 'DataTables Responsive requires DataTables 1.10.1 or newer';
}
this.s = {
dt: new DataTable.Api( settings ),
columns: []
};
// Check if responsive has already been initialised on this table
if ( this.s.dt.settings()[0].responsive ) {
return;
}
// details is an object, but for simplicity the user can give it as a string
if ( opts && typeof opts.details === 'string' ) {
opts.details = { type: opts.details };
}
this.c = $.extend( true, {}, Responsive.defaults, DataTable.defaults.responsive, opts );
settings.responsive = this;
this._constructor();
} | javascript | function ( settings, opts ) {
// Sanity check that we are using DataTables 1.10 or newer
if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.1' ) ) {
throw 'DataTables Responsive requires DataTables 1.10.1 or newer';
}
this.s = {
dt: new DataTable.Api( settings ),
columns: []
};
// Check if responsive has already been initialised on this table
if ( this.s.dt.settings()[0].responsive ) {
return;
}
// details is an object, but for simplicity the user can give it as a string
if ( opts && typeof opts.details === 'string' ) {
opts.details = { type: opts.details };
}
this.c = $.extend( true, {}, Responsive.defaults, DataTable.defaults.responsive, opts );
settings.responsive = this;
this._constructor();
} | [
"function",
"(",
"settings",
",",
"opts",
")",
"{",
"if",
"(",
"!",
"DataTable",
".",
"versionCheck",
"||",
"!",
"DataTable",
".",
"versionCheck",
"(",
"'1.10.1'",
")",
")",
"{",
"throw",
"'DataTables Responsive requires DataTables 1.10.1 or newer'",
";",
"}",
"this",
".",
"s",
"=",
"{",
"dt",
":",
"new",
"DataTable",
".",
"Api",
"(",
"settings",
")",
",",
"columns",
":",
"[",
"]",
"}",
";",
"if",
"(",
"this",
".",
"s",
".",
"dt",
".",
"settings",
"(",
")",
"[",
"0",
"]",
".",
"responsive",
")",
"{",
"return",
";",
"}",
"if",
"(",
"opts",
"&&",
"typeof",
"opts",
".",
"details",
"===",
"'string'",
")",
"{",
"opts",
".",
"details",
"=",
"{",
"type",
":",
"opts",
".",
"details",
"}",
";",
"}",
"this",
".",
"c",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"Responsive",
".",
"defaults",
",",
"DataTable",
".",
"defaults",
".",
"responsive",
",",
"opts",
")",
";",
"settings",
".",
"responsive",
"=",
"this",
";",
"this",
".",
"_constructor",
"(",
")",
";",
"}"
]
| Responsive is a plug-in for the DataTables library that makes use of
DataTables' ability to change the visibility of columns, changing the
visibility of columns so the displayed columns fit into the table container.
The end result is that complex tables will be dynamically adjusted to fit
into the viewport, be it on a desktop, tablet or mobile browser.
Responsive for DataTables has two modes of operation, which can used
individually or combined:
* Class name based control - columns assigned class names that match the
breakpoint logic can be shown / hidden as required for each breakpoint.
* Automatic control - columns are automatically hidden when there is no
room left to display them. Columns removed from the right.
In additional to column visibility control, Responsive also has built into
options to use DataTables' child row display to show / hide the information
from the table that has been hidden. There are also two modes of operation
for this child row display:
* Inline - when the control element that the user can use to show / hide
child rows is displayed inside the first column of the table.
* Column - where a whole column is dedicated to be the show / hide control.
Initialisation of Responsive is performed by:
* Adding the class `responsive` or `dt-responsive` to the table. In this case
Responsive will automatically be initialised with the default configuration
options when the DataTable is created.
* Using the `responsive` option in the DataTables configuration options. This
can also be used to specify the configuration options, or simply set to
`true` to use the defaults.
@class
@param {object} settings DataTables settings object for the host table
@param {object} [opts] Configuration options
@requires jQuery 1.7+
@requires DataTables 1.10.1+
@example
$('#example').DataTable( {
responsive: true
} );
} ); | [
"Responsive",
"is",
"a",
"plug",
"-",
"in",
"for",
"the",
"DataTables",
"library",
"that",
"makes",
"use",
"of",
"DataTables",
"ability",
"to",
"change",
"the",
"visibility",
"of",
"columns",
"changing",
"the",
"visibility",
"of",
"columns",
"so",
"the",
"displayed",
"columns",
"fit",
"into",
"the",
"table",
"container",
".",
"The",
"end",
"result",
"is",
"that",
"complex",
"tables",
"will",
"be",
"dynamically",
"adjusted",
"to",
"fit",
"into",
"the",
"viewport",
"be",
"it",
"on",
"a",
"desktop",
"tablet",
"or",
"mobile",
"browser",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L75-L99 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ( colIdx, name ) {
var includeIn = columns[ colIdx ].includeIn;
if ( $.inArray( name, includeIn ) === -1 ) {
includeIn.push( name );
}
} | javascript | function ( colIdx, name ) {
var includeIn = columns[ colIdx ].includeIn;
if ( $.inArray( name, includeIn ) === -1 ) {
includeIn.push( name );
}
} | [
"function",
"(",
"colIdx",
",",
"name",
")",
"{",
"var",
"includeIn",
"=",
"columns",
"[",
"colIdx",
"]",
".",
"includeIn",
";",
"if",
"(",
"$",
".",
"inArray",
"(",
"name",
",",
"includeIn",
")",
"===",
"-",
"1",
")",
"{",
"includeIn",
".",
"push",
"(",
"name",
")",
";",
"}",
"}"
]
| Simply add a breakpoint to `includeIn` array, ensuring that there are no duplicates | [
"Simply",
"add",
"a",
"breakpoint",
"to",
"includeIn",
"array",
"ensuring",
"that",
"there",
"are",
"no",
"duplicates"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L314-L320 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ()
{
var that = this;
var dt = this.s.dt;
var details = this.c.details;
// The inline type always uses the first child as the target
if ( details.type === 'inline' ) {
details.target = 'td:first-child';
}
// type.target can be a string jQuery selector or a column index
var target = details.target;
var selector = typeof target === 'string' ? target : 'td';
// Click handler to show / hide the details rows when they are available
$( dt.table().body() ).on( 'click', selector, function (e) {
// If the table is not collapsed (i.e. there is no hidden columns)
// then take no action
if ( ! $(dt.table().node()).hasClass('collapsed' ) ) {
return;
}
// Check that the row is actually a DataTable's controlled node
if ( ! dt.row( $(this).closest('tr') ).length ) {
return;
}
// For column index, we determine if we should act or not in the
// handler - otherwise it is already okay
if ( typeof target === 'number' ) {
var targetIdx = target < 0 ?
dt.columns().eq(0).length + target :
target;
if ( dt.cell( this ).index().column !== targetIdx ) {
return;
}
}
// $().closest() includes itself in its check
var row = dt.row( $(this).closest('tr') );
if ( row.child.isShown() ) {
row.child( false );
$( row.node() ).removeClass( 'parent' );
}
else {
var info = that.c.details.renderer( dt, row[0] );
row.child( info, 'child' ).show();
$( row.node() ).addClass( 'parent' );
}
} );
} | javascript | function ()
{
var that = this;
var dt = this.s.dt;
var details = this.c.details;
// The inline type always uses the first child as the target
if ( details.type === 'inline' ) {
details.target = 'td:first-child';
}
// type.target can be a string jQuery selector or a column index
var target = details.target;
var selector = typeof target === 'string' ? target : 'td';
// Click handler to show / hide the details rows when they are available
$( dt.table().body() ).on( 'click', selector, function (e) {
// If the table is not collapsed (i.e. there is no hidden columns)
// then take no action
if ( ! $(dt.table().node()).hasClass('collapsed' ) ) {
return;
}
// Check that the row is actually a DataTable's controlled node
if ( ! dt.row( $(this).closest('tr') ).length ) {
return;
}
// For column index, we determine if we should act or not in the
// handler - otherwise it is already okay
if ( typeof target === 'number' ) {
var targetIdx = target < 0 ?
dt.columns().eq(0).length + target :
target;
if ( dt.cell( this ).index().column !== targetIdx ) {
return;
}
}
// $().closest() includes itself in its check
var row = dt.row( $(this).closest('tr') );
if ( row.child.isShown() ) {
row.child( false );
$( row.node() ).removeClass( 'parent' );
}
else {
var info = that.c.details.renderer( dt, row[0] );
row.child( info, 'child' ).show();
$( row.node() ).addClass( 'parent' );
}
} );
} | [
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"details",
"=",
"this",
".",
"c",
".",
"details",
";",
"if",
"(",
"details",
".",
"type",
"===",
"'inline'",
")",
"{",
"details",
".",
"target",
"=",
"'td:first-child'",
";",
"}",
"var",
"target",
"=",
"details",
".",
"target",
";",
"var",
"selector",
"=",
"typeof",
"target",
"===",
"'string'",
"?",
"target",
":",
"'td'",
";",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"body",
"(",
")",
")",
".",
"on",
"(",
"'click'",
",",
"selector",
",",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"node",
"(",
")",
")",
".",
"hasClass",
"(",
"'collapsed'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"dt",
".",
"row",
"(",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"'tr'",
")",
")",
".",
"length",
")",
"{",
"return",
";",
"}",
"if",
"(",
"typeof",
"target",
"===",
"'number'",
")",
"{",
"var",
"targetIdx",
"=",
"target",
"<",
"0",
"?",
"dt",
".",
"columns",
"(",
")",
".",
"eq",
"(",
"0",
")",
".",
"length",
"+",
"target",
":",
"target",
";",
"if",
"(",
"dt",
".",
"cell",
"(",
"this",
")",
".",
"index",
"(",
")",
".",
"column",
"!==",
"targetIdx",
")",
"{",
"return",
";",
"}",
"}",
"var",
"row",
"=",
"dt",
".",
"row",
"(",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"'tr'",
")",
")",
";",
"if",
"(",
"row",
".",
"child",
".",
"isShown",
"(",
")",
")",
"{",
"row",
".",
"child",
"(",
"false",
")",
";",
"$",
"(",
"row",
".",
"node",
"(",
")",
")",
".",
"removeClass",
"(",
"'parent'",
")",
";",
"}",
"else",
"{",
"var",
"info",
"=",
"that",
".",
"c",
".",
"details",
".",
"renderer",
"(",
"dt",
",",
"row",
"[",
"0",
"]",
")",
";",
"row",
".",
"child",
"(",
"info",
",",
"'child'",
")",
".",
"show",
"(",
")",
";",
"$",
"(",
"row",
".",
"node",
"(",
")",
")",
".",
"addClass",
"(",
"'parent'",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Initialisation for the details handler
@private | [
"Initialisation",
"for",
"the",
"details",
"handler"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L426-L479 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ()
{
var that = this;
var dt = this.s.dt;
// Find how many columns are hidden
var hiddenColumns = dt.columns().indexes().filter( function ( idx ) {
var col = dt.column( idx );
if ( col.visible() ) {
return null;
}
// Only counts as hidden if it doesn't have the `never` class
return $( col.header() ).hasClass( 'never' ) ? null : idx;
} );
var haveHidden = true;
if ( hiddenColumns.length === 0 || ( hiddenColumns.length === 1 && this.s.columns[ hiddenColumns[0] ].control ) ) {
haveHidden = false;
}
if ( haveHidden ) {
// Show all existing child rows
dt.rows( { page: 'current' } ).eq(0).each( function (idx) {
var row = dt.row( idx );
if ( row.child() ) {
var info = that.c.details.renderer( dt, row[0] );
// The renderer can return false to have no child row
if ( info === false ) {
row.child.hide();
}
else {
row.child( info, 'child' ).show();
}
}
} );
}
else {
// Hide all existing child rows
dt.rows( { page: 'current' } ).eq(0).each( function (idx) {
dt.row( idx ).child.hide();
} );
}
} | javascript | function ()
{
var that = this;
var dt = this.s.dt;
// Find how many columns are hidden
var hiddenColumns = dt.columns().indexes().filter( function ( idx ) {
var col = dt.column( idx );
if ( col.visible() ) {
return null;
}
// Only counts as hidden if it doesn't have the `never` class
return $( col.header() ).hasClass( 'never' ) ? null : idx;
} );
var haveHidden = true;
if ( hiddenColumns.length === 0 || ( hiddenColumns.length === 1 && this.s.columns[ hiddenColumns[0] ].control ) ) {
haveHidden = false;
}
if ( haveHidden ) {
// Show all existing child rows
dt.rows( { page: 'current' } ).eq(0).each( function (idx) {
var row = dt.row( idx );
if ( row.child() ) {
var info = that.c.details.renderer( dt, row[0] );
// The renderer can return false to have no child row
if ( info === false ) {
row.child.hide();
}
else {
row.child( info, 'child' ).show();
}
}
} );
}
else {
// Hide all existing child rows
dt.rows( { page: 'current' } ).eq(0).each( function (idx) {
dt.row( idx ).child.hide();
} );
}
} | [
"function",
"(",
")",
"{",
"var",
"that",
"=",
"this",
";",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"hiddenColumns",
"=",
"dt",
".",
"columns",
"(",
")",
".",
"indexes",
"(",
")",
".",
"filter",
"(",
"function",
"(",
"idx",
")",
"{",
"var",
"col",
"=",
"dt",
".",
"column",
"(",
"idx",
")",
";",
"if",
"(",
"col",
".",
"visible",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"(",
"col",
".",
"header",
"(",
")",
")",
".",
"hasClass",
"(",
"'never'",
")",
"?",
"null",
":",
"idx",
";",
"}",
")",
";",
"var",
"haveHidden",
"=",
"true",
";",
"if",
"(",
"hiddenColumns",
".",
"length",
"===",
"0",
"||",
"(",
"hiddenColumns",
".",
"length",
"===",
"1",
"&&",
"this",
".",
"s",
".",
"columns",
"[",
"hiddenColumns",
"[",
"0",
"]",
"]",
".",
"control",
")",
")",
"{",
"haveHidden",
"=",
"false",
";",
"}",
"if",
"(",
"haveHidden",
")",
"{",
"dt",
".",
"rows",
"(",
"{",
"page",
":",
"'current'",
"}",
")",
".",
"eq",
"(",
"0",
")",
".",
"each",
"(",
"function",
"(",
"idx",
")",
"{",
"var",
"row",
"=",
"dt",
".",
"row",
"(",
"idx",
")",
";",
"if",
"(",
"row",
".",
"child",
"(",
")",
")",
"{",
"var",
"info",
"=",
"that",
".",
"c",
".",
"details",
".",
"renderer",
"(",
"dt",
",",
"row",
"[",
"0",
"]",
")",
";",
"if",
"(",
"info",
"===",
"false",
")",
"{",
"row",
".",
"child",
".",
"hide",
"(",
")",
";",
"}",
"else",
"{",
"row",
".",
"child",
"(",
"info",
",",
"'child'",
")",
".",
"show",
"(",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"else",
"{",
"dt",
".",
"rows",
"(",
"{",
"page",
":",
"'current'",
"}",
")",
".",
"eq",
"(",
"0",
")",
".",
"each",
"(",
"function",
"(",
"idx",
")",
"{",
"dt",
".",
"row",
"(",
"idx",
")",
".",
"child",
".",
"hide",
"(",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Update the child rows in the table whenever the column visibility changes
@private | [
"Update",
"the",
"child",
"rows",
"in",
"the",
"table",
"whenever",
"the",
"column",
"visibility",
"changes"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L487-L533 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ( name )
{
var breakpoints = this.c.breakpoints;
for ( var i=0, ien=breakpoints.length ; i<ien ; i++ ) {
if ( breakpoints[i].name === name ) {
return breakpoints[i];
}
}
} | javascript | function ( name )
{
var breakpoints = this.c.breakpoints;
for ( var i=0, ien=breakpoints.length ; i<ien ; i++ ) {
if ( breakpoints[i].name === name ) {
return breakpoints[i];
}
}
} | [
"function",
"(",
"name",
")",
"{",
"var",
"breakpoints",
"=",
"this",
".",
"c",
".",
"breakpoints",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"ien",
"=",
"breakpoints",
".",
"length",
";",
"i",
"<",
"ien",
";",
"i",
"++",
")",
"{",
"if",
"(",
"breakpoints",
"[",
"i",
"]",
".",
"name",
"===",
"name",
")",
"{",
"return",
"breakpoints",
"[",
"i",
"]",
";",
"}",
"}",
"}"
]
| Find a breakpoint object from a name
@param {string} name Breakpoint name to find
@return {object} Breakpoint description object | [
"Find",
"a",
"breakpoint",
"object",
"from",
"a",
"name"
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L541-L550 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ()
{
var dt = this.s.dt;
var width = $(window).width();
var breakpoints = this.c.breakpoints;
var breakpoint = breakpoints[0].name;
var columns = this.s.columns;
var i, ien;
// Determine what breakpoint we are currently at
for ( i=breakpoints.length-1 ; i>=0 ; i-- ) {
if ( width <= breakpoints[i].width ) {
breakpoint = breakpoints[i].name;
break;
}
}
// Show the columns for that break point
var columnsVis = this._columnsVisiblity( breakpoint );
// Set the class before the column visibility is changed so event
// listeners know what the state is. Need to determine if there are
// any columns that are not visible but can be shown
var collapsedClass = false;
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
if ( columnsVis[i] === false && ! columns[i].never ) {
collapsedClass = true;
break;
}
}
$( dt.table().node() ).toggleClass('collapsed', collapsedClass );
dt.columns().eq(0).each( function ( colIdx, i ) {
dt.column( colIdx ).visible( columnsVis[i] );
} );
} | javascript | function ()
{
var dt = this.s.dt;
var width = $(window).width();
var breakpoints = this.c.breakpoints;
var breakpoint = breakpoints[0].name;
var columns = this.s.columns;
var i, ien;
// Determine what breakpoint we are currently at
for ( i=breakpoints.length-1 ; i>=0 ; i-- ) {
if ( width <= breakpoints[i].width ) {
breakpoint = breakpoints[i].name;
break;
}
}
// Show the columns for that break point
var columnsVis = this._columnsVisiblity( breakpoint );
// Set the class before the column visibility is changed so event
// listeners know what the state is. Need to determine if there are
// any columns that are not visible but can be shown
var collapsedClass = false;
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
if ( columnsVis[i] === false && ! columns[i].never ) {
collapsedClass = true;
break;
}
}
$( dt.table().node() ).toggleClass('collapsed', collapsedClass );
dt.columns().eq(0).each( function ( colIdx, i ) {
dt.column( colIdx ).visible( columnsVis[i] );
} );
} | [
"function",
"(",
")",
"{",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"width",
"=",
"$",
"(",
"window",
")",
".",
"width",
"(",
")",
";",
"var",
"breakpoints",
"=",
"this",
".",
"c",
".",
"breakpoints",
";",
"var",
"breakpoint",
"=",
"breakpoints",
"[",
"0",
"]",
".",
"name",
";",
"var",
"columns",
"=",
"this",
".",
"s",
".",
"columns",
";",
"var",
"i",
",",
"ien",
";",
"for",
"(",
"i",
"=",
"breakpoints",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"width",
"<=",
"breakpoints",
"[",
"i",
"]",
".",
"width",
")",
"{",
"breakpoint",
"=",
"breakpoints",
"[",
"i",
"]",
".",
"name",
";",
"break",
";",
"}",
"}",
"var",
"columnsVis",
"=",
"this",
".",
"_columnsVisiblity",
"(",
"breakpoint",
")",
";",
"var",
"collapsedClass",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"0",
",",
"ien",
"=",
"columns",
".",
"length",
";",
"i",
"<",
"ien",
";",
"i",
"++",
")",
"{",
"if",
"(",
"columnsVis",
"[",
"i",
"]",
"===",
"false",
"&&",
"!",
"columns",
"[",
"i",
"]",
".",
"never",
")",
"{",
"collapsedClass",
"=",
"true",
";",
"break",
";",
"}",
"}",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"node",
"(",
")",
")",
".",
"toggleClass",
"(",
"'collapsed'",
",",
"collapsedClass",
")",
";",
"dt",
".",
"columns",
"(",
")",
".",
"eq",
"(",
"0",
")",
".",
"each",
"(",
"function",
"(",
"colIdx",
",",
"i",
")",
"{",
"dt",
".",
"column",
"(",
"colIdx",
")",
".",
"visible",
"(",
"columnsVis",
"[",
"i",
"]",
")",
";",
"}",
")",
";",
"}"
]
| Alter the table display for a resized viewport. This involves first
determining what breakpoint the window currently is in, getting the
column visibilities to apply and then setting them.
@private | [
"Alter",
"the",
"table",
"display",
"for",
"a",
"resized",
"viewport",
".",
"This",
"involves",
"first",
"determining",
"what",
"breakpoint",
"the",
"window",
"currently",
"is",
"in",
"getting",
"the",
"column",
"visibilities",
"to",
"apply",
"and",
"then",
"setting",
"them",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L560-L596 | train |
|
S3bb1/ah-dashboard-plugin | public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js | function ()
{
var dt = this.s.dt;
var columns = this.s.columns;
// Are we allowed to do auto sizing?
if ( ! this.c.auto ) {
return;
}
// Are there any columns that actually need auto-sizing, or do they all
// have classes defined
if ( $.inArray( true, $.map( columns, function (c) { return c.auto; } ) ) === -1 ) {
return;
}
// Clone the table with the current data in it
var tableWidth = dt.table().node().offsetWidth;
var columnWidths = dt.columns;
var clonedTable = dt.table().node().cloneNode( false );
var clonedHeader = $( dt.table().header().cloneNode( false ) ).appendTo( clonedTable );
var clonedBody = $( dt.table().body().cloneNode( false ) ).appendTo( clonedTable );
$( dt.table().footer() ).clone( false ).appendTo( clonedTable );
// This is a bit slow, but we need to get a clone of each row that
// includes all columns. As such, try to do this as little as possible.
dt.rows( { page: 'current' } ).indexes().flatten().each( function ( idx ) {
var clone = dt.row( idx ).node().cloneNode( true );
if ( dt.columns( ':hidden' ).flatten().length ) {
$(clone).append( dt.cells( idx, ':hidden' ).nodes().to$().clone() );
}
$(clone).appendTo( clonedBody );
} );
var cells = dt.columns().header().to$().clone( false );
$('<tr/>')
.append( cells )
.appendTo( clonedHeader );
// In the inline case extra padding is applied to the first column to
// give space for the show / hide icon. We need to use this in the
// calculation
if ( this.c.details.type === 'inline' ) {
$(clonedTable).addClass( 'dtr-inline collapsed' );
}
var inserted = $('<div/>')
.css( {
width: 1,
height: 1,
overflow: 'hidden'
} )
.append( clonedTable );
// Remove columns which are not to be included
inserted.find('th.never, td.never').remove();
inserted.insertBefore( dt.table().node() );
// The cloned header now contains the smallest that each column can be
dt.columns().eq(0).each( function ( idx ) {
columns[idx].minWidth = cells[ idx ].offsetWidth || 0;
} );
inserted.remove();
} | javascript | function ()
{
var dt = this.s.dt;
var columns = this.s.columns;
// Are we allowed to do auto sizing?
if ( ! this.c.auto ) {
return;
}
// Are there any columns that actually need auto-sizing, or do they all
// have classes defined
if ( $.inArray( true, $.map( columns, function (c) { return c.auto; } ) ) === -1 ) {
return;
}
// Clone the table with the current data in it
var tableWidth = dt.table().node().offsetWidth;
var columnWidths = dt.columns;
var clonedTable = dt.table().node().cloneNode( false );
var clonedHeader = $( dt.table().header().cloneNode( false ) ).appendTo( clonedTable );
var clonedBody = $( dt.table().body().cloneNode( false ) ).appendTo( clonedTable );
$( dt.table().footer() ).clone( false ).appendTo( clonedTable );
// This is a bit slow, but we need to get a clone of each row that
// includes all columns. As such, try to do this as little as possible.
dt.rows( { page: 'current' } ).indexes().flatten().each( function ( idx ) {
var clone = dt.row( idx ).node().cloneNode( true );
if ( dt.columns( ':hidden' ).flatten().length ) {
$(clone).append( dt.cells( idx, ':hidden' ).nodes().to$().clone() );
}
$(clone).appendTo( clonedBody );
} );
var cells = dt.columns().header().to$().clone( false );
$('<tr/>')
.append( cells )
.appendTo( clonedHeader );
// In the inline case extra padding is applied to the first column to
// give space for the show / hide icon. We need to use this in the
// calculation
if ( this.c.details.type === 'inline' ) {
$(clonedTable).addClass( 'dtr-inline collapsed' );
}
var inserted = $('<div/>')
.css( {
width: 1,
height: 1,
overflow: 'hidden'
} )
.append( clonedTable );
// Remove columns which are not to be included
inserted.find('th.never, td.never').remove();
inserted.insertBefore( dt.table().node() );
// The cloned header now contains the smallest that each column can be
dt.columns().eq(0).each( function ( idx ) {
columns[idx].minWidth = cells[ idx ].offsetWidth || 0;
} );
inserted.remove();
} | [
"function",
"(",
")",
"{",
"var",
"dt",
"=",
"this",
".",
"s",
".",
"dt",
";",
"var",
"columns",
"=",
"this",
".",
"s",
".",
"columns",
";",
"if",
"(",
"!",
"this",
".",
"c",
".",
"auto",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
".",
"inArray",
"(",
"true",
",",
"$",
".",
"map",
"(",
"columns",
",",
"function",
"(",
"c",
")",
"{",
"return",
"c",
".",
"auto",
";",
"}",
")",
")",
"===",
"-",
"1",
")",
"{",
"return",
";",
"}",
"var",
"tableWidth",
"=",
"dt",
".",
"table",
"(",
")",
".",
"node",
"(",
")",
".",
"offsetWidth",
";",
"var",
"columnWidths",
"=",
"dt",
".",
"columns",
";",
"var",
"clonedTable",
"=",
"dt",
".",
"table",
"(",
")",
".",
"node",
"(",
")",
".",
"cloneNode",
"(",
"false",
")",
";",
"var",
"clonedHeader",
"=",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"header",
"(",
")",
".",
"cloneNode",
"(",
"false",
")",
")",
".",
"appendTo",
"(",
"clonedTable",
")",
";",
"var",
"clonedBody",
"=",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"body",
"(",
")",
".",
"cloneNode",
"(",
"false",
")",
")",
".",
"appendTo",
"(",
"clonedTable",
")",
";",
"$",
"(",
"dt",
".",
"table",
"(",
")",
".",
"footer",
"(",
")",
")",
".",
"clone",
"(",
"false",
")",
".",
"appendTo",
"(",
"clonedTable",
")",
";",
"dt",
".",
"rows",
"(",
"{",
"page",
":",
"'current'",
"}",
")",
".",
"indexes",
"(",
")",
".",
"flatten",
"(",
")",
".",
"each",
"(",
"function",
"(",
"idx",
")",
"{",
"var",
"clone",
"=",
"dt",
".",
"row",
"(",
"idx",
")",
".",
"node",
"(",
")",
".",
"cloneNode",
"(",
"true",
")",
";",
"if",
"(",
"dt",
".",
"columns",
"(",
"':hidden'",
")",
".",
"flatten",
"(",
")",
".",
"length",
")",
"{",
"$",
"(",
"clone",
")",
".",
"append",
"(",
"dt",
".",
"cells",
"(",
"idx",
",",
"':hidden'",
")",
".",
"nodes",
"(",
")",
".",
"to$",
"(",
")",
".",
"clone",
"(",
")",
")",
";",
"}",
"$",
"(",
"clone",
")",
".",
"appendTo",
"(",
"clonedBody",
")",
";",
"}",
")",
";",
"var",
"cells",
"=",
"dt",
".",
"columns",
"(",
")",
".",
"header",
"(",
")",
".",
"to$",
"(",
")",
".",
"clone",
"(",
"false",
")",
";",
"$",
"(",
"'<tr/>'",
")",
".",
"append",
"(",
"cells",
")",
".",
"appendTo",
"(",
"clonedHeader",
")",
";",
"if",
"(",
"this",
".",
"c",
".",
"details",
".",
"type",
"===",
"'inline'",
")",
"{",
"$",
"(",
"clonedTable",
")",
".",
"addClass",
"(",
"'dtr-inline collapsed'",
")",
";",
"}",
"var",
"inserted",
"=",
"$",
"(",
"'<div/>'",
")",
".",
"css",
"(",
"{",
"width",
":",
"1",
",",
"height",
":",
"1",
",",
"overflow",
":",
"'hidden'",
"}",
")",
".",
"append",
"(",
"clonedTable",
")",
";",
"inserted",
".",
"find",
"(",
"'th.never, td.never'",
")",
".",
"remove",
"(",
")",
";",
"inserted",
".",
"insertBefore",
"(",
"dt",
".",
"table",
"(",
")",
".",
"node",
"(",
")",
")",
";",
"dt",
".",
"columns",
"(",
")",
".",
"eq",
"(",
"0",
")",
".",
"each",
"(",
"function",
"(",
"idx",
")",
"{",
"columns",
"[",
"idx",
"]",
".",
"minWidth",
"=",
"cells",
"[",
"idx",
"]",
".",
"offsetWidth",
"||",
"0",
";",
"}",
")",
";",
"inserted",
".",
"remove",
"(",
")",
";",
"}"
]
| Determine the width of each column in the table so the auto column hiding
has that information to work with. This method is never going to be 100%
perfect since column widths can change slightly per page, but without
seriously compromising performance this is quite effective.
@private | [
"Determine",
"the",
"width",
"of",
"each",
"column",
"in",
"the",
"table",
"so",
"the",
"auto",
"column",
"hiding",
"has",
"that",
"information",
"to",
"work",
"with",
".",
"This",
"method",
"is",
"never",
"going",
"to",
"be",
"100%",
"perfect",
"since",
"column",
"widths",
"can",
"change",
"slightly",
"per",
"page",
"but",
"without",
"seriously",
"compromising",
"performance",
"this",
"is",
"quite",
"effective",
"."
]
| c283370ec0f99a25db5bb7029a98b4febf8c5251 | https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/admin-lte/plugins/datatables/extensions/Responsive/js/dataTables.responsive.js#L607-L675 | train |
|
MaddHacker/server-lite | lib/sl-content.js | Content | function Content(mimeType, content) {
var obj = {};
obj.type = mimeType + '; charset=utf-8';
obj.value = content;
obj.length = content.length;
return obj;
} | javascript | function Content(mimeType, content) {
var obj = {};
obj.type = mimeType + '; charset=utf-8';
obj.value = content;
obj.length = content.length;
return obj;
} | [
"function",
"Content",
"(",
"mimeType",
",",
"content",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
";",
"obj",
".",
"type",
"=",
"mimeType",
"+",
"'; charset=utf-8'",
";",
"obj",
".",
"value",
"=",
"content",
";",
"obj",
".",
"length",
"=",
"content",
".",
"length",
";",
"return",
"obj",
";",
"}"
]
| Generic concept of a Content-Type model => all content is assumed to have charset = 'utf-8'
@param {String} mimeType => how the client should read the content
@param {Object} content => actual content (file, image, etc)
@returns {Content} content wrapper for given payload. | [
"Generic",
"concept",
"of",
"a",
"Content",
"-",
"Type",
"model",
"=",
">",
"all",
"content",
"is",
"assumed",
"to",
"have",
"charset",
"=",
"utf",
"-",
"8"
]
| 5cf606503bb7c434c5a29b3bbbf39fab1cb24fa8 | https://github.com/MaddHacker/server-lite/blob/5cf606503bb7c434c5a29b3bbbf39fab1cb24fa8/lib/sl-content.js#L26-L34 | train |
adrai/node-cqs | lib/domain/domain.js | function(cmdPointer, next) {
// Publish it now...
commandDispatcher.dispatch(cmdPointer.command, function(err) {
if (cmdPointer.callback) cmdPointer.callback(null);
next();
});
} | javascript | function(cmdPointer, next) {
// Publish it now...
commandDispatcher.dispatch(cmdPointer.command, function(err) {
if (cmdPointer.callback) cmdPointer.callback(null);
next();
});
} | [
"function",
"(",
"cmdPointer",
",",
"next",
")",
"{",
"commandDispatcher",
".",
"dispatch",
"(",
"cmdPointer",
".",
"command",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"cmdPointer",
".",
"callback",
")",
"cmdPointer",
".",
"callback",
"(",
"null",
")",
";",
"next",
"(",
")",
";",
"}",
")",
";",
"}"
]
| dipatch one command in queue and call the _next_ callback, which will call _process_ for the next command in queue. | [
"dipatch",
"one",
"command",
"in",
"queue",
"and",
"call",
"the",
"_next_",
"callback",
"which",
"will",
"call",
"_process_",
"for",
"the",
"next",
"command",
"in",
"queue",
"."
]
| 1691670a6e35d0b20904a5bd1b74adbe92f496eb | https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/domain.js#L163-L170 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.