id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
56,900 | forfuturellc/svc-fbr | src/lib/db.js | composeAddRemoveGroupMember | function composeAddRemoveGroupMember({ action="add", roles="members" }) {
/**
* Add/Remove user from group
*
* @param {String} username
* @param {String} groupname
* @param {Function} done - done(err)
*/
return function(username, groupname, done) {
return getGroup(groupname, function(getGroupErr, group) {
if (getGroupErr) {
return done(getGroupErr);
}
if (!group) {
return done(new Error(`group '${groupname}' not found`));
}
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
group[roles][action](user.id);
return group.save(done);
});
});
};
} | javascript | function composeAddRemoveGroupMember({ action="add", roles="members" }) {
/**
* Add/Remove user from group
*
* @param {String} username
* @param {String} groupname
* @param {Function} done - done(err)
*/
return function(username, groupname, done) {
return getGroup(groupname, function(getGroupErr, group) {
if (getGroupErr) {
return done(getGroupErr);
}
if (!group) {
return done(new Error(`group '${groupname}' not found`));
}
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
group[roles][action](user.id);
return group.save(done);
});
});
};
} | [
"function",
"composeAddRemoveGroupMember",
"(",
"{",
"action",
"=",
"\"add\"",
",",
"roles",
"=",
"\"members\"",
"}",
")",
"{",
"/**\n * Add/Remove user from group\n *\n * @param {String} username\n * @param {String} groupname\n * @param {Function} done - done(err)\n */",
"return",
"function",
"(",
"username",
",",
"groupname",
",",
"done",
")",
"{",
"return",
"getGroup",
"(",
"groupname",
",",
"function",
"(",
"getGroupErr",
",",
"group",
")",
"{",
"if",
"(",
"getGroupErr",
")",
"{",
"return",
"done",
"(",
"getGroupErr",
")",
";",
"}",
"if",
"(",
"!",
"group",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"groupname",
"}",
"`",
")",
")",
";",
"}",
"return",
"getUser",
"(",
"username",
",",
"function",
"(",
"getUserErr",
",",
"user",
")",
"{",
"if",
"(",
"getUserErr",
")",
"{",
"return",
"done",
"(",
"getUserErr",
")",
";",
"}",
"if",
"(",
"!",
"user",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"username",
"}",
"`",
")",
")",
";",
"}",
"group",
"[",
"roles",
"]",
"[",
"action",
"]",
"(",
"user",
".",
"id",
")",
";",
"return",
"group",
".",
"save",
"(",
"done",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Compose function for removing or adding user to group
@param {Boolean} [action="add"] | [
"Compose",
"function",
"for",
"removing",
"or",
"adding",
"user",
"to",
"group"
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L259-L291 |
56,901 | forfuturellc/svc-fbr | src/lib/db.js | getUser | function getUser(username, done) {
return getModels(function(m) {
return m.collections.user.findOne({ username })
.populate("tokens")
.populate("groups")
.populate("leading")
.exec(done);
});
} | javascript | function getUser(username, done) {
return getModels(function(m) {
return m.collections.user.findOne({ username })
.populate("tokens")
.populate("groups")
.populate("leading")
.exec(done);
});
} | [
"function",
"getUser",
"(",
"username",
",",
"done",
")",
"{",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"collections",
".",
"user",
".",
"findOne",
"(",
"{",
"username",
"}",
")",
".",
"populate",
"(",
"\"tokens\"",
")",
".",
"populate",
"(",
"\"groups\"",
")",
".",
"populate",
"(",
"\"leading\"",
")",
".",
"exec",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Get a single user. Automatically loads the tokens.
@param {String} username
@param {Function} done - done(err, user) | [
"Get",
"a",
"single",
"user",
".",
"Automatically",
"loads",
"the",
"tokens",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L300-L308 |
56,902 | forfuturellc/svc-fbr | src/lib/db.js | deleteUser | function deleteUser(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
user.tokens.forEach((token) => token.destroy());
user.groups.forEach((group) => { group.members.remove(user.id); group.save(); });
user.leading.forEach((group) => { group.leaders.remove(user.id); group.save(); });
user.destroy(done);
});
} | javascript | function deleteUser(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
user.tokens.forEach((token) => token.destroy());
user.groups.forEach((group) => { group.members.remove(user.id); group.save(); });
user.leading.forEach((group) => { group.leaders.remove(user.id); group.save(); });
user.destroy(done);
});
} | [
"function",
"deleteUser",
"(",
"username",
",",
"done",
")",
"{",
"return",
"getUser",
"(",
"username",
",",
"function",
"(",
"getUserErr",
",",
"user",
")",
"{",
"if",
"(",
"getUserErr",
")",
"{",
"return",
"done",
"(",
"getUserErr",
")",
";",
"}",
"if",
"(",
"!",
"user",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"username",
"}",
"`",
")",
")",
";",
"}",
"user",
".",
"tokens",
".",
"forEach",
"(",
"(",
"token",
")",
"=>",
"token",
".",
"destroy",
"(",
")",
")",
";",
"user",
".",
"groups",
".",
"forEach",
"(",
"(",
"group",
")",
"=>",
"{",
"group",
".",
"members",
".",
"remove",
"(",
"user",
".",
"id",
")",
";",
"group",
".",
"save",
"(",
")",
";",
"}",
")",
";",
"user",
".",
"leading",
".",
"forEach",
"(",
"(",
"group",
")",
"=>",
"{",
"group",
".",
"leaders",
".",
"remove",
"(",
"user",
".",
"id",
")",
";",
"group",
".",
"save",
"(",
")",
";",
"}",
")",
";",
"user",
".",
"destroy",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Destroy a user. This also deletes all the user's tokens.
@param {String} username
@param {Function} done - done(err) | [
"Destroy",
"a",
"user",
".",
"This",
"also",
"deletes",
"all",
"the",
"user",
"s",
"tokens",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L347-L362 |
56,903 | forfuturellc/svc-fbr | src/lib/db.js | getUsers | function getUsers(done) {
return getModels(function(m) {
return m.collections.user.find().exec(done);
});
} | javascript | function getUsers(done) {
return getModels(function(m) {
return m.collections.user.find().exec(done);
});
} | [
"function",
"getUsers",
"(",
"done",
")",
"{",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"m",
".",
"collections",
".",
"user",
".",
"find",
"(",
")",
".",
"exec",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Get all users. Note that the tokens are not loaded. This is by design;
it might be very expensive to do so.
@param {Function} done - done(err, users) | [
"Get",
"all",
"users",
".",
"Note",
"that",
"the",
"tokens",
"are",
"not",
"loaded",
".",
"This",
"is",
"by",
"design",
";",
"it",
"might",
"be",
"very",
"expensive",
"to",
"do",
"so",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L371-L375 |
56,904 | forfuturellc/svc-fbr | src/lib/db.js | hashToken | function hashToken(token, done) {
return bcrypt.genSalt(10, function(genSaltErr, salt) {
if (genSaltErr) {
return done(genSaltErr);
}
bcrypt.hash(token, salt, done);
});
} | javascript | function hashToken(token, done) {
return bcrypt.genSalt(10, function(genSaltErr, salt) {
if (genSaltErr) {
return done(genSaltErr);
}
bcrypt.hash(token, salt, done);
});
} | [
"function",
"hashToken",
"(",
"token",
",",
"done",
")",
"{",
"return",
"bcrypt",
".",
"genSalt",
"(",
"10",
",",
"function",
"(",
"genSaltErr",
",",
"salt",
")",
"{",
"if",
"(",
"genSaltErr",
")",
"{",
"return",
"done",
"(",
"genSaltErr",
")",
";",
"}",
"bcrypt",
".",
"hash",
"(",
"token",
",",
"salt",
",",
"done",
")",
";",
"}",
")",
";",
"}"
] | Hash a token. We shall not store the token in plain text for security
purposes.
@param {String} token
@param {Function} done - done(err, hash) | [
"Hash",
"a",
"token",
".",
"We",
"shall",
"not",
"store",
"the",
"token",
"in",
"plain",
"text",
"for",
"security",
"purposes",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L385-L393 |
56,905 | forfuturellc/svc-fbr | src/lib/db.js | createToken | function createToken(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
const token = uuid.v4();
return hashToken(token, function(cryptErr, hash) {
if (cryptErr) {
return done(cryptErr);
}
return getModels(function(m) {
m.collections.token.create({
uuid: hash,
owner: user.id,
}, function(createTokenErr) {
if (createTokenErr) {
return done(createTokenErr);
}
return done(null, token);
}); // m.collections.token.create
}); // getModels
}); // hashToken
}); // getUser
} | javascript | function createToken(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
const token = uuid.v4();
return hashToken(token, function(cryptErr, hash) {
if (cryptErr) {
return done(cryptErr);
}
return getModels(function(m) {
m.collections.token.create({
uuid: hash,
owner: user.id,
}, function(createTokenErr) {
if (createTokenErr) {
return done(createTokenErr);
}
return done(null, token);
}); // m.collections.token.create
}); // getModels
}); // hashToken
}); // getUser
} | [
"function",
"createToken",
"(",
"username",
",",
"done",
")",
"{",
"return",
"getUser",
"(",
"username",
",",
"function",
"(",
"getUserErr",
",",
"user",
")",
"{",
"if",
"(",
"getUserErr",
")",
"{",
"return",
"done",
"(",
"getUserErr",
")",
";",
"}",
"if",
"(",
"!",
"user",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"username",
"}",
"`",
")",
")",
";",
"}",
"const",
"token",
"=",
"uuid",
".",
"v4",
"(",
")",
";",
"return",
"hashToken",
"(",
"token",
",",
"function",
"(",
"cryptErr",
",",
"hash",
")",
"{",
"if",
"(",
"cryptErr",
")",
"{",
"return",
"done",
"(",
"cryptErr",
")",
";",
"}",
"return",
"getModels",
"(",
"function",
"(",
"m",
")",
"{",
"m",
".",
"collections",
".",
"token",
".",
"create",
"(",
"{",
"uuid",
":",
"hash",
",",
"owner",
":",
"user",
".",
"id",
",",
"}",
",",
"function",
"(",
"createTokenErr",
")",
"{",
"if",
"(",
"createTokenErr",
")",
"{",
"return",
"done",
"(",
"createTokenErr",
")",
";",
"}",
"return",
"done",
"(",
"null",
",",
"token",
")",
";",
"}",
")",
";",
"// m.collections.token.create",
"}",
")",
";",
"// getModels",
"}",
")",
";",
"// hashToken",
"}",
")",
";",
"// getUser",
"}"
] | Create a token for a user. A token is simply a v4 uuid.
@param {String} username
@param {Function} done - done(err, token) | [
"Create",
"a",
"token",
"for",
"a",
"user",
".",
"A",
"token",
"is",
"simply",
"a",
"v4",
"uuid",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L402-L433 |
56,906 | forfuturellc/svc-fbr | src/lib/db.js | getTokenHashes | function getTokenHashes(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
return done(null, user.tokens);
});
} | javascript | function getTokenHashes(username, done) {
return getUser(username, function(getUserErr, user) {
if (getUserErr) {
return done(getUserErr);
}
if (!user) {
return done(new Error(`user '${username}' not found`));
}
return done(null, user.tokens);
});
} | [
"function",
"getTokenHashes",
"(",
"username",
",",
"done",
")",
"{",
"return",
"getUser",
"(",
"username",
",",
"function",
"(",
"getUserErr",
",",
"user",
")",
"{",
"if",
"(",
"getUserErr",
")",
"{",
"return",
"done",
"(",
"getUserErr",
")",
";",
"}",
"if",
"(",
"!",
"user",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"username",
"}",
"`",
")",
")",
";",
"}",
"return",
"done",
"(",
"null",
",",
"user",
".",
"tokens",
")",
";",
"}",
")",
";",
"}"
] | Retrieve users tokens
@param {String} username
@param {Function} done - done(err, hashes) | [
"Retrieve",
"users",
"tokens"
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L442-L454 |
56,907 | forfuturellc/svc-fbr | src/lib/db.js | tokenExists | function tokenExists(username, token, done) {
return getTokenHashes(username, function(getTokensErr, hashes) {
if (getTokensErr) {
return done(getTokensErr);
}
if (!hashes || !hashes.length) {
return done(null, false);
}
let index = 0;
let found = false;
async.until(() => found || (index >= hashes.length), function(next) {
bcrypt.compare(token, hashes[index++].uuid, function(err, match) {
found = match;
return next(err);
});
}, (err) => done(err, found ? hashes[index - 1] : undefined));
});
} | javascript | function tokenExists(username, token, done) {
return getTokenHashes(username, function(getTokensErr, hashes) {
if (getTokensErr) {
return done(getTokensErr);
}
if (!hashes || !hashes.length) {
return done(null, false);
}
let index = 0;
let found = false;
async.until(() => found || (index >= hashes.length), function(next) {
bcrypt.compare(token, hashes[index++].uuid, function(err, match) {
found = match;
return next(err);
});
}, (err) => done(err, found ? hashes[index - 1] : undefined));
});
} | [
"function",
"tokenExists",
"(",
"username",
",",
"token",
",",
"done",
")",
"{",
"return",
"getTokenHashes",
"(",
"username",
",",
"function",
"(",
"getTokensErr",
",",
"hashes",
")",
"{",
"if",
"(",
"getTokensErr",
")",
"{",
"return",
"done",
"(",
"getTokensErr",
")",
";",
"}",
"if",
"(",
"!",
"hashes",
"||",
"!",
"hashes",
".",
"length",
")",
"{",
"return",
"done",
"(",
"null",
",",
"false",
")",
";",
"}",
"let",
"index",
"=",
"0",
";",
"let",
"found",
"=",
"false",
";",
"async",
".",
"until",
"(",
"(",
")",
"=>",
"found",
"||",
"(",
"index",
">=",
"hashes",
".",
"length",
")",
",",
"function",
"(",
"next",
")",
"{",
"bcrypt",
".",
"compare",
"(",
"token",
",",
"hashes",
"[",
"index",
"++",
"]",
".",
"uuid",
",",
"function",
"(",
"err",
",",
"match",
")",
"{",
"found",
"=",
"match",
";",
"return",
"next",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
",",
"(",
"err",
")",
"=>",
"done",
"(",
"err",
",",
"found",
"?",
"hashes",
"[",
"index",
"-",
"1",
"]",
":",
"undefined",
")",
")",
";",
"}",
")",
";",
"}"
] | Check if token exists. If found it is returned.
@param {String} token
@param {Function} done - done(err, tokenObj) | [
"Check",
"if",
"token",
"exists",
".",
"If",
"found",
"it",
"is",
"returned",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L463-L483 |
56,908 | forfuturellc/svc-fbr | src/lib/db.js | deleteToken | function deleteToken(username, token, done) {
return tokenExists(username, token, function(existsErr, tokenObj) {
if (existsErr) {
return done(existsErr);
}
if (!tokenObj) {
return done(new Error(`token '${token}' not found`));
}
return tokenObj.destroy(done);
});
} | javascript | function deleteToken(username, token, done) {
return tokenExists(username, token, function(existsErr, tokenObj) {
if (existsErr) {
return done(existsErr);
}
if (!tokenObj) {
return done(new Error(`token '${token}' not found`));
}
return tokenObj.destroy(done);
});
} | [
"function",
"deleteToken",
"(",
"username",
",",
"token",
",",
"done",
")",
"{",
"return",
"tokenExists",
"(",
"username",
",",
"token",
",",
"function",
"(",
"existsErr",
",",
"tokenObj",
")",
"{",
"if",
"(",
"existsErr",
")",
"{",
"return",
"done",
"(",
"existsErr",
")",
";",
"}",
"if",
"(",
"!",
"tokenObj",
")",
"{",
"return",
"done",
"(",
"new",
"Error",
"(",
"`",
"${",
"token",
"}",
"`",
")",
")",
";",
"}",
"return",
"tokenObj",
".",
"destroy",
"(",
"done",
")",
";",
"}",
")",
";",
"}"
] | Destroy a token. Username is required as we use it to search through
tokens.
@param {String} username
@param {String} token
@param {Function} done - done(err) | [
"Destroy",
"a",
"token",
".",
"Username",
"is",
"required",
"as",
"we",
"use",
"it",
"to",
"search",
"through",
"tokens",
"."
] | 8c07c71d6423d1dbd4f903a032dea0bfec63894e | https://github.com/forfuturellc/svc-fbr/blob/8c07c71d6423d1dbd4f903a032dea0bfec63894e/src/lib/db.js#L494-L506 |
56,909 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | _onInboxMessage | function _onInboxMessage (sender, _, msgBuffer) {
let message = JSON.parse(msgBuffer)
masterBroker.setIP(message.toAddress)
switch (message.type) {
case 'voteRequest':
debug(`sending vote to ${node.name === message.from ? 'myself' : message.from}`)
_inbox.send([sender, _, JSON.stringify({
id: _advertiseId || node.id,
name: node.name,
endpoints: masterBroker.endpoints,
isMaster: masterBroker.isMaster,
candidate: !_advertiseId
})])
break
case 'masterRequest':
let connectedMaster = node.master
if (connectedMaster) {
debug(`sending master coordinates to ${message.from}`)
_inbox.send([sender, _, JSON.stringify(connectedMaster)])
} else {
debug(`unable to send master coordinates to ${message.from}`)
_inbox.send([sender, _, JSON.stringify(false)])
}
break
case 'masterElected':
_inbox.send([sender, _, ''])
debug(`received notice of master election: ${message.data.name}`)
resolver.emit('newmaster', message.data)
}
} | javascript | function _onInboxMessage (sender, _, msgBuffer) {
let message = JSON.parse(msgBuffer)
masterBroker.setIP(message.toAddress)
switch (message.type) {
case 'voteRequest':
debug(`sending vote to ${node.name === message.from ? 'myself' : message.from}`)
_inbox.send([sender, _, JSON.stringify({
id: _advertiseId || node.id,
name: node.name,
endpoints: masterBroker.endpoints,
isMaster: masterBroker.isMaster,
candidate: !_advertiseId
})])
break
case 'masterRequest':
let connectedMaster = node.master
if (connectedMaster) {
debug(`sending master coordinates to ${message.from}`)
_inbox.send([sender, _, JSON.stringify(connectedMaster)])
} else {
debug(`unable to send master coordinates to ${message.from}`)
_inbox.send([sender, _, JSON.stringify(false)])
}
break
case 'masterElected':
_inbox.send([sender, _, ''])
debug(`received notice of master election: ${message.data.name}`)
resolver.emit('newmaster', message.data)
}
} | [
"function",
"_onInboxMessage",
"(",
"sender",
",",
"_",
",",
"msgBuffer",
")",
"{",
"let",
"message",
"=",
"JSON",
".",
"parse",
"(",
"msgBuffer",
")",
"masterBroker",
".",
"setIP",
"(",
"message",
".",
"toAddress",
")",
"switch",
"(",
"message",
".",
"type",
")",
"{",
"case",
"'voteRequest'",
":",
"debug",
"(",
"`",
"${",
"node",
".",
"name",
"===",
"message",
".",
"from",
"?",
"'myself'",
":",
"message",
".",
"from",
"}",
"`",
")",
"_inbox",
".",
"send",
"(",
"[",
"sender",
",",
"_",
",",
"JSON",
".",
"stringify",
"(",
"{",
"id",
":",
"_advertiseId",
"||",
"node",
".",
"id",
",",
"name",
":",
"node",
".",
"name",
",",
"endpoints",
":",
"masterBroker",
".",
"endpoints",
",",
"isMaster",
":",
"masterBroker",
".",
"isMaster",
",",
"candidate",
":",
"!",
"_advertiseId",
"}",
")",
"]",
")",
"break",
"case",
"'masterRequest'",
":",
"let",
"connectedMaster",
"=",
"node",
".",
"master",
"if",
"(",
"connectedMaster",
")",
"{",
"debug",
"(",
"`",
"${",
"message",
".",
"from",
"}",
"`",
")",
"_inbox",
".",
"send",
"(",
"[",
"sender",
",",
"_",
",",
"JSON",
".",
"stringify",
"(",
"connectedMaster",
")",
"]",
")",
"}",
"else",
"{",
"debug",
"(",
"`",
"${",
"message",
".",
"from",
"}",
"`",
")",
"_inbox",
".",
"send",
"(",
"[",
"sender",
",",
"_",
",",
"JSON",
".",
"stringify",
"(",
"false",
")",
"]",
")",
"}",
"break",
"case",
"'masterElected'",
":",
"_inbox",
".",
"send",
"(",
"[",
"sender",
",",
"_",
",",
"''",
"]",
")",
"debug",
"(",
"`",
"${",
"message",
".",
"data",
".",
"name",
"}",
"`",
")",
"resolver",
".",
"emit",
"(",
"'newmaster'",
",",
"message",
".",
"data",
")",
"}",
"}"
] | function receiving the messages from the coordination router
@param {buffer} sender
@param {void} _
@param {buffer} msgBuffer | [
"function",
"receiving",
"the",
"messages",
"from",
"the",
"coordination",
"router"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L33-L63 |
56,910 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | _broadcastMessage | function _broadcastMessage (type, data) {
data = data || {}
let message = {type, data}
let { host, coordinationPort } = node.settings
dns.resolve4(host, (err, addresses) => {
if (err) {
debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
return
}
debug(`broadcasting message '${type}' to '${host}' nodes: ${addresses}`)
addresses.forEach(address => {
let messenger = zmq.socket('req')
messenger.connect(`tcp://${address}:${coordinationPort}`)
messenger.send(JSON.stringify({
...message,
toAddress: address
}))
let _end = false
function closeSocket () {
if (_end) return
_end = true
messenger.close()
}
messenger.on('message', closeSocket)
setTimeout(closeSocket, 300)
})
})
} | javascript | function _broadcastMessage (type, data) {
data = data || {}
let message = {type, data}
let { host, coordinationPort } = node.settings
dns.resolve4(host, (err, addresses) => {
if (err) {
debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
return
}
debug(`broadcasting message '${type}' to '${host}' nodes: ${addresses}`)
addresses.forEach(address => {
let messenger = zmq.socket('req')
messenger.connect(`tcp://${address}:${coordinationPort}`)
messenger.send(JSON.stringify({
...message,
toAddress: address
}))
let _end = false
function closeSocket () {
if (_end) return
_end = true
messenger.close()
}
messenger.on('message', closeSocket)
setTimeout(closeSocket, 300)
})
})
} | [
"function",
"_broadcastMessage",
"(",
"type",
",",
"data",
")",
"{",
"data",
"=",
"data",
"||",
"{",
"}",
"let",
"message",
"=",
"{",
"type",
",",
"data",
"}",
"let",
"{",
"host",
",",
"coordinationPort",
"}",
"=",
"node",
".",
"settings",
"dns",
".",
"resolve4",
"(",
"host",
",",
"(",
"err",
",",
"addresses",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"`",
"${",
"host",
"}",
"`",
")",
"return",
"}",
"debug",
"(",
"`",
"${",
"type",
"}",
"${",
"host",
"}",
"${",
"addresses",
"}",
"`",
")",
"addresses",
".",
"forEach",
"(",
"address",
"=>",
"{",
"let",
"messenger",
"=",
"zmq",
".",
"socket",
"(",
"'req'",
")",
"messenger",
".",
"connect",
"(",
"`",
"${",
"address",
"}",
"${",
"coordinationPort",
"}",
"`",
")",
"messenger",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"...",
"message",
",",
"toAddress",
":",
"address",
"}",
")",
")",
"let",
"_end",
"=",
"false",
"function",
"closeSocket",
"(",
")",
"{",
"if",
"(",
"_end",
")",
"return",
"_end",
"=",
"true",
"messenger",
".",
"close",
"(",
")",
"}",
"messenger",
".",
"on",
"(",
"'message'",
",",
"closeSocket",
")",
"setTimeout",
"(",
"closeSocket",
",",
"300",
")",
"}",
")",
"}",
")",
"}"
] | broadcasts a message to the coordination socket of all the dnsNodes
@param {string} type - Type of message
@param {object} data - Payload of the message | [
"broadcasts",
"a",
"message",
"to",
"the",
"coordination",
"socket",
"of",
"all",
"the",
"dnsNodes"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L69-L98 |
56,911 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | _requestVotes | function _requestVotes () {
let { host, coordinationPort } = node.settings
let message = {
type: 'voteRequest',
data: {}
}
return new Promise((resolve, reject) => {
let resolveStart = Date.now()
dns.resolve4(host, (err, addresses) => {
if (err) {
debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
return reject(err)
}
debug(`resolved ${addresses.length} IP(s) for host '${host}' in ${Date.now() - resolveStart} ms`)
debug(`requesting votes from ${addresses.length} nodes`)
Promise.all(
addresses.map(address => new Promise((resolve, reject) => {
let voteRequestTime = Date.now()
let messenger = zmq.socket('req')
messenger.connect(`tcp://${address}:${coordinationPort}`)
messenger.send(JSON.stringify({
...message,
toAddress: address,
from: node.name
}))
let _resolved = false
function onEnd (candidateBuffer) {
if (_resolved) return
_resolved = true
messenger.removeListener('message', onEnd)
messenger.close()
let candidate = candidateBuffer && JSON.parse(candidateBuffer)
if (candidate) {
let elapsed = Date.now() - voteRequestTime
candidate.candidate && debug(`received vote by ${candidate.name === node.name ? 'myself' : candidate.name}${candidate.isMaster ? ' (master)' : ''} in ${elapsed} ms`)
} else {
debug(`missed vote by peer at ${address}`)
}
resolve(candidate)
}
messenger.on('message', onEnd)
setTimeout(onEnd, node.settings.voteTimeout)
}))
)
.then(nodes => compact(nodes))
.then(nodes => resolve(nodes.filter(({candidate}) => candidate)))
})
})
} | javascript | function _requestVotes () {
let { host, coordinationPort } = node.settings
let message = {
type: 'voteRequest',
data: {}
}
return new Promise((resolve, reject) => {
let resolveStart = Date.now()
dns.resolve4(host, (err, addresses) => {
if (err) {
debug(`cannot resolve host '${host}'. Check DNS infrastructure.`)
return reject(err)
}
debug(`resolved ${addresses.length} IP(s) for host '${host}' in ${Date.now() - resolveStart} ms`)
debug(`requesting votes from ${addresses.length} nodes`)
Promise.all(
addresses.map(address => new Promise((resolve, reject) => {
let voteRequestTime = Date.now()
let messenger = zmq.socket('req')
messenger.connect(`tcp://${address}:${coordinationPort}`)
messenger.send(JSON.stringify({
...message,
toAddress: address,
from: node.name
}))
let _resolved = false
function onEnd (candidateBuffer) {
if (_resolved) return
_resolved = true
messenger.removeListener('message', onEnd)
messenger.close()
let candidate = candidateBuffer && JSON.parse(candidateBuffer)
if (candidate) {
let elapsed = Date.now() - voteRequestTime
candidate.candidate && debug(`received vote by ${candidate.name === node.name ? 'myself' : candidate.name}${candidate.isMaster ? ' (master)' : ''} in ${elapsed} ms`)
} else {
debug(`missed vote by peer at ${address}`)
}
resolve(candidate)
}
messenger.on('message', onEnd)
setTimeout(onEnd, node.settings.voteTimeout)
}))
)
.then(nodes => compact(nodes))
.then(nodes => resolve(nodes.filter(({candidate}) => candidate)))
})
})
} | [
"function",
"_requestVotes",
"(",
")",
"{",
"let",
"{",
"host",
",",
"coordinationPort",
"}",
"=",
"node",
".",
"settings",
"let",
"message",
"=",
"{",
"type",
":",
"'voteRequest'",
",",
"data",
":",
"{",
"}",
"}",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"resolveStart",
"=",
"Date",
".",
"now",
"(",
")",
"dns",
".",
"resolve4",
"(",
"host",
",",
"(",
"err",
",",
"addresses",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"debug",
"(",
"`",
"${",
"host",
"}",
"`",
")",
"return",
"reject",
"(",
"err",
")",
"}",
"debug",
"(",
"`",
"${",
"addresses",
".",
"length",
"}",
"${",
"host",
"}",
"${",
"Date",
".",
"now",
"(",
")",
"-",
"resolveStart",
"}",
"`",
")",
"debug",
"(",
"`",
"${",
"addresses",
".",
"length",
"}",
"`",
")",
"Promise",
".",
"all",
"(",
"addresses",
".",
"map",
"(",
"address",
"=>",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"let",
"voteRequestTime",
"=",
"Date",
".",
"now",
"(",
")",
"let",
"messenger",
"=",
"zmq",
".",
"socket",
"(",
"'req'",
")",
"messenger",
".",
"connect",
"(",
"`",
"${",
"address",
"}",
"${",
"coordinationPort",
"}",
"`",
")",
"messenger",
".",
"send",
"(",
"JSON",
".",
"stringify",
"(",
"{",
"...",
"message",
",",
"toAddress",
":",
"address",
",",
"from",
":",
"node",
".",
"name",
"}",
")",
")",
"let",
"_resolved",
"=",
"false",
"function",
"onEnd",
"(",
"candidateBuffer",
")",
"{",
"if",
"(",
"_resolved",
")",
"return",
"_resolved",
"=",
"true",
"messenger",
".",
"removeListener",
"(",
"'message'",
",",
"onEnd",
")",
"messenger",
".",
"close",
"(",
")",
"let",
"candidate",
"=",
"candidateBuffer",
"&&",
"JSON",
".",
"parse",
"(",
"candidateBuffer",
")",
"if",
"(",
"candidate",
")",
"{",
"let",
"elapsed",
"=",
"Date",
".",
"now",
"(",
")",
"-",
"voteRequestTime",
"candidate",
".",
"candidate",
"&&",
"debug",
"(",
"`",
"${",
"candidate",
".",
"name",
"===",
"node",
".",
"name",
"?",
"'myself'",
":",
"candidate",
".",
"name",
"}",
"${",
"candidate",
".",
"isMaster",
"?",
"' (master)'",
":",
"''",
"}",
"${",
"elapsed",
"}",
"`",
")",
"}",
"else",
"{",
"debug",
"(",
"`",
"${",
"address",
"}",
"`",
")",
"}",
"resolve",
"(",
"candidate",
")",
"}",
"messenger",
".",
"on",
"(",
"'message'",
",",
"onEnd",
")",
"setTimeout",
"(",
"onEnd",
",",
"node",
".",
"settings",
".",
"voteTimeout",
")",
"}",
")",
")",
")",
".",
"then",
"(",
"nodes",
"=>",
"compact",
"(",
"nodes",
")",
")",
".",
"then",
"(",
"nodes",
"=>",
"resolve",
"(",
"nodes",
".",
"filter",
"(",
"(",
"{",
"candidate",
"}",
")",
"=>",
"candidate",
")",
")",
")",
"}",
")",
"}",
")",
"}"
] | requests the voting identity of all the eligible dnsNodes
@return {promise} An list of objects representing nodes eligible as master | [
"requests",
"the",
"voting",
"identity",
"of",
"all",
"the",
"eligible",
"dnsNodes"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L103-L154 |
56,912 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | bind | function bind () {
_inbox.bindSync(`tcp://0.0.0.0:${node.settings.coordinationPort}`)
_inbox.on('message', _onInboxMessage)
return resolver
} | javascript | function bind () {
_inbox.bindSync(`tcp://0.0.0.0:${node.settings.coordinationPort}`)
_inbox.on('message', _onInboxMessage)
return resolver
} | [
"function",
"bind",
"(",
")",
"{",
"_inbox",
".",
"bindSync",
"(",
"`",
"${",
"node",
".",
"settings",
".",
"coordinationPort",
"}",
"`",
")",
"_inbox",
".",
"on",
"(",
"'message'",
",",
"_onInboxMessage",
")",
"return",
"resolver",
"}"
] | Binds the coordination router socket to all interfaces
@return {object} masterElector | [
"Binds",
"the",
"coordination",
"router",
"socket",
"to",
"all",
"interfaces"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L160-L164 |
56,913 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | unbind | function unbind () {
_inbox.unbindSync(`tcp://0.0.0.0:${node.settings.coordinationPort}`)
_inbox.removeListener('message', _onInboxMessage)
return resolver
} | javascript | function unbind () {
_inbox.unbindSync(`tcp://0.0.0.0:${node.settings.coordinationPort}`)
_inbox.removeListener('message', _onInboxMessage)
return resolver
} | [
"function",
"unbind",
"(",
")",
"{",
"_inbox",
".",
"unbindSync",
"(",
"`",
"${",
"node",
".",
"settings",
".",
"coordinationPort",
"}",
"`",
")",
"_inbox",
".",
"removeListener",
"(",
"'message'",
",",
"_onInboxMessage",
")",
"return",
"resolver",
"}"
] | Unbinds the coordination router socket from all interfaces
@return {object} masterElector | [
"Unbinds",
"the",
"coordination",
"router",
"socket",
"from",
"all",
"interfaces"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L169-L173 |
56,914 | gtriggiano/dnsmq-messagebus | src/MasterElector.js | electMaster | function electMaster (advertiseId) {
_advertiseId = advertiseId || null
if (_electingMaster) return _electingMaster
_electingMaster = _requestVotes()
.then(nodes => {
_electingMaster = false
_advertiseId = null
const masterNodes = nodes.filter(
({isMaster}) => isMaster)
nodes = masterNodes.length ? masterNodes : nodes
const electedMaster = sortBy(nodes, ({id}) => id)[0]
if (!electedMaster) throw new Error('could not elect a master')
debug(`elected master: ${electedMaster.name} ${JSON.stringify(electedMaster.endpoints)}`)
_broadcastMessage('masterElected', electedMaster)
return electedMaster
})
_electingMaster.catch(() => {
_electingMaster = false
_advertiseId = null
})
return _electingMaster
} | javascript | function electMaster (advertiseId) {
_advertiseId = advertiseId || null
if (_electingMaster) return _electingMaster
_electingMaster = _requestVotes()
.then(nodes => {
_electingMaster = false
_advertiseId = null
const masterNodes = nodes.filter(
({isMaster}) => isMaster)
nodes = masterNodes.length ? masterNodes : nodes
const electedMaster = sortBy(nodes, ({id}) => id)[0]
if (!electedMaster) throw new Error('could not elect a master')
debug(`elected master: ${electedMaster.name} ${JSON.stringify(electedMaster.endpoints)}`)
_broadcastMessage('masterElected', electedMaster)
return electedMaster
})
_electingMaster.catch(() => {
_electingMaster = false
_advertiseId = null
})
return _electingMaster
} | [
"function",
"electMaster",
"(",
"advertiseId",
")",
"{",
"_advertiseId",
"=",
"advertiseId",
"||",
"null",
"if",
"(",
"_electingMaster",
")",
"return",
"_electingMaster",
"_electingMaster",
"=",
"_requestVotes",
"(",
")",
".",
"then",
"(",
"nodes",
"=>",
"{",
"_electingMaster",
"=",
"false",
"_advertiseId",
"=",
"null",
"const",
"masterNodes",
"=",
"nodes",
".",
"filter",
"(",
"(",
"{",
"isMaster",
"}",
")",
"=>",
"isMaster",
")",
"nodes",
"=",
"masterNodes",
".",
"length",
"?",
"masterNodes",
":",
"nodes",
"const",
"electedMaster",
"=",
"sortBy",
"(",
"nodes",
",",
"(",
"{",
"id",
"}",
")",
"=>",
"id",
")",
"[",
"0",
"]",
"if",
"(",
"!",
"electedMaster",
")",
"throw",
"new",
"Error",
"(",
"'could not elect a master'",
")",
"debug",
"(",
"`",
"${",
"electedMaster",
".",
"name",
"}",
"${",
"JSON",
".",
"stringify",
"(",
"electedMaster",
".",
"endpoints",
")",
"}",
"`",
")",
"_broadcastMessage",
"(",
"'masterElected'",
",",
"electedMaster",
")",
"return",
"electedMaster",
"}",
")",
"_electingMaster",
".",
"catch",
"(",
"(",
")",
"=>",
"{",
"_electingMaster",
"=",
"false",
"_advertiseId",
"=",
"null",
"}",
")",
"return",
"_electingMaster",
"}"
] | Triggers a master election
@alias resolve
@param {string} [advertiseId] - A fake id to use for this node during the election
@return {promise} An object containing the name and the pub/sub endpoints of the master node | [
"Triggers",
"a",
"master",
"election"
] | ab935cae537f8a7e61a6ed6fba247661281c9374 | https://github.com/gtriggiano/dnsmq-messagebus/blob/ab935cae537f8a7e61a6ed6fba247661281c9374/src/MasterElector.js#L180-L203 |
56,915 | mnaamani/otr3-em | lib/bigint.js | millerRabin | function millerRabin(x,b) {
var i,j,k,s;
if (mr_x1.length!=x.length) {
mr_x1=dup(x);
mr_r=dup(x);
mr_a=dup(x);
}
copy_(mr_a,b);
copy_(mr_r,x);
copy_(mr_x1,x);
addInt_(mr_r,-1);
addInt_(mr_x1,-1);
//s=the highest power of two that divides mr_r
/*
k=0;
for (i=0;i<mr_r.length;i++)
for (j=1;j<mask;j<<=1)
if (x[i] & j) {
s=(k<mr_r.length+bpe ? k : 0);
i=mr_r.length;
j=mask;
} else
k++;
*/
/* http://www.javascripter.net/math/primes/millerrabinbug-bigint54.htm */
if (isZero(mr_r)) return 0;
for (k=0; mr_r[k]==0; k++);
for (i=1,j=2; mr_r[k]%j==0; j*=2,i++ );
s = k*bpe + i - 1;
/* end */
if (s)
rightShift_(mr_r,s);
powMod_(mr_a,mr_r,x);
if (!equalsInt(mr_a,1) && !equals(mr_a,mr_x1)) {
j=1;
while (j<=s-1 && !equals(mr_a,mr_x1)) {
squareMod_(mr_a,x);
if (equalsInt(mr_a,1)) {
return 0;
}
j++;
}
if (!equals(mr_a,mr_x1)) {
return 0;
}
}
return 1;
} | javascript | function millerRabin(x,b) {
var i,j,k,s;
if (mr_x1.length!=x.length) {
mr_x1=dup(x);
mr_r=dup(x);
mr_a=dup(x);
}
copy_(mr_a,b);
copy_(mr_r,x);
copy_(mr_x1,x);
addInt_(mr_r,-1);
addInt_(mr_x1,-1);
//s=the highest power of two that divides mr_r
/*
k=0;
for (i=0;i<mr_r.length;i++)
for (j=1;j<mask;j<<=1)
if (x[i] & j) {
s=(k<mr_r.length+bpe ? k : 0);
i=mr_r.length;
j=mask;
} else
k++;
*/
/* http://www.javascripter.net/math/primes/millerrabinbug-bigint54.htm */
if (isZero(mr_r)) return 0;
for (k=0; mr_r[k]==0; k++);
for (i=1,j=2; mr_r[k]%j==0; j*=2,i++ );
s = k*bpe + i - 1;
/* end */
if (s)
rightShift_(mr_r,s);
powMod_(mr_a,mr_r,x);
if (!equalsInt(mr_a,1) && !equals(mr_a,mr_x1)) {
j=1;
while (j<=s-1 && !equals(mr_a,mr_x1)) {
squareMod_(mr_a,x);
if (equalsInt(mr_a,1)) {
return 0;
}
j++;
}
if (!equals(mr_a,mr_x1)) {
return 0;
}
}
return 1;
} | [
"function",
"millerRabin",
"(",
"x",
",",
"b",
")",
"{",
"var",
"i",
",",
"j",
",",
"k",
",",
"s",
";",
"if",
"(",
"mr_x1",
".",
"length",
"!=",
"x",
".",
"length",
")",
"{",
"mr_x1",
"=",
"dup",
"(",
"x",
")",
";",
"mr_r",
"=",
"dup",
"(",
"x",
")",
";",
"mr_a",
"=",
"dup",
"(",
"x",
")",
";",
"}",
"copy_",
"(",
"mr_a",
",",
"b",
")",
";",
"copy_",
"(",
"mr_r",
",",
"x",
")",
";",
"copy_",
"(",
"mr_x1",
",",
"x",
")",
";",
"addInt_",
"(",
"mr_r",
",",
"-",
"1",
")",
";",
"addInt_",
"(",
"mr_x1",
",",
"-",
"1",
")",
";",
"//s=the highest power of two that divides mr_r",
"/*\n k=0;\n for (i=0;i<mr_r.length;i++)\n for (j=1;j<mask;j<<=1)\n if (x[i] & j) {\n s=(k<mr_r.length+bpe ? k : 0); \n i=mr_r.length;\n j=mask;\n } else\n k++;\n */",
"/* http://www.javascripter.net/math/primes/millerrabinbug-bigint54.htm */",
"if",
"(",
"isZero",
"(",
"mr_r",
")",
")",
"return",
"0",
";",
"for",
"(",
"k",
"=",
"0",
";",
"mr_r",
"[",
"k",
"]",
"==",
"0",
";",
"k",
"++",
")",
";",
"for",
"(",
"i",
"=",
"1",
",",
"j",
"=",
"2",
";",
"mr_r",
"[",
"k",
"]",
"%",
"j",
"==",
"0",
";",
"j",
"*=",
"2",
",",
"i",
"++",
")",
";",
"s",
"=",
"k",
"*",
"bpe",
"+",
"i",
"-",
"1",
";",
"/* end */",
"if",
"(",
"s",
")",
"rightShift_",
"(",
"mr_r",
",",
"s",
")",
";",
"powMod_",
"(",
"mr_a",
",",
"mr_r",
",",
"x",
")",
";",
"if",
"(",
"!",
"equalsInt",
"(",
"mr_a",
",",
"1",
")",
"&&",
"!",
"equals",
"(",
"mr_a",
",",
"mr_x1",
")",
")",
"{",
"j",
"=",
"1",
";",
"while",
"(",
"j",
"<=",
"s",
"-",
"1",
"&&",
"!",
"equals",
"(",
"mr_a",
",",
"mr_x1",
")",
")",
"{",
"squareMod_",
"(",
"mr_a",
",",
"x",
")",
";",
"if",
"(",
"equalsInt",
"(",
"mr_a",
",",
"1",
")",
")",
"{",
"return",
"0",
";",
"}",
"j",
"++",
";",
"}",
"if",
"(",
"!",
"equals",
"(",
"mr_a",
",",
"mr_x1",
")",
")",
"{",
"return",
"0",
";",
"}",
"}",
"return",
"1",
";",
"}"
] | does a single round of Miller-Rabin base b consider x to be a possible prime? x and b are bigInts with b<x | [
"does",
"a",
"single",
"round",
"of",
"Miller",
"-",
"Rabin",
"base",
"b",
"consider",
"x",
"to",
"be",
"a",
"possible",
"prime?",
"x",
"and",
"b",
"are",
"bigInts",
"with",
"b<x"
] | f335c03d1be2c8c73a192908088a2dc366ba6a4e | https://github.com/mnaamani/otr3-em/blob/f335c03d1be2c8c73a192908088a2dc366ba6a4e/lib/bigint.js#L302-L358 |
56,916 | mnaamani/otr3-em | lib/bigint.js | bigInt2str | function bigInt2str(x,base) {
var i,t,s="";
if (s6.length!=x.length)
s6=dup(x);
else
copy_(s6,x);
if (base==-1) { //return the list of array contents
for (i=x.length-1;i>0;i--)
s+=x[i]+',';
s+=x[0];
}
else { //return it in the given base
while (!isZero(s6)) {
t=divInt_(s6,base); //t=s6 % base; s6=floor(s6/base);
s=digitsStr.substring(t,t+1)+s;
}
}
if (s.length==0)
s="0";
return s;
} | javascript | function bigInt2str(x,base) {
var i,t,s="";
if (s6.length!=x.length)
s6=dup(x);
else
copy_(s6,x);
if (base==-1) { //return the list of array contents
for (i=x.length-1;i>0;i--)
s+=x[i]+',';
s+=x[0];
}
else { //return it in the given base
while (!isZero(s6)) {
t=divInt_(s6,base); //t=s6 % base; s6=floor(s6/base);
s=digitsStr.substring(t,t+1)+s;
}
}
if (s.length==0)
s="0";
return s;
} | [
"function",
"bigInt2str",
"(",
"x",
",",
"base",
")",
"{",
"var",
"i",
",",
"t",
",",
"s",
"=",
"\"\"",
";",
"if",
"(",
"s6",
".",
"length",
"!=",
"x",
".",
"length",
")",
"s6",
"=",
"dup",
"(",
"x",
")",
";",
"else",
"copy_",
"(",
"s6",
",",
"x",
")",
";",
"if",
"(",
"base",
"==",
"-",
"1",
")",
"{",
"//return the list of array contents",
"for",
"(",
"i",
"=",
"x",
".",
"length",
"-",
"1",
";",
"i",
">",
"0",
";",
"i",
"--",
")",
"s",
"+=",
"x",
"[",
"i",
"]",
"+",
"','",
";",
"s",
"+=",
"x",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"//return it in the given base",
"while",
"(",
"!",
"isZero",
"(",
"s6",
")",
")",
"{",
"t",
"=",
"divInt_",
"(",
"s6",
",",
"base",
")",
";",
"//t=s6 % base; s6=floor(s6/base);",
"s",
"=",
"digitsStr",
".",
"substring",
"(",
"t",
",",
"t",
"+",
"1",
")",
"+",
"s",
";",
"}",
"}",
"if",
"(",
"s",
".",
"length",
"==",
"0",
")",
"s",
"=",
"\"0\"",
";",
"return",
"s",
";",
"}"
] | convert a bigInt into a string in a given base, from base 2 up to base 95. Base -1 prints the contents of the array representing the number. | [
"convert",
"a",
"bigInt",
"into",
"a",
"string",
"in",
"a",
"given",
"base",
"from",
"base",
"2",
"up",
"to",
"base",
"95",
".",
"Base",
"-",
"1",
"prints",
"the",
"contents",
"of",
"the",
"array",
"representing",
"the",
"number",
"."
] | f335c03d1be2c8c73a192908088a2dc366ba6a4e | https://github.com/mnaamani/otr3-em/blob/f335c03d1be2c8c73a192908088a2dc366ba6a4e/lib/bigint.js#L1128-L1150 |
56,917 | mnaamani/otr3-em | lib/bigint.js | dup | function dup(x) {
var i, buff;
buff=new Array(x.length);
copy_(buff,x);
return buff;
} | javascript | function dup(x) {
var i, buff;
buff=new Array(x.length);
copy_(buff,x);
return buff;
} | [
"function",
"dup",
"(",
"x",
")",
"{",
"var",
"i",
",",
"buff",
";",
"buff",
"=",
"new",
"Array",
"(",
"x",
".",
"length",
")",
";",
"copy_",
"(",
"buff",
",",
"x",
")",
";",
"return",
"buff",
";",
"}"
] | returns a duplicate of bigInt x | [
"returns",
"a",
"duplicate",
"of",
"bigInt",
"x"
] | f335c03d1be2c8c73a192908088a2dc366ba6a4e | https://github.com/mnaamani/otr3-em/blob/f335c03d1be2c8c73a192908088a2dc366ba6a4e/lib/bigint.js#L1153-L1158 |
56,918 | mnaamani/otr3-em | lib/bigint.js | copyInt_ | function copyInt_(x,n) {
var i,c;
for (c=n,i=0;i<x.length;i++) {
x[i]=c & mask;
c>>=bpe;
}
} | javascript | function copyInt_(x,n) {
var i,c;
for (c=n,i=0;i<x.length;i++) {
x[i]=c & mask;
c>>=bpe;
}
} | [
"function",
"copyInt_",
"(",
"x",
",",
"n",
")",
"{",
"var",
"i",
",",
"c",
";",
"for",
"(",
"c",
"=",
"n",
",",
"i",
"=",
"0",
";",
"i",
"<",
"x",
".",
"length",
";",
"i",
"++",
")",
"{",
"x",
"[",
"i",
"]",
"=",
"c",
"&",
"mask",
";",
"c",
">>=",
"bpe",
";",
"}",
"}"
] | do x=y on bigInt x and integer y. | [
"do",
"x",
"=",
"y",
"on",
"bigInt",
"x",
"and",
"integer",
"y",
"."
] | f335c03d1be2c8c73a192908088a2dc366ba6a4e | https://github.com/mnaamani/otr3-em/blob/f335c03d1be2c8c73a192908088a2dc366ba6a4e/lib/bigint.js#L1171-L1177 |
56,919 | zedgu/ovenware | lib/loader.js | pathParser | function pathParser(root, extname, subPath, paths) {
var dirPath = path.resolve(subPath || root);
var files;
paths = paths || {};
try {
files = fs.readdirSync(dirPath);
} catch(e) {
files = [];
}
files.forEach(function(file) {
file = path.join(dirPath, '/', file);
if (fs.statSync(file).isFile()) {
if (~extname.split('|').indexOf(path.extname(file).substr(1))) {
var rootPath = '^' + path.join(path.resolve(root), '/');
rootPath = rootPath.replace(/\\/g, '\\\\') + '(.*)\.(' + extname + ')$';
paths[file.match(new RegExp(rootPath))[1].toLowerCase()] = file;
}
} else if (fs.statSync(file).isDirectory()) {
pathParser(root, extname, file, paths);
}
});
return paths;
} | javascript | function pathParser(root, extname, subPath, paths) {
var dirPath = path.resolve(subPath || root);
var files;
paths = paths || {};
try {
files = fs.readdirSync(dirPath);
} catch(e) {
files = [];
}
files.forEach(function(file) {
file = path.join(dirPath, '/', file);
if (fs.statSync(file).isFile()) {
if (~extname.split('|').indexOf(path.extname(file).substr(1))) {
var rootPath = '^' + path.join(path.resolve(root), '/');
rootPath = rootPath.replace(/\\/g, '\\\\') + '(.*)\.(' + extname + ')$';
paths[file.match(new RegExp(rootPath))[1].toLowerCase()] = file;
}
} else if (fs.statSync(file).isDirectory()) {
pathParser(root, extname, file, paths);
}
});
return paths;
} | [
"function",
"pathParser",
"(",
"root",
",",
"extname",
",",
"subPath",
",",
"paths",
")",
"{",
"var",
"dirPath",
"=",
"path",
".",
"resolve",
"(",
"subPath",
"||",
"root",
")",
";",
"var",
"files",
";",
"paths",
"=",
"paths",
"||",
"{",
"}",
";",
"try",
"{",
"files",
"=",
"fs",
".",
"readdirSync",
"(",
"dirPath",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"files",
"=",
"[",
"]",
";",
"}",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"file",
"=",
"path",
".",
"join",
"(",
"dirPath",
",",
"'/'",
",",
"file",
")",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"file",
")",
".",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"~",
"extname",
".",
"split",
"(",
"'|'",
")",
".",
"indexOf",
"(",
"path",
".",
"extname",
"(",
"file",
")",
".",
"substr",
"(",
"1",
")",
")",
")",
"{",
"var",
"rootPath",
"=",
"'^'",
"+",
"path",
".",
"join",
"(",
"path",
".",
"resolve",
"(",
"root",
")",
",",
"'/'",
")",
";",
"rootPath",
"=",
"rootPath",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'\\\\\\\\'",
")",
"+",
"'(.*)\\.('",
"+",
"extname",
"+",
"')$'",
";",
"paths",
"[",
"file",
".",
"match",
"(",
"new",
"RegExp",
"(",
"rootPath",
")",
")",
"[",
"1",
"]",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"file",
";",
"}",
"}",
"else",
"if",
"(",
"fs",
".",
"statSync",
"(",
"file",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"pathParser",
"(",
"root",
",",
"extname",
",",
"file",
",",
"paths",
")",
";",
"}",
"}",
")",
";",
"return",
"paths",
";",
"}"
] | to parse the paths of files
@param {String} root root path
@param {String} subPath sub dir path
@param {Object} paths dictionary of the paths
@return {Object} dictionary of the paths
@api private | [
"to",
"parse",
"the",
"paths",
"of",
"files"
] | 0fa42d020ce303ee63c58b9d58774880fc2117d7 | https://github.com/zedgu/ovenware/blob/0fa42d020ce303ee63c58b9d58774880fc2117d7/lib/loader.js#L23-L46 |
56,920 | byu-oit/fully-typed | bin/boolean.js | TypedBoolean | function TypedBoolean (config) {
const boolean = this;
// define properties
Object.defineProperties(boolean, {
strict: {
/**
* @property
* @name TypedBoolean#strict
* @type {boolean}
*/
value: config.hasOwnProperty('strict') ? !!config.strict : false,
writable: false
}
});
return boolean;
} | javascript | function TypedBoolean (config) {
const boolean = this;
// define properties
Object.defineProperties(boolean, {
strict: {
/**
* @property
* @name TypedBoolean#strict
* @type {boolean}
*/
value: config.hasOwnProperty('strict') ? !!config.strict : false,
writable: false
}
});
return boolean;
} | [
"function",
"TypedBoolean",
"(",
"config",
")",
"{",
"const",
"boolean",
"=",
"this",
";",
"// define properties",
"Object",
".",
"defineProperties",
"(",
"boolean",
",",
"{",
"strict",
":",
"{",
"/**\n * @property\n * @name TypedBoolean#strict\n * @type {boolean}\n */",
"value",
":",
"config",
".",
"hasOwnProperty",
"(",
"'strict'",
")",
"?",
"!",
"!",
"config",
".",
"strict",
":",
"false",
",",
"writable",
":",
"false",
"}",
"}",
")",
";",
"return",
"boolean",
";",
"}"
] | Create a TypedBoolean instance.
@param {object} config
@returns {TypedBoolean}
@augments Typed
@constructor | [
"Create",
"a",
"TypedBoolean",
"instance",
"."
] | ed6b3ed88ffc72990acffb765232eaaee261afef | https://github.com/byu-oit/fully-typed/blob/ed6b3ed88ffc72990acffb765232eaaee261afef/bin/boolean.js#L29-L48 |
56,921 | semibran/css-duration | index.js | duration | function duration (time) {
var number = parseFloat(time)
switch (unit(time)) {
case null:
case 'ms': return number
case 's': return number * 1000
case 'm': return number * 60000
case 'h': return number * 3600000
case 'd': return number * 86400000
case 'w': return number * 604800000
default: return null
}
} | javascript | function duration (time) {
var number = parseFloat(time)
switch (unit(time)) {
case null:
case 'ms': return number
case 's': return number * 1000
case 'm': return number * 60000
case 'h': return number * 3600000
case 'd': return number * 86400000
case 'w': return number * 604800000
default: return null
}
} | [
"function",
"duration",
"(",
"time",
")",
"{",
"var",
"number",
"=",
"parseFloat",
"(",
"time",
")",
"switch",
"(",
"unit",
"(",
"time",
")",
")",
"{",
"case",
"null",
":",
"case",
"'ms'",
":",
"return",
"number",
"case",
"'s'",
":",
"return",
"number",
"*",
"1000",
"case",
"'m'",
":",
"return",
"number",
"*",
"60000",
"case",
"'h'",
":",
"return",
"number",
"*",
"3600000",
"case",
"'d'",
":",
"return",
"number",
"*",
"86400000",
"case",
"'w'",
":",
"return",
"number",
"*",
"604800000",
"default",
":",
"return",
"null",
"}",
"}"
] | Normalize duration value into milliseconds. | [
"Normalize",
"duration",
"value",
"into",
"milliseconds",
"."
] | ca9b1a2f5a03630c034ec92b4f61561cc8013eae | https://github.com/semibran/css-duration/blob/ca9b1a2f5a03630c034ec92b4f61561cc8013eae/index.js#L8-L20 |
56,922 | GeorP/js-ntc-logger | src/core/utils.js | mergeTags | function mergeTags(base, addition) {
Array.prototype.push.apply(base, addition);
return base;
} | javascript | function mergeTags(base, addition) {
Array.prototype.push.apply(base, addition);
return base;
} | [
"function",
"mergeTags",
"(",
"base",
",",
"addition",
")",
"{",
"Array",
".",
"prototype",
".",
"push",
".",
"apply",
"(",
"base",
",",
"addition",
")",
";",
"return",
"base",
";",
"}"
] | Modify base array adding all tag from addition | [
"Modify",
"base",
"array",
"adding",
"all",
"tag",
"from",
"addition"
] | 8eec0fc95794ae25d65b4424154ded72d7887ca2 | https://github.com/GeorP/js-ntc-logger/blob/8eec0fc95794ae25d65b4424154ded72d7887ca2/src/core/utils.js#L29-L32 |
56,923 | GeorP/js-ntc-logger | src/core/utils.js | logLevelLabel | function logLevelLabel(logLevel) {
switch (logLevel) {
case exports.LOG_EMERGENCY: return 'emergency';
case exports.LOG_ALERT: return 'alert';
case exports.LOG_CRITICAL: return 'critical';
case exports.LOG_ERROR: return 'error';
case exports.LOG_WARNING: return 'warning';
case exports.LOG_NOTICE: return 'notice';
case exports.LOG_INFORMATIONAL: return 'info';
case exports.LOG_DEBUG: return 'debug';
default: return '';
}
} | javascript | function logLevelLabel(logLevel) {
switch (logLevel) {
case exports.LOG_EMERGENCY: return 'emergency';
case exports.LOG_ALERT: return 'alert';
case exports.LOG_CRITICAL: return 'critical';
case exports.LOG_ERROR: return 'error';
case exports.LOG_WARNING: return 'warning';
case exports.LOG_NOTICE: return 'notice';
case exports.LOG_INFORMATIONAL: return 'info';
case exports.LOG_DEBUG: return 'debug';
default: return '';
}
} | [
"function",
"logLevelLabel",
"(",
"logLevel",
")",
"{",
"switch",
"(",
"logLevel",
")",
"{",
"case",
"exports",
".",
"LOG_EMERGENCY",
":",
"return",
"'emergency'",
";",
"case",
"exports",
".",
"LOG_ALERT",
":",
"return",
"'alert'",
";",
"case",
"exports",
".",
"LOG_CRITICAL",
":",
"return",
"'critical'",
";",
"case",
"exports",
".",
"LOG_ERROR",
":",
"return",
"'error'",
";",
"case",
"exports",
".",
"LOG_WARNING",
":",
"return",
"'warning'",
";",
"case",
"exports",
".",
"LOG_NOTICE",
":",
"return",
"'notice'",
";",
"case",
"exports",
".",
"LOG_INFORMATIONAL",
":",
"return",
"'info'",
";",
"case",
"exports",
".",
"LOG_DEBUG",
":",
"return",
"'debug'",
";",
"default",
":",
"return",
"''",
";",
"}",
"}"
] | Get label by syslog level tag | [
"Get",
"label",
"by",
"syslog",
"level",
"tag"
] | 8eec0fc95794ae25d65b4424154ded72d7887ca2 | https://github.com/GeorP/js-ntc-logger/blob/8eec0fc95794ae25d65b4424154ded72d7887ca2/src/core/utils.js#L37-L49 |
56,924 | GeorP/js-ntc-logger | src/core/utils.js | hasLogLevel | function hasLogLevel(tags, searchLogLevels) {
var logLevel = tags.filter(function (tag) { return searchLogLevels.indexOf(tag) !== -1; });
return logLevel.length ? logLevel[0] : '';
} | javascript | function hasLogLevel(tags, searchLogLevels) {
var logLevel = tags.filter(function (tag) { return searchLogLevels.indexOf(tag) !== -1; });
return logLevel.length ? logLevel[0] : '';
} | [
"function",
"hasLogLevel",
"(",
"tags",
",",
"searchLogLevels",
")",
"{",
"var",
"logLevel",
"=",
"tags",
".",
"filter",
"(",
"function",
"(",
"tag",
")",
"{",
"return",
"searchLogLevels",
".",
"indexOf",
"(",
"tag",
")",
"!==",
"-",
"1",
";",
"}",
")",
";",
"return",
"logLevel",
".",
"length",
"?",
"logLevel",
"[",
"0",
"]",
":",
"''",
";",
"}"
] | Check if list of tags has log level from searchLogLevels array
Returns first met tag or empty string if log level not found | [
"Check",
"if",
"list",
"of",
"tags",
"has",
"log",
"level",
"from",
"searchLogLevels",
"array",
"Returns",
"first",
"met",
"tag",
"or",
"empty",
"string",
"if",
"log",
"level",
"not",
"found"
] | 8eec0fc95794ae25d65b4424154ded72d7887ca2 | https://github.com/GeorP/js-ntc-logger/blob/8eec0fc95794ae25d65b4424154ded72d7887ca2/src/core/utils.js#L55-L58 |
56,925 | smikodanic/angular-form-validator | src/factory/validateFact.js | function (scope, iAttrs, newValue) {
'use strict';
var ngModelArr = iAttrs.ngModel.split('.');
// console.log(JSON.stringify(ngModelArr, null, 2));
switch (ngModelArr.length) {
case 1:
scope.$apply(function () {scope[ngModelArr[0]] = newValue;});
break;
case 2:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]] = newValue;});
break;
case 3:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]] = newValue;});
break;
case 4:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]][ngModelArr[3]] = newValue;});
break;
case 5:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]][ngModelArr[3]][ngModelArr[4]] = newValue;});
break;
default:
scope.$apply(function () {scope[iAttrs.ngModel] = newValue;});
}
} | javascript | function (scope, iAttrs, newValue) {
'use strict';
var ngModelArr = iAttrs.ngModel.split('.');
// console.log(JSON.stringify(ngModelArr, null, 2));
switch (ngModelArr.length) {
case 1:
scope.$apply(function () {scope[ngModelArr[0]] = newValue;});
break;
case 2:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]] = newValue;});
break;
case 3:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]] = newValue;});
break;
case 4:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]][ngModelArr[3]] = newValue;});
break;
case 5:
scope.$apply(function () {scope[ngModelArr[0]][ngModelArr[1]][ngModelArr[2]][ngModelArr[3]][ngModelArr[4]] = newValue;});
break;
default:
scope.$apply(function () {scope[iAttrs.ngModel] = newValue;});
}
} | [
"function",
"(",
"scope",
",",
"iAttrs",
",",
"newValue",
")",
"{",
"'use strict'",
";",
"var",
"ngModelArr",
"=",
"iAttrs",
".",
"ngModel",
".",
"split",
"(",
"'.'",
")",
";",
"// console.log(JSON.stringify(ngModelArr, null, 2));",
"switch",
"(",
"ngModelArr",
".",
"length",
")",
"{",
"case",
"1",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"ngModelArr",
"[",
"0",
"]",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"break",
";",
"case",
"2",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"ngModelArr",
"[",
"0",
"]",
"]",
"[",
"ngModelArr",
"[",
"1",
"]",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"break",
";",
"case",
"3",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"ngModelArr",
"[",
"0",
"]",
"]",
"[",
"ngModelArr",
"[",
"1",
"]",
"]",
"[",
"ngModelArr",
"[",
"2",
"]",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"break",
";",
"case",
"4",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"ngModelArr",
"[",
"0",
"]",
"]",
"[",
"ngModelArr",
"[",
"1",
"]",
"]",
"[",
"ngModelArr",
"[",
"2",
"]",
"]",
"[",
"ngModelArr",
"[",
"3",
"]",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"break",
";",
"case",
"5",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"ngModelArr",
"[",
"0",
"]",
"]",
"[",
"ngModelArr",
"[",
"1",
"]",
"]",
"[",
"ngModelArr",
"[",
"2",
"]",
"]",
"[",
"ngModelArr",
"[",
"3",
"]",
"]",
"[",
"ngModelArr",
"[",
"4",
"]",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"break",
";",
"default",
":",
"scope",
".",
"$apply",
"(",
"function",
"(",
")",
"{",
"scope",
"[",
"iAttrs",
".",
"ngModel",
"]",
"=",
"newValue",
";",
"}",
")",
";",
"}",
"}"
] | Update scope value. Usually on autocorrection.
@param {Object} scope - angular $scope object
@param {Object} iAttrs - attribute object which contains HTML tag attributes
@param {Mixed} - new value | [
"Update",
"scope",
"value",
".",
"Usually",
"on",
"autocorrection",
"."
] | 7030eacb4695e5f0a77a99f4234fe46d3357a4a3 | https://github.com/smikodanic/angular-form-validator/blob/7030eacb4695e5f0a77a99f4234fe46d3357a4a3/src/factory/validateFact.js#L27-L53 |
|
56,926 | YusukeHirao/sceg | lib/fn/get.js | get | function get(path) {
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = assignConfig_1.default(option, path);
return globElements_1.default(config).then(readElements_1.default(config)).then(optimize_1.default());
} | javascript | function get(path) {
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var config = assignConfig_1.default(option, path);
return globElements_1.default(config).then(readElements_1.default(config)).then(optimize_1.default());
} | [
"function",
"get",
"(",
"path",
")",
"{",
"var",
"option",
"=",
"arguments",
".",
"length",
">",
"1",
"&&",
"arguments",
"[",
"1",
"]",
"!==",
"undefined",
"?",
"arguments",
"[",
"1",
"]",
":",
"{",
"}",
";",
"var",
"config",
"=",
"assignConfig_1",
".",
"default",
"(",
"option",
",",
"path",
")",
";",
"return",
"globElements_1",
".",
"default",
"(",
"config",
")",
".",
"then",
"(",
"readElements_1",
".",
"default",
"(",
"config",
")",
")",
".",
"then",
"(",
"optimize_1",
".",
"default",
"(",
")",
")",
";",
"}"
] | Create guide data from elements
@param path Paths of element files that glob pattern
@param option Optional configure
@return guide data object | [
"Create",
"guide",
"data",
"from",
"elements"
] | 4cde1e56d48dd3b604cc2ddff36b2e9de3348771 | https://github.com/YusukeHirao/sceg/blob/4cde1e56d48dd3b604cc2ddff36b2e9de3348771/lib/fn/get.js#L15-L20 |
56,927 | tniedbala/jxh | dist/jxh.js | jxh | function jxh(obj, indentStr = ' ', indentLevel = 0) {
let html = '';
switch (getType(obj)) {
case 'array':
for (let item of obj) {
html += jxh(item, indentStr, indentLevel);
}
break;
case 'object':
for (let tag in obj) {
let content = obj[tag];
html += routeTags(tag, content, indentStr, indentLevel);
}
break;
default:
objTypeError(obj);
break;
}
return html;
} | javascript | function jxh(obj, indentStr = ' ', indentLevel = 0) {
let html = '';
switch (getType(obj)) {
case 'array':
for (let item of obj) {
html += jxh(item, indentStr, indentLevel);
}
break;
case 'object':
for (let tag in obj) {
let content = obj[tag];
html += routeTags(tag, content, indentStr, indentLevel);
}
break;
default:
objTypeError(obj);
break;
}
return html;
} | [
"function",
"jxh",
"(",
"obj",
",",
"indentStr",
"=",
"' '",
",",
"indentLevel",
"=",
"0",
")",
"{",
"let",
"html",
"=",
"''",
";",
"switch",
"(",
"getType",
"(",
"obj",
")",
")",
"{",
"case",
"'array'",
":",
"for",
"(",
"let",
"item",
"of",
"obj",
")",
"{",
"html",
"+=",
"jxh",
"(",
"item",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"}",
"break",
";",
"case",
"'object'",
":",
"for",
"(",
"let",
"tag",
"in",
"obj",
")",
"{",
"let",
"content",
"=",
"obj",
"[",
"tag",
"]",
";",
"html",
"+=",
"routeTags",
"(",
"tag",
",",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"}",
"break",
";",
"default",
":",
"objTypeError",
"(",
"obj",
")",
";",
"break",
";",
"}",
"return",
"html",
";",
"}"
] | main function - entry point for object & array arguments | [
"main",
"function",
"-",
"entry",
"point",
"for",
"object",
"&",
"array",
"arguments"
] | 83d699b126c5c7099ffea1f86ccacf5ec50ee6a9 | https://github.com/tniedbala/jxh/blob/83d699b126c5c7099ffea1f86ccacf5ec50ee6a9/dist/jxh.js#L14-L33 |
56,928 | tniedbala/jxh | dist/jxh.js | routeTags | function routeTags(tag, content, indentStr, indentLevel) {
if (COMPONENT.test(tag)) {
return jxh(content, indentStr, indentLevel);
} else {
let attrs = getType(content)==='object' ? getAttributes(content) : '';
switch (getType(content)) {
case 'null':
case 'undefined':
case 'NaN':
case 'string':
case 'number':
case 'boolean':
return renderElement(tag, attrs, content, indentStr, indentLevel);
break;
case 'array':
return parseArray(tag, attrs, content, indentStr, indentLevel);
break;
case 'object':
return parseObject(tag, attrs, content, indentStr, indentLevel);
break;
default:
objTypeError(content);
break;
}
}
} | javascript | function routeTags(tag, content, indentStr, indentLevel) {
if (COMPONENT.test(tag)) {
return jxh(content, indentStr, indentLevel);
} else {
let attrs = getType(content)==='object' ? getAttributes(content) : '';
switch (getType(content)) {
case 'null':
case 'undefined':
case 'NaN':
case 'string':
case 'number':
case 'boolean':
return renderElement(tag, attrs, content, indentStr, indentLevel);
break;
case 'array':
return parseArray(tag, attrs, content, indentStr, indentLevel);
break;
case 'object':
return parseObject(tag, attrs, content, indentStr, indentLevel);
break;
default:
objTypeError(content);
break;
}
}
} | [
"function",
"routeTags",
"(",
"tag",
",",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
"{",
"if",
"(",
"COMPONENT",
".",
"test",
"(",
"tag",
")",
")",
"{",
"return",
"jxh",
"(",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"}",
"else",
"{",
"let",
"attrs",
"=",
"getType",
"(",
"content",
")",
"===",
"'object'",
"?",
"getAttributes",
"(",
"content",
")",
":",
"''",
";",
"switch",
"(",
"getType",
"(",
"content",
")",
")",
"{",
"case",
"'null'",
":",
"case",
"'undefined'",
":",
"case",
"'NaN'",
":",
"case",
"'string'",
":",
"case",
"'number'",
":",
"case",
"'boolean'",
":",
"return",
"renderElement",
"(",
"tag",
",",
"attrs",
",",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"break",
";",
"case",
"'array'",
":",
"return",
"parseArray",
"(",
"tag",
",",
"attrs",
",",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"break",
";",
"case",
"'object'",
":",
"return",
"parseObject",
"(",
"tag",
",",
"attrs",
",",
"content",
",",
"indentStr",
",",
"indentLevel",
")",
";",
"break",
";",
"default",
":",
"objTypeError",
"(",
"content",
")",
";",
"break",
";",
"}",
"}",
"}"
] | route object members to appropriate parsing function based on member type | [
"route",
"object",
"members",
"to",
"appropriate",
"parsing",
"function",
"based",
"on",
"member",
"type"
] | 83d699b126c5c7099ffea1f86ccacf5ec50ee6a9 | https://github.com/tniedbala/jxh/blob/83d699b126c5c7099ffea1f86ccacf5ec50ee6a9/dist/jxh.js#L36-L61 |
56,929 | ugate/releasebot | lib/cmd.js | execCmd | function execCmd(c, gcr) {
return shell.exec(gcr ? c.replace(regexGitCmd, gcr) : c, {
silent : true
});
} | javascript | function execCmd(c, gcr) {
return shell.exec(gcr ? c.replace(regexGitCmd, gcr) : c, {
silent : true
});
} | [
"function",
"execCmd",
"(",
"c",
",",
"gcr",
")",
"{",
"return",
"shell",
".",
"exec",
"(",
"gcr",
"?",
"c",
".",
"replace",
"(",
"regexGitCmd",
",",
"gcr",
")",
":",
"c",
",",
"{",
"silent",
":",
"true",
"}",
")",
";",
"}"
] | Executes a shell command
@param c
the command to execute
@param gcr
the optional command replacement that will be substituted for the
"git" CLI (when applicable) | [
"Executes",
"a",
"shell",
"command"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/lib/cmd.js#L162-L166 |
56,930 | Industryswarm/isnode-mod-data | lib/mongodb/bson/lib/bson/regexp.js | BSONRegExp | function BSONRegExp(pattern, options) {
if (!(this instanceof BSONRegExp)) return new BSONRegExp();
// Execute
this._bsontype = 'BSONRegExp';
this.pattern = pattern || '';
this.options = options || '';
// Validate options
for (var i = 0; i < this.options.length; i++) {
if (
!(
this.options[i] === 'i' ||
this.options[i] === 'm' ||
this.options[i] === 'x' ||
this.options[i] === 'l' ||
this.options[i] === 's' ||
this.options[i] === 'u'
)
) {
throw new Error('the regular expression options [' + this.options[i] + '] is not supported');
}
}
} | javascript | function BSONRegExp(pattern, options) {
if (!(this instanceof BSONRegExp)) return new BSONRegExp();
// Execute
this._bsontype = 'BSONRegExp';
this.pattern = pattern || '';
this.options = options || '';
// Validate options
for (var i = 0; i < this.options.length; i++) {
if (
!(
this.options[i] === 'i' ||
this.options[i] === 'm' ||
this.options[i] === 'x' ||
this.options[i] === 'l' ||
this.options[i] === 's' ||
this.options[i] === 'u'
)
) {
throw new Error('the regular expression options [' + this.options[i] + '] is not supported');
}
}
} | [
"function",
"BSONRegExp",
"(",
"pattern",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"BSONRegExp",
")",
")",
"return",
"new",
"BSONRegExp",
"(",
")",
";",
"// Execute",
"this",
".",
"_bsontype",
"=",
"'BSONRegExp'",
";",
"this",
".",
"pattern",
"=",
"pattern",
"||",
"''",
";",
"this",
".",
"options",
"=",
"options",
"||",
"''",
";",
"// Validate options",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"options",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"(",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'i'",
"||",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'m'",
"||",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'x'",
"||",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'l'",
"||",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'s'",
"||",
"this",
".",
"options",
"[",
"i",
"]",
"===",
"'u'",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'the regular expression options ['",
"+",
"this",
".",
"options",
"[",
"i",
"]",
"+",
"'] is not supported'",
")",
";",
"}",
"}",
"}"
] | A class representation of the BSON RegExp type.
@class
@return {BSONRegExp} A MinKey instance | [
"A",
"class",
"representation",
"of",
"the",
"BSON",
"RegExp",
"type",
"."
] | 5adc639b88a0d72cbeef23a6b5df7f4540745089 | https://github.com/Industryswarm/isnode-mod-data/blob/5adc639b88a0d72cbeef23a6b5df7f4540745089/lib/mongodb/bson/lib/bson/regexp.js#L7-L30 |
56,931 | meisterplayer/js-dev | gulp/watch.js | createWatcher | function createWatcher(inPath, callback) {
if (!inPath) {
throw new Error('Input path argument is required');
}
if (!callback) {
throw new Error('Callback argument is required');
}
return function watcher() {
watch(inPath, callback);
};
} | javascript | function createWatcher(inPath, callback) {
if (!inPath) {
throw new Error('Input path argument is required');
}
if (!callback) {
throw new Error('Callback argument is required');
}
return function watcher() {
watch(inPath, callback);
};
} | [
"function",
"createWatcher",
"(",
"inPath",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"inPath",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Input path argument is required'",
")",
";",
"}",
"if",
"(",
"!",
"callback",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Callback argument is required'",
")",
";",
"}",
"return",
"function",
"watcher",
"(",
")",
"{",
"watch",
"(",
"inPath",
",",
"callback",
")",
";",
"}",
";",
"}"
] | Higher order function to create gulp function that watches files and calls a callback on changes.
@param {string|string[]} inPath The globs to the files that need to be watched.
@param {function} callback Callback to be called when the watched files change.
@return {function} Function that can be used as a gulp task | [
"Higher",
"order",
"function",
"to",
"create",
"gulp",
"function",
"that",
"watches",
"files",
"and",
"calls",
"a",
"callback",
"on",
"changes",
"."
] | c2646678c49dcdaa120ba3f24824da52b0c63e31 | https://github.com/meisterplayer/js-dev/blob/c2646678c49dcdaa120ba3f24824da52b0c63e31/gulp/watch.js#L9-L21 |
56,932 | sazze/node-eventsd-server | lib/consumers/amqp.js | stopAll | function stopAll(socket) {
if (_.isEmpty(this.consumers)) {
return;
}
_.forOwn(this.consumers[socket.id].routingKeys, function (consumer, routingKey) {
if (routingKey == '#') {
// this must be done to prevent infinite stop loop
routingKey = '##';
}
this.stopConsume(socket, {routingKey: routingKey});
}.bind(this));
} | javascript | function stopAll(socket) {
if (_.isEmpty(this.consumers)) {
return;
}
_.forOwn(this.consumers[socket.id].routingKeys, function (consumer, routingKey) {
if (routingKey == '#') {
// this must be done to prevent infinite stop loop
routingKey = '##';
}
this.stopConsume(socket, {routingKey: routingKey});
}.bind(this));
} | [
"function",
"stopAll",
"(",
"socket",
")",
"{",
"if",
"(",
"_",
".",
"isEmpty",
"(",
"this",
".",
"consumers",
")",
")",
"{",
"return",
";",
"}",
"_",
".",
"forOwn",
"(",
"this",
".",
"consumers",
"[",
"socket",
".",
"id",
"]",
".",
"routingKeys",
",",
"function",
"(",
"consumer",
",",
"routingKey",
")",
"{",
"if",
"(",
"routingKey",
"==",
"'#'",
")",
"{",
"// this must be done to prevent infinite stop loop",
"routingKey",
"=",
"'##'",
";",
"}",
"this",
".",
"stopConsume",
"(",
"socket",
",",
"{",
"routingKey",
":",
"routingKey",
"}",
")",
";",
"}",
".",
"bind",
"(",
"this",
")",
")",
";",
"}"
] | Stop all consumers linked to a socket
@param socket | [
"Stop",
"all",
"consumers",
"linked",
"to",
"a",
"socket"
] | a11ce6d4b3f002dab4c8692743cb6d59ad4b0abb | https://github.com/sazze/node-eventsd-server/blob/a11ce6d4b3f002dab4c8692743cb6d59ad4b0abb/lib/consumers/amqp.js#L136-L149 |
56,933 | activethread/vulpejs | lib/utils/index.js | function(array, property, searchTerm) {
for (var i = 0, len = array.length; i < len; ++i) {
var value = array[i][property];
if (value === searchTerm || value.indexOf(searchTerm) !== -1) {
return i
};
}
return -1;
} | javascript | function(array, property, searchTerm) {
for (var i = 0, len = array.length; i < len; ++i) {
var value = array[i][property];
if (value === searchTerm || value.indexOf(searchTerm) !== -1) {
return i
};
}
return -1;
} | [
"function",
"(",
"array",
",",
"property",
",",
"searchTerm",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"array",
".",
"length",
";",
"i",
"<",
"len",
";",
"++",
"i",
")",
"{",
"var",
"value",
"=",
"array",
"[",
"i",
"]",
"[",
"property",
"]",
";",
"if",
"(",
"value",
"===",
"searchTerm",
"||",
"value",
".",
"indexOf",
"(",
"searchTerm",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"i",
"}",
";",
"}",
"return",
"-",
"1",
";",
"}"
] | Return index of array on search by term in specific property.
@param {Array} array
@param {String} property
@param {String} searchTerm
@return {Integer} Index | [
"Return",
"index",
"of",
"array",
"on",
"search",
"by",
"term",
"in",
"specific",
"property",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/utils/index.js#L19-L27 |
|
56,934 | antonycourtney/tabli-core | lib/js/components/NewTabPage.js | sendHelperMessage | function sendHelperMessage(msg) {
var port = chrome.runtime.connect({ name: 'popup' });
port.postMessage(msg);
port.onMessage.addListener(function (response) {
console.log('Got response message: ', response);
});
} | javascript | function sendHelperMessage(msg) {
var port = chrome.runtime.connect({ name: 'popup' });
port.postMessage(msg);
port.onMessage.addListener(function (response) {
console.log('Got response message: ', response);
});
} | [
"function",
"sendHelperMessage",
"(",
"msg",
")",
"{",
"var",
"port",
"=",
"chrome",
".",
"runtime",
".",
"connect",
"(",
"{",
"name",
":",
"'popup'",
"}",
")",
";",
"port",
".",
"postMessage",
"(",
"msg",
")",
";",
"port",
".",
"onMessage",
".",
"addListener",
"(",
"function",
"(",
"response",
")",
"{",
"console",
".",
"log",
"(",
"'Got response message: '",
",",
"response",
")",
";",
"}",
")",
";",
"}"
] | send message to BGhelper | [
"send",
"message",
"to",
"BGhelper"
] | 76cc540891421bc6c8bdcf00f277ebb6e716fdd9 | https://github.com/antonycourtney/tabli-core/blob/76cc540891421bc6c8bdcf00f277ebb6e716fdd9/lib/js/components/NewTabPage.js#L44-L50 |
56,935 | scottyapp/node-scottyapp-api-client | lib/client.js | Client | function Client(key, secret, scope) {
this.key = key;
this.secret = secret;
this.scope = scope != null ? scope : "read write";
this._request = __bind(this._request, this);
this._delete = __bind(this._delete, this);
this._put = __bind(this._put, this);
this._post = __bind(this._post, this);
this._postAsForm = __bind(this._postAsForm, this);
this._get = __bind(this._get, this);
this.info = __bind(this.info, this);
this.deleteApp = __bind(this.deleteApp, this);
this.updateApp = __bind(this.updateApp, this);
this.app = __bind(this.app, this);
this.createApp = __bind(this.createApp, this);
this.appsForOrganization = __bind(this.appsForOrganization, this);
this.deleteOrganization = __bind(this.deleteOrganization, this);
this.createOrganization = __bind(this.createOrganization, this);
this.updateOrganization = __bind(this.updateOrganization, this);
this.organization = __bind(this.organization, this);
this.organizations = __bind(this.organizations, this);
this.organizationsForUser = __bind(this.organizationsForUser, this);
this.updateUser = __bind(this.updateUser, this);
this.createUser = __bind(this.createUser, this);
this.updateMe = __bind(this.updateMe, this);
this.me = __bind(this.me, this);
this.authenticate = __bind(this.authenticate, this);
this.setAccessToken = __bind(this.setAccessToken, this);
if (!(this.key && this.secret)) {
throw new Error("You need to pass a key and secret");
}
} | javascript | function Client(key, secret, scope) {
this.key = key;
this.secret = secret;
this.scope = scope != null ? scope : "read write";
this._request = __bind(this._request, this);
this._delete = __bind(this._delete, this);
this._put = __bind(this._put, this);
this._post = __bind(this._post, this);
this._postAsForm = __bind(this._postAsForm, this);
this._get = __bind(this._get, this);
this.info = __bind(this.info, this);
this.deleteApp = __bind(this.deleteApp, this);
this.updateApp = __bind(this.updateApp, this);
this.app = __bind(this.app, this);
this.createApp = __bind(this.createApp, this);
this.appsForOrganization = __bind(this.appsForOrganization, this);
this.deleteOrganization = __bind(this.deleteOrganization, this);
this.createOrganization = __bind(this.createOrganization, this);
this.updateOrganization = __bind(this.updateOrganization, this);
this.organization = __bind(this.organization, this);
this.organizations = __bind(this.organizations, this);
this.organizationsForUser = __bind(this.organizationsForUser, this);
this.updateUser = __bind(this.updateUser, this);
this.createUser = __bind(this.createUser, this);
this.updateMe = __bind(this.updateMe, this);
this.me = __bind(this.me, this);
this.authenticate = __bind(this.authenticate, this);
this.setAccessToken = __bind(this.setAccessToken, this);
if (!(this.key && this.secret)) {
throw new Error("You need to pass a key and secret");
}
} | [
"function",
"Client",
"(",
"key",
",",
"secret",
",",
"scope",
")",
"{",
"this",
".",
"key",
"=",
"key",
";",
"this",
".",
"secret",
"=",
"secret",
";",
"this",
".",
"scope",
"=",
"scope",
"!=",
"null",
"?",
"scope",
":",
"\"read write\"",
";",
"this",
".",
"_request",
"=",
"__bind",
"(",
"this",
".",
"_request",
",",
"this",
")",
";",
"this",
".",
"_delete",
"=",
"__bind",
"(",
"this",
".",
"_delete",
",",
"this",
")",
";",
"this",
".",
"_put",
"=",
"__bind",
"(",
"this",
".",
"_put",
",",
"this",
")",
";",
"this",
".",
"_post",
"=",
"__bind",
"(",
"this",
".",
"_post",
",",
"this",
")",
";",
"this",
".",
"_postAsForm",
"=",
"__bind",
"(",
"this",
".",
"_postAsForm",
",",
"this",
")",
";",
"this",
".",
"_get",
"=",
"__bind",
"(",
"this",
".",
"_get",
",",
"this",
")",
";",
"this",
".",
"info",
"=",
"__bind",
"(",
"this",
".",
"info",
",",
"this",
")",
";",
"this",
".",
"deleteApp",
"=",
"__bind",
"(",
"this",
".",
"deleteApp",
",",
"this",
")",
";",
"this",
".",
"updateApp",
"=",
"__bind",
"(",
"this",
".",
"updateApp",
",",
"this",
")",
";",
"this",
".",
"app",
"=",
"__bind",
"(",
"this",
".",
"app",
",",
"this",
")",
";",
"this",
".",
"createApp",
"=",
"__bind",
"(",
"this",
".",
"createApp",
",",
"this",
")",
";",
"this",
".",
"appsForOrganization",
"=",
"__bind",
"(",
"this",
".",
"appsForOrganization",
",",
"this",
")",
";",
"this",
".",
"deleteOrganization",
"=",
"__bind",
"(",
"this",
".",
"deleteOrganization",
",",
"this",
")",
";",
"this",
".",
"createOrganization",
"=",
"__bind",
"(",
"this",
".",
"createOrganization",
",",
"this",
")",
";",
"this",
".",
"updateOrganization",
"=",
"__bind",
"(",
"this",
".",
"updateOrganization",
",",
"this",
")",
";",
"this",
".",
"organization",
"=",
"__bind",
"(",
"this",
".",
"organization",
",",
"this",
")",
";",
"this",
".",
"organizations",
"=",
"__bind",
"(",
"this",
".",
"organizations",
",",
"this",
")",
";",
"this",
".",
"organizationsForUser",
"=",
"__bind",
"(",
"this",
".",
"organizationsForUser",
",",
"this",
")",
";",
"this",
".",
"updateUser",
"=",
"__bind",
"(",
"this",
".",
"updateUser",
",",
"this",
")",
";",
"this",
".",
"createUser",
"=",
"__bind",
"(",
"this",
".",
"createUser",
",",
"this",
")",
";",
"this",
".",
"updateMe",
"=",
"__bind",
"(",
"this",
".",
"updateMe",
",",
"this",
")",
";",
"this",
".",
"me",
"=",
"__bind",
"(",
"this",
".",
"me",
",",
"this",
")",
";",
"this",
".",
"authenticate",
"=",
"__bind",
"(",
"this",
".",
"authenticate",
",",
"this",
")",
";",
"this",
".",
"setAccessToken",
"=",
"__bind",
"(",
"this",
".",
"setAccessToken",
",",
"this",
")",
";",
"if",
"(",
"!",
"(",
"this",
".",
"key",
"&&",
"this",
".",
"secret",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You need to pass a key and secret\"",
")",
";",
"}",
"}"
] | Initializes a new instance of @see Client
@param (String) key the api key obtained from scottyapp.com/developers
@param (String) secret the api secret
@param (String) scope defaults to "read write". | [
"Initializes",
"a",
"new",
"instance",
"of"
] | d63fe1cea2fa1cebcf8ad8332559ba0e86d9886e | https://github.com/scottyapp/node-scottyapp-api-client/blob/d63fe1cea2fa1cebcf8ad8332559ba0e86d9886e/lib/client.js#L21-L52 |
56,936 | tfennelly/jenkins-js-logging | index.js | function (message) {
if (this.isEnabled(Level.LOG)) {
console.log.apply(console, logArgs(Level.LOG, this.category, arguments));
}
} | javascript | function (message) {
if (this.isEnabled(Level.LOG)) {
console.log.apply(console, logArgs(Level.LOG, this.category, arguments));
}
} | [
"function",
"(",
"message",
")",
"{",
"if",
"(",
"this",
".",
"isEnabled",
"(",
"Level",
".",
"LOG",
")",
")",
"{",
"console",
".",
"log",
".",
"apply",
"(",
"console",
",",
"logArgs",
"(",
"Level",
".",
"LOG",
",",
"this",
".",
"category",
",",
"arguments",
")",
")",
";",
"}",
"}"
] | Log an "log" level message.
@param {...*} message Message arguments. | [
"Log",
"an",
"log",
"level",
"message",
"."
] | 4bc37157f1b6e001b97f41ce53df301ed8d50df7 | https://github.com/tfennelly/jenkins-js-logging/blob/4bc37157f1b6e001b97f41ce53df301ed8d50df7/index.js#L213-L217 |
|
56,937 | tfennelly/jenkins-js-logging | index.js | function (message) {
if (this.isEnabled(Level.INFO)) {
console.info.apply(console, logArgs(Level.INFO, this.category, arguments));
}
} | javascript | function (message) {
if (this.isEnabled(Level.INFO)) {
console.info.apply(console, logArgs(Level.INFO, this.category, arguments));
}
} | [
"function",
"(",
"message",
")",
"{",
"if",
"(",
"this",
".",
"isEnabled",
"(",
"Level",
".",
"INFO",
")",
")",
"{",
"console",
".",
"info",
".",
"apply",
"(",
"console",
",",
"logArgs",
"(",
"Level",
".",
"INFO",
",",
"this",
".",
"category",
",",
"arguments",
")",
")",
";",
"}",
"}"
] | Log an info message.
@param {...*} message Message arguments. | [
"Log",
"an",
"info",
"message",
"."
] | 4bc37157f1b6e001b97f41ce53df301ed8d50df7 | https://github.com/tfennelly/jenkins-js-logging/blob/4bc37157f1b6e001b97f41ce53df301ed8d50df7/index.js#L223-L227 |
|
56,938 | tfennelly/jenkins-js-logging | index.js | function (message) {
if (this.isEnabled(Level.WARN)) {
console.warn.apply(console, logArgs(Level.WARN, this.category, arguments));
}
} | javascript | function (message) {
if (this.isEnabled(Level.WARN)) {
console.warn.apply(console, logArgs(Level.WARN, this.category, arguments));
}
} | [
"function",
"(",
"message",
")",
"{",
"if",
"(",
"this",
".",
"isEnabled",
"(",
"Level",
".",
"WARN",
")",
")",
"{",
"console",
".",
"warn",
".",
"apply",
"(",
"console",
",",
"logArgs",
"(",
"Level",
".",
"WARN",
",",
"this",
".",
"category",
",",
"arguments",
")",
")",
";",
"}",
"}"
] | Log a warn message.
@param {...*} message Message arguments. | [
"Log",
"a",
"warn",
"message",
"."
] | 4bc37157f1b6e001b97f41ce53df301ed8d50df7 | https://github.com/tfennelly/jenkins-js-logging/blob/4bc37157f1b6e001b97f41ce53df301ed8d50df7/index.js#L233-L237 |
|
56,939 | acos-server/acos-kelmu | static/kelmu.js | function() {
annotationsDiv.children().remove();
container.find('.kelmu-arrow-handle').remove();
container.children('svg').first().remove();
container.find('audio.kelmu-annotation-sound').each(function() {
try {
this.pause();
} catch (err) {
// Ignore if stopping sounds raised any errors
}
});
} | javascript | function() {
annotationsDiv.children().remove();
container.find('.kelmu-arrow-handle').remove();
container.children('svg').first().remove();
container.find('audio.kelmu-annotation-sound').each(function() {
try {
this.pause();
} catch (err) {
// Ignore if stopping sounds raised any errors
}
});
} | [
"function",
"(",
")",
"{",
"annotationsDiv",
".",
"children",
"(",
")",
".",
"remove",
"(",
")",
";",
"container",
".",
"find",
"(",
"'.kelmu-arrow-handle'",
")",
".",
"remove",
"(",
")",
";",
"container",
".",
"children",
"(",
"'svg'",
")",
".",
"first",
"(",
")",
".",
"remove",
"(",
")",
";",
"container",
".",
"find",
"(",
"'audio.kelmu-annotation-sound'",
")",
".",
"each",
"(",
"function",
"(",
")",
"{",
"try",
"{",
"this",
".",
"pause",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"// Ignore if stopping sounds raised any errors",
"}",
"}",
")",
";",
"}"
] | default value which can be changed by sending animationLength message | [
"default",
"value",
"which",
"can",
"be",
"changed",
"by",
"sending",
"animationLength",
"message"
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L71-L82 |
|
56,940 | acos-server/acos-kelmu | static/kelmu.js | function(event) {
event.preventDefault();
if ((window.kelmu.data[id].definitions['step' + window.kelmu.data[id].stepNumber] || [null]).length - 1 === window.kelmu.data[id].subStepNumber) {
// Move to next step
clearAnnotations();
window.kelmu.data[id].stepNumber += 1;
window.kelmu.data[id].subStepNumber = 0;
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
originalStep(event);
// If the animator is not able to report when the animation is ready,
// create the annotations for the next step after a delay
if (!window.kelmu.data[id].animationReadyAvailable) {
setTimeout(function() {
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}, window.kelmu.data[id].settings.animationLength);
}
} else {
// Move to next substep
window.kelmu.data[id].subStepNumber += 1;
window.kelmu.data[id].actions.setSubstep(window.kelmu.data[id].subStepNumber);
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}
if (window.kelmu.data[id].stepsToRun === 0) {
// Add the current state to the undo stack if there are no more steps to run
window.kelmu.data[id].undoStack.splice(window.kelmu.data[id].undoStackPointer + 1, window.kelmu.data[id].undoStack.length);
window.kelmu.data[id].undoStack.push([window.kelmu.data[id].stepNumber, window.kelmu.data[id].subStepNumber]);
window.kelmu.data[id].undoStackPointer += 1;
}
} | javascript | function(event) {
event.preventDefault();
if ((window.kelmu.data[id].definitions['step' + window.kelmu.data[id].stepNumber] || [null]).length - 1 === window.kelmu.data[id].subStepNumber) {
// Move to next step
clearAnnotations();
window.kelmu.data[id].stepNumber += 1;
window.kelmu.data[id].subStepNumber = 0;
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
originalStep(event);
// If the animator is not able to report when the animation is ready,
// create the annotations for the next step after a delay
if (!window.kelmu.data[id].animationReadyAvailable) {
setTimeout(function() {
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}, window.kelmu.data[id].settings.animationLength);
}
} else {
// Move to next substep
window.kelmu.data[id].subStepNumber += 1;
window.kelmu.data[id].actions.setSubstep(window.kelmu.data[id].subStepNumber);
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}
if (window.kelmu.data[id].stepsToRun === 0) {
// Add the current state to the undo stack if there are no more steps to run
window.kelmu.data[id].undoStack.splice(window.kelmu.data[id].undoStackPointer + 1, window.kelmu.data[id].undoStack.length);
window.kelmu.data[id].undoStack.push([window.kelmu.data[id].stepNumber, window.kelmu.data[id].subStepNumber]);
window.kelmu.data[id].undoStackPointer += 1;
}
} | [
"function",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"definitions",
"[",
"'step'",
"+",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
"]",
"||",
"[",
"null",
"]",
")",
".",
"length",
"-",
"1",
"===",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
")",
"{",
"// Move to next step",
"clearAnnotations",
"(",
")",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
"+=",
"1",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"=",
"0",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
"true",
",",
"true",
")",
";",
"}",
"originalStep",
"(",
"event",
")",
";",
"// If the animator is not able to report when the animation is ready,",
"// create the annotations for the next step after a delay",
"if",
"(",
"!",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"animationReadyAvailable",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"createAnnotations",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
"true",
",",
"true",
")",
";",
"}",
"}",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"animationLength",
")",
";",
"}",
"}",
"else",
"{",
"// Move to next substep",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"+=",
"1",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"setSubstep",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
"true",
",",
"true",
")",
";",
"}",
"}",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepsToRun",
"===",
"0",
")",
"{",
"// Add the current state to the undo stack if there are no more steps to run",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"splice",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"+",
"1",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"length",
")",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"push",
"(",
"[",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"]",
")",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"+=",
"1",
";",
"}",
"}"
] | Functionality for step button. | [
"Functionality",
"for",
"step",
"button",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L92-L134 |
|
56,941 | acos-server/acos-kelmu | static/kelmu.js | function(event) {
event.preventDefault();
if (window.kelmu.data[id].undoStackPointer < window.kelmu.data[id].undoStack.length - 1) {
var sp = window.kelmu.data[id].undoStackPointer;
if (window.kelmu.data[id].undoStack[sp + 1][0] !== window.kelmu.data[id].stepNumber) {
originalRedo(event);
}
window.kelmu.data[id].undoStackPointer += 1;
sp = window.kelmu.data[id].undoStackPointer;
window.kelmu.data[id].stepNumber = window.kelmu.data[id].undoStack[sp][0];
window.kelmu.data[id].subStepNumber = window.kelmu.data[id].undoStack[sp][1];
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}
} | javascript | function(event) {
event.preventDefault();
if (window.kelmu.data[id].undoStackPointer < window.kelmu.data[id].undoStack.length - 1) {
var sp = window.kelmu.data[id].undoStackPointer;
if (window.kelmu.data[id].undoStack[sp + 1][0] !== window.kelmu.data[id].stepNumber) {
originalRedo(event);
}
window.kelmu.data[id].undoStackPointer += 1;
sp = window.kelmu.data[id].undoStackPointer;
window.kelmu.data[id].stepNumber = window.kelmu.data[id].undoStack[sp][0];
window.kelmu.data[id].subStepNumber = window.kelmu.data[id].undoStack[sp][1];
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
}
} | [
"function",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"<",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"length",
"-",
"1",
")",
"{",
"var",
"sp",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
"[",
"sp",
"+",
"1",
"]",
"[",
"0",
"]",
"!==",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
")",
"{",
"originalRedo",
"(",
"event",
")",
";",
"}",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"+=",
"1",
";",
"sp",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
"[",
"sp",
"]",
"[",
"0",
"]",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
"[",
"sp",
"]",
"[",
"1",
"]",
";",
"createAnnotations",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
"true",
",",
"true",
")",
";",
"}",
"}",
"}"
] | Functionality for redo button. | [
"Functionality",
"for",
"redo",
"button",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L139-L162 |
|
56,942 | acos-server/acos-kelmu | static/kelmu.js | function(event) {
event.preventDefault();
if (window.kelmu.data[id].undoStack[0][0] !== window.kelmu.data[id].stepNumber) {
originalBegin(event);
}
window.kelmu.data[id].undoStackPointer = 0;
window.kelmu.data[id].stepNumber = 0;
window.kelmu.data[id].subStepNumber = 0;
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
} | javascript | function(event) {
event.preventDefault();
if (window.kelmu.data[id].undoStack[0][0] !== window.kelmu.data[id].stepNumber) {
originalBegin(event);
}
window.kelmu.data[id].undoStackPointer = 0;
window.kelmu.data[id].stepNumber = 0;
window.kelmu.data[id].subStepNumber = 0;
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor(true, true);
}
} | [
"function",
"(",
"event",
")",
"{",
"event",
".",
"preventDefault",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
"[",
"0",
"]",
"[",
"0",
"]",
"!==",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
")",
"{",
"originalBegin",
"(",
"event",
")",
";",
"}",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"=",
"0",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
"=",
"0",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"=",
"0",
";",
"createAnnotations",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
"true",
",",
"true",
")",
";",
"}",
"}"
] | Functionality for begin button. | [
"Functionality",
"for",
"begin",
"button",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L195-L212 |
|
56,943 | acos-server/acos-kelmu | static/kelmu.js | function(event, showAction) {
var data = window.kelmu.data[id];
var count = Math.max(+showAction.parameter || 1, 1);
var action = function() {
forward(event);
};
if (!data.animationReadyAvailable) {
for (var i = 0; i < count; i++) {
setTimeout(action, i * (data.settings.animationLength + 300));
}
} else {
data.stepEvent = event;
data.stepsToRun = count - 1;
if (data.stepsToRun > 0) {
// Notify the animator that we are running multiple steps that should be combined into a single step
window.kelmu.sendMessage(id, 'showSequence');
}
forward(event);
}
} | javascript | function(event, showAction) {
var data = window.kelmu.data[id];
var count = Math.max(+showAction.parameter || 1, 1);
var action = function() {
forward(event);
};
if (!data.animationReadyAvailable) {
for (var i = 0; i < count; i++) {
setTimeout(action, i * (data.settings.animationLength + 300));
}
} else {
data.stepEvent = event;
data.stepsToRun = count - 1;
if (data.stepsToRun > 0) {
// Notify the animator that we are running multiple steps that should be combined into a single step
window.kelmu.sendMessage(id, 'showSequence');
}
forward(event);
}
} | [
"function",
"(",
"event",
",",
"showAction",
")",
"{",
"var",
"data",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
";",
"var",
"count",
"=",
"Math",
".",
"max",
"(",
"+",
"showAction",
".",
"parameter",
"||",
"1",
",",
"1",
")",
";",
"var",
"action",
"=",
"function",
"(",
")",
"{",
"forward",
"(",
"event",
")",
";",
"}",
";",
"if",
"(",
"!",
"data",
".",
"animationReadyAvailable",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"setTimeout",
"(",
"action",
",",
"i",
"*",
"(",
"data",
".",
"settings",
".",
"animationLength",
"+",
"300",
")",
")",
";",
"}",
"}",
"else",
"{",
"data",
".",
"stepEvent",
"=",
"event",
";",
"data",
".",
"stepsToRun",
"=",
"count",
"-",
"1",
";",
"if",
"(",
"data",
".",
"stepsToRun",
">",
"0",
")",
"{",
"// Notify the animator that we are running multiple steps that should be combined into a single step",
"window",
".",
"kelmu",
".",
"sendMessage",
"(",
"id",
",",
"'showSequence'",
")",
";",
"}",
"forward",
"(",
"event",
")",
";",
"}",
"}"
] | Functionality for the `show` action. | [
"Functionality",
"for",
"the",
"show",
"action",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L217-L240 |
|
56,944 | acos-server/acos-kelmu | static/kelmu.js | function() {
var events;
var button;
if (window.kelmu.data[id].settings.step && !stepButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.step);
if (button.length > 0) {
events = $._data(button[0], 'events');
stepButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalStep = events.click[0].handler;
events.click[0].handler = forwardAndSkip;
} else {
button.click(forwardAndSkip);
}
}
}
if (window.kelmu.data[id].settings.redo && !redoButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.redo);
if (button.length > 0) {
events = $._data(button[0], 'events');
redoButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalRedo = events.click[0].handler;
events.click[0].handler = redo;
} else {
button.click(redo);
}
}
}
if (window.kelmu.data[id].settings.undo && !undoButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.undo);
if (button.length > 0) {
events = $._data(button[0], 'events');
undoButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalUndo = events.click[0].handler;
events.click[0].handler = undo;
} else {
button.click(undo);
}
}
}
if (window.kelmu.data[id].settings.begin && !beginButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.begin);
if (button.length > 0) {
events = $._data(button[0], 'events');
beginButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalBegin = events.click[0].handler;
events.click[0].handler = begin;
} else {
button.click(begin);
}
}
}
} | javascript | function() {
var events;
var button;
if (window.kelmu.data[id].settings.step && !stepButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.step);
if (button.length > 0) {
events = $._data(button[0], 'events');
stepButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalStep = events.click[0].handler;
events.click[0].handler = forwardAndSkip;
} else {
button.click(forwardAndSkip);
}
}
}
if (window.kelmu.data[id].settings.redo && !redoButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.redo);
if (button.length > 0) {
events = $._data(button[0], 'events');
redoButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalRedo = events.click[0].handler;
events.click[0].handler = redo;
} else {
button.click(redo);
}
}
}
if (window.kelmu.data[id].settings.undo && !undoButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.undo);
if (button.length > 0) {
events = $._data(button[0], 'events');
undoButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalUndo = events.click[0].handler;
events.click[0].handler = undo;
} else {
button.click(undo);
}
}
}
if (window.kelmu.data[id].settings.begin && !beginButtonInitialized) {
button = element.find(window.kelmu.data[id].settings.begin);
if (button.length > 0) {
events = $._data(button[0], 'events');
beginButtonInitialized = true;
if (events && events.click && events.click.length > 0) {
originalBegin = events.click[0].handler;
events.click[0].handler = begin;
} else {
button.click(begin);
}
}
}
} | [
"function",
"(",
")",
"{",
"var",
"events",
";",
"var",
"button",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"step",
"&&",
"!",
"stepButtonInitialized",
")",
"{",
"button",
"=",
"element",
".",
"find",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"step",
")",
";",
"if",
"(",
"button",
".",
"length",
">",
"0",
")",
"{",
"events",
"=",
"$",
".",
"_data",
"(",
"button",
"[",
"0",
"]",
",",
"'events'",
")",
";",
"stepButtonInitialized",
"=",
"true",
";",
"if",
"(",
"events",
"&&",
"events",
".",
"click",
"&&",
"events",
".",
"click",
".",
"length",
">",
"0",
")",
"{",
"originalStep",
"=",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
";",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
"=",
"forwardAndSkip",
";",
"}",
"else",
"{",
"button",
".",
"click",
"(",
"forwardAndSkip",
")",
";",
"}",
"}",
"}",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"redo",
"&&",
"!",
"redoButtonInitialized",
")",
"{",
"button",
"=",
"element",
".",
"find",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"redo",
")",
";",
"if",
"(",
"button",
".",
"length",
">",
"0",
")",
"{",
"events",
"=",
"$",
".",
"_data",
"(",
"button",
"[",
"0",
"]",
",",
"'events'",
")",
";",
"redoButtonInitialized",
"=",
"true",
";",
"if",
"(",
"events",
"&&",
"events",
".",
"click",
"&&",
"events",
".",
"click",
".",
"length",
">",
"0",
")",
"{",
"originalRedo",
"=",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
";",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
"=",
"redo",
";",
"}",
"else",
"{",
"button",
".",
"click",
"(",
"redo",
")",
";",
"}",
"}",
"}",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"undo",
"&&",
"!",
"undoButtonInitialized",
")",
"{",
"button",
"=",
"element",
".",
"find",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"undo",
")",
";",
"if",
"(",
"button",
".",
"length",
">",
"0",
")",
"{",
"events",
"=",
"$",
".",
"_data",
"(",
"button",
"[",
"0",
"]",
",",
"'events'",
")",
";",
"undoButtonInitialized",
"=",
"true",
";",
"if",
"(",
"events",
"&&",
"events",
".",
"click",
"&&",
"events",
".",
"click",
".",
"length",
">",
"0",
")",
"{",
"originalUndo",
"=",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
";",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
"=",
"undo",
";",
"}",
"else",
"{",
"button",
".",
"click",
"(",
"undo",
")",
";",
"}",
"}",
"}",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"begin",
"&&",
"!",
"beginButtonInitialized",
")",
"{",
"button",
"=",
"element",
".",
"find",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"begin",
")",
";",
"if",
"(",
"button",
".",
"length",
">",
"0",
")",
"{",
"events",
"=",
"$",
".",
"_data",
"(",
"button",
"[",
"0",
"]",
",",
"'events'",
")",
";",
"beginButtonInitialized",
"=",
"true",
";",
"if",
"(",
"events",
"&&",
"events",
".",
"click",
"&&",
"events",
".",
"click",
".",
"length",
">",
"0",
")",
"{",
"originalBegin",
"=",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
";",
"events",
".",
"click",
"[",
"0",
"]",
".",
"handler",
"=",
"begin",
";",
"}",
"else",
"{",
"button",
".",
"click",
"(",
"begin",
")",
";",
"}",
"}",
"}",
"}"
] | Initializes the buttons and sets proxies to take over the original click handlers. | [
"Initializes",
"the",
"buttons",
"and",
"sets",
"proxies",
"to",
"take",
"over",
"the",
"original",
"click",
"handlers",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L271-L336 |
|
56,945 | acos-server/acos-kelmu | static/kelmu.js | function(event, action) {
var data = window.kelmu.data[id];
var stepsLeft = Math.max(+(action.parameter || 1), 1);
var stepsToRun = 0;
var proceed = function() {
this('skip', stepsToRun);
};
while (stepsLeft > 0) {
var subSteps = (data.definitions['step' + data.stepNumber] || [null]).length - 1;
var currentSub = data.subStepNumber;
var canIncrease = subSteps - currentSub;
if (canIncrease < stepsLeft) {
data.stepNumber += 1;
data.subStepNumber = 0;
stepsToRun += 1;
stepsLeft -= canIncrease + 1;
} else if (canIncrease > 0) {
if (stepsToRun > 0) {
$.each(window.kelmu.callbacks[id], proceed);
stepsToRun = 0;
clearAnnotations();
originalStep(event);
}
stepsLeft -= canIncrease;
data.subStepNumber = data.subStepNumber + canIncrease;
} else {
data.stepNumber += 1;
stepsToRun += 1;
stepsLeft -= 1;
}
}
if (stepsToRun > 0) {
$.each(window.kelmu.callbacks[id], proceed);
stepsToRun = 0;
clearAnnotations();
originalStep(event);
if (!window.kelmu.data[id].animationReadyAvailable) {
setTimeout(function() {
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor();
}
}, window.kelmu.data[id].settings.animationLength);
}
} else {
createAnnotations();
}
window.kelmu.data[id].undoStack.splice(window.kelmu.data[id].undoStackPointer + 1, window.kelmu.data[id].undoStack.length);
window.kelmu.data[id].undoStack.push([window.kelmu.data[id].stepNumber, window.kelmu.data[id].subStepNumber]);
window.kelmu.data[id].undoStackPointer += 1;
} | javascript | function(event, action) {
var data = window.kelmu.data[id];
var stepsLeft = Math.max(+(action.parameter || 1), 1);
var stepsToRun = 0;
var proceed = function() {
this('skip', stepsToRun);
};
while (stepsLeft > 0) {
var subSteps = (data.definitions['step' + data.stepNumber] || [null]).length - 1;
var currentSub = data.subStepNumber;
var canIncrease = subSteps - currentSub;
if (canIncrease < stepsLeft) {
data.stepNumber += 1;
data.subStepNumber = 0;
stepsToRun += 1;
stepsLeft -= canIncrease + 1;
} else if (canIncrease > 0) {
if (stepsToRun > 0) {
$.each(window.kelmu.callbacks[id], proceed);
stepsToRun = 0;
clearAnnotations();
originalStep(event);
}
stepsLeft -= canIncrease;
data.subStepNumber = data.subStepNumber + canIncrease;
} else {
data.stepNumber += 1;
stepsToRun += 1;
stepsLeft -= 1;
}
}
if (stepsToRun > 0) {
$.each(window.kelmu.callbacks[id], proceed);
stepsToRun = 0;
clearAnnotations();
originalStep(event);
if (!window.kelmu.data[id].animationReadyAvailable) {
setTimeout(function() {
createAnnotations();
if (window.kelmu.data[id].actions.updateEditor) {
window.kelmu.data[id].actions.updateEditor();
}
}, window.kelmu.data[id].settings.animationLength);
}
} else {
createAnnotations();
}
window.kelmu.data[id].undoStack.splice(window.kelmu.data[id].undoStackPointer + 1, window.kelmu.data[id].undoStack.length);
window.kelmu.data[id].undoStack.push([window.kelmu.data[id].stepNumber, window.kelmu.data[id].subStepNumber]);
window.kelmu.data[id].undoStackPointer += 1;
} | [
"function",
"(",
"event",
",",
"action",
")",
"{",
"var",
"data",
"=",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
";",
"var",
"stepsLeft",
"=",
"Math",
".",
"max",
"(",
"+",
"(",
"action",
".",
"parameter",
"||",
"1",
")",
",",
"1",
")",
";",
"var",
"stepsToRun",
"=",
"0",
";",
"var",
"proceed",
"=",
"function",
"(",
")",
"{",
"this",
"(",
"'skip'",
",",
"stepsToRun",
")",
";",
"}",
";",
"while",
"(",
"stepsLeft",
">",
"0",
")",
"{",
"var",
"subSteps",
"=",
"(",
"data",
".",
"definitions",
"[",
"'step'",
"+",
"data",
".",
"stepNumber",
"]",
"||",
"[",
"null",
"]",
")",
".",
"length",
"-",
"1",
";",
"var",
"currentSub",
"=",
"data",
".",
"subStepNumber",
";",
"var",
"canIncrease",
"=",
"subSteps",
"-",
"currentSub",
";",
"if",
"(",
"canIncrease",
"<",
"stepsLeft",
")",
"{",
"data",
".",
"stepNumber",
"+=",
"1",
";",
"data",
".",
"subStepNumber",
"=",
"0",
";",
"stepsToRun",
"+=",
"1",
";",
"stepsLeft",
"-=",
"canIncrease",
"+",
"1",
";",
"}",
"else",
"if",
"(",
"canIncrease",
">",
"0",
")",
"{",
"if",
"(",
"stepsToRun",
">",
"0",
")",
"{",
"$",
".",
"each",
"(",
"window",
".",
"kelmu",
".",
"callbacks",
"[",
"id",
"]",
",",
"proceed",
")",
";",
"stepsToRun",
"=",
"0",
";",
"clearAnnotations",
"(",
")",
";",
"originalStep",
"(",
"event",
")",
";",
"}",
"stepsLeft",
"-=",
"canIncrease",
";",
"data",
".",
"subStepNumber",
"=",
"data",
".",
"subStepNumber",
"+",
"canIncrease",
";",
"}",
"else",
"{",
"data",
".",
"stepNumber",
"+=",
"1",
";",
"stepsToRun",
"+=",
"1",
";",
"stepsLeft",
"-=",
"1",
";",
"}",
"}",
"if",
"(",
"stepsToRun",
">",
"0",
")",
"{",
"$",
".",
"each",
"(",
"window",
".",
"kelmu",
".",
"callbacks",
"[",
"id",
"]",
",",
"proceed",
")",
";",
"stepsToRun",
"=",
"0",
";",
"clearAnnotations",
"(",
")",
";",
"originalStep",
"(",
"event",
")",
";",
"if",
"(",
"!",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"animationReadyAvailable",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"createAnnotations",
"(",
")",
";",
"if",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
")",
"{",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"actions",
".",
"updateEditor",
"(",
")",
";",
"}",
"}",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"settings",
".",
"animationLength",
")",
";",
"}",
"}",
"else",
"{",
"createAnnotations",
"(",
")",
";",
"}",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"splice",
"(",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"+",
"1",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"length",
")",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStack",
".",
"push",
"(",
"[",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"stepNumber",
",",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"subStepNumber",
"]",
")",
";",
"window",
".",
"kelmu",
".",
"data",
"[",
"id",
"]",
".",
"undoStackPointer",
"+=",
"1",
";",
"}"
] | Functionality for the `skip` action. | [
"Functionality",
"for",
"the",
"skip",
"action",
"."
] | 71105b5b43027c517a1da99d6cb0a7687fe253b9 | https://github.com/acos-server/acos-kelmu/blob/71105b5b43027c517a1da99d6cb0a7687fe253b9/static/kelmu.js#L341-L405 |
|
56,946 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/wysiwygarea/plugin.js | blockResizeStart | function blockResizeStart() {
var lastListeningElement;
// We'll attach only one listener at a time, instead of adding it to every img, input, hr etc.
// Listener will be attached upon selectionChange, we'll also check if there was any element that
// got listener before (lastListeningElement) - if so we need to remove previous listener.
editor.editable().attachListener( editor, 'selectionChange', function() {
var selectedElement = editor.getSelection().getSelectedElement();
if ( selectedElement ) {
if ( lastListeningElement ) {
lastListeningElement.detachEvent( 'onresizestart', resizeStartListener );
lastListeningElement = null;
}
// IE requires using attachEvent, because it does not work using W3C compilant addEventListener,
// tested with IE10.
selectedElement.$.attachEvent( 'onresizestart', resizeStartListener );
lastListeningElement = selectedElement.$;
}
} );
} | javascript | function blockResizeStart() {
var lastListeningElement;
// We'll attach only one listener at a time, instead of adding it to every img, input, hr etc.
// Listener will be attached upon selectionChange, we'll also check if there was any element that
// got listener before (lastListeningElement) - if so we need to remove previous listener.
editor.editable().attachListener( editor, 'selectionChange', function() {
var selectedElement = editor.getSelection().getSelectedElement();
if ( selectedElement ) {
if ( lastListeningElement ) {
lastListeningElement.detachEvent( 'onresizestart', resizeStartListener );
lastListeningElement = null;
}
// IE requires using attachEvent, because it does not work using W3C compilant addEventListener,
// tested with IE10.
selectedElement.$.attachEvent( 'onresizestart', resizeStartListener );
lastListeningElement = selectedElement.$;
}
} );
} | [
"function",
"blockResizeStart",
"(",
")",
"{",
"var",
"lastListeningElement",
";",
"// We'll attach only one listener at a time, instead of adding it to every img, input, hr etc.\r",
"// Listener will be attached upon selectionChange, we'll also check if there was any element that\r",
"// got listener before (lastListeningElement) - if so we need to remove previous listener.\r",
"editor",
".",
"editable",
"(",
")",
".",
"attachListener",
"(",
"editor",
",",
"'selectionChange'",
",",
"function",
"(",
")",
"{",
"var",
"selectedElement",
"=",
"editor",
".",
"getSelection",
"(",
")",
".",
"getSelectedElement",
"(",
")",
";",
"if",
"(",
"selectedElement",
")",
"{",
"if",
"(",
"lastListeningElement",
")",
"{",
"lastListeningElement",
".",
"detachEvent",
"(",
"'onresizestart'",
",",
"resizeStartListener",
")",
";",
"lastListeningElement",
"=",
"null",
";",
"}",
"// IE requires using attachEvent, because it does not work using W3C compilant addEventListener,\r",
"// tested with IE10.\r",
"selectedElement",
".",
"$",
".",
"attachEvent",
"(",
"'onresizestart'",
",",
"resizeStartListener",
")",
";",
"lastListeningElement",
"=",
"selectedElement",
".",
"$",
";",
"}",
"}",
")",
";",
"}"
] | Disables resizing by preventing default action on resizestart event. | [
"Disables",
"resizing",
"by",
"preventing",
"default",
"action",
"on",
"resizestart",
"event",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/wysiwygarea/plugin.js#L569-L590 |
56,947 | david4096/ga4gh-node-gateway | src/router.js | expressGetHandler | function expressGetHandler(endpoint) {
return function(req, res) {
// We have to handle request parameters differently since they're not in the
// request body.
rpc.getMethod(endpoint.name)({request: req.params}, function(err, doc) {
res.send(doc);
res.end();
});
};
} | javascript | function expressGetHandler(endpoint) {
return function(req, res) {
// We have to handle request parameters differently since they're not in the
// request body.
rpc.getMethod(endpoint.name)({request: req.params}, function(err, doc) {
res.send(doc);
res.end();
});
};
} | [
"function",
"expressGetHandler",
"(",
"endpoint",
")",
"{",
"return",
"function",
"(",
"req",
",",
"res",
")",
"{",
"// We have to handle request parameters differently since they're not in the",
"// request body.",
"rpc",
".",
"getMethod",
"(",
"endpoint",
".",
"name",
")",
"(",
"{",
"request",
":",
"req",
".",
"params",
"}",
",",
"function",
"(",
"err",
",",
"doc",
")",
"{",
"res",
".",
"send",
"(",
"doc",
")",
";",
"res",
".",
"end",
"(",
")",
";",
"}",
")",
";",
"}",
";",
"}"
] | Returns a callback that will be sent to the controller function when a GET endpoint is requested. | [
"Returns",
"a",
"callback",
"that",
"will",
"be",
"sent",
"to",
"the",
"controller",
"function",
"when",
"a",
"GET",
"endpoint",
"is",
"requested",
"."
] | 3864c10503c9273ea2697d1754bef775ec6ad536 | https://github.com/david4096/ga4gh-node-gateway/blob/3864c10503c9273ea2697d1754bef775ec6ad536/src/router.js#L28-L37 |
56,948 | tunnckoCore/load-deps | index.js | req | function req (name, opts) {
if (opts && opts.require) {
return opts.require(name, opts)
}
var fp = require.resolve(name)
return require(fp)
} | javascript | function req (name, opts) {
if (opts && opts.require) {
return opts.require(name, opts)
}
var fp = require.resolve(name)
return require(fp)
} | [
"function",
"req",
"(",
"name",
",",
"opts",
")",
"{",
"if",
"(",
"opts",
"&&",
"opts",
".",
"require",
")",
"{",
"return",
"opts",
".",
"require",
"(",
"name",
",",
"opts",
")",
"}",
"var",
"fp",
"=",
"require",
".",
"resolve",
"(",
"name",
")",
"return",
"require",
"(",
"fp",
")",
"}"
] | Default `require` function. Pass a custom function to
`opts.require` to override.
@param {String} `name`
@param {Object} `opts`
@return {String} | [
"Default",
"require",
"function",
".",
"Pass",
"a",
"custom",
"function",
"to",
"opts",
".",
"require",
"to",
"override",
"."
] | ddf4f81c06664fc0d6ff3bb87aa942f3be0ee2e0 | https://github.com/tunnckoCore/load-deps/blob/ddf4f81c06664fc0d6ff3bb87aa942f3be0ee2e0/index.js#L81-L87 |
56,949 | tunnckoCore/load-deps | index.js | renameKey | function renameKey (name, opts) {
if (opts && opts.renameKey) {
return opts.renameKey(name, opts)
}
return name
} | javascript | function renameKey (name, opts) {
if (opts && opts.renameKey) {
return opts.renameKey(name, opts)
}
return name
} | [
"function",
"renameKey",
"(",
"name",
",",
"opts",
")",
"{",
"if",
"(",
"opts",
"&&",
"opts",
".",
"renameKey",
")",
"{",
"return",
"opts",
".",
"renameKey",
"(",
"name",
",",
"opts",
")",
"}",
"return",
"name",
"}"
] | Default `renameKey` function. Pass a custom function to
`opts.renameKey` to override.
@param {String} `name`
@param {Object} `opts`
@return {String} | [
"Default",
"renameKey",
"function",
".",
"Pass",
"a",
"custom",
"function",
"to",
"opts",
".",
"renameKey",
"to",
"override",
"."
] | ddf4f81c06664fc0d6ff3bb87aa942f3be0ee2e0 | https://github.com/tunnckoCore/load-deps/blob/ddf4f81c06664fc0d6ff3bb87aa942f3be0ee2e0/index.js#L97-L102 |
56,950 | mobkits/tap-event | index.js | cleanup | function cleanup(e2) {
// if it's the same event as the origin,
// then don't actually cleanup.
// hit issues with this - don't remember
if (e1 === e2) return
clearTimeout(timeout_id)
el.removeEventListener('touchmove', cleanup)
endEvents.forEach(function (event) {
el.removeEventListener(event, done)
})
} | javascript | function cleanup(e2) {
// if it's the same event as the origin,
// then don't actually cleanup.
// hit issues with this - don't remember
if (e1 === e2) return
clearTimeout(timeout_id)
el.removeEventListener('touchmove', cleanup)
endEvents.forEach(function (event) {
el.removeEventListener(event, done)
})
} | [
"function",
"cleanup",
"(",
"e2",
")",
"{",
"// if it's the same event as the origin,",
"// then don't actually cleanup.",
"// hit issues with this - don't remember",
"if",
"(",
"e1",
"===",
"e2",
")",
"return",
"clearTimeout",
"(",
"timeout_id",
")",
"el",
".",
"removeEventListener",
"(",
"'touchmove'",
",",
"cleanup",
")",
"endEvents",
".",
"forEach",
"(",
"function",
"(",
"event",
")",
"{",
"el",
".",
"removeEventListener",
"(",
"event",
",",
"done",
")",
"}",
")",
"}"
] | cleanup end events to cancel the tap, just run this early | [
"cleanup",
"end",
"events",
"to",
"cancel",
"the",
"tap",
"just",
"run",
"this",
"early"
] | f8d7a4a2db607bed162b7697e5c9daa2097e0a61 | https://github.com/mobkits/tap-event/blob/f8d7a4a2db607bed162b7697e5c9daa2097e0a61/index.js#L72-L85 |
56,951 | stdarg/async-err | index.js | asyncerr | function asyncerr(err, cb) {
if (!util.isError(err, Error))
return debug(BAD_ERR_ERR);
if (typeof err.message === 'string' && err.message.length)
debug(err.message);
if (typeof err.stack === 'object')
debug(err.stack);
if (!is.func(cb))
return debug(BAD_CB_ERR+util.inspect(cb));
// call the callback on the next tick of the event loop
process.nextTick(function() {
cb(err);
});
} | javascript | function asyncerr(err, cb) {
if (!util.isError(err, Error))
return debug(BAD_ERR_ERR);
if (typeof err.message === 'string' && err.message.length)
debug(err.message);
if (typeof err.stack === 'object')
debug(err.stack);
if (!is.func(cb))
return debug(BAD_CB_ERR+util.inspect(cb));
// call the callback on the next tick of the event loop
process.nextTick(function() {
cb(err);
});
} | [
"function",
"asyncerr",
"(",
"err",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"util",
".",
"isError",
"(",
"err",
",",
"Error",
")",
")",
"return",
"debug",
"(",
"BAD_ERR_ERR",
")",
";",
"if",
"(",
"typeof",
"err",
".",
"message",
"===",
"'string'",
"&&",
"err",
".",
"message",
".",
"length",
")",
"debug",
"(",
"err",
".",
"message",
")",
";",
"if",
"(",
"typeof",
"err",
".",
"stack",
"===",
"'object'",
")",
"debug",
"(",
"err",
".",
"stack",
")",
";",
"if",
"(",
"!",
"is",
".",
"func",
"(",
"cb",
")",
")",
"return",
"debug",
"(",
"BAD_CB_ERR",
"+",
"util",
".",
"inspect",
"(",
"cb",
")",
")",
";",
"// call the callback on the next tick of the event loop",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"cb",
"(",
"err",
")",
";",
"}",
")",
";",
"}"
] | A convenience function to make otherwise sync errors async. If you give
asyncerr incorrect arguments, it will send messages to the console via the
debug module, but that's it.
@param {Object} err A Node.js Error object.
@param {Function} cb A function object as callback. | [
"A",
"convenience",
"function",
"to",
"make",
"otherwise",
"sync",
"errors",
"async",
".",
"If",
"you",
"give",
"asyncerr",
"incorrect",
"arguments",
"it",
"will",
"send",
"messages",
"to",
"the",
"console",
"via",
"the",
"debug",
"module",
"but",
"that",
"s",
"it",
"."
] | 36ada42c92963f5a6648e9463b3e4767875437e1 | https://github.com/stdarg/async-err/blob/36ada42c92963f5a6648e9463b3e4767875437e1/index.js#L19-L36 |
56,952 | douglasduteil/ngdoc-parser | lib/DocCommentParser.js | DocCommentParser | function DocCommentParser(text) {
this.lines = text.split(END_OF_LINE);
this.lineNumber = 0;
this.length = this.lines.length;
this.line = '';
this.match = [];
this.tagDef = {};
this.mode = this._extractLine;
this.data = {};
} | javascript | function DocCommentParser(text) {
this.lines = text.split(END_OF_LINE);
this.lineNumber = 0;
this.length = this.lines.length;
this.line = '';
this.match = [];
this.tagDef = {};
this.mode = this._extractLine;
this.data = {};
} | [
"function",
"DocCommentParser",
"(",
"text",
")",
"{",
"this",
".",
"lines",
"=",
"text",
".",
"split",
"(",
"END_OF_LINE",
")",
";",
"this",
".",
"lineNumber",
"=",
"0",
";",
"this",
".",
"length",
"=",
"this",
".",
"lines",
".",
"length",
";",
"this",
".",
"line",
"=",
"''",
";",
"this",
".",
"match",
"=",
"[",
"]",
";",
"this",
".",
"tagDef",
"=",
"{",
"}",
";",
"this",
".",
"mode",
"=",
"this",
".",
"_extractLine",
";",
"this",
".",
"data",
"=",
"{",
"}",
";",
"}"
] | A little doc parser to extract inline or multiline comments
@alias module:DocCommentParser
@param {string} text The text to parse.
@constructor | [
"A",
"little",
"doc",
"parser",
"to",
"extract",
"inline",
"or",
"multiline",
"comments"
] | 9fc11adb71cd260f8d67f6fd34b907ba92e3ecbb | https://github.com/douglasduteil/ngdoc-parser/blob/9fc11adb71cd260f8d67f6fd34b907ba92e3ecbb/lib/DocCommentParser.js#L22-L34 |
56,953 | IonicaBizau/diable | lib/index.js | Diable | function Diable(opts) {
// The process is a daemon
if (Diable.isDaemon()) {
return false
}
opts = opts || {}
const args = [].concat(process.argv)
args.shift()
const script = args.shift()
, env = opts.env || process.env
Diable.daemonize(script, args, opts)
return process.exit()
} | javascript | function Diable(opts) {
// The process is a daemon
if (Diable.isDaemon()) {
return false
}
opts = opts || {}
const args = [].concat(process.argv)
args.shift()
const script = args.shift()
, env = opts.env || process.env
Diable.daemonize(script, args, opts)
return process.exit()
} | [
"function",
"Diable",
"(",
"opts",
")",
"{",
"// The process is a daemon",
"if",
"(",
"Diable",
".",
"isDaemon",
"(",
")",
")",
"{",
"return",
"false",
"}",
"opts",
"=",
"opts",
"||",
"{",
"}",
"const",
"args",
"=",
"[",
"]",
".",
"concat",
"(",
"process",
".",
"argv",
")",
"args",
".",
"shift",
"(",
")",
"const",
"script",
"=",
"args",
".",
"shift",
"(",
")",
",",
"env",
"=",
"opts",
".",
"env",
"||",
"process",
".",
"env",
"Diable",
".",
"daemonize",
"(",
"script",
",",
"args",
",",
"opts",
")",
"return",
"process",
".",
"exit",
"(",
")",
"}"
] | Diable
Daemonizes processes the current process.
@name Diable
@function
@param {Object} opts An object which will be passed to the `exec` function. It is extended with:
- `env` (Object): The environment object (default: `process.env`).
@return {Number|Process} `false` if the process was already daemonized. Otherwise the process is closed anyways. | [
"Diable",
"Daemonizes",
"processes",
"the",
"current",
"process",
"."
] | dddf7ef19b233a3f4c0e464b4f9e689f7f64d351 | https://github.com/IonicaBizau/diable/blob/dddf7ef19b233a3f4c0e464b4f9e689f7f64d351/lib/index.js#L17-L34 |
56,954 | gummesson/markdown-stream | index.js | markdown | function markdown(preset, options) {
var stream = through(transform, flush)
var parser = new Remarkable(preset, options)
var buffer = []
function transform(chunk, encoding, done) {
buffer.push(chunk)
done()
}
function flush(done) {
this.push(parser.render(buffer.join('\n')))
done()
}
return stream
} | javascript | function markdown(preset, options) {
var stream = through(transform, flush)
var parser = new Remarkable(preset, options)
var buffer = []
function transform(chunk, encoding, done) {
buffer.push(chunk)
done()
}
function flush(done) {
this.push(parser.render(buffer.join('\n')))
done()
}
return stream
} | [
"function",
"markdown",
"(",
"preset",
",",
"options",
")",
"{",
"var",
"stream",
"=",
"through",
"(",
"transform",
",",
"flush",
")",
"var",
"parser",
"=",
"new",
"Remarkable",
"(",
"preset",
",",
"options",
")",
"var",
"buffer",
"=",
"[",
"]",
"function",
"transform",
"(",
"chunk",
",",
"encoding",
",",
"done",
")",
"{",
"buffer",
".",
"push",
"(",
"chunk",
")",
"done",
"(",
")",
"}",
"function",
"flush",
"(",
"done",
")",
"{",
"this",
".",
"push",
"(",
"parser",
".",
"render",
"(",
"buffer",
".",
"join",
"(",
"'\\n'",
")",
")",
")",
"done",
"(",
")",
"}",
"return",
"stream",
"}"
] | Tranform a stream of Markdown into HTML.
@param {string} [preset]
@param {object} [options]
@return {object}
@api public | [
"Tranform",
"a",
"stream",
"of",
"Markdown",
"into",
"HTML",
"."
] | 1841c046b96cb82fe1ad080f5f429c3c386c8f33 | https://github.com/gummesson/markdown-stream/blob/1841c046b96cb82fe1ad080f5f429c3c386c8f33/index.js#L18-L34 |
56,955 | gaiajs/gaiajs | lib/config/index.js | getFileContent | function getFileContent(ext, file) {
var conf = {};
switch (ext) {
case '.js':
conf = require(file);
break;
case '.json':
conf = JSON.parse(fs.readFileSync(file, {
encoding: 'utf-8'
}));
break;
case '.yml':
conf = yaml.safeLoad(fs.readFileSync(file, {
encoding: 'utf-8'
}));
break;
}
return conf;
} | javascript | function getFileContent(ext, file) {
var conf = {};
switch (ext) {
case '.js':
conf = require(file);
break;
case '.json':
conf = JSON.parse(fs.readFileSync(file, {
encoding: 'utf-8'
}));
break;
case '.yml':
conf = yaml.safeLoad(fs.readFileSync(file, {
encoding: 'utf-8'
}));
break;
}
return conf;
} | [
"function",
"getFileContent",
"(",
"ext",
",",
"file",
")",
"{",
"var",
"conf",
"=",
"{",
"}",
";",
"switch",
"(",
"ext",
")",
"{",
"case",
"'.js'",
":",
"conf",
"=",
"require",
"(",
"file",
")",
";",
"break",
";",
"case",
"'.json'",
":",
"conf",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"{",
"encoding",
":",
"'utf-8'",
"}",
")",
")",
";",
"break",
";",
"case",
"'.yml'",
":",
"conf",
"=",
"yaml",
".",
"safeLoad",
"(",
"fs",
".",
"readFileSync",
"(",
"file",
",",
"{",
"encoding",
":",
"'utf-8'",
"}",
")",
")",
";",
"break",
";",
"}",
"return",
"conf",
";",
"}"
] | Get file content | [
"Get",
"file",
"content"
] | a8ebc50274b83bed8bed007e691761bdc3b52eaa | https://github.com/gaiajs/gaiajs/blob/a8ebc50274b83bed8bed007e691761bdc3b52eaa/lib/config/index.js#L145-L164 |
56,956 | seriousManual/node-depugger | index.js | depugger | function depugger(pDebug, pName) {
var debug, name, backend;
if (typeof pDebug === 'object') {
debug = !!pDebug.debug;
name = pDebug.name || '';
backend = pDebug.backend || stdBackend;
} else {
debug = !!pDebug;
name = pName || '';
backend = stdBackend;
}
var prefix = name ? util.format('[%s] ', name) : '';
var logFunction = function() {
var args = Array.prototype.splice.call(arguments, 0);
var message = util.format.apply(null, args);
message = prefix + message;
backend.write(message);
};
if(!debug) {
logFunction = noop;
}
logFunction.child = function(childName) {
var newName = name ? name + '.' + childName : childName;
return depugger({debug: debug, name: newName, backend: backend});
};
return logFunction;
} | javascript | function depugger(pDebug, pName) {
var debug, name, backend;
if (typeof pDebug === 'object') {
debug = !!pDebug.debug;
name = pDebug.name || '';
backend = pDebug.backend || stdBackend;
} else {
debug = !!pDebug;
name = pName || '';
backend = stdBackend;
}
var prefix = name ? util.format('[%s] ', name) : '';
var logFunction = function() {
var args = Array.prototype.splice.call(arguments, 0);
var message = util.format.apply(null, args);
message = prefix + message;
backend.write(message);
};
if(!debug) {
logFunction = noop;
}
logFunction.child = function(childName) {
var newName = name ? name + '.' + childName : childName;
return depugger({debug: debug, name: newName, backend: backend});
};
return logFunction;
} | [
"function",
"depugger",
"(",
"pDebug",
",",
"pName",
")",
"{",
"var",
"debug",
",",
"name",
",",
"backend",
";",
"if",
"(",
"typeof",
"pDebug",
"===",
"'object'",
")",
"{",
"debug",
"=",
"!",
"!",
"pDebug",
".",
"debug",
";",
"name",
"=",
"pDebug",
".",
"name",
"||",
"''",
";",
"backend",
"=",
"pDebug",
".",
"backend",
"||",
"stdBackend",
";",
"}",
"else",
"{",
"debug",
"=",
"!",
"!",
"pDebug",
";",
"name",
"=",
"pName",
"||",
"''",
";",
"backend",
"=",
"stdBackend",
";",
"}",
"var",
"prefix",
"=",
"name",
"?",
"util",
".",
"format",
"(",
"'[%s] '",
",",
"name",
")",
":",
"''",
";",
"var",
"logFunction",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"splice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
";",
"var",
"message",
"=",
"util",
".",
"format",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"message",
"=",
"prefix",
"+",
"message",
";",
"backend",
".",
"write",
"(",
"message",
")",
";",
"}",
";",
"if",
"(",
"!",
"debug",
")",
"{",
"logFunction",
"=",
"noop",
";",
"}",
"logFunction",
".",
"child",
"=",
"function",
"(",
"childName",
")",
"{",
"var",
"newName",
"=",
"name",
"?",
"name",
"+",
"'.'",
"+",
"childName",
":",
"childName",
";",
"return",
"depugger",
"(",
"{",
"debug",
":",
"debug",
",",
"name",
":",
"newName",
",",
"backend",
":",
"backend",
"}",
")",
";",
"}",
";",
"return",
"logFunction",
";",
"}"
] | returns a a function that is used to create debug messages
the logging of the messages happens in the context of the initializing factory method
@param pDebug flag that indicates if debugging should be activated
@param pName context name for debugging messages
@return {Function} | [
"returns",
"a",
"a",
"function",
"that",
"is",
"used",
"to",
"create",
"debug",
"messages",
"the",
"logging",
"of",
"the",
"messages",
"happens",
"in",
"the",
"context",
"of",
"the",
"initializing",
"factory",
"method"
] | 3568fd546f8674ade271361de38e1d5374ff2ce6 | https://github.com/seriousManual/node-depugger/blob/3568fd546f8674ade271361de38e1d5374ff2ce6/index.js#L15-L49 |
56,957 | kudla/react-declaration-loader | lib/traverse.js | traverse | function traverse(ast) {
var visitors = flatten(slice.call(arguments, 1));
estraverse.traverse(ast, {
enter: function(node) {
var type = node.type;
var methodName = type + 'Enter';
visitorsCall('enter', this, arguments);
visitorsCall(methodName, this, arguments);
},
leave: function(node) {
var type = node.type;
var methodName = type + 'Leave';
visitorsCall('leave', this, arguments);
visitorsCall(methodName, this, arguments);
}
});
function visitorsCall(methodName, context, args) {
var callArgs = slice.call(args);
var callBreak;
var visitorContext = Object.assign(
Object.create(context),
{
skip: function() {
callBreak = true;
context.skip();
},
break: function() {
callBreak = true;
context.break();
}
}
);
visitors.some(function(visitor) {
var method = visitor[methodName];
if (method) {
method.apply(visitorContext, callArgs);
}
return callBreak;
});
}
} | javascript | function traverse(ast) {
var visitors = flatten(slice.call(arguments, 1));
estraverse.traverse(ast, {
enter: function(node) {
var type = node.type;
var methodName = type + 'Enter';
visitorsCall('enter', this, arguments);
visitorsCall(methodName, this, arguments);
},
leave: function(node) {
var type = node.type;
var methodName = type + 'Leave';
visitorsCall('leave', this, arguments);
visitorsCall(methodName, this, arguments);
}
});
function visitorsCall(methodName, context, args) {
var callArgs = slice.call(args);
var callBreak;
var visitorContext = Object.assign(
Object.create(context),
{
skip: function() {
callBreak = true;
context.skip();
},
break: function() {
callBreak = true;
context.break();
}
}
);
visitors.some(function(visitor) {
var method = visitor[methodName];
if (method) {
method.apply(visitorContext, callArgs);
}
return callBreak;
});
}
} | [
"function",
"traverse",
"(",
"ast",
")",
"{",
"var",
"visitors",
"=",
"flatten",
"(",
"slice",
".",
"call",
"(",
"arguments",
",",
"1",
")",
")",
";",
"estraverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
")",
"{",
"var",
"type",
"=",
"node",
".",
"type",
";",
"var",
"methodName",
"=",
"type",
"+",
"'Enter'",
";",
"visitorsCall",
"(",
"'enter'",
",",
"this",
",",
"arguments",
")",
";",
"visitorsCall",
"(",
"methodName",
",",
"this",
",",
"arguments",
")",
";",
"}",
",",
"leave",
":",
"function",
"(",
"node",
")",
"{",
"var",
"type",
"=",
"node",
".",
"type",
";",
"var",
"methodName",
"=",
"type",
"+",
"'Leave'",
";",
"visitorsCall",
"(",
"'leave'",
",",
"this",
",",
"arguments",
")",
";",
"visitorsCall",
"(",
"methodName",
",",
"this",
",",
"arguments",
")",
";",
"}",
"}",
")",
";",
"function",
"visitorsCall",
"(",
"methodName",
",",
"context",
",",
"args",
")",
"{",
"var",
"callArgs",
"=",
"slice",
".",
"call",
"(",
"args",
")",
";",
"var",
"callBreak",
";",
"var",
"visitorContext",
"=",
"Object",
".",
"assign",
"(",
"Object",
".",
"create",
"(",
"context",
")",
",",
"{",
"skip",
":",
"function",
"(",
")",
"{",
"callBreak",
"=",
"true",
";",
"context",
".",
"skip",
"(",
")",
";",
"}",
",",
"break",
":",
"function",
"(",
")",
"{",
"callBreak",
"=",
"true",
";",
"context",
".",
"break",
"(",
")",
";",
"}",
"}",
")",
";",
"visitors",
".",
"some",
"(",
"function",
"(",
"visitor",
")",
"{",
"var",
"method",
"=",
"visitor",
"[",
"methodName",
"]",
";",
"if",
"(",
"method",
")",
"{",
"method",
".",
"apply",
"(",
"visitorContext",
",",
"callArgs",
")",
";",
"}",
"return",
"callBreak",
";",
"}",
")",
";",
"}",
"}"
] | traverse - AST traverse helper
@param {AST} ast
@param {Object} ...visitors hash of visitor functions | [
"traverse",
"-",
"AST",
"traverse",
"helper"
] | 50f430a49cffc99a8188648452d3740cbef49c1c | https://github.com/kudla/react-declaration-loader/blob/50f430a49cffc99a8188648452d3740cbef49c1c/lib/traverse.js#L14-L57 |
56,958 | andrepolischuk/eventhash | index.js | fix | function fix(fn, path) {
if (!running) return;
if (path !== location.hash) {
fn();
path = location.hash;
}
setTimeout(function() {
fix(fn, path);
}, 500);
} | javascript | function fix(fn, path) {
if (!running) return;
if (path !== location.hash) {
fn();
path = location.hash;
}
setTimeout(function() {
fix(fn, path);
}, 500);
} | [
"function",
"fix",
"(",
"fn",
",",
"path",
")",
"{",
"if",
"(",
"!",
"running",
")",
"return",
";",
"if",
"(",
"path",
"!==",
"location",
".",
"hash",
")",
"{",
"fn",
"(",
")",
";",
"path",
"=",
"location",
".",
"hash",
";",
"}",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"fix",
"(",
"fn",
",",
"path",
")",
";",
"}",
",",
"500",
")",
";",
"}"
] | onhashchange fix for IE<8
@param {Function} fn
@param {String} path
@api private | [
"onhashchange",
"fix",
"for",
"IE<8"
] | b34584acd7cae3e40c1f55e50a0a5b1dd321a031 | https://github.com/andrepolischuk/eventhash/blob/b34584acd7cae3e40c1f55e50a0a5b1dd321a031/index.js#L65-L76 |
56,959 | sciolist/pellets | browser/pellets.js | parseContinueStatement | function parseContinueStatement() {
var token, label = null;
expectKeyword('continue');
// Optimize the most common form: 'continue;'.
if (source[index] === ';') {
lex();
if (!inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: null
};
}
if (peekLineTerminator()) {
if (!inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: null
};
}
token = lookahead();
if (token.type === Token.Identifier) {
label = parseVariableIdentifier();
if (!Object.prototype.hasOwnProperty.call(labelSet, label.name)) {
throwError({}, Messages.UnknownLabel, label.name);
}
}
consumeSemicolon();
if (label === null && !inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: label
};
} | javascript | function parseContinueStatement() {
var token, label = null;
expectKeyword('continue');
// Optimize the most common form: 'continue;'.
if (source[index] === ';') {
lex();
if (!inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: null
};
}
if (peekLineTerminator()) {
if (!inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: null
};
}
token = lookahead();
if (token.type === Token.Identifier) {
label = parseVariableIdentifier();
if (!Object.prototype.hasOwnProperty.call(labelSet, label.name)) {
throwError({}, Messages.UnknownLabel, label.name);
}
}
consumeSemicolon();
if (label === null && !inIteration) {
throwError({}, Messages.IllegalContinue);
}
return {
type: Syntax.ContinueStatement,
label: label
};
} | [
"function",
"parseContinueStatement",
"(",
")",
"{",
"var",
"token",
",",
"label",
"=",
"null",
";",
"expectKeyword",
"(",
"'continue'",
")",
";",
"// Optimize the most common form: 'continue;'.",
"if",
"(",
"source",
"[",
"index",
"]",
"===",
"';'",
")",
"{",
"lex",
"(",
")",
";",
"if",
"(",
"!",
"inIteration",
")",
"{",
"throwError",
"(",
"{",
"}",
",",
"Messages",
".",
"IllegalContinue",
")",
";",
"}",
"return",
"{",
"type",
":",
"Syntax",
".",
"ContinueStatement",
",",
"label",
":",
"null",
"}",
";",
"}",
"if",
"(",
"peekLineTerminator",
"(",
")",
")",
"{",
"if",
"(",
"!",
"inIteration",
")",
"{",
"throwError",
"(",
"{",
"}",
",",
"Messages",
".",
"IllegalContinue",
")",
";",
"}",
"return",
"{",
"type",
":",
"Syntax",
".",
"ContinueStatement",
",",
"label",
":",
"null",
"}",
";",
"}",
"token",
"=",
"lookahead",
"(",
")",
";",
"if",
"(",
"token",
".",
"type",
"===",
"Token",
".",
"Identifier",
")",
"{",
"label",
"=",
"parseVariableIdentifier",
"(",
")",
";",
"if",
"(",
"!",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"labelSet",
",",
"label",
".",
"name",
")",
")",
"{",
"throwError",
"(",
"{",
"}",
",",
"Messages",
".",
"UnknownLabel",
",",
"label",
".",
"name",
")",
";",
"}",
"}",
"consumeSemicolon",
"(",
")",
";",
"if",
"(",
"label",
"===",
"null",
"&&",
"!",
"inIteration",
")",
"{",
"throwError",
"(",
"{",
"}",
",",
"Messages",
".",
"IllegalContinue",
")",
";",
"}",
"return",
"{",
"type",
":",
"Syntax",
".",
"ContinueStatement",
",",
"label",
":",
"label",
"}",
";",
"}"
] | 12.7 The continue statement | [
"12",
".",
"7",
"The",
"continue",
"statement"
] | 98ce4b3b9bd0fb4893562d7ba1e121952169cb53 | https://github.com/sciolist/pellets/blob/98ce4b3b9bd0fb4893562d7ba1e121952169cb53/browser/pellets.js#L3088-L3137 |
56,960 | sciolist/pellets | browser/pellets.js | parseReturnStatement | function parseReturnStatement() {
var token, argument = null;
expectKeyword('return');
if (!inFunctionBody) {
throwErrorTolerant({}, Messages.IllegalReturn);
}
// 'return' followed by a space and an identifier is very common.
if (source[index] === ' ') {
if (isIdentifierStart(source[index + 1])) {
argument = parseExpression();
consumeSemicolon();
return {
type: Syntax.ReturnStatement,
argument: argument
};
}
}
if (peekLineTerminator()) {
return {
type: Syntax.ReturnStatement,
argument: null
};
}
if (!match(';')) {
token = lookahead();
if (!match('}') && token.type !== Token.EOF) {
argument = parseExpression();
}
}
consumeSemicolon();
return {
type: Syntax.ReturnStatement,
argument: argument
};
} | javascript | function parseReturnStatement() {
var token, argument = null;
expectKeyword('return');
if (!inFunctionBody) {
throwErrorTolerant({}, Messages.IllegalReturn);
}
// 'return' followed by a space and an identifier is very common.
if (source[index] === ' ') {
if (isIdentifierStart(source[index + 1])) {
argument = parseExpression();
consumeSemicolon();
return {
type: Syntax.ReturnStatement,
argument: argument
};
}
}
if (peekLineTerminator()) {
return {
type: Syntax.ReturnStatement,
argument: null
};
}
if (!match(';')) {
token = lookahead();
if (!match('}') && token.type !== Token.EOF) {
argument = parseExpression();
}
}
consumeSemicolon();
return {
type: Syntax.ReturnStatement,
argument: argument
};
} | [
"function",
"parseReturnStatement",
"(",
")",
"{",
"var",
"token",
",",
"argument",
"=",
"null",
";",
"expectKeyword",
"(",
"'return'",
")",
";",
"if",
"(",
"!",
"inFunctionBody",
")",
"{",
"throwErrorTolerant",
"(",
"{",
"}",
",",
"Messages",
".",
"IllegalReturn",
")",
";",
"}",
"// 'return' followed by a space and an identifier is very common.",
"if",
"(",
"source",
"[",
"index",
"]",
"===",
"' '",
")",
"{",
"if",
"(",
"isIdentifierStart",
"(",
"source",
"[",
"index",
"+",
"1",
"]",
")",
")",
"{",
"argument",
"=",
"parseExpression",
"(",
")",
";",
"consumeSemicolon",
"(",
")",
";",
"return",
"{",
"type",
":",
"Syntax",
".",
"ReturnStatement",
",",
"argument",
":",
"argument",
"}",
";",
"}",
"}",
"if",
"(",
"peekLineTerminator",
"(",
")",
")",
"{",
"return",
"{",
"type",
":",
"Syntax",
".",
"ReturnStatement",
",",
"argument",
":",
"null",
"}",
";",
"}",
"if",
"(",
"!",
"match",
"(",
"';'",
")",
")",
"{",
"token",
"=",
"lookahead",
"(",
")",
";",
"if",
"(",
"!",
"match",
"(",
"'}'",
")",
"&&",
"token",
".",
"type",
"!==",
"Token",
".",
"EOF",
")",
"{",
"argument",
"=",
"parseExpression",
"(",
")",
";",
"}",
"}",
"consumeSemicolon",
"(",
")",
";",
"return",
"{",
"type",
":",
"Syntax",
".",
"ReturnStatement",
",",
"argument",
":",
"argument",
"}",
";",
"}"
] | 12.9 The return statement | [
"12",
".",
"9",
"The",
"return",
"statement"
] | 98ce4b3b9bd0fb4893562d7ba1e121952169cb53 | https://github.com/sciolist/pellets/blob/98ce4b3b9bd0fb4893562d7ba1e121952169cb53/browser/pellets.js#L3194-L3235 |
56,961 | sciolist/pellets | browser/pellets.js | SourceNodeMock | function SourceNodeMock(line, column, filename, chunk) {
var result = [];
function flatten(input) {
var i, iz;
if (isArray(input)) {
for (i = 0, iz = input.length; i < iz; ++i) {
flatten(input[i]);
}
} else if (input instanceof SourceNodeMock) {
result.push(input);
} else if (typeof input === 'string' && input) {
result.push(input);
}
}
flatten(chunk);
this.children = result;
} | javascript | function SourceNodeMock(line, column, filename, chunk) {
var result = [];
function flatten(input) {
var i, iz;
if (isArray(input)) {
for (i = 0, iz = input.length; i < iz; ++i) {
flatten(input[i]);
}
} else if (input instanceof SourceNodeMock) {
result.push(input);
} else if (typeof input === 'string' && input) {
result.push(input);
}
}
flatten(chunk);
this.children = result;
} | [
"function",
"SourceNodeMock",
"(",
"line",
",",
"column",
",",
"filename",
",",
"chunk",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"function",
"flatten",
"(",
"input",
")",
"{",
"var",
"i",
",",
"iz",
";",
"if",
"(",
"isArray",
"(",
"input",
")",
")",
"{",
"for",
"(",
"i",
"=",
"0",
",",
"iz",
"=",
"input",
".",
"length",
";",
"i",
"<",
"iz",
";",
"++",
"i",
")",
"{",
"flatten",
"(",
"input",
"[",
"i",
"]",
")",
";",
"}",
"}",
"else",
"if",
"(",
"input",
"instanceof",
"SourceNodeMock",
")",
"{",
"result",
".",
"push",
"(",
"input",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"input",
"===",
"'string'",
"&&",
"input",
")",
"{",
"result",
".",
"push",
"(",
"input",
")",
";",
"}",
"}",
"flatten",
"(",
"chunk",
")",
";",
"this",
".",
"children",
"=",
"result",
";",
"}"
] | Fallback for the non SourceMap environment | [
"Fallback",
"for",
"the",
"non",
"SourceMap",
"environment"
] | 98ce4b3b9bd0fb4893562d7ba1e121952169cb53 | https://github.com/sciolist/pellets/blob/98ce4b3b9bd0fb4893562d7ba1e121952169cb53/browser/pellets.js#L4536-L4554 |
56,962 | christophercrouzet/pillr | lib/utils.js | trimExtension | function trimExtension(filePath) {
const ext = path.extname(filePath);
return filePath.slice(0, filePath.length - ext.length);
} | javascript | function trimExtension(filePath) {
const ext = path.extname(filePath);
return filePath.slice(0, filePath.length - ext.length);
} | [
"function",
"trimExtension",
"(",
"filePath",
")",
"{",
"const",
"ext",
"=",
"path",
".",
"extname",
"(",
"filePath",
")",
";",
"return",
"filePath",
".",
"slice",
"(",
"0",
",",
"filePath",
".",
"length",
"-",
"ext",
".",
"length",
")",
";",
"}"
] | Remove the extension. | [
"Remove",
"the",
"extension",
"."
] | 411ccd344a03478776c4e8d2e2f9bdc45dc8ee45 | https://github.com/christophercrouzet/pillr/blob/411ccd344a03478776c4e8d2e2f9bdc45dc8ee45/lib/utils.js#L21-L24 |
56,963 | christophercrouzet/pillr | lib/utils.js | asDataMap | function asDataMap(files, mapping, callback) {
try {
const out = files.reduce((obj, file) => {
let key;
switch (mapping) {
case Mapping.DIR:
key = path.dirname(file.path);
break;
case Mapping.MODULE:
key = trimExtension(file.path).replace(PATH_SEP_RE, '.');
break;
default:
key = file.path;
break;
}
return Object.assign(obj, { [key]: file.data });
}, {});
async.nextTick(callback, null, out);
} catch (error) {
async.nextTick(callback, error);
}
} | javascript | function asDataMap(files, mapping, callback) {
try {
const out = files.reduce((obj, file) => {
let key;
switch (mapping) {
case Mapping.DIR:
key = path.dirname(file.path);
break;
case Mapping.MODULE:
key = trimExtension(file.path).replace(PATH_SEP_RE, '.');
break;
default:
key = file.path;
break;
}
return Object.assign(obj, { [key]: file.data });
}, {});
async.nextTick(callback, null, out);
} catch (error) {
async.nextTick(callback, error);
}
} | [
"function",
"asDataMap",
"(",
"files",
",",
"mapping",
",",
"callback",
")",
"{",
"try",
"{",
"const",
"out",
"=",
"files",
".",
"reduce",
"(",
"(",
"obj",
",",
"file",
")",
"=>",
"{",
"let",
"key",
";",
"switch",
"(",
"mapping",
")",
"{",
"case",
"Mapping",
".",
"DIR",
":",
"key",
"=",
"path",
".",
"dirname",
"(",
"file",
".",
"path",
")",
";",
"break",
";",
"case",
"Mapping",
".",
"MODULE",
":",
"key",
"=",
"trimExtension",
"(",
"file",
".",
"path",
")",
".",
"replace",
"(",
"PATH_SEP_RE",
",",
"'.'",
")",
";",
"break",
";",
"default",
":",
"key",
"=",
"file",
".",
"path",
";",
"break",
";",
"}",
"return",
"Object",
".",
"assign",
"(",
"obj",
",",
"{",
"[",
"key",
"]",
":",
"file",
".",
"data",
"}",
")",
";",
"}",
",",
"{",
"}",
")",
";",
"async",
".",
"nextTick",
"(",
"callback",
",",
"null",
",",
"out",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"async",
".",
"nextTick",
"(",
"callback",
",",
"error",
")",
";",
"}",
"}"
] | Map files data with their path as key. | [
"Map",
"files",
"data",
"with",
"their",
"path",
"as",
"key",
"."
] | 411ccd344a03478776c4e8d2e2f9bdc45dc8ee45 | https://github.com/christophercrouzet/pillr/blob/411ccd344a03478776c4e8d2e2f9bdc45dc8ee45/lib/utils.js#L28-L50 |
56,964 | christophercrouzet/pillr | lib/utils.js | mkdir | function mkdir(dirPath, callback) {
// Credits: https://github.com/substack/node-mkdirp
// Recursively go through the parents.
const recurse = () => {
mkdir(path.dirname(dirPath), (error) => {
if (error) {
async.nextTick(callback, error);
return;
}
// Try again.
mkdir(dirPath, callback);
});
};
// Plan B for when things seem to go wrong.
const fallBack = () => {
fs.stat(dirPath, (error, stat) => {
if (error || !stat.isDirectory()) {
async.nextTick(
callback,
new Error(`${dirPath}: Could not create the directory`)
);
return;
}
async.nextTick(callback, null);
});
};
fs.mkdir(dirPath, (error) => {
if (!error) {
async.nextTick(callback, null);
return;
}
switch (error.code) {
case 'ENOENT':
recurse();
break;
default:
fallBack();
break;
}
});
} | javascript | function mkdir(dirPath, callback) {
// Credits: https://github.com/substack/node-mkdirp
// Recursively go through the parents.
const recurse = () => {
mkdir(path.dirname(dirPath), (error) => {
if (error) {
async.nextTick(callback, error);
return;
}
// Try again.
mkdir(dirPath, callback);
});
};
// Plan B for when things seem to go wrong.
const fallBack = () => {
fs.stat(dirPath, (error, stat) => {
if (error || !stat.isDirectory()) {
async.nextTick(
callback,
new Error(`${dirPath}: Could not create the directory`)
);
return;
}
async.nextTick(callback, null);
});
};
fs.mkdir(dirPath, (error) => {
if (!error) {
async.nextTick(callback, null);
return;
}
switch (error.code) {
case 'ENOENT':
recurse();
break;
default:
fallBack();
break;
}
});
} | [
"function",
"mkdir",
"(",
"dirPath",
",",
"callback",
")",
"{",
"// Credits: https://github.com/substack/node-mkdirp",
"// Recursively go through the parents.",
"const",
"recurse",
"=",
"(",
")",
"=>",
"{",
"mkdir",
"(",
"path",
".",
"dirname",
"(",
"dirPath",
")",
",",
"(",
"error",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"async",
".",
"nextTick",
"(",
"callback",
",",
"error",
")",
";",
"return",
";",
"}",
"// Try again.",
"mkdir",
"(",
"dirPath",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
";",
"// Plan B for when things seem to go wrong.",
"const",
"fallBack",
"=",
"(",
")",
"=>",
"{",
"fs",
".",
"stat",
"(",
"dirPath",
",",
"(",
"error",
",",
"stat",
")",
"=>",
"{",
"if",
"(",
"error",
"||",
"!",
"stat",
".",
"isDirectory",
"(",
")",
")",
"{",
"async",
".",
"nextTick",
"(",
"callback",
",",
"new",
"Error",
"(",
"`",
"${",
"dirPath",
"}",
"`",
")",
")",
";",
"return",
";",
"}",
"async",
".",
"nextTick",
"(",
"callback",
",",
"null",
")",
";",
"}",
")",
";",
"}",
";",
"fs",
".",
"mkdir",
"(",
"dirPath",
",",
"(",
"error",
")",
"=>",
"{",
"if",
"(",
"!",
"error",
")",
"{",
"async",
".",
"nextTick",
"(",
"callback",
",",
"null",
")",
";",
"return",
";",
"}",
"switch",
"(",
"error",
".",
"code",
")",
"{",
"case",
"'ENOENT'",
":",
"recurse",
"(",
")",
";",
"break",
";",
"default",
":",
"fallBack",
"(",
")",
";",
"break",
";",
"}",
"}",
")",
";",
"}"
] | Create a directory and any missing parent directory. | [
"Create",
"a",
"directory",
"and",
"any",
"missing",
"parent",
"directory",
"."
] | 411ccd344a03478776c4e8d2e2f9bdc45dc8ee45 | https://github.com/christophercrouzet/pillr/blob/411ccd344a03478776c4e8d2e2f9bdc45dc8ee45/lib/utils.js#L64-L110 |
56,965 | christophercrouzet/pillr | lib/utils.js | write | function write(filePath, data, mode, callback) {
async.series([
cb => mkdir(path.dirname(filePath), cb),
(cb) => {
if (mode === WriteMode.UTF8) {
fs.writeFile(filePath, data, 'utf8', (error) => {
if (error) {
console.error(`${filePath}: Could not write the file`);
}
async.nextTick(cb, error);
});
} else if (mode === WriteMode.STREAM) {
try {
data.pipe(fs.createWriteStream(filePath));
async.nextTick(cb, null);
} catch (error) {
console.error(`${filePath}: Could not create the write stream`);
async.nextTick(cb, error);
}
}
},
], error => async.nextTick(callback, error));
} | javascript | function write(filePath, data, mode, callback) {
async.series([
cb => mkdir(path.dirname(filePath), cb),
(cb) => {
if (mode === WriteMode.UTF8) {
fs.writeFile(filePath, data, 'utf8', (error) => {
if (error) {
console.error(`${filePath}: Could not write the file`);
}
async.nextTick(cb, error);
});
} else if (mode === WriteMode.STREAM) {
try {
data.pipe(fs.createWriteStream(filePath));
async.nextTick(cb, null);
} catch (error) {
console.error(`${filePath}: Could not create the write stream`);
async.nextTick(cb, error);
}
}
},
], error => async.nextTick(callback, error));
} | [
"function",
"write",
"(",
"filePath",
",",
"data",
",",
"mode",
",",
"callback",
")",
"{",
"async",
".",
"series",
"(",
"[",
"cb",
"=>",
"mkdir",
"(",
"path",
".",
"dirname",
"(",
"filePath",
")",
",",
"cb",
")",
",",
"(",
"cb",
")",
"=>",
"{",
"if",
"(",
"mode",
"===",
"WriteMode",
".",
"UTF8",
")",
"{",
"fs",
".",
"writeFile",
"(",
"filePath",
",",
"data",
",",
"'utf8'",
",",
"(",
"error",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"filePath",
"}",
"`",
")",
";",
"}",
"async",
".",
"nextTick",
"(",
"cb",
",",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"mode",
"===",
"WriteMode",
".",
"STREAM",
")",
"{",
"try",
"{",
"data",
".",
"pipe",
"(",
"fs",
".",
"createWriteStream",
"(",
"filePath",
")",
")",
";",
"async",
".",
"nextTick",
"(",
"cb",
",",
"null",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"`",
"${",
"filePath",
"}",
"`",
")",
";",
"async",
".",
"nextTick",
"(",
"cb",
",",
"error",
")",
";",
"}",
"}",
"}",
",",
"]",
",",
"error",
"=>",
"async",
".",
"nextTick",
"(",
"callback",
",",
"error",
")",
")",
";",
"}"
] | Write a file. | [
"Write",
"a",
"file",
"."
] | 411ccd344a03478776c4e8d2e2f9bdc45dc8ee45 | https://github.com/christophercrouzet/pillr/blob/411ccd344a03478776c4e8d2e2f9bdc45dc8ee45/lib/utils.js#L173-L196 |
56,966 | pinyin/outline | vendor/transformation-matrix/shear.js | shear | function shear(shx, shy) {
return {
a: 1, c: shx, e: 0,
b: shy, d: 1, f: 0
};
} | javascript | function shear(shx, shy) {
return {
a: 1, c: shx, e: 0,
b: shy, d: 1, f: 0
};
} | [
"function",
"shear",
"(",
"shx",
",",
"shy",
")",
"{",
"return",
"{",
"a",
":",
"1",
",",
"c",
":",
"shx",
",",
"e",
":",
"0",
",",
"b",
":",
"shy",
",",
"d",
":",
"1",
",",
"f",
":",
"0",
"}",
";",
"}"
] | Calculate a shear matrix
@param shx Shear on axis x
@param shy Shear on axis y
@returns {{a: number, b: number, c: number, e: number, d: number, f: number}} Affine matrix | [
"Calculate",
"a",
"shear",
"matrix"
] | e49f05d2f8ab384f5b1d71b2b10875cd48d41051 | https://github.com/pinyin/outline/blob/e49f05d2f8ab384f5b1d71b2b10875cd48d41051/vendor/transformation-matrix/shear.js#L14-L19 |
56,967 | olizilla/instagrab | index.js | apiUrlFor | function apiUrlFor (shortcode, size) {
if (!shortcode) throw new Error('shortcode parameter is required')
size = size || 'l'
var api = 'http://instagram.com/p/%s/media/?size=%s'
return util.format(api, shortcode, size)
} | javascript | function apiUrlFor (shortcode, size) {
if (!shortcode) throw new Error('shortcode parameter is required')
size = size || 'l'
var api = 'http://instagram.com/p/%s/media/?size=%s'
return util.format(api, shortcode, size)
} | [
"function",
"apiUrlFor",
"(",
"shortcode",
",",
"size",
")",
"{",
"if",
"(",
"!",
"shortcode",
")",
"throw",
"new",
"Error",
"(",
"'shortcode parameter is required'",
")",
"size",
"=",
"size",
"||",
"'l'",
"var",
"api",
"=",
"'http://instagram.com/p/%s/media/?size=%s'",
"return",
"util",
".",
"format",
"(",
"api",
",",
"shortcode",
",",
"size",
")",
"}"
] | Build the api url from it's ingredients | [
"Build",
"the",
"api",
"url",
"from",
"it",
"s",
"ingredients"
] | fe21a57a0aeecacaaa37eccc9d06822889d78ba6 | https://github.com/olizilla/instagrab/blob/fe21a57a0aeecacaaa37eccc9d06822889d78ba6/index.js#L36-L42 |
56,968 | olizilla/instagrab | index.js | filenameFor | function filenameFor(shortcode, size) {
if (!shortcode) throw new Error('shortcode parameter is required')
size = size || 'l'
return [shortcode, size, 'jpg'].join('.')
} | javascript | function filenameFor(shortcode, size) {
if (!shortcode) throw new Error('shortcode parameter is required')
size = size || 'l'
return [shortcode, size, 'jpg'].join('.')
} | [
"function",
"filenameFor",
"(",
"shortcode",
",",
"size",
")",
"{",
"if",
"(",
"!",
"shortcode",
")",
"throw",
"new",
"Error",
"(",
"'shortcode parameter is required'",
")",
"size",
"=",
"size",
"||",
"'l'",
"return",
"[",
"shortcode",
",",
"size",
",",
"'jpg'",
"]",
".",
"join",
"(",
"'.'",
")",
"}"
] | Make up a useful filename | [
"Make",
"up",
"a",
"useful",
"filename"
] | fe21a57a0aeecacaaa37eccc9d06822889d78ba6 | https://github.com/olizilla/instagrab/blob/fe21a57a0aeecacaaa37eccc9d06822889d78ba6/index.js#L45-L50 |
56,969 | olizilla/instagrab | index.js | resolvedUrlFor | function resolvedUrlFor (shortcode, size, cb) {
if (typeof size === 'function') {
cb = size
size = 'l'
}
cb = cb || function () {}
var apiUrl = apiUrlFor(shortcode, size)
var opts = url.parse(apiUrl)
// http requests use the global Agent (connection pool) and defaults to `Connection: keep-alive`
// This causes the test suite to hang, so we explicitly set it to close.
// Alternatively, set `opts.agent: false` to opt out of connection pool and default to `Connection: close`
// see: http://nodejs.org/api/http.html#http_http_request_options_callback
opts.headers = {
Connection:'close'
}
http.get(opts, function (res) {
var url = res && res.headers && res.headers.location
if (!url) return cb(new Error('Couldn\'t get url; no `location` header on response'), res)
cb(null, url)
}).on('error', cb)
} | javascript | function resolvedUrlFor (shortcode, size, cb) {
if (typeof size === 'function') {
cb = size
size = 'l'
}
cb = cb || function () {}
var apiUrl = apiUrlFor(shortcode, size)
var opts = url.parse(apiUrl)
// http requests use the global Agent (connection pool) and defaults to `Connection: keep-alive`
// This causes the test suite to hang, so we explicitly set it to close.
// Alternatively, set `opts.agent: false` to opt out of connection pool and default to `Connection: close`
// see: http://nodejs.org/api/http.html#http_http_request_options_callback
opts.headers = {
Connection:'close'
}
http.get(opts, function (res) {
var url = res && res.headers && res.headers.location
if (!url) return cb(new Error('Couldn\'t get url; no `location` header on response'), res)
cb(null, url)
}).on('error', cb)
} | [
"function",
"resolvedUrlFor",
"(",
"shortcode",
",",
"size",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"size",
"===",
"'function'",
")",
"{",
"cb",
"=",
"size",
"size",
"=",
"'l'",
"}",
"cb",
"=",
"cb",
"||",
"function",
"(",
")",
"{",
"}",
"var",
"apiUrl",
"=",
"apiUrlFor",
"(",
"shortcode",
",",
"size",
")",
"var",
"opts",
"=",
"url",
".",
"parse",
"(",
"apiUrl",
")",
"// http requests use the global Agent (connection pool) and defaults to `Connection: keep-alive`",
"// This causes the test suite to hang, so we explicitly set it to close.",
"// Alternatively, set `opts.agent: false` to opt out of connection pool and default to `Connection: close`",
"// see: http://nodejs.org/api/http.html#http_http_request_options_callback",
"opts",
".",
"headers",
"=",
"{",
"Connection",
":",
"'close'",
"}",
"http",
".",
"get",
"(",
"opts",
",",
"function",
"(",
"res",
")",
"{",
"var",
"url",
"=",
"res",
"&&",
"res",
".",
"headers",
"&&",
"res",
".",
"headers",
".",
"location",
"if",
"(",
"!",
"url",
")",
"return",
"cb",
"(",
"new",
"Error",
"(",
"'Couldn\\'t get url; no `location` header on response'",
")",
",",
"res",
")",
"cb",
"(",
"null",
",",
"url",
")",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"cb",
")",
"}"
] | Grab the location header from the initial response. | [
"Grab",
"the",
"location",
"header",
"from",
"the",
"initial",
"response",
"."
] | fe21a57a0aeecacaaa37eccc9d06822889d78ba6 | https://github.com/olizilla/instagrab/blob/fe21a57a0aeecacaaa37eccc9d06822889d78ba6/index.js#L59-L83 |
56,970 | thadeudepaula/enqjs | enq.js | binder | function binder(taskID) {
expected++;
return function(ret) {
expected--;
if(!returned && taskID !== 'false') {
if (typeof taskID == 'number') returned=[];
else if (typeof taskID == 'string') returned={};
};
taskID !== false ? returned[taskID]=ret : returned = ret;
// Timeout needed to increment expected, if next item exists.
// If it run without timeout, expected always be 0 and only
// the first function of the group will be executed.
setTimeout(function(){if (! expected) runQueue();},1);
}
} | javascript | function binder(taskID) {
expected++;
return function(ret) {
expected--;
if(!returned && taskID !== 'false') {
if (typeof taskID == 'number') returned=[];
else if (typeof taskID == 'string') returned={};
};
taskID !== false ? returned[taskID]=ret : returned = ret;
// Timeout needed to increment expected, if next item exists.
// If it run without timeout, expected always be 0 and only
// the first function of the group will be executed.
setTimeout(function(){if (! expected) runQueue();},1);
}
} | [
"function",
"binder",
"(",
"taskID",
")",
"{",
"expected",
"++",
";",
"return",
"function",
"(",
"ret",
")",
"{",
"expected",
"--",
";",
"if",
"(",
"!",
"returned",
"&&",
"taskID",
"!==",
"'false'",
")",
"{",
"if",
"(",
"typeof",
"taskID",
"==",
"'number'",
")",
"returned",
"=",
"[",
"]",
";",
"else",
"if",
"(",
"typeof",
"taskID",
"==",
"'string'",
")",
"returned",
"=",
"{",
"}",
";",
"}",
";",
"taskID",
"!==",
"false",
"?",
"returned",
"[",
"taskID",
"]",
"=",
"ret",
":",
"returned",
"=",
"ret",
";",
"// Timeout needed to increment expected, if next item exists.",
"// If it run without timeout, expected always be 0 and only",
"// the first function of the group will be executed.",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"expected",
")",
"runQueue",
"(",
")",
";",
"}",
",",
"1",
")",
";",
"}",
"}"
] | Generate the return function for taskObject. Each task needs a specific function to bind the response to correct order of call | [
"Generate",
"the",
"return",
"function",
"for",
"taskObject",
".",
"Each",
"task",
"needs",
"a",
"specific",
"function",
"to",
"bind",
"the",
"response",
"to",
"correct",
"order",
"of",
"call"
] | e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e | https://github.com/thadeudepaula/enqjs/blob/e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e/enq.js#L10-L24 |
56,971 | thadeudepaula/enqjs | enq.js | argumentFilter | function argumentFilter(args){
var ret;
if (typeof args[0] == 'object') {
args=args[0];
ret={};
for (var i in args) if (args.hasOwnProperty(i) && typeof args[i] == 'function') {
ret[i]=args[i];
}
return ret;
}
ret=[];
for (var i=0,ii=args.length;i<ii;i++) if (typeof args[i] == 'function') {
ret.push(args[i]);
}
return ret;
} | javascript | function argumentFilter(args){
var ret;
if (typeof args[0] == 'object') {
args=args[0];
ret={};
for (var i in args) if (args.hasOwnProperty(i) && typeof args[i] == 'function') {
ret[i]=args[i];
}
return ret;
}
ret=[];
for (var i=0,ii=args.length;i<ii;i++) if (typeof args[i] == 'function') {
ret.push(args[i]);
}
return ret;
} | [
"function",
"argumentFilter",
"(",
"args",
")",
"{",
"var",
"ret",
";",
"if",
"(",
"typeof",
"args",
"[",
"0",
"]",
"==",
"'object'",
")",
"{",
"args",
"=",
"args",
"[",
"0",
"]",
";",
"ret",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"i",
"in",
"args",
")",
"if",
"(",
"args",
".",
"hasOwnProperty",
"(",
"i",
")",
"&&",
"typeof",
"args",
"[",
"i",
"]",
"==",
"'function'",
")",
"{",
"ret",
"[",
"i",
"]",
"=",
"args",
"[",
"i",
"]",
";",
"}",
"return",
"ret",
";",
"}",
"ret",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"ii",
"=",
"args",
".",
"length",
";",
"i",
"<",
"ii",
";",
"i",
"++",
")",
"if",
"(",
"typeof",
"args",
"[",
"i",
"]",
"==",
"'function'",
")",
"{",
"ret",
".",
"push",
"(",
"args",
"[",
"i",
"]",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | If first item of args is an object, it returns the functions contained there else return a list of functions in args | [
"If",
"first",
"item",
"of",
"args",
"is",
"an",
"object",
"it",
"returns",
"the",
"functions",
"contained",
"there",
"else",
"return",
"a",
"list",
"of",
"functions",
"in",
"args"
] | e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e | https://github.com/thadeudepaula/enqjs/blob/e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e/enq.js#L35-L50 |
56,972 | thadeudepaula/enqjs | enq.js | runQueue | function runQueue() {
var lastReturned = returned instanceof Array ? returned : [returned]
, tasks = queued.shift();
if (tasks) tasks = tasks.tasks;
returned = undefined;
if (tasks instanceof Array) {
for (var t=0,tt=tasks.length; t<tt; t++) {
tasks[t].apply(taskObject(t),lastReturned);
};
return;
}
if (typeof tasks == 'object') {
for (var t in tasks) if (tasks.hasOwnProperty(t)) {
tasks[t].apply(taskObject(t),lastReturned);
}
return;
}
} | javascript | function runQueue() {
var lastReturned = returned instanceof Array ? returned : [returned]
, tasks = queued.shift();
if (tasks) tasks = tasks.tasks;
returned = undefined;
if (tasks instanceof Array) {
for (var t=0,tt=tasks.length; t<tt; t++) {
tasks[t].apply(taskObject(t),lastReturned);
};
return;
}
if (typeof tasks == 'object') {
for (var t in tasks) if (tasks.hasOwnProperty(t)) {
tasks[t].apply(taskObject(t),lastReturned);
}
return;
}
} | [
"function",
"runQueue",
"(",
")",
"{",
"var",
"lastReturned",
"=",
"returned",
"instanceof",
"Array",
"?",
"returned",
":",
"[",
"returned",
"]",
",",
"tasks",
"=",
"queued",
".",
"shift",
"(",
")",
";",
"if",
"(",
"tasks",
")",
"tasks",
"=",
"tasks",
".",
"tasks",
";",
"returned",
"=",
"undefined",
";",
"if",
"(",
"tasks",
"instanceof",
"Array",
")",
"{",
"for",
"(",
"var",
"t",
"=",
"0",
",",
"tt",
"=",
"tasks",
".",
"length",
";",
"t",
"<",
"tt",
";",
"t",
"++",
")",
"{",
"tasks",
"[",
"t",
"]",
".",
"apply",
"(",
"taskObject",
"(",
"t",
")",
",",
"lastReturned",
")",
";",
"}",
";",
"return",
";",
"}",
"if",
"(",
"typeof",
"tasks",
"==",
"'object'",
")",
"{",
"for",
"(",
"var",
"t",
"in",
"tasks",
")",
"if",
"(",
"tasks",
".",
"hasOwnProperty",
"(",
"t",
")",
")",
"{",
"tasks",
"[",
"t",
"]",
".",
"apply",
"(",
"taskObject",
"(",
"t",
")",
",",
"lastReturned",
")",
";",
"}",
"return",
";",
"}",
"}"
] | Take the next group of tasks from the stack; | [
"Take",
"the",
"next",
"group",
"of",
"tasks",
"from",
"the",
"stack",
";"
] | e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e | https://github.com/thadeudepaula/enqjs/blob/e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e/enq.js#L53-L72 |
56,973 | thadeudepaula/enqjs | enq.js | enqueue | function enqueue(){
var tasks = argumentFilter(arguments);
queued.push({ tasks:tasks });
// Timeout needed to increment expected, if next item exists.
// If it run without timeout, expected always be 0 and the functions
// will be executed immediately obtaining undefined as parameter.
setTimeout(function(){if (! expected) runQueue();},1);
return enqueue;
} | javascript | function enqueue(){
var tasks = argumentFilter(arguments);
queued.push({ tasks:tasks });
// Timeout needed to increment expected, if next item exists.
// If it run without timeout, expected always be 0 and the functions
// will be executed immediately obtaining undefined as parameter.
setTimeout(function(){if (! expected) runQueue();},1);
return enqueue;
} | [
"function",
"enqueue",
"(",
")",
"{",
"var",
"tasks",
"=",
"argumentFilter",
"(",
"arguments",
")",
";",
"queued",
".",
"push",
"(",
"{",
"tasks",
":",
"tasks",
"}",
")",
";",
"// Timeout needed to increment expected, if next item exists.",
"// If it run without timeout, expected always be 0 and the functions",
"// will be executed immediately obtaining undefined as parameter.",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"expected",
")",
"runQueue",
"(",
")",
";",
"}",
",",
"1",
")",
";",
"return",
"enqueue",
";",
"}"
] | Add a new group of tasks in stack. | [
"Add",
"a",
"new",
"group",
"of",
"tasks",
"in",
"stack",
"."
] | e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e | https://github.com/thadeudepaula/enqjs/blob/e6cf9704a1d1ba5f8c1b8639672ce554cc3b4e1e/enq.js#L75-L83 |
56,974 | MiguelCastillo/p-stream | index.js | readableStream | function readableStream(stream) {
return new Promise(function(resolve, reject) {
var chunks = {
data: []
};
function onData(chunk) {
if (!chunks.type) {
chunks.type = chunkTypes[typeof chunk];
}
chunks.data.push(chunk);
}
function onEnd() {
if (chunks.type === chunkTypes.object) {
resolve(Buffer.concat(chunks.data));
}
else {
resolve(chunks.data.join(""));
}
}
function onError(error) {
reject(error);
}
stream
.on("error", onError)
.on("data", onData)
.on("end", onEnd);
});
} | javascript | function readableStream(stream) {
return new Promise(function(resolve, reject) {
var chunks = {
data: []
};
function onData(chunk) {
if (!chunks.type) {
chunks.type = chunkTypes[typeof chunk];
}
chunks.data.push(chunk);
}
function onEnd() {
if (chunks.type === chunkTypes.object) {
resolve(Buffer.concat(chunks.data));
}
else {
resolve(chunks.data.join(""));
}
}
function onError(error) {
reject(error);
}
stream
.on("error", onError)
.on("data", onData)
.on("end", onEnd);
});
} | [
"function",
"readableStream",
"(",
"stream",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"var",
"chunks",
"=",
"{",
"data",
":",
"[",
"]",
"}",
";",
"function",
"onData",
"(",
"chunk",
")",
"{",
"if",
"(",
"!",
"chunks",
".",
"type",
")",
"{",
"chunks",
".",
"type",
"=",
"chunkTypes",
"[",
"typeof",
"chunk",
"]",
";",
"}",
"chunks",
".",
"data",
".",
"push",
"(",
"chunk",
")",
";",
"}",
"function",
"onEnd",
"(",
")",
"{",
"if",
"(",
"chunks",
".",
"type",
"===",
"chunkTypes",
".",
"object",
")",
"{",
"resolve",
"(",
"Buffer",
".",
"concat",
"(",
"chunks",
".",
"data",
")",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
"chunks",
".",
"data",
".",
"join",
"(",
"\"\"",
")",
")",
";",
"}",
"}",
"function",
"onError",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"}",
"stream",
".",
"on",
"(",
"\"error\"",
",",
"onError",
")",
".",
"on",
"(",
"\"data\"",
",",
"onData",
")",
".",
"on",
"(",
"\"end\"",
",",
"onEnd",
")",
";",
"}",
")",
";",
"}"
] | Takes in a readable stream and returns a promise. The promise is resolved
when all the data is read. Or reject if the stream has errors.
@param {Stream} stream - Stream to read from to resolve the promise with.
@returns {Promise} | [
"Takes",
"in",
"a",
"readable",
"stream",
"and",
"returns",
"a",
"promise",
".",
"The",
"promise",
"is",
"resolved",
"when",
"all",
"the",
"data",
"is",
"read",
".",
"Or",
"reject",
"if",
"the",
"stream",
"has",
"errors",
"."
] | e6d1bb92c14cc609d756e862577e984148d7b955 | https://github.com/MiguelCastillo/p-stream/blob/e6d1bb92c14cc609d756e862577e984148d7b955/index.js#L15-L47 |
56,975 | stephenharris/grunt-checkwpversion | tasks/checkwpversion.js | function( version ){
//lowercase
version = version.toLowerCase();
//Remove spaces;
version = version.replace( ' ', '' );
//Make delimiters all the same
version = version.replace( '-', '.' );
version = version.replace( '_', '.' );
version = version.replace( '+', '.' );
var length = version.length;
var newVersion = false;
newVersion = version[0];
for( var i=1; i < length; i++ ){
var a = version[i-1];
var b = version[i];
if( '.' === a || '.' === b ){
newVersion += b;
continue;
}
var sameType = ( isNaN( a ) === isNaN( b ) );
if( sameType ){
newVersion += b;
}else{
newVersion += "."+b;
}
}
//Split at delimiter
var versionArray = newVersion.split( '.' );
//Filter empty parts
versionArray = versionArray.filter( function(e){ return ( e !== "" ); } );
//Convert special text into character form.
versionArray = versionArray.map( function( e ){
switch( e ){
case 'alpha':
return 'a';
case 'beta':
return 'b';
case 'pl':
return 'p';
default:
return e;
}
} );
return versionArray.join('.');
} | javascript | function( version ){
//lowercase
version = version.toLowerCase();
//Remove spaces;
version = version.replace( ' ', '' );
//Make delimiters all the same
version = version.replace( '-', '.' );
version = version.replace( '_', '.' );
version = version.replace( '+', '.' );
var length = version.length;
var newVersion = false;
newVersion = version[0];
for( var i=1; i < length; i++ ){
var a = version[i-1];
var b = version[i];
if( '.' === a || '.' === b ){
newVersion += b;
continue;
}
var sameType = ( isNaN( a ) === isNaN( b ) );
if( sameType ){
newVersion += b;
}else{
newVersion += "."+b;
}
}
//Split at delimiter
var versionArray = newVersion.split( '.' );
//Filter empty parts
versionArray = versionArray.filter( function(e){ return ( e !== "" ); } );
//Convert special text into character form.
versionArray = versionArray.map( function( e ){
switch( e ){
case 'alpha':
return 'a';
case 'beta':
return 'b';
case 'pl':
return 'p';
default:
return e;
}
} );
return versionArray.join('.');
} | [
"function",
"(",
"version",
")",
"{",
"//lowercase",
"version",
"=",
"version",
".",
"toLowerCase",
"(",
")",
";",
"//Remove spaces;",
"version",
"=",
"version",
".",
"replace",
"(",
"' '",
",",
"''",
")",
";",
"//Make delimiters all the same",
"version",
"=",
"version",
".",
"replace",
"(",
"'-'",
",",
"'.'",
")",
";",
"version",
"=",
"version",
".",
"replace",
"(",
"'_'",
",",
"'.'",
")",
";",
"version",
"=",
"version",
".",
"replace",
"(",
"'+'",
",",
"'.'",
")",
";",
"var",
"length",
"=",
"version",
".",
"length",
";",
"var",
"newVersion",
"=",
"false",
";",
"newVersion",
"=",
"version",
"[",
"0",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"var",
"a",
"=",
"version",
"[",
"i",
"-",
"1",
"]",
";",
"var",
"b",
"=",
"version",
"[",
"i",
"]",
";",
"if",
"(",
"'.'",
"===",
"a",
"||",
"'.'",
"===",
"b",
")",
"{",
"newVersion",
"+=",
"b",
";",
"continue",
";",
"}",
"var",
"sameType",
"=",
"(",
"isNaN",
"(",
"a",
")",
"===",
"isNaN",
"(",
"b",
")",
")",
";",
"if",
"(",
"sameType",
")",
"{",
"newVersion",
"+=",
"b",
";",
"}",
"else",
"{",
"newVersion",
"+=",
"\".\"",
"+",
"b",
";",
"}",
"}",
"//Split at delimiter",
"var",
"versionArray",
"=",
"newVersion",
".",
"split",
"(",
"'.'",
")",
";",
"//Filter empty parts",
"versionArray",
"=",
"versionArray",
".",
"filter",
"(",
"function",
"(",
"e",
")",
"{",
"return",
"(",
"e",
"!==",
"\"\"",
")",
";",
"}",
")",
";",
"//Convert special text into character form.",
"versionArray",
"=",
"versionArray",
".",
"map",
"(",
"function",
"(",
"e",
")",
"{",
"switch",
"(",
"e",
")",
"{",
"case",
"'alpha'",
":",
"return",
"'a'",
";",
"case",
"'beta'",
":",
"return",
"'b'",
";",
"case",
"'pl'",
":",
"return",
"'p'",
";",
"default",
":",
"return",
"e",
";",
"}",
"}",
")",
";",
"return",
"versionArray",
".",
"join",
"(",
"'.'",
")",
";",
"}"
] | Sanitize a version string
It does the following:
* Casts the string to lower case
* Empty spaces are removed
* Converts accepted delimiters ('.', '_', '-', '+') to '.'
* Adds a . between strings and non-strings: e.g. "1.4b1" becomes "1.4.b.1"
* Empty components are removed, e.g. "1.4..1" because "1.4.1"
* "alpha", "beta", "pl" are converted to their 1-character equivalents: "a", "b", "p"
@param version
@returns | [
"Sanitize",
"a",
"version",
"string"
] | 42172ead82c87693726d2116830b5a286b115a2a | https://github.com/stephenharris/grunt-checkwpversion/blob/42172ead82c87693726d2116830b5a286b115a2a/tasks/checkwpversion.js#L144-L206 |
|
56,976 | stephenharris/grunt-checkwpversion | tasks/checkwpversion.js | function ( version, options ){
var matches;
//First if version is 'readme' or 'plugin' version values
if( version === 'readme' ){
var readme = grunt.file.read( options.readme );
matches = readme.match( new RegExp("^Stable tag:\\s*(\\S+)","im") );
if( matches.length <= 1 ){
grunt.fail.fatal( 'Could not find version in "' + options.readme + '"' );
}
version = matches[1];
}else if( version === 'plugin' ){
var plugin = grunt.file.read( options.plugin );
matches = plugin.match( new RegExp("^[\* ]*Version:\\s*(\\S+)","im") );
if( matches.length <= 1 ){
grunt.fail.fatal( 'Could not find version in "' + options.readme + '"' );
}
version = matches[1];
}
return version;
} | javascript | function ( version, options ){
var matches;
//First if version is 'readme' or 'plugin' version values
if( version === 'readme' ){
var readme = grunt.file.read( options.readme );
matches = readme.match( new RegExp("^Stable tag:\\s*(\\S+)","im") );
if( matches.length <= 1 ){
grunt.fail.fatal( 'Could not find version in "' + options.readme + '"' );
}
version = matches[1];
}else if( version === 'plugin' ){
var plugin = grunt.file.read( options.plugin );
matches = plugin.match( new RegExp("^[\* ]*Version:\\s*(\\S+)","im") );
if( matches.length <= 1 ){
grunt.fail.fatal( 'Could not find version in "' + options.readme + '"' );
}
version = matches[1];
}
return version;
} | [
"function",
"(",
"version",
",",
"options",
")",
"{",
"var",
"matches",
";",
"//First if version is 'readme' or 'plugin' version values",
"if",
"(",
"version",
"===",
"'readme'",
")",
"{",
"var",
"readme",
"=",
"grunt",
".",
"file",
".",
"read",
"(",
"options",
".",
"readme",
")",
";",
"matches",
"=",
"readme",
".",
"match",
"(",
"new",
"RegExp",
"(",
"\"^Stable tag:\\\\s*(\\\\S+)\"",
",",
"\"im\"",
")",
")",
";",
"if",
"(",
"matches",
".",
"length",
"<=",
"1",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'Could not find version in \"'",
"+",
"options",
".",
"readme",
"+",
"'\"'",
")",
";",
"}",
"version",
"=",
"matches",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"version",
"===",
"'plugin'",
")",
"{",
"var",
"plugin",
"=",
"grunt",
".",
"file",
".",
"read",
"(",
"options",
".",
"plugin",
")",
";",
"matches",
"=",
"plugin",
".",
"match",
"(",
"new",
"RegExp",
"(",
"\"^[\\* ]*Version:\\\\s*(\\\\S+)\"",
",",
"\"im\"",
")",
")",
";",
"if",
"(",
"matches",
".",
"length",
"<=",
"1",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'Could not find version in \"'",
"+",
"options",
".",
"readme",
"+",
"'\"'",
")",
";",
"}",
"version",
"=",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"version",
";",
"}"
] | If version is 'readme' or 'plugin', attempts to extract the version stored in
the corresponding files as specified by options. | [
"If",
"version",
"is",
"readme",
"or",
"plugin",
"attempts",
"to",
"extract",
"the",
"version",
"stored",
"in",
"the",
"corresponding",
"files",
"as",
"specified",
"by",
"options",
"."
] | 42172ead82c87693726d2116830b5a286b115a2a | https://github.com/stephenharris/grunt-checkwpversion/blob/42172ead82c87693726d2116830b5a286b115a2a/tasks/checkwpversion.js#L239-L263 |
|
56,977 | altshift/altshift | lib/altshift/application.js | register | function register(app) {
//Check if registered twice
if (applicationCurrent === app) {
return;
}
//Only one application can be registered
if (applicationCurrent) {
throw new core.Error({
code: 'application-registered',
message: 'An application was already registered'
});
}
//Set all handlers
Interface.ensure(app, IApplication);
applicationCurrent = app;
currentHandlers.SIGINT = function () {
console.log('Application interrupted');
app.exit();
};
/*
FIXME: Eclipse bug
currentHandlers.SIGTERM = function () {
console.log('Killing in the name of!');
unregister();
process.exit();
};*/
currentHandlers.uncaughtException = function (error) {
app.handleError(error);
};
currentHandlers.exit = function () {
exports.unregister();
};
EVENTS.forEach(function (event) {
if (currentHandlers[event]) {
process.on(event, currentHandlers[event]);
}
});
//Start application
applicationCurrent.start();
} | javascript | function register(app) {
//Check if registered twice
if (applicationCurrent === app) {
return;
}
//Only one application can be registered
if (applicationCurrent) {
throw new core.Error({
code: 'application-registered',
message: 'An application was already registered'
});
}
//Set all handlers
Interface.ensure(app, IApplication);
applicationCurrent = app;
currentHandlers.SIGINT = function () {
console.log('Application interrupted');
app.exit();
};
/*
FIXME: Eclipse bug
currentHandlers.SIGTERM = function () {
console.log('Killing in the name of!');
unregister();
process.exit();
};*/
currentHandlers.uncaughtException = function (error) {
app.handleError(error);
};
currentHandlers.exit = function () {
exports.unregister();
};
EVENTS.forEach(function (event) {
if (currentHandlers[event]) {
process.on(event, currentHandlers[event]);
}
});
//Start application
applicationCurrent.start();
} | [
"function",
"register",
"(",
"app",
")",
"{",
"//Check if registered twice",
"if",
"(",
"applicationCurrent",
"===",
"app",
")",
"{",
"return",
";",
"}",
"//Only one application can be registered",
"if",
"(",
"applicationCurrent",
")",
"{",
"throw",
"new",
"core",
".",
"Error",
"(",
"{",
"code",
":",
"'application-registered'",
",",
"message",
":",
"'An application was already registered'",
"}",
")",
";",
"}",
"//Set all handlers",
"Interface",
".",
"ensure",
"(",
"app",
",",
"IApplication",
")",
";",
"applicationCurrent",
"=",
"app",
";",
"currentHandlers",
".",
"SIGINT",
"=",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Application interrupted'",
")",
";",
"app",
".",
"exit",
"(",
")",
";",
"}",
";",
"/*\n FIXME: Eclipse bug\n currentHandlers.SIGTERM = function () {\n console.log('Killing in the name of!');\n unregister();\n process.exit();\n };*/",
"currentHandlers",
".",
"uncaughtException",
"=",
"function",
"(",
"error",
")",
"{",
"app",
".",
"handleError",
"(",
"error",
")",
";",
"}",
";",
"currentHandlers",
".",
"exit",
"=",
"function",
"(",
")",
"{",
"exports",
".",
"unregister",
"(",
")",
";",
"}",
";",
"EVENTS",
".",
"forEach",
"(",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"currentHandlers",
"[",
"event",
"]",
")",
"{",
"process",
".",
"on",
"(",
"event",
",",
"currentHandlers",
"[",
"event",
"]",
")",
";",
"}",
"}",
")",
";",
"//Start application",
"applicationCurrent",
".",
"start",
"(",
")",
";",
"}"
] | Register app as the current executing application.
This will also register all error handler for uncaught exceptions
@param {Application} app
@return undefined | [
"Register",
"app",
"as",
"the",
"current",
"executing",
"application",
".",
"This",
"will",
"also",
"register",
"all",
"error",
"handler",
"for",
"uncaught",
"exceptions"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/application.js#L36-L83 |
56,978 | altshift/altshift | lib/altshift/application.js | unregister | function unregister() {
if (!applicationCurrent) {
return;
}
applicationCurrent.stop();
EVENTS.forEach(function (event) {
process.removeListener(event, currentHandlers[event]);
});
applicationCurrent = null;
currentHandlers = {};
} | javascript | function unregister() {
if (!applicationCurrent) {
return;
}
applicationCurrent.stop();
EVENTS.forEach(function (event) {
process.removeListener(event, currentHandlers[event]);
});
applicationCurrent = null;
currentHandlers = {};
} | [
"function",
"unregister",
"(",
")",
"{",
"if",
"(",
"!",
"applicationCurrent",
")",
"{",
"return",
";",
"}",
"applicationCurrent",
".",
"stop",
"(",
")",
";",
"EVENTS",
".",
"forEach",
"(",
"function",
"(",
"event",
")",
"{",
"process",
".",
"removeListener",
"(",
"event",
",",
"currentHandlers",
"[",
"event",
"]",
")",
";",
"}",
")",
";",
"applicationCurrent",
"=",
"null",
";",
"currentHandlers",
"=",
"{",
"}",
";",
"}"
] | Unregister current application and remove all corrsponding listeners
@return undefined | [
"Unregister",
"current",
"application",
"and",
"remove",
"all",
"corrsponding",
"listeners"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/application.js#L90-L102 |
56,979 | altshift/altshift | lib/altshift/application.js | function (config) {
config = config || {};
if (config.onStart !== undefined) {
if (!isFunction(config.onStart)) {
throw new core.TypeError({
code: 'application-configure',
message: "config.onStart must be a function"
});
}
this.onStart = config.onStart;
}
if (config.onStop !== undefined) {
if (!isFunction(config.onStop)) {
throw new core.TypeError({
code: 'application-configure',
message: "config.onStop must be a function"
});
}
this.onStop = config.onStop;
}
return this;
} | javascript | function (config) {
config = config || {};
if (config.onStart !== undefined) {
if (!isFunction(config.onStart)) {
throw new core.TypeError({
code: 'application-configure',
message: "config.onStart must be a function"
});
}
this.onStart = config.onStart;
}
if (config.onStop !== undefined) {
if (!isFunction(config.onStop)) {
throw new core.TypeError({
code: 'application-configure',
message: "config.onStop must be a function"
});
}
this.onStop = config.onStop;
}
return this;
} | [
"function",
"(",
"config",
")",
"{",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"if",
"(",
"config",
".",
"onStart",
"!==",
"undefined",
")",
"{",
"if",
"(",
"!",
"isFunction",
"(",
"config",
".",
"onStart",
")",
")",
"{",
"throw",
"new",
"core",
".",
"TypeError",
"(",
"{",
"code",
":",
"'application-configure'",
",",
"message",
":",
"\"config.onStart must be a function\"",
"}",
")",
";",
"}",
"this",
".",
"onStart",
"=",
"config",
".",
"onStart",
";",
"}",
"if",
"(",
"config",
".",
"onStop",
"!==",
"undefined",
")",
"{",
"if",
"(",
"!",
"isFunction",
"(",
"config",
".",
"onStop",
")",
")",
"{",
"throw",
"new",
"core",
".",
"TypeError",
"(",
"{",
"code",
":",
"'application-configure'",
",",
"message",
":",
"\"config.onStop must be a function\"",
"}",
")",
";",
"}",
"this",
".",
"onStop",
"=",
"config",
".",
"onStop",
";",
"}",
"return",
"this",
";",
"}"
] | Configure the application
@param {Object} config
@return this | [
"Configure",
"the",
"application"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/application.js#L162-L187 |
|
56,980 | altshift/altshift | lib/altshift/application.js | function (error) {
if (!this.started) {
return;
}
var errorHandlers = this.errorHandlers,
length = errorHandlers.length,
errorHandler,
errorHandled = false,
errorString,
i;
//Exit handling
if (error instanceof SystemExit) {
this._exit(error.code);
return;
}
try {
for (i = 0; i < length; i += 1) {
errorHandler = errorHandlers[i];
errorHandled = !!errorHandler(error);
if (errorHandled) {
return;
}
}
} catch (e) {
this._printError(e);
this._exit(1);
}
//Default error handling
errorString = '' + (error.stack || error);
this._printError(errorString);
this._exit(1);
} | javascript | function (error) {
if (!this.started) {
return;
}
var errorHandlers = this.errorHandlers,
length = errorHandlers.length,
errorHandler,
errorHandled = false,
errorString,
i;
//Exit handling
if (error instanceof SystemExit) {
this._exit(error.code);
return;
}
try {
for (i = 0; i < length; i += 1) {
errorHandler = errorHandlers[i];
errorHandled = !!errorHandler(error);
if (errorHandled) {
return;
}
}
} catch (e) {
this._printError(e);
this._exit(1);
}
//Default error handling
errorString = '' + (error.stack || error);
this._printError(errorString);
this._exit(1);
} | [
"function",
"(",
"error",
")",
"{",
"if",
"(",
"!",
"this",
".",
"started",
")",
"{",
"return",
";",
"}",
"var",
"errorHandlers",
"=",
"this",
".",
"errorHandlers",
",",
"length",
"=",
"errorHandlers",
".",
"length",
",",
"errorHandler",
",",
"errorHandled",
"=",
"false",
",",
"errorString",
",",
"i",
";",
"//Exit handling",
"if",
"(",
"error",
"instanceof",
"SystemExit",
")",
"{",
"this",
".",
"_exit",
"(",
"error",
".",
"code",
")",
";",
"return",
";",
"}",
"try",
"{",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"+=",
"1",
")",
"{",
"errorHandler",
"=",
"errorHandlers",
"[",
"i",
"]",
";",
"errorHandled",
"=",
"!",
"!",
"errorHandler",
"(",
"error",
")",
";",
"if",
"(",
"errorHandled",
")",
"{",
"return",
";",
"}",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"this",
".",
"_printError",
"(",
"e",
")",
";",
"this",
".",
"_exit",
"(",
"1",
")",
";",
"}",
"//Default error handling",
"errorString",
"=",
"''",
"+",
"(",
"error",
".",
"stack",
"||",
"error",
")",
";",
"this",
".",
"_printError",
"(",
"errorString",
")",
";",
"this",
".",
"_exit",
"(",
"1",
")",
";",
"}"
] | Handle one error
@param {*} error | [
"Handle",
"one",
"error"
] | 5c051157e6f558636c8e12081b6707caa66249de | https://github.com/altshift/altshift/blob/5c051157e6f558636c8e12081b6707caa66249de/lib/altshift/application.js#L222-L258 |
|
56,981 | RnbWd/parse-browserify | lib/cloud.js | function(name, data, options) {
options = options || {};
var request = Parse._request({
route: "functions",
className: name,
method: 'POST',
useMasterKey: options.useMasterKey,
data: Parse._encode(data, null, true)
});
return request.then(function(resp) {
return Parse._decode(null, resp).result;
})._thenRunCallbacks(options);
} | javascript | function(name, data, options) {
options = options || {};
var request = Parse._request({
route: "functions",
className: name,
method: 'POST',
useMasterKey: options.useMasterKey,
data: Parse._encode(data, null, true)
});
return request.then(function(resp) {
return Parse._decode(null, resp).result;
})._thenRunCallbacks(options);
} | [
"function",
"(",
"name",
",",
"data",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"request",
"=",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"\"functions\"",
",",
"className",
":",
"name",
",",
"method",
":",
"'POST'",
",",
"useMasterKey",
":",
"options",
".",
"useMasterKey",
",",
"data",
":",
"Parse",
".",
"_encode",
"(",
"data",
",",
"null",
",",
"true",
")",
"}",
")",
";",
"return",
"request",
".",
"then",
"(",
"function",
"(",
"resp",
")",
"{",
"return",
"Parse",
".",
"_decode",
"(",
"null",
",",
"resp",
")",
".",
"result",
";",
"}",
")",
".",
"_thenRunCallbacks",
"(",
"options",
")",
";",
"}"
] | Makes a call to a cloud function.
@param {String} name The function name.
@param {Object} data The parameters to send to the cloud function.
@param {Object} options A Backbone-style options object
options.success, if set, should be a function to handle a successful
call to a cloud function. options.error should be a function that
handles an error running the cloud function. Both functions are
optional. Both functions take a single argument.
@return {Parse.Promise} A promise that will be resolved with the result
of the function. | [
"Makes",
"a",
"call",
"to",
"a",
"cloud",
"function",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/cloud.js#L28-L42 |
|
56,982 | ikondrat/franky | src/etc/views.js | function (/**Array|Object*/tmpl, /**Object*/data) /**String*/{
var res= "";
// there are thre possible declarations array of functions, string and function
// array case
if (franky.isArray(tmpl)) {
res = franky.map(tmpl, function (item) {
return typeof item === "string" ?
item:
item(data);
}).join("");
// function case
} else if (franky.isFunction(tmpl)) {
res = tmpl(data);
// default string case
} else {
res = tmpl.toString();
}
return res;
} | javascript | function (/**Array|Object*/tmpl, /**Object*/data) /**String*/{
var res= "";
// there are thre possible declarations array of functions, string and function
// array case
if (franky.isArray(tmpl)) {
res = franky.map(tmpl, function (item) {
return typeof item === "string" ?
item:
item(data);
}).join("");
// function case
} else if (franky.isFunction(tmpl)) {
res = tmpl(data);
// default string case
} else {
res = tmpl.toString();
}
return res;
} | [
"function",
"(",
"/**Array|Object*/",
"tmpl",
",",
"/**Object*/",
"data",
")",
"/**String*/",
"{",
"var",
"res",
"=",
"\"\"",
";",
"// there are thre possible declarations array of functions, string and function",
"// array case",
"if",
"(",
"franky",
".",
"isArray",
"(",
"tmpl",
")",
")",
"{",
"res",
"=",
"franky",
".",
"map",
"(",
"tmpl",
",",
"function",
"(",
"item",
")",
"{",
"return",
"typeof",
"item",
"===",
"\"string\"",
"?",
"item",
":",
"item",
"(",
"data",
")",
";",
"}",
")",
".",
"join",
"(",
"\"\"",
")",
";",
"// function case",
"}",
"else",
"if",
"(",
"franky",
".",
"isFunction",
"(",
"tmpl",
")",
")",
"{",
"res",
"=",
"tmpl",
"(",
"data",
")",
";",
"// default string case",
"}",
"else",
"{",
"res",
"=",
"tmpl",
".",
"toString",
"(",
")",
";",
"}",
"return",
"res",
";",
"}"
] | Returns processed string | [
"Returns",
"processed",
"string"
] | 6a7368891f39620a225e37c4a56d2bf99644c3e7 | https://github.com/ikondrat/franky/blob/6a7368891f39620a225e37c4a56d2bf99644c3e7/src/etc/views.js#L114-L133 |
|
56,983 | ikondrat/franky | src/etc/views.js | function (/**String*/name, /**Object*/data) /**String*/ {
var self = this;
var template = data && data.views ?
data.views.templates[name] : this.templates[name];
if(!template){
return '';
}
return self.getContent(template, data);
} | javascript | function (/**String*/name, /**Object*/data) /**String*/ {
var self = this;
var template = data && data.views ?
data.views.templates[name] : this.templates[name];
if(!template){
return '';
}
return self.getContent(template, data);
} | [
"function",
"(",
"/**String*/",
"name",
",",
"/**Object*/",
"data",
")",
"/**String*/",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"template",
"=",
"data",
"&&",
"data",
".",
"views",
"?",
"data",
".",
"views",
".",
"templates",
"[",
"name",
"]",
":",
"this",
".",
"templates",
"[",
"name",
"]",
";",
"if",
"(",
"!",
"template",
")",
"{",
"return",
"''",
";",
"}",
"return",
"self",
".",
"getContent",
"(",
"template",
",",
"data",
")",
";",
"}"
] | Gets transformed value by defined template and data | [
"Gets",
"transformed",
"value",
"by",
"defined",
"template",
"and",
"data"
] | 6a7368891f39620a225e37c4a56d2bf99644c3e7 | https://github.com/ikondrat/franky/blob/6a7368891f39620a225e37c4a56d2bf99644c3e7/src/etc/views.js#L136-L144 |
|
56,984 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | fixInitialSelection | function fixInitialSelection( root, nativeSel, doFocus ) {
// It may happen that setting proper selection will
// cause focus to be fired (even without actually focusing root).
// Cancel it because focus shouldn't be fired when retriving selection. (#10115)
var listener = root.on( 'focus', function( evt ) {
evt.cancel();
}, null, null, -100 );
// FF && Webkit.
if ( !CKEDITOR.env.ie ) {
var range = new CKEDITOR.dom.range( root );
range.moveToElementEditStart( root );
var nativeRange = root.getDocument().$.createRange();
nativeRange.setStart( range.startContainer.$, range.startOffset );
nativeRange.collapse( 1 );
nativeSel.removeAllRanges();
nativeSel.addRange( nativeRange );
}
else {
// IE in specific case may also fire selectionchange.
// We cannot block bubbling selectionchange, so at least we
// can prevent from falling into inf recursion caused by fix for #9699
// (see wysiwygarea plugin).
// http://dev.ckeditor.com/ticket/10438#comment:13
var listener2 = root.getDocument().on( 'selectionchange', function( evt ) {
evt.cancel();
}, null, null, -100 );
}
doFocus && root.focus();
listener.removeListener();
listener2 && listener2.removeListener();
} | javascript | function fixInitialSelection( root, nativeSel, doFocus ) {
// It may happen that setting proper selection will
// cause focus to be fired (even without actually focusing root).
// Cancel it because focus shouldn't be fired when retriving selection. (#10115)
var listener = root.on( 'focus', function( evt ) {
evt.cancel();
}, null, null, -100 );
// FF && Webkit.
if ( !CKEDITOR.env.ie ) {
var range = new CKEDITOR.dom.range( root );
range.moveToElementEditStart( root );
var nativeRange = root.getDocument().$.createRange();
nativeRange.setStart( range.startContainer.$, range.startOffset );
nativeRange.collapse( 1 );
nativeSel.removeAllRanges();
nativeSel.addRange( nativeRange );
}
else {
// IE in specific case may also fire selectionchange.
// We cannot block bubbling selectionchange, so at least we
// can prevent from falling into inf recursion caused by fix for #9699
// (see wysiwygarea plugin).
// http://dev.ckeditor.com/ticket/10438#comment:13
var listener2 = root.getDocument().on( 'selectionchange', function( evt ) {
evt.cancel();
}, null, null, -100 );
}
doFocus && root.focus();
listener.removeListener();
listener2 && listener2.removeListener();
} | [
"function",
"fixInitialSelection",
"(",
"root",
",",
"nativeSel",
",",
"doFocus",
")",
"{",
"// It may happen that setting proper selection will",
"// cause focus to be fired (even without actually focusing root).",
"// Cancel it because focus shouldn't be fired when retriving selection. (#10115)",
"var",
"listener",
"=",
"root",
".",
"on",
"(",
"'focus'",
",",
"function",
"(",
"evt",
")",
"{",
"evt",
".",
"cancel",
"(",
")",
";",
"}",
",",
"null",
",",
"null",
",",
"-",
"100",
")",
";",
"// FF && Webkit.",
"if",
"(",
"!",
"CKEDITOR",
".",
"env",
".",
"ie",
")",
"{",
"var",
"range",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"range",
"(",
"root",
")",
";",
"range",
".",
"moveToElementEditStart",
"(",
"root",
")",
";",
"var",
"nativeRange",
"=",
"root",
".",
"getDocument",
"(",
")",
".",
"$",
".",
"createRange",
"(",
")",
";",
"nativeRange",
".",
"setStart",
"(",
"range",
".",
"startContainer",
".",
"$",
",",
"range",
".",
"startOffset",
")",
";",
"nativeRange",
".",
"collapse",
"(",
"1",
")",
";",
"nativeSel",
".",
"removeAllRanges",
"(",
")",
";",
"nativeSel",
".",
"addRange",
"(",
"nativeRange",
")",
";",
"}",
"else",
"{",
"// IE in specific case may also fire selectionchange.",
"// We cannot block bubbling selectionchange, so at least we",
"// can prevent from falling into inf recursion caused by fix for #9699",
"// (see wysiwygarea plugin).",
"// http://dev.ckeditor.com/ticket/10438#comment:13",
"var",
"listener2",
"=",
"root",
".",
"getDocument",
"(",
")",
".",
"on",
"(",
"'selectionchange'",
",",
"function",
"(",
"evt",
")",
"{",
"evt",
".",
"cancel",
"(",
")",
";",
"}",
",",
"null",
",",
"null",
",",
"-",
"100",
")",
";",
"}",
"doFocus",
"&&",
"root",
".",
"focus",
"(",
")",
";",
"listener",
".",
"removeListener",
"(",
")",
";",
"listener2",
"&&",
"listener2",
".",
"removeListener",
"(",
")",
";",
"}"
] | Read the comments in selection constructor. | [
"Read",
"the",
"comments",
"in",
"selection",
"constructor",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L208-L243 |
56,985 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | hideSelection | function hideSelection( editor ) {
var style = CKEDITOR.env.ie ? 'display:none' : 'position:fixed;top:0;left:-1000px',
hiddenEl = CKEDITOR.dom.element.createFromHtml(
'<div data-cke-hidden-sel="1" data-cke-temp="1" style="' + style + '"> </div>',
editor.document );
editor.fire( 'lockSnapshot' );
editor.editable().append( hiddenEl );
// Always use real selection to avoid overriding locked one (http://dev.ckeditor.com/ticket/11104#comment:13).
var sel = editor.getSelection( 1 ),
range = editor.createRange(),
// Cancel selectionchange fired by selectRanges - prevent from firing selectionChange.
listener = sel.root.on( 'selectionchange', function( evt ) {
evt.cancel();
}, null, null, 0 );
range.setStartAt( hiddenEl, CKEDITOR.POSITION_AFTER_START );
range.setEndAt( hiddenEl, CKEDITOR.POSITION_BEFORE_END );
sel.selectRanges( [ range ] );
listener.removeListener();
editor.fire( 'unlockSnapshot' );
// Set this value at the end, so reset() executed by selectRanges()
// will clean up old hidden selection container.
editor._.hiddenSelectionContainer = hiddenEl;
} | javascript | function hideSelection( editor ) {
var style = CKEDITOR.env.ie ? 'display:none' : 'position:fixed;top:0;left:-1000px',
hiddenEl = CKEDITOR.dom.element.createFromHtml(
'<div data-cke-hidden-sel="1" data-cke-temp="1" style="' + style + '"> </div>',
editor.document );
editor.fire( 'lockSnapshot' );
editor.editable().append( hiddenEl );
// Always use real selection to avoid overriding locked one (http://dev.ckeditor.com/ticket/11104#comment:13).
var sel = editor.getSelection( 1 ),
range = editor.createRange(),
// Cancel selectionchange fired by selectRanges - prevent from firing selectionChange.
listener = sel.root.on( 'selectionchange', function( evt ) {
evt.cancel();
}, null, null, 0 );
range.setStartAt( hiddenEl, CKEDITOR.POSITION_AFTER_START );
range.setEndAt( hiddenEl, CKEDITOR.POSITION_BEFORE_END );
sel.selectRanges( [ range ] );
listener.removeListener();
editor.fire( 'unlockSnapshot' );
// Set this value at the end, so reset() executed by selectRanges()
// will clean up old hidden selection container.
editor._.hiddenSelectionContainer = hiddenEl;
} | [
"function",
"hideSelection",
"(",
"editor",
")",
"{",
"var",
"style",
"=",
"CKEDITOR",
".",
"env",
".",
"ie",
"?",
"'display:none'",
":",
"'position:fixed;top:0;left:-1000px'",
",",
"hiddenEl",
"=",
"CKEDITOR",
".",
"dom",
".",
"element",
".",
"createFromHtml",
"(",
"'<div data-cke-hidden-sel=\"1\" data-cke-temp=\"1\" style=\"'",
"+",
"style",
"+",
"'\"> </div>'",
",",
"editor",
".",
"document",
")",
";",
"editor",
".",
"fire",
"(",
"'lockSnapshot'",
")",
";",
"editor",
".",
"editable",
"(",
")",
".",
"append",
"(",
"hiddenEl",
")",
";",
"// Always use real selection to avoid overriding locked one (http://dev.ckeditor.com/ticket/11104#comment:13).",
"var",
"sel",
"=",
"editor",
".",
"getSelection",
"(",
"1",
")",
",",
"range",
"=",
"editor",
".",
"createRange",
"(",
")",
",",
"// Cancel selectionchange fired by selectRanges - prevent from firing selectionChange.",
"listener",
"=",
"sel",
".",
"root",
".",
"on",
"(",
"'selectionchange'",
",",
"function",
"(",
"evt",
")",
"{",
"evt",
".",
"cancel",
"(",
")",
";",
"}",
",",
"null",
",",
"null",
",",
"0",
")",
";",
"range",
".",
"setStartAt",
"(",
"hiddenEl",
",",
"CKEDITOR",
".",
"POSITION_AFTER_START",
")",
";",
"range",
".",
"setEndAt",
"(",
"hiddenEl",
",",
"CKEDITOR",
".",
"POSITION_BEFORE_END",
")",
";",
"sel",
".",
"selectRanges",
"(",
"[",
"range",
"]",
")",
";",
"listener",
".",
"removeListener",
"(",
")",
";",
"editor",
".",
"fire",
"(",
"'unlockSnapshot'",
")",
";",
"// Set this value at the end, so reset() executed by selectRanges()",
"// will clean up old hidden selection container.",
"editor",
".",
"_",
".",
"hiddenSelectionContainer",
"=",
"hiddenEl",
";",
"}"
] | Creates cke_hidden_sel container and puts real selection there. | [
"Creates",
"cke_hidden_sel",
"container",
"and",
"puts",
"real",
"selection",
"there",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L246-L275 |
56,986 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | getOnKeyDownListener | function getOnKeyDownListener( editor ) {
var keystrokes = { 37: 1, 39: 1, 8: 1, 46: 1 };
return function( evt ) {
var keystroke = evt.data.getKeystroke();
// Handle only left/right/del/bspace keys.
if ( !keystrokes[ keystroke ] )
return;
var sel = editor.getSelection(),
ranges = sel.getRanges(),
range = ranges[ 0 ];
// Handle only single range and it has to be collapsed.
if ( ranges.length != 1 || !range.collapsed )
return;
var next = range[ keystroke < 38 ? 'getPreviousEditableNode' : 'getNextEditableNode' ]();
if ( next && next.type == CKEDITOR.NODE_ELEMENT && next.getAttribute( 'contenteditable' ) == 'false' ) {
editor.getSelection().fake( next );
evt.data.preventDefault();
evt.cancel();
}
};
} | javascript | function getOnKeyDownListener( editor ) {
var keystrokes = { 37: 1, 39: 1, 8: 1, 46: 1 };
return function( evt ) {
var keystroke = evt.data.getKeystroke();
// Handle only left/right/del/bspace keys.
if ( !keystrokes[ keystroke ] )
return;
var sel = editor.getSelection(),
ranges = sel.getRanges(),
range = ranges[ 0 ];
// Handle only single range and it has to be collapsed.
if ( ranges.length != 1 || !range.collapsed )
return;
var next = range[ keystroke < 38 ? 'getPreviousEditableNode' : 'getNextEditableNode' ]();
if ( next && next.type == CKEDITOR.NODE_ELEMENT && next.getAttribute( 'contenteditable' ) == 'false' ) {
editor.getSelection().fake( next );
evt.data.preventDefault();
evt.cancel();
}
};
} | [
"function",
"getOnKeyDownListener",
"(",
"editor",
")",
"{",
"var",
"keystrokes",
"=",
"{",
"37",
":",
"1",
",",
"39",
":",
"1",
",",
"8",
":",
"1",
",",
"46",
":",
"1",
"}",
";",
"return",
"function",
"(",
"evt",
")",
"{",
"var",
"keystroke",
"=",
"evt",
".",
"data",
".",
"getKeystroke",
"(",
")",
";",
"// Handle only left/right/del/bspace keys.",
"if",
"(",
"!",
"keystrokes",
"[",
"keystroke",
"]",
")",
"return",
";",
"var",
"sel",
"=",
"editor",
".",
"getSelection",
"(",
")",
",",
"ranges",
"=",
"sel",
".",
"getRanges",
"(",
")",
",",
"range",
"=",
"ranges",
"[",
"0",
"]",
";",
"// Handle only single range and it has to be collapsed.",
"if",
"(",
"ranges",
".",
"length",
"!=",
"1",
"||",
"!",
"range",
".",
"collapsed",
")",
"return",
";",
"var",
"next",
"=",
"range",
"[",
"keystroke",
"<",
"38",
"?",
"'getPreviousEditableNode'",
":",
"'getNextEditableNode'",
"]",
"(",
")",
";",
"if",
"(",
"next",
"&&",
"next",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
"&&",
"next",
".",
"getAttribute",
"(",
"'contenteditable'",
")",
"==",
"'false'",
")",
"{",
"editor",
".",
"getSelection",
"(",
")",
".",
"fake",
"(",
"next",
")",
";",
"evt",
".",
"data",
".",
"preventDefault",
"(",
")",
";",
"evt",
".",
"cancel",
"(",
")",
";",
"}",
"}",
";",
"}"
] | Handle left, right, delete and backspace keystrokes next to non-editable elements by faking selection on them. | [
"Handle",
"left",
"right",
"delete",
"and",
"backspace",
"keystrokes",
"next",
"to",
"non",
"-",
"editable",
"elements",
"by",
"faking",
"selection",
"on",
"them",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L357-L383 |
56,987 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | getNonEditableFakeSelectionReceiver | function getNonEditableFakeSelectionReceiver( ranges ) {
var enclosedNode, shrinkedNode, clone, range;
if ( ranges.length == 1 && !( range = ranges[ 0 ] ).collapsed &&
( enclosedNode = range.getEnclosedNode() ) && enclosedNode.type == CKEDITOR.NODE_ELEMENT ) {
// So far we can't say that enclosed element is non-editable. Before checking,
// we'll shrink range (clone). Shrinking will stop on non-editable range, or
// innermost element (#11114).
clone = range.clone();
clone.shrink( CKEDITOR.SHRINK_ELEMENT, true );
// If shrinked range still encloses an element, check this one (shrink stops only on non-editable elements).
if ( ( shrinkedNode = clone.getEnclosedNode() ) && shrinkedNode.type == CKEDITOR.NODE_ELEMENT )
enclosedNode = shrinkedNode;
if ( enclosedNode.getAttribute( 'contenteditable' ) == 'false' )
return enclosedNode;
}
} | javascript | function getNonEditableFakeSelectionReceiver( ranges ) {
var enclosedNode, shrinkedNode, clone, range;
if ( ranges.length == 1 && !( range = ranges[ 0 ] ).collapsed &&
( enclosedNode = range.getEnclosedNode() ) && enclosedNode.type == CKEDITOR.NODE_ELEMENT ) {
// So far we can't say that enclosed element is non-editable. Before checking,
// we'll shrink range (clone). Shrinking will stop on non-editable range, or
// innermost element (#11114).
clone = range.clone();
clone.shrink( CKEDITOR.SHRINK_ELEMENT, true );
// If shrinked range still encloses an element, check this one (shrink stops only on non-editable elements).
if ( ( shrinkedNode = clone.getEnclosedNode() ) && shrinkedNode.type == CKEDITOR.NODE_ELEMENT )
enclosedNode = shrinkedNode;
if ( enclosedNode.getAttribute( 'contenteditable' ) == 'false' )
return enclosedNode;
}
} | [
"function",
"getNonEditableFakeSelectionReceiver",
"(",
"ranges",
")",
"{",
"var",
"enclosedNode",
",",
"shrinkedNode",
",",
"clone",
",",
"range",
";",
"if",
"(",
"ranges",
".",
"length",
"==",
"1",
"&&",
"!",
"(",
"range",
"=",
"ranges",
"[",
"0",
"]",
")",
".",
"collapsed",
"&&",
"(",
"enclosedNode",
"=",
"range",
".",
"getEnclosedNode",
"(",
")",
")",
"&&",
"enclosedNode",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
")",
"{",
"// So far we can't say that enclosed element is non-editable. Before checking,",
"// we'll shrink range (clone). Shrinking will stop on non-editable range, or",
"// innermost element (#11114).",
"clone",
"=",
"range",
".",
"clone",
"(",
")",
";",
"clone",
".",
"shrink",
"(",
"CKEDITOR",
".",
"SHRINK_ELEMENT",
",",
"true",
")",
";",
"// If shrinked range still encloses an element, check this one (shrink stops only on non-editable elements).",
"if",
"(",
"(",
"shrinkedNode",
"=",
"clone",
".",
"getEnclosedNode",
"(",
")",
")",
"&&",
"shrinkedNode",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
")",
"enclosedNode",
"=",
"shrinkedNode",
";",
"if",
"(",
"enclosedNode",
".",
"getAttribute",
"(",
"'contenteditable'",
")",
"==",
"'false'",
")",
"return",
"enclosedNode",
";",
"}",
"}"
] | If fake selection should be applied this function will return instance of CKEDITOR.dom.element which should gain fake selection. | [
"If",
"fake",
"selection",
"should",
"be",
"applied",
"this",
"function",
"will",
"return",
"instance",
"of",
"CKEDITOR",
".",
"dom",
".",
"element",
"which",
"should",
"gain",
"fake",
"selection",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L387-L405 |
56,988 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | onHover | function onHover( evt ) {
evt = evt.data.$;
if ( textRng ) {
// Read the current cursor.
var rngEnd = body.$.createTextRange();
moveRangeToPoint( rngEnd, evt.clientX, evt.clientY );
// Handle drag directions.
textRng.setEndPoint(
startRng.compareEndPoints( 'StartToStart', rngEnd ) < 0 ?
'EndToEnd' : 'StartToStart', rngEnd );
// Update selection with new range.
textRng.select();
}
} | javascript | function onHover( evt ) {
evt = evt.data.$;
if ( textRng ) {
// Read the current cursor.
var rngEnd = body.$.createTextRange();
moveRangeToPoint( rngEnd, evt.clientX, evt.clientY );
// Handle drag directions.
textRng.setEndPoint(
startRng.compareEndPoints( 'StartToStart', rngEnd ) < 0 ?
'EndToEnd' : 'StartToStart', rngEnd );
// Update selection with new range.
textRng.select();
}
} | [
"function",
"onHover",
"(",
"evt",
")",
"{",
"evt",
"=",
"evt",
".",
"data",
".",
"$",
";",
"if",
"(",
"textRng",
")",
"{",
"// Read the current cursor.",
"var",
"rngEnd",
"=",
"body",
".",
"$",
".",
"createTextRange",
"(",
")",
";",
"moveRangeToPoint",
"(",
"rngEnd",
",",
"evt",
".",
"clientX",
",",
"evt",
".",
"clientY",
")",
";",
"// Handle drag directions.",
"textRng",
".",
"setEndPoint",
"(",
"startRng",
".",
"compareEndPoints",
"(",
"'StartToStart'",
",",
"rngEnd",
")",
"<",
"0",
"?",
"'EndToEnd'",
":",
"'StartToStart'",
",",
"rngEnd",
")",
";",
"// Update selection with new range.",
"textRng",
".",
"select",
"(",
")",
";",
"}",
"}"
] | Expand the text range along with mouse move. | [
"Expand",
"the",
"text",
"range",
"along",
"with",
"mouse",
"move",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L626-L642 |
56,989 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function() {
if ( this._.cache.nativeSel !== undefined )
return this._.cache.nativeSel;
return ( this._.cache.nativeSel = isMSSelection ? this.document.$.selection : this.document.getWindow().$.getSelection() );
} | javascript | function() {
if ( this._.cache.nativeSel !== undefined )
return this._.cache.nativeSel;
return ( this._.cache.nativeSel = isMSSelection ? this.document.$.selection : this.document.getWindow().$.getSelection() );
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_",
".",
"cache",
".",
"nativeSel",
"!==",
"undefined",
")",
"return",
"this",
".",
"_",
".",
"cache",
".",
"nativeSel",
";",
"return",
"(",
"this",
".",
"_",
".",
"cache",
".",
"nativeSel",
"=",
"isMSSelection",
"?",
"this",
".",
"document",
".",
"$",
".",
"selection",
":",
"this",
".",
"document",
".",
"getWindow",
"(",
")",
".",
"$",
".",
"getSelection",
"(",
")",
")",
";",
"}"
] | Gets the native selection object from the browser.
var selection = editor.getSelection().getNative();
@returns {Object} The native browser selection object. | [
"Gets",
"the",
"native",
"selection",
"object",
"from",
"the",
"browser",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L1210-L1215 |
|
56,990 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function() {
var range = self.getRanges()[ 0 ].clone(),
enclosed, selected;
// Check first any enclosed element, e.g. <ul>[<li><a href="#">item</a></li>]</ul>
for ( var i = 2; i && !( ( enclosed = range.getEnclosedNode() ) && ( enclosed.type == CKEDITOR.NODE_ELEMENT ) && styleObjectElements[ enclosed.getName() ] && ( selected = enclosed ) ); i-- ) {
// Then check any deep wrapped element, e.g. [<b><i><img /></i></b>]
range.shrink( CKEDITOR.SHRINK_ELEMENT );
}
return selected && selected.$;
} | javascript | function() {
var range = self.getRanges()[ 0 ].clone(),
enclosed, selected;
// Check first any enclosed element, e.g. <ul>[<li><a href="#">item</a></li>]</ul>
for ( var i = 2; i && !( ( enclosed = range.getEnclosedNode() ) && ( enclosed.type == CKEDITOR.NODE_ELEMENT ) && styleObjectElements[ enclosed.getName() ] && ( selected = enclosed ) ); i-- ) {
// Then check any deep wrapped element, e.g. [<b><i><img /></i></b>]
range.shrink( CKEDITOR.SHRINK_ELEMENT );
}
return selected && selected.$;
} | [
"function",
"(",
")",
"{",
"var",
"range",
"=",
"self",
".",
"getRanges",
"(",
")",
"[",
"0",
"]",
".",
"clone",
"(",
")",
",",
"enclosed",
",",
"selected",
";",
"// Check first any enclosed element, e.g. <ul>[<li><a href=\"#\">item</a></li>]</ul>",
"for",
"(",
"var",
"i",
"=",
"2",
";",
"i",
"&&",
"!",
"(",
"(",
"enclosed",
"=",
"range",
".",
"getEnclosedNode",
"(",
")",
")",
"&&",
"(",
"enclosed",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
")",
"&&",
"styleObjectElements",
"[",
"enclosed",
".",
"getName",
"(",
")",
"]",
"&&",
"(",
"selected",
"=",
"enclosed",
")",
")",
";",
"i",
"--",
")",
"{",
"// Then check any deep wrapped element, e.g. [<b><i><img /></i></b>]",
"range",
".",
"shrink",
"(",
"CKEDITOR",
".",
"SHRINK_ELEMENT",
")",
";",
"}",
"return",
"selected",
"&&",
"selected",
".",
"$",
";",
"}"
] | Figure it out by checking if there's a single enclosed node of the range. | [
"Figure",
"it",
"out",
"by",
"checking",
"if",
"there",
"s",
"a",
"single",
"enclosed",
"node",
"of",
"the",
"range",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L1603-L1614 |
|
56,991 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function() {
this._.cache = {};
this.isFake = 0;
var editor = this.root.editor;
// Invalidate any fake selection available in the editor.
if ( editor && editor._.fakeSelection ) {
// Test whether this selection is the one that was
// faked or its clone.
if ( this.rev == editor._.fakeSelection.rev ) {
delete editor._.fakeSelection;
removeHiddenSelectionContainer( editor );
}
// jshint ignore:start
// TODO after #9786 use commented out lines instead of console.log.
else { // %REMOVE_LINE%
window.console && console.log( 'Wrong selection instance resets fake selection.' ); // %REMOVE_LINE%
} // %REMOVE_LINE%
// else // %REMOVE_LINE%
// CKEDITOR.debug.error( 'Wrong selection instance resets fake selection.', CKEDITOR.DEBUG_CRITICAL ); // %REMOVE_LINE%
// jshint ignore:end
}
this.rev = nextRev++;
} | javascript | function() {
this._.cache = {};
this.isFake = 0;
var editor = this.root.editor;
// Invalidate any fake selection available in the editor.
if ( editor && editor._.fakeSelection ) {
// Test whether this selection is the one that was
// faked or its clone.
if ( this.rev == editor._.fakeSelection.rev ) {
delete editor._.fakeSelection;
removeHiddenSelectionContainer( editor );
}
// jshint ignore:start
// TODO after #9786 use commented out lines instead of console.log.
else { // %REMOVE_LINE%
window.console && console.log( 'Wrong selection instance resets fake selection.' ); // %REMOVE_LINE%
} // %REMOVE_LINE%
// else // %REMOVE_LINE%
// CKEDITOR.debug.error( 'Wrong selection instance resets fake selection.', CKEDITOR.DEBUG_CRITICAL ); // %REMOVE_LINE%
// jshint ignore:end
}
this.rev = nextRev++;
} | [
"function",
"(",
")",
"{",
"this",
".",
"_",
".",
"cache",
"=",
"{",
"}",
";",
"this",
".",
"isFake",
"=",
"0",
";",
"var",
"editor",
"=",
"this",
".",
"root",
".",
"editor",
";",
"// Invalidate any fake selection available in the editor.",
"if",
"(",
"editor",
"&&",
"editor",
".",
"_",
".",
"fakeSelection",
")",
"{",
"// Test whether this selection is the one that was",
"// faked or its clone.",
"if",
"(",
"this",
".",
"rev",
"==",
"editor",
".",
"_",
".",
"fakeSelection",
".",
"rev",
")",
"{",
"delete",
"editor",
".",
"_",
".",
"fakeSelection",
";",
"removeHiddenSelectionContainer",
"(",
"editor",
")",
";",
"}",
"// jshint ignore:start",
"// TODO after #9786 use commented out lines instead of console.log.",
"else",
"{",
"// %REMOVE_LINE%",
"window",
".",
"console",
"&&",
"console",
".",
"log",
"(",
"'Wrong selection instance resets fake selection.'",
")",
";",
"// %REMOVE_LINE%",
"}",
"// %REMOVE_LINE%",
"// else // %REMOVE_LINE%",
"//\tCKEDITOR.debug.error( 'Wrong selection instance resets fake selection.', CKEDITOR.DEBUG_CRITICAL ); // %REMOVE_LINE%",
"// jshint ignore:end",
"}",
"this",
".",
"rev",
"=",
"nextRev",
"++",
";",
"}"
] | Clears the selection cache.
editor.getSelection().reset(); | [
"Clears",
"the",
"selection",
"cache",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L1697-L1723 |
|
56,992 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function( element ) {
var editor = this.root.editor;
// Cleanup after previous selection - e.g. remove hidden sel container.
this.reset();
hideSelection( editor );
// Set this value after executing hiseSelection, because it may
// cause reset() which overwrites cache.
var cache = this._.cache;
// Caches a range than holds the element.
var range = new CKEDITOR.dom.range( this.root );
range.setStartBefore( element );
range.setEndAfter( element );
cache.ranges = new CKEDITOR.dom.rangeList( range );
// Put this element in the cache.
cache.selectedElement = cache.startElement = element;
cache.type = CKEDITOR.SELECTION_ELEMENT;
// Properties that will not be available when isFake.
cache.selectedText = cache.nativeSel = null;
this.isFake = 1;
this.rev = nextRev++;
// Save this selection, so it can be returned by editor.getSelection().
editor._.fakeSelection = this;
// Fire selectionchange, just like a normal selection.
this.root.fire( 'selectionchange' );
} | javascript | function( element ) {
var editor = this.root.editor;
// Cleanup after previous selection - e.g. remove hidden sel container.
this.reset();
hideSelection( editor );
// Set this value after executing hiseSelection, because it may
// cause reset() which overwrites cache.
var cache = this._.cache;
// Caches a range than holds the element.
var range = new CKEDITOR.dom.range( this.root );
range.setStartBefore( element );
range.setEndAfter( element );
cache.ranges = new CKEDITOR.dom.rangeList( range );
// Put this element in the cache.
cache.selectedElement = cache.startElement = element;
cache.type = CKEDITOR.SELECTION_ELEMENT;
// Properties that will not be available when isFake.
cache.selectedText = cache.nativeSel = null;
this.isFake = 1;
this.rev = nextRev++;
// Save this selection, so it can be returned by editor.getSelection().
editor._.fakeSelection = this;
// Fire selectionchange, just like a normal selection.
this.root.fire( 'selectionchange' );
} | [
"function",
"(",
"element",
")",
"{",
"var",
"editor",
"=",
"this",
".",
"root",
".",
"editor",
";",
"// Cleanup after previous selection - e.g. remove hidden sel container.",
"this",
".",
"reset",
"(",
")",
";",
"hideSelection",
"(",
"editor",
")",
";",
"// Set this value after executing hiseSelection, because it may",
"// cause reset() which overwrites cache.",
"var",
"cache",
"=",
"this",
".",
"_",
".",
"cache",
";",
"// Caches a range than holds the element.",
"var",
"range",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"range",
"(",
"this",
".",
"root",
")",
";",
"range",
".",
"setStartBefore",
"(",
"element",
")",
";",
"range",
".",
"setEndAfter",
"(",
"element",
")",
";",
"cache",
".",
"ranges",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"rangeList",
"(",
"range",
")",
";",
"// Put this element in the cache.",
"cache",
".",
"selectedElement",
"=",
"cache",
".",
"startElement",
"=",
"element",
";",
"cache",
".",
"type",
"=",
"CKEDITOR",
".",
"SELECTION_ELEMENT",
";",
"// Properties that will not be available when isFake.",
"cache",
".",
"selectedText",
"=",
"cache",
".",
"nativeSel",
"=",
"null",
";",
"this",
".",
"isFake",
"=",
"1",
";",
"this",
".",
"rev",
"=",
"nextRev",
"++",
";",
"// Save this selection, so it can be returned by editor.getSelection().",
"editor",
".",
"_",
".",
"fakeSelection",
"=",
"this",
";",
"// Fire selectionchange, just like a normal selection.",
"this",
".",
"root",
".",
"fire",
"(",
"'selectionchange'",
")",
";",
"}"
] | Makes a "fake selection" of an element.
A fake selection does not render UI artifacts over the selected
element. Additionally, the browser native selection system is not
aware of the fake selection. In practice, the native selection is
moved to a hidden place where no native selection UI artifacts are
displayed to the user.
@param {CKEDITOR.dom.element} element The element to be "selected". | [
"Makes",
"a",
"fake",
"selection",
"of",
"an",
"element",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L2001-L2034 |
|
56,993 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function() {
var el = this.getCommonAncestor();
if ( el && el.type == CKEDITOR.NODE_TEXT )
el = el.getParent();
return !!( el && el.data( 'cke-hidden-sel' ) );
} | javascript | function() {
var el = this.getCommonAncestor();
if ( el && el.type == CKEDITOR.NODE_TEXT )
el = el.getParent();
return !!( el && el.data( 'cke-hidden-sel' ) );
} | [
"function",
"(",
")",
"{",
"var",
"el",
"=",
"this",
".",
"getCommonAncestor",
"(",
")",
";",
"if",
"(",
"el",
"&&",
"el",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_TEXT",
")",
"el",
"=",
"el",
".",
"getParent",
"(",
")",
";",
"return",
"!",
"!",
"(",
"el",
"&&",
"el",
".",
"data",
"(",
"'cke-hidden-sel'",
")",
")",
";",
"}"
] | Checks whether selection is placed in hidden element.
This method is to be used to verify whether fake selection
(see {@link #fake}) is still hidden.
**Note:** this method should be executed on real selection - e.g.:
editor.getSelection( true ).isHidden();
@returns {Boolean} | [
"Checks",
"whether",
"selection",
"is",
"placed",
"in",
"hidden",
"element",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L2048-L2055 |
|
56,994 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/core/selection.js | function() {
// Don't clear selection outside this selection's root (#11500).
if ( this.getType() == CKEDITOR.SELECTION_NONE )
return;
var nativ = this.getNative();
try {
nativ && nativ[ isMSSelection ? 'empty' : 'removeAllRanges' ]();
} catch ( er ) {}
this.reset();
} | javascript | function() {
// Don't clear selection outside this selection's root (#11500).
if ( this.getType() == CKEDITOR.SELECTION_NONE )
return;
var nativ = this.getNative();
try {
nativ && nativ[ isMSSelection ? 'empty' : 'removeAllRanges' ]();
} catch ( er ) {}
this.reset();
} | [
"function",
"(",
")",
"{",
"// Don't clear selection outside this selection's root (#11500).",
"if",
"(",
"this",
".",
"getType",
"(",
")",
"==",
"CKEDITOR",
".",
"SELECTION_NONE",
")",
"return",
";",
"var",
"nativ",
"=",
"this",
".",
"getNative",
"(",
")",
";",
"try",
"{",
"nativ",
"&&",
"nativ",
"[",
"isMSSelection",
"?",
"'empty'",
":",
"'removeAllRanges'",
"]",
"(",
")",
";",
"}",
"catch",
"(",
"er",
")",
"{",
"}",
"this",
".",
"reset",
"(",
")",
";",
"}"
] | Remove all the selection ranges from the document. | [
"Remove",
"all",
"the",
"selection",
"ranges",
"from",
"the",
"document",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/core/selection.js#L2145-L2157 |
|
56,995 | openplacedatabase/opd-js-sdk | src/sdk.js | _multiCallback | function _multiCallback(serverError, serverResponse, callback, interleave, requestedIds){
var clientResponse = {};
// Handle response errors
_.each(serverResponse, function(data, id){
var thisError = serverError;
if(serverError && data.status.code !== 200){
thisError = new Error(data.status.msgs.join('. '));
thisError.code = data.status.code;
}
clientResponse[id] = {
error: thisError,
data: data.data
};
});
// Handle request level errors
if(serverError && !serverResponse){
_.each(requestedIds, function(id){
if(_.isUndefined(clientResponse[id])){
clientResponse[id] = {
error: serverError,
data: null
};
}
});
}
// Interleave validation errors
if(interleave){
_.extend(clientResponse, interleave);
}
callback(clientResponse);
} | javascript | function _multiCallback(serverError, serverResponse, callback, interleave, requestedIds){
var clientResponse = {};
// Handle response errors
_.each(serverResponse, function(data, id){
var thisError = serverError;
if(serverError && data.status.code !== 200){
thisError = new Error(data.status.msgs.join('. '));
thisError.code = data.status.code;
}
clientResponse[id] = {
error: thisError,
data: data.data
};
});
// Handle request level errors
if(serverError && !serverResponse){
_.each(requestedIds, function(id){
if(_.isUndefined(clientResponse[id])){
clientResponse[id] = {
error: serverError,
data: null
};
}
});
}
// Interleave validation errors
if(interleave){
_.extend(clientResponse, interleave);
}
callback(clientResponse);
} | [
"function",
"_multiCallback",
"(",
"serverError",
",",
"serverResponse",
",",
"callback",
",",
"interleave",
",",
"requestedIds",
")",
"{",
"var",
"clientResponse",
"=",
"{",
"}",
";",
"// Handle response errors",
"_",
".",
"each",
"(",
"serverResponse",
",",
"function",
"(",
"data",
",",
"id",
")",
"{",
"var",
"thisError",
"=",
"serverError",
";",
"if",
"(",
"serverError",
"&&",
"data",
".",
"status",
".",
"code",
"!==",
"200",
")",
"{",
"thisError",
"=",
"new",
"Error",
"(",
"data",
".",
"status",
".",
"msgs",
".",
"join",
"(",
"'. '",
")",
")",
";",
"thisError",
".",
"code",
"=",
"data",
".",
"status",
".",
"code",
";",
"}",
"clientResponse",
"[",
"id",
"]",
"=",
"{",
"error",
":",
"thisError",
",",
"data",
":",
"data",
".",
"data",
"}",
";",
"}",
")",
";",
"// Handle request level errors",
"if",
"(",
"serverError",
"&&",
"!",
"serverResponse",
")",
"{",
"_",
".",
"each",
"(",
"requestedIds",
",",
"function",
"(",
"id",
")",
"{",
"if",
"(",
"_",
".",
"isUndefined",
"(",
"clientResponse",
"[",
"id",
"]",
")",
")",
"{",
"clientResponse",
"[",
"id",
"]",
"=",
"{",
"error",
":",
"serverError",
",",
"data",
":",
"null",
"}",
";",
"}",
"}",
")",
";",
"}",
"// Interleave validation errors",
"if",
"(",
"interleave",
")",
"{",
"_",
".",
"extend",
"(",
"clientResponse",
",",
"interleave",
")",
";",
"}",
"callback",
"(",
"clientResponse",
")",
";",
"}"
] | Callback used by Multi methods that
generates the proper response format | [
"Callback",
"used",
"by",
"Multi",
"methods",
"that",
"generates",
"the",
"proper",
"response",
"format"
] | e64eb079cc76af5a5acff27a7614ffb70f0b7e33 | https://github.com/openplacedatabase/opd-js-sdk/blob/e64eb079cc76af5a5acff27a7614ffb70f0b7e33/src/sdk.js#L195-L229 |
56,996 | dashed/providence | src/index.js | Providence | function Providence(options = NOT_SET, skipDataCheck = false, skipProcessOptions = false) {
if(options === NOT_SET) {
throw new Error('Expected options to be a plain object or an Immutable Map');
}
// This will not support constructors that are extending Providence.
// They should provide their own setup in their constructor function.
if(!(this instanceof Providence)) {
return new Providence(options, skipDataCheck, skipProcessOptions);
}
this._options = skipProcessOptions ? options : processOptions(options);
// Used for caching value of the Providence object.
// When the unboxed root data and this._refUnboxedRootData are equal,
// then unboxed root data hasn't changed since the previous look up, and thus
// this._cachedValue and value at path also hasn't changed.
this._refUnboxedRootData = NOT_SET;
this._cachedValue = NOT_SET;
if(!skipDataCheck && this._options.getIn(DATA_PATH, NOT_SET) === NOT_SET) {
throw new Error("value at path ['root', 'data'] is required!")
}
} | javascript | function Providence(options = NOT_SET, skipDataCheck = false, skipProcessOptions = false) {
if(options === NOT_SET) {
throw new Error('Expected options to be a plain object or an Immutable Map');
}
// This will not support constructors that are extending Providence.
// They should provide their own setup in their constructor function.
if(!(this instanceof Providence)) {
return new Providence(options, skipDataCheck, skipProcessOptions);
}
this._options = skipProcessOptions ? options : processOptions(options);
// Used for caching value of the Providence object.
// When the unboxed root data and this._refUnboxedRootData are equal,
// then unboxed root data hasn't changed since the previous look up, and thus
// this._cachedValue and value at path also hasn't changed.
this._refUnboxedRootData = NOT_SET;
this._cachedValue = NOT_SET;
if(!skipDataCheck && this._options.getIn(DATA_PATH, NOT_SET) === NOT_SET) {
throw new Error("value at path ['root', 'data'] is required!")
}
} | [
"function",
"Providence",
"(",
"options",
"=",
"NOT_SET",
",",
"skipDataCheck",
"=",
"false",
",",
"skipProcessOptions",
"=",
"false",
")",
"{",
"if",
"(",
"options",
"===",
"NOT_SET",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Expected options to be a plain object or an Immutable Map'",
")",
";",
"}",
"// This will not support constructors that are extending Providence.",
"// They should provide their own setup in their constructor function.",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Providence",
")",
")",
"{",
"return",
"new",
"Providence",
"(",
"options",
",",
"skipDataCheck",
",",
"skipProcessOptions",
")",
";",
"}",
"this",
".",
"_options",
"=",
"skipProcessOptions",
"?",
"options",
":",
"processOptions",
"(",
"options",
")",
";",
"// Used for caching value of the Providence object.",
"// When the unboxed root data and this._refUnboxedRootData are equal,",
"// then unboxed root data hasn't changed since the previous look up, and thus",
"// this._cachedValue and value at path also hasn't changed.",
"this",
".",
"_refUnboxedRootData",
"=",
"NOT_SET",
";",
"this",
".",
"_cachedValue",
"=",
"NOT_SET",
";",
"if",
"(",
"!",
"skipDataCheck",
"&&",
"this",
".",
"_options",
".",
"getIn",
"(",
"DATA_PATH",
",",
"NOT_SET",
")",
"===",
"NOT_SET",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"value at path ['root', 'data'] is required!\"",
")",
"}",
"}"
] | Create a Providence cursor given options.
Options may either be plain object or an Immutable Map.
@param {Object | Immutable Map} options Defines the character of the providence cursor. | [
"Create",
"a",
"Providence",
"cursor",
"given",
"options",
".",
"Options",
"may",
"either",
"be",
"plain",
"object",
"or",
"an",
"Immutable",
"Map",
"."
] | 8e0e5631e092b11f1fd8500c634523a231aec00f | https://github.com/dashed/providence/blob/8e0e5631e092b11f1fd8500c634523a231aec00f/src/index.js#L66-L90 |
56,997 | kaelzhang/node-cobj | index.js | _set | function _set (data, keys, value) {
var i = 0;
var prop;
var length = keys.length;
for(; i < length; i ++){
prop = keys[i];
if (i === length - 1) {
// if the last key, set value
data[prop] = value;
return;
}
if (
!(prop in data)
// If the current value is not an object, we will override it.
// The logic who invoke `.set()` method should make sure `data[prop]` is an object,
// which `.set()` doesn't concern
|| !is_object(data[prop])
) {
data[prop] = {};
}
data = data[prop];
}
} | javascript | function _set (data, keys, value) {
var i = 0;
var prop;
var length = keys.length;
for(; i < length; i ++){
prop = keys[i];
if (i === length - 1) {
// if the last key, set value
data[prop] = value;
return;
}
if (
!(prop in data)
// If the current value is not an object, we will override it.
// The logic who invoke `.set()` method should make sure `data[prop]` is an object,
// which `.set()` doesn't concern
|| !is_object(data[prop])
) {
data[prop] = {};
}
data = data[prop];
}
} | [
"function",
"_set",
"(",
"data",
",",
"keys",
",",
"value",
")",
"{",
"var",
"i",
"=",
"0",
";",
"var",
"prop",
";",
"var",
"length",
"=",
"keys",
".",
"length",
";",
"for",
"(",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"prop",
"=",
"keys",
"[",
"i",
"]",
";",
"if",
"(",
"i",
"===",
"length",
"-",
"1",
")",
"{",
"// if the last key, set value",
"data",
"[",
"prop",
"]",
"=",
"value",
";",
"return",
";",
"}",
"if",
"(",
"!",
"(",
"prop",
"in",
"data",
")",
"// If the current value is not an object, we will override it.",
"// The logic who invoke `.set()` method should make sure `data[prop]` is an object,",
"// which `.set()` doesn't concern",
"||",
"!",
"is_object",
"(",
"data",
"[",
"prop",
"]",
")",
")",
"{",
"data",
"[",
"prop",
"]",
"=",
"{",
"}",
";",
"}",
"data",
"=",
"data",
"[",
"prop",
"]",
";",
"}",
"}"
] | For better testing | [
"For",
"better",
"testing"
] | ced3c8031f3a6f69ae151bceba3ccb85dcab2f9e | https://github.com/kaelzhang/node-cobj/blob/ced3c8031f3a6f69ae151bceba3ccb85dcab2f9e/index.js#L69-L94 |
56,998 | mcrowe/channel | lib/util.js | pull | function pull(xs, x) {
const idx = xs.indexOf(x);
if (idx > -1) {
xs.splice(idx, 1);
}
} | javascript | function pull(xs, x) {
const idx = xs.indexOf(x);
if (idx > -1) {
xs.splice(idx, 1);
}
} | [
"function",
"pull",
"(",
"xs",
",",
"x",
")",
"{",
"const",
"idx",
"=",
"xs",
".",
"indexOf",
"(",
"x",
")",
";",
"if",
"(",
"idx",
">",
"-",
"1",
")",
"{",
"xs",
".",
"splice",
"(",
"idx",
",",
"1",
")",
";",
"}",
"}"
] | Remove an item from a list, in place. | [
"Remove",
"an",
"item",
"from",
"a",
"list",
"in",
"place",
"."
] | b1cf88f8b614d902b91923329fdac5cae8458b2d | https://github.com/mcrowe/channel/blob/b1cf88f8b614d902b91923329fdac5cae8458b2d/lib/util.js#L6-L11 |
56,999 | cliffano/pkjutil | lib/cli.js | exec | function exec() {
var actions = {
commands: {
'list-dependencies': { action: _listDependencies },
'list-devdependencies': { action: _listDevDependencies },
'list-peerdependencies': { action: _listPeerDependencies },
'list-optdependencies': { action: _listOptDependencies },
'list-alldependencies': { action: _listAllDependencies },
'set-node-engine': { action: _setNodeEngine },
'sort-dependencies': { action: _sortDependencies },
'sort-devdependencies': { action: _sortDevDependencies },
'sort-peerdependencies': { action: _sortPeerDependencies },
'sort-optdependencies': { action: _sortOptDependencies },
'sort-alldependencies': { action: _sortAllDependencies },
'traverse-dependencies': { action: _traverseDependencies },
'upgrade-version-patch': { action: _upgradeVersionPatch },
'upgrade-version-minor': { action: _upgradeVersionMinor },
'upgrade-version-major': { action: _upgradeVersionMajor },
'upgrade-version': { action: _upgradeVersionPatch },
'upgrade-dependencies': { action: _upgradeDependencies },
}
};
cli.command(__dirname, actions);
} | javascript | function exec() {
var actions = {
commands: {
'list-dependencies': { action: _listDependencies },
'list-devdependencies': { action: _listDevDependencies },
'list-peerdependencies': { action: _listPeerDependencies },
'list-optdependencies': { action: _listOptDependencies },
'list-alldependencies': { action: _listAllDependencies },
'set-node-engine': { action: _setNodeEngine },
'sort-dependencies': { action: _sortDependencies },
'sort-devdependencies': { action: _sortDevDependencies },
'sort-peerdependencies': { action: _sortPeerDependencies },
'sort-optdependencies': { action: _sortOptDependencies },
'sort-alldependencies': { action: _sortAllDependencies },
'traverse-dependencies': { action: _traverseDependencies },
'upgrade-version-patch': { action: _upgradeVersionPatch },
'upgrade-version-minor': { action: _upgradeVersionMinor },
'upgrade-version-major': { action: _upgradeVersionMajor },
'upgrade-version': { action: _upgradeVersionPatch },
'upgrade-dependencies': { action: _upgradeDependencies },
}
};
cli.command(__dirname, actions);
} | [
"function",
"exec",
"(",
")",
"{",
"var",
"actions",
"=",
"{",
"commands",
":",
"{",
"'list-dependencies'",
":",
"{",
"action",
":",
"_listDependencies",
"}",
",",
"'list-devdependencies'",
":",
"{",
"action",
":",
"_listDevDependencies",
"}",
",",
"'list-peerdependencies'",
":",
"{",
"action",
":",
"_listPeerDependencies",
"}",
",",
"'list-optdependencies'",
":",
"{",
"action",
":",
"_listOptDependencies",
"}",
",",
"'list-alldependencies'",
":",
"{",
"action",
":",
"_listAllDependencies",
"}",
",",
"'set-node-engine'",
":",
"{",
"action",
":",
"_setNodeEngine",
"}",
",",
"'sort-dependencies'",
":",
"{",
"action",
":",
"_sortDependencies",
"}",
",",
"'sort-devdependencies'",
":",
"{",
"action",
":",
"_sortDevDependencies",
"}",
",",
"'sort-peerdependencies'",
":",
"{",
"action",
":",
"_sortPeerDependencies",
"}",
",",
"'sort-optdependencies'",
":",
"{",
"action",
":",
"_sortOptDependencies",
"}",
",",
"'sort-alldependencies'",
":",
"{",
"action",
":",
"_sortAllDependencies",
"}",
",",
"'traverse-dependencies'",
":",
"{",
"action",
":",
"_traverseDependencies",
"}",
",",
"'upgrade-version-patch'",
":",
"{",
"action",
":",
"_upgradeVersionPatch",
"}",
",",
"'upgrade-version-minor'",
":",
"{",
"action",
":",
"_upgradeVersionMinor",
"}",
",",
"'upgrade-version-major'",
":",
"{",
"action",
":",
"_upgradeVersionMajor",
"}",
",",
"'upgrade-version'",
":",
"{",
"action",
":",
"_upgradeVersionPatch",
"}",
",",
"'upgrade-dependencies'",
":",
"{",
"action",
":",
"_upgradeDependencies",
"}",
",",
"}",
"}",
";",
"cli",
".",
"command",
"(",
"__dirname",
",",
"actions",
")",
";",
"}"
] | Execute PkjUtil CLI. | [
"Execute",
"PkjUtil",
"CLI",
"."
] | 8c6d69bf375619da0ee0a1a031312a3f20d53fcf | https://github.com/cliffano/pkjutil/blob/8c6d69bf375619da0ee0a1a031312a3f20d53fcf/lib/cli.js#L111-L136 |
Subsets and Splits