_id
stringlengths 2
6
| title
stringlengths 0
58
| partition
stringclasses 3
values | text
stringlengths 27
233k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q2000
|
train
|
function( entireComponent ) {
// Insert a new component holder in the root or box.
if ( entireComponent ) P.$root.html( createWrappedComponent() )
else
|
javascript
|
{
"resource": ""
}
|
|
q2001
|
train
|
function() {
// If it’s already stopped, do nothing.
if ( !STATE.start ) return P
// Then close the picker.
P.close()
// Remove the hidden field.
if ( P._hidden ) {
P._hidden.parentNode.removeChild( P._hidden )
}
// Remove the root.
P.$root.remove()
// Remove the input class, remove the stored data, and unbind
|
javascript
|
{
"resource": ""
}
|
|
q2002
|
train
|
function( dontGiveFocus ) {
// If it’s already open, do nothing.
if ( STATE.open ) return P
// Add the “active” class.
$ELEMENT.addClass( CLASSES.active )
aria( ELEMENT, 'expanded', true )
// * A Firefox bug, when `html` has `overflow:hidden`, results in
// killing transitions :(. So add the “opened” state on the next tick.
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
setTimeout( function() {
// Add the “opened” class to the picker root.
P.$root.addClass( CLASSES.opened )
aria( P.$root[0], 'hidden', false )
}, 0 )
// If we have to give focus, bind the element and doc events.
if ( dontGiveFocus !== false ) {
// Set it as open.
STATE.open = true
// Prevent the page from scrolling.
if ( IS_DEFAULT_THEME ) {
$html.
css( 'overflow', 'hidden' ).
css( 'padding-right', '+=' + getScrollbarWidth() )
}
// Pass focus to the root element’s jQuery object.
// * Workaround for iOS8 to bring the picker’s root into view.
P.$root[0].focus()
// Bind the document events.
$document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) {
var target = event.target
// If the target of the event is not the element, close the picker picker.
// * Don’t worry about clicks or focusins on the root because those don’t bubble up.
// Also, for Firefox, a click on an `option` element bubbles up directly
// to the doc. So make sure the target wasn't the doc.
// * In Firefox stopPropagation() doesn’t prevent right-click events from bubbling,
// which causes the picker to unexpectedly close when right-clicking it. So make
// sure the event wasn’t a right-click.
if ( target != ELEMENT && target != document && event.which != 3 ) {
// If the target was the holder that covers the screen,
// keep the element focused to maintain tabindex.
P.close( target === P.$root.children()[0] )
}
}).on( 'keydown.' + STATE.id, function( event ) {
var
// Get the keycode.
keycode = event.keyCode,
// Translate that to a selection change.
keycodeToMove = P.component.key[ keycode ],
// Grab the target.
target = event.target
|
javascript
|
{
"resource": ""
}
|
|
q2003
|
train
|
function( thing, value, options ) {
var thingItem, thingValue,
thingIsObject = $.isPlainObject( thing ),
thingObject = thingIsObject ? thing : {}
// Make sure we have usable options.
options = thingIsObject && $.isPlainObject( value ) ? value : options || {}
if ( thing ) {
// If the thing isn’t an object, make it one.
if ( !thingIsObject ) {
thingObject[ thing ] = value
}
// Go through the things of items to set.
for ( thingItem in thingObject ) {
// Grab the value of the thing.
|
javascript
|
{
"resource": ""
}
|
|
q2004
|
train
|
function( thing, format ) {
// Make sure there’s something to get.
thing = thing || 'value'
// If a picker state exists, return that.
if ( STATE[ thing ] != null ) {
return STATE[ thing ]
}
// Return the submission value, if that.
if ( thing == 'valueSubmit' ) {
if ( P._hidden ) {
return P._hidden.value
}
thing = 'value'
}
// Return the value, if that.
if ( thing == 'value' ) {
return ELEMENT.value
}
// Check if a component item exists, return that.
if (
|
javascript
|
{
"resource": ""
}
|
|
q2005
|
train
|
function( thing, method, internal ) {
var thingName, thingMethod,
thingIsObject = $.isPlainObject( thing ),
thingObject = thingIsObject ? thing : {}
if ( thing ) {
// If the thing isn’t an object, make it one.
if ( !thingIsObject ) {
thingObject[ thing ] = method
}
// Go through the things to bind to.
for ( thingName in thingObject ) {
// Grab the method of the thing.
thingMethod = thingObject[ thingName ]
// If it was an internal binding, prefix it.
if ( internal ) {
|
javascript
|
{
"resource": ""
}
|
|
q2006
|
train
|
function() {
var i, thingName,
names = arguments;
for ( i = 0, namesCount = names.length; i < namesCount; i += 1 ) {
|
javascript
|
{
"resource": ""
}
|
|
q2007
|
train
|
function( name, data ) {
var _trigger = function( name ) {
var methodList = STATE.methods[ name ]
if ( methodList ) {
methodList.map( function( method
|
javascript
|
{
"resource": ""
}
|
|
q2008
|
createWrappedComponent
|
train
|
function createWrappedComponent() {
// Create a picker wrapper holder
return PickerConstructor._.node( 'div',
// Create a picker wrapper node
PickerConstructor._.node( 'div',
// Create a picker frame
PickerConstructor._.node( 'div',
// Create a picker box node
PickerConstructor._.node( 'div',
// Create the components nodes.
P.component.nodes( STATE.open ),
// The picker box class
CLASSES.box
|
javascript
|
{
"resource": ""
}
|
q2009
|
prepareElement
|
train
|
function prepareElement() {
$ELEMENT.
// Store the picker data by component name.
data(NAME, P).
// Add the “input” class name.
addClass(CLASSES.input).
// Remove the tabindex.
attr('tabindex', -1).
// If there’s a `data-value`, update the value of the element.
val( $ELEMENT.data('value') ?
P.get('select', SETTINGS.format) :
ELEMENT.value
)
// Only bind keydown events if the element isn’t editable.
if ( !SETTINGS.editable ) {
$ELEMENT.
// On focus/click, focus onto the root to open it up.
on( 'focus.' + STATE.id + ' click.' + STATE.id, function( event ) {
event.preventDefault()
P.$root[0].focus()
|
javascript
|
{
"resource": ""
}
|
q2010
|
prepareElementRoot
|
train
|
function prepareElementRoot() {
P.$root.
on({
// For iOS8.
keydown: handleKeydownEvent,
// When something within the root is focused, stop from bubbling
// to the doc and remove the “focused” state from the root.
focusin: function( event ) {
P.$root.removeClass( CLASSES.focused )
event.stopPropagation()
},
// When something within the root holder is clicked, stop it
// from bubbling to the doc.
'mousedown click': function( event ) {
var target = event.target
// Make sure the target isn’t the root holder so it can bubble up.
if ( target != P.$root.children()[ 0 ] ) {
event.stopPropagation()
// * For mousedown events, cancel the default action in order to
// prevent cases where focus is shifted onto external elements
// when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
// Also, for Firefox, don’t prevent action on the `option` element.
if ( event.type == 'mousedown' && !$( target ).is( 'input, select, textarea, button, option' )) {
event.preventDefault()
// Re-focus onto the root so that users can click away
// from elements focused within the picker.
P.$root[0].focus()
|
javascript
|
{
"resource": ""
}
|
q2011
|
train
|
function( event ) {
var target = event.target
// Make sure the target isn’t the root holder so it can bubble up.
if ( target != P.$root.children()[ 0 ] ) {
event.stopPropagation()
// * For mousedown events, cancel the default action in order to
// prevent cases where focus is shifted onto external elements
// when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
// Also, for Firefox, don’t prevent action
|
javascript
|
{
"resource": ""
}
|
|
q2012
|
prepareElementHidden
|
train
|
function prepareElementHidden() {
var name
if ( SETTINGS.hiddenName === true ) {
name = ELEMENT.name
ELEMENT.name = ''
}
else {
name = [
typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
]
name = name[0] + ELEMENT.name + name[1]
}
P._hidden = $(
'<input ' +
'type=hidden ' +
// Create the name using the original input’s with a prefix and suffix.
'name="' + name + '"' +
// If the element has a value, set the hidden value as well.
(
$ELEMENT.data('value') || ELEMENT.value ?
' value="' + P.get('select', SETTINGS.formatSubmit) + '"' :
''
)
|
javascript
|
{
"resource": ""
}
|
q2013
|
handleKeydownEvent
|
train
|
function handleKeydownEvent( event ) {
var keycode = event.keyCode,
// Check if one of the delete keys was pressed.
isKeycodeDelete = /^(8|46)$/.test(keycode)
// For some reason IE clears the input value on “escape”.
if ( keycode == 27 ) {
P.close()
return false
}
// Check if `space` or `delete`
|
javascript
|
{
"resource": ""
}
|
q2014
|
handleFocusToOpenEvent
|
train
|
function handleFocusToOpenEvent( event ) {
// Stop the event from propagating to the doc.
event.stopPropagation()
// If it’s a focus event, add the “focused” class to the root.
if ( event.type == 'focus' ) {
|
javascript
|
{
"resource": ""
}
|
q2015
|
isUsingDefaultTheme
|
train
|
function isUsingDefaultTheme( element ) {
var theme,
prop = 'position'
// For IE.
if ( element.currentStyle ) {
theme = element.currentStyle[prop]
}
|
javascript
|
{
"resource": ""
}
|
q2016
|
train
|
function( wrapper, item, klass, attribute ) {
// If the item is false-y, just return an empty string
if ( !item ) return ''
// If the item is an array, do a join
item = $.isArray( item ) ? item.join( '' ) : item
// Check for the class
klass = klass ? ' class="' + klass
|
javascript
|
{
"resource": ""
}
|
|
q2017
|
getWordLengthFromCollection
|
train
|
function getWordLengthFromCollection( string, collection, dateObject ) {
// Grab the first word from the string.
var word = string.match( /\w+/ )[ 0 ]
// If there's no month index, add it to the date object
if ( !dateObject.mm && !dateObject.m ) {
|
javascript
|
{
"resource": ""
}
|
q2018
|
train
|
function ( formatString, itemObject ) {
var calendar = this
return calendar.formats.toArray( formatString ).map( function( label ) {
|
javascript
|
{
"resource": ""
}
|
|
q2019
|
_addRouteRecord
|
train
|
function _addRouteRecord(route, parent, exclude = false, ancestors = []) {
const { path, name, handler } = route;
const finalPath = _normalizePath(path, parent, ancestors);
// Push path into ancestors array
ancestors.push(path);
const record = {
name,
parent,
handler,
path: finalPath,
regex: PathToRegexp(finalPath),
// redirect, TODO: Look into redirect functionality further
before: route.before,
init: route.init,
update: route.update,
after: route.after,
|
javascript
|
{
"resource": ""
}
|
q2020
|
_normalizePath
|
train
|
function _normalizePath(path, parent, ancestors) {
if (path === '/') {
return path;
}
path = path.replace(/\/$/, '');
// If path begins with / then assume it is independent route
if (path[0] === '/') {
return path;
}
// If no parent, and route doesn't start with /, then
|
javascript
|
{
"resource": ""
}
|
q2021
|
build_doc_map
|
train
|
function build_doc_map(docs) {
var map = {};
_.each(docs, function(tag) {
if (map[tag["tagname"]])
map[tag["tagname"]].push(tag);
|
javascript
|
{
"resource": ""
}
|
q2022
|
isIso8601DateTimeString
|
train
|
function isIso8601DateTimeString(value) {
var regex = /^(([+-]\d{6}|\d{4})(-(0[1-9]|1[0-2])(-(0[1-9]|[12]\d|3[01]))?)?)(T((([01]\d|2[0-3])(:[0-5]\d)(:[0-5]\d(\.\d{1,3})?)?)|(24:00(:00(\.0{1,3})?)?))(Z|([+-])([01]\d|2[0-3]):([0-5]\d))?)?$/;
|
javascript
|
{
"resource": ""
}
|
q2023
|
isIso8601DateString
|
train
|
function isIso8601DateString(value) {
var regex = /^([+-]\d{6}|\d{4})(-(0[1-9]|1[0-2])(-(0[1-9]|[12]\d|3[01]))?)?$/;
// Verify that it's in ISO 8601 format (via the regex) and that
|
javascript
|
{
"resource": ""
}
|
q2024
|
extractIso8601TimePieces
|
train
|
function extractIso8601TimePieces(value) {
var timePieces = /^(\d{2}):(\d{2})(?:\:(\d{2}))?(?:\.(\d{1,3}))?$/.exec(value);
if (timePieces === null) {
return null;
}
var hour = timePieces[1] ? parseInt(timePieces[1], 10) : 0;
var minute =
|
javascript
|
{
"resource": ""
}
|
q2025
|
compareTimes
|
train
|
function compareTimes(a, b) {
if (typeof a !== 'string' || typeof b !== 'string') {
return NaN;
}
var aTimePieces = extractIso8601TimePieces(a);
var bTimePieces = extractIso8601TimePieces(b);
if (aTimePieces === null || bTimePieces === null) {
return NaN;
}
for (var timePieceIndex = 0; timePieceIndex < aTimePieces.length; timePieceIndex++) {
if (aTimePieces[timePieceIndex]
|
javascript
|
{
"resource": ""
}
|
q2026
|
convertToTimestamp
|
train
|
function convertToTimestamp(value) {
if (value instanceof Date) {
return value.getTime();
} else if (typeof value === 'number') {
return Math.floor(value);
} else
|
javascript
|
{
"resource": ""
}
|
q2027
|
compareDates
|
train
|
function compareDates(a, b) {
var aTimestamp = convertToTimestamp(a);
var bTimestamp = convertToTimestamp(b);
if (isNaN(aTimestamp) || isNaN(bTimestamp))
|
javascript
|
{
"resource": ""
}
|
q2028
|
normalizeIso8601TimeZone
|
train
|
function normalizeIso8601TimeZone(value) {
if (value === 'Z') {
return 0;
}
var regex = /^([+-])(\d\d):?(\d\d)$/;
var matches = regex.exec(value);
if (matches === null) {
return NaN;
} else {
var multiplicationFactor = (matches[1] === '+') ? 1 : -1;
|
javascript
|
{
"resource": ""
}
|
q2029
|
compareTimeZones
|
train
|
function compareTimeZones(a, b) {
if (typeof a !== 'string' || typeof b !== 'string') {
return NaN;
}
|
javascript
|
{
"resource": ""
}
|
q2030
|
decode_param
|
train
|
function decode_param(val) {
if (typeof val !== 'string' || val.length === 0) {
return val;
}
try {
return decodeURIComponent(val);
} catch (err) {
if (err instanceof URIError) {
|
javascript
|
{
"resource": ""
}
|
q2031
|
train
|
function (mime) {
var info = {
type: UNKNOWN,
format: RAW,
guessed: true
},
match,
base;
// extract the mime base
base = (base = mime.split(SEP)) && base[0] || E;
// bail out on the mime types that are sure-shot ones with no ambiguity
match = base.match(AUDIO_VIDEO_IMAGE_TEXT);
if (match && match[1]) {
info.type = info.format = match[1];
// we do special kane matching to extract the format in case the match was text
// this ensures that we get same formats like we will do in kane match later down the line
if (info.type === TEXT) {
match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
info.format = match && match[1] || PLAIN;
}
return info;
}
// we do a kane match on entire mime (not just base) to find texts
match = mime.match(JSON_XML_SCRIPT_SIBLINGS);
if (match && match[1]) {
info.type = TEXT;
info.format = match[1];
|
javascript
|
{
"resource": ""
}
|
|
q2032
|
train
|
function(o) {
var a = [];
_.each(o, function(value,
|
javascript
|
{
"resource": ""
}
|
|
q2033
|
expand
|
train
|
function expand(docset, customTags) {
docset["comment"] = DocParser.parse(docset["comment"], customTags);
docset["tagname"] = DocType.detect(docset["comment"], docset["code"]);
if
|
javascript
|
{
"resource": ""
}
|
q2034
|
merge
|
train
|
function merge(docset, customTags) {
doc_ast.linenr = docset["linenr"];
// useful for applying global NS items to the proper NS
docset["original_name"] = docset["code"].name;
|
javascript
|
{
"resource": ""
}
|
q2035
|
createBasicTranslation
|
train
|
function createBasicTranslation(memberName, type, i, options) {
var node = {};
node["id"] = memberName;
node["type"] = type;
if (i["inheritdoc"] !== undefined) {
node["inheritdoc"] = i["inheritdoc"].src;
}
else if (i["doc"] !== undefined) {
node["description"] = i["doc"];
// short description lasts until the first empty line
node["short_description"] = node["description"].replace(/\n\n[\s\S]*$/, '\n');
}
else {
node["undocumented"] = true;
}
node["line"] = i["linenr"];
if (i["private"] !== undefined)
node["private"] = i["private"];
if (i["experimental"] !== undefined)
node["experimental"] = i["experimental"];
if (i["ignore"] !== undefined)
node["ignore"] = i["ignore"];
if (i["chainable"] !== undefined)
node["chainable"] = i["chainable"];
if (i["see"] !== undefined)
node["related_to"] = i["see"].name;
if (i["author"] !== undefined && i["author"].length > 0)
|
javascript
|
{
"resource": ""
}
|
q2036
|
Route
|
train
|
function Route(path) {
this.path = path;
this.stack = [];
this.handle = compose(this.stack);
debug('new %s', path);
|
javascript
|
{
"resource": ""
}
|
q2037
|
train
|
function(data, name, $field, $el, field, callback) {
data[name] = self.getArea($el, name);
if (field.required && (apos.areaIsEmpty(data[name]))) {
|
javascript
|
{
"resource": ""
}
|
|
q2038
|
train
|
function(data, name, $field, $el, field, callback) {
data[name] = $field.val();
if (field.required && !data[name].length) {
return apos.afterYield(_.partial(callback, 'required'));
}
if (field.max && (data[name].length > field.max)) {
var $fieldset = self.findFieldset($el, name);
|
javascript
|
{
"resource": ""
}
|
|
q2039
|
_isValid
|
train
|
function _isValid(el, currentPath) {
// Link has no destination URL
if (! el.href) { return false; }
// Link opens a new browser window
if (el.target === '_blank') { return false; }
// Link is not absolute URL
if (! /https?:/.test(el.href)) { return false; }
// Link is a download
if (el.hasAttribute('download')) { return false; }
// Link is supposed to be ignored
if (el.hasAttribute('data-static')) { return false; }
// Link is
|
javascript
|
{
"resource": ""
}
|
q2040
|
_path
|
train
|
function _path(loc) {
loc = loc || location;
return
|
javascript
|
{
"resource": ""
}
|
q2041
|
train
|
function (message) {
if (options.force) {
grunt.log.error(message);
} else
|
javascript
|
{
"resource": ""
}
|
|
q2042
|
simpleTypeFilter
|
train
|
function simpleTypeFilter(newDoc, oldDoc, candidateDocType) {
if (oldDoc) {
if (newDoc._deleted) {
return oldDoc.type === candidateDocType;
} else {
|
javascript
|
{
"resource": ""
}
|
q2043
|
train
|
function(methodName, alternatives) {
return function() {
var callback = Array.prototype.slice.call(arguments).pop();
if (!Array.isArray(alternatives)) {
alternatives = [alternatives];
}
var alternativeString;
if (alternatives.length === 1) {
alternativeString = alternatives[0];
} else {
var lastItem = alternatives.pop();
alternativeString = alternatives.join('", "') + '" or "' +
|
javascript
|
{
"resource": ""
}
|
|
q2044
|
add_shared
|
train
|
function add_shared(hash, customTags, doc_map) {
hash = utils.merge(hash, {
"inheritable" : !!doc_map["inheritable"],
"inheritdoc" : extract(doc_map, "inheritdoc"),
"related" : extract(doc_map, "related"),
"see" : extract(doc_map, "see"),
"private" : extract(doc_map, "private") !== null ? true : false,
"experimental" : extract(doc_map, "experimental") !== null ? true : false,
"ignore" : extract(doc_map, "ignore") !== null ? true : false,
"author" : extract_plural(doc_map["author"] || []),
"version" : extract(doc_map, "version"),
"since" : extract(doc_map, "since"),
"todo" : extract(doc_map, "todo")
});
if (customTags
|
javascript
|
{
"resource": ""
}
|
q2045
|
detect_list
|
train
|
function detect_list(type, doc_map) {
if (doc_map[type])
return _.flatten(_.map(doc_map[type],
|
javascript
|
{
"resource": ""
}
|
q2046
|
detect_doc
|
train
|
function detect_doc(docs, customTags) {
var ignore_tags = _.union(["param", "return", "author", "version",
"cancelable", "bubbles", "since", "inherits",
|
javascript
|
{
"resource": ""
}
|
q2047
|
maybe_name
|
train
|
function maybe_name() {
skip_horiz_white();
if (look(ident_pattern_with_dot)) {
current_tag["name"] = match(ident_pattern_with_dot);
}
else if
|
javascript
|
{
"resource": ""
}
|
q2048
|
default_value
|
train
|
function default_value() {
start_pos = input.pointer();
value = parse_balanced(/\[/, /\]/, /[^\[\]]*/);
if (look(/\]/)) {
return value;
}
else
|
javascript
|
{
"resource": ""
}
|
q2049
|
parse_balanced
|
train
|
function parse_balanced(re_open, re_close, re_rest) {
result = match(re_rest);
while (look(re_open)) {
result += match(re_open);
result += parse_balanced(re_open,
|
javascript
|
{
"resource": ""
}
|
q2050
|
RedisPool
|
train
|
function RedisPool(opts) {
if (!(this instanceof RedisPool)) {
return new RedisPool(opts);
}
EventEmitter.call(this);
opts = opts || {};
var defaults = {
host: '127.0.0.1',
port: '6379',
max: 50,
idleTimeoutMillis: 10000,
reapIntervalMillis: 1000,
noReadyCheck: false,
returnToHead: false,
unwatchOnRelease: true,
name: 'default',
log: false,
slowPool: {
log: false,
elapsedThreshold: 25
},
emitter: {
statusInterval: 60000
},
commands: []
};
this.options = _.defaults(opts, defaults);
this.pools = {};
this.elapsedThreshold = this.options.slowPool.elapsedThreshold;
// add custom Redis commands
if (this.options.commands && this.options.commands.length) {
|
javascript
|
{
"resource": ""
}
|
q2051
|
makePool
|
train
|
function makePool(options, database) {
return Pool({
name: options.name + ':' + database,
create: function(callback) {
var callbackCalled = false;
var client = redis.createClient(options.port, options.host, {
no_ready_check: options.noReadyCheck
});
client.on('error', function (err) {
log(options, {db: database, action: 'error', err: err.message});
if (!callbackCalled) {
callbackCalled = true;
callback(err, client);
}
client.end(FLUSH_CONNECTION);
});
client.on('ready', function () {
client.select(database, function(err/*, res*/) {
if (!callbackCalled) {
callbackCalled = true;
|
javascript
|
{
"resource": ""
}
|
q2052
|
_storageFactory
|
train
|
function _storageFactory(type) {
let storage;
if (type === 'local') {
storage = window.localStorage;
} else if (type === 'session') {
storage = window.sessionStorage;
}
return {
getItem(key) {
return JSON.parse(storage.getItem(key));
},
|
javascript
|
{
"resource": ""
}
|
q2053
|
train
|
function(numberOfDownloaded, finishCallback, allCompletedCallback) {
let downloadedItem = 0;
return zincGeometry => {
downloadedItem = downloadedItem + 1;
if (finishCallback != undefined && (typeof finishCallback == 'function'))
finishCallback(zincGeometry);
|
javascript
|
{
"resource": ""
}
|
|
q2054
|
extend
|
train
|
function extend (host, methods) {
for (var name in methods)
|
javascript
|
{
"resource": ""
}
|
q2055
|
makeTypeConstraintsSchema
|
train
|
function makeTypeConstraintsSchema(typeName) {
const allTypeConstraints = typeSpecificConstraintSchemas();
const constraints = Object.assign({ }, universalConstraintSchemas(typeEqualitySchemas[typeName]), allTypeConstraints[typeName]);
return joi.object().keys(constraints)
// Prevent the use of more than one constraint from the "required value" category
.without('required', [ 'mustNotBeMissing', 'mustNotBeNull' ])
.without('mustNotBeMissing', [ 'required', 'mustNotBeNull' ])
.without('mustNotBeNull', [ 'required', 'mustNotBeMissing' ])
// Prevent the use of more than one constraint from the "equality" category
.without('mustEqual', [ 'mustEqualStrict', 'mustEqualIgnoreCase' ])
.without('mustEqualStrict', [ 'mustEqual', 'mustEqualIgnoreCase' ])
.without('mustEqualIgnoreCase', [ 'mustEqual', 'mustEqualStrict' ])
// Prevent the use of more than one constraint from the "minimum value" category
.without('minimumValue', [ 'minimumValueExclusive', 'mustEqual', 'mustEqualStrict', 'mustEqualIgnoreCase' ])
.without('minimumValueExclusive', [ 'minimumValue', 'mustEqual', 'mustEqualStrict', 'mustEqualIgnoreCase' ])
// Prevent the use of more than one constraint from the "maximum value" category
.without('maximumValue', [ 'maximumValueExclusive', 'mustEqualStrict', 'mustEqual', 'mustEqualIgnoreCase' ])
|
javascript
|
{
"resource": ""
}
|
q2056
|
processOne
|
train
|
function processOne() {
var item = array.pop();
fn(item, function(result, err) {
if (array.length > 0)
processOne();
|
javascript
|
{
"resource": ""
}
|
q2057
|
_setClass
|
train
|
function _setClass(el, className) {
el instanceof SVGElement ?
|
javascript
|
{
"resource": ""
}
|
q2058
|
_toCamel
|
train
|
function _toCamel(name) {
return name.toLowerCase()
.replace(/-(.)/g,
|
javascript
|
{
"resource": ""
}
|
q2059
|
_getSelected
|
train
|
function _getSelected(select) {
const arr = [];
_slice.call(select.options).map((el) => {
if (el.selected) {
|
javascript
|
{
"resource": ""
}
|
q2060
|
_getSibling
|
train
|
function _getSibling(target, dir, filter, options) {
let match;
$each(target, (el) => {
const index = $index(el) + dir;
$children($parent(el)).forEach((el, i) => {
if (i === index &&
|
javascript
|
{
"resource": ""
}
|
q2061
|
partialCallback
|
train
|
function partialCallback(text, urlIndex) {
result[urlIndex] = text;
numComplete++;
// When all files have downloaded
|
javascript
|
{
"resource": ""
}
|
q2062
|
write
|
train
|
function write(id, chunk) {
// They want to write to our real stream
var stream = streams[id];
|
javascript
|
{
"resource": ""
}
|
q2063
|
expand_comment
|
train
|
function expand_comment(docset) {
groups = {
"class": [],
"cfg": [],
"Constructor": []
}
// By default everything goes to :class group
var group_name = "class";
_.each(docset["comment"], function (tag) {
tagname = tag["tagname"];
if (tagname == "cfg" || tagname == "Constructor") {
group_name = tagname;
if (tagname == "cfg")
groups["cfg"].push([]);
|
javascript
|
{
"resource": ""
}
|
q2064
|
groups_to_docsets
|
train
|
function groups_to_docsets(groups, docset) {
var results = [{
"tagname": "class",
"type": docset["type"],
"comment": groups["class"],
"code": docset["code"],
"linenr": docset["linenr"]
}];
_.each(groups["cfg"], function(cfg) {
results.push({
"tagname": "cfg",
"type": docset["type"],
|
javascript
|
{
"resource": ""
}
|
q2065
|
expand_code
|
train
|
function expand_code(docset) {
var results = [];
if (docset["code"] && docset["code"]["members"]) {
_.each(docset["code"]["members"], function(m) {
if
|
javascript
|
{
"resource": ""
}
|
q2066
|
vertextes
|
train
|
function vertextes(parent, exist = [], item, _path) {
return [...parent.children].reduce( (acc, node, index) => {
if(node.tagName === "IMG") {
//const [ name, props = {} ] = JSON.parse(node.getAttribute("m2") || "[]");
node.setAttribute("m2", JSON.stringify([
`*${imgcounter++}`, { resources: [ {type: "img", url: node.getAttribute("src") } ]}
]));
item = [];
}
/*
if(node.tagName === "link" && node.getAttribute("rel") === "stylesheet") {
exist[1].resources.push( {type: "style", url: node.getAttribute("href") } );
node.remove();
return acc;
}*/
if(node.getAttribute("m2")) {
|
javascript
|
{
"resource": ""
}
|
q2067
|
declarationImpliesInitialisation
|
train
|
function declarationImpliesInitialisation(variable, scope) {
return variable.name === "arguments" && scope.type === ScopeType.FUNCTION ||
variable.declarations.some(decl =>
decl.type === DeclarationType.PARAMETER ||
|
javascript
|
{
"resource": ""
}
|
q2068
|
_arrEquals
|
train
|
function _arrEquals(a, b) {
return a.length == b.length &&
|
javascript
|
{
"resource": ""
}
|
q2069
|
_copy
|
train
|
function _copy(val) {
const type = $type(val);
if (type == 'object') {
val = _extend({}, val, true);
} else if
|
javascript
|
{
"resource": ""
}
|
q2070
|
_equals
|
train
|
function _equals(a, b) {
if (a === b) {
return true;
}
const aType = $type(a);
if (aType != $type(b)) {
return false;
}
if (aType == 'array') {
return _arrEquals(a, b);
}
|
javascript
|
{
"resource": ""
}
|
q2071
|
_objEquals
|
train
|
function _objEquals(a, b) {
const aKeys = Object.keys(a);
return _arrEquals(aKeys.sort(), Object.keys(b).sort())
|
javascript
|
{
"resource": ""
}
|
q2072
|
format_parsed
|
train
|
function format_parsed (parsed) {
var pkg = (parsed.s && '@' + parsed.s +
|
javascript
|
{
"resource": ""
}
|
q2073
|
mix
|
train
|
function mix (receiver, supplier) {
for (var key in supplier) {
receiver[key] =
|
javascript
|
{
"resource": ""
}
|
q2074
|
_whichTransitionEvent
|
train
|
function _whichTransitionEvent() {
const el = document.createElement('meta');
const animations = {
transition: 'transitionend',
OTransition: 'oTransitionEnd',
|
javascript
|
{
"resource": ""
}
|
q2075
|
_addRule
|
train
|
function _addRule(conf) {
// Attach unique identifier
conf.i = id++;
// Only setup watching when enabled
if (conf.watch !== false) {
events.push(conf);
// Only attach event once
if (! bound) {
const run = _run.bind(this, false, 0, null);
bound = 1;
events = [conf];
// Attach resize event
|
javascript
|
{
"resource": ""
}
|
q2076
|
_eq
|
train
|
function _eq(evt, size, init) {
const sz = evt.size;
const mn = evt.min;
const mx = evt.max;
const ex = evt.each || init;
// Check match against rules
return (! sz && ! mn && ! mx) ||
(sz && sz === size) ||
|
javascript
|
{
"resource": ""
}
|
q2077
|
_run
|
train
|
function _run(init, rules, namespace) {
const size = _size();
let evts = rules || events;
let i;
// If breakpoint has been hit or resize logic initialized
if (size && (init || size !== current)) {
if (namespace) {
evts = evts.filter(obj => obj.namespace === namespace);
}
i = evts.length;
while (i--) {
const evt = evts[i];
if (_eq(evt, size, init)) {
const f = init && ! current;
const data = {
dir: f ? 0 : (size > current ? 1 : -1),
init: f,
prev: current,
size,
|
javascript
|
{
"resource": ""
}
|
q2078
|
router
|
train
|
function router(config = {}) {
$extend(settings, config);
// Update scrollBehavior property in case that was changed
|
javascript
|
{
"resource": ""
}
|
q2079
|
run_callbacks
|
train
|
function run_callbacks (object, key) {
var callbacks = object[key];
var callback;
// Mark the module is ready
// `delete module.c` is not safe
// #135
// Android 2.2 might treat `null` as [object Global] and equal
|
javascript
|
{
"resource": ""
}
|
q2080
|
Parser
|
train
|
function Parser(options) {
options = options || {};
// env storage
this._env = Object.create(null);
// current env
this._currEnv = options.currEnv || process.env;
// enable/disable booleans
this._allowBool = has.call(options, 'booleans')
?
|
javascript
|
{
"resource": ""
}
|
q2081
|
scan
|
train
|
function scan(str, re) {
var match = null;
var ret = [];
while (match = re.exec(str))
|
javascript
|
{
"resource": ""
}
|
q2082
|
train
|
function() {
// First deal only with doc-comments
doc_comments = _.filter(docs, function(d) {
return d["type"] == "doc_comment";
});
// Detect code in each docset. Sometimes a docset has already
// been detected as part of detecting some previous docset (like
// Class detecting all of its configs) -
|
javascript
|
{
"resource": ""
}
|
|
q2083
|
detect_class_members_from_object
|
train
|
function detect_class_members_from_object(cls, ast) {
cls["members"] = []
return each_pair_in_object_expression(ast, function(key, value, pair)
|
javascript
|
{
"resource": ""
}
|
q2084
|
detect_class_members_from_array
|
train
|
function detect_class_members_from_array(cls, ast) {
cls["members"] = [];
return _.each(ast["elements"], function(el) {
|
javascript
|
{
"resource": ""
}
|
q2085
|
detect_method_or_property
|
train
|
function detect_method_or_property(cls, key, value, pair) {
if (isFn(value)) {
var m = make_method(key, value);
if (apply_autodetected(m, pair))
return cls["members"].push(m);
}
else {
|
javascript
|
{
"resource": ""
}
|
q2086
|
apply_autodetected
|
train
|
function apply_autodetected(m, ast, inheritable) {
docset = find_docset(ast);
var inheritable = inheritable || true;
if (!docset || docset["type"] != "doc_comment") {
if (inheritable)
m["inheritdoc"] = {};
else
m["private"] = true;
m["autodetected"] = true;
}
if (docset) {
docset["code"] = m;
|
javascript
|
{
"resource": ""
}
|
q2087
|
each_pair_in_object_expression
|
train
|
function each_pair_in_object_expression(ast, func) {
if (! (ast && ast["type"] == "ObjectExpression")) {
return;
}
|
javascript
|
{
"resource": ""
}
|
q2088
|
createFetchInstance
|
train
|
function createFetchInstance(defaultConfig) {
const context = fetchFactory(defaultConfig);
const instance = bind(context.request, context);
|
javascript
|
{
"resource": ""
}
|
q2089
|
line_number
|
train
|
function line_number(index, source) {
// To speed things up, remember the index until which we counted,
// then next time just begin counting from there. This way we
|
javascript
|
{
"resource": ""
}
|
q2090
|
stuff_after
|
train
|
function stuff_after(comment, ast) {
var code = code_after(comment["range"], ast);
if (code && comment["next"])
|
javascript
|
{
"resource": ""
}
|
q2091
|
code_after
|
train
|
function code_after(range, parent) {
// Look through all child nodes of parent...
var children = child_nodes(parent);
for (var i = 0; i < children.length; i++) {
if (less(range, children[i]["range"])) {
// If node is after our range, then that's it. There could
// be comments in our way, but that's taken care of in
// #stuff_after
|
javascript
|
{
"resource": ""
}
|
q2092
|
child_nodes
|
train
|
function child_nodes(node) {
var properties = NODE_TYPES[node["type"]];
if (properties === undefined) {
console.error("FATAL".red + ": Unknown node type: " + node["type"]);
console.trace();
process.exit(1);
|
javascript
|
{
"resource": ""
}
|
q2093
|
train
|
function(req, data, name, snippet, field, callback) {
var manager = self._pages.getManager(field.withType);
if (!manager) {
return callback(new Error('join with type ' + field.withType + ' unrecognized'));
}
var titleOrId = self._apos.sanitizeString(data[name]);
var criteria = { $or: [ { sortTitle: self._apos.sortify(titleOrId) }, { _id: titleOrId } ] };
return manager.get(req, criteria, { fields: { _id: 1 } }, function(err, results) {
|
javascript
|
{
"resource": ""
}
|
|
q2094
|
train
|
function(req, data, name, snippet, field, callback) {
var manager = self._pages.getManager(field.withType);
if (!manager) {
return callback(new Error('join with type ' + field.withType + ' unrecognized'));
}
var titlesOrIds = self._apos.sanitizeString(data[name]).split(/\s*,\s*/);
if ((!titlesOrIds) || (titlesOrIds[0] === undefined)) {
return setImmediate(callback);
}
var clauses = [];
_.each(titlesOrIds, function(titleOrId) {
clauses.push({ sortTitle: self._apos.sortify(titleOrId) });
clauses.push({ _id: titleOrId });
});
return manager.get(req, { $or: clauses }, { fields: { _id: 1 }, withJoins: false }, function(err,
|
javascript
|
{
"resource": ""
}
|
|
q2095
|
error
|
train
|
function error() {
reject(new TypeError());
|
javascript
|
{
"resource": ""
}
|
q2096
|
insertInto
|
train
|
function insertInto(annotations, index, text, afterExisting) {
for (let i = 0; i < annotations.length; ++i) {
if (annotations[i].index >= index) {
if (afterExisting) {
while (i < annotations.length && annotations[i].index === index) {
++i;
|
javascript
|
{
"resource": ""
}
|
q2097
|
DiscordJS
|
train
|
function DiscordJS(embed) {
if (embed.file) {
console.log('Files in embeds will not be sent.');
embed.file
|
javascript
|
{
"resource": ""
}
|
q2098
|
parse_files
|
train
|
function parse_files(files, options, callback) {
var nodes = {
// root section node
'': {
id: '',
type: 'section',
children: [],
description: '',
short_description: '',
href: '#',
root: true,
file: '',
line: 0
}
};
var reportObject = { };
async.forEachSeries(files, function (file, next_file) {
var fn = parsers[path.extname(file)];
if (!fn) {
next_file();
return;
}
console.info('Parsing file: ' + file);
fn(file, options, function (err, file_nodes, file_report) {
// TODO: fail on name clash here as
|
javascript
|
{
"resource": ""
}
|
q2099
|
isPortTaken
|
train
|
function isPortTaken(port, fn) {
const net = require('net')
const tester = net.createServer()
.once('error', function (err) {
if (err.code != 'EADDRINUSE') return fn(err)
fn(null, true)
})
|
javascript
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.