_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q49800 | setHeadersFromArray | train | function setHeadersFromArray (res, headers) {
for (var i = 0; i < headers.length; i++) {
res.setHeader(headers[i][0], headers[i][1])
}
} | javascript | {
"resource": ""
} |
q49801 | setHeadersFromObject | train | function setHeadersFromObject (res, headers) {
var keys = Object.keys(headers)
for (var i = 0; i < keys.length; i++) {
var k = keys[i]
if (k) res.setHeader(k, headers[k])
}
} | javascript | {
"resource": ""
} |
q49802 | setWriteHeadHeaders | train | function setWriteHeadHeaders (statusCode) {
var length = arguments.length
var headerIndex = length > 1 && typeof arguments[1] === 'string'
? 2
: 1
var headers = length >= headerIndex + 1
? arguments[headerIndex]
: undefined
this.statusCode = statusCode
if (Array.isArray(headers)) {
// h... | javascript | {
"resource": ""
} |
q49803 | _getVideo | train | function _getVideo(element) {
var videoElement = null;
if (element.tagName === 'VIDEO') {
videoElement = element;
}
else {
var videos = element.getElementsByTagName('video');
if (videos[0]) {
videoElement = videos[0];
}
}
return videoElement;
} | javascript | {
"resource": ""
} |
q49804 | videoEnterFullscreen | train | function videoEnterFullscreen(element) {
var videoElement = _getVideo(element);
if (videoElement && videoElement.webkitEnterFullscreen) {
try {
if (videoElement.readyState < videoElement.HAVE_METADATA) {
videoElement.addEventListener('loadedmetadata', function onMetadataLoaded() {
videoElement.re... | javascript | {
"resource": ""
} |
q49805 | train | function(reason, element) {
if (elements.length > 0) {
var obj = elements.pop();
element = element || obj.element;
obj.error.call(element, reason);
bigscreen.onerror(element, reason);
}
} | javascript | {
"resource": ""
} | |
q49806 | gcd | train | function gcd(a, b) {
var t;
while (b) {
t = a;
a = b;
b = t % b;
}
return Math.abs(a);
} | javascript | {
"resource": ""
} |
q49807 | train | function(a, b) {
// gcd = a * s + b * t
var s = 0, t = 1, u = 1, v = 0;
while (a !== 0) {
var q = b / a | 0, r = b % a;
var m = s - u * q, n = t - v * q;
b = a;
a = r;
s = u;
t = v;
u = m;
v = n;
}
return [b /* gcd*/, s, t];
} | javascript | {
"resource": ""
} | |
q49808 | keyUnion | train | function keyUnion(a, b) {
var k = {};
for (var i in a) {
k[i] = 1;
}
for (var i in b) {
k[i] = 1;
}
return k;
} | javascript | {
"resource": ""
} |
q49809 | degree | train | function degree(x) {
var i = Number.NEGATIVE_INFINITY;
for (var k in x) {
if (!FIELD['empty'](x[k]))
i = Math.max(k, i);
}
return i;
} | javascript | {
"resource": ""
} |
q49810 | train | function(x, y) {
var r = {};
var i = degree(x);
var j = degree(y);
var trace = [];
while (i >= j) {
var tmp = r[i - j] = FIELD['div'](x[i] || 0, y[j] || 0);
for (var k in y) {
x[+k + i - j] = FIELD['sub'](x[+k + i - j] || 0, FIELD['mul'](y[k] || 0, tmp));
}
if (... | javascript | {
"resource": ""
} | |
q49811 | train | function(x) {
var ret = {};
if (x === null || x === undefined) {
x = 0;
}
switch (typeof x) {
case "object":
if (x['coeff']) {
x = x['coeff'];
}
if (Fraction && x instanceof Fraction || Complex && x instanceof Complex || Quaternion && x instanceof Quat... | javascript | {
"resource": ""
} | |
q49812 | train | function(fn) {
/**
* The actual to string function
*
* @returns {string|null}
*/
var Str = function() {
var poly = this['coeff'];
var keys = [];
for (var i in poly) {
keys.push(+i);
}
if (keys.length === 0)
return "0";
keys.sort(func... | javascript | {
"resource": ""
} | |
q49813 | factor | train | function factor(P) {
var xn = 1;
var F = Polynomial(P); // f(x)
var f = F['derive'](); // f'(x)
var res = [];
do {
var prev, xn = Polynomial(1).coeff[0];
var k = 0;
do {
prev = xn;
//xn = FIELD['sub'](xn, FIELD.div(F.result(xn), f.result(xn)));
... | javascript | {
"resource": ""
} |
q49814 | serveapp | train | function serveapp (directory) {
/* istanbul ignore next */
return async function serveEmberAPP (ctx, next) {
await next();
if (!ctx.body) {
await ctx.render(directory);
}
};
} | javascript | {
"resource": ""
} |
q49815 | EvalRoute | train | function EvalRoute (ctx, next) {
let router = this;
let matched = router.match(router.opts.routerPath || ctx.routerPath || ctx.path, ctx.method);
/* istanbul ignore else */
if (ctx.matched) {
ctx.matched.push.apply(ctx.matched, matched.path);
} else {
ctx.matched = matched.path;
}
if (matched.route) {
retu... | javascript | {
"resource": ""
} |
q49816 | handle | train | function handle (fn) {
return function (...args) {
return new Promise((resolve) => {
fn.bind(this)(...args, function (err, result) {
/* istanbul ignore if */
if (err) {
debug(err);
} else {
resolve(result);
}
});
});
};
} | javascript | {
"resource": ""
} |
q49817 | DeepDevOrProd | train | function DeepDevOrProd (object, prop) {
let target = object[prop];
if (Object.keys(target).indexOf('dev') === -1 && typeof target === 'object') {
for (const deep of Object.keys(target)) {
DeepDevOrProd(object[prop], deep);
}
} else {
if (Object.keys(target).indexOf('dev') === -1) {
object[prop] = target;... | javascript | {
"resource": ""
} |
q49818 | handlebars | train | function handlebars () {
const Handlebars = require(ProyPath('node_modules', 'handlebars'));
const layouts = require(ProyPath('node_modules', 'handlebars-layouts'));
Handlebars.registerHelper(layouts(Handlebars));
Handlebars.registerHelper('link', function (url, helper) {
return makeLink(helper.data.root, url, he... | javascript | {
"resource": ""
} |
q49819 | findmodel | train | async function findmodel (ctx, next) {
let pmodel = ctx.request.url.split('?')[0].split('/')[1];
ctx.model = ctx.db[pmodel];
ctx.state.model = ctx.state.db[pmodel];
await next();
} | javascript | {
"resource": ""
} |
q49820 | protect | train | async function protect (ctx, next) {
if (ctx.isAuthenticated()) {
await next();
} else {
await passport.authenticate('bearer', {
session: false
}, async function (err, user) {
// console.log(err, user);
/* istanbul ignore if */
if (err) {
throw err;
}
if (user === false) {
ctx.body = n... | javascript | {
"resource": ""
} |
q49821 | makerelation | train | function makerelation (model, relation) {
let options = {
as: relation.As,
foreignKey: relation.key
};
let target = exp.databases[inflector.pluralize(relation.Children)];
if (relation.Rel !== 'manyToMany') {
exp.databases[model][relation.Rel](target, options);
} else {
exp.databases[model].prototype.many2m... | javascript | {
"resource": ""
} |
q49822 | createUser | train | async function createUser (username, password, /* istanbul ignore next */ body = {}) {
const user = await getUser(username, password);
body[configuration.security.username] = username;
body[configuration.security.password] = await hash(password, 5);
if (user === null) {
return AuthModel.create(body);
} else {
... | javascript | {
"resource": ""
} |
q49823 | deepRegister | train | function deepRegister(r) {
r.keys().forEach(key => {
const component = r(key)
registry.register(component.default, component.registryName)
})
} | javascript | {
"resource": ""
} |
q49824 | repeat | train | function repeat (string, width) {
var result = ''
var n = width
do {
if (n % 2) {
result += string
}
n = Math.floor(n / 2)
/* eslint no-self-assign: 0 */
string += string
} while (n && stringWidth(result) < width)
return wideTruncate(result, width)
} | javascript | {
"resource": ""
} |
q49825 | compile | train | function compile(inFile, outFile, sourceMap, cb) {
console.log('Compiling ' + inFile + ' to ' + outFile);
var outStream = fs.createWriteStream(outFile, 'utf8');
outStream.on('close', cb);
browserify({debug: true})
.require(inFile, { entry: true })
.bundle()
.pipe(exorcist(sourceMap))
... | javascript | {
"resource": ""
} |
q49826 | Hebcal | train | function Hebcal(year, month) {
var me = this; // whenever this is done, it is for optimizations.
if (!year) {
year = (new HDate())[getFullYear](); // this year;
}
if (typeof year !== 'number') {
throw new TE('year to Hebcal() is not a number');
}
me.year = year;
if (month) {
if (typeof month == 'string') {... | javascript | {
"resource": ""
} |
q49827 | abs | train | function abs(year, absDate) {
// find the first saturday on or after today's date
absDate = c.dayOnOrBefore(6, absDate + 6);
var weekNum = (absDate - year.first_saturday) / 7;
var index = year.theSedraArray[weekNum];
if (undefined === index) {
return abs(new Sedra(year.year + 1, year.il), absDate); // must be... | javascript | {
"resource": ""
} |
q49828 | train | function(stack, done, opts) {
var lines;
var line;
var mapForUri = {};
var rows = {};
var fields;
var uri;
var expected_fields;
var regex;
var skip_lines;
var fetcher = new Fetcher(opts);
if (isChromeOrEdge() || isIE11Plus()) {
regex = /^ +at.+\((.*):([0-9]+):([0-9]+)... | javascript | {
"resource": ""
} | |
q49829 | handleResponse | train | function handleResponse(conn, cb, opts) {
opts = opts || {};
return function(err, result) {
pool.release(conn);
if (err) {
return cb && cb(err);
}
if (opts.parse) {
if (result && opts.compress) {
return zlib.gunzip(result, opts.compress.params || {}, functio... | javascript | {
"resource": ""
} |
q49830 | getFromUrl | train | function getFromUrl(args) {
if (!args || typeof args.url !== 'string') {
return args;
}
try {
var options = redisUrl.parse(args.url);
// make a clone so we don't change input args
return applyOptionsToArgs(args, options);
} catch (e) {
//url is unparsable so returning orig... | javascript | {
"resource": ""
} |
q49831 | cloneArgs | train | function cloneArgs(args) {
var newArgs = {};
for(var key in args){
if (key && args.hasOwnProperty(key)) {
newArgs[key] = args[key];
}
}
newArgs.isCacheableValue = args.isCacheableValue && args.isCacheableValue.bind(newArgs);
return newArgs;
} | javascript | {
"resource": ""
} |
q49832 | applyOptionsToArgs | train | function applyOptionsToArgs(args, options) {
var newArgs = cloneArgs(args);
newArgs.host = options.hostname;
newArgs.port = parseInt(options.port, 10);
newArgs.db = parseInt(options.database, 10);
newArgs.auth_pass = options.password;
newArgs.password = options.password;
if(options.query && ... | javascript | {
"resource": ""
} |
q49833 | persist | train | function persist(pErr, pVal) {
if (pErr) {
return cb(pErr);
}
if (ttl) {
conn.setex(key, ttl, pVal, handleResponse(conn, cb));
} else {
conn.set(key, pVal, handleResponse(conn, cb));
}
} | javascript | {
"resource": ""
} |
q49834 | copyScript | train | function copyScript (script) {
fs.copySync(path.join(__dirname, script), path.join(appScriptsPath, script))
} | javascript | {
"resource": ""
} |
q49835 | decode | train | function decode(s) {
if (s) {
s = s.toString().replace(re.pluses, '%20');
s = decodeURIComponent(s);
}
return s;
} | javascript | {
"resource": ""
} |
q49836 | parseUri | train | function parseUri(str) {
var parser = re.uri_parser;
var parserKeys = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "isColonUri", "relative", "path", "directory", "file", "query", "anchor"];
var m = parser.exec(str || '');
var parts = {};
parserKeys.forEach(fun... | javascript | {
"resource": ""
} |
q49837 | Uri | train | function Uri(str) {
this.uriParts = parseUri(str);
this.queryPairs = parseQuery(this.uriParts.query);
this.hasAuthorityPrefixUserPref = null;
} | javascript | {
"resource": ""
} |
q49838 | LokiStore | train | function LokiStore (options) {
if (!(this instanceof LokiStore)) {
throw new TypeError('Cannot call LokiStore constructor as a function')
}
let self = this
// Parse options
options = options || {}
Store.call(this, options)
this.autosave = options.autosave !== false
this.storePa... | javascript | {
"resource": ""
} |
q49839 | train | function(data) {
// parse basic info from the dom item
var item = {
link: data.id,
text: data.textContent || data.innerText,
parent: ''
};
// build type identifier
var level = data.tagName;
for (var i = 0; i < data.classList.length; i++) {
level += ',' + data.classList[i];
}
//... | javascript | {
"resource": ""
} | |
q49840 | train | function (translationId) {
var deferred = $q.defer();
var regardless = function (value) {
results[translationId] = value;
deferred.resolve([translationId, value]);
};
// we don't care whether the promise was resolved or rejected; ju... | javascript | {
"resource": ""
} | |
q49841 | isFlippable | train | function isFlippable(node, prevNode) {
if (node.type == 'comment') {
return false;
}
if (prevNode && prevNode.type == 'comment') {
return !RE_NOFLIP.test(prevNode.comment);
}
return true;
} | javascript | {
"resource": ""
} |
q49842 | isReplaceable | train | function isReplaceable(node, prevNode) {
if (node.type == 'comment') {
return false;
}
if (prevNode && prevNode.type == 'comment') {
return RE_REPLACE.test(prevNode.comment);
}
return false;
} | javascript | {
"resource": ""
} |
q49843 | flip | train | function flip(str, options) {
if (typeof str != 'string') {
throw new Error('input is not a String.');
}
var node = css.parse(str, options);
flipNode(node.stylesheet);
return css.stringify(node, options);
} | javascript | {
"resource": ""
} |
q49844 | transition | train | function transition(value) {
var RE_PROP = /^\s*([a-zA-z\-]+)/;
var parts = value.split(/\s*,\s*/);
return parts.map(function (part) {
// extract the property if the value is for the `transition` shorthand
if (RE_PROP.test(part)) {
var prop = part.match(RE_PROP)[1];
var newProp = flipProperty... | javascript | {
"resource": ""
} |
q49845 | flipProperty | train | function flipProperty(prop) {
var normalizedProperty = prop.toLowerCase();
return PROPERTIES.hasOwnProperty(normalizedProperty) ? PROPERTIES[normalizedProperty] : prop;
} | javascript | {
"resource": ""
} |
q49846 | flipCorners | train | function flipCorners(value) {
var elements = value.split(/\s+/);
if (!elements) { return value; }
switch (elements.length) {
// 5px 10px 15px 20px => 10px 5px 20px 15px
case 4: return [elements[1], elements[0], elements[3], elements[2]].join(' ');
// 5px 10px 20px => 10px 5px 10px 20px
case 3: ... | javascript | {
"resource": ""
} |
q49847 | flipValueOf | train | function flipValueOf(prop, value) {
var RE_IMPORTANT = /\s*!important/;
var RE_PREFIX = /^-[a-zA-Z]+-/;
// find normalized property name (removing any vendor prefixes)
var normalizedProperty = prop.toLowerCase().trim();
normalizedProperty = (RE_PREFIX.test(normalizedProperty) ? normalizedProperty.split(RE_PR... | javascript | {
"resource": ""
} |
q49848 | flipShadow | train | function flipShadow(value) {
var elements = value.split(/\s+/);
if (!elements) { return value; }
var inset = (elements[0] == 'inset') ? elements.shift() + ' ' : '';
var property = elements[0].match(/^([-+]?\d+)(\w*)$/);
if (!property) { return value; }
return inset + [(-1 * +property[1]) + property[2]]
... | javascript | {
"resource": ""
} |
q49849 | train | function(state1, state2) {
// if state1 is undefined, return state2 + isEqual=false and velocity=0 as delta
if(!state1 || !state2)
return angular.extend(
{isEqual: false, velocityX: 0, velocityY: 0},
state2
);
// calculate delta of state1 and state2
var delta= {
posX: state2.posX - state1.pos... | javascript | {
"resource": ""
} | |
q49850 | get | train | function get(src) {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
ImgCache.isCached(src, function(path, success) {
if (success) {
defer.resolve(path);
} else {
defer.reject();
}
}, defer.reject);
... | javascript | {
"resource": ""
} |
q49851 | remove | train | function remove(src) {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
ImgCache.isCached(src, function(path, success) {
ImgCache.removeFile(src, function() {
defer.resolve();
}, defer.reject);
}, defer.reject);
})
... | javascript | {
"resource": ""
} |
q49852 | checkCacheStatus | train | function checkCacheStatus(src) {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
ImgCache.isCached(src, function(path, success) {
if (success) {
defer.resolve(path);
} else {
ImgCache.cacheFile(src, function() {
... | javascript | {
"resource": ""
} |
q49853 | checkBgCacheStatus | train | function checkBgCacheStatus(element) {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
ImgCache.isBackgroundCached(element, function(path, success) {
if (success) {
defer.resolve(path);
} else {
ImgCache.cacheBackground(... | javascript | {
"resource": ""
} |
q49854 | clearCache | train | function clearCache() {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
ImgCache.clearCache(defer.resolve, defer.reject);
})
.catch(defer.reject);
return defer.promise;
} | javascript | {
"resource": ""
} |
q49855 | getCacheSize | train | function getCacheSize() {
var defer = $q.defer();
_checkImgCacheReady()
.then(function() {
defer.resolve(ImgCache.getCurrentSize());
})
.catch(defer.reject);
return defer.promise;
} | javascript | {
"resource": ""
} |
q49856 | _checkImgCacheReady | train | function _checkImgCacheReady() {
var defer = $q.defer();
if (ImgCache.ready) {
defer.resolve();
}
else{
document.addEventListener('ImgCacheReady', function() { // eslint-disable-line
defer.resolve();
}, false);
}
return defer.promise;
} | javascript | {
"resource": ""
} |
q49857 | randomString | train | function randomString(length) {
var bits = 36,
tmp,
out = "";
while (out.length < length) {
tmp = Math.random().toString(bits).slice(2);
out += tmp.slice(0, Math.min(tmp.length, (length - out.length)));
}
return out.toUpperCase();
} | javascript | {
"resource": ""
} |
q49858 | logtap | train | function logtap(logger, message, data) {
data = _.clone(data);
if (data.payload_binary) {
data.payload_binary = '... (' + data.payload_binary.length + ' bytes)';
}
logger.debug(message, data);
} | javascript | {
"resource": ""
} |
q49859 | train | function(message) {
if (message.namespace === data.namespace &&
message.data.requestId === data.data.requestId) {
if (timer) {
clearTimeout(timer);
}
self.removeListener('message', answer);
self.removeListener('disconnect', cancel);
cb(null, message);
... | javascript | {
"resource": ""
} | |
q49860 | getPathHostName | train | function getPathHostName(origin, path) {
const pathOverride = {
'/oauth/userinfo': `https://${origin}.battle.net`,
};
return Object.prototype.hasOwnProperty.call(pathOverride, path) ? pathOverride[path] : endpoints[origin].hostname;
} | javascript | {
"resource": ""
} |
q49861 | getEndpoint | train | function getEndpoint(origin, locale, path) {
const validOrigin = Object.prototype.hasOwnProperty.call(endpoints, origin) ? origin : 'us';
const endpoint = endpoints[validOrigin];
return Object.assign(
{},
{ origin: validOrigin },
{ hostname: origin === 'cn' ? endpoint.hostname : getPathHostName(valid... | javascript | {
"resource": ""
} |
q49862 | Blizzard | train | function Blizzard(args, instance) {
const { key, secret, token } = args;
const { origin, locale } = endpoints.getEndpoint(args.origin, args.locale);
this.version = pkg.version;
this.defaults = {
origin,
locale,
key,
secret,
token,
};
this.axios = axios.create(instance);
/**
* Acco... | javascript | {
"resource": ""
} |
q49863 | unescape | train | function unescape(str, type) {
if (!isString(str)) return '';
var chars = charSets[type || 'default'];
var regex = toRegex(type, chars);
return str.replace(regex, function(m) {
return chars[m];
});
} | javascript | {
"resource": ""
} |
q49864 | roundToStepRatio | train | function roundToStepRatio (value, stepRatio) {
const stepRatioDecimals = calculateDecimals(stepRatio);
const stepDecimalsMultiplier = Math.pow(10, stepRatioDecimals);
value = Math.round(value / stepRatio) * stepRatio;
return Math.round(value * stepDecimalsMultiplier) / stepDecimalsMultiplier;
} | javascript | {
"resource": ""
} |
q49865 | findSameInArray | train | function findSameInArray (array, compareIndex) {
const sliders = [];
array.forEach((value, index) => {
if (value === array[compareIndex]) {
sliders.push(index);
}
});
return sliders;
} | javascript | {
"resource": ""
} |
q49866 | findClosestValue | train | function findClosestValue (values, lookupVal) {
let diff = 1;
let id = 0;
values.forEach((value, index) => {
const actualDiff = Math.abs(value - lookupVal);
if (actualDiff < diff) {
id = index;
diff = actualDiff;
}
});
return id;
} | javascript | {
"resource": ""
} |
q49867 | roundToStep | train | function roundToStep (value, step) {
const stepDecimals = calculateDecimals(step);
const stepDecimalsMultiplier = Math.pow(10, stepDecimals);
value = Math.round(value / step) * step;
return Math.round(value * stepDecimalsMultiplier) / stepDecimalsMultiplier;
} | javascript | {
"resource": ""
} |
q49868 | train | function(lock) {
lock.acquire = function(key, fn) {
Lock._acquiredLocks[lock._id] = lock;
lock._locked = true;
lock._key = key;
return client.setAsync(key, lock._id).nodeify(fn);
};
} | javascript | {
"resource": ""
} | |
q49869 | Tokenizer | train | function Tokenizer( regex, token ) {
var matches = [],
index = 0;
/**
* Add a match.
*
* @private
* @param {string} match Matched string
* @return {string} Token to leave in the matched string's place
*/
function tokenizeCallback( match ) {
matches.push( match );
return token;
}
/**
* Get a ... | javascript | {
"resource": ""
} |
q49870 | CSSJanus | train | function CSSJanus() {
var
// Tokens
temporaryToken = '`TMP`',
noFlipSingleToken = '`NOFLIP_SINGLE`',
noFlipClassToken = '`NOFLIP_CLASS`',
commentToken = '`COMMENT`',
// Patterns
nonAsciiPattern = '[^\\u0020-\\u007e]',
unicodePattern = '(?:(?:\\\\[0-9a-f]{1,6})(?:\\r\\n|\\s)?)',
numPattern = '(?:[0-9... | javascript | {
"resource": ""
} |
q49871 | calculateNewBackgroundPosition | train | function calculateNewBackgroundPosition( match, pre, value ) {
var idx, len;
if ( value.slice( -1 ) === '%' ) {
idx = value.indexOf( '.' );
if ( idx !== -1 ) {
// Two off, one for the "%" at the end, one for the dot itself
len = value.length - idx - 2;
value = 100 - parseFloat( value );
value ... | javascript | {
"resource": ""
} |
q49872 | train | function ( css, options ) { // eslint-disable-line quote-props, (for closure compiler)
// Tokenizers
var noFlipSingleTokenizer = new Tokenizer( noFlipSingleRegExp, noFlipSingleToken ),
noFlipClassTokenizer = new Tokenizer( noFlipClassRegExp, noFlipClassToken ),
commentTokenizer = new Tokenizer( commentReg... | javascript | {
"resource": ""
} | |
q49873 | tryToSplit | train | function tryToSplit(value) {
if (value.match(HAS_SEMICOLON_SEPARATOR)) {
value = value.replace(/\\,/g, ',');
return splitValue(value, ';');
} else if (value.match(HAS_COMMA_SEPARATOR)) {
value = value.replace(/\\;/g, ';');
return splitValue(value, ',');
} else {
retur... | javascript | {
"resource": ""
} |
q49874 | convert | train | function convert (message) {
const obj = {}
const lines = message.toString().trim().split('\r\n')
if (lines && lines[0]) {
obj.status = lines[0]
for (const line of lines) {
const fields = line.split(': ')
if (fields.length === 2) {
obj[fields[0].toLowerCase()] = fields[1]
}
}... | javascript | {
"resource": ""
} |
q49875 | keyOptions | train | function keyOptions (key, options) {
const _key = options._key == null
? key
: options._key + '.' + key
return Object.assign({}, options, { _key: _key })
} | javascript | {
"resource": ""
} |
q49876 | idOptions | train | function idOptions (id, options) {
const _key = options._key == null
? '[' + id + ']'
: options._key + '[' + id + ']'
return Object.assign({}, options, { _key: _key })
} | javascript | {
"resource": ""
} |
q49877 | tweakWebpackConfig | train | function tweakWebpackConfig(module) {
const { default: webpackConfig = module } = module;
const config = handleWebpackConfig(webpackConfig);
if (!config) {
throw new Error(
'Not found webpack configuration. For multiple configurations in single file you must provide config with target "node".'
);
... | javascript | {
"resource": ""
} |
q49878 | buildExcludeCheck | train | function buildExcludeCheck (transpileDependencies = []) {
const dependencyChecks = transpileDependencies.map((dependency) => (
new RegExp(`node_modules.${dependency}`)
))
// see: https://webpack.js.org/configuration/module/#condition
return function (assetPath) {
const shouldTranspile = dependencyCheck... | javascript | {
"resource": ""
} |
q49879 | vimeo | train | function vimeo(str) {
if (str.indexOf('#') > -1) {
str = str.split('#')[0];
}
if (str.indexOf('?') > -1 && str.indexOf('clip_id=') === -1) {
str = str.split('?')[0];
}
var id;
var arr;
if (/https?:\/\/vimeo\.com\/[0-9]+$|https?:\/\/player\.vimeo\.com\/video\/[0-9]+$|https?:\/\/vimeo\.com\/channels|groups|a... | javascript | {
"resource": ""
} |
q49880 | vine | train | function vine(str) {
var regex = /https:\/\/vine\.co\/v\/([a-zA-Z0-9]*)\/?/;
var matches = regex.exec(str);
return matches && matches[1];
} | javascript | {
"resource": ""
} |
q49881 | youtube | train | function youtube(str) {
// shortcode
var shortcode = /youtube:\/\/|https?:\/\/youtu\.be\//g;
if (shortcode.test(str)) {
var shortcodeid = str.split(shortcode)[1];
return stripParameters(shortcodeid);
}
// /v/ or /vi/
var inlinev = /\/v\/|\/vi\//g;
if (inlinev.test(str)) {
var inlineid = str.split(inline... | javascript | {
"resource": ""
} |
q49882 | videopress | train | function videopress(str) {
var idRegex;
if (str.indexOf('embed') > -1) {
idRegex = /embed\/(\w{8})/;
return str.match(idRegex)[1];
}
idRegex = /\/v\/(\w{8})/;
var match = str.match(idRegex);
if (match && match.length > 0) {
return str.match(idRegex)[1];
}
return undefined;
} | javascript | {
"resource": ""
} |
q49883 | train | function (name) {
(Array.isArray(this._pending) ? this._pending : (this._pending = [])).push(arguments);
this.emit(DISPATCHQUEUE_EVENT, name);
} | javascript | {
"resource": ""
} | |
q49884 | train | function() {
const packages = [
{
name: 'ember-auto-import',
target: getDependencyVersion(pkg, 'ember-auto-import'),
},
{
name: 'react',
target: getPeerDependencyVersion(pkg, 'react'),
},
{
name: 'react-dom',
target: getPeerDependencyVers... | javascript | {
"resource": ""
} | |
q49885 | train | function () {
this.input = new YASMIJ.Input();
this.output = new YASMIJ.Output();
this.tableau = new YASMIJ.Tableau();
this.state = null;
} | javascript | {
"resource": ""
} | |
q49886 | train | function(msg){
var logs = document.getElementById("logs");
logs.innerHTML += Funcs.util.getTimeStamp() + ": " + msg + "\n";
} | javascript | {
"resource": ""
} | |
q49887 | train | function(){
return {
type : document.getElementById("problemType").value,
objective : document.getElementById("problemObjective").value,
constraints : $(".input_constraint").filter(function(){
return /\w/.test( $(this).val() );
}).map(function(){
return $(this).val();
}).toArray()
};
} | javascript | {
"resource": ""
} | |
q49888 | react | train | function react(h) {
var node = h && h('div')
return Boolean(
node && ('_owner' in node || '_store' in node) && node.key === null
)
} | javascript | {
"resource": ""
} |
q49889 | crawl | train | function crawl(callback, callbackArg, options) {
options || (options = {});
if (callback == 'custom') {
var isCustom = true;
} else {
isCustom = false;
callback = filters[callback];
}
var data,
index,
pool,
pooled,
queue,
... | javascript | {
"resource": ""
} |
q49890 | log | train | function log() {
var defaultCount = 2,
console = isHostType(context, 'console') && context.console,
document = isHostType(context, 'document') && context.document,
phantom = isHostType(context, 'phantom') && context.phantom,
JSON = isHostType(context, 'JSON') && _.isFunctio... | javascript | {
"resource": ""
} |
q49891 | train | function(key, value, expiration) {
// set item
var ret = this._storage.setItem(key, value);
// set expiration timestamp (only if defined)
if (expiration) {
this.updateExpiration(key, expiration);
}
// return set value return valu... | javascript | {
"resource": ""
} | |
q49892 | train | function(key) {
// get value and time left
var ret = {
value: this._storage.getItem(key),
timeLeft: this.getTimeLeft(key),
};
// set if expired
ret.isExpired = ret.timeLeft !== null && ret.timeLeft <= 0;
// return... | javascript | {
"resource": ""
} | |
q49893 | train | function(key) {
// try to fetch expiration time for key
var expireTime = parseInt(this._storage.getItem(this._expiration_key_prefix + key));
// if got expiration time return how much left to live
if (expireTime && !isNaN(expireTime)) {
return expireTime... | javascript | {
"resource": ""
} | |
q49894 | train | function(key, val, expiration)
{
// special case - make sure not undefined, because it would just write "undefined" and crash on reading.
if (val === undefined) {
throw new Error("Cannot set undefined value as JSON!");
}
// set stringified value
... | javascript | {
"resource": ""
} | |
q49895 | train | function(key)
{
// get value
var val = this.getItem(key);
// if null, return null
if (val === null) {
return null;
}
// parse and return value
return JSON.parse(val);
} | javascript | {
"resource": ""
} | |
q49896 | train | function(callback) {
// first check if storage define a 'keys()' function. if it does, use it
if (typeof this._storage.keys === "function") {
var keys = this._storage.keys();
for (var i = 0; i < keys.length; ++i) {
callback(keys[i]);
... | javascript | {
"resource": ""
} | |
q49897 | ContextController | train | function ContextController(context) {
const _t = this;
this._view = null;
this.context = context;
/**
* @package
* @type {!Array.<ZxQuery>}
**/
this._fieldCache = [];
// Interface methods
/** @type {function} */
this.init = null;
/** @type {function} */
this.c... | javascript | {
"resource": ""
} |
q49898 | TaskQueue | train | function TaskQueue(listener) {
const _t = this;
_t._worker = null;
_t._taskList = [];
_t._requests = [];
if (listener == null) {
listener = function() { };
}
_t.taskQueue = function(tid, fn, pri) {
_t._taskList.push({
tid: tid,
fn: fn,
stat... | javascript | {
"resource": ""
} |
q49899 | ZxQuery | train | function ZxQuery(element) {
/** @protected */
this._selection = [];
if (typeof element === 'undefined') {
element = document.documentElement;
}
if (element instanceof ZxQuery) {
return element;
} else if (element instanceof HTMLCollection || element instanceof NodeList) {
... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.