id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
12,300
|
cyclosproject/ng-swagger-gen
|
ng-swagger-gen.js
|
operationId
|
function operationId(given, method, url, allKnown) {
var id;
var generate = given == null;
if (generate) {
id = toIdentifier(method + url);
} else {
id = toIdentifier(given);
}
var duplicated = allKnown.has(id);
if (duplicated) {
var i = 1;
while (allKnown.has(id + '_' + i)) {
i++;
}
id = id + '_' + i;
}
if (generate) {
console.warn(
"Operation '" +
method +
"' on '" +
url +
"' defines no operationId. Assuming '" +
id +
"'."
);
} else if (duplicated) {
console.warn(
"Operation '" +
method +
"' on '" +
url +
"' defines a duplicated operationId: " +
given +
'. ' +
"Assuming '" +
id +
"'."
);
}
allKnown.add(id);
return id;
}
|
javascript
|
function operationId(given, method, url, allKnown) {
var id;
var generate = given == null;
if (generate) {
id = toIdentifier(method + url);
} else {
id = toIdentifier(given);
}
var duplicated = allKnown.has(id);
if (duplicated) {
var i = 1;
while (allKnown.has(id + '_' + i)) {
i++;
}
id = id + '_' + i;
}
if (generate) {
console.warn(
"Operation '" +
method +
"' on '" +
url +
"' defines no operationId. Assuming '" +
id +
"'."
);
} else if (duplicated) {
console.warn(
"Operation '" +
method +
"' on '" +
url +
"' defines a duplicated operationId: " +
given +
'. ' +
"Assuming '" +
id +
"'."
);
}
allKnown.add(id);
return id;
}
|
[
"function",
"operationId",
"(",
"given",
",",
"method",
",",
"url",
",",
"allKnown",
")",
"{",
"var",
"id",
";",
"var",
"generate",
"=",
"given",
"==",
"null",
";",
"if",
"(",
"generate",
")",
"{",
"id",
"=",
"toIdentifier",
"(",
"method",
"+",
"url",
")",
";",
"}",
"else",
"{",
"id",
"=",
"toIdentifier",
"(",
"given",
")",
";",
"}",
"var",
"duplicated",
"=",
"allKnown",
".",
"has",
"(",
"id",
")",
";",
"if",
"(",
"duplicated",
")",
"{",
"var",
"i",
"=",
"1",
";",
"while",
"(",
"allKnown",
".",
"has",
"(",
"id",
"+",
"'_'",
"+",
"i",
")",
")",
"{",
"i",
"++",
";",
"}",
"id",
"=",
"id",
"+",
"'_'",
"+",
"i",
";",
"}",
"if",
"(",
"generate",
")",
"{",
"console",
".",
"warn",
"(",
"\"Operation '\"",
"+",
"method",
"+",
"\"' on '\"",
"+",
"url",
"+",
"\"' defines no operationId. Assuming '\"",
"+",
"id",
"+",
"\"'.\"",
")",
";",
"}",
"else",
"if",
"(",
"duplicated",
")",
"{",
"console",
".",
"warn",
"(",
"\"Operation '\"",
"+",
"method",
"+",
"\"' on '\"",
"+",
"url",
"+",
"\"' defines a duplicated operationId: \"",
"+",
"given",
"+",
"'. '",
"+",
"\"Assuming '\"",
"+",
"id",
"+",
"\"'.\"",
")",
";",
"}",
"allKnown",
".",
"add",
"(",
"id",
")",
";",
"return",
"id",
";",
"}"
] |
Returns the actual operation id, assuming the one given.
If none is given, generates one
|
[
"Returns",
"the",
"actual",
"operation",
"id",
"assuming",
"the",
"one",
"given",
".",
"If",
"none",
"is",
"given",
"generates",
"one"
] |
64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb
|
https://github.com/cyclosproject/ng-swagger-gen/blob/64fa7bab50a6ceb2b7ffd610498c97bc1377c9fb/ng-swagger-gen.js#L965-L1007
|
12,301
|
jquery-backstretch/jquery-backstretch
|
jquery.backstretch.js
|
function (image) {
for (var i = 0; i < cache.length; i++) {
if (cache[i].src === image.src) {
return cache[i];
}
}
cache.push(image);
return image;
}
|
javascript
|
function (image) {
for (var i = 0; i < cache.length; i++) {
if (cache[i].src === image.src) {
return cache[i];
}
}
cache.push(image);
return image;
}
|
[
"function",
"(",
"image",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"cache",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"cache",
"[",
"i",
"]",
".",
"src",
"===",
"image",
".",
"src",
")",
"{",
"return",
"cache",
"[",
"i",
"]",
";",
"}",
"}",
"cache",
".",
"push",
"(",
"image",
")",
";",
"return",
"image",
";",
"}"
] |
Wrapper for cache
|
[
"Wrapper",
"for",
"cache"
] |
8f0d9dc99ec6e81bf427e3988930e4b57f406f82
|
https://github.com/jquery-backstretch/jquery-backstretch/blob/8f0d9dc99ec6e81bf427e3988930e4b57f406f82/jquery.backstretch.js#L318-L326
|
|
12,302
|
jquery-backstretch/jquery-backstretch
|
jquery.backstretch.js
|
function () {
if (oldVideoWrapper) {
oldVideoWrapper.stop();
oldVideoWrapper.destroy();
}
$oldItemWrapper.remove();
// Resume the slideshow
if (!that.paused && that.images.length > 1) {
that.cycle();
}
// Now we can clear the background on the element, to spare memory
if (!that.options.bypassCss && !that.isBody) {
that.$container.css('background-image', 'none');
}
// Trigger the "after" and "show" events
// "show" is being deprecated
$(['after', 'show']).each(function () {
that.$container.trigger($.Event('backstretch.' + this, evtOptions), [that, newIndex]);
});
if (isVideo) {
that.videoWrapper.play();
}
}
|
javascript
|
function () {
if (oldVideoWrapper) {
oldVideoWrapper.stop();
oldVideoWrapper.destroy();
}
$oldItemWrapper.remove();
// Resume the slideshow
if (!that.paused && that.images.length > 1) {
that.cycle();
}
// Now we can clear the background on the element, to spare memory
if (!that.options.bypassCss && !that.isBody) {
that.$container.css('background-image', 'none');
}
// Trigger the "after" and "show" events
// "show" is being deprecated
$(['after', 'show']).each(function () {
that.$container.trigger($.Event('backstretch.' + this, evtOptions), [that, newIndex]);
});
if (isVideo) {
that.videoWrapper.play();
}
}
|
[
"function",
"(",
")",
"{",
"if",
"(",
"oldVideoWrapper",
")",
"{",
"oldVideoWrapper",
".",
"stop",
"(",
")",
";",
"oldVideoWrapper",
".",
"destroy",
"(",
")",
";",
"}",
"$oldItemWrapper",
".",
"remove",
"(",
")",
";",
"// Resume the slideshow",
"if",
"(",
"!",
"that",
".",
"paused",
"&&",
"that",
".",
"images",
".",
"length",
">",
"1",
")",
"{",
"that",
".",
"cycle",
"(",
")",
";",
"}",
"// Now we can clear the background on the element, to spare memory",
"if",
"(",
"!",
"that",
".",
"options",
".",
"bypassCss",
"&&",
"!",
"that",
".",
"isBody",
")",
"{",
"that",
".",
"$container",
".",
"css",
"(",
"'background-image'",
",",
"'none'",
")",
";",
"}",
"// Trigger the \"after\" and \"show\" events",
"// \"show\" is being deprecated",
"$",
"(",
"[",
"'after'",
",",
"'show'",
"]",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"that",
".",
"$container",
".",
"trigger",
"(",
"$",
".",
"Event",
"(",
"'backstretch.'",
"+",
"this",
",",
"evtOptions",
")",
",",
"[",
"that",
",",
"newIndex",
"]",
")",
";",
"}",
")",
";",
"if",
"(",
"isVideo",
")",
"{",
"that",
".",
"videoWrapper",
".",
"play",
"(",
")",
";",
"}",
"}"
] |
Show the image, then delete the old one
|
[
"Show",
"the",
"image",
"then",
"delete",
"the",
"old",
"one"
] |
8f0d9dc99ec6e81bf427e3988930e4b57f406f82
|
https://github.com/jquery-backstretch/jquery-backstretch/blob/8f0d9dc99ec6e81bf427e3988930e4b57f406f82/jquery.backstretch.js#L965-L993
|
|
12,303
|
videojs/mux.js
|
lib/flv/coalesce-stream.js
|
function(options) {
// Number of Tracks per output segment
// If greater than 1, we combine multiple
// tracks into a single segment
this.numberOfTracks = 0;
this.metadataStream = options.metadataStream;
this.videoTags = [];
this.audioTags = [];
this.videoTrack = null;
this.audioTrack = null;
this.pendingCaptions = [];
this.pendingMetadata = [];
this.pendingTracks = 0;
this.processedTracks = 0;
CoalesceStream.prototype.init.call(this);
// Take output from multiple
this.push = function(output) {
// buffer incoming captions until the associated video segment
// finishes
if (output.text) {
return this.pendingCaptions.push(output);
}
// buffer incoming id3 tags until the final flush
if (output.frames) {
return this.pendingMetadata.push(output);
}
if (output.track.type === 'video') {
this.videoTrack = output.track;
this.videoTags = output.tags;
this.pendingTracks++;
}
if (output.track.type === 'audio') {
this.audioTrack = output.track;
this.audioTags = output.tags;
this.pendingTracks++;
}
};
}
|
javascript
|
function(options) {
// Number of Tracks per output segment
// If greater than 1, we combine multiple
// tracks into a single segment
this.numberOfTracks = 0;
this.metadataStream = options.metadataStream;
this.videoTags = [];
this.audioTags = [];
this.videoTrack = null;
this.audioTrack = null;
this.pendingCaptions = [];
this.pendingMetadata = [];
this.pendingTracks = 0;
this.processedTracks = 0;
CoalesceStream.prototype.init.call(this);
// Take output from multiple
this.push = function(output) {
// buffer incoming captions until the associated video segment
// finishes
if (output.text) {
return this.pendingCaptions.push(output);
}
// buffer incoming id3 tags until the final flush
if (output.frames) {
return this.pendingMetadata.push(output);
}
if (output.track.type === 'video') {
this.videoTrack = output.track;
this.videoTags = output.tags;
this.pendingTracks++;
}
if (output.track.type === 'audio') {
this.audioTrack = output.track;
this.audioTags = output.tags;
this.pendingTracks++;
}
};
}
|
[
"function",
"(",
"options",
")",
"{",
"// Number of Tracks per output segment",
"// If greater than 1, we combine multiple",
"// tracks into a single segment",
"this",
".",
"numberOfTracks",
"=",
"0",
";",
"this",
".",
"metadataStream",
"=",
"options",
".",
"metadataStream",
";",
"this",
".",
"videoTags",
"=",
"[",
"]",
";",
"this",
".",
"audioTags",
"=",
"[",
"]",
";",
"this",
".",
"videoTrack",
"=",
"null",
";",
"this",
".",
"audioTrack",
"=",
"null",
";",
"this",
".",
"pendingCaptions",
"=",
"[",
"]",
";",
"this",
".",
"pendingMetadata",
"=",
"[",
"]",
";",
"this",
".",
"pendingTracks",
"=",
"0",
";",
"this",
".",
"processedTracks",
"=",
"0",
";",
"CoalesceStream",
".",
"prototype",
".",
"init",
".",
"call",
"(",
"this",
")",
";",
"// Take output from multiple",
"this",
".",
"push",
"=",
"function",
"(",
"output",
")",
"{",
"// buffer incoming captions until the associated video segment",
"// finishes",
"if",
"(",
"output",
".",
"text",
")",
"{",
"return",
"this",
".",
"pendingCaptions",
".",
"push",
"(",
"output",
")",
";",
"}",
"// buffer incoming id3 tags until the final flush",
"if",
"(",
"output",
".",
"frames",
")",
"{",
"return",
"this",
".",
"pendingMetadata",
".",
"push",
"(",
"output",
")",
";",
"}",
"if",
"(",
"output",
".",
"track",
".",
"type",
"===",
"'video'",
")",
"{",
"this",
".",
"videoTrack",
"=",
"output",
".",
"track",
";",
"this",
".",
"videoTags",
"=",
"output",
".",
"tags",
";",
"this",
".",
"pendingTracks",
"++",
";",
"}",
"if",
"(",
"output",
".",
"track",
".",
"type",
"===",
"'audio'",
")",
"{",
"this",
".",
"audioTrack",
"=",
"output",
".",
"track",
";",
"this",
".",
"audioTags",
"=",
"output",
".",
"tags",
";",
"this",
".",
"pendingTracks",
"++",
";",
"}",
"}",
";",
"}"
] |
The final stage of the transmuxer that emits the flv tags
for audio, video, and metadata. Also tranlates in time and
outputs caption data and id3 cues.
|
[
"The",
"final",
"stage",
"of",
"the",
"transmuxer",
"that",
"emits",
"the",
"flv",
"tags",
"for",
"audio",
"video",
"and",
"metadata",
".",
"Also",
"tranlates",
"in",
"time",
"and",
"outputs",
"caption",
"data",
"and",
"id3",
"cues",
"."
] |
0a0215b57bdaebcf9d7794dac53b61a01bbbf1de
|
https://github.com/videojs/mux.js/blob/0a0215b57bdaebcf9d7794dac53b61a01bbbf1de/lib/flv/coalesce-stream.js#L16-L57
|
|
12,304
|
donmccurdy/aframe-physics-system
|
src/drivers/webworkify-debug.js
|
webworkifyDebug
|
function webworkifyDebug (worker) {
var targetA = new EventTarget(),
targetB = new EventTarget();
targetA.setTarget(targetB);
targetB.setTarget(targetA);
worker(targetA);
return targetB;
}
|
javascript
|
function webworkifyDebug (worker) {
var targetA = new EventTarget(),
targetB = new EventTarget();
targetA.setTarget(targetB);
targetB.setTarget(targetA);
worker(targetA);
return targetB;
}
|
[
"function",
"webworkifyDebug",
"(",
"worker",
")",
"{",
"var",
"targetA",
"=",
"new",
"EventTarget",
"(",
")",
",",
"targetB",
"=",
"new",
"EventTarget",
"(",
")",
";",
"targetA",
".",
"setTarget",
"(",
"targetB",
")",
";",
"targetB",
".",
"setTarget",
"(",
"targetA",
")",
";",
"worker",
"(",
"targetA",
")",
";",
"return",
"targetB",
";",
"}"
] |
Stub version of webworkify, for debugging code outside of a webworker.
|
[
"Stub",
"version",
"of",
"webworkify",
"for",
"debugging",
"code",
"outside",
"of",
"a",
"webworker",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/drivers/webworkify-debug.js#L4-L13
|
12,305
|
donmccurdy/aframe-physics-system
|
src/system.js
|
function () {
var data = this.data;
// If true, show wireframes around physics bodies.
this.debug = data.debug;
this.callbacks = {beforeStep: [], step: [], afterStep: []};
this.listeners = {};
this.driver = null;
switch (data.driver) {
case 'local':
this.driver = new LocalDriver();
break;
case 'network':
this.driver = new NetworkDriver(data.networkUrl);
break;
case 'worker':
this.driver = new WorkerDriver({
fps: data.workerFps,
engine: data.workerEngine,
interpolate: data.workerInterpolate,
interpolationBufferSize: data.workerInterpBufferSize,
debug: data.workerDebug
});
break;
default:
throw new Error('[physics] Driver not recognized: "%s".', data.driver);
}
this.driver.init({
quatNormalizeSkip: 0,
quatNormalizeFast: false,
solverIterations: data.iterations,
gravity: data.gravity
});
this.driver.addMaterial({name: 'defaultMaterial'});
this.driver.addMaterial({name: 'staticMaterial'});
this.driver.addContactMaterial('defaultMaterial', 'defaultMaterial', {
friction: data.friction,
restitution: data.restitution,
contactEquationStiffness: data.contactEquationStiffness,
contactEquationRelaxation: data.contactEquationRelaxation,
frictionEquationStiffness: data.frictionEquationStiffness,
frictionEquationRegularization: data.frictionEquationRegularization
});
this.driver.addContactMaterial('staticMaterial', 'defaultMaterial', {
friction: 1.0,
restitution: 0.0,
contactEquationStiffness: data.contactEquationStiffness,
contactEquationRelaxation: data.contactEquationRelaxation,
frictionEquationStiffness: data.frictionEquationStiffness,
frictionEquationRegularization: data.frictionEquationRegularization
});
}
|
javascript
|
function () {
var data = this.data;
// If true, show wireframes around physics bodies.
this.debug = data.debug;
this.callbacks = {beforeStep: [], step: [], afterStep: []};
this.listeners = {};
this.driver = null;
switch (data.driver) {
case 'local':
this.driver = new LocalDriver();
break;
case 'network':
this.driver = new NetworkDriver(data.networkUrl);
break;
case 'worker':
this.driver = new WorkerDriver({
fps: data.workerFps,
engine: data.workerEngine,
interpolate: data.workerInterpolate,
interpolationBufferSize: data.workerInterpBufferSize,
debug: data.workerDebug
});
break;
default:
throw new Error('[physics] Driver not recognized: "%s".', data.driver);
}
this.driver.init({
quatNormalizeSkip: 0,
quatNormalizeFast: false,
solverIterations: data.iterations,
gravity: data.gravity
});
this.driver.addMaterial({name: 'defaultMaterial'});
this.driver.addMaterial({name: 'staticMaterial'});
this.driver.addContactMaterial('defaultMaterial', 'defaultMaterial', {
friction: data.friction,
restitution: data.restitution,
contactEquationStiffness: data.contactEquationStiffness,
contactEquationRelaxation: data.contactEquationRelaxation,
frictionEquationStiffness: data.frictionEquationStiffness,
frictionEquationRegularization: data.frictionEquationRegularization
});
this.driver.addContactMaterial('staticMaterial', 'defaultMaterial', {
friction: 1.0,
restitution: 0.0,
contactEquationStiffness: data.contactEquationStiffness,
contactEquationRelaxation: data.contactEquationRelaxation,
frictionEquationStiffness: data.frictionEquationStiffness,
frictionEquationRegularization: data.frictionEquationRegularization
});
}
|
[
"function",
"(",
")",
"{",
"var",
"data",
"=",
"this",
".",
"data",
";",
"// If true, show wireframes around physics bodies.",
"this",
".",
"debug",
"=",
"data",
".",
"debug",
";",
"this",
".",
"callbacks",
"=",
"{",
"beforeStep",
":",
"[",
"]",
",",
"step",
":",
"[",
"]",
",",
"afterStep",
":",
"[",
"]",
"}",
";",
"this",
".",
"listeners",
"=",
"{",
"}",
";",
"this",
".",
"driver",
"=",
"null",
";",
"switch",
"(",
"data",
".",
"driver",
")",
"{",
"case",
"'local'",
":",
"this",
".",
"driver",
"=",
"new",
"LocalDriver",
"(",
")",
";",
"break",
";",
"case",
"'network'",
":",
"this",
".",
"driver",
"=",
"new",
"NetworkDriver",
"(",
"data",
".",
"networkUrl",
")",
";",
"break",
";",
"case",
"'worker'",
":",
"this",
".",
"driver",
"=",
"new",
"WorkerDriver",
"(",
"{",
"fps",
":",
"data",
".",
"workerFps",
",",
"engine",
":",
"data",
".",
"workerEngine",
",",
"interpolate",
":",
"data",
".",
"workerInterpolate",
",",
"interpolationBufferSize",
":",
"data",
".",
"workerInterpBufferSize",
",",
"debug",
":",
"data",
".",
"workerDebug",
"}",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"Error",
"(",
"'[physics] Driver not recognized: \"%s\".'",
",",
"data",
".",
"driver",
")",
";",
"}",
"this",
".",
"driver",
".",
"init",
"(",
"{",
"quatNormalizeSkip",
":",
"0",
",",
"quatNormalizeFast",
":",
"false",
",",
"solverIterations",
":",
"data",
".",
"iterations",
",",
"gravity",
":",
"data",
".",
"gravity",
"}",
")",
";",
"this",
".",
"driver",
".",
"addMaterial",
"(",
"{",
"name",
":",
"'defaultMaterial'",
"}",
")",
";",
"this",
".",
"driver",
".",
"addMaterial",
"(",
"{",
"name",
":",
"'staticMaterial'",
"}",
")",
";",
"this",
".",
"driver",
".",
"addContactMaterial",
"(",
"'defaultMaterial'",
",",
"'defaultMaterial'",
",",
"{",
"friction",
":",
"data",
".",
"friction",
",",
"restitution",
":",
"data",
".",
"restitution",
",",
"contactEquationStiffness",
":",
"data",
".",
"contactEquationStiffness",
",",
"contactEquationRelaxation",
":",
"data",
".",
"contactEquationRelaxation",
",",
"frictionEquationStiffness",
":",
"data",
".",
"frictionEquationStiffness",
",",
"frictionEquationRegularization",
":",
"data",
".",
"frictionEquationRegularization",
"}",
")",
";",
"this",
".",
"driver",
".",
"addContactMaterial",
"(",
"'staticMaterial'",
",",
"'defaultMaterial'",
",",
"{",
"friction",
":",
"1.0",
",",
"restitution",
":",
"0.0",
",",
"contactEquationStiffness",
":",
"data",
".",
"contactEquationStiffness",
",",
"contactEquationRelaxation",
":",
"data",
".",
"contactEquationRelaxation",
",",
"frictionEquationStiffness",
":",
"data",
".",
"frictionEquationStiffness",
",",
"frictionEquationRegularization",
":",
"data",
".",
"frictionEquationRegularization",
"}",
")",
";",
"}"
] |
Initializes the physics system.
|
[
"Initializes",
"the",
"physics",
"system",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/system.js#L45-L104
|
|
12,306
|
donmccurdy/aframe-physics-system
|
src/system.js
|
function (body) {
var driver = this.driver;
body.__applyImpulse = body.applyImpulse;
body.applyImpulse = function () {
driver.applyBodyMethod(body, 'applyImpulse', arguments);
};
body.__applyForce = body.applyForce;
body.applyForce = function () {
driver.applyBodyMethod(body, 'applyForce', arguments);
};
body.updateProperties = function () {
driver.updateBodyProperties(body);
};
this.listeners[body.id] = function (e) { body.el.emit('collide', e); };
body.addEventListener('collide', this.listeners[body.id]);
this.driver.addBody(body);
}
|
javascript
|
function (body) {
var driver = this.driver;
body.__applyImpulse = body.applyImpulse;
body.applyImpulse = function () {
driver.applyBodyMethod(body, 'applyImpulse', arguments);
};
body.__applyForce = body.applyForce;
body.applyForce = function () {
driver.applyBodyMethod(body, 'applyForce', arguments);
};
body.updateProperties = function () {
driver.updateBodyProperties(body);
};
this.listeners[body.id] = function (e) { body.el.emit('collide', e); };
body.addEventListener('collide', this.listeners[body.id]);
this.driver.addBody(body);
}
|
[
"function",
"(",
"body",
")",
"{",
"var",
"driver",
"=",
"this",
".",
"driver",
";",
"body",
".",
"__applyImpulse",
"=",
"body",
".",
"applyImpulse",
";",
"body",
".",
"applyImpulse",
"=",
"function",
"(",
")",
"{",
"driver",
".",
"applyBodyMethod",
"(",
"body",
",",
"'applyImpulse'",
",",
"arguments",
")",
";",
"}",
";",
"body",
".",
"__applyForce",
"=",
"body",
".",
"applyForce",
";",
"body",
".",
"applyForce",
"=",
"function",
"(",
")",
"{",
"driver",
".",
"applyBodyMethod",
"(",
"body",
",",
"'applyForce'",
",",
"arguments",
")",
";",
"}",
";",
"body",
".",
"updateProperties",
"=",
"function",
"(",
")",
"{",
"driver",
".",
"updateBodyProperties",
"(",
"body",
")",
";",
"}",
";",
"this",
".",
"listeners",
"[",
"body",
".",
"id",
"]",
"=",
"function",
"(",
"e",
")",
"{",
"body",
".",
"el",
".",
"emit",
"(",
"'collide'",
",",
"e",
")",
";",
"}",
";",
"body",
".",
"addEventListener",
"(",
"'collide'",
",",
"this",
".",
"listeners",
"[",
"body",
".",
"id",
"]",
")",
";",
"this",
".",
"driver",
".",
"addBody",
"(",
"body",
")",
";",
"}"
] |
Adds a body to the scene, and binds proxied methods to the driver.
@param {CANNON.Body} body
|
[
"Adds",
"a",
"body",
"to",
"the",
"scene",
"and",
"binds",
"proxied",
"methods",
"to",
"the",
"driver",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/system.js#L139-L160
|
|
12,307
|
donmccurdy/aframe-physics-system
|
src/system.js
|
function (body) {
this.driver.removeBody(body);
body.removeEventListener('collide', this.listeners[body.id]);
delete this.listeners[body.id];
body.applyImpulse = body.__applyImpulse;
delete body.__applyImpulse;
body.applyForce = body.__applyForce;
delete body.__applyForce;
delete body.updateProperties;
}
|
javascript
|
function (body) {
this.driver.removeBody(body);
body.removeEventListener('collide', this.listeners[body.id]);
delete this.listeners[body.id];
body.applyImpulse = body.__applyImpulse;
delete body.__applyImpulse;
body.applyForce = body.__applyForce;
delete body.__applyForce;
delete body.updateProperties;
}
|
[
"function",
"(",
"body",
")",
"{",
"this",
".",
"driver",
".",
"removeBody",
"(",
"body",
")",
";",
"body",
".",
"removeEventListener",
"(",
"'collide'",
",",
"this",
".",
"listeners",
"[",
"body",
".",
"id",
"]",
")",
";",
"delete",
"this",
".",
"listeners",
"[",
"body",
".",
"id",
"]",
";",
"body",
".",
"applyImpulse",
"=",
"body",
".",
"__applyImpulse",
";",
"delete",
"body",
".",
"__applyImpulse",
";",
"body",
".",
"applyForce",
"=",
"body",
".",
"__applyForce",
";",
"delete",
"body",
".",
"__applyForce",
";",
"delete",
"body",
".",
"updateProperties",
";",
"}"
] |
Removes a body and its proxied methods.
@param {CANNON.Body} body
|
[
"Removes",
"a",
"body",
"and",
"its",
"proxied",
"methods",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/system.js#L166-L179
|
|
12,308
|
donmccurdy/aframe-physics-system
|
src/system.js
|
function (component) {
var callbacks = this.callbacks;
if (component.beforeStep) callbacks.beforeStep.push(component);
if (component.step) callbacks.step.push(component);
if (component.afterStep) callbacks.afterStep.push(component);
}
|
javascript
|
function (component) {
var callbacks = this.callbacks;
if (component.beforeStep) callbacks.beforeStep.push(component);
if (component.step) callbacks.step.push(component);
if (component.afterStep) callbacks.afterStep.push(component);
}
|
[
"function",
"(",
"component",
")",
"{",
"var",
"callbacks",
"=",
"this",
".",
"callbacks",
";",
"if",
"(",
"component",
".",
"beforeStep",
")",
"callbacks",
".",
"beforeStep",
".",
"push",
"(",
"component",
")",
";",
"if",
"(",
"component",
".",
"step",
")",
"callbacks",
".",
"step",
".",
"push",
"(",
"component",
")",
";",
"if",
"(",
"component",
".",
"afterStep",
")",
"callbacks",
".",
"afterStep",
".",
"push",
"(",
"component",
")",
";",
"}"
] |
Adds a component instance to the system and schedules its update methods to be called
the given phase.
@param {Component} component
@param {string} phase
|
[
"Adds",
"a",
"component",
"instance",
"to",
"the",
"system",
"and",
"schedules",
"its",
"update",
"methods",
"to",
"be",
"called",
"the",
"given",
"phase",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/system.js#L210-L215
|
|
12,309
|
donmccurdy/aframe-physics-system
|
src/system.js
|
function (component) {
var callbacks = this.callbacks;
if (component.beforeStep) {
callbacks.beforeStep.splice(callbacks.beforeStep.indexOf(component), 1);
}
if (component.step) {
callbacks.step.splice(callbacks.step.indexOf(component), 1);
}
if (component.afterStep) {
callbacks.afterStep.splice(callbacks.afterStep.indexOf(component), 1);
}
}
|
javascript
|
function (component) {
var callbacks = this.callbacks;
if (component.beforeStep) {
callbacks.beforeStep.splice(callbacks.beforeStep.indexOf(component), 1);
}
if (component.step) {
callbacks.step.splice(callbacks.step.indexOf(component), 1);
}
if (component.afterStep) {
callbacks.afterStep.splice(callbacks.afterStep.indexOf(component), 1);
}
}
|
[
"function",
"(",
"component",
")",
"{",
"var",
"callbacks",
"=",
"this",
".",
"callbacks",
";",
"if",
"(",
"component",
".",
"beforeStep",
")",
"{",
"callbacks",
".",
"beforeStep",
".",
"splice",
"(",
"callbacks",
".",
"beforeStep",
".",
"indexOf",
"(",
"component",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"component",
".",
"step",
")",
"{",
"callbacks",
".",
"step",
".",
"splice",
"(",
"callbacks",
".",
"step",
".",
"indexOf",
"(",
"component",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"component",
".",
"afterStep",
")",
"{",
"callbacks",
".",
"afterStep",
".",
"splice",
"(",
"callbacks",
".",
"afterStep",
".",
"indexOf",
"(",
"component",
")",
",",
"1",
")",
";",
"}",
"}"
] |
Removes a component instance from the system.
@param {Component} component
@param {string} phase
|
[
"Removes",
"a",
"component",
"instance",
"from",
"the",
"system",
"."
] |
cbe574c9c2e1d946e9806d9ba30c201461cdce07
|
https://github.com/donmccurdy/aframe-physics-system/blob/cbe574c9c2e1d946e9806d9ba30c201461cdce07/src/system.js#L222-L233
|
|
12,310
|
rollbar/rollbar.js
|
browserstack.browsers.js
|
filter
|
function filter() {
var ret = [];
var labels = Array.prototype.slice.call(arguments);
labels.forEach(function(label) {
browsers.forEach(function(browser) {
if (label === 'bs_all') {
ret.push(browser);
} else if (browser._alias.match(new RegExp(label.slice(2) + '$'))) {
ret.push(browser);
}
});
});
return ret;
}
|
javascript
|
function filter() {
var ret = [];
var labels = Array.prototype.slice.call(arguments);
labels.forEach(function(label) {
browsers.forEach(function(browser) {
if (label === 'bs_all') {
ret.push(browser);
} else if (browser._alias.match(new RegExp(label.slice(2) + '$'))) {
ret.push(browser);
}
});
});
return ret;
}
|
[
"function",
"filter",
"(",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"var",
"labels",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"labels",
".",
"forEach",
"(",
"function",
"(",
"label",
")",
"{",
"browsers",
".",
"forEach",
"(",
"function",
"(",
"browser",
")",
"{",
"if",
"(",
"label",
"===",
"'bs_all'",
")",
"{",
"ret",
".",
"push",
"(",
"browser",
")",
";",
"}",
"else",
"if",
"(",
"browser",
".",
"_alias",
".",
"match",
"(",
"new",
"RegExp",
"(",
"label",
".",
"slice",
"(",
"2",
")",
"+",
"'$'",
")",
")",
")",
"{",
"ret",
".",
"push",
"(",
"browser",
")",
";",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"ret",
";",
"}"
] |
Returns an array of Objects that match the requested filters.
If no arguments are provided, an empty array is returned.
E.g.
filter('bs_latest') - Will return the latest browser Objects for each browser.
filter('bs_latest', 'bs_previous') - Will return the latest and previous browser Objects for each browser.
filter('bs_ie_latest', 'bs_oldest') - Will return the latest IE browser and all of the oldest browsers.
filter('bs_all') - Will return the all of the browser Objects.
@returns {Array}
|
[
"Returns",
"an",
"array",
"of",
"Objects",
"that",
"match",
"the",
"requested",
"filters",
".",
"If",
"no",
"arguments",
"are",
"provided",
"an",
"empty",
"array",
"is",
"returned",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/browserstack.browsers.js#L130-L145
|
12,311
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
guessFunctionName
|
function guessFunctionName(url, lineNo) {
var reFunctionArgNames = /function ([^(]*)\(([^)]*)\)/,
reGuessFunction = /['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,
line = '',
maxLines = 10,
source = getSource(url),
m;
if (!source.length) {
return UNKNOWN_FUNCTION;
}
// Walk backwards from the first line in the function until we find the line which
// matches the pattern above, which is the function definition
for (var i = 0; i < maxLines; ++i) {
line = source[lineNo - i] + line;
if (!_isUndefined(line)) {
if ((m = reGuessFunction.exec(line))) {
return m[1];
} else if ((m = reFunctionArgNames.exec(line))) {
return m[1];
}
}
}
return UNKNOWN_FUNCTION;
}
|
javascript
|
function guessFunctionName(url, lineNo) {
var reFunctionArgNames = /function ([^(]*)\(([^)]*)\)/,
reGuessFunction = /['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,
line = '',
maxLines = 10,
source = getSource(url),
m;
if (!source.length) {
return UNKNOWN_FUNCTION;
}
// Walk backwards from the first line in the function until we find the line which
// matches the pattern above, which is the function definition
for (var i = 0; i < maxLines; ++i) {
line = source[lineNo - i] + line;
if (!_isUndefined(line)) {
if ((m = reGuessFunction.exec(line))) {
return m[1];
} else if ((m = reFunctionArgNames.exec(line))) {
return m[1];
}
}
}
return UNKNOWN_FUNCTION;
}
|
[
"function",
"guessFunctionName",
"(",
"url",
",",
"lineNo",
")",
"{",
"var",
"reFunctionArgNames",
"=",
"/",
"function ([^(]*)\\(([^)]*)\\)",
"/",
",",
"reGuessFunction",
"=",
"/",
"['\"]?([0-9A-Za-z$_]+)['\"]?\\s*[:=]\\s*(function|eval|new Function)",
"/",
",",
"line",
"=",
"''",
",",
"maxLines",
"=",
"10",
",",
"source",
"=",
"getSource",
"(",
"url",
")",
",",
"m",
";",
"if",
"(",
"!",
"source",
".",
"length",
")",
"{",
"return",
"UNKNOWN_FUNCTION",
";",
"}",
"// Walk backwards from the first line in the function until we find the line which",
"// matches the pattern above, which is the function definition",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"maxLines",
";",
"++",
"i",
")",
"{",
"line",
"=",
"source",
"[",
"lineNo",
"-",
"i",
"]",
"+",
"line",
";",
"if",
"(",
"!",
"_isUndefined",
"(",
"line",
")",
")",
"{",
"if",
"(",
"(",
"m",
"=",
"reGuessFunction",
".",
"exec",
"(",
"line",
")",
")",
")",
"{",
"return",
"m",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"(",
"m",
"=",
"reFunctionArgNames",
".",
"exec",
"(",
"line",
")",
")",
")",
"{",
"return",
"m",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"return",
"UNKNOWN_FUNCTION",
";",
"}"
] |
Tries to use an externally loaded copy of source code to determine
the name of a function by looking at the name of the variable it was
assigned to, if any.
@param {string} url URL of source code.
@param {(string|number)} lineNo Line number in source code.
@return {string} The function name, if discoverable.
|
[
"Tries",
"to",
"use",
"an",
"externally",
"loaded",
"copy",
"of",
"source",
"code",
"to",
"determine",
"the",
"name",
"of",
"a",
"function",
"by",
"looking",
"at",
"the",
"name",
"of",
"the",
"variable",
"it",
"was",
"assigned",
"to",
"if",
"any",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L543-L570
|
12,312
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
gatherContext
|
function gatherContext(url, line) {
var source = getSource(url);
if (!source.length) {
return null;
}
var context = [],
// linesBefore & linesAfter are inclusive with the offending line.
// if linesOfContext is even, there will be one extra line
// *before* the offending line.
linesBefore = Math.floor(linesOfContext / 2),
// Add one extra line if linesOfContext is odd
linesAfter = linesBefore + (linesOfContext % 2),
start = Math.max(0, line - linesBefore - 1),
end = Math.min(source.length, line + linesAfter - 1);
line -= 1; // convert to 0-based index
for (var i = start; i < end; ++i) {
if (!_isUndefined(source[i])) {
context.push(source[i]);
}
}
return context.length > 0 ? context : null;
}
|
javascript
|
function gatherContext(url, line) {
var source = getSource(url);
if (!source.length) {
return null;
}
var context = [],
// linesBefore & linesAfter are inclusive with the offending line.
// if linesOfContext is even, there will be one extra line
// *before* the offending line.
linesBefore = Math.floor(linesOfContext / 2),
// Add one extra line if linesOfContext is odd
linesAfter = linesBefore + (linesOfContext % 2),
start = Math.max(0, line - linesBefore - 1),
end = Math.min(source.length, line + linesAfter - 1);
line -= 1; // convert to 0-based index
for (var i = start; i < end; ++i) {
if (!_isUndefined(source[i])) {
context.push(source[i]);
}
}
return context.length > 0 ? context : null;
}
|
[
"function",
"gatherContext",
"(",
"url",
",",
"line",
")",
"{",
"var",
"source",
"=",
"getSource",
"(",
"url",
")",
";",
"if",
"(",
"!",
"source",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"var",
"context",
"=",
"[",
"]",
",",
"// linesBefore & linesAfter are inclusive with the offending line.",
"// if linesOfContext is even, there will be one extra line",
"// *before* the offending line.",
"linesBefore",
"=",
"Math",
".",
"floor",
"(",
"linesOfContext",
"/",
"2",
")",
",",
"// Add one extra line if linesOfContext is odd",
"linesAfter",
"=",
"linesBefore",
"+",
"(",
"linesOfContext",
"%",
"2",
")",
",",
"start",
"=",
"Math",
".",
"max",
"(",
"0",
",",
"line",
"-",
"linesBefore",
"-",
"1",
")",
",",
"end",
"=",
"Math",
".",
"min",
"(",
"source",
".",
"length",
",",
"line",
"+",
"linesAfter",
"-",
"1",
")",
";",
"line",
"-=",
"1",
";",
"// convert to 0-based index",
"for",
"(",
"var",
"i",
"=",
"start",
";",
"i",
"<",
"end",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"_isUndefined",
"(",
"source",
"[",
"i",
"]",
")",
")",
"{",
"context",
".",
"push",
"(",
"source",
"[",
"i",
"]",
")",
";",
"}",
"}",
"return",
"context",
".",
"length",
">",
"0",
"?",
"context",
":",
"null",
";",
"}"
] |
Retrieves the surrounding lines from where an exception occurred.
@param {string} url URL of source code.
@param {(string|number)} line Line number in source code to centre
around for context.
@return {?Array.<string>} Lines of source code.
|
[
"Retrieves",
"the",
"surrounding",
"lines",
"from",
"where",
"an",
"exception",
"occurred",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L579-L605
|
12,313
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
escapeCodeAsRegExpForMatchingInsideHTML
|
function escapeCodeAsRegExpForMatchingInsideHTML(body) {
return escapeRegExp(body).replace('<', '(?:<|<)').replace('>', '(?:>|>)').replace('&', '(?:&|&)').replace('"', '(?:"|")').replace(/\s+/g, '\\s+');
}
|
javascript
|
function escapeCodeAsRegExpForMatchingInsideHTML(body) {
return escapeRegExp(body).replace('<', '(?:<|<)').replace('>', '(?:>|>)').replace('&', '(?:&|&)').replace('"', '(?:"|")').replace(/\s+/g, '\\s+');
}
|
[
"function",
"escapeCodeAsRegExpForMatchingInsideHTML",
"(",
"body",
")",
"{",
"return",
"escapeRegExp",
"(",
"body",
")",
".",
"replace",
"(",
"'<'",
",",
"'(?:<|<)'",
")",
".",
"replace",
"(",
"'>'",
",",
"'(?:>|>)'",
")",
".",
"replace",
"(",
"'&'",
",",
"'(?:&|&)'",
")",
".",
"replace",
"(",
"'\"'",
",",
"'(?:\"|")'",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'\\\\s+'",
")",
";",
"}"
] |
Escapes special characters in a string to be used inside a regular
expression as a string literal. Also ensures that HTML entities will
be matched the same as their literal friends.
@param {string} body The string.
@return {string} The escaped string.
|
[
"Escapes",
"special",
"characters",
"in",
"a",
"string",
"to",
"be",
"used",
"inside",
"a",
"regular",
"expression",
"as",
"a",
"string",
"literal",
".",
"Also",
"ensures",
"that",
"HTML",
"entities",
"will",
"be",
"matched",
"the",
"same",
"as",
"their",
"literal",
"friends",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L624-L626
|
12,314
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
findSourceInLine
|
function findSourceInLine(fragment, url, line) {
var source = getSource(url),
re = new RegExp('\\b' + escapeRegExp(fragment) + '\\b'),
m;
line -= 1;
if (source && source.length > line && (m = re.exec(source[line]))) {
return m.index;
}
return null;
}
|
javascript
|
function findSourceInLine(fragment, url, line) {
var source = getSource(url),
re = new RegExp('\\b' + escapeRegExp(fragment) + '\\b'),
m;
line -= 1;
if (source && source.length > line && (m = re.exec(source[line]))) {
return m.index;
}
return null;
}
|
[
"function",
"findSourceInLine",
"(",
"fragment",
",",
"url",
",",
"line",
")",
"{",
"var",
"source",
"=",
"getSource",
"(",
"url",
")",
",",
"re",
"=",
"new",
"RegExp",
"(",
"'\\\\b'",
"+",
"escapeRegExp",
"(",
"fragment",
")",
"+",
"'\\\\b'",
")",
",",
"m",
";",
"line",
"-=",
"1",
";",
"if",
"(",
"source",
"&&",
"source",
".",
"length",
">",
"line",
"&&",
"(",
"m",
"=",
"re",
".",
"exec",
"(",
"source",
"[",
"line",
"]",
")",
")",
")",
"{",
"return",
"m",
".",
"index",
";",
"}",
"return",
"null",
";",
"}"
] |
Determines at which column a code fragment occurs on a line of the
source code.
@param {string} fragment The code fragment.
@param {string} url The URL to search.
@param {(string|number)} line The line number to examine.
@return {?number} The column number.
|
[
"Determines",
"at",
"which",
"column",
"a",
"code",
"fragment",
"occurs",
"on",
"a",
"line",
"of",
"the",
"source",
"code",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L666-L678
|
12,315
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
computeStackTraceFromStacktraceProp
|
function computeStackTraceFromStacktraceProp(ex) {
// Access and store the stacktrace property before doing ANYTHING
// else to it because Opera is not very good at providing it
// reliably in other circumstances.
var stacktrace = ex.stacktrace;
var testRE = / line (\d+), column (\d+) in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\) in (.*):\s*$/i,
lines = stacktrace.split('\n'),
stack = [],
parts;
for (var i = 0, j = lines.length; i < j; i += 2) {
if ((parts = testRE.exec(lines[i]))) {
var element = {
'line': +parts[1],
'column': +parts[2],
'func': parts[3] || parts[4],
'args': parts[5] ? parts[5].split(',') : [],
'url': parts[6]
};
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
try {
element.context = gatherContext(element.url, element.line);
} catch (exc) {}
}
if (!element.context) {
element.context = [lines[i + 1]];
}
stack.push(element);
}
}
if (!stack.length) {
return null;
}
return {
'mode': 'stacktrace',
'name': ex.name,
'message': ex.message,
'url': document.location.href,
'stack': stack,
'useragent': navigator.userAgent
};
}
|
javascript
|
function computeStackTraceFromStacktraceProp(ex) {
// Access and store the stacktrace property before doing ANYTHING
// else to it because Opera is not very good at providing it
// reliably in other circumstances.
var stacktrace = ex.stacktrace;
var testRE = / line (\d+), column (\d+) in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\) in (.*):\s*$/i,
lines = stacktrace.split('\n'),
stack = [],
parts;
for (var i = 0, j = lines.length; i < j; i += 2) {
if ((parts = testRE.exec(lines[i]))) {
var element = {
'line': +parts[1],
'column': +parts[2],
'func': parts[3] || parts[4],
'args': parts[5] ? parts[5].split(',') : [],
'url': parts[6]
};
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
try {
element.context = gatherContext(element.url, element.line);
} catch (exc) {}
}
if (!element.context) {
element.context = [lines[i + 1]];
}
stack.push(element);
}
}
if (!stack.length) {
return null;
}
return {
'mode': 'stacktrace',
'name': ex.name,
'message': ex.message,
'url': document.location.href,
'stack': stack,
'useragent': navigator.userAgent
};
}
|
[
"function",
"computeStackTraceFromStacktraceProp",
"(",
"ex",
")",
"{",
"// Access and store the stacktrace property before doing ANYTHING",
"// else to it because Opera is not very good at providing it",
"// reliably in other circumstances.",
"var",
"stacktrace",
"=",
"ex",
".",
"stacktrace",
";",
"var",
"testRE",
"=",
"/",
" line (\\d+), column (\\d+) in (?:<anonymous function: ([^>]+)>|([^\\)]+))\\((.*)\\) in (.*):\\s*$",
"/",
"i",
",",
"lines",
"=",
"stacktrace",
".",
"split",
"(",
"'\\n'",
")",
",",
"stack",
"=",
"[",
"]",
",",
"parts",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"lines",
".",
"length",
";",
"i",
"<",
"j",
";",
"i",
"+=",
"2",
")",
"{",
"if",
"(",
"(",
"parts",
"=",
"testRE",
".",
"exec",
"(",
"lines",
"[",
"i",
"]",
")",
")",
")",
"{",
"var",
"element",
"=",
"{",
"'line'",
":",
"+",
"parts",
"[",
"1",
"]",
",",
"'column'",
":",
"+",
"parts",
"[",
"2",
"]",
",",
"'func'",
":",
"parts",
"[",
"3",
"]",
"||",
"parts",
"[",
"4",
"]",
",",
"'args'",
":",
"parts",
"[",
"5",
"]",
"?",
"parts",
"[",
"5",
"]",
".",
"split",
"(",
"','",
")",
":",
"[",
"]",
",",
"'url'",
":",
"parts",
"[",
"6",
"]",
"}",
";",
"if",
"(",
"!",
"element",
".",
"func",
"&&",
"element",
".",
"line",
")",
"{",
"element",
".",
"func",
"=",
"guessFunctionName",
"(",
"element",
".",
"url",
",",
"element",
".",
"line",
")",
";",
"}",
"if",
"(",
"element",
".",
"line",
")",
"{",
"try",
"{",
"element",
".",
"context",
"=",
"gatherContext",
"(",
"element",
".",
"url",
",",
"element",
".",
"line",
")",
";",
"}",
"catch",
"(",
"exc",
")",
"{",
"}",
"}",
"if",
"(",
"!",
"element",
".",
"context",
")",
"{",
"element",
".",
"context",
"=",
"[",
"lines",
"[",
"i",
"+",
"1",
"]",
"]",
";",
"}",
"stack",
".",
"push",
"(",
"element",
")",
";",
"}",
"}",
"if",
"(",
"!",
"stack",
".",
"length",
")",
"{",
"return",
"null",
";",
"}",
"return",
"{",
"'mode'",
":",
"'stacktrace'",
",",
"'name'",
":",
"ex",
".",
"name",
",",
"'message'",
":",
"ex",
".",
"message",
",",
"'url'",
":",
"document",
".",
"location",
".",
"href",
",",
"'stack'",
":",
"stack",
",",
"'useragent'",
":",
"navigator",
".",
"userAgent",
"}",
";",
"}"
] |
Computes stack trace information from the stacktrace property.
Opera 10 uses this property.
@param {Error} ex
@return {?Object.<string, *>} Stack trace information.
|
[
"Computes",
"stack",
"trace",
"information",
"from",
"the",
"stacktrace",
"property",
".",
"Opera",
"10",
"uses",
"this",
"property",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L857-L907
|
12,316
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
augmentStackTraceWithInitialElement
|
function augmentStackTraceWithInitialElement(stackInfo, url, lineNo, message) {
var initial = {
'url': url,
'line': lineNo
};
if (initial.url && initial.line) {
stackInfo.incomplete = false;
if (!initial.func) {
initial.func = guessFunctionName(initial.url, initial.line);
}
if (!initial.context) {
initial.context = gatherContext(initial.url, initial.line);
}
var reference = / '([^']+)' /.exec(message);
if (reference) {
initial.column = findSourceInLine(reference[1], initial.url, initial.line);
}
if (stackInfo.stack.length > 0) {
if (stackInfo.stack[0].url === initial.url) {
if (stackInfo.stack[0].line === initial.line) {
return false; // already in stack trace
} else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) {
stackInfo.stack[0].line = initial.line;
stackInfo.stack[0].context = initial.context;
return false;
}
}
}
stackInfo.stack.unshift(initial);
stackInfo.partial = true;
return true;
} else {
stackInfo.incomplete = true;
}
return false;
}
|
javascript
|
function augmentStackTraceWithInitialElement(stackInfo, url, lineNo, message) {
var initial = {
'url': url,
'line': lineNo
};
if (initial.url && initial.line) {
stackInfo.incomplete = false;
if (!initial.func) {
initial.func = guessFunctionName(initial.url, initial.line);
}
if (!initial.context) {
initial.context = gatherContext(initial.url, initial.line);
}
var reference = / '([^']+)' /.exec(message);
if (reference) {
initial.column = findSourceInLine(reference[1], initial.url, initial.line);
}
if (stackInfo.stack.length > 0) {
if (stackInfo.stack[0].url === initial.url) {
if (stackInfo.stack[0].line === initial.line) {
return false; // already in stack trace
} else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) {
stackInfo.stack[0].line = initial.line;
stackInfo.stack[0].context = initial.context;
return false;
}
}
}
stackInfo.stack.unshift(initial);
stackInfo.partial = true;
return true;
} else {
stackInfo.incomplete = true;
}
return false;
}
|
[
"function",
"augmentStackTraceWithInitialElement",
"(",
"stackInfo",
",",
"url",
",",
"lineNo",
",",
"message",
")",
"{",
"var",
"initial",
"=",
"{",
"'url'",
":",
"url",
",",
"'line'",
":",
"lineNo",
"}",
";",
"if",
"(",
"initial",
".",
"url",
"&&",
"initial",
".",
"line",
")",
"{",
"stackInfo",
".",
"incomplete",
"=",
"false",
";",
"if",
"(",
"!",
"initial",
".",
"func",
")",
"{",
"initial",
".",
"func",
"=",
"guessFunctionName",
"(",
"initial",
".",
"url",
",",
"initial",
".",
"line",
")",
";",
"}",
"if",
"(",
"!",
"initial",
".",
"context",
")",
"{",
"initial",
".",
"context",
"=",
"gatherContext",
"(",
"initial",
".",
"url",
",",
"initial",
".",
"line",
")",
";",
"}",
"var",
"reference",
"=",
"/",
" '([^']+)' ",
"/",
".",
"exec",
"(",
"message",
")",
";",
"if",
"(",
"reference",
")",
"{",
"initial",
".",
"column",
"=",
"findSourceInLine",
"(",
"reference",
"[",
"1",
"]",
",",
"initial",
".",
"url",
",",
"initial",
".",
"line",
")",
";",
"}",
"if",
"(",
"stackInfo",
".",
"stack",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"url",
"===",
"initial",
".",
"url",
")",
"{",
"if",
"(",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"line",
"===",
"initial",
".",
"line",
")",
"{",
"return",
"false",
";",
"// already in stack trace",
"}",
"else",
"if",
"(",
"!",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"line",
"&&",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"func",
"===",
"initial",
".",
"func",
")",
"{",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"line",
"=",
"initial",
".",
"line",
";",
"stackInfo",
".",
"stack",
"[",
"0",
"]",
".",
"context",
"=",
"initial",
".",
"context",
";",
"return",
"false",
";",
"}",
"}",
"}",
"stackInfo",
".",
"stack",
".",
"unshift",
"(",
"initial",
")",
";",
"stackInfo",
".",
"partial",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"stackInfo",
".",
"incomplete",
"=",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Adds information about the first frame to incomplete stack traces.
Safari and IE require this to get complete data on the first frame.
@param {Object.<string, *>} stackInfo Stack trace information from
one of the compute* methods.
@param {string} url The URL of the script that caused an error.
@param {(number|string)} lineNo The line number of the script that
caused an error.
@param {string=} message The error generated by the browser, which
hopefully contains the name of the object that caused the error.
@return {boolean} Whether or not the stack information was
augmented.
|
[
"Adds",
"information",
"about",
"the",
"first",
"frame",
"to",
"incomplete",
"stack",
"traces",
".",
"Safari",
"and",
"IE",
"require",
"this",
"to",
"get",
"complete",
"data",
"on",
"the",
"first",
"frame",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L1034-L1076
|
12,317
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
computeStackTrace
|
function computeStackTrace(ex, depth) {
var stack = null;
depth = (depth == null ? 0 : +depth);
try {
// This must be tried first because Opera 10 *destroys*
// its stacktrace property if you try to access the stack
// property first!!
stack = computeStackTraceFromStacktraceProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromStackProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromOperaMultiLineMessage(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceByWalkingCallerChain(ex, depth + 1);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
return {
'mode': 'failed'
};
}
|
javascript
|
function computeStackTrace(ex, depth) {
var stack = null;
depth = (depth == null ? 0 : +depth);
try {
// This must be tried first because Opera 10 *destroys*
// its stacktrace property if you try to access the stack
// property first!!
stack = computeStackTraceFromStacktraceProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromStackProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromOperaMultiLineMessage(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceByWalkingCallerChain(ex, depth + 1);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
return {
'mode': 'failed'
};
}
|
[
"function",
"computeStackTrace",
"(",
"ex",
",",
"depth",
")",
"{",
"var",
"stack",
"=",
"null",
";",
"depth",
"=",
"(",
"depth",
"==",
"null",
"?",
"0",
":",
"+",
"depth",
")",
";",
"try",
"{",
"// This must be tried first because Opera 10 *destroys*",
"// its stacktrace property if you try to access the stack",
"// property first!!",
"stack",
"=",
"computeStackTraceFromStacktraceProp",
"(",
"ex",
")",
";",
"if",
"(",
"stack",
")",
"{",
"return",
"stack",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"try",
"{",
"stack",
"=",
"computeStackTraceFromStackProp",
"(",
"ex",
")",
";",
"if",
"(",
"stack",
")",
"{",
"return",
"stack",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"try",
"{",
"stack",
"=",
"computeStackTraceFromOperaMultiLineMessage",
"(",
"ex",
")",
";",
"if",
"(",
"stack",
")",
"{",
"return",
"stack",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"try",
"{",
"stack",
"=",
"computeStackTraceByWalkingCallerChain",
"(",
"ex",
",",
"depth",
"+",
"1",
")",
";",
"if",
"(",
"stack",
")",
"{",
"return",
"stack",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"throw",
"e",
";",
"}",
"}",
"return",
"{",
"'mode'",
":",
"'failed'",
"}",
";",
"}"
] |
Computes a stack trace for an exception.
@param {Error} ex
@param {(string|number)=} depth
|
[
"Computes",
"a",
"stack",
"trace",
"for",
"an",
"exception",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L1161-L1215
|
12,318
|
rollbar/rollbar.js
|
release/rollbar-1.2.0.commonjs.js
|
computeStackTraceOfCaller
|
function computeStackTraceOfCaller(depth) {
depth = (depth == null ? 0 : +depth) + 1; // "+ 1" because "ofCaller" should drop one frame
try {
throw new Error();
} catch (ex) {
return computeStackTrace(ex, depth + 1);
}
}
|
javascript
|
function computeStackTraceOfCaller(depth) {
depth = (depth == null ? 0 : +depth) + 1; // "+ 1" because "ofCaller" should drop one frame
try {
throw new Error();
} catch (ex) {
return computeStackTrace(ex, depth + 1);
}
}
|
[
"function",
"computeStackTraceOfCaller",
"(",
"depth",
")",
"{",
"depth",
"=",
"(",
"depth",
"==",
"null",
"?",
"0",
":",
"+",
"depth",
")",
"+",
"1",
";",
"// \"+ 1\" because \"ofCaller\" should drop one frame",
"try",
"{",
"throw",
"new",
"Error",
"(",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"return",
"computeStackTrace",
"(",
"ex",
",",
"depth",
"+",
"1",
")",
";",
"}",
"}"
] |
Logs a stacktrace starting from the previous call and working down.
@param {(number|string)=} depth How many frames deep to trace.
@return {Object.<string, *>} Stack trace information.
|
[
"Logs",
"a",
"stacktrace",
"starting",
"from",
"the",
"previous",
"call",
"and",
"working",
"down",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.2.0.commonjs.js#L1222-L1229
|
12,319
|
rollbar/rollbar.js
|
dist/rollbar.named-amd.js
|
Api
|
function Api(options, t, u, j) {
this.options = options;
this.transport = t;
this.url = u;
this.jsonBackup = j;
this.accessToken = options.accessToken;
this.transportOptions = _getTransport(options, u);
}
|
javascript
|
function Api(options, t, u, j) {
this.options = options;
this.transport = t;
this.url = u;
this.jsonBackup = j;
this.accessToken = options.accessToken;
this.transportOptions = _getTransport(options, u);
}
|
[
"function",
"Api",
"(",
"options",
",",
"t",
",",
"u",
",",
"j",
")",
"{",
"this",
".",
"options",
"=",
"options",
";",
"this",
".",
"transport",
"=",
"t",
";",
"this",
".",
"url",
"=",
"u",
";",
"this",
".",
"jsonBackup",
"=",
"j",
";",
"this",
".",
"accessToken",
"=",
"options",
".",
"accessToken",
";",
"this",
".",
"transportOptions",
"=",
"_getTransport",
"(",
"options",
",",
"u",
")",
";",
"}"
] |
Api is an object that encapsulates methods of communicating with
the Rollbar API. It is a standard interface with some parts implemented
differently for server or browser contexts. It is an object that should
be instantiated when used so it can contain non-global options that may
be different for another instance of RollbarApi.
@param options {
accessToken: the accessToken to use for posting items to rollbar
endpoint: an alternative endpoint to send errors to
must be a valid, fully qualified URL.
The default is: https://api.rollbar.com/api/1/item
proxy: if you wish to proxy requests provide an object
with the following keys:
host or hostname (required): foo.example.com
port (optional): 123
protocol (optional): https
}
|
[
"Api",
"is",
"an",
"object",
"that",
"encapsulates",
"methods",
"of",
"communicating",
"with",
"the",
"Rollbar",
"API",
".",
"It",
"is",
"a",
"standard",
"interface",
"with",
"some",
"parts",
"implemented",
"differently",
"for",
"server",
"or",
"browser",
"contexts",
".",
"It",
"is",
"an",
"object",
"that",
"should",
"be",
"instantiated",
"when",
"used",
"so",
"it",
"can",
"contain",
"non",
"-",
"global",
"options",
"that",
"may",
"be",
"different",
"for",
"another",
"instance",
"of",
"RollbarApi",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/dist/rollbar.named-amd.js#L3025-L3032
|
12,320
|
rollbar/rollbar.js
|
dist/rollbar.named-amd.js
|
ErrorStackParser$$parse
|
function ErrorStackParser$$parse(error) {
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') {
return this.parseOpera(error);
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
return this.parseV8OrIE(error);
} else if (error.stack) {
return this.parseFFOrSafari(error);
} else {
throw new Error('Cannot parse given Error object');
}
}
|
javascript
|
function ErrorStackParser$$parse(error) {
if (typeof error.stacktrace !== 'undefined' || typeof error['opera#sourceloc'] !== 'undefined') {
return this.parseOpera(error);
} else if (error.stack && error.stack.match(CHROME_IE_STACK_REGEXP)) {
return this.parseV8OrIE(error);
} else if (error.stack) {
return this.parseFFOrSafari(error);
} else {
throw new Error('Cannot parse given Error object');
}
}
|
[
"function",
"ErrorStackParser$$parse",
"(",
"error",
")",
"{",
"if",
"(",
"typeof",
"error",
".",
"stacktrace",
"!==",
"'undefined'",
"||",
"typeof",
"error",
"[",
"'opera#sourceloc'",
"]",
"!==",
"'undefined'",
")",
"{",
"return",
"this",
".",
"parseOpera",
"(",
"error",
")",
";",
"}",
"else",
"if",
"(",
"error",
".",
"stack",
"&&",
"error",
".",
"stack",
".",
"match",
"(",
"CHROME_IE_STACK_REGEXP",
")",
")",
"{",
"return",
"this",
".",
"parseV8OrIE",
"(",
"error",
")",
";",
"}",
"else",
"if",
"(",
"error",
".",
"stack",
")",
"{",
"return",
"this",
".",
"parseFFOrSafari",
"(",
"error",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"'Cannot parse given Error object'",
")",
";",
"}",
"}"
] |
Given an Error object, extract the most information from it.
@param error {Error}
@return Array[StackFrame]
|
[
"Given",
"an",
"Error",
"object",
"extract",
"the",
"most",
"information",
"from",
"it",
"."
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/dist/rollbar.named-amd.js#L4340-L4350
|
12,321
|
rollbar/rollbar.js
|
release/rollbar-1.0.1.require.js
|
_rollbarWindowOnError
|
function _rollbarWindowOnError(client, old, args) {
if (!args[4] && window._rollbarWrappedError) {
args[4] = window._rollbarWrappedError;
window._rollbarWrappedError = null;
}
globalNotifier.uncaughtError.apply(globalNotifier, args);
if (old) {
old.apply(window, args);
}
}
|
javascript
|
function _rollbarWindowOnError(client, old, args) {
if (!args[4] && window._rollbarWrappedError) {
args[4] = window._rollbarWrappedError;
window._rollbarWrappedError = null;
}
globalNotifier.uncaughtError.apply(globalNotifier, args);
if (old) {
old.apply(window, args);
}
}
|
[
"function",
"_rollbarWindowOnError",
"(",
"client",
",",
"old",
",",
"args",
")",
"{",
"if",
"(",
"!",
"args",
"[",
"4",
"]",
"&&",
"window",
".",
"_rollbarWrappedError",
")",
"{",
"args",
"[",
"4",
"]",
"=",
"window",
".",
"_rollbarWrappedError",
";",
"window",
".",
"_rollbarWrappedError",
"=",
"null",
";",
"}",
"globalNotifier",
".",
"uncaughtError",
".",
"apply",
"(",
"globalNotifier",
",",
"args",
")",
";",
"if",
"(",
"old",
")",
"{",
"old",
".",
"apply",
"(",
"window",
",",
"args",
")",
";",
"}",
"}"
] |
Global window.onerror handler
|
[
"Global",
"window",
".",
"onerror",
"handler"
] |
d35e544f4347970e2a3082cac3e4af43e5e35113
|
https://github.com/rollbar/rollbar.js/blob/d35e544f4347970e2a3082cac3e4af43e5e35113/release/rollbar-1.0.1.require.js#L2395-L2405
|
12,322
|
jonschlinkert/gray-matter
|
examples/excerpt.js
|
firstFourLines
|
function firstFourLines(file, options) {
file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}
|
javascript
|
function firstFourLines(file, options) {
file.excerpt = file.content.split('\n').slice(0, 4).join(' ');
}
|
[
"function",
"firstFourLines",
"(",
"file",
",",
"options",
")",
"{",
"file",
".",
"excerpt",
"=",
"file",
".",
"content",
".",
"split",
"(",
"'\\n'",
")",
".",
"slice",
"(",
"0",
",",
"4",
")",
".",
"join",
"(",
"' '",
")",
";",
"}"
] |
excerpt as a function returns the first 4 lines of the contents
|
[
"excerpt",
"as",
"a",
"function",
"returns",
"the",
"first",
"4",
"lines",
"of",
"the",
"contents"
] |
8a22958e0afd4b2e09c705becec1c35e76c4f0ee
|
https://github.com/jonschlinkert/gray-matter/blob/8a22958e0afd4b2e09c705becec1c35e76c4f0ee/examples/excerpt.js#L20-L22
|
12,323
|
jonschlinkert/gray-matter
|
benchmark/code/read.js
|
parser
|
function parser(lang, opts) {
lang = lang || opts.lang;
if (engines.hasOwnProperty(lang)) {
return engines[lang];
}
return engines.yaml;
}
|
javascript
|
function parser(lang, opts) {
lang = lang || opts.lang;
if (engines.hasOwnProperty(lang)) {
return engines[lang];
}
return engines.yaml;
}
|
[
"function",
"parser",
"(",
"lang",
",",
"opts",
")",
"{",
"lang",
"=",
"lang",
"||",
"opts",
".",
"lang",
";",
"if",
"(",
"engines",
".",
"hasOwnProperty",
"(",
"lang",
")",
")",
"{",
"return",
"engines",
"[",
"lang",
"]",
";",
"}",
"return",
"engines",
".",
"yaml",
";",
"}"
] |
Determine the correct the parser to use
@param {String} `lang` Use this if defined and it exists
@param {Object} `opts` Otherwise, fall back to options.parser or js-yaml
@return {Function}
|
[
"Determine",
"the",
"correct",
"the",
"parser",
"to",
"use"
] |
8a22958e0afd4b2e09c705becec1c35e76c4f0ee
|
https://github.com/jonschlinkert/gray-matter/blob/8a22958e0afd4b2e09c705becec1c35e76c4f0ee/benchmark/code/read.js#L67-L73
|
12,324
|
jonschlinkert/gray-matter
|
index.js
|
parseMatter
|
function parseMatter(file, options) {
const opts = defaults(options);
const open = opts.delimiters[0];
const close = '\n' + opts.delimiters[1];
let str = file.content;
if (opts.language) {
file.language = opts.language;
}
// get the length of the opening delimiter
const openLen = open.length;
if (!utils.startsWith(str, open, openLen)) {
excerpt(file, opts);
return file;
}
// if the next character after the opening delimiter is
// a character from the delimiter, then it's not a front-
// matter delimiter
if (str.charAt(openLen) === open.slice(-1)) {
return file;
}
// strip the opening delimiter
str = str.slice(openLen);
const len = str.length;
// use the language defined after first delimiter, if it exists
const language = matter.language(str, opts);
if (language.name) {
file.language = language.name;
str = str.slice(language.raw.length);
}
// get the index of the closing delimiter
let closeIndex = str.indexOf(close);
if (closeIndex === -1) {
closeIndex = len;
}
// get the raw front-matter block
file.matter = str.slice(0, closeIndex);
const block = file.matter.replace(/^\s*#[^\n]+/gm, '').trim();
if (block === '') {
file.isEmpty = true;
file.empty = file.content;
file.data = {};
} else {
// create file.data by parsing the raw file.matter block
file.data = parse(file.language, file.matter, opts);
}
// update file.content
if (closeIndex === len) {
file.content = '';
} else {
file.content = str.slice(closeIndex + close.length);
if (file.content[0] === '\r') {
file.content = file.content.slice(1);
}
if (file.content[0] === '\n') {
file.content = file.content.slice(1);
}
}
excerpt(file, opts);
if (opts.sections === true || typeof opts.section === 'function') {
sections(file, opts.section);
}
return file;
}
|
javascript
|
function parseMatter(file, options) {
const opts = defaults(options);
const open = opts.delimiters[0];
const close = '\n' + opts.delimiters[1];
let str = file.content;
if (opts.language) {
file.language = opts.language;
}
// get the length of the opening delimiter
const openLen = open.length;
if (!utils.startsWith(str, open, openLen)) {
excerpt(file, opts);
return file;
}
// if the next character after the opening delimiter is
// a character from the delimiter, then it's not a front-
// matter delimiter
if (str.charAt(openLen) === open.slice(-1)) {
return file;
}
// strip the opening delimiter
str = str.slice(openLen);
const len = str.length;
// use the language defined after first delimiter, if it exists
const language = matter.language(str, opts);
if (language.name) {
file.language = language.name;
str = str.slice(language.raw.length);
}
// get the index of the closing delimiter
let closeIndex = str.indexOf(close);
if (closeIndex === -1) {
closeIndex = len;
}
// get the raw front-matter block
file.matter = str.slice(0, closeIndex);
const block = file.matter.replace(/^\s*#[^\n]+/gm, '').trim();
if (block === '') {
file.isEmpty = true;
file.empty = file.content;
file.data = {};
} else {
// create file.data by parsing the raw file.matter block
file.data = parse(file.language, file.matter, opts);
}
// update file.content
if (closeIndex === len) {
file.content = '';
} else {
file.content = str.slice(closeIndex + close.length);
if (file.content[0] === '\r') {
file.content = file.content.slice(1);
}
if (file.content[0] === '\n') {
file.content = file.content.slice(1);
}
}
excerpt(file, opts);
if (opts.sections === true || typeof opts.section === 'function') {
sections(file, opts.section);
}
return file;
}
|
[
"function",
"parseMatter",
"(",
"file",
",",
"options",
")",
"{",
"const",
"opts",
"=",
"defaults",
"(",
"options",
")",
";",
"const",
"open",
"=",
"opts",
".",
"delimiters",
"[",
"0",
"]",
";",
"const",
"close",
"=",
"'\\n'",
"+",
"opts",
".",
"delimiters",
"[",
"1",
"]",
";",
"let",
"str",
"=",
"file",
".",
"content",
";",
"if",
"(",
"opts",
".",
"language",
")",
"{",
"file",
".",
"language",
"=",
"opts",
".",
"language",
";",
"}",
"// get the length of the opening delimiter",
"const",
"openLen",
"=",
"open",
".",
"length",
";",
"if",
"(",
"!",
"utils",
".",
"startsWith",
"(",
"str",
",",
"open",
",",
"openLen",
")",
")",
"{",
"excerpt",
"(",
"file",
",",
"opts",
")",
";",
"return",
"file",
";",
"}",
"// if the next character after the opening delimiter is",
"// a character from the delimiter, then it's not a front-",
"// matter delimiter",
"if",
"(",
"str",
".",
"charAt",
"(",
"openLen",
")",
"===",
"open",
".",
"slice",
"(",
"-",
"1",
")",
")",
"{",
"return",
"file",
";",
"}",
"// strip the opening delimiter",
"str",
"=",
"str",
".",
"slice",
"(",
"openLen",
")",
";",
"const",
"len",
"=",
"str",
".",
"length",
";",
"// use the language defined after first delimiter, if it exists",
"const",
"language",
"=",
"matter",
".",
"language",
"(",
"str",
",",
"opts",
")",
";",
"if",
"(",
"language",
".",
"name",
")",
"{",
"file",
".",
"language",
"=",
"language",
".",
"name",
";",
"str",
"=",
"str",
".",
"slice",
"(",
"language",
".",
"raw",
".",
"length",
")",
";",
"}",
"// get the index of the closing delimiter",
"let",
"closeIndex",
"=",
"str",
".",
"indexOf",
"(",
"close",
")",
";",
"if",
"(",
"closeIndex",
"===",
"-",
"1",
")",
"{",
"closeIndex",
"=",
"len",
";",
"}",
"// get the raw front-matter block",
"file",
".",
"matter",
"=",
"str",
".",
"slice",
"(",
"0",
",",
"closeIndex",
")",
";",
"const",
"block",
"=",
"file",
".",
"matter",
".",
"replace",
"(",
"/",
"^\\s*#[^\\n]+",
"/",
"gm",
",",
"''",
")",
".",
"trim",
"(",
")",
";",
"if",
"(",
"block",
"===",
"''",
")",
"{",
"file",
".",
"isEmpty",
"=",
"true",
";",
"file",
".",
"empty",
"=",
"file",
".",
"content",
";",
"file",
".",
"data",
"=",
"{",
"}",
";",
"}",
"else",
"{",
"// create file.data by parsing the raw file.matter block",
"file",
".",
"data",
"=",
"parse",
"(",
"file",
".",
"language",
",",
"file",
".",
"matter",
",",
"opts",
")",
";",
"}",
"// update file.content",
"if",
"(",
"closeIndex",
"===",
"len",
")",
"{",
"file",
".",
"content",
"=",
"''",
";",
"}",
"else",
"{",
"file",
".",
"content",
"=",
"str",
".",
"slice",
"(",
"closeIndex",
"+",
"close",
".",
"length",
")",
";",
"if",
"(",
"file",
".",
"content",
"[",
"0",
"]",
"===",
"'\\r'",
")",
"{",
"file",
".",
"content",
"=",
"file",
".",
"content",
".",
"slice",
"(",
"1",
")",
";",
"}",
"if",
"(",
"file",
".",
"content",
"[",
"0",
"]",
"===",
"'\\n'",
")",
"{",
"file",
".",
"content",
"=",
"file",
".",
"content",
".",
"slice",
"(",
"1",
")",
";",
"}",
"}",
"excerpt",
"(",
"file",
",",
"opts",
")",
";",
"if",
"(",
"opts",
".",
"sections",
"===",
"true",
"||",
"typeof",
"opts",
".",
"section",
"===",
"'function'",
")",
"{",
"sections",
"(",
"file",
",",
"opts",
".",
"section",
")",
";",
"}",
"return",
"file",
";",
"}"
] |
Parse front matter
|
[
"Parse",
"front",
"matter"
] |
8a22958e0afd4b2e09c705becec1c35e76c4f0ee
|
https://github.com/jonschlinkert/gray-matter/blob/8a22958e0afd4b2e09c705becec1c35e76c4f0ee/index.js#L57-L131
|
12,325
|
nkzawa/socket.io-stream
|
lib/socket.js
|
Socket
|
function Socket(sio, options) {
if (!(this instanceof Socket)) {
return new Socket(sio, options);
}
EventEmitter.call(this);
options = options || {};
this.sio = sio;
this.forceBase64 = !!options.forceBase64;
this.streams = {};
this.encoder = new parser.Encoder();
this.decoder = new parser.Decoder();
var eventName = exports.event;
sio.on(eventName, bind(this, emit));
sio.on(eventName + '-read', bind(this, '_onread'));
sio.on(eventName + '-write', bind(this, '_onwrite'));
sio.on(eventName + '-end', bind(this, '_onend'));
sio.on(eventName + '-error', bind(this, '_onerror'));
sio.on('error', bind(this, emit, 'error'));
sio.on('disconnect', bind(this, '_ondisconnect'));
this.encoder.on('stream', bind(this, '_onencode'));
this.decoder.on('stream', bind(this, '_ondecode'));
}
|
javascript
|
function Socket(sio, options) {
if (!(this instanceof Socket)) {
return new Socket(sio, options);
}
EventEmitter.call(this);
options = options || {};
this.sio = sio;
this.forceBase64 = !!options.forceBase64;
this.streams = {};
this.encoder = new parser.Encoder();
this.decoder = new parser.Decoder();
var eventName = exports.event;
sio.on(eventName, bind(this, emit));
sio.on(eventName + '-read', bind(this, '_onread'));
sio.on(eventName + '-write', bind(this, '_onwrite'));
sio.on(eventName + '-end', bind(this, '_onend'));
sio.on(eventName + '-error', bind(this, '_onerror'));
sio.on('error', bind(this, emit, 'error'));
sio.on('disconnect', bind(this, '_ondisconnect'));
this.encoder.on('stream', bind(this, '_onencode'));
this.decoder.on('stream', bind(this, '_ondecode'));
}
|
[
"function",
"Socket",
"(",
"sio",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Socket",
")",
")",
"{",
"return",
"new",
"Socket",
"(",
"sio",
",",
"options",
")",
";",
"}",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"sio",
"=",
"sio",
";",
"this",
".",
"forceBase64",
"=",
"!",
"!",
"options",
".",
"forceBase64",
";",
"this",
".",
"streams",
"=",
"{",
"}",
";",
"this",
".",
"encoder",
"=",
"new",
"parser",
".",
"Encoder",
"(",
")",
";",
"this",
".",
"decoder",
"=",
"new",
"parser",
".",
"Decoder",
"(",
")",
";",
"var",
"eventName",
"=",
"exports",
".",
"event",
";",
"sio",
".",
"on",
"(",
"eventName",
",",
"bind",
"(",
"this",
",",
"emit",
")",
")",
";",
"sio",
".",
"on",
"(",
"eventName",
"+",
"'-read'",
",",
"bind",
"(",
"this",
",",
"'_onread'",
")",
")",
";",
"sio",
".",
"on",
"(",
"eventName",
"+",
"'-write'",
",",
"bind",
"(",
"this",
",",
"'_onwrite'",
")",
")",
";",
"sio",
".",
"on",
"(",
"eventName",
"+",
"'-end'",
",",
"bind",
"(",
"this",
",",
"'_onend'",
")",
")",
";",
"sio",
".",
"on",
"(",
"eventName",
"+",
"'-error'",
",",
"bind",
"(",
"this",
",",
"'_onerror'",
")",
")",
";",
"sio",
".",
"on",
"(",
"'error'",
",",
"bind",
"(",
"this",
",",
"emit",
",",
"'error'",
")",
")",
";",
"sio",
".",
"on",
"(",
"'disconnect'",
",",
"bind",
"(",
"this",
",",
"'_ondisconnect'",
")",
")",
";",
"this",
".",
"encoder",
".",
"on",
"(",
"'stream'",
",",
"bind",
"(",
"this",
",",
"'_onencode'",
")",
")",
";",
"this",
".",
"decoder",
".",
"on",
"(",
"'stream'",
",",
"bind",
"(",
"this",
",",
"'_ondecode'",
")",
")",
";",
"}"
] |
Bidirectional stream socket which wraps Socket.IO.
@param {socket.io#Socket} socket.io
@api public
|
[
"Bidirectional",
"stream",
"socket",
"which",
"wraps",
"Socket",
".",
"IO",
"."
] |
8feef9e9ce296ec87e471731735abc6982e4158d
|
https://github.com/nkzawa/socket.io-stream/blob/8feef9e9ce296ec87e471731735abc6982e4158d/lib/socket.js#L35-L61
|
12,326
|
nkzawa/socket.io-stream
|
lib/index.js
|
lookup
|
function lookup(sio, options) {
options = options || {};
if (null == options.forceBase64) {
options.forceBase64 = exports.forceBase64;
}
if (!sio._streamSocket) {
sio._streamSocket = new Socket(sio, options);
}
return sio._streamSocket;
}
|
javascript
|
function lookup(sio, options) {
options = options || {};
if (null == options.forceBase64) {
options.forceBase64 = exports.forceBase64;
}
if (!sio._streamSocket) {
sio._streamSocket = new Socket(sio, options);
}
return sio._streamSocket;
}
|
[
"function",
"lookup",
"(",
"sio",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"null",
"==",
"options",
".",
"forceBase64",
")",
"{",
"options",
".",
"forceBase64",
"=",
"exports",
".",
"forceBase64",
";",
"}",
"if",
"(",
"!",
"sio",
".",
"_streamSocket",
")",
"{",
"sio",
".",
"_streamSocket",
"=",
"new",
"Socket",
"(",
"sio",
",",
"options",
")",
";",
"}",
"return",
"sio",
".",
"_streamSocket",
";",
"}"
] |
Look up an existing Socket.
@param {socket.io#Socket} socket.io
@param {Object} options
@return {Socket} Socket instance
@api public
|
[
"Look",
"up",
"an",
"existing",
"Socket",
"."
] |
8feef9e9ce296ec87e471731735abc6982e4158d
|
https://github.com/nkzawa/socket.io-stream/blob/8feef9e9ce296ec87e471731735abc6982e4158d/lib/index.js#L44-L54
|
12,327
|
nkzawa/socket.io-stream
|
lib/blob-read-stream.js
|
BlobReadStream
|
function BlobReadStream(blob, options) {
if (!(this instanceof BlobReadStream)) {
return new BlobReadStream(blob, options);
}
Readable.call(this, options);
options = options || {};
this.blob = blob;
this.slice = blob.slice || blob.webkitSlice || blob.mozSlice;
this.start = 0;
this.sync = options.synchronous || false;
var fileReader;
if (options.synchronous) {
fileReader = this.fileReader = new FileReaderSync();
} else {
fileReader = this.fileReader = new FileReader();
}
fileReader.onload = bind(this, '_onload');
fileReader.onerror = bind(this, '_onerror');
}
|
javascript
|
function BlobReadStream(blob, options) {
if (!(this instanceof BlobReadStream)) {
return new BlobReadStream(blob, options);
}
Readable.call(this, options);
options = options || {};
this.blob = blob;
this.slice = blob.slice || blob.webkitSlice || blob.mozSlice;
this.start = 0;
this.sync = options.synchronous || false;
var fileReader;
if (options.synchronous) {
fileReader = this.fileReader = new FileReaderSync();
} else {
fileReader = this.fileReader = new FileReader();
}
fileReader.onload = bind(this, '_onload');
fileReader.onerror = bind(this, '_onerror');
}
|
[
"function",
"BlobReadStream",
"(",
"blob",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"BlobReadStream",
")",
")",
"{",
"return",
"new",
"BlobReadStream",
"(",
"blob",
",",
"options",
")",
";",
"}",
"Readable",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"blob",
"=",
"blob",
";",
"this",
".",
"slice",
"=",
"blob",
".",
"slice",
"||",
"blob",
".",
"webkitSlice",
"||",
"blob",
".",
"mozSlice",
";",
"this",
".",
"start",
"=",
"0",
";",
"this",
".",
"sync",
"=",
"options",
".",
"synchronous",
"||",
"false",
";",
"var",
"fileReader",
";",
"if",
"(",
"options",
".",
"synchronous",
")",
"{",
"fileReader",
"=",
"this",
".",
"fileReader",
"=",
"new",
"FileReaderSync",
"(",
")",
";",
"}",
"else",
"{",
"fileReader",
"=",
"this",
".",
"fileReader",
"=",
"new",
"FileReader",
"(",
")",
";",
"}",
"fileReader",
".",
"onload",
"=",
"bind",
"(",
"this",
",",
"'_onload'",
")",
";",
"fileReader",
".",
"onerror",
"=",
"bind",
"(",
"this",
",",
"'_onerror'",
")",
";",
"}"
] |
Readable stream for Blob and File on browser.
@param {Object} options
@api private
|
[
"Readable",
"stream",
"for",
"Blob",
"and",
"File",
"on",
"browser",
"."
] |
8feef9e9ce296ec87e471731735abc6982e4158d
|
https://github.com/nkzawa/socket.io-stream/blob/8feef9e9ce296ec87e471731735abc6982e4158d/lib/blob-read-stream.js#L16-L39
|
12,328
|
LeaVerou/prefixfree
|
plugins/prefixfree.jsapi.js
|
dig
|
function dig(o, namerg) {
var os = [],
out;
function digger(o, namerg, res) {
o = o || this;
res = res || [];
for(var i = 0; i < res.length; i++) {
if(o === res[i]) {
return res;
}
}
os.push(o);
try{
for(var name in o);
} catch(e) {
return [];
}
var inside,
clean = true;
for(name in o) {
if(clean && o.hasOwnProperty(name) && name.match(namerg)) {
res.push(o);
clean = false;
}
var isObject = false;
try{
isObject = o[name] === Object(o[name]) && typeof o[name] != "function";
} catch(e) {}
if(isObject) {
inside = false;
for (i = 0, ii = os.length; i < ii; i++) {
if (os[i] == o[name]) {
inside = true;
break;
}
}
if (!inside) {
digger(o[name], namerg, res);
}
}
}
return res;
}
out = digger(o, namerg);
os = null;
return out;
}
|
javascript
|
function dig(o, namerg) {
var os = [],
out;
function digger(o, namerg, res) {
o = o || this;
res = res || [];
for(var i = 0; i < res.length; i++) {
if(o === res[i]) {
return res;
}
}
os.push(o);
try{
for(var name in o);
} catch(e) {
return [];
}
var inside,
clean = true;
for(name in o) {
if(clean && o.hasOwnProperty(name) && name.match(namerg)) {
res.push(o);
clean = false;
}
var isObject = false;
try{
isObject = o[name] === Object(o[name]) && typeof o[name] != "function";
} catch(e) {}
if(isObject) {
inside = false;
for (i = 0, ii = os.length; i < ii; i++) {
if (os[i] == o[name]) {
inside = true;
break;
}
}
if (!inside) {
digger(o[name], namerg, res);
}
}
}
return res;
}
out = digger(o, namerg);
os = null;
return out;
}
|
[
"function",
"dig",
"(",
"o",
",",
"namerg",
")",
"{",
"var",
"os",
"=",
"[",
"]",
",",
"out",
";",
"function",
"digger",
"(",
"o",
",",
"namerg",
",",
"res",
")",
"{",
"o",
"=",
"o",
"||",
"this",
";",
"res",
"=",
"res",
"||",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"res",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"o",
"===",
"res",
"[",
"i",
"]",
")",
"{",
"return",
"res",
";",
"}",
"}",
"os",
".",
"push",
"(",
"o",
")",
";",
"try",
"{",
"for",
"(",
"var",
"name",
"in",
"o",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"[",
"]",
";",
"}",
"var",
"inside",
",",
"clean",
"=",
"true",
";",
"for",
"(",
"name",
"in",
"o",
")",
"{",
"if",
"(",
"clean",
"&&",
"o",
".",
"hasOwnProperty",
"(",
"name",
")",
"&&",
"name",
".",
"match",
"(",
"namerg",
")",
")",
"{",
"res",
".",
"push",
"(",
"o",
")",
";",
"clean",
"=",
"false",
";",
"}",
"var",
"isObject",
"=",
"false",
";",
"try",
"{",
"isObject",
"=",
"o",
"[",
"name",
"]",
"===",
"Object",
"(",
"o",
"[",
"name",
"]",
")",
"&&",
"typeof",
"o",
"[",
"name",
"]",
"!=",
"\"function\"",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"}",
"if",
"(",
"isObject",
")",
"{",
"inside",
"=",
"false",
";",
"for",
"(",
"i",
"=",
"0",
",",
"ii",
"=",
"os",
".",
"length",
";",
"i",
"<",
"ii",
";",
"i",
"++",
")",
"{",
"if",
"(",
"os",
"[",
"i",
"]",
"==",
"o",
"[",
"name",
"]",
")",
"{",
"inside",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"inside",
")",
"{",
"digger",
"(",
"o",
"[",
"name",
"]",
",",
"namerg",
",",
"res",
")",
";",
"}",
"}",
"}",
"return",
"res",
";",
"}",
"out",
"=",
"digger",
"(",
"o",
",",
"namerg",
")",
";",
"os",
"=",
"null",
";",
"return",
"out",
";",
"}"
] |
This function digs through the objects in order to find out which have prefixed methods and therefore, which need to be extended.
|
[
"This",
"function",
"digs",
"through",
"the",
"objects",
"in",
"order",
"to",
"find",
"out",
"which",
"have",
"prefixed",
"methods",
"and",
"therefore",
"which",
"need",
"to",
"be",
"extended",
"."
] |
d69c83ae5e149363a480cd0182f91bce61600482
|
https://github.com/LeaVerou/prefixfree/blob/d69c83ae5e149363a480cd0182f91bce61600482/plugins/prefixfree.jsapi.js#L50-L96
|
12,329
|
felipernb/algorithms.js
|
src/algorithms/math/collatz_conjecture.js
|
calculateCollatzConjecture
|
function calculateCollatzConjecture(number) {
if (!(number in cache)) {
if (number % 2 === 0) cache[number] = number >> 1;
else cache[number] = number * 3 + 1;
}
return cache[number];
}
|
javascript
|
function calculateCollatzConjecture(number) {
if (!(number in cache)) {
if (number % 2 === 0) cache[number] = number >> 1;
else cache[number] = number * 3 + 1;
}
return cache[number];
}
|
[
"function",
"calculateCollatzConjecture",
"(",
"number",
")",
"{",
"if",
"(",
"!",
"(",
"number",
"in",
"cache",
")",
")",
"{",
"if",
"(",
"number",
"%",
"2",
"===",
"0",
")",
"cache",
"[",
"number",
"]",
"=",
"number",
">>",
"1",
";",
"else",
"cache",
"[",
"number",
"]",
"=",
"number",
"*",
"3",
"+",
"1",
";",
"}",
"return",
"cache",
"[",
"number",
"]",
";",
"}"
] |
Collatz Conjecture algorithm
@param Number
@return Number
|
[
"Collatz",
"Conjecture",
"algorithm"
] |
94b4bb6050b5671f3405af0189369452fda6b4df
|
https://github.com/felipernb/algorithms.js/blob/94b4bb6050b5671f3405af0189369452fda6b4df/src/algorithms/math/collatz_conjecture.js#L10-L17
|
12,330
|
felipernb/algorithms.js
|
src/algorithms/math/collatz_conjecture.js
|
generateCollatzConjecture
|
function generateCollatzConjecture(number) {
const collatzConjecture = [];
do {
number = calculateCollatzConjecture(number);
collatzConjecture.push(number);
} while (number !== 1);
return collatzConjecture;
}
|
javascript
|
function generateCollatzConjecture(number) {
const collatzConjecture = [];
do {
number = calculateCollatzConjecture(number);
collatzConjecture.push(number);
} while (number !== 1);
return collatzConjecture;
}
|
[
"function",
"generateCollatzConjecture",
"(",
"number",
")",
"{",
"const",
"collatzConjecture",
"=",
"[",
"]",
";",
"do",
"{",
"number",
"=",
"calculateCollatzConjecture",
"(",
"number",
")",
";",
"collatzConjecture",
".",
"push",
"(",
"number",
")",
";",
"}",
"while",
"(",
"number",
"!==",
"1",
")",
";",
"return",
"collatzConjecture",
";",
"}"
] |
Generate Collatz Conjecture
@param Number
@return Array
|
[
"Generate",
"Collatz",
"Conjecture"
] |
94b4bb6050b5671f3405af0189369452fda6b4df
|
https://github.com/felipernb/algorithms.js/blob/94b4bb6050b5671f3405af0189369452fda6b4df/src/algorithms/math/collatz_conjecture.js#L25-L34
|
12,331
|
felipernb/algorithms.js
|
src/algorithms/graph/dijkstra.js
|
dijkstra
|
function dijkstra(graph, s) {
const distance = {};
const previous = {};
const q = new PriorityQueue();
// Initialize
distance[s] = 0;
graph.vertices.forEach(v => {
if (v !== s) {
distance[v] = Infinity;
}
q.insert(v, distance[v]);
});
let currNode;
const relax = v => {
const newDistance = distance[currNode] + graph.edge(currNode, v);
if (newDistance < distance[v]) {
distance[v] = newDistance;
previous[v] = currNode;
q.changePriority(v, distance[v]);
}
};
while (!q.isEmpty()) {
currNode = q.extract();
graph.neighbors(currNode).forEach(relax);
}
return {
distance,
previous
};
}
|
javascript
|
function dijkstra(graph, s) {
const distance = {};
const previous = {};
const q = new PriorityQueue();
// Initialize
distance[s] = 0;
graph.vertices.forEach(v => {
if (v !== s) {
distance[v] = Infinity;
}
q.insert(v, distance[v]);
});
let currNode;
const relax = v => {
const newDistance = distance[currNode] + graph.edge(currNode, v);
if (newDistance < distance[v]) {
distance[v] = newDistance;
previous[v] = currNode;
q.changePriority(v, distance[v]);
}
};
while (!q.isEmpty()) {
currNode = q.extract();
graph.neighbors(currNode).forEach(relax);
}
return {
distance,
previous
};
}
|
[
"function",
"dijkstra",
"(",
"graph",
",",
"s",
")",
"{",
"const",
"distance",
"=",
"{",
"}",
";",
"const",
"previous",
"=",
"{",
"}",
";",
"const",
"q",
"=",
"new",
"PriorityQueue",
"(",
")",
";",
"// Initialize",
"distance",
"[",
"s",
"]",
"=",
"0",
";",
"graph",
".",
"vertices",
".",
"forEach",
"(",
"v",
"=>",
"{",
"if",
"(",
"v",
"!==",
"s",
")",
"{",
"distance",
"[",
"v",
"]",
"=",
"Infinity",
";",
"}",
"q",
".",
"insert",
"(",
"v",
",",
"distance",
"[",
"v",
"]",
")",
";",
"}",
")",
";",
"let",
"currNode",
";",
"const",
"relax",
"=",
"v",
"=>",
"{",
"const",
"newDistance",
"=",
"distance",
"[",
"currNode",
"]",
"+",
"graph",
".",
"edge",
"(",
"currNode",
",",
"v",
")",
";",
"if",
"(",
"newDistance",
"<",
"distance",
"[",
"v",
"]",
")",
"{",
"distance",
"[",
"v",
"]",
"=",
"newDistance",
";",
"previous",
"[",
"v",
"]",
"=",
"currNode",
";",
"q",
".",
"changePriority",
"(",
"v",
",",
"distance",
"[",
"v",
"]",
")",
";",
"}",
"}",
";",
"while",
"(",
"!",
"q",
".",
"isEmpty",
"(",
")",
")",
"{",
"currNode",
"=",
"q",
".",
"extract",
"(",
")",
";",
"graph",
".",
"neighbors",
"(",
"currNode",
")",
".",
"forEach",
"(",
"relax",
")",
";",
"}",
"return",
"{",
"distance",
",",
"previous",
"}",
";",
"}"
] |
Calculates the shortest paths in a graph to every node from the node s
with Dijkstra's algorithm
@param {Object} graph An adjacency list representing the graph
@param {string} s the starting node
|
[
"Calculates",
"the",
"shortest",
"paths",
"in",
"a",
"graph",
"to",
"every",
"node",
"from",
"the",
"node",
"s",
"with",
"Dijkstra",
"s",
"algorithm"
] |
94b4bb6050b5671f3405af0189369452fda6b4df
|
https://github.com/felipernb/algorithms.js/blob/94b4bb6050b5671f3405af0189369452fda6b4df/src/algorithms/graph/dijkstra.js#L11-L41
|
12,332
|
timekit-io/booking-js
|
src/render.js
|
function(suppliedConfig) {
var targetElement = suppliedConfig.el || getConfig().el;
rootTarget = $(targetElement);
if (rootTarget.length === 0) {
throw triggerError('No target DOM element was found (' + targetElement + ')');
}
rootTarget.addClass('bookingjs');
rootTarget.children(':not(script)').remove();
}
|
javascript
|
function(suppliedConfig) {
var targetElement = suppliedConfig.el || getConfig().el;
rootTarget = $(targetElement);
if (rootTarget.length === 0) {
throw triggerError('No target DOM element was found (' + targetElement + ')');
}
rootTarget.addClass('bookingjs');
rootTarget.children(':not(script)').remove();
}
|
[
"function",
"(",
"suppliedConfig",
")",
"{",
"var",
"targetElement",
"=",
"suppliedConfig",
".",
"el",
"||",
"getConfig",
"(",
")",
".",
"el",
";",
"rootTarget",
"=",
"$",
"(",
"targetElement",
")",
";",
"if",
"(",
"rootTarget",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"triggerError",
"(",
"'No target DOM element was found ('",
"+",
"targetElement",
"+",
"')'",
")",
";",
"}",
"rootTarget",
".",
"addClass",
"(",
"'bookingjs'",
")",
";",
"rootTarget",
".",
"children",
"(",
"':not(script)'",
")",
".",
"remove",
"(",
")",
";",
"}"
] |
Make sure DOM element is ready and clean it
|
[
"Make",
"sure",
"DOM",
"element",
"is",
"ready",
"and",
"clean",
"it"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L34-L47
|
|
12,333
|
timekit-io/booking-js
|
src/render.js
|
function() {
showLoadingScreen();
calendarTarget.fullCalendar('removeEventSources');
if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
// If in group bookings mode, fetch slots
timekitGetBookingSlots();
} else {
// If in normal single-participant mode, call findtime
timekitFetchAvailability();
}
}
|
javascript
|
function() {
showLoadingScreen();
calendarTarget.fullCalendar('removeEventSources');
if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
// If in group bookings mode, fetch slots
timekitGetBookingSlots();
} else {
// If in normal single-participant mode, call findtime
timekitFetchAvailability();
}
}
|
[
"function",
"(",
")",
"{",
"showLoadingScreen",
"(",
")",
";",
"calendarTarget",
".",
"fullCalendar",
"(",
"'removeEventSources'",
")",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"booking",
".",
"graph",
"===",
"'group_customer'",
"||",
"getConfig",
"(",
")",
".",
"booking",
".",
"graph",
"===",
"'group_customer_payment'",
")",
"{",
"// If in group bookings mode, fetch slots",
"timekitGetBookingSlots",
"(",
")",
";",
"}",
"else",
"{",
"// If in normal single-participant mode, call findtime",
"timekitFetchAvailability",
"(",
")",
";",
"}",
"}"
] |
Universal functional to retrieve availability through either findtime or group booking slots
|
[
"Universal",
"functional",
"to",
"retrieve",
"availability",
"through",
"either",
"findtime",
"or",
"group",
"booking",
"slots"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L144-L158
|
|
12,334
|
timekit-io/booking-js
|
src/render.js
|
function(firstEventStart) {
calendarTarget.fullCalendar('gotoDate', firstEventStart);
var firstEventStartHour = moment(firstEventStart).format('H');
scrollToTime(firstEventStartHour);
}
|
javascript
|
function(firstEventStart) {
calendarTarget.fullCalendar('gotoDate', firstEventStart);
var firstEventStartHour = moment(firstEventStart).format('H');
scrollToTime(firstEventStartHour);
}
|
[
"function",
"(",
"firstEventStart",
")",
"{",
"calendarTarget",
".",
"fullCalendar",
"(",
"'gotoDate'",
",",
"firstEventStart",
")",
";",
"var",
"firstEventStartHour",
"=",
"moment",
"(",
"firstEventStart",
")",
".",
"format",
"(",
"'H'",
")",
";",
"scrollToTime",
"(",
"firstEventStartHour",
")",
";",
"}"
] |
Go to the first timeslot in a list of timeslots
|
[
"Go",
"to",
"the",
"first",
"timeslot",
"in",
"a",
"list",
"of",
"timeslots"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L161-L168
|
|
12,335
|
timekit-io/booking-js
|
src/render.js
|
function(time) {
// Only proceed for agendaWeek view
if (calendarTarget.fullCalendar('getView').name !== 'agendaWeek'){
return;
}
// Get height of each hour row
var slotDuration = calendarTarget.fullCalendar('option', 'slotDuration');
var slotDurationMinutes = 30;
if (slotDuration) slotDurationMinutes = slotDuration.slice(3, 5);
var hours = calendarTarget.find('.fc-slats .fc-minor');
var hourHeight = $(hours[0]).height() * (60 / slotDurationMinutes);
// If minTime is set in fullCalendar config, subtract that from the scollTo calculationn
var minTimeHeight = 0;
if (getConfig().fullcalendar.minTime) {
var minTime = moment(getConfig().fullcalendar.minTime, 'HH:mm:ss').format('H');
minTimeHeight = hourHeight * minTime;
}
// Calculate scrolling location and container sizes
var scrollTo = (hourHeight * time) - minTimeHeight;
var scrollable = calendarTarget.find('.fc-scroller');
var scrollableHeight = scrollable.height();
var scrollableScrollTop = scrollable.scrollTop();
var maximumHeight = scrollable.find('.fc-time-grid').height();
// Only perform the scroll if the scrollTo is outside the current visible boundary
if (scrollTo > scrollableScrollTop && scrollTo < scrollableScrollTop + scrollableHeight) {
return;
}
// If scrollTo point is past the maximum height, then scroll to maximum possible while still animating
if (scrollTo > maximumHeight - scrollableHeight) {
scrollTo = maximumHeight - scrollableHeight;
}
// Perform the scrollTo animation
scrollable.animate({scrollTop: scrollTo});
}
|
javascript
|
function(time) {
// Only proceed for agendaWeek view
if (calendarTarget.fullCalendar('getView').name !== 'agendaWeek'){
return;
}
// Get height of each hour row
var slotDuration = calendarTarget.fullCalendar('option', 'slotDuration');
var slotDurationMinutes = 30;
if (slotDuration) slotDurationMinutes = slotDuration.slice(3, 5);
var hours = calendarTarget.find('.fc-slats .fc-minor');
var hourHeight = $(hours[0]).height() * (60 / slotDurationMinutes);
// If minTime is set in fullCalendar config, subtract that from the scollTo calculationn
var minTimeHeight = 0;
if (getConfig().fullcalendar.minTime) {
var minTime = moment(getConfig().fullcalendar.minTime, 'HH:mm:ss').format('H');
minTimeHeight = hourHeight * minTime;
}
// Calculate scrolling location and container sizes
var scrollTo = (hourHeight * time) - minTimeHeight;
var scrollable = calendarTarget.find('.fc-scroller');
var scrollableHeight = scrollable.height();
var scrollableScrollTop = scrollable.scrollTop();
var maximumHeight = scrollable.find('.fc-time-grid').height();
// Only perform the scroll if the scrollTo is outside the current visible boundary
if (scrollTo > scrollableScrollTop && scrollTo < scrollableScrollTop + scrollableHeight) {
return;
}
// If scrollTo point is past the maximum height, then scroll to maximum possible while still animating
if (scrollTo > maximumHeight - scrollableHeight) {
scrollTo = maximumHeight - scrollableHeight;
}
// Perform the scrollTo animation
scrollable.animate({scrollTop: scrollTo});
}
|
[
"function",
"(",
"time",
")",
"{",
"// Only proceed for agendaWeek view",
"if",
"(",
"calendarTarget",
".",
"fullCalendar",
"(",
"'getView'",
")",
".",
"name",
"!==",
"'agendaWeek'",
")",
"{",
"return",
";",
"}",
"// Get height of each hour row",
"var",
"slotDuration",
"=",
"calendarTarget",
".",
"fullCalendar",
"(",
"'option'",
",",
"'slotDuration'",
")",
";",
"var",
"slotDurationMinutes",
"=",
"30",
";",
"if",
"(",
"slotDuration",
")",
"slotDurationMinutes",
"=",
"slotDuration",
".",
"slice",
"(",
"3",
",",
"5",
")",
";",
"var",
"hours",
"=",
"calendarTarget",
".",
"find",
"(",
"'.fc-slats .fc-minor'",
")",
";",
"var",
"hourHeight",
"=",
"$",
"(",
"hours",
"[",
"0",
"]",
")",
".",
"height",
"(",
")",
"*",
"(",
"60",
"/",
"slotDurationMinutes",
")",
";",
"// If minTime is set in fullCalendar config, subtract that from the scollTo calculationn",
"var",
"minTimeHeight",
"=",
"0",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"fullcalendar",
".",
"minTime",
")",
"{",
"var",
"minTime",
"=",
"moment",
"(",
"getConfig",
"(",
")",
".",
"fullcalendar",
".",
"minTime",
",",
"'HH:mm:ss'",
")",
".",
"format",
"(",
"'H'",
")",
";",
"minTimeHeight",
"=",
"hourHeight",
"*",
"minTime",
";",
"}",
"// Calculate scrolling location and container sizes",
"var",
"scrollTo",
"=",
"(",
"hourHeight",
"*",
"time",
")",
"-",
"minTimeHeight",
";",
"var",
"scrollable",
"=",
"calendarTarget",
".",
"find",
"(",
"'.fc-scroller'",
")",
";",
"var",
"scrollableHeight",
"=",
"scrollable",
".",
"height",
"(",
")",
";",
"var",
"scrollableScrollTop",
"=",
"scrollable",
".",
"scrollTop",
"(",
")",
";",
"var",
"maximumHeight",
"=",
"scrollable",
".",
"find",
"(",
"'.fc-time-grid'",
")",
".",
"height",
"(",
")",
";",
"// Only perform the scroll if the scrollTo is outside the current visible boundary",
"if",
"(",
"scrollTo",
">",
"scrollableScrollTop",
"&&",
"scrollTo",
"<",
"scrollableScrollTop",
"+",
"scrollableHeight",
")",
"{",
"return",
";",
"}",
"// If scrollTo point is past the maximum height, then scroll to maximum possible while still animating",
"if",
"(",
"scrollTo",
">",
"maximumHeight",
"-",
"scrollableHeight",
")",
"{",
"scrollTo",
"=",
"maximumHeight",
"-",
"scrollableHeight",
";",
"}",
"// Perform the scrollTo animation",
"scrollable",
".",
"animate",
"(",
"{",
"scrollTop",
":",
"scrollTo",
"}",
")",
";",
"}"
] |
Scrolls fullcalendar to the specified hour
|
[
"Scrolls",
"fullcalendar",
"to",
"the",
"specified",
"hour"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L171-L212
|
|
12,336
|
timekit-io/booking-js
|
src/render.js
|
function() {
var showTimezoneHelper = getConfig().ui.show_timezone_helper;
var showCredits = getConfig().ui.show_credits;
// If neither TZ helper or credits is shown, dont render the footer
if (!showTimezoneHelper && !showCredits) return
var campaignName = 'widget';
var campaignSource = window.location.hostname.replace(/\./g, '-');
if (getConfig().project_id) { campaignName = 'embedded-widget'; }
if (getConfig().project_slug) { campaignName = 'hosted-widget'; }
var timezoneIcon = require('!svg-inline!./assets/timezone-icon.svg');
var arrowDownIcon = require('!svg-inline!./assets/arrow-down-icon.svg');
var timekitLogo = require('!svg-inline!./assets/timekit-logo.svg');
var template = require('./templates/footer.html');
var footerTarget = $(template.render({
timezoneIcon: timezoneIcon,
arrowDownIcon: arrowDownIcon,
listTimezones: timezones,
timekitLogo: timekitLogo,
campaignName: campaignName,
campaignSource: campaignSource,
showCredits: showCredits,
showTimezoneHelper: showTimezoneHelper
}));
rootTarget.append(footerTarget);
// Set initial customer timezone
var pickerSelect = $('.bookingjs-footer-tz-picker-select');
pickerSelect.val(customerTimezone);
// Listen to changes by the user
pickerSelect.change(function() {
setCustomerTimezone(pickerSelect.val());
$(rootTarget).trigger('customer-timezone-changed');
})
}
|
javascript
|
function() {
var showTimezoneHelper = getConfig().ui.show_timezone_helper;
var showCredits = getConfig().ui.show_credits;
// If neither TZ helper or credits is shown, dont render the footer
if (!showTimezoneHelper && !showCredits) return
var campaignName = 'widget';
var campaignSource = window.location.hostname.replace(/\./g, '-');
if (getConfig().project_id) { campaignName = 'embedded-widget'; }
if (getConfig().project_slug) { campaignName = 'hosted-widget'; }
var timezoneIcon = require('!svg-inline!./assets/timezone-icon.svg');
var arrowDownIcon = require('!svg-inline!./assets/arrow-down-icon.svg');
var timekitLogo = require('!svg-inline!./assets/timekit-logo.svg');
var template = require('./templates/footer.html');
var footerTarget = $(template.render({
timezoneIcon: timezoneIcon,
arrowDownIcon: arrowDownIcon,
listTimezones: timezones,
timekitLogo: timekitLogo,
campaignName: campaignName,
campaignSource: campaignSource,
showCredits: showCredits,
showTimezoneHelper: showTimezoneHelper
}));
rootTarget.append(footerTarget);
// Set initial customer timezone
var pickerSelect = $('.bookingjs-footer-tz-picker-select');
pickerSelect.val(customerTimezone);
// Listen to changes by the user
pickerSelect.change(function() {
setCustomerTimezone(pickerSelect.val());
$(rootTarget).trigger('customer-timezone-changed');
})
}
|
[
"function",
"(",
")",
"{",
"var",
"showTimezoneHelper",
"=",
"getConfig",
"(",
")",
".",
"ui",
".",
"show_timezone_helper",
";",
"var",
"showCredits",
"=",
"getConfig",
"(",
")",
".",
"ui",
".",
"show_credits",
";",
"// If neither TZ helper or credits is shown, dont render the footer",
"if",
"(",
"!",
"showTimezoneHelper",
"&&",
"!",
"showCredits",
")",
"return",
"var",
"campaignName",
"=",
"'widget'",
";",
"var",
"campaignSource",
"=",
"window",
".",
"location",
".",
"hostname",
".",
"replace",
"(",
"/",
"\\.",
"/",
"g",
",",
"'-'",
")",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"project_id",
")",
"{",
"campaignName",
"=",
"'embedded-widget'",
";",
"}",
"if",
"(",
"getConfig",
"(",
")",
".",
"project_slug",
")",
"{",
"campaignName",
"=",
"'hosted-widget'",
";",
"}",
"var",
"timezoneIcon",
"=",
"require",
"(",
"'!svg-inline!./assets/timezone-icon.svg'",
")",
";",
"var",
"arrowDownIcon",
"=",
"require",
"(",
"'!svg-inline!./assets/arrow-down-icon.svg'",
")",
";",
"var",
"timekitLogo",
"=",
"require",
"(",
"'!svg-inline!./assets/timekit-logo.svg'",
")",
";",
"var",
"template",
"=",
"require",
"(",
"'./templates/footer.html'",
")",
";",
"var",
"footerTarget",
"=",
"$",
"(",
"template",
".",
"render",
"(",
"{",
"timezoneIcon",
":",
"timezoneIcon",
",",
"arrowDownIcon",
":",
"arrowDownIcon",
",",
"listTimezones",
":",
"timezones",
",",
"timekitLogo",
":",
"timekitLogo",
",",
"campaignName",
":",
"campaignName",
",",
"campaignSource",
":",
"campaignSource",
",",
"showCredits",
":",
"showCredits",
",",
"showTimezoneHelper",
":",
"showTimezoneHelper",
"}",
")",
")",
";",
"rootTarget",
".",
"append",
"(",
"footerTarget",
")",
";",
"// Set initial customer timezone",
"var",
"pickerSelect",
"=",
"$",
"(",
"'.bookingjs-footer-tz-picker-select'",
")",
";",
"pickerSelect",
".",
"val",
"(",
"customerTimezone",
")",
";",
"// Listen to changes by the user",
"pickerSelect",
".",
"change",
"(",
"function",
"(",
")",
"{",
"setCustomerTimezone",
"(",
"pickerSelect",
".",
"val",
"(",
")",
")",
";",
"$",
"(",
"rootTarget",
")",
".",
"trigger",
"(",
"'customer-timezone-changed'",
")",
";",
"}",
")",
"}"
] |
Calculate and display timezone helper
|
[
"Calculate",
"and",
"display",
"timezone",
"helper"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L228-L267
|
|
12,337
|
timekit-io/booking-js
|
src/render.js
|
function () {
var tzGuess = moment.tz.guess() || 'UTC';
setCustomerTimezone(tzGuess);
// Add the guessed customer timezone to list if its unknwon
var knownTimezone = $.grep(timezones, function (tz) {
return tz.key === customerTimezone
}).length > 0
if (!knownTimezone) {
var name = '(' + moment().tz(customerTimezone).format('Z') + ') ' + customerTimezone
timezones.unshift({
key: customerTimezone,
name: name
});
}
}
|
javascript
|
function () {
var tzGuess = moment.tz.guess() || 'UTC';
setCustomerTimezone(tzGuess);
// Add the guessed customer timezone to list if its unknwon
var knownTimezone = $.grep(timezones, function (tz) {
return tz.key === customerTimezone
}).length > 0
if (!knownTimezone) {
var name = '(' + moment().tz(customerTimezone).format('Z') + ') ' + customerTimezone
timezones.unshift({
key: customerTimezone,
name: name
});
}
}
|
[
"function",
"(",
")",
"{",
"var",
"tzGuess",
"=",
"moment",
".",
"tz",
".",
"guess",
"(",
")",
"||",
"'UTC'",
";",
"setCustomerTimezone",
"(",
"tzGuess",
")",
";",
"// Add the guessed customer timezone to list if its unknwon",
"var",
"knownTimezone",
"=",
"$",
".",
"grep",
"(",
"timezones",
",",
"function",
"(",
"tz",
")",
"{",
"return",
"tz",
".",
"key",
"===",
"customerTimezone",
"}",
")",
".",
"length",
">",
"0",
"if",
"(",
"!",
"knownTimezone",
")",
"{",
"var",
"name",
"=",
"'('",
"+",
"moment",
"(",
")",
".",
"tz",
"(",
"customerTimezone",
")",
".",
"format",
"(",
"'Z'",
")",
"+",
"') '",
"+",
"customerTimezone",
"timezones",
".",
"unshift",
"(",
"{",
"key",
":",
"customerTimezone",
",",
"name",
":",
"name",
"}",
")",
";",
"}",
"}"
] |
Guess the timezone and set global variable
|
[
"Guess",
"the",
"timezone",
"and",
"set",
"global",
"variable"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L270-L285
|
|
12,338
|
timekit-io/booking-js
|
src/render.js
|
function() {
var sizing = decideCalendarSize(getConfig().fullcalendar.defaultView);
var args = {
height: sizing.height,
eventClick: clickTimeslot,
windowResize: function() {
var sizing = decideCalendarSize();
calendarTarget.fullCalendar('changeView', sizing.view);
calendarTarget.fullCalendar('option', 'height', sizing.height);
}
};
$.extend(true, args, getConfig().fullcalendar);
args.defaultView = sizing.view;
calendarTarget = $('<div class="bookingjs-calendar empty-calendar">');
rootTarget.append(calendarTarget);
calendarTarget.fullCalendar(args);
$(rootTarget).on('customer-timezone-changed', function () {
if (!calendarTarget) return
getAvailability();
calendarTarget.fullCalendar('option', 'now', moment().tz(customerTimezone).format());
})
utils.doCallback('fullCalendarInitialized');
}
|
javascript
|
function() {
var sizing = decideCalendarSize(getConfig().fullcalendar.defaultView);
var args = {
height: sizing.height,
eventClick: clickTimeslot,
windowResize: function() {
var sizing = decideCalendarSize();
calendarTarget.fullCalendar('changeView', sizing.view);
calendarTarget.fullCalendar('option', 'height', sizing.height);
}
};
$.extend(true, args, getConfig().fullcalendar);
args.defaultView = sizing.view;
calendarTarget = $('<div class="bookingjs-calendar empty-calendar">');
rootTarget.append(calendarTarget);
calendarTarget.fullCalendar(args);
$(rootTarget).on('customer-timezone-changed', function () {
if (!calendarTarget) return
getAvailability();
calendarTarget.fullCalendar('option', 'now', moment().tz(customerTimezone).format());
})
utils.doCallback('fullCalendarInitialized');
}
|
[
"function",
"(",
")",
"{",
"var",
"sizing",
"=",
"decideCalendarSize",
"(",
"getConfig",
"(",
")",
".",
"fullcalendar",
".",
"defaultView",
")",
";",
"var",
"args",
"=",
"{",
"height",
":",
"sizing",
".",
"height",
",",
"eventClick",
":",
"clickTimeslot",
",",
"windowResize",
":",
"function",
"(",
")",
"{",
"var",
"sizing",
"=",
"decideCalendarSize",
"(",
")",
";",
"calendarTarget",
".",
"fullCalendar",
"(",
"'changeView'",
",",
"sizing",
".",
"view",
")",
";",
"calendarTarget",
".",
"fullCalendar",
"(",
"'option'",
",",
"'height'",
",",
"sizing",
".",
"height",
")",
";",
"}",
"}",
";",
"$",
".",
"extend",
"(",
"true",
",",
"args",
",",
"getConfig",
"(",
")",
".",
"fullcalendar",
")",
";",
"args",
".",
"defaultView",
"=",
"sizing",
".",
"view",
";",
"calendarTarget",
"=",
"$",
"(",
"'<div class=\"bookingjs-calendar empty-calendar\">'",
")",
";",
"rootTarget",
".",
"append",
"(",
"calendarTarget",
")",
";",
"calendarTarget",
".",
"fullCalendar",
"(",
"args",
")",
";",
"$",
"(",
"rootTarget",
")",
".",
"on",
"(",
"'customer-timezone-changed'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"calendarTarget",
")",
"return",
"getAvailability",
"(",
")",
";",
"calendarTarget",
".",
"fullCalendar",
"(",
"'option'",
",",
"'now'",
",",
"moment",
"(",
")",
".",
"tz",
"(",
"customerTimezone",
")",
".",
"format",
"(",
")",
")",
";",
"}",
")",
"utils",
".",
"doCallback",
"(",
"'fullCalendarInitialized'",
")",
";",
"}"
] |
Setup and render FullCalendar
|
[
"Setup",
"and",
"render",
"FullCalendar"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L296-L326
|
|
12,339
|
timekit-io/booking-js
|
src/render.js
|
function(eventData) {
if (!getConfig().disable_confirm_page) {
showBookingPage(eventData)
} else {
$('.fc-event-clicked').removeClass('fc-event-clicked');
$(this).addClass('fc-event-clicked');
utils.doCallback('clickTimeslot', eventData);
}
}
|
javascript
|
function(eventData) {
if (!getConfig().disable_confirm_page) {
showBookingPage(eventData)
} else {
$('.fc-event-clicked').removeClass('fc-event-clicked');
$(this).addClass('fc-event-clicked');
utils.doCallback('clickTimeslot', eventData);
}
}
|
[
"function",
"(",
"eventData",
")",
"{",
"if",
"(",
"!",
"getConfig",
"(",
")",
".",
"disable_confirm_page",
")",
"{",
"showBookingPage",
"(",
"eventData",
")",
"}",
"else",
"{",
"$",
"(",
"'.fc-event-clicked'",
")",
".",
"removeClass",
"(",
"'fc-event-clicked'",
")",
";",
"$",
"(",
"this",
")",
".",
"addClass",
"(",
"'fc-event-clicked'",
")",
";",
"utils",
".",
"doCallback",
"(",
"'clickTimeslot'",
",",
"eventData",
")",
";",
"}",
"}"
] |
Clicking a timeslot
|
[
"Clicking",
"a",
"timeslot"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L329-L339
|
|
12,340
|
timekit-io/booking-js
|
src/render.js
|
function(currentView) {
currentView = currentView || calendarTarget.fullCalendar('getView').name
var view = getConfig().fullcalendar.defaultView
var height = 385;
if (rootTarget.width() < 480) {
rootTarget.addClass('is-small');
if (getConfig().ui.avatar) height -= 15;
if (currentView === 'agendaWeek' || currentView === 'basicDay') {
view = 'basicDay';
}
} else {
rootTarget.removeClass('is-small');
}
$.each(getConfig().customer_fields, function(key, field) {
if (field.format === 'textarea') height += 98;
else if (field.format === 'checkbox') height += 51;
else height += 66;
})
return {
height: height,
view: view
};
}
|
javascript
|
function(currentView) {
currentView = currentView || calendarTarget.fullCalendar('getView').name
var view = getConfig().fullcalendar.defaultView
var height = 385;
if (rootTarget.width() < 480) {
rootTarget.addClass('is-small');
if (getConfig().ui.avatar) height -= 15;
if (currentView === 'agendaWeek' || currentView === 'basicDay') {
view = 'basicDay';
}
} else {
rootTarget.removeClass('is-small');
}
$.each(getConfig().customer_fields, function(key, field) {
if (field.format === 'textarea') height += 98;
else if (field.format === 'checkbox') height += 51;
else height += 66;
})
return {
height: height,
view: view
};
}
|
[
"function",
"(",
"currentView",
")",
"{",
"currentView",
"=",
"currentView",
"||",
"calendarTarget",
".",
"fullCalendar",
"(",
"'getView'",
")",
".",
"name",
"var",
"view",
"=",
"getConfig",
"(",
")",
".",
"fullcalendar",
".",
"defaultView",
"var",
"height",
"=",
"385",
";",
"if",
"(",
"rootTarget",
".",
"width",
"(",
")",
"<",
"480",
")",
"{",
"rootTarget",
".",
"addClass",
"(",
"'is-small'",
")",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"ui",
".",
"avatar",
")",
"height",
"-=",
"15",
";",
"if",
"(",
"currentView",
"===",
"'agendaWeek'",
"||",
"currentView",
"===",
"'basicDay'",
")",
"{",
"view",
"=",
"'basicDay'",
";",
"}",
"}",
"else",
"{",
"rootTarget",
".",
"removeClass",
"(",
"'is-small'",
")",
";",
"}",
"$",
".",
"each",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
",",
"function",
"(",
"key",
",",
"field",
")",
"{",
"if",
"(",
"field",
".",
"format",
"===",
"'textarea'",
")",
"height",
"+=",
"98",
";",
"else",
"if",
"(",
"field",
".",
"format",
"===",
"'checkbox'",
")",
"height",
"+=",
"51",
";",
"else",
"height",
"+=",
"66",
";",
"}",
")",
"return",
"{",
"height",
":",
"height",
",",
"view",
":",
"view",
"}",
";",
"}"
] |
Fires when window is resized and calendar must adhere
|
[
"Fires",
"when",
"window",
"is",
"resized",
"and",
"calendar",
"must",
"adhere"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L342-L370
|
|
12,341
|
timekit-io/booking-js
|
src/render.js
|
function(eventData) {
var firstEventStart = moment(eventData[0].start)
var firstEventEnd = moment(eventData[0].end)
var firstEventDuration = firstEventEnd.diff(firstEventStart, 'minutes')
if (firstEventDuration <= 90) {
calendarTarget.fullCalendar('option', 'slotDuration', '00:15:00')
}
calendarTarget.fullCalendar('addEventSource', {
events: eventData
});
calendarTarget.removeClass('empty-calendar');
// Go to first event if enabled
goToFirstEvent(eventData[0].start);
}
|
javascript
|
function(eventData) {
var firstEventStart = moment(eventData[0].start)
var firstEventEnd = moment(eventData[0].end)
var firstEventDuration = firstEventEnd.diff(firstEventStart, 'minutes')
if (firstEventDuration <= 90) {
calendarTarget.fullCalendar('option', 'slotDuration', '00:15:00')
}
calendarTarget.fullCalendar('addEventSource', {
events: eventData
});
calendarTarget.removeClass('empty-calendar');
// Go to first event if enabled
goToFirstEvent(eventData[0].start);
}
|
[
"function",
"(",
"eventData",
")",
"{",
"var",
"firstEventStart",
"=",
"moment",
"(",
"eventData",
"[",
"0",
"]",
".",
"start",
")",
"var",
"firstEventEnd",
"=",
"moment",
"(",
"eventData",
"[",
"0",
"]",
".",
"end",
")",
"var",
"firstEventDuration",
"=",
"firstEventEnd",
".",
"diff",
"(",
"firstEventStart",
",",
"'minutes'",
")",
"if",
"(",
"firstEventDuration",
"<=",
"90",
")",
"{",
"calendarTarget",
".",
"fullCalendar",
"(",
"'option'",
",",
"'slotDuration'",
",",
"'00:15:00'",
")",
"}",
"calendarTarget",
".",
"fullCalendar",
"(",
"'addEventSource'",
",",
"{",
"events",
":",
"eventData",
"}",
")",
";",
"calendarTarget",
".",
"removeClass",
"(",
"'empty-calendar'",
")",
";",
"// Go to first event if enabled",
"goToFirstEvent",
"(",
"eventData",
"[",
"0",
"]",
".",
"start",
")",
";",
"}"
] |
Render the supplied calendar events in FullCalendar
|
[
"Render",
"the",
"supplied",
"calendar",
"events",
"in",
"FullCalendar"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L373-L392
|
|
12,342
|
timekit-io/booking-js
|
src/render.js
|
function() {
utils.doCallback('showLoadingScreen');
var template = require('./templates/loading.html');
loadingTarget = $(template.render({
loadingIcon: require('!svg-inline!./assets/loading-spinner.svg')
}));
rootTarget.append(loadingTarget);
}
|
javascript
|
function() {
utils.doCallback('showLoadingScreen');
var template = require('./templates/loading.html');
loadingTarget = $(template.render({
loadingIcon: require('!svg-inline!./assets/loading-spinner.svg')
}));
rootTarget.append(loadingTarget);
}
|
[
"function",
"(",
")",
"{",
"utils",
".",
"doCallback",
"(",
"'showLoadingScreen'",
")",
";",
"var",
"template",
"=",
"require",
"(",
"'./templates/loading.html'",
")",
";",
"loadingTarget",
"=",
"$",
"(",
"template",
".",
"render",
"(",
"{",
"loadingIcon",
":",
"require",
"(",
"'!svg-inline!./assets/loading-spinner.svg'",
")",
"}",
")",
")",
";",
"rootTarget",
".",
"append",
"(",
"loadingTarget",
")",
";",
"}"
] |
Show loading spinner screen
|
[
"Show",
"loading",
"spinner",
"screen"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L421-L432
|
|
12,343
|
timekit-io/booking-js
|
src/render.js
|
function(message) {
// If an error already has been thrown, exit
if (errorTarget) return message
utils.doCallback('errorTriggered', message);
utils.logError(message)
// If no target DOM element exists, only do the logging
if (!rootTarget) return message
var messageProcessed = message
var contextProcessed = null
if (utils.isArray(message)) {
messageProcessed = message[0]
if (message[1].data) {
contextProcessed = stringify(message[1].data.errors || message[1].data.error || message[1].data)
} else {
contextProcessed = stringify(message[1])
}
}
var template = require('./templates/error.html');
errorTarget = $(template.render({
errorWarningIcon: require('!svg-inline!./assets/error-warning-icon.svg'),
message: messageProcessed,
context: contextProcessed
}));
rootTarget.append(errorTarget);
return message
}
|
javascript
|
function(message) {
// If an error already has been thrown, exit
if (errorTarget) return message
utils.doCallback('errorTriggered', message);
utils.logError(message)
// If no target DOM element exists, only do the logging
if (!rootTarget) return message
var messageProcessed = message
var contextProcessed = null
if (utils.isArray(message)) {
messageProcessed = message[0]
if (message[1].data) {
contextProcessed = stringify(message[1].data.errors || message[1].data.error || message[1].data)
} else {
contextProcessed = stringify(message[1])
}
}
var template = require('./templates/error.html');
errorTarget = $(template.render({
errorWarningIcon: require('!svg-inline!./assets/error-warning-icon.svg'),
message: messageProcessed,
context: contextProcessed
}));
rootTarget.append(errorTarget);
return message
}
|
[
"function",
"(",
"message",
")",
"{",
"// If an error already has been thrown, exit",
"if",
"(",
"errorTarget",
")",
"return",
"message",
"utils",
".",
"doCallback",
"(",
"'errorTriggered'",
",",
"message",
")",
";",
"utils",
".",
"logError",
"(",
"message",
")",
"// If no target DOM element exists, only do the logging",
"if",
"(",
"!",
"rootTarget",
")",
"return",
"message",
"var",
"messageProcessed",
"=",
"message",
"var",
"contextProcessed",
"=",
"null",
"if",
"(",
"utils",
".",
"isArray",
"(",
"message",
")",
")",
"{",
"messageProcessed",
"=",
"message",
"[",
"0",
"]",
"if",
"(",
"message",
"[",
"1",
"]",
".",
"data",
")",
"{",
"contextProcessed",
"=",
"stringify",
"(",
"message",
"[",
"1",
"]",
".",
"data",
".",
"errors",
"||",
"message",
"[",
"1",
"]",
".",
"data",
".",
"error",
"||",
"message",
"[",
"1",
"]",
".",
"data",
")",
"}",
"else",
"{",
"contextProcessed",
"=",
"stringify",
"(",
"message",
"[",
"1",
"]",
")",
"}",
"}",
"var",
"template",
"=",
"require",
"(",
"'./templates/error.html'",
")",
";",
"errorTarget",
"=",
"$",
"(",
"template",
".",
"render",
"(",
"{",
"errorWarningIcon",
":",
"require",
"(",
"'!svg-inline!./assets/error-warning-icon.svg'",
")",
",",
"message",
":",
"messageProcessed",
",",
"context",
":",
"contextProcessed",
"}",
")",
")",
";",
"rootTarget",
".",
"append",
"(",
"errorTarget",
")",
";",
"return",
"message",
"}"
] |
Show error and warning screen
|
[
"Show",
"error",
"and",
"warning",
"screen"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L447-L481
|
|
12,344
|
timekit-io/booking-js
|
src/render.js
|
function () {
var textTemplate = require('./templates/fields/text.html');
var textareaTemplate = require('./templates/fields/textarea.html');
var selectTemplate = require('./templates/fields/select.html');
var checkboxTemplate = require('./templates/fields/checkbox.html');
var fieldsTarget = []
$.each(getConfig().customer_fields, function(key, field) {
var tmpl = textTemplate
if (field.format === 'textarea') tmpl = textareaTemplate
if (field.format === 'select') tmpl = selectTemplate
if (field.format === 'checkbox') tmpl = checkboxTemplate
if (!field.format) field.format = 'text'
if (key === 'email') field.format = 'email'
var data = $.extend({
key: key,
arrowDownIcon: require('!svg-inline!./assets/arrow-down-icon.svg')
}, field)
var fieldTarget = $(tmpl.render(data))
fieldsTarget.push(fieldTarget)
})
return fieldsTarget
}
|
javascript
|
function () {
var textTemplate = require('./templates/fields/text.html');
var textareaTemplate = require('./templates/fields/textarea.html');
var selectTemplate = require('./templates/fields/select.html');
var checkboxTemplate = require('./templates/fields/checkbox.html');
var fieldsTarget = []
$.each(getConfig().customer_fields, function(key, field) {
var tmpl = textTemplate
if (field.format === 'textarea') tmpl = textareaTemplate
if (field.format === 'select') tmpl = selectTemplate
if (field.format === 'checkbox') tmpl = checkboxTemplate
if (!field.format) field.format = 'text'
if (key === 'email') field.format = 'email'
var data = $.extend({
key: key,
arrowDownIcon: require('!svg-inline!./assets/arrow-down-icon.svg')
}, field)
var fieldTarget = $(tmpl.render(data))
fieldsTarget.push(fieldTarget)
})
return fieldsTarget
}
|
[
"function",
"(",
")",
"{",
"var",
"textTemplate",
"=",
"require",
"(",
"'./templates/fields/text.html'",
")",
";",
"var",
"textareaTemplate",
"=",
"require",
"(",
"'./templates/fields/textarea.html'",
")",
";",
"var",
"selectTemplate",
"=",
"require",
"(",
"'./templates/fields/select.html'",
")",
";",
"var",
"checkboxTemplate",
"=",
"require",
"(",
"'./templates/fields/checkbox.html'",
")",
";",
"var",
"fieldsTarget",
"=",
"[",
"]",
"$",
".",
"each",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
",",
"function",
"(",
"key",
",",
"field",
")",
"{",
"var",
"tmpl",
"=",
"textTemplate",
"if",
"(",
"field",
".",
"format",
"===",
"'textarea'",
")",
"tmpl",
"=",
"textareaTemplate",
"if",
"(",
"field",
".",
"format",
"===",
"'select'",
")",
"tmpl",
"=",
"selectTemplate",
"if",
"(",
"field",
".",
"format",
"===",
"'checkbox'",
")",
"tmpl",
"=",
"checkboxTemplate",
"if",
"(",
"!",
"field",
".",
"format",
")",
"field",
".",
"format",
"=",
"'text'",
"if",
"(",
"key",
"===",
"'email'",
")",
"field",
".",
"format",
"=",
"'email'",
"var",
"data",
"=",
"$",
".",
"extend",
"(",
"{",
"key",
":",
"key",
",",
"arrowDownIcon",
":",
"require",
"(",
"'!svg-inline!./assets/arrow-down-icon.svg'",
")",
"}",
",",
"field",
")",
"var",
"fieldTarget",
"=",
"$",
"(",
"tmpl",
".",
"render",
"(",
"data",
")",
")",
"fieldsTarget",
".",
"push",
"(",
"fieldTarget",
")",
"}",
")",
"return",
"fieldsTarget",
"}"
] |
Render customer fields
|
[
"Render",
"customer",
"fields"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L484-L508
|
|
12,345
|
timekit-io/booking-js
|
src/render.js
|
function(eventData) {
utils.doCallback('showBookingPage', eventData);
var template = require('./templates/booking-page.html');
var dateFormat = getConfig().ui.booking_date_format || moment.localeData().longDateFormat('LL');
var timeFormat = getConfig().ui.booking_time_format || moment.localeData().longDateFormat('LT');
var allocatedResource = eventData.resources ? eventData.resources[0].name : false;
bookingPageTarget = $(template.render({
chosenDate: formatTimestamp(eventData.start, dateFormat),
chosenTime: formatTimestamp(eventData.start, timeFormat) + ' - ' + formatTimestamp(eventData.end, timeFormat),
allocatedResourcePrefix: getConfig().ui.localization.allocated_resource_prefix,
allocatedResource: allocatedResource,
closeIcon: require('!svg-inline!./assets/close-icon.svg'),
checkmarkIcon: require('!svg-inline!./assets/checkmark-icon.svg'),
loadingIcon: require('!svg-inline!./assets/loading-spinner.svg'),
errorIcon: require('!svg-inline!./assets/error-icon.svg'),
submitText: getConfig().ui.localization.submit_button,
successMessage: interpolate.sprintf(getConfig().ui.localization.success_message, '<span class="booked-email"></span>')
}));
var formFields = bookingPageTarget.find('.bookingjs-form-fields');
$(formFields).append(renderCustomerFields());
var form = bookingPageTarget.children('.bookingjs-form');
bookingPageTarget.children('.bookingjs-bookpage-close').click(function(e) {
e.preventDefault();
var bookingHasBeenCreated = $(form).hasClass('success');
if (bookingHasBeenCreated) getAvailability();
hideBookingPage();
});
if (eventData.resources) {
utils.logDebug(['Available resources for chosen timeslot:', eventData.resources]);
}
form.find('.bookingjs-form-input').on('input', function() {
var field = $(this).closest('.bookingjs-form-field');
if (this.value) field.addClass('bookingjs-form-field--dirty');
else field.removeClass('bookingjs-form-field--dirty');
});
form.submit(function(e) {
submitBookingForm(this, e, eventData);
});
$(rootTarget).on('customer-timezone-changed', function () {
if (!bookingPageTarget) return
$('.bookingjs-bookpage-date').text(formatTimestamp(eventData.start, dateFormat));
$('.bookingjs-bookpage-time').text(formatTimestamp(eventData.start, timeFormat) + ' - ' + formatTimestamp(eventData.end, timeFormat));
});
$(document).on('keyup', function(e) {
// escape key maps to keycode `27`
if (e.keyCode === 27) { hideBookingPage(); }
});
rootTarget.append(bookingPageTarget);
setTimeout(function(){
bookingPageTarget.addClass('show');
}, 100);
}
|
javascript
|
function(eventData) {
utils.doCallback('showBookingPage', eventData);
var template = require('./templates/booking-page.html');
var dateFormat = getConfig().ui.booking_date_format || moment.localeData().longDateFormat('LL');
var timeFormat = getConfig().ui.booking_time_format || moment.localeData().longDateFormat('LT');
var allocatedResource = eventData.resources ? eventData.resources[0].name : false;
bookingPageTarget = $(template.render({
chosenDate: formatTimestamp(eventData.start, dateFormat),
chosenTime: formatTimestamp(eventData.start, timeFormat) + ' - ' + formatTimestamp(eventData.end, timeFormat),
allocatedResourcePrefix: getConfig().ui.localization.allocated_resource_prefix,
allocatedResource: allocatedResource,
closeIcon: require('!svg-inline!./assets/close-icon.svg'),
checkmarkIcon: require('!svg-inline!./assets/checkmark-icon.svg'),
loadingIcon: require('!svg-inline!./assets/loading-spinner.svg'),
errorIcon: require('!svg-inline!./assets/error-icon.svg'),
submitText: getConfig().ui.localization.submit_button,
successMessage: interpolate.sprintf(getConfig().ui.localization.success_message, '<span class="booked-email"></span>')
}));
var formFields = bookingPageTarget.find('.bookingjs-form-fields');
$(formFields).append(renderCustomerFields());
var form = bookingPageTarget.children('.bookingjs-form');
bookingPageTarget.children('.bookingjs-bookpage-close').click(function(e) {
e.preventDefault();
var bookingHasBeenCreated = $(form).hasClass('success');
if (bookingHasBeenCreated) getAvailability();
hideBookingPage();
});
if (eventData.resources) {
utils.logDebug(['Available resources for chosen timeslot:', eventData.resources]);
}
form.find('.bookingjs-form-input').on('input', function() {
var field = $(this).closest('.bookingjs-form-field');
if (this.value) field.addClass('bookingjs-form-field--dirty');
else field.removeClass('bookingjs-form-field--dirty');
});
form.submit(function(e) {
submitBookingForm(this, e, eventData);
});
$(rootTarget).on('customer-timezone-changed', function () {
if (!bookingPageTarget) return
$('.bookingjs-bookpage-date').text(formatTimestamp(eventData.start, dateFormat));
$('.bookingjs-bookpage-time').text(formatTimestamp(eventData.start, timeFormat) + ' - ' + formatTimestamp(eventData.end, timeFormat));
});
$(document).on('keyup', function(e) {
// escape key maps to keycode `27`
if (e.keyCode === 27) { hideBookingPage(); }
});
rootTarget.append(bookingPageTarget);
setTimeout(function(){
bookingPageTarget.addClass('show');
}, 100);
}
|
[
"function",
"(",
"eventData",
")",
"{",
"utils",
".",
"doCallback",
"(",
"'showBookingPage'",
",",
"eventData",
")",
";",
"var",
"template",
"=",
"require",
"(",
"'./templates/booking-page.html'",
")",
";",
"var",
"dateFormat",
"=",
"getConfig",
"(",
")",
".",
"ui",
".",
"booking_date_format",
"||",
"moment",
".",
"localeData",
"(",
")",
".",
"longDateFormat",
"(",
"'LL'",
")",
";",
"var",
"timeFormat",
"=",
"getConfig",
"(",
")",
".",
"ui",
".",
"booking_time_format",
"||",
"moment",
".",
"localeData",
"(",
")",
".",
"longDateFormat",
"(",
"'LT'",
")",
";",
"var",
"allocatedResource",
"=",
"eventData",
".",
"resources",
"?",
"eventData",
".",
"resources",
"[",
"0",
"]",
".",
"name",
":",
"false",
";",
"bookingPageTarget",
"=",
"$",
"(",
"template",
".",
"render",
"(",
"{",
"chosenDate",
":",
"formatTimestamp",
"(",
"eventData",
".",
"start",
",",
"dateFormat",
")",
",",
"chosenTime",
":",
"formatTimestamp",
"(",
"eventData",
".",
"start",
",",
"timeFormat",
")",
"+",
"' - '",
"+",
"formatTimestamp",
"(",
"eventData",
".",
"end",
",",
"timeFormat",
")",
",",
"allocatedResourcePrefix",
":",
"getConfig",
"(",
")",
".",
"ui",
".",
"localization",
".",
"allocated_resource_prefix",
",",
"allocatedResource",
":",
"allocatedResource",
",",
"closeIcon",
":",
"require",
"(",
"'!svg-inline!./assets/close-icon.svg'",
")",
",",
"checkmarkIcon",
":",
"require",
"(",
"'!svg-inline!./assets/checkmark-icon.svg'",
")",
",",
"loadingIcon",
":",
"require",
"(",
"'!svg-inline!./assets/loading-spinner.svg'",
")",
",",
"errorIcon",
":",
"require",
"(",
"'!svg-inline!./assets/error-icon.svg'",
")",
",",
"submitText",
":",
"getConfig",
"(",
")",
".",
"ui",
".",
"localization",
".",
"submit_button",
",",
"successMessage",
":",
"interpolate",
".",
"sprintf",
"(",
"getConfig",
"(",
")",
".",
"ui",
".",
"localization",
".",
"success_message",
",",
"'<span class=\"booked-email\"></span>'",
")",
"}",
")",
")",
";",
"var",
"formFields",
"=",
"bookingPageTarget",
".",
"find",
"(",
"'.bookingjs-form-fields'",
")",
";",
"$",
"(",
"formFields",
")",
".",
"append",
"(",
"renderCustomerFields",
"(",
")",
")",
";",
"var",
"form",
"=",
"bookingPageTarget",
".",
"children",
"(",
"'.bookingjs-form'",
")",
";",
"bookingPageTarget",
".",
"children",
"(",
"'.bookingjs-bookpage-close'",
")",
".",
"click",
"(",
"function",
"(",
"e",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"bookingHasBeenCreated",
"=",
"$",
"(",
"form",
")",
".",
"hasClass",
"(",
"'success'",
")",
";",
"if",
"(",
"bookingHasBeenCreated",
")",
"getAvailability",
"(",
")",
";",
"hideBookingPage",
"(",
")",
";",
"}",
")",
";",
"if",
"(",
"eventData",
".",
"resources",
")",
"{",
"utils",
".",
"logDebug",
"(",
"[",
"'Available resources for chosen timeslot:'",
",",
"eventData",
".",
"resources",
"]",
")",
";",
"}",
"form",
".",
"find",
"(",
"'.bookingjs-form-input'",
")",
".",
"on",
"(",
"'input'",
",",
"function",
"(",
")",
"{",
"var",
"field",
"=",
"$",
"(",
"this",
")",
".",
"closest",
"(",
"'.bookingjs-form-field'",
")",
";",
"if",
"(",
"this",
".",
"value",
")",
"field",
".",
"addClass",
"(",
"'bookingjs-form-field--dirty'",
")",
";",
"else",
"field",
".",
"removeClass",
"(",
"'bookingjs-form-field--dirty'",
")",
";",
"}",
")",
";",
"form",
".",
"submit",
"(",
"function",
"(",
"e",
")",
"{",
"submitBookingForm",
"(",
"this",
",",
"e",
",",
"eventData",
")",
";",
"}",
")",
";",
"$",
"(",
"rootTarget",
")",
".",
"on",
"(",
"'customer-timezone-changed'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"bookingPageTarget",
")",
"return",
"$",
"(",
"'.bookingjs-bookpage-date'",
")",
".",
"text",
"(",
"formatTimestamp",
"(",
"eventData",
".",
"start",
",",
"dateFormat",
")",
")",
";",
"$",
"(",
"'.bookingjs-bookpage-time'",
")",
".",
"text",
"(",
"formatTimestamp",
"(",
"eventData",
".",
"start",
",",
"timeFormat",
")",
"+",
"' - '",
"+",
"formatTimestamp",
"(",
"eventData",
".",
"end",
",",
"timeFormat",
")",
")",
";",
"}",
")",
";",
"$",
"(",
"document",
")",
".",
"on",
"(",
"'keyup'",
",",
"function",
"(",
"e",
")",
"{",
"// escape key maps to keycode `27`",
"if",
"(",
"e",
".",
"keyCode",
"===",
"27",
")",
"{",
"hideBookingPage",
"(",
")",
";",
"}",
"}",
")",
";",
"rootTarget",
".",
"append",
"(",
"bookingPageTarget",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"bookingPageTarget",
".",
"addClass",
"(",
"'show'",
")",
";",
"}",
",",
"100",
")",
";",
"}"
] |
Event handler when a timeslot is clicked in FullCalendar
|
[
"Event",
"handler",
"when",
"a",
"timeslot",
"is",
"clicked",
"in",
"FullCalendar"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L511-L577
|
|
12,346
|
timekit-io/booking-js
|
src/render.js
|
function(form, e, eventData) {
e.preventDefault();
var formElement = $(form);
if(formElement.hasClass('success')) {
getAvailability();
hideBookingPage();
return;
}
// Abort if form is submitting, have submitted or does not validate
if(formElement.hasClass('loading') || formElement.hasClass('error') || !e.target.checkValidity()) {
var submitButton = formElement.find('.bookingjs-form-button');
submitButton.addClass('button-shake');
setTimeout(function() {
submitButton.removeClass('button-shake');
}, 500);
return;
}
var formData = {};
$.each(formElement.serializeArray(), function(i, field) {
formData[field.name] = field.value;
});
formElement.addClass('loading');
utils.doCallback('submitBookingForm', formData);
// Call create event endpoint
timekitCreateBooking(formData, eventData).then(function(response){
formElement.find('.booked-email').html(formData.email);
formElement.removeClass('loading').addClass('success');
}).catch(function(response){
showBookingFailed(formElement)
});
}
|
javascript
|
function(form, e, eventData) {
e.preventDefault();
var formElement = $(form);
if(formElement.hasClass('success')) {
getAvailability();
hideBookingPage();
return;
}
// Abort if form is submitting, have submitted or does not validate
if(formElement.hasClass('loading') || formElement.hasClass('error') || !e.target.checkValidity()) {
var submitButton = formElement.find('.bookingjs-form-button');
submitButton.addClass('button-shake');
setTimeout(function() {
submitButton.removeClass('button-shake');
}, 500);
return;
}
var formData = {};
$.each(formElement.serializeArray(), function(i, field) {
formData[field.name] = field.value;
});
formElement.addClass('loading');
utils.doCallback('submitBookingForm', formData);
// Call create event endpoint
timekitCreateBooking(formData, eventData).then(function(response){
formElement.find('.booked-email').html(formData.email);
formElement.removeClass('loading').addClass('success');
}).catch(function(response){
showBookingFailed(formElement)
});
}
|
[
"function",
"(",
"form",
",",
"e",
",",
"eventData",
")",
"{",
"e",
".",
"preventDefault",
"(",
")",
";",
"var",
"formElement",
"=",
"$",
"(",
"form",
")",
";",
"if",
"(",
"formElement",
".",
"hasClass",
"(",
"'success'",
")",
")",
"{",
"getAvailability",
"(",
")",
";",
"hideBookingPage",
"(",
")",
";",
"return",
";",
"}",
"// Abort if form is submitting, have submitted or does not validate",
"if",
"(",
"formElement",
".",
"hasClass",
"(",
"'loading'",
")",
"||",
"formElement",
".",
"hasClass",
"(",
"'error'",
")",
"||",
"!",
"e",
".",
"target",
".",
"checkValidity",
"(",
")",
")",
"{",
"var",
"submitButton",
"=",
"formElement",
".",
"find",
"(",
"'.bookingjs-form-button'",
")",
";",
"submitButton",
".",
"addClass",
"(",
"'button-shake'",
")",
";",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"submitButton",
".",
"removeClass",
"(",
"'button-shake'",
")",
";",
"}",
",",
"500",
")",
";",
"return",
";",
"}",
"var",
"formData",
"=",
"{",
"}",
";",
"$",
".",
"each",
"(",
"formElement",
".",
"serializeArray",
"(",
")",
",",
"function",
"(",
"i",
",",
"field",
")",
"{",
"formData",
"[",
"field",
".",
"name",
"]",
"=",
"field",
".",
"value",
";",
"}",
")",
";",
"formElement",
".",
"addClass",
"(",
"'loading'",
")",
";",
"utils",
".",
"doCallback",
"(",
"'submitBookingForm'",
",",
"formData",
")",
";",
"// Call create event endpoint",
"timekitCreateBooking",
"(",
"formData",
",",
"eventData",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"formElement",
".",
"find",
"(",
"'.booked-email'",
")",
".",
"html",
"(",
"formData",
".",
"email",
")",
";",
"formElement",
".",
"removeClass",
"(",
"'loading'",
")",
".",
"addClass",
"(",
"'success'",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"response",
")",
"{",
"showBookingFailed",
"(",
"formElement",
")",
"}",
")",
";",
"}"
] |
Event handler on form submit
|
[
"Event",
"handler",
"on",
"form",
"submit"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L600-L643
|
|
12,347
|
timekit-io/booking-js
|
src/render.js
|
function(formData, eventData) {
var nativeFields = ['name', 'email', 'location', 'comment', 'phone', 'voip']
var args = {
start: eventData.start.format(),
end: eventData.end.format(),
description: '',
customer: {
name: formData.name,
email: formData.email,
timezone: customerTimezone
}
};
if (getConfig().project_id) {
args.project_id = getConfig().project_id
} else {
$.extend(true, args, {
what: 'Meeting with ' + formData.name,
where: 'TBD'
});
}
args.description += (getConfig().customer_fields.name.title || 'Name') + ': ' + formData.name + '\n';
args.description += (getConfig().customer_fields.name.email || 'Email') + ': ' + formData.email + '\n';
if (getConfig().customer_fields.location) {
args.customer.where = formData.location;
args.where = formData.location;
}
if (getConfig().customer_fields.comment) {
args.customer.comment = formData.comment;
args.description += (getConfig().customer_fields.comment.title || 'Comment') + ': ' + formData.comment + '\n';
}
if (getConfig().customer_fields.phone) {
args.customer.phone = formData.phone;
args.description += (getConfig().customer_fields.phone.title || 'Phone') + ': ' + formData.phone + '\n';
}
if (getConfig().customer_fields.voip) {
args.customer.voip = formData.voip;
args.description += (getConfig().customer_fields.voip.title || 'Voip') + ': ' + formData.voip + '\n';
}
// Save custom fields in meta object
$.each(getConfig().customer_fields, function(key, field) {
if ($.inArray(key, nativeFields) >= 0) return
if (field.format === 'checkbox') formData[key] = !!formData[key]
args.customer[key] = formData[key]
args.description += (getConfig().customer_fields[key].title || key) + ': ' + formData[key] + '\n';
})
if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
args.related = { owner_booking_id: eventData.booking.id }
args.resource_id = eventData.booking.resource.id
} else if (typeof eventData.resources === 'undefined' || eventData.resources.length === 0) {
throw triggerError(['No resources to pick from when creating booking']);
} else {
args.resource_id = eventData.resources[0].id
}
$.extend(true, args, getConfig().booking);
utils.doCallback('createBookingStarted', args);
var request = sdk
.include(getConfig().create_booking_response_include)
.createBooking(args);
request
.then(function(response){
utils.doCallback('createBookingSuccessful', response);
}).catch(function(response){
utils.doCallback('createBookingFailed', response);
triggerError(['An error with Timekit Create Booking occured', response]);
});
return request;
}
|
javascript
|
function(formData, eventData) {
var nativeFields = ['name', 'email', 'location', 'comment', 'phone', 'voip']
var args = {
start: eventData.start.format(),
end: eventData.end.format(),
description: '',
customer: {
name: formData.name,
email: formData.email,
timezone: customerTimezone
}
};
if (getConfig().project_id) {
args.project_id = getConfig().project_id
} else {
$.extend(true, args, {
what: 'Meeting with ' + formData.name,
where: 'TBD'
});
}
args.description += (getConfig().customer_fields.name.title || 'Name') + ': ' + formData.name + '\n';
args.description += (getConfig().customer_fields.name.email || 'Email') + ': ' + formData.email + '\n';
if (getConfig().customer_fields.location) {
args.customer.where = formData.location;
args.where = formData.location;
}
if (getConfig().customer_fields.comment) {
args.customer.comment = formData.comment;
args.description += (getConfig().customer_fields.comment.title || 'Comment') + ': ' + formData.comment + '\n';
}
if (getConfig().customer_fields.phone) {
args.customer.phone = formData.phone;
args.description += (getConfig().customer_fields.phone.title || 'Phone') + ': ' + formData.phone + '\n';
}
if (getConfig().customer_fields.voip) {
args.customer.voip = formData.voip;
args.description += (getConfig().customer_fields.voip.title || 'Voip') + ': ' + formData.voip + '\n';
}
// Save custom fields in meta object
$.each(getConfig().customer_fields, function(key, field) {
if ($.inArray(key, nativeFields) >= 0) return
if (field.format === 'checkbox') formData[key] = !!formData[key]
args.customer[key] = formData[key]
args.description += (getConfig().customer_fields[key].title || key) + ': ' + formData[key] + '\n';
})
if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
args.related = { owner_booking_id: eventData.booking.id }
args.resource_id = eventData.booking.resource.id
} else if (typeof eventData.resources === 'undefined' || eventData.resources.length === 0) {
throw triggerError(['No resources to pick from when creating booking']);
} else {
args.resource_id = eventData.resources[0].id
}
$.extend(true, args, getConfig().booking);
utils.doCallback('createBookingStarted', args);
var request = sdk
.include(getConfig().create_booking_response_include)
.createBooking(args);
request
.then(function(response){
utils.doCallback('createBookingSuccessful', response);
}).catch(function(response){
utils.doCallback('createBookingFailed', response);
triggerError(['An error with Timekit Create Booking occured', response]);
});
return request;
}
|
[
"function",
"(",
"formData",
",",
"eventData",
")",
"{",
"var",
"nativeFields",
"=",
"[",
"'name'",
",",
"'email'",
",",
"'location'",
",",
"'comment'",
",",
"'phone'",
",",
"'voip'",
"]",
"var",
"args",
"=",
"{",
"start",
":",
"eventData",
".",
"start",
".",
"format",
"(",
")",
",",
"end",
":",
"eventData",
".",
"end",
".",
"format",
"(",
")",
",",
"description",
":",
"''",
",",
"customer",
":",
"{",
"name",
":",
"formData",
".",
"name",
",",
"email",
":",
"formData",
".",
"email",
",",
"timezone",
":",
"customerTimezone",
"}",
"}",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"project_id",
")",
"{",
"args",
".",
"project_id",
"=",
"getConfig",
"(",
")",
".",
"project_id",
"}",
"else",
"{",
"$",
".",
"extend",
"(",
"true",
",",
"args",
",",
"{",
"what",
":",
"'Meeting with '",
"+",
"formData",
".",
"name",
",",
"where",
":",
"'TBD'",
"}",
")",
";",
"}",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"name",
".",
"title",
"||",
"'Name'",
")",
"+",
"': '",
"+",
"formData",
".",
"name",
"+",
"'\\n'",
";",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"name",
".",
"email",
"||",
"'Email'",
")",
"+",
"': '",
"+",
"formData",
".",
"email",
"+",
"'\\n'",
";",
"if",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"location",
")",
"{",
"args",
".",
"customer",
".",
"where",
"=",
"formData",
".",
"location",
";",
"args",
".",
"where",
"=",
"formData",
".",
"location",
";",
"}",
"if",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"comment",
")",
"{",
"args",
".",
"customer",
".",
"comment",
"=",
"formData",
".",
"comment",
";",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"comment",
".",
"title",
"||",
"'Comment'",
")",
"+",
"': '",
"+",
"formData",
".",
"comment",
"+",
"'\\n'",
";",
"}",
"if",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"phone",
")",
"{",
"args",
".",
"customer",
".",
"phone",
"=",
"formData",
".",
"phone",
";",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"phone",
".",
"title",
"||",
"'Phone'",
")",
"+",
"': '",
"+",
"formData",
".",
"phone",
"+",
"'\\n'",
";",
"}",
"if",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"voip",
")",
"{",
"args",
".",
"customer",
".",
"voip",
"=",
"formData",
".",
"voip",
";",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
".",
"voip",
".",
"title",
"||",
"'Voip'",
")",
"+",
"': '",
"+",
"formData",
".",
"voip",
"+",
"'\\n'",
";",
"}",
"// Save custom fields in meta object",
"$",
".",
"each",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
",",
"function",
"(",
"key",
",",
"field",
")",
"{",
"if",
"(",
"$",
".",
"inArray",
"(",
"key",
",",
"nativeFields",
")",
">=",
"0",
")",
"return",
"if",
"(",
"field",
".",
"format",
"===",
"'checkbox'",
")",
"formData",
"[",
"key",
"]",
"=",
"!",
"!",
"formData",
"[",
"key",
"]",
"args",
".",
"customer",
"[",
"key",
"]",
"=",
"formData",
"[",
"key",
"]",
"args",
".",
"description",
"+=",
"(",
"getConfig",
"(",
")",
".",
"customer_fields",
"[",
"key",
"]",
".",
"title",
"||",
"key",
")",
"+",
"': '",
"+",
"formData",
"[",
"key",
"]",
"+",
"'\\n'",
";",
"}",
")",
"if",
"(",
"getConfig",
"(",
")",
".",
"booking",
".",
"graph",
"===",
"'group_customer'",
"||",
"getConfig",
"(",
")",
".",
"booking",
".",
"graph",
"===",
"'group_customer_payment'",
")",
"{",
"args",
".",
"related",
"=",
"{",
"owner_booking_id",
":",
"eventData",
".",
"booking",
".",
"id",
"}",
"args",
".",
"resource_id",
"=",
"eventData",
".",
"booking",
".",
"resource",
".",
"id",
"}",
"else",
"if",
"(",
"typeof",
"eventData",
".",
"resources",
"===",
"'undefined'",
"||",
"eventData",
".",
"resources",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"triggerError",
"(",
"[",
"'No resources to pick from when creating booking'",
"]",
")",
";",
"}",
"else",
"{",
"args",
".",
"resource_id",
"=",
"eventData",
".",
"resources",
"[",
"0",
"]",
".",
"id",
"}",
"$",
".",
"extend",
"(",
"true",
",",
"args",
",",
"getConfig",
"(",
")",
".",
"booking",
")",
";",
"utils",
".",
"doCallback",
"(",
"'createBookingStarted'",
",",
"args",
")",
";",
"var",
"request",
"=",
"sdk",
".",
"include",
"(",
"getConfig",
"(",
")",
".",
"create_booking_response_include",
")",
".",
"createBooking",
"(",
"args",
")",
";",
"request",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"utils",
".",
"doCallback",
"(",
"'createBookingSuccessful'",
",",
"response",
")",
";",
"}",
")",
".",
"catch",
"(",
"function",
"(",
"response",
")",
"{",
"utils",
".",
"doCallback",
"(",
"'createBookingFailed'",
",",
"response",
")",
";",
"triggerError",
"(",
"[",
"'An error with Timekit Create Booking occured'",
",",
"response",
"]",
")",
";",
"}",
")",
";",
"return",
"request",
";",
"}"
] |
Create new booking
|
[
"Create",
"new",
"booking"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/render.js#L661-L740
|
|
12,348
|
timekit-io/booking-js
|
src/init.js
|
function (response, suppliedConfig) {
var remoteConfig = response.data
// streamline naming of object keys
if (remoteConfig.id) {
remoteConfig.project_id = remoteConfig.id
delete remoteConfig.id
}
if (remoteConfig.slug) {
remoteConfig.project_slug = remoteConfig.slug
delete remoteConfig.slug
}
// merge with supplied config for overwriting settings
var mergedConfig = $.extend(true, {}, remoteConfig, suppliedConfig);
utils.logDebug(['Remote config:', remoteConfig]);
startWithConfig(mergedConfig)
}
|
javascript
|
function (response, suppliedConfig) {
var remoteConfig = response.data
// streamline naming of object keys
if (remoteConfig.id) {
remoteConfig.project_id = remoteConfig.id
delete remoteConfig.id
}
if (remoteConfig.slug) {
remoteConfig.project_slug = remoteConfig.slug
delete remoteConfig.slug
}
// merge with supplied config for overwriting settings
var mergedConfig = $.extend(true, {}, remoteConfig, suppliedConfig);
utils.logDebug(['Remote config:', remoteConfig]);
startWithConfig(mergedConfig)
}
|
[
"function",
"(",
"response",
",",
"suppliedConfig",
")",
"{",
"var",
"remoteConfig",
"=",
"response",
".",
"data",
"// streamline naming of object keys",
"if",
"(",
"remoteConfig",
".",
"id",
")",
"{",
"remoteConfig",
".",
"project_id",
"=",
"remoteConfig",
".",
"id",
"delete",
"remoteConfig",
".",
"id",
"}",
"if",
"(",
"remoteConfig",
".",
"slug",
")",
"{",
"remoteConfig",
".",
"project_slug",
"=",
"remoteConfig",
".",
"slug",
"delete",
"remoteConfig",
".",
"slug",
"}",
"// merge with supplied config for overwriting settings",
"var",
"mergedConfig",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"remoteConfig",
",",
"suppliedConfig",
")",
";",
"utils",
".",
"logDebug",
"(",
"[",
"'Remote config:'",
",",
"remoteConfig",
"]",
")",
";",
"startWithConfig",
"(",
"mergedConfig",
")",
"}"
] |
Process retrieved project config and start
|
[
"Process",
"retrieved",
"project",
"config",
"and",
"start"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/init.js#L105-L120
|
|
12,349
|
timekit-io/booking-js
|
src/init.js
|
function(suppliedConfig) {
// Handle config and defaults
try {
config.parseAndUpdate(suppliedConfig);
} catch (e) {
render.triggerError(e);
return this
}
utils.logDebug(['Final config:', getConfig()]);
try {
return startRender();
} catch (e) {
render.triggerError(e);
return this
}
}
|
javascript
|
function(suppliedConfig) {
// Handle config and defaults
try {
config.parseAndUpdate(suppliedConfig);
} catch (e) {
render.triggerError(e);
return this
}
utils.logDebug(['Final config:', getConfig()]);
try {
return startRender();
} catch (e) {
render.triggerError(e);
return this
}
}
|
[
"function",
"(",
"suppliedConfig",
")",
"{",
"// Handle config and defaults",
"try",
"{",
"config",
".",
"parseAndUpdate",
"(",
"suppliedConfig",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"render",
".",
"triggerError",
"(",
"e",
")",
";",
"return",
"this",
"}",
"utils",
".",
"logDebug",
"(",
"[",
"'Final config:'",
",",
"getConfig",
"(",
")",
"]",
")",
";",
"try",
"{",
"return",
"startRender",
"(",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"render",
".",
"triggerError",
"(",
"e",
")",
";",
"return",
"this",
"}",
"}"
] |
Parse the config and start rendering
|
[
"Parse",
"the",
"config",
"and",
"start",
"rendering"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/init.js#L123-L140
|
|
12,350
|
timekit-io/booking-js
|
src/config.js
|
function(suppliedConfig) {
if (typeof suppliedConfig.sdk === 'undefined') suppliedConfig.sdk = {}
if (suppliedConfig.app_key) suppliedConfig.sdk.appKey = suppliedConfig.app_key
return $.extend(true, {}, defaultConfig.primary.sdk, suppliedConfig.sdk);
}
|
javascript
|
function(suppliedConfig) {
if (typeof suppliedConfig.sdk === 'undefined') suppliedConfig.sdk = {}
if (suppliedConfig.app_key) suppliedConfig.sdk.appKey = suppliedConfig.app_key
return $.extend(true, {}, defaultConfig.primary.sdk, suppliedConfig.sdk);
}
|
[
"function",
"(",
"suppliedConfig",
")",
"{",
"if",
"(",
"typeof",
"suppliedConfig",
".",
"sdk",
"===",
"'undefined'",
")",
"suppliedConfig",
".",
"sdk",
"=",
"{",
"}",
"if",
"(",
"suppliedConfig",
".",
"app_key",
")",
"suppliedConfig",
".",
"sdk",
".",
"appKey",
"=",
"suppliedConfig",
".",
"app_key",
"return",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"defaultConfig",
".",
"primary",
".",
"sdk",
",",
"suppliedConfig",
".",
"sdk",
")",
";",
"}"
] |
Setup defaults for the SDK
|
[
"Setup",
"defaults",
"for",
"the",
"SDK"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/config.js#L13-L17
|
|
12,351
|
timekit-io/booking-js
|
src/config.js
|
function(suppliedConfig) {
suppliedConfig.sdk = prepareSdkConfig(suppliedConfig)
return $.extend(true, {}, defaultConfig.primary, suppliedConfig);
}
|
javascript
|
function(suppliedConfig) {
suppliedConfig.sdk = prepareSdkConfig(suppliedConfig)
return $.extend(true, {}, defaultConfig.primary, suppliedConfig);
}
|
[
"function",
"(",
"suppliedConfig",
")",
"{",
"suppliedConfig",
".",
"sdk",
"=",
"prepareSdkConfig",
"(",
"suppliedConfig",
")",
"return",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"defaultConfig",
".",
"primary",
",",
"suppliedConfig",
")",
";",
"}"
] |
Merge defaults into passed config
|
[
"Merge",
"defaults",
"into",
"passed",
"config"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/config.js#L20-L23
|
|
12,352
|
timekit-io/booking-js
|
src/config.js
|
function(config) {
$.each(config.customer_fields, function (key, field) {
if (!defaultConfig.customerFieldsNativeFormats[key]) return
config.customer_fields[key] = $.extend({}, defaultConfig.customerFieldsNativeFormats[key], field);
})
return config
}
|
javascript
|
function(config) {
$.each(config.customer_fields, function (key, field) {
if (!defaultConfig.customerFieldsNativeFormats[key]) return
config.customer_fields[key] = $.extend({}, defaultConfig.customerFieldsNativeFormats[key], field);
})
return config
}
|
[
"function",
"(",
"config",
")",
"{",
"$",
".",
"each",
"(",
"config",
".",
"customer_fields",
",",
"function",
"(",
"key",
",",
"field",
")",
"{",
"if",
"(",
"!",
"defaultConfig",
".",
"customerFieldsNativeFormats",
"[",
"key",
"]",
")",
"return",
"config",
".",
"customer_fields",
"[",
"key",
"]",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"defaultConfig",
".",
"customerFieldsNativeFormats",
"[",
"key",
"]",
",",
"field",
")",
";",
"}",
")",
"return",
"config",
"}"
] |
Set default formats for native fields
|
[
"Set",
"default",
"formats",
"for",
"native",
"fields"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/config.js#L31-L37
|
|
12,353
|
timekit-io/booking-js
|
src/config.js
|
function (localConfig, propertyName, propertyObject) {
var presetCheck = defaultConfig.presets[propertyName][propertyObject];
if (presetCheck) return $.extend(true, {}, presetCheck, localConfig);
return localConfig
}
|
javascript
|
function (localConfig, propertyName, propertyObject) {
var presetCheck = defaultConfig.presets[propertyName][propertyObject];
if (presetCheck) return $.extend(true, {}, presetCheck, localConfig);
return localConfig
}
|
[
"function",
"(",
"localConfig",
",",
"propertyName",
",",
"propertyObject",
")",
"{",
"var",
"presetCheck",
"=",
"defaultConfig",
".",
"presets",
"[",
"propertyName",
"]",
"[",
"propertyObject",
"]",
";",
"if",
"(",
"presetCheck",
")",
"return",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"}",
",",
"presetCheck",
",",
"localConfig",
")",
";",
"return",
"localConfig",
"}"
] |
Apply the config presets given a configuration
|
[
"Apply",
"the",
"config",
"presets",
"given",
"a",
"configuration"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/config.js#L40-L44
|
|
12,354
|
timekit-io/booking-js
|
src/config.js
|
function (suppliedConfig, urlParams) {
$.each(suppliedConfig.customer_fields, function (key) {
if (!urlParams['customer.' + key]) return
suppliedConfig.customer_fields[key].prefilled = urlParams['customer.' + key];
});
return suppliedConfig
}
|
javascript
|
function (suppliedConfig, urlParams) {
$.each(suppliedConfig.customer_fields, function (key) {
if (!urlParams['customer.' + key]) return
suppliedConfig.customer_fields[key].prefilled = urlParams['customer.' + key];
});
return suppliedConfig
}
|
[
"function",
"(",
"suppliedConfig",
",",
"urlParams",
")",
"{",
"$",
".",
"each",
"(",
"suppliedConfig",
".",
"customer_fields",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"!",
"urlParams",
"[",
"'customer.'",
"+",
"key",
"]",
")",
"return",
"suppliedConfig",
".",
"customer_fields",
"[",
"key",
"]",
".",
"prefilled",
"=",
"urlParams",
"[",
"'customer.'",
"+",
"key",
"]",
";",
"}",
")",
";",
"return",
"suppliedConfig",
"}"
] |
Prefill customer fields based on URL query string
|
[
"Prefill",
"customer",
"fields",
"based",
"on",
"URL",
"query",
"string"
] |
c6dc20bccc9407d3f090c6f454bb9796388df218
|
https://github.com/timekit-io/booking-js/blob/c6dc20bccc9407d3f090c6f454bb9796388df218/src/config.js#L47-L53
|
|
12,355
|
yoannmoinet/nipplejs
|
src/collection.js
|
function (evt, data) {
// Identify the event type with the nipple's id.
type = evt.type + ' ' + data.id + ':' + evt.type;
self.trigger(type, data);
}
|
javascript
|
function (evt, data) {
// Identify the event type with the nipple's id.
type = evt.type + ' ' + data.id + ':' + evt.type;
self.trigger(type, data);
}
|
[
"function",
"(",
"evt",
",",
"data",
")",
"{",
"// Identify the event type with the nipple's id.",
"type",
"=",
"evt",
".",
"type",
"+",
"' '",
"+",
"data",
".",
"id",
"+",
"':'",
"+",
"evt",
".",
"type",
";",
"self",
".",
"trigger",
"(",
"type",
",",
"data",
")",
";",
"}"
] |
Bubble up identified events.
|
[
"Bubble",
"up",
"identified",
"events",
"."
] |
dfa253f80230c31478aca083bfe2dac2bc45ea08
|
https://github.com/yoannmoinet/nipplejs/blob/dfa253f80230c31478aca083bfe2dac2bc45ea08/src/collection.js#L196-L200
|
|
12,356
|
werk85/node-html-to-text
|
lib/helper.js
|
splitLongWord
|
function splitLongWord(word, options) {
var wrapCharacters = options.longWordSplit.wrapCharacters || [];
var forceWrapOnLimit = options.longWordSplit.forceWrapOnLimit || false;
var max = options.wordwrap;
var fuseWord = [];
var idx = 0;
while (word.length > max) {
var firstLine = word.substr(0, max);
var remainingChars = word.substr(max);
var splitIndex = firstLine.lastIndexOf(wrapCharacters[idx]);
if (splitIndex > -1) {
// We've found a character to split on, store before the split then check if we
// need to split again
word = firstLine.substr(splitIndex + 1) + remainingChars;
fuseWord.push(firstLine.substr(0, splitIndex + 1));
} else {
idx++;
if (idx >= wrapCharacters.length) {
// Cannot split on character, so either split at 'max' or preserve length
if (forceWrapOnLimit) {
fuseWord.push(firstLine);
word = remainingChars;
if (word.length > max) {
continue;
}
} else {
word = firstLine + remainingChars;
if (!options.preserveNewlines) {
word += '\n';
}
}
break;
} else {
word = firstLine + remainingChars;
}
}
}
fuseWord.push(word);
return fuseWord.join('\n');
}
|
javascript
|
function splitLongWord(word, options) {
var wrapCharacters = options.longWordSplit.wrapCharacters || [];
var forceWrapOnLimit = options.longWordSplit.forceWrapOnLimit || false;
var max = options.wordwrap;
var fuseWord = [];
var idx = 0;
while (word.length > max) {
var firstLine = word.substr(0, max);
var remainingChars = word.substr(max);
var splitIndex = firstLine.lastIndexOf(wrapCharacters[idx]);
if (splitIndex > -1) {
// We've found a character to split on, store before the split then check if we
// need to split again
word = firstLine.substr(splitIndex + 1) + remainingChars;
fuseWord.push(firstLine.substr(0, splitIndex + 1));
} else {
idx++;
if (idx >= wrapCharacters.length) {
// Cannot split on character, so either split at 'max' or preserve length
if (forceWrapOnLimit) {
fuseWord.push(firstLine);
word = remainingChars;
if (word.length > max) {
continue;
}
} else {
word = firstLine + remainingChars;
if (!options.preserveNewlines) {
word += '\n';
}
}
break;
} else {
word = firstLine + remainingChars;
}
}
}
fuseWord.push(word);
return fuseWord.join('\n');
}
|
[
"function",
"splitLongWord",
"(",
"word",
",",
"options",
")",
"{",
"var",
"wrapCharacters",
"=",
"options",
".",
"longWordSplit",
".",
"wrapCharacters",
"||",
"[",
"]",
";",
"var",
"forceWrapOnLimit",
"=",
"options",
".",
"longWordSplit",
".",
"forceWrapOnLimit",
"||",
"false",
";",
"var",
"max",
"=",
"options",
".",
"wordwrap",
";",
"var",
"fuseWord",
"=",
"[",
"]",
";",
"var",
"idx",
"=",
"0",
";",
"while",
"(",
"word",
".",
"length",
">",
"max",
")",
"{",
"var",
"firstLine",
"=",
"word",
".",
"substr",
"(",
"0",
",",
"max",
")",
";",
"var",
"remainingChars",
"=",
"word",
".",
"substr",
"(",
"max",
")",
";",
"var",
"splitIndex",
"=",
"firstLine",
".",
"lastIndexOf",
"(",
"wrapCharacters",
"[",
"idx",
"]",
")",
";",
"if",
"(",
"splitIndex",
">",
"-",
"1",
")",
"{",
"// We've found a character to split on, store before the split then check if we",
"// need to split again",
"word",
"=",
"firstLine",
".",
"substr",
"(",
"splitIndex",
"+",
"1",
")",
"+",
"remainingChars",
";",
"fuseWord",
".",
"push",
"(",
"firstLine",
".",
"substr",
"(",
"0",
",",
"splitIndex",
"+",
"1",
")",
")",
";",
"}",
"else",
"{",
"idx",
"++",
";",
"if",
"(",
"idx",
">=",
"wrapCharacters",
".",
"length",
")",
"{",
"// Cannot split on character, so either split at 'max' or preserve length",
"if",
"(",
"forceWrapOnLimit",
")",
"{",
"fuseWord",
".",
"push",
"(",
"firstLine",
")",
";",
"word",
"=",
"remainingChars",
";",
"if",
"(",
"word",
".",
"length",
">",
"max",
")",
"{",
"continue",
";",
"}",
"}",
"else",
"{",
"word",
"=",
"firstLine",
"+",
"remainingChars",
";",
"if",
"(",
"!",
"options",
".",
"preserveNewlines",
")",
"{",
"word",
"+=",
"'\\n'",
";",
"}",
"}",
"break",
";",
"}",
"else",
"{",
"word",
"=",
"firstLine",
"+",
"remainingChars",
";",
"}",
"}",
"}",
"fuseWord",
".",
"push",
"(",
"word",
")",
";",
"return",
"fuseWord",
".",
"join",
"(",
"'\\n'",
")",
";",
"}"
] |
Split a long word up to fit within the word wrap limit. Use either a character to split looking back from the word wrap limit, or truncate to the word wrap limit.
|
[
"Split",
"a",
"long",
"word",
"up",
"to",
"fit",
"within",
"the",
"word",
"wrap",
"limit",
".",
"Use",
"either",
"a",
"character",
"to",
"split",
"looking",
"back",
"from",
"the",
"word",
"wrap",
"limit",
"or",
"truncate",
"to",
"the",
"word",
"wrap",
"limit",
"."
] |
b5f26807a8f8987a8a2f4a9f349ec9d0dba4a2e3
|
https://github.com/werk85/node-html-to-text/blob/b5f26807a8f8987a8a2f4a9f349ec9d0dba4a2e3/lib/helper.js#L7-L50
|
12,357
|
remarkjs/remark-lint
|
script/util/rule.js
|
ruleSync
|
function ruleSync(filePath) {
var ruleId = path.basename(filePath)
var result = {}
var tests = {}
var description
var code
var tags
var name
ruleId = ruleId.slice('remark-lint-'.length)
code = fs.readFileSync(path.join(filePath, 'index.js'), 'utf-8')
tags = dox.parseComments(code)[0].tags
description = find(tags, 'fileoverview')
name = find(tags, 'module')
/* istanbul ignore if */
if (name !== ruleId) {
throw new Error(ruleId + ' has an invalid `@module`: ' + name)
}
/* istanbul ignore if */
if (!description) {
throw new Error(ruleId + ' is missing a `@fileoverview`')
}
description = strip(description)
result.ruleId = ruleId
result.description = trim(description)
result.tests = tests
result.filePath = filePath
find
.all(tags, 'example')
.map(strip)
.forEach(check)
return result
function check(example) {
var lines = example.split('\n')
var value = strip(lines.slice(1).join('\n'))
var info
var setting
var context
var name
try {
info = JSON.parse(lines[0])
} catch (error) {
/* istanbul ignore next */
throw new Error(
'Could not parse example in ' + ruleId + ':\n' + error.stack
)
}
setting = JSON.stringify(info.setting || true)
context = tests[setting]
name = info.name
if (!context) {
context = []
tests[setting] = context
}
if (!info.label) {
context[name] = {
config: info.config || {},
setting: setting,
input: value,
output: []
}
return
}
/* istanbul ignore if */
if (info.label !== 'input' && info.label !== 'output') {
throw new Error(
'Expected `input` or `ouput` for `label` in ' +
ruleId +
', not `' +
info.label +
'`'
)
}
if (!context[name]) {
context[name] = {config: info.config || {}}
}
context[name].setting = setting
if (info.label === 'output') {
value = value.split('\n')
}
context[name][info.label] = value
}
}
|
javascript
|
function ruleSync(filePath) {
var ruleId = path.basename(filePath)
var result = {}
var tests = {}
var description
var code
var tags
var name
ruleId = ruleId.slice('remark-lint-'.length)
code = fs.readFileSync(path.join(filePath, 'index.js'), 'utf-8')
tags = dox.parseComments(code)[0].tags
description = find(tags, 'fileoverview')
name = find(tags, 'module')
/* istanbul ignore if */
if (name !== ruleId) {
throw new Error(ruleId + ' has an invalid `@module`: ' + name)
}
/* istanbul ignore if */
if (!description) {
throw new Error(ruleId + ' is missing a `@fileoverview`')
}
description = strip(description)
result.ruleId = ruleId
result.description = trim(description)
result.tests = tests
result.filePath = filePath
find
.all(tags, 'example')
.map(strip)
.forEach(check)
return result
function check(example) {
var lines = example.split('\n')
var value = strip(lines.slice(1).join('\n'))
var info
var setting
var context
var name
try {
info = JSON.parse(lines[0])
} catch (error) {
/* istanbul ignore next */
throw new Error(
'Could not parse example in ' + ruleId + ':\n' + error.stack
)
}
setting = JSON.stringify(info.setting || true)
context = tests[setting]
name = info.name
if (!context) {
context = []
tests[setting] = context
}
if (!info.label) {
context[name] = {
config: info.config || {},
setting: setting,
input: value,
output: []
}
return
}
/* istanbul ignore if */
if (info.label !== 'input' && info.label !== 'output') {
throw new Error(
'Expected `input` or `ouput` for `label` in ' +
ruleId +
', not `' +
info.label +
'`'
)
}
if (!context[name]) {
context[name] = {config: info.config || {}}
}
context[name].setting = setting
if (info.label === 'output') {
value = value.split('\n')
}
context[name][info.label] = value
}
}
|
[
"function",
"ruleSync",
"(",
"filePath",
")",
"{",
"var",
"ruleId",
"=",
"path",
".",
"basename",
"(",
"filePath",
")",
"var",
"result",
"=",
"{",
"}",
"var",
"tests",
"=",
"{",
"}",
"var",
"description",
"var",
"code",
"var",
"tags",
"var",
"name",
"ruleId",
"=",
"ruleId",
".",
"slice",
"(",
"'remark-lint-'",
".",
"length",
")",
"code",
"=",
"fs",
".",
"readFileSync",
"(",
"path",
".",
"join",
"(",
"filePath",
",",
"'index.js'",
")",
",",
"'utf-8'",
")",
"tags",
"=",
"dox",
".",
"parseComments",
"(",
"code",
")",
"[",
"0",
"]",
".",
"tags",
"description",
"=",
"find",
"(",
"tags",
",",
"'fileoverview'",
")",
"name",
"=",
"find",
"(",
"tags",
",",
"'module'",
")",
"/* istanbul ignore if */",
"if",
"(",
"name",
"!==",
"ruleId",
")",
"{",
"throw",
"new",
"Error",
"(",
"ruleId",
"+",
"' has an invalid `@module`: '",
"+",
"name",
")",
"}",
"/* istanbul ignore if */",
"if",
"(",
"!",
"description",
")",
"{",
"throw",
"new",
"Error",
"(",
"ruleId",
"+",
"' is missing a `@fileoverview`'",
")",
"}",
"description",
"=",
"strip",
"(",
"description",
")",
"result",
".",
"ruleId",
"=",
"ruleId",
"result",
".",
"description",
"=",
"trim",
"(",
"description",
")",
"result",
".",
"tests",
"=",
"tests",
"result",
".",
"filePath",
"=",
"filePath",
"find",
".",
"all",
"(",
"tags",
",",
"'example'",
")",
".",
"map",
"(",
"strip",
")",
".",
"forEach",
"(",
"check",
")",
"return",
"result",
"function",
"check",
"(",
"example",
")",
"{",
"var",
"lines",
"=",
"example",
".",
"split",
"(",
"'\\n'",
")",
"var",
"value",
"=",
"strip",
"(",
"lines",
".",
"slice",
"(",
"1",
")",
".",
"join",
"(",
"'\\n'",
")",
")",
"var",
"info",
"var",
"setting",
"var",
"context",
"var",
"name",
"try",
"{",
"info",
"=",
"JSON",
".",
"parse",
"(",
"lines",
"[",
"0",
"]",
")",
"}",
"catch",
"(",
"error",
")",
"{",
"/* istanbul ignore next */",
"throw",
"new",
"Error",
"(",
"'Could not parse example in '",
"+",
"ruleId",
"+",
"':\\n'",
"+",
"error",
".",
"stack",
")",
"}",
"setting",
"=",
"JSON",
".",
"stringify",
"(",
"info",
".",
"setting",
"||",
"true",
")",
"context",
"=",
"tests",
"[",
"setting",
"]",
"name",
"=",
"info",
".",
"name",
"if",
"(",
"!",
"context",
")",
"{",
"context",
"=",
"[",
"]",
"tests",
"[",
"setting",
"]",
"=",
"context",
"}",
"if",
"(",
"!",
"info",
".",
"label",
")",
"{",
"context",
"[",
"name",
"]",
"=",
"{",
"config",
":",
"info",
".",
"config",
"||",
"{",
"}",
",",
"setting",
":",
"setting",
",",
"input",
":",
"value",
",",
"output",
":",
"[",
"]",
"}",
"return",
"}",
"/* istanbul ignore if */",
"if",
"(",
"info",
".",
"label",
"!==",
"'input'",
"&&",
"info",
".",
"label",
"!==",
"'output'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected `input` or `ouput` for `label` in '",
"+",
"ruleId",
"+",
"', not `'",
"+",
"info",
".",
"label",
"+",
"'`'",
")",
"}",
"if",
"(",
"!",
"context",
"[",
"name",
"]",
")",
"{",
"context",
"[",
"name",
"]",
"=",
"{",
"config",
":",
"info",
".",
"config",
"||",
"{",
"}",
"}",
"}",
"context",
"[",
"name",
"]",
".",
"setting",
"=",
"setting",
"if",
"(",
"info",
".",
"label",
"===",
"'output'",
")",
"{",
"value",
"=",
"value",
".",
"split",
"(",
"'\\n'",
")",
"}",
"context",
"[",
"name",
"]",
"[",
"info",
".",
"label",
"]",
"=",
"value",
"}",
"}"
] |
Get information for a rule at `filePath`.
|
[
"Get",
"information",
"for",
"a",
"rule",
"at",
"filePath",
"."
] |
315156a02ed4cd2bb87448b4e0cafd86d7b93d5a
|
https://github.com/remarkjs/remark-lint/blob/315156a02ed4cd2bb87448b4e0cafd86d7b93d5a/script/util/rule.js#L13-L112
|
12,358
|
remarkjs/remark-lint
|
packages/remark-lint-no-reference-like-url/index.js
|
check
|
function check(node) {
var url = node.url
var reason
if (identifiers.indexOf(url.toLowerCase()) !== -1) {
reason =
'Did you mean to use `[' +
url +
']` instead of ' +
'`(' +
url +
')`, a reference?'
file.message(reason, node)
}
}
|
javascript
|
function check(node) {
var url = node.url
var reason
if (identifiers.indexOf(url.toLowerCase()) !== -1) {
reason =
'Did you mean to use `[' +
url +
']` instead of ' +
'`(' +
url +
')`, a reference?'
file.message(reason, node)
}
}
|
[
"function",
"check",
"(",
"node",
")",
"{",
"var",
"url",
"=",
"node",
".",
"url",
"var",
"reason",
"if",
"(",
"identifiers",
".",
"indexOf",
"(",
"url",
".",
"toLowerCase",
"(",
")",
")",
"!==",
"-",
"1",
")",
"{",
"reason",
"=",
"'Did you mean to use `['",
"+",
"url",
"+",
"']` instead of '",
"+",
"'`('",
"+",
"url",
"+",
"')`, a reference?'",
"file",
".",
"message",
"(",
"reason",
",",
"node",
")",
"}",
"}"
] |
Check `node`.
|
[
"Check",
"node",
"."
] |
315156a02ed4cd2bb87448b4e0cafd86d7b93d5a
|
https://github.com/remarkjs/remark-lint/blob/315156a02ed4cd2bb87448b4e0cafd86d7b93d5a/packages/remark-lint-no-reference-like-url/index.js#L48-L63
|
12,359
|
remarkjs/remark-lint
|
packages/remark-lint-no-consecutive-blank-lines/index.js
|
compare
|
function compare(start, end, max) {
var diff = end.line - start.line
var lines = Math.abs(diff) - max
var reason
if (lines > 0) {
reason =
'Remove ' +
lines +
' ' +
plural('line', lines) +
' ' +
(diff > 0 ? 'before' : 'after') +
' node'
file.message(reason, end)
}
}
|
javascript
|
function compare(start, end, max) {
var diff = end.line - start.line
var lines = Math.abs(diff) - max
var reason
if (lines > 0) {
reason =
'Remove ' +
lines +
' ' +
plural('line', lines) +
' ' +
(diff > 0 ? 'before' : 'after') +
' node'
file.message(reason, end)
}
}
|
[
"function",
"compare",
"(",
"start",
",",
"end",
",",
"max",
")",
"{",
"var",
"diff",
"=",
"end",
".",
"line",
"-",
"start",
".",
"line",
"var",
"lines",
"=",
"Math",
".",
"abs",
"(",
"diff",
")",
"-",
"max",
"var",
"reason",
"if",
"(",
"lines",
">",
"0",
")",
"{",
"reason",
"=",
"'Remove '",
"+",
"lines",
"+",
"' '",
"+",
"plural",
"(",
"'line'",
",",
"lines",
")",
"+",
"' '",
"+",
"(",
"diff",
">",
"0",
"?",
"'before'",
":",
"'after'",
")",
"+",
"' node'",
"file",
".",
"message",
"(",
"reason",
",",
"end",
")",
"}",
"}"
] |
Compare the difference between `start` and `end`, and warn when that difference exceeds `max`.
|
[
"Compare",
"the",
"difference",
"between",
"start",
"and",
"end",
"and",
"warn",
"when",
"that",
"difference",
"exceeds",
"max",
"."
] |
315156a02ed4cd2bb87448b4e0cafd86d7b93d5a
|
https://github.com/remarkjs/remark-lint/blob/315156a02ed4cd2bb87448b4e0cafd86d7b93d5a/packages/remark-lint-no-consecutive-blank-lines/index.js#L94-L111
|
12,360
|
remarkjs/remark-lint
|
packages/remark-lint-code-block-style/index.js
|
check
|
function check(node) {
var initial = start(node).offset
var final = end(node).offset
if (generated(node)) {
return null
}
return node.lang || /^\s*([~`])\1{2,}/.test(contents.slice(initial, final))
? 'fenced'
: 'indented'
}
|
javascript
|
function check(node) {
var initial = start(node).offset
var final = end(node).offset
if (generated(node)) {
return null
}
return node.lang || /^\s*([~`])\1{2,}/.test(contents.slice(initial, final))
? 'fenced'
: 'indented'
}
|
[
"function",
"check",
"(",
"node",
")",
"{",
"var",
"initial",
"=",
"start",
"(",
"node",
")",
".",
"offset",
"var",
"final",
"=",
"end",
"(",
"node",
")",
".",
"offset",
"if",
"(",
"generated",
"(",
"node",
")",
")",
"{",
"return",
"null",
"}",
"return",
"node",
".",
"lang",
"||",
"/",
"^\\s*([~`])\\1{2,}",
"/",
".",
"test",
"(",
"contents",
".",
"slice",
"(",
"initial",
",",
"final",
")",
")",
"?",
"'fenced'",
":",
"'indented'",
"}"
] |
Get the style of `node`.
|
[
"Get",
"the",
"style",
"of",
"node",
"."
] |
315156a02ed4cd2bb87448b4e0cafd86d7b93d5a
|
https://github.com/remarkjs/remark-lint/blob/315156a02ed4cd2bb87448b4e0cafd86d7b93d5a/packages/remark-lint-code-block-style/index.js#L136-L147
|
12,361
|
bttmly/nba
|
src/util/string.js
|
unDashHyphen
|
function unDashHyphen (str) {
return str
.trim()
.toLowerCase()
.replace(/[-_\s]+(.)?/g, function (match, c) {
return c ? c.toUpperCase() : "";
});
}
|
javascript
|
function unDashHyphen (str) {
return str
.trim()
.toLowerCase()
.replace(/[-_\s]+(.)?/g, function (match, c) {
return c ? c.toUpperCase() : "";
});
}
|
[
"function",
"unDashHyphen",
"(",
"str",
")",
"{",
"return",
"str",
".",
"trim",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"/",
"[-_\\s]+(.)?",
"/",
"g",
",",
"function",
"(",
"match",
",",
"c",
")",
"{",
"return",
"c",
"?",
"c",
".",
"toUpperCase",
"(",
")",
":",
"\"\"",
";",
"}",
")",
";",
"}"
] |
converts a dash or hypen separated string to camelCase
|
[
"converts",
"a",
"dash",
"or",
"hypen",
"separated",
"string",
"to",
"camelCase"
] |
653a7199857a2e7ef96b44cf0262033349fa2354
|
https://github.com/bttmly/nba/blob/653a7199857a2e7ef96b44cf0262033349fa2354/src/util/string.js#L12-L19
|
12,362
|
bttmly/nba
|
src/util/string.js
|
isAllUpperCase
|
function isAllUpperCase (str) {
return str
.split("")
.map(ch => ch.charCodeAt(0))
.every(n => n >= 65 && n <= 90);
}
|
javascript
|
function isAllUpperCase (str) {
return str
.split("")
.map(ch => ch.charCodeAt(0))
.every(n => n >= 65 && n <= 90);
}
|
[
"function",
"isAllUpperCase",
"(",
"str",
")",
"{",
"return",
"str",
".",
"split",
"(",
"\"\"",
")",
".",
"map",
"(",
"ch",
"=>",
"ch",
".",
"charCodeAt",
"(",
"0",
")",
")",
".",
"every",
"(",
"n",
"=>",
"n",
">=",
"65",
"&&",
"n",
"<=",
"90",
")",
";",
"}"
] |
checks if a string consists of only uppercase letters
|
[
"checks",
"if",
"a",
"string",
"consists",
"of",
"only",
"uppercase",
"letters"
] |
653a7199857a2e7ef96b44cf0262033349fa2354
|
https://github.com/bttmly/nba/blob/653a7199857a2e7ef96b44cf0262033349fa2354/src/util/string.js#L22-L27
|
12,363
|
bttmly/nba
|
src/transforms.js
|
players
|
function players (resp) {
return base(resp).map(function (player) {
var names = player.displayLastCommaFirst.split(", ").reverse();
return {
firstName: names[0].trim(),
lastName: (names[1] ? names[1] : "").trim(),
playerId: player.personId,
teamId: player.teamId,
};
});
}
|
javascript
|
function players (resp) {
return base(resp).map(function (player) {
var names = player.displayLastCommaFirst.split(", ").reverse();
return {
firstName: names[0].trim(),
lastName: (names[1] ? names[1] : "").trim(),
playerId: player.personId,
teamId: player.teamId,
};
});
}
|
[
"function",
"players",
"(",
"resp",
")",
"{",
"return",
"base",
"(",
"resp",
")",
".",
"map",
"(",
"function",
"(",
"player",
")",
"{",
"var",
"names",
"=",
"player",
".",
"displayLastCommaFirst",
".",
"split",
"(",
"\", \"",
")",
".",
"reverse",
"(",
")",
";",
"return",
"{",
"firstName",
":",
"names",
"[",
"0",
"]",
".",
"trim",
"(",
")",
",",
"lastName",
":",
"(",
"names",
"[",
"1",
"]",
"?",
"names",
"[",
"1",
"]",
":",
"\"\"",
")",
".",
"trim",
"(",
")",
",",
"playerId",
":",
"player",
".",
"personId",
",",
"teamId",
":",
"player",
".",
"teamId",
",",
"}",
";",
"}",
")",
";",
"}"
] |
todo make this work identical to update-players.js
|
[
"todo",
"make",
"this",
"work",
"identical",
"to",
"update",
"-",
"players",
".",
"js"
] |
653a7199857a2e7ef96b44cf0262033349fa2354
|
https://github.com/bttmly/nba/blob/653a7199857a2e7ef96b44cf0262033349fa2354/src/transforms.js#L24-L34
|
12,364
|
steveukx/git-js
|
src/git.js
|
Git
|
function Git (baseDir, ChildProcess, Buffer) {
this._baseDir = baseDir;
this._runCache = [];
this.ChildProcess = ChildProcess;
this.Buffer = Buffer;
}
|
javascript
|
function Git (baseDir, ChildProcess, Buffer) {
this._baseDir = baseDir;
this._runCache = [];
this.ChildProcess = ChildProcess;
this.Buffer = Buffer;
}
|
[
"function",
"Git",
"(",
"baseDir",
",",
"ChildProcess",
",",
"Buffer",
")",
"{",
"this",
".",
"_baseDir",
"=",
"baseDir",
";",
"this",
".",
"_runCache",
"=",
"[",
"]",
";",
"this",
".",
"ChildProcess",
"=",
"ChildProcess",
";",
"this",
".",
"Buffer",
"=",
"Buffer",
";",
"}"
] |
Git handling for node. All public functions can be chained and all `then` handlers are optional.
@param {string} baseDir base directory for all processes to run
@param {Object} ChildProcess The ChildProcess module
@param {Function} Buffer The Buffer implementation to use
@constructor
|
[
"Git",
"handling",
"for",
"node",
".",
"All",
"public",
"functions",
"can",
"be",
"chained",
"and",
"all",
"then",
"handlers",
"are",
"optional",
"."
] |
11fe5e8dfe271317ce902f9b1816322ac97271bd
|
https://github.com/steveukx/git-js/blob/11fe5e8dfe271317ce902f9b1816322ac97271bd/src/git.js#L20-L26
|
12,365
|
db-migrate/node-db-migrate
|
api.js
|
function (callback) {
var plugins = this.internals.plugins;
var self = this;
return Promise.resolve(Object.keys(APIHooks))
.each(function (hook) {
var plugin = plugins.hook(hook);
if (!plugin) return;
var APIHook = APIHooks[hook].bind(self);
return Promise.resolve(plugin)
.map(function (plugin) {
return plugin[hook]();
})
.each(function (args) {
return APIHook.apply(self, args);
});
})
.asCallback(callback);
}
|
javascript
|
function (callback) {
var plugins = this.internals.plugins;
var self = this;
return Promise.resolve(Object.keys(APIHooks))
.each(function (hook) {
var plugin = plugins.hook(hook);
if (!plugin) return;
var APIHook = APIHooks[hook].bind(self);
return Promise.resolve(plugin)
.map(function (plugin) {
return plugin[hook]();
})
.each(function (args) {
return APIHook.apply(self, args);
});
})
.asCallback(callback);
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"plugins",
"=",
"this",
".",
"internals",
".",
"plugins",
";",
"var",
"self",
"=",
"this",
";",
"return",
"Promise",
".",
"resolve",
"(",
"Object",
".",
"keys",
"(",
"APIHooks",
")",
")",
".",
"each",
"(",
"function",
"(",
"hook",
")",
"{",
"var",
"plugin",
"=",
"plugins",
".",
"hook",
"(",
"hook",
")",
";",
"if",
"(",
"!",
"plugin",
")",
"return",
";",
"var",
"APIHook",
"=",
"APIHooks",
"[",
"hook",
"]",
".",
"bind",
"(",
"self",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
"plugin",
")",
".",
"map",
"(",
"function",
"(",
"plugin",
")",
"{",
"return",
"plugin",
"[",
"hook",
"]",
"(",
")",
";",
"}",
")",
".",
"each",
"(",
"function",
"(",
"args",
")",
"{",
"return",
"APIHook",
".",
"apply",
"(",
"self",
",",
"args",
")",
";",
"}",
")",
";",
"}",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Registers and initializes hooks.
@returns Promise
|
[
"Registers",
"and",
"initializes",
"hooks",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L114-L134
|
|
12,366
|
db-migrate/node-db-migrate
|
api.js
|
function (description, args, type) {
var name = args.shift();
this.internals.argv.describe(name, description);
for (var i = 0; i < args.length; ++i) {
this.internals.argv.alias(args[i], name);
}
switch (type) {
case 'string':
this.internals.argv.string(name);
break;
case 'boolean':
this.internals.argv.boolean(name);
break;
default:
return false;
}
return true;
}
|
javascript
|
function (description, args, type) {
var name = args.shift();
this.internals.argv.describe(name, description);
for (var i = 0; i < args.length; ++i) {
this.internals.argv.alias(args[i], name);
}
switch (type) {
case 'string':
this.internals.argv.string(name);
break;
case 'boolean':
this.internals.argv.boolean(name);
break;
default:
return false;
}
return true;
}
|
[
"function",
"(",
"description",
",",
"args",
",",
"type",
")",
"{",
"var",
"name",
"=",
"args",
".",
"shift",
"(",
")",
";",
"this",
".",
"internals",
".",
"argv",
".",
"describe",
"(",
"name",
",",
"description",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"++",
"i",
")",
"{",
"this",
".",
"internals",
".",
"argv",
".",
"alias",
"(",
"args",
"[",
"i",
"]",
",",
"name",
")",
";",
"}",
"switch",
"(",
"type",
")",
"{",
"case",
"'string'",
":",
"this",
".",
"internals",
".",
"argv",
".",
"string",
"(",
"name",
")",
";",
"break",
";",
"case",
"'boolean'",
":",
"this",
".",
"internals",
".",
"argv",
".",
"boolean",
"(",
"name",
")",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Add a configuration option to dbmigrate.
@return boolean
|
[
"Add",
"a",
"configuration",
"option",
"to",
"dbmigrate",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L143-L165
|
|
12,367
|
db-migrate/node-db-migrate
|
api.js
|
function (specification, opts, callback) {
var executeSync = load('sync');
if (arguments.length > 0) {
if (typeof specification === 'string') {
this.internals.argv.destination = specification;
}
if (typeof opts === 'string') {
this.internals.migrationMode = opts;
this.internals.matching = opts;
} else if (typeof opts === 'function') {
callback = opts;
}
}
return Promise.fromCallback(
function (callback) {
executeSync(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (specification, opts, callback) {
var executeSync = load('sync');
if (arguments.length > 0) {
if (typeof specification === 'string') {
this.internals.argv.destination = specification;
}
if (typeof opts === 'string') {
this.internals.migrationMode = opts;
this.internals.matching = opts;
} else if (typeof opts === 'function') {
callback = opts;
}
}
return Promise.fromCallback(
function (callback) {
executeSync(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"specification",
",",
"opts",
",",
"callback",
")",
"{",
"var",
"executeSync",
"=",
"load",
"(",
"'sync'",
")",
";",
"if",
"(",
"arguments",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"typeof",
"specification",
"===",
"'string'",
")",
"{",
"this",
".",
"internals",
".",
"argv",
".",
"destination",
"=",
"specification",
";",
"}",
"if",
"(",
"typeof",
"opts",
"===",
"'string'",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"opts",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"opts",
";",
"}",
"else",
"if",
"(",
"typeof",
"opts",
"===",
"'function'",
")",
"{",
"callback",
"=",
"opts",
";",
"}",
"}",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeSync",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Executes up a given number of migrations or a specific one.
Defaults to up all migrations if no count is given.
|
[
"Executes",
"up",
"a",
"given",
"number",
"of",
"migrations",
"or",
"a",
"specific",
"one",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L266-L287
|
|
12,368
|
db-migrate/node-db-migrate
|
api.js
|
function (scope, callback) {
var executeDown = load('down');
if (typeof scope === 'string') {
this.internals.migrationMode = scope;
this.internals.matching = scope;
} else if (typeof scope === 'function') {
callback = scope;
}
this.internals.argv.count = Number.MAX_VALUE;
return Promise.fromCallback(
function (callback) {
executeDown(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (scope, callback) {
var executeDown = load('down');
if (typeof scope === 'string') {
this.internals.migrationMode = scope;
this.internals.matching = scope;
} else if (typeof scope === 'function') {
callback = scope;
}
this.internals.argv.count = Number.MAX_VALUE;
return Promise.fromCallback(
function (callback) {
executeDown(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"scope",
",",
"callback",
")",
"{",
"var",
"executeDown",
"=",
"load",
"(",
"'down'",
")",
";",
"if",
"(",
"typeof",
"scope",
"===",
"'string'",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"scope",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"scope",
";",
"}",
"else",
"if",
"(",
"typeof",
"scope",
"===",
"'function'",
")",
"{",
"callback",
"=",
"scope",
";",
"}",
"this",
".",
"internals",
".",
"argv",
".",
"count",
"=",
"Number",
".",
"MAX_VALUE",
";",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeDown",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Executes down for all currently migrated migrations.
|
[
"Executes",
"down",
"for",
"all",
"currently",
"migrated",
"migrations",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L292-L308
|
|
12,369
|
db-migrate/node-db-migrate
|
api.js
|
function (migrationName, scope, callback) {
var executeCreateMigration = load('create-migration');
if (typeof scope === 'function') {
callback = scope;
} else if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
this.internals.argv._.push(migrationName);
return Promise.fromCallback(
function (callback) {
executeCreateMigration(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (migrationName, scope, callback) {
var executeCreateMigration = load('create-migration');
if (typeof scope === 'function') {
callback = scope;
} else if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
this.internals.argv._.push(migrationName);
return Promise.fromCallback(
function (callback) {
executeCreateMigration(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"migrationName",
",",
"scope",
",",
"callback",
")",
"{",
"var",
"executeCreateMigration",
"=",
"load",
"(",
"'create-migration'",
")",
";",
"if",
"(",
"typeof",
"scope",
"===",
"'function'",
")",
"{",
"callback",
"=",
"scope",
";",
"}",
"else",
"if",
"(",
"scope",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"scope",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"scope",
";",
"}",
"this",
".",
"internals",
".",
"argv",
".",
"_",
".",
"push",
"(",
"migrationName",
")",
";",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeCreateMigration",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Creates a correctly formatted migration
|
[
"Creates",
"a",
"correctly",
"formatted",
"migration"
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L327-L342
|
|
12,370
|
db-migrate/node-db-migrate
|
api.js
|
function (dbname, callback) {
var executeDB = load('db');
this.internals.argv._.push(dbname);
this.internals.mode = 'create';
return Promise.fromCallback(
function (callback) {
executeDB(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (dbname, callback) {
var executeDB = load('db');
this.internals.argv._.push(dbname);
this.internals.mode = 'create';
return Promise.fromCallback(
function (callback) {
executeDB(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"dbname",
",",
"callback",
")",
"{",
"var",
"executeDB",
"=",
"load",
"(",
"'db'",
")",
";",
"this",
".",
"internals",
".",
"argv",
".",
"_",
".",
"push",
"(",
"dbname",
")",
";",
"this",
".",
"internals",
".",
"mode",
"=",
"'create'",
";",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeDB",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Creates a database of the given dbname.
|
[
"Creates",
"a",
"database",
"of",
"the",
"given",
"dbname",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L347-L356
|
|
12,371
|
db-migrate/node-db-migrate
|
api.js
|
function (mode, scope, callback) {
var executeSeed = load('seed');
if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
this.internals.mode = mode || 'vc';
return Promise.fromCallback(
function (callback) {
executeSeed(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (mode, scope, callback) {
var executeSeed = load('seed');
if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
this.internals.mode = mode || 'vc';
return Promise.fromCallback(
function (callback) {
executeSeed(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"mode",
",",
"scope",
",",
"callback",
")",
"{",
"var",
"executeSeed",
"=",
"load",
"(",
"'seed'",
")",
";",
"if",
"(",
"scope",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"scope",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"scope",
";",
"}",
"this",
".",
"internals",
".",
"mode",
"=",
"mode",
"||",
"'vc'",
";",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeSeed",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Seeds either the static or version controlled seeders, controlled by
the passed mode.
|
[
"Seeds",
"either",
"the",
"static",
"or",
"version",
"controlled",
"seeders",
"controlled",
"by",
"the",
"passed",
"mode",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L400-L413
|
|
12,372
|
db-migrate/node-db-migrate
|
api.js
|
function (specification, scope, callback) {
var executeUndoSeed = load('undo-seed');
if (arguments.length > 0) {
if (typeof specification === 'number') {
this.internals.argv.count = specification;
if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
} else if (typeof specification === 'string') {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
}
return Promise.fromCallback(
function (callback) {
executeUndoSeed(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
javascript
|
function (specification, scope, callback) {
var executeUndoSeed = load('undo-seed');
if (arguments.length > 0) {
if (typeof specification === 'number') {
this.internals.argv.count = specification;
if (scope) {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
} else if (typeof specification === 'string') {
this.internals.migrationMode = scope;
this.internals.matching = scope;
}
}
return Promise.fromCallback(
function (callback) {
executeUndoSeed(this.internals, this.config, callback);
}.bind(this)
).asCallback(callback);
}
|
[
"function",
"(",
"specification",
",",
"scope",
",",
"callback",
")",
"{",
"var",
"executeUndoSeed",
"=",
"load",
"(",
"'undo-seed'",
")",
";",
"if",
"(",
"arguments",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"typeof",
"specification",
"===",
"'number'",
")",
"{",
"this",
".",
"internals",
".",
"argv",
".",
"count",
"=",
"specification",
";",
"if",
"(",
"scope",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"scope",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"scope",
";",
"}",
"}",
"else",
"if",
"(",
"typeof",
"specification",
"===",
"'string'",
")",
"{",
"this",
".",
"internals",
".",
"migrationMode",
"=",
"scope",
";",
"this",
".",
"internals",
".",
"matching",
"=",
"scope",
";",
"}",
"}",
"return",
"Promise",
".",
"fromCallback",
"(",
"function",
"(",
"callback",
")",
"{",
"executeUndoSeed",
"(",
"this",
".",
"internals",
",",
"this",
".",
"config",
",",
"callback",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
".",
"asCallback",
"(",
"callback",
")",
";",
"}"
] |
Execute the down function of currently executed seeds.
|
[
"Execute",
"the",
"down",
"function",
"of",
"currently",
"executed",
"seeds",
"."
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/api.js#L418-L439
|
|
12,373
|
db-migrate/node-db-migrate
|
lib/walker.js
|
SeedLink
|
function SeedLink (driver, internals) {
this.seeder = require('./seeder.js')(
driver,
internals.argv['vcseeder-dir'],
true,
internals
);
this.internals = internals;
this.links = [];
}
|
javascript
|
function SeedLink (driver, internals) {
this.seeder = require('./seeder.js')(
driver,
internals.argv['vcseeder-dir'],
true,
internals
);
this.internals = internals;
this.links = [];
}
|
[
"function",
"SeedLink",
"(",
"driver",
",",
"internals",
")",
"{",
"this",
".",
"seeder",
"=",
"require",
"(",
"'./seeder.js'",
")",
"(",
"driver",
",",
"internals",
".",
"argv",
"[",
"'vcseeder-dir'",
"]",
",",
"true",
",",
"internals",
")",
";",
"this",
".",
"internals",
"=",
"internals",
";",
"this",
".",
"links",
"=",
"[",
"]",
";",
"}"
] |
Not sure what will happen to this yet
|
[
"Not",
"sure",
"what",
"will",
"happen",
"to",
"this",
"yet"
] |
3f22c400490f5714cc1aa7a1890406a0ea1b900e
|
https://github.com/db-migrate/node-db-migrate/blob/3f22c400490f5714cc1aa7a1890406a0ea1b900e/lib/walker.js#L9-L18
|
12,374
|
jhipster/jhipster-core
|
lib/export/jdl_exporter.js
|
exportToJDL
|
function exportToJDL(jdl, path) {
if (!jdl) {
throw new Error('A JDLObject has to be passed to be exported.');
}
if (!path) {
path = './jhipster-jdl.jh';
}
fs.writeFileSync(path, jdl.toString());
}
|
javascript
|
function exportToJDL(jdl, path) {
if (!jdl) {
throw new Error('A JDLObject has to be passed to be exported.');
}
if (!path) {
path = './jhipster-jdl.jh';
}
fs.writeFileSync(path, jdl.toString());
}
|
[
"function",
"exportToJDL",
"(",
"jdl",
",",
"path",
")",
"{",
"if",
"(",
"!",
"jdl",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A JDLObject has to be passed to be exported.'",
")",
";",
"}",
"if",
"(",
"!",
"path",
")",
"{",
"path",
"=",
"'./jhipster-jdl.jh'",
";",
"}",
"fs",
".",
"writeFileSync",
"(",
"path",
",",
"jdl",
".",
"toString",
"(",
")",
")",
";",
"}"
] |
Writes down the given JDL to a file.
@param jdl the JDL to write.
@param path the path where the file will be written.
|
[
"Writes",
"down",
"the",
"given",
"JDL",
"to",
"a",
"file",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jdl_exporter.js#L31-L39
|
12,375
|
jhipster/jhipster-core
|
lib/converters/json_to_jdl_entity_converter.js
|
convertEntitiesToJDL
|
function convertEntitiesToJDL(entities, jdl) {
if (!entities) {
throw new Error('Entities have to be passed to be converted.');
}
init(entities, jdl);
addEntities();
addRelationshipsToJDL();
return configuration.jdl;
}
|
javascript
|
function convertEntitiesToJDL(entities, jdl) {
if (!entities) {
throw new Error('Entities have to be passed to be converted.');
}
init(entities, jdl);
addEntities();
addRelationshipsToJDL();
return configuration.jdl;
}
|
[
"function",
"convertEntitiesToJDL",
"(",
"entities",
",",
"jdl",
")",
"{",
"if",
"(",
"!",
"entities",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Entities have to be passed to be converted.'",
")",
";",
"}",
"init",
"(",
"entities",
",",
"jdl",
")",
";",
"addEntities",
"(",
")",
";",
"addRelationshipsToJDL",
"(",
")",
";",
"return",
"configuration",
".",
"jdl",
";",
"}"
] |
Converts the JSON entities into JDL.
@param entities the entities in plain JS format.
@param jdl {JDLObject} the base JDLObject to use as conversion result.
@returns {*} the updated JDLObject.
|
[
"Converts",
"the",
"JSON",
"entities",
"into",
"JDL",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/converters/json_to_jdl_entity_converter.js#L62-L70
|
12,376
|
jhipster/jhipster-core
|
lib/export/jhipster_entity_exporter.js
|
exportEntitiesInApplications
|
function exportEntitiesInApplications(passedConfiguration) {
if (!passedConfiguration || !passedConfiguration.entities) {
throw new Error('Entities have to be passed to be exported.');
}
let exportedEntities = [];
Object.keys(passedConfiguration.applications).forEach(applicationName => {
const application = passedConfiguration.applications[applicationName];
const entitiesToExport = getEntitiesToExport(application.entityNames, passedConfiguration.entities);
exportedEntities = exportedEntities.concat(
exportEntities({
entities: entitiesToExport,
forceNoFiltering: passedConfiguration.forceNoFiltering,
application: {
forSeveralApplications: Object.keys(passedConfiguration.applications).length !== 1,
name: application.config.baseName,
type: application.config.applicationType
}
})
);
});
return exportedEntities;
}
|
javascript
|
function exportEntitiesInApplications(passedConfiguration) {
if (!passedConfiguration || !passedConfiguration.entities) {
throw new Error('Entities have to be passed to be exported.');
}
let exportedEntities = [];
Object.keys(passedConfiguration.applications).forEach(applicationName => {
const application = passedConfiguration.applications[applicationName];
const entitiesToExport = getEntitiesToExport(application.entityNames, passedConfiguration.entities);
exportedEntities = exportedEntities.concat(
exportEntities({
entities: entitiesToExport,
forceNoFiltering: passedConfiguration.forceNoFiltering,
application: {
forSeveralApplications: Object.keys(passedConfiguration.applications).length !== 1,
name: application.config.baseName,
type: application.config.applicationType
}
})
);
});
return exportedEntities;
}
|
[
"function",
"exportEntitiesInApplications",
"(",
"passedConfiguration",
")",
"{",
"if",
"(",
"!",
"passedConfiguration",
"||",
"!",
"passedConfiguration",
".",
"entities",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Entities have to be passed to be exported.'",
")",
";",
"}",
"let",
"exportedEntities",
"=",
"[",
"]",
";",
"Object",
".",
"keys",
"(",
"passedConfiguration",
".",
"applications",
")",
".",
"forEach",
"(",
"applicationName",
"=>",
"{",
"const",
"application",
"=",
"passedConfiguration",
".",
"applications",
"[",
"applicationName",
"]",
";",
"const",
"entitiesToExport",
"=",
"getEntitiesToExport",
"(",
"application",
".",
"entityNames",
",",
"passedConfiguration",
".",
"entities",
")",
";",
"exportedEntities",
"=",
"exportedEntities",
".",
"concat",
"(",
"exportEntities",
"(",
"{",
"entities",
":",
"entitiesToExport",
",",
"forceNoFiltering",
":",
"passedConfiguration",
".",
"forceNoFiltering",
",",
"application",
":",
"{",
"forSeveralApplications",
":",
"Object",
".",
"keys",
"(",
"passedConfiguration",
".",
"applications",
")",
".",
"length",
"!==",
"1",
",",
"name",
":",
"application",
".",
"config",
".",
"baseName",
",",
"type",
":",
"application",
".",
"config",
".",
"applicationType",
"}",
"}",
")",
")",
";",
"}",
")",
";",
"return",
"exportedEntities",
";",
"}"
] |
Exports the passed entities to JSON in the applications.
@param passedConfiguration the object having the keys:
- entities: the entities to export,
- forceNoFiltering: whether to filter out unchanged entities,
- applications: the application iterable containing some or all the entities
@return the exported entities per application name.
|
[
"Exports",
"the",
"passed",
"entities",
"to",
"JSON",
"in",
"the",
"applications",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_entity_exporter.js#L43-L64
|
12,377
|
jhipster/jhipster-core
|
lib/export/jhipster_entity_exporter.js
|
exportEntities
|
function exportEntities(passedConfiguration) {
init(passedConfiguration);
createJHipsterJSONFolder(
passedConfiguration.application.forSeveralApplications ? configuration.application.name : ''
);
if (!configuration.forceNoFiltering) {
filterOutUnchangedEntities();
}
if (shouldFilterOutEntitiesBasedOnMicroservice()) {
filterOutEntitiesByMicroservice();
}
writeEntities(passedConfiguration.application.forSeveralApplications ? configuration.application.name : '');
return Object.values(configuration.entities);
}
|
javascript
|
function exportEntities(passedConfiguration) {
init(passedConfiguration);
createJHipsterJSONFolder(
passedConfiguration.application.forSeveralApplications ? configuration.application.name : ''
);
if (!configuration.forceNoFiltering) {
filterOutUnchangedEntities();
}
if (shouldFilterOutEntitiesBasedOnMicroservice()) {
filterOutEntitiesByMicroservice();
}
writeEntities(passedConfiguration.application.forSeveralApplications ? configuration.application.name : '');
return Object.values(configuration.entities);
}
|
[
"function",
"exportEntities",
"(",
"passedConfiguration",
")",
"{",
"init",
"(",
"passedConfiguration",
")",
";",
"createJHipsterJSONFolder",
"(",
"passedConfiguration",
".",
"application",
".",
"forSeveralApplications",
"?",
"configuration",
".",
"application",
".",
"name",
":",
"''",
")",
";",
"if",
"(",
"!",
"configuration",
".",
"forceNoFiltering",
")",
"{",
"filterOutUnchangedEntities",
"(",
")",
";",
"}",
"if",
"(",
"shouldFilterOutEntitiesBasedOnMicroservice",
"(",
")",
")",
"{",
"filterOutEntitiesByMicroservice",
"(",
")",
";",
"}",
"writeEntities",
"(",
"passedConfiguration",
".",
"application",
".",
"forSeveralApplications",
"?",
"configuration",
".",
"application",
".",
"name",
":",
"''",
")",
";",
"return",
"Object",
".",
"values",
"(",
"configuration",
".",
"entities",
")",
";",
"}"
] |
Exports the passed entities to JSON.
@param passedConfiguration the object having the keys:
- entities: the entity objects to export (key: entity name, value: the entity),
- forceNoFiltering: whether to filter out unchanged entities,
- application:
- forSeveralApplications: whether more than one application have to be generated,
- name: application base name,
- type: application type
@returns The exported entities.
|
[
"Exports",
"the",
"passed",
"entities",
"to",
"JSON",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_entity_exporter.js#L85-L98
|
12,378
|
jhipster/jhipster-core
|
lib/export/jhipster_entity_exporter.js
|
writeEntities
|
function writeEntities(subFolder) {
for (let i = 0, entityNames = Object.keys(configuration.entities); i < entityNames.length; i++) {
const filePath = path.join(subFolder, toFilePath(entityNames[i]));
const entity = updateChangelogDate(filePath, configuration.entities[entityNames[i]]);
fs.writeFileSync(filePath, JSON.stringify(entity, null, 4));
}
}
|
javascript
|
function writeEntities(subFolder) {
for (let i = 0, entityNames = Object.keys(configuration.entities); i < entityNames.length; i++) {
const filePath = path.join(subFolder, toFilePath(entityNames[i]));
const entity = updateChangelogDate(filePath, configuration.entities[entityNames[i]]);
fs.writeFileSync(filePath, JSON.stringify(entity, null, 4));
}
}
|
[
"function",
"writeEntities",
"(",
"subFolder",
")",
"{",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"entityNames",
"=",
"Object",
".",
"keys",
"(",
"configuration",
".",
"entities",
")",
";",
"i",
"<",
"entityNames",
".",
"length",
";",
"i",
"++",
")",
"{",
"const",
"filePath",
"=",
"path",
".",
"join",
"(",
"subFolder",
",",
"toFilePath",
"(",
"entityNames",
"[",
"i",
"]",
")",
")",
";",
"const",
"entity",
"=",
"updateChangelogDate",
"(",
"filePath",
",",
"configuration",
".",
"entities",
"[",
"entityNames",
"[",
"i",
"]",
"]",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"filePath",
",",
"JSON",
".",
"stringify",
"(",
"entity",
",",
"null",
",",
"4",
")",
")",
";",
"}",
"}"
] |
Writes entities in a sub folder.
@param subFolder the folder (to create) in which the JHipster entity folder will be.
|
[
"Writes",
"entities",
"in",
"a",
"sub",
"folder",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_entity_exporter.js#L119-L125
|
12,379
|
jhipster/jhipster-core
|
lib/export/export_utils.js
|
writeConfigFile
|
function writeConfigFile(config, yoRcPath = '.yo-rc.json') {
let newYoRc = { ...config };
if (FileUtils.doesFileExist(yoRcPath)) {
const yoRc = JSON.parse(fs.readFileSync(yoRcPath, { encoding: 'utf-8' }));
newYoRc = {
...yoRc,
...config,
[GENERATOR_NAME]: {
...yoRc[GENERATOR_NAME],
...config[GENERATOR_NAME]
}
};
}
fs.writeFileSync(yoRcPath, JSON.stringify(newYoRc, null, 2));
}
|
javascript
|
function writeConfigFile(config, yoRcPath = '.yo-rc.json') {
let newYoRc = { ...config };
if (FileUtils.doesFileExist(yoRcPath)) {
const yoRc = JSON.parse(fs.readFileSync(yoRcPath, { encoding: 'utf-8' }));
newYoRc = {
...yoRc,
...config,
[GENERATOR_NAME]: {
...yoRc[GENERATOR_NAME],
...config[GENERATOR_NAME]
}
};
}
fs.writeFileSync(yoRcPath, JSON.stringify(newYoRc, null, 2));
}
|
[
"function",
"writeConfigFile",
"(",
"config",
",",
"yoRcPath",
"=",
"'.yo-rc.json'",
")",
"{",
"let",
"newYoRc",
"=",
"{",
"...",
"config",
"}",
";",
"if",
"(",
"FileUtils",
".",
"doesFileExist",
"(",
"yoRcPath",
")",
")",
"{",
"const",
"yoRc",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"yoRcPath",
",",
"{",
"encoding",
":",
"'utf-8'",
"}",
")",
")",
";",
"newYoRc",
"=",
"{",
"...",
"yoRc",
",",
"...",
"config",
",",
"[",
"GENERATOR_NAME",
"]",
":",
"{",
"...",
"yoRc",
"[",
"GENERATOR_NAME",
"]",
",",
"...",
"config",
"[",
"GENERATOR_NAME",
"]",
"}",
"}",
";",
"}",
"fs",
".",
"writeFileSync",
"(",
"yoRcPath",
",",
"JSON",
".",
"stringify",
"(",
"newYoRc",
",",
"null",
",",
"2",
")",
")",
";",
"}"
] |
This function writes a Yeoman config file in the current folder.
@param config the configuration.
@param yoRcPath the yeoman conf file path
|
[
"This",
"function",
"writes",
"a",
"Yeoman",
"config",
"file",
"in",
"the",
"current",
"folder",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/export_utils.js#L51-L65
|
12,380
|
jhipster/jhipster-core
|
lib/reader/file_reader.js
|
readFile
|
function readFile(path) {
if (!path) {
throw new Error('The passed file must not be nil to be read.');
}
if (!FileUtils.doesFileExist(path)) {
throw new Error(`The passed file '${path}' must exist and must not be a directory to be read.`);
}
return fs.readFileSync(path, 'utf-8').toString();
}
|
javascript
|
function readFile(path) {
if (!path) {
throw new Error('The passed file must not be nil to be read.');
}
if (!FileUtils.doesFileExist(path)) {
throw new Error(`The passed file '${path}' must exist and must not be a directory to be read.`);
}
return fs.readFileSync(path, 'utf-8').toString();
}
|
[
"function",
"readFile",
"(",
"path",
")",
"{",
"if",
"(",
"!",
"path",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The passed file must not be nil to be read.'",
")",
";",
"}",
"if",
"(",
"!",
"FileUtils",
".",
"doesFileExist",
"(",
"path",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"path",
"}",
"`",
")",
";",
"}",
"return",
"fs",
".",
"readFileSync",
"(",
"path",
",",
"'utf-8'",
")",
".",
"toString",
"(",
")",
";",
"}"
] |
Reads a given file.
@param path the file's path.
@returns {string} the file's content.
|
[
"Reads",
"a",
"given",
"file",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/reader/file_reader.js#L45-L53
|
12,381
|
jhipster/jhipster-core
|
lib/parser/entity_parser.js
|
parse
|
function parse(args) {
const merged = merge(defaults(), args);
if (!args || !merged.jdlObject || !args.databaseType) {
throw new Error('The JDL object and the database type are both mandatory.');
}
if (merged.applicationType !== GATEWAY) {
checkNoSQLModeling(merged.jdlObject, args.databaseType);
}
init(merged);
initializeEntities();
setOptions();
fillEntities();
setApplicationToEntities();
return entities;
}
|
javascript
|
function parse(args) {
const merged = merge(defaults(), args);
if (!args || !merged.jdlObject || !args.databaseType) {
throw new Error('The JDL object and the database type are both mandatory.');
}
if (merged.applicationType !== GATEWAY) {
checkNoSQLModeling(merged.jdlObject, args.databaseType);
}
init(merged);
initializeEntities();
setOptions();
fillEntities();
setApplicationToEntities();
return entities;
}
|
[
"function",
"parse",
"(",
"args",
")",
"{",
"const",
"merged",
"=",
"merge",
"(",
"defaults",
"(",
")",
",",
"args",
")",
";",
"if",
"(",
"!",
"args",
"||",
"!",
"merged",
".",
"jdlObject",
"||",
"!",
"args",
".",
"databaseType",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The JDL object and the database type are both mandatory.'",
")",
";",
"}",
"if",
"(",
"merged",
".",
"applicationType",
"!==",
"GATEWAY",
")",
"{",
"checkNoSQLModeling",
"(",
"merged",
".",
"jdlObject",
",",
"args",
".",
"databaseType",
")",
";",
"}",
"init",
"(",
"merged",
")",
";",
"initializeEntities",
"(",
")",
";",
"setOptions",
"(",
")",
";",
"fillEntities",
"(",
")",
";",
"setApplicationToEntities",
"(",
")",
";",
"return",
"entities",
";",
"}"
] |
Converts a JDLObject to ready-to-be exported JSON entities.
@param args the configuration object, keys:
- jdlObject, the JDLObject to convert to JSON
- databaseType
- applicationType
@returns {*} entities that can be exported to JSON.
|
[
"Converts",
"a",
"JDLObject",
"to",
"ready",
"-",
"to",
"-",
"be",
"exported",
"JSON",
"entities",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/parser/entity_parser.js#L57-L71
|
12,382
|
jhipster/jhipster-core
|
lib/exceptions/application_validator.js
|
checkApplication
|
function checkApplication(jdlApplication) {
if (!jdlApplication || !jdlApplication.config) {
throw new Error('An application must be passed to be validated.');
}
applicationConfig = jdlApplication.config;
checkForValidValues();
checkForNoDatabaseType();
checkForInvalidDatabaseCombinations();
}
|
javascript
|
function checkApplication(jdlApplication) {
if (!jdlApplication || !jdlApplication.config) {
throw new Error('An application must be passed to be validated.');
}
applicationConfig = jdlApplication.config;
checkForValidValues();
checkForNoDatabaseType();
checkForInvalidDatabaseCombinations();
}
|
[
"function",
"checkApplication",
"(",
"jdlApplication",
")",
"{",
"if",
"(",
"!",
"jdlApplication",
"||",
"!",
"jdlApplication",
".",
"config",
")",
"{",
"throw",
"new",
"Error",
"(",
"'An application must be passed to be validated.'",
")",
";",
"}",
"applicationConfig",
"=",
"jdlApplication",
".",
"config",
";",
"checkForValidValues",
"(",
")",
";",
"checkForNoDatabaseType",
"(",
")",
";",
"checkForInvalidDatabaseCombinations",
"(",
")",
";",
"}"
] |
Checks whether a JDL application is valid. If everything's okay, no exception is thrown.
@param jdlApplication the application to check
|
[
"Checks",
"whether",
"a",
"JDL",
"application",
"is",
"valid",
".",
"If",
"everything",
"s",
"okay",
"no",
"exception",
"is",
"thrown",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/exceptions/application_validator.js#L50-L58
|
12,383
|
jhipster/jhipster-core
|
lib/export/jhipster_application_exporter.js
|
exportApplication
|
function exportApplication(application) {
checkForErrors(application);
const formattedApplication = setUpApplicationStructure(application);
writeConfigFile(formattedApplication);
return formattedApplication;
}
|
javascript
|
function exportApplication(application) {
checkForErrors(application);
const formattedApplication = setUpApplicationStructure(application);
writeConfigFile(formattedApplication);
return formattedApplication;
}
|
[
"function",
"exportApplication",
"(",
"application",
")",
"{",
"checkForErrors",
"(",
"application",
")",
";",
"const",
"formattedApplication",
"=",
"setUpApplicationStructure",
"(",
"application",
")",
";",
"writeConfigFile",
"(",
"formattedApplication",
")",
";",
"return",
"formattedApplication",
";",
"}"
] |
Exports JDL a application to a JDL file in the current directory.
@param application, the JDL application to export.
@return the exported application in its final form.
|
[
"Exports",
"JDL",
"a",
"application",
"to",
"a",
"JDL",
"file",
"in",
"the",
"current",
"directory",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_application_exporter.js#L52-L57
|
12,384
|
jhipster/jhipster-core
|
lib/export/jhipster_application_exporter.js
|
writeApplicationFileForMultipleApplications
|
function writeApplicationFileForMultipleApplications(application) {
const applicationBaseName = application[GENERATOR_NAME].baseName;
checkPath(applicationBaseName);
createFolderIfNeeded(applicationBaseName);
writeConfigFile(application, path.join(applicationBaseName, '.yo-rc.json'));
}
|
javascript
|
function writeApplicationFileForMultipleApplications(application) {
const applicationBaseName = application[GENERATOR_NAME].baseName;
checkPath(applicationBaseName);
createFolderIfNeeded(applicationBaseName);
writeConfigFile(application, path.join(applicationBaseName, '.yo-rc.json'));
}
|
[
"function",
"writeApplicationFileForMultipleApplications",
"(",
"application",
")",
"{",
"const",
"applicationBaseName",
"=",
"application",
"[",
"GENERATOR_NAME",
"]",
".",
"baseName",
";",
"checkPath",
"(",
"applicationBaseName",
")",
";",
"createFolderIfNeeded",
"(",
"applicationBaseName",
")",
";",
"writeConfigFile",
"(",
"application",
",",
"path",
".",
"join",
"(",
"applicationBaseName",
",",
"'.yo-rc.json'",
")",
")",
";",
"}"
] |
This function writes a Yeoman config file in an application folder.
@param application the application.
|
[
"This",
"function",
"writes",
"a",
"Yeoman",
"config",
"file",
"in",
"an",
"application",
"folder",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_application_exporter.js#L99-L104
|
12,385
|
jhipster/jhipster-core
|
lib/converters/json_to_jdl_option_converter.js
|
convertServerOptionsToJDL
|
function convertServerOptionsToJDL(config, jdl) {
const jdlObject = jdl || new JDLObject();
const jhipsterConfig = config || {};
[SKIP_CLIENT, SKIP_SERVER, SKIP_USER_MANAGEMENT].forEach(option => {
if (jhipsterConfig[option] === true) {
jdlObject.addOption(
new JDLUnaryOption({
name: option,
value: jhipsterConfig[option]
})
);
}
});
return jdlObject;
}
|
javascript
|
function convertServerOptionsToJDL(config, jdl) {
const jdlObject = jdl || new JDLObject();
const jhipsterConfig = config || {};
[SKIP_CLIENT, SKIP_SERVER, SKIP_USER_MANAGEMENT].forEach(option => {
if (jhipsterConfig[option] === true) {
jdlObject.addOption(
new JDLUnaryOption({
name: option,
value: jhipsterConfig[option]
})
);
}
});
return jdlObject;
}
|
[
"function",
"convertServerOptionsToJDL",
"(",
"config",
",",
"jdl",
")",
"{",
"const",
"jdlObject",
"=",
"jdl",
"||",
"new",
"JDLObject",
"(",
")",
";",
"const",
"jhipsterConfig",
"=",
"config",
"||",
"{",
"}",
";",
"[",
"SKIP_CLIENT",
",",
"SKIP_SERVER",
",",
"SKIP_USER_MANAGEMENT",
"]",
".",
"forEach",
"(",
"option",
"=>",
"{",
"if",
"(",
"jhipsterConfig",
"[",
"option",
"]",
"===",
"true",
")",
"{",
"jdlObject",
".",
"addOption",
"(",
"new",
"JDLUnaryOption",
"(",
"{",
"name",
":",
"option",
",",
"value",
":",
"jhipsterConfig",
"[",
"option",
"]",
"}",
")",
")",
";",
"}",
"}",
")",
";",
"return",
"jdlObject",
";",
"}"
] |
Parses the jhipster configuration into JDL.
@param config the jhipster config ('generator-jhipster' in .yo-rc.json)
@param jdl {JDLObject} to which the parsed options are added. If undefined a new JDLObject is created.
@returns {JDLObject} the JDLObject
|
[
"Parses",
"the",
"jhipster",
"configuration",
"into",
"JDL",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/converters/json_to_jdl_option_converter.js#L34-L48
|
12,386
|
jhipster/jhipster-core
|
lib/parser/document_parser.js
|
parseFromConfigurationObject
|
function parseFromConfigurationObject(configuration) {
if (!configuration.document) {
throw new Error('The parsed JDL content must be passed.');
}
init(configuration);
fillApplications();
fillDeployments();
fillEnums();
fillClassesAndFields();
fillAssociations();
fillOptions();
return jdlObject;
}
|
javascript
|
function parseFromConfigurationObject(configuration) {
if (!configuration.document) {
throw new Error('The parsed JDL content must be passed.');
}
init(configuration);
fillApplications();
fillDeployments();
fillEnums();
fillClassesAndFields();
fillAssociations();
fillOptions();
return jdlObject;
}
|
[
"function",
"parseFromConfigurationObject",
"(",
"configuration",
")",
"{",
"if",
"(",
"!",
"configuration",
".",
"document",
")",
"{",
"throw",
"new",
"Error",
"(",
"'The parsed JDL content must be passed.'",
")",
";",
"}",
"init",
"(",
"configuration",
")",
";",
"fillApplications",
"(",
")",
";",
"fillDeployments",
"(",
")",
";",
"fillEnums",
"(",
")",
";",
"fillClassesAndFields",
"(",
")",
";",
"fillAssociations",
"(",
")",
";",
"fillOptions",
"(",
")",
";",
"return",
"jdlObject",
";",
"}"
] |
Converts the intermediate document to a JDLObject from a configuration object.
@param configuration The configuration object, keys:
- document
- applicationType
- applicationName
- generatorVersion
|
[
"Converts",
"the",
"intermediate",
"document",
"to",
"a",
"JDLObject",
"from",
"a",
"configuration",
"object",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/parser/document_parser.js#L59-L71
|
12,387
|
jhipster/jhipster-core
|
lib/exceptions/option_validator.js
|
checkOptions
|
function checkOptions(
{ jdlObject, applicationSettings, applicationsPerEntityName } = {
applicationSettings: {},
applicationsPerEntityName: {}
}
) {
if (!jdlObject) {
throw new Error('A JDL object has to be passed to check its options.');
}
configuration = {
jdlObject,
applicationSettings,
applicationsPerEntityName
};
jdlObject.getOptions().forEach(option => {
checkOption(option);
});
}
|
javascript
|
function checkOptions(
{ jdlObject, applicationSettings, applicationsPerEntityName } = {
applicationSettings: {},
applicationsPerEntityName: {}
}
) {
if (!jdlObject) {
throw new Error('A JDL object has to be passed to check its options.');
}
configuration = {
jdlObject,
applicationSettings,
applicationsPerEntityName
};
jdlObject.getOptions().forEach(option => {
checkOption(option);
});
}
|
[
"function",
"checkOptions",
"(",
"{",
"jdlObject",
",",
"applicationSettings",
",",
"applicationsPerEntityName",
"}",
"=",
"{",
"applicationSettings",
":",
"{",
"}",
",",
"applicationsPerEntityName",
":",
"{",
"}",
"}",
")",
"{",
"if",
"(",
"!",
"jdlObject",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A JDL object has to be passed to check its options.'",
")",
";",
"}",
"configuration",
"=",
"{",
"jdlObject",
",",
"applicationSettings",
",",
"applicationsPerEntityName",
"}",
";",
"jdlObject",
".",
"getOptions",
"(",
")",
".",
"forEach",
"(",
"option",
"=>",
"{",
"checkOption",
"(",
"option",
")",
";",
"}",
")",
";",
"}"
] |
Checks whether the passed JDL options are valid.
@param jdlObject the JDL object containing the options to check.
@param applicationSettings the application configuration.
@param applicationsPerEntityName applications per entity entity name.
|
[
"Checks",
"whether",
"the",
"passed",
"JDL",
"options",
"are",
"valid",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/exceptions/option_validator.js#L35-L52
|
12,388
|
jhipster/jhipster-core
|
lib/utils/format_utils.js
|
formatComment
|
function formatComment(comment) {
if (!comment) {
return undefined;
}
const parts = comment.trim().split('\n');
if (parts.length === 1 && parts[0].indexOf('*') !== 0) {
return parts[0];
}
return parts.reduce((previousValue, currentValue) => {
// newlines in the middle of the comment should stay to achieve:
// multiline comments entered by user drive unchanged from JDL
// studio to generated domain class
let delimiter = '';
if (previousValue !== '') {
delimiter = '\n';
}
return previousValue.concat(delimiter, currentValue.trim().replace(/[*]*\s*/, ''));
}, '');
}
|
javascript
|
function formatComment(comment) {
if (!comment) {
return undefined;
}
const parts = comment.trim().split('\n');
if (parts.length === 1 && parts[0].indexOf('*') !== 0) {
return parts[0];
}
return parts.reduce((previousValue, currentValue) => {
// newlines in the middle of the comment should stay to achieve:
// multiline comments entered by user drive unchanged from JDL
// studio to generated domain class
let delimiter = '';
if (previousValue !== '') {
delimiter = '\n';
}
return previousValue.concat(delimiter, currentValue.trim().replace(/[*]*\s*/, ''));
}, '');
}
|
[
"function",
"formatComment",
"(",
"comment",
")",
"{",
"if",
"(",
"!",
"comment",
")",
"{",
"return",
"undefined",
";",
"}",
"const",
"parts",
"=",
"comment",
".",
"trim",
"(",
")",
".",
"split",
"(",
"'\\n'",
")",
";",
"if",
"(",
"parts",
".",
"length",
"===",
"1",
"&&",
"parts",
"[",
"0",
"]",
".",
"indexOf",
"(",
"'*'",
")",
"!==",
"0",
")",
"{",
"return",
"parts",
"[",
"0",
"]",
";",
"}",
"return",
"parts",
".",
"reduce",
"(",
"(",
"previousValue",
",",
"currentValue",
")",
"=>",
"{",
"// newlines in the middle of the comment should stay to achieve:",
"// multiline comments entered by user drive unchanged from JDL",
"// studio to generated domain class",
"let",
"delimiter",
"=",
"''",
";",
"if",
"(",
"previousValue",
"!==",
"''",
")",
"{",
"delimiter",
"=",
"'\\n'",
";",
"}",
"return",
"previousValue",
".",
"concat",
"(",
"delimiter",
",",
"currentValue",
".",
"trim",
"(",
")",
".",
"replace",
"(",
"/",
"[*]*\\s*",
"/",
",",
"''",
")",
")",
";",
"}",
",",
"''",
")",
";",
"}"
] |
formats a comment
@param {String} comment string.
@returns {String} formatted comment string
|
[
"formats",
"a",
"comment"
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/utils/format_utils.js#L32-L50
|
12,389
|
jhipster/jhipster-core
|
lib/utils/file_utils.js
|
createDirectory
|
function createDirectory(directory) {
if (!directory) {
throw new Error('A directory must be passed to be created.');
}
const statObject = getStatObject(directory);
if (statObject && statObject.isFile()) {
throw new Error(`The directory to create '${directory}' is a file.`);
}
fse.ensureDirSync(directory);
}
|
javascript
|
function createDirectory(directory) {
if (!directory) {
throw new Error('A directory must be passed to be created.');
}
const statObject = getStatObject(directory);
if (statObject && statObject.isFile()) {
throw new Error(`The directory to create '${directory}' is a file.`);
}
fse.ensureDirSync(directory);
}
|
[
"function",
"createDirectory",
"(",
"directory",
")",
"{",
"if",
"(",
"!",
"directory",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A directory must be passed to be created.'",
")",
";",
"}",
"const",
"statObject",
"=",
"getStatObject",
"(",
"directory",
")",
";",
"if",
"(",
"statObject",
"&&",
"statObject",
".",
"isFile",
"(",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"directory",
"}",
"`",
")",
";",
"}",
"fse",
".",
"ensureDirSync",
"(",
"directory",
")",
";",
"}"
] |
Creates a directory, if it doesn't exist already.
@param directory the directory to create.
@throws WrongDirException if the directory to create exists and is a file.
|
[
"Creates",
"a",
"directory",
"if",
"it",
"doesn",
"t",
"exist",
"already",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/utils/file_utils.js#L53-L62
|
12,390
|
jhipster/jhipster-core
|
lib/export/jhipster_deployment_exporter.js
|
writeDeploymentConfigs
|
function writeDeploymentConfigs(deployment) {
const folderName = deployment[GENERATOR_NAME].deploymentType;
checkPath(folderName);
createFolderIfNeeded(folderName);
writeConfigFile(deployment, path.join(folderName, '.yo-rc.json'));
}
|
javascript
|
function writeDeploymentConfigs(deployment) {
const folderName = deployment[GENERATOR_NAME].deploymentType;
checkPath(folderName);
createFolderIfNeeded(folderName);
writeConfigFile(deployment, path.join(folderName, '.yo-rc.json'));
}
|
[
"function",
"writeDeploymentConfigs",
"(",
"deployment",
")",
"{",
"const",
"folderName",
"=",
"deployment",
"[",
"GENERATOR_NAME",
"]",
".",
"deploymentType",
";",
"checkPath",
"(",
"folderName",
")",
";",
"createFolderIfNeeded",
"(",
"folderName",
")",
";",
"writeConfigFile",
"(",
"deployment",
",",
"path",
".",
"join",
"(",
"folderName",
",",
"'.yo-rc.json'",
")",
")",
";",
"}"
] |
This function writes a Yeoman config file in a folder.
@param deployment the deployment.
|
[
"This",
"function",
"writes",
"a",
"Yeoman",
"config",
"file",
"in",
"a",
"folder",
"."
] |
dce9a29cd27a3c62eb8db580669d7d01a98290c3
|
https://github.com/jhipster/jhipster-core/blob/dce9a29cd27a3c62eb8db580669d7d01a98290c3/lib/export/jhipster_deployment_exporter.js#L78-L83
|
12,391
|
farzher/fuzzysort
|
fuzzysort.js
|
function(target) {
if(target.length > 999) return fuzzysort.prepare(target) // don't cache huge targets
var targetPrepared = preparedCache.get(target)
if(targetPrepared !== undefined) return targetPrepared
targetPrepared = fuzzysort.prepare(target)
preparedCache.set(target, targetPrepared)
return targetPrepared
}
|
javascript
|
function(target) {
if(target.length > 999) return fuzzysort.prepare(target) // don't cache huge targets
var targetPrepared = preparedCache.get(target)
if(targetPrepared !== undefined) return targetPrepared
targetPrepared = fuzzysort.prepare(target)
preparedCache.set(target, targetPrepared)
return targetPrepared
}
|
[
"function",
"(",
"target",
")",
"{",
"if",
"(",
"target",
".",
"length",
">",
"999",
")",
"return",
"fuzzysort",
".",
"prepare",
"(",
"target",
")",
"// don't cache huge targets",
"var",
"targetPrepared",
"=",
"preparedCache",
".",
"get",
"(",
"target",
")",
"if",
"(",
"targetPrepared",
"!==",
"undefined",
")",
"return",
"targetPrepared",
"targetPrepared",
"=",
"fuzzysort",
".",
"prepare",
"(",
"target",
")",
"preparedCache",
".",
"set",
"(",
"target",
",",
"targetPrepared",
")",
"return",
"targetPrepared",
"}"
] |
Below this point is only internal code Below this point is only internal code Below this point is only internal code Below this point is only internal code
|
[
"Below",
"this",
"point",
"is",
"only",
"internal",
"code",
"Below",
"this",
"point",
"is",
"only",
"internal",
"code",
"Below",
"this",
"point",
"is",
"only",
"internal",
"code",
"Below",
"this",
"point",
"is",
"only",
"internal",
"code"
] |
c6604993ac51bfe4de8e82c0a4d9b0c6e1794682
|
https://github.com/farzher/fuzzysort/blob/c6604993ac51bfe4de8e82c0a4d9b0c6e1794682/fuzzysort.js#L310-L317
|
|
12,392
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
negotiation
|
function negotiation(opt) {
var self = {
type : new type.UInt8(),
flag : new type.UInt8(),
length : new type.UInt16Le(0x0008, { constant : true }),
result : new type.UInt32Le()
};
return new type.Component(self, opt);
}
|
javascript
|
function negotiation(opt) {
var self = {
type : new type.UInt8(),
flag : new type.UInt8(),
length : new type.UInt16Le(0x0008, { constant : true }),
result : new type.UInt32Le()
};
return new type.Component(self, opt);
}
|
[
"function",
"negotiation",
"(",
"opt",
")",
"{",
"var",
"self",
"=",
"{",
"type",
":",
"new",
"type",
".",
"UInt8",
"(",
")",
",",
"flag",
":",
"new",
"type",
".",
"UInt8",
"(",
")",
",",
"length",
":",
"new",
"type",
".",
"UInt16Le",
"(",
"0x0008",
",",
"{",
"constant",
":",
"true",
"}",
")",
",",
"result",
":",
"new",
"type",
".",
"UInt32Le",
"(",
")",
"}",
";",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
",",
"opt",
")",
";",
"}"
] |
Use to negotiate security layer of RDP stack
In node-rdpjs only ssl is available
@param opt {object} component type options
@see request -> http://msdn.microsoft.com/en-us/library/cc240500.aspx
@see response -> http://msdn.microsoft.com/en-us/library/cc240506.aspx
@see failure ->http://msdn.microsoft.com/en-us/library/cc240507.aspx
|
[
"Use",
"to",
"negotiate",
"security",
"layer",
"of",
"RDP",
"stack",
"In",
"node",
"-",
"rdpjs",
"only",
"ssl",
"is",
"available"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L64-L72
|
12,393
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
clientConnectionRequestPDU
|
function clientConnectionRequestPDU(opt, cookie) {
var self = {
len : new type.UInt8(function() {
return new type.Component(self).size() - 1;
}),
code : new type.UInt8(MessageType.X224_TPDU_CONNECTION_REQUEST, { constant : true }),
padding : new type.Component([new type.UInt16Le(), new type.UInt16Le(), new type.UInt8()]),
cookie : cookie || new type.Factory( function (s) {
var offset = 0;
while (true) {
var token = s.buffer.readUInt16LE(s.offset + offset);
if (token === 0x0a0d) {
self.cookie = new type.BinaryString(null, { readLength : new type.CallableValue(offset + 2) }).read(s);
return;
}
else {
offset += 1;
}
}
}, { conditional : function () {
return self.len.value > 14;
}}),
protocolNeg : negotiation({ optional : true })
};
return new type.Component(self, opt);
}
|
javascript
|
function clientConnectionRequestPDU(opt, cookie) {
var self = {
len : new type.UInt8(function() {
return new type.Component(self).size() - 1;
}),
code : new type.UInt8(MessageType.X224_TPDU_CONNECTION_REQUEST, { constant : true }),
padding : new type.Component([new type.UInt16Le(), new type.UInt16Le(), new type.UInt8()]),
cookie : cookie || new type.Factory( function (s) {
var offset = 0;
while (true) {
var token = s.buffer.readUInt16LE(s.offset + offset);
if (token === 0x0a0d) {
self.cookie = new type.BinaryString(null, { readLength : new type.CallableValue(offset + 2) }).read(s);
return;
}
else {
offset += 1;
}
}
}, { conditional : function () {
return self.len.value > 14;
}}),
protocolNeg : negotiation({ optional : true })
};
return new type.Component(self, opt);
}
|
[
"function",
"clientConnectionRequestPDU",
"(",
"opt",
",",
"cookie",
")",
"{",
"var",
"self",
"=",
"{",
"len",
":",
"new",
"type",
".",
"UInt8",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
")",
".",
"size",
"(",
")",
"-",
"1",
";",
"}",
")",
",",
"code",
":",
"new",
"type",
".",
"UInt8",
"(",
"MessageType",
".",
"X224_TPDU_CONNECTION_REQUEST",
",",
"{",
"constant",
":",
"true",
"}",
")",
",",
"padding",
":",
"new",
"type",
".",
"Component",
"(",
"[",
"new",
"type",
".",
"UInt16Le",
"(",
")",
",",
"new",
"type",
".",
"UInt16Le",
"(",
")",
",",
"new",
"type",
".",
"UInt8",
"(",
")",
"]",
")",
",",
"cookie",
":",
"cookie",
"||",
"new",
"type",
".",
"Factory",
"(",
"function",
"(",
"s",
")",
"{",
"var",
"offset",
"=",
"0",
";",
"while",
"(",
"true",
")",
"{",
"var",
"token",
"=",
"s",
".",
"buffer",
".",
"readUInt16LE",
"(",
"s",
".",
"offset",
"+",
"offset",
")",
";",
"if",
"(",
"token",
"===",
"0x0a0d",
")",
"{",
"self",
".",
"cookie",
"=",
"new",
"type",
".",
"BinaryString",
"(",
"null",
",",
"{",
"readLength",
":",
"new",
"type",
".",
"CallableValue",
"(",
"offset",
"+",
"2",
")",
"}",
")",
".",
"read",
"(",
"s",
")",
";",
"return",
";",
"}",
"else",
"{",
"offset",
"+=",
"1",
";",
"}",
"}",
"}",
",",
"{",
"conditional",
":",
"function",
"(",
")",
"{",
"return",
"self",
".",
"len",
".",
"value",
">",
"14",
";",
"}",
"}",
")",
",",
"protocolNeg",
":",
"negotiation",
"(",
"{",
"optional",
":",
"true",
"}",
")",
"}",
";",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
",",
"opt",
")",
";",
"}"
] |
X224 client connection request
@param opt {object} component type options
@see http://msdn.microsoft.com/en-us/library/cc240470.aspx
|
[
"X224",
"client",
"connection",
"request"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L79-L105
|
12,394
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
serverConnectionConfirm
|
function serverConnectionConfirm(opt) {
var self = {
len : new type.UInt8(function() {
return new type.Component(self).size() - 1;
}),
code : new type.UInt8(MessageType.X224_TPDU_CONNECTION_CONFIRM, { constant : true }),
padding : new type.Component([new type.UInt16Le(), new type.UInt16Le(), new type.UInt8()]),
protocolNeg : negotiation({ optional : true })
};
return new type.Component(self, opt);
}
|
javascript
|
function serverConnectionConfirm(opt) {
var self = {
len : new type.UInt8(function() {
return new type.Component(self).size() - 1;
}),
code : new type.UInt8(MessageType.X224_TPDU_CONNECTION_CONFIRM, { constant : true }),
padding : new type.Component([new type.UInt16Le(), new type.UInt16Le(), new type.UInt8()]),
protocolNeg : negotiation({ optional : true })
};
return new type.Component(self, opt);
}
|
[
"function",
"serverConnectionConfirm",
"(",
"opt",
")",
"{",
"var",
"self",
"=",
"{",
"len",
":",
"new",
"type",
".",
"UInt8",
"(",
"function",
"(",
")",
"{",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
")",
".",
"size",
"(",
")",
"-",
"1",
";",
"}",
")",
",",
"code",
":",
"new",
"type",
".",
"UInt8",
"(",
"MessageType",
".",
"X224_TPDU_CONNECTION_CONFIRM",
",",
"{",
"constant",
":",
"true",
"}",
")",
",",
"padding",
":",
"new",
"type",
".",
"Component",
"(",
"[",
"new",
"type",
".",
"UInt16Le",
"(",
")",
",",
"new",
"type",
".",
"UInt16Le",
"(",
")",
",",
"new",
"type",
".",
"UInt8",
"(",
")",
"]",
")",
",",
"protocolNeg",
":",
"negotiation",
"(",
"{",
"optional",
":",
"true",
"}",
")",
"}",
";",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
",",
"opt",
")",
";",
"}"
] |
X224 Server connection confirm
@param opt {object} component type options
@see http://msdn.microsoft.com/en-us/library/cc240506.aspx
|
[
"X224",
"Server",
"connection",
"confirm"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L112-L123
|
12,395
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
x224DataHeader
|
function x224DataHeader() {
var self = {
header : new type.UInt8(2),
messageType : new type.UInt8(MessageType.X224_TPDU_DATA, { constant : true }),
separator : new type.UInt8(0x80, { constant : true })
};
return new type.Component(self);
}
|
javascript
|
function x224DataHeader() {
var self = {
header : new type.UInt8(2),
messageType : new type.UInt8(MessageType.X224_TPDU_DATA, { constant : true }),
separator : new type.UInt8(0x80, { constant : true })
};
return new type.Component(self);
}
|
[
"function",
"x224DataHeader",
"(",
")",
"{",
"var",
"self",
"=",
"{",
"header",
":",
"new",
"type",
".",
"UInt8",
"(",
"2",
")",
",",
"messageType",
":",
"new",
"type",
".",
"UInt8",
"(",
"MessageType",
".",
"X224_TPDU_DATA",
",",
"{",
"constant",
":",
"true",
"}",
")",
",",
"separator",
":",
"new",
"type",
".",
"UInt8",
"(",
"0x80",
",",
"{",
"constant",
":",
"true",
"}",
")",
"}",
";",
"return",
"new",
"type",
".",
"Component",
"(",
"self",
")",
";",
"}"
] |
Header of each data message from x224 layer
@returns {type.Component}
|
[
"Header",
"of",
"each",
"data",
"message",
"from",
"x224",
"layer"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L129-L136
|
12,396
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
X224
|
function X224(transport) {
this.transport = transport;
this.requestedProtocol = Protocols.PROTOCOL_SSL;
this.selectedProtocol = Protocols.PROTOCOL_SSL;
var self = this;
this.transport.on('close', function() {
self.emit('close');
}).on('error', function (err) {
self.emit('error', err);
});
}
|
javascript
|
function X224(transport) {
this.transport = transport;
this.requestedProtocol = Protocols.PROTOCOL_SSL;
this.selectedProtocol = Protocols.PROTOCOL_SSL;
var self = this;
this.transport.on('close', function() {
self.emit('close');
}).on('error', function (err) {
self.emit('error', err);
});
}
|
[
"function",
"X224",
"(",
"transport",
")",
"{",
"this",
".",
"transport",
"=",
"transport",
";",
"this",
".",
"requestedProtocol",
"=",
"Protocols",
".",
"PROTOCOL_SSL",
";",
"this",
".",
"selectedProtocol",
"=",
"Protocols",
".",
"PROTOCOL_SSL",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"transport",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'close'",
")",
";",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"}",
")",
";",
"}"
] |
Common X224 Automata
@param presentation {Layer} presentation layer
|
[
"Common",
"X224",
"Automata"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L142-L153
|
12,397
|
citronneur/node-rdpjs
|
lib/protocol/x224.js
|
Server
|
function Server(transport, keyFilePath, crtFilePath) {
X224.call(this, transport);
this.keyFilePath = keyFilePath;
this.crtFilePath = crtFilePath;
var self = this;
this.transport.once('data', function (s) {
self.recvConnectionRequest(s);
});
}
|
javascript
|
function Server(transport, keyFilePath, crtFilePath) {
X224.call(this, transport);
this.keyFilePath = keyFilePath;
this.crtFilePath = crtFilePath;
var self = this;
this.transport.once('data', function (s) {
self.recvConnectionRequest(s);
});
}
|
[
"function",
"Server",
"(",
"transport",
",",
"keyFilePath",
",",
"crtFilePath",
")",
"{",
"X224",
".",
"call",
"(",
"this",
",",
"transport",
")",
";",
"this",
".",
"keyFilePath",
"=",
"keyFilePath",
";",
"this",
".",
"crtFilePath",
"=",
"crtFilePath",
";",
"var",
"self",
"=",
"this",
";",
"this",
".",
"transport",
".",
"once",
"(",
"'data'",
",",
"function",
"(",
"s",
")",
"{",
"self",
".",
"recvConnectionRequest",
"(",
"s",
")",
";",
"}",
")",
";",
"}"
] |
Server x224 automata
|
[
"Server",
"x224",
"automata"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/x224.js#L256-L264
|
12,398
|
citronneur/node-rdpjs
|
lib/core/layer.js
|
BufferLayer
|
function BufferLayer(socket) {
//for ssl connection
this.securePair = null;
this.socket = socket;
var self = this;
// bind event
this.socket.on('data', function(data) {
try {
self.recv(data);
}
catch(e) {
self.socket.destroy();
self.emit('error', e);
}
}).on('close', function() {
self.emit('close');
}).on('error', function (err) {
self.emit('error', err);
});
//buffer data
this.buffers = [];
this.bufferLength = 0;
//expected size
this.expectedSize = 0;
}
|
javascript
|
function BufferLayer(socket) {
//for ssl connection
this.securePair = null;
this.socket = socket;
var self = this;
// bind event
this.socket.on('data', function(data) {
try {
self.recv(data);
}
catch(e) {
self.socket.destroy();
self.emit('error', e);
}
}).on('close', function() {
self.emit('close');
}).on('error', function (err) {
self.emit('error', err);
});
//buffer data
this.buffers = [];
this.bufferLength = 0;
//expected size
this.expectedSize = 0;
}
|
[
"function",
"BufferLayer",
"(",
"socket",
")",
"{",
"//for ssl connection",
"this",
".",
"securePair",
"=",
"null",
";",
"this",
".",
"socket",
"=",
"socket",
";",
"var",
"self",
"=",
"this",
";",
"// bind event",
"this",
".",
"socket",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"try",
"{",
"self",
".",
"recv",
"(",
"data",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"self",
".",
"socket",
".",
"destroy",
"(",
")",
";",
"self",
".",
"emit",
"(",
"'error'",
",",
"e",
")",
";",
"}",
"}",
")",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
")",
"{",
"self",
".",
"emit",
"(",
"'close'",
")",
";",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"}",
")",
";",
"//buffer data",
"this",
".",
"buffers",
"=",
"[",
"]",
";",
"this",
".",
"bufferLength",
"=",
"0",
";",
"//expected size",
"this",
".",
"expectedSize",
"=",
"0",
";",
"}"
] |
Buffer data from socket to present
well formed packets
|
[
"Buffer",
"data",
"from",
"socket",
"to",
"present",
"well",
"formed",
"packets"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/core/layer.js#L33-L59
|
12,399
|
citronneur/node-rdpjs
|
lib/protocol/t125/per.js
|
readObjectIdentifier
|
function readObjectIdentifier(s, oid) {
var size = readLength(s);
if(size !== 5) {
return false;
}
var a_oid = [0, 0, 0, 0, 0, 0];
var t12 = new type.UInt8().read(s).value;
a_oid[0] = t12 >> 4;
a_oid[1] = t12 & 0x0f;
a_oid[2] = new type.UInt8().read(s).value;
a_oid[3] = new type.UInt8().read(s).value;
a_oid[4] = new type.UInt8().read(s).value;
a_oid[5] = new type.UInt8().read(s).value;
for(var i in oid) {
if(oid[i] !== a_oid[i]) return false;
}
return true;
}
|
javascript
|
function readObjectIdentifier(s, oid) {
var size = readLength(s);
if(size !== 5) {
return false;
}
var a_oid = [0, 0, 0, 0, 0, 0];
var t12 = new type.UInt8().read(s).value;
a_oid[0] = t12 >> 4;
a_oid[1] = t12 & 0x0f;
a_oid[2] = new type.UInt8().read(s).value;
a_oid[3] = new type.UInt8().read(s).value;
a_oid[4] = new type.UInt8().read(s).value;
a_oid[5] = new type.UInt8().read(s).value;
for(var i in oid) {
if(oid[i] !== a_oid[i]) return false;
}
return true;
}
|
[
"function",
"readObjectIdentifier",
"(",
"s",
",",
"oid",
")",
"{",
"var",
"size",
"=",
"readLength",
"(",
"s",
")",
";",
"if",
"(",
"size",
"!==",
"5",
")",
"{",
"return",
"false",
";",
"}",
"var",
"a_oid",
"=",
"[",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
"]",
";",
"var",
"t12",
"=",
"new",
"type",
".",
"UInt8",
"(",
")",
".",
"read",
"(",
"s",
")",
".",
"value",
";",
"a_oid",
"[",
"0",
"]",
"=",
"t12",
">>",
"4",
";",
"a_oid",
"[",
"1",
"]",
"=",
"t12",
"&",
"0x0f",
";",
"a_oid",
"[",
"2",
"]",
"=",
"new",
"type",
".",
"UInt8",
"(",
")",
".",
"read",
"(",
"s",
")",
".",
"value",
";",
"a_oid",
"[",
"3",
"]",
"=",
"new",
"type",
".",
"UInt8",
"(",
")",
".",
"read",
"(",
"s",
")",
".",
"value",
";",
"a_oid",
"[",
"4",
"]",
"=",
"new",
"type",
".",
"UInt8",
"(",
")",
".",
"read",
"(",
"s",
")",
".",
"value",
";",
"a_oid",
"[",
"5",
"]",
"=",
"new",
"type",
".",
"UInt8",
"(",
")",
".",
"read",
"(",
"s",
")",
".",
"value",
";",
"for",
"(",
"var",
"i",
"in",
"oid",
")",
"{",
"if",
"(",
"oid",
"[",
"i",
"]",
"!==",
"a_oid",
"[",
"i",
"]",
")",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check object identifier
@param s {type.Stream}
@param oid {array} object identifier to check
|
[
"Check",
"object",
"identifier"
] |
0f487aa6c1f681bde6b416ca5b574e92f9184148
|
https://github.com/citronneur/node-rdpjs/blob/0f487aa6c1f681bde6b416ca5b574e92f9184148/lib/protocol/t125/per.js#L180-L200
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.