_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q17500 | toFormat | train | function toFormat (format, options) {
if (is.object(format) && is.string(format.id)) {
format = format.id;
}
if (format === 'jpg') format = 'jpeg';
if (!is.inArray(format, ['jpeg', 'png', 'webp', 'tiff', 'raw'])) {
throw new Error('Unsupported output format ' + format);
}
return this[format](options... | javascript | {
"resource": ""
} |
q17501 | _updateFormatOut | train | function _updateFormatOut (formatOut, options) {
if (!(is.object(options) && options.force === false)) {
this.options.formatOut = formatOut;
}
return this;
} | javascript | {
"resource": ""
} |
q17502 | _setBooleanOption | train | function _setBooleanOption (key, val) {
if (is.bool(val)) {
this.options[key] = val;
} else {
throw new Error('Invalid ' + key + ' (boolean) ' + val);
}
} | javascript | {
"resource": ""
} |
q17503 | tint | train | function tint (rgb) {
const colour = color(rgb);
this.options.tintA = colour.a();
this.options.tintB = colour.b();
return this;
} | javascript | {
"resource": ""
} |
q17504 | toColourspace | train | function toColourspace (colourspace) {
if (!is.string(colourspace)) {
throw new Error('Invalid output colourspace ' + colourspace);
}
this.options.colourspace = colourspace;
return this;
} | javascript | {
"resource": ""
} |
q17505 | _setColourOption | train | function _setColourOption (key, val) {
if (is.object(val) || is.string(val)) {
const colour = color(val);
this.options[key] = [
colour.red(),
colour.green(),
colour.blue(),
Math.round(colour.alpha() * 255)
];
}
} | javascript | {
"resource": ""
} |
q17506 | extract | train | function extract (options) {
const suffix = this.options.width === -1 && this.options.height === -1 ? 'Pre' : 'Post';
['left', 'top', 'width', 'height'].forEach(function (name) {
const value = options[name];
if (is.integer(value) && value >= 0) {
this.options[name + (name === 'left' || name === 'top' ... | javascript | {
"resource": ""
} |
q17507 | trim | train | function trim (threshold) {
if (!is.defined(threshold)) {
this.options.trimThreshold = 10;
} else if (is.number(threshold) && threshold > 0) {
this.options.trimThreshold = threshold;
} else {
throw is.invalidParameterError('threshold', 'number greater than zero', threshold);
}
return this;
} | javascript | {
"resource": ""
} |
q17508 | rotate | train | function rotate (angle, options) {
if (!is.defined(angle)) {
this.options.useExifOrientation = true;
} else if (is.integer(angle) && !(angle % 90)) {
this.options.angle = angle;
} else if (is.number(angle)) {
this.options.rotationAngle = angle;
if (is.object(options) && options.background) {
... | javascript | {
"resource": ""
} |
q17509 | sharpen | train | function sharpen (sigma, flat, jagged) {
if (!is.defined(sigma)) {
// No arguments: default to mild sharpen
this.options.sharpenSigma = -1;
} else if (is.bool(sigma)) {
// Boolean argument: apply mild sharpen?
this.options.sharpenSigma = sigma ? -1 : 0;
} else if (is.number(sigma) && is.inRange(si... | javascript | {
"resource": ""
} |
q17510 | median | train | function median (size) {
if (!is.defined(size)) {
// No arguments: default to 3x3
this.options.medianSize = 3;
} else if (is.integer(size) && is.inRange(size, 1, 1000)) {
// Numeric argument: specific sigma
this.options.medianSize = size;
} else {
throw new Error('Invalid median size ' + size)... | javascript | {
"resource": ""
} |
q17511 | blur | train | function blur (sigma) {
if (!is.defined(sigma)) {
// No arguments: default to mild blur
this.options.blurSigma = -1;
} else if (is.bool(sigma)) {
// Boolean argument: apply mild blur?
this.options.blurSigma = sigma ? -1 : 0;
} else if (is.number(sigma) && is.inRange(sigma, 0.3, 1000)) {
// Num... | javascript | {
"resource": ""
} |
q17512 | flatten | train | function flatten (options) {
this.options.flatten = is.bool(options) ? options : true;
if (is.object(options)) {
this._setColourOption('flattenBackground', options.background);
}
return this;
} | javascript | {
"resource": ""
} |
q17513 | convolve | train | function convolve (kernel) {
if (!is.object(kernel) || !Array.isArray(kernel.kernel) ||
!is.integer(kernel.width) || !is.integer(kernel.height) ||
!is.inRange(kernel.width, 3, 1001) || !is.inRange(kernel.height, 3, 1001) ||
kernel.height * kernel.width !== kernel.kernel.length
) {
// must pass... | javascript | {
"resource": ""
} |
q17514 | threshold | train | function threshold (threshold, options) {
if (!is.defined(threshold)) {
this.options.threshold = 128;
} else if (is.bool(threshold)) {
this.options.threshold = threshold ? 128 : 0;
} else if (is.integer(threshold) && is.inRange(threshold, 0, 255)) {
this.options.threshold = threshold;
} else {
t... | javascript | {
"resource": ""
} |
q17515 | boolean | train | function boolean (operand, operator, options) {
this.options.boolean = this._createInputDescriptor(operand, options);
if (is.string(operator) && is.inArray(operator, ['and', 'or', 'eor'])) {
this.options.booleanOp = operator;
} else {
throw new Error('Invalid boolean operator ' + operator);
}
return t... | javascript | {
"resource": ""
} |
q17516 | recomb | train | function recomb (inputMatrix) {
if (!Array.isArray(inputMatrix) || inputMatrix.length !== 3 ||
inputMatrix[0].length !== 3 ||
inputMatrix[1].length !== 3 ||
inputMatrix[2].length !== 3
) {
// must pass in a kernel
throw new Error('Invalid Recomb Matrix');
}
this.options.recombMatrix = ... | javascript | {
"resource": ""
} |
q17517 | modulate | train | function modulate (options) {
if (!is.plainObject(options)) {
throw is.invalidParameterError('options', 'plain object', options);
}
if ('brightness' in options) {
if (is.number(options.brightness) && options.brightness >= 0) {
this.options.brightness = options.brightness;
} else {
throw is... | javascript | {
"resource": ""
} |
q17518 | findWhereUnwrapped | train | function findWhereUnwrapped(wrapper, predicate, filter = treeFilter) {
return wrapper.flatMap(n => filter(n.getNodeInternal(), predicate));
} | javascript | {
"resource": ""
} |
q17519 | filterWhereUnwrapped | train | function filterWhereUnwrapped(wrapper, predicate) {
return wrapper.wrap(wrapper.getNodesInternal().filter(predicate).filter(Boolean));
} | javascript | {
"resource": ""
} |
q17520 | validateOptions | train | function validateOptions(options) {
const {
lifecycleExperimental,
disableLifecycleMethods,
enableComponentDidUpdateOnSetState,
supportPrevContextArgumentOfComponentDidUpdate,
lifecycles,
} = options;
if (typeof lifecycleExperimental !== 'undefined' && typeof lifecycleExperimental !== 'boolean... | javascript | {
"resource": ""
} |
q17521 | getContextFromWrappingComponent | train | function getContextFromWrappingComponent(wrapper, adapter) {
const rootFinder = deepRender(wrapper, wrapper[ROOT_FINDER], adapter);
if (!rootFinder) {
throw new Error('`wrappingComponent` must render its children!');
}
return {
legacyContext: rootFinder[OPTIONS].context,
providerValues: rootFinder[P... | javascript | {
"resource": ""
} |
q17522 | updatePrimaryRootContext | train | function updatePrimaryRootContext(wrappingComponent) {
const adapter = getAdapter(wrappingComponent[OPTIONS]);
const primaryWrapper = wrappingComponent[PRIMARY_WRAPPER];
const primaryRenderer = primaryWrapper[RENDERER];
const primaryNode = primaryRenderer.getNode();
const {
legacyContext,
providerValu... | javascript | {
"resource": ""
} |
q17523 | nodeMatchesToken | train | function nodeMatchesToken(node, token, root) {
if (node === null || typeof node === 'string') {
return false;
}
switch (token.type) {
/**
* Match every node
* @example '*' matches every node
*/
case UNIVERSAL_SELECTOR:
return true;
/**
* Match against the className prop
... | javascript | {
"resource": ""
} |
q17524 | buildPredicateFromToken | train | function buildPredicateFromToken(token, root) {
return node => token.body.every(bodyToken => nodeMatchesToken(node, bodyToken, root));
} | javascript | {
"resource": ""
} |
q17525 | matchDescendant | train | function matchDescendant(nodes, predicate) {
return uniqueReduce(
(matches, node) => matches.concat(treeFilter(node, predicate)),
flat(nodes.map(childrenOfNode)),
);
} | javascript | {
"resource": ""
} |
q17526 | getEntry | train | function getEntry(knownHashes, url, revision) {
// We're assuming that if the URL contains any of the known hashes
// (either the short or full chunk hash or compilation hash) then it's
// already revisioned, and we don't need additional out-of-band revisioning.
if (!revision || knownHashes.some((hash) => url.i... | javascript | {
"resource": ""
} |
q17527 | getKnownHashesFromAssets | train | function getKnownHashesFromAssets(assetMetadata) {
const knownHashes = new Set();
for (const metadata of Object.values(assetMetadata)) {
knownHashes.add(metadata.hash);
}
return knownHashes;
} | javascript | {
"resource": ""
} |
q17528 | getManifestEntriesFromCompilation | train | function getManifestEntriesFromCompilation(compilation, config) {
const blacklistedChunkNames = config.excludeChunks;
const whitelistedChunkNames = config.chunks;
const {assets, chunks} = compilation;
const {publicPath} = compilation.options.output;
const assetMetadata = generateMetadataForAssets(assets, chu... | javascript | {
"resource": ""
} |
q17529 | getOptionsString | train | function getOptionsString(options = {}) {
let plugins = [];
if (options.plugins) {
// Using libs because JSON.stringify won't handle functions.
plugins = options.plugins.map(stringifyWithoutComments);
delete options.plugins;
}
// Pull handler-specific config from the options object, since they are
... | javascript | {
"resource": ""
} |
q17530 | generateSWString | train | async function generateSWString(config) {
// This check needs to be done before validation, since the deprecated options
// will be renamed.
const deprecationWarnings = checkForDeprecatedOptions(config);
const options = validate(config, generateSWStringSchema);
const {manifestEntries, warnings} = await getF... | javascript | {
"resource": ""
} |
q17531 | runBuildCommand | train | async function runBuildCommand({command, config, watch}) {
try {
const {size, count, warnings} = await workboxBuild[command](config);
for (const warning of warnings) {
logger.warn(warning);
}
logger.log(`The service worker was written to ${config.swDest}\n` +
`${count} files will be prec... | javascript | {
"resource": ""
} |
q17532 | getManifest | train | async function getManifest(config) {
// This check needs to be done before validation, since the deprecated options
// will be renamed.
const deprecationWarnings = checkForDeprecatedOptions(config);
const options = validate(config, getManifestSchema);
const {manifestEntries, count, size, warnings} =
awa... | javascript | {
"resource": ""
} |
q17533 | Seeder | train | function Seeder(knex) {
this.knex = knex;
this.config = this.setConfig(knex.client.config.seeds);
} | javascript | {
"resource": ""
} |
q17534 | JoinClause | train | function JoinClause(table, type, schema) {
this.schema = schema;
this.table = table;
this.joinType = type;
this.and = this;
this.clauses = [];
} | javascript | {
"resource": ""
} |
q17535 | yyyymmddhhmmss | train | function yyyymmddhhmmss() {
const d = new Date();
return (
d.getFullYear().toString() +
padDate(d.getMonth() + 1) +
padDate(d.getDate()) +
padDate(d.getHours()) +
padDate(d.getMinutes()) +
padDate(d.getSeconds())
);
} | javascript | {
"resource": ""
} |
q17536 | SchemaBuilder | train | function SchemaBuilder(client) {
this.client = client;
this._sequence = [];
if (client.config) {
this._debug = client.config.debug;
saveAsyncStack(this, 4);
}
} | javascript | {
"resource": ""
} |
q17537 | Client | train | function Client(config = {}) {
this.config = config;
this.logger = new Logger(config);
//Client is a required field, so throw error if it's not supplied.
//If 'this.dialect' is set, then this is a 'super()' call, in which case
//'client' does not have to be set as it's already assigned on the client prototyp... | javascript | {
"resource": ""
} |
q17538 | SQLite3_DDL | train | function SQLite3_DDL(client, tableCompiler, pragma, connection) {
this.client = client;
this.tableCompiler = tableCompiler;
this.pragma = pragma;
this.tableNameRaw = this.tableCompiler.tableNameRaw;
this.alteredName = uniqueId('_knex_temp_alter');
this.connection = connection;
this.formatter =
client ... | javascript | {
"resource": ""
} |
q17539 | makeTransactor | train | function makeTransactor(trx, connection, trxClient) {
const transactor = makeKnex(trxClient);
transactor.withUserParams = () => {
throw new Error(
'Cannot set user params on a transaction - it can only inherit params from main knex instance'
);
};
transactor.isTransaction = true;
transactor.us... | javascript | {
"resource": ""
} |
q17540 | makeTxClient | train | function makeTxClient(trx, client, connection) {
const trxClient = Object.create(client.constructor.prototype);
trxClient.version = client.version;
trxClient.config = client.config;
trxClient.driver = client.driver;
trxClient.connectionSettings = client.connectionSettings;
trxClient.transacting = true;
tr... | javascript | {
"resource": ""
} |
q17541 | getTable | train | function getTable(trxOrKnex, tableName, schemaName) {
return schemaName
? trxOrKnex(tableName).withSchema(schemaName)
: trxOrKnex(tableName);
} | javascript | {
"resource": ""
} |
q17542 | validateMigrationList | train | function validateMigrationList(migrationSource, migrations) {
const all = migrations[0];
const completed = migrations[1];
const diff = getMissingMigrations(migrationSource, completed, all);
if (!isEmpty(diff)) {
throw new Error(
`The migration directory is corrupt, the following files are missing: ${d... | javascript | {
"resource": ""
} |
q17543 | findAccessibleSync | train | function findAccessibleSync (logprefix, dir, candidates) {
for (var next = 0; next < candidates.length; next++) {
var candidate = path.resolve(dir, candidates[next])
try {
var fd = fs.openSync(candidate, 'r')
} catch (e) {
// this candidate was not found or not readable, do nothing
... | javascript | {
"resource": ""
} |
q17544 | findPython | train | function findPython() {
const SKIP=0, FAIL=1
const toCheck = [
{
before: () => {
if (!this.configPython) {
this.addLog(
'Python is not set from command line or npm configuration')
return SKIP
}
this.addLog('checking Python explici... | javascript | {
"resource": ""
} |
q17545 | checkExecPath | train | function checkExecPath (execPath, errorCallback) {
this.log.verbose(`- executing "${execPath}" to get version`)
this.run(execPath, this.argsVersion, false, function (err, version) {
// Possible outcomes:
// - Error: executable can not be run (likely meaning the command wasn't
// a Python exe... | javascript | {
"resource": ""
} |
q17546 | run | train | function run(exec, args, shell, callback) {
var env = extend({}, this.env)
env.TERM = 'dumb'
const opts = { env: env, shell: shell }
this.log.silly('execFile: exec = %j', exec)
this.log.silly('execFile: args = %j', args)
this.log.silly('execFile: opts = %j', opts)
try {
this.execFile(... | javascript | {
"resource": ""
} |
q17547 | cb | train | function cb (err) {
if (cb.done) return
cb.done = true
if (err) {
log.warn('install', 'got an error, rolling back install')
// roll-back the install if anything went wrong
gyp.commands.remove([ release.versionDir ], function () {
callback(err)
})
} else {
callback(n... | javascript | {
"resource": ""
} |
q17548 | afterTarball | train | function afterTarball () {
if (badDownload) return
if (extractCount === 0) {
return cb(new Error('There was a fatal problem while downloading/extracting the tarball'))
}
log.verbose('tarball', 'done parsing tarball')
var async = 0
if (win) {
// need t... | javascript | {
"resource": ""
} |
q17549 | loadConfigGypi | train | function loadConfigGypi () {
var configPath = path.resolve('build', 'config.gypi')
fs.readFile(configPath, 'utf8', function (err, data) {
if (err) {
if (err.code == 'ENOENT') {
callback(new Error('You must run `node-gyp configure` first!'))
} else {
callback(err)
... | javascript | {
"resource": ""
} |
q17550 | findMsbuild | train | function findMsbuild () {
log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
var notfoundErr = 'Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?'
var cmd = 'reg query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
if (process.ar... | javascript | {
"resource": ""
} |
q17551 | doBuild | train | function doBuild () {
// Enable Verbose build
var verbose = log.levels[log.level] <= log.levels.verbose
if (!win && verbose) {
argv.push('V=1')
}
if (win && !verbose) {
argv.push('/clp:Verbosity=minimal')
}
if (win) {
// Turn off the Microsoft logo on Windows
argv.pu... | javascript | {
"resource": ""
} |
q17552 | inflateOnData | train | function inflateOnData(chunk) {
this[kTotalLength] += chunk.length;
if (
this[kPerMessageDeflate]._maxPayload < 1 ||
this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
) {
this[kBuffers].push(chunk);
return;
}
this[kError] = new RangeError('Max payload size exceeded');
this[kError]... | javascript | {
"resource": ""
} |
q17553 | error | train | function error(ErrorCtor, message, prefix, statusCode) {
const err = new ErrorCtor(
prefix ? `Invalid WebSocket frame: ${message}` : message
);
Error.captureStackTrace(err, error);
err[kStatusCode] = statusCode;
return err;
} | javascript | {
"resource": ""
} |
q17554 | concat | train | function concat(list, totalLength) {
if (list.length === 0) return EMPTY_BUFFER;
if (list.length === 1) return list[0];
const target = Buffer.allocUnsafe(totalLength);
let offset = 0;
for (let i = 0; i < list.length; i++) {
const buf = list[i];
buf.copy(target, offset);
offset += buf.length;
}... | javascript | {
"resource": ""
} |
q17555 | _mask | train | function _mask(source, mask, output, offset, length) {
for (let i = 0; i < length; i++) {
output[offset + i] = source[i] ^ mask[i & 3];
}
} | javascript | {
"resource": ""
} |
q17556 | _unmask | train | function _unmask(buffer, mask) {
// Required until https://github.com/nodejs/node/issues/9006 is resolved.
const length = buffer.length;
for (let i = 0; i < length; i++) {
buffer[i] ^= mask[i & 3];
}
} | javascript | {
"resource": ""
} |
q17557 | toArrayBuffer | train | function toArrayBuffer(buf) {
if (buf.byteLength === buf.buffer.byteLength) {
return buf.buffer;
}
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
} | javascript | {
"resource": ""
} |
q17558 | toBuffer | train | function toBuffer(data) {
toBuffer.readOnly = true;
if (Buffer.isBuffer(data)) return data;
let buf;
if (data instanceof ArrayBuffer) {
buf = Buffer.from(data);
} else if (ArrayBuffer.isView(data)) {
buf = viewToBuffer(data);
} else {
buf = Buffer.from(data);
toBuffer.readOnly = false;
... | javascript | {
"resource": ""
} |
q17559 | viewToBuffer | train | function viewToBuffer(view) {
const buf = Buffer.from(view.buffer);
if (view.byteLength !== view.buffer.byteLength) {
return buf.slice(view.byteOffset, view.byteOffset + view.byteLength);
}
return buf;
} | javascript | {
"resource": ""
} |
q17560 | abortHandshake | train | function abortHandshake(socket, code, message, headers) {
if (socket.writable) {
message = message || STATUS_CODES[code];
headers = {
Connection: 'close',
'Content-type': 'text/html',
'Content-Length': Buffer.byteLength(message),
...headers
};
socket.write(
`HTTP/1.1 ${c... | javascript | {
"resource": ""
} |
q17561 | push | train | function push(dest, name, elem) {
if (dest[name] === undefined) dest[name] = [elem];
else dest[name].push(elem);
} | javascript | {
"resource": ""
} |
q17562 | format | train | function format(extensions) {
return Object.keys(extensions)
.map((extension) => {
let configurations = extensions[extension];
if (!Array.isArray(configurations)) configurations = [configurations];
return configurations
.map((params) => {
return [extension]
.concat(... | javascript | {
"resource": ""
} |
q17563 | tlsConnect | train | function tlsConnect(options) {
options.path = undefined;
options.servername = options.servername || options.host;
return tls.connect(options);
} | javascript | {
"resource": ""
} |
q17564 | abortHandshake | train | function abortHandshake(websocket, stream, message) {
websocket.readyState = WebSocket.CLOSING;
const err = new Error(message);
Error.captureStackTrace(err, abortHandshake);
if (stream.setHeader) {
stream.abort();
stream.once('abort', websocket.emitClose.bind(websocket));
websocket.emit('error', e... | javascript | {
"resource": ""
} |
q17565 | receiverOnConclude | train | function receiverOnConclude(code, reason) {
const websocket = this[kWebSocket];
websocket._socket.removeListener('data', socketOnData);
websocket._socket.resume();
websocket._closeFrameReceived = true;
websocket._closeMessage = reason;
websocket._closeCode = code;
if (code === 1005) websocket.close();
... | javascript | {
"resource": ""
} |
q17566 | receiverOnError | train | function receiverOnError(err) {
const websocket = this[kWebSocket];
websocket._socket.removeListener('data', socketOnData);
websocket.readyState = WebSocket.CLOSING;
websocket._closeCode = err[kStatusCode];
websocket.emit('error', err);
websocket._socket.destroy();
} | javascript | {
"resource": ""
} |
q17567 | receiverOnPing | train | function receiverOnPing(data) {
const websocket = this[kWebSocket];
websocket.pong(data, !websocket._isServer, NOOP);
websocket.emit('ping', data);
} | javascript | {
"resource": ""
} |
q17568 | socketOnClose | train | function socketOnClose() {
const websocket = this[kWebSocket];
this.removeListener('close', socketOnClose);
this.removeListener('end', socketOnEnd);
websocket.readyState = WebSocket.CLOSING;
//
// The close frame might not have been received or the `'end'` event emitted,
// for example, if the socket w... | javascript | {
"resource": ""
} |
q17569 | socketOnEnd | train | function socketOnEnd() {
const websocket = this[kWebSocket];
websocket.readyState = WebSocket.CLOSING;
websocket._receiver.end();
this.end();
} | javascript | {
"resource": ""
} |
q17570 | socketOnError | train | function socketOnError() {
const websocket = this[kWebSocket];
this.removeListener('error', socketOnError);
this.on('error', NOOP);
websocket.readyState = WebSocket.CLOSING;
this.destroy();
} | javascript | {
"resource": ""
} |
q17571 | all | train | function all(array, pred) {
for (let idx = 0, len = array.length; idx < len; idx++) {
if (!pred(array[idx])) {
return false;
}
}
return true;
} | javascript | {
"resource": ""
} |
q17572 | contains | train | function contains(array, item) {
if (array && array.length && item) {
return array.indexOf(item) !== -1;
}
return false;
} | javascript | {
"resource": ""
} |
q17573 | sum | train | function sum(array, fn) {
fn = fn || func.self;
return array.reduce(function(memo, v) {
return memo + fn(v);
}, 0);
} | javascript | {
"resource": ""
} |
q17574 | from | train | function from(collection) {
const result = [];
const length = collection.length;
let idx = -1;
while (++idx < length) {
result[idx] = collection[idx];
}
return result;
} | javascript | {
"resource": ""
} |
q17575 | compact | train | function compact(array) {
const aResult = [];
for (let idx = 0, len = array.length; idx < len; idx++) {
if (array[idx]) { aResult.push(array[idx]); }
}
return aResult;
} | javascript | {
"resource": ""
} |
q17576 | unique | train | function unique(array) {
const results = [];
for (let idx = 0, len = array.length; idx < len; idx++) {
if (!contains(results, array[idx])) {
results.push(array[idx]);
}
}
return results;
} | javascript | {
"resource": ""
} |
q17577 | prev | train | function prev(array, item) {
if (array && array.length && item) {
const idx = array.indexOf(item);
return idx === -1 ? null : array[idx - 1];
}
return null;
} | javascript | {
"resource": ""
} |
q17578 | listDescendant | train | function listDescendant(node, pred) {
const descendants = [];
pred = pred || func.ok;
// start DFS(depth first search) with node
(function fnWalk(current) {
if (node !== current && pred(current)) {
descendants.push(current);
}
for (let idx = 0, len = current.childNodes.length; idx < len; idx+... | javascript | {
"resource": ""
} |
q17579 | isLeftEdgeOf | train | function isLeftEdgeOf(node, ancestor) {
while (node && node !== ancestor) {
if (position(node) !== 0) {
return false;
}
node = node.parentNode;
}
return true;
} | javascript | {
"resource": ""
} |
q17580 | prevPoint | train | function prevPoint(point, isSkipInnerOffset) {
let node;
let offset;
if (point.offset === 0) {
if (isEditable(point.node)) {
return null;
}
node = point.node.parentNode;
offset = position(point.node);
} else if (hasChildren(point.node)) {
node = point.node.childNodes[point.offset - 1... | javascript | {
"resource": ""
} |
q17581 | isSamePoint | train | function isSamePoint(pointA, pointB) {
return pointA.node === pointB.node && pointA.offset === pointB.offset;
} | javascript | {
"resource": ""
} |
q17582 | textRangeToPoint | train | function textRangeToPoint(textRange, isStart) {
let container = textRange.parentElement();
let offset;
const tester = document.body.createTextRange();
let prevContainer;
const childNodes = lists.from(container.childNodes);
for (offset = 0; offset < childNodes.length; offset++) {
if (dom.isText(childNod... | javascript | {
"resource": ""
} |
q17583 | isFontInstalled | train | function isFontInstalled(fontName) {
const testFontName = fontName === 'Comic Sans MS' ? 'Courier New' : 'Comic Sans MS';
const testText = 'mmmmmmmmmmwwwww';
const testSize = '200px';
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = testSize + " '" + tes... | javascript | {
"resource": ""
} |
q17584 | mapValues | train | function mapValues(fn, obj) {
return keys(obj).reduce(function(acc, key) {
acc[key] = fn(obj[key]);
return acc;
}, {});
} | javascript | {
"resource": ""
} |
q17585 | getOffsetElement | train | function getOffsetElement(el) {
return el
? 'offsetTop' in el
? el
: getOffsetElement(el.parentNode)
: document.body;
} | javascript | {
"resource": ""
} |
q17586 | root | train | function root (options$$1, next) {
var url = next(options$$1);
if (isString(options$$1.root) && !/^(https?:)?\//.test(url)) {
url = trimEnd(options$$1.root, '/') + '/' + url;
}
return url;
} | javascript | {
"resource": ""
} |
q17587 | query | train | function query (options$$1, next) {
var urlParams = Object.keys(Url.options.params), query = {}, url = next(options$$1);
each(options$$1.params, function (value, key) {
if (urlParams.indexOf(key) === -1) {
query[key] = value;
}
});
query = Url.params(query);
if (query... | javascript | {
"resource": ""
} |
q17588 | form | train | function form (request) {
if (isFormData(request.body)) {
request.headers.delete('Content-Type');
} else if (isObject(request.body) && request.emulateJSON) {
request.body = Url.params(request.body);
request.headers.set('Content-Type', 'application/x-www-form-urlencoded');
}
} | javascript | {
"resource": ""
} |
q17589 | json | train | function json (request) {
var type = request.headers.get('Content-Type') || '';
if (isObject(request.body) && type.indexOf('application/json') === 0) {
request.body = JSON.stringify(request.body);
}
return function (response) {
return response.bodyText ? when(response.text(), functio... | javascript | {
"resource": ""
} |
q17590 | method | train | function method (request) {
if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) {
request.headers.set('X-HTTP-Method-Override', request.method);
request.method = 'POST';
}
} | javascript | {
"resource": ""
} |
q17591 | header | train | function header (request) {
var headers = assign({}, Http.headers.common,
!request.crossOrigin ? Http.headers.custom : {},
Http.headers[toLower(request.method)]
);
each(headers, function (value, name) {
if (!request.headers.has(name)) {
request.headers.set(name, value);... | javascript | {
"resource": ""
} |
q17592 | Client | train | function Client (context) {
var reqHandlers = [sendRequest], resHandlers = [];
if (!isObject(context)) {
context = null;
}
function Client(request) {
while (reqHandlers.length) {
var handler = reqHandlers.pop();
if (isFunction(handler)) {
var... | javascript | {
"resource": ""
} |
q17593 | Headers | train | function Headers(headers) {
var this$1 = this;
this.map = {};
each(headers, function (value, name) { return this$1.append(name, value); });
} | javascript | {
"resource": ""
} |
q17594 | Response | train | function Response(body, ref) {
var url = ref.url;
var headers = ref.headers;
var status = ref.status;
var statusText = ref.statusText;
this.url = url;
this.ok = status >= 200 && status < 300;
this.status = status || 0;
this.statusText = statusText || '';
this.headers = new Headers(... | javascript | {
"resource": ""
} |
q17595 | Request | train | function Request(options$$1) {
this.body = null;
this.params = {};
assign(this, options$$1, {
method: toUpper(options$$1.method || 'GET')
});
if (!(this.headers instanceof Headers)) {
this.headers = new Headers(this.headers);
}
} | javascript | {
"resource": ""
} |
q17596 | Resource | train | function Resource(url, params, actions, options$$1) {
var self = this || {}, resource = {};
actions = assign({},
Resource.actions,
actions
);
each(actions, function (action, name) {
action = merge({url: url, params: assign({}, params)}, options$$1, action);
resource[... | javascript | {
"resource": ""
} |
q17597 | plugin | train | function plugin(Vue) {
if (plugin.installed) {
return;
}
Util(Vue);
Vue.url = Url;
Vue.http = Http;
Vue.resource = Resource;
Vue.Promise = PromiseObj;
Object.defineProperties(Vue.prototype, {
$url: {
get: function get() {
return options(Vu... | javascript | {
"resource": ""
} |
q17598 | onLocationChange | train | async function onLocationChange(location, action) {
// Remember the latest scroll position for the previous location
scrollPositionsHistory[currentLocation.key] = {
scrollX: window.pageXOffset,
scrollY: window.pageYOffset,
};
// Delete stored scroll position for next page if any
if (action === 'PUSH')... | javascript | {
"resource": ""
} |
q17599 | involuteXbez | train | function involuteXbez(t)
{
// map t (0 <= t <= 1) onto x (where -1 <= x <= 1)
var x = t*2-1;
//map theta (where ts <= theta <= te) from x (-1 <=x <= 1)
var theta = x*(te-ts)/2 + (ts + te)/2;
return Rb*(Math.cos(theta)+theta*Math.sin(theta));
} | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.