repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
SPANDigital/presidium-core | src/config.js | resolveConfig | function resolveConfig(conf, version = '') {
conf['siteroot'] = conf.baseurl || '/';
if (version) {
conf['baseurl'] = path.join(conf.siteroot, version);
}
for (let key in conf) {
if (CONFIG_VAR_REGEX.test(conf[key])) {
conf[key] = resolve(conf[key], conf, [key]);
}
}
return conf;
} | javascript | function resolveConfig(conf, version = '') {
conf['siteroot'] = conf.baseurl || '/';
if (version) {
conf['baseurl'] = path.join(conf.siteroot, version);
}
for (let key in conf) {
if (CONFIG_VAR_REGEX.test(conf[key])) {
conf[key] = resolve(conf[key], conf, [key]);
}
}
return conf;
} | [
"function",
"resolveConfig",
"(",
"conf",
",",
"version",
"=",
"''",
")",
"{",
"conf",
"[",
"'siteroot'",
"]",
"=",
"conf",
".",
"baseurl",
"||",
"'/'",
";",
"if",
"(",
"version",
")",
"{",
"conf",
"[",
"'baseurl'",
"]",
"=",
"path",
".",
"join",
"(",
"conf",
".",
"siteroot",
",",
"version",
")",
";",
"}",
"for",
"(",
"let",
"key",
"in",
"conf",
")",
"{",
"if",
"(",
"CONFIG_VAR_REGEX",
".",
"test",
"(",
"conf",
"[",
"key",
"]",
")",
")",
"{",
"conf",
"[",
"key",
"]",
"=",
"resolve",
"(",
"conf",
"[",
"key",
"]",
",",
"conf",
",",
"[",
"key",
"]",
")",
";",
"}",
"}",
"return",
"conf",
";",
"}"
] | Helper function that resolves any variable depenencies in the config.
@param {String} version - The version number supplied.
@param {Object} conf - The parsed config file. | [
"Helper",
"function",
"that",
"resolves",
"any",
"variable",
"depenencies",
"in",
"the",
"config",
"."
] | 8d3034d97ef85f95391a14bd895898a0ab2e92ed | https://github.com/SPANDigital/presidium-core/blob/8d3034d97ef85f95391a14bd895898a0ab2e92ed/src/config.js#L79-L91 | train |
SPANDigital/presidium-core | src/config.js | resolve | function resolve(value, conf, ring = []) {
value.match(CONFIG_VAR_REGEX).forEach((variable) => {
const key = variable.substring(variable.lastIndexOf('${') + 2, variable.lastIndexOf('}'));
if (ring.includes(key)) {
throw `Circular dependency error: cannot resolve variable(s) ${ring}.`;
}
ring.push(key);
let resolved = conf[key];
if (!resolved) {
throw `Could not resolve ${key} - make sure this key is defined in _config.yml.`;
}
if (CONFIG_VAR_REGEX.test(resolved)) {
resolved = resolve(resolved, conf, ring);
}
value = value.replace(variable, resolved);
ring.pop();
});
return value;
} | javascript | function resolve(value, conf, ring = []) {
value.match(CONFIG_VAR_REGEX).forEach((variable) => {
const key = variable.substring(variable.lastIndexOf('${') + 2, variable.lastIndexOf('}'));
if (ring.includes(key)) {
throw `Circular dependency error: cannot resolve variable(s) ${ring}.`;
}
ring.push(key);
let resolved = conf[key];
if (!resolved) {
throw `Could not resolve ${key} - make sure this key is defined in _config.yml.`;
}
if (CONFIG_VAR_REGEX.test(resolved)) {
resolved = resolve(resolved, conf, ring);
}
value = value.replace(variable, resolved);
ring.pop();
});
return value;
} | [
"function",
"resolve",
"(",
"value",
",",
"conf",
",",
"ring",
"=",
"[",
"]",
")",
"{",
"value",
".",
"match",
"(",
"CONFIG_VAR_REGEX",
")",
".",
"forEach",
"(",
"(",
"variable",
")",
"=>",
"{",
"const",
"key",
"=",
"variable",
".",
"substring",
"(",
"variable",
".",
"lastIndexOf",
"(",
"'${'",
")",
"+",
"2",
",",
"variable",
".",
"lastIndexOf",
"(",
"'}'",
")",
")",
";",
"if",
"(",
"ring",
".",
"includes",
"(",
"key",
")",
")",
"{",
"throw",
"`",
"${",
"ring",
"}",
"`",
";",
"}",
"ring",
".",
"push",
"(",
"key",
")",
";",
"let",
"resolved",
"=",
"conf",
"[",
"key",
"]",
";",
"if",
"(",
"!",
"resolved",
")",
"{",
"throw",
"`",
"${",
"key",
"}",
"`",
";",
"}",
"if",
"(",
"CONFIG_VAR_REGEX",
".",
"test",
"(",
"resolved",
")",
")",
"{",
"resolved",
"=",
"resolve",
"(",
"resolved",
",",
"conf",
",",
"ring",
")",
";",
"}",
"value",
"=",
"value",
".",
"replace",
"(",
"variable",
",",
"resolved",
")",
";",
"ring",
".",
"pop",
"(",
")",
";",
"}",
")",
";",
"return",
"value",
";",
"}"
] | Recursively resolve variable depedencies.
@param {String} value - String to resolve of dependencies.
@param {Dictionary} conf - The parsed config file.
@param {Array} ring - An array of previously seen keys. | [
"Recursively",
"resolve",
"variable",
"depedencies",
"."
] | 8d3034d97ef85f95391a14bd895898a0ab2e92ed | https://github.com/SPANDigital/presidium-core/blob/8d3034d97ef85f95391a14bd895898a0ab2e92ed/src/config.js#L99-L119 | train |
holidayextras/hxTracer | index.js | timeAndLog | function timeAndLog(text) {
if (active) {
var spaces = space.substring(0, currentIndentation);
console.error('TRACER TXT', meaningfulTime(), spaces, text);
}
} | javascript | function timeAndLog(text) {
if (active) {
var spaces = space.substring(0, currentIndentation);
console.error('TRACER TXT', meaningfulTime(), spaces, text);
}
} | [
"function",
"timeAndLog",
"(",
"text",
")",
"{",
"if",
"(",
"active",
")",
"{",
"var",
"spaces",
"=",
"space",
".",
"substring",
"(",
"0",
",",
"currentIndentation",
")",
";",
"console",
".",
"error",
"(",
"'TRACER TXT'",
",",
"meaningfulTime",
"(",
")",
",",
"spaces",
",",
"text",
")",
";",
"}",
"}"
] | Grab a timestamp and add it to the tracers output | [
"Grab",
"a",
"timestamp",
"and",
"add",
"it",
"to",
"the",
"tracers",
"output"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L58-L63 | train |
holidayextras/hxTracer | index.js | processModules | function processModules(item) {
if (item.exports && !item._traced) {
bootstrap(item, 'exports', item.filename);
item._traced = true;
}
if (item.children) {
item.children.map(processModules);
}
} | javascript | function processModules(item) {
if (item.exports && !item._traced) {
bootstrap(item, 'exports', item.filename);
item._traced = true;
}
if (item.children) {
item.children.map(processModules);
}
} | [
"function",
"processModules",
"(",
"item",
")",
"{",
"if",
"(",
"item",
".",
"exports",
"&&",
"!",
"item",
".",
"_traced",
")",
"{",
"bootstrap",
"(",
"item",
",",
"'exports'",
",",
"item",
".",
"filename",
")",
";",
"item",
".",
"_traced",
"=",
"true",
";",
"}",
"if",
"(",
"item",
".",
"children",
")",
"{",
"item",
".",
"children",
".",
"map",
"(",
"processModules",
")",
";",
"}",
"}"
] | This iterates over every module in the project and attempts to bootstrap each one in turn | [
"This",
"iterates",
"over",
"every",
"module",
"in",
"the",
"project",
"and",
"attempts",
"to",
"bootstrap",
"each",
"one",
"in",
"turn"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L67-L75 | train |
holidayextras/hxTracer | index.js | bootstrap | function bootstrap(item, prop, path) {
if ( (path.split('node_modules').length > 2) || (path.slice(-4) == 'emit') || (item == require('util') && (prop=='format')) ) return;
if (!item.hasOwnProperty(prop) || Object.getOwnPropertyDescriptor(item, prop).get) return;
var original = item[prop];
if (allFuncs.indexOf(original) !== -1) return;
allFuncs.push(original);
if (item[prop] instanceof Function) {
infect(item, prop, path);
if (item[prop].prototype) {
bootstrap(item[prop], 'prototype', path+'.prototype');
}
for (var i in original) {
if (!original.hasOwnProperty(i) || Object.getOwnPropertyDescriptor(original, i).get) return;
item[prop][i] = original[i];
}
}
if (item[prop] instanceof Object) {
for (var i in item[prop]) {
bootstrap(item[prop], i, path+'.'+i);
}
}
return item;
} | javascript | function bootstrap(item, prop, path) {
if ( (path.split('node_modules').length > 2) || (path.slice(-4) == 'emit') || (item == require('util') && (prop=='format')) ) return;
if (!item.hasOwnProperty(prop) || Object.getOwnPropertyDescriptor(item, prop).get) return;
var original = item[prop];
if (allFuncs.indexOf(original) !== -1) return;
allFuncs.push(original);
if (item[prop] instanceof Function) {
infect(item, prop, path);
if (item[prop].prototype) {
bootstrap(item[prop], 'prototype', path+'.prototype');
}
for (var i in original) {
if (!original.hasOwnProperty(i) || Object.getOwnPropertyDescriptor(original, i).get) return;
item[prop][i] = original[i];
}
}
if (item[prop] instanceof Object) {
for (var i in item[prop]) {
bootstrap(item[prop], i, path+'.'+i);
}
}
return item;
} | [
"function",
"bootstrap",
"(",
"item",
",",
"prop",
",",
"path",
")",
"{",
"if",
"(",
"(",
"path",
".",
"split",
"(",
"'node_modules'",
")",
".",
"length",
">",
"2",
")",
"||",
"(",
"path",
".",
"slice",
"(",
"-",
"4",
")",
"==",
"'emit'",
")",
"||",
"(",
"item",
"==",
"require",
"(",
"'util'",
")",
"&&",
"(",
"prop",
"==",
"'format'",
")",
")",
")",
"return",
";",
"if",
"(",
"!",
"item",
".",
"hasOwnProperty",
"(",
"prop",
")",
"||",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"item",
",",
"prop",
")",
".",
"get",
")",
"return",
";",
"var",
"original",
"=",
"item",
"[",
"prop",
"]",
";",
"if",
"(",
"allFuncs",
".",
"indexOf",
"(",
"original",
")",
"!==",
"-",
"1",
")",
"return",
";",
"allFuncs",
".",
"push",
"(",
"original",
")",
";",
"if",
"(",
"item",
"[",
"prop",
"]",
"instanceof",
"Function",
")",
"{",
"infect",
"(",
"item",
",",
"prop",
",",
"path",
")",
";",
"if",
"(",
"item",
"[",
"prop",
"]",
".",
"prototype",
")",
"{",
"bootstrap",
"(",
"item",
"[",
"prop",
"]",
",",
"'prototype'",
",",
"path",
"+",
"'.prototype'",
")",
";",
"}",
"for",
"(",
"var",
"i",
"in",
"original",
")",
"{",
"if",
"(",
"!",
"original",
".",
"hasOwnProperty",
"(",
"i",
")",
"||",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"original",
",",
"i",
")",
".",
"get",
")",
"return",
";",
"item",
"[",
"prop",
"]",
"[",
"i",
"]",
"=",
"original",
"[",
"i",
"]",
";",
"}",
"}",
"if",
"(",
"item",
"[",
"prop",
"]",
"instanceof",
"Object",
")",
"{",
"for",
"(",
"var",
"i",
"in",
"item",
"[",
"prop",
"]",
")",
"{",
"bootstrap",
"(",
"item",
"[",
"prop",
"]",
",",
"i",
",",
"path",
"+",
"'.'",
"+",
"i",
")",
";",
"}",
"}",
"return",
"item",
";",
"}"
] | Bootstrap recursively iterates through an item, infecting every Function | [
"Bootstrap",
"recursively",
"iterates",
"through",
"an",
"item",
"infecting",
"every",
"Function"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L79-L101 | train |
holidayextras/hxTracer | index.js | timeDiff | function timeDiff(newest, oldest) {
var diff = (parseFloat(newest) - parseFloat(oldest));
if (diff < 0) {
diff = ((10000 + parseFloat(newest)) - parseFloat(oldest));
}
return diff;
} | javascript | function timeDiff(newest, oldest) {
var diff = (parseFloat(newest) - parseFloat(oldest));
if (diff < 0) {
diff = ((10000 + parseFloat(newest)) - parseFloat(oldest));
}
return diff;
} | [
"function",
"timeDiff",
"(",
"newest",
",",
"oldest",
")",
"{",
"var",
"diff",
"=",
"(",
"parseFloat",
"(",
"newest",
")",
"-",
"parseFloat",
"(",
"oldest",
")",
")",
";",
"if",
"(",
"diff",
"<",
"0",
")",
"{",
"diff",
"=",
"(",
"(",
"10000",
"+",
"parseFloat",
"(",
"newest",
")",
")",
"-",
"parseFloat",
"(",
"oldest",
")",
")",
";",
"}",
"return",
"diff",
";",
"}"
] | The timestamps we get are artificilly limited to 10 seconds. They might wrap around, so take that in to account | [
"The",
"timestamps",
"we",
"get",
"are",
"artificilly",
"limited",
"to",
"10",
"seconds",
".",
"They",
"might",
"wrap",
"around",
"so",
"take",
"that",
"in",
"to",
"account"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L219-L225 | train |
holidayextras/hxTracer | index.js | meaningfulTime | function meaningfulTime() {
if (moduleRef) {
var parts = processRef.hrtime();
return (((parts[0]*1000)+(parts[1]/1000000))%10000).toFixed(2) + 'ms';
} else {
return performance.now().toFixed(2)+'ms';
}
} | javascript | function meaningfulTime() {
if (moduleRef) {
var parts = processRef.hrtime();
return (((parts[0]*1000)+(parts[1]/1000000))%10000).toFixed(2) + 'ms';
} else {
return performance.now().toFixed(2)+'ms';
}
} | [
"function",
"meaningfulTime",
"(",
")",
"{",
"if",
"(",
"moduleRef",
")",
"{",
"var",
"parts",
"=",
"processRef",
".",
"hrtime",
"(",
")",
";",
"return",
"(",
"(",
"(",
"parts",
"[",
"0",
"]",
"*",
"1000",
")",
"+",
"(",
"parts",
"[",
"1",
"]",
"/",
"1000000",
")",
")",
"%",
"10000",
")",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
";",
"}",
"else",
"{",
"return",
"performance",
".",
"now",
"(",
")",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
";",
"}",
"}"
] | Get a sub-millisecond timing thats actually readable | [
"Get",
"a",
"sub",
"-",
"millisecond",
"timing",
"thats",
"actually",
"readable"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L228-L235 | train |
holidayextras/hxTracer | index.js | measureTracerOverhead | function measureTracerOverhead() {
var time1 = meaningfulTime();
var time2 = meaningfulTime();
console.error("TRACER OVERHEAD", timeDiff(time2, time1).toFixed(2)+'ms', 'per timing');
} | javascript | function measureTracerOverhead() {
var time1 = meaningfulTime();
var time2 = meaningfulTime();
console.error("TRACER OVERHEAD", timeDiff(time2, time1).toFixed(2)+'ms', 'per timing');
} | [
"function",
"measureTracerOverhead",
"(",
")",
"{",
"var",
"time1",
"=",
"meaningfulTime",
"(",
")",
";",
"var",
"time2",
"=",
"meaningfulTime",
"(",
")",
";",
"console",
".",
"error",
"(",
"\"TRACER OVERHEAD\"",
",",
"timeDiff",
"(",
"time2",
",",
"time1",
")",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
",",
"'per timing'",
")",
";",
"}"
] | How much time does it take to measure time? | [
"How",
"much",
"time",
"does",
"it",
"take",
"to",
"measure",
"time?"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L238-L242 | train |
holidayextras/hxTracer | index.js | processLogs | function processLogs() {
var calcs = 0;
for (var i in stats) {
stats[i].average = stats[i].totalTime / stats[i].count;
calcs += stats[i].calcs;
}
var time1 = meaningfulTime();
var time2 = meaningfulTime();
console.error("TRACER TOTAL OVERHEAD", (calcs*timeDiff(time2, time1)).toFixed(2)+'ms');
while (Object.keys(stats).length > 0) {
var biggest = 0;
var biggestPath = Object.keys(stats)[0];
for (var path in stats) {
if (stats[path].average >= biggest) {
biggestPath = path;
biggest = stats[path].average;
}
}
console.error("TRACER TOTAL",
stats[biggestPath].min.toFixed(2)+'ms',
stats[biggestPath].average.toFixed(2)+'ms',
stats[biggestPath].max.toFixed(2)+'ms',
stats[biggestPath].count,
biggestPath);
delete stats[biggestPath];
}
} | javascript | function processLogs() {
var calcs = 0;
for (var i in stats) {
stats[i].average = stats[i].totalTime / stats[i].count;
calcs += stats[i].calcs;
}
var time1 = meaningfulTime();
var time2 = meaningfulTime();
console.error("TRACER TOTAL OVERHEAD", (calcs*timeDiff(time2, time1)).toFixed(2)+'ms');
while (Object.keys(stats).length > 0) {
var biggest = 0;
var biggestPath = Object.keys(stats)[0];
for (var path in stats) {
if (stats[path].average >= biggest) {
biggestPath = path;
biggest = stats[path].average;
}
}
console.error("TRACER TOTAL",
stats[biggestPath].min.toFixed(2)+'ms',
stats[biggestPath].average.toFixed(2)+'ms',
stats[biggestPath].max.toFixed(2)+'ms',
stats[biggestPath].count,
biggestPath);
delete stats[biggestPath];
}
} | [
"function",
"processLogs",
"(",
")",
"{",
"var",
"calcs",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"in",
"stats",
")",
"{",
"stats",
"[",
"i",
"]",
".",
"average",
"=",
"stats",
"[",
"i",
"]",
".",
"totalTime",
"/",
"stats",
"[",
"i",
"]",
".",
"count",
";",
"calcs",
"+=",
"stats",
"[",
"i",
"]",
".",
"calcs",
";",
"}",
"var",
"time1",
"=",
"meaningfulTime",
"(",
")",
";",
"var",
"time2",
"=",
"meaningfulTime",
"(",
")",
";",
"console",
".",
"error",
"(",
"\"TRACER TOTAL OVERHEAD\"",
",",
"(",
"calcs",
"*",
"timeDiff",
"(",
"time2",
",",
"time1",
")",
")",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
")",
";",
"while",
"(",
"Object",
".",
"keys",
"(",
"stats",
")",
".",
"length",
">",
"0",
")",
"{",
"var",
"biggest",
"=",
"0",
";",
"var",
"biggestPath",
"=",
"Object",
".",
"keys",
"(",
"stats",
")",
"[",
"0",
"]",
";",
"for",
"(",
"var",
"path",
"in",
"stats",
")",
"{",
"if",
"(",
"stats",
"[",
"path",
"]",
".",
"average",
">=",
"biggest",
")",
"{",
"biggestPath",
"=",
"path",
";",
"biggest",
"=",
"stats",
"[",
"path",
"]",
".",
"average",
";",
"}",
"}",
"console",
".",
"error",
"(",
"\"TRACER TOTAL\"",
",",
"stats",
"[",
"biggestPath",
"]",
".",
"min",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
",",
"stats",
"[",
"biggestPath",
"]",
".",
"average",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
",",
"stats",
"[",
"biggestPath",
"]",
".",
"max",
".",
"toFixed",
"(",
"2",
")",
"+",
"'ms'",
",",
"stats",
"[",
"biggestPath",
"]",
".",
"count",
",",
"biggestPath",
")",
";",
"delete",
"stats",
"[",
"biggestPath",
"]",
";",
"}",
"}"
] | Process our logs after tracing to work out how much time is spent where | [
"Process",
"our",
"logs",
"after",
"tracing",
"to",
"work",
"out",
"how",
"much",
"time",
"is",
"spent",
"where"
] | cff4321e10d816239a025363dec73f093f52963f | https://github.com/holidayextras/hxTracer/blob/cff4321e10d816239a025363dec73f093f52963f/index.js#L245-L272 | train |
Enplug/dashboard-sdk | dist/sdk.js | debug | function debug(message) {
if (enplug.debug) {
arguments[0] = TAG + arguments[0];
console.log.apply(console, arguments);
}
} | javascript | function debug(message) {
if (enplug.debug) {
arguments[0] = TAG + arguments[0];
console.log.apply(console, arguments);
}
} | [
"function",
"debug",
"(",
"message",
")",
"{",
"if",
"(",
"enplug",
".",
"debug",
")",
"{",
"arguments",
"[",
"0",
"]",
"=",
"TAG",
"+",
"arguments",
"[",
"0",
"]",
";",
"console",
".",
"log",
".",
"apply",
"(",
"console",
",",
"arguments",
")",
";",
"}",
"}"
] | Logs messages to console when enplug.debug is enabled. Adds tag to messages.
@param message | [
"Logs",
"messages",
"to",
"console",
"when",
"enplug",
".",
"debug",
"is",
"enabled",
".",
"Adds",
"tag",
"to",
"messages",
"."
] | f5f5c69437e56072032effad6daa4088314b66b4 | https://github.com/Enplug/dashboard-sdk/blob/f5f5c69437e56072032effad6daa4088314b66b4/dist/sdk.js#L71-L76 | train |
Enplug/dashboard-sdk | dist/sdk.js | validateCallbacks | function validateCallbacks(options) {
if (options.successCallback && typeof options.successCallback !== 'function') {
throw new Error(TAG + 'Success callback must be a function.');
} else {
options.successCallback = options.successCallback || enplug.noop;
}
if (options.errorCallback && typeof options.errorCallback !== 'function') {
throw new Error(TAG + 'Error callback must be a function.');
} else {
options.errorCallback = options.errorCallback || enplug.noop;
}
} | javascript | function validateCallbacks(options) {
if (options.successCallback && typeof options.successCallback !== 'function') {
throw new Error(TAG + 'Success callback must be a function.');
} else {
options.successCallback = options.successCallback || enplug.noop;
}
if (options.errorCallback && typeof options.errorCallback !== 'function') {
throw new Error(TAG + 'Error callback must be a function.');
} else {
options.errorCallback = options.errorCallback || enplug.noop;
}
} | [
"function",
"validateCallbacks",
"(",
"options",
")",
"{",
"if",
"(",
"options",
".",
"successCallback",
"&&",
"typeof",
"options",
".",
"successCallback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"TAG",
"+",
"'Success callback must be a function.'",
")",
";",
"}",
"else",
"{",
"options",
".",
"successCallback",
"=",
"options",
".",
"successCallback",
"||",
"enplug",
".",
"noop",
";",
"}",
"if",
"(",
"options",
".",
"errorCallback",
"&&",
"typeof",
"options",
".",
"errorCallback",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"Error",
"(",
"TAG",
"+",
"'Error callback must be a function.'",
")",
";",
"}",
"else",
"{",
"options",
".",
"errorCallback",
"=",
"options",
".",
"errorCallback",
"||",
"enplug",
".",
"noop",
";",
"}",
"}"
] | Validate and assign defaults for callback methods.
@param {MethodCall} options | [
"Validate",
"and",
"assign",
"defaults",
"for",
"callback",
"methods",
"."
] | f5f5c69437e56072032effad6daa4088314b66b4 | https://github.com/Enplug/dashboard-sdk/blob/f5f5c69437e56072032effad6daa4088314b66b4/dist/sdk.js#L82-L94 | train |
Enplug/dashboard-sdk | dist/sdk.js | parseResponse | function parseResponse(event) {
try {
var response = JSON.parse(event.data);
// Check for success key to ignore messages being sent
if (response.namespace === namespace && typeof response.success === 'boolean') {
return response;
}
return false;
} catch (e) {}
return false;
} | javascript | function parseResponse(event) {
try {
var response = JSON.parse(event.data);
// Check for success key to ignore messages being sent
if (response.namespace === namespace && typeof response.success === 'boolean') {
return response;
}
return false;
} catch (e) {}
return false;
} | [
"function",
"parseResponse",
"(",
"event",
")",
"{",
"try",
"{",
"var",
"response",
"=",
"JSON",
".",
"parse",
"(",
"event",
".",
"data",
")",
";",
"if",
"(",
"response",
".",
"namespace",
"===",
"namespace",
"&&",
"typeof",
"response",
".",
"success",
"===",
"'boolean'",
")",
"{",
"return",
"response",
";",
"}",
"return",
"false",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"return",
"false",
";",
"}"
] | Verifies that a message is intended for the transport.
@param {MessageEvent} event
@returns {boolean} - Whether the message was successfully parsed. | [
"Verifies",
"that",
"a",
"message",
"is",
"intended",
"for",
"the",
"transport",
"."
] | f5f5c69437e56072032effad6daa4088314b66b4 | https://github.com/Enplug/dashboard-sdk/blob/f5f5c69437e56072032effad6daa4088314b66b4/dist/sdk.js#L101-L114 | train |
Enplug/dashboard-sdk | dist/sdk.js | function (options) {
if (typeof options === 'object') {
// Add implementation-specific method prefix (dashboard or app)
options.name = this.prefix + '.' + options.name;
return this.transport.send(options);
} else {
throw new Error('Transport options must be an object.');
}
} | javascript | function (options) {
if (typeof options === 'object') {
// Add implementation-specific method prefix (dashboard or app)
options.name = this.prefix + '.' + options.name;
return this.transport.send(options);
} else {
throw new Error('Transport options must be an object.');
}
} | [
"function",
"(",
"options",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'object'",
")",
"{",
"options",
".",
"name",
"=",
"this",
".",
"prefix",
"+",
"'.'",
"+",
"options",
".",
"name",
";",
"return",
"this",
".",
"transport",
".",
"send",
"(",
"options",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Transport options must be an object.'",
")",
";",
"}",
"}"
] | Factory for all SDK method calls.
@param {MethodCall|*} options
@returns {number} callId | [
"Factory",
"for",
"all",
"SDK",
"method",
"calls",
"."
] | f5f5c69437e56072032effad6daa4088314b66b4 | https://github.com/Enplug/dashboard-sdk/blob/f5f5c69437e56072032effad6daa4088314b66b4/dist/sdk.js#L263-L273 | train |
|
Enplug/dashboard-sdk | dist/sdk.js | decorateSend | function decorateSend(q, scope, transport) {
var original = transport.send;
transport.send = function (options) {
// Store originals
var defer = q.defer(),
onSuccess = options.successCallback || angular.noop,
onError = options.errorCallback || angular.noop;
options.successCallback = function (result) {
scope.$apply(function () {
defer.resolve(result);
onSuccess(result);
});
};
options.errorCallback = function (result) {
scope.$apply(function () {
defer.reject(result);
onError(result);
});
};
// Call the original transport method
// but use our promise as the return value
original.call(transport, options);
return defer.promise;
};
} | javascript | function decorateSend(q, scope, transport) {
var original = transport.send;
transport.send = function (options) {
// Store originals
var defer = q.defer(),
onSuccess = options.successCallback || angular.noop,
onError = options.errorCallback || angular.noop;
options.successCallback = function (result) {
scope.$apply(function () {
defer.resolve(result);
onSuccess(result);
});
};
options.errorCallback = function (result) {
scope.$apply(function () {
defer.reject(result);
onError(result);
});
};
// Call the original transport method
// but use our promise as the return value
original.call(transport, options);
return defer.promise;
};
} | [
"function",
"decorateSend",
"(",
"q",
",",
"scope",
",",
"transport",
")",
"{",
"var",
"original",
"=",
"transport",
".",
"send",
";",
"transport",
".",
"send",
"=",
"function",
"(",
"options",
")",
"{",
"var",
"defer",
"=",
"q",
".",
"defer",
"(",
")",
",",
"onSuccess",
"=",
"options",
".",
"successCallback",
"||",
"angular",
".",
"noop",
",",
"onError",
"=",
"options",
".",
"errorCallback",
"||",
"angular",
".",
"noop",
";",
"options",
".",
"successCallback",
"=",
"function",
"(",
"result",
")",
"{",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"defer",
".",
"resolve",
"(",
"result",
")",
";",
"onSuccess",
"(",
"result",
")",
";",
"}",
")",
";",
"}",
";",
"options",
".",
"errorCallback",
"=",
"function",
"(",
"result",
")",
"{",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"defer",
".",
"reject",
"(",
"result",
")",
";",
"onError",
"(",
"result",
")",
";",
"}",
")",
";",
"}",
";",
"original",
".",
"call",
"(",
"transport",
",",
"options",
")",
";",
"return",
"defer",
".",
"promise",
";",
"}",
";",
"}"
] | Modifies transport.send to return promises.
@param {Object} q
@param {Object} scope
@param {Object} transport | [
"Modifies",
"transport",
".",
"send",
"to",
"return",
"promises",
"."
] | f5f5c69437e56072032effad6daa4088314b66b4 | https://github.com/Enplug/dashboard-sdk/blob/f5f5c69437e56072032effad6daa4088314b66b4/dist/sdk.js#L1558-L1586 | train |
evannetwork/dbcp | scripts/deploy.js | function (hash) {
return new Promise((resolve, reject) => {
request(`${ ipfsProtocol }://${ ipfsHost }/ipfs/${hash}`, function (err, response, body) {
if (err) {
reject(err);
} else {
resolve(response);
}
});
});
} | javascript | function (hash) {
return new Promise((resolve, reject) => {
request(`${ ipfsProtocol }://${ ipfsHost }/ipfs/${hash}`, function (err, response, body) {
if (err) {
reject(err);
} else {
resolve(response);
}
});
});
} | [
"function",
"(",
"hash",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"request",
"(",
"`",
"${",
"ipfsProtocol",
"}",
"${",
"ipfsHost",
"}",
"${",
"hash",
"}",
"`",
",",
"function",
"(",
"err",
",",
"response",
",",
"body",
")",
"{",
"if",
"(",
"err",
")",
"{",
"reject",
"(",
"err",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"response",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"}"
] | Loads an ipfs hash to be sure, that its added and pinned.
@param {string} hash ipfs hash to load | [
"Loads",
"an",
"ipfs",
"hash",
"to",
"be",
"sure",
"that",
"its",
"added",
"and",
"pinned",
"."
] | c1f29577e0cc829a1259d683914673da7d54b58c | https://github.com/evannetwork/dbcp/blob/c1f29577e0cc829a1259d683914673da7d54b58c/scripts/deploy.js#L172-L182 | train |
|
evannetwork/dbcp | scripts/deploy.js | deleteDeploymentFolder | async function deleteDeploymentFolder() {
del.sync(deploymentTmpFolder, { force: true });
del.sync(deploymentFolder, { force: true });
} | javascript | async function deleteDeploymentFolder() {
del.sync(deploymentTmpFolder, { force: true });
del.sync(deploymentFolder, { force: true });
} | [
"async",
"function",
"deleteDeploymentFolder",
"(",
")",
"{",
"del",
".",
"sync",
"(",
"deploymentTmpFolder",
",",
"{",
"force",
":",
"true",
"}",
")",
";",
"del",
".",
"sync",
"(",
"deploymentFolder",
",",
"{",
"force",
":",
"true",
"}",
")",
";",
"}"
] | Delete the deployment folder when everything is ready. | [
"Delete",
"the",
"deployment",
"folder",
"when",
"everything",
"is",
"ready",
"."
] | c1f29577e0cc829a1259d683914673da7d54b58c | https://github.com/evannetwork/dbcp/blob/c1f29577e0cc829a1259d683914673da7d54b58c/scripts/deploy.js#L253-L256 | train |
evannetwork/dbcp | scripts/deploy.js | deploy | async function deploy() {
try {
await browserifyDBCP();
await uglify();
const ipfsHash = await deployToIPFS(`${ deploymentFolder}/${ browserifyName}`);
await pinToIPFS(ipfsHash);
const ipnsHash = await deployToIpns(ipfsHash);
deleteDeploymentFolder();
console.log(`\nFinished deployment`);
console.log(`IPFS: ${ ipfsHash }`);
console.log(`IPNS: ${ ipnsHash }`);
} catch (ex) {
console.error(ex);
}
} | javascript | async function deploy() {
try {
await browserifyDBCP();
await uglify();
const ipfsHash = await deployToIPFS(`${ deploymentFolder}/${ browserifyName}`);
await pinToIPFS(ipfsHash);
const ipnsHash = await deployToIpns(ipfsHash);
deleteDeploymentFolder();
console.log(`\nFinished deployment`);
console.log(`IPFS: ${ ipfsHash }`);
console.log(`IPNS: ${ ipnsHash }`);
} catch (ex) {
console.error(ex);
}
} | [
"async",
"function",
"deploy",
"(",
")",
"{",
"try",
"{",
"await",
"browserifyDBCP",
"(",
")",
";",
"await",
"uglify",
"(",
")",
";",
"const",
"ipfsHash",
"=",
"await",
"deployToIPFS",
"(",
"`",
"${",
"deploymentFolder",
"}",
"${",
"browserifyName",
"}",
"`",
")",
";",
"await",
"pinToIPFS",
"(",
"ipfsHash",
")",
";",
"const",
"ipnsHash",
"=",
"await",
"deployToIpns",
"(",
"ipfsHash",
")",
";",
"deleteDeploymentFolder",
"(",
")",
";",
"console",
".",
"log",
"(",
"`",
"\\n",
"`",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"ipfsHash",
"}",
"`",
")",
";",
"console",
".",
"log",
"(",
"`",
"${",
"ipnsHash",
"}",
"`",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"console",
".",
"error",
"(",
"ex",
")",
";",
"}",
"}"
] | Build the js files into one file using browserify, deploys the file to ipfs and binds the new hash to ipns | [
"Build",
"the",
"js",
"files",
"into",
"one",
"file",
"using",
"browserify",
"deploys",
"the",
"file",
"to",
"ipfs",
"and",
"binds",
"the",
"new",
"hash",
"to",
"ipns"
] | c1f29577e0cc829a1259d683914673da7d54b58c | https://github.com/evannetwork/dbcp/blob/c1f29577e0cc829a1259d683914673da7d54b58c/scripts/deploy.js#L261-L276 | train |
nickschot/ember-mobile-core | addon/utils/parse-touch-data.js | getPointDistance | function getPointDistance(x0, x1, y0, y1) {
return (Math.sqrt(((x1 - x0) * (x1 - x0)) + ((y1 - y0) * (y1 - y0))));
} | javascript | function getPointDistance(x0, x1, y0, y1) {
return (Math.sqrt(((x1 - x0) * (x1 - x0)) + ((y1 - y0) * (y1 - y0))));
} | [
"function",
"getPointDistance",
"(",
"x0",
",",
"x1",
",",
"y0",
",",
"y1",
")",
"{",
"return",
"(",
"Math",
".",
"sqrt",
"(",
"(",
"(",
"x1",
"-",
"x0",
")",
"*",
"(",
"x1",
"-",
"x0",
")",
")",
"+",
"(",
"(",
"y1",
"-",
"y0",
")",
"*",
"(",
"y1",
"-",
"y0",
")",
")",
")",
")",
";",
"}"
] | Calculates the distance between two points
@function getPointDistance
@param {number} x0 X coordinate of the origin
@param {number} x1 X coordinate of the current position
@param {number} y0 Y coordinate of the origin
@param {number} y1 Y coordinate of the current position
@return {number} Distance between the two points
@private | [
"Calculates",
"the",
"distance",
"between",
"two",
"points"
] | b9baebf8c62cdc38e3ee5dd6063c46c95cfcbc92 | https://github.com/nickschot/ember-mobile-core/blob/b9baebf8c62cdc38e3ee5dd6063c46c95cfcbc92/addon/utils/parse-touch-data.js#L155-L157 | train |
nickschot/ember-mobile-core | addon/utils/parse-touch-data.js | getAngle | function getAngle(originX, originY, projectionX, projectionY) {
const angle = Math.atan2(projectionY - originY, projectionX - originX) * ((180) / Math.PI);
return 360 - ((angle < 0) ? (360 + angle) : angle);
} | javascript | function getAngle(originX, originY, projectionX, projectionY) {
const angle = Math.atan2(projectionY - originY, projectionX - originX) * ((180) / Math.PI);
return 360 - ((angle < 0) ? (360 + angle) : angle);
} | [
"function",
"getAngle",
"(",
"originX",
",",
"originY",
",",
"projectionX",
",",
"projectionY",
")",
"{",
"const",
"angle",
"=",
"Math",
".",
"atan2",
"(",
"projectionY",
"-",
"originY",
",",
"projectionX",
"-",
"originX",
")",
"*",
"(",
"(",
"180",
")",
"/",
"Math",
".",
"PI",
")",
";",
"return",
"360",
"-",
"(",
"(",
"angle",
"<",
"0",
")",
"?",
"(",
"360",
"+",
"angle",
")",
":",
"angle",
")",
";",
"}"
] | Calculates the angle between two points.
@function getAngle
@param {number} originX
@param {number} originY
@param {number} projectionX
@param {number} projectionY
@return {number} Angle between the two points
@private | [
"Calculates",
"the",
"angle",
"between",
"two",
"points",
"."
] | b9baebf8c62cdc38e3ee5dd6063c46c95cfcbc92 | https://github.com/nickschot/ember-mobile-core/blob/b9baebf8c62cdc38e3ee5dd6063c46c95cfcbc92/addon/utils/parse-touch-data.js#L170-L173 | train |
nyteshade/graphql-lattice | dist/decorators/ModelProperties.js | add | function add(className) {
if (typeof className === 'function') {
className = className.name;
}
extractBits.DIRECT_TYPES.push(className);
} | javascript | function add(className) {
if (typeof className === 'function') {
className = className.name;
}
extractBits.DIRECT_TYPES.push(className);
} | [
"function",
"add",
"(",
"className",
")",
"{",
"if",
"(",
"typeof",
"className",
"===",
"'function'",
")",
"{",
"className",
"=",
"className",
".",
"name",
";",
"}",
"extractBits",
".",
"DIRECT_TYPES",
".",
"push",
"(",
"className",
")",
";",
"}"
] | Appends the supplied class name to the list of registered direct types. If
a class or function is passed, rather than a String,
@method DirectTypeManager#types
@param {Function|string|RegExp} className the name of the class to append.
Typically it is best to pass the name property of the class in question
such as `RegExp.name` or `MyClass.name`. | [
"Appends",
"the",
"supplied",
"class",
"name",
"to",
"the",
"list",
"of",
"registered",
"direct",
"types",
".",
"If",
"a",
"class",
"or",
"function",
"is",
"passed",
"rather",
"than",
"a",
"String"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/decorators/ModelProperties.js#L254-L260 | train |
nyteshade/graphql-lattice | dist/decorators/ModelProperties.js | applyTags | function applyTags(Class, addTags, fieldName, descriptor) {
var tags = (Array.isArray(addTags) && addTags || []).map(function (tag) {
return typeof tag === 'string' && Symbol.for(tag) || tag;
}).filter(function (tag) {
return (0, _typeof2.default)(tag) === 'symbol';
});
tags.forEach(function (tag) {
Class[_GQLBase.META_KEY][tag] = Class[_GQLBase.META_KEY][tag] || {};
Class[_GQLBase.META_KEY][tag][fieldName] = descriptor;
});
} | javascript | function applyTags(Class, addTags, fieldName, descriptor) {
var tags = (Array.isArray(addTags) && addTags || []).map(function (tag) {
return typeof tag === 'string' && Symbol.for(tag) || tag;
}).filter(function (tag) {
return (0, _typeof2.default)(tag) === 'symbol';
});
tags.forEach(function (tag) {
Class[_GQLBase.META_KEY][tag] = Class[_GQLBase.META_KEY][tag] || {};
Class[_GQLBase.META_KEY][tag][fieldName] = descriptor;
});
} | [
"function",
"applyTags",
"(",
"Class",
",",
"addTags",
",",
"fieldName",
",",
"descriptor",
")",
"{",
"var",
"tags",
"=",
"(",
"Array",
".",
"isArray",
"(",
"addTags",
")",
"&&",
"addTags",
"||",
"[",
"]",
")",
".",
"map",
"(",
"function",
"(",
"tag",
")",
"{",
"return",
"typeof",
"tag",
"===",
"'string'",
"&&",
"Symbol",
".",
"for",
"(",
"tag",
")",
"||",
"tag",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"tag",
")",
"{",
"return",
"(",
"0",
",",
"_typeof2",
".",
"default",
")",
"(",
"tag",
")",
"===",
"'symbol'",
";",
"}",
")",
";",
"tags",
".",
"forEach",
"(",
"function",
"(",
"tag",
")",
"{",
"Class",
"[",
"_GQLBase",
".",
"META_KEY",
"]",
"[",
"tag",
"]",
"=",
"Class",
"[",
"_GQLBase",
".",
"META_KEY",
"]",
"[",
"tag",
"]",
"||",
"{",
"}",
";",
"Class",
"[",
"_GQLBase",
".",
"META_KEY",
"]",
"[",
"tag",
"]",
"[",
"fieldName",
"]",
"=",
"descriptor",
";",
"}",
")",
";",
"}"
] | When applying multiple property getters and setters, knowing some info
about what was applied elsewhere can be important. "Tags" can be applied
that store the fieldName and descriptor applied via one of these decorators.
Multiple "tags" are supported to allow for detecting the difference between
decorators applied by the developer using lattice and something auto
generated such as auto-props.
@param {GQLBase} Class an instance of GQLBase to apply the tags tp
@param {Array<string|Symbol>} addTags an array of Symbols or strings to be
wrapped in Symbols that will be used as tag keys
@param {string} fieldName the name of the field being decorated
@param {Object} descriptor the JavaScript descriptor object to associate
with this tagged field. | [
"When",
"applying",
"multiple",
"property",
"getters",
"and",
"setters",
"knowing",
"some",
"info",
"about",
"what",
"was",
"applied",
"elsewhere",
"can",
"be",
"important",
".",
"Tags",
"can",
"be",
"applied",
"that",
"store",
"the",
"fieldName",
"and",
"descriptor",
"applied",
"via",
"one",
"of",
"these",
"decorators",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/decorators/ModelProperties.js#L323-L333 | train |
SimpliField/oh-csv | src/index.js | csvWrapForExcel | function csvWrapForExcel(encoder) {
// Pipe the CSV encoder to the ucs2 converter
var converter = new Stream.Transform();
var csvStream = new Stream.PassThrough();
converter._transform = function(chunk, encoding, cb) {
this.push(new Buffer(chunk.toString(), 'ucs2'));
cb();
};
// Write the UCS2 BOM http://www.unicode.org/faq/utf_bom.html#bom1
csvStream.write(new Buffer([0xFF, 0xFE]));
return encoder.pipe(converter).pipe(csvStream);
} | javascript | function csvWrapForExcel(encoder) {
// Pipe the CSV encoder to the ucs2 converter
var converter = new Stream.Transform();
var csvStream = new Stream.PassThrough();
converter._transform = function(chunk, encoding, cb) {
this.push(new Buffer(chunk.toString(), 'ucs2'));
cb();
};
// Write the UCS2 BOM http://www.unicode.org/faq/utf_bom.html#bom1
csvStream.write(new Buffer([0xFF, 0xFE]));
return encoder.pipe(converter).pipe(csvStream);
} | [
"function",
"csvWrapForExcel",
"(",
"encoder",
")",
"{",
"var",
"converter",
"=",
"new",
"Stream",
".",
"Transform",
"(",
")",
";",
"var",
"csvStream",
"=",
"new",
"Stream",
".",
"PassThrough",
"(",
")",
";",
"converter",
".",
"_transform",
"=",
"function",
"(",
"chunk",
",",
"encoding",
",",
"cb",
")",
"{",
"this",
".",
"push",
"(",
"new",
"Buffer",
"(",
"chunk",
".",
"toString",
"(",
")",
",",
"'ucs2'",
")",
")",
";",
"cb",
"(",
")",
";",
"}",
";",
"csvStream",
".",
"write",
"(",
"new",
"Buffer",
"(",
"[",
"0xFF",
",",
"0xFE",
"]",
")",
")",
";",
"return",
"encoder",
".",
"pipe",
"(",
"converter",
")",
".",
"pipe",
"(",
"csvStream",
")",
";",
"}"
] | X-Platform Excel encoder | [
"X",
"-",
"Platform",
"Excel",
"encoder"
] | c6c921783fb257cbc4d4e806210b1eccaf1d0f74 | https://github.com/SimpliField/oh-csv/blob/c6c921783fb257cbc4d4e806210b1eccaf1d0f74/src/index.js#L465-L476 | train |
mjeanroy/karma-json-preprocessor | src/karma-json-preprocessor.js | createJsonPreprocessor | function createJsonPreprocessor(logger, basePath, config) {
const log = logger.create('preprocessor.json');
const conf = config || {};
const stripPrefix = new RegExp(`^${(conf.stripPrefix || '')}`);
return function(content, file, done) {
log.debug('Processing "%s".', file.originalPath);
// Build json path file.
const jsonPath = file.originalPath
.replace(`${basePath}/`, '')
.replace(stripPrefix, '');
const template = createTemplate(conf.varName || '__json__');
// Update file path
file.path = `${file.path}.js`;
try {
const o = JSON.parse(content.trim());
done(util.format(template, jsonPath, JSON.stringify(o)));
} catch (e) {
log.error('Json representation of %s is not valid !', file.originalPath);
done('');
}
};
} | javascript | function createJsonPreprocessor(logger, basePath, config) {
const log = logger.create('preprocessor.json');
const conf = config || {};
const stripPrefix = new RegExp(`^${(conf.stripPrefix || '')}`);
return function(content, file, done) {
log.debug('Processing "%s".', file.originalPath);
// Build json path file.
const jsonPath = file.originalPath
.replace(`${basePath}/`, '')
.replace(stripPrefix, '');
const template = createTemplate(conf.varName || '__json__');
// Update file path
file.path = `${file.path}.js`;
try {
const o = JSON.parse(content.trim());
done(util.format(template, jsonPath, JSON.stringify(o)));
} catch (e) {
log.error('Json representation of %s is not valid !', file.originalPath);
done('');
}
};
} | [
"function",
"createJsonPreprocessor",
"(",
"logger",
",",
"basePath",
",",
"config",
")",
"{",
"const",
"log",
"=",
"logger",
".",
"create",
"(",
"'preprocessor.json'",
")",
";",
"const",
"conf",
"=",
"config",
"||",
"{",
"}",
";",
"const",
"stripPrefix",
"=",
"new",
"RegExp",
"(",
"`",
"${",
"(",
"conf",
".",
"stripPrefix",
"||",
"''",
")",
"}",
"`",
")",
";",
"return",
"function",
"(",
"content",
",",
"file",
",",
"done",
")",
"{",
"log",
".",
"debug",
"(",
"'Processing \"%s\".'",
",",
"file",
".",
"originalPath",
")",
";",
"const",
"jsonPath",
"=",
"file",
".",
"originalPath",
".",
"replace",
"(",
"`",
"${",
"basePath",
"}",
"`",
",",
"''",
")",
".",
"replace",
"(",
"stripPrefix",
",",
"''",
")",
";",
"const",
"template",
"=",
"createTemplate",
"(",
"conf",
".",
"varName",
"||",
"'__json__'",
")",
";",
"file",
".",
"path",
"=",
"`",
"${",
"file",
".",
"path",
"}",
"`",
";",
"try",
"{",
"const",
"o",
"=",
"JSON",
".",
"parse",
"(",
"content",
".",
"trim",
"(",
")",
")",
";",
"done",
"(",
"util",
".",
"format",
"(",
"template",
",",
"jsonPath",
",",
"JSON",
".",
"stringify",
"(",
"o",
")",
")",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"log",
".",
"error",
"(",
"'Json representation of %s is not valid !'",
",",
"file",
".",
"originalPath",
")",
";",
"done",
"(",
"''",
")",
";",
"}",
"}",
";",
"}"
] | Create the JSON preprocessor.
@param {Object} logger Karma logger.
@param {string} basePath The base path initialized by karma.
@param {Object} config The configuration object.
@return {function} The preprocessor function. | [
"Create",
"the",
"JSON",
"preprocessor",
"."
] | 732be0355edfb40b4116a3fd0ed41ca3c218cf73 | https://github.com/mjeanroy/karma-json-preprocessor/blob/732be0355edfb40b4116a3fd0ed41ca3c218cf73/src/karma-json-preprocessor.js#L59-L85 | train |
rocjs/extensions | packages/roc-package-webpack-dev/src/webpack/utils/rocExportWebpackPlugin.js | createGetAlias | function createGetAlias(aliases) {
if (isPlainObject(aliases) && !Array.isArray(aliases)) {
aliases = Object.keys(aliases).map((key) => { // eslint-disable-line
let onlyModule = false;
let obj = aliases[key];
if (/\$$/.test(key)) {
onlyModule = true;
key = key.substr(0, key.length - 1); // eslint-disable-line
}
if (isString(obj)) {
obj = {
alias: obj,
};
}
return {
name: key,
onlyModule,
...obj,
};
});
}
return (request) => {
for (const alias of aliases) {
if ((!alias.onlyModule && request.indexOf(`${alias.name}/`) === 0) || request === alias.name) {
if (request.indexOf(`${alias.alias}/`) !== 0 && request !== alias.alias) {
return alias.alias + request.substr(alias.name.length);
}
}
}
return request;
};
} | javascript | function createGetAlias(aliases) {
if (isPlainObject(aliases) && !Array.isArray(aliases)) {
aliases = Object.keys(aliases).map((key) => { // eslint-disable-line
let onlyModule = false;
let obj = aliases[key];
if (/\$$/.test(key)) {
onlyModule = true;
key = key.substr(0, key.length - 1); // eslint-disable-line
}
if (isString(obj)) {
obj = {
alias: obj,
};
}
return {
name: key,
onlyModule,
...obj,
};
});
}
return (request) => {
for (const alias of aliases) {
if ((!alias.onlyModule && request.indexOf(`${alias.name}/`) === 0) || request === alias.name) {
if (request.indexOf(`${alias.alias}/`) !== 0 && request !== alias.alias) {
return alias.alias + request.substr(alias.name.length);
}
}
}
return request;
};
} | [
"function",
"createGetAlias",
"(",
"aliases",
")",
"{",
"if",
"(",
"isPlainObject",
"(",
"aliases",
")",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"aliases",
")",
")",
"{",
"aliases",
"=",
"Object",
".",
"keys",
"(",
"aliases",
")",
".",
"map",
"(",
"(",
"key",
")",
"=>",
"{",
"let",
"onlyModule",
"=",
"false",
";",
"let",
"obj",
"=",
"aliases",
"[",
"key",
"]",
";",
"if",
"(",
"/",
"\\$$",
"/",
".",
"test",
"(",
"key",
")",
")",
"{",
"onlyModule",
"=",
"true",
";",
"key",
"=",
"key",
".",
"substr",
"(",
"0",
",",
"key",
".",
"length",
"-",
"1",
")",
";",
"}",
"if",
"(",
"isString",
"(",
"obj",
")",
")",
"{",
"obj",
"=",
"{",
"alias",
":",
"obj",
",",
"}",
";",
"}",
"return",
"{",
"name",
":",
"key",
",",
"onlyModule",
",",
"...",
"obj",
",",
"}",
";",
"}",
")",
";",
"}",
"return",
"(",
"request",
")",
"=>",
"{",
"for",
"(",
"const",
"alias",
"of",
"aliases",
")",
"{",
"if",
"(",
"(",
"!",
"alias",
".",
"onlyModule",
"&&",
"request",
".",
"indexOf",
"(",
"`",
"${",
"alias",
".",
"name",
"}",
"`",
")",
"===",
"0",
")",
"||",
"request",
"===",
"alias",
".",
"name",
")",
"{",
"if",
"(",
"request",
".",
"indexOf",
"(",
"`",
"${",
"alias",
".",
"alias",
"}",
"`",
")",
"!==",
"0",
"&&",
"request",
"!==",
"alias",
".",
"alias",
")",
"{",
"return",
"alias",
".",
"alias",
"+",
"request",
".",
"substr",
"(",
"alias",
".",
"name",
".",
"length",
")",
";",
"}",
"}",
"}",
"return",
"request",
";",
"}",
";",
"}"
] | Based on code from enhanced-resolve | [
"Based",
"on",
"code",
"from",
"enhanced",
"-",
"resolve"
] | e9c364768c4edd30b789b94c51d20778d903d063 | https://github.com/rocjs/extensions/blob/e9c364768c4edd30b789b94c51d20778d903d063/packages/roc-package-webpack-dev/src/webpack/utils/rocExportWebpackPlugin.js#L91-L123 | train |
nyteshade/graphql-lattice | dist/LatticeFactory.js | setChecklist | function setChecklist(Class, item) {
var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var checklist = getChecklist(Class);
if (checklist) {
// $FlowFixMe
checklist[item] = value;
}
} | javascript | function setChecklist(Class, item) {
var value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
var checklist = getChecklist(Class);
if (checklist) {
// $FlowFixMe
checklist[item] = value;
}
} | [
"function",
"setChecklist",
"(",
"Class",
",",
"item",
")",
"{",
"var",
"value",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"true",
";",
"var",
"checklist",
"=",
"getChecklist",
"(",
"Class",
")",
";",
"if",
"(",
"checklist",
")",
"{",
"checklist",
"[",
"item",
"]",
"=",
"value",
";",
"}",
"}"
] | Obtains the checklist from the supplied GQLBase extended class. If the
class has a checklist, its checklist item is set to true or the boolean
value specified.
@param {Function} Class a reference to the GQLBase class to set
@param {Symbol} item one of CHECK_SCHEMA, CHECK_RESOLVERS, or
CHECK_API_DOCS
@param {Boolean} value the value for the checklist item to set | [
"Obtains",
"the",
"checklist",
"from",
"the",
"supplied",
"GQLBase",
"extended",
"class",
".",
"If",
"the",
"class",
"has",
"a",
"checklist",
"its",
"checklist",
"item",
"is",
"set",
"to",
"true",
"or",
"the",
"boolean",
"value",
"specified",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/LatticeFactory.js#L280-L288 | train |
nyteshade/graphql-lattice | dist/LatticeFactory.js | hasChecklist | function hasChecklist(Class) {
var checklist = getChecklist(Class);
for (var _len2 = arguments.length, items = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
items[_key2 - 1] = arguments[_key2];
}
if (checklist && items.length) {
for (var _i2 = 0; _i2 < items.length; _i2++) {
var item = items[_i2];
if (!checklist[item]) {
return false;
}
}
return true;
}
return checklist;
} | javascript | function hasChecklist(Class) {
var checklist = getChecklist(Class);
for (var _len2 = arguments.length, items = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
items[_key2 - 1] = arguments[_key2];
}
if (checklist && items.length) {
for (var _i2 = 0; _i2 < items.length; _i2++) {
var item = items[_i2];
if (!checklist[item]) {
return false;
}
}
return true;
}
return checklist;
} | [
"function",
"hasChecklist",
"(",
"Class",
")",
"{",
"var",
"checklist",
"=",
"getChecklist",
"(",
"Class",
")",
";",
"for",
"(",
"var",
"_len2",
"=",
"arguments",
".",
"length",
",",
"items",
"=",
"new",
"Array",
"(",
"_len2",
">",
"1",
"?",
"_len2",
"-",
"1",
":",
"0",
")",
",",
"_key2",
"=",
"1",
";",
"_key2",
"<",
"_len2",
";",
"_key2",
"++",
")",
"{",
"items",
"[",
"_key2",
"-",
"1",
"]",
"=",
"arguments",
"[",
"_key2",
"]",
";",
"}",
"if",
"(",
"checklist",
"&&",
"items",
".",
"length",
")",
"{",
"for",
"(",
"var",
"_i2",
"=",
"0",
";",
"_i2",
"<",
"items",
".",
"length",
";",
"_i2",
"++",
")",
"{",
"var",
"item",
"=",
"items",
"[",
"_i2",
"]",
";",
"if",
"(",
"!",
"checklist",
"[",
"item",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"checklist",
";",
"}"
] | This function, when invoked with only a class will return true if the
Class has a defined checklist. If one ore more CHECKLIST symbols are
passed, the function will only return true if all the supplied symbols
are set to truthy values.
@param {Function} Class a reference to the GQLBase class to set
@param {Array<Symbol>} items any of CHECK_SCHEMA, CHECK_RESOLVERS, or
CHECK_API_DOCS
@return {Boolean} true if the checklist and/or all items are true and
present. | [
"This",
"function",
"when",
"invoked",
"with",
"only",
"a",
"class",
"will",
"return",
"true",
"if",
"the",
"Class",
"has",
"a",
"defined",
"checklist",
".",
"If",
"one",
"ore",
"more",
"CHECKLIST",
"symbols",
"are",
"passed",
"the",
"function",
"will",
"only",
"return",
"true",
"if",
"all",
"the",
"supplied",
"symbols",
"are",
"set",
"to",
"truthy",
"values",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/LatticeFactory.js#L303-L323 | train |
nyteshade/graphql-lattice | dist/LatticeFactory.js | newChecklist | function newChecklist(Class) {
if (Class) {
var _keys, _complete, _Class$META_KEY$CHECK, _mutatorMap;
// $FlowFixMe
Class[_GQLBase.META_KEY][CHECKLIST] = (_Class$META_KEY$CHECK = {}, (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_SCHEMA, false), (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_RESOLVERS, false), (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_API_DOCS, false), _keys = "keys", _mutatorMap = {}, _mutatorMap[_keys] = _mutatorMap[_keys] || {}, _mutatorMap[_keys].get = function () {
return [CHECK_SCHEMA, CHECK_RESOLVERS, CHECK_API_DOCS];
}, _complete = "complete", _mutatorMap[_complete] = _mutatorMap[_complete] || {}, _mutatorMap[_complete].get = function () {
var _this = this;
return this.keys.reduce(function (p, c, i, a) {
if (!p || !_this[c]) {
return false;
}
}, true);
}, (0, _defineEnumerableProperties2.default)(_Class$META_KEY$CHECK, _mutatorMap), _Class$META_KEY$CHECK);
} else {
throw new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject()));
}
} | javascript | function newChecklist(Class) {
if (Class) {
var _keys, _complete, _Class$META_KEY$CHECK, _mutatorMap;
// $FlowFixMe
Class[_GQLBase.META_KEY][CHECKLIST] = (_Class$META_KEY$CHECK = {}, (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_SCHEMA, false), (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_RESOLVERS, false), (0, _defineProperty2.default)(_Class$META_KEY$CHECK, CHECK_API_DOCS, false), _keys = "keys", _mutatorMap = {}, _mutatorMap[_keys] = _mutatorMap[_keys] || {}, _mutatorMap[_keys].get = function () {
return [CHECK_SCHEMA, CHECK_RESOLVERS, CHECK_API_DOCS];
}, _complete = "complete", _mutatorMap[_complete] = _mutatorMap[_complete] || {}, _mutatorMap[_complete].get = function () {
var _this = this;
return this.keys.reduce(function (p, c, i, a) {
if (!p || !_this[c]) {
return false;
}
}, true);
}, (0, _defineEnumerableProperties2.default)(_Class$META_KEY$CHECK, _mutatorMap), _Class$META_KEY$CHECK);
} else {
throw new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject()));
}
} | [
"function",
"newChecklist",
"(",
"Class",
")",
"{",
"if",
"(",
"Class",
")",
"{",
"var",
"_keys",
",",
"_complete",
",",
"_Class$META_KEY$CHECK",
",",
"_mutatorMap",
";",
"Class",
"[",
"_GQLBase",
".",
"META_KEY",
"]",
"[",
"CHECKLIST",
"]",
"=",
"(",
"_Class$META_KEY$CHECK",
"=",
"{",
"}",
",",
"(",
"0",
",",
"_defineProperty2",
".",
"default",
")",
"(",
"_Class$META_KEY$CHECK",
",",
"CHECK_SCHEMA",
",",
"false",
")",
",",
"(",
"0",
",",
"_defineProperty2",
".",
"default",
")",
"(",
"_Class$META_KEY$CHECK",
",",
"CHECK_RESOLVERS",
",",
"false",
")",
",",
"(",
"0",
",",
"_defineProperty2",
".",
"default",
")",
"(",
"_Class$META_KEY$CHECK",
",",
"CHECK_API_DOCS",
",",
"false",
")",
",",
"_keys",
"=",
"\"keys\"",
",",
"_mutatorMap",
"=",
"{",
"}",
",",
"_mutatorMap",
"[",
"_keys",
"]",
"=",
"_mutatorMap",
"[",
"_keys",
"]",
"||",
"{",
"}",
",",
"_mutatorMap",
"[",
"_keys",
"]",
".",
"get",
"=",
"function",
"(",
")",
"{",
"return",
"[",
"CHECK_SCHEMA",
",",
"CHECK_RESOLVERS",
",",
"CHECK_API_DOCS",
"]",
";",
"}",
",",
"_complete",
"=",
"\"complete\"",
",",
"_mutatorMap",
"[",
"_complete",
"]",
"=",
"_mutatorMap",
"[",
"_complete",
"]",
"||",
"{",
"}",
",",
"_mutatorMap",
"[",
"_complete",
"]",
".",
"get",
"=",
"function",
"(",
")",
"{",
"var",
"_this",
"=",
"this",
";",
"return",
"this",
".",
"keys",
".",
"reduce",
"(",
"function",
"(",
"p",
",",
"c",
",",
"i",
",",
"a",
")",
"{",
"if",
"(",
"!",
"p",
"||",
"!",
"_this",
"[",
"c",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
",",
"true",
")",
";",
"}",
",",
"(",
"0",
",",
"_defineEnumerableProperties2",
".",
"default",
")",
"(",
"_Class$META_KEY$CHECK",
",",
"_mutatorMap",
")",
",",
"_Class$META_KEY$CHECK",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject",
"(",
")",
")",
")",
";",
"}",
"}"
] | Injects and creates a new CHECKLIST object on the supplied GQLBase
extended class. All items are installed and set to false.
@param {Function} Class a reference to the GQLBase class to set | [
"Injects",
"and",
"creates",
"a",
"new",
"CHECKLIST",
"object",
"on",
"the",
"supplied",
"GQLBase",
"extended",
"class",
".",
"All",
"items",
"are",
"installed",
"and",
"set",
"to",
"false",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/LatticeFactory.js#L332-L353 | train |
nyteshade/graphql-lattice | dist/LatticeFactory.js | validateTemplate | function validateTemplate(template) {
var hide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var results = new ValidationResults();
var indent = function indent(string) {
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
var space = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' ';
return string.split('\n').map(function (s) {
return s.trim().replace(/(^)/gm, "$1".concat(space.repeat(count)));
}).join('\n');
};
if (typeof template.name === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject2())));
}
if (!(0, _neTypes.extendsFrom)(template.name, String)) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject3())));
}
if (typeof template.schema === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject4())));
}
if (!(0, _neTypes.extendsFrom)(template.schema, String)) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject5())));
}
if (!(0, _neTypes.extendsFrom)(template.resolvers, Object) // Supports 95% of objects
|| (0, _typeof2.default)(template.resolvers) !== 'object' // Supports Object.create(null)
) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject6())));
}
if (typeof template.docs === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject7())));
}
if (!(0, _neTypes.extendsFrom)(template.docs, Object) // Supports 95% of objects
|| (0, _typeof2.default)(template.docs) !== 'object' // Supports Object.create(null)
) {
var dr = '\x1b[31m',
br = '\x1b[91m';
var b1 = '\x1b[1m',
b0 = '\x1b[22m';
var bb = '\x1b[90m';
var dg = '\x1b[37m',
bg = '\x1b[97m';
var a0 = '\x1b[0m';
var gr = '\x1b[32m',
bgr = '\x1b[92m';
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject8(), bb, dg, b1, b0, gr, dg, b1, b0, b1, b0, gr, dg, gr, dg, gr, dg, b1, b0, gr, dg, b1, b0, gr, dg)));
}
if (!results.valid) {
var errorStrings = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = results.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _error = _step.value;
var message = _error.message,
stack = _error.stack;
stack = stack.trim().split('\n').splice(message.split('\n').length).map(function (s) {
return s.trim();
}).join('\n');
message = message.replace(/(Error:\s)/, '$1\n').trim();
errorStrings.push("\x1B[31;1m".concat(message, "\x1B[0m\n") + indent(stack));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var error = new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject9()).replace(/@template/, indent(_i(template))).replace(/@errors/, errorStrings.join('\n\n')));
error.stack = error.message;
error.message = '';
if (!hide) throw error;
}
return results;
} | javascript | function validateTemplate(template) {
var hide = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var results = new ValidationResults();
var indent = function indent(string) {
var count = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 4;
var space = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ' ';
return string.split('\n').map(function (s) {
return s.trim().replace(/(^)/gm, "$1".concat(space.repeat(count)));
}).join('\n');
};
if (typeof template.name === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject2())));
}
if (!(0, _neTypes.extendsFrom)(template.name, String)) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject3())));
}
if (typeof template.schema === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject4())));
}
if (!(0, _neTypes.extendsFrom)(template.schema, String)) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject5())));
}
if (!(0, _neTypes.extendsFrom)(template.resolvers, Object) // Supports 95% of objects
|| (0, _typeof2.default)(template.resolvers) !== 'object' // Supports Object.create(null)
) {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject6())));
}
if (typeof template.docs === 'undefined') {
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject7())));
}
if (!(0, _neTypes.extendsFrom)(template.docs, Object) // Supports 95% of objects
|| (0, _typeof2.default)(template.docs) !== 'object' // Supports Object.create(null)
) {
var dr = '\x1b[31m',
br = '\x1b[91m';
var b1 = '\x1b[1m',
b0 = '\x1b[22m';
var bb = '\x1b[90m';
var dg = '\x1b[37m',
bg = '\x1b[97m';
var a0 = '\x1b[0m';
var gr = '\x1b[32m',
bgr = '\x1b[92m';
results.errors.push(new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject8(), bb, dg, b1, b0, gr, dg, b1, b0, b1, b0, gr, dg, gr, dg, gr, dg, b1, b0, gr, dg, b1, b0, gr, dg)));
}
if (!results.valid) {
var errorStrings = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = results.errors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _error = _step.value;
var message = _error.message,
stack = _error.stack;
stack = stack.trim().split('\n').splice(message.split('\n').length).map(function (s) {
return s.trim();
}).join('\n');
message = message.replace(/(Error:\s)/, '$1\n').trim();
errorStrings.push("\x1B[31;1m".concat(message, "\x1B[0m\n") + indent(stack));
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var error = new Error((0, _neTagFns.customDedent)({
dropLowest: true
})(_templateObject9()).replace(/@template/, indent(_i(template))).replace(/@errors/, errorStrings.join('\n\n')));
error.stack = error.message;
error.message = '';
if (!hide) throw error;
}
return results;
} | [
"function",
"validateTemplate",
"(",
"template",
")",
"{",
"var",
"hide",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"false",
";",
"var",
"results",
"=",
"new",
"ValidationResults",
"(",
")",
";",
"var",
"indent",
"=",
"function",
"indent",
"(",
"string",
")",
"{",
"var",
"count",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"4",
";",
"var",
"space",
"=",
"arguments",
".",
"length",
">",
"2",
"&&",
"arguments",
"[",
"2",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"2",
"]",
":",
"' '",
";",
"return",
"string",
".",
"split",
"(",
"'\\n'",
")",
".",
"\\n",
"map",
".",
"(",
"function",
"(",
"s",
")",
"{",
"return",
"s",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"(^)",
"/",
"gm",
",",
"\"$1\"",
".",
"concat",
"(",
"space",
".",
"repeat",
"(",
"count",
")",
")",
")",
";",
"}",
")",
"join",
";",
"}",
";",
"(",
"'\\n'",
")",
"\\n",
"if",
"(",
"typeof",
"template",
".",
"name",
"===",
"'undefined'",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject2",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"0",
",",
"_neTypes",
".",
"extendsFrom",
")",
"(",
"template",
".",
"name",
",",
"String",
")",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject3",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"template",
".",
"schema",
"===",
"'undefined'",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject4",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"0",
",",
"_neTypes",
".",
"extendsFrom",
")",
"(",
"template",
".",
"schema",
",",
"String",
")",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject5",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"0",
",",
"_neTypes",
".",
"extendsFrom",
")",
"(",
"template",
".",
"resolvers",
",",
"Object",
")",
"||",
"(",
"0",
",",
"_typeof2",
".",
"default",
")",
"(",
"template",
".",
"resolvers",
")",
"!==",
"'object'",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject6",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"typeof",
"template",
".",
"docs",
"===",
"'undefined'",
")",
"{",
"results",
".",
"errors",
".",
"push",
"(",
"new",
"Error",
"(",
"(",
"0",
",",
"_neTagFns",
".",
"customDedent",
")",
"(",
"{",
"dropLowest",
":",
"true",
"}",
")",
"(",
"_templateObject7",
"(",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"(",
"0",
",",
"_neTypes",
".",
"extendsFrom",
")",
"(",
"template",
".",
"docs",
",",
"Object",
")",
"||",
"(",
"0",
",",
"_typeof2",
".",
"default",
")",
"(",
"template",
".",
"docs",
")",
"!==",
"'object'",
")",
"{",
"var",
"dr",
"=",
"'\\x1b[31m'",
",",
"\\x1b",
";",
"br",
"=",
"'\\x1b[91m'",
"\\x1b",
"var",
"b1",
"=",
"'\\x1b[1m'",
",",
"\\x1b",
";",
"b0",
"=",
"'\\x1b[22m'",
"\\x1b",
"var",
"bb",
"=",
"'\\x1b[90m'",
";",
"}",
"}"
] | Walks through a supplied template object and collects errors with its
format before bubbling up an exception if any part of it fails to
pass muster. The exception can be prevented from throwing if hide is set
to true
@param {Object} template an object to be parsed for construction via the
Lattice Factory
@param {boolean} hide if true, an invalid template will NOT throw errors
@return {ValidationResults} a `ValidationResults` object containing the
collected errors and a `valid` that is dynamically calculated. | [
"Walks",
"through",
"a",
"supplied",
"template",
"object",
"and",
"collects",
"errors",
"with",
"its",
"format",
"before",
"bubbling",
"up",
"an",
"exception",
"if",
"any",
"part",
"of",
"it",
"fails",
"to",
"pass",
"muster",
".",
"The",
"exception",
"can",
"be",
"prevented",
"from",
"throwing",
"if",
"hide",
"is",
"set",
"to",
"true"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/LatticeFactory.js#L409-L518 | train |
fourplusone/etherpad-plugins | ep_headings/static/js/index.js | function(hook, context){
var hs = $('#heading-selection');
hs.on('change', function(){
var value = $(this).val();
var intValue = parseInt(value,10);
if(!_.isNaN(intValue)){
context.ace.callWithAce(function(ace){
ace.ace_doInsertHeading(intValue);
},'insertheading' , true);
hs.val("dummy");
}
})
} | javascript | function(hook, context){
var hs = $('#heading-selection');
hs.on('change', function(){
var value = $(this).val();
var intValue = parseInt(value,10);
if(!_.isNaN(intValue)){
context.ace.callWithAce(function(ace){
ace.ace_doInsertHeading(intValue);
},'insertheading' , true);
hs.val("dummy");
}
})
} | [
"function",
"(",
"hook",
",",
"context",
")",
"{",
"var",
"hs",
"=",
"$",
"(",
"'#heading-selection'",
")",
";",
"hs",
".",
"on",
"(",
"'change'",
",",
"function",
"(",
")",
"{",
"var",
"value",
"=",
"$",
"(",
"this",
")",
".",
"val",
"(",
")",
";",
"var",
"intValue",
"=",
"parseInt",
"(",
"value",
",",
"10",
")",
";",
"if",
"(",
"!",
"_",
".",
"isNaN",
"(",
"intValue",
")",
")",
"{",
"context",
".",
"ace",
".",
"callWithAce",
"(",
"function",
"(",
"ace",
")",
"{",
"ace",
".",
"ace_doInsertHeading",
"(",
"intValue",
")",
";",
"}",
",",
"'insertheading'",
",",
"true",
")",
";",
"hs",
".",
"val",
"(",
"\"dummy\"",
")",
";",
"}",
"}",
")",
"}"
] | Bind the event handler to the toolbar buttons | [
"Bind",
"the",
"event",
"handler",
"to",
"the",
"toolbar",
"buttons"
] | f6561a2b2323f8df2d3ef79154527f1ec5adfa56 | https://github.com/fourplusone/etherpad-plugins/blob/f6561a2b2323f8df2d3ef79154527f1ec5adfa56/ep_headings/static/js/index.js#L15-L27 | train |
|
fourplusone/etherpad-plugins | ep_headings/static/js/index.js | aceInitialized | function aceInitialized(hook, context){
var editorInfo = context.editorInfo;
editorInfo.ace_doInsertHeading = _(doInsertHeading).bind(context);
} | javascript | function aceInitialized(hook, context){
var editorInfo = context.editorInfo;
editorInfo.ace_doInsertHeading = _(doInsertHeading).bind(context);
} | [
"function",
"aceInitialized",
"(",
"hook",
",",
"context",
")",
"{",
"var",
"editorInfo",
"=",
"context",
".",
"editorInfo",
";",
"editorInfo",
".",
"ace_doInsertHeading",
"=",
"_",
"(",
"doInsertHeading",
")",
".",
"bind",
"(",
"context",
")",
";",
"}"
] | Once ace is initialized, we set ace_doInsertHeading and bind it to the context | [
"Once",
"ace",
"is",
"initialized",
"we",
"set",
"ace_doInsertHeading",
"and",
"bind",
"it",
"to",
"the",
"context"
] | f6561a2b2323f8df2d3ef79154527f1ec5adfa56 | https://github.com/fourplusone/etherpad-plugins/blob/f6561a2b2323f8df2d3ef79154527f1ec5adfa56/ep_headings/static/js/index.js#L86-L89 | train |
nyteshade/graphql-lattice | dist/utils.js | argMapper | function argMapper(arg, index, array) {
var isError = (0, _neTypes.typeOf)(arg) === Error.name;
var showStack = /\bSTACK\b/i.test(process.env.LATTICE_ERRORS || ''); // $FlowFixMe
return !isError ? arg : showStack ? arg : arg.message;
} | javascript | function argMapper(arg, index, array) {
var isError = (0, _neTypes.typeOf)(arg) === Error.name;
var showStack = /\bSTACK\b/i.test(process.env.LATTICE_ERRORS || ''); // $FlowFixMe
return !isError ? arg : showStack ? arg : arg.message;
} | [
"function",
"argMapper",
"(",
"arg",
",",
"index",
",",
"array",
")",
"{",
"var",
"isError",
"=",
"(",
"0",
",",
"_neTypes",
".",
"typeOf",
")",
"(",
"arg",
")",
"===",
"Error",
".",
"name",
";",
"var",
"showStack",
"=",
"/",
"\\bSTACK\\b",
"/",
"i",
".",
"test",
"(",
"process",
".",
"env",
".",
"LATTICE_ERRORS",
"||",
"''",
")",
";",
"return",
"!",
"isError",
"?",
"arg",
":",
"showStack",
"?",
"arg",
":",
"arg",
".",
"message",
";",
"}"
] | All arguments of any logging function in `LatticeLogs` get passed through
this function first to modify or alter the type of value being logged.
@param {mixed} arg the argument being passed to the `map()` function
@param {number} index the index in the array of arguments
@param {Array<mixed>} array the array containing this element | [
"All",
"arguments",
"of",
"any",
"logging",
"function",
"in",
"LatticeLogs",
"get",
"passed",
"through",
"this",
"function",
"first",
"to",
"modify",
"or",
"alter",
"the",
"type",
"of",
"value",
"being",
"logged",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L351-L356 | train |
nyteshade/graphql-lattice | dist/utils.js | failFast | function failFast(logLevel, lessThan) {
var ll = LatticeLogs;
if (logLevel) {
var compareTo = lessThan || process.env.LATTICE_LOGLEVEL || ll.ERROR;
if (!ll.equalOrBelow(logLevel, compareTo)) return true;
}
return /\b(NONE|OFF|NO|0)\b/i.test(process.env.LATTICE_ERRORS || '');
} | javascript | function failFast(logLevel, lessThan) {
var ll = LatticeLogs;
if (logLevel) {
var compareTo = lessThan || process.env.LATTICE_LOGLEVEL || ll.ERROR;
if (!ll.equalOrBelow(logLevel, compareTo)) return true;
}
return /\b(NONE|OFF|NO|0)\b/i.test(process.env.LATTICE_ERRORS || '');
} | [
"function",
"failFast",
"(",
"logLevel",
",",
"lessThan",
")",
"{",
"var",
"ll",
"=",
"LatticeLogs",
";",
"if",
"(",
"logLevel",
")",
"{",
"var",
"compareTo",
"=",
"lessThan",
"||",
"process",
".",
"env",
".",
"LATTICE_LOGLEVEL",
"||",
"ll",
".",
"ERROR",
";",
"if",
"(",
"!",
"ll",
".",
"equalOrBelow",
"(",
"logLevel",
",",
"compareTo",
")",
")",
"return",
"true",
";",
"}",
"return",
"/",
"\\b(NONE|OFF|NO|0)\\b",
"/",
"i",
".",
"test",
"(",
"process",
".",
"env",
".",
"LATTICE_ERRORS",
"||",
"''",
")",
";",
"}"
] | A function that, when it returns true, will cause logging to be skipped | [
"A",
"function",
"that",
"when",
"it",
"returns",
"true",
"will",
"cause",
"logging",
"to",
"be",
"skipped"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L359-L368 | train |
nyteshade/graphql-lattice | dist/utils.js | log | function log() {
var _console;
if (LatticeLogs.failFast(LatticeLogs.LOG)) return;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
(_console = console).log.apply(_console, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | javascript | function log() {
var _console;
if (LatticeLogs.failFast(LatticeLogs.LOG)) return;
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
(_console = console).log.apply(_console, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | [
"function",
"log",
"(",
")",
"{",
"var",
"_console",
";",
"if",
"(",
"LatticeLogs",
".",
"failFast",
"(",
"LatticeLogs",
".",
"LOG",
")",
")",
"return",
";",
"for",
"(",
"var",
"_len3",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len3",
")",
",",
"_key3",
"=",
"0",
";",
"_key3",
"<",
"_len3",
";",
"_key3",
"++",
")",
"{",
"args",
"[",
"_key3",
"]",
"=",
"arguments",
"[",
"_key3",
"]",
";",
"}",
"(",
"_console",
"=",
"console",
")",
".",
"log",
".",
"apply",
"(",
"_console",
",",
"(",
"0",
",",
"_toConsumableArray2",
".",
"default",
")",
"(",
"args",
".",
"map",
"(",
"LatticeLogs",
".",
"argMapper",
")",
")",
")",
";",
"}"
] | Pass-thru to console.log; arguments parsed via `argMapper` | [
"Pass",
"-",
"thru",
"to",
"console",
".",
"log",
";",
"arguments",
"parsed",
"via",
"argMapper"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L371-L381 | train |
nyteshade/graphql-lattice | dist/utils.js | warn | function warn() {
var _console2;
if (LatticeLogs.failFast(LatticeLogs.WARN)) return;
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
(_console2 = console).warn.apply(_console2, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | javascript | function warn() {
var _console2;
if (LatticeLogs.failFast(LatticeLogs.WARN)) return;
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
(_console2 = console).warn.apply(_console2, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | [
"function",
"warn",
"(",
")",
"{",
"var",
"_console2",
";",
"if",
"(",
"LatticeLogs",
".",
"failFast",
"(",
"LatticeLogs",
".",
"WARN",
")",
")",
"return",
";",
"for",
"(",
"var",
"_len4",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len4",
")",
",",
"_key4",
"=",
"0",
";",
"_key4",
"<",
"_len4",
";",
"_key4",
"++",
")",
"{",
"args",
"[",
"_key4",
"]",
"=",
"arguments",
"[",
"_key4",
"]",
";",
"}",
"(",
"_console2",
"=",
"console",
")",
".",
"warn",
".",
"apply",
"(",
"_console2",
",",
"(",
"0",
",",
"_toConsumableArray2",
".",
"default",
")",
"(",
"args",
".",
"map",
"(",
"LatticeLogs",
".",
"argMapper",
")",
")",
")",
";",
"}"
] | Pass-thru to console.warn; arguments parsed via `argMapper` | [
"Pass",
"-",
"thru",
"to",
"console",
".",
"warn",
";",
"arguments",
"parsed",
"via",
"argMapper"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L384-L394 | train |
nyteshade/graphql-lattice | dist/utils.js | error | function error() {
var _console3;
if (LatticeLogs.failFast(LatticeLogs.ERROR)) return;
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
(_console3 = console).error.apply(_console3, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | javascript | function error() {
var _console3;
if (LatticeLogs.failFast(LatticeLogs.ERROR)) return;
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
(_console3 = console).error.apply(_console3, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | [
"function",
"error",
"(",
")",
"{",
"var",
"_console3",
";",
"if",
"(",
"LatticeLogs",
".",
"failFast",
"(",
"LatticeLogs",
".",
"ERROR",
")",
")",
"return",
";",
"for",
"(",
"var",
"_len5",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len5",
")",
",",
"_key5",
"=",
"0",
";",
"_key5",
"<",
"_len5",
";",
"_key5",
"++",
")",
"{",
"args",
"[",
"_key5",
"]",
"=",
"arguments",
"[",
"_key5",
"]",
";",
"}",
"(",
"_console3",
"=",
"console",
")",
".",
"error",
".",
"apply",
"(",
"_console3",
",",
"(",
"0",
",",
"_toConsumableArray2",
".",
"default",
")",
"(",
"args",
".",
"map",
"(",
"LatticeLogs",
".",
"argMapper",
")",
")",
")",
";",
"}"
] | Pass-thru to console.error; arguments parsed via `argMapper` | [
"Pass",
"-",
"thru",
"to",
"console",
".",
"error",
";",
"arguments",
"parsed",
"via",
"argMapper"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L397-L407 | train |
nyteshade/graphql-lattice | dist/utils.js | info | function info() {
var _console4;
if (LatticeLogs.failFast(LatticeLogs.INFO)) return;
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
(_console4 = console).info.apply(_console4, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | javascript | function info() {
var _console4;
if (LatticeLogs.failFast(LatticeLogs.INFO)) return;
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
(_console4 = console).info.apply(_console4, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | [
"function",
"info",
"(",
")",
"{",
"var",
"_console4",
";",
"if",
"(",
"LatticeLogs",
".",
"failFast",
"(",
"LatticeLogs",
".",
"INFO",
")",
")",
"return",
";",
"for",
"(",
"var",
"_len6",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len6",
")",
",",
"_key6",
"=",
"0",
";",
"_key6",
"<",
"_len6",
";",
"_key6",
"++",
")",
"{",
"args",
"[",
"_key6",
"]",
"=",
"arguments",
"[",
"_key6",
"]",
";",
"}",
"(",
"_console4",
"=",
"console",
")",
".",
"info",
".",
"apply",
"(",
"_console4",
",",
"(",
"0",
",",
"_toConsumableArray2",
".",
"default",
")",
"(",
"args",
".",
"map",
"(",
"LatticeLogs",
".",
"argMapper",
")",
")",
")",
";",
"}"
] | Pass-thru to console.info; arguments parsed via `argMapper` | [
"Pass",
"-",
"thru",
"to",
"console",
".",
"info",
";",
"arguments",
"parsed",
"via",
"argMapper"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L410-L420 | train |
nyteshade/graphql-lattice | dist/utils.js | trace | function trace() {
var _console5;
if (LatticeLogs.failFast(LatticeLogs.TRACE)) return;
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
(_console5 = console).trace.apply(_console5, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | javascript | function trace() {
var _console5;
if (LatticeLogs.failFast(LatticeLogs.TRACE)) return;
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
args[_key7] = arguments[_key7];
}
(_console5 = console).trace.apply(_console5, (0, _toConsumableArray2.default)(args.map(LatticeLogs.argMapper)));
} | [
"function",
"trace",
"(",
")",
"{",
"var",
"_console5",
";",
"if",
"(",
"LatticeLogs",
".",
"failFast",
"(",
"LatticeLogs",
".",
"TRACE",
")",
")",
"return",
";",
"for",
"(",
"var",
"_len7",
"=",
"arguments",
".",
"length",
",",
"args",
"=",
"new",
"Array",
"(",
"_len7",
")",
",",
"_key7",
"=",
"0",
";",
"_key7",
"<",
"_len7",
";",
"_key7",
"++",
")",
"{",
"args",
"[",
"_key7",
"]",
"=",
"arguments",
"[",
"_key7",
"]",
";",
"}",
"(",
"_console5",
"=",
"console",
")",
".",
"trace",
".",
"apply",
"(",
"_console5",
",",
"(",
"0",
",",
"_toConsumableArray2",
".",
"default",
")",
"(",
"args",
".",
"map",
"(",
"LatticeLogs",
".",
"argMapper",
")",
")",
")",
";",
"}"
] | Pass-thru to console.trace; arguments parsed via `argMapper` | [
"Pass",
"-",
"thru",
"to",
"console",
".",
"trace",
";",
"arguments",
"parsed",
"via",
"argMapper"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/utils.js#L423-L433 | train |
nyteshade/graphql-lattice | dist/GQLBase.js | notDefined | function notDefined(keyToTest, keySupplied, instance) {
return new RegExp("^" + keyToTest + "$").test(keySupplied.toString()) && !instance.hasOwnProperty(keyToTest);
} | javascript | function notDefined(keyToTest, keySupplied, instance) {
return new RegExp("^" + keyToTest + "$").test(keySupplied.toString()) && !instance.hasOwnProperty(keyToTest);
} | [
"function",
"notDefined",
"(",
"keyToTest",
",",
"keySupplied",
",",
"instance",
")",
"{",
"return",
"new",
"RegExp",
"(",
"\"^\"",
"+",
"keyToTest",
"+",
"\"$\"",
")",
".",
"test",
"(",
"keySupplied",
".",
"toString",
"(",
")",
")",
"&&",
"!",
"instance",
".",
"hasOwnProperty",
"(",
"keyToTest",
")",
";",
"}"
] | Simple function to check if a supplied key matches a string of your
choosing and that string is not a defined property on the instance
passed to the check.
@method GQLBaseEnv~notDefined
@memberof GQLBaseEnv
@since 2.5.0
@param {string} keyToTest a String denoting the property you wish to test
@param {mixed} keySupplied a value, coerced `toString()`, to compare to
`keyToTest`
@param {mixed} instance an object instance to check `hasOwnProperty` on for
the `keyToTest` supplied.
@return {Boolean} true if the property matches the supplied key and that
property is not an ownedProperty of the instance supplied. | [
"Simple",
"function",
"to",
"check",
"if",
"a",
"supplied",
"key",
"matches",
"a",
"string",
"of",
"your",
"choosing",
"and",
"that",
"string",
"is",
"not",
"a",
"defined",
"property",
"on",
"the",
"instance",
"passed",
"to",
"the",
"check",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/GQLBase.js#L158-L160 | train |
nyteshade/graphql-lattice | dist/GQLBase.js | getProp | function getProp(propName) {
var bindGetters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var bindTo = arguments.length > 2 ? arguments[2] : undefined;
// $FlowFixMe
var proto = Object.getPrototypeOf(this);
var descriptor = Object.getOwnPropertyDescriptor(proto, propName);
var result;
if (!descriptor) {
return null;
}
if (descriptor) {
if (descriptor.initializer || descriptor.get) {
var what = descriptor.initializer || descriptor.get;
if (bindGetters) {
result = what.bind(bindTo || this);
} else {
result = what;
}
} else if (descriptor.value) {
result = descriptor.value;
}
}
return result;
} | javascript | function getProp(propName) {
var bindGetters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var bindTo = arguments.length > 2 ? arguments[2] : undefined;
// $FlowFixMe
var proto = Object.getPrototypeOf(this);
var descriptor = Object.getOwnPropertyDescriptor(proto, propName);
var result;
if (!descriptor) {
return null;
}
if (descriptor) {
if (descriptor.initializer || descriptor.get) {
var what = descriptor.initializer || descriptor.get;
if (bindGetters) {
result = what.bind(bindTo || this);
} else {
result = what;
}
} else if (descriptor.value) {
result = descriptor.value;
}
}
return result;
} | [
"function",
"getProp",
"(",
"propName",
")",
"{",
"var",
"bindGetters",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"true",
";",
"var",
"bindTo",
"=",
"arguments",
".",
"length",
">",
"2",
"?",
"arguments",
"[",
"2",
"]",
":",
"undefined",
";",
"var",
"proto",
"=",
"Object",
".",
"getPrototypeOf",
"(",
"this",
")",
";",
"var",
"descriptor",
"=",
"Object",
".",
"getOwnPropertyDescriptor",
"(",
"proto",
",",
"propName",
")",
";",
"var",
"result",
";",
"if",
"(",
"!",
"descriptor",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"descriptor",
")",
"{",
"if",
"(",
"descriptor",
".",
"initializer",
"||",
"descriptor",
".",
"get",
")",
"{",
"var",
"what",
"=",
"descriptor",
".",
"initializer",
"||",
"descriptor",
".",
"get",
";",
"if",
"(",
"bindGetters",
")",
"{",
"result",
"=",
"what",
".",
"bind",
"(",
"bindTo",
"||",
"this",
")",
";",
"}",
"else",
"{",
"result",
"=",
"what",
";",
"}",
"}",
"else",
"if",
"(",
"descriptor",
".",
"value",
")",
"{",
"result",
"=",
"descriptor",
".",
"value",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Properties defined for GraphQL types in Lattice can be defined as
a getter, a function or an async function. In the case of standard
functions, if they return a promise they will be handled as though
they were async
Given the variety of things a GraphQL type can actually be, obtaining
its value can annoying. This method tends to lessen that boilerplate.
Errors raised will be thrown.
@instance
@memberof GQLBase
@method ⌾⠀getProp
@param {string|Symbol} propName the name of the property in question
@param {boolean} bindGetters true, by default, if the `get` or
`initializer` descriptor values should be bound to the current instance
or an object of the programmers choice before returning
@param {mixed} bindTo the `this` object to use for binding when
`bindGetters` is set to true.
@return {mixed} the value of the `propName` as a Function or something
else when the requested property name exists
@throws {Error} errors raised in awaiting results will be thrown | [
"Properties",
"defined",
"for",
"GraphQL",
"types",
"in",
"Lattice",
"can",
"be",
"defined",
"as",
"a",
"getter",
"a",
"function",
"or",
"an",
"async",
"function",
".",
"In",
"the",
"case",
"of",
"standard",
"functions",
"if",
"they",
"return",
"a",
"promise",
"they",
"will",
"be",
"handled",
"as",
"though",
"they",
"were",
"async"
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/GQLBase.js#L495-L522 | train |
nyteshade/graphql-lattice | dist/GQLBase.js | IDLFilePath | function IDLFilePath(path) {
var extension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.graphql';
return Symbol.for("Path ".concat(path, " Extension ").concat(extension));
} | javascript | function IDLFilePath(path) {
var extension = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '.graphql';
return Symbol.for("Path ".concat(path, " Extension ").concat(extension));
} | [
"function",
"IDLFilePath",
"(",
"path",
")",
"{",
"var",
"extension",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"'.graphql'",
";",
"return",
"Symbol",
".",
"for",
"(",
"\"Path \"",
".",
"concat",
"(",
"path",
",",
"\" Extension \"",
")",
".",
"concat",
"(",
"extension",
")",
")",
";",
"}"
] | Creates an appropriate Symbol crafted with the right data for use by
the IDLFileHandler class below.
@static
@memberof GQLBase
@method ⌾⠀IDLFilePath
@param {string} path a path to the IDL containing file
@param {string} [extension='.graphql'] an extension, including the
prefixed period, that will be added to the supplied path should it not
already exist.
@return Symbol
@see {@link GQLBase#SCHEMA} | [
"Creates",
"an",
"appropriate",
"Symbol",
"crafted",
"with",
"the",
"right",
"data",
"for",
"use",
"by",
"the",
"IDLFileHandler",
"class",
"below",
"."
] | c95aba71e769eac2c900a4a578109a42e385342a | https://github.com/nyteshade/graphql-lattice/blob/c95aba71e769eac2c900a4a578109a42e385342a/dist/GQLBase.js#L1042-L1045 | train |
jacobrask/eslint-plugin-sorting | lib/rules/sort-object-props.js | nodeToString | function nodeToString(node) {
switch (node.type) {
case ("BinaryExpression"): {
return nodeToString(node.left) + node.operator.toString() + nodeToString(node.right);
}
case ("CallExpression"): {
var args = node.arguments.map(function(arg) {
return nodeToString(arg);
}).toString();
return nodeToString(node.callee) + "(" + args + ")";
}
case ("ConditionalExpression"): {
return nodeToString(node.test) + "?" + nodeToString(node.consequent) + ":" + nodeToString(node.alternate);
}
case ("Identifier"): {
return node.name.toString();
}
case ("Literal"): {
return node.value.toString();
}
case ("MemberExpression"): {
return nodeToString(node.object) + "[" + nodeToString(node.property) + "]";
}
case ("TemplateElement"): {
return node.value.raw.toString();
}
case ("TemplateLiteral"): {
// interleave quasis with expressions
var s = [];
node.quasis.forEach(function(quasi, i) {
if (quasi.value.raw) {
s.push(nodeToString(quasi));
}
var expression = node.expressions[i];
if (expression) {
s.push(nodeToString(expression));
}
});
return s.join("");
}
default: {
// Silently ignore Nodes with types we don't handle
return "";
}
}
} | javascript | function nodeToString(node) {
switch (node.type) {
case ("BinaryExpression"): {
return nodeToString(node.left) + node.operator.toString() + nodeToString(node.right);
}
case ("CallExpression"): {
var args = node.arguments.map(function(arg) {
return nodeToString(arg);
}).toString();
return nodeToString(node.callee) + "(" + args + ")";
}
case ("ConditionalExpression"): {
return nodeToString(node.test) + "?" + nodeToString(node.consequent) + ":" + nodeToString(node.alternate);
}
case ("Identifier"): {
return node.name.toString();
}
case ("Literal"): {
return node.value.toString();
}
case ("MemberExpression"): {
return nodeToString(node.object) + "[" + nodeToString(node.property) + "]";
}
case ("TemplateElement"): {
return node.value.raw.toString();
}
case ("TemplateLiteral"): {
// interleave quasis with expressions
var s = [];
node.quasis.forEach(function(quasi, i) {
if (quasi.value.raw) {
s.push(nodeToString(quasi));
}
var expression = node.expressions[i];
if (expression) {
s.push(nodeToString(expression));
}
});
return s.join("");
}
default: {
// Silently ignore Nodes with types we don't handle
return "";
}
}
} | [
"function",
"nodeToString",
"(",
"node",
")",
"{",
"switch",
"(",
"node",
".",
"type",
")",
"{",
"case",
"(",
"\"BinaryExpression\"",
")",
":",
"{",
"return",
"nodeToString",
"(",
"node",
".",
"left",
")",
"+",
"node",
".",
"operator",
".",
"toString",
"(",
")",
"+",
"nodeToString",
"(",
"node",
".",
"right",
")",
";",
"}",
"case",
"(",
"\"CallExpression\"",
")",
":",
"{",
"var",
"args",
"=",
"node",
".",
"arguments",
".",
"map",
"(",
"function",
"(",
"arg",
")",
"{",
"return",
"nodeToString",
"(",
"arg",
")",
";",
"}",
")",
".",
"toString",
"(",
")",
";",
"return",
"nodeToString",
"(",
"node",
".",
"callee",
")",
"+",
"\"(\"",
"+",
"args",
"+",
"\")\"",
";",
"}",
"case",
"(",
"\"ConditionalExpression\"",
")",
":",
"{",
"return",
"nodeToString",
"(",
"node",
".",
"test",
")",
"+",
"\"?\"",
"+",
"nodeToString",
"(",
"node",
".",
"consequent",
")",
"+",
"\":\"",
"+",
"nodeToString",
"(",
"node",
".",
"alternate",
")",
";",
"}",
"case",
"(",
"\"Identifier\"",
")",
":",
"{",
"return",
"node",
".",
"name",
".",
"toString",
"(",
")",
";",
"}",
"case",
"(",
"\"Literal\"",
")",
":",
"{",
"return",
"node",
".",
"value",
".",
"toString",
"(",
")",
";",
"}",
"case",
"(",
"\"MemberExpression\"",
")",
":",
"{",
"return",
"nodeToString",
"(",
"node",
".",
"object",
")",
"+",
"\"[\"",
"+",
"nodeToString",
"(",
"node",
".",
"property",
")",
"+",
"\"]\"",
";",
"}",
"case",
"(",
"\"TemplateElement\"",
")",
":",
"{",
"return",
"node",
".",
"value",
".",
"raw",
".",
"toString",
"(",
")",
";",
"}",
"case",
"(",
"\"TemplateLiteral\"",
")",
":",
"{",
"var",
"s",
"=",
"[",
"]",
";",
"node",
".",
"quasis",
".",
"forEach",
"(",
"function",
"(",
"quasi",
",",
"i",
")",
"{",
"if",
"(",
"quasi",
".",
"value",
".",
"raw",
")",
"{",
"s",
".",
"push",
"(",
"nodeToString",
"(",
"quasi",
")",
")",
";",
"}",
"var",
"expression",
"=",
"node",
".",
"expressions",
"[",
"i",
"]",
";",
"if",
"(",
"expression",
")",
"{",
"s",
".",
"push",
"(",
"nodeToString",
"(",
"expression",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"s",
".",
"join",
"(",
"\"\"",
")",
";",
"}",
"default",
":",
"{",
"return",
"\"\"",
";",
"}",
"}",
"}"
] | Recursively converts Nodes to strings so they can be sorted
@param {Node} node: Babel AST Node
@returns {String} Node value as a string | [
"Recursively",
"converts",
"Nodes",
"to",
"strings",
"so",
"they",
"can",
"be",
"sorted"
] | ea30e0011bad0768b16f70e3526db93e119b5eaa | https://github.com/jacobrask/eslint-plugin-sorting/blob/ea30e0011bad0768b16f70e3526db93e119b5eaa/lib/rules/sort-object-props.js#L10-L55 | train |
gl-vis/gl-streamtube3d | streamtube.js | function(positions) {
var xs = [], ys = [], zs = [];
var xi = {}, yi = {}, zi = {};
for (var i=0; i<positions.length; i++) {
var p = positions[i];
var x = p[0], y = p[1], z = p[2];
// Split the positions array into arrays of unique component values.
//
// Why go through the trouble of using a uniqueness hash table vs
// sort and uniq:
//
// Suppose you've got a million positions in a 100x100x100 grid.
//
// Using a uniqueness hash table, you're doing 1M array reads,
// 3M hash table lookups from 100-element hashes, 300 hash table inserts, then
// sorting three 100-element arrays and iterating over them.
// Roughly, 1M + 3M * ln(100) + 300 * ln(100/2) + 3 * 100 * ln(100) + 3 * 100 =
// 1M + 13.8M + 0.0012M + 0.0014M + 0.0003M
// =~ 15M
//
// Sort and uniq solution would do 1M array reads, 3M array inserts,
// sort three 1M-element arrays and iterate over them.
// Roughly, 1M + 3M + 3 * 1M * ln(1M) + 3 * 1M =
// 1M + 3M + 41.4M + 3M
// =~ 48.4M
//
// Guessing that a hard-coded sort & uniq would be faster due to not having
// to run a hashing function on everything. More memory usage though
// (bunch of small hash tables vs. duplicating the input array.)
//
// In JS-land, who knows. Maybe xi[x] casts x to string and destroys perf,
// maybe numeric keys get special-cased, maybe the object lookups run at near O(1)-speeds.
// Maybe the sorting comparison function is expensive to call, maybe it gets inlined or special-cased.
//
// ... You're probably not going to call this with more than 10k positions anyhow, so this is very academic.
//
if (!xi[x]) {
xs.push(x);
xi[x] = true;
}
if (!yi[y]) {
ys.push(y);
yi[y] = true;
}
if (!zi[z]) {
zs.push(z);
zi[z] = true;
}
}
var xSep = findMinSeparation(xs);
var ySep = findMinSeparation(ys);
var zSep = findMinSeparation(zs);
var minSeparation = Math.min(xSep, ySep, zSep);
if (!isFinite(minSeparation)) {
return 1;
}
return minSeparation;
} | javascript | function(positions) {
var xs = [], ys = [], zs = [];
var xi = {}, yi = {}, zi = {};
for (var i=0; i<positions.length; i++) {
var p = positions[i];
var x = p[0], y = p[1], z = p[2];
// Split the positions array into arrays of unique component values.
//
// Why go through the trouble of using a uniqueness hash table vs
// sort and uniq:
//
// Suppose you've got a million positions in a 100x100x100 grid.
//
// Using a uniqueness hash table, you're doing 1M array reads,
// 3M hash table lookups from 100-element hashes, 300 hash table inserts, then
// sorting three 100-element arrays and iterating over them.
// Roughly, 1M + 3M * ln(100) + 300 * ln(100/2) + 3 * 100 * ln(100) + 3 * 100 =
// 1M + 13.8M + 0.0012M + 0.0014M + 0.0003M
// =~ 15M
//
// Sort and uniq solution would do 1M array reads, 3M array inserts,
// sort three 1M-element arrays and iterate over them.
// Roughly, 1M + 3M + 3 * 1M * ln(1M) + 3 * 1M =
// 1M + 3M + 41.4M + 3M
// =~ 48.4M
//
// Guessing that a hard-coded sort & uniq would be faster due to not having
// to run a hashing function on everything. More memory usage though
// (bunch of small hash tables vs. duplicating the input array.)
//
// In JS-land, who knows. Maybe xi[x] casts x to string and destroys perf,
// maybe numeric keys get special-cased, maybe the object lookups run at near O(1)-speeds.
// Maybe the sorting comparison function is expensive to call, maybe it gets inlined or special-cased.
//
// ... You're probably not going to call this with more than 10k positions anyhow, so this is very academic.
//
if (!xi[x]) {
xs.push(x);
xi[x] = true;
}
if (!yi[y]) {
ys.push(y);
yi[y] = true;
}
if (!zi[z]) {
zs.push(z);
zi[z] = true;
}
}
var xSep = findMinSeparation(xs);
var ySep = findMinSeparation(ys);
var zSep = findMinSeparation(zs);
var minSeparation = Math.min(xSep, ySep, zSep);
if (!isFinite(minSeparation)) {
return 1;
}
return minSeparation;
} | [
"function",
"(",
"positions",
")",
"{",
"var",
"xs",
"=",
"[",
"]",
",",
"ys",
"=",
"[",
"]",
",",
"zs",
"=",
"[",
"]",
";",
"var",
"xi",
"=",
"{",
"}",
",",
"yi",
"=",
"{",
"}",
",",
"zi",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"positions",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"p",
"=",
"positions",
"[",
"i",
"]",
";",
"var",
"x",
"=",
"p",
"[",
"0",
"]",
",",
"y",
"=",
"p",
"[",
"1",
"]",
",",
"z",
"=",
"p",
"[",
"2",
"]",
";",
"if",
"(",
"!",
"xi",
"[",
"x",
"]",
")",
"{",
"xs",
".",
"push",
"(",
"x",
")",
";",
"xi",
"[",
"x",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"yi",
"[",
"y",
"]",
")",
"{",
"ys",
".",
"push",
"(",
"y",
")",
";",
"yi",
"[",
"y",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"zi",
"[",
"z",
"]",
")",
"{",
"zs",
".",
"push",
"(",
"z",
")",
";",
"zi",
"[",
"z",
"]",
"=",
"true",
";",
"}",
"}",
"var",
"xSep",
"=",
"findMinSeparation",
"(",
"xs",
")",
";",
"var",
"ySep",
"=",
"findMinSeparation",
"(",
"ys",
")",
";",
"var",
"zSep",
"=",
"findMinSeparation",
"(",
"zs",
")",
";",
"var",
"minSeparation",
"=",
"Math",
".",
"min",
"(",
"xSep",
",",
"ySep",
",",
"zSep",
")",
";",
"if",
"(",
"!",
"isFinite",
"(",
"minSeparation",
")",
")",
"{",
"return",
"1",
";",
"}",
"return",
"minSeparation",
";",
"}"
] | Finds the minimum per-component distance in positions. | [
"Finds",
"the",
"minimum",
"per",
"-",
"component",
"distance",
"in",
"positions",
"."
] | e07fe532d22e6c9c45f60e318f6f38e116a60952 | https://github.com/gl-vis/gl-streamtube3d/blob/e07fe532d22e6c9c45f60e318f6f38e116a60952/streamtube.js#L301-L359 | train |
|
emilbayes/noise-protocol | symmetric-state.js | encryptAndHash | function encryptAndHash (state, ciphertext, plaintext) {
assert(state.byteLength === STATELEN)
assert(ciphertext.byteLength != null)
assert(plaintext.byteLength != null)
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END)
var h = state.subarray(HASH_BEGIN, HASH_END)
cipherState.encryptWithAd(cstate, ciphertext, h, plaintext)
encryptAndHash.bytesRead = cipherState.encryptWithAd.bytesRead
encryptAndHash.bytesWritten = cipherState.encryptWithAd.bytesWritten
mixHash(state, ciphertext.subarray(0, encryptAndHash.bytesWritten))
} | javascript | function encryptAndHash (state, ciphertext, plaintext) {
assert(state.byteLength === STATELEN)
assert(ciphertext.byteLength != null)
assert(plaintext.byteLength != null)
var cstate = state.subarray(CIPHER_BEGIN, CIPHER_END)
var h = state.subarray(HASH_BEGIN, HASH_END)
cipherState.encryptWithAd(cstate, ciphertext, h, plaintext)
encryptAndHash.bytesRead = cipherState.encryptWithAd.bytesRead
encryptAndHash.bytesWritten = cipherState.encryptWithAd.bytesWritten
mixHash(state, ciphertext.subarray(0, encryptAndHash.bytesWritten))
} | [
"function",
"encryptAndHash",
"(",
"state",
",",
"ciphertext",
",",
"plaintext",
")",
"{",
"assert",
"(",
"state",
".",
"byteLength",
"===",
"STATELEN",
")",
"assert",
"(",
"ciphertext",
".",
"byteLength",
"!=",
"null",
")",
"assert",
"(",
"plaintext",
".",
"byteLength",
"!=",
"null",
")",
"var",
"cstate",
"=",
"state",
".",
"subarray",
"(",
"CIPHER_BEGIN",
",",
"CIPHER_END",
")",
"var",
"h",
"=",
"state",
".",
"subarray",
"(",
"HASH_BEGIN",
",",
"HASH_END",
")",
"cipherState",
".",
"encryptWithAd",
"(",
"cstate",
",",
"ciphertext",
",",
"h",
",",
"plaintext",
")",
"encryptAndHash",
".",
"bytesRead",
"=",
"cipherState",
".",
"encryptWithAd",
".",
"bytesRead",
"encryptAndHash",
".",
"bytesWritten",
"=",
"cipherState",
".",
"encryptWithAd",
".",
"bytesWritten",
"mixHash",
"(",
"state",
",",
"ciphertext",
".",
"subarray",
"(",
"0",
",",
"encryptAndHash",
".",
"bytesWritten",
")",
")",
"}"
] | ciphertext is the output here | [
"ciphertext",
"is",
"the",
"output",
"here"
] | ad2f08fd09af1eb55433b9d34f71a85979cbbe9d | https://github.com/emilbayes/noise-protocol/blob/ad2f08fd09af1eb55433b9d34f71a85979cbbe9d/symmetric-state.js#L97-L109 | train |
rocjs/extensions | examples/web-app-react/complex/src/components/main/index.js | mapStateToProps | function mapStateToProps(state) {
return {
clicker: state.clicker,
repoUser: state.repoUser,
repositories: state.repositories,
errors: state.errors
};
} | javascript | function mapStateToProps(state) {
return {
clicker: state.clicker,
repoUser: state.repoUser,
repositories: state.repositories,
errors: state.errors
};
} | [
"function",
"mapStateToProps",
"(",
"state",
")",
"{",
"return",
"{",
"clicker",
":",
"state",
".",
"clicker",
",",
"repoUser",
":",
"state",
".",
"repoUser",
",",
"repositories",
":",
"state",
".",
"repositories",
",",
"errors",
":",
"state",
".",
"errors",
"}",
";",
"}"
] | this maps values from redux store to props of this component | [
"this",
"maps",
"values",
"from",
"redux",
"store",
"to",
"props",
"of",
"this",
"component"
] | e9c364768c4edd30b789b94c51d20778d903d063 | https://github.com/rocjs/extensions/blob/e9c364768c4edd30b789b94c51d20778d903d063/examples/web-app-react/complex/src/components/main/index.js#L29-L36 | train |
CoinifySoftware/node-currency | src/index.js | computeRateBetweenSubunitAmounts | function computeRateBetweenSubunitAmounts(fromCurrency, fromAmount, toCurrency, toAmount) {
/*
* If currencies are equal, rate is 1
*/
if (fromCurrency === toCurrency) {
return 1;
}
/*
* If toAmount is 0, we don't want to divide by zero.
* In this case, return NaN
*/
if (toAmount === 0) {
return NaN;
}
/*
* Convert both amounts to main units
*/
const fromAmountMainUnit = fromSmallestSubunit(fromAmount, fromCurrency);
const toAmountMainUnit = fromSmallestSubunit(toAmount, toCurrency);
/*
* Compute and return rate
*/
return fromAmountMainUnit / toAmountMainUnit;
} | javascript | function computeRateBetweenSubunitAmounts(fromCurrency, fromAmount, toCurrency, toAmount) {
/*
* If currencies are equal, rate is 1
*/
if (fromCurrency === toCurrency) {
return 1;
}
/*
* If toAmount is 0, we don't want to divide by zero.
* In this case, return NaN
*/
if (toAmount === 0) {
return NaN;
}
/*
* Convert both amounts to main units
*/
const fromAmountMainUnit = fromSmallestSubunit(fromAmount, fromCurrency);
const toAmountMainUnit = fromSmallestSubunit(toAmount, toCurrency);
/*
* Compute and return rate
*/
return fromAmountMainUnit / toAmountMainUnit;
} | [
"function",
"computeRateBetweenSubunitAmounts",
"(",
"fromCurrency",
",",
"fromAmount",
",",
"toCurrency",
",",
"toAmount",
")",
"{",
"if",
"(",
"fromCurrency",
"===",
"toCurrency",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"toAmount",
"===",
"0",
")",
"{",
"return",
"NaN",
";",
"}",
"const",
"fromAmountMainUnit",
"=",
"fromSmallestSubunit",
"(",
"fromAmount",
",",
"fromCurrency",
")",
";",
"const",
"toAmountMainUnit",
"=",
"fromSmallestSubunit",
"(",
"toAmount",
",",
"toCurrency",
")",
";",
"return",
"fromAmountMainUnit",
"/",
"toAmountMainUnit",
";",
"}"
] | Computes a rate between two amounts in two different currencies.
The result is fromAmount / toAmount (in the main units of their respective currencies)
@param {string} fromCurrency
@param {int} fromAmount Amount denominated in smallest sub-unit of fromCurrency
@param {string} toCurrency
@param {int} toAmount Amount denominated in smallest sub-unit of toCurrency | [
"Computes",
"a",
"rate",
"between",
"two",
"amounts",
"in",
"two",
"different",
"currencies",
"."
] | d4e84e34da0bcdc922a2696387bf6cc30b6791c9 | https://github.com/CoinifySoftware/node-currency/blob/d4e84e34da0bcdc922a2696387bf6cc30b6791c9/src/index.js#L86-L112 | train |
canjs/can-view-scope | can-view-scope.js | function(context, keys){
// If nothing can be found with the keys we are looking for, save the
// first possible match. This is where we will write to.
if(firstSearchedContext === undefined && !(context instanceof LetContext)) {
firstSearchedContext = context;
}
// If we have multiple keys ...
if(keys.length > 1) {
// see if we can find the parent ...
var parentKeys = keys.slice(0, keys.length-1);
var parent = stacheKey.read(context, parentKeys, options).value;
// If there is a parent, see if it has the last key
if( parent != null && canReflect.hasKey(parent, keys[keys.length-1].key ) ) {
return {
parent: parent,
parentHasKey: true,
value: undefined
};
} else {
return {};
}
}
// If we have only one key, try to find a context with this key
else if(keys.length === 1) {
if( canReflect.hasKey(context, keys[0].key ) ) {
return {
parent: context,
parentHasKey: true,
value: undefined
};
} else {
return {};
}
}
// If we have no keys, we are reading `this`.
else {
return {
value: context
};
}
} | javascript | function(context, keys){
// If nothing can be found with the keys we are looking for, save the
// first possible match. This is where we will write to.
if(firstSearchedContext === undefined && !(context instanceof LetContext)) {
firstSearchedContext = context;
}
// If we have multiple keys ...
if(keys.length > 1) {
// see if we can find the parent ...
var parentKeys = keys.slice(0, keys.length-1);
var parent = stacheKey.read(context, parentKeys, options).value;
// If there is a parent, see if it has the last key
if( parent != null && canReflect.hasKey(parent, keys[keys.length-1].key ) ) {
return {
parent: parent,
parentHasKey: true,
value: undefined
};
} else {
return {};
}
}
// If we have only one key, try to find a context with this key
else if(keys.length === 1) {
if( canReflect.hasKey(context, keys[0].key ) ) {
return {
parent: context,
parentHasKey: true,
value: undefined
};
} else {
return {};
}
}
// If we have no keys, we are reading `this`.
else {
return {
value: context
};
}
} | [
"function",
"(",
"context",
",",
"keys",
")",
"{",
"if",
"(",
"firstSearchedContext",
"===",
"undefined",
"&&",
"!",
"(",
"context",
"instanceof",
"LetContext",
")",
")",
"{",
"firstSearchedContext",
"=",
"context",
";",
"}",
"if",
"(",
"keys",
".",
"length",
">",
"1",
")",
"{",
"var",
"parentKeys",
"=",
"keys",
".",
"slice",
"(",
"0",
",",
"keys",
".",
"length",
"-",
"1",
")",
";",
"var",
"parent",
"=",
"stacheKey",
".",
"read",
"(",
"context",
",",
"parentKeys",
",",
"options",
")",
".",
"value",
";",
"if",
"(",
"parent",
"!=",
"null",
"&&",
"canReflect",
".",
"hasKey",
"(",
"parent",
",",
"keys",
"[",
"keys",
".",
"length",
"-",
"1",
"]",
".",
"key",
")",
")",
"{",
"return",
"{",
"parent",
":",
"parent",
",",
"parentHasKey",
":",
"true",
",",
"value",
":",
"undefined",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"}",
";",
"}",
"}",
"else",
"if",
"(",
"keys",
".",
"length",
"===",
"1",
")",
"{",
"if",
"(",
"canReflect",
".",
"hasKey",
"(",
"context",
",",
"keys",
"[",
"0",
"]",
".",
"key",
")",
")",
"{",
"return",
"{",
"parent",
":",
"context",
",",
"parentHasKey",
":",
"true",
",",
"value",
":",
"undefined",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"}",
";",
"}",
"}",
"else",
"{",
"return",
"{",
"value",
":",
"context",
"}",
";",
"}",
"}"
] | This read is used by `._walk` to read from the scope. This will use `hasKey` on the last property instead of reading it. | [
"This",
"read",
"is",
"used",
"by",
".",
"_walk",
"to",
"read",
"from",
"the",
"scope",
".",
"This",
"will",
"use",
"hasKey",
"on",
"the",
"last",
"property",
"instead",
"of",
"reading",
"it",
"."
] | 5f6f517bc7de8726331872480c369fe6d27392c9 | https://github.com/canjs/can-view-scope/blob/5f6f517bc7de8726331872480c369fe6d27392c9/can-view-scope.js#L528-L570 | train |
|
canjs/can-view-scope | can-view-scope.js | function() {
var top;
this.getScope(function(scope) {
if (scope._meta.viewModel) {
top = scope;
}
// walk entire scope tree
return false;
});
return top && top._context;
} | javascript | function() {
var top;
this.getScope(function(scope) {
if (scope._meta.viewModel) {
top = scope;
}
// walk entire scope tree
return false;
});
return top && top._context;
} | [
"function",
"(",
")",
"{",
"var",
"top",
";",
"this",
".",
"getScope",
"(",
"function",
"(",
"scope",
")",
"{",
"if",
"(",
"scope",
".",
"_meta",
".",
"viewModel",
")",
"{",
"top",
"=",
"scope",
";",
"}",
"return",
"false",
";",
"}",
")",
";",
"return",
"top",
"&&",
"top",
".",
"_context",
";",
"}"
] | _top_ viewModel scope | [
"_top_",
"viewModel",
"scope"
] | 5f6f517bc7de8726331872480c369fe6d27392c9 | https://github.com/canjs/can-view-scope/blob/5f6f517bc7de8726331872480c369fe6d27392c9/can-view-scope.js#L749-L762 | train |
|
Rekord/rekord | build/rekord.js | toArray | function toArray(x, delimiter)
{
if ( x instanceof Array )
{
return x;
}
if ( isString( x ) )
{
return x.split( delimiter );
}
if ( isValue( x ) )
{
return [ x ];
}
return [];
} | javascript | function toArray(x, delimiter)
{
if ( x instanceof Array )
{
return x;
}
if ( isString( x ) )
{
return x.split( delimiter );
}
if ( isValue( x ) )
{
return [ x ];
}
return [];
} | [
"function",
"toArray",
"(",
"x",
",",
"delimiter",
")",
"{",
"if",
"(",
"x",
"instanceof",
"Array",
")",
"{",
"return",
"x",
";",
"}",
"if",
"(",
"isString",
"(",
"x",
")",
")",
"{",
"return",
"x",
".",
"split",
"(",
"delimiter",
")",
";",
"}",
"if",
"(",
"isValue",
"(",
"x",
")",
")",
"{",
"return",
"[",
"x",
"]",
";",
"}",
"return",
"[",
"]",
";",
"}"
] | Converts the given variable to an array of strings. If the variable is a
string it is split based on the delimiter given. If the variable is an
array then it is returned. If the variable is any other type it may result
in an error.
```javascript
Rekord.toArray([1, 2, 3]); // [1, 2, 3]
Rekord.toArray('1,2,3', ','); // ['1', '2', '3']
Rekord.toArray(1); // [1]
Rekord.toArray(null); // []
```
@memberof Rekord
@param {String|String[]} x
The variable to convert to an Array.
@param {String} [delimiter]
The delimiter to split if the given variable is a string.
@return {String[]} -
The array of strings created. | [
"Converts",
"the",
"given",
"variable",
"to",
"an",
"array",
"of",
"strings",
".",
"If",
"the",
"variable",
"is",
"a",
"string",
"it",
"is",
"split",
"based",
"on",
"the",
"delimiter",
"given",
".",
"If",
"the",
"variable",
"is",
"an",
"array",
"then",
"it",
"is",
"returned",
".",
"If",
"the",
"variable",
"is",
"any",
"other",
"type",
"it",
"may",
"result",
"in",
"an",
"error",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L53-L69 | train |
Rekord/rekord | build/rekord.js | indexOf | function indexOf(arr, x, comparator)
{
var cmp = comparator || equalsStrict;
for (var i = 0, n = arr.length; i < n; i++)
{
if ( cmp( arr[i], x ) )
{
return i;
}
}
return false;
} | javascript | function indexOf(arr, x, comparator)
{
var cmp = comparator || equalsStrict;
for (var i = 0, n = arr.length; i < n; i++)
{
if ( cmp( arr[i], x ) )
{
return i;
}
}
return false;
} | [
"function",
"indexOf",
"(",
"arr",
",",
"x",
",",
"comparator",
")",
"{",
"var",
"cmp",
"=",
"comparator",
"||",
"equalsStrict",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"n",
"=",
"arr",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cmp",
"(",
"arr",
"[",
"i",
"]",
",",
"x",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Finds the index of a variable in an array optionally using a custom
comparison function. If the variable is not found in the array then `false`
is returned.
```javascript
Rekord.indexOf([1, 2, 3], 1); // 0
Rekord.indexOf([1, 2, 3], 4); // false
Rekord.indexOf([1, 2, 2], 2); // 1
```
@memberof Rekord
@param {Array} arr
The array to search through.
@param {Any} x
The variable to search for.
@param {Function} [comparator]
The function to use which compares two values and returns a truthy
value if they are considered equivalent. If a comparator is not given
then strict comparison is used to determine equivalence.
@return {Number|Boolean} -
The index in the array the variable exists at, otherwise false if
the variable wasn't found in the array. | [
"Finds",
"the",
"index",
"of",
"a",
"variable",
"in",
"an",
"array",
"optionally",
"using",
"a",
"custom",
"comparison",
"function",
".",
"If",
"the",
"variable",
"is",
"not",
"found",
"in",
"the",
"array",
"then",
"false",
"is",
"returned",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L96-L109 | train |
Rekord/rekord | build/rekord.js | isRekord | function isRekord(x)
{
return !!(x && x.Database && isFunction( x ) && x.prototype instanceof Model);
} | javascript | function isRekord(x)
{
return !!(x && x.Database && isFunction( x ) && x.prototype instanceof Model);
} | [
"function",
"isRekord",
"(",
"x",
")",
"{",
"return",
"!",
"!",
"(",
"x",
"&&",
"x",
".",
"Database",
"&&",
"isFunction",
"(",
"x",
")",
"&&",
"x",
".",
"prototype",
"instanceof",
"Model",
")",
";",
"}"
] | Determines whether the given variable is a Rekord object. A Rekord object is a
constructor for a model and also has a Database variable. A Rekord object is
strictly created by the Rekord function.
```javascript
var Task = Rekord({
name: 'task',
fields: ['name', 'done', 'finished_at', 'created_at', 'assigned_to']
});
Rekord.isRekord( Task ); // true
```
@memberof Rekord
@param {Any} x
The variable to test.
@return {Boolean} -
True if the variable is a Rekord object, otherwise false. | [
"Determines",
"whether",
"the",
"given",
"variable",
"is",
"a",
"Rekord",
"object",
".",
"A",
"Rekord",
"object",
"is",
"a",
"constructor",
"for",
"a",
"model",
"and",
"also",
"has",
"a",
"Database",
"variable",
".",
"A",
"Rekord",
"object",
"is",
"strictly",
"created",
"by",
"the",
"Rekord",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L460-L463 | train |
Rekord/rekord | build/rekord.js | createComparator | function createComparator(comparator, nullsFirst)
{
if ( isFunction( comparator ) )
{
return comparator;
}
else if ( isString( comparator ) )
{
if ( comparator in Comparators )
{
return Comparators[ comparator ];
}
if ( comparator.charAt(0) === '-' )
{
var parsed = createComparator( comparator.substring( 1 ), !nullsFirst );
return function compareObjectsReversed(a, b)
{
return -parsed( a, b );
};
}
else if ( isFormatInput( comparator ) )
{
var formatter = createFormatter( comparator );
return function compareFormatted(a, b)
{
var af = formatter( a );
var bf = formatter( b );
return af.localeCompare( bf );
};
}
else if ( isParseInput( comparator ) )
{
var parser = createParser( comparator );
return function compareExpression(a, b)
{
var ap = parser( a );
var bp = parser( b );
return compare( ap, bp, nullsFirst );
};
}
else
{
return function compareObjects(a, b)
{
var av = isValue( a ) ? a[ comparator ] : a;
var bv = isValue( b ) ? b[ comparator ] : b;
return compare( av, bv, nullsFirst );
};
}
}
else if ( isArray( comparator ) )
{
var parsedChain = [];
for (var i = 0; i < comparator.length; i++)
{
parsedChain[ i ] = createComparator( comparator[ i ], nullsFirst );
}
return function compareObjectsCascade(a, b)
{
var d = 0;
for (var i = 0; i < parsedChain.length && d === 0; i++)
{
d = parsedChain[ i ]( a, b );
}
return d;
};
}
return null;
} | javascript | function createComparator(comparator, nullsFirst)
{
if ( isFunction( comparator ) )
{
return comparator;
}
else if ( isString( comparator ) )
{
if ( comparator in Comparators )
{
return Comparators[ comparator ];
}
if ( comparator.charAt(0) === '-' )
{
var parsed = createComparator( comparator.substring( 1 ), !nullsFirst );
return function compareObjectsReversed(a, b)
{
return -parsed( a, b );
};
}
else if ( isFormatInput( comparator ) )
{
var formatter = createFormatter( comparator );
return function compareFormatted(a, b)
{
var af = formatter( a );
var bf = formatter( b );
return af.localeCompare( bf );
};
}
else if ( isParseInput( comparator ) )
{
var parser = createParser( comparator );
return function compareExpression(a, b)
{
var ap = parser( a );
var bp = parser( b );
return compare( ap, bp, nullsFirst );
};
}
else
{
return function compareObjects(a, b)
{
var av = isValue( a ) ? a[ comparator ] : a;
var bv = isValue( b ) ? b[ comparator ] : b;
return compare( av, bv, nullsFirst );
};
}
}
else if ( isArray( comparator ) )
{
var parsedChain = [];
for (var i = 0; i < comparator.length; i++)
{
parsedChain[ i ] = createComparator( comparator[ i ], nullsFirst );
}
return function compareObjectsCascade(a, b)
{
var d = 0;
for (var i = 0; i < parsedChain.length && d === 0; i++)
{
d = parsedChain[ i ]( a, b );
}
return d;
};
}
return null;
} | [
"function",
"createComparator",
"(",
"comparator",
",",
"nullsFirst",
")",
"{",
"if",
"(",
"isFunction",
"(",
"comparator",
")",
")",
"{",
"return",
"comparator",
";",
"}",
"else",
"if",
"(",
"isString",
"(",
"comparator",
")",
")",
"{",
"if",
"(",
"comparator",
"in",
"Comparators",
")",
"{",
"return",
"Comparators",
"[",
"comparator",
"]",
";",
"}",
"if",
"(",
"comparator",
".",
"charAt",
"(",
"0",
")",
"===",
"'-'",
")",
"{",
"var",
"parsed",
"=",
"createComparator",
"(",
"comparator",
".",
"substring",
"(",
"1",
")",
",",
"!",
"nullsFirst",
")",
";",
"return",
"function",
"compareObjectsReversed",
"(",
"a",
",",
"b",
")",
"{",
"return",
"-",
"parsed",
"(",
"a",
",",
"b",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"isFormatInput",
"(",
"comparator",
")",
")",
"{",
"var",
"formatter",
"=",
"createFormatter",
"(",
"comparator",
")",
";",
"return",
"function",
"compareFormatted",
"(",
"a",
",",
"b",
")",
"{",
"var",
"af",
"=",
"formatter",
"(",
"a",
")",
";",
"var",
"bf",
"=",
"formatter",
"(",
"b",
")",
";",
"return",
"af",
".",
"localeCompare",
"(",
"bf",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"isParseInput",
"(",
"comparator",
")",
")",
"{",
"var",
"parser",
"=",
"createParser",
"(",
"comparator",
")",
";",
"return",
"function",
"compareExpression",
"(",
"a",
",",
"b",
")",
"{",
"var",
"ap",
"=",
"parser",
"(",
"a",
")",
";",
"var",
"bp",
"=",
"parser",
"(",
"b",
")",
";",
"return",
"compare",
"(",
"ap",
",",
"bp",
",",
"nullsFirst",
")",
";",
"}",
";",
"}",
"else",
"{",
"return",
"function",
"compareObjects",
"(",
"a",
",",
"b",
")",
"{",
"var",
"av",
"=",
"isValue",
"(",
"a",
")",
"?",
"a",
"[",
"comparator",
"]",
":",
"a",
";",
"var",
"bv",
"=",
"isValue",
"(",
"b",
")",
"?",
"b",
"[",
"comparator",
"]",
":",
"b",
";",
"return",
"compare",
"(",
"av",
",",
"bv",
",",
"nullsFirst",
")",
";",
"}",
";",
"}",
"}",
"else",
"if",
"(",
"isArray",
"(",
"comparator",
")",
")",
"{",
"var",
"parsedChain",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"comparator",
".",
"length",
";",
"i",
"++",
")",
"{",
"parsedChain",
"[",
"i",
"]",
"=",
"createComparator",
"(",
"comparator",
"[",
"i",
"]",
",",
"nullsFirst",
")",
";",
"}",
"return",
"function",
"compareObjectsCascade",
"(",
"a",
",",
"b",
")",
"{",
"var",
"d",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parsedChain",
".",
"length",
"&&",
"d",
"===",
"0",
";",
"i",
"++",
")",
"{",
"d",
"=",
"parsedChain",
"[",
"i",
"]",
"(",
"a",
",",
"b",
")",
";",
"}",
"return",
"d",
";",
"}",
";",
"}",
"return",
"null",
";",
"}"
] | Creates a function which compares two values.
@memberof Rekord
@param {comparatorInput} comparator
The input which creates a comparison function.
@param {Boolean} [nullsFirst=false] -
True if null values should be sorted first.
@return {comparisonCallback} | [
"Creates",
"a",
"function",
"which",
"compares",
"two",
"values",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L844-L924 | train |
Rekord/rekord | build/rekord.js | on | function on(events, callback, context)
{
return onListeners( this, events, callback, context, EventNode.Types.Persistent );
} | javascript | function on(events, callback, context)
{
return onListeners( this, events, callback, context, EventNode.Types.Persistent );
} | [
"function",
"on",
"(",
"events",
",",
"callback",
",",
"context",
")",
"{",
"return",
"onListeners",
"(",
"this",
",",
"events",
",",
"callback",
",",
"context",
",",
"EventNode",
".",
"Types",
".",
"Persistent",
")",
";",
"}"
] | Listens for every occurrence of the given events and invokes the callback
each time any of them are triggered.
@method on
@memberof Rekord.Eventful#
@param {String|Array} events -
The event or events to listen to.
@param {Function} callback -
The function to invoke when any of the events are invoked.
@param {Object} [context] -
The value of `this` when the callback is invoked. If not specified, the
reference of the object this function exists on will be `this`.
@return {Function} -
A function to invoke to stop listening to all of the events given.
Listens for every occurrence of the given events and invokes the callback
each time any of them are triggered.
@method $on
@memberof Rekord.Eventful$#
@param {String|Array} events -
The event or events to listen to.
@param {Function} callback -
The function to invoke when any of the events are invoked.
@param {Object} [context] -
The value of `this` when the callback is invoked. If not specified, the
reference of the object this function exists on will be `this`.
@return {Function} -
A function to invoke to stop listening to all of the events given. | [
"Listens",
"for",
"every",
"occurrence",
"of",
"the",
"given",
"events",
"and",
"invokes",
"the",
"callback",
"each",
"time",
"any",
"of",
"them",
"are",
"triggered",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1361-L1364 | train |
Rekord/rekord | build/rekord.js | once | function once(events, callback, context)
{
return onListeners( this, events, callback, context, EventNode.Types.Once );
} | javascript | function once(events, callback, context)
{
return onListeners( this, events, callback, context, EventNode.Types.Once );
} | [
"function",
"once",
"(",
"events",
",",
"callback",
",",
"context",
")",
"{",
"return",
"onListeners",
"(",
"this",
",",
"events",
",",
"callback",
",",
"context",
",",
"EventNode",
".",
"Types",
".",
"Once",
")",
";",
"}"
] | Listens for the first of the given events to be triggered and invokes the
callback once.
@method once
@memberof Rekord.Eventful#
@param {String|Array} events -
The event or events to listen to.
@param {Function} callback -
The function to invoke when any of the events are invoked.
@param {Object} [context] -
The value of `this` when the callback is invoked. If not specified, the
reference of the object this function exists on will be `this`.
@return {Function} -
A function to invoke to stop listening to all of the events given.
Listens for the first of the given events to be triggered and invokes the
callback once.
@method $once
@memberof Rekord.Eventful$#
@param {String|Array} events -
The event or events to listen to.
@param {Function} callback -
The function to invoke when any of the events are invoked.
@param {Object} [context] -
The value of `this` when the callback is invoked. If not specified, the
reference of the object this function exists on will be `this`.
@return {Function} -
A function to invoke to stop listening to all of the events given. | [
"Listens",
"for",
"the",
"first",
"of",
"the",
"given",
"events",
"to",
"be",
"triggered",
"and",
"invokes",
"the",
"callback",
"once",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1400-L1403 | train |
Rekord/rekord | build/rekord.js | offListeners | function offListeners(listeners, event, callback)
{
if (listeners && event in listeners)
{
var eventListeners = listeners[ event ];
var next, node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
if (node.callback === callback)
{
node.remove();
}
node = next;
}
}
} | javascript | function offListeners(listeners, event, callback)
{
if (listeners && event in listeners)
{
var eventListeners = listeners[ event ];
var next, node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
if (node.callback === callback)
{
node.remove();
}
node = next;
}
}
} | [
"function",
"offListeners",
"(",
"listeners",
",",
"event",
",",
"callback",
")",
"{",
"if",
"(",
"listeners",
"&&",
"event",
"in",
"listeners",
")",
"{",
"var",
"eventListeners",
"=",
"listeners",
"[",
"event",
"]",
";",
"var",
"next",
",",
"node",
"=",
"eventListeners",
".",
"next",
";",
"while",
"(",
"node",
"!==",
"eventListeners",
")",
"{",
"next",
"=",
"node",
".",
"next",
";",
"if",
"(",
"node",
".",
"callback",
"===",
"callback",
")",
"{",
"node",
".",
"remove",
"(",
")",
";",
"}",
"node",
"=",
"next",
";",
"}",
"}",
"}"
] | Removes a listener from an array of listeners. | [
"Removes",
"a",
"listener",
"from",
"an",
"array",
"of",
"listeners",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1411-L1430 | train |
Rekord/rekord | build/rekord.js | off | function off(eventsInput, callback)
{
// Remove ALL listeners
if ( !isDefined( eventsInput ) )
{
deleteProperty( this, '$$on' );
}
else
{
var events = toArray( eventsInput, ' ' );
// Remove listeners for given events
if ( !isFunction( callback ) )
{
for (var i = 0; i < events.length; i++)
{
deleteProperty( this.$$on, events[i] );
}
}
// Remove specific listener
else
{
for (var i = 0; i < events.length; i++)
{
offListeners( this.$$on, events[i], callback );
}
}
}
return this;
} | javascript | function off(eventsInput, callback)
{
// Remove ALL listeners
if ( !isDefined( eventsInput ) )
{
deleteProperty( this, '$$on' );
}
else
{
var events = toArray( eventsInput, ' ' );
// Remove listeners for given events
if ( !isFunction( callback ) )
{
for (var i = 0; i < events.length; i++)
{
deleteProperty( this.$$on, events[i] );
}
}
// Remove specific listener
else
{
for (var i = 0; i < events.length; i++)
{
offListeners( this.$$on, events[i], callback );
}
}
}
return this;
} | [
"function",
"off",
"(",
"eventsInput",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"isDefined",
"(",
"eventsInput",
")",
")",
"{",
"deleteProperty",
"(",
"this",
",",
"'$$on'",
")",
";",
"}",
"else",
"{",
"var",
"events",
"=",
"toArray",
"(",
"eventsInput",
",",
"' '",
")",
";",
"if",
"(",
"!",
"isFunction",
"(",
"callback",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"events",
".",
"length",
";",
"i",
"++",
")",
"{",
"deleteProperty",
"(",
"this",
".",
"$$on",
",",
"events",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"events",
".",
"length",
";",
"i",
"++",
")",
"{",
"offListeners",
"(",
"this",
".",
"$$on",
",",
"events",
"[",
"i",
"]",
",",
"callback",
")",
";",
"}",
"}",
"}",
"return",
"this",
";",
"}"
] | Stops listening for a given callback for a given set of events.
**Examples:**
target.off(); // remove all listeners
target.off('a b'); // remove all listeners on events a & b
target.off(['a', 'b']); // remove all listeners on events a & b
target.off('a', x); // remove listener x from event a
@method off
@for addEventful
@param {String|Array|Object} [eventsInput]
@param {Function} [callback]
@chainable | [
"Stops",
"listening",
"for",
"a",
"given",
"callback",
"for",
"a",
"given",
"set",
"of",
"events",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1457-L1487 | train |
Rekord/rekord | build/rekord.js | triggerListeners | function triggerListeners(listeners, event, args)
{
if (listeners && event in listeners)
{
var eventListeners = listeners[ event ];
var triggerGroup = ++triggerId;
var next, node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
node.trigger( triggerGroup, args, false );
node = next;
}
node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
node.trigger( triggerGroup, args, true );
node = next;
}
}
} | javascript | function triggerListeners(listeners, event, args)
{
if (listeners && event in listeners)
{
var eventListeners = listeners[ event ];
var triggerGroup = ++triggerId;
var next, node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
node.trigger( triggerGroup, args, false );
node = next;
}
node = eventListeners.next;
while (node !== eventListeners)
{
next = node.next;
node.trigger( triggerGroup, args, true );
node = next;
}
}
} | [
"function",
"triggerListeners",
"(",
"listeners",
",",
"event",
",",
"args",
")",
"{",
"if",
"(",
"listeners",
"&&",
"event",
"in",
"listeners",
")",
"{",
"var",
"eventListeners",
"=",
"listeners",
"[",
"event",
"]",
";",
"var",
"triggerGroup",
"=",
"++",
"triggerId",
";",
"var",
"next",
",",
"node",
"=",
"eventListeners",
".",
"next",
";",
"while",
"(",
"node",
"!==",
"eventListeners",
")",
"{",
"next",
"=",
"node",
".",
"next",
";",
"node",
".",
"trigger",
"(",
"triggerGroup",
",",
"args",
",",
"false",
")",
";",
"node",
"=",
"next",
";",
"}",
"node",
"=",
"eventListeners",
".",
"next",
";",
"while",
"(",
"node",
"!==",
"eventListeners",
")",
"{",
"next",
"=",
"node",
".",
"next",
";",
"node",
".",
"trigger",
"(",
"triggerGroup",
",",
"args",
",",
"true",
")",
";",
"node",
"=",
"next",
";",
"}",
"}",
"}"
] | Triggers listeneers for the given event | [
"Triggers",
"listeneers",
"for",
"the",
"given",
"event"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1490-L1514 | train |
Rekord/rekord | build/rekord.js | trigger | function trigger(eventsInput, args)
{
try
{
var events = toArray( eventsInput, ' ' );
for (var i = 0; i < events.length; i++)
{
triggerListeners( this.$$on, events[ i ], args );
}
}
catch (ex)
{
Rekord.trigger( Rekord.Events.Error, [ex] );
}
return this;
} | javascript | function trigger(eventsInput, args)
{
try
{
var events = toArray( eventsInput, ' ' );
for (var i = 0; i < events.length; i++)
{
triggerListeners( this.$$on, events[ i ], args );
}
}
catch (ex)
{
Rekord.trigger( Rekord.Events.Error, [ex] );
}
return this;
} | [
"function",
"trigger",
"(",
"eventsInput",
",",
"args",
")",
"{",
"try",
"{",
"var",
"events",
"=",
"toArray",
"(",
"eventsInput",
",",
"' '",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"events",
".",
"length",
";",
"i",
"++",
")",
"{",
"triggerListeners",
"(",
"this",
".",
"$$on",
",",
"events",
"[",
"i",
"]",
",",
"args",
")",
";",
"}",
"}",
"catch",
"(",
"ex",
")",
"{",
"Rekord",
".",
"trigger",
"(",
"Rekord",
".",
"Events",
".",
"Error",
",",
"[",
"ex",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Triggers a single event optionally passing an argument to any listeners.
@method trigger
@for addEventful
@param {String} eventsInput
@param {Array} args
@chainable | [
"Triggers",
"a",
"single",
"event",
"optionally",
"passing",
"an",
"argument",
"to",
"any",
"listeners",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1525-L1542 | train |
Rekord/rekord | build/rekord.js | merge | function merge(dst, src, ignoreMap)
{
if (isObject( dst ) && isObject( src ))
{
for (var prop in src)
{
if (!ignoreMap || !ignoreMap[ prop ])
{
var adding = src[ prop ];
if (prop in dst)
{
var existing = dst[ prop ];
if (isArray( existing ))
{
if (isArray( adding ))
{
existing.push.apply( existing, adding );
}
else
{
existing.push( adding );
}
}
else if (isObject( existing ))
{
merge( existing, adding, ignoreMap );
}
else
{
dst[ prop ] = copy( adding, true );
}
}
else
{
dst[ prop ] = copy( adding, true );
}
}
}
}
return dst;
} | javascript | function merge(dst, src, ignoreMap)
{
if (isObject( dst ) && isObject( src ))
{
for (var prop in src)
{
if (!ignoreMap || !ignoreMap[ prop ])
{
var adding = src[ prop ];
if (prop in dst)
{
var existing = dst[ prop ];
if (isArray( existing ))
{
if (isArray( adding ))
{
existing.push.apply( existing, adding );
}
else
{
existing.push( adding );
}
}
else if (isObject( existing ))
{
merge( existing, adding, ignoreMap );
}
else
{
dst[ prop ] = copy( adding, true );
}
}
else
{
dst[ prop ] = copy( adding, true );
}
}
}
}
return dst;
} | [
"function",
"merge",
"(",
"dst",
",",
"src",
",",
"ignoreMap",
")",
"{",
"if",
"(",
"isObject",
"(",
"dst",
")",
"&&",
"isObject",
"(",
"src",
")",
")",
"{",
"for",
"(",
"var",
"prop",
"in",
"src",
")",
"{",
"if",
"(",
"!",
"ignoreMap",
"||",
"!",
"ignoreMap",
"[",
"prop",
"]",
")",
"{",
"var",
"adding",
"=",
"src",
"[",
"prop",
"]",
";",
"if",
"(",
"prop",
"in",
"dst",
")",
"{",
"var",
"existing",
"=",
"dst",
"[",
"prop",
"]",
";",
"if",
"(",
"isArray",
"(",
"existing",
")",
")",
"{",
"if",
"(",
"isArray",
"(",
"adding",
")",
")",
"{",
"existing",
".",
"push",
".",
"apply",
"(",
"existing",
",",
"adding",
")",
";",
"}",
"else",
"{",
"existing",
".",
"push",
"(",
"adding",
")",
";",
"}",
"}",
"else",
"if",
"(",
"isObject",
"(",
"existing",
")",
")",
"{",
"merge",
"(",
"existing",
",",
"adding",
",",
"ignoreMap",
")",
";",
"}",
"else",
"{",
"dst",
"[",
"prop",
"]",
"=",
"copy",
"(",
"adding",
",",
"true",
")",
";",
"}",
"}",
"else",
"{",
"dst",
"[",
"prop",
"]",
"=",
"copy",
"(",
"adding",
",",
"true",
")",
";",
"}",
"}",
"}",
"}",
"return",
"dst",
";",
"}"
] | Given two objects, merge src into dst. - If a property in src has a truthy value in ignoreMap then skip merging it. - If a property exists in src and not in dst, the property is added to dst. - If an array property exists in src and in dst, the src elements are added to dst. - If an array property exists in dst and a non array value exists in src, added the value to the dst array. - If a property in dst is an object, try to merge the property from src into it. - If a property exists in dst that is not an object or array, replace it with the value in src. | [
"Given",
"two",
"objects",
"merge",
"src",
"into",
"dst",
".",
"-",
"If",
"a",
"property",
"in",
"src",
"has",
"a",
"truthy",
"value",
"in",
"ignoreMap",
"then",
"skip",
"merging",
"it",
".",
"-",
"If",
"a",
"property",
"exists",
"in",
"src",
"and",
"not",
"in",
"dst",
"the",
"property",
"is",
"added",
"to",
"dst",
".",
"-",
"If",
"an",
"array",
"property",
"exists",
"in",
"src",
"and",
"in",
"dst",
"the",
"src",
"elements",
"are",
"added",
"to",
"dst",
".",
"-",
"If",
"an",
"array",
"property",
"exists",
"in",
"dst",
"and",
"a",
"non",
"array",
"value",
"exists",
"in",
"src",
"added",
"the",
"value",
"to",
"the",
"dst",
"array",
".",
"-",
"If",
"a",
"property",
"in",
"dst",
"is",
"an",
"object",
"try",
"to",
"merge",
"the",
"property",
"from",
"src",
"into",
"it",
".",
"-",
"If",
"a",
"property",
"exists",
"in",
"dst",
"that",
"is",
"not",
"an",
"object",
"or",
"array",
"replace",
"it",
"with",
"the",
"value",
"in",
"src",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1585-L1628 | train |
Rekord/rekord | build/rekord.js | propsMatch | function propsMatch(test, testFields, expected, expectedFields, equals)
{
var equality = equals || Rekord.equals;
if ( isString( testFields ) ) // && isString( expectedFields )
{
return equality( test[ testFields ], expected[ expectedFields ] );
}
else // if ( isArray( testFields ) && isArray( expectedFields ) )
{
for (var i = 0; i < testFields.length; i++)
{
var testProp = testFields[ i ];
var expectedProp = expectedFields[ i ];
if ( !equality( test[ testProp ], expected[ expectedProp ] ) )
{
return false;
}
}
return true;
}
return false;
} | javascript | function propsMatch(test, testFields, expected, expectedFields, equals)
{
var equality = equals || Rekord.equals;
if ( isString( testFields ) ) // && isString( expectedFields )
{
return equality( test[ testFields ], expected[ expectedFields ] );
}
else // if ( isArray( testFields ) && isArray( expectedFields ) )
{
for (var i = 0; i < testFields.length; i++)
{
var testProp = testFields[ i ];
var expectedProp = expectedFields[ i ];
if ( !equality( test[ testProp ], expected[ expectedProp ] ) )
{
return false;
}
}
return true;
}
return false;
} | [
"function",
"propsMatch",
"(",
"test",
",",
"testFields",
",",
"expected",
",",
"expectedFields",
",",
"equals",
")",
"{",
"var",
"equality",
"=",
"equals",
"||",
"Rekord",
".",
"equals",
";",
"if",
"(",
"isString",
"(",
"testFields",
")",
")",
"{",
"return",
"equality",
"(",
"test",
"[",
"testFields",
"]",
",",
"expected",
"[",
"expectedFields",
"]",
")",
";",
"}",
"else",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"testFields",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"testProp",
"=",
"testFields",
"[",
"i",
"]",
";",
"var",
"expectedProp",
"=",
"expectedFields",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"equality",
"(",
"test",
"[",
"testProp",
"]",
",",
"expected",
"[",
"expectedProp",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines whether the properties on one object equals the properties on
another object.
@memberof Rekord
@param {Object} test -
The object to test for matching.
@param {String|String[]} testFields -
The property name or array of properties to test for equality on `test`.
@param {Object} expected -
The object with the expected values.
@param {String|String[]} expectedFields -
The property name or array of properties to test for equality on `expected`.
@param {equalityCallback} [equals] -
The equality function which compares two values and returns whether they
are considered equivalent.
@return {Boolean} -
True if the `testFields` properties on `test` are equivalent to the
`expectedFields` on `expected` according to the `equals` function. | [
"Determines",
"whether",
"the",
"properties",
"on",
"one",
"object",
"equals",
"the",
"properties",
"on",
"another",
"object",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1694-L1719 | train |
Rekord/rekord | build/rekord.js | hasFields | function hasFields(model, fields, exists)
{
if ( isArray( fields ) )
{
for (var i = 0; i < fields.length; i++)
{
if ( !exists( model[ fields[ i ] ] ) )
{
return false;
}
}
return true;
}
else // isString( fields )
{
return exists( model[ fields ] );
}
} | javascript | function hasFields(model, fields, exists)
{
if ( isArray( fields ) )
{
for (var i = 0; i < fields.length; i++)
{
if ( !exists( model[ fields[ i ] ] ) )
{
return false;
}
}
return true;
}
else // isString( fields )
{
return exists( model[ fields ] );
}
} | [
"function",
"hasFields",
"(",
"model",
",",
"fields",
",",
"exists",
")",
"{",
"if",
"(",
"isArray",
"(",
"fields",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"fields",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"exists",
"(",
"model",
"[",
"fields",
"[",
"i",
"]",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"exists",
"(",
"model",
"[",
"fields",
"]",
")",
";",
"}",
"}"
] | Determines whether the given model has the given fields | [
"Determines",
"whether",
"the",
"given",
"model",
"has",
"the",
"given",
"fields"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L1722-L1740 | train |
Rekord/rekord | build/rekord.js | createPropertyResolver | function createPropertyResolver(properties)
{
if ( isFunction( properties ) )
{
return properties;
}
else if ( isString( properties ) )
{
if ( properties in PropertyResolvers )
{
return PropertyResolvers[ properties ];
}
if ( isFormatInput( properties ) )
{
return createFormatter( properties );
}
else if ( isParseInput( properties ) )
{
return createParser( properties );
}
else
{
return function resolveProperty(model)
{
return model ? model[ properties ] : undefined;
};
}
}
else if ( isArray( properties ) )
{
return function resolveProperties(model)
{
return pull( model, properties );
};
}
else if ( isObject( properties ) )
{
var propsArray = [];
var propsResolver = [];
for (var prop in properties)
{
propsArray.push( prop );
propsResolver.push( createPropertyResolver( properties[ prop ] ) );
}
return function resolvePropertyObject(model)
{
var resolved = {};
for (var i = 0; i < propsArray.length; i++)
{
var prop = propsArray[ i ];
resolved[ prop ] = propsResolver[ i ]( model[ prop ] );
}
return resolved;
};
}
else
{
return function resolveNone(model)
{
return model;
};
}
} | javascript | function createPropertyResolver(properties)
{
if ( isFunction( properties ) )
{
return properties;
}
else if ( isString( properties ) )
{
if ( properties in PropertyResolvers )
{
return PropertyResolvers[ properties ];
}
if ( isFormatInput( properties ) )
{
return createFormatter( properties );
}
else if ( isParseInput( properties ) )
{
return createParser( properties );
}
else
{
return function resolveProperty(model)
{
return model ? model[ properties ] : undefined;
};
}
}
else if ( isArray( properties ) )
{
return function resolveProperties(model)
{
return pull( model, properties );
};
}
else if ( isObject( properties ) )
{
var propsArray = [];
var propsResolver = [];
for (var prop in properties)
{
propsArray.push( prop );
propsResolver.push( createPropertyResolver( properties[ prop ] ) );
}
return function resolvePropertyObject(model)
{
var resolved = {};
for (var i = 0; i < propsArray.length; i++)
{
var prop = propsArray[ i ];
resolved[ prop ] = propsResolver[ i ]( model[ prop ] );
}
return resolved;
};
}
else
{
return function resolveNone(model)
{
return model;
};
}
} | [
"function",
"createPropertyResolver",
"(",
"properties",
")",
"{",
"if",
"(",
"isFunction",
"(",
"properties",
")",
")",
"{",
"return",
"properties",
";",
"}",
"else",
"if",
"(",
"isString",
"(",
"properties",
")",
")",
"{",
"if",
"(",
"properties",
"in",
"PropertyResolvers",
")",
"{",
"return",
"PropertyResolvers",
"[",
"properties",
"]",
";",
"}",
"if",
"(",
"isFormatInput",
"(",
"properties",
")",
")",
"{",
"return",
"createFormatter",
"(",
"properties",
")",
";",
"}",
"else",
"if",
"(",
"isParseInput",
"(",
"properties",
")",
")",
"{",
"return",
"createParser",
"(",
"properties",
")",
";",
"}",
"else",
"{",
"return",
"function",
"resolveProperty",
"(",
"model",
")",
"{",
"return",
"model",
"?",
"model",
"[",
"properties",
"]",
":",
"undefined",
";",
"}",
";",
"}",
"}",
"else",
"if",
"(",
"isArray",
"(",
"properties",
")",
")",
"{",
"return",
"function",
"resolveProperties",
"(",
"model",
")",
"{",
"return",
"pull",
"(",
"model",
",",
"properties",
")",
";",
"}",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"properties",
")",
")",
"{",
"var",
"propsArray",
"=",
"[",
"]",
";",
"var",
"propsResolver",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"prop",
"in",
"properties",
")",
"{",
"propsArray",
".",
"push",
"(",
"prop",
")",
";",
"propsResolver",
".",
"push",
"(",
"createPropertyResolver",
"(",
"properties",
"[",
"prop",
"]",
")",
")",
";",
"}",
"return",
"function",
"resolvePropertyObject",
"(",
"model",
")",
"{",
"var",
"resolved",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"propsArray",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"prop",
"=",
"propsArray",
"[",
"i",
"]",
";",
"resolved",
"[",
"prop",
"]",
"=",
"propsResolver",
"[",
"i",
"]",
"(",
"model",
"[",
"prop",
"]",
")",
";",
"}",
"return",
"resolved",
";",
"}",
";",
"}",
"else",
"{",
"return",
"function",
"resolveNone",
"(",
"model",
")",
"{",
"return",
"model",
";",
"}",
";",
"}",
"}"
] | Creates a function which resolves a value from another value given an
expression. This is often used to get a property value of an object.
```javascript
// x = {age: 6, name: 'tom', user: {first: 'jack'}}
createPropertyResolver()( x ) // x
createPropertyResolver( 'age' )( x ) // 6
createPropertyResolver( 'user.first' )( x ) // 'jack'
createPropertyResolver( '{name} & {user.first}')( x ) // 'tom & jack'
createPropertyResolver( ['name', 'age'] )( x ) // ['tom', 6]
createPropertyResolver( {age:null, user:'first'})( x ) // {age: 6, user:'jack'}
```
@memberof Rekord
@param {propertyResolverInput} [properties] -
The expression which converts one value into another.
@return {propertyResolverCallback} -
A function to take values and resolve new ones. | [
"Creates",
"a",
"function",
"which",
"resolves",
"a",
"value",
"from",
"another",
"value",
"given",
"an",
"expression",
".",
"This",
"is",
"often",
"used",
"to",
"get",
"a",
"property",
"value",
"of",
"an",
"object",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L2166-L2234 | train |
Rekord/rekord | build/rekord.js | createWhere | function createWhere(properties, value, equals)
{
var equality = equals || equalsStrict;
if ( isFunction( properties ) )
{
return properties;
}
else if ( isArray( properties ) )
{
var parsed = [];
for (var i = 0; i < properties.length; i++)
{
var where = properties[ i ];
parsed.push( isArray( where ) ? createWhere.apply( this, where ) : createWhere( where ) );
}
return function whereMultiple(model)
{
for (var i = 0; i < parsed.length; i++)
{
if ( !parsed[ i ]( model ) )
{
return false;
}
}
return true;
};
}
else if ( isObject( properties ) )
{
var props = [];
for (var prop in properties)
{
props.push({
tester: exprEqualsTester( properties[ prop ], equality ),
resolver: createPropertyResolver( prop )
});
}
return function whereEqualsObject(model)
{
for (var i = 0; i < props.length; i++)
{
var prop = props[ i ];
if ( !prop.tester( prop.resolver( model ) ) )
{
return false;
}
}
return true;
};
}
else if ( isString( properties ) )
{
if ( properties in Wheres )
{
return Wheres[ properties ];
}
var resolver = createPropertyResolver( properties );
if ( isValue( value ) )
{
var tester = exprEqualsTester( value, equality );
return function whereEqualsValue(model)
{
return tester( resolver( model ) );
};
}
else
{
return function whereHasValue(model)
{
return isValue( resolver( model ) );
};
}
}
else
{
return function whereAll(model)
{
return true;
};
}
} | javascript | function createWhere(properties, value, equals)
{
var equality = equals || equalsStrict;
if ( isFunction( properties ) )
{
return properties;
}
else if ( isArray( properties ) )
{
var parsed = [];
for (var i = 0; i < properties.length; i++)
{
var where = properties[ i ];
parsed.push( isArray( where ) ? createWhere.apply( this, where ) : createWhere( where ) );
}
return function whereMultiple(model)
{
for (var i = 0; i < parsed.length; i++)
{
if ( !parsed[ i ]( model ) )
{
return false;
}
}
return true;
};
}
else if ( isObject( properties ) )
{
var props = [];
for (var prop in properties)
{
props.push({
tester: exprEqualsTester( properties[ prop ], equality ),
resolver: createPropertyResolver( prop )
});
}
return function whereEqualsObject(model)
{
for (var i = 0; i < props.length; i++)
{
var prop = props[ i ];
if ( !prop.tester( prop.resolver( model ) ) )
{
return false;
}
}
return true;
};
}
else if ( isString( properties ) )
{
if ( properties in Wheres )
{
return Wheres[ properties ];
}
var resolver = createPropertyResolver( properties );
if ( isValue( value ) )
{
var tester = exprEqualsTester( value, equality );
return function whereEqualsValue(model)
{
return tester( resolver( model ) );
};
}
else
{
return function whereHasValue(model)
{
return isValue( resolver( model ) );
};
}
}
else
{
return function whereAll(model)
{
return true;
};
}
} | [
"function",
"createWhere",
"(",
"properties",
",",
"value",
",",
"equals",
")",
"{",
"var",
"equality",
"=",
"equals",
"||",
"equalsStrict",
";",
"if",
"(",
"isFunction",
"(",
"properties",
")",
")",
"{",
"return",
"properties",
";",
"}",
"else",
"if",
"(",
"isArray",
"(",
"properties",
")",
")",
"{",
"var",
"parsed",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"properties",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"where",
"=",
"properties",
"[",
"i",
"]",
";",
"parsed",
".",
"push",
"(",
"isArray",
"(",
"where",
")",
"?",
"createWhere",
".",
"apply",
"(",
"this",
",",
"where",
")",
":",
"createWhere",
"(",
"where",
")",
")",
";",
"}",
"return",
"function",
"whereMultiple",
"(",
"model",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"parsed",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"parsed",
"[",
"i",
"]",
"(",
"model",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"properties",
")",
")",
"{",
"var",
"props",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"prop",
"in",
"properties",
")",
"{",
"props",
".",
"push",
"(",
"{",
"tester",
":",
"exprEqualsTester",
"(",
"properties",
"[",
"prop",
"]",
",",
"equality",
")",
",",
"resolver",
":",
"createPropertyResolver",
"(",
"prop",
")",
"}",
")",
";",
"}",
"return",
"function",
"whereEqualsObject",
"(",
"model",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"props",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"prop",
"=",
"props",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"prop",
".",
"tester",
"(",
"prop",
".",
"resolver",
"(",
"model",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
";",
"}",
"else",
"if",
"(",
"isString",
"(",
"properties",
")",
")",
"{",
"if",
"(",
"properties",
"in",
"Wheres",
")",
"{",
"return",
"Wheres",
"[",
"properties",
"]",
";",
"}",
"var",
"resolver",
"=",
"createPropertyResolver",
"(",
"properties",
")",
";",
"if",
"(",
"isValue",
"(",
"value",
")",
")",
"{",
"var",
"tester",
"=",
"exprEqualsTester",
"(",
"value",
",",
"equality",
")",
";",
"return",
"function",
"whereEqualsValue",
"(",
"model",
")",
"{",
"return",
"tester",
"(",
"resolver",
"(",
"model",
")",
")",
";",
"}",
";",
"}",
"else",
"{",
"return",
"function",
"whereHasValue",
"(",
"model",
")",
"{",
"return",
"isValue",
"(",
"resolver",
"(",
"model",
")",
")",
";",
"}",
";",
"}",
"}",
"else",
"{",
"return",
"function",
"whereAll",
"(",
"model",
")",
"{",
"return",
"true",
";",
"}",
";",
"}",
"}"
] | Creates a function which returns a true or false value given a test value.
This is also known as a filter function.
```javascript
Rekord.createWhere('field', true); // when an object has property where field=true
Rekord.createWhere('field'); // when an object has the property named field
Rekord.createWhere(function(){}); // a function can be given which is immediately returned
Rekord.createWhere(['field', function(){}, ['field', true]]); // when an object meets all of the above criteria
Rekord.createWhere({foo: 1, bar: 2}); // when an object has foo=1 and bar=2
Rekord.createWhere('field', true, myEquals); // A custom comparison function can be given.
Rekord.createWhere(); // always returns true
```
@memberof Rekord
@param {whereInput} [properties] -
The first expression used to generate a filter function.
@param {Any} [value] -
When the first argument is a string this argument will be treated as a
value to compare to the value of the named property on the object passed
through the filter function.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
An alternative function can be used to compare to values.
@return {whereCallback} -
A function which takes a value (typically an object) and returns a true
or false value.
@see Rekord.saveWhere | [
"Creates",
"a",
"function",
"which",
"returns",
"a",
"true",
"or",
"false",
"value",
"given",
"a",
"test",
"value",
".",
"This",
"is",
"also",
"known",
"as",
"a",
"filter",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L2400-L2492 | train |
Rekord/rekord | build/rekord.js | Rekord | function Rekord(options)
{
var promise = Rekord.get( options.name );
if ( promise.isComplete() )
{
return promise.results[0];
}
Rekord.trigger( Rekord.Events.Options, [options] );
var database = new Database( options );
var model = Class.dynamic(
Model,
new Model( database ),
database.className,
'(props, remoteData) { this.$init( props, remoteData ) }'
);
database.Model = model;
model.Database = database;
Rekord.classes[ database.name ] = model;
Rekord.trigger( Rekord.Events.Plugins, [model, database, options] );
if ( Rekord.autoload )
{
database.loadBegin(function onLoadFinish(success)
{
if ( success )
{
database.loadFinish();
}
});
}
else
{
Rekord.unloaded.push( database );
}
Rekord.get( database.name ).resolve( model );
Rekord.get( database.className ).resolve( model );
Rekord.debug( Rekord.Debugs.CREATION, database, options );
return model;
} | javascript | function Rekord(options)
{
var promise = Rekord.get( options.name );
if ( promise.isComplete() )
{
return promise.results[0];
}
Rekord.trigger( Rekord.Events.Options, [options] );
var database = new Database( options );
var model = Class.dynamic(
Model,
new Model( database ),
database.className,
'(props, remoteData) { this.$init( props, remoteData ) }'
);
database.Model = model;
model.Database = database;
Rekord.classes[ database.name ] = model;
Rekord.trigger( Rekord.Events.Plugins, [model, database, options] );
if ( Rekord.autoload )
{
database.loadBegin(function onLoadFinish(success)
{
if ( success )
{
database.loadFinish();
}
});
}
else
{
Rekord.unloaded.push( database );
}
Rekord.get( database.name ).resolve( model );
Rekord.get( database.className ).resolve( model );
Rekord.debug( Rekord.Debugs.CREATION, database, options );
return model;
} | [
"function",
"Rekord",
"(",
"options",
")",
"{",
"var",
"promise",
"=",
"Rekord",
".",
"get",
"(",
"options",
".",
"name",
")",
";",
"if",
"(",
"promise",
".",
"isComplete",
"(",
")",
")",
"{",
"return",
"promise",
".",
"results",
"[",
"0",
"]",
";",
"}",
"Rekord",
".",
"trigger",
"(",
"Rekord",
".",
"Events",
".",
"Options",
",",
"[",
"options",
"]",
")",
";",
"var",
"database",
"=",
"new",
"Database",
"(",
"options",
")",
";",
"var",
"model",
"=",
"Class",
".",
"dynamic",
"(",
"Model",
",",
"new",
"Model",
"(",
"database",
")",
",",
"database",
".",
"className",
",",
"'(props, remoteData) { this.$init( props, remoteData ) }'",
")",
";",
"database",
".",
"Model",
"=",
"model",
";",
"model",
".",
"Database",
"=",
"database",
";",
"Rekord",
".",
"classes",
"[",
"database",
".",
"name",
"]",
"=",
"model",
";",
"Rekord",
".",
"trigger",
"(",
"Rekord",
".",
"Events",
".",
"Plugins",
",",
"[",
"model",
",",
"database",
",",
"options",
"]",
")",
";",
"if",
"(",
"Rekord",
".",
"autoload",
")",
"{",
"database",
".",
"loadBegin",
"(",
"function",
"onLoadFinish",
"(",
"success",
")",
"{",
"if",
"(",
"success",
")",
"{",
"database",
".",
"loadFinish",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"Rekord",
".",
"unloaded",
".",
"push",
"(",
"database",
")",
";",
"}",
"Rekord",
".",
"get",
"(",
"database",
".",
"name",
")",
".",
"resolve",
"(",
"model",
")",
";",
"Rekord",
".",
"get",
"(",
"database",
".",
"className",
")",
".",
"resolve",
"(",
"model",
")",
";",
"Rekord",
".",
"debug",
"(",
"Rekord",
".",
"Debugs",
".",
"CREATION",
",",
"database",
",",
"options",
")",
";",
"return",
"model",
";",
"}"
] | Creates a Rekord object given a set of options. A Rekord object is also the
constructor for creating instances of the Rekord object defined.
@namespace
@param {Object} options
The options of | [
"Creates",
"a",
"Rekord",
"object",
"given",
"a",
"set",
"of",
"options",
".",
"A",
"Rekord",
"object",
"is",
"also",
"the",
"constructor",
"for",
"creating",
"instances",
"of",
"the",
"Rekord",
"object",
"defined",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L2578-L2626 | train |
Rekord/rekord | build/rekord.js | function(saving)
{
if ( !isObject( saving ) )
{
return false;
}
for (var prop in saving)
{
if ( !this.ignoredFields[ prop ] )
{
return true;
}
}
return false;
} | javascript | function(saving)
{
if ( !isObject( saving ) )
{
return false;
}
for (var prop in saving)
{
if ( !this.ignoredFields[ prop ] )
{
return true;
}
}
return false;
} | [
"function",
"(",
"saving",
")",
"{",
"if",
"(",
"!",
"isObject",
"(",
"saving",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"var",
"prop",
"in",
"saving",
")",
"{",
"if",
"(",
"!",
"this",
".",
"ignoredFields",
"[",
"prop",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines whether the given object has data to save | [
"Determines",
"whether",
"the",
"given",
"object",
"has",
"data",
"to",
"save"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L4051-L4067 | train |
|
Rekord/rekord | build/rekord.js | function(input, callback, context, remoteData)
{
var db = this;
var promise = new Promise();
promise.success( callback, context || db );
function checkModel()
{
var result = db.parseModel( input, remoteData );
if ( result !== false && !promise.isComplete() && db.initialized )
{
var remoteLoaded = db.remoteLoaded || !db.hasLoad( Load.All );
var missingModel = (result === null || !result.$isSaved());
var lazyLoad = db.hasLoad( Load.Lazy );
if ( lazyLoad && remoteLoaded && missingModel )
{
if ( !result )
{
result = db.keyHandler.buildObjectFromKey( db.keyHandler.buildKeyFromInput( input ) );
}
result.$once( Model.Events.RemoteGets, function()
{
if ( !promise.isComplete() )
{
if ( isObject( input ) )
{
result.$set( input );
}
promise.resolve( result.$isSaved() ? result : null );
}
});
result.$refresh( Cascade.All, db.fetchOptions );
}
else
{
promise.resolve( result );
}
}
return promise.isComplete() ? false : true;
}
if ( checkModel() )
{
db.ready( checkModel, db, true );
}
return promise;
} | javascript | function(input, callback, context, remoteData)
{
var db = this;
var promise = new Promise();
promise.success( callback, context || db );
function checkModel()
{
var result = db.parseModel( input, remoteData );
if ( result !== false && !promise.isComplete() && db.initialized )
{
var remoteLoaded = db.remoteLoaded || !db.hasLoad( Load.All );
var missingModel = (result === null || !result.$isSaved());
var lazyLoad = db.hasLoad( Load.Lazy );
if ( lazyLoad && remoteLoaded && missingModel )
{
if ( !result )
{
result = db.keyHandler.buildObjectFromKey( db.keyHandler.buildKeyFromInput( input ) );
}
result.$once( Model.Events.RemoteGets, function()
{
if ( !promise.isComplete() )
{
if ( isObject( input ) )
{
result.$set( input );
}
promise.resolve( result.$isSaved() ? result : null );
}
});
result.$refresh( Cascade.All, db.fetchOptions );
}
else
{
promise.resolve( result );
}
}
return promise.isComplete() ? false : true;
}
if ( checkModel() )
{
db.ready( checkModel, db, true );
}
return promise;
} | [
"function",
"(",
"input",
",",
"callback",
",",
"context",
",",
"remoteData",
")",
"{",
"var",
"db",
"=",
"this",
";",
"var",
"promise",
"=",
"new",
"Promise",
"(",
")",
";",
"promise",
".",
"success",
"(",
"callback",
",",
"context",
"||",
"db",
")",
";",
"function",
"checkModel",
"(",
")",
"{",
"var",
"result",
"=",
"db",
".",
"parseModel",
"(",
"input",
",",
"remoteData",
")",
";",
"if",
"(",
"result",
"!==",
"false",
"&&",
"!",
"promise",
".",
"isComplete",
"(",
")",
"&&",
"db",
".",
"initialized",
")",
"{",
"var",
"remoteLoaded",
"=",
"db",
".",
"remoteLoaded",
"||",
"!",
"db",
".",
"hasLoad",
"(",
"Load",
".",
"All",
")",
";",
"var",
"missingModel",
"=",
"(",
"result",
"===",
"null",
"||",
"!",
"result",
".",
"$isSaved",
"(",
")",
")",
";",
"var",
"lazyLoad",
"=",
"db",
".",
"hasLoad",
"(",
"Load",
".",
"Lazy",
")",
";",
"if",
"(",
"lazyLoad",
"&&",
"remoteLoaded",
"&&",
"missingModel",
")",
"{",
"if",
"(",
"!",
"result",
")",
"{",
"result",
"=",
"db",
".",
"keyHandler",
".",
"buildObjectFromKey",
"(",
"db",
".",
"keyHandler",
".",
"buildKeyFromInput",
"(",
"input",
")",
")",
";",
"}",
"result",
".",
"$once",
"(",
"Model",
".",
"Events",
".",
"RemoteGets",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"promise",
".",
"isComplete",
"(",
")",
")",
"{",
"if",
"(",
"isObject",
"(",
"input",
")",
")",
"{",
"result",
".",
"$set",
"(",
"input",
")",
";",
"}",
"promise",
".",
"resolve",
"(",
"result",
".",
"$isSaved",
"(",
")",
"?",
"result",
":",
"null",
")",
";",
"}",
"}",
")",
";",
"result",
".",
"$refresh",
"(",
"Cascade",
".",
"All",
",",
"db",
".",
"fetchOptions",
")",
";",
"}",
"else",
"{",
"promise",
".",
"resolve",
"(",
"result",
")",
";",
"}",
"}",
"return",
"promise",
".",
"isComplete",
"(",
")",
"?",
"false",
":",
"true",
";",
"}",
"if",
"(",
"checkModel",
"(",
")",
")",
"{",
"db",
".",
"ready",
"(",
"checkModel",
",",
"db",
",",
"true",
")",
";",
"}",
"return",
"promise",
";",
"}"
] | Grab a model with the given input and notify the callback | [
"Grab",
"a",
"model",
"with",
"the",
"given",
"input",
"and",
"notify",
"the",
"callback"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L4070-L4124 | train |
|
Rekord/rekord | build/rekord.js | function(revision)
{
if ( isFunction( revision ) )
{
this.revisionFunction = revision;
}
else if ( isString( revision ) )
{
this.revisionFunction = function(a, b)
{
var ar = isObject( a ) && revision in a ? a[ revision ] : undefined;
var br = isObject( b ) && revision in b ? b[ revision ] : undefined;
return ar === undefined || br === undefined ? false : compare( ar, br ) > 0;
};
}
else
{
this.revisionFunction = function(a, b)
{
return false;
};
}
} | javascript | function(revision)
{
if ( isFunction( revision ) )
{
this.revisionFunction = revision;
}
else if ( isString( revision ) )
{
this.revisionFunction = function(a, b)
{
var ar = isObject( a ) && revision in a ? a[ revision ] : undefined;
var br = isObject( b ) && revision in b ? b[ revision ] : undefined;
return ar === undefined || br === undefined ? false : compare( ar, br ) > 0;
};
}
else
{
this.revisionFunction = function(a, b)
{
return false;
};
}
} | [
"function",
"(",
"revision",
")",
"{",
"if",
"(",
"isFunction",
"(",
"revision",
")",
")",
"{",
"this",
".",
"revisionFunction",
"=",
"revision",
";",
"}",
"else",
"if",
"(",
"isString",
"(",
"revision",
")",
")",
"{",
"this",
".",
"revisionFunction",
"=",
"function",
"(",
"a",
",",
"b",
")",
"{",
"var",
"ar",
"=",
"isObject",
"(",
"a",
")",
"&&",
"revision",
"in",
"a",
"?",
"a",
"[",
"revision",
"]",
":",
"undefined",
";",
"var",
"br",
"=",
"isObject",
"(",
"b",
")",
"&&",
"revision",
"in",
"b",
"?",
"b",
"[",
"revision",
"]",
":",
"undefined",
";",
"return",
"ar",
"===",
"undefined",
"||",
"br",
"===",
"undefined",
"?",
"false",
":",
"compare",
"(",
"ar",
",",
"br",
")",
">",
"0",
";",
"}",
";",
"}",
"else",
"{",
"this",
".",
"revisionFunction",
"=",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"false",
";",
"}",
";",
"}",
"}"
] | Sets a revision comparision function for this database. It can be a field name or a function. This is used to avoid updating model data that is older than the model's current data. | [
"Sets",
"a",
"revision",
"comparision",
"function",
"for",
"this",
"database",
".",
"It",
"can",
"be",
"a",
"field",
"name",
"or",
"a",
"function",
".",
"This",
"is",
"used",
"to",
"avoid",
"updating",
"model",
"data",
"that",
"is",
"older",
"than",
"the",
"model",
"s",
"current",
"data",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L4216-L4239 | train |
|
Rekord/rekord | build/rekord.js | function(key)
{
var db = this;
var model = db.all[ key ];
if ( db.cache === Cache.All )
{
return db.destroyLocalCachedModel( model, key );
}
else
{
return db.destroyLocalUncachedModel( model, key );
}
} | javascript | function(key)
{
var db = this;
var model = db.all[ key ];
if ( db.cache === Cache.All )
{
return db.destroyLocalCachedModel( model, key );
}
else
{
return db.destroyLocalUncachedModel( model, key );
}
} | [
"function",
"(",
"key",
")",
"{",
"var",
"db",
"=",
"this",
";",
"var",
"model",
"=",
"db",
".",
"all",
"[",
"key",
"]",
";",
"if",
"(",
"db",
".",
"cache",
"===",
"Cache",
".",
"All",
")",
"{",
"return",
"db",
".",
"destroyLocalCachedModel",
"(",
"model",
",",
"key",
")",
";",
"}",
"else",
"{",
"return",
"db",
".",
"destroyLocalUncachedModel",
"(",
"model",
",",
"key",
")",
";",
"}",
"}"
] | Destroys a model locally because it doesn't exist remotely | [
"Destroys",
"a",
"model",
"locally",
"because",
"it",
"doesn",
"t",
"exist",
"remotely"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L4626-L4639 | train |
|
Rekord/rekord | build/rekord.js | function(callback, context)
{
var db = this;
var promise = new Promise();
var success = this.handleRefreshSuccess( promise );
var failure = this.handleRefreshFailure( promise );
promise.complete( callback, context || db );
batchExecute(function()
{
db.executeRefresh( success, failure );
});
return promise;
} | javascript | function(callback, context)
{
var db = this;
var promise = new Promise();
var success = this.handleRefreshSuccess( promise );
var failure = this.handleRefreshFailure( promise );
promise.complete( callback, context || db );
batchExecute(function()
{
db.executeRefresh( success, failure );
});
return promise;
} | [
"function",
"(",
"callback",
",",
"context",
")",
"{",
"var",
"db",
"=",
"this",
";",
"var",
"promise",
"=",
"new",
"Promise",
"(",
")",
";",
"var",
"success",
"=",
"this",
".",
"handleRefreshSuccess",
"(",
"promise",
")",
";",
"var",
"failure",
"=",
"this",
".",
"handleRefreshFailure",
"(",
"promise",
")",
";",
"promise",
".",
"complete",
"(",
"callback",
",",
"context",
"||",
"db",
")",
";",
"batchExecute",
"(",
"function",
"(",
")",
"{",
"db",
".",
"executeRefresh",
"(",
"success",
",",
"failure",
")",
";",
"}",
")",
";",
"return",
"promise",
";",
"}"
] | Loads all data remotely | [
"Loads",
"all",
"data",
"remotely"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L4904-L4919 | train |
|
Rekord/rekord | build/rekord.js | function(model, cascade, options)
{
var db = this;
if ( model.$isDeleted() )
{
Rekord.debug( Rekord.Debugs.SAVE_DELETED, db, model );
return;
}
var key = model.$key();
var existing = db.models.has( key );
if ( existing )
{
db.trigger( Database.Events.ModelUpdated, [model] );
model.$trigger( Model.Events.UpdateAndSave );
}
else
{
db.saveReference( model, key );
db.trigger( Database.Events.ModelAdded, [model] );
db.updated();
model.$trigger( Model.Events.CreateAndSave );
}
model.$addOperation( SaveLocal, cascade, options );
} | javascript | function(model, cascade, options)
{
var db = this;
if ( model.$isDeleted() )
{
Rekord.debug( Rekord.Debugs.SAVE_DELETED, db, model );
return;
}
var key = model.$key();
var existing = db.models.has( key );
if ( existing )
{
db.trigger( Database.Events.ModelUpdated, [model] );
model.$trigger( Model.Events.UpdateAndSave );
}
else
{
db.saveReference( model, key );
db.trigger( Database.Events.ModelAdded, [model] );
db.updated();
model.$trigger( Model.Events.CreateAndSave );
}
model.$addOperation( SaveLocal, cascade, options );
} | [
"function",
"(",
"model",
",",
"cascade",
",",
"options",
")",
"{",
"var",
"db",
"=",
"this",
";",
"if",
"(",
"model",
".",
"$isDeleted",
"(",
")",
")",
"{",
"Rekord",
".",
"debug",
"(",
"Rekord",
".",
"Debugs",
".",
"SAVE_DELETED",
",",
"db",
",",
"model",
")",
";",
"return",
";",
"}",
"var",
"key",
"=",
"model",
".",
"$key",
"(",
")",
";",
"var",
"existing",
"=",
"db",
".",
"models",
".",
"has",
"(",
"key",
")",
";",
"if",
"(",
"existing",
")",
"{",
"db",
".",
"trigger",
"(",
"Database",
".",
"Events",
".",
"ModelUpdated",
",",
"[",
"model",
"]",
")",
";",
"model",
".",
"$trigger",
"(",
"Model",
".",
"Events",
".",
"UpdateAndSave",
")",
";",
"}",
"else",
"{",
"db",
".",
"saveReference",
"(",
"model",
",",
"key",
")",
";",
"db",
".",
"trigger",
"(",
"Database",
".",
"Events",
".",
"ModelAdded",
",",
"[",
"model",
"]",
")",
";",
"db",
".",
"updated",
"(",
")",
";",
"model",
".",
"$trigger",
"(",
"Model",
".",
"Events",
".",
"CreateAndSave",
")",
";",
"}",
"model",
".",
"$addOperation",
"(",
"SaveLocal",
",",
"cascade",
",",
"options",
")",
";",
"}"
] | Save the model | [
"Save",
"the",
"model"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L5020-L5050 | train |
|
Rekord/rekord | build/rekord.js | function(model, cascade, options)
{
var db = this;
// If we have it in the models, remove it!
this.removeFromModels( model );
// If we're offline and we have a pending save - cancel the pending save.
if ( model.$status === Model.Status.SavePending )
{
Rekord.debug( Rekord.Debugs.REMOVE_CANCEL_SAVE, db, model );
}
model.$status = Model.Status.RemovePending;
model.$addOperation( RemoveLocal, cascade, options );
} | javascript | function(model, cascade, options)
{
var db = this;
// If we have it in the models, remove it!
this.removeFromModels( model );
// If we're offline and we have a pending save - cancel the pending save.
if ( model.$status === Model.Status.SavePending )
{
Rekord.debug( Rekord.Debugs.REMOVE_CANCEL_SAVE, db, model );
}
model.$status = Model.Status.RemovePending;
model.$addOperation( RemoveLocal, cascade, options );
} | [
"function",
"(",
"model",
",",
"cascade",
",",
"options",
")",
"{",
"var",
"db",
"=",
"this",
";",
"this",
".",
"removeFromModels",
"(",
"model",
")",
";",
"if",
"(",
"model",
".",
"$status",
"===",
"Model",
".",
"Status",
".",
"SavePending",
")",
"{",
"Rekord",
".",
"debug",
"(",
"Rekord",
".",
"Debugs",
".",
"REMOVE_CANCEL_SAVE",
",",
"db",
",",
"model",
")",
";",
"}",
"model",
".",
"$status",
"=",
"Model",
".",
"Status",
".",
"RemovePending",
";",
"model",
".",
"$addOperation",
"(",
"RemoveLocal",
",",
"cascade",
",",
"options",
")",
";",
"}"
] | Remove the model | [
"Remove",
"the",
"model"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L5053-L5069 | train |
|
Rekord/rekord | build/rekord.js | function(key, value)
{
if ( key in this.indices )
{
this.values[ this.indices[ key ] ] = value;
}
else
{
this.indices[ key ] = this.values.length;
AP.push.call( this.values, value );
AP.push.call( this.keys, key );
}
return this;
} | javascript | function(key, value)
{
if ( key in this.indices )
{
this.values[ this.indices[ key ] ] = value;
}
else
{
this.indices[ key ] = this.values.length;
AP.push.call( this.values, value );
AP.push.call( this.keys, key );
}
return this;
} | [
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"key",
"in",
"this",
".",
"indices",
")",
"{",
"this",
".",
"values",
"[",
"this",
".",
"indices",
"[",
"key",
"]",
"]",
"=",
"value",
";",
"}",
"else",
"{",
"this",
".",
"indices",
"[",
"key",
"]",
"=",
"this",
".",
"values",
".",
"length",
";",
"AP",
".",
"push",
".",
"call",
"(",
"this",
".",
"values",
",",
"value",
")",
";",
"AP",
".",
"push",
".",
"call",
"(",
"this",
".",
"keys",
",",
"key",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Puts the value in the map by the given key.
@param {String} key
@param {V} value
@return {Rekord.Map} -
The reference to this map. | [
"Puts",
"the",
"value",
"in",
"the",
"map",
"by",
"the",
"given",
"key",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6087-L6101 | train |
|
Rekord/rekord | build/rekord.js | function(index)
{
var key = this.keys[ index ];
var lastValue = AP.pop.apply( this.values );
var lastKey = AP.pop.apply( this.keys );
if ( index < this.values.length )
{
this.values[ index ] = lastValue;
this.keys[ index ] = lastKey;
this.indices[ lastKey ] = index;
}
delete this.indices[ key ];
return this;
} | javascript | function(index)
{
var key = this.keys[ index ];
var lastValue = AP.pop.apply( this.values );
var lastKey = AP.pop.apply( this.keys );
if ( index < this.values.length )
{
this.values[ index ] = lastValue;
this.keys[ index ] = lastKey;
this.indices[ lastKey ] = index;
}
delete this.indices[ key ];
return this;
} | [
"function",
"(",
"index",
")",
"{",
"var",
"key",
"=",
"this",
".",
"keys",
"[",
"index",
"]",
";",
"var",
"lastValue",
"=",
"AP",
".",
"pop",
".",
"apply",
"(",
"this",
".",
"values",
")",
";",
"var",
"lastKey",
"=",
"AP",
".",
"pop",
".",
"apply",
"(",
"this",
".",
"keys",
")",
";",
"if",
"(",
"index",
"<",
"this",
".",
"values",
".",
"length",
")",
"{",
"this",
".",
"values",
"[",
"index",
"]",
"=",
"lastValue",
";",
"this",
".",
"keys",
"[",
"index",
"]",
"=",
"lastKey",
";",
"this",
".",
"indices",
"[",
"lastKey",
"]",
"=",
"index",
";",
"}",
"delete",
"this",
".",
"indices",
"[",
"key",
"]",
";",
"return",
"this",
";",
"}"
] | Removes the value & key at the given index.
@param {Number} index
@return {Rekord.Map} -
The reference to this map. | [
"Removes",
"the",
"value",
"&",
"key",
"at",
"the",
"given",
"index",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6140-L6156 | train |
|
Rekord/rekord | build/rekord.js | function(callback, dest)
{
var out = dest || new Map();
var n = this.size();
var values = this.values;
var keys = this.keys;
for (var i = 0; i < n; i++)
{
var v = values[ i ];
var k = keys[ i ];
if ( callback( v, k ) )
{
out.put( k, v );
}
}
return out;
} | javascript | function(callback, dest)
{
var out = dest || new Map();
var n = this.size();
var values = this.values;
var keys = this.keys;
for (var i = 0; i < n; i++)
{
var v = values[ i ];
var k = keys[ i ];
if ( callback( v, k ) )
{
out.put( k, v );
}
}
return out;
} | [
"function",
"(",
"callback",
",",
"dest",
")",
"{",
"var",
"out",
"=",
"dest",
"||",
"new",
"Map",
"(",
")",
";",
"var",
"n",
"=",
"this",
".",
"size",
"(",
")",
";",
"var",
"values",
"=",
"this",
".",
"values",
";",
"var",
"keys",
"=",
"this",
".",
"keys",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"var",
"v",
"=",
"values",
"[",
"i",
"]",
";",
"var",
"k",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"callback",
"(",
"v",
",",
"k",
")",
")",
"{",
"out",
".",
"put",
"(",
"k",
",",
"v",
")",
";",
"}",
"}",
"return",
"out",
";",
"}"
] | Passes all values & keys in this map to a callback and if it returns a
truthy value then the key and value are placed in the destination map.
@param {Function} callback [description]
@param {Rekord.Map} [dest] [description]
@return {Rekord.Map} [description] | [
"Passes",
"all",
"values",
"&",
"keys",
"in",
"this",
"map",
"to",
"a",
"callback",
"and",
"if",
"it",
"returns",
"a",
"truthy",
"value",
"then",
"the",
"key",
"and",
"value",
"are",
"placed",
"in",
"the",
"destination",
"map",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6208-L6227 | train |
|
Rekord/rekord | build/rekord.js | function(comparator)
{
var map = this;
// Sort this partition!
function partition(left, right)
{
var pivot = map.values[ Math.floor((right + left) / 2) ];
var i = left;
var j = right;
while (i <= j)
{
while (comparator( map.values[i], pivot ) < 0)
{
i++;
}
while (comparator( map.values[j], pivot ) > 0)
{
j--;
}
if (i <= j)
{
swap( map.values, i, j );
swap( map.keys, i, j );
i++;
j--;
}
}
return i;
}
// Quicksort
function qsort(left, right)
{
var index = partition( left, right );
if (left < index - 1)
{
qsort( left, index - 1 );
}
if (index < right)
{
qsort( index, right );
}
}
var right = this.size() - 1;
// Are there elements to sort?
if ( right > 0 )
{
qsort( 0, right );
this.rebuildIndex();
}
return this;
} | javascript | function(comparator)
{
var map = this;
// Sort this partition!
function partition(left, right)
{
var pivot = map.values[ Math.floor((right + left) / 2) ];
var i = left;
var j = right;
while (i <= j)
{
while (comparator( map.values[i], pivot ) < 0)
{
i++;
}
while (comparator( map.values[j], pivot ) > 0)
{
j--;
}
if (i <= j)
{
swap( map.values, i, j );
swap( map.keys, i, j );
i++;
j--;
}
}
return i;
}
// Quicksort
function qsort(left, right)
{
var index = partition( left, right );
if (left < index - 1)
{
qsort( left, index - 1 );
}
if (index < right)
{
qsort( index, right );
}
}
var right = this.size() - 1;
// Are there elements to sort?
if ( right > 0 )
{
qsort( 0, right );
this.rebuildIndex();
}
return this;
} | [
"function",
"(",
"comparator",
")",
"{",
"var",
"map",
"=",
"this",
";",
"function",
"partition",
"(",
"left",
",",
"right",
")",
"{",
"var",
"pivot",
"=",
"map",
".",
"values",
"[",
"Math",
".",
"floor",
"(",
"(",
"right",
"+",
"left",
")",
"/",
"2",
")",
"]",
";",
"var",
"i",
"=",
"left",
";",
"var",
"j",
"=",
"right",
";",
"while",
"(",
"i",
"<=",
"j",
")",
"{",
"while",
"(",
"comparator",
"(",
"map",
".",
"values",
"[",
"i",
"]",
",",
"pivot",
")",
"<",
"0",
")",
"{",
"i",
"++",
";",
"}",
"while",
"(",
"comparator",
"(",
"map",
".",
"values",
"[",
"j",
"]",
",",
"pivot",
")",
">",
"0",
")",
"{",
"j",
"--",
";",
"}",
"if",
"(",
"i",
"<=",
"j",
")",
"{",
"swap",
"(",
"map",
".",
"values",
",",
"i",
",",
"j",
")",
";",
"swap",
"(",
"map",
".",
"keys",
",",
"i",
",",
"j",
")",
";",
"i",
"++",
";",
"j",
"--",
";",
"}",
"}",
"return",
"i",
";",
"}",
"function",
"qsort",
"(",
"left",
",",
"right",
")",
"{",
"var",
"index",
"=",
"partition",
"(",
"left",
",",
"right",
")",
";",
"if",
"(",
"left",
"<",
"index",
"-",
"1",
")",
"{",
"qsort",
"(",
"left",
",",
"index",
"-",
"1",
")",
";",
"}",
"if",
"(",
"index",
"<",
"right",
")",
"{",
"qsort",
"(",
"index",
",",
"right",
")",
";",
"}",
"}",
"var",
"right",
"=",
"this",
".",
"size",
"(",
")",
"-",
"1",
";",
"if",
"(",
"right",
">",
"0",
")",
"{",
"qsort",
"(",
"0",
",",
"right",
")",
";",
"this",
".",
"rebuildIndex",
"(",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Sorts the underlying values & keys given a value compare function.
@param {function} comparator
A function which accepts two values and returns a number used for
sorting. If the first argument is less than the second argument, a
negative number should be returned. If the arguments are equivalent
then 0 should be returned, otherwise a positive number should be
returned.
@return {Map} -
The reference to this map. | [
"Sorts",
"the",
"underlying",
"values",
"&",
"keys",
"given",
"a",
"value",
"compare",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6267-L6328 | train |
|
Rekord/rekord | build/rekord.js | partition | function partition(left, right)
{
var pivot = map.values[ Math.floor((right + left) / 2) ];
var i = left;
var j = right;
while (i <= j)
{
while (comparator( map.values[i], pivot ) < 0)
{
i++;
}
while (comparator( map.values[j], pivot ) > 0)
{
j--;
}
if (i <= j)
{
swap( map.values, i, j );
swap( map.keys, i, j );
i++;
j--;
}
}
return i;
} | javascript | function partition(left, right)
{
var pivot = map.values[ Math.floor((right + left) / 2) ];
var i = left;
var j = right;
while (i <= j)
{
while (comparator( map.values[i], pivot ) < 0)
{
i++;
}
while (comparator( map.values[j], pivot ) > 0)
{
j--;
}
if (i <= j)
{
swap( map.values, i, j );
swap( map.keys, i, j );
i++;
j--;
}
}
return i;
} | [
"function",
"partition",
"(",
"left",
",",
"right",
")",
"{",
"var",
"pivot",
"=",
"map",
".",
"values",
"[",
"Math",
".",
"floor",
"(",
"(",
"right",
"+",
"left",
")",
"/",
"2",
")",
"]",
";",
"var",
"i",
"=",
"left",
";",
"var",
"j",
"=",
"right",
";",
"while",
"(",
"i",
"<=",
"j",
")",
"{",
"while",
"(",
"comparator",
"(",
"map",
".",
"values",
"[",
"i",
"]",
",",
"pivot",
")",
"<",
"0",
")",
"{",
"i",
"++",
";",
"}",
"while",
"(",
"comparator",
"(",
"map",
".",
"values",
"[",
"j",
"]",
",",
"pivot",
")",
">",
"0",
")",
"{",
"j",
"--",
";",
"}",
"if",
"(",
"i",
"<=",
"j",
")",
"{",
"swap",
"(",
"map",
".",
"values",
",",
"i",
",",
"j",
")",
";",
"swap",
"(",
"map",
".",
"keys",
",",
"i",
",",
"j",
")",
";",
"i",
"++",
";",
"j",
"--",
";",
"}",
"}",
"return",
"i",
";",
"}"
] | Sort this partition! | [
"Sort",
"this",
"partition!"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6272-L6299 | train |
Rekord/rekord | build/rekord.js | function()
{
this.indices = {};
for (var i = 0, l = this.keys.length; i < l; i++)
{
this.indices[ this.keys[ i ] ] = i;
}
return this;
} | javascript | function()
{
this.indices = {};
for (var i = 0, l = this.keys.length; i < l; i++)
{
this.indices[ this.keys[ i ] ] = i;
}
return this;
} | [
"function",
"(",
")",
"{",
"this",
".",
"indices",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"this",
".",
"keys",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"this",
".",
"indices",
"[",
"this",
".",
"keys",
"[",
"i",
"]",
"]",
"=",
"i",
";",
"}",
"return",
"this",
";",
"}"
] | Rebuilds the index based on the keys.
@return {Rekord.Map} -
The reference to this map. | [
"Rebuilds",
"the",
"index",
"based",
"on",
"the",
"keys",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6336-L6346 | train |
|
Rekord/rekord | build/rekord.js | function(out)
{
var target = out || {};
var keys = this.keys;
var values = this.values;
for (var i = 0; i < keys.length; i++)
{
target[ keys[ i ] ] = values[ i ];
}
return target;
} | javascript | function(out)
{
var target = out || {};
var keys = this.keys;
var values = this.values;
for (var i = 0; i < keys.length; i++)
{
target[ keys[ i ] ] = values[ i ];
}
return target;
} | [
"function",
"(",
"out",
")",
"{",
"var",
"target",
"=",
"out",
"||",
"{",
"}",
";",
"var",
"keys",
"=",
"this",
".",
"keys",
";",
"var",
"values",
"=",
"this",
".",
"values",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"keys",
".",
"length",
";",
"i",
"++",
")",
"{",
"target",
"[",
"keys",
"[",
"i",
"]",
"]",
"=",
"values",
"[",
"i",
"]",
";",
"}",
"return",
"target",
";",
"}"
] | Builds an object contain the keys and values in this map.
@return {Object} -
The built object. | [
"Builds",
"an",
"object",
"contain",
"the",
"keys",
"and",
"values",
"in",
"this",
"map",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L6354-L6366 | train |
|
Rekord/rekord | build/rekord.js | function(comparator, nullsFirst)
{
var cmp = comparator ? createComparator( comparator, nullsFirst ) : this.comparator;
return isSorted( cmp, this );
} | javascript | function(comparator, nullsFirst)
{
var cmp = comparator ? createComparator( comparator, nullsFirst ) : this.comparator;
return isSorted( cmp, this );
} | [
"function",
"(",
"comparator",
",",
"nullsFirst",
")",
"{",
"var",
"cmp",
"=",
"comparator",
"?",
"createComparator",
"(",
"comparator",
",",
"nullsFirst",
")",
":",
"this",
".",
"comparator",
";",
"return",
"isSorted",
"(",
"cmp",
",",
"this",
")",
";",
"}"
] | Determines if the collection is currently sorted based on the current
comparator of the collection unless a comparator is given
@method
@memberof Rekord.Collection#
@param {ComparatorInput} [comparator] -
The comparator input to convert to a comparison function.
@param {Boolean} [nullsFirst=false] -
When a comparison is done involving a null/undefined value this can
determine which is ordered before the other.
@see Rekord.createComparator
@return {Boolean} | [
"Determines",
"if",
"the",
"collection",
"is",
"currently",
"sorted",
"based",
"on",
"the",
"current",
"comparator",
"of",
"the",
"collection",
"unless",
"a",
"comparator",
"is",
"given"
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L7610-L7615 | train |
|
Rekord/rekord | build/rekord.js | function(comparator, nullsFirst, ignorePrimitive)
{
var cmp = comparator ? createComparator( comparator, nullsFirst ) : this.comparator;
if ( !isSorted( cmp, this ) || ( !ignorePrimitive && !cmp && isPrimitiveArray( this ) ) )
{
AP.sort.call( this, cmp );
this.trigger( Collection.Events.Sort, [this] );
}
return this;
} | javascript | function(comparator, nullsFirst, ignorePrimitive)
{
var cmp = comparator ? createComparator( comparator, nullsFirst ) : this.comparator;
if ( !isSorted( cmp, this ) || ( !ignorePrimitive && !cmp && isPrimitiveArray( this ) ) )
{
AP.sort.call( this, cmp );
this.trigger( Collection.Events.Sort, [this] );
}
return this;
} | [
"function",
"(",
"comparator",
",",
"nullsFirst",
",",
"ignorePrimitive",
")",
"{",
"var",
"cmp",
"=",
"comparator",
"?",
"createComparator",
"(",
"comparator",
",",
"nullsFirst",
")",
":",
"this",
".",
"comparator",
";",
"if",
"(",
"!",
"isSorted",
"(",
"cmp",
",",
"this",
")",
"||",
"(",
"!",
"ignorePrimitive",
"&&",
"!",
"cmp",
"&&",
"isPrimitiveArray",
"(",
"this",
")",
")",
")",
"{",
"AP",
".",
"sort",
".",
"call",
"(",
"this",
",",
"cmp",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Sort",
",",
"[",
"this",
"]",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Sorts the elements in this collection based on the current comparator
unless a comparator is given. If a comparator is given it will not override
the current comparator, subsequent operations to the collection may trigger
a sort if the collection has a comparator.
@method
@memberof Rekord.Collection#
@param {ComparatorInput} [comparator] -
The comparator input to convert to a comparison function.
@param {Boolean} [nullsFirst=false] -
When a comparison is done involving a null/undefined value this can
determine which is ordered before the other.
@param {Boolean} [ignorePrimitive=false] -
Sorting is automatically done for non-primitive collections if a
comparator exists. This flag ensures primitive collections aren't sorted
after every operation.
@return {Rekord.Collection} -
The reference to this collection.
@emits Rekord.Collection#sort
@see Rekord.createComparator | [
"Sorts",
"the",
"elements",
"in",
"this",
"collection",
"based",
"on",
"the",
"current",
"comparator",
"unless",
"a",
"comparator",
"is",
"given",
".",
"If",
"a",
"comparator",
"is",
"given",
"it",
"will",
"not",
"override",
"the",
"current",
"comparator",
"subsequent",
"operations",
"to",
"the",
"collection",
"may",
"trigger",
"a",
"sort",
"if",
"the",
"collection",
"has",
"a",
"comparator",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L7639-L7651 | train |
|
Rekord/rekord | build/rekord.js | function(values)
{
this.length = 0;
if ( isArray( values ) )
{
AP.push.apply( this, values );
}
else if ( isValue( values ) )
{
AP.push.call( this, values );
}
this.trigger( Collection.Events.Reset, [this] );
this.sort( undefined, undefined, true );
return this;
} | javascript | function(values)
{
this.length = 0;
if ( isArray( values ) )
{
AP.push.apply( this, values );
}
else if ( isValue( values ) )
{
AP.push.call( this, values );
}
this.trigger( Collection.Events.Reset, [this] );
this.sort( undefined, undefined, true );
return this;
} | [
"function",
"(",
"values",
")",
"{",
"this",
".",
"length",
"=",
"0",
";",
"if",
"(",
"isArray",
"(",
"values",
")",
")",
"{",
"AP",
".",
"push",
".",
"apply",
"(",
"this",
",",
"values",
")",
";",
"}",
"else",
"if",
"(",
"isValue",
"(",
"values",
")",
")",
"{",
"AP",
".",
"push",
".",
"call",
"(",
"this",
",",
"values",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Reset",
",",
"[",
"this",
"]",
")",
";",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"return",
"this",
";",
"}"
] | Resets the values in this collection with a new collection of values.
@method
@memberof Rekord.Collection#
@param {Any[]} [values] -
The new array of values in this collection.
@return {Rekord.Collection} -
The reference to this collection.
@emits Rekord.Collection#reset | [
"Resets",
"the",
"values",
"in",
"this",
"collection",
"with",
"a",
"new",
"collection",
"of",
"values",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L7664-L7681 | train |
|
Rekord/rekord | build/rekord.js | function(collection, out, equals)
{
var target = out || this.cloneEmpty();
var equality = equals || equalsStrict;
for (var i = 0; i < this.length; i++)
{
var a = this[ i ];
var exists = false;
for (var j = 0; j < collection.length && !exists; j++)
{
exists = equality( a, collection[ j ] );
}
if (!exists)
{
target.push( a );
}
}
return target;
} | javascript | function(collection, out, equals)
{
var target = out || this.cloneEmpty();
var equality = equals || equalsStrict;
for (var i = 0; i < this.length; i++)
{
var a = this[ i ];
var exists = false;
for (var j = 0; j < collection.length && !exists; j++)
{
exists = equality( a, collection[ j ] );
}
if (!exists)
{
target.push( a );
}
}
return target;
} | [
"function",
"(",
"collection",
",",
"out",
",",
"equals",
")",
"{",
"var",
"target",
"=",
"out",
"||",
"this",
".",
"cloneEmpty",
"(",
")",
";",
"var",
"equality",
"=",
"equals",
"||",
"equalsStrict",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"a",
"=",
"this",
"[",
"i",
"]",
";",
"var",
"exists",
"=",
"false",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"collection",
".",
"length",
"&&",
"!",
"exists",
";",
"j",
"++",
")",
"{",
"exists",
"=",
"equality",
"(",
"a",
",",
"collection",
"[",
"j",
"]",
")",
";",
"}",
"if",
"(",
"!",
"exists",
")",
"{",
"target",
".",
"push",
"(",
"a",
")",
";",
"}",
"}",
"return",
"target",
";",
"}"
] | Returns a collection with elements that exist in this collection but does
not exist in the given collection.
```javascript
var a = Rekord.collect(1, 2, 3, 4);
var b = Rekord.collect(1, 3, 5);
var c = a.subtract( b ); // [2, 4]
```
@method
@memberof Rekord.Collection#
@param {Array} collection -
The array of elements that shouldn't exist in the resulting collection.
@param {Array} [out=this.cloneEmpty()] -
The array to place the elements that exist in this collection but not in
the given collection. If this is not given - a collection of this type
will be created.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
The function which determines whether one of the elements that exist in
this collection are equivalent to an element that exists in the given
collection.
@return {Array} -
The collection of elements that exist in this collection and not the
given collection. | [
"Returns",
"a",
"collection",
"with",
"elements",
"that",
"exist",
"in",
"this",
"collection",
"but",
"does",
"not",
"exist",
"in",
"the",
"given",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L7800-L7822 | train |
|
Rekord/rekord | build/rekord.js | function()
{
var values = arguments;
AP.unshift.apply( this, values );
this.trigger( Collection.Events.Adds, [this, AP.slice.apply(values), 0] );
this.sort( undefined, undefined, true );
return this.length;
} | javascript | function()
{
var values = arguments;
AP.unshift.apply( this, values );
this.trigger( Collection.Events.Adds, [this, AP.slice.apply(values), 0] );
this.sort( undefined, undefined, true );
return this.length;
} | [
"function",
"(",
")",
"{",
"var",
"values",
"=",
"arguments",
";",
"AP",
".",
"unshift",
".",
"apply",
"(",
"this",
",",
"values",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Adds",
",",
"[",
"this",
",",
"AP",
".",
"slice",
".",
"apply",
"(",
"values",
")",
",",
"0",
"]",
")",
";",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"return",
"this",
".",
"length",
";",
"}"
] | Adds one or more elements to the beginning of this collection - sorting the
collection if a comparator is set on this collection.
```javascript
var a = Rekord.collect(1, 2, 3, 4);
a.unshift( 5, 6, 7 ); // 7
a // [5, 6, 7, 1, 2, 3, 4]
```
@method
@memberof Rekord.Collection#
@param {...Any} value -
The values to add to this collection.
@return {Number} -
The new length of this collection.
@emits Rekord.Collection#adds
@emits Rekord.Collection#sort | [
"Adds",
"one",
"or",
"more",
"elements",
"to",
"the",
"beginning",
"of",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8036-L8047 | train |
|
Rekord/rekord | build/rekord.js | function(values, delaySort)
{
if ( isArray( values ) && values.length )
{
var i = this.length;
AP.push.apply( this, values );
this.trigger( Collection.Events.Adds, [this, values, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return this;
} | javascript | function(values, delaySort)
{
if ( isArray( values ) && values.length )
{
var i = this.length;
AP.push.apply( this, values );
this.trigger( Collection.Events.Adds, [this, values, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return this;
} | [
"function",
"(",
"values",
",",
"delaySort",
")",
"{",
"if",
"(",
"isArray",
"(",
"values",
")",
"&&",
"values",
".",
"length",
")",
"{",
"var",
"i",
"=",
"this",
".",
"length",
";",
"AP",
".",
"push",
".",
"apply",
"(",
"this",
",",
"values",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Adds",
",",
"[",
"this",
",",
"values",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"}",
"return",
"this",
";",
"}"
] | Adds all elements in the given array to this collection - sorting the
collection if a comparator is set on this collection and `delaySort` is
not specified or a true value.
```javascript
var a = Rekord.collect(1, 2, 3, 4);
a.addAll( [5, 6] ); // [1, 2, 3, 4, 5, 6]
```
@method
@memberof Rekord.Collection#
@param {Any[]} values -
The values to add to this collection.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@return {Rekord.Collection} -
The reference to this collection.
@emits Rekord.Collection#adds
@emits Rekord.Collection#sort | [
"Adds",
"all",
"elements",
"in",
"the",
"given",
"array",
"to",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8071-L8088 | train |
|
Rekord/rekord | build/rekord.js | function(i, value, delaySort)
{
AP.splice.call( this, i, 0, value );
this.trigger( Collection.Events.Add, [this, value, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return this;
} | javascript | function(i, value, delaySort)
{
AP.splice.call( this, i, 0, value );
this.trigger( Collection.Events.Add, [this, value, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return this;
} | [
"function",
"(",
"i",
",",
"value",
",",
"delaySort",
")",
"{",
"AP",
".",
"splice",
".",
"call",
"(",
"this",
",",
"i",
",",
"0",
",",
"value",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Add",
",",
"[",
"this",
",",
"value",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Inserts an element into this collection at the given index - sorting the
collection if a comparator is set on this collection and `delaySort` is not
specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.insertAt( 0, 0 ); // [0, 1, 2, 3, 4]
c.insertAt( 2, 1.5 ); // [0, 1, 1.5, 2, 3, 4]
```
@method
@memberof Rekord.Collection#
@param {Number} i -
The index to insert the element at.
@param {Any} value -
The value to insert into the collection.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@return {Rekord.Collection} -
The reference to this collection.
@emits Rekord.Collection#add
@emits Rekord.Collection#sort | [
"Inserts",
"an",
"element",
"into",
"this",
"collection",
"at",
"the",
"given",
"index",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8115-L8127 | train |
|
Rekord/rekord | build/rekord.js | function(delaySort)
{
var removed = AP.pop.apply( this );
var i = this.length;
this.trigger( Collection.Events.Remove, [this, removed, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return removed;
} | javascript | function(delaySort)
{
var removed = AP.pop.apply( this );
var i = this.length;
this.trigger( Collection.Events.Remove, [this, removed, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return removed;
} | [
"function",
"(",
"delaySort",
")",
"{",
"var",
"removed",
"=",
"AP",
".",
"pop",
".",
"apply",
"(",
"this",
")",
";",
"var",
"i",
"=",
"this",
".",
"length",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removed",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"return",
"removed",
";",
"}"
] | Removes the last element in this collection and returns it - sorting the
collection if a comparator is set on this collection and `delaySort` is
no specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.pop(); // 4
```
@method
@memberof Rekord.Collection#
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@return {Any} -
The element removed from the end of the collection.
@emits Rekord.Collection#remove
@emits Rekord.Collection#sort | [
"Removes",
"the",
"last",
"element",
"in",
"this",
"collection",
"and",
"returns",
"it",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"no",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8149-L8162 | train |
|
Rekord/rekord | build/rekord.js | function(delaySort)
{
var removed = AP.shift.apply( this );
this.trigger( Collection.Events.Remove, [this, removed, 0] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return removed;
} | javascript | function(delaySort)
{
var removed = AP.shift.apply( this );
this.trigger( Collection.Events.Remove, [this, removed, 0] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
return removed;
} | [
"function",
"(",
"delaySort",
")",
"{",
"var",
"removed",
"=",
"AP",
".",
"shift",
".",
"apply",
"(",
"this",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removed",
",",
"0",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"return",
"removed",
";",
"}"
] | Removes the first element in this collection and returns it - sorting the
collection if a comparator is set on this collection and `delaySort` is
no specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.shift(); // 1
```
@method
@memberof Rekord.Collection#
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@return {Any} -
The element removed from the beginning of the collection.
@emits Rekord.Collection#remove
@emits Rekord.Collection#sort | [
"Removes",
"the",
"first",
"element",
"in",
"this",
"collection",
"and",
"returns",
"it",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"no",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8184-L8196 | train |
|
Rekord/rekord | build/rekord.js | function(i, delaySort)
{
var removing;
if (i >= 0 && i < this.length)
{
removing = this[ i ];
AP.splice.call( this, i, 1 );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return removing;
} | javascript | function(i, delaySort)
{
var removing;
if (i >= 0 && i < this.length)
{
removing = this[ i ];
AP.splice.call( this, i, 1 );
this.trigger( Collection.Events.Remove, [this, removing, i] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return removing;
} | [
"function",
"(",
"i",
",",
"delaySort",
")",
"{",
"var",
"removing",
";",
"if",
"(",
"i",
">=",
"0",
"&&",
"i",
"<",
"this",
".",
"length",
")",
"{",
"removing",
"=",
"this",
"[",
"i",
"]",
";",
"AP",
".",
"splice",
".",
"call",
"(",
"this",
",",
"i",
",",
"1",
")",
";",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Remove",
",",
"[",
"this",
",",
"removing",
",",
"i",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"}",
"return",
"removing",
";",
"}"
] | Removes the element in this collection at the given index `i` - sorting
the collection if a comparator is set on this collection and `delaySort` is
not specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.removeAt( 1 ); // 2
c.removeAt( 5 ); // undefined
c // [1, 3, 4]
```
@method
@memberof Rekord.Collection#
@param {Number} i -
The index of the element to remove.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@return {Any} -
The element removed, or undefined if the index was invalid.
@emits Rekord.Collection#remove
@emits Rekord.Collection#sort | [
"Removes",
"the",
"element",
"in",
"this",
"collection",
"at",
"the",
"given",
"index",
"i",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8222-L8240 | train |
|
Rekord/rekord | build/rekord.js | function(value, delaySort, equals)
{
var i = this.indexOf( value, equals );
var element = this[ i ];
if ( i !== -1 )
{
this.removeAt( i, delaySort );
}
return element;
} | javascript | function(value, delaySort, equals)
{
var i = this.indexOf( value, equals );
var element = this[ i ];
if ( i !== -1 )
{
this.removeAt( i, delaySort );
}
return element;
} | [
"function",
"(",
"value",
",",
"delaySort",
",",
"equals",
")",
"{",
"var",
"i",
"=",
"this",
".",
"indexOf",
"(",
"value",
",",
"equals",
")",
";",
"var",
"element",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"i",
"!==",
"-",
"1",
")",
"{",
"this",
".",
"removeAt",
"(",
"i",
",",
"delaySort",
")",
";",
"}",
"return",
"element",
";",
"}"
] | Removes the given value from this collection if it exists - sorting the
collection if a comparator is set on this collection and `delaySort` is not
specified or a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.remove( 1 ); // 1
c.remove( 5 ); // undefined
c // [2, 3, 4]
```
@method
@memberof Rekord.Collection#
@param {Any} value -
The value to remove from this collection if it exists.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
The function which determines whether one of the elements that exist in
this collection are equivalent to the given value.
@return {Any} -
The element removed from this collection.
@emits Rekord.Collection#remove
@emits Rekord.Collection#sort | [
"Removes",
"the",
"given",
"value",
"from",
"this",
"collection",
"if",
"it",
"exists",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8269-L8280 | train |
|
Rekord/rekord | build/rekord.js | function(values, delaySort, equals)
{
var removed = [];
var removedIndices = [];
if ( isArray( values ) && values.length )
{
for (var i = 0; i < values.length; i++)
{
var value = values[ i ];
var k = this.indexOf( value, equals );
if ( k !== -1 )
{
removedIndices.push( k );
removed.push( value );
}
}
removedIndices.sort();
for (var i = removedIndices.length - 1; i >= 0; i--)
{
AP.splice.call( this, removedIndices[ i ], 1 );
}
this.trigger( Collection.Events.Removes, [this, removed, removedIndices] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return removed;
} | javascript | function(values, delaySort, equals)
{
var removed = [];
var removedIndices = [];
if ( isArray( values ) && values.length )
{
for (var i = 0; i < values.length; i++)
{
var value = values[ i ];
var k = this.indexOf( value, equals );
if ( k !== -1 )
{
removedIndices.push( k );
removed.push( value );
}
}
removedIndices.sort();
for (var i = removedIndices.length - 1; i >= 0; i--)
{
AP.splice.call( this, removedIndices[ i ], 1 );
}
this.trigger( Collection.Events.Removes, [this, removed, removedIndices] );
if ( !delaySort )
{
this.sort( undefined, undefined, true );
}
}
return removed;
} | [
"function",
"(",
"values",
",",
"delaySort",
",",
"equals",
")",
"{",
"var",
"removed",
"=",
"[",
"]",
";",
"var",
"removedIndices",
"=",
"[",
"]",
";",
"if",
"(",
"isArray",
"(",
"values",
")",
"&&",
"values",
".",
"length",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"values",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"value",
"=",
"values",
"[",
"i",
"]",
";",
"var",
"k",
"=",
"this",
".",
"indexOf",
"(",
"value",
",",
"equals",
")",
";",
"if",
"(",
"k",
"!==",
"-",
"1",
")",
"{",
"removedIndices",
".",
"push",
"(",
"k",
")",
";",
"removed",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"removedIndices",
".",
"sort",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"removedIndices",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"AP",
".",
"splice",
".",
"call",
"(",
"this",
",",
"removedIndices",
"[",
"i",
"]",
",",
"1",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Removes",
",",
"[",
"this",
",",
"removed",
",",
"removedIndices",
"]",
")",
";",
"if",
"(",
"!",
"delaySort",
")",
"{",
"this",
".",
"sort",
"(",
"undefined",
",",
"undefined",
",",
"true",
")",
";",
"}",
"}",
"return",
"removed",
";",
"}"
] | Removes the given values from this collection - sorting the collection if
a comparator is set on this collection and `delaySort` is not specified or
a true value.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.removeAll( [1, 5] ); // [1]
c // [2, 3, 4]
```
@method
@memberof Rekord.Collection#
@param {Any[]} values -
The values to remove from this collection if they exist.
@param {Boolean} [delaySort=false] -
Whether automatic sorting should be delayed until the user manually
calls {@link Rekord.Collection#sort sort}.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
The function which determines whether one of the elements that exist in
this collection are equivalent to any of the given values.
@return {Any[]} -
The elements removed from this collection.
@emits Rekord.Collection#removes
@emits Rekord.Collection#sort | [
"Removes",
"the",
"given",
"values",
"from",
"this",
"collection",
"-",
"sorting",
"the",
"collection",
"if",
"a",
"comparator",
"is",
"set",
"on",
"this",
"collection",
"and",
"delaySort",
"is",
"not",
"specified",
"or",
"a",
"true",
"value",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8308-L8343 | train |
|
Rekord/rekord | build/rekord.js | function()
{
if ( AP.reverse )
{
AP.reverse.apply( this );
}
else
{
reverse( this );
}
this.trigger( Collection.Events.Updates, [this] );
return this;
} | javascript | function()
{
if ( AP.reverse )
{
AP.reverse.apply( this );
}
else
{
reverse( this );
}
this.trigger( Collection.Events.Updates, [this] );
return this;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"AP",
".",
"reverse",
")",
"{",
"AP",
".",
"reverse",
".",
"apply",
"(",
"this",
")",
";",
"}",
"else",
"{",
"reverse",
"(",
"this",
")",
";",
"}",
"this",
".",
"trigger",
"(",
"Collection",
".",
"Events",
".",
"Updates",
",",
"[",
"this",
"]",
")",
";",
"return",
"this",
";",
"}"
] | Reverses the order of elements in this collection.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.reverse(); // [4, 3, 2, 1]
```
@method
@memberof Rekord.Collection#
@return {Rekord.Collection} -
The reference to this collection.
@emits Rekord.Collection#updates | [
"Reverses",
"the",
"order",
"of",
"elements",
"in",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8468-L8482 | train |
|
Rekord/rekord | build/rekord.js | function(value, equals)
{
var equality = equals || equalsStrict;
for (var i = 0; i < this.length; i++)
{
if ( equality( value, this[ i ] ) )
{
return i;
}
}
return -1;
} | javascript | function(value, equals)
{
var equality = equals || equalsStrict;
for (var i = 0; i < this.length; i++)
{
if ( equality( value, this[ i ] ) )
{
return i;
}
}
return -1;
} | [
"function",
"(",
"value",
",",
"equals",
")",
"{",
"var",
"equality",
"=",
"equals",
"||",
"equalsStrict",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"equality",
"(",
"value",
",",
"this",
"[",
"i",
"]",
")",
")",
"{",
"return",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Returns the index of the given element in this collection or returns -1
if the element doesn't exist in this collection.
```javascript
var c = Rekord.collect(1, 2, 3, 4);
c.indexOf( 1 ); // 0
c.indexOf( 2 ); // 1
c.indexOf( 5 ); // -1
```
@method
@memberof Rekord.Collection#
@param {Any} value -
The value to search for.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
The function which determines whether one of the elements that exist in
this collection are equivalent to the given value.
@return {Number} -
The index of the element in this collection or -1 if it was not found.
@see Rekord.equals
@see Rekord.equalsStrict | [
"Returns",
"the",
"index",
"of",
"the",
"given",
"element",
"in",
"this",
"collection",
"or",
"returns",
"-",
"1",
"if",
"the",
"element",
"doesn",
"t",
"exist",
"in",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8507-L8520 | train |
|
Rekord/rekord | build/rekord.js | function(comparator, startingValue)
{
var cmp = createComparator( comparator || this.comparator, false );
var min = startingValue;
for (var i = 0; i < this.length; i++)
{
if ( cmp( min, this[i] ) > 0 )
{
min = this[i];
}
}
return min;
} | javascript | function(comparator, startingValue)
{
var cmp = createComparator( comparator || this.comparator, false );
var min = startingValue;
for (var i = 0; i < this.length; i++)
{
if ( cmp( min, this[i] ) > 0 )
{
min = this[i];
}
}
return min;
} | [
"function",
"(",
"comparator",
",",
"startingValue",
")",
"{",
"var",
"cmp",
"=",
"createComparator",
"(",
"comparator",
"||",
"this",
".",
"comparator",
",",
"false",
")",
";",
"var",
"min",
"=",
"startingValue",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cmp",
"(",
"min",
",",
"this",
"[",
"i",
"]",
")",
">",
"0",
")",
"{",
"min",
"=",
"this",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"min",
";",
"}"
] | Returns the element with the minimum value given a comparator.
```javascript
var c = Rekord.collect({age: 4}, {age: 5}, {age: 6}, {age: 3});
c.minModel('age'); // {age: 3}
c.minModel('-age'); // {age: 6}
```
@method
@memberof Rekord.Collection#
@param {comparatorInput} comparator -
The comparator which calculates the minimum model.
@param {Any} [startingValue]
The initial minimum value. If a value is specified, it's compared
against all elements in this collection until the comparator function
finds a more minimal value. If it doesn't - this is the value returned.
@return {Any} -
The minimum element in the collection given the comparator function.
@see Rekord.createComparator | [
"Returns",
"the",
"element",
"with",
"the",
"minimum",
"value",
"given",
"a",
"comparator",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8543-L8557 | train |
|
Rekord/rekord | build/rekord.js | function(comparator, startingValue)
{
var cmp = createComparator( comparator || this.comparator, true );
var max = startingValue;
for (var i = 0; i < this.length; i++)
{
if ( cmp( max, this[i] ) < 0 )
{
max = this[i];
}
}
return max;
} | javascript | function(comparator, startingValue)
{
var cmp = createComparator( comparator || this.comparator, true );
var max = startingValue;
for (var i = 0; i < this.length; i++)
{
if ( cmp( max, this[i] ) < 0 )
{
max = this[i];
}
}
return max;
} | [
"function",
"(",
"comparator",
",",
"startingValue",
")",
"{",
"var",
"cmp",
"=",
"createComparator",
"(",
"comparator",
"||",
"this",
".",
"comparator",
",",
"true",
")",
";",
"var",
"max",
"=",
"startingValue",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cmp",
"(",
"max",
",",
"this",
"[",
"i",
"]",
")",
"<",
"0",
")",
"{",
"max",
"=",
"this",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"max",
";",
"}"
] | Returns the element with the maximum value given a comparator.
```javascript
var c = Rekord.collect({age: 4}, {age: 5}, {age: 6}, {age: 3});
c.maxModel('age'); // {age: 6}
c.maxModel('-age'); // {age: 3}
```
@method
@memberof Rekord.Collection#
@param {comparatorInput} comparator -
The comparator which calculates the maximum model.
@param {Any} [startingValue] -
The initial maximum value. If a value is specified, it's compared
against all elements in this collection until the comparator function
finds a more maximal value. If it doesn't - this is the value returned.
@return {Any} -
The maximum element in the collection given the comparator function.
@see Rekord.createComparator | [
"Returns",
"the",
"element",
"with",
"the",
"maximum",
"value",
"given",
"a",
"comparator",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8580-L8594 | train |
|
Rekord/rekord | build/rekord.js | function(properties, startingValue, compareFunction)
{
var comparator = compareFunction || compare;
var resolver = createPropertyResolver( properties );
var min = startingValue;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( comparator( min, resolved, false ) > 0 )
{
min = resolved;
}
}
return min;
} | javascript | function(properties, startingValue, compareFunction)
{
var comparator = compareFunction || compare;
var resolver = createPropertyResolver( properties );
var min = startingValue;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( comparator( min, resolved, false ) > 0 )
{
min = resolved;
}
}
return min;
} | [
"function",
"(",
"properties",
",",
"startingValue",
",",
"compareFunction",
")",
"{",
"var",
"comparator",
"=",
"compareFunction",
"||",
"compare",
";",
"var",
"resolver",
"=",
"createPropertyResolver",
"(",
"properties",
")",
";",
"var",
"min",
"=",
"startingValue",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"resolved",
"=",
"resolver",
"(",
"this",
"[",
"i",
"]",
")",
";",
"if",
"(",
"comparator",
"(",
"min",
",",
"resolved",
",",
"false",
")",
">",
"0",
")",
"{",
"min",
"=",
"resolved",
";",
"}",
"}",
"return",
"min",
";",
"}"
] | Returns the minimum value for the given property expression out of all the
elements this collection.
```javascript
var c = Rekord.collect({age: 6}, {age: 5}, {notage: 5});
c.min('age'); // 5
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [properties] -
The expression which takes an element in this container and resolves a
value that can be compared to the current minimum.
@param {Any} [startingValue] -
The initial minimum value. If a value is specified, it's compared
against all elements in this collection until the comparator function
finds a more minimal value. If it doesn't - this is the value returned.
@param {compareCallback} [compareFunction=Rekord.compare] -
A comparison function to use.
@return {Any} -
The minimum value found.
@see Rekord.createPropertyResolver
@see Rekord.compare | [
"Returns",
"the",
"minimum",
"value",
"for",
"the",
"given",
"property",
"expression",
"out",
"of",
"all",
"the",
"elements",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8621-L8638 | train |
|
Rekord/rekord | build/rekord.js | function(properties, startingValue, compareFunction)
{
var comparator = compareFunction || compare;
var resolver = createPropertyResolver( properties );
var max = startingValue;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( comparator( max, resolved, true ) < 0 )
{
max = resolved;
}
}
return max;
} | javascript | function(properties, startingValue, compareFunction)
{
var comparator = compareFunction || compare;
var resolver = createPropertyResolver( properties );
var max = startingValue;
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( comparator( max, resolved, true ) < 0 )
{
max = resolved;
}
}
return max;
} | [
"function",
"(",
"properties",
",",
"startingValue",
",",
"compareFunction",
")",
"{",
"var",
"comparator",
"=",
"compareFunction",
"||",
"compare",
";",
"var",
"resolver",
"=",
"createPropertyResolver",
"(",
"properties",
")",
";",
"var",
"max",
"=",
"startingValue",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"resolved",
"=",
"resolver",
"(",
"this",
"[",
"i",
"]",
")",
";",
"if",
"(",
"comparator",
"(",
"max",
",",
"resolved",
",",
"true",
")",
"<",
"0",
")",
"{",
"max",
"=",
"resolved",
";",
"}",
"}",
"return",
"max",
";",
"}"
] | Returns the maximum value for the given property expression out of all the
elements this collection.
```javascript
var c = Rekord.collect({age: 6}, {age: 5}, {notage: 5});
c.max('age'); // 6
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [properties] -
The expression which takes an element in this container and resolves a
value that can be compared to the current maximum.
@param {Any} [startingValue] -
The initial maximum value. If a value is specified, it's compared
against all elements in this collection until the comparator function
finds a more maximal value. If it doesn't - this is the value returned.
@param {compareCallback} [compareFunction=Rekord.compare] -
A comparison function to use.
@return {Any} -
The maximum value found.
@see Rekord.createPropertyResolver
@see Rekord.compare | [
"Returns",
"the",
"maximum",
"value",
"for",
"the",
"given",
"property",
"expression",
"out",
"of",
"all",
"the",
"elements",
"this",
"collection",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8665-L8682 | train |
|
Rekord/rekord | build/rekord.js | function(whereProperties, whereValue, whereEquals)
{
var where = createWhere( whereProperties, whereValue, whereEquals );
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
if ( where( model ) )
{
return model;
}
}
return null;
} | javascript | function(whereProperties, whereValue, whereEquals)
{
var where = createWhere( whereProperties, whereValue, whereEquals );
for (var i = 0; i < this.length; i++)
{
var model = this[ i ];
if ( where( model ) )
{
return model;
}
}
return null;
} | [
"function",
"(",
"whereProperties",
",",
"whereValue",
",",
"whereEquals",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"whereProperties",
",",
"whereValue",
",",
"whereEquals",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"where",
"(",
"model",
")",
")",
"{",
"return",
"model",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the first element where the given expression is true.
```javascript
var c = Rekord.collect([{x: 5}, {y: 6}, {y: 6, age: 8}, {z: 7}]);
c.firstWhere('y', 6); // {x: 6}
c.firstWhere(); // {x: 5}
```
@method
@memberof Rekord.Collection#
@param {whereInput} [whereProperties] -
The expression used to create a function to test the elements in this
collection.
@param {Any} [whereValue] -
When the first argument is a string this argument will be treated as a
value to compare to the value of the named property on the object passed
through the filter function.
@param {equalityCallback} [whereEquals=Rekord.equalsStrict] -
An alternative function can be used to compare to values.
@return {Any} -
The first element in this collection that matches the given expression.
@see Rekord.createWhere | [
"Returns",
"the",
"first",
"element",
"where",
"the",
"given",
"expression",
"is",
"true",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8708-L8723 | train |
|
Rekord/rekord | build/rekord.js | function(properties)
{
var resolver = createPropertyResolver( properties );
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( isValue( resolved ) )
{
return resolved;
}
}
} | javascript | function(properties)
{
var resolver = createPropertyResolver( properties );
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( isValue( resolved ) )
{
return resolved;
}
}
} | [
"function",
"(",
"properties",
")",
"{",
"var",
"resolver",
"=",
"createPropertyResolver",
"(",
"properties",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"resolved",
"=",
"resolver",
"(",
"this",
"[",
"i",
"]",
")",
";",
"if",
"(",
"isValue",
"(",
"resolved",
")",
")",
"{",
"return",
"resolved",
";",
"}",
"}",
"}"
] | Returns the first non-null value in this collection given a property
expression. If no non-null values exist for the given property expression,
then undefined will be returned.
```javascript
var c = Rekord.collect([{x: 5}, {y: 6}, {y: 4}, {z: 7}]);
c.first('y'); // 6
c.first(); // {x: 5}
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [properties] -
The expression which converts one value into another.
@return {Any} -
@see Rekord.createPropertyResolver
@see Rekord.isValue | [
"Returns",
"the",
"first",
"non",
"-",
"null",
"value",
"in",
"this",
"collection",
"given",
"a",
"property",
"expression",
".",
"If",
"no",
"non",
"-",
"null",
"values",
"exist",
"for",
"the",
"given",
"property",
"expression",
"then",
"undefined",
"will",
"be",
"returned",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8744-L8757 | train |
|
Rekord/rekord | build/rekord.js | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
for (var i = this.length - 1; i >= 0; i--)
{
var model = this[ i ];
if ( where( model ) )
{
return model;
}
}
return null;
} | javascript | function(properties, value, equals)
{
var where = createWhere( properties, value, equals );
for (var i = this.length - 1; i >= 0; i--)
{
var model = this[ i ];
if ( where( model ) )
{
return model;
}
}
return null;
} | [
"function",
"(",
"properties",
",",
"value",
",",
"equals",
")",
"{",
"var",
"where",
"=",
"createWhere",
"(",
"properties",
",",
"value",
",",
"equals",
")",
";",
"for",
"(",
"var",
"i",
"=",
"this",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"model",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"where",
"(",
"model",
")",
")",
"{",
"return",
"model",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the last element where the given expression is true.
```javascript
var c = Rekord.collect([{x: 5}, {y: 6}, {y: 6, age: 8}, {z: 7}]);
c.lastWhere('y', 6); // {x: 6, age: 8}
c.lastWhere(); // {z: 7}
```
@method
@memberof Rekord.Collection#
@param {whereInput} [properties] -
The expression used to create a function to test the elements in this
collection.
@param {Any} [value] -
When the first argument is a string this argument will be treated as a
value to compare to the value of the named property on the object passed
through the filter function.
@param {equalityCallback} [equals=Rekord.equalsStrict] -
An alternative function can be used to compare to values.
@return {Any} -
The last element in this collection that matches the given expression.
@see Rekord.createWhere | [
"Returns",
"the",
"last",
"element",
"where",
"the",
"given",
"expression",
"is",
"true",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8783-L8798 | train |
|
Rekord/rekord | build/rekord.js | function(resolver, validator, process, getResult)
{
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( validator( resolved ) )
{
process( resolved );
}
}
return getResult();
} | javascript | function(resolver, validator, process, getResult)
{
for (var i = 0; i < this.length; i++)
{
var resolved = resolver( this[ i ] );
if ( validator( resolved ) )
{
process( resolved );
}
}
return getResult();
} | [
"function",
"(",
"resolver",
",",
"validator",
",",
"process",
",",
"getResult",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"resolved",
"=",
"resolver",
"(",
"this",
"[",
"i",
"]",
")",
";",
"if",
"(",
"validator",
"(",
"resolved",
")",
")",
"{",
"process",
"(",
"resolved",
")",
";",
"}",
"}",
"return",
"getResult",
"(",
")",
";",
"}"
] | Iterates over all elements in this collection and passes them through the
`resolver` function. The returned value is passed through the `validator`
function and if that returns true the resolved value is passed through the
`process` function. After iteration, the `getResult` function is executed
and the returned value is returned by this function.
@method
@memberof Rekord.Collection#
@param {Function} resolver -
The function which takes an element in this collection and returns a
value based on that element.
@param {Function} validator -
The function which takes the resolved value and determines whether it
passes some test.
@param {Function} process -
The function which is given the resolved value if it passes the test.
@param {Function} getResult -
The function which is executed at the end of iteration and the result is
is returned by this function.
@return {Any} -
The value returned by `getResult`. | [
"Iterates",
"over",
"all",
"elements",
"in",
"this",
"collection",
"and",
"passes",
"them",
"through",
"the",
"resolver",
"function",
".",
"The",
"returned",
"value",
"is",
"passed",
"through",
"the",
"validator",
"function",
"and",
"if",
"that",
"returns",
"true",
"the",
"resolved",
"value",
"is",
"passed",
"through",
"the",
"process",
"function",
".",
"After",
"iteration",
"the",
"getResult",
"function",
"is",
"executed",
"and",
"the",
"returned",
"value",
"is",
"returned",
"by",
"this",
"function",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8857-L8870 | train |
|
Rekord/rekord | build/rekord.js | function(numbers)
{
var resolver = createNumberResolver( numbers );
var result = 0;
var total = 0;
function process(x)
{
result += x;
total++;
}
function getResult()
{
return total === 0 ? 0 : result / total;
}
return this.aggregate( resolver, isNumber, process, getResult );
} | javascript | function(numbers)
{
var resolver = createNumberResolver( numbers );
var result = 0;
var total = 0;
function process(x)
{
result += x;
total++;
}
function getResult()
{
return total === 0 ? 0 : result / total;
}
return this.aggregate( resolver, isNumber, process, getResult );
} | [
"function",
"(",
"numbers",
")",
"{",
"var",
"resolver",
"=",
"createNumberResolver",
"(",
"numbers",
")",
";",
"var",
"result",
"=",
"0",
";",
"var",
"total",
"=",
"0",
";",
"function",
"process",
"(",
"x",
")",
"{",
"result",
"+=",
"x",
";",
"total",
"++",
";",
"}",
"function",
"getResult",
"(",
")",
"{",
"return",
"total",
"===",
"0",
"?",
"0",
":",
"result",
"/",
"total",
";",
"}",
"return",
"this",
".",
"aggregate",
"(",
"resolver",
",",
"isNumber",
",",
"process",
",",
"getResult",
")",
";",
"}"
] | Averages all numbers resolved from the given property expression and
returns the result.
```javascript
var c = Rekord.collect([2, 3, 4]);
c.avg(); // 3
var d = Rekord.collect([{age: 5}, {age: 4}, {age: 2}]);
d.avg('age'); // 3.66666
```
@method
@memberof Rekord.Collection#
@param {propertyResolverInput} [numbers]
The expression which converts an element in this collection to a number.
@return {Number} -
The average of all valid numbers found in this collection.
@see Rekord.createNumberResolver | [
"Averages",
"all",
"numbers",
"resolved",
"from",
"the",
"given",
"property",
"expression",
"and",
"returns",
"the",
"result",
"."
] | 6663dbedad865549a6b9bccaa9a993b2074483e6 | https://github.com/Rekord/rekord/blob/6663dbedad865549a6b9bccaa9a993b2074483e6/build/rekord.js#L8928-L8946 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.