_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q7800 | __expand | train | function __expand(bytes) {
// Resize buffer if more space needed
if (length+bytes >= buffer.length) {
var new_buffer = new Uint8Array((length+bytes)*2);
new_buffer.set(buffer);
buffer = new_buffer;
}
length += bytes;
} | javascript | {
"resource": ""
} |
q7801 | __append_utf8 | train | function __append_utf8(codepoint) {
var mask;
var bytes;
// 1 byte
if (codepoint <= 0x7F) {
mask = 0x00;
bytes = 1;
}
// 2 byte
else if (codepoint <= 0x7FF) {
mask = 0xC0;
bytes = 2;
}
// 3 byte
... | javascript | {
"resource": ""
} |
q7802 | __encode_utf8 | train | function __encode_utf8(text) {
// Fill buffer with UTF-8
for (var i=0; i<text.length; i++) {
var codepoint = text.charCodeAt(i);
__append_utf8(codepoint);
}
// Flush buffer
if (length > 0) {
var out_buffer = buffer.subarray(0, length);
... | javascript | {
"resource": ""
} |
q7803 | set | train | function set(prefix, value) {
for (const key of keys(value)) {
const name = prefix ? `${prefix}[${key}]` : key
const field = value[key]
if (isArray(field) || isPlainObject(field)) {
set(name, field)
} else {
if (options.strict && (isBoolean(field) && field === false)) {
... | javascript | {
"resource": ""
} |
q7804 | getValueAt | train | function getValueAt(audioData, t) {
// Convert [0, 1] range to [0, audioData.length - 1]
var index = (audioData.length - 1) * t;
// Determine the start and end points for the summation used by the
// Lanczos interpolation algorithm (see: https://en.wikipedia.org/wiki/Lanczos_resampling... | javascript | {
"resource": ""
} |
q7805 | toSampleArray | train | function toSampleArray(audioBuffer) {
// Track overall amount of data read
var inSamples = audioBuffer.length;
readSamples += inSamples;
// Calculate the total number of samples that should be written as of
// the audio data just received and adjust the size of the output
... | javascript | {
"resource": ""
} |
q7806 | beginAudioCapture | train | function beginAudioCapture() {
// Attempt to retrieve an audio input stream from the browser
navigator.mediaDevices.getUserMedia({ 'audio' : true }, function streamReceived(stream) {
// Create processing node which receives appropriately-sized audio buffers
processor = context.... | javascript | {
"resource": ""
} |
q7807 | stopAudioCapture | train | function stopAudioCapture() {
// Disconnect media source node from script processor
if (source)
source.disconnect();
// Disconnect associated script processor node
if (processor)
processor.disconnect();
// Stop capture
if (mediaStream) {
... | javascript | {
"resource": ""
} |
q7808 | __decode_utf8 | train | function __decode_utf8(buffer) {
var text = "";
var bytes = new Uint8Array(buffer);
for (var i=0; i<bytes.length; i++) {
// Get current byte
var value = bytes[i];
// Start new codepoint if nothing yet read
if (bytes_remaining === 0) {
... | javascript | {
"resource": ""
} |
q7809 | extractMediaQuery | train | function extractMediaQuery(props){
var mediaValue = props.length && props[0];
if(Object.keys(fucss.media).indexOf(mediaValue) !== -1){
return props.shift();
}
} | javascript | {
"resource": ""
} |
q7810 | include | train | function include(ckey, file) {
var
match = file.match(INCNAME)
file = match && match[1]
if (file) {
var ch = file[0]
if ((ch === '"' || ch === "'") && ch === file.slice(-1))
file = file.slice(1, -1).trim()
}
if (file) {
result.insert = file
result.once = !!ckey... | javascript | {
"resource": ""
} |
q7811 | normalize | train | function normalize(key, expr) {
if (key.slice(0, 4) !== 'incl') {
expr = expr.replace(/[/\*]\/.*/, '').trim()
// all keywords must have an expression, except `#else/#endif`
if (!expr && key !== 'else' && key !== 'endif') {
emitError('Expected expression for #' + key + ' in @')
re... | javascript | {
"resource": ""
} |
q7812 | checkInBlock | train | function checkInBlock(mask) {
var block = cc.block[last]
if (block && block === (block & mask))
return true
emitError('Unexpected #' + key + ' in @')
return false
} | javascript | {
"resource": ""
} |
q7813 | _repeat | train | function _repeat (source, times) {
var result = "";
for (var i = 0; i < times; i++) {
result += source;
}
return result;
} | javascript | {
"resource": ""
} |
q7814 | unsignEncryptedContent | train | function unsignEncryptedContent(content) {
const newIndex = content.indexOf(SIGNING_KEY);
const oldIndex = content.indexOf(SIGNING_KEY_OLD);
if (newIndex === -1 && oldIndex === -1) {
throw new Error("Invalid credentials content (unknown signature)");
}
return newIndex >= 0
? content.... | javascript | {
"resource": ""
} |
q7815 | compileCss | train | function compileCss(src, dest) {
gulp
.src(src)
.pipe(plumber(config.plumberOptions))
.pipe(gulpif(!config.production, sourcemaps.init()))
.pipe(sass({
outputStyle: config.production ? 'compressed' : 'expanded',
precision: 5
}))
.pipe(postcss(processors))
.pipe(gulpif... | javascript | {
"resource": ""
} |
q7816 | setEnabledStateOfLed | train | function setEnabledStateOfLed(callback) {
var index = 0;
var setEnabledStateOfLedInterval = setInterval(function() {
if (index <= 5) {
dothat.barGraph.setEnabledStateOfLed(index, false);
index++;
} else {
clearInterval(setEnabledStateOfLedInt... | javascript | {
"resource": ""
} |
q7817 | _setIn | train | function _setIn (source, key, value) {
var result = {};
for (var prop in source) {
result[prop] = source[prop];
}
result[key] = value;
return result;
} | javascript | {
"resource": ""
} |
q7818 | getInterceptedXHR | train | function getInterceptedXHR(req) {
var requestPath = req.requestPath;
var interceptedXHRs = interceptXHRMap[requestPath];
var interceptedXHRsObj = {};
var counter = 1;
if (interceptedXHRs != undefined) {
for (var i = 0; i < interceptedXHRs.length; i++) {
... | javascript | {
"resource": ""
} |
q7819 | isFakeRespond | train | function isFakeRespond(req) {
var temp = req.url.toString();
var uniqueID = md5(JSON.stringify(req.body));
if (temp.indexOf("?") >= 0)
req.url = reparsePath(temp);
if (req.method === 'POST' && ((req.url in mockReqRespMap) && (mockReqRespMap[req.url] !== undefined)) &&
... | javascript | {
"resource": ""
} |
q7820 | isInterceptXHR | train | function isInterceptXHR(req) {
if (((req.url in interceptXHRMap) && (interceptXHRMap[req.url] !== undefined)) ||
((req._parsedUrl.pathname in interceptXHRMap) && (interceptXHRMap[req._parsedUrl.pathname] !== undefined))) {
return true;
} else {
return false;
}... | javascript | {
"resource": ""
} |
q7821 | reparsePath | train | function reparsePath(oldpath) {
if (oldpath.indexOf("?") >= 0) {
var vars = oldpath.split("?")[1].split("&");
var result = oldpath.split("?")[0] + '?';
var firstFlag = 0;
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split("=");
... | javascript | {
"resource": ""
} |
q7822 | modelMethod | train | function modelMethod(model, method, data, done) {
model[method](data).then(function(results) {
done(null, results);
})
.catch(function(error) {
// Try again on timeout
if (error.message == "connect ETIMEDOUT") {
modelMethod(model, method, data, done);
return;
}
done(error);
});
} | javascript | {
"resource": ""
} |
q7823 | runQuery | train | function runQuery(connection, query, options, done) {
options = _.isObject(options) ? options :
connection.QueryTypes[options] ? { type: connection.QueryTypes[options] } : {};
connection.query(query, options)
.then(function(results) {
done(null, results);
})
.catch(function(error) {
if ... | javascript | {
"resource": ""
} |
q7824 | mysqlBulkUpsert | train | function mysqlBulkUpsert(model, data) {
var mysql = require("mysql");
var queries = ["SET AUTOCOMMIT = 0"];
// Transform data
_.each(data, function(d) {
var query = "REPLACE INTO " + model.tableName + " ([[COLUMNS]]) VALUES (?)";
query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
query = m... | javascript | {
"resource": ""
} |
q7825 | sqliteBulkUpsert | train | function sqliteBulkUpsert(model, data) {
var queries = ["BEGIN"];
var values = [];
// Transform data
_.each(data, function(d) {
var query = "INSERT OR REPLACE INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
query = query.replace("[[COLUMNS]]", _.keys(d).join(", "));
// Put in ?'s
... | javascript | {
"resource": ""
} |
q7826 | pgsqlBulkUpsert | train | function pgsqlBulkUpsert(model, data) {
var queries = [];
// Transform data
_.each(data, function(d) {
// TODO: Postgres does not have easy UPSERT syntax, the ON CONFLICT UPDATE requires specific columns
var query = "INSERT INTO " + model.tableName + " ([[COLUMNS]]) VALUES ([[VALUES]])";
query = quer... | javascript | {
"resource": ""
} |
q7827 | vacuum | train | function vacuum(connection, done) {
var n = connection.connectionManager.dialectName;
var query;
// Make query based on dialiect
if (n === "mysql" || n === "mariadb" || n === "mysqli") {
query = "SELECT 1";
}
else if (n === "sqlite") {
query = "VACUUM";
}
else if (n === "pgsql" || n === "postgr... | javascript | {
"resource": ""
} |
q7828 | getUriMappers | train | function getUriMappers (serviceLocator) {
var routeDefinitions;
try {
routeDefinitions = serviceLocator.resolveAll('routeDefinition');
} catch (e) {
routeDefinitions = [];
}
return routeDefinitions
.map(route => {
var mapper = routeHelper.compileRoute(route.expression);
return {
... | javascript | {
"resource": ""
} |
q7829 | runPostMapping | train | function runPostMapping (args, uriMappers, location) {
uriMappers.some(mapper => {
if (mapper.expression.test(location.path)) {
args = mapper.map(args);
return true;
}
return false;
});
return args;
} | javascript | {
"resource": ""
} |
q7830 | dotNotation | train | function dotNotation(path) {
if (path instanceof Array) {
return {
path: path,
str: path.join('.')
}
}
if (typeof path !== 'string') {
return;
}
return {
path: path.split('\.'),
str: path
}
} | javascript | {
"resource": ""
} |
q7831 | getPropertyValue | train | function getPropertyValue(obj, path) {
if (path.length === 0 || obj === undefined) {
return undefined;
}
var notation = dotNotation(path);
if (!notation) {
return;
}
path = notation.path;
for (var i = 0; i < path.length; i++) {
obj = obj[path[i]];
if (obj === undefined) {
... | javascript | {
"resource": ""
} |
q7832 | setHiddenProperty | train | function setHiddenProperty(obj, key, value) {
Object.defineProperty(obj, key, {
enumerable: false,
value: value
});
return value;
} | javascript | {
"resource": ""
} |
q7833 | tryToCoverWindow | train | function tryToCoverWindow(code) {
if (typeof window === "object") {
var variables = Object.getOwnPropertyNames(window);
if (!window.hasOwnProperty('window')) {
variables.push('window');
}
var stubDeclarations = '';
variables.forEa... | javascript | {
"resource": ""
} |
q7834 | createCORSRequest | train | function createCORSRequest (method, url) {
var xhr;
xhr = new window.XMLHttpRequest();
if ("withCredentials" in xhr) {
// XHR for Chrome/Firefox/Opera/Safari.
xhr.open(method, url, true);
} else if (window.XDomainRequest) {
// XDomainRequest for IE.... | javascript | {
"resource": ""
} |
q7835 | makePostCorsRequest | train | function makePostCorsRequest (url, data) {
var xhr = createCORSRequest('POST', url, data);
if (typeof _beforeXHRCallback === 'function') {
_beforeXHRCallback(xhr);
}
if ('withCredentials' in xhr) {
xhr.onreadystatechange = function() {
if (xhr.r... | javascript | {
"resource": ""
} |
q7836 | createUriPathMapper | train | function createUriPathMapper (expression, parameters) {
return (uriPath, args) => {
var matches = uriPath.match(expression);
if (!matches || matches.length < 2) {
return args;
}
// start with second match because first match is always
// the whole URI path
matches = matches.splice(1);
... | javascript | {
"resource": ""
} |
q7837 | createUriQueryMapper | train | function createUriQueryMapper (query) {
var parameters = extractQueryParameters(query);
return (queryValues, args) => {
queryValues = queryValues || Object.create(null);
Object.keys(queryValues)
.forEach(queryKey => {
var parameter = parameters[queryKey];
if (!parameter) {
... | javascript | {
"resource": ""
} |
q7838 | createUriQueryValueMapper | train | function createUriQueryValueMapper (expression) {
return value => {
value = value.toString();
var matches = value.match(expression);
if (!matches || matches.length === 0) {
return null;
}
// the value is the second item, the first is a whole string
var mappedValue = matches[matches.leng... | javascript | {
"resource": ""
} |
q7839 | getParameterDescriptor | train | function getParameterDescriptor (parameter) {
var parts = parameter.split(SLASHED_BRACKETS_REG_EXP);
return {
name: parts[0].trim().substring(1)
};
} | javascript | {
"resource": ""
} |
q7840 | extractQueryParameters | train | function extractQueryParameters (query) {
return Object.keys(query.values)
.reduce((queryParameters, name) => {
// arrays in routing definitions are not supported
if (util.isArray(query.values[name])) {
return queryParameters;
}
// escape regular expression characters
var es... | javascript | {
"resource": ""
} |
q7841 | compileStringRouteExpression | train | function compileStringRouteExpression (routeExpression) {
var routeUri = new URI(routeExpression);
routeUri.path = module.exports.removeEndSlash(routeUri.path);
if (!routeUri) {
return null;
}
// escape regular expression characters
var escaped = routeUri.path.replace(
EXPRESSION_ESCAPE_REG_EXP, '\... | javascript | {
"resource": ""
} |
q7842 | toSQLName | train | function toSQLName(input) {
return !input || _.isObject(input) || _.isArray(input) || _.isNaN(input) ? undefined :
input.toString().toLowerCase()
.replace(/\W+/g, " ")
.trim()
.replace(/\s+/g, "_")
.replace(/_+/g, "_")
.substring(0, 64);
} | javascript | {
"resource": ""
} |
q7843 | standardizeInput | train | function standardizeInput(input) {
if ([undefined, null].indexOf(input) !== -1) {
input = null;
}
else if (_.isNaN(input)) {
input = null;
}
else if (_.isString(input)) {
input = input.trim();
// Written empty values
if (["unspecified", "unknown", "none", "null", "empty", ""].indexOf(inpu... | javascript | {
"resource": ""
} |
q7844 | suit | train | function suit(options) {
options = options || {};
// for backwards compatibility with rework-npm < 1.0.0
options.root = options.root || options.dir;
return function (ast, reworkObj) {
reworkObj
// inline imports
.use(inliner({
alias: options.alias,
prefilter: function (css) {
... | javascript | {
"resource": ""
} |
q7845 | train | function(leaveState, event, data) {
// If `data` is a string, it is the destination state of the transition
if (_.isString(data)) data = {enterState: data}
else data = _.clone(data)
if (leaveState !== ANY_STATE && !this._states.hasOwnProperty(leaveState))
this.state(leaveState... | javascript | {
"resource": ""
} | |
q7846 | train | function(name, data) {
if (name === ANY_STATE)
throw new Error('state name "' + ANY_STATE + '" is forbidden')
data = _.clone(data)
data.enter = this._collectMethods((data.enter || []))
data.leave = this._collectMethods((data.leave || []))
this._states[name] = data
... | javascript | {
"resource": ""
} | |
q7847 | train | function() {
var events = _.reduce(_.values(this._transitions), function(memo, transitions) {
return memo.concat(_.keys(transitions))
}, [])
return _.uniq(events)
} | javascript | {
"resource": ""
} | |
q7848 | train | function(event) {
var data, extraArgs, key, transitions = this._transitions
if (transitions.hasOwnProperty((key = this.currentState)) &&
transitions[key].hasOwnProperty(event)) {
data = transitions[key][event]
} else if (transitions.hasOwnProperty(ANY_STATE) &&
tran... | javascript | {
"resource": ""
} | |
q7849 | train | function(data, event) {
var extraArgs = _.toArray(arguments).slice(2),
leaveState = this.currentState,
enterState = data.enterState,
triggers = data.triggers
if (!this.silent)
this.trigger.apply(this, ['leaveState:' + leaveState].concat(extraArgs))
this._callCa... | javascript | {
"resource": ""
} | |
q7850 | train | function(methodNames) {
var methods = [], i, length, method
for (i = 0, length = methodNames.length; i < length; i++) {
// first, check if this is an anonymous function
if (_.isFunction(methodNames[i]))
method = methodNames[i]
else {
// else, get th... | javascript | {
"resource": ""
} | |
q7851 | train | function(cbArray, extraArgs) {
var i, length
for (i = 0, length = cbArray.length; i < length; i++)
cbArray[i].apply(this, extraArgs)
} | javascript | {
"resource": ""
} | |
q7852 | train | function(instance) {
// If this is the first state machine registered in the debugger,
// we create the debugger's html.
if (this.viewsArray.length === 0) {
var container = this.el = $('<div id="backbone-statemachine-debug-container">'+
'<h3>backbone.statemachine: DEBUGGER<... | javascript | {
"resource": ""
} | |
q7853 | basic_medium | train | function basic_medium(req, res, next) {
var auth = basic_small(req);
if (auth !== '') {
if (check(auth, my.hash, my.file) === true) { // check if different
return setHeader(res, 'WWW-Authenticate', my.realms) === true
? end_work(err, next, 401) : null;
}
if (my.agent === ''... | javascript | {
"resource": ""
} |
q7854 | pad | train | function pad(number, size) {
var stringNum = String(number);
while (stringNum.length < (size || 2)) {
stringNum = '0' + stringNum;
}
return stringNum;
} | javascript | {
"resource": ""
} |
q7855 | strCompact | train | function strCompact(str) {
return this.trim(str).replace(/([\r\n\s])+/g, function (match, whitespace) {
return whitespace === ' ' ? whitespace : ' ';
});
} | javascript | {
"resource": ""
} |
q7856 | strReplace | train | function strReplace(search, replace, subject) {
var regex = void 0;
if (validateHelpers.isArray(search)) {
for (var i = 0; i < search.length; i++) {
search[i] = search[i].replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
regex = new RegExp(search[i], 'g... | javascript | {
"resource": ""
} |
q7857 | underscore | train | function underscore(str) {
return str.replace(/[-\s]+/g, '_').replace(/([A-Z\d]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').toLowerCase();
} | javascript | {
"resource": ""
} |
q7858 | camelize | train | function camelize(obj) {
var _this = this;
var _camelize = function _camelize(str) {
str = stringHelpers.underscore(str);
str = stringHelpers.slugifyText(str);
return str.replace(/[_.-\s](\w|$)/g, function (_, x) {
return x.toUpperCase();
... | javascript | {
"resource": ""
} |
q7859 | contains | train | function contains(value, elem) {
if (validateHelpers.isArray(elem)) {
for (var i = 0, len = elem.length; i < len; i += 1) {
if (elem[i] === value) {
return true;
}
}
}
if (validateHelpers.isString(elem)) {
r... | javascript | {
"resource": ""
} |
q7860 | getUrlParameter | train | function getUrlParameter(name, entryPoint) {
entryPoint = !validateHelpers.isString(entryPoint) ? window.location.href : entryPoint.substring(0, 1) === '?' ? entryPoint : '?' + entryPoint;
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&... | javascript | {
"resource": ""
} |
q7861 | resizeImageByRatio | train | function resizeImageByRatio(type, newSize, aspectRatio, decimal) {
if (!validateHelpers.isNumber(newSize) || !validateHelpers.isNumber(aspectRatio)) {
newSize = parseFloat(newSize, 10);
aspectRatio = parseFloat(aspectRatio, 10);
}
var dimensions = {};
decimal = d... | javascript | {
"resource": ""
} |
q7862 | semverCompare | train | function semverCompare(v1, v2) {
var semver = /^v?(?:\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+)(\.(?:[x*]|\d+))?(?:-[\da-z\-]+(?:\.[\da-z\-]+)*)?(?:\+[\da-z\-]+(?:\.[\da-z\-]+)*)?)?)?$/i;
var validate = function validate(version) {
if (!validateHelpers.isString(version)) {
throw new ... | javascript | {
"resource": ""
} |
q7863 | stripTags | train | function stripTags(input, allowed) {
allowed = (((allowed || '') + '').toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // Making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
var commentsAndPhpTags = /<!--[\... | javascript | {
"resource": ""
} |
q7864 | times | train | function times(n, iteratee) {
/** Used as references for various `Number` constants. */
var MAX_SAFE_INTEGER = 9007199254740991;
/** Used as references for the maximum length and index of an array. */
var MAX_ARRAY_LENGTH = 4294967295;
if (n < 1 || n > MAX_SAFE_INTEGER) {
... | javascript | {
"resource": ""
} |
q7865 | unserialize | train | function unserialize(str) {
str = !validateHelpers.isString(str) ? window.location.href : str;
if (str.indexOf('?') < 0) {
return {};
}
str = str.indexOf('?') === 0 ? str.substr(1) : str.slice(str.indexOf('?') + 1);
var query = {};
var parts = str.split('&'... | javascript | {
"resource": ""
} |
q7866 | isArguments | train | function isArguments(value) {
// fallback check is for IE
return toString.call(value) === '[object Arguments]' || value != null && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && 'callee' in value;
} | javascript | {
"resource": ""
} |
q7867 | isArray | train | function isArray(value) {
// check native isArray first
if (Array.isArray) {
return Array.isArray(value);
}
return toString.call(value) === '[object Array]';
} | javascript | {
"resource": ""
} |
q7868 | isEmpty | train | function isEmpty(variable) {
var emptyVariables = {
'undefined': true,
'null': true,
'number': false,
'boolean': false,
'function': false,
'regexp': false,
'date': false,
'error': false
};
var strTyp... | javascript | {
"resource": ""
} |
q7869 | isJson | train | function isJson(str) {
try {
var obj = JSON.parse(str);
return this.isObject(obj);
} catch (e) {/* ignore */}
return false;
} | javascript | {
"resource": ""
} |
q7870 | isNumber | train | function isNumber(value) {
var isNaN = Number.isNaN || window.isNaN;
return typeof value === 'number' && !isNaN(value);
} | javascript | {
"resource": ""
} |
q7871 | isObjectEmpty | train | function isObjectEmpty(obj) {
if (!this.isObject(obj)) {
return false;
}
for (var x in obj) {
if ({}.hasOwnProperty.call(obj, x)) {
return false;
}
}
return true;
} | javascript | {
"resource": ""
} |
q7872 | isSameType | train | function isSameType(value, other) {
var tag = toString.call(value);
if (tag !== toString.call(other)) {
return false;
}
return true;
} | javascript | {
"resource": ""
} |
q7873 | arrayClone | train | function arrayClone(arr) {
var clone = new Array(arr.length);
this._forEach(arr, function (el, i) {
clone[i] = el;
});
return clone;
} | javascript | {
"resource": ""
} |
q7874 | arrayFlatten | train | function arrayFlatten(arr, level) {
var self = this;
var result = [];
var current = 0;
level = level || Infinity;
self._forEach(arr, function (el) {
if (validateHelpers.isArray(el) && current < level) {
result = result.concat(self.arrayFlatten(el, lev... | javascript | {
"resource": ""
} |
q7875 | arraySample | train | function arraySample(arr, num, remove) {
var result = [];
var _num = void 0;
var _remove = void 0;
var single = void 0;
if (validateHelpers.isBoolean(num)) {
_remove = num;
} else {
_num = num;
_remove = remove;
}
if (... | javascript | {
"resource": ""
} |
q7876 | chunk | train | function chunk(array, size) {
size = Math.max(size, 0);
var length = array === null ? 0 : array.length;
if (!length || size < 1) {
return [];
}
var index = 0;
var resIndex = 0;
var result = new Array(Math.ceil(length / size));
while (index <... | javascript | {
"resource": ""
} |
q7877 | cleanArray | train | function cleanArray(array) {
var newArray = [];
for (var i = 0, len = array.length; i < len; i += 1) {
if (array[i]) {
newArray.push(array[i]);
}
}
return newArray;
} | javascript | {
"resource": ""
} |
q7878 | explode | train | function explode(str, separator, limit) {
if (!validateHelpers.isString(str)) {
throw new Error('\'str\' must be a String');
}
var arr = str.split(separator);
if (limit !== undefined && arr.length >= limit) {
arr.push(arr.splice(limit - 1).join(separator));
... | javascript | {
"resource": ""
} |
q7879 | implode | train | function implode(pieces, glue) {
if (validateHelpers.isArray(pieces)) {
return pieces.join(glue || ',');
} else if (validateHelpers.isObject(pieces)) {
var arr = [];
for (var o in pieces) {
if (object.hasOwnProperty(o)) {
arr.push(p... | javascript | {
"resource": ""
} |
q7880 | toNumber | train | function toNumber(value) {
var _this = this;
if (validateHelpers.isArray(value)) {
return value.map(function (a) {
return _this.toNumber(a);
});
}
var number = parseFloat(value);
if (number === undefined) {
return value;
... | javascript | {
"resource": ""
} |
q7881 | extend | train | function extend(obj) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
if (validateHelpers.isObject(obj) && args.length > 0) {
if (Object.assign) {
return Object... | javascript | {
"resource": ""
} |
q7882 | getDescendantProp | train | function getDescendantProp(obj, path) {
if (!validateHelpers.isPlainObject(obj)) {
throw new TypeError('\'obj\' param must be an plain object');
}
return path.split('.').reduce(function (acc, part) {
return acc && acc[part];
}, obj);
} | javascript | {
"resource": ""
} |
q7883 | groupObjectByValue | train | function groupObjectByValue(item, key) {
var camelize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (!validateHelpers.isArray(item)) {
throw new Error('\'item\' must be an array of objects');
}
var grouped = item.reduce(function (r, a) {
... | javascript | {
"resource": ""
} |
q7884 | objectArraySortByValue | train | function objectArraySortByValue(arr, map, key) {
var _this2 = this;
var reverse = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
if (!validateHelpers.isArray(map) || map.length < 1) {
var compare = function compare(a, b, n) {
return _this... | javascript | {
"resource": ""
} |
q7885 | objectToArray | train | function objectToArray(obj) {
if (!validateHelpers.isPlainObject(obj)) {
throw new Error('\'obj\' must be a plain object');
}
return Object.keys(obj).map(function (key) {
return obj[key];
});
} | javascript | {
"resource": ""
} |
q7886 | renameKeys | train | function renameKeys(obj, keysMap) {
if (!validateHelpers.isPlainObject(obj)) {
throw new Error('\'obj\' must be an plain object');
}
return Object.keys(obj).reduce(function (acc, key) {
return _extends({}, acc, defineProperty({}, keysMap[key] || key, obj[key]));
... | javascript | {
"resource": ""
} |
q7887 | getUserLocation | train | function getUserLocation(cache, storage) {
var _this = this;
if (cache) {
this._initLocationStorage(storage);
}
var store = storage.session.get(CONSTANTS.STORAGE_NAME);
/* eslint-disable */
return $.Deferred(function (def) {
/* eslint-enable */
... | javascript | {
"resource": ""
} |
q7888 | filteredRegion | train | function filteredRegion(state) {
var _this2 = this;
var filteredRegion = '';
var _loop = function _loop(region) {
if ({}.hasOwnProperty.call(_this2._regionMap, region)) {
_this2._regionMap[region].some(function (el, i, arr) {
if (stringHelpers.re... | javascript | {
"resource": ""
} |
q7889 | Utilify | train | function Utilify() {
classCallCheck(this, Utilify);
/**
* Version
* @type {String}
*/
this.version = '0.10.1';
/**
* Package name
* @type {String}
*/
this.name = '@UtilifyJS';
/**
* Global Helpers instance
* @type {GlobalHelpers}
*/
this.globalHelpers = new GlobalHelpers();
... | javascript | {
"resource": ""
} |
q7890 | train | function ( target, store, template, options ) {
var ref = [store],
obj, instance;
if ( !( target instanceof Element ) || typeof store !== "object" || !regex.string_object.test( typeof template ) ) {
throw new Error( label.error.invalidArguments );
}
obj = element.create( "ul", {"class": "list", id: s... | javascript | {
"resource": ""
} | |
q7891 | train | function () {
if ( isNaN( this.pageSize ) ) {
throw new Error( label.error.invalidArguments );
}
return number.round( ( !this.filter ? this.total : this.filtered.length ) / this.pageSize, "up" );
} | javascript | {
"resource": ""
} | |
q7892 | train | function (fileName) {
fileName = (fileName || "").toLowerCase();
var validExtensions = ["svg", "cdr", "eps", "ai"],
fileExtension = fileName.substr(fileName.lastIndexOf('.') + 1);
return validExtensions.indexOf(fileExtension) != -1;
} | javascript | {
"resource": ""
} | |
q7893 | train | function(pluginOptions, options) {
options.isFactoryFunctionRun = true;
return new GrawlixPlugin({
name: 'blank-plugin-2',
init: function(opts) {
opts.isLoaded = true;
}
});
} | javascript | {
"resource": ""
} | |
q7894 | train | function(ed25519Sk, callback){
if (typeof callback != 'function') throw new TypeError('callback must be a function');
try {
isValidInput(ed25519Sk, 'ed25519Sk', MiniSodium.crypto_sign_SECRETKEYBYTES);
} catch (e){
callback(e);
return;
}
ed25519Sk = to_hex(ed25519Sk);
var params = [ed25519Sk];
c... | javascript | {
"resource": ""
} | |
q7895 | train | function(str) {
if (str instanceof Uint8Array) return str;
if (!is_hex(str)) {
throw new TypeError("The provided string doesn't look like hex data");
}
var result = new Uint8Array(str.length / 2);
for (var i = 0; i < str.length; i += 2) {
result[i >>> 1] = parseInt(str.substr(i, 2), 16);
... | javascript | {
"resource": ""
} | |
q7896 | buildRouterPath | train | function buildRouterPath(path, prefix) {
if (!prefix) {
prefix = '';
}
if (prefix.length && path === '/') {
return prefix;
}
return prefix + path;
} | javascript | {
"resource": ""
} |
q7897 | compareRouteAndApplyArgs | train | function compareRouteAndApplyArgs (route, request_url, request_method) {
if (route.method !== request_method) {
return false;
}
let template = route.path.split('/');
if (template[0] === '') {
template = template.slice(1); // Slice kills the emptystring before the leading slash
}
let actual = request_url.pat... | javascript | {
"resource": ""
} |
q7898 | applyArg | train | function applyArg(request_url, template_part, actual_part) {
if (typeof(request_url.args) === "undefined") {
request_url.args = {};
}
if (typeof request_url.args !== "object") {
throw new Error("The request url's args have already been defined as a " + typeof request_url.args + " and we expected an object. For ... | javascript | {
"resource": ""
} |
q7899 | getNotificationState | train | function getNotificationState () {
if (process.platform !== 'win32') {
throw new Error('windows-notification-state only works on windows')
}
const QUERY_USER_NOTIFICATION_STATE = [
'',
'QUNS_NOT_PRESENT',
'QUNS_BUSY',
'QUNS_RUNNING_D3D_FULL_SCREEN',
'QUNS_PRESENTATION_MODE',
'QUNS_ACC... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.