_id stringlengths 2 6 | title stringlengths 0 58 | partition stringclasses 3
values | text stringlengths 52 373k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q42900 | train | function (is_ignore_errors) {
var file_paths = [];
// root of dependence source directory
file_paths.push('./commands.json');
// root of denhub-device directory
file_paths.push(__dirname + '/../commands.json');
var file = null;
for (var i = 0, l = file_paths.length; i < l; i++) {
try {
file = re... | javascript | {
"resource": ""
} | |
q42901 | train | function (str) {
var self = this;
if ('i' !== 'I'.toLowerCase()) {
// Thanks for http://qiita.com/niusounds/items/fff91f3f236c31ca910f
return str.replace(/[a-z]/g, function(ch) {
return String.fromCharCode(ch.charCodeAt(0) & ~32);
});
}
return str.toUpperCase();
} | javascript | {
"resource": ""
} | |
q42902 | train | function (obj, var_type) {
var text_class = Object.prototype.toString.call(obj).slice(8, -1);
return (text_class == var_type);
} | javascript | {
"resource": ""
} | |
q42903 | train | function(paramd) {
var self = this
paramd = defaults(paramd, {
iri: "http://data.sparkfun.com"
})
self.iri = paramd.iri
} | javascript | {
"resource": ""
} | |
q42904 | train | function(paramd, defaultd) {
if (paramd === undefined) {
return defaultd
}
for (var key in defaultd) {
var pvalue = paramd[key]
if (pvalue === undefined) {
paramd[key] = defaultd[key]
}
}
return paramd;
} | javascript | {
"resource": ""
} | |
q42905 | train | function (customEvent, callback, filter, prepend) {
return Event.after(customEvent, callback, this, filter, prepend);
} | javascript | {
"resource": ""
} | |
q42906 | train | function (customEvent, callback, filter, prepend) {
return Event.before(customEvent, callback, this, filter, prepend);
} | javascript | {
"resource": ""
} | |
q42907 | setBox | train | function setBox(){
if(my.container){
my.box = {
x: 0,
y: 0,
width: my.container.clientWidth,
height: my.container.clientHeight
};
}
} | javascript | {
"resource": ""
} |
q42908 | aliasesInLayout | train | function aliasesInLayout(layout, sizes){
return Object.keys(computeLayout(layout, sizes, {
width: 100,
height: 100
}));
} | javascript | {
"resource": ""
} |
q42909 | parseParams | train | function parseParams(params, init) {
return reduce(params, function(obj, param) {
var parts = param.split(/ *= */);
var key = removeQuote(parts[0]);
obj[key] = removeQuote(parts[1]);
return obj;
}, init);
} | javascript | {
"resource": ""
} |
q42910 | CompileModules | train | function CompileModules(inputTree, options) {
this.setInputTree(inputTree);
this.setInputFiles(options.inputFiles);
this.setResolvers(options.resolvers || []);
this.setOutput(options.output);
this.setFormatter(options.formatter);
if (options.output) {
this.description = 'CompileModules (' + options.o... | javascript | {
"resource": ""
} |
q42911 | ObfuscatingStorageWrapper | train | function ObfuscatingStorageWrapper(storage) {
var SECRET_KEY_KEY = "___XX";
var wellKnownKey = "ce56c9aa-d287-4e7c-b9d5-edca7a985487";
function getSecretKey() {
var secretKeyName = scrambleKey(SECRET_KEY_KEY, wellKnownKey);
var secretKey = storage.getItem(secretKeyName);
if (secret... | javascript | {
"resource": ""
} |
q42912 | phaserShimDebug | train | function phaserShimDebug(source) {
this.cacheable && this.cacheable();
source = source.replace(/(var\s+ui\s*=\s*require\('\.\/util\/ui'\))/, 'var Phaser = _Phaser; $1');
source = '(function () { var _Phaser = require("phaser").Phaser;\n\n' + source + '\n\n}());';
return source;
} | javascript | {
"resource": ""
} |
q42913 | retry | train | function retry(err) {
if (currentAttempt >= retryCount) {
return callback(err, null, currentAttempt);
}
currentAttempt += 1;
// Since the currentAttempt starts at 1 and it was just incremented
// currentAttempt - 2 will be the actual timeout index.
return setTimeout(attempt, timeouts[cur... | javascript | {
"resource": ""
} |
q42914 | make | train | function make(component, config) {
var Constructor, Subclass,
conf = config || {};
// Config exists as a way to create pass a set of derived options. In the original use case a function was created
// to parse the DOM and pass information to the component at the time of creation.
// Allow the $el... | javascript | {
"resource": ""
} |
q42915 | emitEvents | train | function emitEvents(stream) {
//if emitEvents gets called while in emitEvents we don't want to screw up the order
if (stream._emittingMatches) {
return;
}
var matches = stream.matches,
i = matches.length;
stream.matches = [];
stream._emittingMatch... | javascript | {
"resource": ""
} |
q42916 | handleData | train | function handleData(stream, asString, data, dataLimit) {
var dataLen = data.length,
i = dataLen,
trailingDataIndex = -1, //index of data after the last delimiter match in data
lastMatchIndex = 0,
matchLimit = dataLimit || Infinity,
len = 0;
/... | javascript | {
"resource": ""
} |
q42917 | train | function (pkg, options) {
var settingsFile = new SettingsFile(pkg, options);
var save = settingsFile.save;
settingsFile.save = _.bind(function (config) {
return save.call(settingsFile, config)
.then(function () {
client.emit('config.global-changed', {
app: pkg,
... | javascript | {
"resource": ""
} | |
q42918 | Rule | train | function Rule(lhs, rhs, valuator) {
let arr = [];
if (!rhs || rhs.length === 0) {
throw new Error('Rule does not produce anything');
}
arr.push.apply(arr, rhs);
arr.lhs = lhs;
Object.defineProperty(arr, 'lhs', { value: lhs });
Object.defineProperty(arr, 'evaluate', {
value: (values) => (valuator... | javascript | {
"resource": ""
} |
q42919 | Sym | train | function Sym(name) {
let symbol = {};
symbol.__proto__ = Sym.prototype;
symbol.name = name;
return symbol;
} | javascript | {
"resource": ""
} |
q42920 | _getMatches | train | function _getMatches(character, modifiers, e, sequenceName, combination, level) {
var i,
callback,
matches = [],
action = e.type;
// if there are no events related to this keycode
if (!this._callbacks[character]) {
return [];
}
// if a modifier key... | javascript | {
"resource": ""
} |
q42921 | _getReverseMap | train | function _getReverseMap() {
if (!this._REVERSE_MAP) {
this._REVERSE_MAP = {};
for (var key in _MAP) {
// pull out the numeric keypad from here cause keypress should
// be able to detect the keys from the character
if (key > 95 && key < 112) {
continue;
}
... | javascript | {
"resource": ""
} |
q42922 | _bindSequence | train | function _bindSequence(combo, keys, callback, action) {
var that = this;
// start off by adding a sequence level record for this combination
// and setting the level to 0
this._sequenceLevels[combo] = 0;
/**
* callback to increase the sequence level for this sequence and reset
* all oth... | javascript | {
"resource": ""
} |
q42923 | _increaseSequence | train | function _increaseSequence(nextAction) {
return function() {
that._nextExpectedAction = nextAction;
++that._sequenceLevels[combo];
_resetSequenceTimer.call(that);
};
} | javascript | {
"resource": ""
} |
q42924 | _callbackAndReset | train | function _callbackAndReset(e) {
_fireCallback.call(this, callback, e, combo);
// we should ignore the next key up if the action is key down
// or keypress. this is so if you finish a sequence and
// release the key the final key will not trigger a keyup
if (action !== 'keyup') {
... | javascript | {
"resource": ""
} |
q42925 | train | function( languageCode, defaultLanguage, callback ) {
// If no languageCode - fallback to browser or default.
// If languageCode - fallback to no-localized version or default.
if ( !languageCode || !CKEDITOR.lang.languages[ languageCode ] )
languageCode = this.detect( defaultLanguage, languageCode );
v... | javascript | {
"resource": ""
} | |
q42926 | train | function(title, obj) {
if (arguments.length == 2) {
this.msg(title);
} else {
obj = title;
}
doLog(generalUtils.getProperties(obj));
} | javascript | {
"resource": ""
} | |
q42927 | split | train | function split(url) {
assert.equal(typeof url, 'string', 'url-querystring: url should be a string');
var res = {};
var nw = url.split('?');
res.url = nw[0];
res.qs = nw.length == 2
? qs.parse(nw[1])
: {};
return res;
} | javascript | {
"resource": ""
} |
q42928 | dirExist | train | function dirExist(dirName) {
return new Promise((resolve, reject) => {
fs.stat(dirName, (err, stats) => {
if (err === null && stats.isDirectory()) {
resolve(dirName);
} else {
resolve(false);
}
});
});
} | javascript | {
"resource": ""
} |
q42929 | Identity | train | function Identity(userID, passphrase, keyPair) {
if (!(this instanceof Identity)) {
return new Identity(userID, passphrase, keyPair);
}
assert(typeof userID === 'string', 'Invalid userID supplied');
assert(typeof passphrase === 'string', 'Invalid passphrase supplied');
this._publicKeyArmored = keyPair.p... | javascript | {
"resource": ""
} |
q42930 | extend | train | function extend(x, y){
for(var key in y) {
if (y.hasOwnProperty(key)) {
x[key] = y[key];
}
}
return x;
} | javascript | {
"resource": ""
} |
q42931 | train | function(mongo_host, db, collection) {
var arrayMongo = function() {
};
arrayMongo.prototype = Array.prototype;
extend(arrayMongo.prototype, {
/**
* Store the parameters
*/
host: function() {
return mongo_host;
},
db: function() {
... | javascript | {
"resource": ""
} | |
q42932 | pwCipher | train | function pwCipher(string) {
if(string) {
if ( typeof pw !== 'string' || pw.length < 8 ) {
throw new Error('Please set a password with 8 or ' +
'more chars on process.env.CIPHER_UTIL_PW!');
}
if ( typeof algo !== 'string' || algo.length <... | javascript | {
"resource": ""
} |
q42933 | pwDecipher | train | function pwDecipher(string) {
if(string) {
if ( typeof pw !== 'string' || pw.length < 8 ) {
throw new Error('Please set a password with 8 or ' +
'more chars on process.env.CIPHER_UTIL_PW!');
}
if ( typeof algo !== 'string' || algo.length... | javascript | {
"resource": ""
} |
q42934 | bundle | train | function bundle(entryPoint, buildContext, opts) {
if (!opts) {
opts = {};
}
if (!opts.outputFileName) {
opts.outputFileName = 'index.js';
}
if (!opts.destPath) {
opts.destPath = buildContext.destPath;
}
if (opts.rev !== false) {
opts.rev = true;
}
var shouldUglify = false;
var con... | javascript | {
"resource": ""
} |
q42935 | is | train | function is(obj, name) {
if (typeof name !== 'string') {
throw new TypeError('expected name to be a string');
}
utils.define(obj, 'is' + utils.pascal(name), true);
utils.define(obj, '_name', name);
} | javascript | {
"resource": ""
} |
q42936 | beforeParse | train | function beforeParse(e)
{
var namespace = e.source.match(rgxNamespace);
var className = e.source.match(rgxClassName);
// Fix members not showing up attached to class
if (namespace && className)
{
// console.log(`${namespace[1]}.${className[2]}`);
// R... | javascript | {
"resource": ""
} |
q42937 | Suite | train | function Suite(title, ctx) {
this.title = title;
this.ctx = ctx;
this.suites = [];
this.tests = [];
this.pending = false;
this._beforeEach = [];
this._beforeAll = [];
this._afterEach = [];
this._afterAll = [];
this.root = !title;
this._timeout = 2000;
this._slow = 75;
this._bail = false;
} | javascript | {
"resource": ""
} |
q42938 | unbox | train | function unbox(value){
if (value instanceof ResType) return when(value, unbox)
if (value && typeof value == 'object') return unboxAll(value)
return value
} | javascript | {
"resource": ""
} |
q42939 | useGatewayAuthentication | train | function useGatewayAuthentication(req) {
// can be set on request if via application supplied callback
if (req.useGateway == true) { return true; }
// otherwise via query parameter
var origUrl = req.originalUrl;
var useGateway = false;
var idx = origUrl.indexOf(gatewayParameter);
if (idx >= 0) {
useG... | javascript | {
"resource": ""
} |
q42940 | stripGatewayAuthenticationParameter | train | function stripGatewayAuthenticationParameter(aUrl) {
if (aUrl.query && aUrl.query.useGateway) {
delete aUrl.query.useGateway;
}
if (aUrl.query.nextUrl) {
var theNextUrl = decodeURIComponent(aUrl.query.nextUrl);
aUrl.query.nextUrl = decodeURIComponent(theNextUrl);
}
var theUrl = url.format(aUrl);
... | javascript | {
"resource": ""
} |
q42941 | train | function ( h )
{ getData ( h, true )
.then
( function ( data )
{ if ( h.readValue == data )
{ // same. ignore
}
else
{ // console.log ( `onChangedPath ( "${h.path}" ) ` )
h.evalValue = null
h.readValue = data
// reload
let callbacks = h.callbacks
f... | javascript | {
"resource": ""
} | |
q42942 | train | function ( path, base )
{ let filename
let start = path.substr ( 0, 2 )
if ( path.charAt ( 0 ) === '/' )
{ // absolute path
filename = path
}
else if ( start == './' || start == '..' || path == '.' )
{ filename = lpath.resolve ( base, path )
}
else
{ // funky node_modules path not supported
t... | javascript | {
"resource": ""
} | |
q42943 | train | function ( path, base )
{ let start = path.substr ( 0, 2 )
let paths
if ( start != './' && start != '..' )
{ // absolute or funky node_modules require
paths = module.paths
}
else
{ paths = [ base ]
}
let filename = findPath ( path, paths )
if ( !filename )
{ throw new Error ( `Cannot find path ... | javascript | {
"resource": ""
} | |
q42944 | train | function(date) {
if (_.isDate(date)) {
this._date = date.toSerialNumber();
} else if (_.isNumber(date)) {
this._date = date;
} else {
throw new CError('wrong date type').log();
}
} | javascript | {
"resource": ""
} | |
q42945 | train | function(password) {
// empty password not allowed
if (password) {
var hmac = forge.hmac.create();
hmac.start('sha256', SECRET);
hmac.update(password);
this._password = password;
this._passwordHash = hmac.digest().toHex();
}
} | javascript | {
"resource": ""
} | |
q42946 | find | train | function find(key, target, opts) {
opts = opts || {};
var path = []
, o = target, i, k, p
, re = opts.re = opts.re || /\./
, parts = key.split(re);
for(i =0;i < parts.length;i++) {
k = parts[i];
p = o;
if(opts.create && o[k] === undefined) o[k] = {};
o = o[k];
path.push(k);
if(... | javascript | {
"resource": ""
} |
q42947 | camelToSnake | train | function camelToSnake( string ) {
return string.replace( ptnCamel, ( all, predecessor, match ) => predecessor + "_" + match.toLocaleLowerCase() );
} | javascript | {
"resource": ""
} |
q42948 | camelToKebab | train | function camelToKebab( string ) {
return string.replace( ptnCamel, ( all, predecessor, match ) => predecessor + "-" + match.toLocaleLowerCase() );
} | javascript | {
"resource": ""
} |
q42949 | snakeToCamel | train | function snakeToCamel( string ) {
return string.replace( ptnSnake, ( all, predecessor, match ) => predecessor + match.toLocaleUpperCase() );
} | javascript | {
"resource": ""
} |
q42950 | snakeToKebab | train | function snakeToKebab( string ) {
return string.replace( ptnSnake, ( all, predecessor, match ) => predecessor + "-" + match );
} | javascript | {
"resource": ""
} |
q42951 | kebabToCamel | train | function kebabToCamel( string ) {
return string.replace( ptnKebab, ( all, predecessor, match ) => predecessor + match.toLocaleUpperCase() );
} | javascript | {
"resource": ""
} |
q42952 | kebabToPascal | train | function kebabToPascal( string ) {
const camel = kebabToCamel( string );
return camel.slice( 0, 1 ).toUpperCase() + camel.slice( 1 );
} | javascript | {
"resource": ""
} |
q42953 | kebabToSnake | train | function kebabToSnake( string ) {
return string.replace( ptnKebab, ( all, predecessor, match ) => predecessor + "_" + match );
} | javascript | {
"resource": ""
} |
q42954 | CodecConfiguration | train | function CodecConfiguration(codecConfigurationDict){
if(!(this instanceof CodecConfiguration))
return new CodecConfiguration(codecConfigurationDict)
// Check codecConfigurationDict has the required fields
checkType('String', 'codecConfigurationDict.name', codecConfigurationDict.name, {required: true});
che... | javascript | {
"resource": ""
} |
q42955 | DefaultHandle | train | function DefaultHandle(done, req, res, parsedUrl) {
this.res = res;
this.res.once('error', this.error.bind(this));
this.req = req;
this.req.once('error', this.error.bind(this));
this.url = parsedUrl;
// If this is the actual constructor call done now
if (this.constructor === DefaultHandle) done(null);
} | javascript | {
"resource": ""
} |
q42956 | varargs | train | function varargs(args) {
var argl = args.length;
var arga;
if (!Array.isArray(args)) {
arga = new Array(argl);
for (var i = 0; i < argl; i++) {
arga[i] = args[i];
}
}
return arga;
} | javascript | {
"resource": ""
} |
q42957 | solveCurveX | train | function solveCurveX(x) {
var t2 = x,
derivative,
x2;
// https://trac.webkit.org/browser/trunk/Source/WebCore/platform/animation
// First try a few iterations of Newton's method -- normally very fast.
// http://en.wikipedia.org/wiki/Newton's_method
for (v... | javascript | {
"resource": ""
} |
q42958 | train | function (name) {
return function (state) {
// Write to output stream
var time = new Date();
self.write(messages[name][state].replace('{pid}', self.pid[name]));
self.write('=== Time: ' + time.toString());
};
} | javascript | {
"resource": ""
} | |
q42959 | ExactPath | train | function ExactPath() {
/**
* Uri to action::method mapping
* @type {Object}
*/
var mapping = {};
/**
* Resolve uri
* @param request
* @returns {*}
*/
this.resolve = function (request) {
var uri = request.url.split('?')[0];
if (mapping[request.method] && mapping[request.method][ur... | javascript | {
"resource": ""
} |
q42960 | train | function(config){
this.options = {
hostname : config.url,
port : 443,
path : '', //override
method : '', //override
auth : config.user + ':' + config.passwd,
headers : config.headers
};
} | javascript | {
"resource": ""
} | |
q42961 | decorateWithSessionsData | train | function decorateWithSessionsData(command, session, options) {
if (!session) {
return;
}
// first apply non-transaction-specific sessions data
const serverSession = session.serverSession;
const inTransaction = session.inTransaction() || isTransactionCommand(command);
const isRetryableWrite = options.wi... | javascript | {
"resource": ""
} |
q42962 | executeWrite | train | function executeWrite(pool, bson, type, opsField, ns, ops, options, callback) {
if (ops.length === 0) throw new MongoError('insert must contain at least one document');
if (typeof options === 'function') {
callback = options;
options = {};
options = options || {};
}
// Split the ns up to get db and... | javascript | {
"resource": ""
} |
q42963 | killCursorCallback | train | function killCursorCallback(err, result) {
if (err) {
if (typeof callback !== 'function') return;
return callback(err);
}
// Result
const r = result.message;
// If we have a timed out query or a cursor that was killed
if ((r.responseFlags & (1 << 0)) !== 0) {
if (typeof callba... | javascript | {
"resource": ""
} |
q42964 | train | function(dependencies) {
var _dependencies = dependencies || {};
var _numberOfOudatedPackages = Object.keys(_dependencies).length;
var _minor = semver.allMinor(dependencies, 'latest');
var _major = semver.allMajor(dependencies, 'latest');
var _patch = semver.allPatch(dependencies... | javascript | {
"resource": ""
} | |
q42965 | resolve_ | train | function resolve_(element, resolve) {
// if element is a fragment, it will load everything
// up to child element
if (element.MaterialFragment) {
element.MaterialFragment.loaded.then(() => {
slice.call(element.querySelectorAll(selClass))
.forEach(element => componentHandler.upgradeEl... | javascript | {
"resource": ""
} |
q42966 | hashchange_ | train | function hashchange_(e) {
if (counterLastMatch > 1) {
counterLastMatch = 0;
throw new Error(`Cannot go back to last matched hash ${e.oldURL}`);
}
// Look for all router3 elements in order
Promise.all(slice
.call(document.querySelectorAll(selClass))
.map(element => {
/**
... | javascript | {
"resource": ""
} |
q42967 | hide_ | train | function hide_(element) {
if (!element.hidden) {
element.hidden = true;
element.style.visibility = 'hidden';
element.style.height = '0px';
element.style.width = '0px';
/**
* Dispatch hide event if URL's fragment matches with a route
* and router.hidden = true
*
... | javascript | {
"resource": ""
} |
q42968 | dispatchShow_ | train | function dispatchShow_(element, detail) {
/**
* Dispatch show event if URL's fragment matches with a route
*
* @event MaterialRouter3#show
* @type {CustomEvent}
* @property {HTMLElement} router - The router that dispatches
* this event
* @property {String} param1
* @proper... | javascript | {
"resource": ""
} |
q42969 | unhide_ | train | function unhide_(element) {
if (element.hidden) {
element.hidden = false;
element.style.visibility = 'visible';
element.style.height = null;
element.style.width = null;
/**
* Dispatch unhide even if URL's fragment matches with a route
* and router.hidden = false
*... | javascript | {
"resource": ""
} |
q42970 | match_ | train | function match_(newHash, parents, hashes) {
parents.push(parents[hashes.length].parentElement.closest(selClass));
hashes.push(parents[hashes.length].getAttribute('hash'));
if (parents[hashes.length]) {
return match_(newHash, parents, hashes);
} else {
return hashes.slice(0, hashes.length).r... | javascript | {
"resource": ""
} |
q42971 | Client | train | function Client(identity) {
if (!(this instanceof Client)) {
return new Client(identity);
}
assert(identity instanceof Identity, 'Invalid identity supplied');
this._identity = identity;
this._podhost = utils.getPodHostFromUserID(this._identity.userID);
this._baseUrl = 'https://' + this._podhost;
thi... | javascript | {
"resource": ""
} |
q42972 | ender | train | function ender(input) {
return signal(function(next) {
var pending = 0
var state = null
return spawn(input, function(item) {
state = item === START ? (pending = pending + 1,
state) :
item === END ? (pending = pending - 1,
pe... | javascript | {
"resource": ""
} |
q42973 | bulkWrite | train | function bulkWrite(coll, operations, options, callback) {
// Add ignoreUndfined
if (coll.s.options.ignoreUndefined) {
options = Object.assign({}, options);
options.ignoreUndefined = coll.s.options.ignoreUndefined;
}
// Create the bulk operation
const bulk =
options.ordered === true || options.ord... | javascript | {
"resource": ""
} |
q42974 | rename | train | function rename(coll, newName, options, callback) {
const Collection = require('../collection');
// Check the collection name
checkCollectionName(newName);
// Build the command
const renameCollection = `${coll.s.dbName}.${coll.s.name}`;
const toCollection = `${coll.s.dbName}.${newName}`;
const dropTarget ... | javascript | {
"resource": ""
} |
q42975 | toPositiveInt | train | function toPositiveInt(num, _default) {
if (isNumeric(num)) {
num = parseInt(num, 10);
} else {
return _default;
}
if (num < 0) {
return _default;
}
return num;
} | javascript | {
"resource": ""
} |
q42976 | validateIODActions | train | function validateIODActions(IOD, IODOpts) {
// Validate IOD action schema
var actionErr = validateAction(IOD, IODOpts.action, IODOpts.params)
if (actionErr) return actionErr
// Validate IOD action required inputs
var inputErr = validateActionInputs(IOD, IODOpts)
if (inputErr) return inputErr
// Validate... | javascript | {
"resource": ""
} |
q42977 | validateIODJob | train | function validateIODJob(IOD, IODOpts) {
var job = IODOpts.job
var errors = []
_.each(job.actions, function(action) {
// Validate every IOD action in job
var err = validateAction(IOD, action.name, action.params)
if (err) return errors.push({
action: action.name,
error: err
})
// Validate e... | javascript | {
"resource": ""
} |
q42978 | create | train | function create(options, cb) {
options.force = (options.force) ? options.force : false;
options.preserve = (options.preserve) ? options.preserve : true;
options.password = getPwHash(options.password);
console.log('Gernerating directories with folling options:\n', options, '\n');
if(options.test) {return;}
//cr... | javascript | {
"resource": ""
} |
q42979 | replace | train | function replace(root, options, callback) {
analyser.readDir(root, options, function(err, files) {
files = _.flatten(files);
_.each(files, function(file){
fs.readFile(file, 'UTF-8', function(err, data) {
if(err) {throw err;}
var i, value;
for(i=0; i<options.values.length; i++) {
value = option... | javascript | {
"resource": ""
} |
q42980 | abs_path | train | function abs_path(file, cwd) {
if(!file || file.length === 0) {
return null;
}
function get_path(p) {
var dir = grunt.file.isPathAbsolute(p) ? "" : (cwd || ".");
return path.join(dir, p);
}
... | javascript | {
"resource": ""
} |
q42981 | format | train | function format(ms) {
if (ms == d) return Math.round(ms / d) + ' day';
if (ms > d) return Math.round(ms / d) + ' days';
if (ms == h) return Math.round(ms / h) + ' hour';
if (ms > h) return Math.round(ms / h) + ' hours';
if (ms == m) return Math.round(ms / m) + ' minute';
if (ms > m) return Math.round(ms / m... | javascript | {
"resource": ""
} |
q42982 | getPartials | train | function getPartials(file, sourcePath, templates, customPartialName, callback) {
const { partials } = templates;
if (file.meta.customLayout === undefined) {
async.nextTick(callback, null, partials);
return;
}
const customLayoutPath = path.join(
sourcePath,
path.resolve(path.sep, file.meta.fileP... | javascript | {
"resource": ""
} |
q42983 | render | train | function render(file, layout, context, partials, callback) {
try {
const data = mustache.render(layout, context, partials);
async.nextTick(callback, null, data);
} catch (error) {
console.error(`${file.path}: Could not render the layout`);
async.nextTick(callback, error);
}
} | javascript | {
"resource": ""
} |
q42984 | wrapFunctions | train | function wrapFunctions(fns, file, files) {
return Object.entries(fns)
.reduce((obj1, [groupName, group]) => {
return Object.assign(obj1, {
[groupName]: Object.entries(group)
.reduce((obj2, [fnName, fn]) => {
return Object.assign(obj2, { [fnName]: fn(file, files) });
}... | javascript | {
"resource": ""
} |
q42985 | train | function (fullPath, autoDefine) {
if (!this.instances[fullPath]) {
this.instances[fullPath] = DevFixturesModule.create({
fullPath: fullPath,
autoDefine: Boolean(autoDefine)
});
}
return this.instances[fullPath];
} | javascript | {
"resource": ""
} | |
q42986 | train | function( obj ) {
var clone;
// Array.
if ( obj && ( obj instanceof Array ) ) {
clone = [];
for ( var i = 0; i < obj.length; i++ )
clone[ i ] = CKEDITOR.tools.clone( obj[ i ] );
return clone;
}
// "Static" types.
if ( obj === null || ( typeof( obj ) != 'object' ) || ( obj instance... | javascript | {
"resource": ""
} | |
q42987 | train | function( str, keepCase ) {
return str.charAt( 0 ).toUpperCase() + ( keepCase ? str.slice( 1 ) : str.slice( 1 ).toLowerCase() );
} | javascript | {
"resource": ""
} | |
q42988 | train | function( property, value, asString ) {
if ( asString )
return cssVendorPrefix + property + ':' + value + ';' + property + ':' + value;
var ret = {};
ret[ property ] = value;
ret[ cssVendorPrefix + property ] = value;
return ret;
} | javascript | {
"resource": ""
} | |
q42989 | train | function( originalFunction, functionBuilder ) {
var newFn = functionBuilder( originalFunction );
newFn.prototype = originalFunction.prototype;
return newFn;
} | javascript | {
"resource": ""
} | |
q42990 | train | function( styleText, nativeNormalize ) {
var props = [],
name,
parsedProps = CKEDITOR.tools.parseCssText( styleText, true, nativeNormalize );
for ( name in parsedProps )
props.push( name + ':' + parsedProps[ name ] );
props.sort();
return props.length ? ( props.join( ';' ) + ';' ) : '';
} | javascript | {
"resource": ""
} | |
q42991 | train | function( styleText, normalize, nativeNormalize ) {
var retval = {};
if ( nativeNormalize ) {
// Injects the style in a temporary span object, so the browser parses it,
// retrieving its final format.
var temp = new CKEDITOR.dom.element( 'span' );
temp.setAttribute( 'style', styleText );
styl... | javascript | {
"resource": ""
} | |
q42992 | train | function( styles, sort ) {
var name,
stylesArr = [];
for ( name in styles )
stylesArr.push( name + ':' + styles[ name ] );
if ( sort )
stylesArr.sort();
return stylesArr.join( '; ' );
} | javascript | {
"resource": ""
} | |
q42993 | train | function( left, right, onlyLeft ) {
var name;
if ( !left && !right )
return true;
if ( !left || !right )
return false;
for ( name in left ) {
if ( left[ name ] != right[ name ] )
return false;
}
if ( !onlyLeft ) {
for ( name in right ) {
if ( left[ name ] != right[ name ]... | javascript | {
"resource": ""
} | |
q42994 | train | function( arr, fillWith ) {
var obj = {};
if ( arguments.length == 1 )
fillWith = true;
for ( var i = 0, l = arr.length; i < l; ++i )
obj[ arr[ i ] ] = fillWith;
return obj;
} | javascript | {
"resource": ""
} | |
q42995 | train | function() {
var domain;
while ( 1 ) {
try {
// Try to access the parent document. It throws
// "access denied" if restricted by the "Same Origin" policy.
domain = window.parent.document.domain;
break;
} catch ( e ) {
// Calculate the value to set to document.domain.
domain ... | javascript | {
"resource": ""
} | |
q42996 | train | function( arr, regexp ) {
for ( var i = 0, l = arr.length; i < l; ++i ) {
if ( arr[ i ].match( regexp ) )
return true;
}
return false;
} | javascript | {
"resource": ""
} | |
q42997 | loadDocument | train | function loadDocument (directory, callback) {
var docPath = path.resolve(directory, '_design.js')
fs.stat(docPath, function (err, stat) {
if (err) return callback.call(null, err);
if (stat.isFile()) {
var document = require(docPath);
return callback.call(null, null, document);
}
return c... | javascript | {
"resource": ""
} |
q42998 | loadAttachments | train | function loadAttachments (doc, directory, callback) {
doc._attachments = doc._attachments || {};
glob('**/*', { cwd: directory }, function (err, files) {
async.each(files, function (file, done) {
if (file.indexOf('_') === 0) return done();
fs.stat(path.join(directory, file), function (err, stat) {
... | javascript | {
"resource": ""
} |
q42999 | push | train | function push (directory, uri, callback) {
var db = nano(uri);
loadDocument(directory, function (err, doc) {
if (err) return callback.call(null, err);
loadAttachments(doc, directory, function (err, doc) {
if (err) return callback.call(null, err);
db.get(doc._id, function (err, body) {
if... | javascript | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.