id
int32
0
58k
repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
39,500
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(event) { var inst = plugin._getInst((event.data && event.data.elem) || event.target); if (!$.isEmptyObject(inst) && inst.options.constrainInput) { var ch = String.fromCharCode(event.keyCode || event.charCode); var allowedChars = plugin._allowedChars(inst); return (event.metaKey || inst.ctrlKey || ch < ' ' || !allowedChars || allowedChars.indexOf(ch) > -1); } return true; }
javascript
function(event) { var inst = plugin._getInst((event.data && event.data.elem) || event.target); if (!$.isEmptyObject(inst) && inst.options.constrainInput) { var ch = String.fromCharCode(event.keyCode || event.charCode); var allowedChars = plugin._allowedChars(inst); return (event.metaKey || inst.ctrlKey || ch < ' ' || !allowedChars || allowedChars.indexOf(ch) > -1); } return true; }
[ "function", "(", "event", ")", "{", "var", "inst", "=", "plugin", ".", "_getInst", "(", "(", "event", ".", "data", "&&", "event", ".", "data", ".", "elem", ")", "||", "event", ".", "target", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", "&&", "inst", ".", "options", ".", "constrainInput", ")", "{", "var", "ch", "=", "String", ".", "fromCharCode", "(", "event", ".", "keyCode", "||", "event", ".", "charCode", ")", ";", "var", "allowedChars", "=", "plugin", ".", "_allowedChars", "(", "inst", ")", ";", "return", "(", "event", ".", "metaKey", "||", "inst", ".", "ctrlKey", "||", "ch", "<", "' '", "||", "!", "allowedChars", "||", "allowedChars", ".", "indexOf", "(", "ch", ")", ">", "-", "1", ")", ";", "}", "return", "true", ";", "}" ]
Filter keystrokes in the datepicker. @memberof CalendarsPicker @private @param event {KeyEvent} The keystroke. @return {boolean} <code>true</code> if allowed, <code>false</code> if not allowed.
[ "Filter", "keystrokes", "in", "the", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1085-L1094
39,501
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(inst) { var allowedChars = (inst.options.multiSelect ? inst.options.multiSeparator : (inst.options.rangeSelect ? inst.options.rangeSeparator : '')); var literal = false; var hasNum = false; var dateFormat = inst.get('dateFormat'); for (var i = 0; i < dateFormat.length; i++) { var ch = dateFormat.charAt(i); if (literal) { if (ch === "'" && dateFormat.charAt(i + 1) !== "'") { literal = false; } else { allowedChars += ch; } } else { switch (ch) { case 'd': case 'm': case 'o': case 'w': allowedChars += (hasNum ? '' : '0123456789'); hasNum = true; break; case 'y': case '@': case '!': allowedChars += (hasNum ? '' : '0123456789') + '-'; hasNum = true; break; case 'J': allowedChars += (hasNum ? '' : '0123456789') + '-.'; hasNum = true; break; case 'D': case 'M': case 'Y': return null; // Accept anything case "'": if (dateFormat.charAt(i + 1) === "'") { allowedChars += "'"; } else { literal = true; } break; default: allowedChars += ch; } } } return allowedChars; }
javascript
function(inst) { var allowedChars = (inst.options.multiSelect ? inst.options.multiSeparator : (inst.options.rangeSelect ? inst.options.rangeSeparator : '')); var literal = false; var hasNum = false; var dateFormat = inst.get('dateFormat'); for (var i = 0; i < dateFormat.length; i++) { var ch = dateFormat.charAt(i); if (literal) { if (ch === "'" && dateFormat.charAt(i + 1) !== "'") { literal = false; } else { allowedChars += ch; } } else { switch (ch) { case 'd': case 'm': case 'o': case 'w': allowedChars += (hasNum ? '' : '0123456789'); hasNum = true; break; case 'y': case '@': case '!': allowedChars += (hasNum ? '' : '0123456789') + '-'; hasNum = true; break; case 'J': allowedChars += (hasNum ? '' : '0123456789') + '-.'; hasNum = true; break; case 'D': case 'M': case 'Y': return null; // Accept anything case "'": if (dateFormat.charAt(i + 1) === "'") { allowedChars += "'"; } else { literal = true; } break; default: allowedChars += ch; } } } return allowedChars; }
[ "function", "(", "inst", ")", "{", "var", "allowedChars", "=", "(", "inst", ".", "options", ".", "multiSelect", "?", "inst", ".", "options", ".", "multiSeparator", ":", "(", "inst", ".", "options", ".", "rangeSelect", "?", "inst", ".", "options", ".", "rangeSeparator", ":", "''", ")", ")", ";", "var", "literal", "=", "false", ";", "var", "hasNum", "=", "false", ";", "var", "dateFormat", "=", "inst", ".", "get", "(", "'dateFormat'", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "dateFormat", ".", "length", ";", "i", "++", ")", "{", "var", "ch", "=", "dateFormat", ".", "charAt", "(", "i", ")", ";", "if", "(", "literal", ")", "{", "if", "(", "ch", "===", "\"'\"", "&&", "dateFormat", ".", "charAt", "(", "i", "+", "1", ")", "!==", "\"'\"", ")", "{", "literal", "=", "false", ";", "}", "else", "{", "allowedChars", "+=", "ch", ";", "}", "}", "else", "{", "switch", "(", "ch", ")", "{", "case", "'d'", ":", "case", "'m'", ":", "case", "'o'", ":", "case", "'w'", ":", "allowedChars", "+=", "(", "hasNum", "?", "''", ":", "'0123456789'", ")", ";", "hasNum", "=", "true", ";", "break", ";", "case", "'y'", ":", "case", "'@'", ":", "case", "'!'", ":", "allowedChars", "+=", "(", "hasNum", "?", "''", ":", "'0123456789'", ")", "+", "'-'", ";", "hasNum", "=", "true", ";", "break", ";", "case", "'J'", ":", "allowedChars", "+=", "(", "hasNum", "?", "''", ":", "'0123456789'", ")", "+", "'-.'", ";", "hasNum", "=", "true", ";", "break", ";", "case", "'D'", ":", "case", "'M'", ":", "case", "'Y'", ":", "return", "null", ";", "// Accept anything", "case", "\"'\"", ":", "if", "(", "dateFormat", ".", "charAt", "(", "i", "+", "1", ")", "===", "\"'\"", ")", "{", "allowedChars", "+=", "\"'\"", ";", "}", "else", "{", "literal", "=", "true", ";", "}", "break", ";", "default", ":", "allowedChars", "+=", "ch", ";", "}", "}", "}", "return", "allowedChars", ";", "}" ]
Determine the set of characters allowed by the date format. @memberof CalendarsPicker @private @param inst {object} The current instance settings. @return {string} The set of allowed characters, or <code>null</code> if anything allowed.
[ "Determine", "the", "set", "of", "characters", "allowed", "by", "the", "date", "format", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1101-L1141
39,502
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(event) { var elem = (event.data && event.data.elem) || event.target; var inst = plugin._getInst(elem); if (!$.isEmptyObject(inst) && !inst.ctrlKey && inst.lastVal !== inst.elem.val()) { try { var dates = plugin._extractDates(inst, inst.elem.val()); if (dates.length > 0) { plugin.setDate(elem, dates, null, true); } } catch (event) { // Ignore } } return true; }
javascript
function(event) { var elem = (event.data && event.data.elem) || event.target; var inst = plugin._getInst(elem); if (!$.isEmptyObject(inst) && !inst.ctrlKey && inst.lastVal !== inst.elem.val()) { try { var dates = plugin._extractDates(inst, inst.elem.val()); if (dates.length > 0) { plugin.setDate(elem, dates, null, true); } } catch (event) { // Ignore } } return true; }
[ "function", "(", "event", ")", "{", "var", "elem", "=", "(", "event", ".", "data", "&&", "event", ".", "data", ".", "elem", ")", "||", "event", ".", "target", ";", "var", "inst", "=", "plugin", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", "&&", "!", "inst", ".", "ctrlKey", "&&", "inst", ".", "lastVal", "!==", "inst", ".", "elem", ".", "val", "(", ")", ")", "{", "try", "{", "var", "dates", "=", "plugin", ".", "_extractDates", "(", "inst", ",", "inst", ".", "elem", ".", "val", "(", ")", ")", ";", "if", "(", "dates", ".", "length", ">", "0", ")", "{", "plugin", ".", "setDate", "(", "elem", ",", "dates", ",", "null", ",", "true", ")", ";", "}", "}", "catch", "(", "event", ")", "{", "// Ignore", "}", "}", "return", "true", ";", "}" ]
Synchronise datepicker with the field. @memberof CalendarsPicker @private @param event {KeyEvent} The keystroke. @return {boolean} <code>true</code> if allowed, <code>false</code> if not allowed.
[ "Synchronise", "datepicker", "with", "the", "field", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1148-L1163
39,503
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst)) { inst.selectedDates = []; this.hide(elem); var defaultDate = inst.get('defaultDate'); if (inst.options.selectDefaultDate && defaultDate) { this.setDate(elem, (defaultDate || inst.options.calendar.today()).newDate()); } else { this._updateInput(elem); } } }
javascript
function(elem) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst)) { inst.selectedDates = []; this.hide(elem); var defaultDate = inst.get('defaultDate'); if (inst.options.selectDefaultDate && defaultDate) { this.setDate(elem, (defaultDate || inst.options.calendar.today()).newDate()); } else { this._updateInput(elem); } } }
[ "function", "(", "elem", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", ")", "{", "inst", ".", "selectedDates", "=", "[", "]", ";", "this", ".", "hide", "(", "elem", ")", ";", "var", "defaultDate", "=", "inst", ".", "get", "(", "'defaultDate'", ")", ";", "if", "(", "inst", ".", "options", ".", "selectDefaultDate", "&&", "defaultDate", ")", "{", "this", ".", "setDate", "(", "elem", ",", "(", "defaultDate", "||", "inst", ".", "options", ".", "calendar", ".", "today", "(", ")", ")", ".", "newDate", "(", ")", ")", ";", "}", "else", "{", "this", ".", "_updateInput", "(", "elem", ")", ";", "}", "}", "}" ]
Clear an input and close a popup datepicker. @memberof CalendarsPicker @param elem {Element} The control to use. @example $(selector).datepick('clear')
[ "Clear", "an", "input", "and", "close", "a", "popup", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1188-L1201
39,504
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, date) { var inst = this._getInst(elem); if ($.isEmptyObject(inst)) { return false; } date = inst.options.calendar.determineDate(date, inst.selectedDates[0] || inst.options.calendar.today(), null, inst.options.dateFormat, inst.getConfig()); return this._isSelectable(elem, date, inst.options.onDate, inst.get('minDate'), inst.get('maxDate')); }
javascript
function(elem, date) { var inst = this._getInst(elem); if ($.isEmptyObject(inst)) { return false; } date = inst.options.calendar.determineDate(date, inst.selectedDates[0] || inst.options.calendar.today(), null, inst.options.dateFormat, inst.getConfig()); return this._isSelectable(elem, date, inst.options.onDate, inst.get('minDate'), inst.get('maxDate')); }
[ "function", "(", "elem", ",", "date", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "$", ".", "isEmptyObject", "(", "inst", ")", ")", "{", "return", "false", ";", "}", "date", "=", "inst", ".", "options", ".", "calendar", ".", "determineDate", "(", "date", ",", "inst", ".", "selectedDates", "[", "0", "]", "||", "inst", ".", "options", ".", "calendar", ".", "today", "(", ")", ",", "null", ",", "inst", ".", "options", ".", "dateFormat", ",", "inst", ".", "getConfig", "(", ")", ")", ";", "return", "this", ".", "_isSelectable", "(", "elem", ",", "date", ",", "inst", ".", "options", ".", "onDate", ",", "inst", ".", "get", "(", "'minDate'", ")", ",", "inst", ".", "get", "(", "'maxDate'", ")", ")", ";", "}" ]
Determine whether a date is selectable for this datepicker. @memberof CalendarsPicker @private @param elem {Element} The control to check. @param date {CDate|string|number} The date to check. @return {boolean} <code>true</code> if selectable, <code>false</code> if not. @example var selectable = $(selector).datepick('isSelectable', date)
[ "Determine", "whether", "a", "date", "is", "selectable", "for", "this", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1283-L1293
39,505
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, date, onDate, minDate, maxDate) { var dateInfo = (typeof onDate === 'boolean' ? {selectable: onDate} : (!$.isFunction(onDate) ? {} : onDate.apply(elem, [date, true]))); return (dateInfo.selectable !== false) && (!minDate || date.toJD() >= minDate.toJD()) && (!maxDate || date.toJD() <= maxDate.toJD()); }
javascript
function(elem, date, onDate, minDate, maxDate) { var dateInfo = (typeof onDate === 'boolean' ? {selectable: onDate} : (!$.isFunction(onDate) ? {} : onDate.apply(elem, [date, true]))); return (dateInfo.selectable !== false) && (!minDate || date.toJD() >= minDate.toJD()) && (!maxDate || date.toJD() <= maxDate.toJD()); }
[ "function", "(", "elem", ",", "date", ",", "onDate", ",", "minDate", ",", "maxDate", ")", "{", "var", "dateInfo", "=", "(", "typeof", "onDate", "===", "'boolean'", "?", "{", "selectable", ":", "onDate", "}", ":", "(", "!", "$", ".", "isFunction", "(", "onDate", ")", "?", "{", "}", ":", "onDate", ".", "apply", "(", "elem", ",", "[", "date", ",", "true", "]", ")", ")", ")", ";", "return", "(", "dateInfo", ".", "selectable", "!==", "false", ")", "&&", "(", "!", "minDate", "||", "date", ".", "toJD", "(", ")", ">=", "minDate", ".", "toJD", "(", ")", ")", "&&", "(", "!", "maxDate", "||", "date", ".", "toJD", "(", ")", "<=", "maxDate", ".", "toJD", "(", ")", ")", ";", "}" ]
Internally determine whether a date is selectable for this datepicker. @memberof CalendarsPicker @private @param elem {Element} the control to check. @param date {CDate} The date to check. @param onDate {function|boolean} Any <code>onDate</code> callback or <code>callback.selectable</code>. @param minDate {CDate} The minimum allowed date. @param maxDate {CDate} The maximum allowed date. @return {boolean} <code>true</code> if selectable, <code>false</code> if not.
[ "Internally", "determine", "whether", "a", "date", "is", "selectable", "for", "this", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1304-L1309
39,506
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, action) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && !this.isDisabled(elem)) { var commands = inst.options.commands; if (commands[action] && commands[action].enabled.apply(elem, [inst])) { commands[action].action.apply(elem, [inst]); } } }
javascript
function(elem, action) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && !this.isDisabled(elem)) { var commands = inst.options.commands; if (commands[action] && commands[action].enabled.apply(elem, [inst])) { commands[action].action.apply(elem, [inst]); } } }
[ "function", "(", "elem", ",", "action", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", "&&", "!", "this", ".", "isDisabled", "(", "elem", ")", ")", "{", "var", "commands", "=", "inst", ".", "options", ".", "commands", ";", "if", "(", "commands", "[", "action", "]", "&&", "commands", "[", "action", "]", ".", "enabled", ".", "apply", "(", "elem", ",", "[", "inst", "]", ")", ")", "{", "commands", "[", "action", "]", ".", "action", ".", "apply", "(", "elem", ",", "[", "inst", "]", ")", ";", "}", "}", "}" ]
Perform a named action for a datepicker. @memberof CalendarsPicker @param elem {element} The control to affect. @param action {string} The name of the action.
[ "Perform", "a", "named", "action", "for", "a", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1315-L1323
39,507
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, year, month, day) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && (day != null || (inst.drawDate.year() !== year || inst.drawDate.month() !== month))) { inst.prevDate = inst.drawDate.newDate(); var calendar = inst.options.calendar; var show = this._checkMinMax((year != null ? calendar.newDate(year, month, 1) : calendar.today()), inst); inst.drawDate.date(show.year(), show.month(), (day != null ? day : Math.min(inst.drawDate.day(), calendar.daysInMonth(show.year(), show.month())))); this._update(elem); } }
javascript
function(elem, year, month, day) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && (day != null || (inst.drawDate.year() !== year || inst.drawDate.month() !== month))) { inst.prevDate = inst.drawDate.newDate(); var calendar = inst.options.calendar; var show = this._checkMinMax((year != null ? calendar.newDate(year, month, 1) : calendar.today()), inst); inst.drawDate.date(show.year(), show.month(), (day != null ? day : Math.min(inst.drawDate.day(), calendar.daysInMonth(show.year(), show.month())))); this._update(elem); } }
[ "function", "(", "elem", ",", "year", ",", "month", ",", "day", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", "&&", "(", "day", "!=", "null", "||", "(", "inst", ".", "drawDate", ".", "year", "(", ")", "!==", "year", "||", "inst", ".", "drawDate", ".", "month", "(", ")", "!==", "month", ")", ")", ")", "{", "inst", ".", "prevDate", "=", "inst", ".", "drawDate", ".", "newDate", "(", ")", ";", "var", "calendar", "=", "inst", ".", "options", ".", "calendar", ";", "var", "show", "=", "this", ".", "_checkMinMax", "(", "(", "year", "!=", "null", "?", "calendar", ".", "newDate", "(", "year", ",", "month", ",", "1", ")", ":", "calendar", ".", "today", "(", ")", ")", ",", "inst", ")", ";", "inst", ".", "drawDate", ".", "date", "(", "show", ".", "year", "(", ")", ",", "show", ".", "month", "(", ")", ",", "(", "day", "!=", "null", "?", "day", ":", "Math", ".", "min", "(", "inst", ".", "drawDate", ".", "day", "(", ")", ",", "calendar", ".", "daysInMonth", "(", "show", ".", "year", "(", ")", ",", "show", ".", "month", "(", ")", ")", ")", ")", ")", ";", "this", ".", "_update", "(", "elem", ")", ";", "}", "}" ]
Set the currently shown month, defaulting to today's. @memberof CalendarsPicker @param elem {Element} The control to affect. @param [year] {number} The year to show. @param [month] {number} The month to show (1-12). @param [day] {number} The day to show. @example $(selector).datepick('showMonth', 2014, 12, 25)
[ "Set", "the", "currently", "shown", "month", "defaulting", "to", "today", "s", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1332-L1345
39,508
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, offset) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst)) { var date = inst.drawDate.newDate().add(offset, 'm'); this.showMonth(elem, date.year(), date.month()); } }
javascript
function(elem, offset) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst)) { var date = inst.drawDate.newDate().add(offset, 'm'); this.showMonth(elem, date.year(), date.month()); } }
[ "function", "(", "elem", ",", "offset", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", ")", "{", "var", "date", "=", "inst", ".", "drawDate", ".", "newDate", "(", ")", ".", "add", "(", "offset", ",", "'m'", ")", ";", "this", ".", "showMonth", "(", "elem", ",", "date", ".", "year", "(", ")", ",", "date", ".", "month", "(", ")", ")", ";", "}", "}" ]
Adjust the currently shown month. @memberof CalendarsPicker @param elem {Element} The control to affect. @param offset {number} The number of months to change by. @example $(selector).datepick('changeMonth', 2)
[ "Adjust", "the", "currently", "shown", "month", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1352-L1358
39,509
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, target) { var inst = this._getInst(elem); return ($.isEmptyObject(inst) ? null : inst.options.calendar.fromJD( parseFloat(target.className.replace(/^.*jd(\d+\.5).*$/, '$1')))); }
javascript
function(elem, target) { var inst = this._getInst(elem); return ($.isEmptyObject(inst) ? null : inst.options.calendar.fromJD( parseFloat(target.className.replace(/^.*jd(\d+\.5).*$/, '$1')))); }
[ "function", "(", "elem", ",", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "return", "(", "$", ".", "isEmptyObject", "(", "inst", ")", "?", "null", ":", "inst", ".", "options", ".", "calendar", ".", "fromJD", "(", "parseFloat", "(", "target", ".", "className", ".", "replace", "(", "/", "^.*jd(\\d+\\.5).*$", "/", ",", "'$1'", ")", ")", ")", ")", ";", "}" ]
Retrieve the date associated with an entry in the datepicker. @memberof CalendarsPicker @param elem {Element} The control to examine. @param target {Element} The selected datepicker element. @return {CDate} The corresponding date, or <code>null</code>. @example var date = $(selector).datepick('retrieveDate', $('div.datepick-popup a:contains(10)')[0])
[ "Retrieve", "the", "date", "associated", "with", "an", "entry", "in", "the", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1392-L1396
39,510
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(elem, target) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && !this.isDisabled(elem)) { var date = this.retrieveDate(elem, target); if (inst.options.multiSelect) { var found = false; for (var i = 0; i < inst.selectedDates.length; i++) { if (date.compareTo(inst.selectedDates[i]) === 0) { inst.selectedDates.splice(i, 1); found = true; break; } } if (!found && inst.selectedDates.length < inst.options.multiSelect) { inst.selectedDates.push(date); } } else if (inst.options.rangeSelect) { if (inst.pickingRange) { inst.selectedDates[1] = date; } else { inst.selectedDates = [date, date]; } inst.pickingRange = !inst.pickingRange; } else { inst.selectedDates = [date]; } inst.prevDate = inst.drawDate = date.newDate(); this._updateInput(elem); if (inst.inline || inst.pickingRange || inst.selectedDates.length < (inst.options.multiSelect || (inst.options.rangeSelect ? 2 : 1))) { this._update(elem); } else { this.hide(elem); } } }
javascript
function(elem, target) { var inst = this._getInst(elem); if (!$.isEmptyObject(inst) && !this.isDisabled(elem)) { var date = this.retrieveDate(elem, target); if (inst.options.multiSelect) { var found = false; for (var i = 0; i < inst.selectedDates.length; i++) { if (date.compareTo(inst.selectedDates[i]) === 0) { inst.selectedDates.splice(i, 1); found = true; break; } } if (!found && inst.selectedDates.length < inst.options.multiSelect) { inst.selectedDates.push(date); } } else if (inst.options.rangeSelect) { if (inst.pickingRange) { inst.selectedDates[1] = date; } else { inst.selectedDates = [date, date]; } inst.pickingRange = !inst.pickingRange; } else { inst.selectedDates = [date]; } inst.prevDate = inst.drawDate = date.newDate(); this._updateInput(elem); if (inst.inline || inst.pickingRange || inst.selectedDates.length < (inst.options.multiSelect || (inst.options.rangeSelect ? 2 : 1))) { this._update(elem); } else { this.hide(elem); } } }
[ "function", "(", "elem", ",", "target", ")", "{", "var", "inst", "=", "this", ".", "_getInst", "(", "elem", ")", ";", "if", "(", "!", "$", ".", "isEmptyObject", "(", "inst", ")", "&&", "!", "this", ".", "isDisabled", "(", "elem", ")", ")", "{", "var", "date", "=", "this", ".", "retrieveDate", "(", "elem", ",", "target", ")", ";", "if", "(", "inst", ".", "options", ".", "multiSelect", ")", "{", "var", "found", "=", "false", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "inst", ".", "selectedDates", ".", "length", ";", "i", "++", ")", "{", "if", "(", "date", ".", "compareTo", "(", "inst", ".", "selectedDates", "[", "i", "]", ")", "===", "0", ")", "{", "inst", ".", "selectedDates", ".", "splice", "(", "i", ",", "1", ")", ";", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "found", "&&", "inst", ".", "selectedDates", ".", "length", "<", "inst", ".", "options", ".", "multiSelect", ")", "{", "inst", ".", "selectedDates", ".", "push", "(", "date", ")", ";", "}", "}", "else", "if", "(", "inst", ".", "options", ".", "rangeSelect", ")", "{", "if", "(", "inst", ".", "pickingRange", ")", "{", "inst", ".", "selectedDates", "[", "1", "]", "=", "date", ";", "}", "else", "{", "inst", ".", "selectedDates", "=", "[", "date", ",", "date", "]", ";", "}", "inst", ".", "pickingRange", "=", "!", "inst", ".", "pickingRange", ";", "}", "else", "{", "inst", ".", "selectedDates", "=", "[", "date", "]", ";", "}", "inst", ".", "prevDate", "=", "inst", ".", "drawDate", "=", "date", ".", "newDate", "(", ")", ";", "this", ".", "_updateInput", "(", "elem", ")", ";", "if", "(", "inst", ".", "inline", "||", "inst", ".", "pickingRange", "||", "inst", ".", "selectedDates", ".", "length", "<", "(", "inst", ".", "options", ".", "multiSelect", "||", "(", "inst", ".", "options", ".", "rangeSelect", "?", "2", ":", "1", ")", ")", ")", "{", "this", ".", "_update", "(", "elem", ")", ";", "}", "else", "{", "this", ".", "hide", "(", "elem", ")", ";", "}", "}", "}" ]
Select a date for this datepicker. @memberof CalendarsPicker @param elem {Element} The control to examine. @param target {Element} The selected datepicker element. @example $(selector).datepick('selectDate', $('div.datepick-popup a:contains(10)')[0])
[ "Select", "a", "date", "for", "this", "datepicker", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1403-L1442
39,511
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(value) { return (inst.options.localNumbers && calendar.local.digits ? calendar.local.digits(value) : value); }
javascript
function(value) { return (inst.options.localNumbers && calendar.local.digits ? calendar.local.digits(value) : value); }
[ "function", "(", "value", ")", "{", "return", "(", "inst", ".", "options", ".", "localNumbers", "&&", "calendar", ".", "local", ".", "digits", "?", "calendar", ".", "local", ".", "digits", "(", "value", ")", ":", "value", ")", ";", "}" ]
Localise numbers if requested and available
[ "Localise", "numbers", "if", "requested", "and", "available" ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1609-L1611
39,512
alexcjohnson/world-calendars
jquery-src/jquery.calendars.picker.js
function(inst, calendar, renderer) { var firstDay = inst.options.firstDay; firstDay = (firstDay == null ? calendar.local.firstDay : firstDay); var header = ''; for (var day = 0; day < calendar.daysInWeek(); day++) { var dow = (day + firstDay) % calendar.daysInWeek(); header += this._prepare(renderer.dayHeader, inst).replace(/\{day\}/g, '<span class="' + this._curDoWClass + dow + '" title="' + calendar.local.dayNames[dow] + '">' + calendar.local.dayNamesMin[dow] + '</span>'); } return header; }
javascript
function(inst, calendar, renderer) { var firstDay = inst.options.firstDay; firstDay = (firstDay == null ? calendar.local.firstDay : firstDay); var header = ''; for (var day = 0; day < calendar.daysInWeek(); day++) { var dow = (day + firstDay) % calendar.daysInWeek(); header += this._prepare(renderer.dayHeader, inst).replace(/\{day\}/g, '<span class="' + this._curDoWClass + dow + '" title="' + calendar.local.dayNames[dow] + '">' + calendar.local.dayNamesMin[dow] + '</span>'); } return header; }
[ "function", "(", "inst", ",", "calendar", ",", "renderer", ")", "{", "var", "firstDay", "=", "inst", ".", "options", ".", "firstDay", ";", "firstDay", "=", "(", "firstDay", "==", "null", "?", "calendar", ".", "local", ".", "firstDay", ":", "firstDay", ")", ";", "var", "header", "=", "''", ";", "for", "(", "var", "day", "=", "0", ";", "day", "<", "calendar", ".", "daysInWeek", "(", ")", ";", "day", "++", ")", "{", "var", "dow", "=", "(", "day", "+", "firstDay", ")", "%", "calendar", ".", "daysInWeek", "(", ")", ";", "header", "+=", "this", ".", "_prepare", "(", "renderer", ".", "dayHeader", ",", "inst", ")", ".", "replace", "(", "/", "\\{day\\}", "/", "g", ",", "'<span class=\"'", "+", "this", ".", "_curDoWClass", "+", "dow", "+", "'\" title=\"'", "+", "calendar", ".", "local", ".", "dayNames", "[", "dow", "]", "+", "'\">'", "+", "calendar", ".", "local", ".", "dayNamesMin", "[", "dow", "]", "+", "'</span>'", ")", ";", "}", "return", "header", ";", "}" ]
Generate the HTML for the day headers. @memberof CalendarsPicker @private @param inst {object} The current instance settings. @param calendar {BaseCalendar} The current calendar. @param renderer {object} The rendering templates. @return {string} A week's worth of day headers.
[ "Generate", "the", "HTML", "for", "the", "day", "headers", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.picker.js#L1681-L1692
39,513
alexcjohnson/world-calendars
jquery-src/jquery.calendars.hebrew.js
function(year, month, day) { var date = this._validate(year, month, day, $.calendars.local.invalidDate); return {yearType: (this.leapYear(date) ? 'embolismic' : 'common') + ' ' + ['deficient', 'regular', 'complete'][this.daysInYear(date) % 10 - 3]}; }
javascript
function(year, month, day) { var date = this._validate(year, month, day, $.calendars.local.invalidDate); return {yearType: (this.leapYear(date) ? 'embolismic' : 'common') + ' ' + ['deficient', 'regular', 'complete'][this.daysInYear(date) % 10 - 3]}; }
[ "function", "(", "year", ",", "month", ",", "day", ")", "{", "var", "date", "=", "this", ".", "_validate", "(", "year", ",", "month", ",", "day", ",", "$", ".", "calendars", ".", "local", ".", "invalidDate", ")", ";", "return", "{", "yearType", ":", "(", "this", ".", "leapYear", "(", "date", ")", "?", "'embolismic'", ":", "'common'", ")", "+", "' '", "+", "[", "'deficient'", ",", "'regular'", ",", "'complete'", "]", "[", "this", ".", "daysInYear", "(", "date", ")", "%", "10", "-", "3", "]", "}", ";", "}" ]
Retrieve additional information about a date - year type. @memberof HebrewCalendar @param year {CDate|number} The date to examine or the year to examine. @param [month] {number} The month to examine. @param [day] {number} The day to examine. @return {object} Additional information - contents depends on calendar. @throws Error if an invalid date or a different calendar used.
[ "Retrieve", "additional", "information", "about", "a", "date", "-", "year", "type", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.hebrew.js#L167-L171
39,514
alexcjohnson/world-calendars
jquery-src/jquery.calendars.hebrew.js
function(year) { var months = Math.floor((235 * year - 234) / 19); var parts = 12084 + 13753 * months; var day = months * 29 + Math.floor(parts / 25920); if (mod(3 * (day + 1), 7) < 3) { day++; } return day; }
javascript
function(year) { var months = Math.floor((235 * year - 234) / 19); var parts = 12084 + 13753 * months; var day = months * 29 + Math.floor(parts / 25920); if (mod(3 * (day + 1), 7) < 3) { day++; } return day; }
[ "function", "(", "year", ")", "{", "var", "months", "=", "Math", ".", "floor", "(", "(", "235", "*", "year", "-", "234", ")", "/", "19", ")", ";", "var", "parts", "=", "12084", "+", "13753", "*", "months", ";", "var", "day", "=", "months", "*", "29", "+", "Math", ".", "floor", "(", "parts", "/", "25920", ")", ";", "if", "(", "mod", "(", "3", "*", "(", "day", "+", "1", ")", ",", "7", ")", "<", "3", ")", "{", "day", "++", ";", "}", "return", "day", ";", "}" ]
Test for delay of start of new year and to avoid Sunday, Wednesday, or Friday as start of the new year. @memberof HebrewCalendar @private @param year {number} The year to examine. @return {number} The days to offset by.
[ "Test", "for", "delay", "of", "start", "of", "new", "year", "and", "to", "avoid", "Sunday", "Wednesday", "or", "Friday", "as", "start", "of", "the", "new", "year", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.hebrew.js#L211-L219
39,515
alexcjohnson/world-calendars
jquery-src/jquery.calendars.hebrew.js
function(year) { var last = this._delay1(year - 1); var present = this._delay1(year); var next = this._delay1(year + 1); return ((next - present) === 356 ? 2 : ((present - last) === 382 ? 1 : 0)); }
javascript
function(year) { var last = this._delay1(year - 1); var present = this._delay1(year); var next = this._delay1(year + 1); return ((next - present) === 356 ? 2 : ((present - last) === 382 ? 1 : 0)); }
[ "function", "(", "year", ")", "{", "var", "last", "=", "this", ".", "_delay1", "(", "year", "-", "1", ")", ";", "var", "present", "=", "this", ".", "_delay1", "(", "year", ")", ";", "var", "next", "=", "this", ".", "_delay1", "(", "year", "+", "1", ")", ";", "return", "(", "(", "next", "-", "present", ")", "===", "356", "?", "2", ":", "(", "(", "present", "-", "last", ")", "===", "382", "?", "1", ":", "0", ")", ")", ";", "}" ]
Check for delay in start of new year due to length of adjacent years. @memberof HebrewCalendar @private @param year {number} The year to examine. @return {number} The days to offset by.
[ "Check", "for", "delay", "in", "start", "of", "new", "year", "due", "to", "length", "of", "adjacent", "years", "." ]
810693882512dec1b804456f8d435b962bd6cf31
https://github.com/alexcjohnson/world-calendars/blob/810693882512dec1b804456f8d435b962bd6cf31/jquery-src/jquery.calendars.hebrew.js#L226-L231
39,516
biancojs/events
index.next.js
manageEvents
function manageEvents(els, evList, cb, method, options) { els = domToArray(els) split(evList).forEach((e) => { els.forEach(el => el[method](e, cb, options || false)) }) }
javascript
function manageEvents(els, evList, cb, method, options) { els = domToArray(els) split(evList).forEach((e) => { els.forEach(el => el[method](e, cb, options || false)) }) }
[ "function", "manageEvents", "(", "els", ",", "evList", ",", "cb", ",", "method", ",", "options", ")", "{", "els", "=", "domToArray", "(", "els", ")", "split", "(", "evList", ")", ".", "forEach", "(", "(", "e", ")", "=>", "{", "els", ".", "forEach", "(", "el", "=>", "el", "[", "method", "]", "(", "e", ",", "cb", ",", "options", "||", "false", ")", ")", "}", ")", "}" ]
Set a listener for all the events received separated by spaces @param { HTMLElement|NodeList|Array } els - DOM node/s where the listeners will be bound @param { string } evList - list of events we want to bind or unbind space separated @param { Function } cb - listeners callback @param { string } method - either 'addEventListener' or 'removeEventListener' @param { Object } options - event options (capture, once and passive) @returns { undefined } @private
[ "Set", "a", "listener", "for", "all", "the", "events", "received", "separated", "by", "spaces" ]
5f7f23932676b4349102dc41fff565a727cd97dc
https://github.com/biancojs/events/blob/5f7f23932676b4349102dc41fff565a727cd97dc/index.next.js#L21-L27
39,517
seattleacademy/mcp9808
index.js
WriteData
function WriteData(Register, ByteArray, Callback) { i2cdevice.writeBytes(Register, ByteArray, function(err) { Callback(err); }); }
javascript
function WriteData(Register, ByteArray, Callback) { i2cdevice.writeBytes(Register, ByteArray, function(err) { Callback(err); }); }
[ "function", "WriteData", "(", "Register", ",", "ByteArray", ",", "Callback", ")", "{", "i2cdevice", ".", "writeBytes", "(", "Register", ",", "ByteArray", ",", "function", "(", "err", ")", "{", "Callback", "(", "err", ")", ";", "}", ")", ";", "}" ]
sends the LSB first. The device wants the MSB first.
[ "sends", "the", "LSB", "first", ".", "The", "device", "wants", "the", "MSB", "first", "." ]
211c07158e0585dfc3c2149b1e5e93d105d89723
https://github.com/seattleacademy/mcp9808/blob/211c07158e0585dfc3c2149b1e5e93d105d89723/index.js#L69-L75
39,518
mangojuicejs/mangojuice
packages/mangojuice-lazy/src/createLazyBlock.js
createLazyBlock
function createLazyBlock( { resolver, chunkName, initModel, loadingView, messages } = {} ) { const resolveState = { resolver: null, block: null, msgs: [], chunkName }; resolveState.resolver = createBlockResolver(resolver, resolveState); const lazyLogic = createLazyLogic(resolveState, initModel); const lazyView = createLazyView(resolveState, loadingView); const lazyMessages = createLazyMessages(resolveState, messages); return { resolver: resolveState.resolver, Logic: lazyLogic, View: lazyView, Messages: lazyMessages }; }
javascript
function createLazyBlock( { resolver, chunkName, initModel, loadingView, messages } = {} ) { const resolveState = { resolver: null, block: null, msgs: [], chunkName }; resolveState.resolver = createBlockResolver(resolver, resolveState); const lazyLogic = createLazyLogic(resolveState, initModel); const lazyView = createLazyView(resolveState, loadingView); const lazyMessages = createLazyMessages(resolveState, messages); return { resolver: resolveState.resolver, Logic: lazyLogic, View: lazyView, Messages: lazyMessages }; }
[ "function", "createLazyBlock", "(", "{", "resolver", ",", "chunkName", ",", "initModel", ",", "loadingView", ",", "messages", "}", "=", "{", "}", ")", "{", "const", "resolveState", "=", "{", "resolver", ":", "null", ",", "block", ":", "null", ",", "msgs", ":", "[", "]", ",", "chunkName", "}", ";", "resolveState", ".", "resolver", "=", "createBlockResolver", "(", "resolver", ",", "resolveState", ")", ";", "const", "lazyLogic", "=", "createLazyLogic", "(", "resolveState", ",", "initModel", ")", ";", "const", "lazyView", "=", "createLazyView", "(", "resolveState", ",", "loadingView", ")", ";", "const", "lazyMessages", "=", "createLazyMessages", "(", "resolveState", ",", "messages", ")", ";", "return", "{", "resolver", ":", "resolveState", ".", "resolver", ",", "Logic", ":", "lazyLogic", ",", "View", ":", "lazyView", ",", "Messages", ":", "lazyMessages", "}", ";", "}" ]
Creates a Block which works as a proxy for some other block, which will be returned by `resolver` function provided in the options object. `resolver` can also return a promise which should resolve and actual block. @param {function} options.resolver @param {string} options.chunkName @param {string} options.initModel @param {function} options.loadingView @param {Object} options.lazyCommands @return {Object}
[ "Creates", "a", "Block", "which", "works", "as", "a", "proxy", "for", "some", "other", "block", "which", "will", "be", "returned", "by", "resolver", "function", "provided", "in", "the", "options", "object", ".", "resolver", "can", "also", "return", "a", "promise", "which", "should", "resolve", "and", "actual", "block", "." ]
15bda5648462c171cc8e2dd0f8f15696655ce11a
https://github.com/mangojuicejs/mangojuice/blob/15bda5648462c171cc8e2dd0f8f15696655ce11a/packages/mangojuice-lazy/src/createLazyBlock.js#L129-L144
39,519
landau/fscache
lib/cache.js
function(arg) { var hash = crypto.createHash('md5') .update(JSON.stringify(arg)) .digest('hex'); return path.join(this.dir, hash); }
javascript
function(arg) { var hash = crypto.createHash('md5') .update(JSON.stringify(arg)) .digest('hex'); return path.join(this.dir, hash); }
[ "function", "(", "arg", ")", "{", "var", "hash", "=", "crypto", ".", "createHash", "(", "'md5'", ")", ".", "update", "(", "JSON", ".", "stringify", "(", "arg", ")", ")", ".", "digest", "(", "'hex'", ")", ";", "return", "path", ".", "join", "(", "this", ".", "dir", ",", "hash", ")", ";", "}" ]
Creates a md5 hash based on the stringified arg
[ "Creates", "a", "md5", "hash", "based", "on", "the", "stringified", "arg" ]
18d0127c06c4da6b2ac03701f8e136ee19ac722c
https://github.com/landau/fscache/blob/18d0127c06c4da6b2ac03701f8e136ee19ac722c/lib/cache.js#L24-L29
39,520
gusnips/koa-error-ejs
index.js
error
function error(opts) { //define your custom views opts = opts || {}; //custom views if(!opts.custom) opts.custom={}; // better to disable layout in not explicity set, in case there are error in it if(!opts.layout) opts.layout= false; // @todo to be easier to install, should render from this module path if(!opts.view) opts.view= 'error'; return function *error(next){ var env= this.app.env; try { yield next; if (this.response.status==404 && !this.response.body) this.throw(404); } catch (err) { this.status = err.status || 500; // application this.app.emit('error', err, this); // accepted types switch (this.accepts('html', 'text', 'json')) { case 'text': if (env==='development') this.body= err.message else if (err.expose) this.body= err.message else this.body= http.STATUS_CODES[this.status]; break; case 'json': if (env==='development') this.body= {error: err.message} else if (err.expose) this.body= {error: err.message} else this.body= {error: http.STATUS_CODES[this.status]} break; case 'html': var view= typeof opts.custom[this.status]!=='undefined' ? opts.custom[this.status] : opts.view; var options= { layout: opts.layout, env: env, ctx: this, request: this.request, response: this.response, error: err.message, stack: err.stack, status: this.status, code: err.code }; //in case of any error view error try{ yield this.render(view, options); }catch(e){ this.body= '<h1>'+e.code+'</h1><h3>'+e.message+'</h3><pre><code>'+e.stack+'</code></pre>' } break; } } } }
javascript
function error(opts) { //define your custom views opts = opts || {}; //custom views if(!opts.custom) opts.custom={}; // better to disable layout in not explicity set, in case there are error in it if(!opts.layout) opts.layout= false; // @todo to be easier to install, should render from this module path if(!opts.view) opts.view= 'error'; return function *error(next){ var env= this.app.env; try { yield next; if (this.response.status==404 && !this.response.body) this.throw(404); } catch (err) { this.status = err.status || 500; // application this.app.emit('error', err, this); // accepted types switch (this.accepts('html', 'text', 'json')) { case 'text': if (env==='development') this.body= err.message else if (err.expose) this.body= err.message else this.body= http.STATUS_CODES[this.status]; break; case 'json': if (env==='development') this.body= {error: err.message} else if (err.expose) this.body= {error: err.message} else this.body= {error: http.STATUS_CODES[this.status]} break; case 'html': var view= typeof opts.custom[this.status]!=='undefined' ? opts.custom[this.status] : opts.view; var options= { layout: opts.layout, env: env, ctx: this, request: this.request, response: this.response, error: err.message, stack: err.stack, status: this.status, code: err.code }; //in case of any error view error try{ yield this.render(view, options); }catch(e){ this.body= '<h1>'+e.code+'</h1><h3>'+e.message+'</h3><pre><code>'+e.stack+'</code></pre>' } break; } } } }
[ "function", "error", "(", "opts", ")", "{", "//define your custom views", "opts", "=", "opts", "||", "{", "}", ";", "//custom views", "if", "(", "!", "opts", ".", "custom", ")", "opts", ".", "custom", "=", "{", "}", ";", "// better to disable layout in not explicity set, in case there are error in it", "if", "(", "!", "opts", ".", "layout", ")", "opts", ".", "layout", "=", "false", ";", "// @todo to be easier to install, should render from this module path", "if", "(", "!", "opts", ".", "view", ")", "opts", ".", "view", "=", "'error'", ";", "return", "function", "*", "error", "(", "next", ")", "{", "var", "env", "=", "this", ".", "app", ".", "env", ";", "try", "{", "yield", "next", ";", "if", "(", "this", ".", "response", ".", "status", "==", "404", "&&", "!", "this", ".", "response", ".", "body", ")", "this", ".", "throw", "(", "404", ")", ";", "}", "catch", "(", "err", ")", "{", "this", ".", "status", "=", "err", ".", "status", "||", "500", ";", "// application", "this", ".", "app", ".", "emit", "(", "'error'", ",", "err", ",", "this", ")", ";", "// accepted types", "switch", "(", "this", ".", "accepts", "(", "'html'", ",", "'text'", ",", "'json'", ")", ")", "{", "case", "'text'", ":", "if", "(", "env", "===", "'development'", ")", "this", ".", "body", "=", "err", ".", "message", "else", "if", "(", "err", ".", "expose", ")", "this", ".", "body", "=", "err", ".", "message", "else", "this", ".", "body", "=", "http", ".", "STATUS_CODES", "[", "this", ".", "status", "]", ";", "break", ";", "case", "'json'", ":", "if", "(", "env", "===", "'development'", ")", "this", ".", "body", "=", "{", "error", ":", "err", ".", "message", "}", "else", "if", "(", "err", ".", "expose", ")", "this", ".", "body", "=", "{", "error", ":", "err", ".", "message", "}", "else", "this", ".", "body", "=", "{", "error", ":", "http", ".", "STATUS_CODES", "[", "this", ".", "status", "]", "}", "break", ";", "case", "'html'", ":", "var", "view", "=", "typeof", "opts", ".", "custom", "[", "this", ".", "status", "]", "!==", "'undefined'", "?", "opts", ".", "custom", "[", "this", ".", "status", "]", ":", "opts", ".", "view", ";", "var", "options", "=", "{", "layout", ":", "opts", ".", "layout", ",", "env", ":", "env", ",", "ctx", ":", "this", ",", "request", ":", "this", ".", "request", ",", "response", ":", "this", ".", "response", ",", "error", ":", "err", ".", "message", ",", "stack", ":", "err", ".", "stack", ",", "status", ":", "this", ".", "status", ",", "code", ":", "err", ".", "code", "}", ";", "//in case of any error view error", "try", "{", "yield", "this", ".", "render", "(", "view", ",", "options", ")", ";", "}", "catch", "(", "e", ")", "{", "this", ".", "body", "=", "'<h1>'", "+", "e", ".", "code", "+", "'</h1><h3>'", "+", "e", ".", "message", "+", "'</h3><pre><code>'", "+", "e", ".", "stack", "+", "'</code></pre>'", "}", "break", ";", "}", "}", "}", "}" ]
Error middleware for EJS. @param {Object} opts `custom` Object views for a status, for example: { 404: 'error/not-found' } `view` String default error view. Defaults to {view.root}/error `layout` String|Boolean layout to use on error view, or false if none. False by default.
[ "Error", "middleware", "for", "EJS", "." ]
177ff9d13f0d95151961106f43d97ade0fa4e0aa
https://github.com/gusnips/koa-error-ejs/blob/177ff9d13f0d95151961106f43d97ade0fa4e0aa/index.js#L24-L92
39,521
chrisJohn404/ljswitchboard-ljm_device_curator
lib/device_curator.js
function(addresses) { var defered = q.defer(); var currentStep = 0; var numSteps = addresses.length; var results = []; var handleReadSuccess = function(res) { results.push({'address': addresses[currentStep], 'isErr': false, 'data': res}); if(currentStep < numSteps) { currentStep += 1; performRead(); } else { defered.resolve(results); } }; var handleReadError = function(err) { results.push({'address': addresses[currentStep], 'isErr': true, 'data': err}); if(currentStep < numSteps) { currentStep += 1; performRead(); } else { defered.resolve(results); } }; var performRead = function() { self.qRead(addresses[currentStep]) .then(handleReadSuccess, handleReadError); }; performRead(); return defered.promise; }
javascript
function(addresses) { var defered = q.defer(); var currentStep = 0; var numSteps = addresses.length; var results = []; var handleReadSuccess = function(res) { results.push({'address': addresses[currentStep], 'isErr': false, 'data': res}); if(currentStep < numSteps) { currentStep += 1; performRead(); } else { defered.resolve(results); } }; var handleReadError = function(err) { results.push({'address': addresses[currentStep], 'isErr': true, 'data': err}); if(currentStep < numSteps) { currentStep += 1; performRead(); } else { defered.resolve(results); } }; var performRead = function() { self.qRead(addresses[currentStep]) .then(handleReadSuccess, handleReadError); }; performRead(); return defered.promise; }
[ "function", "(", "addresses", ")", "{", "var", "defered", "=", "q", ".", "defer", "(", ")", ";", "var", "currentStep", "=", "0", ";", "var", "numSteps", "=", "addresses", ".", "length", ";", "var", "results", "=", "[", "]", ";", "var", "handleReadSuccess", "=", "function", "(", "res", ")", "{", "results", ".", "push", "(", "{", "'address'", ":", "addresses", "[", "currentStep", "]", ",", "'isErr'", ":", "false", ",", "'data'", ":", "res", "}", ")", ";", "if", "(", "currentStep", "<", "numSteps", ")", "{", "currentStep", "+=", "1", ";", "performRead", "(", ")", ";", "}", "else", "{", "defered", ".", "resolve", "(", "results", ")", ";", "}", "}", ";", "var", "handleReadError", "=", "function", "(", "err", ")", "{", "results", ".", "push", "(", "{", "'address'", ":", "addresses", "[", "currentStep", "]", ",", "'isErr'", ":", "true", ",", "'data'", ":", "err", "}", ")", ";", "if", "(", "currentStep", "<", "numSteps", ")", "{", "currentStep", "+=", "1", ";", "performRead", "(", ")", ";", "}", "else", "{", "defered", ".", "resolve", "(", "results", ")", ";", "}", "}", ";", "var", "performRead", "=", "function", "(", ")", "{", "self", ".", "qRead", "(", "addresses", "[", "currentStep", "]", ")", ".", "then", "(", "handleReadSuccess", ",", "handleReadError", ")", ";", "}", ";", "performRead", "(", ")", ";", "return", "defered", ".", "promise", ";", "}" ]
An experimental implementation of the readMultiple function that doesn't use the async library.
[ "An", "experimental", "implementation", "of", "the", "readMultiple", "function", "that", "doesn", "t", "use", "the", "async", "library", "." ]
36cb25645dfa0a68e906d5ec43e5514391947257
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/device_curator.js#L1226-L1258
39,522
sorellabs/black
src/core.js
unpack
function unpack(kind, root, target, proto, source){ if (ownp(kind)) do_unpack(proto, source, methodize) if (genericp(kind)) do_unpack(target, source) if (utilsp(kind)) do_unpack(root, source.$black_utils) }
javascript
function unpack(kind, root, target, proto, source){ if (ownp(kind)) do_unpack(proto, source, methodize) if (genericp(kind)) do_unpack(target, source) if (utilsp(kind)) do_unpack(root, source.$black_utils) }
[ "function", "unpack", "(", "kind", ",", "root", ",", "target", ",", "proto", ",", "source", ")", "{", "if", "(", "ownp", "(", "kind", ")", ")", "do_unpack", "(", "proto", ",", "source", ",", "methodize", ")", "if", "(", "genericp", "(", "kind", ")", ")", "do_unpack", "(", "target", ",", "source", ")", "if", "(", "utilsp", "(", "kind", ")", ")", "do_unpack", "(", "root", ",", "source", ".", "$black_utils", ")", "}" ]
Unpacks a black module so it's used in a sane way
[ "Unpacks", "a", "black", "module", "so", "it", "s", "used", "in", "a", "sane", "way" ]
713a5ac396c4b8d5d501f5370272c20713839fc1
https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L24-L28
39,523
sorellabs/black
src/core.js
unpack_all
function unpack_all(kind, global) { keys(this).forEach(function(module) { module = this[module] if (!fnp(module)) unpack( kind , global || top , module.$black_box , module.$black_proto , module) }, this) }
javascript
function unpack_all(kind, global) { keys(this).forEach(function(module) { module = this[module] if (!fnp(module)) unpack( kind , global || top , module.$black_box , module.$black_proto , module) }, this) }
[ "function", "unpack_all", "(", "kind", ",", "global", ")", "{", "keys", "(", "this", ")", ".", "forEach", "(", "function", "(", "module", ")", "{", "module", "=", "this", "[", "module", "]", "if", "(", "!", "fnp", "(", "module", ")", ")", "unpack", "(", "kind", ",", "global", "||", "top", ",", "module", ".", "$black_box", ",", "module", ".", "$black_proto", ",", "module", ")", "}", ",", "this", ")", "}" ]
Unpacks all modules in black. Utils go in `target` or the global obj
[ "Unpacks", "all", "modules", "in", "black", ".", "Utils", "go", "in", "target", "or", "the", "global", "obj" ]
713a5ac396c4b8d5d501f5370272c20713839fc1
https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L41-L49
39,524
sorellabs/black
src/core.js
methodize
function methodize(fn) { return function() { var args args = slice.call(arguments) return fn.apply(this, [this].concat(args)) } }
javascript
function methodize(fn) { return function() { var args args = slice.call(arguments) return fn.apply(this, [this].concat(args)) } }
[ "function", "methodize", "(", "fn", ")", "{", "return", "function", "(", ")", "{", "var", "args", "args", "=", "slice", ".", "call", "(", "arguments", ")", "return", "fn", ".", "apply", "(", "this", ",", "[", "this", "]", ".", "concat", "(", "args", ")", ")", "}", "}" ]
Transforms a generic method into a SLOOOOOOOOOOOW instance method.
[ "Transforms", "a", "generic", "method", "into", "a", "SLOOOOOOOOOOOW", "instance", "method", "." ]
713a5ac396c4b8d5d501f5370272c20713839fc1
https://github.com/sorellabs/black/blob/713a5ac396c4b8d5d501f5370272c20713839fc1/src/core.js#L52-L56
39,525
chrisJohn404/ljswitchboard-ljm_device_curator
lib/manufacturing_info_operations.js
createReadManufacturingInfoBundle
function createReadManufacturingInfoBundle() { debugRMIOps('in createReadManufacturingInfoBundle'); // Initialize the bundle object with some basic data. var bundle = { 'info': {}, 'infoString': '', 'manufacturingData': manufacturingData, 'isError': false, 'errorStep': '', 'error': undefined, 'errorCode': 0, }; // Initialize the manufacturing info object with dummy data. manufacturingData.forEach(function(manData) { if(manData.type === 'str') { bundle.info[manData.key] = ''; } else if(manData.type === 'fl4') { bundle.info[manData.key] = 0.000; } else if(manData.type === 'int') { bundle.info[manData.key] = 0; } else { bundle.info[manData.key] = ''; } }); return bundle; }
javascript
function createReadManufacturingInfoBundle() { debugRMIOps('in createReadManufacturingInfoBundle'); // Initialize the bundle object with some basic data. var bundle = { 'info': {}, 'infoString': '', 'manufacturingData': manufacturingData, 'isError': false, 'errorStep': '', 'error': undefined, 'errorCode': 0, }; // Initialize the manufacturing info object with dummy data. manufacturingData.forEach(function(manData) { if(manData.type === 'str') { bundle.info[manData.key] = ''; } else if(manData.type === 'fl4') { bundle.info[manData.key] = 0.000; } else if(manData.type === 'int') { bundle.info[manData.key] = 0; } else { bundle.info[manData.key] = ''; } }); return bundle; }
[ "function", "createReadManufacturingInfoBundle", "(", ")", "{", "debugRMIOps", "(", "'in createReadManufacturingInfoBundle'", ")", ";", "// Initialize the bundle object with some basic data.", "var", "bundle", "=", "{", "'info'", ":", "{", "}", ",", "'infoString'", ":", "''", ",", "'manufacturingData'", ":", "manufacturingData", ",", "'isError'", ":", "false", ",", "'errorStep'", ":", "''", ",", "'error'", ":", "undefined", ",", "'errorCode'", ":", "0", ",", "}", ";", "// Initialize the manufacturing info object with dummy data.", "manufacturingData", ".", "forEach", "(", "function", "(", "manData", ")", "{", "if", "(", "manData", ".", "type", "===", "'str'", ")", "{", "bundle", ".", "info", "[", "manData", ".", "key", "]", "=", "''", ";", "}", "else", "if", "(", "manData", ".", "type", "===", "'fl4'", ")", "{", "bundle", ".", "info", "[", "manData", ".", "key", "]", "=", "0.000", ";", "}", "else", "if", "(", "manData", ".", "type", "===", "'int'", ")", "{", "bundle", ".", "info", "[", "manData", ".", "key", "]", "=", "0", ";", "}", "else", "{", "bundle", ".", "info", "[", "manData", ".", "key", "]", "=", "''", ";", "}", "}", ")", ";", "return", "bundle", ";", "}" ]
Define a function that is used to initialize the data object built up during the process of reading the manufacturing data from a T7.
[ "Define", "a", "function", "that", "is", "used", "to", "initialize", "the", "data", "object", "built", "up", "during", "the", "process", "of", "reading", "the", "manufacturing", "data", "from", "a", "T7", "." ]
36cb25645dfa0a68e906d5ec43e5514391947257
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/manufacturing_info_operations.js#L145-L172
39,526
chrisJohn404/ljswitchboard-ljm_device_curator
lib/manufacturing_info_operations.js
readManufacturingInfoFlashData
function readManufacturingInfoFlashData(bundle) { debugRMIOps('in readManufacturingInfoFlashData'); var defered = q.defer(); var startingAddress = 0x3C6000; var numIntsToRead = 8*8; self.readFlash(startingAddress, numIntsToRead) .then(function(res) { // res is an object with an attribute "results" that is an array // of bytes. Therefore this debug call outputs a lot of data: // debugRMIOps('in readManufacturingInfoFlashData res', res); var str = ''; var rawData = []; res.results.forEach(function(val) { var bA = (val >> 24) & 0xFF; rawData.push(bA); var bB = (val >> 16) & 0xFF; rawData.push(bB); var bC = (val >> 8) & 0xFF; rawData.push(bC); var bD = (val >> 0) & 0xFF; rawData.push(bD); }); function isASCII(str, extended) { return (extended ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str); } // debugRMIOps('in readManufacturingInfoFlashData', rawData); rawData.forEach(function(raw) { var newStrPartial = String.fromCharCode(raw); if(isASCII(newStrPartial)) { str += newStrPartial; } }); debugRMIOps('in readManufacturingInfoFlashData', str); // console.log('Data:'); // console.log(str); var noReturnChars = str.split('\r').join(''); strPartials = noReturnChars.split('\n'); var manufacturingInfoStr = ''; // console.log('Processing partials'); strPartials.forEach(function(strPartial) { try { // console.log('Checking partial', strPartial); if(isData.test(strPartial)) { // console.log('Parsing partial', strPartial); var parsedInfo = parseManufacturingInfo(strPartial); // console.log('Saving partial', strPartial, parsedInfo); manufacturingInfoStr += parsedInfo.str; manufacturingInfoStr += ': '; manufacturingInfoStr += parsedInfo.rawData; manufacturingInfoStr += '\n'; bundle = saveParsedDataToBundle(bundle, parsedInfo); } else { // console.log('Not Checking partial', strPartial); } } catch(err) { errorLog('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial); errorLog(err.stack); console.error('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial); } }); // console.log(noReturnChars); bundle.infoString = manufacturingInfoStr; // console.log(bundle.info); defered.resolve(bundle); }, function(err) { debugRMIOps('in readManufacturingInfoFlashData err', err); bundle.isError = true; bundle.errorStep = 'readManufacturingInfoFlashData'; bundle.error = modbusMap.getErrorInfo(err); bundle.errorCode = err; defered.reject(bundle); }); return defered.promise; }
javascript
function readManufacturingInfoFlashData(bundle) { debugRMIOps('in readManufacturingInfoFlashData'); var defered = q.defer(); var startingAddress = 0x3C6000; var numIntsToRead = 8*8; self.readFlash(startingAddress, numIntsToRead) .then(function(res) { // res is an object with an attribute "results" that is an array // of bytes. Therefore this debug call outputs a lot of data: // debugRMIOps('in readManufacturingInfoFlashData res', res); var str = ''; var rawData = []; res.results.forEach(function(val) { var bA = (val >> 24) & 0xFF; rawData.push(bA); var bB = (val >> 16) & 0xFF; rawData.push(bB); var bC = (val >> 8) & 0xFF; rawData.push(bC); var bD = (val >> 0) & 0xFF; rawData.push(bD); }); function isASCII(str, extended) { return (extended ? /^[\x00-\xFF]*$/ : /^[\x00-\x7F]*$/).test(str); } // debugRMIOps('in readManufacturingInfoFlashData', rawData); rawData.forEach(function(raw) { var newStrPartial = String.fromCharCode(raw); if(isASCII(newStrPartial)) { str += newStrPartial; } }); debugRMIOps('in readManufacturingInfoFlashData', str); // console.log('Data:'); // console.log(str); var noReturnChars = str.split('\r').join(''); strPartials = noReturnChars.split('\n'); var manufacturingInfoStr = ''; // console.log('Processing partials'); strPartials.forEach(function(strPartial) { try { // console.log('Checking partial', strPartial); if(isData.test(strPartial)) { // console.log('Parsing partial', strPartial); var parsedInfo = parseManufacturingInfo(strPartial); // console.log('Saving partial', strPartial, parsedInfo); manufacturingInfoStr += parsedInfo.str; manufacturingInfoStr += ': '; manufacturingInfoStr += parsedInfo.rawData; manufacturingInfoStr += '\n'; bundle = saveParsedDataToBundle(bundle, parsedInfo); } else { // console.log('Not Checking partial', strPartial); } } catch(err) { errorLog('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial); errorLog(err.stack); console.error('Error parsing partial (t7_manufacturing_info_ops.js)', err, strPartial); } }); // console.log(noReturnChars); bundle.infoString = manufacturingInfoStr; // console.log(bundle.info); defered.resolve(bundle); }, function(err) { debugRMIOps('in readManufacturingInfoFlashData err', err); bundle.isError = true; bundle.errorStep = 'readManufacturingInfoFlashData'; bundle.error = modbusMap.getErrorInfo(err); bundle.errorCode = err; defered.reject(bundle); }); return defered.promise; }
[ "function", "readManufacturingInfoFlashData", "(", "bundle", ")", "{", "debugRMIOps", "(", "'in readManufacturingInfoFlashData'", ")", ";", "var", "defered", "=", "q", ".", "defer", "(", ")", ";", "var", "startingAddress", "=", "0x3C6000", ";", "var", "numIntsToRead", "=", "8", "*", "8", ";", "self", ".", "readFlash", "(", "startingAddress", ",", "numIntsToRead", ")", ".", "then", "(", "function", "(", "res", ")", "{", "// res is an object with an attribute \"results\" that is an array", "// of bytes. Therefore this debug call outputs a lot of data:", "// debugRMIOps('in readManufacturingInfoFlashData res', res);", "var", "str", "=", "''", ";", "var", "rawData", "=", "[", "]", ";", "res", ".", "results", ".", "forEach", "(", "function", "(", "val", ")", "{", "var", "bA", "=", "(", "val", ">>", "24", ")", "&", "0xFF", ";", "rawData", ".", "push", "(", "bA", ")", ";", "var", "bB", "=", "(", "val", ">>", "16", ")", "&", "0xFF", ";", "rawData", ".", "push", "(", "bB", ")", ";", "var", "bC", "=", "(", "val", ">>", "8", ")", "&", "0xFF", ";", "rawData", ".", "push", "(", "bC", ")", ";", "var", "bD", "=", "(", "val", ">>", "0", ")", "&", "0xFF", ";", "rawData", ".", "push", "(", "bD", ")", ";", "}", ")", ";", "function", "isASCII", "(", "str", ",", "extended", ")", "{", "return", "(", "extended", "?", "/", "^[\\x00-\\xFF]*$", "/", ":", "/", "^[\\x00-\\x7F]*$", "/", ")", ".", "test", "(", "str", ")", ";", "}", "// debugRMIOps('in readManufacturingInfoFlashData', rawData);", "rawData", ".", "forEach", "(", "function", "(", "raw", ")", "{", "var", "newStrPartial", "=", "String", ".", "fromCharCode", "(", "raw", ")", ";", "if", "(", "isASCII", "(", "newStrPartial", ")", ")", "{", "str", "+=", "newStrPartial", ";", "}", "}", ")", ";", "debugRMIOps", "(", "'in readManufacturingInfoFlashData'", ",", "str", ")", ";", "// console.log('Data:');", "// console.log(str);", "var", "noReturnChars", "=", "str", ".", "split", "(", "'\\r'", ")", ".", "join", "(", "''", ")", ";", "strPartials", "=", "noReturnChars", ".", "split", "(", "'\\n'", ")", ";", "var", "manufacturingInfoStr", "=", "''", ";", "// console.log('Processing partials');", "strPartials", ".", "forEach", "(", "function", "(", "strPartial", ")", "{", "try", "{", "// console.log('Checking partial', strPartial);", "if", "(", "isData", ".", "test", "(", "strPartial", ")", ")", "{", "// console.log('Parsing partial', strPartial);", "var", "parsedInfo", "=", "parseManufacturingInfo", "(", "strPartial", ")", ";", "// console.log('Saving partial', strPartial, parsedInfo);", "manufacturingInfoStr", "+=", "parsedInfo", ".", "str", ";", "manufacturingInfoStr", "+=", "': '", ";", "manufacturingInfoStr", "+=", "parsedInfo", ".", "rawData", ";", "manufacturingInfoStr", "+=", "'\\n'", ";", "bundle", "=", "saveParsedDataToBundle", "(", "bundle", ",", "parsedInfo", ")", ";", "}", "else", "{", "// console.log('Not Checking partial', strPartial);", "}", "}", "catch", "(", "err", ")", "{", "errorLog", "(", "'Error parsing partial (t7_manufacturing_info_ops.js)'", ",", "err", ",", "strPartial", ")", ";", "errorLog", "(", "err", ".", "stack", ")", ";", "console", ".", "error", "(", "'Error parsing partial (t7_manufacturing_info_ops.js)'", ",", "err", ",", "strPartial", ")", ";", "}", "}", ")", ";", "// console.log(noReturnChars);", "bundle", ".", "infoString", "=", "manufacturingInfoStr", ";", "// console.log(bundle.info);", "defered", ".", "resolve", "(", "bundle", ")", ";", "}", ",", "function", "(", "err", ")", "{", "debugRMIOps", "(", "'in readManufacturingInfoFlashData err'", ",", "err", ")", ";", "bundle", ".", "isError", "=", "true", ";", "bundle", ".", "errorStep", "=", "'readManufacturingInfoFlashData'", ";", "bundle", ".", "error", "=", "modbusMap", ".", "getErrorInfo", "(", "err", ")", ";", "bundle", ".", "errorCode", "=", "err", ";", "defered", ".", "reject", "(", "bundle", ")", ";", "}", ")", ";", "return", "defered", ".", "promise", ";", "}" ]
Read the manufacturing data from a T7.
[ "Read", "the", "manufacturing", "data", "from", "a", "T7", "." ]
36cb25645dfa0a68e906d5ec43e5514391947257
https://github.com/chrisJohn404/ljswitchboard-ljm_device_curator/blob/36cb25645dfa0a68e906d5ec43e5514391947257/lib/manufacturing_info_operations.js#L175-L249
39,527
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(element, rule){ var elementClassName = element.className, elementID = element.id, elementTagName = element.tagName, elementDisplayName = element.constructor.displayName; if(rule.tagName && !this.tagName(rule.tagName, elementTagName, elementDisplayName)){ return false; } if(rule.id && !this.id(rule.id, elementID)){ return false; } if(rule.classNames && !this.className(rule.classNames, elementClassName)){ return false; } if(rule.pseudos && !this.pseudoMatcher(rule.pseudos, element, elementTagName)){ return false; } if(rule.attrs && !this.attributeMatcher(rule.attrs, element)){ return false; } return true; }
javascript
function(element, rule){ var elementClassName = element.className, elementID = element.id, elementTagName = element.tagName, elementDisplayName = element.constructor.displayName; if(rule.tagName && !this.tagName(rule.tagName, elementTagName, elementDisplayName)){ return false; } if(rule.id && !this.id(rule.id, elementID)){ return false; } if(rule.classNames && !this.className(rule.classNames, elementClassName)){ return false; } if(rule.pseudos && !this.pseudoMatcher(rule.pseudos, element, elementTagName)){ return false; } if(rule.attrs && !this.attributeMatcher(rule.attrs, element)){ return false; } return true; }
[ "function", "(", "element", ",", "rule", ")", "{", "var", "elementClassName", "=", "element", ".", "className", ",", "elementID", "=", "element", ".", "id", ",", "elementTagName", "=", "element", ".", "tagName", ",", "elementDisplayName", "=", "element", ".", "constructor", ".", "displayName", ";", "if", "(", "rule", ".", "tagName", "&&", "!", "this", ".", "tagName", "(", "rule", ".", "tagName", ",", "elementTagName", ",", "elementDisplayName", ")", ")", "{", "return", "false", ";", "}", "if", "(", "rule", ".", "id", "&&", "!", "this", ".", "id", "(", "rule", ".", "id", ",", "elementID", ")", ")", "{", "return", "false", ";", "}", "if", "(", "rule", ".", "classNames", "&&", "!", "this", ".", "className", "(", "rule", ".", "classNames", ",", "elementClassName", ")", ")", "{", "return", "false", ";", "}", "if", "(", "rule", ".", "pseudos", "&&", "!", "this", ".", "pseudoMatcher", "(", "rule", ".", "pseudos", ",", "element", ",", "elementTagName", ")", ")", "{", "return", "false", ";", "}", "if", "(", "rule", ".", "attrs", "&&", "!", "this", ".", "attributeMatcher", "(", "rule", ".", "attrs", ",", "element", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Given an array, reduces the items based on the provided parsed CSS pseudo selector. @param {Object} element Element to test @param {Object} rule Parsed pseudo CSS selector @return {Array} Reduced matches based on selector processing
[ "Given", "an", "array", "reduces", "the", "items", "based", "on", "the", "provided", "parsed", "CSS", "pseudo", "selector", "." ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L10-L34
39,528
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(pseudoRule, element, elementTagName){ if(pseudoRule.name === 'checked'){ return this.checked(element, elementTagName); } if(pseudoRule.name === 'empty'){ return this.empty(element); } }
javascript
function(pseudoRule, element, elementTagName){ if(pseudoRule.name === 'checked'){ return this.checked(element, elementTagName); } if(pseudoRule.name === 'empty'){ return this.empty(element); } }
[ "function", "(", "pseudoRule", ",", "element", ",", "elementTagName", ")", "{", "if", "(", "pseudoRule", ".", "name", "===", "'checked'", ")", "{", "return", "this", ".", "checked", "(", "element", ",", "elementTagName", ")", ";", "}", "if", "(", "pseudoRule", ".", "name", "===", "'empty'", ")", "{", "return", "this", ".", "empty", "(", "element", ")", ";", "}", "}" ]
Routes pseudo selector to proper handler @param {Object} pseudoRule Parsed CSS pseudo rule @param {Object} element Element to check against pseudo rule @param {String} elementTagName Tag name of the element @return {Bool} Whether element matches pseudo rule
[ "Routes", "pseudo", "selector", "to", "proper", "handler" ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L43-L50
39,529
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(attributeRules, element){ for(var i = 0; i < attributeRules.length; i++){ var attributeName = attributeRules[i].name, objectToCheck = element; if(typeof element.context === 'undefined'){ //Native DOM node if(_.startsWith(attributeName, 'data-')){ objectToCheck = element.dataset; attributeName = attributeName.split('-')[1]; } } else{ //React component instance objectToCheck = element.props; } var elementProperty = objectToCheck[attributeName], operator = attributeRules[i].operator, value = attributeRules[i].value; //Only checking for existance, don't care about the value if(!operator && elementProperty === undefined){ return false; } var doesValueMatch = this.compareElementProperty(elementProperty, operator, value); if(!doesValueMatch){ return false; } } return true; }
javascript
function(attributeRules, element){ for(var i = 0; i < attributeRules.length; i++){ var attributeName = attributeRules[i].name, objectToCheck = element; if(typeof element.context === 'undefined'){ //Native DOM node if(_.startsWith(attributeName, 'data-')){ objectToCheck = element.dataset; attributeName = attributeName.split('-')[1]; } } else{ //React component instance objectToCheck = element.props; } var elementProperty = objectToCheck[attributeName], operator = attributeRules[i].operator, value = attributeRules[i].value; //Only checking for existance, don't care about the value if(!operator && elementProperty === undefined){ return false; } var doesValueMatch = this.compareElementProperty(elementProperty, operator, value); if(!doesValueMatch){ return false; } } return true; }
[ "function", "(", "attributeRules", ",", "element", ")", "{", "for", "(", "var", "i", "=", "0", ";", "i", "<", "attributeRules", ".", "length", ";", "i", "++", ")", "{", "var", "attributeName", "=", "attributeRules", "[", "i", "]", ".", "name", ",", "objectToCheck", "=", "element", ";", "if", "(", "typeof", "element", ".", "context", "===", "'undefined'", ")", "{", "//Native DOM node", "if", "(", "_", ".", "startsWith", "(", "attributeName", ",", "'data-'", ")", ")", "{", "objectToCheck", "=", "element", ".", "dataset", ";", "attributeName", "=", "attributeName", ".", "split", "(", "'-'", ")", "[", "1", "]", ";", "}", "}", "else", "{", "//React component instance", "objectToCheck", "=", "element", ".", "props", ";", "}", "var", "elementProperty", "=", "objectToCheck", "[", "attributeName", "]", ",", "operator", "=", "attributeRules", "[", "i", "]", ".", "operator", ",", "value", "=", "attributeRules", "[", "i", "]", ".", "value", ";", "//Only checking for existance, don't care about the value", "if", "(", "!", "operator", "&&", "elementProperty", "===", "undefined", ")", "{", "return", "false", ";", "}", "var", "doesValueMatch", "=", "this", ".", "compareElementProperty", "(", "elementProperty", ",", "operator", ",", "value", ")", ";", "if", "(", "!", "doesValueMatch", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Validates if the provided element matches the provided array of attribute CSS selectors. @param {Array} attributeRules Array of attribute rules to check @param {Object} element Element to check @return {Bool} Whether element matches all attribute rules
[ "Validates", "if", "the", "provided", "element", "matches", "the", "provided", "array", "of", "attribute", "CSS", "selectors", "." ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L59-L91
39,530
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(ruleClassName, elementClassName){ if(!elementClassName){ return false; } for(var i = 0; i < ruleClassName.length; i++){ if((' ' + elementClassName + ' ').indexOf(' ' + ruleClassName[i] + ' ') === -1){ return false; } } return true; }
javascript
function(ruleClassName, elementClassName){ if(!elementClassName){ return false; } for(var i = 0; i < ruleClassName.length; i++){ if((' ' + elementClassName + ' ').indexOf(' ' + ruleClassName[i] + ' ') === -1){ return false; } } return true; }
[ "function", "(", "ruleClassName", ",", "elementClassName", ")", "{", "if", "(", "!", "elementClassName", ")", "{", "return", "false", ";", "}", "for", "(", "var", "i", "=", "0", ";", "i", "<", "ruleClassName", ".", "length", ";", "i", "++", ")", "{", "if", "(", "(", "' '", "+", "elementClassName", "+", "' '", ")", ".", "indexOf", "(", "' '", "+", "ruleClassName", "[", "i", "]", "+", "' '", ")", "===", "-", "1", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Checks if the element class names match the provided CSS selector names @param {Array} ruleClassName Class name of CSS selector @param {String} elementClassName Class name of element @return {Bool} Whether element class names CSS selectors
[ "Checks", "if", "the", "element", "class", "names", "match", "the", "provided", "CSS", "selector", "names" ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L128-L138
39,531
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(element, tagName){ if(!tagName || tagName.toLowerCase() !== 'input'){ return false; } var inputType = element.type.toLowerCase(); if(inputType !== 'checkbox' && inputType !== 'radio'){ return false; } return element.checked !== false; }
javascript
function(element, tagName){ if(!tagName || tagName.toLowerCase() !== 'input'){ return false; } var inputType = element.type.toLowerCase(); if(inputType !== 'checkbox' && inputType !== 'radio'){ return false; } return element.checked !== false; }
[ "function", "(", "element", ",", "tagName", ")", "{", "if", "(", "!", "tagName", "||", "tagName", ".", "toLowerCase", "(", ")", "!==", "'input'", ")", "{", "return", "false", ";", "}", "var", "inputType", "=", "element", ".", "type", ".", "toLowerCase", "(", ")", ";", "if", "(", "inputType", "!==", "'checkbox'", "&&", "inputType", "!==", "'radio'", ")", "{", "return", "false", ";", "}", "return", "element", ".", "checked", "!==", "false", ";", "}" ]
Checks if the provided element is "checked". Only applies to inputs of type radio and checkbox. Checks for both the checked property and defaultChecked property. @param {Object} element Element to test @param {String} tagName Tag name of the element @return {Bool} Whether element is the correct input type and is checked
[ "Checks", "if", "the", "provided", "element", "is", "checked", ".", "Only", "applies", "to", "inputs", "of", "type", "radio", "and", "checkbox", ".", "Checks", "for", "both", "the", "checked", "property", "and", "defaultChecked", "property", "." ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L156-L167
39,532
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(property, operator, value){ if(operator === '='){ return this.compareElementPropertyEquality(property, value); } if(operator === '~='){ return String(property).split(" ").indexOf(value) !== -1; } if(operator === '^='){ return _.startsWith(property, value); } if(operator === '$='){ return _.endsWith(property, value); } if(operator === '*='){ return property && property.indexOf(value) !== -1; } return true; }
javascript
function(property, operator, value){ if(operator === '='){ return this.compareElementPropertyEquality(property, value); } if(operator === '~='){ return String(property).split(" ").indexOf(value) !== -1; } if(operator === '^='){ return _.startsWith(property, value); } if(operator === '$='){ return _.endsWith(property, value); } if(operator === '*='){ return property && property.indexOf(value) !== -1; } return true; }
[ "function", "(", "property", ",", "operator", ",", "value", ")", "{", "if", "(", "operator", "===", "'='", ")", "{", "return", "this", ".", "compareElementPropertyEquality", "(", "property", ",", "value", ")", ";", "}", "if", "(", "operator", "===", "'~='", ")", "{", "return", "String", "(", "property", ")", ".", "split", "(", "\" \"", ")", ".", "indexOf", "(", "value", ")", "!==", "-", "1", ";", "}", "if", "(", "operator", "===", "'^='", ")", "{", "return", "_", ".", "startsWith", "(", "property", ",", "value", ")", ";", "}", "if", "(", "operator", "===", "'$='", ")", "{", "return", "_", ".", "endsWith", "(", "property", ",", "value", ")", ";", "}", "if", "(", "operator", "===", "'*='", ")", "{", "return", "property", "&&", "property", ".", "indexOf", "(", "value", ")", "!==", "-", "1", ";", "}", "return", "true", ";", "}" ]
Function to parse attribute CSS queries for the various types of comparitor functions supported in attribute queries and then performs the specific comparison of property and value @param {Mixed} property Value of component prop to compare against @param {String} operator Comparison operator @param {String} value Value to compare @return {Bool} Whether property matches value with the given operator check
[ "Function", "to", "parse", "attribute", "CSS", "queries", "for", "the", "various", "types", "of", "comparitor", "functions", "supported", "in", "attribute", "queries", "and", "then", "performs", "the", "specific", "comparison", "of", "property", "and", "value" ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L177-L194
39,533
dataminr/expanded-react-test-utils
lib/SelectorMatchers.js
function(property, value){ //When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since //the value in the selector always comes through as a string if(_.isNumber(property)){ return property === parseInt(value); } else if(_.isBoolean(property)){ return property === (value === 'true' ? true : false); } else if(value === "null"){ return property === null; } return property === value; }
javascript
function(property, value){ //When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since //the value in the selector always comes through as a string if(_.isNumber(property)){ return property === parseInt(value); } else if(_.isBoolean(property)){ return property === (value === 'true' ? true : false); } else if(value === "null"){ return property === null; } return property === value; }
[ "function", "(", "property", ",", "value", ")", "{", "//When doing direct comparisons, do some conversions between numbers, booleans, null/undefined since", "//the value in the selector always comes through as a string", "if", "(", "_", ".", "isNumber", "(", "property", ")", ")", "{", "return", "property", "===", "parseInt", "(", "value", ")", ";", "}", "else", "if", "(", "_", ".", "isBoolean", "(", "property", ")", ")", "{", "return", "property", "===", "(", "value", "===", "'true'", "?", "true", ":", "false", ")", ";", "}", "else", "if", "(", "value", "===", "\"null\"", ")", "{", "return", "property", "===", "null", ";", "}", "return", "property", "===", "value", ";", "}" ]
Does a equality comparison, handling for the fact that value is always a string. Supports casting of values into numbers, booleans, and null. @param {Mixed} property Element prop value to check @param {String} value CSS selector value to compare @return {Bool} Whether property and value match
[ "Does", "a", "equality", "comparison", "handling", "for", "the", "fact", "that", "value", "is", "always", "a", "string", ".", "Supports", "casting", "of", "values", "into", "numbers", "booleans", "and", "null", "." ]
cb23cd10cd29839401939561ee0081a49235b358
https://github.com/dataminr/expanded-react-test-utils/blob/cb23cd10cd29839401939561ee0081a49235b358/lib/SelectorMatchers.js#L203-L216
39,534
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
isVersionAtLeast
function isVersionAtLeast(dottedVersion, major, minor, patch){ var i, v, t, verParts = $.map($.trim(dottedVersion).split("."), function(e){ return parseInt(e, 10); }), testParts = $.map(Array.prototype.slice.call(arguments, 1), function(e){ return parseInt(e, 10); }); for( i = 0; i < testParts.length; i++ ){ v = verParts[i] || 0; t = testParts[i] || 0; if( v !== t ){ return ( v > t ); } } return true; }
javascript
function isVersionAtLeast(dottedVersion, major, minor, patch){ var i, v, t, verParts = $.map($.trim(dottedVersion).split("."), function(e){ return parseInt(e, 10); }), testParts = $.map(Array.prototype.slice.call(arguments, 1), function(e){ return parseInt(e, 10); }); for( i = 0; i < testParts.length; i++ ){ v = verParts[i] || 0; t = testParts[i] || 0; if( v !== t ){ return ( v > t ); } } return true; }
[ "function", "isVersionAtLeast", "(", "dottedVersion", ",", "major", ",", "minor", ",", "patch", ")", "{", "var", "i", ",", "v", ",", "t", ",", "verParts", "=", "$", ".", "map", "(", "$", ".", "trim", "(", "dottedVersion", ")", ".", "split", "(", "\".\"", ")", ",", "function", "(", "e", ")", "{", "return", "parseInt", "(", "e", ",", "10", ")", ";", "}", ")", ",", "testParts", "=", "$", ".", "map", "(", "Array", ".", "prototype", ".", "slice", ".", "call", "(", "arguments", ",", "1", ")", ",", "function", "(", "e", ")", "{", "return", "parseInt", "(", "e", ",", "10", ")", ";", "}", ")", ";", "for", "(", "i", "=", "0", ";", "i", "<", "testParts", ".", "length", ";", "i", "++", ")", "{", "v", "=", "verParts", "[", "i", "]", "||", "0", ";", "t", "=", "testParts", "[", "i", "]", "||", "0", ";", "if", "(", "v", "!==", "t", ")", "{", "return", "(", "v", ">", "t", ")", ";", "}", "}", "return", "true", ";", "}" ]
Return true if dotted version string is equal or higher than requested version. See http://jsfiddle.net/mar10/FjSAN/
[ "Return", "true", "if", "dotted", "version", "string", "is", "equal", "or", "higher", "than", "requested", "version", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L73-L86
39,535
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(targetNode, mode, map) { if(mode === undefined || mode === "over"){ mode = "child"; } var pos, prevParent = this.parent, targetParent = (mode === "child") ? targetNode : targetNode.parent; if(this === targetNode){ return; }else if( !this.parent ){ throw "Cannot move system root"; }else if( targetParent.isDescendantOf(this) ){ throw "Cannot move a node to its own descendant"; } // Unlink this node from current parent if( this.parent.children.length === 1 ) { if( this.parent === targetParent ){ return; // #258 } this.parent.children = this.parent.lazy ? [] : null; this.parent.expanded = false; } else { pos = $.inArray(this, this.parent.children); _assert(pos >= 0); this.parent.children.splice(pos, 1); } // Remove from source DOM parent // if(this.parent.ul){ // this.parent.ul.removeChild(this.li); // } // Insert this node to target parent's child list this.parent = targetParent; if( targetParent.hasChildren() ) { switch(mode) { case "child": // Append to existing target children targetParent.children.push(this); break; case "before": // Insert this node before target node pos = $.inArray(targetNode, targetParent.children); _assert(pos >= 0); targetParent.children.splice(pos, 0, this); break; case "after": // Insert this node after target node pos = $.inArray(targetNode, targetParent.children); _assert(pos >= 0); targetParent.children.splice(pos+1, 0, this); break; default: throw "Invalid mode " + mode; } } else { targetParent.children = [ this ]; } // Parent has no <ul> tag yet: // if( !targetParent.ul ) { // // This is the parent's first child: create UL tag // // (Hidden, because it will be // targetParent.ul = document.createElement("ul"); // targetParent.ul.style.display = "none"; // targetParent.li.appendChild(targetParent.ul); // } // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded)) // if(this.li){ // targetParent.ul.appendChild(this.li); // }^ // Let caller modify the nodes if( map ){ targetNode.visit(map, true); } // Handle cross-tree moves if( this.tree !== targetNode.tree ) { // Fix node.tree for all source nodes // _assert(false, "Cross-tree move is not yet implemented."); this.warn("Cross-tree moveTo is experimantal!"); this.visit(function(n){ // TODO: fix selection state and activation, ... n.tree = targetNode.tree; }, true); } // A collaposed node won't re-render children, so we have to remove it manually // if( !targetParent.expanded ){ // prevParent.ul.removeChild(this.li); // } // Update HTML markup if( !prevParent.isDescendantOf(targetParent)) { prevParent.render(); } if( !targetParent.isDescendantOf(prevParent) && targetParent !== prevParent) { targetParent.render(); } // TODO: fix selection state // TODO: fix active state /* var tree = this.tree; var opts = tree.options; var pers = tree.persistence; // Always expand, if it's below minExpandLevel // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel()); if ( opts.minExpandLevel >= ftnode.getLevel() ) { // tree.logDebug ("Force expand for %o", ftnode); this.bExpanded = true; } // In multi-hier mode, update the parents selection state // DT issue #82: only if not initializing, because the children may not exist yet // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing ) // ftnode._fixSelectionState(); // In multi-hier mode, update the parents selection state if( ftnode.bSelected && opts.selectMode==3 ) { var p = this; while( p ) { if( !p.hasSubSel ) p._setSubSel(true); p = p.parent; } } // render this node and the new child if ( tree.bEnableUpdate ) this.render(); return ftnode; */ }
javascript
function(targetNode, mode, map) { if(mode === undefined || mode === "over"){ mode = "child"; } var pos, prevParent = this.parent, targetParent = (mode === "child") ? targetNode : targetNode.parent; if(this === targetNode){ return; }else if( !this.parent ){ throw "Cannot move system root"; }else if( targetParent.isDescendantOf(this) ){ throw "Cannot move a node to its own descendant"; } // Unlink this node from current parent if( this.parent.children.length === 1 ) { if( this.parent === targetParent ){ return; // #258 } this.parent.children = this.parent.lazy ? [] : null; this.parent.expanded = false; } else { pos = $.inArray(this, this.parent.children); _assert(pos >= 0); this.parent.children.splice(pos, 1); } // Remove from source DOM parent // if(this.parent.ul){ // this.parent.ul.removeChild(this.li); // } // Insert this node to target parent's child list this.parent = targetParent; if( targetParent.hasChildren() ) { switch(mode) { case "child": // Append to existing target children targetParent.children.push(this); break; case "before": // Insert this node before target node pos = $.inArray(targetNode, targetParent.children); _assert(pos >= 0); targetParent.children.splice(pos, 0, this); break; case "after": // Insert this node after target node pos = $.inArray(targetNode, targetParent.children); _assert(pos >= 0); targetParent.children.splice(pos+1, 0, this); break; default: throw "Invalid mode " + mode; } } else { targetParent.children = [ this ]; } // Parent has no <ul> tag yet: // if( !targetParent.ul ) { // // This is the parent's first child: create UL tag // // (Hidden, because it will be // targetParent.ul = document.createElement("ul"); // targetParent.ul.style.display = "none"; // targetParent.li.appendChild(targetParent.ul); // } // // Issue 319: Add to target DOM parent (only if node was already rendered(expanded)) // if(this.li){ // targetParent.ul.appendChild(this.li); // }^ // Let caller modify the nodes if( map ){ targetNode.visit(map, true); } // Handle cross-tree moves if( this.tree !== targetNode.tree ) { // Fix node.tree for all source nodes // _assert(false, "Cross-tree move is not yet implemented."); this.warn("Cross-tree moveTo is experimantal!"); this.visit(function(n){ // TODO: fix selection state and activation, ... n.tree = targetNode.tree; }, true); } // A collaposed node won't re-render children, so we have to remove it manually // if( !targetParent.expanded ){ // prevParent.ul.removeChild(this.li); // } // Update HTML markup if( !prevParent.isDescendantOf(targetParent)) { prevParent.render(); } if( !targetParent.isDescendantOf(prevParent) && targetParent !== prevParent) { targetParent.render(); } // TODO: fix selection state // TODO: fix active state /* var tree = this.tree; var opts = tree.options; var pers = tree.persistence; // Always expand, if it's below minExpandLevel // tree.logDebug ("%s._addChildNode(%o), l=%o", this, ftnode, ftnode.getLevel()); if ( opts.minExpandLevel >= ftnode.getLevel() ) { // tree.logDebug ("Force expand for %o", ftnode); this.bExpanded = true; } // In multi-hier mode, update the parents selection state // DT issue #82: only if not initializing, because the children may not exist yet // if( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing ) // ftnode._fixSelectionState(); // In multi-hier mode, update the parents selection state if( ftnode.bSelected && opts.selectMode==3 ) { var p = this; while( p ) { if( !p.hasSubSel ) p._setSubSel(true); p = p.parent; } } // render this node and the new child if ( tree.bEnableUpdate ) this.render(); return ftnode; */ }
[ "function", "(", "targetNode", ",", "mode", ",", "map", ")", "{", "if", "(", "mode", "===", "undefined", "||", "mode", "===", "\"over\"", ")", "{", "mode", "=", "\"child\"", ";", "}", "var", "pos", ",", "prevParent", "=", "this", ".", "parent", ",", "targetParent", "=", "(", "mode", "===", "\"child\"", ")", "?", "targetNode", ":", "targetNode", ".", "parent", ";", "if", "(", "this", "===", "targetNode", ")", "{", "return", ";", "}", "else", "if", "(", "!", "this", ".", "parent", ")", "{", "throw", "\"Cannot move system root\"", ";", "}", "else", "if", "(", "targetParent", ".", "isDescendantOf", "(", "this", ")", ")", "{", "throw", "\"Cannot move a node to its own descendant\"", ";", "}", "// Unlink this node from current parent", "if", "(", "this", ".", "parent", ".", "children", ".", "length", "===", "1", ")", "{", "if", "(", "this", ".", "parent", "===", "targetParent", ")", "{", "return", ";", "// #258", "}", "this", ".", "parent", ".", "children", "=", "this", ".", "parent", ".", "lazy", "?", "[", "]", ":", "null", ";", "this", ".", "parent", ".", "expanded", "=", "false", ";", "}", "else", "{", "pos", "=", "$", ".", "inArray", "(", "this", ",", "this", ".", "parent", ".", "children", ")", ";", "_assert", "(", "pos", ">=", "0", ")", ";", "this", ".", "parent", ".", "children", ".", "splice", "(", "pos", ",", "1", ")", ";", "}", "// Remove from source DOM parent", "//\t\tif(this.parent.ul){", "//\t\t\tthis.parent.ul.removeChild(this.li);", "//\t\t}", "// Insert this node to target parent's child list", "this", ".", "parent", "=", "targetParent", ";", "if", "(", "targetParent", ".", "hasChildren", "(", ")", ")", "{", "switch", "(", "mode", ")", "{", "case", "\"child\"", ":", "// Append to existing target children", "targetParent", ".", "children", ".", "push", "(", "this", ")", ";", "break", ";", "case", "\"before\"", ":", "// Insert this node before target node", "pos", "=", "$", ".", "inArray", "(", "targetNode", ",", "targetParent", ".", "children", ")", ";", "_assert", "(", "pos", ">=", "0", ")", ";", "targetParent", ".", "children", ".", "splice", "(", "pos", ",", "0", ",", "this", ")", ";", "break", ";", "case", "\"after\"", ":", "// Insert this node after target node", "pos", "=", "$", ".", "inArray", "(", "targetNode", ",", "targetParent", ".", "children", ")", ";", "_assert", "(", "pos", ">=", "0", ")", ";", "targetParent", ".", "children", ".", "splice", "(", "pos", "+", "1", ",", "0", ",", "this", ")", ";", "break", ";", "default", ":", "throw", "\"Invalid mode \"", "+", "mode", ";", "}", "}", "else", "{", "targetParent", ".", "children", "=", "[", "this", "]", ";", "}", "// Parent has no <ul> tag yet:", "//\t\tif( !targetParent.ul ) {", "//\t\t\t// This is the parent's first child: create UL tag", "//\t\t\t// (Hidden, because it will be", "//\t\t\ttargetParent.ul = document.createElement(\"ul\");", "//\t\t\ttargetParent.ul.style.display = \"none\";", "//\t\t\ttargetParent.li.appendChild(targetParent.ul);", "//\t\t}", "//\t\t// Issue 319: Add to target DOM parent (only if node was already rendered(expanded))", "//\t\tif(this.li){", "//\t\t\ttargetParent.ul.appendChild(this.li);", "//\t\t}^", "// Let caller modify the nodes", "if", "(", "map", ")", "{", "targetNode", ".", "visit", "(", "map", ",", "true", ")", ";", "}", "// Handle cross-tree moves", "if", "(", "this", ".", "tree", "!==", "targetNode", ".", "tree", ")", "{", "// Fix node.tree for all source nodes", "//\t\t\t_assert(false, \"Cross-tree move is not yet implemented.\");", "this", ".", "warn", "(", "\"Cross-tree moveTo is experimantal!\"", ")", ";", "this", ".", "visit", "(", "function", "(", "n", ")", "{", "// TODO: fix selection state and activation, ...", "n", ".", "tree", "=", "targetNode", ".", "tree", ";", "}", ",", "true", ")", ";", "}", "// A collaposed node won't re-render children, so we have to remove it manually", "// if( !targetParent.expanded ){", "// prevParent.ul.removeChild(this.li);", "// }", "// Update HTML markup", "if", "(", "!", "prevParent", ".", "isDescendantOf", "(", "targetParent", ")", ")", "{", "prevParent", ".", "render", "(", ")", ";", "}", "if", "(", "!", "targetParent", ".", "isDescendantOf", "(", "prevParent", ")", "&&", "targetParent", "!==", "prevParent", ")", "{", "targetParent", ".", "render", "(", ")", ";", "}", "// TODO: fix selection state", "// TODO: fix active state", "/*\n\t\tvar tree = this.tree;\n\t\tvar opts = tree.options;\n\t\tvar pers = tree.persistence;\n\n\n\t\t// Always expand, if it's below minExpandLevel\n//\t\ttree.logDebug (\"%s._addChildNode(%o), l=%o\", this, ftnode, ftnode.getLevel());\n\t\tif ( opts.minExpandLevel >= ftnode.getLevel() ) {\n//\t\t\ttree.logDebug (\"Force expand for %o\", ftnode);\n\t\t\tthis.bExpanded = true;\n\t\t}\n\n\t\t// In multi-hier mode, update the parents selection state\n\t\t// DT issue #82: only if not initializing, because the children may not exist yet\n//\t\tif( !ftnode.data.isStatusNode() && opts.selectMode==3 && !isInitializing )\n//\t\t\tftnode._fixSelectionState();\n\n\t\t// In multi-hier mode, update the parents selection state\n\t\tif( ftnode.bSelected && opts.selectMode==3 ) {\n\t\t\tvar p = this;\n\t\t\twhile( p ) {\n\t\t\t\tif( !p.hasSubSel )\n\t\t\t\t\tp._setSubSel(true);\n\t\t\t\tp = p.parent;\n\t\t\t}\n\t\t}\n\t\t// render this node and the new child\n\t\tif ( tree.bEnableUpdate )\n\t\t\tthis.render();\n\n\t\treturn ftnode;\n\n*/", "}" ]
Move this node to targetNode. @param {FancytreeNode} targetNode @param {string} mode <pre> 'child': append this node as last child of targetNode. This is the default. To be compatble with the D'n'd hitMode, we also accept 'over'. 'before': add this node as sibling before targetNode. 'after': add this node as sibling after targetNode.</pre> @param {function} [map] optional callback(FancytreeNode) to allow modifcations
[ "Move", "this", "node", "to", "targetNode", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L1073-L1208
39,536
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(stopOnParents) { var nodeList = []; this.rootNode.visit(function(node){ if( node.selected ) { nodeList.push(node); if( stopOnParents === true ){ return "skip"; // stop processing this branch } } }); return nodeList; }
javascript
function(stopOnParents) { var nodeList = []; this.rootNode.visit(function(node){ if( node.selected ) { nodeList.push(node); if( stopOnParents === true ){ return "skip"; // stop processing this branch } } }); return nodeList; }
[ "function", "(", "stopOnParents", ")", "{", "var", "nodeList", "=", "[", "]", ";", "this", ".", "rootNode", ".", "visit", "(", "function", "(", "node", ")", "{", "if", "(", "node", ".", "selected", ")", "{", "nodeList", ".", "push", "(", "node", ")", ";", "if", "(", "stopOnParents", "===", "true", ")", "{", "return", "\"skip\"", ";", "// stop processing this branch", "}", "}", "}", ")", ";", "return", "nodeList", ";", "}" ]
Return an array of selected nodes. @param {boolean} [stopOnParents=false] only return the topmost selected node (useful with selectMode 3) @returns {FancytreeNode[]}
[ "Return", "an", "array", "of", "selected", "nodes", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2067-L2078
39,537
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(setFocus) { var node = this.activeNode; if( node ) { this.activeNode = null; // Force re-activating node.setActive(); if( setFocus ){ node.setFocus(); } } }
javascript
function(setFocus) { var node = this.activeNode; if( node ) { this.activeNode = null; // Force re-activating node.setActive(); if( setFocus ){ node.setFocus(); } } }
[ "function", "(", "setFocus", ")", "{", "var", "node", "=", "this", ".", "activeNode", ";", "if", "(", "node", ")", "{", "this", ".", "activeNode", "=", "null", ";", "// Force re-activating", "node", ".", "setActive", "(", ")", ";", "if", "(", "setFocus", ")", "{", "node", ".", "setFocus", "(", ")", ";", "}", "}", "}" ]
Re-fire beforeActivate and activate events.
[ "Re", "-", "fire", "beforeActivate", "and", "activate", "events", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2195-L2204
39,538
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(ctx) { // TODO: return promise? if( ctx.targetType === "title" && ctx.options.clickFolderMode === 4) { // this.nodeSetFocus(ctx); // this._callHook("nodeSetActive", ctx, true); this._callHook("nodeToggleExpanded", ctx); } // TODO: prevent text selection on dblclicks if( ctx.targetType === "title" ) { ctx.originalEvent.preventDefault(); } }
javascript
function(ctx) { // TODO: return promise? if( ctx.targetType === "title" && ctx.options.clickFolderMode === 4) { // this.nodeSetFocus(ctx); // this._callHook("nodeSetActive", ctx, true); this._callHook("nodeToggleExpanded", ctx); } // TODO: prevent text selection on dblclicks if( ctx.targetType === "title" ) { ctx.originalEvent.preventDefault(); } }
[ "function", "(", "ctx", ")", "{", "// TODO: return promise?", "if", "(", "ctx", ".", "targetType", "===", "\"title\"", "&&", "ctx", ".", "options", ".", "clickFolderMode", "===", "4", ")", "{", "//\t\t\tthis.nodeSetFocus(ctx);", "//\t\t\tthis._callHook(\"nodeSetActive\", ctx, true);", "this", ".", "_callHook", "(", "\"nodeToggleExpanded\"", ",", "ctx", ")", ";", "}", "// TODO: prevent text selection on dblclicks", "if", "(", "ctx", ".", "targetType", "===", "\"title\"", ")", "{", "ctx", ".", "originalEvent", ".", "preventDefault", "(", ")", ";", "}", "}" ]
Default handling for mouse douleclick events. @param {EventData} ctx
[ "Default", "handling", "for", "mouse", "douleclick", "events", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2375-L2386
39,539
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(ctx) { var node = ctx.node; // FT.debug("nodeRemoveChildMarkup()", node.toString()); // TODO: Unlink attr.ftnode to support GC if(node.ul){ if( node.isRoot() ) { $(node.ul).empty(); } else { $(node.ul).remove(); node.ul = null; } node.visit(function(n){ n.li = n.ul = null; }); } }
javascript
function(ctx) { var node = ctx.node; // FT.debug("nodeRemoveChildMarkup()", node.toString()); // TODO: Unlink attr.ftnode to support GC if(node.ul){ if( node.isRoot() ) { $(node.ul).empty(); } else { $(node.ul).remove(); node.ul = null; } node.visit(function(n){ n.li = n.ul = null; }); } }
[ "function", "(", "ctx", ")", "{", "var", "node", "=", "ctx", ".", "node", ";", "// FT.debug(\"nodeRemoveChildMarkup()\", node.toString());", "// TODO: Unlink attr.ftnode to support GC", "if", "(", "node", ".", "ul", ")", "{", "if", "(", "node", ".", "isRoot", "(", ")", ")", "{", "$", "(", "node", ".", "ul", ")", ".", "empty", "(", ")", ";", "}", "else", "{", "$", "(", "node", ".", "ul", ")", ".", "remove", "(", ")", ";", "node", ".", "ul", "=", "null", ";", "}", "node", ".", "visit", "(", "function", "(", "n", ")", "{", "n", ".", "li", "=", "n", ".", "ul", "=", "null", ";", "}", ")", ";", "}", "}" ]
Remove HTML markup for all descendents of ctx.node. @param {EventData} ctx
[ "Remove", "HTML", "markup", "for", "all", "descendents", "of", "ctx", ".", "node", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L2628-L2644
39,540
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(ctx, flag) { // ctx.node.debug("nodeSetFocus(" + flag + ")"); var ctx2, tree = ctx.tree, node = ctx.node; flag = (flag !== false); // Blur previous node if any if(tree.focusNode){ if(tree.focusNode === node && flag){ // node.debug("nodeSetFocus(" + flag + "): nothing to do"); return; } ctx2 = $.extend({}, ctx, {node: tree.focusNode}); tree.focusNode = null; this._triggerNodeEvent("blur", ctx2); this._callHook("nodeRenderStatus", ctx2); } // Set focus to container and node if(flag){ if( !this.hasFocus() ){ node.debug("nodeSetFocus: forcing container focus"); // Note: we pass _calledByNodeSetFocus=true this._callHook("treeSetFocus", ctx, true, true); } // this.nodeMakeVisible(ctx); node.makeVisible({scrollIntoView: false}); tree.focusNode = node; // node.debug("FOCUS..."); // $(node.span).find(".fancytree-title").focus(); this._triggerNodeEvent("focus", ctx); // if(ctx.options.autoActivate){ // tree.nodeSetActive(ctx, true); // } if(ctx.options.autoScroll){ node.scrollIntoView(); } this._callHook("nodeRenderStatus", ctx); } }
javascript
function(ctx, flag) { // ctx.node.debug("nodeSetFocus(" + flag + ")"); var ctx2, tree = ctx.tree, node = ctx.node; flag = (flag !== false); // Blur previous node if any if(tree.focusNode){ if(tree.focusNode === node && flag){ // node.debug("nodeSetFocus(" + flag + "): nothing to do"); return; } ctx2 = $.extend({}, ctx, {node: tree.focusNode}); tree.focusNode = null; this._triggerNodeEvent("blur", ctx2); this._callHook("nodeRenderStatus", ctx2); } // Set focus to container and node if(flag){ if( !this.hasFocus() ){ node.debug("nodeSetFocus: forcing container focus"); // Note: we pass _calledByNodeSetFocus=true this._callHook("treeSetFocus", ctx, true, true); } // this.nodeMakeVisible(ctx); node.makeVisible({scrollIntoView: false}); tree.focusNode = node; // node.debug("FOCUS..."); // $(node.span).find(".fancytree-title").focus(); this._triggerNodeEvent("focus", ctx); // if(ctx.options.autoActivate){ // tree.nodeSetActive(ctx, true); // } if(ctx.options.autoScroll){ node.scrollIntoView(); } this._callHook("nodeRenderStatus", ctx); } }
[ "function", "(", "ctx", ",", "flag", ")", "{", "// ctx.node.debug(\"nodeSetFocus(\" + flag + \")\");", "var", "ctx2", ",", "tree", "=", "ctx", ".", "tree", ",", "node", "=", "ctx", ".", "node", ";", "flag", "=", "(", "flag", "!==", "false", ")", ";", "// Blur previous node if any", "if", "(", "tree", ".", "focusNode", ")", "{", "if", "(", "tree", ".", "focusNode", "===", "node", "&&", "flag", ")", "{", "// node.debug(\"nodeSetFocus(\" + flag + \"): nothing to do\");", "return", ";", "}", "ctx2", "=", "$", ".", "extend", "(", "{", "}", ",", "ctx", ",", "{", "node", ":", "tree", ".", "focusNode", "}", ")", ";", "tree", ".", "focusNode", "=", "null", ";", "this", ".", "_triggerNodeEvent", "(", "\"blur\"", ",", "ctx2", ")", ";", "this", ".", "_callHook", "(", "\"nodeRenderStatus\"", ",", "ctx2", ")", ";", "}", "// Set focus to container and node", "if", "(", "flag", ")", "{", "if", "(", "!", "this", ".", "hasFocus", "(", ")", ")", "{", "node", ".", "debug", "(", "\"nodeSetFocus: forcing container focus\"", ")", ";", "// Note: we pass _calledByNodeSetFocus=true", "this", ".", "_callHook", "(", "\"treeSetFocus\"", ",", "ctx", ",", "true", ",", "true", ")", ";", "}", "// this.nodeMakeVisible(ctx);", "node", ".", "makeVisible", "(", "{", "scrollIntoView", ":", "false", "}", ")", ";", "tree", ".", "focusNode", "=", "node", ";", "//\t\t\tnode.debug(\"FOCUS...\");", "//\t\t\t$(node.span).find(\".fancytree-title\").focus();", "this", ".", "_triggerNodeEvent", "(", "\"focus\"", ",", "ctx", ")", ";", "// if(ctx.options.autoActivate){", "// tree.nodeSetActive(ctx, true);", "// }", "if", "(", "ctx", ".", "options", ".", "autoScroll", ")", "{", "node", ".", "scrollIntoView", "(", ")", ";", "}", "this", ".", "_callHook", "(", "\"nodeRenderStatus\"", ",", "ctx", ")", ";", "}", "}" ]
Focus ot blur this node. @param {EventData} ctx @param {boolean} [flag=true]
[ "Focus", "ot", "blur", "this", "node", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L3302-L3342
39,541
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(el){ if(el instanceof FancytreeNode){ return el; // el already was a FancytreeNode }else if(el.selector !== undefined){ el = el[0]; // el was a jQuery object: use the DOM element }else if(el.originalEvent !== undefined){ el = el.target; // el was an Event } while( el ) { if(el.ftnode) { return el.ftnode; } el = el.parentNode; } return null; }
javascript
function(el){ if(el instanceof FancytreeNode){ return el; // el already was a FancytreeNode }else if(el.selector !== undefined){ el = el[0]; // el was a jQuery object: use the DOM element }else if(el.originalEvent !== undefined){ el = el.target; // el was an Event } while( el ) { if(el.ftnode) { return el.ftnode; } el = el.parentNode; } return null; }
[ "function", "(", "el", ")", "{", "if", "(", "el", "instanceof", "FancytreeNode", ")", "{", "return", "el", ";", "// el already was a FancytreeNode", "}", "else", "if", "(", "el", ".", "selector", "!==", "undefined", ")", "{", "el", "=", "el", "[", "0", "]", ";", "// el was a jQuery object: use the DOM element", "}", "else", "if", "(", "el", ".", "originalEvent", "!==", "undefined", ")", "{", "el", "=", "el", ".", "target", ";", "// el was an Event", "}", "while", "(", "el", ")", "{", "if", "(", "el", ".", "ftnode", ")", "{", "return", "el", ".", "ftnode", ";", "}", "el", "=", "el", ".", "parentNode", ";", "}", "return", "null", ";", "}" ]
Return a FancytreeNode instance from element. @param {Element | jQueryObject | Event} el @returns {FancytreeNode} matching node or null
[ "Return", "a", "FancytreeNode", "instance", "from", "element", "." ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4033-L4048
39,542
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(ctx, title) { var node = ctx.node, extOpts = ctx.options.childcounter, count = (node.data.childCounter == null) ? node.countChildren(extOpts.deep) : +node.data.childCounter; // Let the base implementation render the title this._super(ctx, title); // Append a counter badge if( (count || ! extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ){ $("span.fancytree-icon", node.span).append($("<span class='fancytree-childcounter'/>").text(count)); } }
javascript
function(ctx, title) { var node = ctx.node, extOpts = ctx.options.childcounter, count = (node.data.childCounter == null) ? node.countChildren(extOpts.deep) : +node.data.childCounter; // Let the base implementation render the title this._super(ctx, title); // Append a counter badge if( (count || ! extOpts.hideZeros) && (!node.isExpanded() || !extOpts.hideExpanded) ){ $("span.fancytree-icon", node.span).append($("<span class='fancytree-childcounter'/>").text(count)); } }
[ "function", "(", "ctx", ",", "title", ")", "{", "var", "node", "=", "ctx", ".", "node", ",", "extOpts", "=", "ctx", ".", "options", ".", "childcounter", ",", "count", "=", "(", "node", ".", "data", ".", "childCounter", "==", "null", ")", "?", "node", ".", "countChildren", "(", "extOpts", ".", "deep", ")", ":", "+", "node", ".", "data", ".", "childCounter", ";", "// Let the base implementation render the title", "this", ".", "_super", "(", "ctx", ",", "title", ")", ";", "// Append a counter badge", "if", "(", "(", "count", "||", "!", "extOpts", ".", "hideZeros", ")", "&&", "(", "!", "node", ".", "isExpanded", "(", ")", "||", "!", "extOpts", ".", "hideExpanded", ")", ")", "{", "$", "(", "\"span.fancytree-icon\"", ",", "node", ".", "span", ")", ".", "append", "(", "$", "(", "\"<span class='fancytree-childcounter'/>\"", ")", ".", "text", "(", "count", ")", ")", ";", "}", "}" ]
Overload the `renderTitle` hook, to append a counter badge
[ "Overload", "the", "renderTitle", "hook", "to", "append", "a", "counter", "badge" ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4345-L4355
39,543
S3bb1/ah-dashboard-plugin
public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js
function(event) { var sourceNode = $.ui.fancytree.getNode(event.target); if(!sourceNode){ // Dynatree issue 211 // might happen, if dragging a table *header* return "<div>ERROR?: helper requested but sourceNode not found</div>"; } return sourceNode.tree.ext.dnd._onDragEvent("helper", sourceNode, null, event, null, null); }
javascript
function(event) { var sourceNode = $.ui.fancytree.getNode(event.target); if(!sourceNode){ // Dynatree issue 211 // might happen, if dragging a table *header* return "<div>ERROR?: helper requested but sourceNode not found</div>"; } return sourceNode.tree.ext.dnd._onDragEvent("helper", sourceNode, null, event, null, null); }
[ "function", "(", "event", ")", "{", "var", "sourceNode", "=", "$", ".", "ui", ".", "fancytree", ".", "getNode", "(", "event", ".", "target", ")", ";", "if", "(", "!", "sourceNode", ")", "{", "// Dynatree issue 211", "// might happen, if dragging a table *header*", "return", "\"<div>ERROR?: helper requested but sourceNode not found</div>\"", ";", "}", "return", "sourceNode", ".", "tree", ".", "ext", ".", "dnd", ".", "_onDragEvent", "(", "\"helper\"", ",", "sourceNode", ",", "null", ",", "event", ",", "null", ",", "null", ")", ";", "}" ]
Let source tree create the helper element
[ "Let", "source", "tree", "create", "the", "helper", "element" ]
c283370ec0f99a25db5bb7029a98b4febf8c5251
https://github.com/S3bb1/ah-dashboard-plugin/blob/c283370ec0f99a25db5bb7029a98b4febf8c5251/public/dashboard/bower_components/fancytree/dist/jquery.fancytree-all.js#L4872-L4879
39,544
lemonde/knex-schema
lib/resolver.js
isResolved
function isResolved(schema, schemas) { return (schema.deps || []).every(_.partial(function (tableNames, tableName) { return tableNames.indexOf(tableName) > -1; }, _.pluck(schemas, 'tableName'))); }
javascript
function isResolved(schema, schemas) { return (schema.deps || []).every(_.partial(function (tableNames, tableName) { return tableNames.indexOf(tableName) > -1; }, _.pluck(schemas, 'tableName'))); }
[ "function", "isResolved", "(", "schema", ",", "schemas", ")", "{", "return", "(", "schema", ".", "deps", "||", "[", "]", ")", ".", "every", "(", "_", ".", "partial", "(", "function", "(", "tableNames", ",", "tableName", ")", "{", "return", "tableNames", ".", "indexOf", "(", "tableName", ")", ">", "-", "1", ";", "}", ",", "_", ".", "pluck", "(", "schemas", ",", "'tableName'", ")", ")", ")", ";", "}" ]
Return true if given schema.deps meet schemas entries. @param Schema schema @param [Schema] schemas @return {Boolean}
[ "Return", "true", "if", "given", "schema", ".", "deps", "meet", "schemas", "entries", "." ]
3e0f6cde374d240552eb08e50e123a513fda44ae
https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/resolver.js#L55-L59
39,545
vadimdemedes/list-dir
index.js
listDir
function listDir (path, originalPath) { if (!originalPath) { originalPath = path + separator; } // promises for sub listDir calls var dirs = []; return Promise.resolve(fs.readdir(path)) // include only files .filter(function (item) { var absolutePath = join(path, item); return fs.stat(absolutePath).then(function (stat) { var isDirectory = stat.isDirectory(); // if directory, read it if (isDirectory) { var list = listDir(absolutePath, originalPath); dirs.push(list); } return !isDirectory; }); }) // return relative paths .map(function (file) { var absolutePath = join(path, file); var relativePath = absolutePath.replace(originalPath, ''); return relativePath; }) // add files from sub-directories .then(function (files) { // wait for all listDir() to complete // and merge their results return Promise .all(dirs) .then(function () { dirs.forEach(function (promise) { var subFiles = promise.value(); files = files.concat(subFiles); }); return files; }); }); }
javascript
function listDir (path, originalPath) { if (!originalPath) { originalPath = path + separator; } // promises for sub listDir calls var dirs = []; return Promise.resolve(fs.readdir(path)) // include only files .filter(function (item) { var absolutePath = join(path, item); return fs.stat(absolutePath).then(function (stat) { var isDirectory = stat.isDirectory(); // if directory, read it if (isDirectory) { var list = listDir(absolutePath, originalPath); dirs.push(list); } return !isDirectory; }); }) // return relative paths .map(function (file) { var absolutePath = join(path, file); var relativePath = absolutePath.replace(originalPath, ''); return relativePath; }) // add files from sub-directories .then(function (files) { // wait for all listDir() to complete // and merge their results return Promise .all(dirs) .then(function () { dirs.forEach(function (promise) { var subFiles = promise.value(); files = files.concat(subFiles); }); return files; }); }); }
[ "function", "listDir", "(", "path", ",", "originalPath", ")", "{", "if", "(", "!", "originalPath", ")", "{", "originalPath", "=", "path", "+", "separator", ";", "}", "// promises for sub listDir calls", "var", "dirs", "=", "[", "]", ";", "return", "Promise", ".", "resolve", "(", "fs", ".", "readdir", "(", "path", ")", ")", "// include only files", ".", "filter", "(", "function", "(", "item", ")", "{", "var", "absolutePath", "=", "join", "(", "path", ",", "item", ")", ";", "return", "fs", ".", "stat", "(", "absolutePath", ")", ".", "then", "(", "function", "(", "stat", ")", "{", "var", "isDirectory", "=", "stat", ".", "isDirectory", "(", ")", ";", "// if directory, read it", "if", "(", "isDirectory", ")", "{", "var", "list", "=", "listDir", "(", "absolutePath", ",", "originalPath", ")", ";", "dirs", ".", "push", "(", "list", ")", ";", "}", "return", "!", "isDirectory", ";", "}", ")", ";", "}", ")", "// return relative paths", ".", "map", "(", "function", "(", "file", ")", "{", "var", "absolutePath", "=", "join", "(", "path", ",", "file", ")", ";", "var", "relativePath", "=", "absolutePath", ".", "replace", "(", "originalPath", ",", "''", ")", ";", "return", "relativePath", ";", "}", ")", "// add files from sub-directories", ".", "then", "(", "function", "(", "files", ")", "{", "// wait for all listDir() to complete", "// and merge their results", "return", "Promise", ".", "all", "(", "dirs", ")", ".", "then", "(", "function", "(", ")", "{", "dirs", ".", "forEach", "(", "function", "(", "promise", ")", "{", "var", "subFiles", "=", "promise", ".", "value", "(", ")", ";", "files", "=", "files", ".", "concat", "(", "subFiles", ")", ";", "}", ")", ";", "return", "files", ";", "}", ")", ";", "}", ")", ";", "}" ]
List directory recursively @param {String} path @return {Promise}
[ "List", "directory", "recursively" ]
4efce85e42e7e6f0eca7f22bbc5abf0af282596d
https://github.com/vadimdemedes/list-dir/blob/4efce85e42e7e6f0eca7f22bbc5abf0af282596d/index.js#L29-L78
39,546
jxson/haiku
lib/page.js
read
function read(src, basedir, callback){ var page = new Page(src, basedir) page.read(callback) }
javascript
function read(src, basedir, callback){ var page = new Page(src, basedir) page.read(callback) }
[ "function", "read", "(", "src", ",", "basedir", ",", "callback", ")", "{", "var", "page", "=", "new", "Page", "(", "src", ",", "basedir", ")", "page", ".", "read", "(", "callback", ")", "}" ]
Async read and instantiate a page from a file
[ "Async", "read", "and", "instantiate", "a", "page", "from", "a", "file" ]
d7dcb3c3b39012082277cf0ed1bcb5c91440c76e
https://github.com/jxson/haiku/blob/d7dcb3c3b39012082277cf0ed1bcb5c91440c76e/lib/page.js#L13-L17
39,547
Knorcedger/apier
index.js
apier
function apier(config) { // on server start.. db.connect(config.mongoUrl); accessVerifier.init(config.access); schemaExtender.handleErrors = true; reqlog.info('apier initialized!!'); var app = function(req, res) { // this is the final handler if no match found router(req, res, function(error) { if (error) { reqlog.error(error); responseBuilder.error(req, res, 'INTERNAL_SERVER_ERROR'); } else { reqlog.info('NOT_FOUND:', req.method + ' ' + req.url); responseBuilder.error(req, res, 'NOT_FOUND'); } }); }; app.endpoint = endpoint; return app; }
javascript
function apier(config) { // on server start.. db.connect(config.mongoUrl); accessVerifier.init(config.access); schemaExtender.handleErrors = true; reqlog.info('apier initialized!!'); var app = function(req, res) { // this is the final handler if no match found router(req, res, function(error) { if (error) { reqlog.error(error); responseBuilder.error(req, res, 'INTERNAL_SERVER_ERROR'); } else { reqlog.info('NOT_FOUND:', req.method + ' ' + req.url); responseBuilder.error(req, res, 'NOT_FOUND'); } }); }; app.endpoint = endpoint; return app; }
[ "function", "apier", "(", "config", ")", "{", "// on server start..", "db", ".", "connect", "(", "config", ".", "mongoUrl", ")", ";", "accessVerifier", ".", "init", "(", "config", ".", "access", ")", ";", "schemaExtender", ".", "handleErrors", "=", "true", ";", "reqlog", ".", "info", "(", "'apier initialized!!'", ")", ";", "var", "app", "=", "function", "(", "req", ",", "res", ")", "{", "// this is the final handler if no match found", "router", "(", "req", ",", "res", ",", "function", "(", "error", ")", "{", "if", "(", "error", ")", "{", "reqlog", ".", "error", "(", "error", ")", ";", "responseBuilder", ".", "error", "(", "req", ",", "res", ",", "'INTERNAL_SERVER_ERROR'", ")", ";", "}", "else", "{", "reqlog", ".", "info", "(", "'NOT_FOUND:'", ",", "req", ".", "method", "+", "' '", "+", "req", ".", "url", ")", ";", "responseBuilder", ".", "error", "(", "req", ",", "res", ",", "'NOT_FOUND'", ")", ";", "}", "}", ")", ";", "}", ";", "app", ".", "endpoint", "=", "endpoint", ";", "return", "app", ";", "}" ]
Create an apier app @method apier @param {object} config The app configuration It must contain the following options mongoUrl: String. The mongo url to connect to handleErrors: Boolean. Define if the schemaExtender will handle the db errors @return {Function} The app to use as server
[ "Create", "an", "apier", "app" ]
de980ebc7656459656d0c850f6584e4da3761b53
https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L26-L49
39,548
Knorcedger/apier
index.js
endpoint
function endpoint(options) { // find the middlewares options.permissions = options.permissions || ['null']; options.middlewares = options.middlewares || []; options.middlewares.unshift([permissioner(options.permissions)]); for (var i = 0, length = options.methods.length; i < length; i++) { var method = options.methods[i].toLowerCase(); reqlog.log('setup endpoint', method + ' ' + options.url); router[method](options.url, options.middlewares, function(req, res) { routerCallback(req, res, options.callback); }); } }
javascript
function endpoint(options) { // find the middlewares options.permissions = options.permissions || ['null']; options.middlewares = options.middlewares || []; options.middlewares.unshift([permissioner(options.permissions)]); for (var i = 0, length = options.methods.length; i < length; i++) { var method = options.methods[i].toLowerCase(); reqlog.log('setup endpoint', method + ' ' + options.url); router[method](options.url, options.middlewares, function(req, res) { routerCallback(req, res, options.callback); }); } }
[ "function", "endpoint", "(", "options", ")", "{", "// find the middlewares", "options", ".", "permissions", "=", "options", ".", "permissions", "||", "[", "'null'", "]", ";", "options", ".", "middlewares", "=", "options", ".", "middlewares", "||", "[", "]", ";", "options", ".", "middlewares", ".", "unshift", "(", "[", "permissioner", "(", "options", ".", "permissions", ")", "]", ")", ";", "for", "(", "var", "i", "=", "0", ",", "length", "=", "options", ".", "methods", ".", "length", ";", "i", "<", "length", ";", "i", "++", ")", "{", "var", "method", "=", "options", ".", "methods", "[", "i", "]", ".", "toLowerCase", "(", ")", ";", "reqlog", ".", "log", "(", "'setup endpoint'", ",", "method", "+", "' '", "+", "options", ".", "url", ")", ";", "router", "[", "method", "]", "(", "options", ".", "url", ",", "options", ".", "middlewares", ",", "function", "(", "req", ",", "res", ")", "{", "routerCallback", "(", "req", ",", "res", ",", "options", ".", "callback", ")", ";", "}", ")", ";", "}", "}" ]
Create an endpoint @method endpoint @param {object} options It contains the following options methods: Array. Can contain 'post', 'get', 'delete', 'put' url: String. The matching url e.g. /users, /users/:id/update middlewares: Array. The middlewares (functions) that will be called before the callback permissions: Array (optional). Docs: https://github.com/Knorcedger/apier-permissioner if no permissions given, 'null' (public service) is assumed callback: Function. The callback function to execute
[ "Create", "an", "endpoint" ]
de980ebc7656459656d0c850f6584e4da3761b53
https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L80-L95
39,549
Knorcedger/apier
index.js
routerCallback
function routerCallback(req, res, callback) { var innerSelf = { req: req, res: res, send: function(data) { send.call(this, data); }, setStatusCode: function(statusCode) { setStatusCode.call(this, statusCode); } }; reqlog.info('inside routerCallback for endpoint: ', req.url); callback.call(innerSelf, req, res); }
javascript
function routerCallback(req, res, callback) { var innerSelf = { req: req, res: res, send: function(data) { send.call(this, data); }, setStatusCode: function(statusCode) { setStatusCode.call(this, statusCode); } }; reqlog.info('inside routerCallback for endpoint: ', req.url); callback.call(innerSelf, req, res); }
[ "function", "routerCallback", "(", "req", ",", "res", ",", "callback", ")", "{", "var", "innerSelf", "=", "{", "req", ":", "req", ",", "res", ":", "res", ",", "send", ":", "function", "(", "data", ")", "{", "send", ".", "call", "(", "this", ",", "data", ")", ";", "}", ",", "setStatusCode", ":", "function", "(", "statusCode", ")", "{", "setStatusCode", ".", "call", "(", "this", ",", "statusCode", ")", ";", "}", "}", ";", "reqlog", ".", "info", "(", "'inside routerCallback for endpoint: '", ",", "req", ".", "url", ")", ";", "callback", ".", "call", "(", "innerSelf", ",", "req", ",", "res", ")", ";", "}" ]
Defines the endpoint callback passed into the router create an object to apply as this in the callback its used to be able to call the send function inside the callback without having to also pass the req and res @method routerCallback @param {object} req A request object @param {object} res A response object @param {Function} callback The user defined endpoint callback
[ "Defines", "the", "endpoint", "callback", "passed", "into", "the", "router" ]
de980ebc7656459656d0c850f6584e4da3761b53
https://github.com/Knorcedger/apier/blob/de980ebc7656459656d0c850f6584e4da3761b53/index.js#L128-L141
39,550
lemonde/knex-schema
lib/sync.js
sync
function sync(schemas) { var resolver = new Resolver(schemas); // Reduce force sequential execution. return Promise.resolve(Promise.reduce(resolver.resolve(), syncSchema.bind(this), [])) .tap(function () { var knex = this.knex; return Promise.map(schemas || [], function(schema) { return (schema.postBuild || _.noop)(knex); }); }.bind(this)); }
javascript
function sync(schemas) { var resolver = new Resolver(schemas); // Reduce force sequential execution. return Promise.resolve(Promise.reduce(resolver.resolve(), syncSchema.bind(this), [])) .tap(function () { var knex = this.knex; return Promise.map(schemas || [], function(schema) { return (schema.postBuild || _.noop)(knex); }); }.bind(this)); }
[ "function", "sync", "(", "schemas", ")", "{", "var", "resolver", "=", "new", "Resolver", "(", "schemas", ")", ";", "// Reduce force sequential execution.", "return", "Promise", ".", "resolve", "(", "Promise", ".", "reduce", "(", "resolver", ".", "resolve", "(", ")", ",", "syncSchema", ".", "bind", "(", "this", ")", ",", "[", "]", ")", ")", ".", "tap", "(", "function", "(", ")", "{", "var", "knex", "=", "this", ".", "knex", ";", "return", "Promise", ".", "map", "(", "schemas", "||", "[", "]", ",", "function", "(", "schema", ")", "{", "return", "(", "schema", ".", "postBuild", "||", "_", ".", "noop", ")", "(", "knex", ")", ";", "}", ")", ";", "}", ".", "bind", "(", "this", ")", ")", ";", "}" ]
Synchronize given schemas with database. If it exists, it calls `postBuild` afterwards @param {[Schemas]} schemas @return {Promise}
[ "Synchronize", "given", "schemas", "with", "database", ".", "If", "it", "exists", "it", "calls", "postBuild", "afterwards" ]
3e0f6cde374d240552eb08e50e123a513fda44ae
https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L20-L30
39,551
lemonde/knex-schema
lib/sync.js
syncSchema
function syncSchema(result, schema) { var knex = this.knex; return knex.schema.hasTable(schema.tableName) .then(function (exists) { if (exists) return result; return knex.schema.createTable(schema.tableName, defineSchemaTable(schema)) .then(function () { return result.concat([schema]); }); }); }
javascript
function syncSchema(result, schema) { var knex = this.knex; return knex.schema.hasTable(schema.tableName) .then(function (exists) { if (exists) return result; return knex.schema.createTable(schema.tableName, defineSchemaTable(schema)) .then(function () { return result.concat([schema]); }); }); }
[ "function", "syncSchema", "(", "result", ",", "schema", ")", "{", "var", "knex", "=", "this", ".", "knex", ";", "return", "knex", ".", "schema", ".", "hasTable", "(", "schema", ".", "tableName", ")", ".", "then", "(", "function", "(", "exists", ")", "{", "if", "(", "exists", ")", "return", "result", ";", "return", "knex", ".", "schema", ".", "createTable", "(", "schema", ".", "tableName", ",", "defineSchemaTable", "(", "schema", ")", ")", ".", "then", "(", "function", "(", ")", "{", "return", "result", ".", "concat", "(", "[", "schema", "]", ")", ";", "}", ")", ";", "}", ")", ";", "}" ]
Synchronize given schema with database. @param {[Schema]} result - reduce accumulator @param {Schema} schema @return {Promise}
[ "Synchronize", "given", "schema", "with", "database", "." ]
3e0f6cde374d240552eb08e50e123a513fda44ae
https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L40-L50
39,552
lemonde/knex-schema
lib/sync.js
defineSchemaTable
function defineSchemaTable(schema) { return function (table) { table.timestamps(); (schema.build || _.noop)(table); }; }
javascript
function defineSchemaTable(schema) { return function (table) { table.timestamps(); (schema.build || _.noop)(table); }; }
[ "function", "defineSchemaTable", "(", "schema", ")", "{", "return", "function", "(", "table", ")", "{", "table", ".", "timestamps", "(", ")", ";", "(", "schema", ".", "build", "||", "_", ".", "noop", ")", "(", "table", ")", ";", "}", ";", "}" ]
Define default properties on the given schema. @param {Schema} schema @return {Function}
[ "Define", "default", "properties", "on", "the", "given", "schema", "." ]
3e0f6cde374d240552eb08e50e123a513fda44ae
https://github.com/lemonde/knex-schema/blob/3e0f6cde374d240552eb08e50e123a513fda44ae/lib/sync.js#L59-L64
39,553
gflarity/response
lib/graphite.js
function( data ) { var read_buffer = read_buffers_by_connection[tcp_connection]; read_buffer += data; //split by new lines, var messages = read_buffer.split('\n'); //last element is either a partial message, or '' read_buffer = messages.pop(); for ( var i = 0; i < messages.length; i++ ) { //TODO error handling var message = messages[i]; var components = message.split( ' ' ); var path = components[0]; var value = components[1]; var timestamp = components[2]; that.emit( path, value, timestamp ); } }
javascript
function( data ) { var read_buffer = read_buffers_by_connection[tcp_connection]; read_buffer += data; //split by new lines, var messages = read_buffer.split('\n'); //last element is either a partial message, or '' read_buffer = messages.pop(); for ( var i = 0; i < messages.length; i++ ) { //TODO error handling var message = messages[i]; var components = message.split( ' ' ); var path = components[0]; var value = components[1]; var timestamp = components[2]; that.emit( path, value, timestamp ); } }
[ "function", "(", "data", ")", "{", "var", "read_buffer", "=", "read_buffers_by_connection", "[", "tcp_connection", "]", ";", "read_buffer", "+=", "data", ";", "//split by new lines, ", "var", "messages", "=", "read_buffer", ".", "split", "(", "'\\n'", ")", ";", "//last element is either a partial message, or '' ", "read_buffer", "=", "messages", ".", "pop", "(", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "messages", ".", "length", ";", "i", "++", ")", "{", "//TODO error handling", "var", "message", "=", "messages", "[", "i", "]", ";", "var", "components", "=", "message", ".", "split", "(", "' '", ")", ";", "var", "path", "=", "components", "[", "0", "]", ";", "var", "value", "=", "components", "[", "1", "]", ";", "var", "timestamp", "=", "components", "[", "2", "]", ";", "that", ".", "emit", "(", "path", ",", "value", ",", "timestamp", ")", ";", "}", "}" ]
setup our handlers for this connection data
[ "setup", "our", "handlers", "for", "this", "connection", "data" ]
bf1f7342afbdf460970935e61abda14d8ef947fe
https://github.com/gflarity/response/blob/bf1f7342afbdf460970935e61abda14d8ef947fe/lib/graphite.js#L34-L57
39,554
kaelzhang/make-array
index.js
isArrayLikeObject
function isArrayLikeObject (subject) { var length = subject.length if ( typeof subject === 'function' || Object(subject) !== subject || typeof length !== 'number' // `window` already has a property `length` || 'setInterval' in subject ) { return false } return length === 0 || length > 0 && (length - 1) in subject }
javascript
function isArrayLikeObject (subject) { var length = subject.length if ( typeof subject === 'function' || Object(subject) !== subject || typeof length !== 'number' // `window` already has a property `length` || 'setInterval' in subject ) { return false } return length === 0 || length > 0 && (length - 1) in subject }
[ "function", "isArrayLikeObject", "(", "subject", ")", "{", "var", "length", "=", "subject", ".", "length", "if", "(", "typeof", "subject", "===", "'function'", "||", "Object", "(", "subject", ")", "!==", "subject", "||", "typeof", "length", "!==", "'number'", "// `window` already has a property `length`", "||", "'setInterval'", "in", "subject", ")", "{", "return", "false", "}", "return", "length", "===", "0", "||", "length", ">", "0", "&&", "(", "length", "-", "1", ")", "in", "subject", "}" ]
altered from jQuery
[ "altered", "from", "jQuery" ]
4e04c3fe7586ccb3fe1e96d06aa694df0c656327
https://github.com/kaelzhang/make-array/blob/4e04c3fe7586ccb3fe1e96d06aa694df0c656327/index.js#L40-L55
39,555
kaelzhang/make-array
index.js
clonePureArray
function clonePureArray (subject, host) { var i = subject.length var start = host.length while (i --) { host[start + i] = subject[i] } return host }
javascript
function clonePureArray (subject, host) { var i = subject.length var start = host.length while (i --) { host[start + i] = subject[i] } return host }
[ "function", "clonePureArray", "(", "subject", ",", "host", ")", "{", "var", "i", "=", "subject", ".", "length", "var", "start", "=", "host", ".", "length", "while", "(", "i", "--", ")", "{", "host", "[", "start", "+", "i", "]", "=", "subject", "[", "i", "]", "}", "return", "host", "}" ]
clone an object as a pure subject, and ignore non-number properties @param {Array} subject @param {Array|Object} host required, receiver which the subject be cloned to
[ "clone", "an", "object", "as", "a", "pure", "subject", "and", "ignore", "non", "-", "number", "properties" ]
4e04c3fe7586ccb3fe1e96d06aa694df0c656327
https://github.com/kaelzhang/make-array/blob/4e04c3fe7586ccb3fe1e96d06aa694df0c656327/index.js#L62-L71
39,556
emeryrose/mtree
lib/tree.js
MerkleTree
function MerkleTree(leaves, hasher) { if (!(this instanceof MerkleTree)) { return new MerkleTree(leaves, hasher); } this._hasher = hasher || this._hasher; this._leaves = []; this._depth = 0; this._rows = []; this._count = 0; assert(Array.isArray(leaves), 'Invalid leaves array supplied'); assert(typeof this._hasher === 'function', 'Invalid hash function supplied'); for (var i = 0; i < leaves.length; i++) { this._feed(leaves[i]); } this._compute(); }
javascript
function MerkleTree(leaves, hasher) { if (!(this instanceof MerkleTree)) { return new MerkleTree(leaves, hasher); } this._hasher = hasher || this._hasher; this._leaves = []; this._depth = 0; this._rows = []; this._count = 0; assert(Array.isArray(leaves), 'Invalid leaves array supplied'); assert(typeof this._hasher === 'function', 'Invalid hash function supplied'); for (var i = 0; i < leaves.length; i++) { this._feed(leaves[i]); } this._compute(); }
[ "function", "MerkleTree", "(", "leaves", ",", "hasher", ")", "{", "if", "(", "!", "(", "this", "instanceof", "MerkleTree", ")", ")", "{", "return", "new", "MerkleTree", "(", "leaves", ",", "hasher", ")", ";", "}", "this", ".", "_hasher", "=", "hasher", "||", "this", ".", "_hasher", ";", "this", ".", "_leaves", "=", "[", "]", ";", "this", ".", "_depth", "=", "0", ";", "this", ".", "_rows", "=", "[", "]", ";", "this", ".", "_count", "=", "0", ";", "assert", "(", "Array", ".", "isArray", "(", "leaves", ")", ",", "'Invalid leaves array supplied'", ")", ";", "assert", "(", "typeof", "this", ".", "_hasher", "===", "'function'", ",", "'Invalid hash function supplied'", ")", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "leaves", ".", "length", ";", "i", "++", ")", "{", "this", ".", "_feed", "(", "leaves", "[", "i", "]", ")", ";", "}", "this", ".", "_compute", "(", ")", ";", "}" ]
Implements a merkle hash tree @constructor @param {Array} leaves - Initial tree input @param {Function} hasher - Hash function for building tree
[ "Implements", "a", "merkle", "hash", "tree" ]
21428212a4955d0498f1272c7df17645dcc379f6
https://github.com/emeryrose/mtree/blob/21428212a4955d0498f1272c7df17645dcc379f6/lib/tree.js#L12-L31
39,557
ofzza/enTT
tasks/index.js
queueTasks
function queueTasks (testTasks, buildTasks) { // Queue up test tasks, removing them if already queued up _.forEach({ test: testTasks, build: buildTasks }, (queuingTasks, type) => { _.forEach(queuingTasks, (task) => { // Remove if already queued const removed = _.remove(queue[type], (queuedTask) => { return (queuedTask === task); }); // Queue task ... queue[type].push(task); // Reorder tasks by original configuration ordering queue[type] = _.sortBy(queue[type], (queuedTask) => { return _.findIndex(orderedTasks, (originalTask) => { return (originalTask === queuedTask); }); }); // Prompt queued task console.log(`> ${removed.length ? 'Requeued' : 'Queued'} ${ type } task for execution: "${ task.blue }"`); console.log(` Queue: ${ [...queue.test, ...queue.build].join(', ').gray }`); }); }); // Execute tasks from the queue executeQueuedTasks(); }
javascript
function queueTasks (testTasks, buildTasks) { // Queue up test tasks, removing them if already queued up _.forEach({ test: testTasks, build: buildTasks }, (queuingTasks, type) => { _.forEach(queuingTasks, (task) => { // Remove if already queued const removed = _.remove(queue[type], (queuedTask) => { return (queuedTask === task); }); // Queue task ... queue[type].push(task); // Reorder tasks by original configuration ordering queue[type] = _.sortBy(queue[type], (queuedTask) => { return _.findIndex(orderedTasks, (originalTask) => { return (originalTask === queuedTask); }); }); // Prompt queued task console.log(`> ${removed.length ? 'Requeued' : 'Queued'} ${ type } task for execution: "${ task.blue }"`); console.log(` Queue: ${ [...queue.test, ...queue.build].join(', ').gray }`); }); }); // Execute tasks from the queue executeQueuedTasks(); }
[ "function", "queueTasks", "(", "testTasks", ",", "buildTasks", ")", "{", "// Queue up test tasks, removing them if already queued up", "_", ".", "forEach", "(", "{", "test", ":", "testTasks", ",", "build", ":", "buildTasks", "}", ",", "(", "queuingTasks", ",", "type", ")", "=>", "{", "_", ".", "forEach", "(", "queuingTasks", ",", "(", "task", ")", "=>", "{", "// Remove if already queued", "const", "removed", "=", "_", ".", "remove", "(", "queue", "[", "type", "]", ",", "(", "queuedTask", ")", "=>", "{", "return", "(", "queuedTask", "===", "task", ")", ";", "}", ")", ";", "// Queue task ...", "queue", "[", "type", "]", ".", "push", "(", "task", ")", ";", "// Reorder tasks by original configuration ordering", "queue", "[", "type", "]", "=", "_", ".", "sortBy", "(", "queue", "[", "type", "]", ",", "(", "queuedTask", ")", "=>", "{", "return", "_", ".", "findIndex", "(", "orderedTasks", ",", "(", "originalTask", ")", "=>", "{", "return", "(", "originalTask", "===", "queuedTask", ")", ";", "}", ")", ";", "}", ")", ";", "// Prompt queued task", "console", ".", "log", "(", "`", "${", "removed", ".", "length", "?", "'Requeued'", ":", "'Queued'", "}", "${", "type", "}", "${", "task", ".", "blue", "}", "`", ")", ";", "console", ".", "log", "(", "`", "${", "[", "...", "queue", ".", "test", ",", "...", "queue", ".", "build", "]", ".", "join", "(", "', '", ")", ".", "gray", "}", "`", ")", ";", "}", ")", ";", "}", ")", ";", "// Execute tasks from the queue", "executeQueuedTasks", "(", ")", ";", "}" ]
Queues up tasks for execution @param {any} testTasks Array of test tasks names @param {any} buildTasks Array of build task names
[ "Queues", "up", "tasks", "for", "execution" ]
fdf27de4142b3c65a3e51dee70e0d7625dff897c
https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/tasks/index.js#L81-L102
39,558
ofzza/enTT
tasks/index.js
executeQueuedTasks
function executeQueuedTasks () { // Delay execution to allow for more tasks to queue up setTimeout(() => { // Check if already executing and if any tasks ready for execution if (!executing && (queue.test.length || queue.build.length)) { // Flag executing status executing = true; // Pop a task from the execution queue const task = (queue.test.length ? queue.test.splice(0, 1)[0] : queue.build.splice(0, 1)[0]); // Execute task gulp.series([task])(() => { // Flag executing status executing = false; // Execute next task from the queue executeQueuedTasks(); }); } }, 250); // If no tasks queued up, prompt watcher done if (!executing && !(queue.test.length || queue.build.length)) { console.log(); console.log(`> WATCHER(S) DONE PROCESSING - WAITING FOR CHANGES ...`.green); console.log(); } }
javascript
function executeQueuedTasks () { // Delay execution to allow for more tasks to queue up setTimeout(() => { // Check if already executing and if any tasks ready for execution if (!executing && (queue.test.length || queue.build.length)) { // Flag executing status executing = true; // Pop a task from the execution queue const task = (queue.test.length ? queue.test.splice(0, 1)[0] : queue.build.splice(0, 1)[0]); // Execute task gulp.series([task])(() => { // Flag executing status executing = false; // Execute next task from the queue executeQueuedTasks(); }); } }, 250); // If no tasks queued up, prompt watcher done if (!executing && !(queue.test.length || queue.build.length)) { console.log(); console.log(`> WATCHER(S) DONE PROCESSING - WAITING FOR CHANGES ...`.green); console.log(); } }
[ "function", "executeQueuedTasks", "(", ")", "{", "// Delay execution to allow for more tasks to queue up", "setTimeout", "(", "(", ")", "=>", "{", "// Check if already executing and if any tasks ready for execution", "if", "(", "!", "executing", "&&", "(", "queue", ".", "test", ".", "length", "||", "queue", ".", "build", ".", "length", ")", ")", "{", "// Flag executing status", "executing", "=", "true", ";", "// Pop a task from the execution queue", "const", "task", "=", "(", "queue", ".", "test", ".", "length", "?", "queue", ".", "test", ".", "splice", "(", "0", ",", "1", ")", "[", "0", "]", ":", "queue", ".", "build", ".", "splice", "(", "0", ",", "1", ")", "[", "0", "]", ")", ";", "// Execute task", "gulp", ".", "series", "(", "[", "task", "]", ")", "(", "(", ")", "=>", "{", "// Flag executing status", "executing", "=", "false", ";", "// Execute next task from the queue", "executeQueuedTasks", "(", ")", ";", "}", ")", ";", "}", "}", ",", "250", ")", ";", "// If no tasks queued up, prompt watcher done", "if", "(", "!", "executing", "&&", "!", "(", "queue", ".", "test", ".", "length", "||", "queue", ".", "build", ".", "length", ")", ")", "{", "console", ".", "log", "(", ")", ";", "console", ".", "log", "(", "`", "`", ".", "green", ")", ";", "console", ".", "log", "(", ")", ";", "}", "}" ]
Executes previously queued up tasks, one-by-one
[ "Executes", "previously", "queued", "up", "tasks", "one", "-", "by", "-", "one" ]
fdf27de4142b3c65a3e51dee70e0d7625dff897c
https://github.com/ofzza/enTT/blob/fdf27de4142b3c65a3e51dee70e0d7625dff897c/tasks/index.js#L107-L131
39,559
ecomfe/jformatter
jformatter.js
function () { return { lineSeparator: '\n', // done maxLength: 120, // TODO wrapIfLong: false, // TODO indent: 4, // done useTabIndent: false, // done spaces: { around: { unaryOperators: false, // TODO binaryOperators: true, // done ternaryOperators: true // done }, before: { functionDeclarationParentheses: false, // done function foo() { functionExpressionParentheses: true, // done var foo = function () { parentheses: true, // done if (), for (), while (), ... leftBrace: true, // done function () {, if () {, do {, try { ... keywords: true // done if {} else {}, do {} while (), try {} catch () {} finally }, within: { // function call, function declaration, if, for, while, switch, catch parentheses: false // done }, other: { beforePropertyNameValueSeparator: false, // done {key: value} {key : value} {key:value} afterPropertyNameValueSeparator: true // done } }, bracesPlacement: { // 1. same line 2. next line functionDeclaration: 1, // TODO other: 1 // TODO }, blankLines: { keepMaxBlankLines: 1, // done atEndOfFile: true // done }, other: { keepArraySingleLine: false // TODO default formatted array multi line }, fix: { prefixSpaceToLineComment: false, // done alterCommonBlockCommentToLineComment: false, // done singleVariableDeclarator: false, // done fixInvalidTypeof: false, // done removeEmptyStatement: false, // done autoSemicolon: false, // done singleQuotes: false, // done eqeqeq: false, // done invalidConstructor: false, // done addCurly: false, // done removeDebugger: false, // done noElseReturn: false } }; }
javascript
function () { return { lineSeparator: '\n', // done maxLength: 120, // TODO wrapIfLong: false, // TODO indent: 4, // done useTabIndent: false, // done spaces: { around: { unaryOperators: false, // TODO binaryOperators: true, // done ternaryOperators: true // done }, before: { functionDeclarationParentheses: false, // done function foo() { functionExpressionParentheses: true, // done var foo = function () { parentheses: true, // done if (), for (), while (), ... leftBrace: true, // done function () {, if () {, do {, try { ... keywords: true // done if {} else {}, do {} while (), try {} catch () {} finally }, within: { // function call, function declaration, if, for, while, switch, catch parentheses: false // done }, other: { beforePropertyNameValueSeparator: false, // done {key: value} {key : value} {key:value} afterPropertyNameValueSeparator: true // done } }, bracesPlacement: { // 1. same line 2. next line functionDeclaration: 1, // TODO other: 1 // TODO }, blankLines: { keepMaxBlankLines: 1, // done atEndOfFile: true // done }, other: { keepArraySingleLine: false // TODO default formatted array multi line }, fix: { prefixSpaceToLineComment: false, // done alterCommonBlockCommentToLineComment: false, // done singleVariableDeclarator: false, // done fixInvalidTypeof: false, // done removeEmptyStatement: false, // done autoSemicolon: false, // done singleQuotes: false, // done eqeqeq: false, // done invalidConstructor: false, // done addCurly: false, // done removeDebugger: false, // done noElseReturn: false } }; }
[ "function", "(", ")", "{", "return", "{", "lineSeparator", ":", "'\\n'", ",", "// done", "maxLength", ":", "120", ",", "// TODO", "wrapIfLong", ":", "false", ",", "// TODO", "indent", ":", "4", ",", "// done", "useTabIndent", ":", "false", ",", "// done", "spaces", ":", "{", "around", ":", "{", "unaryOperators", ":", "false", ",", "// TODO", "binaryOperators", ":", "true", ",", "// done", "ternaryOperators", ":", "true", "// done", "}", ",", "before", ":", "{", "functionDeclarationParentheses", ":", "false", ",", "// done function foo() {", "functionExpressionParentheses", ":", "true", ",", "// done var foo = function () {", "parentheses", ":", "true", ",", "// done if (), for (), while (), ...", "leftBrace", ":", "true", ",", "// done function () {, if () {, do {, try { ...", "keywords", ":", "true", "// done if {} else {}, do {} while (), try {} catch () {} finally", "}", ",", "within", ":", "{", "// function call, function declaration, if, for, while, switch, catch", "parentheses", ":", "false", "// done", "}", ",", "other", ":", "{", "beforePropertyNameValueSeparator", ":", "false", ",", "// done {key: value} {key : value} {key:value}", "afterPropertyNameValueSeparator", ":", "true", "// done", "}", "}", ",", "bracesPlacement", ":", "{", "// 1. same line 2. next line", "functionDeclaration", ":", "1", ",", "// TODO", "other", ":", "1", "// TODO", "}", ",", "blankLines", ":", "{", "keepMaxBlankLines", ":", "1", ",", "// done", "atEndOfFile", ":", "true", "// done", "}", ",", "other", ":", "{", "keepArraySingleLine", ":", "false", "// TODO default formatted array multi line", "}", ",", "fix", ":", "{", "prefixSpaceToLineComment", ":", "false", ",", "// done", "alterCommonBlockCommentToLineComment", ":", "false", ",", "// done", "singleVariableDeclarator", ":", "false", ",", "// done", "fixInvalidTypeof", ":", "false", ",", "// done", "removeEmptyStatement", ":", "false", ",", "// done", "autoSemicolon", ":", "false", ",", "// done", "singleQuotes", ":", "false", ",", "// done", "eqeqeq", ":", "false", ",", "// done", "invalidConstructor", ":", "false", ",", "// done", "addCurly", ":", "false", ",", "// done", "removeDebugger", ":", "false", ",", "// done", "noElseReturn", ":", "false", "}", "}", ";", "}" ]
returns default config @returns {Object}
[ "returns", "default", "config" ]
fce4c775a54362a7dc67cab71f8dc8f54d809b3d
https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L11-L66
39,560
ecomfe/jformatter
jformatter.js
function (defaults, configure) { for (var key in defaults) { if (defaults.hasOwnProperty(key)) { if (typeof defaults[key] === 'object') { // recursive if (typeof configure[key] === 'object') { overwriteConfig(defaults[key], configure[key]); } } else { // copy directly if (typeof configure[key] !== 'undefined') { defaults[key] = configure[key]; } } } } }
javascript
function (defaults, configure) { for (var key in defaults) { if (defaults.hasOwnProperty(key)) { if (typeof defaults[key] === 'object') { // recursive if (typeof configure[key] === 'object') { overwriteConfig(defaults[key], configure[key]); } } else { // copy directly if (typeof configure[key] !== 'undefined') { defaults[key] = configure[key]; } } } } }
[ "function", "(", "defaults", ",", "configure", ")", "{", "for", "(", "var", "key", "in", "defaults", ")", "{", "if", "(", "defaults", ".", "hasOwnProperty", "(", "key", ")", ")", "{", "if", "(", "typeof", "defaults", "[", "key", "]", "===", "'object'", ")", "{", "// recursive", "if", "(", "typeof", "configure", "[", "key", "]", "===", "'object'", ")", "{", "overwriteConfig", "(", "defaults", "[", "key", "]", ",", "configure", "[", "key", "]", ")", ";", "}", "}", "else", "{", "// copy directly", "if", "(", "typeof", "configure", "[", "key", "]", "!==", "'undefined'", ")", "{", "defaults", "[", "key", "]", "=", "configure", "[", "key", "]", ";", "}", "}", "}", "}", "}" ]
defaults the config
[ "defaults", "the", "config" ]
fce4c775a54362a7dc67cab71f8dc8f54d809b3d
https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L71-L87
39,561
ecomfe/jformatter
jformatter.js
function () { var indentStr = ''; for (var i = 0; i < indentLevel; i++) { indentStr += INDENT; } return { type: 'WhiteSpace', value: indentStr }; }
javascript
function () { var indentStr = ''; for (var i = 0; i < indentLevel; i++) { indentStr += INDENT; } return { type: 'WhiteSpace', value: indentStr }; }
[ "function", "(", ")", "{", "var", "indentStr", "=", "''", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "indentLevel", ";", "i", "++", ")", "{", "indentStr", "+=", "INDENT", ";", "}", "return", "{", "type", ":", "'WhiteSpace'", ",", "value", ":", "indentStr", "}", ";", "}" ]
create a indent token with indent level @returns {Object}
[ "create", "a", "indent", "token", "with", "indent", "level" ]
fce4c775a54362a7dc67cab71f8dc8f54d809b3d
https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L135-L144
39,562
ecomfe/jformatter
jformatter.js
function (token) { var inline = false; if (token) { if (token.type === 'LineComment') { inline = true; } else if (token.type === 'BlockComment') { inline = (token.value.indexOf('\n') === -1); } } return inline; }
javascript
function (token) { var inline = false; if (token) { if (token.type === 'LineComment') { inline = true; } else if (token.type === 'BlockComment') { inline = (token.value.indexOf('\n') === -1); } } return inline; }
[ "function", "(", "token", ")", "{", "var", "inline", "=", "false", ";", "if", "(", "token", ")", "{", "if", "(", "token", ".", "type", "===", "'LineComment'", ")", "{", "inline", "=", "true", ";", "}", "else", "if", "(", "token", ".", "type", "===", "'BlockComment'", ")", "{", "inline", "=", "(", "token", ".", "value", ".", "indexOf", "(", "'\\n'", ")", "===", "-", "1", ")", ";", "}", "}", "return", "inline", ";", "}" ]
check if a token is comment in one line @param {Object} token - the token to check @returns {boolean}
[ "check", "if", "a", "token", "is", "comment", "in", "one", "line" ]
fce4c775a54362a7dc67cab71f8dc8f54d809b3d
https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L226-L236
39,563
ecomfe/jformatter
jformatter.js
function (startToken, endToken, types) { var is = true; var token = startToken; while (token.next && token.next !== endToken) { token = token.next; if (types.indexOf(token.type) === -1) { is = false; break; } } return is; }
javascript
function (startToken, endToken, types) { var is = true; var token = startToken; while (token.next && token.next !== endToken) { token = token.next; if (types.indexOf(token.type) === -1) { is = false; break; } } return is; }
[ "function", "(", "startToken", ",", "endToken", ",", "types", ")", "{", "var", "is", "=", "true", ";", "var", "token", "=", "startToken", ";", "while", "(", "token", ".", "next", "&&", "token", ".", "next", "!==", "endToken", ")", "{", "token", "=", "token", ".", "next", ";", "if", "(", "types", ".", "indexOf", "(", "token", ".", "type", ")", "===", "-", "1", ")", "{", "is", "=", "false", ";", "break", ";", "}", "}", "return", "is", ";", "}" ]
check if only types between startToken and endToken @param {Object} startToken - the token to start check @param {Object} endToken - the token to end check @param {Array} types - allow types array @returns {boolean}
[ "check", "if", "only", "types", "between", "startToken", "and", "endToken" ]
fce4c775a54362a7dc67cab71f8dc8f54d809b3d
https://github.com/ecomfe/jformatter/blob/fce4c775a54362a7dc67cab71f8dc8f54d809b3d/jformatter.js#L246-L257
39,564
sithmel/obj-path-expression-parser
lib/parser/grammar.js
pathExpression
function pathExpression (token, tokens) { const expression = [] while (true) { if (!token) { break } if (token === ')') { tokens.unshift(token) break } if (includes('}]', token)) { throw new Error(`A fragment can't contain "${token}"`) } if (token === ',') { break } if (token === '[') { expression.push(escapedFragment(token, tokens)) } else if (token === '(') { expression.push(pathExpressions(token, tokens)) } else if (token === '{') { expression.push(customFragment(token, tokens)) } else { expression.push(unescapedFragment(token, tokens)) } token = tokens.shift() } return { _type: pathExpression.name, expression } }
javascript
function pathExpression (token, tokens) { const expression = [] while (true) { if (!token) { break } if (token === ')') { tokens.unshift(token) break } if (includes('}]', token)) { throw new Error(`A fragment can't contain "${token}"`) } if (token === ',') { break } if (token === '[') { expression.push(escapedFragment(token, tokens)) } else if (token === '(') { expression.push(pathExpressions(token, tokens)) } else if (token === '{') { expression.push(customFragment(token, tokens)) } else { expression.push(unescapedFragment(token, tokens)) } token = tokens.shift() } return { _type: pathExpression.name, expression } }
[ "function", "pathExpression", "(", "token", ",", "tokens", ")", "{", "const", "expression", "=", "[", "]", "while", "(", "true", ")", "{", "if", "(", "!", "token", ")", "{", "break", "}", "if", "(", "token", "===", "')'", ")", "{", "tokens", ".", "unshift", "(", "token", ")", "break", "}", "if", "(", "includes", "(", "'}]'", ",", "token", ")", ")", "{", "throw", "new", "Error", "(", "`", "${", "token", "}", "`", ")", "}", "if", "(", "token", "===", "','", ")", "{", "break", "}", "if", "(", "token", "===", "'['", ")", "{", "expression", ".", "push", "(", "escapedFragment", "(", "token", ",", "tokens", ")", ")", "}", "else", "if", "(", "token", "===", "'('", ")", "{", "expression", ".", "push", "(", "pathExpressions", "(", "token", ",", "tokens", ")", ")", "}", "else", "if", "(", "token", "===", "'{'", ")", "{", "expression", ".", "push", "(", "customFragment", "(", "token", ",", "tokens", ")", ")", "}", "else", "{", "expression", ".", "push", "(", "unescapedFragment", "(", "token", ",", "tokens", ")", ")", "}", "token", "=", "tokens", ".", "shift", "(", ")", "}", "return", "{", "_type", ":", "pathExpression", ".", "name", ",", "expression", "}", "}" ]
ends with "," or with "end of string"
[ "ends", "with", "or", "with", "end", "of", "string" ]
ba942086d98f42d01ea34592328630179c4bde80
https://github.com/sithmel/obj-path-expression-parser/blob/ba942086d98f42d01ea34592328630179c4bde80/lib/parser/grammar.js#L91-L121
39,565
jonschlinkert/api-toc
index.js
context
function context(str) { var arr = code(str); var len = arr.length, i = 0; var res = {}; while (len--) { var ele = arr[i++]; if (ele.type !== 'comment') { res[ele.name] = ele.begin; } } return res; }
javascript
function context(str) { var arr = code(str); var len = arr.length, i = 0; var res = {}; while (len--) { var ele = arr[i++]; if (ele.type !== 'comment') { res[ele.name] = ele.begin; } } return res; }
[ "function", "context", "(", "str", ")", "{", "var", "arr", "=", "code", "(", "str", ")", ";", "var", "len", "=", "arr", ".", "length", ",", "i", "=", "0", ";", "var", "res", "=", "{", "}", ";", "while", "(", "len", "--", ")", "{", "var", "ele", "=", "arr", "[", "i", "++", "]", ";", "if", "(", "ele", ".", "type", "!==", "'comment'", ")", "{", "res", "[", "ele", ".", "name", "]", "=", "ele", ".", "begin", ";", "}", "}", "return", "res", ";", "}" ]
Get the code context for a JavaScript file.
[ "Get", "the", "code", "context", "for", "a", "JavaScript", "file", "." ]
2723a7b597a1a9629309396e0e613591783f841b
https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L67-L79
39,566
jonschlinkert/api-toc
index.js
format
function format(obj, opts, fn) { if (typeof opts === 'function') { fn = opts; opts = {}; } opts = opts || {}; if (Array.isArray(opts.filter) || typeof opts.filter === 'string') { obj = filter(obj, opts.filter); } var keys = Object.keys(obj); var len = keys.length, i = 0; var str = ''; var total = len; while (len--) { var fp = keys[i++]; var ctx = context(read(fp), fn); var name = basename(fp); str += heading(name, fp); var list = obj[fp]; var methods = Object.keys(list); total += methods.length; str += listify(fp, methods, ctx); } var res = {}; res.list = str; res.total = total; return res; }
javascript
function format(obj, opts, fn) { if (typeof opts === 'function') { fn = opts; opts = {}; } opts = opts || {}; if (Array.isArray(opts.filter) || typeof opts.filter === 'string') { obj = filter(obj, opts.filter); } var keys = Object.keys(obj); var len = keys.length, i = 0; var str = ''; var total = len; while (len--) { var fp = keys[i++]; var ctx = context(read(fp), fn); var name = basename(fp); str += heading(name, fp); var list = obj[fp]; var methods = Object.keys(list); total += methods.length; str += listify(fp, methods, ctx); } var res = {}; res.list = str; res.total = total; return res; }
[ "function", "format", "(", "obj", ",", "opts", ",", "fn", ")", "{", "if", "(", "typeof", "opts", "===", "'function'", ")", "{", "fn", "=", "opts", ";", "opts", "=", "{", "}", ";", "}", "opts", "=", "opts", "||", "{", "}", ";", "if", "(", "Array", ".", "isArray", "(", "opts", ".", "filter", ")", "||", "typeof", "opts", ".", "filter", "===", "'string'", ")", "{", "obj", "=", "filter", "(", "obj", ",", "opts", ".", "filter", ")", ";", "}", "var", "keys", "=", "Object", ".", "keys", "(", "obj", ")", ";", "var", "len", "=", "keys", ".", "length", ",", "i", "=", "0", ";", "var", "str", "=", "''", ";", "var", "total", "=", "len", ";", "while", "(", "len", "--", ")", "{", "var", "fp", "=", "keys", "[", "i", "++", "]", ";", "var", "ctx", "=", "context", "(", "read", "(", "fp", ")", ",", "fn", ")", ";", "var", "name", "=", "basename", "(", "fp", ")", ";", "str", "+=", "heading", "(", "name", ",", "fp", ")", ";", "var", "list", "=", "obj", "[", "fp", "]", ";", "var", "methods", "=", "Object", ".", "keys", "(", "list", ")", ";", "total", "+=", "methods", ".", "length", ";", "str", "+=", "listify", "(", "fp", ",", "methods", ",", "ctx", ")", ";", "}", "var", "res", "=", "{", "}", ";", "res", ".", "list", "=", "str", ";", "res", ".", "total", "=", "total", ";", "return", "res", ";", "}" ]
Generate a formatted list that includes the given files, and their respective methods. Uses code context to build the list. @param {Object} `obj` Object, The key is a file name and the properties are the methods. @return {Object}
[ "Generate", "a", "formatted", "list", "that", "includes", "the", "given", "files", "and", "their", "respective", "methods", ".", "Uses", "code", "context", "to", "build", "the", "list", "." ]
2723a7b597a1a9629309396e0e613591783f841b
https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L90-L122
39,567
jonschlinkert/api-toc
index.js
listify
function listify(fp, methods, ctx) { var len = methods.length, i = 0; var res = ['']; while (len--) { var method = methods[i++]; var line = ctx[method]; var item = line ? linkify('.' + method, fp, '#L' + line) : method; item = ' - ' + item; res.push(item); } return res.sort().join('\n'); }
javascript
function listify(fp, methods, ctx) { var len = methods.length, i = 0; var res = ['']; while (len--) { var method = methods[i++]; var line = ctx[method]; var item = line ? linkify('.' + method, fp, '#L' + line) : method; item = ' - ' + item; res.push(item); } return res.sort().join('\n'); }
[ "function", "listify", "(", "fp", ",", "methods", ",", "ctx", ")", "{", "var", "len", "=", "methods", ".", "length", ",", "i", "=", "0", ";", "var", "res", "=", "[", "''", "]", ";", "while", "(", "len", "--", ")", "{", "var", "method", "=", "methods", "[", "i", "++", "]", ";", "var", "line", "=", "ctx", "[", "method", "]", ";", "var", "item", "=", "line", "?", "linkify", "(", "'.'", "+", "method", ",", "fp", ",", "'#L'", "+", "line", ")", ":", "method", ";", "item", "=", "' - '", "+", "item", ";", "res", ".", "push", "(", "item", ")", ";", "}", "return", "res", ".", "sort", "(", ")", ".", "join", "(", "'\\n'", ")", ";", "}" ]
Create a formatted list for a file and it methods. @param {String} `fp` File path @param {Array} `items` Array of items to format. @param {Object} `ctx` Code context, mainly for getting line numbers to create links. @return {Array}
[ "Create", "a", "formatted", "list", "for", "a", "file", "and", "it", "methods", "." ]
2723a7b597a1a9629309396e0e613591783f841b
https://github.com/jonschlinkert/api-toc/blob/2723a7b597a1a9629309396e0e613591783f841b/index.js#L133-L144
39,568
EricCrosson/coinmarketcap-cli
index.js
tableize
function tableize(tableData) { var table = new Table({ head: Object.keys(tableData[0]), chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''}, style: { 'padding-left': 0, 'padding-right': 0 } }); _.each(tableData, function(row, index) { table.push(_.values(row)); }); return table; }
javascript
function tableize(tableData) { var table = new Table({ head: Object.keys(tableData[0]), chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''}, style: { 'padding-left': 0, 'padding-right': 0 } }); _.each(tableData, function(row, index) { table.push(_.values(row)); }); return table; }
[ "function", "tableize", "(", "tableData", ")", "{", "var", "table", "=", "new", "Table", "(", "{", "head", ":", "Object", ".", "keys", "(", "tableData", "[", "0", "]", ")", ",", "chars", ":", "{", "'mid'", ":", "''", ",", "'left-mid'", ":", "''", ",", "'mid-mid'", ":", "''", ",", "'right-mid'", ":", "''", "}", ",", "style", ":", "{", "'padding-left'", ":", "0", ",", "'padding-right'", ":", "0", "}", "}", ")", ";", "_", ".", "each", "(", "tableData", ",", "function", "(", "row", ",", "index", ")", "{", "table", ".", "push", "(", "_", ".", "values", "(", "row", ")", ")", ";", "}", ")", ";", "return", "table", ";", "}" ]
returns a table object
[ "returns", "a", "table", "object" ]
bdf4fbf28f8706d80415905d90b9458bd37f905d
https://github.com/EricCrosson/coinmarketcap-cli/blob/bdf4fbf28f8706d80415905d90b9458bd37f905d/index.js#L13-L24
39,569
CandleFW/wick
build/wick.node.js
CreateSchemedProperty
function CreateSchemedProperty(object, scheme, schema_name, index) { if (object[schema_name]) return; Object.defineProperty(object, schema_name, { configurable: false, enumerable: true, get: function() { return this.getHook(schema_name, this.prop_array[index]); }, set: function(value) { let result = { valid: false }; let val = scheme.parse(value); scheme.verify(val, result); if (result.valid && this.prop_array[index] != val) { this.prop_array[index] = this.setHook(schema_name, val); this.scheduleUpdate(schema_name); this._changed_ = true; } } }); }
javascript
function CreateSchemedProperty(object, scheme, schema_name, index) { if (object[schema_name]) return; Object.defineProperty(object, schema_name, { configurable: false, enumerable: true, get: function() { return this.getHook(schema_name, this.prop_array[index]); }, set: function(value) { let result = { valid: false }; let val = scheme.parse(value); scheme.verify(val, result); if (result.valid && this.prop_array[index] != val) { this.prop_array[index] = this.setHook(schema_name, val); this.scheduleUpdate(schema_name); this._changed_ = true; } } }); }
[ "function", "CreateSchemedProperty", "(", "object", ",", "scheme", ",", "schema_name", ",", "index", ")", "{", "if", "(", "object", "[", "schema_name", "]", ")", "return", ";", "Object", ".", "defineProperty", "(", "object", ",", "schema_name", ",", "{", "configurable", ":", "false", ",", "enumerable", ":", "true", ",", "get", ":", "function", "(", ")", "{", "return", "this", ".", "getHook", "(", "schema_name", ",", "this", ".", "prop_array", "[", "index", "]", ")", ";", "}", ",", "set", ":", "function", "(", "value", ")", "{", "let", "result", "=", "{", "valid", ":", "false", "}", ";", "let", "val", "=", "scheme", ".", "parse", "(", "value", ")", ";", "scheme", ".", "verify", "(", "val", ",", "result", ")", ";", "if", "(", "result", ".", "valid", "&&", "this", ".", "prop_array", "[", "index", "]", "!=", "val", ")", "{", "this", ".", "prop_array", "[", "index", "]", "=", "this", ".", "setHook", "(", "schema_name", ",", "val", ")", ";", "this", ".", "scheduleUpdate", "(", "schema_name", ")", ";", "this", ".", "_changed_", "=", "true", ";", "}", "}", "}", ")", ";", "}" ]
This is used by Model to create custom property getter and setters on non-ModelContainerBase and non-Model properties of the Model constructor. @protected @memberof module:wick~internals.model
[ "This", "is", "used", "by", "Model", "to", "create", "custom", "property", "getter", "and", "setters", "on", "non", "-", "ModelContainerBase", "and", "non", "-", "Model", "properties", "of", "the", "Model", "constructor", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L3628-L3653
39,570
CandleFW/wick
build/wick.node.js
CreateModelProperty
function CreateModelProperty(object, model, schema_name, index) { Object.defineProperty(object, schema_name, { configurable: false, enumerable: true, get: function() { let m = this.prop_array[index]; if (!m) { let address = this.address.slice(); address.push(index); m = new model(null, this.root, address); m.par = this; m.prop_name = schema_name; m.MUTATION_ID = this.MUTATION_ID; this.prop_array[index] = m; } return this.getHook(schema_name, m); } }); }
javascript
function CreateModelProperty(object, model, schema_name, index) { Object.defineProperty(object, schema_name, { configurable: false, enumerable: true, get: function() { let m = this.prop_array[index]; if (!m) { let address = this.address.slice(); address.push(index); m = new model(null, this.root, address); m.par = this; m.prop_name = schema_name; m.MUTATION_ID = this.MUTATION_ID; this.prop_array[index] = m; } return this.getHook(schema_name, m); } }); }
[ "function", "CreateModelProperty", "(", "object", ",", "model", ",", "schema_name", ",", "index", ")", "{", "Object", ".", "defineProperty", "(", "object", ",", "schema_name", ",", "{", "configurable", ":", "false", ",", "enumerable", ":", "true", ",", "get", ":", "function", "(", ")", "{", "let", "m", "=", "this", ".", "prop_array", "[", "index", "]", ";", "if", "(", "!", "m", ")", "{", "let", "address", "=", "this", ".", "address", ".", "slice", "(", ")", ";", "address", ".", "push", "(", "index", ")", ";", "m", "=", "new", "model", "(", "null", ",", "this", ".", "root", ",", "address", ")", ";", "m", ".", "par", "=", "this", ";", "m", ".", "prop_name", "=", "schema_name", ";", "m", ".", "MUTATION_ID", "=", "this", ".", "MUTATION_ID", ";", "this", ".", "prop_array", "[", "index", "]", "=", "m", ";", "}", "return", "this", ".", "getHook", "(", "schema_name", ",", "m", ")", ";", "}", "}", ")", ";", "}" ]
This is used by Model to create custom property getter and setters on Model properties of the Model constructor. @protected @memberof module:wick~internals.model
[ "This", "is", "used", "by", "Model", "to", "create", "custom", "property", "getter", "and", "setters", "on", "Model", "properties", "of", "the", "Model", "constructor", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L3660-L3682
39,571
CandleFW/wick
build/wick.node.js
function(node = this.fch) { if (node && node.nxt != this.fch && this.fch) return node.nxt; return null; }
javascript
function(node = this.fch) { if (node && node.nxt != this.fch && this.fch) return node.nxt; return null; }
[ "function", "(", "node", "=", "this", ".", "fch", ")", "{", "if", "(", "node", "&&", "node", ".", "nxt", "!=", "this", ".", "fch", "&&", "this", ".", "fch", ")", "return", "node", ".", "nxt", ";", "return", "null", ";", "}" ]
Gets the next node. @param {HTMLNode} node The node to get the sibling of. @return {HTMLNode | TextNode | undefined}
[ "Gets", "the", "next", "node", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L4881-L4885
39,572
CandleFW/wick
build/wick.node.js
function(index, node = this.fch) { if(node.par !== this) node = this.fch; let first = node; let i = 0; while (node && node != first) { if (i++ == index) return node; node = node.nxt; } return null; }
javascript
function(index, node = this.fch) { if(node.par !== this) node = this.fch; let first = node; let i = 0; while (node && node != first) { if (i++ == index) return node; node = node.nxt; } return null; }
[ "function", "(", "index", ",", "node", "=", "this", ".", "fch", ")", "{", "if", "(", "node", ".", "par", "!==", "this", ")", "node", "=", "this", ".", "fch", ";", "let", "first", "=", "node", ";", "let", "i", "=", "0", ";", "while", "(", "node", "&&", "node", "!=", "first", ")", "{", "if", "(", "i", "++", "==", "index", ")", "return", "node", ";", "node", "=", "node", ".", "nxt", ";", "}", "return", "null", ";", "}" ]
Gets the child at index. @param {number} index The index
[ "Gets", "the", "child", "at", "index", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L4892-L4905
39,573
CandleFW/wick
build/wick.node.js
JSExpressionIdentifiers
function JSExpressionIdentifiers(lex) { let _identifiers_ = []; let model_cache = {}; let IN_OBJ = false, CAN_BE_ID = true; while (!lex.END) { switch (lex.ty) { case lex.types.id: if (!IN_OBJ || CAN_BE_ID) { let id = lex.tx; if (!model_cache[id]) { _identifiers_.push(lex.tx); model_cache[id] = true; } } break; case lex.types.op: case lex.types.sym: case lex.types.ob: case lex.types.cb: switch (lex.ch) { case "+": case ">": case "<": case "/": case "*": case "-": CAN_BE_ID = true; break; case "[": IN_OBJ = false; CAN_BE_ID = true; break; case "{": case ".": //Property Getters CAN_BE_ID = false; IN_OBJ = true; break; case "]": case ";": case "=": case "}": case "(": IN_OBJ = false; break; case ",": if (IN_OBJ) CAN_BE_ID = false; else IN_OBJ = false; break; case ":": case "=": CAN_BE_ID = true; } break; } lex.n; } return _identifiers_; }
javascript
function JSExpressionIdentifiers(lex) { let _identifiers_ = []; let model_cache = {}; let IN_OBJ = false, CAN_BE_ID = true; while (!lex.END) { switch (lex.ty) { case lex.types.id: if (!IN_OBJ || CAN_BE_ID) { let id = lex.tx; if (!model_cache[id]) { _identifiers_.push(lex.tx); model_cache[id] = true; } } break; case lex.types.op: case lex.types.sym: case lex.types.ob: case lex.types.cb: switch (lex.ch) { case "+": case ">": case "<": case "/": case "*": case "-": CAN_BE_ID = true; break; case "[": IN_OBJ = false; CAN_BE_ID = true; break; case "{": case ".": //Property Getters CAN_BE_ID = false; IN_OBJ = true; break; case "]": case ";": case "=": case "}": case "(": IN_OBJ = false; break; case ",": if (IN_OBJ) CAN_BE_ID = false; else IN_OBJ = false; break; case ":": case "=": CAN_BE_ID = true; } break; } lex.n; } return _identifiers_; }
[ "function", "JSExpressionIdentifiers", "(", "lex", ")", "{", "let", "_identifiers_", "=", "[", "]", ";", "let", "model_cache", "=", "{", "}", ";", "let", "IN_OBJ", "=", "false", ",", "CAN_BE_ID", "=", "true", ";", "while", "(", "!", "lex", ".", "END", ")", "{", "switch", "(", "lex", ".", "ty", ")", "{", "case", "lex", ".", "types", ".", "id", ":", "if", "(", "!", "IN_OBJ", "||", "CAN_BE_ID", ")", "{", "let", "id", "=", "lex", ".", "tx", ";", "if", "(", "!", "model_cache", "[", "id", "]", ")", "{", "_identifiers_", ".", "push", "(", "lex", ".", "tx", ")", ";", "model_cache", "[", "id", "]", "=", "true", ";", "}", "}", "break", ";", "case", "lex", ".", "types", ".", "op", ":", "case", "lex", ".", "types", ".", "sym", ":", "case", "lex", ".", "types", ".", "ob", ":", "case", "lex", ".", "types", ".", "cb", ":", "switch", "(", "lex", ".", "ch", ")", "{", "case", "\"+\"", ":", "case", "\">\"", ":", "case", "\"<\"", ":", "case", "\"/\"", ":", "case", "\"*\"", ":", "case", "\"-\"", ":", "CAN_BE_ID", "=", "true", ";", "break", ";", "case", "\"[\"", ":", "IN_OBJ", "=", "false", ";", "CAN_BE_ID", "=", "true", ";", "break", ";", "case", "\"{\"", ":", "case", "\".\"", ":", "//Property Getters", "CAN_BE_ID", "=", "false", ";", "IN_OBJ", "=", "true", ";", "break", ";", "case", "\"]\"", ":", "case", "\";\"", ":", "case", "\"=\"", ":", "case", "\"}\"", ":", "case", "\"(\"", ":", "IN_OBJ", "=", "false", ";", "break", ";", "case", "\",\"", ":", "if", "(", "IN_OBJ", ")", "CAN_BE_ID", "=", "false", ";", "else", "IN_OBJ", "=", "false", ";", "break", ";", "case", "\":\"", ":", "case", "\"=\"", ":", "CAN_BE_ID", "=", "true", ";", "}", "break", ";", "}", "lex", ".", "n", ";", "}", "return", "_identifiers_", ";", "}" ]
Basic JS Parser Kludge to get legitimate foreign identifiers from expressions. This could later be expanded into a full JS parser to generate proper JS ASTs. @class JSExpressionIdentifiers @param {Lexer} lex The lex @return {Object} { description_of_the_return_value }
[ "Basic", "JS", "Parser", "Kludge", "to", "get", "legitimate", "foreign", "identifiers", "from", "expressions", ".", "This", "could", "later", "be", "expanded", "into", "a", "full", "JS", "parser", "to", "generate", "proper", "JS", "ASTs", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L10247-L10311
39,574
CandleFW/wick
build/wick.node.js
TransformTo
function TransformTo(element_from, element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER) { let rect = element_from.getBoundingClientRect(); let cs = window.getComputedStyle(element_from, null); let margin_left = parseFloat(cs.getPropertyValue("margin")); let seq = Animation.createSequence({ obj: element_from, width: { value: "0px"}, height: { value: "0px"}, backgroundColor: { value: "rgb(1,1,1)"}, left: [{value:rect.left+"px"},{ value: "0px"}], top: [{value:rect.top+"px"},{ value: "0px"}] }); if (!element_to) { let a = (seq) => (element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER = false) => { setTo(element_to, seq, duration, easing); seq.duration = duration; return seq; }; return a(seq); } setTo(element_to, duration, easing); seq.duration = duration; return seq; }
javascript
function TransformTo(element_from, element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER) { let rect = element_from.getBoundingClientRect(); let cs = window.getComputedStyle(element_from, null); let margin_left = parseFloat(cs.getPropertyValue("margin")); let seq = Animation.createSequence({ obj: element_from, width: { value: "0px"}, height: { value: "0px"}, backgroundColor: { value: "rgb(1,1,1)"}, left: [{value:rect.left+"px"},{ value: "0px"}], top: [{value:rect.top+"px"},{ value: "0px"}] }); if (!element_to) { let a = (seq) => (element_to, duration = 500, easing = Animation.easing.linear, HIDE_OTHER = false) => { setTo(element_to, seq, duration, easing); seq.duration = duration; return seq; }; return a(seq); } setTo(element_to, duration, easing); seq.duration = duration; return seq; }
[ "function", "TransformTo", "(", "element_from", ",", "element_to", ",", "duration", "=", "500", ",", "easing", "=", "Animation", ".", "easing", ".", "linear", ",", "HIDE_OTHER", ")", "{", "let", "rect", "=", "element_from", ".", "getBoundingClientRect", "(", ")", ";", "let", "cs", "=", "window", ".", "getComputedStyle", "(", "element_from", ",", "null", ")", ";", "let", "margin_left", "=", "parseFloat", "(", "cs", ".", "getPropertyValue", "(", "\"margin\"", ")", ")", ";", "let", "seq", "=", "Animation", ".", "createSequence", "(", "{", "obj", ":", "element_from", ",", "width", ":", "{", "value", ":", "\"0px\"", "}", ",", "height", ":", "{", "value", ":", "\"0px\"", "}", ",", "backgroundColor", ":", "{", "value", ":", "\"rgb(1,1,1)\"", "}", ",", "left", ":", "[", "{", "value", ":", "rect", ".", "left", "+", "\"px\"", "}", ",", "{", "value", ":", "\"0px\"", "}", "]", ",", "top", ":", "[", "{", "value", ":", "rect", ".", "top", "+", "\"px\"", "}", ",", "{", "value", ":", "\"0px\"", "}", "]", "}", ")", ";", "if", "(", "!", "element_to", ")", "{", "let", "a", "=", "(", "seq", ")", "=>", "(", "element_to", ",", "duration", "=", "500", ",", "easing", "=", "Animation", ".", "easing", ".", "linear", ",", "HIDE_OTHER", "=", "false", ")", "=>", "{", "setTo", "(", "element_to", ",", "seq", ",", "duration", ",", "easing", ")", ";", "seq", ".", "duration", "=", "duration", ";", "return", "seq", ";", "}", ";", "return", "a", "(", "seq", ")", ";", "}", "setTo", "(", "element_to", ",", "duration", ",", "easing", ")", ";", "seq", ".", "duration", "=", "duration", ";", "return", "seq", ";", "}" ]
Transform one element from another back to itself @alias module:wick~internals.TransformTo
[ "Transform", "one", "element", "from", "another", "back", "to", "itself" ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L11928-L11956
39,575
CandleFW/wick
build/wick.node.js
CreateHTMLNode
function CreateHTMLNode(tag) { //jump table. switch (tag[0]) { case "w": switch (tag) { case "w-s": return new SourceNode$1(); //This node is used to case "w-c": return new SourceTemplateNode$1(); //This node is used to } break; default: switch (tag) { case "a": return new LinkNode$1(); /** void elements **/ case "template": return new VoidNode$1(); case "style": return new StyleNode$1(); case "script": return new ScriptNode$1(); case "svg": case "path": return new SVGNode(); } } return new RootNode(); }
javascript
function CreateHTMLNode(tag) { //jump table. switch (tag[0]) { case "w": switch (tag) { case "w-s": return new SourceNode$1(); //This node is used to case "w-c": return new SourceTemplateNode$1(); //This node is used to } break; default: switch (tag) { case "a": return new LinkNode$1(); /** void elements **/ case "template": return new VoidNode$1(); case "style": return new StyleNode$1(); case "script": return new ScriptNode$1(); case "svg": case "path": return new SVGNode(); } } return new RootNode(); }
[ "function", "CreateHTMLNode", "(", "tag", ")", "{", "//jump table.", "switch", "(", "tag", "[", "0", "]", ")", "{", "case", "\"w\"", ":", "switch", "(", "tag", ")", "{", "case", "\"w-s\"", ":", "return", "new", "SourceNode$1", "(", ")", ";", "//This node is used to ", "case", "\"w-c\"", ":", "return", "new", "SourceTemplateNode$1", "(", ")", ";", "//This node is used to ", "}", "break", ";", "default", ":", "switch", "(", "tag", ")", "{", "case", "\"a\"", ":", "return", "new", "LinkNode$1", "(", ")", ";", "/** void elements **/", "case", "\"template\"", ":", "return", "new", "VoidNode$1", "(", ")", ";", "case", "\"style\"", ":", "return", "new", "StyleNode$1", "(", ")", ";", "case", "\"script\"", ":", "return", "new", "ScriptNode$1", "(", ")", ";", "case", "\"svg\"", ":", "case", "\"path\"", ":", "return", "new", "SVGNode", "(", ")", ";", "}", "}", "return", "new", "RootNode", "(", ")", ";", "}" ]
Since all nodes extend the RootNode, this needs to be declared here to prevent module cycles.
[ "Since", "all", "nodes", "extend", "the", "RootNode", "this", "needs", "to", "be", "declared", "here", "to", "prevent", "module", "cycles", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L13092-L13121
39,576
CandleFW/wick
build/wick.node.js
CompileSource
function CompileSource(SourcePackage, presets, element, url, win = window) { let lex; if (element instanceof whind$1.constructor) { lex = element; } else if (typeof(element) == "string") lex = whind$1(element); else if (element instanceof EL) { if (element.tagName == "TEMPLATE") { let temp = document.createElement("div"); temp.appendChild(element.content); element = temp; } lex = whind$1(element.innerHTML); } else { let e = new Error("Cannot compile component"); SourcePackage._addError_(e); SourcePackage._complete_(); } return parseText(lex, SourcePackage, presets, url, win); }
javascript
function CompileSource(SourcePackage, presets, element, url, win = window) { let lex; if (element instanceof whind$1.constructor) { lex = element; } else if (typeof(element) == "string") lex = whind$1(element); else if (element instanceof EL) { if (element.tagName == "TEMPLATE") { let temp = document.createElement("div"); temp.appendChild(element.content); element = temp; } lex = whind$1(element.innerHTML); } else { let e = new Error("Cannot compile component"); SourcePackage._addError_(e); SourcePackage._complete_(); } return parseText(lex, SourcePackage, presets, url, win); }
[ "function", "CompileSource", "(", "SourcePackage", ",", "presets", ",", "element", ",", "url", ",", "win", "=", "window", ")", "{", "let", "lex", ";", "if", "(", "element", "instanceof", "whind$1", ".", "constructor", ")", "{", "lex", "=", "element", ";", "}", "else", "if", "(", "typeof", "(", "element", ")", "==", "\"string\"", ")", "lex", "=", "whind$1", "(", "element", ")", ";", "else", "if", "(", "element", "instanceof", "EL", ")", "{", "if", "(", "element", ".", "tagName", "==", "\"TEMPLATE\"", ")", "{", "let", "temp", "=", "document", ".", "createElement", "(", "\"div\"", ")", ";", "temp", ".", "appendChild", "(", "element", ".", "content", ")", ";", "element", "=", "temp", ";", "}", "lex", "=", "whind$1", "(", "element", ".", "innerHTML", ")", ";", "}", "else", "{", "let", "e", "=", "new", "Error", "(", "\"Cannot compile component\"", ")", ";", "SourcePackage", ".", "_addError_", "(", "e", ")", ";", "SourcePackage", ".", "_complete_", "(", ")", ";", "}", "return", "parseText", "(", "lex", ",", "SourcePackage", ",", "presets", ",", "url", ",", "win", ")", ";", "}" ]
Compiles an object graph based input into a SourcePackage. @param {SourcePackage} SourcePackage The source package @param {Presets} presets The global Presets instance @param {HTMLElement | Lexer | string} element The element @memberof module:wick~internals.templateCompiler @alias CompileSource
[ "Compiles", "an", "object", "graph", "based", "input", "into", "a", "SourcePackage", "." ]
139861e3696598db5b1e5c809ce36691ae61c633
https://github.com/CandleFW/wick/blob/139861e3696598db5b1e5c809ce36691ae61c633/build/wick.node.js#L13267-L13286
39,577
wikimedia/web-html-stream
lib/cssSelectorParser.js
parseCSSSelector
function parseCSSSelector(selector) { const match = SELECTOR_RE.exec(selector); if (!match) { throw new Error("Unsupported or invalid CSS selector: " + selector); } const res = { nodeName: match[1].trim() }; if (match[2]) { const attr = [match[2]]; if (match[3]) { attr.push(match[3]); } // Decode the attribute value if(match[4]) { attr.push(match[4].replace(/\\([nrtf"\\])/g, function(_, k) { return valueDecodeTable[k]; })); } res.attributes = [attr]; } return res; }
javascript
function parseCSSSelector(selector) { const match = SELECTOR_RE.exec(selector); if (!match) { throw new Error("Unsupported or invalid CSS selector: " + selector); } const res = { nodeName: match[1].trim() }; if (match[2]) { const attr = [match[2]]; if (match[3]) { attr.push(match[3]); } // Decode the attribute value if(match[4]) { attr.push(match[4].replace(/\\([nrtf"\\])/g, function(_, k) { return valueDecodeTable[k]; })); } res.attributes = [attr]; } return res; }
[ "function", "parseCSSSelector", "(", "selector", ")", "{", "const", "match", "=", "SELECTOR_RE", ".", "exec", "(", "selector", ")", ";", "if", "(", "!", "match", ")", "{", "throw", "new", "Error", "(", "\"Unsupported or invalid CSS selector: \"", "+", "selector", ")", ";", "}", "const", "res", "=", "{", "nodeName", ":", "match", "[", "1", "]", ".", "trim", "(", ")", "}", ";", "if", "(", "match", "[", "2", "]", ")", "{", "const", "attr", "=", "[", "match", "[", "2", "]", "]", ";", "if", "(", "match", "[", "3", "]", ")", "{", "attr", ".", "push", "(", "match", "[", "3", "]", ")", ";", "}", "// Decode the attribute value", "if", "(", "match", "[", "4", "]", ")", "{", "attr", ".", "push", "(", "match", "[", "4", "]", ".", "replace", "(", "/", "\\\\([nrtf\"\\\\])", "/", "g", ",", "function", "(", "_", ",", "k", ")", "{", "return", "valueDecodeTable", "[", "k", "]", ";", "}", ")", ")", ";", "}", "res", ".", "attributes", "=", "[", "attr", "]", ";", "}", "return", "res", ";", "}" ]
Simple CSS selector parser. Limitations: - Only supports single attribute selector.
[ "Simple", "CSS", "selector", "parser", "." ]
21a42a0dc6769dfbb8e9430ae41c323512bb762b
https://github.com/wikimedia/web-html-stream/blob/21a42a0dc6769dfbb8e9430ae41c323512bb762b/lib/cssSelectorParser.js#L21-L39
39,578
patrick-steele-idem/events-light
src/index.js
function(type, listener) { checkListener(listener); var events = this.$e; var listeners; if (events && (listeners = events[type])) { if (isFunction(listeners)) { if (listeners === listener) { delete events[type]; } } else { for (var i=listeners.length-1; i>=0; i--) { if (listeners[i] === listener) { listeners.splice(i, 1); } } } } return this; }
javascript
function(type, listener) { checkListener(listener); var events = this.$e; var listeners; if (events && (listeners = events[type])) { if (isFunction(listeners)) { if (listeners === listener) { delete events[type]; } } else { for (var i=listeners.length-1; i>=0; i--) { if (listeners[i] === listener) { listeners.splice(i, 1); } } } } return this; }
[ "function", "(", "type", ",", "listener", ")", "{", "checkListener", "(", "listener", ")", ";", "var", "events", "=", "this", ".", "$e", ";", "var", "listeners", ";", "if", "(", "events", "&&", "(", "listeners", "=", "events", "[", "type", "]", ")", ")", "{", "if", "(", "isFunction", "(", "listeners", ")", ")", "{", "if", "(", "listeners", "===", "listener", ")", "{", "delete", "events", "[", "type", "]", ";", "}", "}", "else", "{", "for", "(", "var", "i", "=", "listeners", ".", "length", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "if", "(", "listeners", "[", "i", "]", "===", "listener", ")", "{", "listeners", ".", "splice", "(", "i", ",", "1", ")", ";", "}", "}", "}", "}", "return", "this", ";", "}" ]
emits a 'removeListener' event iff the listener was removed
[ "emits", "a", "removeListener", "event", "iff", "the", "listener", "was", "removed" ]
eb1081346caf33f0f4c6f66e2d988984d379d40c
https://github.com/patrick-steele-idem/events-light/blob/eb1081346caf33f0f4c6f66e2d988984d379d40c/src/index.js#L129-L150
39,579
imwtr/find-free-port-sync
find-free-port-sync.js
FindFreePortSync
function FindFreePortSync(options = {}) { this.defaultOptions = { // port start for scan start: 1, // port end for scan end: 65534, // ports number for scan num: 1, // specify ip for scan ip: '0.0.0.0|127.0.0.1', // for inner usage, some platforms like darkwin shows commom address 0.0.0.0:10000 as *.10000 _ipSpecial: '\\*|127.0.0.1', // scan this port port: null }; this.msg = { error: 'Cannot find free port' } this.adjustOptions(options); }
javascript
function FindFreePortSync(options = {}) { this.defaultOptions = { // port start for scan start: 1, // port end for scan end: 65534, // ports number for scan num: 1, // specify ip for scan ip: '0.0.0.0|127.0.0.1', // for inner usage, some platforms like darkwin shows commom address 0.0.0.0:10000 as *.10000 _ipSpecial: '\\*|127.0.0.1', // scan this port port: null }; this.msg = { error: 'Cannot find free port' } this.adjustOptions(options); }
[ "function", "FindFreePortSync", "(", "options", "=", "{", "}", ")", "{", "this", ".", "defaultOptions", "=", "{", "// port start for scan", "start", ":", "1", ",", "// port end for scan", "end", ":", "65534", ",", "// ports number for scan", "num", ":", "1", ",", "// specify ip for scan", "ip", ":", "'0.0.0.0|127.0.0.1'", ",", "// for inner usage, some platforms like darkwin shows commom address 0.0.0.0:10000 as *.10000", "_ipSpecial", ":", "'\\\\*|127.0.0.1'", ",", "// scan this port", "port", ":", "null", "}", ";", "this", ".", "msg", "=", "{", "error", ":", "'Cannot find free port'", "}", "this", ".", "adjustOptions", "(", "options", ")", ";", "}" ]
Finding free port synchronously @param {Object} options [description]
[ "Finding", "free", "port", "synchronously" ]
6eb36867d80072cf4b20b1d5a878ab02170b6198
https://github.com/imwtr/find-free-port-sync/blob/6eb36867d80072cf4b20b1d5a878ab02170b6198/find-free-port-sync.js#L8-L29
39,580
base/base-generators
index.js
function(name, val, options) { debug('.generator', name, val); if (this.hasGenerator(name)) { return this.getGenerator(name); } this.setGenerator.apply(this, arguments); return this.getGenerator(name); }
javascript
function(name, val, options) { debug('.generator', name, val); if (this.hasGenerator(name)) { return this.getGenerator(name); } this.setGenerator.apply(this, arguments); return this.getGenerator(name); }
[ "function", "(", "name", ",", "val", ",", "options", ")", "{", "debug", "(", "'.generator'", ",", "name", ",", "val", ")", ";", "if", "(", "this", ".", "hasGenerator", "(", "name", ")", ")", "{", "return", "this", ".", "getGenerator", "(", "name", ")", ";", "}", "this", ".", "setGenerator", ".", "apply", "(", "this", ",", "arguments", ")", ";", "return", "this", ".", "getGenerator", "(", "name", ")", ";", "}" ]
Get and invoke generator `name`, or register generator `name` with the given `val` and `options`, then invoke and return the generator instance. This method differs from `.register`, which lazily invokes generator functions when `.generate` is called. ```js app.generator('foo', function(app, base, env, options) { // "app" - private instance created for generator "foo" // "base" - instance shared by all generators // "env" - environment object for the generator // "options" - options passed to the generator }); ``` @name .generator @param {String} `name` @param {Function|Object} `fn` Generator function, instance or filepath. @return {Object} Returns the generator instance or undefined if not resolved. @api public
[ "Get", "and", "invoke", "generator", "name", "or", "register", "generator", "name", "with", "the", "given", "val", "and", "options", "then", "invoke", "and", "return", "the", "generator", "instance", ".", "This", "method", "differs", "from", ".", "register", "which", "lazily", "invokes", "generator", "functions", "when", ".", "generate", "is", "called", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L85-L94
39,581
base/base-generators
index.js
function(name, val, options) { debug('.setGenerator', name); if (this.hasGenerator(name)) { return this.findGenerator(name); } // ensure local sub-generator paths are resolved if (typeof val === 'string' && val.charAt(0) === '.' && this.env) { val = path.resolve(this.env.dirname, val); } return generator(name, val, options, this); }
javascript
function(name, val, options) { debug('.setGenerator', name); if (this.hasGenerator(name)) { return this.findGenerator(name); } // ensure local sub-generator paths are resolved if (typeof val === 'string' && val.charAt(0) === '.' && this.env) { val = path.resolve(this.env.dirname, val); } return generator(name, val, options, this); }
[ "function", "(", "name", ",", "val", ",", "options", ")", "{", "debug", "(", "'.setGenerator'", ",", "name", ")", ";", "if", "(", "this", ".", "hasGenerator", "(", "name", ")", ")", "{", "return", "this", ".", "findGenerator", "(", "name", ")", ";", "}", "// ensure local sub-generator paths are resolved", "if", "(", "typeof", "val", "===", "'string'", "&&", "val", ".", "charAt", "(", "0", ")", "===", "'.'", "&&", "this", ".", "env", ")", "{", "val", "=", "path", ".", "resolve", "(", "this", ".", "env", ".", "dirname", ",", "val", ")", ";", "}", "return", "generator", "(", "name", ",", "val", ",", "options", ",", "this", ")", ";", "}" ]
Store a generator by file path or instance with the given `name` and `options`. ```js app.setGenerator('foo', function(app, base) { // "app" - private instance created for generator "foo" // "base" - instance shared by all generators // "env" - environment object for the generator // "options" - options passed to the generator }); ``` @name .setGenerator @param {String} `name` The generator's name @param {Object|Function|String} `options` or generator @param {Object|Function|String} `generator` Generator function, instance or filepath. @return {Object} Returns the generator instance. @api public
[ "Store", "a", "generator", "by", "file", "path", "or", "instance", "with", "the", "given", "name", "and", "options", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L116-L129
39,582
base/base-generators
index.js
fn
function fn(name, options) { debug('.findGenerator', name); if (utils.isObject(name)) { return name; } if (Array.isArray(name)) { name = name.join('.'); } if (typeof name !== 'string') { throw new TypeError('expected name to be a string'); } if (cache.hasOwnProperty(name)) { return cache[name]; } var app = this.generators[name] || this.base.generators[name] || this._findGenerator(name, options); // if no app, check the `base` instance if (typeof app === 'undefined' && this.hasOwnProperty('parent')) { app = this.base._findGenerator(name, options); } if (app) { cache[app.name] = app; cache[app.alias] = app; cache[name] = app; return app; } var search = {name, options}; this.base.emit('unresolved', search, this); if (search.app) { cache[search.app.name] = search.app; cache[search.app.alias] = search.app; return search.app; } cache[name] = null; }
javascript
function fn(name, options) { debug('.findGenerator', name); if (utils.isObject(name)) { return name; } if (Array.isArray(name)) { name = name.join('.'); } if (typeof name !== 'string') { throw new TypeError('expected name to be a string'); } if (cache.hasOwnProperty(name)) { return cache[name]; } var app = this.generators[name] || this.base.generators[name] || this._findGenerator(name, options); // if no app, check the `base` instance if (typeof app === 'undefined' && this.hasOwnProperty('parent')) { app = this.base._findGenerator(name, options); } if (app) { cache[app.name] = app; cache[app.alias] = app; cache[name] = app; return app; } var search = {name, options}; this.base.emit('unresolved', search, this); if (search.app) { cache[search.app.name] = search.app; cache[search.app.alias] = search.app; return search.app; } cache[name] = null; }
[ "function", "fn", "(", "name", ",", "options", ")", "{", "debug", "(", "'.findGenerator'", ",", "name", ")", ";", "if", "(", "utils", ".", "isObject", "(", "name", ")", ")", "{", "return", "name", ";", "}", "if", "(", "Array", ".", "isArray", "(", "name", ")", ")", "{", "name", "=", "name", ".", "join", "(", "'.'", ")", ";", "}", "if", "(", "typeof", "name", "!==", "'string'", ")", "{", "throw", "new", "TypeError", "(", "'expected name to be a string'", ")", ";", "}", "if", "(", "cache", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "return", "cache", "[", "name", "]", ";", "}", "var", "app", "=", "this", ".", "generators", "[", "name", "]", "||", "this", ".", "base", ".", "generators", "[", "name", "]", "||", "this", ".", "_findGenerator", "(", "name", ",", "options", ")", ";", "// if no app, check the `base` instance", "if", "(", "typeof", "app", "===", "'undefined'", "&&", "this", ".", "hasOwnProperty", "(", "'parent'", ")", ")", "{", "app", "=", "this", ".", "base", ".", "_findGenerator", "(", "name", ",", "options", ")", ";", "}", "if", "(", "app", ")", "{", "cache", "[", "app", ".", "name", "]", "=", "app", ";", "cache", "[", "app", ".", "alias", "]", "=", "app", ";", "cache", "[", "name", "]", "=", "app", ";", "return", "app", ";", "}", "var", "search", "=", "{", "name", ",", "options", "}", ";", "this", ".", "base", ".", "emit", "(", "'unresolved'", ",", "search", ",", "this", ")", ";", "if", "(", "search", ".", "app", ")", "{", "cache", "[", "search", ".", "app", ".", "name", "]", "=", "search", ".", "app", ";", "cache", "[", "search", ".", "app", ".", "alias", "]", "=", "search", ".", "app", ";", "return", "search", ".", "app", ";", "}", "cache", "[", "name", "]", "=", "null", ";", "}" ]
Find generator `name`, by first searching the cache, then searching the cache of the `base` generator. Use this to get a generator without invoking it. ```js // search by "alias" var foo = app.findGenerator('foo'); // search by "full name" var foo = app.findGenerator('generate-foo'); ``` @name .findGenerator @param {String} `name` @param {Function} `options` Optionally supply a rename function on `options.toAlias` @return {Object|undefined} Returns the generator instance if found, or undefined. @api public
[ "Find", "generator", "name", "by", "first", "searching", "the", "cache", "then", "searching", "the", "cache", "of", "the", "base", "generator", ".", "Use", "this", "to", "get", "a", "generator", "without", "invoking", "it", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L179-L222
39,583
base/base-generators
index.js
function(name, options) { if (this.generators.hasOwnProperty(name)) { return this.generators[name]; } if (~name.indexOf('.')) { return this.getSubGenerator.apply(this, arguments); } var opts = utils.extend({}, this.options, options); if (typeof opts.lookup === 'function') { var app = this.lookupGenerator(name, opts, opts.lookup); if (app) { return app; } } return this.matchGenerator(name); }
javascript
function(name, options) { if (this.generators.hasOwnProperty(name)) { return this.generators[name]; } if (~name.indexOf('.')) { return this.getSubGenerator.apply(this, arguments); } var opts = utils.extend({}, this.options, options); if (typeof opts.lookup === 'function') { var app = this.lookupGenerator(name, opts, opts.lookup); if (app) { return app; } } return this.matchGenerator(name); }
[ "function", "(", "name", ",", "options", ")", "{", "if", "(", "this", ".", "generators", ".", "hasOwnProperty", "(", "name", ")", ")", "{", "return", "this", ".", "generators", "[", "name", "]", ";", "}", "if", "(", "~", "name", ".", "indexOf", "(", "'.'", ")", ")", "{", "return", "this", ".", "getSubGenerator", ".", "apply", "(", "this", ",", "arguments", ")", ";", "}", "var", "opts", "=", "utils", ".", "extend", "(", "{", "}", ",", "this", ".", "options", ",", "options", ")", ";", "if", "(", "typeof", "opts", ".", "lookup", "===", "'function'", ")", "{", "var", "app", "=", "this", ".", "lookupGenerator", "(", "name", ",", "opts", ",", "opts", ".", "lookup", ")", ";", "if", "(", "app", ")", "{", "return", "app", ";", "}", "}", "return", "this", ".", "matchGenerator", "(", "name", ")", ";", "}" ]
Private method used by `.findGenerator`.
[ "Private", "method", "used", "by", ".", "findGenerator", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L228-L245
39,584
base/base-generators
index.js
function(name, options) { debug('.getSubGenerator', name); var segs = name.split('.'); var len = segs.length; var idx = -1; var app = this; while (++idx < len) { var key = segs[idx]; app = app.getGenerator(key, options); if (!app) { break; } } return app; }
javascript
function(name, options) { debug('.getSubGenerator', name); var segs = name.split('.'); var len = segs.length; var idx = -1; var app = this; while (++idx < len) { var key = segs[idx]; app = app.getGenerator(key, options); if (!app) { break; } } return app; }
[ "function", "(", "name", ",", "options", ")", "{", "debug", "(", "'.getSubGenerator'", ",", "name", ")", ";", "var", "segs", "=", "name", ".", "split", "(", "'.'", ")", ";", "var", "len", "=", "segs", ".", "length", ";", "var", "idx", "=", "-", "1", ";", "var", "app", "=", "this", ";", "while", "(", "++", "idx", "<", "len", ")", "{", "var", "key", "=", "segs", "[", "idx", "]", ";", "app", "=", "app", ".", "getGenerator", "(", "key", ",", "options", ")", ";", "if", "(", "!", "app", ")", "{", "break", ";", "}", "}", "return", "app", ";", "}" ]
Get sub-generator `name`, optionally using dot-notation for nested generators. ```js app.getSubGenerator('foo.bar.baz'); ``` @name .getSubGenerator @param {String} `name` The property-path of the generator to get @param {Object} `options` @api public
[ "Get", "sub", "-", "generator", "name", "optionally", "using", "dot", "-", "notation", "for", "nested", "generators", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L259-L274
39,585
base/base-generators
index.js
function(name, options, fn) { debug('.lookupGenerator', name); if (typeof options === 'function') { fn = options; options = {}; } if (typeof fn !== 'function') { throw new TypeError('expected `fn` to be a lookup function'); } options = options || {}; // remove `lookup` fn from options to prevent self-recursion delete this.options.lookup; delete options.lookup; var names = fn(name); debug('looking up generator "%s" with "%j"', name, names); var len = names.length; var idx = -1; while (++idx < len) { var gen = this.findGenerator(names[idx], options); if (gen) { this.options.lookup = fn; return gen; } } this.options.lookup = fn; }
javascript
function(name, options, fn) { debug('.lookupGenerator', name); if (typeof options === 'function') { fn = options; options = {}; } if (typeof fn !== 'function') { throw new TypeError('expected `fn` to be a lookup function'); } options = options || {}; // remove `lookup` fn from options to prevent self-recursion delete this.options.lookup; delete options.lookup; var names = fn(name); debug('looking up generator "%s" with "%j"', name, names); var len = names.length; var idx = -1; while (++idx < len) { var gen = this.findGenerator(names[idx], options); if (gen) { this.options.lookup = fn; return gen; } } this.options.lookup = fn; }
[ "function", "(", "name", ",", "options", ",", "fn", ")", "{", "debug", "(", "'.lookupGenerator'", ",", "name", ")", ";", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "fn", "=", "options", ";", "options", "=", "{", "}", ";", "}", "if", "(", "typeof", "fn", "!==", "'function'", ")", "{", "throw", "new", "TypeError", "(", "'expected `fn` to be a lookup function'", ")", ";", "}", "options", "=", "options", "||", "{", "}", ";", "// remove `lookup` fn from options to prevent self-recursion", "delete", "this", ".", "options", ".", "lookup", ";", "delete", "options", ".", "lookup", ";", "var", "names", "=", "fn", "(", "name", ")", ";", "debug", "(", "'looking up generator \"%s\" with \"%j\"'", ",", "name", ",", "names", ")", ";", "var", "len", "=", "names", ".", "length", ";", "var", "idx", "=", "-", "1", ";", "while", "(", "++", "idx", "<", "len", ")", "{", "var", "gen", "=", "this", ".", "findGenerator", "(", "names", "[", "idx", "]", ",", "options", ")", ";", "if", "(", "gen", ")", "{", "this", ".", "options", ".", "lookup", "=", "fn", ";", "return", "gen", ";", "}", "}", "this", ".", "options", ".", "lookup", "=", "fn", ";", "}" ]
Tries to find a registered generator that matches `name` by iterating over the `generators` object, and doing a strict comparison of each name returned by the given lookup `fn`. The lookup function receives `name` and must return an array of names to use for the lookup. For example, if the lookup `name` is `foo`, the function might return `["generator-foo", "foo"]`, to ensure that the lookup happens in that order. @param {String} `name` Generator name to search for @param {Object} `options` @param {Function} `fn` Lookup function that must return an array of names. @return {Object} @api public
[ "Tries", "to", "find", "a", "registered", "generator", "that", "matches", "name", "by", "iterating", "over", "the", "generators", "object", "and", "doing", "a", "strict", "comparison", "of", "each", "name", "returned", "by", "the", "given", "lookup", "fn", ".", "The", "lookup", "function", "receives", "name", "and", "must", "return", "an", "array", "of", "names", "to", "use", "for", "the", "lookup", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L329-L361
39,586
base/base-generators
index.js
function(name, options) { if (typeof name === 'function') { this.use(name, options); return this; } if (Array.isArray(name)) { var len = name.length; var idx = -1; while (++idx < len) { this.extendWith(name[idx], options); } return this; } var app = name; if (typeof name === 'string') { app = this.generators[name] || this.findGenerator(name, options); if (!app && utils.exists(name)) { var fn = utils.tryRequire(name, this.cwd); if (typeof fn === 'function') { app = this.register(name, fn); } } } if (!utils.isValidInstance(app)) { throw new Error('cannot find generator: "' + name + '"'); } var alias = app.env ? app.env.alias : 'default'; debug('extending "%s" with "%s"', alias, name); app.run(this); app.invoke(options, this); return this; }
javascript
function(name, options) { if (typeof name === 'function') { this.use(name, options); return this; } if (Array.isArray(name)) { var len = name.length; var idx = -1; while (++idx < len) { this.extendWith(name[idx], options); } return this; } var app = name; if (typeof name === 'string') { app = this.generators[name] || this.findGenerator(name, options); if (!app && utils.exists(name)) { var fn = utils.tryRequire(name, this.cwd); if (typeof fn === 'function') { app = this.register(name, fn); } } } if (!utils.isValidInstance(app)) { throw new Error('cannot find generator: "' + name + '"'); } var alias = app.env ? app.env.alias : 'default'; debug('extending "%s" with "%s"', alias, name); app.run(this); app.invoke(options, this); return this; }
[ "function", "(", "name", ",", "options", ")", "{", "if", "(", "typeof", "name", "===", "'function'", ")", "{", "this", ".", "use", "(", "name", ",", "options", ")", ";", "return", "this", ";", "}", "if", "(", "Array", ".", "isArray", "(", "name", ")", ")", "{", "var", "len", "=", "name", ".", "length", ";", "var", "idx", "=", "-", "1", ";", "while", "(", "++", "idx", "<", "len", ")", "{", "this", ".", "extendWith", "(", "name", "[", "idx", "]", ",", "options", ")", ";", "}", "return", "this", ";", "}", "var", "app", "=", "name", ";", "if", "(", "typeof", "name", "===", "'string'", ")", "{", "app", "=", "this", ".", "generators", "[", "name", "]", "||", "this", ".", "findGenerator", "(", "name", ",", "options", ")", ";", "if", "(", "!", "app", "&&", "utils", ".", "exists", "(", "name", ")", ")", "{", "var", "fn", "=", "utils", ".", "tryRequire", "(", "name", ",", "this", ".", "cwd", ")", ";", "if", "(", "typeof", "fn", "===", "'function'", ")", "{", "app", "=", "this", ".", "register", "(", "name", ",", "fn", ")", ";", "}", "}", "}", "if", "(", "!", "utils", ".", "isValidInstance", "(", "app", ")", ")", "{", "throw", "new", "Error", "(", "'cannot find generator: \"'", "+", "name", "+", "'\"'", ")", ";", "}", "var", "alias", "=", "app", ".", "env", "?", "app", ".", "env", ".", "alias", ":", "'default'", ";", "debug", "(", "'extending \"%s\" with \"%s\"'", ",", "alias", ",", "name", ")", ";", "app", ".", "run", "(", "this", ")", ";", "app", ".", "invoke", "(", "options", ",", "this", ")", ";", "return", "this", ";", "}" ]
Extend the generator instance with settings and features of another generator. ```js var foo = base.generator('foo'); app.extendWith(foo); // or app.extendWith('foo'); // or app.extendWith(['foo', 'bar', 'baz']); app.extendWith(require('generate-defaults')); ``` @name .extendWith @param {String|Object} `app` @return {Object} Returns the instance for chaining. @api public
[ "Extend", "the", "generator", "instance", "with", "settings", "and", "features", "of", "another", "generator", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L384-L419
39,587
base/base-generators
index.js
function(name, options) { if (typeof options === 'function') { return options(name); } if (options && typeof options.toAlias === 'function') { return options.toAlias(name); } if (typeof app.options.toAlias === 'function') { return app.options.toAlias(name); } return name; }
javascript
function(name, options) { if (typeof options === 'function') { return options(name); } if (options && typeof options.toAlias === 'function') { return options.toAlias(name); } if (typeof app.options.toAlias === 'function') { return app.options.toAlias(name); } return name; }
[ "function", "(", "name", ",", "options", ")", "{", "if", "(", "typeof", "options", "===", "'function'", ")", "{", "return", "options", "(", "name", ")", ";", "}", "if", "(", "options", "&&", "typeof", "options", ".", "toAlias", "===", "'function'", ")", "{", "return", "options", ".", "toAlias", "(", "name", ")", ";", "}", "if", "(", "typeof", "app", ".", "options", ".", "toAlias", "===", "'function'", ")", "{", "return", "app", ".", "options", ".", "toAlias", "(", "name", ")", ";", "}", "return", "name", ";", "}" ]
Create a generator alias from the given `name`. By default the alias is the string after the last dash. Or the whole string if no dash exists. ```js var camelcase = require('camel-case'); var alias = app.toAlias('foo-bar-baz'); //=> 'baz' // custom `toAlias` function app.option('toAlias', function(name) { return camelcase(name); }); var alias = app.toAlias('foo-bar-baz'); //=> 'fooBarBaz' ``` @name .toAlias @param {String} `name` @param {Object} `options` @return {String} Returns the alias. @api public
[ "Create", "a", "generator", "alias", "from", "the", "given", "name", ".", "By", "default", "the", "alias", "is", "the", "string", "after", "the", "last", "dash", ".", "Or", "the", "whole", "string", "if", "no", "dash", "exists", "." ]
9a741117b80ed19b281177169c0f98059cb97c90
https://github.com/base/base-generators/blob/9a741117b80ed19b281177169c0f98059cb97c90/index.js#L554-L565
39,588
jonschlinkert/lang-map
index.js
map
function map() { var cache = {}; if (!cache.extensions) cache.extensions = require('./lib/exts.json'); if (!cache.languages) cache.languages = require('./lib/lang.json'); return cache; }
javascript
function map() { var cache = {}; if (!cache.extensions) cache.extensions = require('./lib/exts.json'); if (!cache.languages) cache.languages = require('./lib/lang.json'); return cache; }
[ "function", "map", "(", ")", "{", "var", "cache", "=", "{", "}", ";", "if", "(", "!", "cache", ".", "extensions", ")", "cache", ".", "extensions", "=", "require", "(", "'./lib/exts.json'", ")", ";", "if", "(", "!", "cache", ".", "languages", ")", "cache", ".", "languages", "=", "require", "(", "'./lib/lang.json'", ")", ";", "return", "cache", ";", "}" ]
Lazy-load and cache extensions and languages
[ "Lazy", "-", "load", "and", "cache", "extensions", "and", "languages" ]
d12ec51ffda3a4bffee9e7cfb49c1e400af145a6
https://github.com/jonschlinkert/lang-map/blob/d12ec51ffda3a4bffee9e7cfb49c1e400af145a6/index.js#L11-L16
39,589
presort/pre-toast
lib/utils/Assertions.js
isUrl
function isUrl(url, error) { if (!Assertions.urlPattern.test(url)) { if (error) { throw new Error("Given url is not valid ! URL :" + url); } return false; } return true; }
javascript
function isUrl(url, error) { if (!Assertions.urlPattern.test(url)) { if (error) { throw new Error("Given url is not valid ! URL :" + url); } return false; } return true; }
[ "function", "isUrl", "(", "url", ",", "error", ")", "{", "if", "(", "!", "Assertions", ".", "urlPattern", ".", "test", "(", "url", ")", ")", "{", "if", "(", "error", ")", "{", "throw", "new", "Error", "(", "\"Given url is not valid ! URL :\"", "+", "url", ")", ";", "}", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if the string is a valid URL. @param {String} url string to check. @param {boolean} error defines the return type of method. If it is true it will throw in case of error , else it will return false. @returns {boolean} "true": is url , "false": is not url. @throws exception if error is true and url provided is not valid.
[ "Checks", "if", "the", "string", "is", "a", "valid", "URL", "." ]
0a6b329dd37cd68c70735b8703869b8c03800a71
https://github.com/presort/pre-toast/blob/0a6b329dd37cd68c70735b8703869b8c03800a71/lib/utils/Assertions.js#L66-L74
39,590
presort/pre-toast
lib/utils/Assertions.js
isReactComponent
function isReactComponent(instance, error) { /* disable-eslint no-underscore-dangle */ if (!(instance && instance.$$typeof)) { if (error) { throw new Error("Given component is not a react component ! Component :" + instance); } return false; } return true; }
javascript
function isReactComponent(instance, error) { /* disable-eslint no-underscore-dangle */ if (!(instance && instance.$$typeof)) { if (error) { throw new Error("Given component is not a react component ! Component :" + instance); } return false; } return true; }
[ "function", "isReactComponent", "(", "instance", ",", "error", ")", "{", "/* disable-eslint no-underscore-dangle */", "if", "(", "!", "(", "instance", "&&", "instance", ".", "$$typeof", ")", ")", "{", "if", "(", "error", ")", "{", "throw", "new", "Error", "(", "\"Given component is not a react component ! Component :\"", "+", "instance", ")", ";", "}", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks instance is React Component or not. @param {Object} instance @param {boolean} error @returns {boolean}
[ "Checks", "instance", "is", "React", "Component", "or", "not", "." ]
0a6b329dd37cd68c70735b8703869b8c03800a71
https://github.com/presort/pre-toast/blob/0a6b329dd37cd68c70735b8703869b8c03800a71/lib/utils/Assertions.js#L314-L323
39,591
MaximilianBuegler/node-kinetics
src/kinetics.js
extractVerticalComponent
function extractVerticalComponent(accelerometerData, attitudeData) { var res=[]; var rm; for (var i=0;i<accelerometerData.length;i++){ rm=new Matrix(module.exports.composeRotation(attitudeData[i][0],attitudeData[i][1],0)); res[i]=new Matrix([accelerometerData[i][0],accelerometerData[i][1],accelerometerData[i][2]]).dot(rm).data[0][2]; } return res; }
javascript
function extractVerticalComponent(accelerometerData, attitudeData) { var res=[]; var rm; for (var i=0;i<accelerometerData.length;i++){ rm=new Matrix(module.exports.composeRotation(attitudeData[i][0],attitudeData[i][1],0)); res[i]=new Matrix([accelerometerData[i][0],accelerometerData[i][1],accelerometerData[i][2]]).dot(rm).data[0][2]; } return res; }
[ "function", "extractVerticalComponent", "(", "accelerometerData", ",", "attitudeData", ")", "{", "var", "res", "=", "[", "]", ";", "var", "rm", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "accelerometerData", ".", "length", ";", "i", "++", ")", "{", "rm", "=", "new", "Matrix", "(", "module", ".", "exports", ".", "composeRotation", "(", "attitudeData", "[", "i", "]", "[", "0", "]", ",", "attitudeData", "[", "i", "]", "[", "1", "]", ",", "0", ")", ")", ";", "res", "[", "i", "]", "=", "new", "Matrix", "(", "[", "accelerometerData", "[", "i", "]", "[", "0", "]", ",", "accelerometerData", "[", "i", "]", "[", "1", "]", ",", "accelerometerData", "[", "i", "]", "[", "2", "]", "]", ")", ".", "dot", "(", "rm", ")", ".", "data", "[", "0", "]", "[", "2", "]", ";", "}", "return", "res", ";", "}" ]
Rotate accelerometer signal using attitude data and extract vertical component. Useful for instance for implementing a pedometer @param {2D array} (linear) accelerometerData 2D array containing time series of acceleration values [[x1, y1, z1],[x2, y2, z2],...] @param {2D array} attitudeData 2D array containing time series of attitude values [[pitch1, roll1, yaw1]. [pitch2, roll2, yaw2],... ] (in Radians) @returns {1D array} of vertical acceleration values [z1, z2,...]
[ "Rotate", "accelerometer", "signal", "using", "attitude", "data", "and", "extract", "vertical", "component", ".", "Useful", "for", "instance", "for", "implementing", "a", "pedometer" ]
fdaea742843014227e42e12bea40827b7fc3d516
https://github.com/MaximilianBuegler/node-kinetics/blob/fdaea742843014227e42e12bea40827b7fc3d516/src/kinetics.js#L34-L42
39,592
observing/mongo-query-filter
index.js
Filter
function Filter(options) { this.options = options || {}; for (var group in operators) { var prop = group.toLowerCase(); this[prop] = this.mask(group, this.options[prop]); } }
javascript
function Filter(options) { this.options = options || {}; for (var group in operators) { var prop = group.toLowerCase(); this[prop] = this.mask(group, this.options[prop]); } }
[ "function", "Filter", "(", "options", ")", "{", "this", ".", "options", "=", "options", "||", "{", "}", ";", "for", "(", "var", "group", "in", "operators", ")", "{", "var", "prop", "=", "group", ".", "toLowerCase", "(", ")", ";", "this", "[", "prop", "]", "=", "this", ".", "mask", "(", "group", ",", "this", ".", "options", "[", "prop", "]", ")", ";", "}", "}" ]
Strip MongoDB operators from user provided objects. @Constructor @param {Object} options @api public
[ "Strip", "MongoDB", "operators", "from", "user", "provided", "objects", "." ]
32bcb4b2cbce3c84022bba449f67cc048978b52e
https://github.com/observing/mongo-query-filter/blob/32bcb4b2cbce3c84022bba449f67cc048978b52e/index.js#L12-L19
39,593
worldline/easydoc
lib/easydoc.js
errorPage
function errorPage(res, err) { if (err) { console.error(err.message); res.send(err, {'Content-Type': 'text/plain'}, 500); } else { res.send(404); } }
javascript
function errorPage(res, err) { if (err) { console.error(err.message); res.send(err, {'Content-Type': 'text/plain'}, 500); } else { res.send(404); } }
[ "function", "errorPage", "(", "res", ",", "err", ")", "{", "if", "(", "err", ")", "{", "console", ".", "error", "(", "err", ".", "message", ")", ";", "res", ".", "send", "(", "err", ",", "{", "'Content-Type'", ":", "'text/plain'", "}", ",", "500", ")", ";", "}", "else", "{", "res", ".", "send", "(", "404", ")", ";", "}", "}" ]
Displays an HTTP error response. If an error is provided, the error is displayed with a 500 error code, otherwise it's a empty 404 error. @param res [Object] Http response @param err [String] Error message. Facultative.
[ "Displays", "an", "HTTP", "error", "response", ".", "If", "an", "error", "is", "provided", "the", "error", "is", "displayed", "with", "a", "500", "error", "code", "otherwise", "it", "s", "a", "empty", "404", "error", "." ]
c055d5aa99be460fef38ac629909ea4a653aaaaf
https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L61-L68
39,594
worldline/easydoc
lib/easydoc.js
compileAndRender
function compileAndRender(templatePath, content, callback) { if (templatePath in templates) { return callback(null, templates[templatePath].render(content)); } fs.readFile(templatePath, 'utf8', function(err, template) { if (err) { return callback(err) } templates[templatePath] = hogan.compile(template); callback(null, templates[templatePath].render(content)); }) }
javascript
function compileAndRender(templatePath, content, callback) { if (templatePath in templates) { return callback(null, templates[templatePath].render(content)); } fs.readFile(templatePath, 'utf8', function(err, template) { if (err) { return callback(err) } templates[templatePath] = hogan.compile(template); callback(null, templates[templatePath].render(content)); }) }
[ "function", "compileAndRender", "(", "templatePath", ",", "content", ",", "callback", ")", "{", "if", "(", "templatePath", "in", "templates", ")", "{", "return", "callback", "(", "null", ",", "templates", "[", "templatePath", "]", ".", "render", "(", "content", ")", ")", ";", "}", "fs", ".", "readFile", "(", "templatePath", ",", "'utf8'", ",", "function", "(", "err", ",", "template", ")", "{", "if", "(", "err", ")", "{", "return", "callback", "(", "err", ")", "}", "templates", "[", "templatePath", "]", "=", "hogan", ".", "compile", "(", "template", ")", ";", "callback", "(", "null", ",", "templates", "[", "templatePath", "]", ".", "render", "(", "content", ")", ")", ";", "}", ")", "}" ]
Render a given template with appropriate content. Use cached pre-compiled template if possible, and populate cache for new templates. @param templatePath [String] path to rendered template, used as key in cache @param content [Object] object used to be rendered inside the template @param callback [Function] end processing callback, invoked with arguments: @option callback err [Error] an error object, or null if no error occured @option callback html [String] Html rendering for this template
[ "Render", "a", "given", "template", "with", "appropriate", "content", ".", "Use", "cached", "pre", "-", "compiled", "template", "if", "possible", "and", "populate", "cache", "for", "new", "templates", "." ]
c055d5aa99be460fef38ac629909ea4a653aaaaf
https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L78-L89
39,595
worldline/easydoc
lib/easydoc.js
search
function search(searched, callback) { var root = pathUtils.resolve(options.root); // search command is platform dependant: use grep on linux, and findstr on windaube. var command = os.platform() === 'win32' ? 'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') : 'grep -rin "'+searched+'" '+root; // exec the command line. exec(command, function (err, stdout, stderr) { if (err) { // a 1 error code means no results. if (err.code === 1) { err = null; } return callback(err, []); } // each line an occurence. var lines = stdout.toString().split(root); // remove files that are not markdown. lines = _.filter(lines, function(val) { return val.trim().length > 0; }); // regroups by files var grouped = {}; for(var i = 0; i < lines.length; i++) { var numStart = lines[i].indexOf(':'); var numEnd = lines[i].indexOf(':', numStart+1); // remove leading \ var fileName = lines[i].substring(1, numStart); // ignore assets files if (/^_assets/.test(fileName)) { continue } if (!(fileName in grouped)) { grouped[fileName] = []; } grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')}); } // sort by relevance var files = []; for(var key in grouped) { files.push({ path: key, hits: grouped[key] }); } callback(null, files.sort(function(a, b) { return b.hits.length - a.hits.length; })); }); }
javascript
function search(searched, callback) { var root = pathUtils.resolve(options.root); // search command is platform dependant: use grep on linux, and findstr on windaube. var command = os.platform() === 'win32' ? 'findstr /spin /c:"'+searched+'" '+ pathUtils.join(root, '*.*') : 'grep -rin "'+searched+'" '+root; // exec the command line. exec(command, function (err, stdout, stderr) { if (err) { // a 1 error code means no results. if (err.code === 1) { err = null; } return callback(err, []); } // each line an occurence. var lines = stdout.toString().split(root); // remove files that are not markdown. lines = _.filter(lines, function(val) { return val.trim().length > 0; }); // regroups by files var grouped = {}; for(var i = 0; i < lines.length; i++) { var numStart = lines[i].indexOf(':'); var numEnd = lines[i].indexOf(':', numStart+1); // remove leading \ var fileName = lines[i].substring(1, numStart); // ignore assets files if (/^_assets/.test(fileName)) { continue } if (!(fileName in grouped)) { grouped[fileName] = []; } grouped[fileName].push({hit:lines[i].substring(numEnd+1).replace(new RegExp(searched, 'gi'), '<b>$&</b>')}); } // sort by relevance var files = []; for(var key in grouped) { files.push({ path: key, hits: grouped[key] }); } callback(null, files.sort(function(a, b) { return b.hits.length - a.hits.length; })); }); }
[ "function", "search", "(", "searched", ",", "callback", ")", "{", "var", "root", "=", "pathUtils", ".", "resolve", "(", "options", ".", "root", ")", ";", "// search command is platform dependant: use grep on linux, and findstr on windaube.", "var", "command", "=", "os", ".", "platform", "(", ")", "===", "'win32'", "?", "'findstr /spin /c:\"'", "+", "searched", "+", "'\" '", "+", "pathUtils", ".", "join", "(", "root", ",", "'*.*'", ")", ":", "'grep -rin \"'", "+", "searched", "+", "'\" '", "+", "root", ";", "// exec the command line.", "exec", "(", "command", ",", "function", "(", "err", ",", "stdout", ",", "stderr", ")", "{", "if", "(", "err", ")", "{", "// a 1 error code means no results.", "if", "(", "err", ".", "code", "===", "1", ")", "{", "err", "=", "null", ";", "}", "return", "callback", "(", "err", ",", "[", "]", ")", ";", "}", "// each line an occurence.", "var", "lines", "=", "stdout", ".", "toString", "(", ")", ".", "split", "(", "root", ")", ";", "// remove files that are not markdown.", "lines", "=", "_", ".", "filter", "(", "lines", ",", "function", "(", "val", ")", "{", "return", "val", ".", "trim", "(", ")", ".", "length", ">", "0", ";", "}", ")", ";", "// regroups by files", "var", "grouped", "=", "{", "}", ";", "for", "(", "var", "i", "=", "0", ";", "i", "<", "lines", ".", "length", ";", "i", "++", ")", "{", "var", "numStart", "=", "lines", "[", "i", "]", ".", "indexOf", "(", "':'", ")", ";", "var", "numEnd", "=", "lines", "[", "i", "]", ".", "indexOf", "(", "':'", ",", "numStart", "+", "1", ")", ";", "// remove leading \\", "var", "fileName", "=", "lines", "[", "i", "]", ".", "substring", "(", "1", ",", "numStart", ")", ";", "// ignore assets files", "if", "(", "/", "^_assets", "/", ".", "test", "(", "fileName", ")", ")", "{", "continue", "}", "if", "(", "!", "(", "fileName", "in", "grouped", ")", ")", "{", "grouped", "[", "fileName", "]", "=", "[", "]", ";", "}", "grouped", "[", "fileName", "]", ".", "push", "(", "{", "hit", ":", "lines", "[", "i", "]", ".", "substring", "(", "numEnd", "+", "1", ")", ".", "replace", "(", "new", "RegExp", "(", "searched", ",", "'gi'", ")", ",", "'<b>$&</b>'", ")", "}", ")", ";", "}", "// sort by relevance", "var", "files", "=", "[", "]", ";", "for", "(", "var", "key", "in", "grouped", ")", "{", "files", ".", "push", "(", "{", "path", ":", "key", ",", "hits", ":", "grouped", "[", "key", "]", "}", ")", ";", "}", "callback", "(", "null", ",", "files", ".", "sort", "(", "function", "(", "a", ",", "b", ")", "{", "return", "b", ".", "hits", ".", "length", "-", "a", ".", "hits", ".", "length", ";", "}", ")", ")", ";", "}", ")", ";", "}" ]
Performs a local-drive search by executing an os-specific command. Uses grep on linux, and findstr on windaube. @param callback [Function] A callback function that will received following arguments: @option callback err [String] an error if somthing goes wrong, null otherwise @option callback results [Array] an array (that may be empty) containing object with the following properties - path [String] file path, relative to root folder. - hits [Array] array of search occurence (strings).
[ "Performs", "a", "local", "-", "drive", "search", "by", "executing", "an", "os", "-", "specific", "command", ".", "Uses", "grep", "on", "linux", "and", "findstr", "on", "windaube", "." ]
c055d5aa99be460fef38ac629909ea4a653aaaaf
https://github.com/worldline/easydoc/blob/c055d5aa99be460fef38ac629909ea4a653aaaaf/lib/easydoc.js#L162-L213
39,596
adrai/node-cqs
lib/domain/bases/commandHandlerBase.js
function(aggregate, vm, callback) { if(aggregate.get('destroyed')) { var reason = { name: 'AggregateDestroyed', message: 'Aggregate has already been destroyed!', aggregateRevision: aggregate.get('revision'), aggregateId: aggregate.id }; return callback(reason); } callback(null, aggregate, vm); }
javascript
function(aggregate, vm, callback) { if(aggregate.get('destroyed')) { var reason = { name: 'AggregateDestroyed', message: 'Aggregate has already been destroyed!', aggregateRevision: aggregate.get('revision'), aggregateId: aggregate.id }; return callback(reason); } callback(null, aggregate, vm); }
[ "function", "(", "aggregate", ",", "vm", ",", "callback", ")", "{", "if", "(", "aggregate", ".", "get", "(", "'destroyed'", ")", ")", "{", "var", "reason", "=", "{", "name", ":", "'AggregateDestroyed'", ",", "message", ":", "'Aggregate has already been destroyed!'", ",", "aggregateRevision", ":", "aggregate", ".", "get", "(", "'revision'", ")", ",", "aggregateId", ":", "aggregate", ".", "id", "}", ";", "return", "callback", "(", "reason", ")", ";", "}", "callback", "(", "null", ",", "aggregate", ",", "vm", ")", ";", "}" ]
reject command if aggregate has already been destroyed
[ "reject", "command", "if", "aggregate", "has", "already", "been", "destroyed" ]
1691670a6e35d0b20904a5bd1b74adbe92f496eb
https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L33-L45
39,597
adrai/node-cqs
lib/domain/bases/commandHandlerBase.js
function(aggregate, vm, callback) { self.validate(cmd.command, cmd.payload, function(err) { callback(err, aggregate, vm); }); }
javascript
function(aggregate, vm, callback) { self.validate(cmd.command, cmd.payload, function(err) { callback(err, aggregate, vm); }); }
[ "function", "(", "aggregate", ",", "vm", ",", "callback", ")", "{", "self", ".", "validate", "(", "cmd", ".", "command", ",", "cmd", ".", "payload", ",", "function", "(", "err", ")", "{", "callback", "(", "err", ",", "aggregate", ",", "vm", ")", ";", "}", ")", ";", "}" ]
call validate command
[ "call", "validate", "command" ]
1691670a6e35d0b20904a5bd1b74adbe92f496eb
https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L55-L59
39,598
adrai/node-cqs
lib/domain/bases/commandHandlerBase.js
function(aggregate, vm, callback) { aggregate[cmd.command](cmd.payload, function(err) { callback(err, aggregate, vm); }); }
javascript
function(aggregate, vm, callback) { aggregate[cmd.command](cmd.payload, function(err) { callback(err, aggregate, vm); }); }
[ "function", "(", "aggregate", ",", "vm", ",", "callback", ")", "{", "aggregate", "[", "cmd", ".", "command", "]", "(", "cmd", ".", "payload", ",", "function", "(", "err", ")", "{", "callback", "(", "err", ",", "aggregate", ",", "vm", ")", ";", "}", ")", ";", "}" ]
call command function on aggregate
[ "call", "command", "function", "on", "aggregate" ]
1691670a6e35d0b20904a5bd1b74adbe92f496eb
https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L62-L66
39,599
adrai/node-cqs
lib/domain/bases/commandHandlerBase.js
function(aggregate, vm, callback) { vm.set(aggregate.toJSON()); self.commit(vm, function(err) { callback(err, aggregate, cmd); }); }
javascript
function(aggregate, vm, callback) { vm.set(aggregate.toJSON()); self.commit(vm, function(err) { callback(err, aggregate, cmd); }); }
[ "function", "(", "aggregate", ",", "vm", ",", "callback", ")", "{", "vm", ".", "set", "(", "aggregate", ".", "toJSON", "(", ")", ")", ";", "self", ".", "commit", "(", "vm", ",", "function", "(", "err", ")", "{", "callback", "(", "err", ",", "aggregate", ",", "cmd", ")", ";", "}", ")", ";", "}" ]
commit the new events
[ "commit", "the", "new", "events" ]
1691670a6e35d0b20904a5bd1b74adbe92f496eb
https://github.com/adrai/node-cqs/blob/1691670a6e35d0b20904a5bd1b74adbe92f496eb/lib/domain/bases/commandHandlerBase.js#L69-L74