_id
stringlengths
2
6
title
stringlengths
0
58
partition
stringclasses
3 values
text
stringlengths
52
373k
language
stringclasses
1 value
meta_information
dict
q61700
validation
function(config) { if(!config) { return ""; } var result = []; for(var key in config) { if(typeof config[key] == "undefined") { continue; } result.push(key + "=" + config[key]); } if(result.length > 0) { return "?" + result.join("&"); } return ""; }
javascript
{ "resource": "" }
q61701
validation
function(consumerKey, consumerSecret, applicationName, format, useCompression) { this.eventHandlers = {}; this.consumerKey = consumerKey; this.consumerSecret = consumerSecret; this.useCompression = useCompression || true; this.format = format || "json"; this.acceptEncoding = this.useCompression ? 'gzip, deflate' : 'identity'; this.applicationName = applicationName ? (applicationName + "/") : ""; if(!this.consumerKey || !this.consumerSecret) { throw "ConsumerKey and ConsumerSecret should be specified in order to use SDK"; } this.applicationName += this.tpl("JavaScript/{SDK_VERSION}/{format}", { SDK_VERSION: this.SDK_VERSION, format: this.format }); }
javascript
{ "resource": "" }
q61702
save
validation
function save(file, options) { var stream = fs.createWriteStream(file, options); function onSave() { stream.removeAllListeners(); this.emit('save'); } function onError(err) { stream.removeAllListeners(); this.emit('error', err); } stream.on('finish', onSave.bind(this)); stream.on('error', onError.bind(this)); this.pipe(stream); return this; }
javascript
{ "resource": "" }
q61703
findPath
validation
function findPath(request, paths) { if (paths.length == 1 && /^\.{2}/.test(request)) { paths[0] = path.dirname(paths[0]) request = request.slice(1) } return originalFindPath(request, paths) }
javascript
{ "resource": "" }
q61704
run
validation
function run(js, path) { var m = new Module(path, module) Module._findPath = findPath m.paths = Module._nodeModulePaths(dirname(path)) m.id = path m.filename = path js = 'module.return=eval(' + json(js) + ')' m._compile(js, path) Module._findPath = originalFindPath return m }
javascript
{ "resource": "" }
q61705
move_aspirate_forward
validation
function move_aspirate_forward(hash) { var asp = u.unasp2asp(hash.stemUlt); if (!asp) return; var stem = u.replaceEnd(hash.stem, hash.stemUlt, asp); if (!stem || stem == hash.stem) return; hash.stems = [stem]; if (debug) log('mod: move_aspirate_forward', stem); }
javascript
{ "resource": "" }
q61706
get
validation
function get (options, config) { options = options || found config = config || {} // Load options. var dir = options.dir || found.dir || 'config' var env = options.env || found.env || 'staging' var base = options.base || found.base || 'base' // Allow many "env" values. var key = env.toLowerCase() .replace(/^([gro]|ca)/, 'p') // gamma, release, one, canary -> "production". .replace(/^(sa|[al])/, 'd') // sandbox, alpha, local -> "development". .replace(/^[qtbcij]/, 's')[0] // qa, test, beta, ci, jenkins -> "staging". // Coerce to an expected environment. var environment = map[key] || map[key = 's'] config.env = env config.environment = environment config.isDebug = /de?bu?g/i.test(env) config.isDevelopment = (key === 'd') config.isStaging = (key === 's') config.isProduction = (key === 'p') // Load files. hide(config, 'load', load) // Load configuration from files. config.load(dir, base) config.load(dir, environment) // Load any matching sub-environments. var subEnvironments = config.subEnvironments if (subEnvironments && subEnvironments.indexOf(env) > -1) { config.load(dir, env) } return config }
javascript
{ "resource": "" }
q61707
decorate
validation
function decorate (object, values) { for (var key in values) { if (typeof object[key] === 'object') { decorate(object[key], values[key]) } else { object[key] = values[key] } } }
javascript
{ "resource": "" }
q61708
hide
validation
function hide (object, name, value) { Object.defineProperty(object, name, { enumerable: false, value: value }) }
javascript
{ "resource": "" }
q61709
_instanceCopy
validation
function _instanceCopy(sourceRef, copyRef, rc, copier) { let origIndex = rc.xStack.indexOf(sourceRef); if (origIndex === -1) { rc.push(sourceRef, copyRef); forEach(sourceRef, function(value, key) { copier(copyRef, value, key); }); rc.pop(); return copyRef; } else return rc.yStack[origIndex]; }
javascript
{ "resource": "" }
q61710
_objectCopy
validation
function _objectCopy(sourceRef, copyRef, rc) { let origIndex = rc.xStack.indexOf(sourceRef); if (origIndex === -1) { rc.push(sourceRef, copyRef); for (let [key, val] of _entries(sourceRef)) copyRef[key] = _clone(val, rc); let symbols = Object.getOwnPropertySymbols(sourceRef); for (let symbol of symbols) copyRef[symbol] = _clone(sourceRef[symbol], rc); rc.pop(); return copyRef; } else return rc.yStack[origIndex]; }
javascript
{ "resource": "" }
q61711
_setCopy
validation
function _setCopy(sourceRef, copyRef, rc) { return _instanceCopy(sourceRef, copyRef, rc, (set, val) => { set.add(_clone(val, rc)); }); }
javascript
{ "resource": "" }
q61712
_mapCopy
validation
function _mapCopy(sourceRef, copyRef, rc) { return _instanceCopy(sourceRef, copyRef, rc, (map, val, key) => { map.set(key, _clone(val, rc)); }); }
javascript
{ "resource": "" }
q61713
_singleCopy
validation
function _singleCopy(sourceRef, copyRef, rc) { return _instanceCopy(sourceRef, copyRef, rc, (item, val, key) => { copyRef[key] = _clone(val, rc); }); }
javascript
{ "resource": "" }
q61714
clone
validation
function clone(origSource) { let origIndex = -1; let rc = new RecurseCounter(1000); return _clone.call(null, origSource, rc); }
javascript
{ "resource": "" }
q61715
_compareObject
validation
function _compareObject(x, y, rc) { if (x === y) return true; if (x.constructor && y.constructor && x.constructor !== y.constructor) return false; let xKeys = Object.keys(x); let yKeys = Object.keys(y); xKeys.sort(); yKeys.sort(); if (!_equals(xKeys, yKeys, rc)) return false; rc.push(x, y); for (let k in x) { if (!_equals(x[k], y[k], rc)) return false; } rc.pop(); return true; }
javascript
{ "resource": "" }
q61716
equals
validation
function equals(x, y) { let rc = new RecurseCounter(1000); return _equals.call(null, x, y, rc); }
javascript
{ "resource": "" }
q61717
forEach
validation
function forEach(item, method, context) { let type = getType(item); switch(type) { case types.date: case types.function: case types.object: case types.regexp: if (!item[Symbol.iterator]) { for (let [key, value] of _entries(item)) { if (item.hasOwnProperty(key)) method.call(context, value, key, item); } } else { // shenanigans for (let value of item) { // do we want to check if value is array, and spread it across value/key? method.call(context, value, undefined, item); } } break; case types.arguments: case types.array: for (let i = 0; i < item.length; i++) method.call(context, item[i], i, item); break; case types.map: for (let [key, value] of item) method.call(context, value, key, item); break; case types.set: for (let value of item) // treat keys and values as equivalent for sets method.call(context, value, value, item); break; default: // if unknown type, then check for Symbol.iterator if (item[Symbol.iterator]) { for (let value of item[Symbol.iterator]()) method.call(context, value, undefined, item); } else if (!typeset.has(type) && type && type.constructor) { for (let [ key, value ] of _entries(item)) { if (item.hasOwnProperty(key)) // necessary with _entries? method.call(context, value, key, item); } } break; } return item; }
javascript
{ "resource": "" }
q61718
typeForExtend
validation
function typeForExtend(val) { // treat unknown types (classes, hopefully?) and functions as objects let type = getType(val); if (type === types.function || !typeset.has(type) && type && type.constructor) type = types.object; return type; }
javascript
{ "resource": "" }
q61719
isExtendable
validation
function isExtendable(...args) { // this is a fairly expensive call. find a way to optimize further? if (args.length < 1) return false; let baseType = typeForExtend(args[0]); if (!( baseType === types.array || baseType === types.object || baseType === types.set || baseType === types.map || baseType === types.function)) { return false; } for (let i = 1; i < args.length; i++) { let targetType = typeForExtend(args[i]); if (targetType !== baseType) return false; } return true; }
javascript
{ "resource": "" }
q61720
_extend
validation
function _extend(a, b) { forEach(b, (bVal, key) => { let type = typeForExtend(a); switch(type) { case types.array: case types.object: if (a[key] === undefined || a[key] === null) a[key] = b[key]; else if (isExtendable(a[key], b[key])) _extend(a[key], b[key]); break; case types.set: if (!a.has(bVal)) a.add(bVal); break; case types.map: if (!a.has(key)) a.set(key, bVal); else { let aVal = a.get(key); if (aVal === undefined || aVal === null) a.set(key, bVal); else if (isExtendable(aVal, bVal)) _extend(aVal, bVal); } break; } }); return a; }
javascript
{ "resource": "" }
q61721
extend
validation
function extend(a, ...rest) { rest.forEach(b => { if (isExtendable(a, b)) _extend(a, b); }); return a; }
javascript
{ "resource": "" }
q61722
_smash
validation
function _smash(a, b) { this.forEach(b, (val, key) => { if (this.isSmashable(a[key], b[key])) // find a way to move isSmashable internal this._smash(a[key], b[key]); else a[key] = this.deepCopy(b[key]); }); return a; }
javascript
{ "resource": "" }
q61723
smash
validation
function smash(a, ...rest) { rest.forEach(b => { if (this.isSmashable(a, b)) // find a way to move isSmashable internal this._smash(a, b); }); return a; }
javascript
{ "resource": "" }
q61724
File
validation
function File(name, file, parent) { this.name = name; this.file = file; this.parent = parent; this.readCursor = 0; this.eof = false; }
javascript
{ "resource": "" }
q61725
validation
function(msg, code, errorStr, cb) { return function(error, data) { if (error) { error = json_rpc.newSysError(msg, code, errorStr, error); } cb(error, data); }; }
javascript
{ "resource": "" }
q61726
getTimeDifference
validation
function getTimeDifference(timestr1, timestr2) { if (typeof timestr1 !== 'string' || typeof timestr2 !== 'string') { throw new Error('pendel.time() expects string arguments'); } // Check if we are getting the short timecode formats // like 1:32PM or 13:32. If Yes, convert it into a // generic datestring so that we can support the old API. var date1 = shortTimeToDateString(timestr1); var date2 = shortTimeToDateString(timestr2); if (!date1) { date1 = new Date(timestr1).toString(); } if (!date2) { date2 = new Date(timestr2).toString(); } var time1 = dateComponents(date1); var time2 = dateComponents(date2); var results = getTotalResultsFromEpochs(time1.epoch, time2.epoch); return { hours: Math.floor(results.totalSeconds / 60 / 60), minutes: Math.floor((results.totalSeconds / 60) % 60), seconds: Math.floor(results.totalSeconds % 60), totalMinutes: results.totalMinutes, totalSeconds: results.totalSeconds }; }
javascript
{ "resource": "" }
q61727
getDateDifference
validation
function getDateDifference(timestr1, timestr2) { // Force into predictable date format var start = timestr1.toLocaleDateString ? timestr1 : new Date(timestr1); var end = timestr2.toLocaleDateString ? timestr2 : new Date(timestr2); if (start.toString() === 'Invalid Date' || end.toString() === 'Invalid Date') { throw new TypeError('pendel.date() expects two valid date strings'); } var dr = moment.range(start, end); return { years: dr.diff('years'), months: dr.diff('months'), weeks: dr.diff('weeks'), days: dr.diff('days'), hours: dr.diff('hours'), minutes: dr.diff('minutes'), seconds: dr.diff('seconds') }; }
javascript
{ "resource": "" }
q61728
getTotalResultsFromEpochs
validation
function getTotalResultsFromEpochs(epoch1, epoch2) { var millisecs = Math.abs(epoch1 - epoch2); var seconds = millisecs / 1000; return { totalSeconds: seconds, totalMinutes: Math.floor(seconds / 60), totalHours: Math.floor(seconds / 60) * 60 }; }
javascript
{ "resource": "" }
q61729
InputCommand
validation
function InputCommand(args) { var parsed = new statements.ArgumentStatement(args); if (!parsed.args.length) throw new SyntaxError('INPUT requires at least one argument'); var question = "", placeVar, file; if (parsed.args.length === 1) placeVar = parsed.args[0]; else { if (parsed.args[0].child instanceof statements.PointerStatement) file = parsed.args[0]; else question = parsed.args[0]; placeVar = parsed.args[1]; } if (!(placeVar.child instanceof statements.VariableStatement || placeVar.child instanceof statements.FunctionStatement)) throw new SyntaxError('Expected variable'); this.file = file; this.question = question; this.placeVar = placeVar; }
javascript
{ "resource": "" }
q61730
PiechartCommand
validation
function PiechartCommand(args) { var parsed = new statements.ArgumentStatement(args); if (parsed.args.length < 8) throw new SyntaxError('PIECHART command requires 8 arguments'); this.x = parsed.args[0]; this.y = parsed.args[1]; this.r = parsed.args[2]; this.itemsLength = parsed.args[3]; this.percentages = parsed.args[4]; this.itemsRed = parsed.args[5]; this.itemsGreen = parsed.args[6]; this.itemsBlue = parsed.args[7]; }
javascript
{ "resource": "" }
q61731
flatMap
validation
function flatMap(mapper) { return function* (iterable) { let index = 0; for (const value of iterable) { const innerIterable = mapper(value, index); for (const inner of innerIterable) { yield inner; } index = index + 1; } }; }
javascript
{ "resource": "" }
q61732
skipWhile
validation
function skipWhile(predicate) { return function* (iterable) { let i = 0; let canReturn = false; for (const item of iterable) { if (!canReturn) { canReturn = !predicate(item, i); if (canReturn) { yield item; } i = i + 1; } else { yield item; } } }; }
javascript
{ "resource": "" }
q61733
skipUntil
validation
function skipUntil(predicate) { return function* (iterable) { let i = 0; let canReturn = false; for (const item of iterable) { if (!canReturn) { canReturn = predicate(item, i); if (canReturn) { yield item; } i = i + 1; } else { yield item; } } }; }
javascript
{ "resource": "" }
q61734
distinctUntilKeyChanged
validation
function distinctUntilKeyChanged(keySelector) { return function* (it) { let prev = undefined; for (const item of it) { const key = keySelector(item); if (key === prev) { continue; } prev = key; yield item; } }; }
javascript
{ "resource": "" }
q61735
orderBy
validation
function orderBy(keySelector, comparison) { const trueKeySelector = keySelector || defaultKeySelector; const trueComparison = comparison || defaultComparison; return function* (item) { const keyedMapper = map((item, index) => ({ item, key: trueKeySelector(item, index) })); const keyed = keyedMapper(item); const keyedArray = Array.from(keyed); keyedArray.sort((a, b) => trueComparison(a.key, b.key)); for (const { item } of keyedArray) { yield item; } }; }
javascript
{ "resource": "" }
q61736
repeat
validation
function repeat(times) { return function* (it) { const buffer = []; for (const item of it) { buffer.push(item); yield item; } for (let i = 0; i < times; ++i) { yield* buffer; } }; }
javascript
{ "resource": "" }
q61737
shuffle
validation
function shuffle(it, rand = () => Math.random()) { return map((x) => x[0])(orderBy((x) => x[1])(map((x) => [x, rand()])(it))); }
javascript
{ "resource": "" }
q61738
validation
function(compressedData) { var inflatedData = zlib.inflateSync( new Buffer(compressedData, 'base64')); var outputString = "[" + String.fromCharCode.apply(null,inflatedData) + "]"; var outputArray = JSON.parse(outputString); return ArrayConverter.diffsToValues(outputArray); }
javascript
{ "resource": "" }
q61739
ShapeCommand
validation
function ShapeCommand(args) { var parsed = new statements.ArgumentStatement(args); if (parsed.args.length < 3) throw new SyntaxError('SHAPE command requires 3 arguments'); this.pointsLength = parsed.args[0]; this.pointsX = parsed.args[1]; this.pointsY = parsed.args[2]; this.stroke = parsed.args.length > 3 ? parsed.args[3] : false; }
javascript
{ "resource": "" }
q61740
scrollSpy
validation
function scrollSpy() { var scrollTop = $window.scrollTop(), $anchors = $childMenu.find('a'), activeIndex; $anchors.each(function (index) { var $target = $($(this).attr('href').replace(/\./g, '\\.')), offsetTop = $target.offset().top, offsetBottom = offsetTop + $target.outerHeight(true); if (offsetTop <= scrollTop && scrollTop < offsetBottom) { activeIndex = index; return false; } }); $childMenuItem.removeClass('kss-active'); if (typeof activeIndex !== 'undefined') { $childMenuItem.eq(activeIndex).addClass('kss-active'); } }
javascript
{ "resource": "" }
q61741
fixSidebar
validation
function fixSidebar() { if ($sidebarInner.outerHeight() < $content.outerHeight()) { $sidebar.addClass('kss-fixed'); if ($sidebarInner.outerHeight() > $window.height()) { $sidebar.height($window.height()); $window.on('scroll', scrollSidebar).trigger('scroll'); } else { $sidebar.height('auto'); $window.off('scroll', scrollSidebar); } } else { $sidebar.removeClass('kss-fixed'); $sidebar.height('auto'); $window.off('scroll', scrollSidebar); } }
javascript
{ "resource": "" }
q61742
scrollSidebar
validation
function scrollSidebar(event) { if (event.handled !== true) { var scrollTop = $window.scrollTop(), maxScrollTop = $document.height() - $window.height(); if (scrollTop >= 0 && prevScrollTop >= 0 && scrollTop <= maxScrollTop && prevScrollTop <= maxScrollTop) { // for Mac scrolling $sidebar.scrollTop($sidebar.scrollTop() + (scrollTop - prevScrollTop)); } prevScrollTop = scrollTop; event.handled = true; } else { return false; } }
javascript
{ "resource": "" }
q61743
forEach
validation
function forEach(declarations, reqName, callback) { var d; if (reqName === "*") { // Iterate over all declarations. for (d in declarations) { callback.call(this, d); } } else if (reqName.charAt(reqName.length - 1) === "*") { // Iterate over uncapped `*` declarations. var baseName = reqName.substring(0, reqName.length - 1); for (d in declarations) { if (d.indexOf(baseName) === 0) { callback.call(this, d); } } } else { // A single dependency iteration. if (declarations[reqName]) { callback.call(this, reqName); } else { error("Invalid dependency '" + reqName + "'"); } } }
javascript
{ "resource": "" }
q61744
mkdir
validation
function mkdir(units, name) { if (name !== "") { var parts = name.split("."); var path = ""; for (var i = 0, len = parts.length; i < len; i++) { var part = parts[i]; path += part; if (units[part] == null) { units[part] = {}; } else if (typeof units[part] !== "object") { error("Cann't init unit '" + name + "' because path element '" + path + "' isn't an object"); } units = units[part]; path += "."; } } return units; }
javascript
{ "resource": "" }
q61745
pickUnit
validation
function pickUnit(srcDecls, destDecls, name, picked, stack) { var decl = srcDecls[name]; if (!picked[name]) { if (stack[name]) { error("Recursive dependency '" + name + "'"); } stack[name] = true; for (var i = 0, len = decl._dependencies.length; i < len; i++) { var reqName = decl._dependencies[i]; forEach(srcDecls, reqName, function(depName) { if (depName !== name) { pickUnit(srcDecls, destDecls, depName, picked, stack); } }); } destDecls[name] = decl; picked[name] = true; } }
javascript
{ "resource": "" }
q61746
pickUnits
validation
function pickUnits(dest, settings) { var units = settings.units; if (!isArray(units)) { error("Invalid units array in pick settings"); } if (!(settings.namespace instanceof Gumup)) { error("Invalid namespace in pick settings"); } var picked = {}, srcDecls = settings.namespace._declarations; for (var i = 0, len = units.length; i < len; i++) { var reqName = units[i]; if (!checkRequireName(reqName)) { error("Invalid unit name '" + reqName + "' in pick settings"); } forEach(srcDecls, reqName, function(depName) { pickUnit(srcDecls, dest._declarations, depName, picked, {}); }); } }
javascript
{ "resource": "" }
q61747
initialize
validation
function initialize(dest, declarations, name, cache, inited) { var decl = declarations[name]; if (!inited[name]) { // Create unit dependencies first. var len = cache.dependencies[name].length; for (var i = 0; i < len; i++) { initialize(dest, declarations, cache.dependencies[name][i], cache, inited); } // Create unit. decl._init(dest, name); inited[name] = true; } }
javascript
{ "resource": "" }
q61748
getShaSalt
validation
function getShaSalt() { var shaDeps = [__filename, __dirname + '/protractor_api.dart']; return shaTextHexDigest.apply(shaDeps.map(utils.readTextFile)); }
javascript
{ "resource": "" }
q61749
isBemDecl
validation
function isBemDecl(node) { if (node.type !== 'CallExpression') { return false; } if (node.callee.type !== 'MemberExpression') { return false; } if (node.callee.property.type !== 'Identifier' || node.callee.property.name !== 'decl') { return false; } var obj = node.callee.object; if (obj.type === "Identifier") { return obj.name === "BEM"; } if (obj.type === "MemberExpression") { if (obj.object.type !== "Identifier") { return false; } if (obj.object.name !== "BEM") { return false; } if (obj.property.type !== "Identifier") { return false; } return obj.property.name === "DOM"; } return false; }
javascript
{ "resource": "" }
q61750
getEntity
validation
function getEntity(decl) { if (decl.type === "Literal") { return {block: decl.value}; } if (decl.type === "ObjectExpression") { var base = getProperty(decl, 'baseBlock'), o = { block: getProperty(decl, 'block'), mod: getProperty(decl, 'modName'), val: getProperty(decl, 'modVal') }; if (base) { o.base = base; } return o; } }
javascript
{ "resource": "" }
q61751
getProperty
validation
function getProperty(objNode, name) { for (var i=0; i<objNode.properties.length; i++) { if (getKey(objNode.properties[i]) === name) { return getValue(objNode.properties[i]); } } }
javascript
{ "resource": "" }
q61752
getKey
validation
function getKey(propNode) { if (propNode.key.type === "Literal") { return propNode.key.value; } if (propNode.key.type === "Identifier") { return propNode.key.name; } }
javascript
{ "resource": "" }
q61753
addDocletBemEntity
validation
function addDocletBemEntity(e) { var bemEntity = e.code.bemEntity; e.doclet.block = bemEntity.block; if (bemEntity.base) { e.doclet.baseBlock = bemEntity.base; } if (bemEntity.mod) { e.doclet.mod = { name: bemEntity.mod, value: bemEntity.val }; } }
javascript
{ "resource": "" }
q61754
isStaticDecl
validation
function isStaticDecl(node) { var parent = node.parent; return hasStatic(parent) && parent.arguments[2] === node; }
javascript
{ "resource": "" }
q61755
hasStatic
validation
function hasStatic(node) { var args = node.arguments; if (!args) { return false; } return args.length >= 3 && args[1].type === "ObjectExpression" && args[2].type === "ObjectExpression"; }
javascript
{ "resource": "" }
q61756
getInputArguments
validation
function getInputArguments(args) { var out = {}; out.localServices = {}; if (args.length > 0) { out.source = args[0]; out.target = args[0]; if (_.isPlainObject(args[0])) { var opts = args[0]; out.target = opts.target; out.source = opts.source; out.instance = opts.instance; } // call(func, callback) if (args.length > 1) { var argsDefined = _.isString(args[0]) || _.isArray(args[0]); if (argsDefined) { if (_.isArray(args[0])) { out.source = args[0]; } else { out.source = _.isString(args[0]) ? [args[0]] : args[0]; } if (_.isFunction(args[1])) { out.target = args[1]; } if (_.isFunction(args[2])) { out.target = args[2]; } } else { if (_.isFunction(args[1])) { out.callReady = args[1]; } if (_.isPlainObject(args[1])) { out.localServices = args[1]; } } } if (args.length === 3) { if (_.isPlainObject(args[1])) { out.localServices = args[1]; } if (_.isFunction(args[2])) { out.callReady = args[2]; } } } out.target = out.target || function() {}; out.source = out.source ? out.source : out.target; out.callReady = out.callReady || function() {}; return out; }
javascript
{ "resource": "" }
q61757
findNext
validation
function findNext(data, items, index) { var currentIndex = data.length + 1, found = ''; for (var i = 0; i < items.length; i++) { var item = items[i]; var location = data.indexOf(item, index); if (location !== -1 && location < currentIndex) { currentIndex = location; found = item; } } if (currentIndex === data.length + 1) return { index: -1, found: '' }; return { index: currentIndex, found: found }; }
javascript
{ "resource": "" }
q61758
findLast
validation
function findLast(data, items, index) { var currentIndex = -1, found = ''; for (var i = 0; i < items.length; i++) { var item = items[i]; var location = data.lastIndexOf(item, index); if (location > currentIndex) { currentIndex = location; found = item; } } return { index: currentIndex, found: found }; }
javascript
{ "resource": "" }
q61759
findNextOutside
validation
function findNextOutside(data, items, index, exclude) { var result, positionResult = {start: 0, end: index ? index - 1 : -1}; do { result = findNext(data, items, positionResult.end + 1); } while (result.index !== -1 && (positionResult = inPosition(result.index, exclude))); return result; }
javascript
{ "resource": "" }
q61760
findLastOutside
validation
function findLastOutside(data, items, index, exclude) { var result, positionResult = {start: index ? index + 1 : data.length + 1, end: 0}; do { result = findLast(data, items, positionResult.start - 1); } while (result.index !== -1 && (positionResult = inPosition(result.index, exclude))); return result; }
javascript
{ "resource": "" }
q61761
indexOfOutside
validation
function indexOfOutside(data, item, index, exclude) { var result, positionResult = {start: 0, end: index ? index - 1 : -1}; do { result = data.indexOf(item, positionResult.end + 1); } while (result !== -1 && (positionResult = inPosition(result, exclude))); return result; }
javascript
{ "resource": "" }
q61762
lastIndexOfOutside
validation
function lastIndexOfOutside(data, item, index, exclude) { var result, positionResult = {start: index ? index + 1 : data.length + 1, end: 0}; do { result = data.lastIndexOf(item, positionResult.start - 1); } while (result.index !== -1 && (positionResult = inPosition(result.index, exclude))); return result; }
javascript
{ "resource": "" }
q61763
splitOutside
validation
function splitOutside(data, separator, exclude) { var result = []; var accumulator = ""; for (var i = 0; i < data.length; i++) { accumulator += data[i]; var isInExclusion = inPosition(i, exclude); if (!isInExclusion && endsWith(accumulator, separator)) { result.push(accumulator.substring(0, accumulator.length - separator.length)); accumulator = ''; } } result.push(accumulator); return result; }
javascript
{ "resource": "" }
q61764
inPosition
validation
function inPosition(index, items) { for (var i = 0; i < items.length; i++) { var item = items[i]; if (index >= item.start && index <= item.end) return item; } return false; }
javascript
{ "resource": "" }
q61765
endsWith
validation
function endsWith(data, str) { if (data.length < str.length) return false; if (data === str) return true; return data.lastIndexOf(str) === data.length - str.length; }
javascript
{ "resource": "" }
q61766
pad
validation
function pad(data, length, pad) { data = String(data); pad = pad || ' '; while (data.length < length) data += pad; return data; }
javascript
{ "resource": "" }
q61767
shallowClone
validation
function shallowClone(source, obj) { if (arguments.length < 2) { obj = source; source = {}; } for (var key in obj) { if (!obj.hasOwnProperty(key)) continue; source[key] = obj[key]; } return source; }
javascript
{ "resource": "" }
q61768
validation
function() { var args = norma('path:s?', arguments); var _url = url.format(_.clone(this.url)); var _path = (args.path || '').replace(/^\//, ''); return url.resolve(_url, _path); }
javascript
{ "resource": "" }
q61769
nextLine
validation
function nextLine(context, ast, prompt, oldPrompt, forceCursor, eval) { rl.question(prompt, function(answer) { eval(answer, context, ast, forceCursor === -1 ? ast.root.length : forceCursor, function(newPrompt, newCursor) { nextLine(context, ast, newPrompt || oldPrompt, oldPrompt, typeof newCursor === 'undefined' ? -1 : newCursor, eval); }); }); }
javascript
{ "resource": "" }
q61770
initialize
validation
function initialize(done) { done = done || function() { }; if (fileContents) done(); fs.readFile(__dirname + '/../../data/filesystem.json', { encoding: 'utf8' }, function(err, data) { if (err) fileContents = {}; else fileContents = JSON.parse(data); done(); }); }
javascript
{ "resource": "" }
q61771
save
validation
function save(done) { if (process.browser) return done(); fs.writeFile(__dirname + '/../../data/filesystem.json', JSON.stringify(fileContents), function(err) { if (done) done(err); }); }
javascript
{ "resource": "" }
q61772
validation
function (i, validate){ // we offer a shortcut to get types when only one argument is provided if (arguments.length === 1) { return av.type(i); } // we store the value in private scope var _i; // our getter-setter-combo including validation var me = function (d){ if (!arguments.length) { if (typeof _i === 'object'){ var o = {}; for (var prop in _i){ o[prop] = _i[prop](); } return o; } else { return _i; } } _i = validate(d); // if _i is an object we expose the getter/setter methods of its attributes if (typeof _i === 'object'){ for (var prop_object in _i){ me[prop_object] = _i[prop_object]; } } }; // we initialize the getter-setter-combo with the provided value me(i); // return the getter-setter-combo (allows chaining, among other things) return me; }
javascript
{ "resource": "" }
q61773
validation
function (d){ if (!arguments.length) { if (typeof _i === 'object'){ var o = {}; for (var prop in _i){ o[prop] = _i[prop](); } return o; } else { return _i; } } _i = validate(d); // if _i is an object we expose the getter/setter methods of its attributes if (typeof _i === 'object'){ for (var prop_object in _i){ me[prop_object] = _i[prop_object]; } } }
javascript
{ "resource": "" }
q61774
DimCommand
validation
function DimCommand(args) { var parsed = new statements.ArgumentStatement(args, { parseArgs: false }); this.creates = []; for (var i = 0; i < parsed.args.length; i++) { var dimDef = parsed.args[i]; var startBracket = dimDef.indexOf('('); var endBracket = dimDef.indexOf(')'); if (startBracket === -1) throw new SyntaxError('Expected start bracket'); if (endBracket === -1) throw new SyntaxError('Expected end bracket'); var arrayName = dimDef.substring(0, startBracket).trim(); var arrayLengthName = dimDef.substring(startBracket + 1, endBracket); var arrayLengthArg = new statements.ArgumentStatement(arrayLengthName); this.creates.push({ name: arrayName, lengths: arrayLengthArg.args }) } }
javascript
{ "resource": "" }
q61775
genEntityDescription
validation
function genEntityDescription(data, kind, entityName) { return data({kind: kind, name: entityName}).select('description').join('\n\n'); }
javascript
{ "resource": "" }
q61776
genBlockMethod
validation
function genBlockMethod(members, name) { var res = { name: name, description: '', params: [], returns: [], deprecated: false, final: false }; members.filter({ kind: 'function', name: name }).each(function(doclet) { if (doclet.description) { res.description += doclet.description + '\n'; } if (!res.access) { res.access = doclet.access; } if (!res.scope) { res.scope = doclet.scope; } if (res.returns.length === 0) { res.returns = genMethodReturns(doclet.returns); } if (res.params.length === 0) { res.params = genMethodParams(doclet.params); } if (doclet.deprecated) { res.deprecated = doclet.deprecated; } if (doclet.final) { res.final = doclet.final; } }); res.scope = res.scope || 'instance'; res.access = res.access || 'public'; return res; }
javascript
{ "resource": "" }
q61777
genParam
validation
function genParam(param) { var res = { name: param.name || '', description: param.description || '', optional: !!param.optional }; if (param.type) { res.types = param.type.names.slice(0); } if (param.defaultvalue) { res['default'] = param.defaultvalue; } return res; }
javascript
{ "resource": "" }
q61778
genProperty
validation
function genProperty(members, name) { var res = { name: name, deprecated: false, description: '', types: [] }; members.filter({ kind: 'member', name: name }).each(function(doclet) { if (doclet.description) { res.description += doclet.description + '\n'; } if (!res.access) { res.access = doclet.access; } if (!res.scope) { res.scope = doclet.scope; } if (doclet.deprected) { res.deprecated = true; } if (res.types.length === 0 && doclet.type) { res.types = doclet.type.names.slice(0); } }); res.scope = res.scope || 'instance'; res.access = res.acccess || 'public'; return res; }
javascript
{ "resource": "" }
q61779
IfCommand
validation
function IfCommand(args, define) { if (util.endsWith(args.toLowerCase(), ' then')) args = args.slice(0, args.length - 5).trim(); else throw new SyntaxError('IF has no THEN'); var parsed = new statements.ArgumentStatement(args, { separator: false }, define); this.condition = parsed.args[0]; this.block = define({ start: 'IF', then: 'ELSE', end: ['ENDIF', 'RETURN'] }); }
javascript
{ "resource": "" }
q61780
logger
validation
function logger(stream){ return (...text) => { text.map(text => { console.log(text) stream.write(`${Date.now()} - ${JSON.stringify(text)}\n`) }) } }
javascript
{ "resource": "" }
q61781
forward
validation
function forward(receiver, provider, keys) { keys = keys || allKeys(provider); keys = Array.isArray(keys) ? keys : [keys]; keys.forEach(function (key) { var val = provider[key]; if (typeof val === 'function') { receiver[key] = function () { return provider[key].apply(provider, arguments); }; } else { receiver[key] = val; } }); return receiver; }
javascript
{ "resource": "" }
q61782
RegexFinderStrategy
validation
function RegexFinderStrategy(config) { config = config || {}; FinderStrategy.call(this, config); this.config = extend(true, this.config, {}, config); }
javascript
{ "resource": "" }
q61783
SyncFile
validation
function SyncFile(path, flags, mode) { flags = flags || 'w'; this.fd = fs.openSync(path, flags, mode); this.crc = new Crc64(); this.converter = new Converter(); }
javascript
{ "resource": "" }
q61784
write
validation
function write(obj) { if(obj.type === 'crc') return this.end(); var buffer = this.converter.entry(obj); this.crc.push(buffer); return this.writeBuffer(buffer); }
javascript
{ "resource": "" }
q61785
writeBuffer
validation
function writeBuffer(buffer) { var written = fs.writeSync(this.fd, buffer, 0, buffer.length, null); fs.fsyncSync(this.fd); return written; }
javascript
{ "resource": "" }
q61786
end
validation
function end() { this.writeBuffer(this.crc.value()); fs.closeSync(this.fd); this.fd = null; this.crc = null; this.converter = null; }
javascript
{ "resource": "" }
q61787
AbstractSyntaxTree
validation
function AbstractSyntaxTree(root, labels, manager) { this.root = root; this.labels = labels; this.manager = manager; manager.parse(this); }
javascript
{ "resource": "" }
q61788
execute
validation
function execute(ast, ctx, done) { if (!done && !(ctx instanceof ExecutionContext)) { done = ctx; ctx = new ExecutionContext(); } ast.execute(ctx, done); }
javascript
{ "resource": "" }
q61789
MarkLogicStore
validation
function MarkLogicStore(options) { options = options || {}; var collectionName = options.collection || defaultOptions.collection; this.baseUri = options.baseUri || encodeURI(collectionName.replace(/\s/g,'-')); Store.call(this, options); this.collectionName = collectionName; this.ttl = options.ttl || defaultOptions.ttl || 0; // retain the client that was passed in, or create a new client this.db = options.client || marklogic.createDatabaseClient(options); }
javascript
{ "resource": "" }
q61790
_vendorsList
validation
function _vendorsList(vendors, ignore = false) { let vendorsList = '' let sign = (ignore) ? '-' : '+' for (let vendor of vendors) { vendorsList += ` ${sign} ${vendor}` } return vendorsList }
javascript
{ "resource": "" }
q61791
create
validation
function create (prototype, properties) { Ctor.prototype = prototype || {} return properties ? copy(new Ctor(), properties) : new Ctor() }
javascript
{ "resource": "" }
q61792
copy
validation
function copy (target, source) { for (var key in Object(source)) target[key] = source[key] return target }
javascript
{ "resource": "" }
q61793
identity
validation
function identity(iterable) { return __asyncGenerator(this, arguments, function* identity_1() { return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(iterable)))); }); }
javascript
{ "resource": "" }
q61794
scan
validation
function scan(predicate, initial) { return function (iterable) { return __asyncGenerator(this, arguments, function* () { var e_7, _a; let index = 0; let prevState = initial; try { for (var iterable_5 = __asyncValues(iterable), iterable_5_1; iterable_5_1 = yield __await(iterable_5.next()), !iterable_5_1.done;) { const value = iterable_5_1.value; prevState = yield __await(Promise.resolve(predicate(prevState, value, index))); yield yield __await(prevState); index = index + 1; } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (iterable_5_1 && !iterable_5_1.done && (_a = iterable_5.return)) yield __await(_a.call(iterable_5)); } finally { if (e_7) throw e_7.error; } } return yield __await(prevState); }); }; }
javascript
{ "resource": "" }
q61795
first
validation
async function first(iterable) { var e_13, _a; try { for (var iterable_11 = __asyncValues(iterable), iterable_11_1; iterable_11_1 = await iterable_11.next(), !iterable_11_1.done;) { const item = iterable_11_1.value; return item; } } catch (e_13_1) { e_13 = { error: e_13_1 }; } finally { try { if (iterable_11_1 && !iterable_11_1.done && (_a = iterable_11.return)) await _a.call(iterable_11); } finally { if (e_13) throw e_13.error; } } return undefined; }
javascript
{ "resource": "" }
q61796
skipUntil
validation
function skipUntil(predicate) { return function (iterable) { return __asyncGenerator(this, arguments, function* () { var e_18, _a; let i = 0; let canReturn = false; try { for (var iterable_16 = __asyncValues(iterable), iterable_16_1; iterable_16_1 = yield __await(iterable_16.next()), !iterable_16_1.done;) { const item = iterable_16_1.value; if (!canReturn) { canReturn = yield __await(predicate(item, i)); if (canReturn) { yield yield __await(item); } i = i + 1; } else { yield yield __await(item); } } } catch (e_18_1) { e_18 = { error: e_18_1 }; } finally { try { if (iterable_16_1 && !iterable_16_1.done && (_a = iterable_16.return)) yield __await(_a.call(iterable_16)); } finally { if (e_18) throw e_18.error; } } }); }; }
javascript
{ "resource": "" }
q61797
concat
validation
function concat(...iterables) { return function (it) { return __asyncGenerator(this, arguments, function* () { var e_20, _a; yield __await(yield* __asyncDelegator(__asyncValues(it))); try { for (var iterables_1 = __asyncValues(iterables), iterables_1_1; iterables_1_1 = yield __await(iterables_1.next()), !iterables_1_1.done;) { const iterable = iterables_1_1.value; yield __await(yield* __asyncDelegator(__asyncValues(iterable))); } } catch (e_20_1) { e_20 = { error: e_20_1 }; } finally { try { if (iterables_1_1 && !iterables_1_1.done && (_a = iterables_1.return)) yield __await(_a.call(iterables_1)); } finally { if (e_20) throw e_20.error; } } }); }; }
javascript
{ "resource": "" }
q61798
distinct
validation
function distinct(it) { return __asyncGenerator(this, arguments, function* distinct_1() { var e_24, _a; const resultSet = new Set(); try { for (var it_5 = __asyncValues(it), it_5_1; it_5_1 = yield __await(it_5.next()), !it_5_1.done;) { const item = it_5_1.value; if (!resultSet.has(item)) { resultSet.add(item); yield yield __await(item); } } } catch (e_24_1) { e_24 = { error: e_24_1 }; } finally { try { if (it_5_1 && !it_5_1.done && (_a = it_5.return)) yield __await(_a.call(it_5)); } finally { if (e_24) throw e_24.error; } } }); }
javascript
{ "resource": "" }
q61799
orderBy
validation
function orderBy(keySelector, comparison) { const trueKeySelector = keySelector || defaultKeySelector; const trueComparison = comparison || defaultComparison; return function (item) { return __asyncGenerator(this, arguments, function* () { var e_25, _a; const keyedMapper = map((item, index) => ({ item, key: trueKeySelector(item, index) })); const keyed = keyedMapper(item); const keyedArray = yield __await(toWriteableArray(keyed)); keyedArray.sort((a, b) => trueComparison(a.key, b.key)); try { for (var keyedArray_1 = __asyncValues(keyedArray), keyedArray_1_1; keyedArray_1_1 = yield __await(keyedArray_1.next()), !keyedArray_1_1.done;) { const { item } = keyedArray_1_1.value; yield yield __await(item); } } catch (e_25_1) { e_25 = { error: e_25_1 }; } finally { try { if (keyedArray_1_1 && !keyedArray_1_1.done && (_a = keyedArray_1.return)) yield __await(_a.call(keyedArray_1)); } finally { if (e_25) throw e_25.error; } } }); }; }
javascript
{ "resource": "" }