repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
primefaces/primeui-distribution | plugins/touchswipe.js | removeListeners | function removeListeners() {
$element.unbind(START_EV, touchStart);
$element.unbind(CANCEL_EV, touchCancel);
$element.unbind(MOVE_EV, touchMove);
$element.unbind(END_EV, touchEnd);
//we only have leave events on desktop, we manually calculate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.unbind(LEAVE_EV, touchLeave);
}
setTouchInProgress(false);
} | javascript | function removeListeners() {
$element.unbind(START_EV, touchStart);
$element.unbind(CANCEL_EV, touchCancel);
$element.unbind(MOVE_EV, touchMove);
$element.unbind(END_EV, touchEnd);
//we only have leave events on desktop, we manually calculate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.unbind(LEAVE_EV, touchLeave);
}
setTouchInProgress(false);
} | [
"function",
"removeListeners",
"(",
")",
"{",
"$element",
".",
"unbind",
"(",
"START_EV",
",",
"touchStart",
")",
";",
"$element",
".",
"unbind",
"(",
"CANCEL_EV",
",",
"touchCancel",
")",
";",
"$element",
".",
"unbind",
"(",
"MOVE_EV",
",",
"touchMove",
")",
";",
"$element",
".",
"unbind",
"(",
"END_EV",
",",
"touchEnd",
")",
";",
"if",
"(",
"LEAVE_EV",
")",
"{",
"$element",
".",
"unbind",
"(",
"LEAVE_EV",
",",
"touchLeave",
")",
";",
"}",
"setTouchInProgress",
"(",
"false",
")",
";",
"}"
] | Removes all listeners that were associated with the plugin
@inner | [
"Removes",
"all",
"listeners",
"that",
"were",
"associated",
"with",
"the",
"plugin"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L874-L886 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | getNextPhase | function getNextPhase(currentPhase) {
var nextPhase = currentPhase;
// Ensure we have valid swipe (under time and over distance and check if we are out of bound...)
var validTime = validateSwipeTime();
var validDistance = validateSwipeDistance();
var didCancel = didSwipeBackToCancel();
//If we have exceeded our time, then cancel
if(!validTime || didCancel) {
nextPhase = PHASE_CANCEL;
}
//Else if we are moving, and have reached distance then end
else if (validDistance && currentPhase == PHASE_MOVE && (!options.triggerOnTouchEnd || options.triggerOnTouchLeave) ) {
nextPhase = PHASE_END;
}
//Else if we have ended by leaving and didn't reach distance, then cancel
else if (!validDistance && currentPhase==PHASE_END && options.triggerOnTouchLeave) {
nextPhase = PHASE_CANCEL;
}
return nextPhase;
} | javascript | function getNextPhase(currentPhase) {
var nextPhase = currentPhase;
// Ensure we have valid swipe (under time and over distance and check if we are out of bound...)
var validTime = validateSwipeTime();
var validDistance = validateSwipeDistance();
var didCancel = didSwipeBackToCancel();
//If we have exceeded our time, then cancel
if(!validTime || didCancel) {
nextPhase = PHASE_CANCEL;
}
//Else if we are moving, and have reached distance then end
else if (validDistance && currentPhase == PHASE_MOVE && (!options.triggerOnTouchEnd || options.triggerOnTouchLeave) ) {
nextPhase = PHASE_END;
}
//Else if we have ended by leaving and didn't reach distance, then cancel
else if (!validDistance && currentPhase==PHASE_END && options.triggerOnTouchLeave) {
nextPhase = PHASE_CANCEL;
}
return nextPhase;
} | [
"function",
"getNextPhase",
"(",
"currentPhase",
")",
"{",
"var",
"nextPhase",
"=",
"currentPhase",
";",
"var",
"validTime",
"=",
"validateSwipeTime",
"(",
")",
";",
"var",
"validDistance",
"=",
"validateSwipeDistance",
"(",
")",
";",
"var",
"didCancel",
"=",
"didSwipeBackToCancel",
"(",
")",
";",
"if",
"(",
"!",
"validTime",
"||",
"didCancel",
")",
"{",
"nextPhase",
"=",
"PHASE_CANCEL",
";",
"}",
"else",
"if",
"(",
"validDistance",
"&&",
"currentPhase",
"==",
"PHASE_MOVE",
"&&",
"(",
"!",
"options",
".",
"triggerOnTouchEnd",
"||",
"options",
".",
"triggerOnTouchLeave",
")",
")",
"{",
"nextPhase",
"=",
"PHASE_END",
";",
"}",
"else",
"if",
"(",
"!",
"validDistance",
"&&",
"currentPhase",
"==",
"PHASE_END",
"&&",
"options",
".",
"triggerOnTouchLeave",
")",
"{",
"nextPhase",
"=",
"PHASE_CANCEL",
";",
"}",
"return",
"nextPhase",
";",
"}"
] | Checks if the time and distance thresholds have been met, and if so then the appropriate handlers are fired. | [
"Checks",
"if",
"the",
"time",
"and",
"distance",
"thresholds",
"have",
"been",
"met",
"and",
"if",
"so",
"then",
"the",
"appropriate",
"handlers",
"are",
"fired",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L892-L915 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | validateSwipeDistance | function validateSwipeDistance() {
var valid = true;
//If we made it past the min swipe distance..
if (options.threshold !== null) {
valid = distance >= options.threshold;
}
return valid;
} | javascript | function validateSwipeDistance() {
var valid = true;
//If we made it past the min swipe distance..
if (options.threshold !== null) {
valid = distance >= options.threshold;
}
return valid;
} | [
"function",
"validateSwipeDistance",
"(",
")",
"{",
"var",
"valid",
"=",
"true",
";",
"if",
"(",
"options",
".",
"threshold",
"!==",
"null",
")",
"{",
"valid",
"=",
"distance",
">=",
"options",
".",
"threshold",
";",
"}",
"return",
"valid",
";",
"}"
] | GESTURE VALIDATION
Checks the user has swipe far enough
@return Boolean if <code>threshold</code> has been set, return true if the threshold was met, else false.
If no threshold was set, then we return true.
@inner | [
"GESTURE",
"VALIDATION",
"Checks",
"the",
"user",
"has",
"swipe",
"far",
"enough"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1209-L1217 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | didSwipeBackToCancel | function didSwipeBackToCancel() {
var cancelled = false;
if(options.cancelThreshold !== null && direction !==null) {
cancelled = (getMaxDistance( direction ) - distance) >= options.cancelThreshold;
}
return cancelled;
} | javascript | function didSwipeBackToCancel() {
var cancelled = false;
if(options.cancelThreshold !== null && direction !==null) {
cancelled = (getMaxDistance( direction ) - distance) >= options.cancelThreshold;
}
return cancelled;
} | [
"function",
"didSwipeBackToCancel",
"(",
")",
"{",
"var",
"cancelled",
"=",
"false",
";",
"if",
"(",
"options",
".",
"cancelThreshold",
"!==",
"null",
"&&",
"direction",
"!==",
"null",
")",
"{",
"cancelled",
"=",
"(",
"getMaxDistance",
"(",
"direction",
")",
"-",
"distance",
")",
">=",
"options",
".",
"cancelThreshold",
";",
"}",
"return",
"cancelled",
";",
"}"
] | Checks the user has swiped back to cancel.
@return Boolean if <code>cancelThreshold</code> has been set, return true if the cancelThreshold was met, else false.
If no cancelThreshold was set, then we return true.
@inner | [
"Checks",
"the",
"user",
"has",
"swiped",
"back",
"to",
"cancel",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1225-L1232 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | validateDefaultEvent | function validateDefaultEvent(jqEvent, direction) {
//If we have no pinches, then do this
//If we have a pinch, and we we have 2 fingers or more down, then dont allow page scroll.
//If the option is set, allways allow the event to bubble up (let user handle wiredness)
if( options.preventDefaultEvents === false) {
return;
}
if (options.allowPageScroll === NONE) {
jqEvent.preventDefault();
} else {
var auto = options.allowPageScroll === AUTO;
switch (direction) {
case LEFT:
if ((options.swipeLeft && auto) || (!auto && options.allowPageScroll != HORIZONTAL)) {
jqEvent.preventDefault();
}
break;
case RIGHT:
if ((options.swipeRight && auto) || (!auto && options.allowPageScroll != HORIZONTAL)) {
jqEvent.preventDefault();
}
break;
case UP:
if ((options.swipeUp && auto) || (!auto && options.allowPageScroll != VERTICAL)) {
jqEvent.preventDefault();
}
break;
case DOWN:
if ((options.swipeDown && auto) || (!auto && options.allowPageScroll != VERTICAL)) {
jqEvent.preventDefault();
}
break;
}
}
} | javascript | function validateDefaultEvent(jqEvent, direction) {
//If we have no pinches, then do this
//If we have a pinch, and we we have 2 fingers or more down, then dont allow page scroll.
//If the option is set, allways allow the event to bubble up (let user handle wiredness)
if( options.preventDefaultEvents === false) {
return;
}
if (options.allowPageScroll === NONE) {
jqEvent.preventDefault();
} else {
var auto = options.allowPageScroll === AUTO;
switch (direction) {
case LEFT:
if ((options.swipeLeft && auto) || (!auto && options.allowPageScroll != HORIZONTAL)) {
jqEvent.preventDefault();
}
break;
case RIGHT:
if ((options.swipeRight && auto) || (!auto && options.allowPageScroll != HORIZONTAL)) {
jqEvent.preventDefault();
}
break;
case UP:
if ((options.swipeUp && auto) || (!auto && options.allowPageScroll != VERTICAL)) {
jqEvent.preventDefault();
}
break;
case DOWN:
if ((options.swipeDown && auto) || (!auto && options.allowPageScroll != VERTICAL)) {
jqEvent.preventDefault();
}
break;
}
}
} | [
"function",
"validateDefaultEvent",
"(",
"jqEvent",
",",
"direction",
")",
"{",
"if",
"(",
"options",
".",
"preventDefaultEvents",
"===",
"false",
")",
"{",
"return",
";",
"}",
"if",
"(",
"options",
".",
"allowPageScroll",
"===",
"NONE",
")",
"{",
"jqEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"else",
"{",
"var",
"auto",
"=",
"options",
".",
"allowPageScroll",
"===",
"AUTO",
";",
"switch",
"(",
"direction",
")",
"{",
"case",
"LEFT",
":",
"if",
"(",
"(",
"options",
".",
"swipeLeft",
"&&",
"auto",
")",
"||",
"(",
"!",
"auto",
"&&",
"options",
".",
"allowPageScroll",
"!=",
"HORIZONTAL",
")",
")",
"{",
"jqEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"break",
";",
"case",
"RIGHT",
":",
"if",
"(",
"(",
"options",
".",
"swipeRight",
"&&",
"auto",
")",
"||",
"(",
"!",
"auto",
"&&",
"options",
".",
"allowPageScroll",
"!=",
"HORIZONTAL",
")",
")",
"{",
"jqEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"break",
";",
"case",
"UP",
":",
"if",
"(",
"(",
"options",
".",
"swipeUp",
"&&",
"auto",
")",
"||",
"(",
"!",
"auto",
"&&",
"options",
".",
"allowPageScroll",
"!=",
"VERTICAL",
")",
")",
"{",
"jqEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"break",
";",
"case",
"DOWN",
":",
"if",
"(",
"(",
"options",
".",
"swipeDown",
"&&",
"auto",
")",
"||",
"(",
"!",
"auto",
"&&",
"options",
".",
"allowPageScroll",
"!=",
"VERTICAL",
")",
")",
"{",
"jqEvent",
".",
"preventDefault",
"(",
")",
";",
"}",
"break",
";",
"}",
"}",
"}"
] | Checks direction of the swipe and the value allowPageScroll to see if we should allow or prevent the default behaviour from occurring.
This will essentially allow page scrolling or not when the user is swiping on a touchSwipe object.
@param {object} jqEvent The normalised jQuery representation of the event object.
@param {string} direction The direction of the event. See {@link $.fn.swipe.directions}
@see $.fn.swipe.directions
@inner | [
"Checks",
"direction",
"of",
"the",
"swipe",
"and",
"the",
"value",
"allowPageScroll",
"to",
"see",
"if",
"we",
"should",
"allow",
"or",
"prevent",
"the",
"default",
"behaviour",
"from",
"occurring",
".",
"This",
"will",
"essentially",
"allow",
"page",
"scrolling",
"or",
"not",
"when",
"the",
"user",
"is",
"swiping",
"on",
"a",
"touchSwipe",
"object",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1280-L1322 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | validatePinch | function validatePinch() {
var hasCorrectFingerCount = validateFingers();
var hasEndPoint = validateEndPoint();
var hasCorrectDistance = validatePinchDistance();
return hasCorrectFingerCount && hasEndPoint && hasCorrectDistance;
} | javascript | function validatePinch() {
var hasCorrectFingerCount = validateFingers();
var hasEndPoint = validateEndPoint();
var hasCorrectDistance = validatePinchDistance();
return hasCorrectFingerCount && hasEndPoint && hasCorrectDistance;
} | [
"function",
"validatePinch",
"(",
")",
"{",
"var",
"hasCorrectFingerCount",
"=",
"validateFingers",
"(",
")",
";",
"var",
"hasEndPoint",
"=",
"validateEndPoint",
"(",
")",
";",
"var",
"hasCorrectDistance",
"=",
"validatePinchDistance",
"(",
")",
";",
"return",
"hasCorrectFingerCount",
"&&",
"hasEndPoint",
"&&",
"hasCorrectDistance",
";",
"}"
] | PINCHES
Returns true of the current pinch meets the thresholds
@return Boolean
@inner | [
"PINCHES",
"Returns",
"true",
"of",
"the",
"current",
"pinch",
"meets",
"the",
"thresholds"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1331-L1337 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | validateSwipe | function validateSwipe() {
//Check validity of swipe
var hasValidTime = validateSwipeTime();
var hasValidDistance = validateSwipeDistance();
var hasCorrectFingerCount = validateFingers();
var hasEndPoint = validateEndPoint();
var didCancel = didSwipeBackToCancel();
// if the user swiped more than the minimum length, perform the appropriate action
// hasValidDistance is null when no distance is set
var valid = !didCancel && hasEndPoint && hasCorrectFingerCount && hasValidDistance && hasValidTime;
return valid;
} | javascript | function validateSwipe() {
//Check validity of swipe
var hasValidTime = validateSwipeTime();
var hasValidDistance = validateSwipeDistance();
var hasCorrectFingerCount = validateFingers();
var hasEndPoint = validateEndPoint();
var didCancel = didSwipeBackToCancel();
// if the user swiped more than the minimum length, perform the appropriate action
// hasValidDistance is null when no distance is set
var valid = !didCancel && hasEndPoint && hasCorrectFingerCount && hasValidDistance && hasValidTime;
return valid;
} | [
"function",
"validateSwipe",
"(",
")",
"{",
"var",
"hasValidTime",
"=",
"validateSwipeTime",
"(",
")",
";",
"var",
"hasValidDistance",
"=",
"validateSwipeDistance",
"(",
")",
";",
"var",
"hasCorrectFingerCount",
"=",
"validateFingers",
"(",
")",
";",
"var",
"hasEndPoint",
"=",
"validateEndPoint",
"(",
")",
";",
"var",
"didCancel",
"=",
"didSwipeBackToCancel",
"(",
")",
";",
"var",
"valid",
"=",
"!",
"didCancel",
"&&",
"hasEndPoint",
"&&",
"hasCorrectFingerCount",
"&&",
"hasValidDistance",
"&&",
"hasValidTime",
";",
"return",
"valid",
";",
"}"
] | SWIPES
Returns true if the current swipe meets the thresholds
@return Boolean
@inner | [
"SWIPES",
"Returns",
"true",
"if",
"the",
"current",
"swipe",
"meets",
"the",
"thresholds"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1368-L1381 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | hasSwipes | function hasSwipes() {
//Enure we dont return 0 or null for false values
return !!(options.swipe || options.swipeStatus || options.swipeLeft || options.swipeRight || options.swipeUp || options.swipeDown);
} | javascript | function hasSwipes() {
//Enure we dont return 0 or null for false values
return !!(options.swipe || options.swipeStatus || options.swipeLeft || options.swipeRight || options.swipeUp || options.swipeDown);
} | [
"function",
"hasSwipes",
"(",
")",
"{",
"return",
"!",
"!",
"(",
"options",
".",
"swipe",
"||",
"options",
".",
"swipeStatus",
"||",
"options",
".",
"swipeLeft",
"||",
"options",
".",
"swipeRight",
"||",
"options",
".",
"swipeUp",
"||",
"options",
".",
"swipeDown",
")",
";",
"}"
] | Returns true if any Swipe events have been registered
@return Boolean
@inner | [
"Returns",
"true",
"if",
"any",
"Swipe",
"events",
"have",
"been",
"registered"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1388-L1391 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | validateDoubleTap | function validateDoubleTap() {
if(doubleTapStartTime==null){
return false;
}
var now = getTimeStamp();
return (hasDoubleTap() && ((now-doubleTapStartTime) <= options.doubleTapThreshold));
} | javascript | function validateDoubleTap() {
if(doubleTapStartTime==null){
return false;
}
var now = getTimeStamp();
return (hasDoubleTap() && ((now-doubleTapStartTime) <= options.doubleTapThreshold));
} | [
"function",
"validateDoubleTap",
"(",
")",
"{",
"if",
"(",
"doubleTapStartTime",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"var",
"now",
"=",
"getTimeStamp",
"(",
")",
";",
"return",
"(",
"hasDoubleTap",
"(",
")",
"&&",
"(",
"(",
"now",
"-",
"doubleTapStartTime",
")",
"<=",
"options",
".",
"doubleTapThreshold",
")",
")",
";",
"}"
] | Returns true if we could be in the process of a double tap (one tap has occurred, we are listening for double taps, and the threshold hasn't past.
@return Boolean
@inner | [
"Returns",
"true",
"if",
"we",
"could",
"be",
"in",
"the",
"process",
"of",
"a",
"double",
"tap",
"(",
"one",
"tap",
"has",
"occurred",
"we",
"are",
"listening",
"for",
"double",
"taps",
"and",
"the",
"threshold",
"hasn",
"t",
"past",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1460-L1466 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | inMultiFingerRelease | function inMultiFingerRelease() {
var withinThreshold = false;
if(previousTouchEndTime) {
var diff = getTimeStamp() - previousTouchEndTime
if( diff<=options.fingerReleaseThreshold ) {
withinThreshold = true;
}
}
return withinThreshold;
} | javascript | function inMultiFingerRelease() {
var withinThreshold = false;
if(previousTouchEndTime) {
var diff = getTimeStamp() - previousTouchEndTime
if( diff<=options.fingerReleaseThreshold ) {
withinThreshold = true;
}
}
return withinThreshold;
} | [
"function",
"inMultiFingerRelease",
"(",
")",
"{",
"var",
"withinThreshold",
"=",
"false",
";",
"if",
"(",
"previousTouchEndTime",
")",
"{",
"var",
"diff",
"=",
"getTimeStamp",
"(",
")",
"-",
"previousTouchEndTime",
"if",
"(",
"diff",
"<=",
"options",
".",
"fingerReleaseThreshold",
")",
"{",
"withinThreshold",
"=",
"true",
";",
"}",
"}",
"return",
"withinThreshold",
";",
"}"
] | Checks if we are in the threshold between 2 fingers being released
@return Boolean
@inner | [
"Checks",
"if",
"we",
"are",
"in",
"the",
"threshold",
"between",
"2",
"fingers",
"being",
"released"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1555-L1567 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | setTouchInProgress | function setTouchInProgress(val) {
//Add or remove event listeners depending on touch status
if(val===true) {
$element.bind(MOVE_EV, touchMove);
$element.bind(END_EV, touchEnd);
//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.bind(LEAVE_EV, touchLeave);
}
} else {
$element.unbind(MOVE_EV, touchMove, false);
$element.unbind(END_EV, touchEnd, false);
//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.unbind(LEAVE_EV, touchLeave, false);
}
}
//strict equality to ensure only true and false can update the value
$element.data(PLUGIN_NS+'_intouch', val === true);
} | javascript | function setTouchInProgress(val) {
//Add or remove event listeners depending on touch status
if(val===true) {
$element.bind(MOVE_EV, touchMove);
$element.bind(END_EV, touchEnd);
//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.bind(LEAVE_EV, touchLeave);
}
} else {
$element.unbind(MOVE_EV, touchMove, false);
$element.unbind(END_EV, touchEnd, false);
//we only have leave events on desktop, we manually calcuate leave on touch as its not supported in webkit
if(LEAVE_EV) {
$element.unbind(LEAVE_EV, touchLeave, false);
}
}
//strict equality to ensure only true and false can update the value
$element.data(PLUGIN_NS+'_intouch', val === true);
} | [
"function",
"setTouchInProgress",
"(",
"val",
")",
"{",
"if",
"(",
"val",
"===",
"true",
")",
"{",
"$element",
".",
"bind",
"(",
"MOVE_EV",
",",
"touchMove",
")",
";",
"$element",
".",
"bind",
"(",
"END_EV",
",",
"touchEnd",
")",
";",
"if",
"(",
"LEAVE_EV",
")",
"{",
"$element",
".",
"bind",
"(",
"LEAVE_EV",
",",
"touchLeave",
")",
";",
"}",
"}",
"else",
"{",
"$element",
".",
"unbind",
"(",
"MOVE_EV",
",",
"touchMove",
",",
"false",
")",
";",
"$element",
".",
"unbind",
"(",
"END_EV",
",",
"touchEnd",
",",
"false",
")",
";",
"if",
"(",
"LEAVE_EV",
")",
"{",
"$element",
".",
"unbind",
"(",
"LEAVE_EV",
",",
"touchLeave",
",",
"false",
")",
";",
"}",
"}",
"$element",
".",
"data",
"(",
"PLUGIN_NS",
"+",
"'_intouch'",
",",
"val",
"===",
"true",
")",
";",
"}"
] | Sets a data flag to indicate that a touch is in progress
@param {boolean} val The value to set the property to
@inner | [
"Sets",
"a",
"data",
"flag",
"to",
"indicate",
"that",
"a",
"touch",
"is",
"in",
"progress"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1585-L1609 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | updateFingerData | function updateFingerData(evt) {
var id = evt.identifier!==undefined ? evt.identifier : 0;
var f = getFingerData( id );
f.end.x = evt.pageX||evt.clientX;
f.end.y = evt.pageY||evt.clientY;
return f;
} | javascript | function updateFingerData(evt) {
var id = evt.identifier!==undefined ? evt.identifier : 0;
var f = getFingerData( id );
f.end.x = evt.pageX||evt.clientX;
f.end.y = evt.pageY||evt.clientY;
return f;
} | [
"function",
"updateFingerData",
"(",
"evt",
")",
"{",
"var",
"id",
"=",
"evt",
".",
"identifier",
"!==",
"undefined",
"?",
"evt",
".",
"identifier",
":",
"0",
";",
"var",
"f",
"=",
"getFingerData",
"(",
"id",
")",
";",
"f",
".",
"end",
".",
"x",
"=",
"evt",
".",
"pageX",
"||",
"evt",
".",
"clientX",
";",
"f",
".",
"end",
".",
"y",
"=",
"evt",
".",
"pageY",
"||",
"evt",
".",
"clientY",
";",
"return",
"f",
";",
"}"
] | Updates the finger data for a particular event object
@param {object} evt The event object containing the touch/finger data to upadte
@return a finger data object.
@inner | [
"Updates",
"the",
"finger",
"data",
"for",
"a",
"particular",
"event",
"object"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1635-L1644 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | getFingerData | function getFingerData( id ) {
for(var i=0; i<fingerData.length; i++) {
if(fingerData[i].identifier == id) {
return fingerData[i];
}
}
} | javascript | function getFingerData( id ) {
for(var i=0; i<fingerData.length; i++) {
if(fingerData[i].identifier == id) {
return fingerData[i];
}
}
} | [
"function",
"getFingerData",
"(",
"id",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"fingerData",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"fingerData",
"[",
"i",
"]",
".",
"identifier",
"==",
"id",
")",
"{",
"return",
"fingerData",
"[",
"i",
"]",
";",
"}",
"}",
"}"
] | Returns a finger data object by its event ID.
Each touch event has an identifier property, which is used
to track repeat touches
@param {int} id The unique id of the finger in the sequence of touch events.
@return a finger data object.
@inner | [
"Returns",
"a",
"finger",
"data",
"object",
"by",
"its",
"event",
"ID",
".",
"Each",
"touch",
"event",
"has",
"an",
"identifier",
"property",
"which",
"is",
"used",
"to",
"track",
"repeat",
"touches"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1654-L1660 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | createAllFingerData | function createAllFingerData() {
var fingerData=[];
for (var i=0; i<=5; i++) {
fingerData.push({
start:{ x: 0, y: 0 },
end:{ x: 0, y: 0 },
identifier:0
});
}
return fingerData;
} | javascript | function createAllFingerData() {
var fingerData=[];
for (var i=0; i<=5; i++) {
fingerData.push({
start:{ x: 0, y: 0 },
end:{ x: 0, y: 0 },
identifier:0
});
}
return fingerData;
} | [
"function",
"createAllFingerData",
"(",
")",
"{",
"var",
"fingerData",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<=",
"5",
";",
"i",
"++",
")",
"{",
"fingerData",
".",
"push",
"(",
"{",
"start",
":",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
",",
"end",
":",
"{",
"x",
":",
"0",
",",
"y",
":",
"0",
"}",
",",
"identifier",
":",
"0",
"}",
")",
";",
"}",
"return",
"fingerData",
";",
"}"
] | Creats all the finger onjects and returns an array of finger data
@return Array of finger objects
@inner | [
"Creats",
"all",
"the",
"finger",
"onjects",
"and",
"returns",
"an",
"array",
"of",
"finger",
"data"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1667-L1678 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | setMaxDistance | function setMaxDistance(direction, distance) {
distance = Math.max(distance, getMaxDistance(direction) );
maximumsMap[direction].distance = distance;
} | javascript | function setMaxDistance(direction, distance) {
distance = Math.max(distance, getMaxDistance(direction) );
maximumsMap[direction].distance = distance;
} | [
"function",
"setMaxDistance",
"(",
"direction",
",",
"distance",
")",
"{",
"distance",
"=",
"Math",
".",
"max",
"(",
"distance",
",",
"getMaxDistance",
"(",
"direction",
")",
")",
";",
"maximumsMap",
"[",
"direction",
"]",
".",
"distance",
"=",
"distance",
";",
"}"
] | Sets the maximum distance swiped in the given direction.
If the new value is lower than the current value, the max value is not changed.
@param {string} direction The direction of the swipe
@param {int} distance The distance of the swipe
@inner | [
"Sets",
"the",
"maximum",
"distance",
"swiped",
"in",
"the",
"given",
"direction",
".",
"If",
"the",
"new",
"value",
"is",
"lower",
"than",
"the",
"current",
"value",
"the",
"max",
"value",
"is",
"not",
"changed",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1687-L1690 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | createMaximumsData | function createMaximumsData() {
var maxData={};
maxData[LEFT]=createMaximumVO(LEFT);
maxData[RIGHT]=createMaximumVO(RIGHT);
maxData[UP]=createMaximumVO(UP);
maxData[DOWN]=createMaximumVO(DOWN);
return maxData;
} | javascript | function createMaximumsData() {
var maxData={};
maxData[LEFT]=createMaximumVO(LEFT);
maxData[RIGHT]=createMaximumVO(RIGHT);
maxData[UP]=createMaximumVO(UP);
maxData[DOWN]=createMaximumVO(DOWN);
return maxData;
} | [
"function",
"createMaximumsData",
"(",
")",
"{",
"var",
"maxData",
"=",
"{",
"}",
";",
"maxData",
"[",
"LEFT",
"]",
"=",
"createMaximumVO",
"(",
"LEFT",
")",
";",
"maxData",
"[",
"RIGHT",
"]",
"=",
"createMaximumVO",
"(",
"RIGHT",
")",
";",
"maxData",
"[",
"UP",
"]",
"=",
"createMaximumVO",
"(",
"UP",
")",
";",
"maxData",
"[",
"DOWN",
"]",
"=",
"createMaximumVO",
"(",
"DOWN",
")",
";",
"return",
"maxData",
";",
"}"
] | Creats a map of directions to maximum swiped values.
@return Object A dictionary of maximum values, indexed by direction.
@inner | [
"Creats",
"a",
"map",
"of",
"directions",
"to",
"maximum",
"swiped",
"values",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1708-L1716 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | calculateAngle | function calculateAngle(startPoint, endPoint) {
var x = startPoint.x - endPoint.x;
var y = endPoint.y - startPoint.y;
var r = Math.atan2(y, x); //radians
var angle = Math.round(r * 180 / Math.PI); //degrees
//ensure value is positive
if (angle < 0) {
angle = 360 - Math.abs(angle);
}
return angle;
} | javascript | function calculateAngle(startPoint, endPoint) {
var x = startPoint.x - endPoint.x;
var y = endPoint.y - startPoint.y;
var r = Math.atan2(y, x); //radians
var angle = Math.round(r * 180 / Math.PI); //degrees
//ensure value is positive
if (angle < 0) {
angle = 360 - Math.abs(angle);
}
return angle;
} | [
"function",
"calculateAngle",
"(",
"startPoint",
",",
"endPoint",
")",
"{",
"var",
"x",
"=",
"startPoint",
".",
"x",
"-",
"endPoint",
".",
"x",
";",
"var",
"y",
"=",
"endPoint",
".",
"y",
"-",
"startPoint",
".",
"y",
";",
"var",
"r",
"=",
"Math",
".",
"atan2",
"(",
"y",
",",
"x",
")",
";",
"var",
"angle",
"=",
"Math",
".",
"round",
"(",
"r",
"*",
"180",
"/",
"Math",
".",
"PI",
")",
";",
"if",
"(",
"angle",
"<",
"0",
")",
"{",
"angle",
"=",
"360",
"-",
"Math",
".",
"abs",
"(",
"angle",
")",
";",
"}",
"return",
"angle",
";",
"}"
] | Calculate the angle of the swipe
@param {point} startPoint A point object containing x and y co-ordinates
@param {point} endPoint A point object containing x and y co-ordinates
@return int
@inner | [
"Calculate",
"the",
"angle",
"of",
"the",
"swipe"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1806-L1818 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | calculateDirection | function calculateDirection(startPoint, endPoint ) {
var angle = calculateAngle(startPoint, endPoint);
if ((angle <= 45) && (angle >= 0)) {
return LEFT;
} else if ((angle <= 360) && (angle >= 315)) {
return LEFT;
} else if ((angle >= 135) && (angle <= 225)) {
return RIGHT;
} else if ((angle > 45) && (angle < 135)) {
return DOWN;
} else {
return UP;
}
} | javascript | function calculateDirection(startPoint, endPoint ) {
var angle = calculateAngle(startPoint, endPoint);
if ((angle <= 45) && (angle >= 0)) {
return LEFT;
} else if ((angle <= 360) && (angle >= 315)) {
return LEFT;
} else if ((angle >= 135) && (angle <= 225)) {
return RIGHT;
} else if ((angle > 45) && (angle < 135)) {
return DOWN;
} else {
return UP;
}
} | [
"function",
"calculateDirection",
"(",
"startPoint",
",",
"endPoint",
")",
"{",
"var",
"angle",
"=",
"calculateAngle",
"(",
"startPoint",
",",
"endPoint",
")",
";",
"if",
"(",
"(",
"angle",
"<=",
"45",
")",
"&&",
"(",
"angle",
">=",
"0",
")",
")",
"{",
"return",
"LEFT",
";",
"}",
"else",
"if",
"(",
"(",
"angle",
"<=",
"360",
")",
"&&",
"(",
"angle",
">=",
"315",
")",
")",
"{",
"return",
"LEFT",
";",
"}",
"else",
"if",
"(",
"(",
"angle",
">=",
"135",
")",
"&&",
"(",
"angle",
"<=",
"225",
")",
")",
"{",
"return",
"RIGHT",
";",
"}",
"else",
"if",
"(",
"(",
"angle",
">",
"45",
")",
"&&",
"(",
"angle",
"<",
"135",
")",
")",
"{",
"return",
"DOWN",
";",
"}",
"else",
"{",
"return",
"UP",
";",
"}",
"}"
] | Calculate the direction of the swipe
This will also call calculateAngle to get the latest angle of swipe
@param {point} startPoint A point object containing x and y co-ordinates
@param {point} endPoint A point object containing x and y co-ordinates
@return string Either {@link $.fn.swipe.directions.LEFT} / {@link $.fn.swipe.directions.RIGHT} / {@link $.fn.swipe.directions.DOWN} / {@link $.fn.swipe.directions.UP}
@see $.fn.swipe.directions
@inner | [
"Calculate",
"the",
"direction",
"of",
"the",
"swipe",
"This",
"will",
"also",
"call",
"calculateAngle",
"to",
"get",
"the",
"latest",
"angle",
"of",
"swipe"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1829-L1843 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | getbounds | function getbounds( el ) {
el = $(el);
var offset = el.offset();
var bounds = {
left:offset.left,
right:offset.left+el.outerWidth(),
top:offset.top,
bottom:offset.top+el.outerHeight()
}
return bounds;
} | javascript | function getbounds( el ) {
el = $(el);
var offset = el.offset();
var bounds = {
left:offset.left,
right:offset.left+el.outerWidth(),
top:offset.top,
bottom:offset.top+el.outerHeight()
}
return bounds;
} | [
"function",
"getbounds",
"(",
"el",
")",
"{",
"el",
"=",
"$",
"(",
"el",
")",
";",
"var",
"offset",
"=",
"el",
".",
"offset",
"(",
")",
";",
"var",
"bounds",
"=",
"{",
"left",
":",
"offset",
".",
"left",
",",
"right",
":",
"offset",
".",
"left",
"+",
"el",
".",
"outerWidth",
"(",
")",
",",
"top",
":",
"offset",
".",
"top",
",",
"bottom",
":",
"offset",
".",
"top",
"+",
"el",
".",
"outerHeight",
"(",
")",
"}",
"return",
"bounds",
";",
"}"
] | Returns a bounds object with left, right, top and bottom properties for the element specified.
@param {DomNode} The DOM node to get the bounds for. | [
"Returns",
"a",
"bounds",
"object",
"with",
"left",
"right",
"top",
"and",
"bottom",
"properties",
"for",
"the",
"element",
"specified",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1862-L1874 | train |
primefaces/primeui-distribution | plugins/touchswipe.js | isInBounds | function isInBounds(point, bounds) {
return (point.x > bounds.left && point.x < bounds.right && point.y > bounds.top && point.y < bounds.bottom);
} | javascript | function isInBounds(point, bounds) {
return (point.x > bounds.left && point.x < bounds.right && point.y > bounds.top && point.y < bounds.bottom);
} | [
"function",
"isInBounds",
"(",
"point",
",",
"bounds",
")",
"{",
"return",
"(",
"point",
".",
"x",
">",
"bounds",
".",
"left",
"&&",
"point",
".",
"x",
"<",
"bounds",
".",
"right",
"&&",
"point",
".",
"y",
">",
"bounds",
".",
"top",
"&&",
"point",
".",
"y",
"<",
"bounds",
".",
"bottom",
")",
";",
"}"
] | Checks if the point object is in the bounds object.
@param {object} point A point object.
@param {int} point.x The x value of the point.
@param {int} point.y The x value of the point.
@param {object} bounds The bounds object to test
@param {int} bounds.left The leftmost value
@param {int} bounds.right The righttmost value
@param {int} bounds.top The topmost value
@param {int} bounds.bottom The bottommost value | [
"Checks",
"if",
"the",
"point",
"object",
"is",
"in",
"the",
"bounds",
"object",
"."
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/touchswipe.js#L1888-L1890 | train |
primefaces/primeui-distribution | primeui-all.js | delayEvent | function delayEvent( type, instance, container ) {
return function( event ) {
container._trigger( type, event, instance._uiHash( instance ) );
};
} | javascript | function delayEvent( type, instance, container ) {
return function( event ) {
container._trigger( type, event, instance._uiHash( instance ) );
};
} | [
"function",
"delayEvent",
"(",
"type",
",",
"instance",
",",
"container",
")",
"{",
"return",
"function",
"(",
"event",
")",
"{",
"container",
".",
"_trigger",
"(",
"type",
",",
"event",
",",
"instance",
".",
"_uiHash",
"(",
"instance",
")",
")",
";",
"}",
";",
"}"
] | Post events to containers | [
"Post",
"events",
"to",
"containers"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L15530-L15534 | train |
primefaces/primeui-distribution | primeui-all.js | function (f, s, o) {
// pattern for standard and localized AM/PM markers
var getPatternAmpm = function (amNames, pmNames) {
var markers = [];
if (amNames) {
$.merge(markers, amNames);
}
if (pmNames) {
$.merge(markers, pmNames);
}
markers = $.map(markers, function (val) {
return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
});
return '(' + markers.join('|') + ')?';
};
// figure out position of time elements.. cause js cant do named captures
var getFormatPositions = function (timeFormat) {
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
orders = {
h: -1,
m: -1,
s: -1,
l: -1,
c: -1,
t: -1,
z: -1
};
if (finds) {
for (var i = 0; i < finds.length; i++) {
if (orders[finds[i].toString().charAt(0)] === -1) {
orders[finds[i].toString().charAt(0)] = i + 1;
}
}
}
return orders;
};
var regstr = '^' + f.toString()
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
var ml = match.length;
switch (match.charAt(0).toLowerCase()) {
case 'h':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 'm':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 's':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 'l':
return '(\\d?\\d?\\d)';
case 'c':
return '(\\d?\\d?\\d)';
case 'z':
return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
case 't':
return getPatternAmpm(o.amNames, o.pmNames);
default: // literal escaped in quotes
return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
}
})
.replace(/\s/g, '\\s?') +
o.timeSuffix + '$',
order = getFormatPositions(f),
ampm = '',
treg;
treg = s.match(new RegExp(regstr, 'i'));
var resTime = {
hour: 0,
minute: 0,
second: 0,
millisec: 0,
microsec: 0
};
if (treg) {
if (order.t !== -1) {
if (treg[order.t] === undefined || treg[order.t].length === 0) {
ampm = '';
resTime.ampm = '';
} else {
ampm = $.inArray(treg[order.t].toUpperCase(), $.map(o.amNames, function (x,i) { return x.toUpperCase(); })) !== -1 ? 'AM' : 'PM';
resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0];
}
}
if (order.h !== -1) {
if (ampm === 'AM' && treg[order.h] === '12') {
resTime.hour = 0; // 12am = 0 hour
} else {
if (ampm === 'PM' && treg[order.h] !== '12') {
resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
} else {
resTime.hour = Number(treg[order.h]);
}
}
}
if (order.m !== -1) {
resTime.minute = Number(treg[order.m]);
}
if (order.s !== -1) {
resTime.second = Number(treg[order.s]);
}
if (order.l !== -1) {
resTime.millisec = Number(treg[order.l]);
}
if (order.c !== -1) {
resTime.microsec = Number(treg[order.c]);
}
if (order.z !== -1 && treg[order.z] !== undefined) {
resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]);
}
return resTime;
}
return false;
} | javascript | function (f, s, o) {
// pattern for standard and localized AM/PM markers
var getPatternAmpm = function (amNames, pmNames) {
var markers = [];
if (amNames) {
$.merge(markers, amNames);
}
if (pmNames) {
$.merge(markers, pmNames);
}
markers = $.map(markers, function (val) {
return val.replace(/[.*+?|()\[\]{}\\]/g, '\\$&');
});
return '(' + markers.join('|') + ')?';
};
// figure out position of time elements.. cause js cant do named captures
var getFormatPositions = function (timeFormat) {
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
orders = {
h: -1,
m: -1,
s: -1,
l: -1,
c: -1,
t: -1,
z: -1
};
if (finds) {
for (var i = 0; i < finds.length; i++) {
if (orders[finds[i].toString().charAt(0)] === -1) {
orders[finds[i].toString().charAt(0)] = i + 1;
}
}
}
return orders;
};
var regstr = '^' + f.toString()
.replace(/([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')/g, function (match) {
var ml = match.length;
switch (match.charAt(0).toLowerCase()) {
case 'h':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 'm':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 's':
return ml === 1 ? '(\\d?\\d)' : '(\\d{' + ml + '})';
case 'l':
return '(\\d?\\d?\\d)';
case 'c':
return '(\\d?\\d?\\d)';
case 'z':
return '(z|[-+]\\d\\d:?\\d\\d|\\S+)?';
case 't':
return getPatternAmpm(o.amNames, o.pmNames);
default: // literal escaped in quotes
return '(' + match.replace(/\'/g, "").replace(/(\.|\$|\^|\\|\/|\(|\)|\[|\]|\?|\+|\*)/g, function (m) { return "\\" + m; }) + ')?';
}
})
.replace(/\s/g, '\\s?') +
o.timeSuffix + '$',
order = getFormatPositions(f),
ampm = '',
treg;
treg = s.match(new RegExp(regstr, 'i'));
var resTime = {
hour: 0,
minute: 0,
second: 0,
millisec: 0,
microsec: 0
};
if (treg) {
if (order.t !== -1) {
if (treg[order.t] === undefined || treg[order.t].length === 0) {
ampm = '';
resTime.ampm = '';
} else {
ampm = $.inArray(treg[order.t].toUpperCase(), $.map(o.amNames, function (x,i) { return x.toUpperCase(); })) !== -1 ? 'AM' : 'PM';
resTime.ampm = o[ampm === 'AM' ? 'amNames' : 'pmNames'][0];
}
}
if (order.h !== -1) {
if (ampm === 'AM' && treg[order.h] === '12') {
resTime.hour = 0; // 12am = 0 hour
} else {
if (ampm === 'PM' && treg[order.h] !== '12') {
resTime.hour = parseInt(treg[order.h], 10) + 12; // 12pm = 12 hour, any other pm = hour + 12
} else {
resTime.hour = Number(treg[order.h]);
}
}
}
if (order.m !== -1) {
resTime.minute = Number(treg[order.m]);
}
if (order.s !== -1) {
resTime.second = Number(treg[order.s]);
}
if (order.l !== -1) {
resTime.millisec = Number(treg[order.l]);
}
if (order.c !== -1) {
resTime.microsec = Number(treg[order.c]);
}
if (order.z !== -1 && treg[order.z] !== undefined) {
resTime.timezone = $.timepicker.timezoneOffsetNumber(treg[order.z]);
}
return resTime;
}
return false;
} | [
"function",
"(",
"f",
",",
"s",
",",
"o",
")",
"{",
"var",
"getPatternAmpm",
"=",
"function",
"(",
"amNames",
",",
"pmNames",
")",
"{",
"var",
"markers",
"=",
"[",
"]",
";",
"if",
"(",
"amNames",
")",
"{",
"$",
".",
"merge",
"(",
"markers",
",",
"amNames",
")",
";",
"}",
"if",
"(",
"pmNames",
")",
"{",
"$",
".",
"merge",
"(",
"markers",
",",
"pmNames",
")",
";",
"}",
"markers",
"=",
"$",
".",
"map",
"(",
"markers",
",",
"function",
"(",
"val",
")",
"{",
"return",
"val",
".",
"replace",
"(",
"/",
"[.*+?|()\\[\\]{}\\\\]",
"/",
"g",
",",
"'\\\\$&'",
")",
";",
"}",
")",
";",
"\\\\",
"}",
";",
"return",
"'('",
"+",
"markers",
".",
"join",
"(",
"'|'",
")",
"+",
"')?'",
";",
"var",
"getFormatPositions",
"=",
"function",
"(",
"timeFormat",
")",
"{",
"var",
"finds",
"=",
"timeFormat",
".",
"toLowerCase",
"(",
")",
".",
"match",
"(",
"/",
"(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')",
"/",
"g",
")",
",",
"orders",
"=",
"{",
"h",
":",
"-",
"1",
",",
"m",
":",
"-",
"1",
",",
"s",
":",
"-",
"1",
",",
"l",
":",
"-",
"1",
",",
"c",
":",
"-",
"1",
",",
"t",
":",
"-",
"1",
",",
"z",
":",
"-",
"1",
"}",
";",
"if",
"(",
"finds",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"finds",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"orders",
"[",
"finds",
"[",
"i",
"]",
".",
"toString",
"(",
")",
".",
"charAt",
"(",
"0",
")",
"]",
"===",
"-",
"1",
")",
"{",
"orders",
"[",
"finds",
"[",
"i",
"]",
".",
"toString",
"(",
")",
".",
"charAt",
"(",
"0",
")",
"]",
"=",
"i",
"+",
"1",
";",
"}",
"}",
"}",
"return",
"orders",
";",
"}",
";",
"var",
"regstr",
"=",
"'^'",
"+",
"f",
".",
"toString",
"(",
")",
".",
"replace",
"(",
"/",
"([hH]{1,2}|mm?|ss?|[tT]{1,2}|[zZ]|[lc]|'.*?')",
"/",
"g",
",",
"function",
"(",
"match",
")",
"{",
"var",
"ml",
"=",
"match",
".",
"length",
";",
"switch",
"(",
"match",
".",
"charAt",
"(",
"0",
")",
".",
"toLowerCase",
"(",
")",
")",
"{",
"case",
"'h'",
":",
"return",
"ml",
"===",
"1",
"?",
"'(\\\\d?\\\\d)'",
":",
"\\\\",
";",
"\\\\",
"'(\\\\d{'",
"+",
"\\\\",
"+",
"ml",
"'})'",
"case",
"'m'",
":",
"return",
"ml",
"===",
"1",
"?",
"'(\\\\d?\\\\d)'",
":",
"\\\\",
";",
"\\\\",
"'(\\\\d{'",
"+",
"\\\\",
"+",
"ml",
"'})'",
"}",
"}",
")",
".",
"case",
"'s'",
":",
"return",
"ml",
"===",
"1",
"?",
"'(\\\\d?\\\\d)'",
":",
"\\\\",
";",
"\\\\",
"+",
"'(\\\\d{'",
"+",
"\\\\",
"+",
"ml",
"+",
"'})'",
",",
"case",
"'l'",
":",
"return",
"'(\\\\d?\\\\d?\\\\d)'",
";",
",",
"\\\\",
",",
"\\\\",
";",
"\\\\",
"case",
"'c'",
":",
"return",
"'(\\\\d?\\\\d?\\\\d)'",
";",
"\\\\",
"}"
] | Strict parse requires the timeString to match the timeFormat exactly | [
"Strict",
"parse",
"requires",
"the",
"timeString",
"to",
"match",
"the",
"timeFormat",
"exactly"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L21988-L22109 | train |
|
primefaces/primeui-distribution | primeui-all.js | function (timeFormat) {
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
orders = {
h: -1,
m: -1,
s: -1,
l: -1,
c: -1,
t: -1,
z: -1
};
if (finds) {
for (var i = 0; i < finds.length; i++) {
if (orders[finds[i].toString().charAt(0)] === -1) {
orders[finds[i].toString().charAt(0)] = i + 1;
}
}
}
return orders;
} | javascript | function (timeFormat) {
var finds = timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')/g),
orders = {
h: -1,
m: -1,
s: -1,
l: -1,
c: -1,
t: -1,
z: -1
};
if (finds) {
for (var i = 0; i < finds.length; i++) {
if (orders[finds[i].toString().charAt(0)] === -1) {
orders[finds[i].toString().charAt(0)] = i + 1;
}
}
}
return orders;
} | [
"function",
"(",
"timeFormat",
")",
"{",
"var",
"finds",
"=",
"timeFormat",
".",
"toLowerCase",
"(",
")",
".",
"match",
"(",
"/",
"(h{1,2}|m{1,2}|s{1,2}|l{1}|c{1}|t{1,2}|z|'.*?')",
"/",
"g",
")",
",",
"orders",
"=",
"{",
"h",
":",
"-",
"1",
",",
"m",
":",
"-",
"1",
",",
"s",
":",
"-",
"1",
",",
"l",
":",
"-",
"1",
",",
"c",
":",
"-",
"1",
",",
"t",
":",
"-",
"1",
",",
"z",
":",
"-",
"1",
"}",
";",
"if",
"(",
"finds",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"finds",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"orders",
"[",
"finds",
"[",
"i",
"]",
".",
"toString",
"(",
")",
".",
"charAt",
"(",
"0",
")",
"]",
"===",
"-",
"1",
")",
"{",
"orders",
"[",
"finds",
"[",
"i",
"]",
".",
"toString",
"(",
")",
".",
"charAt",
"(",
"0",
")",
"]",
"=",
"i",
"+",
"1",
";",
"}",
"}",
"}",
"return",
"orders",
";",
"}"
] | figure out position of time elements.. cause js cant do named captures | [
"figure",
"out",
"position",
"of",
"time",
"elements",
"..",
"cause",
"js",
"cant",
"do",
"named",
"captures"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L22006-L22026 | train |
|
primefaces/primeui-distribution | primeui-all.js | function (f, s, o) {
try {
var d = new Date('2012-01-01 ' + s);
if (isNaN(d.getTime())) {
d = new Date('2012-01-01T' + s);
if (isNaN(d.getTime())) {
d = new Date('01/01/2012 ' + s);
if (isNaN(d.getTime())) {
throw "Unable to parse time with native Date: " + s;
}
}
}
return {
hour: d.getHours(),
minute: d.getMinutes(),
second: d.getSeconds(),
millisec: d.getMilliseconds(),
microsec: d.getMicroseconds(),
timezone: d.getTimezoneOffset() * -1
};
}
catch (err) {
try {
return strictParse(f, s, o);
}
catch (err2) {
$.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
}
}
return false;
} | javascript | function (f, s, o) {
try {
var d = new Date('2012-01-01 ' + s);
if (isNaN(d.getTime())) {
d = new Date('2012-01-01T' + s);
if (isNaN(d.getTime())) {
d = new Date('01/01/2012 ' + s);
if (isNaN(d.getTime())) {
throw "Unable to parse time with native Date: " + s;
}
}
}
return {
hour: d.getHours(),
minute: d.getMinutes(),
second: d.getSeconds(),
millisec: d.getMilliseconds(),
microsec: d.getMicroseconds(),
timezone: d.getTimezoneOffset() * -1
};
}
catch (err) {
try {
return strictParse(f, s, o);
}
catch (err2) {
$.timepicker.log("Unable to parse \ntimeString: " + s + "\ntimeFormat: " + f);
}
}
return false;
} | [
"function",
"(",
"f",
",",
"s",
",",
"o",
")",
"{",
"try",
"{",
"var",
"d",
"=",
"new",
"Date",
"(",
"'2012-01-01 '",
"+",
"s",
")",
";",
"if",
"(",
"isNaN",
"(",
"d",
".",
"getTime",
"(",
")",
")",
")",
"{",
"d",
"=",
"new",
"Date",
"(",
"'2012-01-01T'",
"+",
"s",
")",
";",
"if",
"(",
"isNaN",
"(",
"d",
".",
"getTime",
"(",
")",
")",
")",
"{",
"d",
"=",
"new",
"Date",
"(",
"'01/01/2012 '",
"+",
"s",
")",
";",
"if",
"(",
"isNaN",
"(",
"d",
".",
"getTime",
"(",
")",
")",
")",
"{",
"throw",
"\"Unable to parse time with native Date: \"",
"+",
"s",
";",
"}",
"}",
"}",
"return",
"{",
"hour",
":",
"d",
".",
"getHours",
"(",
")",
",",
"minute",
":",
"d",
".",
"getMinutes",
"(",
")",
",",
"second",
":",
"d",
".",
"getSeconds",
"(",
")",
",",
"millisec",
":",
"d",
".",
"getMilliseconds",
"(",
")",
",",
"microsec",
":",
"d",
".",
"getMicroseconds",
"(",
")",
",",
"timezone",
":",
"d",
".",
"getTimezoneOffset",
"(",
")",
"*",
"-",
"1",
"}",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"try",
"{",
"return",
"strictParse",
"(",
"f",
",",
"s",
",",
"o",
")",
";",
"}",
"catch",
"(",
"err2",
")",
"{",
"$",
".",
"timepicker",
".",
"log",
"(",
"\"Unable to parse \\ntimeString: \"",
"+",
"\\n",
"+",
"s",
"+",
"\"\\ntimeFormat: \"",
")",
";",
"}",
"}",
"\\n",
"}"
] | end strictParse First try JS Date, if that fails, use strictParse | [
"end",
"strictParse",
"First",
"try",
"JS",
"Date",
"if",
"that",
"fails",
"use",
"strictParse"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L22112-L22143 | train |
|
primefaces/primeui-distribution | primeui-all.js | function(container, item) {
var borderTop = parseFloat(container.css('borderTopWidth')) || 0,
paddingTop = parseFloat(container.css('paddingTop')) || 0,
offset = item.offset().top - container.offset().top - borderTop - paddingTop,
scroll = container.scrollTop(),
elementHeight = container.height(),
itemHeight = item.outerHeight(true);
if(offset < 0) {
container.scrollTop(scroll + offset);
}
else if((offset + itemHeight) > elementHeight) {
container.scrollTop(scroll + offset - elementHeight + itemHeight);
}
} | javascript | function(container, item) {
var borderTop = parseFloat(container.css('borderTopWidth')) || 0,
paddingTop = parseFloat(container.css('paddingTop')) || 0,
offset = item.offset().top - container.offset().top - borderTop - paddingTop,
scroll = container.scrollTop(),
elementHeight = container.height(),
itemHeight = item.outerHeight(true);
if(offset < 0) {
container.scrollTop(scroll + offset);
}
else if((offset + itemHeight) > elementHeight) {
container.scrollTop(scroll + offset - elementHeight + itemHeight);
}
} | [
"function",
"(",
"container",
",",
"item",
")",
"{",
"var",
"borderTop",
"=",
"parseFloat",
"(",
"container",
".",
"css",
"(",
"'borderTopWidth'",
")",
")",
"||",
"0",
",",
"paddingTop",
"=",
"parseFloat",
"(",
"container",
".",
"css",
"(",
"'paddingTop'",
")",
")",
"||",
"0",
",",
"offset",
"=",
"item",
".",
"offset",
"(",
")",
".",
"top",
"-",
"container",
".",
"offset",
"(",
")",
".",
"top",
"-",
"borderTop",
"-",
"paddingTop",
",",
"scroll",
"=",
"container",
".",
"scrollTop",
"(",
")",
",",
"elementHeight",
"=",
"container",
".",
"height",
"(",
")",
",",
"itemHeight",
"=",
"item",
".",
"outerHeight",
"(",
"true",
")",
";",
"if",
"(",
"offset",
"<",
"0",
")",
"{",
"container",
".",
"scrollTop",
"(",
"scroll",
"+",
"offset",
")",
";",
"}",
"else",
"if",
"(",
"(",
"offset",
"+",
"itemHeight",
")",
">",
"elementHeight",
")",
"{",
"container",
".",
"scrollTop",
"(",
"scroll",
"+",
"offset",
"-",
"elementHeight",
"+",
"itemHeight",
")",
";",
"}",
"}"
] | Aligns container scrollbar to keep item in container viewport, algorithm copied from jquery-ui menu widget | [
"Aligns",
"container",
"scrollbar",
"to",
"keep",
"item",
"in",
"container",
"viewport",
"algorithm",
"copied",
"from",
"jquery",
"-",
"ui",
"menu",
"widget"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L23103-L23117 | train |
|
primefaces/primeui-distribution | primeui-all.js | function(jQuery) {
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
var platform_match = /(ipad)/.exec( ua ) ||
/(iphone)/.exec( ua ) ||
/(android)/.exec( ua ) ||
/(windows phone)/.exec( ua ) ||
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
/(cros)/i.exec( ua ) ||
[];
return {
browser: match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || "0",
platform: platform_match[ 0 ] || ""
};
};
matched = jQuery.uaMatch( window.navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.version);
}
if ( matched.platform ) {
browser[ matched.platform ] = true;
}
// These are all considered mobile platforms, meaning they run a mobile browser
if ( browser.android || browser.ipad || browser.iphone || browser[ "windows phone" ] ) {
browser.mobile = true;
}
// These are all considered desktop platforms, meaning they run a desktop browser
if ( browser.cros || browser.mac || browser.linux || browser.win ) {
browser.desktop = true;
}
// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
}
// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv )
{
var ie = "msie";
matched.browser = ie;
browser[ie] = true;
}
// Opera 15+ are identified as opr
if ( browser.opr )
{
var opera = "opera";
matched.browser = opera;
browser[opera] = true;
}
// Stock Android browsers are marked as Safari on Android.
if ( browser.safari && browser.android )
{
var android = "android";
matched.browser = android;
browser[android] = true;
}
// Assign the name and platform variable
browser.name = matched.browser;
browser.platform = matched.platform;
this.browser = browser;
$.browser = browser;
} | javascript | function(jQuery) {
var matched, browser;
jQuery.uaMatch = function( ua ) {
ua = ua.toLowerCase();
var match = /(opr)[\/]([\w.]+)/.exec( ua ) ||
/(chrome)[ \/]([\w.]+)/.exec( ua ) ||
/(version)[ \/]([\w.]+).*(safari)[ \/]([\w.]+)/.exec( ua ) ||
/(webkit)[ \/]([\w.]+)/.exec( ua ) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) ||
/(msie) ([\w.]+)/.exec( ua ) ||
ua.indexOf("trident") >= 0 && /(rv)(?::| )([\w.]+)/.exec( ua ) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) ||
[];
var platform_match = /(ipad)/.exec( ua ) ||
/(iphone)/.exec( ua ) ||
/(android)/.exec( ua ) ||
/(windows phone)/.exec( ua ) ||
/(win)/.exec( ua ) ||
/(mac)/.exec( ua ) ||
/(linux)/.exec( ua ) ||
/(cros)/i.exec( ua ) ||
[];
return {
browser: match[ 3 ] || match[ 1 ] || "",
version: match[ 2 ] || "0",
platform: platform_match[ 0 ] || ""
};
};
matched = jQuery.uaMatch( window.navigator.userAgent );
browser = {};
if ( matched.browser ) {
browser[ matched.browser ] = true;
browser.version = matched.version;
browser.versionNumber = parseInt(matched.version);
}
if ( matched.platform ) {
browser[ matched.platform ] = true;
}
// These are all considered mobile platforms, meaning they run a mobile browser
if ( browser.android || browser.ipad || browser.iphone || browser[ "windows phone" ] ) {
browser.mobile = true;
}
// These are all considered desktop platforms, meaning they run a desktop browser
if ( browser.cros || browser.mac || browser.linux || browser.win ) {
browser.desktop = true;
}
// Chrome, Opera 15+ and Safari are webkit based browsers
if ( browser.chrome || browser.opr || browser.safari ) {
browser.webkit = true;
}
// IE11 has a new token so we will assign it msie to avoid breaking changes
if ( browser.rv )
{
var ie = "msie";
matched.browser = ie;
browser[ie] = true;
}
// Opera 15+ are identified as opr
if ( browser.opr )
{
var opera = "opera";
matched.browser = opera;
browser[opera] = true;
}
// Stock Android browsers are marked as Safari on Android.
if ( browser.safari && browser.android )
{
var android = "android";
matched.browser = android;
browser[android] = true;
}
// Assign the name and platform variable
browser.name = matched.browser;
browser.platform = matched.platform;
this.browser = browser;
$.browser = browser;
} | [
"function",
"(",
"jQuery",
")",
"{",
"var",
"matched",
",",
"browser",
";",
"jQuery",
".",
"uaMatch",
"=",
"function",
"(",
"ua",
")",
"{",
"ua",
"=",
"ua",
".",
"toLowerCase",
"(",
")",
";",
"var",
"match",
"=",
"/",
"(opr)[\\/]([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(chrome)[ \\/]([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(version)[ \\/]([\\w.]+).*(safari)[ \\/]([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(webkit)[ \\/]([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(opera)(?:.*version|)[ \\/]([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(msie) ([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"ua",
".",
"indexOf",
"(",
"\"trident\"",
")",
">=",
"0",
"&&",
"/",
"(rv)(?::| )([\\w.]+)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"ua",
".",
"indexOf",
"(",
"\"compatible\"",
")",
"<",
"0",
"&&",
"/",
"(mozilla)(?:.*? rv:([\\w.]+)|)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"[",
"]",
";",
"var",
"platform_match",
"=",
"/",
"(ipad)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(iphone)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(android)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(windows phone)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(win)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(mac)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(linux)",
"/",
".",
"exec",
"(",
"ua",
")",
"||",
"/",
"(cros)",
"/",
"i",
".",
"exec",
"(",
"ua",
")",
"||",
"[",
"]",
";",
"return",
"{",
"browser",
":",
"match",
"[",
"3",
"]",
"||",
"match",
"[",
"1",
"]",
"||",
"\"\"",
",",
"version",
":",
"match",
"[",
"2",
"]",
"||",
"\"0\"",
",",
"platform",
":",
"platform_match",
"[",
"0",
"]",
"||",
"\"\"",
"}",
";",
"}",
";",
"matched",
"=",
"jQuery",
".",
"uaMatch",
"(",
"window",
".",
"navigator",
".",
"userAgent",
")",
";",
"browser",
"=",
"{",
"}",
";",
"if",
"(",
"matched",
".",
"browser",
")",
"{",
"browser",
"[",
"matched",
".",
"browser",
"]",
"=",
"true",
";",
"browser",
".",
"version",
"=",
"matched",
".",
"version",
";",
"browser",
".",
"versionNumber",
"=",
"parseInt",
"(",
"matched",
".",
"version",
")",
";",
"}",
"if",
"(",
"matched",
".",
"platform",
")",
"{",
"browser",
"[",
"matched",
".",
"platform",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"android",
"||",
"browser",
".",
"ipad",
"||",
"browser",
".",
"iphone",
"||",
"browser",
"[",
"\"windows phone\"",
"]",
")",
"{",
"browser",
".",
"mobile",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"cros",
"||",
"browser",
".",
"mac",
"||",
"browser",
".",
"linux",
"||",
"browser",
".",
"win",
")",
"{",
"browser",
".",
"desktop",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"chrome",
"||",
"browser",
".",
"opr",
"||",
"browser",
".",
"safari",
")",
"{",
"browser",
".",
"webkit",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"rv",
")",
"{",
"var",
"ie",
"=",
"\"msie\"",
";",
"matched",
".",
"browser",
"=",
"ie",
";",
"browser",
"[",
"ie",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"opr",
")",
"{",
"var",
"opera",
"=",
"\"opera\"",
";",
"matched",
".",
"browser",
"=",
"opera",
";",
"browser",
"[",
"opera",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"browser",
".",
"safari",
"&&",
"browser",
".",
"android",
")",
"{",
"var",
"android",
"=",
"\"android\"",
";",
"matched",
".",
"browser",
"=",
"android",
";",
"browser",
"[",
"android",
"]",
"=",
"true",
";",
"}",
"browser",
".",
"name",
"=",
"matched",
".",
"browser",
";",
"browser",
".",
"platform",
"=",
"matched",
".",
"platform",
";",
"this",
".",
"browser",
"=",
"browser",
";",
"$",
".",
"browser",
"=",
"browser",
";",
"}"
] | adapted from jquery browser plugin | [
"adapted",
"from",
"jquery",
"browser",
"plugin"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L23190-L23284 | train |
|
primefaces/primeui-distribution | primeui-all.js | function(index, silent) {
var panel = this.panels.eq(index);
if(!silent) {
this._trigger('change', null, {'index': index});
}
//update state
if(this.options.multiple) {
this._addToSelection(index);
}
else {
this.options.activeIndex = index;
}
this._show(panel);
} | javascript | function(index, silent) {
var panel = this.panels.eq(index);
if(!silent) {
this._trigger('change', null, {'index': index});
}
//update state
if(this.options.multiple) {
this._addToSelection(index);
}
else {
this.options.activeIndex = index;
}
this._show(panel);
} | [
"function",
"(",
"index",
",",
"silent",
")",
"{",
"var",
"panel",
"=",
"this",
".",
"panels",
".",
"eq",
"(",
"index",
")",
";",
"if",
"(",
"!",
"silent",
")",
"{",
"this",
".",
"_trigger",
"(",
"'change'",
",",
"null",
",",
"{",
"'index'",
":",
"index",
"}",
")",
";",
"}",
"if",
"(",
"this",
".",
"options",
".",
"multiple",
")",
"{",
"this",
".",
"_addToSelection",
"(",
"index",
")",
";",
"}",
"else",
"{",
"this",
".",
"options",
".",
"activeIndex",
"=",
"index",
";",
"}",
"this",
".",
"_show",
"(",
"panel",
")",
";",
"}"
] | Activates a tab with given index | [
"Activates",
"a",
"tab",
"with",
"given",
"index"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L23453-L23468 | train |
|
primefaces/primeui-distribution | primeui-all.js | function(index) {
var panel = this.panels.eq(index),
header = panel.prev();
header.attr('aria-expanded', false).children('.fa').removeClass('fa-caret-down').addClass('fa-caret-right');
header.removeClass('ui-state-active ui-corner-top').addClass('ui-corner-all');
panel.attr('aria-hidden', true).slideUp();
this._removeFromSelection(index);
} | javascript | function(index) {
var panel = this.panels.eq(index),
header = panel.prev();
header.attr('aria-expanded', false).children('.fa').removeClass('fa-caret-down').addClass('fa-caret-right');
header.removeClass('ui-state-active ui-corner-top').addClass('ui-corner-all');
panel.attr('aria-hidden', true).slideUp();
this._removeFromSelection(index);
} | [
"function",
"(",
"index",
")",
"{",
"var",
"panel",
"=",
"this",
".",
"panels",
".",
"eq",
"(",
"index",
")",
",",
"header",
"=",
"panel",
".",
"prev",
"(",
")",
";",
"header",
".",
"attr",
"(",
"'aria-expanded'",
",",
"false",
")",
".",
"children",
"(",
"'.fa'",
")",
".",
"removeClass",
"(",
"'fa-caret-down'",
")",
".",
"addClass",
"(",
"'fa-caret-right'",
")",
";",
"header",
".",
"removeClass",
"(",
"'ui-state-active ui-corner-top'",
")",
".",
"addClass",
"(",
"'ui-corner-all'",
")",
";",
"panel",
".",
"attr",
"(",
"'aria-hidden'",
",",
"true",
")",
".",
"slideUp",
"(",
")",
";",
"this",
".",
"_removeFromSelection",
"(",
"index",
")",
";",
"}"
] | Deactivates a tab with given index | [
"Deactivates",
"a",
"tab",
"with",
"given",
"index"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L23473-L23482 | train |
|
primefaces/primeui-distribution | primeui-all.js | function(pos) {
var l = pos.left < 0 ? 0 : pos.left,
t = pos.top < 0 ? 0 : pos.top;
$(this).css({
left: l,
top: t
});
} | javascript | function(pos) {
var l = pos.left < 0 ? 0 : pos.left,
t = pos.top < 0 ? 0 : pos.top;
$(this).css({
left: l,
top: t
});
} | [
"function",
"(",
"pos",
")",
"{",
"var",
"l",
"=",
"pos",
".",
"left",
"<",
"0",
"?",
"0",
":",
"pos",
".",
"left",
",",
"t",
"=",
"pos",
".",
"top",
"<",
"0",
"?",
"0",
":",
"pos",
".",
"top",
";",
"$",
"(",
"this",
")",
".",
"css",
"(",
"{",
"left",
":",
"l",
",",
"top",
":",
"t",
"}",
")",
";",
"}"
] | make sure dialog stays in viewport | [
"make",
"sure",
"dialog",
"stays",
"in",
"viewport"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/primeui-all.js#L27378-L27386 | train |
|
mikestead/swagger-routes | src/apiSpecs.js | apiSpecs | function apiSpecs(options) {
options = Options.applyDefaultSpecOptions(options)
if (options.headers) {
request.defaults.headers.common = Object.assign({}, request.defaults.headers.common, options.headers)
}
const api = swaggerSpec.getSpecSync(options.api)
const operations = swaggerSpec.getAllOperations(api)
options.fixtures = getJsonFile(options.fixtures)
describeApi(api, operations, options)
} | javascript | function apiSpecs(options) {
options = Options.applyDefaultSpecOptions(options)
if (options.headers) {
request.defaults.headers.common = Object.assign({}, request.defaults.headers.common, options.headers)
}
const api = swaggerSpec.getSpecSync(options.api)
const operations = swaggerSpec.getAllOperations(api)
options.fixtures = getJsonFile(options.fixtures)
describeApi(api, operations, options)
} | [
"function",
"apiSpecs",
"(",
"options",
")",
"{",
"options",
"=",
"Options",
".",
"applyDefaultSpecOptions",
"(",
"options",
")",
"if",
"(",
"options",
".",
"headers",
")",
"{",
"request",
".",
"defaults",
".",
"headers",
".",
"common",
"=",
"Object",
".",
"assign",
"(",
"{",
"}",
",",
"request",
".",
"defaults",
".",
"headers",
".",
"common",
",",
"options",
".",
"headers",
")",
"}",
"const",
"api",
"=",
"swaggerSpec",
".",
"getSpecSync",
"(",
"options",
".",
"api",
")",
"const",
"operations",
"=",
"swaggerSpec",
".",
"getAllOperations",
"(",
"api",
")",
"options",
".",
"fixtures",
"=",
"getJsonFile",
"(",
"options",
".",
"fixtures",
")",
"describeApi",
"(",
"api",
",",
"operations",
",",
"options",
")",
"}"
] | Generates a suite of Mocha test specifications for each of your Swagger api operations.
Both request and response of an operation call are validated for conformity
with your Swagger document.
You'll need to depend on and set up Mocha in your project yourself.
@param {object} options
- `api` path to your Swagger spec, or the loaded spec reference.
- `host` server host + port where your tests will run e.g. `localhost:3453`.
- `specs` path to specs dir, or function to return the set of specs for an operation.
- `maxTimeout` maximum time a test can take to complete.
- `slowTime` time taken before a test is marked slow. Defaults to 1 second.
- `startServer(done)` function called before all tests where you can start your local server.
- `stopServer(done)`function called after all tests where you can stop your local server.
- `fixtures`: path to a yaml file with test fixtures.
- `sortByStatus`: Sort specs by response status, lowest to highest. Defaults to true.
- `prefetch`: path to a yaml file with requests to prefetch values into fixtures before
executing specs, e.g. auth tokens
@return {void} | [
"Generates",
"a",
"suite",
"of",
"Mocha",
"test",
"specifications",
"for",
"each",
"of",
"your",
"Swagger",
"api",
"operations",
"."
] | dfa1cd16df18aa26925ce377bfdb5b18f88e2a77 | https://github.com/mikestead/swagger-routes/blob/dfa1cd16df18aa26925ce377bfdb5b18f88e2a77/src/apiSpecs.js#L42-L51 | train |
stdarg/config-js | index.js | Config | function Config(pathToConfigFileIn, region) {
have(arguments, {pathToConfigFile: 'str', region: 'opt str' });
debug('pathToConfigFileIn: '+pathToConfigFileIn);
// if the path has '##' and process.env.NODE_ENV is a non-empty string,
// replace '##' with the contents of process.env.NODE_ENV
var pathToConfigFile = pathToConfigFileIn;
var idx = pathToConfigFileIn.indexOf('##');
if (idx > -1 && is.nonEmptyStr(process.env.NODE_ENV)) {
pathToConfigFile = pathToConfigFileIn.substr(0, idx) +
process.env.NODE_ENV + pathToConfigFileIn.substr(idx+2);
}
// complimentary to have arg checking
if (!is.nonEmptyStr(pathToConfigFile))
throw new Error('Bad path to config file: '+pathToConfigFile);
if (!fs.existsSync(pathToConfigFile))
throw new Error('Config file is missing: '+pathToConfigFile);
if (is.defined(region)) assert.ok(is.nonEmptyStr(region));
// english is the default
if (is.undefined(region)) region = 'en';
debug('## sub: pathToConfigFileIn: '+pathToConfigFileIn);
this.pathToDefaults = path.join(path.dirname(pathToConfigFileIn),
'defaults.js');
this.pathToConfigFile = pathToConfigFile;
debug('region: '+region);
this.region = region;
var self = this;
debug('pathToDeafults: '+this.pathToDefaults);
// set a watch for when the file changes, to reload the file.
fs.watchFile(this.pathToConfigFile, function () {
self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
});
// we can't wait for the file to change to re-load, so we load it now
this.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
var util = require('util');
debug('Config: '+util.inspect(this.configObj));
} | javascript | function Config(pathToConfigFileIn, region) {
have(arguments, {pathToConfigFile: 'str', region: 'opt str' });
debug('pathToConfigFileIn: '+pathToConfigFileIn);
// if the path has '##' and process.env.NODE_ENV is a non-empty string,
// replace '##' with the contents of process.env.NODE_ENV
var pathToConfigFile = pathToConfigFileIn;
var idx = pathToConfigFileIn.indexOf('##');
if (idx > -1 && is.nonEmptyStr(process.env.NODE_ENV)) {
pathToConfigFile = pathToConfigFileIn.substr(0, idx) +
process.env.NODE_ENV + pathToConfigFileIn.substr(idx+2);
}
// complimentary to have arg checking
if (!is.nonEmptyStr(pathToConfigFile))
throw new Error('Bad path to config file: '+pathToConfigFile);
if (!fs.existsSync(pathToConfigFile))
throw new Error('Config file is missing: '+pathToConfigFile);
if (is.defined(region)) assert.ok(is.nonEmptyStr(region));
// english is the default
if (is.undefined(region)) region = 'en';
debug('## sub: pathToConfigFileIn: '+pathToConfigFileIn);
this.pathToDefaults = path.join(path.dirname(pathToConfigFileIn),
'defaults.js');
this.pathToConfigFile = pathToConfigFile;
debug('region: '+region);
this.region = region;
var self = this;
debug('pathToDeafults: '+this.pathToDefaults);
// set a watch for when the file changes, to reload the file.
fs.watchFile(this.pathToConfigFile, function () {
self.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
});
// we can't wait for the file to change to re-load, so we load it now
this.loadConfig(self.pathToDefaults, self.pathToConfigFile, self.region);
var util = require('util');
debug('Config: '+util.inspect(this.configObj));
} | [
"function",
"Config",
"(",
"pathToConfigFileIn",
",",
"region",
")",
"{",
"have",
"(",
"arguments",
",",
"{",
"pathToConfigFile",
":",
"'str'",
",",
"region",
":",
"'opt str'",
"}",
")",
";",
"debug",
"(",
"'pathToConfigFileIn: '",
"+",
"pathToConfigFileIn",
")",
";",
"var",
"pathToConfigFile",
"=",
"pathToConfigFileIn",
";",
"var",
"idx",
"=",
"pathToConfigFileIn",
".",
"indexOf",
"(",
"'##'",
")",
";",
"if",
"(",
"idx",
">",
"-",
"1",
"&&",
"is",
".",
"nonEmptyStr",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
")",
")",
"{",
"pathToConfigFile",
"=",
"pathToConfigFileIn",
".",
"substr",
"(",
"0",
",",
"idx",
")",
"+",
"process",
".",
"env",
".",
"NODE_ENV",
"+",
"pathToConfigFileIn",
".",
"substr",
"(",
"idx",
"+",
"2",
")",
";",
"}",
"if",
"(",
"!",
"is",
".",
"nonEmptyStr",
"(",
"pathToConfigFile",
")",
")",
"throw",
"new",
"Error",
"(",
"'Bad path to config file: '",
"+",
"pathToConfigFile",
")",
";",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"pathToConfigFile",
")",
")",
"throw",
"new",
"Error",
"(",
"'Config file is missing: '",
"+",
"pathToConfigFile",
")",
";",
"if",
"(",
"is",
".",
"defined",
"(",
"region",
")",
")",
"assert",
".",
"ok",
"(",
"is",
".",
"nonEmptyStr",
"(",
"region",
")",
")",
";",
"if",
"(",
"is",
".",
"undefined",
"(",
"region",
")",
")",
"region",
"=",
"'en'",
";",
"debug",
"(",
"'## sub: pathToConfigFileIn: '",
"+",
"pathToConfigFileIn",
")",
";",
"this",
".",
"pathToDefaults",
"=",
"path",
".",
"join",
"(",
"path",
".",
"dirname",
"(",
"pathToConfigFileIn",
")",
",",
"'defaults.js'",
")",
";",
"this",
".",
"pathToConfigFile",
"=",
"pathToConfigFile",
";",
"debug",
"(",
"'region: '",
"+",
"region",
")",
";",
"this",
".",
"region",
"=",
"region",
";",
"var",
"self",
"=",
"this",
";",
"debug",
"(",
"'pathToDeafults: '",
"+",
"this",
".",
"pathToDefaults",
")",
";",
"fs",
".",
"watchFile",
"(",
"this",
".",
"pathToConfigFile",
",",
"function",
"(",
")",
"{",
"self",
".",
"loadConfig",
"(",
"self",
".",
"pathToDefaults",
",",
"self",
".",
"pathToConfigFile",
",",
"self",
".",
"region",
")",
";",
"}",
")",
";",
"this",
".",
"loadConfig",
"(",
"self",
".",
"pathToDefaults",
",",
"self",
".",
"pathToConfigFile",
",",
"self",
".",
"region",
")",
";",
"var",
"util",
"=",
"require",
"(",
"'util'",
")",
";",
"debug",
"(",
"'Config: '",
"+",
"util",
".",
"inspect",
"(",
"this",
".",
"configObj",
")",
")",
";",
"}"
] | Config provides a simple read-only API to a configuration object.
@param {String} pathToConfigFile The configuration file
@param {String} [region] Optional indicator for the current region, e.g. 'en' | [
"Config",
"provides",
"a",
"simple",
"read",
"-",
"only",
"API",
"to",
"a",
"configuration",
"object",
"."
] | 2b87c4f7573298d28e27a8bce1e95ade7101bb35 | https://github.com/stdarg/config-js/blob/2b87c4f7573298d28e27a8bce1e95ade7101bb35/index.js#L32-L73 | train |
bruderstein/gulp-html-src | index.js | transformFile | function transformFile(contents) {
var $ = cheerio.load(contents.toString());
var result = [];
$(options.selector).each(function() {
var element = $(this);
var fileName = options.getFileName(element);
result.push(fileName);
});
return result;
} | javascript | function transformFile(contents) {
var $ = cheerio.load(contents.toString());
var result = [];
$(options.selector).each(function() {
var element = $(this);
var fileName = options.getFileName(element);
result.push(fileName);
});
return result;
} | [
"function",
"transformFile",
"(",
"contents",
")",
"{",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"contents",
".",
"toString",
"(",
")",
")",
";",
"var",
"result",
"=",
"[",
"]",
";",
"$",
"(",
"options",
".",
"selector",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"var",
"element",
"=",
"$",
"(",
"this",
")",
";",
"var",
"fileName",
"=",
"options",
".",
"getFileName",
"(",
"element",
")",
";",
"result",
".",
"push",
"(",
"fileName",
")",
";",
"}",
")",
";",
"return",
"result",
";",
"}"
] | Returns an array of matched files - empty if no file is found.
@param contents
@returns {Array} | [
"Returns",
"an",
"array",
"of",
"matched",
"files",
"-",
"empty",
"if",
"no",
"file",
"is",
"found",
"."
] | 42a45f27ba6380346d54cd252cd110c20ac21278 | https://github.com/bruderstein/gulp-html-src/blob/42a45f27ba6380346d54cd252cd110c20ac21278/index.js#L71-L81 | train |
JordanDelcros/npm-three-js | addons/MTLLoader.js | function ( text ) {
var lines = text.split( "\n" );
var info = {};
var delimiter_pattern = /\s+/;
var materialsInfo = {};
for ( var i = 0; i < lines.length; i ++ ) {
var line = lines[ i ];
line = line.trim();
if ( line.length === 0 || line.charAt( 0 ) === '#' ) {
// Blank line or comment ignore
continue;
}
var pos = line.indexOf( ' ' );
var key = ( pos >= 0 ) ? line.substring( 0, pos ) : line;
key = key.toLowerCase();
var value = ( pos >= 0 ) ? line.substring( pos + 1 ) : "";
value = value.trim();
if ( key === "newmtl" ) {
// New material
info = { name: value };
materialsInfo[ value ] = info;
} else if ( info ) {
if ( key === "ka" || key === "kd" || key === "ks" ) {
var ss = value.split( delimiter_pattern, 3 );
info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
} else {
info[ key ] = value;
}
}
}
var materialCreator = new THREE.MTLLoader.MaterialCreator( this.baseUrl, this.materialOptions );
materialCreator.setCrossOrigin( this.crossOrigin );
materialCreator.setManager( this.manager );
materialCreator.setMaterials( materialsInfo );
return materialCreator;
} | javascript | function ( text ) {
var lines = text.split( "\n" );
var info = {};
var delimiter_pattern = /\s+/;
var materialsInfo = {};
for ( var i = 0; i < lines.length; i ++ ) {
var line = lines[ i ];
line = line.trim();
if ( line.length === 0 || line.charAt( 0 ) === '#' ) {
// Blank line or comment ignore
continue;
}
var pos = line.indexOf( ' ' );
var key = ( pos >= 0 ) ? line.substring( 0, pos ) : line;
key = key.toLowerCase();
var value = ( pos >= 0 ) ? line.substring( pos + 1 ) : "";
value = value.trim();
if ( key === "newmtl" ) {
// New material
info = { name: value };
materialsInfo[ value ] = info;
} else if ( info ) {
if ( key === "ka" || key === "kd" || key === "ks" ) {
var ss = value.split( delimiter_pattern, 3 );
info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
} else {
info[ key ] = value;
}
}
}
var materialCreator = new THREE.MTLLoader.MaterialCreator( this.baseUrl, this.materialOptions );
materialCreator.setCrossOrigin( this.crossOrigin );
materialCreator.setManager( this.manager );
materialCreator.setMaterials( materialsInfo );
return materialCreator;
} | [
"function",
"(",
"text",
")",
"{",
"var",
"lines",
"=",
"text",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"\\n",
"var",
"info",
"=",
"{",
"}",
";",
"var",
"delimiter_pattern",
"=",
"/",
"\\s+",
"/",
";",
"var",
"materialsInfo",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"lines",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"line",
"=",
"lines",
"[",
"i",
"]",
";",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"if",
"(",
"line",
".",
"length",
"===",
"0",
"||",
"line",
".",
"charAt",
"(",
"0",
")",
"===",
"'#'",
")",
"{",
"continue",
";",
"}",
"var",
"pos",
"=",
"line",
".",
"indexOf",
"(",
"' '",
")",
";",
"var",
"key",
"=",
"(",
"pos",
">=",
"0",
")",
"?",
"line",
".",
"substring",
"(",
"0",
",",
"pos",
")",
":",
"line",
";",
"key",
"=",
"key",
".",
"toLowerCase",
"(",
")",
";",
"var",
"value",
"=",
"(",
"pos",
">=",
"0",
")",
"?",
"line",
".",
"substring",
"(",
"pos",
"+",
"1",
")",
":",
"\"\"",
";",
"value",
"=",
"value",
".",
"trim",
"(",
")",
";",
"if",
"(",
"key",
"===",
"\"newmtl\"",
")",
"{",
"info",
"=",
"{",
"name",
":",
"value",
"}",
";",
"materialsInfo",
"[",
"value",
"]",
"=",
"info",
";",
"}",
"else",
"if",
"(",
"info",
")",
"{",
"if",
"(",
"key",
"===",
"\"ka\"",
"||",
"key",
"===",
"\"kd\"",
"||",
"key",
"===",
"\"ks\"",
")",
"{",
"var",
"ss",
"=",
"value",
".",
"split",
"(",
"delimiter_pattern",
",",
"3",
")",
";",
"info",
"[",
"key",
"]",
"=",
"[",
"parseFloat",
"(",
"ss",
"[",
"0",
"]",
")",
",",
"parseFloat",
"(",
"ss",
"[",
"1",
"]",
")",
",",
"parseFloat",
"(",
"ss",
"[",
"2",
"]",
")",
"]",
";",
"}",
"else",
"{",
"info",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"}",
"}",
"var",
"materialCreator",
"=",
"new",
"THREE",
".",
"MTLLoader",
".",
"MaterialCreator",
"(",
"this",
".",
"baseUrl",
",",
"this",
".",
"materialOptions",
")",
";",
"materialCreator",
".",
"setCrossOrigin",
"(",
"this",
".",
"crossOrigin",
")",
";",
"materialCreator",
".",
"setManager",
"(",
"this",
".",
"manager",
")",
";",
"materialCreator",
".",
"setMaterials",
"(",
"materialsInfo",
")",
";",
"}"
] | Parses loaded MTL file
@param text - Content of MTL file
@return {THREE.MTLLoader.MaterialCreator} | [
"Parses",
"loaded",
"MTL",
"file"
] | ab3b58a5ecea9498bec8c1dcf52e91b89f437801 | https://github.com/JordanDelcros/npm-three-js/blob/ab3b58a5ecea9498bec8c1dcf52e91b89f437801/addons/MTLLoader.js#L64-L121 | train |
|
primefaces/primeui-distribution | plugins/cursorposition.js | function(target, styleName) {
var styleVal = this.getComputedStyle(styleName);
if (!!styleVal) {
$(target).css(styleName, styleVal);
}
} | javascript | function(target, styleName) {
var styleVal = this.getComputedStyle(styleName);
if (!!styleVal) {
$(target).css(styleName, styleVal);
}
} | [
"function",
"(",
"target",
",",
"styleName",
")",
"{",
"var",
"styleVal",
"=",
"this",
".",
"getComputedStyle",
"(",
"styleName",
")",
";",
"if",
"(",
"!",
"!",
"styleVal",
")",
"{",
"$",
"(",
"target",
")",
".",
"css",
"(",
"styleName",
",",
"styleVal",
")",
";",
"}",
"}"
] | easy clone method | [
"easy",
"clone",
"method"
] | 234d466a6cbc8eb3325eeef27df84e81812bf394 | https://github.com/primefaces/primeui-distribution/blob/234d466a6cbc8eb3325eeef27df84e81812bf394/plugins/cursorposition.js#L94-L99 | train |
|
kaizhu256/node-utility2 | raw.istanbul.js | function (coverage /*, testName */) {
var store = this.store;
Object.keys(coverage).forEach(function (key) {
var fileCoverage = coverage[key];
if (store.hasKey(key)) {
store.setObject(key, utils.mergeFileCoverage(fileCoverage, store.getObject(key)));
} else {
store.setObject(key, fileCoverage);
}
});
} | javascript | function (coverage /*, testName */) {
var store = this.store;
Object.keys(coverage).forEach(function (key) {
var fileCoverage = coverage[key];
if (store.hasKey(key)) {
store.setObject(key, utils.mergeFileCoverage(fileCoverage, store.getObject(key)));
} else {
store.setObject(key, fileCoverage);
}
});
} | [
"function",
"(",
"coverage",
")",
"{",
"var",
"store",
"=",
"this",
".",
"store",
";",
"Object",
".",
"keys",
"(",
"coverage",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"fileCoverage",
"=",
"coverage",
"[",
"key",
"]",
";",
"if",
"(",
"store",
".",
"hasKey",
"(",
"key",
")",
")",
"{",
"store",
".",
"setObject",
"(",
"key",
",",
"utils",
".",
"mergeFileCoverage",
"(",
"fileCoverage",
",",
"store",
".",
"getObject",
"(",
"key",
")",
")",
")",
";",
"}",
"else",
"{",
"store",
".",
"setObject",
"(",
"key",
",",
"fileCoverage",
")",
";",
"}",
"}",
")",
";",
"}"
] | adds a coverage object to the collector.
@method add
@param {Object} coverage the coverage object.
@param {String} testName Optional. The name of the test used to produce the object.
This is currently not used. | [
"adds",
"a",
"coverage",
"object",
"to",
"the",
"collector",
"."
] | 9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0 | https://github.com/kaizhu256/node-utility2/blob/9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0/raw.istanbul.js#L1309-L1319 | train |
|
nojhamster/osu-parser | lib/slidercalc.js | getCircumCircle | function getCircumCircle(p1, p2, p3) {
var x1 = p1[0];
var y1 = p1[1];
var x2 = p2[0];
var y2 = p2[1];
var x3 = p3[0];
var y3 = p3[1];
//center of circle
var D = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
var Ux = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1) + (x3 * x3 + y3 * y3) * (y1 - y2)) / D;
var Uy = ((x1 * x1 + y1 * y1) * (x3 - x2) + (x2 * x2 + y2 * y2) * (x1 - x3) + (x3 * x3 + y3 * y3) * (x2 - x1)) / D;
var px = Ux - x1;
var py = Uy - y1;
var r = Math.sqrt(px * px + py * py);
return {
cx: Ux,
cy: Uy,
radius: r
};
} | javascript | function getCircumCircle(p1, p2, p3) {
var x1 = p1[0];
var y1 = p1[1];
var x2 = p2[0];
var y2 = p2[1];
var x3 = p3[0];
var y3 = p3[1];
//center of circle
var D = 2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
var Ux = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1) + (x3 * x3 + y3 * y3) * (y1 - y2)) / D;
var Uy = ((x1 * x1 + y1 * y1) * (x3 - x2) + (x2 * x2 + y2 * y2) * (x1 - x3) + (x3 * x3 + y3 * y3) * (x2 - x1)) / D;
var px = Ux - x1;
var py = Uy - y1;
var r = Math.sqrt(px * px + py * py);
return {
cx: Ux,
cy: Uy,
radius: r
};
} | [
"function",
"getCircumCircle",
"(",
"p1",
",",
"p2",
",",
"p3",
")",
"{",
"var",
"x1",
"=",
"p1",
"[",
"0",
"]",
";",
"var",
"y1",
"=",
"p1",
"[",
"1",
"]",
";",
"var",
"x2",
"=",
"p2",
"[",
"0",
"]",
";",
"var",
"y2",
"=",
"p2",
"[",
"1",
"]",
";",
"var",
"x3",
"=",
"p3",
"[",
"0",
"]",
";",
"var",
"y3",
"=",
"p3",
"[",
"1",
"]",
";",
"var",
"D",
"=",
"2",
"*",
"(",
"x1",
"*",
"(",
"y2",
"-",
"y3",
")",
"+",
"x2",
"*",
"(",
"y3",
"-",
"y1",
")",
"+",
"x3",
"*",
"(",
"y1",
"-",
"y2",
")",
")",
";",
"var",
"Ux",
"=",
"(",
"(",
"x1",
"*",
"x1",
"+",
"y1",
"*",
"y1",
")",
"*",
"(",
"y2",
"-",
"y3",
")",
"+",
"(",
"x2",
"*",
"x2",
"+",
"y2",
"*",
"y2",
")",
"*",
"(",
"y3",
"-",
"y1",
")",
"+",
"(",
"x3",
"*",
"x3",
"+",
"y3",
"*",
"y3",
")",
"*",
"(",
"y1",
"-",
"y2",
")",
")",
"/",
"D",
";",
"var",
"Uy",
"=",
"(",
"(",
"x1",
"*",
"x1",
"+",
"y1",
"*",
"y1",
")",
"*",
"(",
"x3",
"-",
"x2",
")",
"+",
"(",
"x2",
"*",
"x2",
"+",
"y2",
"*",
"y2",
")",
"*",
"(",
"x1",
"-",
"x3",
")",
"+",
"(",
"x3",
"*",
"x3",
"+",
"y3",
"*",
"y3",
")",
"*",
"(",
"x2",
"-",
"x1",
")",
")",
"/",
"D",
";",
"var",
"px",
"=",
"Ux",
"-",
"x1",
";",
"var",
"py",
"=",
"Uy",
"-",
"y1",
";",
"var",
"r",
"=",
"Math",
".",
"sqrt",
"(",
"px",
"*",
"px",
"+",
"py",
"*",
"py",
")",
";",
"return",
"{",
"cx",
":",
"Ux",
",",
"cy",
":",
"Uy",
",",
"radius",
":",
"r",
"}",
";",
"}"
] | Get circum circle of 3 points
@param {Object} p1 first point
@param {Object} p2 second point
@param {Object} p3 third point
@return {Object} circumCircle | [
"Get",
"circum",
"circle",
"of",
"3",
"points"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/lib/slidercalc.js#L113-L138 | train |
hash-bang/mocha-logger | index.js | _argArray | function _argArray(argObj, prefix, suffix) {
var args = Array.prototype.slice.call(argObj);
if (prefix) args.unshift(prefix);
if (suffix) args.push(suffix);
return args;
} | javascript | function _argArray(argObj, prefix, suffix) {
var args = Array.prototype.slice.call(argObj);
if (prefix) args.unshift(prefix);
if (suffix) args.push(suffix);
return args;
} | [
"function",
"_argArray",
"(",
"argObj",
",",
"prefix",
",",
"suffix",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"argObj",
")",
";",
"if",
"(",
"prefix",
")",
"args",
".",
"unshift",
"(",
"prefix",
")",
";",
"if",
"(",
"suffix",
")",
"args",
".",
"push",
"(",
"suffix",
")",
";",
"return",
"args",
";",
"}"
] | Convert a JavaScript arguments object into an array and optionally surround it with the given values
@param arguments arguments A JavaScript arguments object
@param string prefix Optional prefix to apply
@param string suffix Optional suffix to apply
@return array A standard array of the extracted arguments | [
"Convert",
"a",
"JavaScript",
"arguments",
"object",
"into",
"an",
"array",
"and",
"optionally",
"surround",
"it",
"with",
"the",
"given",
"values"
] | b5b6d7d05dd2d8b6302532184a985730ff3627a0 | https://github.com/hash-bang/mocha-logger/blob/b5b6d7d05dd2d8b6302532184a985730ff3627a0/index.js#L10-L15 | train |
gregtatum/gl-engine | lib/renderer/multipass/debug.js | drawPass | function drawPass (bindings, passIndex, passCount, outputFBO) {
var { debugFBO, gl, canvas, shader, quad, resolution, scale, offset } = bindings
var { uniforms } = shader
var { width, height } = canvas
debugFBO.bind()
shader.bind()
// update shader
var resizeResolutionX = width / passCount * (1 - MARGIN * 2)
var resizeResolutionY = height / passCount * (1 - MARGIN * 2)
resolution[0] = width
resolution[1] = height
scale[0] = width / resizeResolutionX
scale[1] = height / resizeResolutionY
var scissorOffsetX = width * passIndex / passCount + width / passCount * MARGIN
var scissorOffsetY = (height / 2) - (resizeResolutionY / 2)
offset[0] = scissorOffsetX / width
offset[1] = scissorOffsetY / height
uniforms.uOffset = offset
uniforms.uResolution = resolution
uniforms.uScale = scale
uniforms.uInput = outputFBO.color[0].bind(0)
// set scissor
gl.enable(gl.SCISSOR_TEST)
gl.scissor(
// coordinate of lower left of box, moving up and to the right
scissorOffsetX,
scissorOffsetY,
resizeResolutionX,
resizeResolutionY
)
// clear first, then draw on it
gl.clearColor(0,0,0,1)
gl.clear(gl.COLOR_BUFFER_BIT)
gl.disable(gl.DEPTH_TEST)
RenderScreen(gl)
// reset state
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
gl.disable(gl.SCISSOR_TEST)
gl.enable(gl.DEPTH_TEST)
gl.scissor(0, 0, width, height)
} | javascript | function drawPass (bindings, passIndex, passCount, outputFBO) {
var { debugFBO, gl, canvas, shader, quad, resolution, scale, offset } = bindings
var { uniforms } = shader
var { width, height } = canvas
debugFBO.bind()
shader.bind()
// update shader
var resizeResolutionX = width / passCount * (1 - MARGIN * 2)
var resizeResolutionY = height / passCount * (1 - MARGIN * 2)
resolution[0] = width
resolution[1] = height
scale[0] = width / resizeResolutionX
scale[1] = height / resizeResolutionY
var scissorOffsetX = width * passIndex / passCount + width / passCount * MARGIN
var scissorOffsetY = (height / 2) - (resizeResolutionY / 2)
offset[0] = scissorOffsetX / width
offset[1] = scissorOffsetY / height
uniforms.uOffset = offset
uniforms.uResolution = resolution
uniforms.uScale = scale
uniforms.uInput = outputFBO.color[0].bind(0)
// set scissor
gl.enable(gl.SCISSOR_TEST)
gl.scissor(
// coordinate of lower left of box, moving up and to the right
scissorOffsetX,
scissorOffsetY,
resizeResolutionX,
resizeResolutionY
)
// clear first, then draw on it
gl.clearColor(0,0,0,1)
gl.clear(gl.COLOR_BUFFER_BIT)
gl.disable(gl.DEPTH_TEST)
RenderScreen(gl)
// reset state
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
gl.disable(gl.SCISSOR_TEST)
gl.enable(gl.DEPTH_TEST)
gl.scissor(0, 0, width, height)
} | [
"function",
"drawPass",
"(",
"bindings",
",",
"passIndex",
",",
"passCount",
",",
"outputFBO",
")",
"{",
"var",
"{",
"debugFBO",
",",
"gl",
",",
"canvas",
",",
"shader",
",",
"quad",
",",
"resolution",
",",
"scale",
",",
"offset",
"}",
"=",
"bindings",
"var",
"{",
"uniforms",
"}",
"=",
"shader",
"var",
"{",
"width",
",",
"height",
"}",
"=",
"canvas",
"debugFBO",
".",
"bind",
"(",
")",
"shader",
".",
"bind",
"(",
")",
"var",
"resizeResolutionX",
"=",
"width",
"/",
"passCount",
"*",
"(",
"1",
"-",
"MARGIN",
"*",
"2",
")",
"var",
"resizeResolutionY",
"=",
"height",
"/",
"passCount",
"*",
"(",
"1",
"-",
"MARGIN",
"*",
"2",
")",
"resolution",
"[",
"0",
"]",
"=",
"width",
"resolution",
"[",
"1",
"]",
"=",
"height",
"scale",
"[",
"0",
"]",
"=",
"width",
"/",
"resizeResolutionX",
"scale",
"[",
"1",
"]",
"=",
"height",
"/",
"resizeResolutionY",
"var",
"scissorOffsetX",
"=",
"width",
"*",
"passIndex",
"/",
"passCount",
"+",
"width",
"/",
"passCount",
"*",
"MARGIN",
"var",
"scissorOffsetY",
"=",
"(",
"height",
"/",
"2",
")",
"-",
"(",
"resizeResolutionY",
"/",
"2",
")",
"offset",
"[",
"0",
"]",
"=",
"scissorOffsetX",
"/",
"width",
"offset",
"[",
"1",
"]",
"=",
"scissorOffsetY",
"/",
"height",
"uniforms",
".",
"uOffset",
"=",
"offset",
"uniforms",
".",
"uResolution",
"=",
"resolution",
"uniforms",
".",
"uScale",
"=",
"scale",
"uniforms",
".",
"uInput",
"=",
"outputFBO",
".",
"color",
"[",
"0",
"]",
".",
"bind",
"(",
"0",
")",
"gl",
".",
"enable",
"(",
"gl",
".",
"SCISSOR_TEST",
")",
"gl",
".",
"scissor",
"(",
"scissorOffsetX",
",",
"scissorOffsetY",
",",
"resizeResolutionX",
",",
"resizeResolutionY",
")",
"gl",
".",
"clearColor",
"(",
"0",
",",
"0",
",",
"0",
",",
"1",
")",
"gl",
".",
"clear",
"(",
"gl",
".",
"COLOR_BUFFER_BIT",
")",
"gl",
".",
"disable",
"(",
"gl",
".",
"DEPTH_TEST",
")",
"RenderScreen",
"(",
"gl",
")",
"gl",
".",
"bindFramebuffer",
"(",
"gl",
".",
"FRAMEBUFFER",
",",
"null",
")",
"gl",
".",
"disable",
"(",
"gl",
".",
"SCISSOR_TEST",
")",
"gl",
".",
"enable",
"(",
"gl",
".",
"DEPTH_TEST",
")",
"gl",
".",
"scissor",
"(",
"0",
",",
"0",
",",
"width",
",",
"height",
")",
"}"
] | Draw a small thumbnail image of the output | [
"Draw",
"a",
"small",
"thumbnail",
"image",
"of",
"the",
"output"
] | b22ab9c19d32948cb9ad7ec7ca7f702f87071988 | https://github.com/gregtatum/gl-engine/blob/b22ab9c19d32948cb9ad7ec7ca7f702f87071988/lib/renderer/multipass/debug.js#L44-L89 | train |
Automattic/i18n-calypso | lib/index.js | normalizeTranslateArguments | function normalizeTranslateArguments( args ) {
var original = args[ 0 ],
options = {},
i;
// warn about older deprecated syntax
if ( typeof original !== 'string' || args.length > 3 || ( args.length > 2 && typeof args[ 1 ] === 'object' && typeof args[ 2 ] === 'object' ) ) {
warn( 'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:', simpleArguments( args ), '. See https://github.com/Automattic/i18n-calypso#translate-method' );
}
if ( args.length === 2 && typeof original === 'string' && typeof args[ 1 ] === 'string' ) {
warn( 'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:', simpleArguments( args ) );
}
// options could be in position 0, 1, or 2
// sending options as the first object is deprecated and will raise a warning
for ( i = 0; i < args.length; i++ ) {
if ( typeof args[ i ] === 'object' ) {
options = args[ i ];
}
}
// `original` can be passed as first parameter or as part of the options object
// though passing original as part of the options is a deprecated approach and will be removed
if ( typeof original === 'string' ) {
options.original = original;
} else if ( typeof options.original === 'object' ) {
options.plural = options.original.plural;
options.count = options.original.count;
options.original = options.original.single;
}
if ( typeof args[ 1 ] === 'string' ) {
options.plural = args[ 1 ];
}
if ( typeof options.original === 'undefined' ) {
throw new Error( 'Translate called without a `string` value as first argument.' );
}
return options;
} | javascript | function normalizeTranslateArguments( args ) {
var original = args[ 0 ],
options = {},
i;
// warn about older deprecated syntax
if ( typeof original !== 'string' || args.length > 3 || ( args.length > 2 && typeof args[ 1 ] === 'object' && typeof args[ 2 ] === 'object' ) ) {
warn( 'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:', simpleArguments( args ), '. See https://github.com/Automattic/i18n-calypso#translate-method' );
}
if ( args.length === 2 && typeof original === 'string' && typeof args[ 1 ] === 'string' ) {
warn( 'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:', simpleArguments( args ) );
}
// options could be in position 0, 1, or 2
// sending options as the first object is deprecated and will raise a warning
for ( i = 0; i < args.length; i++ ) {
if ( typeof args[ i ] === 'object' ) {
options = args[ i ];
}
}
// `original` can be passed as first parameter or as part of the options object
// though passing original as part of the options is a deprecated approach and will be removed
if ( typeof original === 'string' ) {
options.original = original;
} else if ( typeof options.original === 'object' ) {
options.plural = options.original.plural;
options.count = options.original.count;
options.original = options.original.single;
}
if ( typeof args[ 1 ] === 'string' ) {
options.plural = args[ 1 ];
}
if ( typeof options.original === 'undefined' ) {
throw new Error( 'Translate called without a `string` value as first argument.' );
}
return options;
} | [
"function",
"normalizeTranslateArguments",
"(",
"args",
")",
"{",
"var",
"original",
"=",
"args",
"[",
"0",
"]",
",",
"options",
"=",
"{",
"}",
",",
"i",
";",
"if",
"(",
"typeof",
"original",
"!==",
"'string'",
"||",
"args",
".",
"length",
">",
"3",
"||",
"(",
"args",
".",
"length",
">",
"2",
"&&",
"typeof",
"args",
"[",
"1",
"]",
"===",
"'object'",
"&&",
"typeof",
"args",
"[",
"2",
"]",
"===",
"'object'",
")",
")",
"{",
"warn",
"(",
"'Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:'",
",",
"simpleArguments",
"(",
"args",
")",
",",
"'. See https://github.com/Automattic/i18n-calypso#translate-method'",
")",
";",
"}",
"if",
"(",
"args",
".",
"length",
"===",
"2",
"&&",
"typeof",
"original",
"===",
"'string'",
"&&",
"typeof",
"args",
"[",
"1",
"]",
"===",
"'string'",
")",
"{",
"warn",
"(",
"'Invalid Invocation: `translate()` requires an options object for plural translations, but passed:'",
",",
"simpleArguments",
"(",
"args",
")",
")",
";",
"}",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"args",
"[",
"i",
"]",
"===",
"'object'",
")",
"{",
"options",
"=",
"args",
"[",
"i",
"]",
";",
"}",
"}",
"if",
"(",
"typeof",
"original",
"===",
"'string'",
")",
"{",
"options",
".",
"original",
"=",
"original",
";",
"}",
"else",
"if",
"(",
"typeof",
"options",
".",
"original",
"===",
"'object'",
")",
"{",
"options",
".",
"plural",
"=",
"options",
".",
"original",
".",
"plural",
";",
"options",
".",
"count",
"=",
"options",
".",
"original",
".",
"count",
";",
"options",
".",
"original",
"=",
"options",
".",
"original",
".",
"single",
";",
"}",
"if",
"(",
"typeof",
"args",
"[",
"1",
"]",
"===",
"'string'",
")",
"{",
"options",
".",
"plural",
"=",
"args",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"typeof",
"options",
".",
"original",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Translate called without a `string` value as first argument.'",
")",
";",
"}",
"return",
"options",
";",
"}"
] | Coerce the possible arguments and normalize to a single object
@param {arguments} args - arguments passed in from `translate()`
@return {object} - a single object describing translation needs | [
"Coerce",
"the",
"possible",
"arguments",
"and",
"normalize",
"to",
"a",
"single",
"object"
] | 661da20f619a8679001d7332e2a7804500e3ac91 | https://github.com/Automattic/i18n-calypso/blob/661da20f619a8679001d7332e2a7804500e3ac91/lib/index.js#L53-L92 | train |
fex-team/fis3-postpackager-loader | lib/lang/html.js | loadDeps | function loadDeps(file, resource) {
file.requires.forEach(function(id) {
resource.add(id);
});
file.asyncs.forEach(function(id) {
resource.add(id, true);
});
} | javascript | function loadDeps(file, resource) {
file.requires.forEach(function(id) {
resource.add(id);
});
file.asyncs.forEach(function(id) {
resource.add(id, true);
});
} | [
"function",
"loadDeps",
"(",
"file",
",",
"resource",
")",
"{",
"file",
".",
"requires",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"resource",
".",
"add",
"(",
"id",
")",
";",
"}",
")",
";",
"file",
".",
"asyncs",
".",
"forEach",
"(",
"function",
"(",
"id",
")",
"{",
"resource",
".",
"add",
"(",
"id",
",",
"true",
")",
";",
"}",
")",
";",
"}"
] | return all; }); } | [
"return",
"all",
";",
"}",
")",
";",
"}"
] | 3352f4f9abe21e348febb82af7c97c677cf874e3 | https://github.com/fex-team/fis3-postpackager-loader/blob/3352f4f9abe21e348febb82af7c97c677cf874e3/lib/lang/html.js#L238-L246 | train |
chjj/zest | lib/zest.js | function(param) {
return function(el) {
var text = el.innerText || el.textContent || el.value || '';
return !!~text.indexOf(param);
};
} | javascript | function(param) {
return function(el) {
var text = el.innerText || el.textContent || el.value || '';
return !!~text.indexOf(param);
};
} | [
"function",
"(",
"param",
")",
"{",
"return",
"function",
"(",
"el",
")",
"{",
"var",
"text",
"=",
"el",
".",
"innerText",
"||",
"el",
".",
"textContent",
"||",
"el",
".",
"value",
"||",
"''",
";",
"return",
"!",
"!",
"~",
"text",
".",
"indexOf",
"(",
"param",
")",
";",
"}",
";",
"}"
] | Non-standard, for compatibility purposes. | [
"Non",
"-",
"standard",
"for",
"compatibility",
"purposes",
"."
] | 22083bc436926e27d48db3e65a2e6085097bd4b8 | https://github.com/chjj/zest/blob/22083bc436926e27d48db3e65a2e6085097bd4b8/lib/zest.js#L440-L445 | train |
|
HQarroum/directed-graph | graph.js | function (graph, head, where) {
var routes = [];
Graph.Visitor.Stacked(graph, head, function (node, stack, weight) {
if (where && where.length !== stack.length){
return;
}
routes.push(new Graph.Route(stack.slice(), weight));
});
return routes;
} | javascript | function (graph, head, where) {
var routes = [];
Graph.Visitor.Stacked(graph, head, function (node, stack, weight) {
if (where && where.length !== stack.length){
return;
}
routes.push(new Graph.Route(stack.slice(), weight));
});
return routes;
} | [
"function",
"(",
"graph",
",",
"head",
",",
"where",
")",
"{",
"var",
"routes",
"=",
"[",
"]",
";",
"Graph",
".",
"Visitor",
".",
"Stacked",
"(",
"graph",
",",
"head",
",",
"function",
"(",
"node",
",",
"stack",
",",
"weight",
")",
"{",
"if",
"(",
"where",
"&&",
"where",
".",
"length",
"!==",
"stack",
".",
"length",
")",
"{",
"return",
";",
"}",
"routes",
".",
"push",
"(",
"new",
"Graph",
".",
"Route",
"(",
"stack",
".",
"slice",
"(",
")",
",",
"weight",
")",
")",
";",
"}",
")",
";",
"return",
"routes",
";",
"}"
] | Helper that will return all the routes
that have the given head node as
a starting point. | [
"Helper",
"that",
"will",
"return",
"all",
"the",
"routes",
"that",
"have",
"the",
"given",
"head",
"node",
"as",
"a",
"starting",
"point",
"."
] | eb298c6a97f701176209830ebd9940739332f938 | https://github.com/HQarroum/directed-graph/blob/eb298c6a97f701176209830ebd9940739332f938/graph.js#L227-L237 | train |
|
nojhamster/osu-parser | index.js | function (offset) {
for (var i = beatmap.timingPoints.length - 1; i >= 0; i--) {
if (beatmap.timingPoints[i].offset <= offset) { return beatmap.timingPoints[i]; }
}
return beatmap.timingPoints[0];
} | javascript | function (offset) {
for (var i = beatmap.timingPoints.length - 1; i >= 0; i--) {
if (beatmap.timingPoints[i].offset <= offset) { return beatmap.timingPoints[i]; }
}
return beatmap.timingPoints[0];
} | [
"function",
"(",
"offset",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"beatmap",
".",
"timingPoints",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"beatmap",
".",
"timingPoints",
"[",
"i",
"]",
".",
"offset",
"<=",
"offset",
")",
"{",
"return",
"beatmap",
".",
"timingPoints",
"[",
"i",
"]",
";",
"}",
"}",
"return",
"beatmap",
".",
"timingPoints",
"[",
"0",
"]",
";",
"}"
] | Get the timing point affecting a specific offset
@param {Integer} offset
@return {Object} timingPoint | [
"Get",
"the",
"timing",
"point",
"affecting",
"a",
"specific",
"offset"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L38-L43 | train |
|
nojhamster/osu-parser | index.js | function (str) {
if (!str) return {};
var additions = {};
var adds = str.split(':');
if (adds[0] && adds[0] !== '0') {
var sample;
switch (adds[0]) {
case '1':
sample = 'normal';
break;
case '2':
sample = 'soft';
break;
case '3':
sample = 'drum';
break;
}
additions.sample = sample;
}
if (adds[1] && adds[1] !== '0') {
var addSample;
switch (adds[1]) {
case '1':
addSample = 'normal';
break;
case '2':
addSample = 'soft';
break;
case '3':
addSample = 'drum';
break;
}
additions.additionalSample = addSample;
}
if (adds[2] && adds[2] !== '0') { additions.customSampleIndex = parseInt(adds[2]); }
if (adds[3] && adds[3] !== '0') { additions.hitsoundVolume = parseInt(adds[3]); }
if (adds[4]) { additions.hitsound = adds[4]; }
return additions;
} | javascript | function (str) {
if (!str) return {};
var additions = {};
var adds = str.split(':');
if (adds[0] && adds[0] !== '0') {
var sample;
switch (adds[0]) {
case '1':
sample = 'normal';
break;
case '2':
sample = 'soft';
break;
case '3':
sample = 'drum';
break;
}
additions.sample = sample;
}
if (adds[1] && adds[1] !== '0') {
var addSample;
switch (adds[1]) {
case '1':
addSample = 'normal';
break;
case '2':
addSample = 'soft';
break;
case '3':
addSample = 'drum';
break;
}
additions.additionalSample = addSample;
}
if (adds[2] && adds[2] !== '0') { additions.customSampleIndex = parseInt(adds[2]); }
if (adds[3] && adds[3] !== '0') { additions.hitsoundVolume = parseInt(adds[3]); }
if (adds[4]) { additions.hitsound = adds[4]; }
return additions;
} | [
"function",
"(",
"str",
")",
"{",
"if",
"(",
"!",
"str",
")",
"return",
"{",
"}",
";",
"var",
"additions",
"=",
"{",
"}",
";",
"var",
"adds",
"=",
"str",
".",
"split",
"(",
"':'",
")",
";",
"if",
"(",
"adds",
"[",
"0",
"]",
"&&",
"adds",
"[",
"0",
"]",
"!==",
"'0'",
")",
"{",
"var",
"sample",
";",
"switch",
"(",
"adds",
"[",
"0",
"]",
")",
"{",
"case",
"'1'",
":",
"sample",
"=",
"'normal'",
";",
"break",
";",
"case",
"'2'",
":",
"sample",
"=",
"'soft'",
";",
"break",
";",
"case",
"'3'",
":",
"sample",
"=",
"'drum'",
";",
"break",
";",
"}",
"additions",
".",
"sample",
"=",
"sample",
";",
"}",
"if",
"(",
"adds",
"[",
"1",
"]",
"&&",
"adds",
"[",
"1",
"]",
"!==",
"'0'",
")",
"{",
"var",
"addSample",
";",
"switch",
"(",
"adds",
"[",
"1",
"]",
")",
"{",
"case",
"'1'",
":",
"addSample",
"=",
"'normal'",
";",
"break",
";",
"case",
"'2'",
":",
"addSample",
"=",
"'soft'",
";",
"break",
";",
"case",
"'3'",
":",
"addSample",
"=",
"'drum'",
";",
"break",
";",
"}",
"additions",
".",
"additionalSample",
"=",
"addSample",
";",
"}",
"if",
"(",
"adds",
"[",
"2",
"]",
"&&",
"adds",
"[",
"2",
"]",
"!==",
"'0'",
")",
"{",
"additions",
".",
"customSampleIndex",
"=",
"parseInt",
"(",
"adds",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"adds",
"[",
"3",
"]",
"&&",
"adds",
"[",
"3",
"]",
"!==",
"'0'",
")",
"{",
"additions",
".",
"hitsoundVolume",
"=",
"parseInt",
"(",
"adds",
"[",
"3",
"]",
")",
";",
"}",
"if",
"(",
"adds",
"[",
"4",
"]",
")",
"{",
"additions",
".",
"hitsound",
"=",
"adds",
"[",
"4",
"]",
";",
"}",
"return",
"additions",
";",
"}"
] | Parse additions member
@param {String} str additions member (sample:add:customSampleIndex:Volume:hitsound)
@return {Object} additions a list of additions | [
"Parse",
"additions",
"member"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L50-L93 | train |
|
nojhamster/osu-parser | index.js | function (line) {
members = line.split(',');
var timingPoint = {
offset: parseInt(members[0]),
beatLength: parseFloat(members[1]),
velocity: 1,
timingSignature: parseInt(members[2]),
sampleSetId: parseInt(members[3]),
customSampleIndex: parseInt(members[4]),
sampleVolume: parseInt(members[5]),
timingChange: (members[6] == 1),
kiaiTimeActive: (members[7] == 1)
};
if (!isNaN(timingPoint.beatLength) && timingPoint.beatLength !== 0) {
if (timingPoint.beatLength > 0) {
// If positive, beatLength is the length of a beat in milliseconds
var bpm = Math.round(60000 / timingPoint.beatLength);
beatmap.bpmMin = beatmap.bpmMin ? Math.min(beatmap.bpmMin, bpm) : bpm;
beatmap.bpmMax = beatmap.bpmMax ? Math.max(beatmap.bpmMax, bpm) : bpm;
timingPoint.bpm = bpm;
} else {
// If negative, beatLength is a velocity factor
timingPoint.velocity = Math.abs(100 / timingPoint.beatLength);
}
}
beatmap.timingPoints.push(timingPoint);
} | javascript | function (line) {
members = line.split(',');
var timingPoint = {
offset: parseInt(members[0]),
beatLength: parseFloat(members[1]),
velocity: 1,
timingSignature: parseInt(members[2]),
sampleSetId: parseInt(members[3]),
customSampleIndex: parseInt(members[4]),
sampleVolume: parseInt(members[5]),
timingChange: (members[6] == 1),
kiaiTimeActive: (members[7] == 1)
};
if (!isNaN(timingPoint.beatLength) && timingPoint.beatLength !== 0) {
if (timingPoint.beatLength > 0) {
// If positive, beatLength is the length of a beat in milliseconds
var bpm = Math.round(60000 / timingPoint.beatLength);
beatmap.bpmMin = beatmap.bpmMin ? Math.min(beatmap.bpmMin, bpm) : bpm;
beatmap.bpmMax = beatmap.bpmMax ? Math.max(beatmap.bpmMax, bpm) : bpm;
timingPoint.bpm = bpm;
} else {
// If negative, beatLength is a velocity factor
timingPoint.velocity = Math.abs(100 / timingPoint.beatLength);
}
}
beatmap.timingPoints.push(timingPoint);
} | [
"function",
"(",
"line",
")",
"{",
"members",
"=",
"line",
".",
"split",
"(",
"','",
")",
";",
"var",
"timingPoint",
"=",
"{",
"offset",
":",
"parseInt",
"(",
"members",
"[",
"0",
"]",
")",
",",
"beatLength",
":",
"parseFloat",
"(",
"members",
"[",
"1",
"]",
")",
",",
"velocity",
":",
"1",
",",
"timingSignature",
":",
"parseInt",
"(",
"members",
"[",
"2",
"]",
")",
",",
"sampleSetId",
":",
"parseInt",
"(",
"members",
"[",
"3",
"]",
")",
",",
"customSampleIndex",
":",
"parseInt",
"(",
"members",
"[",
"4",
"]",
")",
",",
"sampleVolume",
":",
"parseInt",
"(",
"members",
"[",
"5",
"]",
")",
",",
"timingChange",
":",
"(",
"members",
"[",
"6",
"]",
"==",
"1",
")",
",",
"kiaiTimeActive",
":",
"(",
"members",
"[",
"7",
"]",
"==",
"1",
")",
"}",
";",
"if",
"(",
"!",
"isNaN",
"(",
"timingPoint",
".",
"beatLength",
")",
"&&",
"timingPoint",
".",
"beatLength",
"!==",
"0",
")",
"{",
"if",
"(",
"timingPoint",
".",
"beatLength",
">",
"0",
")",
"{",
"var",
"bpm",
"=",
"Math",
".",
"round",
"(",
"60000",
"/",
"timingPoint",
".",
"beatLength",
")",
";",
"beatmap",
".",
"bpmMin",
"=",
"beatmap",
".",
"bpmMin",
"?",
"Math",
".",
"min",
"(",
"beatmap",
".",
"bpmMin",
",",
"bpm",
")",
":",
"bpm",
";",
"beatmap",
".",
"bpmMax",
"=",
"beatmap",
".",
"bpmMax",
"?",
"Math",
".",
"max",
"(",
"beatmap",
".",
"bpmMax",
",",
"bpm",
")",
":",
"bpm",
";",
"timingPoint",
".",
"bpm",
"=",
"bpm",
";",
"}",
"else",
"{",
"timingPoint",
".",
"velocity",
"=",
"Math",
".",
"abs",
"(",
"100",
"/",
"timingPoint",
".",
"beatLength",
")",
";",
"}",
"}",
"beatmap",
".",
"timingPoints",
".",
"push",
"(",
"timingPoint",
")",
";",
"}"
] | Parse a timing line
@param {String} line | [
"Parse",
"a",
"timing",
"line"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L99-L128 | train |
|
nojhamster/osu-parser | index.js | function (line) {
/**
* Background line : 0,0,"bg.jpg"
* TODO: confirm that the second member is always zero
*
* Breaktimes lines : 2,1000,2000
* second integer is start offset
* third integer is end offset
*/
members = line.split(',');
if (members[0] == '0' && members[1] == '0' && members[2]) {
var bgName = members[2].trim();
if (bgName.charAt(0) == '"' && bgName.charAt(bgName.length - 1) == '"') {
beatmap.bgFilename = bgName.substring(1, bgName.length - 1);
} else {
beatmap.bgFilename = bgName;
}
} else if (members[0] == '2' && /^[0-9]+$/.test(members[1]) && /^[0-9]+$/.test(members[2])) {
beatmap.breakTimes.push({
startTime: parseInt(members[1]),
endTime: parseInt(members[2])
});
}
} | javascript | function (line) {
/**
* Background line : 0,0,"bg.jpg"
* TODO: confirm that the second member is always zero
*
* Breaktimes lines : 2,1000,2000
* second integer is start offset
* third integer is end offset
*/
members = line.split(',');
if (members[0] == '0' && members[1] == '0' && members[2]) {
var bgName = members[2].trim();
if (bgName.charAt(0) == '"' && bgName.charAt(bgName.length - 1) == '"') {
beatmap.bgFilename = bgName.substring(1, bgName.length - 1);
} else {
beatmap.bgFilename = bgName;
}
} else if (members[0] == '2' && /^[0-9]+$/.test(members[1]) && /^[0-9]+$/.test(members[2])) {
beatmap.breakTimes.push({
startTime: parseInt(members[1]),
endTime: parseInt(members[2])
});
}
} | [
"function",
"(",
"line",
")",
"{",
"members",
"=",
"line",
".",
"split",
"(",
"','",
")",
";",
"if",
"(",
"members",
"[",
"0",
"]",
"==",
"'0'",
"&&",
"members",
"[",
"1",
"]",
"==",
"'0'",
"&&",
"members",
"[",
"2",
"]",
")",
"{",
"var",
"bgName",
"=",
"members",
"[",
"2",
"]",
".",
"trim",
"(",
")",
";",
"if",
"(",
"bgName",
".",
"charAt",
"(",
"0",
")",
"==",
"'\"'",
"&&",
"bgName",
".",
"charAt",
"(",
"bgName",
".",
"length",
"-",
"1",
")",
"==",
"'\"'",
")",
"{",
"beatmap",
".",
"bgFilename",
"=",
"bgName",
".",
"substring",
"(",
"1",
",",
"bgName",
".",
"length",
"-",
"1",
")",
";",
"}",
"else",
"{",
"beatmap",
".",
"bgFilename",
"=",
"bgName",
";",
"}",
"}",
"else",
"if",
"(",
"members",
"[",
"0",
"]",
"==",
"'2'",
"&&",
"/",
"^[0-9]+$",
"/",
".",
"test",
"(",
"members",
"[",
"1",
"]",
")",
"&&",
"/",
"^[0-9]+$",
"/",
".",
"test",
"(",
"members",
"[",
"2",
"]",
")",
")",
"{",
"beatmap",
".",
"breakTimes",
".",
"push",
"(",
"{",
"startTime",
":",
"parseInt",
"(",
"members",
"[",
"1",
"]",
")",
",",
"endTime",
":",
"parseInt",
"(",
"members",
"[",
"2",
"]",
")",
"}",
")",
";",
"}",
"}"
] | Parse an event line
@param {String} line | [
"Parse",
"an",
"event",
"line"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L268-L293 | train |
|
nojhamster/osu-parser | index.js | function () {
var firstObject = beatmap.hitObjects[0];
var lastObject = beatmap.hitObjects[beatmap.hitObjects.length - 1];
var totalBreakTime = 0;
beatmap.breakTimes.forEach(function (breakTime) {
totalBreakTime += (breakTime.endTime - breakTime.startTime);
});
if (firstObject && lastObject) {
beatmap.totalTime = Math.floor(lastObject.startTime / 1000);
beatmap.drainingTime = Math.floor((lastObject.startTime - firstObject.startTime - totalBreakTime) / 1000);
} else {
beatmap.totalTime = 0;
beatmap.drainingTime = 0;
}
} | javascript | function () {
var firstObject = beatmap.hitObjects[0];
var lastObject = beatmap.hitObjects[beatmap.hitObjects.length - 1];
var totalBreakTime = 0;
beatmap.breakTimes.forEach(function (breakTime) {
totalBreakTime += (breakTime.endTime - breakTime.startTime);
});
if (firstObject && lastObject) {
beatmap.totalTime = Math.floor(lastObject.startTime / 1000);
beatmap.drainingTime = Math.floor((lastObject.startTime - firstObject.startTime - totalBreakTime) / 1000);
} else {
beatmap.totalTime = 0;
beatmap.drainingTime = 0;
}
} | [
"function",
"(",
")",
"{",
"var",
"firstObject",
"=",
"beatmap",
".",
"hitObjects",
"[",
"0",
"]",
";",
"var",
"lastObject",
"=",
"beatmap",
".",
"hitObjects",
"[",
"beatmap",
".",
"hitObjects",
".",
"length",
"-",
"1",
"]",
";",
"var",
"totalBreakTime",
"=",
"0",
";",
"beatmap",
".",
"breakTimes",
".",
"forEach",
"(",
"function",
"(",
"breakTime",
")",
"{",
"totalBreakTime",
"+=",
"(",
"breakTime",
".",
"endTime",
"-",
"breakTime",
".",
"startTime",
")",
";",
"}",
")",
";",
"if",
"(",
"firstObject",
"&&",
"lastObject",
")",
"{",
"beatmap",
".",
"totalTime",
"=",
"Math",
".",
"floor",
"(",
"lastObject",
".",
"startTime",
"/",
"1000",
")",
";",
"beatmap",
".",
"drainingTime",
"=",
"Math",
".",
"floor",
"(",
"(",
"lastObject",
".",
"startTime",
"-",
"firstObject",
".",
"startTime",
"-",
"totalBreakTime",
")",
"/",
"1000",
")",
";",
"}",
"else",
"{",
"beatmap",
".",
"totalTime",
"=",
"0",
";",
"beatmap",
".",
"drainingTime",
"=",
"0",
";",
"}",
"}"
] | Compute the total time and the draining time of the beatmap | [
"Compute",
"the",
"total",
"time",
"and",
"the",
"draining",
"time",
"of",
"the",
"beatmap"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L298-L315 | train |
|
nojhamster/osu-parser | index.js | function () {
if (beatmap.timingPoints.length === 0) { return; }
var maxCombo = 0;
var sliderMultiplier = parseFloat(beatmap.SliderMultiplier);
var sliderTickRate = parseInt(beatmap.SliderTickRate, 10);
var timingPoints = beatmap.timingPoints;
var currentTiming = timingPoints[0];
var nextOffset = timingPoints[1] ? timingPoints[1].offset : Infinity;
var i = 1;
beatmap.hitObjects.forEach(function (hitObject) {
if (hitObject.startTime >= nextOffset) {
currentTiming = timingPoints[i++];
nextOffset = timingPoints[i] ? timingPoints[i].offset : Infinity;
}
var osupxPerBeat = sliderMultiplier * 100 * currentTiming.velocity;
var tickLength = osupxPerBeat / sliderTickRate;
switch (hitObject.objectName) {
case 'spinner':
case 'circle':
maxCombo++;
break;
case 'slider':
var tickPerSide = Math.ceil((Math.floor(hitObject.pixelLength / tickLength * 100) / 100) - 1);
maxCombo += (hitObject.edges.length - 1) * (tickPerSide + 1) + 1; // 1 combo for each tick and endpoint
}
});
beatmap.maxCombo = maxCombo;
} | javascript | function () {
if (beatmap.timingPoints.length === 0) { return; }
var maxCombo = 0;
var sliderMultiplier = parseFloat(beatmap.SliderMultiplier);
var sliderTickRate = parseInt(beatmap.SliderTickRate, 10);
var timingPoints = beatmap.timingPoints;
var currentTiming = timingPoints[0];
var nextOffset = timingPoints[1] ? timingPoints[1].offset : Infinity;
var i = 1;
beatmap.hitObjects.forEach(function (hitObject) {
if (hitObject.startTime >= nextOffset) {
currentTiming = timingPoints[i++];
nextOffset = timingPoints[i] ? timingPoints[i].offset : Infinity;
}
var osupxPerBeat = sliderMultiplier * 100 * currentTiming.velocity;
var tickLength = osupxPerBeat / sliderTickRate;
switch (hitObject.objectName) {
case 'spinner':
case 'circle':
maxCombo++;
break;
case 'slider':
var tickPerSide = Math.ceil((Math.floor(hitObject.pixelLength / tickLength * 100) / 100) - 1);
maxCombo += (hitObject.edges.length - 1) * (tickPerSide + 1) + 1; // 1 combo for each tick and endpoint
}
});
beatmap.maxCombo = maxCombo;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"beatmap",
".",
"timingPoints",
".",
"length",
"===",
"0",
")",
"{",
"return",
";",
"}",
"var",
"maxCombo",
"=",
"0",
";",
"var",
"sliderMultiplier",
"=",
"parseFloat",
"(",
"beatmap",
".",
"SliderMultiplier",
")",
";",
"var",
"sliderTickRate",
"=",
"parseInt",
"(",
"beatmap",
".",
"SliderTickRate",
",",
"10",
")",
";",
"var",
"timingPoints",
"=",
"beatmap",
".",
"timingPoints",
";",
"var",
"currentTiming",
"=",
"timingPoints",
"[",
"0",
"]",
";",
"var",
"nextOffset",
"=",
"timingPoints",
"[",
"1",
"]",
"?",
"timingPoints",
"[",
"1",
"]",
".",
"offset",
":",
"Infinity",
";",
"var",
"i",
"=",
"1",
";",
"beatmap",
".",
"hitObjects",
".",
"forEach",
"(",
"function",
"(",
"hitObject",
")",
"{",
"if",
"(",
"hitObject",
".",
"startTime",
">=",
"nextOffset",
")",
"{",
"currentTiming",
"=",
"timingPoints",
"[",
"i",
"++",
"]",
";",
"nextOffset",
"=",
"timingPoints",
"[",
"i",
"]",
"?",
"timingPoints",
"[",
"i",
"]",
".",
"offset",
":",
"Infinity",
";",
"}",
"var",
"osupxPerBeat",
"=",
"sliderMultiplier",
"*",
"100",
"*",
"currentTiming",
".",
"velocity",
";",
"var",
"tickLength",
"=",
"osupxPerBeat",
"/",
"sliderTickRate",
";",
"switch",
"(",
"hitObject",
".",
"objectName",
")",
"{",
"case",
"'spinner'",
":",
"case",
"'circle'",
":",
"maxCombo",
"++",
";",
"break",
";",
"case",
"'slider'",
":",
"var",
"tickPerSide",
"=",
"Math",
".",
"ceil",
"(",
"(",
"Math",
".",
"floor",
"(",
"hitObject",
".",
"pixelLength",
"/",
"tickLength",
"*",
"100",
")",
"/",
"100",
")",
"-",
"1",
")",
";",
"maxCombo",
"+=",
"(",
"hitObject",
".",
"edges",
".",
"length",
"-",
"1",
")",
"*",
"(",
"tickPerSide",
"+",
"1",
")",
"+",
"1",
";",
"}",
"}",
")",
";",
"beatmap",
".",
"maxCombo",
"=",
"maxCombo",
";",
"}"
] | Browse objects and compute max combo | [
"Browse",
"objects",
"and",
"compute",
"max",
"combo"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L320-L353 | train |
|
nojhamster/osu-parser | index.js | function () {
if (beatmap.Tags) {
beatmap.tagsArray = beatmap.Tags.split(' ');
}
eventsLines.forEach(parseEvent);
beatmap.breakTimes.sort(function (a, b) { return (a.startTime > b.startTime ? 1 : -1); });
timingLines.forEach(parseTimingPoint);
beatmap.timingPoints.sort(function (a, b) { return (a.offset > b.offset ? 1 : -1); });
var timingPoints = beatmap.timingPoints;
for (var i = 1, l = timingPoints.length; i < l; i++) {
if (!timingPoints[i].hasOwnProperty('bpm')) {
timingPoints[i].beatLength = timingPoints[i - 1].beatLength;
timingPoints[i].bpm = timingPoints[i - 1].bpm;
}
}
objectLines.forEach(parseHitObject);
beatmap.hitObjects.sort(function (a, b) { return (a.startTime > b.startTime ? 1 : -1); });
computeMaxCombo();
computeDuration();
return beatmap;
} | javascript | function () {
if (beatmap.Tags) {
beatmap.tagsArray = beatmap.Tags.split(' ');
}
eventsLines.forEach(parseEvent);
beatmap.breakTimes.sort(function (a, b) { return (a.startTime > b.startTime ? 1 : -1); });
timingLines.forEach(parseTimingPoint);
beatmap.timingPoints.sort(function (a, b) { return (a.offset > b.offset ? 1 : -1); });
var timingPoints = beatmap.timingPoints;
for (var i = 1, l = timingPoints.length; i < l; i++) {
if (!timingPoints[i].hasOwnProperty('bpm')) {
timingPoints[i].beatLength = timingPoints[i - 1].beatLength;
timingPoints[i].bpm = timingPoints[i - 1].bpm;
}
}
objectLines.forEach(parseHitObject);
beatmap.hitObjects.sort(function (a, b) { return (a.startTime > b.startTime ? 1 : -1); });
computeMaxCombo();
computeDuration();
return beatmap;
} | [
"function",
"(",
")",
"{",
"if",
"(",
"beatmap",
".",
"Tags",
")",
"{",
"beatmap",
".",
"tagsArray",
"=",
"beatmap",
".",
"Tags",
".",
"split",
"(",
"' '",
")",
";",
"}",
"eventsLines",
".",
"forEach",
"(",
"parseEvent",
")",
";",
"beatmap",
".",
"breakTimes",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
".",
"startTime",
">",
"b",
".",
"startTime",
"?",
"1",
":",
"-",
"1",
")",
";",
"}",
")",
";",
"timingLines",
".",
"forEach",
"(",
"parseTimingPoint",
")",
";",
"beatmap",
".",
"timingPoints",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
".",
"offset",
">",
"b",
".",
"offset",
"?",
"1",
":",
"-",
"1",
")",
";",
"}",
")",
";",
"var",
"timingPoints",
"=",
"beatmap",
".",
"timingPoints",
";",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"l",
"=",
"timingPoints",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"timingPoints",
"[",
"i",
"]",
".",
"hasOwnProperty",
"(",
"'bpm'",
")",
")",
"{",
"timingPoints",
"[",
"i",
"]",
".",
"beatLength",
"=",
"timingPoints",
"[",
"i",
"-",
"1",
"]",
".",
"beatLength",
";",
"timingPoints",
"[",
"i",
"]",
".",
"bpm",
"=",
"timingPoints",
"[",
"i",
"-",
"1",
"]",
".",
"bpm",
";",
"}",
"}",
"objectLines",
".",
"forEach",
"(",
"parseHitObject",
")",
";",
"beatmap",
".",
"hitObjects",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"(",
"a",
".",
"startTime",
">",
"b",
".",
"startTime",
"?",
"1",
":",
"-",
"1",
")",
";",
"}",
")",
";",
"computeMaxCombo",
"(",
")",
";",
"computeDuration",
"(",
")",
";",
"return",
"beatmap",
";",
"}"
] | Compute everything that require the file to be completely parsed and return the beatmap
@return {Object} beatmap | [
"Compute",
"everything",
"that",
"require",
"the",
"file",
"to",
"be",
"completely",
"parsed",
"and",
"return",
"the",
"beatmap"
] | 539b73e087d46de7aa7159476c7ea6ac50983c97 | https://github.com/nojhamster/osu-parser/blob/539b73e087d46de7aa7159476c7ea6ac50983c97/index.js#L400-L427 | train |
|
kaizhu256/node-utility2 | lib.terser.js | function(no_in) {
handle_regexp();
var start = S.token;
if (start.type == "name" && start.value == "yield") {
if (is_in_generator()) {
next();
return _yield_expression();
} else if (S.input.has_directive("use strict")) {
token_error(S.token, "Unexpected yield identifier inside strict mode");
}
}
var left = maybe_conditional(no_in);
var val = S.token.value;
if (is("operator") && ASSIGNMENT(val)) {
if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
next();
return new AST_Assign({
start : start,
left : left,
operator : val,
right : maybe_assign(no_in),
end : prev()
});
}
croak("Invalid assignment");
}
return left;
} | javascript | function(no_in) {
handle_regexp();
var start = S.token;
if (start.type == "name" && start.value == "yield") {
if (is_in_generator()) {
next();
return _yield_expression();
} else if (S.input.has_directive("use strict")) {
token_error(S.token, "Unexpected yield identifier inside strict mode");
}
}
var left = maybe_conditional(no_in);
var val = S.token.value;
if (is("operator") && ASSIGNMENT(val)) {
if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
next();
return new AST_Assign({
start : start,
left : left,
operator : val,
right : maybe_assign(no_in),
end : prev()
});
}
croak("Invalid assignment");
}
return left;
} | [
"function",
"(",
"no_in",
")",
"{",
"handle_regexp",
"(",
")",
";",
"var",
"start",
"=",
"S",
".",
"token",
";",
"if",
"(",
"start",
".",
"type",
"==",
"\"name\"",
"&&",
"start",
".",
"value",
"==",
"\"yield\"",
")",
"{",
"if",
"(",
"is_in_generator",
"(",
")",
")",
"{",
"next",
"(",
")",
";",
"return",
"_yield_expression",
"(",
")",
";",
"}",
"else",
"if",
"(",
"S",
".",
"input",
".",
"has_directive",
"(",
"\"use strict\"",
")",
")",
"{",
"token_error",
"(",
"S",
".",
"token",
",",
"\"Unexpected yield identifier inside strict mode\"",
")",
";",
"}",
"}",
"var",
"left",
"=",
"maybe_conditional",
"(",
"no_in",
")",
";",
"var",
"val",
"=",
"S",
".",
"token",
".",
"value",
";",
"if",
"(",
"is",
"(",
"\"operator\"",
")",
"&&",
"ASSIGNMENT",
"(",
"val",
")",
")",
"{",
"if",
"(",
"is_assignable",
"(",
"left",
")",
"||",
"(",
"left",
"=",
"to_destructuring",
"(",
"left",
")",
")",
"instanceof",
"AST_Destructuring",
")",
"{",
"next",
"(",
")",
";",
"return",
"new",
"AST_Assign",
"(",
"{",
"start",
":",
"start",
",",
"left",
":",
"left",
",",
"operator",
":",
"val",
",",
"right",
":",
"maybe_assign",
"(",
"no_in",
")",
",",
"end",
":",
"prev",
"(",
")",
"}",
")",
";",
"}",
"croak",
"(",
"\"Invalid assignment\"",
")",
";",
"}",
"return",
"left",
";",
"}"
] | In ES6, AssignmentExpression can also be an ArrowFunction | [
"In",
"ES6",
"AssignmentExpression",
"can",
"also",
"be",
"an",
"ArrowFunction"
] | 9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0 | https://github.com/kaizhu256/node-utility2/blob/9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0/lib.terser.js#L3260-L3290 | train |
|
kaizhu256/node-utility2 | lib.terser.js | is_true | function is_true(node) {
return node instanceof AST_True
|| in_bool
&& node instanceof AST_Constant
&& node.getValue()
|| (node instanceof AST_UnaryPrefix
&& node.operator == "!"
&& node.expression instanceof AST_Constant
&& !node.expression.getValue());
} | javascript | function is_true(node) {
return node instanceof AST_True
|| in_bool
&& node instanceof AST_Constant
&& node.getValue()
|| (node instanceof AST_UnaryPrefix
&& node.operator == "!"
&& node.expression instanceof AST_Constant
&& !node.expression.getValue());
} | [
"function",
"is_true",
"(",
"node",
")",
"{",
"return",
"node",
"instanceof",
"AST_True",
"||",
"in_bool",
"&&",
"node",
"instanceof",
"AST_Constant",
"&&",
"node",
".",
"getValue",
"(",
")",
"||",
"(",
"node",
"instanceof",
"AST_UnaryPrefix",
"&&",
"node",
".",
"operator",
"==",
"\"!\"",
"&&",
"node",
".",
"expression",
"instanceof",
"AST_Constant",
"&&",
"!",
"node",
".",
"expression",
".",
"getValue",
"(",
")",
")",
";",
"}"
] | AST_True or !0 | [
"AST_True",
"or",
"!0"
] | 9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0 | https://github.com/kaizhu256/node-utility2/blob/9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0/lib.terser.js#L13925-L13934 | train |
kaizhu256/node-utility2 | lib.terser.js | is_false | function is_false(node) {
return node instanceof AST_False
|| in_bool
&& node instanceof AST_Constant
&& !node.getValue()
|| (node instanceof AST_UnaryPrefix
&& node.operator == "!"
&& node.expression instanceof AST_Constant
&& node.expression.getValue());
} | javascript | function is_false(node) {
return node instanceof AST_False
|| in_bool
&& node instanceof AST_Constant
&& !node.getValue()
|| (node instanceof AST_UnaryPrefix
&& node.operator == "!"
&& node.expression instanceof AST_Constant
&& node.expression.getValue());
} | [
"function",
"is_false",
"(",
"node",
")",
"{",
"return",
"node",
"instanceof",
"AST_False",
"||",
"in_bool",
"&&",
"node",
"instanceof",
"AST_Constant",
"&&",
"!",
"node",
".",
"getValue",
"(",
")",
"||",
"(",
"node",
"instanceof",
"AST_UnaryPrefix",
"&&",
"node",
".",
"operator",
"==",
"\"!\"",
"&&",
"node",
".",
"expression",
"instanceof",
"AST_Constant",
"&&",
"node",
".",
"expression",
".",
"getValue",
"(",
")",
")",
";",
"}"
] | AST_False or !1 | [
"AST_False",
"or",
"!1"
] | 9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0 | https://github.com/kaizhu256/node-utility2/blob/9ae3ed7a859b3a2b41e598db96a9f6d6594d43e0/lib.terser.js#L13936-L13945 | train |
ecomfe/htmlcs | lib/rules/tag-pair.js | function (tag) {
if (voidElements.indexOf(tag.name) < 0) {
reporter.warn(
tag.pos,
'035',
'Tag ' + tag.name + ' is not paired.'
);
}
} | javascript | function (tag) {
if (voidElements.indexOf(tag.name) < 0) {
reporter.warn(
tag.pos,
'035',
'Tag ' + tag.name + ' is not paired.'
);
}
} | [
"function",
"(",
"tag",
")",
"{",
"if",
"(",
"voidElements",
".",
"indexOf",
"(",
"tag",
".",
"name",
")",
"<",
"0",
")",
"{",
"reporter",
".",
"warn",
"(",
"tag",
".",
"pos",
",",
"'035'",
",",
"'Tag '",
"+",
"tag",
".",
"name",
"+",
"' is not paired.'",
")",
";",
"}",
"}"
] | check & report | [
"check",
"&",
"report"
] | 6703496e4a2da6081e99261fd7885c2a965eefce | https://github.com/ecomfe/htmlcs/blob/6703496e4a2da6081e99261fd7885c2a965eefce/lib/rules/tag-pair.js#L38-L46 | train |
|
Automattic/i18n-calypso | cli/preprocess-xgettextjs-match.js | concatenateBinaryExpression | function concatenateBinaryExpression( ASTNode ) {
var result;
if ( ASTNode.operator !== '+' ) {
return false;
}
result = ( 'StringLiteral' === ASTNode.left.type ) ? ASTNode.left.value : concatenateBinaryExpression( ASTNode.left );
result += ( 'StringLiteral' === ASTNode.right.type ) ? ASTNode.right.value : concatenateBinaryExpression( ASTNode.right );
return result;
} | javascript | function concatenateBinaryExpression( ASTNode ) {
var result;
if ( ASTNode.operator !== '+' ) {
return false;
}
result = ( 'StringLiteral' === ASTNode.left.type ) ? ASTNode.left.value : concatenateBinaryExpression( ASTNode.left );
result += ( 'StringLiteral' === ASTNode.right.type ) ? ASTNode.right.value : concatenateBinaryExpression( ASTNode.right );
return result;
} | [
"function",
"concatenateBinaryExpression",
"(",
"ASTNode",
")",
"{",
"var",
"result",
";",
"if",
"(",
"ASTNode",
".",
"operator",
"!==",
"'+'",
")",
"{",
"return",
"false",
";",
"}",
"result",
"=",
"(",
"'StringLiteral'",
"===",
"ASTNode",
".",
"left",
".",
"type",
")",
"?",
"ASTNode",
".",
"left",
".",
"value",
":",
"concatenateBinaryExpression",
"(",
"ASTNode",
".",
"left",
")",
";",
"result",
"+=",
"(",
"'StringLiteral'",
"===",
"ASTNode",
".",
"right",
".",
"type",
")",
"?",
"ASTNode",
".",
"right",
".",
"value",
":",
"concatenateBinaryExpression",
"(",
"ASTNode",
".",
"right",
")",
";",
"return",
"result",
";",
"}"
] | Long translation strings can be broken into multiple strings concatenated with the + operator.
This function concatenates the substrings into a single string.
@param {object} ASTNode - the BinaryExpression object returned from the AST parser
@return {string} - the concatenated string | [
"Long",
"translation",
"strings",
"can",
"be",
"broken",
"into",
"multiple",
"strings",
"concatenated",
"with",
"the",
"+",
"operator",
".",
"This",
"function",
"concatenates",
"the",
"substrings",
"into",
"a",
"single",
"string",
"."
] | 661da20f619a8679001d7332e2a7804500e3ac91 | https://github.com/Automattic/i18n-calypso/blob/661da20f619a8679001d7332e2a7804500e3ac91/cli/preprocess-xgettextjs-match.js#L79-L88 | train |
rehypejs/rehype-highlight | index.js | language | function language(node) {
var className = node.properties.className || []
var length = className.length
var index = -1
var value
while (++index < length) {
value = className[index]
if (value === 'no-highlight' || value === 'nohighlight') {
return false
}
if (value.slice(0, 5) === 'lang-') {
return value.slice(5)
}
if (value.slice(0, 9) === 'language-') {
return value.slice(9)
}
}
return null
} | javascript | function language(node) {
var className = node.properties.className || []
var length = className.length
var index = -1
var value
while (++index < length) {
value = className[index]
if (value === 'no-highlight' || value === 'nohighlight') {
return false
}
if (value.slice(0, 5) === 'lang-') {
return value.slice(5)
}
if (value.slice(0, 9) === 'language-') {
return value.slice(9)
}
}
return null
} | [
"function",
"language",
"(",
"node",
")",
"{",
"var",
"className",
"=",
"node",
".",
"properties",
".",
"className",
"||",
"[",
"]",
"var",
"length",
"=",
"className",
".",
"length",
"var",
"index",
"=",
"-",
"1",
"var",
"value",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"value",
"=",
"className",
"[",
"index",
"]",
"if",
"(",
"value",
"===",
"'no-highlight'",
"||",
"value",
"===",
"'nohighlight'",
")",
"{",
"return",
"false",
"}",
"if",
"(",
"value",
".",
"slice",
"(",
"0",
",",
"5",
")",
"===",
"'lang-'",
")",
"{",
"return",
"value",
".",
"slice",
"(",
"5",
")",
"}",
"if",
"(",
"value",
".",
"slice",
"(",
"0",
",",
"9",
")",
"===",
"'language-'",
")",
"{",
"return",
"value",
".",
"slice",
"(",
"9",
")",
"}",
"}",
"return",
"null",
"}"
] | Get the programming language of `node`. | [
"Get",
"the",
"programming",
"language",
"of",
"node",
"."
] | 684774b1b4060f050ff2ea59ca2871481dd33723 | https://github.com/rehypejs/rehype-highlight/blob/684774b1b4060f050ff2ea59ca2871481dd33723/index.js#L84-L107 | train |
molgenis/molgenis-js-rsql | src/rsql.js | getChildRsql | function getChildRsql (perhapsWrap, constraint) {
const rsql = getRsqlFromConstraint(constraint)
if (constraint.operands && constraint.operands.length === 1) {
// Skip this node, render the only child node
return getChildRsql(perhapsWrap, constraint.operands[0])
}
if (perhapsWrap && constraint.operator === 'OR') {
if (constraint.operands.length > 1) {
return `(${rsql})`
}
}
return rsql
} | javascript | function getChildRsql (perhapsWrap, constraint) {
const rsql = getRsqlFromConstraint(constraint)
if (constraint.operands && constraint.operands.length === 1) {
// Skip this node, render the only child node
return getChildRsql(perhapsWrap, constraint.operands[0])
}
if (perhapsWrap && constraint.operator === 'OR') {
if (constraint.operands.length > 1) {
return `(${rsql})`
}
}
return rsql
} | [
"function",
"getChildRsql",
"(",
"perhapsWrap",
",",
"constraint",
")",
"{",
"const",
"rsql",
"=",
"getRsqlFromConstraint",
"(",
"constraint",
")",
"if",
"(",
"constraint",
".",
"operands",
"&&",
"constraint",
".",
"operands",
".",
"length",
"===",
"1",
")",
"{",
"return",
"getChildRsql",
"(",
"perhapsWrap",
",",
"constraint",
".",
"operands",
"[",
"0",
"]",
")",
"}",
"if",
"(",
"perhapsWrap",
"&&",
"constraint",
".",
"operator",
"===",
"'OR'",
")",
"{",
"if",
"(",
"constraint",
".",
"operands",
".",
"length",
">",
"1",
")",
"{",
"return",
"`",
"${",
"rsql",
"}",
"`",
"}",
"}",
"return",
"rsql",
"}"
] | Transforms a constraint to rsql, and wraps it in brackets if needed.
Brackets are needed if the precedence of the operator in the subtree has lower precedence than the operator of the parent.
The rsql comparison operators all have higher precedence than the AND and OR operators so a simple constraint never
needs to be wrapped.
The OR operator has lower precedence than the AND operator so an OR constraint with more than one operand and an
AND parent needs to be wrapped.
@param perhapsWrap The child constraint may need to be wrapped
@param constraint the child constraint to transform to rsql
@returns {string} | [
"Transforms",
"a",
"constraint",
"to",
"rsql",
"and",
"wraps",
"it",
"in",
"brackets",
"if",
"needed",
"."
] | a15b57cd3dc8d65df63c58b588263769f565da5c | https://github.com/molgenis/molgenis-js-rsql/blob/a15b57cd3dc8d65df63c58b588263769f565da5c/src/rsql.js#L67-L79 | train |
antonmedv/jsize | index.js | build | function build (config) {
return new Promise((resolve, reject) => {
const compiler = webpack(Object.assign(config, {
output: { filename: 'file' },
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
'process.browser': true
})
]
}), (err, stats) => {
if (err || stats.hasErrors()) reject(err || new Error(stats.toString('errors-only')))
const compilation = stats.compilation
const compiler = compilation.compiler
const memoryFs = compiler.outputFileSystem
const outputFile = compilation.assets.file.existsAt
resolve(memoryFs.readFileSync(outputFile, 'utf8'))
})
compiler.outputFileSystem = new MemoryFs()
})
} | javascript | function build (config) {
return new Promise((resolve, reject) => {
const compiler = webpack(Object.assign(config, {
output: { filename: 'file' },
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"',
'process.browser': true
})
]
}), (err, stats) => {
if (err || stats.hasErrors()) reject(err || new Error(stats.toString('errors-only')))
const compilation = stats.compilation
const compiler = compilation.compiler
const memoryFs = compiler.outputFileSystem
const outputFile = compilation.assets.file.existsAt
resolve(memoryFs.readFileSync(outputFile, 'utf8'))
})
compiler.outputFileSystem = new MemoryFs()
})
} | [
"function",
"build",
"(",
"config",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"compiler",
"=",
"webpack",
"(",
"Object",
".",
"assign",
"(",
"config",
",",
"{",
"output",
":",
"{",
"filename",
":",
"'file'",
"}",
",",
"plugins",
":",
"[",
"new",
"webpack",
".",
"DefinePlugin",
"(",
"{",
"'process.env.NODE_ENV'",
":",
"'\"production\"'",
",",
"'process.browser'",
":",
"true",
"}",
")",
"]",
"}",
")",
",",
"(",
"err",
",",
"stats",
")",
"=>",
"{",
"if",
"(",
"err",
"||",
"stats",
".",
"hasErrors",
"(",
")",
")",
"reject",
"(",
"err",
"||",
"new",
"Error",
"(",
"stats",
".",
"toString",
"(",
"'errors-only'",
")",
")",
")",
"const",
"compilation",
"=",
"stats",
".",
"compilation",
"const",
"compiler",
"=",
"compilation",
".",
"compiler",
"const",
"memoryFs",
"=",
"compiler",
".",
"outputFileSystem",
"const",
"outputFile",
"=",
"compilation",
".",
"assets",
".",
"file",
".",
"existsAt",
"resolve",
"(",
"memoryFs",
".",
"readFileSync",
"(",
"outputFile",
",",
"'utf8'",
")",
")",
"}",
")",
"compiler",
".",
"outputFileSystem",
"=",
"new",
"MemoryFs",
"(",
")",
"}",
")",
"}"
] | Uses webpack to build a file in memory and return the bundle.
@param {object} config - webpack config options.
@return {Promise<string>} | [
"Uses",
"webpack",
"to",
"build",
"a",
"file",
"in",
"memory",
"and",
"return",
"the",
"bundle",
"."
] | 53bfd3d241ce07984f9e21623612f3a2236b1a47 | https://github.com/antonmedv/jsize/blob/53bfd3d241ce07984f9e21623612f3a2236b1a47/index.js#L76-L96 | train |
antonmedv/jsize | index.js | loadPaths | function loadPaths (pkg) {
const name = pkg.name
const file = pkg.path
return resolveFile(tmp, path.join(name, file)).then(entry => ({
entry: entry,
package: path.join(tmp, 'node_modules', name, 'package.json')
}))
} | javascript | function loadPaths (pkg) {
const name = pkg.name
const file = pkg.path
return resolveFile(tmp, path.join(name, file)).then(entry => ({
entry: entry,
package: path.join(tmp, 'node_modules', name, 'package.json')
}))
} | [
"function",
"loadPaths",
"(",
"pkg",
")",
"{",
"const",
"name",
"=",
"pkg",
".",
"name",
"const",
"file",
"=",
"pkg",
".",
"path",
"return",
"resolveFile",
"(",
"tmp",
",",
"path",
".",
"join",
"(",
"name",
",",
"file",
")",
")",
".",
"then",
"(",
"entry",
"=>",
"(",
"{",
"entry",
":",
"entry",
",",
"package",
":",
"path",
".",
"join",
"(",
"tmp",
",",
"'node_modules'",
",",
"name",
",",
"'package.json'",
")",
"}",
")",
")",
"}"
] | Given package details loads resolved package and entry files.
@param {object} pkg - the parsed package details.
@return {Promise} | [
"Given",
"package",
"details",
"loads",
"resolved",
"package",
"and",
"entry",
"files",
"."
] | 53bfd3d241ce07984f9e21623612f3a2236b1a47 | https://github.com/antonmedv/jsize/blob/53bfd3d241ce07984f9e21623612f3a2236b1a47/index.js#L104-L111 | train |
antonmedv/jsize | index.js | resolveFile | function resolveFile (dir, file) {
return new Promise((resolve, reject) => {
resolver.resolve({}, dir, file, (err, result) => {
if (err) reject(err)
else resolve(result)
})
})
} | javascript | function resolveFile (dir, file) {
return new Promise((resolve, reject) => {
resolver.resolve({}, dir, file, (err, result) => {
if (err) reject(err)
else resolve(result)
})
})
} | [
"function",
"resolveFile",
"(",
"dir",
",",
"file",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"resolver",
".",
"resolve",
"(",
"{",
"}",
",",
"dir",
",",
"file",
",",
"(",
"err",
",",
"result",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"reject",
"(",
"err",
")",
"else",
"resolve",
"(",
"result",
")",
"}",
")",
"}",
")",
"}"
] | Async resolve a files path using nodes module resolution.
@param {string} dir - the directory to look in.
@param {string} file - the file to find.
@return {Promise<string>} | [
"Async",
"resolve",
"a",
"files",
"path",
"using",
"nodes",
"module",
"resolution",
"."
] | 53bfd3d241ce07984f9e21623612f3a2236b1a47 | https://github.com/antonmedv/jsize/blob/53bfd3d241ce07984f9e21623612f3a2236b1a47/index.js#L120-L127 | train |
zbjornson/node-bswap | benchmark/benchmark-unaligned.js | formatNumber | function formatNumber(number) {
number = String(number).split('.');
return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') +
(number[1] ? '.' + number[1] : '');
} | javascript | function formatNumber(number) {
number = String(number).split('.');
return number[0].replace(/(?=(?:\d{3})+$)(?!\b)/g, ',') +
(number[1] ? '.' + number[1] : '');
} | [
"function",
"formatNumber",
"(",
"number",
")",
"{",
"number",
"=",
"String",
"(",
"number",
")",
".",
"split",
"(",
"'.'",
")",
";",
"return",
"number",
"[",
"0",
"]",
".",
"replace",
"(",
"/",
"(?=(?:\\d{3})+$)(?!\\b)",
"/",
"g",
",",
"','",
")",
"+",
"(",
"number",
"[",
"1",
"]",
"?",
"'.'",
"+",
"number",
"[",
"1",
"]",
":",
"''",
")",
";",
"}"
] | From benchmark.js | [
"From",
"benchmark",
".",
"js"
] | 887246d09389c0dd3e10f5824cbe758f79665170 | https://github.com/zbjornson/node-bswap/blob/887246d09389c0dd3e10f5824cbe758f79665170/benchmark/benchmark-unaligned.js#L6-L10 | train |
zbjornson/node-bswap | benchmark/benchmark-unaligned.js | formatResult | function formatResult(event, times) {
var hz = event.hz * times;
var stats = event.stats;
var size = stats.sample.length;
var pm = '\xb1';
var result = " (array length " + times + ")";
result += ' x ' + chalk.cyan(formatNumber(hz.toFixed(hz < 100 ? 2 : 0))) + ' ops/sec ' + pm +
stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)';
return result;
} | javascript | function formatResult(event, times) {
var hz = event.hz * times;
var stats = event.stats;
var size = stats.sample.length;
var pm = '\xb1';
var result = " (array length " + times + ")";
result += ' x ' + chalk.cyan(formatNumber(hz.toFixed(hz < 100 ? 2 : 0))) + ' ops/sec ' + pm +
stats.rme.toFixed(2) + '% (' + size + ' run' + (size == 1 ? '' : 's') + ' sampled)';
return result;
} | [
"function",
"formatResult",
"(",
"event",
",",
"times",
")",
"{",
"var",
"hz",
"=",
"event",
".",
"hz",
"*",
"times",
";",
"var",
"stats",
"=",
"event",
".",
"stats",
";",
"var",
"size",
"=",
"stats",
".",
"sample",
".",
"length",
";",
"var",
"pm",
"=",
"'\\xb1'",
";",
"\\xb1",
"var",
"result",
"=",
"\" (array length \"",
"+",
"times",
"+",
"\")\"",
";",
"result",
"+=",
"' x '",
"+",
"chalk",
".",
"cyan",
"(",
"formatNumber",
"(",
"hz",
".",
"toFixed",
"(",
"hz",
"<",
"100",
"?",
"2",
":",
"0",
")",
")",
")",
"+",
"' ops/sec '",
"+",
"pm",
"+",
"stats",
".",
"rme",
".",
"toFixed",
"(",
"2",
")",
"+",
"'% ('",
"+",
"size",
"+",
"' run'",
"+",
"(",
"size",
"==",
"1",
"?",
"''",
":",
"'s'",
")",
"+",
"' sampled)'",
";",
"}"
] | Modified from benchmark.js | [
"Modified",
"from",
"benchmark",
".",
"js"
] | 887246d09389c0dd3e10f5824cbe758f79665170 | https://github.com/zbjornson/node-bswap/blob/887246d09389c0dd3e10f5824cbe758f79665170/benchmark/benchmark-unaligned.js#L17-L29 | train |
naistran/vdom-to-html | create-attribute.js | createAttribute | function createAttribute(name, value, isAttribute) {
if (properties.hasOwnProperty(name)) {
if (shouldSkip(name, value)) return '';
name = (attributeNames[name] || name).toLowerCase();
var attrType = properties[name];
// for BOOLEAN `value` only has to be truthy
// for OVERLOADED_BOOLEAN `value` has to be === true
if ((attrType === types.BOOLEAN) ||
(attrType === types.OVERLOADED_BOOLEAN && value === true)) {
return escape(name);
}
return prefixAttribute(name) + escape(value) + '"';
} else if (isAttribute) {
if (value == null) return '';
return prefixAttribute(name) + escape(value) + '"';
}
// return null if `name` is neither a valid property nor an attribute
return null;
} | javascript | function createAttribute(name, value, isAttribute) {
if (properties.hasOwnProperty(name)) {
if (shouldSkip(name, value)) return '';
name = (attributeNames[name] || name).toLowerCase();
var attrType = properties[name];
// for BOOLEAN `value` only has to be truthy
// for OVERLOADED_BOOLEAN `value` has to be === true
if ((attrType === types.BOOLEAN) ||
(attrType === types.OVERLOADED_BOOLEAN && value === true)) {
return escape(name);
}
return prefixAttribute(name) + escape(value) + '"';
} else if (isAttribute) {
if (value == null) return '';
return prefixAttribute(name) + escape(value) + '"';
}
// return null if `name` is neither a valid property nor an attribute
return null;
} | [
"function",
"createAttribute",
"(",
"name",
",",
"value",
",",
"isAttribute",
")",
"{",
"if",
"(",
"properties",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"if",
"(",
"shouldSkip",
"(",
"name",
",",
"value",
")",
")",
"return",
"''",
";",
"name",
"=",
"(",
"attributeNames",
"[",
"name",
"]",
"||",
"name",
")",
".",
"toLowerCase",
"(",
")",
";",
"var",
"attrType",
"=",
"properties",
"[",
"name",
"]",
";",
"if",
"(",
"(",
"attrType",
"===",
"types",
".",
"BOOLEAN",
")",
"||",
"(",
"attrType",
"===",
"types",
".",
"OVERLOADED_BOOLEAN",
"&&",
"value",
"===",
"true",
")",
")",
"{",
"return",
"escape",
"(",
"name",
")",
";",
"}",
"return",
"prefixAttribute",
"(",
"name",
")",
"+",
"escape",
"(",
"value",
")",
"+",
"'\"'",
";",
"}",
"else",
"if",
"(",
"isAttribute",
")",
"{",
"if",
"(",
"value",
"==",
"null",
")",
"return",
"''",
";",
"return",
"prefixAttribute",
"(",
"name",
")",
"+",
"escape",
"(",
"value",
")",
"+",
"'\"'",
";",
"}",
"return",
"null",
";",
"}"
] | Create attribute string.
@param {String} name The name of the property or attribute
@param {*} value The value
@param {Boolean} [isAttribute] Denotes whether `name` is an attribute.
@return {?String} Attribute string || null if not a valid property or custom attribute. | [
"Create",
"attribute",
"string",
"."
] | 6999583bd348795671c46361349fef9b227ae469 | https://github.com/naistran/vdom-to-html/blob/6999583bd348795671c46361349fef9b227ae469/create-attribute.js#L22-L40 | train |
naistran/vdom-to-html | create-attribute.js | shouldSkip | function shouldSkip(name, value) {
var attrType = properties[name];
return value == null ||
(attrType === types.BOOLEAN && !value) ||
(attrType === types.OVERLOADED_BOOLEAN && value === false);
} | javascript | function shouldSkip(name, value) {
var attrType = properties[name];
return value == null ||
(attrType === types.BOOLEAN && !value) ||
(attrType === types.OVERLOADED_BOOLEAN && value === false);
} | [
"function",
"shouldSkip",
"(",
"name",
",",
"value",
")",
"{",
"var",
"attrType",
"=",
"properties",
"[",
"name",
"]",
";",
"return",
"value",
"==",
"null",
"||",
"(",
"attrType",
"===",
"types",
".",
"BOOLEAN",
"&&",
"!",
"value",
")",
"||",
"(",
"attrType",
"===",
"types",
".",
"OVERLOADED_BOOLEAN",
"&&",
"value",
"===",
"false",
")",
";",
"}"
] | Should skip false boolean attributes. | [
"Should",
"skip",
"false",
"boolean",
"attributes",
"."
] | 6999583bd348795671c46361349fef9b227ae469 | https://github.com/naistran/vdom-to-html/blob/6999583bd348795671c46361349fef9b227ae469/create-attribute.js#L46-L51 | train |
senecajs/seneca-user | user.js | round | function round() {
i++
var shasum = Crypto.createHash('sha512')
shasum.update(out, 'utf8')
out = shasum.digest('hex')
if (rounds <= i) {
return done(out)
}
if (0 === i % 88) {
return process.nextTick(round)
}
round()
} | javascript | function round() {
i++
var shasum = Crypto.createHash('sha512')
shasum.update(out, 'utf8')
out = shasum.digest('hex')
if (rounds <= i) {
return done(out)
}
if (0 === i % 88) {
return process.nextTick(round)
}
round()
} | [
"function",
"round",
"(",
")",
"{",
"i",
"++",
"var",
"shasum",
"=",
"Crypto",
".",
"createHash",
"(",
"'sha512'",
")",
"shasum",
".",
"update",
"(",
"out",
",",
"'utf8'",
")",
"out",
"=",
"shasum",
".",
"digest",
"(",
"'hex'",
")",
"if",
"(",
"rounds",
"<=",
"i",
")",
"{",
"return",
"done",
"(",
"out",
")",
"}",
"if",
"(",
"0",
"===",
"i",
"%",
"88",
")",
"{",
"return",
"process",
".",
"nextTick",
"(",
"round",
")",
"}",
"round",
"(",
")",
"}"
] | don't chew up the CPU | [
"don",
"t",
"chew",
"up",
"the",
"CPU"
] | fde6d4e86b0cc8ed3ee23c82dff822e933b3d835 | https://github.com/senecajs/seneca-user/blob/fde6d4e86b0cc8ed3ee23c82dff822e933b3d835/user.js#L365-L377 | train |
senecajs/seneca-user | user.js | checkemail | function checkemail(next) {
if (user.email) {
userent.load$({ email: user.email }, function(err, userfound) {
if (err) return done(err, { ok: false, user: user })
if (userfound)
return done(null, {
ok: false,
why: 'email-exists',
nick: args.nick
})
next()
})
return
}
next()
} | javascript | function checkemail(next) {
if (user.email) {
userent.load$({ email: user.email }, function(err, userfound) {
if (err) return done(err, { ok: false, user: user })
if (userfound)
return done(null, {
ok: false,
why: 'email-exists',
nick: args.nick
})
next()
})
return
}
next()
} | [
"function",
"checkemail",
"(",
"next",
")",
"{",
"if",
"(",
"user",
".",
"email",
")",
"{",
"userent",
".",
"load$",
"(",
"{",
"email",
":",
"user",
".",
"email",
"}",
",",
"function",
"(",
"err",
",",
"userfound",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
",",
"{",
"ok",
":",
"false",
",",
"user",
":",
"user",
"}",
")",
"if",
"(",
"userfound",
")",
"return",
"done",
"(",
"null",
",",
"{",
"ok",
":",
"false",
",",
"why",
":",
"'email-exists'",
",",
"nick",
":",
"args",
".",
"nick",
"}",
")",
"next",
"(",
")",
"}",
")",
"return",
"}",
"next",
"(",
")",
"}"
] | unsafe email unique check, data store should also enforce !! | [
"unsafe",
"email",
"unique",
"check",
"data",
"store",
"should",
"also",
"enforce",
"!!"
] | fde6d4e86b0cc8ed3ee23c82dff822e933b3d835 | https://github.com/senecajs/seneca-user/blob/fde6d4e86b0cc8ed3ee23c82dff822e933b3d835/user.js#L592-L607 | train |
senecajs/seneca-user | user.js | checknick | function checknick(next) {
if (args.nick) {
userent.list$({ nick: args.nick }, function(err, users) {
if (err) return done(err, { ok: false, user: user })
for (var i = 0; i < users.length; i++) {
var each = users[i]
if (each.id !== user.id) {
return done(null, {
ok: false,
why: 'nick-exists',
nick: args.nick
})
}
}
next()
})
return
}
next()
} | javascript | function checknick(next) {
if (args.nick) {
userent.list$({ nick: args.nick }, function(err, users) {
if (err) return done(err, { ok: false, user: user })
for (var i = 0; i < users.length; i++) {
var each = users[i]
if (each.id !== user.id) {
return done(null, {
ok: false,
why: 'nick-exists',
nick: args.nick
})
}
}
next()
})
return
}
next()
} | [
"function",
"checknick",
"(",
"next",
")",
"{",
"if",
"(",
"args",
".",
"nick",
")",
"{",
"userent",
".",
"list$",
"(",
"{",
"nick",
":",
"args",
".",
"nick",
"}",
",",
"function",
"(",
"err",
",",
"users",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
",",
"{",
"ok",
":",
"false",
",",
"user",
":",
"user",
"}",
")",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"users",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"each",
"=",
"users",
"[",
"i",
"]",
"if",
"(",
"each",
".",
"id",
"!==",
"user",
".",
"id",
")",
"{",
"return",
"done",
"(",
"null",
",",
"{",
"ok",
":",
"false",
",",
"why",
":",
"'nick-exists'",
",",
"nick",
":",
"args",
".",
"nick",
"}",
")",
"}",
"}",
"next",
"(",
")",
"}",
")",
"return",
"}",
"next",
"(",
")",
"}"
] | unsafe nick unique check, data store should also enforce !! | [
"unsafe",
"nick",
"unique",
"check",
"data",
"store",
"should",
"also",
"enforce",
"!!"
] | fde6d4e86b0cc8ed3ee23c82dff822e933b3d835 | https://github.com/senecajs/seneca-user/blob/fde6d4e86b0cc8ed3ee23c82dff822e933b3d835/user.js#L1162-L1182 | train |
senecajs/seneca-user | user.js | cmd_clean | function cmd_clean(args, done) {
var user = args.user.data$()
delete user.pass
delete user.salt
delete user.active
delete user.$
done(null, user)
} | javascript | function cmd_clean(args, done) {
var user = args.user.data$()
delete user.pass
delete user.salt
delete user.active
delete user.$
done(null, user)
} | [
"function",
"cmd_clean",
"(",
"args",
",",
"done",
")",
"{",
"var",
"user",
"=",
"args",
".",
"user",
".",
"data$",
"(",
")",
"delete",
"user",
".",
"pass",
"delete",
"user",
".",
"salt",
"delete",
"user",
".",
"active",
"delete",
"user",
".",
"$",
"done",
"(",
"null",
",",
"user",
")",
"}"
] | DEPRECATED - do this in seneca-auth | [
"DEPRECATED",
"-",
"do",
"this",
"in",
"seneca",
"-",
"auth"
] | fde6d4e86b0cc8ed3ee23c82dff822e933b3d835 | https://github.com/senecajs/seneca-user/blob/fde6d4e86b0cc8ed3ee23c82dff822e933b3d835/user.js#L1275-L1282 | train |
MeadCo/ScriptX.Print.Client | src/meadco-core.js | function (namespace) {
var nsparts = namespace.split(".");
var parent = module.scope.MeadCo;
// we want to be able to include or exclude the root namespace so we strip
// it if it's in the namespace
if (nsparts[0] === "MeadCo") {
nsparts = nsparts.slice(1);
}
// loop through the parts and create a nested namespace if necessary
for (var i = 0; i < nsparts.length; i++) {
var partname = nsparts[i];
// check if the current parent already has the namespace declared
// if it isn't, then create it
if (typeof parent[partname] === "undefined") {
parent[partname] = {};
}
// get a reference to the deepest element in the hierarchy so far
parent = parent[partname];
}
// the parent is now constructed with empty namespaces and can be used.
// we return the outermost namespace
return parent;
} | javascript | function (namespace) {
var nsparts = namespace.split(".");
var parent = module.scope.MeadCo;
// we want to be able to include or exclude the root namespace so we strip
// it if it's in the namespace
if (nsparts[0] === "MeadCo") {
nsparts = nsparts.slice(1);
}
// loop through the parts and create a nested namespace if necessary
for (var i = 0; i < nsparts.length; i++) {
var partname = nsparts[i];
// check if the current parent already has the namespace declared
// if it isn't, then create it
if (typeof parent[partname] === "undefined") {
parent[partname] = {};
}
// get a reference to the deepest element in the hierarchy so far
parent = parent[partname];
}
// the parent is now constructed with empty namespaces and can be used.
// we return the outermost namespace
return parent;
} | [
"function",
"(",
"namespace",
")",
"{",
"var",
"nsparts",
"=",
"namespace",
".",
"split",
"(",
"\".\"",
")",
";",
"var",
"parent",
"=",
"module",
".",
"scope",
".",
"MeadCo",
";",
"if",
"(",
"nsparts",
"[",
"0",
"]",
"===",
"\"MeadCo\"",
")",
"{",
"nsparts",
"=",
"nsparts",
".",
"slice",
"(",
"1",
")",
";",
"}",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"nsparts",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"partname",
"=",
"nsparts",
"[",
"i",
"]",
";",
"if",
"(",
"typeof",
"parent",
"[",
"partname",
"]",
"===",
"\"undefined\"",
")",
"{",
"parent",
"[",
"partname",
"]",
"=",
"{",
"}",
";",
"}",
"parent",
"=",
"parent",
"[",
"partname",
"]",
";",
"}",
"return",
"parent",
";",
"}"
] | Create a namespace
@function createNS
@memberof MeadCo
@param {string} namespace path of the namespace
@returns {object} static object for the namespace
@example
var ui = MeadCo.createNS("MeadCo.ScriptX.Print.UI");
ui.Show = function() { alert("hello"); } | [
"Create",
"a",
"namespace"
] | 53d2c8b8e2178fd79166abcfc2c103f9c46f792e | https://github.com/MeadCo/ScriptX.Print.Client/blob/53d2c8b8e2178fd79166abcfc2c103f9c46f792e/src/meadco-core.js#L210-L234 | train |
|
MeadCo/ScriptX.Print.Client | src/meadco-core.js | function (serverUrl, apiLocation) {
// check if given partial ...
var p = serverUrl.indexOf("/api");
if (p === -1) {
if (serverUrl.lastIndexOf("/") !== (serverUrl.length - 1)) {
serverUrl += "/";
}
serverUrl += "api/" + apiLocation;
}
else {
// given another api, chop and replace with requested api
serverUrl = serverUrl.substr(0, p) + "/api/" + apiLocation;
}
return serverUrl;
} | javascript | function (serverUrl, apiLocation) {
// check if given partial ...
var p = serverUrl.indexOf("/api");
if (p === -1) {
if (serverUrl.lastIndexOf("/") !== (serverUrl.length - 1)) {
serverUrl += "/";
}
serverUrl += "api/" + apiLocation;
}
else {
// given another api, chop and replace with requested api
serverUrl = serverUrl.substr(0, p) + "/api/" + apiLocation;
}
return serverUrl;
} | [
"function",
"(",
"serverUrl",
",",
"apiLocation",
")",
"{",
"var",
"p",
"=",
"serverUrl",
".",
"indexOf",
"(",
"\"/api\"",
")",
";",
"if",
"(",
"p",
"===",
"-",
"1",
")",
"{",
"if",
"(",
"serverUrl",
".",
"lastIndexOf",
"(",
"\"/\"",
")",
"!==",
"(",
"serverUrl",
".",
"length",
"-",
"1",
")",
")",
"{",
"serverUrl",
"+=",
"\"/\"",
";",
"}",
"serverUrl",
"+=",
"\"api/\"",
"+",
"apiLocation",
";",
"}",
"else",
"{",
"serverUrl",
"=",
"serverUrl",
".",
"substr",
"(",
"0",
",",
"p",
")",
"+",
"\"/api/\"",
"+",
"apiLocation",
";",
"}",
"return",
"serverUrl",
";",
"}"
] | Get the url to a ScriptX.Services api endpoint. If an enpoint is already present, it is replaced.
@function makeApiEndPoint
@memberof MeadCo
@param {string} serverUrl url to the server
@param {string} apiLocation the api, e.g. v1/printhtml
@returns {string} url to the api | [
"Get",
"the",
"url",
"to",
"a",
"ScriptX",
".",
"Services",
"api",
"endpoint",
".",
"If",
"an",
"enpoint",
"is",
"already",
"present",
"it",
"is",
"replaced",
"."
] | 53d2c8b8e2178fd79166abcfc2c103f9c46f792e | https://github.com/MeadCo/ScriptX.Print.Client/blob/53d2c8b8e2178fd79166abcfc2c103f9c46f792e/src/meadco-core.js#L251-L265 | train |
|
MeadCo/ScriptX.Print.Client | src/jQuery-MeadCo.ScriptX.Print.UI.js | showPrinterSettings | function showPrinterSettings() {
fillAndSetBinsList();
var $dlg = $('#dlg-printersettings');
var printer = MeadCo.ScriptX.Printing;
$dlg.find('#fld-collate').prop('checked', printer.collate);
$dlg.find('#fld-copies').val(printer.copies);
} | javascript | function showPrinterSettings() {
fillAndSetBinsList();
var $dlg = $('#dlg-printersettings');
var printer = MeadCo.ScriptX.Printing;
$dlg.find('#fld-collate').prop('checked', printer.collate);
$dlg.find('#fld-copies').val(printer.copies);
} | [
"function",
"showPrinterSettings",
"(",
")",
"{",
"fillAndSetBinsList",
"(",
")",
";",
"var",
"$dlg",
"=",
"$",
"(",
"'#dlg-printersettings'",
")",
";",
"var",
"printer",
"=",
"MeadCo",
".",
"ScriptX",
".",
"Printing",
";",
"$dlg",
".",
"find",
"(",
"'#fld-collate'",
")",
".",
"prop",
"(",
"'checked'",
",",
"printer",
".",
"collate",
")",
";",
"$dlg",
".",
"find",
"(",
"'#fld-copies'",
")",
".",
"val",
"(",
"printer",
".",
"copies",
")",
";",
"}"
] | show available sources and options | [
"show",
"available",
"sources",
"and",
"options"
] | 53d2c8b8e2178fd79166abcfc2c103f9c46f792e | https://github.com/MeadCo/ScriptX.Print.Client/blob/53d2c8b8e2178fd79166abcfc2c103f9c46f792e/src/jQuery-MeadCo.ScriptX.Print.UI.js#L428-L437 | train |
MeadCo/ScriptX.Print.Client | src/jQuery-MeadCo.ScriptX.Print.UI.js | fillPrintersList | function fillPrintersList() {
var printer = MeadCo.ScriptX.Printing;
var $printers = $('#fld-printerselect');
$('#fld-printerselect > option').remove();
var name;
for (var i = 0; (name = printer.EnumPrinters(i)).length > 0 ; i++) {
$printers.append("<option>" + name);
}
$printers.val(printer.currentPrinter);
if ($printers.hasClass("selectpicker")) {
$printers.selectpicker('refresh');
}
} | javascript | function fillPrintersList() {
var printer = MeadCo.ScriptX.Printing;
var $printers = $('#fld-printerselect');
$('#fld-printerselect > option').remove();
var name;
for (var i = 0; (name = printer.EnumPrinters(i)).length > 0 ; i++) {
$printers.append("<option>" + name);
}
$printers.val(printer.currentPrinter);
if ($printers.hasClass("selectpicker")) {
$printers.selectpicker('refresh');
}
} | [
"function",
"fillPrintersList",
"(",
")",
"{",
"var",
"printer",
"=",
"MeadCo",
".",
"ScriptX",
".",
"Printing",
";",
"var",
"$printers",
"=",
"$",
"(",
"'#fld-printerselect'",
")",
";",
"$",
"(",
"'#fld-printerselect > option'",
")",
".",
"remove",
"(",
")",
";",
"var",
"name",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"(",
"name",
"=",
"printer",
".",
"EnumPrinters",
"(",
"i",
")",
")",
".",
"length",
">",
"0",
";",
"i",
"++",
")",
"{",
"$printers",
".",
"append",
"(",
"\"<option>\"",
"+",
"name",
")",
";",
"}",
"$printers",
".",
"val",
"(",
"printer",
".",
"currentPrinter",
")",
";",
"if",
"(",
"$printers",
".",
"hasClass",
"(",
"\"selectpicker\"",
")",
")",
"{",
"$printers",
".",
"selectpicker",
"(",
"'refresh'",
")",
";",
"}",
"}"
] | fill printers dropdown with those available | [
"fill",
"printers",
"dropdown",
"with",
"those",
"available"
] | 53d2c8b8e2178fd79166abcfc2c103f9c46f792e | https://github.com/MeadCo/ScriptX.Print.Client/blob/53d2c8b8e2178fd79166abcfc2c103f9c46f792e/src/jQuery-MeadCo.ScriptX.Print.UI.js#L480-L495 | train |
oldtimeguitarguy/angular-middleware | dist/angular-middleware.js | concatMiddlewareNames | function concatMiddlewareNames(routes) {
var output = [];
// Concat each route's middleware names
for (var i = 0; i < routes.length; i++) {
output = output.concat(
getMiddlewareNames(routes[i])
);
}
return output;
} | javascript | function concatMiddlewareNames(routes) {
var output = [];
// Concat each route's middleware names
for (var i = 0; i < routes.length; i++) {
output = output.concat(
getMiddlewareNames(routes[i])
);
}
return output;
} | [
"function",
"concatMiddlewareNames",
"(",
"routes",
")",
"{",
"var",
"output",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"routes",
".",
"length",
";",
"i",
"++",
")",
"{",
"output",
"=",
"output",
".",
"concat",
"(",
"getMiddlewareNames",
"(",
"routes",
"[",
"i",
"]",
")",
")",
";",
"}",
"return",
"output",
";",
"}"
] | Concat the middleware names of the given routes
@param {array} routes
@return {array} | [
"Concat",
"the",
"middleware",
"names",
"of",
"the",
"given",
"routes"
] | 3606c3d14400636f9e8530814c2438c5a5858318 | https://github.com/oldtimeguitarguy/angular-middleware/blob/3606c3d14400636f9e8530814c2438c5a5858318/dist/angular-middleware.js#L129-L140 | train |
oldtimeguitarguy/angular-middleware | dist/angular-middleware.js | getMiddlewareNames | function getMiddlewareNames(route) {
var middleware = getRouteMiddleware(route);
// If the middleware is an array, just return it
if ( middleware instanceof Array ) {
return middleware;
}
// If there is no middleware, then return an empty array
if ( typeof middleware === 'undefined' ) {
return [];
}
// Otherwise, split the pipes & return an array
return middleware.split('|');
} | javascript | function getMiddlewareNames(route) {
var middleware = getRouteMiddleware(route);
// If the middleware is an array, just return it
if ( middleware instanceof Array ) {
return middleware;
}
// If there is no middleware, then return an empty array
if ( typeof middleware === 'undefined' ) {
return [];
}
// Otherwise, split the pipes & return an array
return middleware.split('|');
} | [
"function",
"getMiddlewareNames",
"(",
"route",
")",
"{",
"var",
"middleware",
"=",
"getRouteMiddleware",
"(",
"route",
")",
";",
"if",
"(",
"middleware",
"instanceof",
"Array",
")",
"{",
"return",
"middleware",
";",
"}",
"if",
"(",
"typeof",
"middleware",
"===",
"'undefined'",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"middleware",
".",
"split",
"(",
"'|'",
")",
";",
"}"
] | Get the middleware names
from an array or a piped string
@param {object} route
@returns {array} | [
"Get",
"the",
"middleware",
"names",
"from",
"an",
"array",
"or",
"a",
"piped",
"string"
] | 3606c3d14400636f9e8530814c2438c5a5858318 | https://github.com/oldtimeguitarguy/angular-middleware/blob/3606c3d14400636f9e8530814c2438c5a5858318/dist/angular-middleware.js#L149-L164 | train |
oldtimeguitarguy/angular-middleware | dist/angular-middleware.js | nextMiddleware | function nextMiddleware() {
// Get the next middleware
var next = _mappings[middleware.names[middleware.index++]];
// If there is middleware, then invoke it, binding request
if ( next ) $injector.invoke(next, request);
} | javascript | function nextMiddleware() {
// Get the next middleware
var next = _mappings[middleware.names[middleware.index++]];
// If there is middleware, then invoke it, binding request
if ( next ) $injector.invoke(next, request);
} | [
"function",
"nextMiddleware",
"(",
")",
"{",
"var",
"next",
"=",
"_mappings",
"[",
"middleware",
".",
"names",
"[",
"middleware",
".",
"index",
"++",
"]",
"]",
";",
"if",
"(",
"next",
")",
"$injector",
".",
"invoke",
"(",
"next",
",",
"request",
")",
";",
"}"
] | Attempt to invoke the next middleware
@returns {void} | [
"Attempt",
"to",
"invoke",
"the",
"next",
"middleware"
] | 3606c3d14400636f9e8530814c2438c5a5858318 | https://github.com/oldtimeguitarguy/angular-middleware/blob/3606c3d14400636f9e8530814c2438c5a5858318/dist/angular-middleware.js#L171-L177 | train |
oldtimeguitarguy/angular-middleware | dist/angular-middleware.js | nextRequest | function nextRequest() {
// If there are no more middleware,
// then resolve the middleware resolution
if ( middleware.index == middleware.names.length ) {
middleware.resolution.resolve();
}
// Attempt to invoke the next middleware
middleware.next();
} | javascript | function nextRequest() {
// If there are no more middleware,
// then resolve the middleware resolution
if ( middleware.index == middleware.names.length ) {
middleware.resolution.resolve();
}
// Attempt to invoke the next middleware
middleware.next();
} | [
"function",
"nextRequest",
"(",
")",
"{",
"if",
"(",
"middleware",
".",
"index",
"==",
"middleware",
".",
"names",
".",
"length",
")",
"{",
"middleware",
".",
"resolution",
".",
"resolve",
"(",
")",
";",
"}",
"middleware",
".",
"next",
"(",
")",
";",
"}"
] | Go to the next request.
If there are more middleware,
then go to the next middleware.
Otherwise, resolve the middleware resolution.
@returns {void} | [
"Go",
"to",
"the",
"next",
"request",
".",
"If",
"there",
"are",
"more",
"middleware",
"then",
"go",
"to",
"the",
"next",
"middleware",
".",
"Otherwise",
"resolve",
"the",
"middleware",
"resolution",
"."
] | 3606c3d14400636f9e8530814c2438c5a5858318 | https://github.com/oldtimeguitarguy/angular-middleware/blob/3606c3d14400636f9e8530814c2438c5a5858318/dist/angular-middleware.js#L187-L196 | train |
oldtimeguitarguy/angular-middleware | dist/angular-middleware.js | redirectTo | function redirectTo(route, params, options) {
middleware.resolution.reject({
type: "redirectTo",
route: route,
params: params,
options: options
});
} | javascript | function redirectTo(route, params, options) {
middleware.resolution.reject({
type: "redirectTo",
route: route,
params: params,
options: options
});
} | [
"function",
"redirectTo",
"(",
"route",
",",
"params",
",",
"options",
")",
"{",
"middleware",
".",
"resolution",
".",
"reject",
"(",
"{",
"type",
":",
"\"redirectTo\"",
",",
"route",
":",
"route",
",",
"params",
":",
"params",
",",
"options",
":",
"options",
"}",
")",
";",
"}"
] | Redirect to another route
@returns {void} | [
"Redirect",
"to",
"another",
"route"
] | 3606c3d14400636f9e8530814c2438c5a5858318 | https://github.com/oldtimeguitarguy/angular-middleware/blob/3606c3d14400636f9e8530814c2438c5a5858318/dist/angular-middleware.js#L203-L210 | train |
martinsbalodis/css-selector | lib/CssSelector.js | function (mergeSelector) {
if (this.tag !== mergeSelector.tag) {
throw "different element selected (tag)";
}
if (this.index !== null) {
if (this.index !== mergeSelector.index) {
// use indexn only for two elements
if (this.indexn === null) {
var indexn = Math.min(mergeSelector.index, this.index);
if (indexn > 1) {
this.indexn = Math.min(mergeSelector.index, this.index);
}
}
else {
this.indexn = -1;
}
this.index = null;
}
}
if(this.isDirectChild === true) {
this.isDirectChild = mergeSelector.isDirectChild;
}
if (this.id !== null) {
if (this.id !== mergeSelector.id) {
this.id = null;
}
}
if (this.classes.length !== 0) {
var classes = new Array();
for (var i in this.classes) {
var cclass = this.classes[i];
if (mergeSelector.classes.indexOf(cclass) !== -1) {
classes.push(cclass);
}
}
this.classes = classes;
}
} | javascript | function (mergeSelector) {
if (this.tag !== mergeSelector.tag) {
throw "different element selected (tag)";
}
if (this.index !== null) {
if (this.index !== mergeSelector.index) {
// use indexn only for two elements
if (this.indexn === null) {
var indexn = Math.min(mergeSelector.index, this.index);
if (indexn > 1) {
this.indexn = Math.min(mergeSelector.index, this.index);
}
}
else {
this.indexn = -1;
}
this.index = null;
}
}
if(this.isDirectChild === true) {
this.isDirectChild = mergeSelector.isDirectChild;
}
if (this.id !== null) {
if (this.id !== mergeSelector.id) {
this.id = null;
}
}
if (this.classes.length !== 0) {
var classes = new Array();
for (var i in this.classes) {
var cclass = this.classes[i];
if (mergeSelector.classes.indexOf(cclass) !== -1) {
classes.push(cclass);
}
}
this.classes = classes;
}
} | [
"function",
"(",
"mergeSelector",
")",
"{",
"if",
"(",
"this",
".",
"tag",
"!==",
"mergeSelector",
".",
"tag",
")",
"{",
"throw",
"\"different element selected (tag)\"",
";",
"}",
"if",
"(",
"this",
".",
"index",
"!==",
"null",
")",
"{",
"if",
"(",
"this",
".",
"index",
"!==",
"mergeSelector",
".",
"index",
")",
"{",
"if",
"(",
"this",
".",
"indexn",
"===",
"null",
")",
"{",
"var",
"indexn",
"=",
"Math",
".",
"min",
"(",
"mergeSelector",
".",
"index",
",",
"this",
".",
"index",
")",
";",
"if",
"(",
"indexn",
">",
"1",
")",
"{",
"this",
".",
"indexn",
"=",
"Math",
".",
"min",
"(",
"mergeSelector",
".",
"index",
",",
"this",
".",
"index",
")",
";",
"}",
"}",
"else",
"{",
"this",
".",
"indexn",
"=",
"-",
"1",
";",
"}",
"this",
".",
"index",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"this",
".",
"isDirectChild",
"===",
"true",
")",
"{",
"this",
".",
"isDirectChild",
"=",
"mergeSelector",
".",
"isDirectChild",
";",
"}",
"if",
"(",
"this",
".",
"id",
"!==",
"null",
")",
"{",
"if",
"(",
"this",
".",
"id",
"!==",
"mergeSelector",
".",
"id",
")",
"{",
"this",
".",
"id",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"this",
".",
"classes",
".",
"length",
"!==",
"0",
")",
"{",
"var",
"classes",
"=",
"new",
"Array",
"(",
")",
";",
"for",
"(",
"var",
"i",
"in",
"this",
".",
"classes",
")",
"{",
"var",
"cclass",
"=",
"this",
".",
"classes",
"[",
"i",
"]",
";",
"if",
"(",
"mergeSelector",
".",
"classes",
".",
"indexOf",
"(",
"cclass",
")",
"!==",
"-",
"1",
")",
"{",
"classes",
".",
"push",
"(",
"cclass",
")",
";",
"}",
"}",
"this",
".",
"classes",
"=",
"classes",
";",
"}",
"}"
] | merges this selector with another one. | [
"merges",
"this",
"selector",
"with",
"another",
"one",
"."
] | d9c20445ae0b8635ccd8c837cb1efc8d455e1a37 | https://github.com/martinsbalodis/css-selector/blob/d9c20445ae0b8635ccd8c837cb1efc8d455e1a37/lib/CssSelector.js#L160-L206 | train |
|
martinsbalodis/css-selector | lib/CssSelector.js | function(element1, element2) {
while (true) {
if(element1.tagName !== element2.tagName) {
return false;
}
if(element1 === element2) {
return true;
}
// stop at body tag
if (element1 === undefined || element1.tagName === 'body'
|| element1.tagName === 'BODY') {
return false;
}
if (element2 === undefined || element2.tagName === 'body'
|| element2.tagName === 'BODY') {
return false;
}
element1 = element1.parentNode;
element2 = element2.parentNode;
}
} | javascript | function(element1, element2) {
while (true) {
if(element1.tagName !== element2.tagName) {
return false;
}
if(element1 === element2) {
return true;
}
// stop at body tag
if (element1 === undefined || element1.tagName === 'body'
|| element1.tagName === 'BODY') {
return false;
}
if (element2 === undefined || element2.tagName === 'body'
|| element2.tagName === 'BODY') {
return false;
}
element1 = element1.parentNode;
element2 = element2.parentNode;
}
} | [
"function",
"(",
"element1",
",",
"element2",
")",
"{",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"element1",
".",
"tagName",
"!==",
"element2",
".",
"tagName",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"element1",
"===",
"element2",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"element1",
"===",
"undefined",
"||",
"element1",
".",
"tagName",
"===",
"'body'",
"||",
"element1",
".",
"tagName",
"===",
"'BODY'",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"element2",
"===",
"undefined",
"||",
"element2",
".",
"tagName",
"===",
"'body'",
"||",
"element2",
".",
"tagName",
"===",
"'BODY'",
")",
"{",
"return",
"false",
";",
"}",
"element1",
"=",
"element1",
".",
"parentNode",
";",
"element2",
"=",
"element2",
".",
"parentNode",
";",
"}",
"}"
] | Compares whether two elements are similar. Similar elements should
have a common parrent and all parent elements should be the same type.
@param element1
@param element2 | [
"Compares",
"whether",
"two",
"elements",
"are",
"similar",
".",
"Similar",
"elements",
"should",
"have",
"a",
"common",
"parrent",
"and",
"all",
"parent",
"elements",
"should",
"be",
"the",
"same",
"type",
"."
] | d9c20445ae0b8635ccd8c837cb1efc8d455e1a37 | https://github.com/martinsbalodis/css-selector/blob/d9c20445ae0b8635ccd8c837cb1efc8d455e1a37/lib/CssSelector.js#L382-L406 | train |
|
martinsbalodis/css-selector | lib/CssSelector.js | function(elements) {
// first elment is in the first group
// @TODO maybe i dont need this?
var groups = [[elements[0]]];
for(var i = 1; i < elements.length; i++) {
var elementNew = elements[i];
var addedToGroup = false;
for(var j = 0; j < groups.length; j++) {
var group = groups[j];
var elementGroup = group[0];
if(this.checkSimilarElements(elementNew, elementGroup)) {
group.push(elementNew);
addedToGroup = true;
break;
}
}
// add new group
if(!addedToGroup) {
groups.push([elementNew]);
}
}
return groups;
} | javascript | function(elements) {
// first elment is in the first group
// @TODO maybe i dont need this?
var groups = [[elements[0]]];
for(var i = 1; i < elements.length; i++) {
var elementNew = elements[i];
var addedToGroup = false;
for(var j = 0; j < groups.length; j++) {
var group = groups[j];
var elementGroup = group[0];
if(this.checkSimilarElements(elementNew, elementGroup)) {
group.push(elementNew);
addedToGroup = true;
break;
}
}
// add new group
if(!addedToGroup) {
groups.push([elementNew]);
}
}
return groups;
} | [
"function",
"(",
"elements",
")",
"{",
"var",
"groups",
"=",
"[",
"[",
"elements",
"[",
"0",
"]",
"]",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"elements",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"elementNew",
"=",
"elements",
"[",
"i",
"]",
";",
"var",
"addedToGroup",
"=",
"false",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"groups",
".",
"length",
";",
"j",
"++",
")",
"{",
"var",
"group",
"=",
"groups",
"[",
"j",
"]",
";",
"var",
"elementGroup",
"=",
"group",
"[",
"0",
"]",
";",
"if",
"(",
"this",
".",
"checkSimilarElements",
"(",
"elementNew",
",",
"elementGroup",
")",
")",
"{",
"group",
".",
"push",
"(",
"elementNew",
")",
";",
"addedToGroup",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"addedToGroup",
")",
"{",
"groups",
".",
"push",
"(",
"[",
"elementNew",
"]",
")",
";",
"}",
"}",
"return",
"groups",
";",
"}"
] | Groups elements into groups if the emelents are not similar
@param elements | [
"Groups",
"elements",
"into",
"groups",
"if",
"the",
"emelents",
"are",
"not",
"similar"
] | d9c20445ae0b8635ccd8c837cb1efc8d455e1a37 | https://github.com/martinsbalodis/css-selector/blob/d9c20445ae0b8635ccd8c837cb1efc8d455e1a37/lib/CssSelector.js#L412-L438 | train |
|
philbooth/check-types.js | src/check-types.js | primitive | function primitive (data) {
var type;
switch (data) {
case null:
case undefined:
case false:
case true:
return true;
}
type = typeof data;
return type === 'string' || type === 'number' || (haveSymbols && type === 'symbol');
} | javascript | function primitive (data) {
var type;
switch (data) {
case null:
case undefined:
case false:
case true:
return true;
}
type = typeof data;
return type === 'string' || type === 'number' || (haveSymbols && type === 'symbol');
} | [
"function",
"primitive",
"(",
"data",
")",
"{",
"var",
"type",
";",
"switch",
"(",
"data",
")",
"{",
"case",
"null",
":",
"case",
"undefined",
":",
"case",
"false",
":",
"case",
"true",
":",
"return",
"true",
";",
"}",
"type",
"=",
"typeof",
"data",
";",
"return",
"type",
"===",
"'string'",
"||",
"type",
"===",
"'number'",
"||",
"(",
"haveSymbols",
"&&",
"type",
"===",
"'symbol'",
")",
";",
"}"
] | Public function `primitive`.
Returns true if `data` is a primitive type, false otherwise. | [
"Public",
"function",
"primitive",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L149-L162 | train |
philbooth/check-types.js | src/check-types.js | between | function between (data, x, y) {
if (x < y) {
return greater(data, x) && data < y;
}
return less(data, x) && data > y;
} | javascript | function between (data, x, y) {
if (x < y) {
return greater(data, x) && data < y;
}
return less(data, x) && data > y;
} | [
"function",
"between",
"(",
"data",
",",
"x",
",",
"y",
")",
"{",
"if",
"(",
"x",
"<",
"y",
")",
"{",
"return",
"greater",
"(",
"data",
",",
"x",
")",
"&&",
"data",
"<",
"y",
";",
"}",
"return",
"less",
"(",
"data",
",",
"x",
")",
"&&",
"data",
">",
"y",
";",
"}"
] | Public function `between`.
Returns true if `data` is a number between `x` and `y`, false otherwise. | [
"Public",
"function",
"between",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L241-L247 | train |
philbooth/check-types.js | src/check-types.js | inRange | function inRange (data, x, y) {
if (x < y) {
return greaterOrEqual(data, x) && data <= y;
}
return lessOrEqual(data, x) && data >= y;
} | javascript | function inRange (data, x, y) {
if (x < y) {
return greaterOrEqual(data, x) && data <= y;
}
return lessOrEqual(data, x) && data >= y;
} | [
"function",
"inRange",
"(",
"data",
",",
"x",
",",
"y",
")",
"{",
"if",
"(",
"x",
"<",
"y",
")",
"{",
"return",
"greaterOrEqual",
"(",
"data",
",",
"x",
")",
"&&",
"data",
"<=",
"y",
";",
"}",
"return",
"lessOrEqual",
"(",
"data",
",",
"x",
")",
"&&",
"data",
">=",
"y",
";",
"}"
] | Public function `inRange`.
Returns true if `data` is a number in the range `x..y`, false otherwise. | [
"Public",
"function",
"inRange",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L274-L280 | train |
philbooth/check-types.js | src/check-types.js | instance | function instance (data, prototype) {
try {
return instanceStrict(data, prototype) ||
data.constructor.name === prototype.name ||
Object.prototype.toString.call(data) === '[object ' + prototype.name + ']';
} catch (error) {
return false;
}
} | javascript | function instance (data, prototype) {
try {
return instanceStrict(data, prototype) ||
data.constructor.name === prototype.name ||
Object.prototype.toString.call(data) === '[object ' + prototype.name + ']';
} catch (error) {
return false;
}
} | [
"function",
"instance",
"(",
"data",
",",
"prototype",
")",
"{",
"try",
"{",
"return",
"instanceStrict",
"(",
"data",
",",
"prototype",
")",
"||",
"data",
".",
"constructor",
".",
"name",
"===",
"prototype",
".",
"name",
"||",
"Object",
".",
"prototype",
".",
"toString",
".",
"call",
"(",
"data",
")",
"===",
"'[object '",
"+",
"prototype",
".",
"name",
"+",
"']'",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Public function `instance`.
Returns true if `data` is an instance of `prototype`, false otherwise.
Falls back to testing constructor.name and Object.prototype.toString
if the initial instanceof test fails. | [
"Public",
"function",
"instance",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L402-L410 | train |
philbooth/check-types.js | src/check-types.js | like | function like (data, archetype) {
var name;
for (name in archetype) {
if (archetype.hasOwnProperty(name)) {
if (data.hasOwnProperty(name) === false || typeof data[name] !== typeof archetype[name]) {
return false;
}
if (object(data[name]) && like(data[name], archetype[name]) === false) {
return false;
}
}
}
return true;
} | javascript | function like (data, archetype) {
var name;
for (name in archetype) {
if (archetype.hasOwnProperty(name)) {
if (data.hasOwnProperty(name) === false || typeof data[name] !== typeof archetype[name]) {
return false;
}
if (object(data[name]) && like(data[name], archetype[name]) === false) {
return false;
}
}
}
return true;
} | [
"function",
"like",
"(",
"data",
",",
"archetype",
")",
"{",
"var",
"name",
";",
"for",
"(",
"name",
"in",
"archetype",
")",
"{",
"if",
"(",
"archetype",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
"{",
"if",
"(",
"data",
".",
"hasOwnProperty",
"(",
"name",
")",
"===",
"false",
"||",
"typeof",
"data",
"[",
"name",
"]",
"!==",
"typeof",
"archetype",
"[",
"name",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"object",
"(",
"data",
"[",
"name",
"]",
")",
"&&",
"like",
"(",
"data",
"[",
"name",
"]",
",",
"archetype",
"[",
"name",
"]",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Public function `like`.
Tests whether `data` 'quacks like a duck'. Returns true if `data` has all
of the properties of `archetype` (the 'duck'), false otherwise. | [
"Public",
"function",
"like",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L418-L434 | train |
philbooth/check-types.js | src/check-types.js | iterable | function iterable (data) {
if (! haveSymbols) {
// Fall back to `arrayLike` predicate in pre-ES6 environments.
return arrayLike(data);
}
return assigned(data) && isFunction(data[Symbol.iterator]);
} | javascript | function iterable (data) {
if (! haveSymbols) {
// Fall back to `arrayLike` predicate in pre-ES6 environments.
return arrayLike(data);
}
return assigned(data) && isFunction(data[Symbol.iterator]);
} | [
"function",
"iterable",
"(",
"data",
")",
"{",
"if",
"(",
"!",
"haveSymbols",
")",
"{",
"return",
"arrayLike",
"(",
"data",
")",
";",
"}",
"return",
"assigned",
"(",
"data",
")",
"&&",
"isFunction",
"(",
"data",
"[",
"Symbol",
".",
"iterator",
"]",
")",
";",
"}"
] | Public function `iterable`.
Returns true if `data` is an iterable, false otherwise. | [
"Public",
"function",
"iterable",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L477-L484 | train |
philbooth/check-types.js | src/check-types.js | includes | function includes (data, value) {
var iterator, iteration, keys, length, i;
if (! assigned(data)) {
return false;
}
if (haveSymbols && data[Symbol.iterator] && isFunction(data.values)) {
iterator = data.values();
do {
iteration = iterator.next();
if (iteration.value === value) {
return true;
}
} while (! iteration.done);
return false;
}
keys = Object.keys(data);
length = keys.length;
for (i = 0; i < length; ++i) {
if (data[keys[i]] === value) {
return true;
}
}
return false;
} | javascript | function includes (data, value) {
var iterator, iteration, keys, length, i;
if (! assigned(data)) {
return false;
}
if (haveSymbols && data[Symbol.iterator] && isFunction(data.values)) {
iterator = data.values();
do {
iteration = iterator.next();
if (iteration.value === value) {
return true;
}
} while (! iteration.done);
return false;
}
keys = Object.keys(data);
length = keys.length;
for (i = 0; i < length; ++i) {
if (data[keys[i]] === value) {
return true;
}
}
return false;
} | [
"function",
"includes",
"(",
"data",
",",
"value",
")",
"{",
"var",
"iterator",
",",
"iteration",
",",
"keys",
",",
"length",
",",
"i",
";",
"if",
"(",
"!",
"assigned",
"(",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"haveSymbols",
"&&",
"data",
"[",
"Symbol",
".",
"iterator",
"]",
"&&",
"isFunction",
"(",
"data",
".",
"values",
")",
")",
"{",
"iterator",
"=",
"data",
".",
"values",
"(",
")",
";",
"do",
"{",
"iteration",
"=",
"iterator",
".",
"next",
"(",
")",
";",
"if",
"(",
"iteration",
".",
"value",
"===",
"value",
")",
"{",
"return",
"true",
";",
"}",
"}",
"while",
"(",
"!",
"iteration",
".",
"done",
")",
";",
"return",
"false",
";",
"}",
"keys",
"=",
"Object",
".",
"keys",
"(",
"data",
")",
";",
"length",
"=",
"keys",
".",
"length",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"++",
"i",
")",
"{",
"if",
"(",
"data",
"[",
"keys",
"[",
"i",
"]",
"]",
"===",
"value",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Public function `includes`.
Returns true if `data` contains `value`, false otherwise. | [
"Public",
"function",
"includes",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L491-L521 | train |
philbooth/check-types.js | src/check-types.js | apply | function apply (data, predicates) {
assert.array(data);
if (isFunction(predicates)) {
return data.map(function (value) {
return predicates(value);
});
}
assert.array(predicates);
assert.hasLength(data, predicates.length);
return data.map(function (value, index) {
return predicates[index](value);
});
} | javascript | function apply (data, predicates) {
assert.array(data);
if (isFunction(predicates)) {
return data.map(function (value) {
return predicates(value);
});
}
assert.array(predicates);
assert.hasLength(data, predicates.length);
return data.map(function (value, index) {
return predicates[index](value);
});
} | [
"function",
"apply",
"(",
"data",
",",
"predicates",
")",
"{",
"assert",
".",
"array",
"(",
"data",
")",
";",
"if",
"(",
"isFunction",
"(",
"predicates",
")",
")",
"{",
"return",
"data",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"predicates",
"(",
"value",
")",
";",
"}",
")",
";",
"}",
"assert",
".",
"array",
"(",
"predicates",
")",
";",
"assert",
".",
"hasLength",
"(",
"data",
",",
"predicates",
".",
"length",
")",
";",
"return",
"data",
".",
"map",
"(",
"function",
"(",
"value",
",",
"index",
")",
"{",
"return",
"predicates",
"[",
"index",
"]",
"(",
"value",
")",
";",
"}",
")",
";",
"}"
] | Public function `apply`.
Maps each value from the `data` to the corresponding predicate and returns
the result array. If the same function is to be applied across all of the
data, a single predicate function may be passed in. | [
"Public",
"function",
"apply",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L559-L574 | train |
philbooth/check-types.js | src/check-types.js | map | function map (data, predicates) {
assert.object(data);
if (isFunction(predicates)) {
return mapSimple(data, predicates);
}
assert.object(predicates);
return mapComplex(data, predicates);
} | javascript | function map (data, predicates) {
assert.object(data);
if (isFunction(predicates)) {
return mapSimple(data, predicates);
}
assert.object(predicates);
return mapComplex(data, predicates);
} | [
"function",
"map",
"(",
"data",
",",
"predicates",
")",
"{",
"assert",
".",
"object",
"(",
"data",
")",
";",
"if",
"(",
"isFunction",
"(",
"predicates",
")",
")",
"{",
"return",
"mapSimple",
"(",
"data",
",",
"predicates",
")",
";",
"}",
"assert",
".",
"object",
"(",
"predicates",
")",
";",
"return",
"mapComplex",
"(",
"data",
",",
"predicates",
")",
";",
"}"
] | Public function `map`.
Maps each value from the `data` to the corresponding predicate and returns
the result object. Supports nested objects. If the `data` is not nested and
the same function is to be applied across all of it, a single predicate
function may be passed in. | [
"Public",
"function",
"map",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L585-L595 | train |
philbooth/check-types.js | src/check-types.js | all | function all (data) {
if (array(data)) {
return testArray(data, false);
}
assert.object(data);
return testObject(data, false);
} | javascript | function all (data) {
if (array(data)) {
return testArray(data, false);
}
assert.object(data);
return testObject(data, false);
} | [
"function",
"all",
"(",
"data",
")",
"{",
"if",
"(",
"array",
"(",
"data",
")",
")",
"{",
"return",
"testArray",
"(",
"data",
",",
"false",
")",
";",
"}",
"assert",
".",
"object",
"(",
"data",
")",
";",
"return",
"testObject",
"(",
"data",
",",
"false",
")",
";",
"}"
] | Public function `all`
Check that all boolean values are true
in an array (returned from `apply`)
or object (returned from `map`). | [
"Public",
"function",
"all"
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L635-L643 | train |
philbooth/check-types.js | src/check-types.js | any | function any (data) {
if (array(data)) {
return testArray(data, true);
}
assert.object(data);
return testObject(data, true);
} | javascript | function any (data) {
if (array(data)) {
return testArray(data, true);
}
assert.object(data);
return testObject(data, true);
} | [
"function",
"any",
"(",
"data",
")",
"{",
"if",
"(",
"array",
"(",
"data",
")",
")",
"{",
"return",
"testArray",
"(",
"data",
",",
"true",
")",
";",
"}",
"assert",
".",
"object",
"(",
"data",
")",
";",
"return",
"testObject",
"(",
"data",
",",
"true",
")",
";",
"}"
] | Public function `any`
Check that at least one boolean value is true
in an array (returned from `apply`)
or object (returned from `map`). | [
"Public",
"function",
"any"
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L685-L693 | train |
philbooth/check-types.js | src/check-types.js | notModifier | function notModifier (predicate) {
var modifiedPredicate = function () {
return notImpl(predicate.apply(null, arguments));
};
modifiedPredicate.l = predicate.length;
return modifiedPredicate;
} | javascript | function notModifier (predicate) {
var modifiedPredicate = function () {
return notImpl(predicate.apply(null, arguments));
};
modifiedPredicate.l = predicate.length;
return modifiedPredicate;
} | [
"function",
"notModifier",
"(",
"predicate",
")",
"{",
"var",
"modifiedPredicate",
"=",
"function",
"(",
")",
"{",
"return",
"notImpl",
"(",
"predicate",
".",
"apply",
"(",
"null",
",",
"arguments",
")",
")",
";",
"}",
";",
"modifiedPredicate",
".",
"l",
"=",
"predicate",
".",
"length",
";",
"return",
"modifiedPredicate",
";",
"}"
] | Public modifier `not`.
Negates `predicate`. | [
"Public",
"modifier",
"not",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L738-L744 | train |
philbooth/check-types.js | src/check-types.js | ofModifier | function ofModifier (target, type, predicate) {
var modifiedPredicate = function () {
var collection, args;
collection = arguments[0];
if (target === 'maybe' && not.assigned(collection)) {
return true;
}
if (!type(collection)) {
return false;
}
collection = coerceCollection(type, collection);
args = slice.call(arguments, 1);
try {
collection.forEach(function (item) {
if (
(target !== 'maybe' || assigned(item)) &&
!predicate.apply(null, [ item ].concat(args))
) {
// TODO: Replace with for...of when ES6 is required.
throw 0;
}
});
} catch (ignore) {
return false;
}
return true;
};
modifiedPredicate.l = predicate.length;
return modifiedPredicate;
} | javascript | function ofModifier (target, type, predicate) {
var modifiedPredicate = function () {
var collection, args;
collection = arguments[0];
if (target === 'maybe' && not.assigned(collection)) {
return true;
}
if (!type(collection)) {
return false;
}
collection = coerceCollection(type, collection);
args = slice.call(arguments, 1);
try {
collection.forEach(function (item) {
if (
(target !== 'maybe' || assigned(item)) &&
!predicate.apply(null, [ item ].concat(args))
) {
// TODO: Replace with for...of when ES6 is required.
throw 0;
}
});
} catch (ignore) {
return false;
}
return true;
};
modifiedPredicate.l = predicate.length;
return modifiedPredicate;
} | [
"function",
"ofModifier",
"(",
"target",
",",
"type",
",",
"predicate",
")",
"{",
"var",
"modifiedPredicate",
"=",
"function",
"(",
")",
"{",
"var",
"collection",
",",
"args",
";",
"collection",
"=",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"target",
"===",
"'maybe'",
"&&",
"not",
".",
"assigned",
"(",
"collection",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"type",
"(",
"collection",
")",
")",
"{",
"return",
"false",
";",
"}",
"collection",
"=",
"coerceCollection",
"(",
"type",
",",
"collection",
")",
";",
"args",
"=",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
";",
"try",
"{",
"collection",
".",
"forEach",
"(",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"(",
"target",
"!==",
"'maybe'",
"||",
"assigned",
"(",
"item",
")",
")",
"&&",
"!",
"predicate",
".",
"apply",
"(",
"null",
",",
"[",
"item",
"]",
".",
"concat",
"(",
"args",
")",
")",
")",
"{",
"throw",
"0",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"ignore",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
";",
"modifiedPredicate",
".",
"l",
"=",
"predicate",
".",
"length",
";",
"return",
"modifiedPredicate",
";",
"}"
] | Public modifier `of`.
Applies the chained predicate to members of the collection. | [
"Public",
"modifier",
"of",
"."
] | 13c7a908c377f4efe5df2a197a23cbd33e724bdb | https://github.com/philbooth/check-types.js/blob/13c7a908c377f4efe5df2a197a23cbd33e724bdb/src/check-types.js#L788-L823 | train |
maxvyaznikov/imapseagull | lib/bodystructure.js | createBodystructure | function createBodystructure(tree, options) {
options = options || {};
var walker = function(node) {
switch((node.parsedHeader['content-type'] || {}).type) {
case 'multipart':
return processMultipartNode(node, options);
case 'text':
return processTextNode(node, options);
case 'message':
if (!options.attachmentRFC822) {
return processRFC822Node(node, options);
}
return processAttachmentNode(node, options);
default:
return processAttachmentNode(node, options);
}
};
return walker(tree);
} | javascript | function createBodystructure(tree, options) {
options = options || {};
var walker = function(node) {
switch((node.parsedHeader['content-type'] || {}).type) {
case 'multipart':
return processMultipartNode(node, options);
case 'text':
return processTextNode(node, options);
case 'message':
if (!options.attachmentRFC822) {
return processRFC822Node(node, options);
}
return processAttachmentNode(node, options);
default:
return processAttachmentNode(node, options);
}
};
return walker(tree);
} | [
"function",
"createBodystructure",
"(",
"tree",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"walker",
"=",
"function",
"(",
"node",
")",
"{",
"switch",
"(",
"(",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
"||",
"{",
"}",
")",
".",
"type",
")",
"{",
"case",
"'multipart'",
":",
"return",
"processMultipartNode",
"(",
"node",
",",
"options",
")",
";",
"case",
"'text'",
":",
"return",
"processTextNode",
"(",
"node",
",",
"options",
")",
";",
"case",
"'message'",
":",
"if",
"(",
"!",
"options",
".",
"attachmentRFC822",
")",
"{",
"return",
"processRFC822Node",
"(",
"node",
",",
"options",
")",
";",
"}",
"return",
"processAttachmentNode",
"(",
"node",
",",
"options",
")",
";",
"default",
":",
"return",
"processAttachmentNode",
"(",
"node",
",",
"options",
")",
";",
"}",
"}",
";",
"return",
"walker",
"(",
"tree",
")",
";",
"}"
] | Generates an object out of parsed mime tree, that can be
serialized into a BODYSTRUCTURE string
@param {Object} tree Parsed mime tree (see mimeparser.js for input)
@param {Object} [options] Optional options object
@param {Boolean} [options.contentLanguageString] If true, convert single element array to string for Content-Language
@param {Boolean} [options.upperCaseKeys] If true, use only upper case key names
@param {Boolean} [options.skipContentLocation] If true, do not include Content-Location in the output
@param {Boolean} [options.body] If true, skip extension fields (needed for BODY)
@param {Object} Object structure in the form of BODYSTRUCTURE | [
"Generates",
"an",
"object",
"out",
"of",
"parsed",
"mime",
"tree",
"that",
"can",
"be",
"serialized",
"into",
"a",
"BODYSTRUCTURE",
"string"
] | 44949b7a338b4c0ace3ef7bb95a77c4794462bda | https://github.com/maxvyaznikov/imapseagull/blob/44949b7a338b4c0ace3ef7bb95a77c4794462bda/lib/bodystructure.js#L22-L41 | train |
maxvyaznikov/imapseagull | lib/bodystructure.js | getBasicFields | function getBasicFields(node, options) {
var bodyType = node.parsedHeader['content-type'] && node.parsedHeader['content-type'].type || null,
bodySubtype = node.parsedHeader['content-type'] && node.parsedHeader['content-type'].subtype || null,
contentTransfer = node.parsedHeader['content-transfer-encoding'] || '7bit';
return [
// body type
options.upperCaseKeys ? bodyType && bodyType.toUpperCase() || null : bodyType,
// body subtype
options.upperCaseKeys ? bodySubtype && bodySubtype.toUpperCase() || null : bodySubtype,
// body parameter parenthesized list
node.parsedHeader['content-type'] &&
node.parsedHeader['content-type'].hasParams &&
flatten(Object.keys(node.parsedHeader['content-type'].params).map(function(key) {
return [
options.upperCaseKeys ? key.toUpperCase() : key,
node.parsedHeader['content-type'].params[key]];
})) || null,
// body id
node.parsedHeader['content-id'] || null,
// body description
node.parsedHeader['content-description'] || null,
// body encoding
options.upperCaseKeys ? contentTransfer && contentTransfer.toUpperCase() || '7bit' : contentTransfer,
// body size
node.size
];
} | javascript | function getBasicFields(node, options) {
var bodyType = node.parsedHeader['content-type'] && node.parsedHeader['content-type'].type || null,
bodySubtype = node.parsedHeader['content-type'] && node.parsedHeader['content-type'].subtype || null,
contentTransfer = node.parsedHeader['content-transfer-encoding'] || '7bit';
return [
// body type
options.upperCaseKeys ? bodyType && bodyType.toUpperCase() || null : bodyType,
// body subtype
options.upperCaseKeys ? bodySubtype && bodySubtype.toUpperCase() || null : bodySubtype,
// body parameter parenthesized list
node.parsedHeader['content-type'] &&
node.parsedHeader['content-type'].hasParams &&
flatten(Object.keys(node.parsedHeader['content-type'].params).map(function(key) {
return [
options.upperCaseKeys ? key.toUpperCase() : key,
node.parsedHeader['content-type'].params[key]];
})) || null,
// body id
node.parsedHeader['content-id'] || null,
// body description
node.parsedHeader['content-description'] || null,
// body encoding
options.upperCaseKeys ? contentTransfer && contentTransfer.toUpperCase() || '7bit' : contentTransfer,
// body size
node.size
];
} | [
"function",
"getBasicFields",
"(",
"node",
",",
"options",
")",
"{",
"var",
"bodyType",
"=",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
"&&",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
".",
"type",
"||",
"null",
",",
"bodySubtype",
"=",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
"&&",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
".",
"subtype",
"||",
"null",
",",
"contentTransfer",
"=",
"node",
".",
"parsedHeader",
"[",
"'content-transfer-encoding'",
"]",
"||",
"'7bit'",
";",
"return",
"[",
"options",
".",
"upperCaseKeys",
"?",
"bodyType",
"&&",
"bodyType",
".",
"toUpperCase",
"(",
")",
"||",
"null",
":",
"bodyType",
",",
"options",
".",
"upperCaseKeys",
"?",
"bodySubtype",
"&&",
"bodySubtype",
".",
"toUpperCase",
"(",
")",
"||",
"null",
":",
"bodySubtype",
",",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
"&&",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
".",
"hasParams",
"&&",
"flatten",
"(",
"Object",
".",
"keys",
"(",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
".",
"params",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"[",
"options",
".",
"upperCaseKeys",
"?",
"key",
".",
"toUpperCase",
"(",
")",
":",
"key",
",",
"node",
".",
"parsedHeader",
"[",
"'content-type'",
"]",
".",
"params",
"[",
"key",
"]",
"]",
";",
"}",
")",
")",
"||",
"null",
",",
"node",
".",
"parsedHeader",
"[",
"'content-id'",
"]",
"||",
"null",
",",
"node",
".",
"parsedHeader",
"[",
"'content-description'",
"]",
"||",
"null",
",",
"options",
".",
"upperCaseKeys",
"?",
"contentTransfer",
"&&",
"contentTransfer",
".",
"toUpperCase",
"(",
")",
"||",
"'7bit'",
":",
"contentTransfer",
",",
"node",
".",
"size",
"]",
";",
"}"
] | Generates a list of basic fields any non-multipart part should have
@param {Object} node A tree node of the parsed mime tree
@param {Object} [options] Optional options object (see createBodystructure for details)
@return {Array} A list of basic fields | [
"Generates",
"a",
"list",
"of",
"basic",
"fields",
"any",
"non",
"-",
"multipart",
"part",
"should",
"have"
] | 44949b7a338b4c0ace3ef7bb95a77c4794462bda | https://github.com/maxvyaznikov/imapseagull/blob/44949b7a338b4c0ace3ef7bb95a77c4794462bda/lib/bodystructure.js#L50-L77 | train |
maxvyaznikov/imapseagull | lib/bodystructure.js | getExtensionFields | function getExtensionFields(node, options) {
options = options || {};
var languageString = node.parsedHeader['content-language'] &&
node.parsedHeader['content-language'].replace(/[ ,]+/g, ',').replace(/^,+|,+$/g, ''),
language = languageString && languageString.split(',') || null,
data;
// if `contentLanguageString` is true, then use a string instead of single element array
if (language && language.length == 1 && options.contentLanguageString) {
language = language[0];
}
data = [
// body MD5
node.parsedHeader['content-md5'] || null,
// body disposition
node.parsedHeader['content-disposition'] && [
options.upperCaseKeys ?
node.parsedHeader['content-disposition'].value.toUpperCase() :
node.parsedHeader['content-disposition'].value,
node.parsedHeader['content-disposition'].params &&
node.parsedHeader['content-disposition'].hasParams &&
flatten(Object.keys(node.parsedHeader['content-disposition'].params).map(function(key) {
return [
options.upperCaseKeys ? key.toUpperCase() : key,
node.parsedHeader['content-disposition'].params[key]];
})) || null
] || null,
// body language
language
];
// if `skipContentLocation` is true, do not include Content-Location in output
//
// NB! RFC3501 has an errata with content-location type, it is described as
// 'A string list' (eg. an array) in RFC but the errata page states
// that it is a string (http://www.rfc-editor.org/errata_search.php?rfc=3501)
// see note for 'Section 7.4.2, page 75'
if (!options.skipContentLocation) {
// body location
data.push(node.parsedHeader['content-location'] || null);
}
return data;
} | javascript | function getExtensionFields(node, options) {
options = options || {};
var languageString = node.parsedHeader['content-language'] &&
node.parsedHeader['content-language'].replace(/[ ,]+/g, ',').replace(/^,+|,+$/g, ''),
language = languageString && languageString.split(',') || null,
data;
// if `contentLanguageString` is true, then use a string instead of single element array
if (language && language.length == 1 && options.contentLanguageString) {
language = language[0];
}
data = [
// body MD5
node.parsedHeader['content-md5'] || null,
// body disposition
node.parsedHeader['content-disposition'] && [
options.upperCaseKeys ?
node.parsedHeader['content-disposition'].value.toUpperCase() :
node.parsedHeader['content-disposition'].value,
node.parsedHeader['content-disposition'].params &&
node.parsedHeader['content-disposition'].hasParams &&
flatten(Object.keys(node.parsedHeader['content-disposition'].params).map(function(key) {
return [
options.upperCaseKeys ? key.toUpperCase() : key,
node.parsedHeader['content-disposition'].params[key]];
})) || null
] || null,
// body language
language
];
// if `skipContentLocation` is true, do not include Content-Location in output
//
// NB! RFC3501 has an errata with content-location type, it is described as
// 'A string list' (eg. an array) in RFC but the errata page states
// that it is a string (http://www.rfc-editor.org/errata_search.php?rfc=3501)
// see note for 'Section 7.4.2, page 75'
if (!options.skipContentLocation) {
// body location
data.push(node.parsedHeader['content-location'] || null);
}
return data;
} | [
"function",
"getExtensionFields",
"(",
"node",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"languageString",
"=",
"node",
".",
"parsedHeader",
"[",
"'content-language'",
"]",
"&&",
"node",
".",
"parsedHeader",
"[",
"'content-language'",
"]",
".",
"replace",
"(",
"/",
"[ ,]+",
"/",
"g",
",",
"','",
")",
".",
"replace",
"(",
"/",
"^,+|,+$",
"/",
"g",
",",
"''",
")",
",",
"language",
"=",
"languageString",
"&&",
"languageString",
".",
"split",
"(",
"','",
")",
"||",
"null",
",",
"data",
";",
"if",
"(",
"language",
"&&",
"language",
".",
"length",
"==",
"1",
"&&",
"options",
".",
"contentLanguageString",
")",
"{",
"language",
"=",
"language",
"[",
"0",
"]",
";",
"}",
"data",
"=",
"[",
"node",
".",
"parsedHeader",
"[",
"'content-md5'",
"]",
"||",
"null",
",",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
"&&",
"[",
"options",
".",
"upperCaseKeys",
"?",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"value",
".",
"toUpperCase",
"(",
")",
":",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"value",
",",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"params",
"&&",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"hasParams",
"&&",
"flatten",
"(",
"Object",
".",
"keys",
"(",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"params",
")",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"[",
"options",
".",
"upperCaseKeys",
"?",
"key",
".",
"toUpperCase",
"(",
")",
":",
"key",
",",
"node",
".",
"parsedHeader",
"[",
"'content-disposition'",
"]",
".",
"params",
"[",
"key",
"]",
"]",
";",
"}",
")",
")",
"||",
"null",
"]",
"||",
"null",
",",
"language",
"]",
";",
"if",
"(",
"!",
"options",
".",
"skipContentLocation",
")",
"{",
"data",
".",
"push",
"(",
"node",
".",
"parsedHeader",
"[",
"'content-location'",
"]",
"||",
"null",
")",
";",
"}",
"return",
"data",
";",
"}"
] | Generates a list of extension fields any non-multipart part should have
@param {Object} node A tree node of the parsed mime tree
@param {Object} [options] Optional options object (see createBodystructure for details)
@return {Array} A list of extension fields | [
"Generates",
"a",
"list",
"of",
"extension",
"fields",
"any",
"non",
"-",
"multipart",
"part",
"should",
"have"
] | 44949b7a338b4c0ace3ef7bb95a77c4794462bda | https://github.com/maxvyaznikov/imapseagull/blob/44949b7a338b4c0ace3ef7bb95a77c4794462bda/lib/bodystructure.js#L86-L131 | train |
maxvyaznikov/imapseagull | lib/bodystructure.js | processAttachmentNode | function processAttachmentNode(node, options) {
options = options || {};
var data = [].concat(getBasicFields(node, options));
if (!options.body) {
data = data.concat(getExtensionFields(node, options));
}
data.node = node;
return data;
} | javascript | function processAttachmentNode(node, options) {
options = options || {};
var data = [].concat(getBasicFields(node, options));
if (!options.body) {
data = data.concat(getExtensionFields(node, options));
}
data.node = node;
return data;
} | [
"function",
"processAttachmentNode",
"(",
"node",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"data",
"=",
"[",
"]",
".",
"concat",
"(",
"getBasicFields",
"(",
"node",
",",
"options",
")",
")",
";",
"if",
"(",
"!",
"options",
".",
"body",
")",
"{",
"data",
"=",
"data",
".",
"concat",
"(",
"getExtensionFields",
"(",
"node",
",",
"options",
")",
")",
";",
"}",
"data",
".",
"node",
"=",
"node",
";",
"return",
"data",
";",
"}"
] | Processes a non-text, non-multipart node
@param {Object} node A tree node of the parsed mime tree
@param {Object} [options] Optional options object (see createBodystructure for details)
@return {Array} BODYSTRUCTURE for the part | [
"Processes",
"a",
"non",
"-",
"text",
"non",
"-",
"multipart",
"node"
] | 44949b7a338b4c0ace3ef7bb95a77c4794462bda | https://github.com/maxvyaznikov/imapseagull/blob/44949b7a338b4c0ace3ef7bb95a77c4794462bda/lib/bodystructure.js#L197-L208 | train |
huafu/ember-google-map | addon/core/google-object-property.js | function (key, config) {
var props = key.split(',');
this._cfg = {
key: key,
properties: props,
name: config.name || camelize(props.join('_')),
toGoogle: config.toGoogle || null,
fromGoogle: config.fromGoogle || null,
read: config.read || null,
write: config.write || null,
event: config.event || null,
cast: config.cast || null,
readOnly: config.readOnly || false,
optionOnly: config.optionOnly || false
};
} | javascript | function (key, config) {
var props = key.split(',');
this._cfg = {
key: key,
properties: props,
name: config.name || camelize(props.join('_')),
toGoogle: config.toGoogle || null,
fromGoogle: config.fromGoogle || null,
read: config.read || null,
write: config.write || null,
event: config.event || null,
cast: config.cast || null,
readOnly: config.readOnly || false,
optionOnly: config.optionOnly || false
};
} | [
"function",
"(",
"key",
",",
"config",
")",
"{",
"var",
"props",
"=",
"key",
".",
"split",
"(",
"','",
")",
";",
"this",
".",
"_cfg",
"=",
"{",
"key",
":",
"key",
",",
"properties",
":",
"props",
",",
"name",
":",
"config",
".",
"name",
"||",
"camelize",
"(",
"props",
".",
"join",
"(",
"'_'",
")",
")",
",",
"toGoogle",
":",
"config",
".",
"toGoogle",
"||",
"null",
",",
"fromGoogle",
":",
"config",
".",
"fromGoogle",
"||",
"null",
",",
"read",
":",
"config",
".",
"read",
"||",
"null",
",",
"write",
":",
"config",
".",
"write",
"||",
"null",
",",
"event",
":",
"config",
".",
"event",
"||",
"null",
",",
"cast",
":",
"config",
".",
"cast",
"||",
"null",
",",
"readOnly",
":",
"config",
".",
"readOnly",
"||",
"false",
",",
"optionOnly",
":",
"config",
".",
"optionOnly",
"||",
"false",
"}",
";",
"}"
] | Handle the linking between a google and an ember object's properties
@class GoogleObjectProperty
@param {String} key
@param {{name: String, toGoogle: Function, fromGoogle: Function, read: Function, write: Function, event: String, cast: Function, readOnly: Boolean, optionOnly: Boolean}} config
@constructor | [
"Handle",
"the",
"linking",
"between",
"a",
"google",
"and",
"an",
"ember",
"object",
"s",
"properties"
] | c454e893ff0ca196fdac684e8369981e985d5619 | https://github.com/huafu/ember-google-map/blob/c454e893ff0ca196fdac684e8369981e985d5619/addon/core/google-object-property.js#L16-L31 | train |
|
flowxo/flowxo-sdk | tasks/lib/run.js | function(callback) {
// If it's a webhook, delegate off
if(method.type === 'webhook') {
return RunUtil.runWebhook(grunt, options, method, callback);
}
// Otherwise, run the method
runner.run(method.slug, 'run', { input: filteredInputs }, callback);
} | javascript | function(callback) {
// If it's a webhook, delegate off
if(method.type === 'webhook') {
return RunUtil.runWebhook(grunt, options, method, callback);
}
// Otherwise, run the method
runner.run(method.slug, 'run', { input: filteredInputs }, callback);
} | [
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"method",
".",
"type",
"===",
"'webhook'",
")",
"{",
"return",
"RunUtil",
".",
"runWebhook",
"(",
"grunt",
",",
"options",
",",
"method",
",",
"callback",
")",
";",
"}",
"runner",
".",
"run",
"(",
"method",
".",
"slug",
",",
"'run'",
",",
"{",
"input",
":",
"filteredInputs",
"}",
",",
"callback",
")",
";",
"}"
] | run.js | [
"run",
".",
"js"
] | 8f71dbfb25a8b57591f5c4df09937289d5c8356b | https://github.com/flowxo/flowxo-sdk/blob/8f71dbfb25a8b57591f5c4df09937289d5c8356b/tasks/lib/run.js#L551-L560 | train |
|
flowxo/flowxo-sdk | tasks/lib/run.js | function(r, callback) {
result = r || {};
RunUtil.displayScriptData(grunt, result);
RunUtil.displayScriptOutput(grunt, outputs, result);
try {
RunUtil.checkRunScriptResult(result, method);
} catch(e) {
CommonUtil.header(grunt, 'VALIDATION:', 'red');
grunt.fail.fatal(e);
}
callback();
} | javascript | function(r, callback) {
result = r || {};
RunUtil.displayScriptData(grunt, result);
RunUtil.displayScriptOutput(grunt, outputs, result);
try {
RunUtil.checkRunScriptResult(result, method);
} catch(e) {
CommonUtil.header(grunt, 'VALIDATION:', 'red');
grunt.fail.fatal(e);
}
callback();
} | [
"function",
"(",
"r",
",",
"callback",
")",
"{",
"result",
"=",
"r",
"||",
"{",
"}",
";",
"RunUtil",
".",
"displayScriptData",
"(",
"grunt",
",",
"result",
")",
";",
"RunUtil",
".",
"displayScriptOutput",
"(",
"grunt",
",",
"outputs",
",",
"result",
")",
";",
"try",
"{",
"RunUtil",
".",
"checkRunScriptResult",
"(",
"result",
",",
"method",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"CommonUtil",
".",
"header",
"(",
"grunt",
",",
"'VALIDATION:'",
",",
"'red'",
")",
";",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"e",
")",
";",
"}",
"callback",
"(",
")",
";",
"}"
] | validation and output | [
"validation",
"and",
"output"
] | 8f71dbfb25a8b57591f5c4df09937289d5c8356b | https://github.com/flowxo/flowxo-sdk/blob/8f71dbfb25a8b57591f5c4df09937289d5c8356b/tasks/lib/run.js#L563-L576 | train |
|
flowxo/flowxo-sdk | tasks/lib/run.js | function(userScript, callback) {
// If it's a run script, do some inputs
script = userScript;
if((userScript === 'run' || userScript === 'output') &&
(method.fields.input || method.scripts.input)) {
var inputs = (method.fields && method.fields.input) || [];
RunUtil.harvestInputs(grunt, runner, method, inputs, callback);
} else {
callback(null, []);
}
} | javascript | function(userScript, callback) {
// If it's a run script, do some inputs
script = userScript;
if((userScript === 'run' || userScript === 'output') &&
(method.fields.input || method.scripts.input)) {
var inputs = (method.fields && method.fields.input) || [];
RunUtil.harvestInputs(grunt, runner, method, inputs, callback);
} else {
callback(null, []);
}
} | [
"function",
"(",
"userScript",
",",
"callback",
")",
"{",
"script",
"=",
"userScript",
";",
"if",
"(",
"(",
"userScript",
"===",
"'run'",
"||",
"userScript",
"===",
"'output'",
")",
"&&",
"(",
"method",
".",
"fields",
".",
"input",
"||",
"method",
".",
"scripts",
".",
"input",
")",
")",
"{",
"var",
"inputs",
"=",
"(",
"method",
".",
"fields",
"&&",
"method",
".",
"fields",
".",
"input",
")",
"||",
"[",
"]",
";",
"RunUtil",
".",
"harvestInputs",
"(",
"grunt",
",",
"runner",
",",
"method",
",",
"inputs",
",",
"callback",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"[",
"]",
")",
";",
"}",
"}"
] | Get some fields | [
"Get",
"some",
"fields"
] | 8f71dbfb25a8b57591f5c4df09937289d5c8356b | https://github.com/flowxo/flowxo-sdk/blob/8f71dbfb25a8b57591f5c4df09937289d5c8356b/tasks/lib/run.js#L628-L638 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.