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,300 | ruifortes/json-deref | src/index.js | processNode | function processNode({rawNode, parsedNode, parentId = resourceId, cursor, refChain, prop}) {
logger.info(`processNode ${cursor}${prop ? '(' + prop + ')' : ''} with refChain ${refChain}`)
const currentId = options.urlBaseKey && rawNode[options.urlBaseKey]
? parseRef(rawNode[options.urlBaseKey], parentId).fullUrl
: parentId
const props = !!prop ? [prop] : Object.getOwnPropertyNames(rawNode)
let propIndex = -1, nodeChanged = 0
return new Promise((accept, reject) => {
nextProp()
function nextProp() {
propIndex++
if(propIndex >= props.length) {
if (!!prop) {
accept(parsedNode[prop])
} else {
accept(nodeChanged ? parsedNode : rawNode)
}
} else {
const prop = props[propIndex]
const sourceValue = rawNode[prop]
const propCursor = `${cursor}/${prop}`
// If prop is already defined in parsedNode assume complete and skip it
if(parsedNode.hasOwnProperty(prop)){
nodeChanged |= parsedNode[prop] !== sourceValue
nextProp()
}
// Is scalar, just set same and continue
else if (typeof sourceValue !== 'object' || sourceValue === null) {
parsedNode[prop] = sourceValue
nextProp()
}
// prop is a reference
else if(!!sourceValue.$ref) {
const {$ref, ...params} = sourceValue
const branchRefChain = [...refChain, propCursor]
const {url, pointer, isLocalRef, isCircular} = parseRef($ref, currentId, branchRefChain) //, options.vars)
if(!url) throw new Error(`Invalid $ref ${$ref}`)
if(isCircular && options.skipCircular || isLocalRef && externalOnly) {
// if(isLocalRef && externalOnly) {
parsedNode[prop] = sourceValue
nextProp()
} else {
Promise.resolve(isLocalRef
? solvePointer(pointer, branchRefChain, currentId)
: externalOnly && pointer
? processResource(url, pointer, branchRefChain, false)
: processResource(url, pointer, branchRefChain)
)
.then(newValue => {
nodeChanged = 1
parsedNode[prop] = newValue
nextProp()
})
.catch(err => {
const log = `Error derefing ${cursor}/${prop}`
if (options.failOnMissing) {
reject(log)
} else {
logger.info(log)
parsedNode[prop] = sourceValue
nextProp()
}
})
}
} else {
const placeholder = parsedNode[prop] = Array.isArray(sourceValue) ? [] : {}
processNode({
rawNode: sourceValue,
parsedNode: placeholder,
parentId: currentId,
cursor: propCursor,
refChain
})
.then(newValue => {
nodeChanged |= newValue !== sourceValue
nextProp()
})
.catch(reject)
}
}
}
})
} | javascript | function processNode({rawNode, parsedNode, parentId = resourceId, cursor, refChain, prop}) {
logger.info(`processNode ${cursor}${prop ? '(' + prop + ')' : ''} with refChain ${refChain}`)
const currentId = options.urlBaseKey && rawNode[options.urlBaseKey]
? parseRef(rawNode[options.urlBaseKey], parentId).fullUrl
: parentId
const props = !!prop ? [prop] : Object.getOwnPropertyNames(rawNode)
let propIndex = -1, nodeChanged = 0
return new Promise((accept, reject) => {
nextProp()
function nextProp() {
propIndex++
if(propIndex >= props.length) {
if (!!prop) {
accept(parsedNode[prop])
} else {
accept(nodeChanged ? parsedNode : rawNode)
}
} else {
const prop = props[propIndex]
const sourceValue = rawNode[prop]
const propCursor = `${cursor}/${prop}`
// If prop is already defined in parsedNode assume complete and skip it
if(parsedNode.hasOwnProperty(prop)){
nodeChanged |= parsedNode[prop] !== sourceValue
nextProp()
}
// Is scalar, just set same and continue
else if (typeof sourceValue !== 'object' || sourceValue === null) {
parsedNode[prop] = sourceValue
nextProp()
}
// prop is a reference
else if(!!sourceValue.$ref) {
const {$ref, ...params} = sourceValue
const branchRefChain = [...refChain, propCursor]
const {url, pointer, isLocalRef, isCircular} = parseRef($ref, currentId, branchRefChain) //, options.vars)
if(!url) throw new Error(`Invalid $ref ${$ref}`)
if(isCircular && options.skipCircular || isLocalRef && externalOnly) {
// if(isLocalRef && externalOnly) {
parsedNode[prop] = sourceValue
nextProp()
} else {
Promise.resolve(isLocalRef
? solvePointer(pointer, branchRefChain, currentId)
: externalOnly && pointer
? processResource(url, pointer, branchRefChain, false)
: processResource(url, pointer, branchRefChain)
)
.then(newValue => {
nodeChanged = 1
parsedNode[prop] = newValue
nextProp()
})
.catch(err => {
const log = `Error derefing ${cursor}/${prop}`
if (options.failOnMissing) {
reject(log)
} else {
logger.info(log)
parsedNode[prop] = sourceValue
nextProp()
}
})
}
} else {
const placeholder = parsedNode[prop] = Array.isArray(sourceValue) ? [] : {}
processNode({
rawNode: sourceValue,
parsedNode: placeholder,
parentId: currentId,
cursor: propCursor,
refChain
})
.then(newValue => {
nodeChanged |= newValue !== sourceValue
nextProp()
})
.catch(reject)
}
}
}
})
} | [
"function",
"processNode",
"(",
"{",
"rawNode",
",",
"parsedNode",
",",
"parentId",
"=",
"resourceId",
",",
"cursor",
",",
"refChain",
",",
"prop",
"}",
")",
"{",
"logger",
".",
"info",
"(",
"`",
"${",
"cursor",
"}",
"${",
"prop",
"?",
"'('",
"+",
"prop",
"+",
"')'",
":",
"''",
"}",
"${",
"refChain",
"}",
"`",
")",
"const",
"currentId",
"=",
"options",
".",
"urlBaseKey",
"&&",
"rawNode",
"[",
"options",
".",
"urlBaseKey",
"]",
"?",
"parseRef",
"(",
"rawNode",
"[",
"options",
".",
"urlBaseKey",
"]",
",",
"parentId",
")",
".",
"fullUrl",
":",
"parentId",
"const",
"props",
"=",
"!",
"!",
"prop",
"?",
"[",
"prop",
"]",
":",
"Object",
".",
"getOwnPropertyNames",
"(",
"rawNode",
")",
"let",
"propIndex",
"=",
"-",
"1",
",",
"nodeChanged",
"=",
"0",
"return",
"new",
"Promise",
"(",
"(",
"accept",
",",
"reject",
")",
"=>",
"{",
"nextProp",
"(",
")",
"function",
"nextProp",
"(",
")",
"{",
"propIndex",
"++",
"if",
"(",
"propIndex",
">=",
"props",
".",
"length",
")",
"{",
"if",
"(",
"!",
"!",
"prop",
")",
"{",
"accept",
"(",
"parsedNode",
"[",
"prop",
"]",
")",
"}",
"else",
"{",
"accept",
"(",
"nodeChanged",
"?",
"parsedNode",
":",
"rawNode",
")",
"}",
"}",
"else",
"{",
"const",
"prop",
"=",
"props",
"[",
"propIndex",
"]",
"const",
"sourceValue",
"=",
"rawNode",
"[",
"prop",
"]",
"const",
"propCursor",
"=",
"`",
"${",
"cursor",
"}",
"${",
"prop",
"}",
"`",
"// If prop is already defined in parsedNode assume complete and skip it",
"if",
"(",
"parsedNode",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"nodeChanged",
"|=",
"parsedNode",
"[",
"prop",
"]",
"!==",
"sourceValue",
"nextProp",
"(",
")",
"}",
"// Is scalar, just set same and continue",
"else",
"if",
"(",
"typeof",
"sourceValue",
"!==",
"'object'",
"||",
"sourceValue",
"===",
"null",
")",
"{",
"parsedNode",
"[",
"prop",
"]",
"=",
"sourceValue",
"nextProp",
"(",
")",
"}",
"// prop is a reference",
"else",
"if",
"(",
"!",
"!",
"sourceValue",
".",
"$ref",
")",
"{",
"const",
"{",
"$ref",
",",
"...",
"params",
"}",
"=",
"sourceValue",
"const",
"branchRefChain",
"=",
"[",
"...",
"refChain",
",",
"propCursor",
"]",
"const",
"{",
"url",
",",
"pointer",
",",
"isLocalRef",
",",
"isCircular",
"}",
"=",
"parseRef",
"(",
"$ref",
",",
"currentId",
",",
"branchRefChain",
")",
"//, options.vars)",
"if",
"(",
"!",
"url",
")",
"throw",
"new",
"Error",
"(",
"`",
"${",
"$ref",
"}",
"`",
")",
"if",
"(",
"isCircular",
"&&",
"options",
".",
"skipCircular",
"||",
"isLocalRef",
"&&",
"externalOnly",
")",
"{",
"// if(isLocalRef && externalOnly) {",
"parsedNode",
"[",
"prop",
"]",
"=",
"sourceValue",
"nextProp",
"(",
")",
"}",
"else",
"{",
"Promise",
".",
"resolve",
"(",
"isLocalRef",
"?",
"solvePointer",
"(",
"pointer",
",",
"branchRefChain",
",",
"currentId",
")",
":",
"externalOnly",
"&&",
"pointer",
"?",
"processResource",
"(",
"url",
",",
"pointer",
",",
"branchRefChain",
",",
"false",
")",
":",
"processResource",
"(",
"url",
",",
"pointer",
",",
"branchRefChain",
")",
")",
".",
"then",
"(",
"newValue",
"=>",
"{",
"nodeChanged",
"=",
"1",
"parsedNode",
"[",
"prop",
"]",
"=",
"newValue",
"nextProp",
"(",
")",
"}",
")",
".",
"catch",
"(",
"err",
"=>",
"{",
"const",
"log",
"=",
"`",
"${",
"cursor",
"}",
"${",
"prop",
"}",
"`",
"if",
"(",
"options",
".",
"failOnMissing",
")",
"{",
"reject",
"(",
"log",
")",
"}",
"else",
"{",
"logger",
".",
"info",
"(",
"log",
")",
"parsedNode",
"[",
"prop",
"]",
"=",
"sourceValue",
"nextProp",
"(",
")",
"}",
"}",
")",
"}",
"}",
"else",
"{",
"const",
"placeholder",
"=",
"parsedNode",
"[",
"prop",
"]",
"=",
"Array",
".",
"isArray",
"(",
"sourceValue",
")",
"?",
"[",
"]",
":",
"{",
"}",
"processNode",
"(",
"{",
"rawNode",
":",
"sourceValue",
",",
"parsedNode",
":",
"placeholder",
",",
"parentId",
":",
"currentId",
",",
"cursor",
":",
"propCursor",
",",
"refChain",
"}",
")",
".",
"then",
"(",
"newValue",
"=>",
"{",
"nodeChanged",
"|=",
"newValue",
"!==",
"sourceValue",
"nextProp",
"(",
")",
"}",
")",
".",
"catch",
"(",
"reject",
")",
"}",
"}",
"}",
"}",
")",
"}"
] | Main recursive traverse function
@param {Object} rawNode - The source node to processed
@param {Object} parsedNode - Object to contain the processed properties
@param {string} cursor - Path of the current node. Adds to refChain...do I need this?
@param {string[]} [refChain=[]] - Parent pointers used to check circular references
@param {string} [prop] - If provided returns an object just that prop parsed | [
"Main",
"recursive",
"traverse",
"function"
] | 1d534d68e5067b3de4bc98080f6e989187a684ca | https://github.com/ruifortes/json-deref/blob/1d534d68e5067b3de4bc98080f6e989187a684ca/src/index.js#L129-L224 |
56,301 | camshaft/node-deploy-yml | index.js | getAll | function getAll(name, deploy, fn, single) {
getTree(name, deploy, function(err, tree) {
if (err) return fn(err);
var acc = [];
flatten(tree, acc);
if (acc.length === 0) return fn(null);
if (single && acc.length === 1) return fn(null, acc[0]);
fn(err, acc);
});
} | javascript | function getAll(name, deploy, fn, single) {
getTree(name, deploy, function(err, tree) {
if (err) return fn(err);
var acc = [];
flatten(tree, acc);
if (acc.length === 0) return fn(null);
if (single && acc.length === 1) return fn(null, acc[0]);
fn(err, acc);
});
} | [
"function",
"getAll",
"(",
"name",
",",
"deploy",
",",
"fn",
",",
"single",
")",
"{",
"getTree",
"(",
"name",
",",
"deploy",
",",
"function",
"(",
"err",
",",
"tree",
")",
"{",
"if",
"(",
"err",
")",
"return",
"fn",
"(",
"err",
")",
";",
"var",
"acc",
"=",
"[",
"]",
";",
"flatten",
"(",
"tree",
",",
"acc",
")",
";",
"if",
"(",
"acc",
".",
"length",
"===",
"0",
")",
"return",
"fn",
"(",
"null",
")",
";",
"if",
"(",
"single",
"&&",
"acc",
".",
"length",
"===",
"1",
")",
"return",
"fn",
"(",
"null",
",",
"acc",
"[",
"0",
"]",
")",
";",
"fn",
"(",
"err",
",",
"acc",
")",
";",
"}",
")",
";",
"}"
] | concats have to go all the way down the chain overrides work backwards and stop at first definition | [
"concats",
"have",
"to",
"go",
"all",
"the",
"way",
"down",
"the",
"chain",
"overrides",
"work",
"backwards",
"and",
"stop",
"at",
"first",
"definition"
] | 1c116f406b7e3c399bffec6732ea0fa1a52deb37 | https://github.com/camshaft/node-deploy-yml/blob/1c116f406b7e3c399bffec6732ea0fa1a52deb37/index.js#L131-L140 |
56,302 | georgenorman/tessel-kit | lib/tessel-utils.js | function(portKey) {
var result = this.isValidPort(portKey) ? tessel.port[this.validLEDNames.indexOf(portKey)] : null;
return result;
} | javascript | function(portKey) {
var result = this.isValidPort(portKey) ? tessel.port[this.validLEDNames.indexOf(portKey)] : null;
return result;
} | [
"function",
"(",
"portKey",
")",
"{",
"var",
"result",
"=",
"this",
".",
"isValidPort",
"(",
"portKey",
")",
"?",
"tessel",
".",
"port",
"[",
"this",
".",
"validLEDNames",
".",
"indexOf",
"(",
"portKey",
")",
"]",
":",
"null",
";",
"return",
"result",
";",
"}"
] | Return the Tessel port, if the given portKey is valid; otherwise, return null. | [
"Return",
"the",
"Tessel",
"port",
"if",
"the",
"given",
"portKey",
"is",
"valid",
";",
"otherwise",
"return",
"null",
"."
] | 487e91360f0ecf8500d24297228842e2c01ac762 | https://github.com/georgenorman/tessel-kit/blob/487e91360f0ecf8500d24297228842e2c01ac762/lib/tessel-utils.js#L36-L40 |
|
56,303 | georgenorman/tessel-kit | lib/tessel-utils.js | function(ledName) {
var result = this.isValidLEDName(ledName) ? tessel.port[this.validLEDNames.indexOf(ledName)] : null;
return result;
} | javascript | function(ledName) {
var result = this.isValidLEDName(ledName) ? tessel.port[this.validLEDNames.indexOf(ledName)] : null;
return result;
} | [
"function",
"(",
"ledName",
")",
"{",
"var",
"result",
"=",
"this",
".",
"isValidLEDName",
"(",
"ledName",
")",
"?",
"tessel",
".",
"port",
"[",
"this",
".",
"validLEDNames",
".",
"indexOf",
"(",
"ledName",
")",
"]",
":",
"null",
";",
"return",
"result",
";",
"}"
] | Return the Tessel LED, if the given LED name is valid; otherwise, return null. | [
"Return",
"the",
"Tessel",
"LED",
"if",
"the",
"given",
"LED",
"name",
"is",
"valid",
";",
"otherwise",
"return",
"null",
"."
] | 487e91360f0ecf8500d24297228842e2c01ac762 | https://github.com/georgenorman/tessel-kit/blob/487e91360f0ecf8500d24297228842e2c01ac762/lib/tessel-utils.js#L59-L63 |
|
56,304 | LoveKino/cl-fsm | lib/nfa.js | function(startState) {
let dfa = new DFA();
let stateMap = {};
let epsilonNFASetCache = {}; // NFA-set -> NFA-set
let startOrigin = {
[startState]: 1
};
let start = this.epsilonClosure(startOrigin);
epsilonNFASetCache[hashNFAStates(startOrigin)] = start;
let dfaStates = {},
newAdded = [];
let last = 0,
offset = 0; // distance between last state and current state
dfaStates[hashNFAStates(start)] = 0; // default, the start state for DFA is 0
stateMap[0] = start;
newAdded.push(start);
while (newAdded.length) {
let newAddedTmp = [];
for (let i = 0, n = newAdded.length; i < n; i++) {
let stateSet = newAdded[i];
let newMap = this._getNFASetTransitionMap(stateSet);
let currentDFAState = i + offset;
for (let letter in newMap) {
let toSet = newMap[letter];
let hashKey = hashNFAStates(toSet);
// find new state
let newItem = null;
if (epsilonNFASetCache[hashKey]) {
newItem = epsilonNFASetCache[hashKey];
} else {
newItem = this.epsilonClosure(newMap[letter]);
}
let newItemHashKey = hashNFAStates(newItem);
//
if (dfaStates[newItemHashKey] !== undefined) {
dfa.addTransition(currentDFAState, letter, dfaStates[newItemHashKey]);
} else {
// find new item
last++; // last + 1 as new DFA state
dfaStates[newItemHashKey] = last;
stateMap[last] = newItem;
newAddedTmp.push(newItem);
// build the connection from (index + offset) -> last
dfa.addTransition(currentDFAState, letter, last);
}
}
}
offset += newAdded.length;
newAdded = newAddedTmp;
}
return {
dfa,
stateMap
};
} | javascript | function(startState) {
let dfa = new DFA();
let stateMap = {};
let epsilonNFASetCache = {}; // NFA-set -> NFA-set
let startOrigin = {
[startState]: 1
};
let start = this.epsilonClosure(startOrigin);
epsilonNFASetCache[hashNFAStates(startOrigin)] = start;
let dfaStates = {},
newAdded = [];
let last = 0,
offset = 0; // distance between last state and current state
dfaStates[hashNFAStates(start)] = 0; // default, the start state for DFA is 0
stateMap[0] = start;
newAdded.push(start);
while (newAdded.length) {
let newAddedTmp = [];
for (let i = 0, n = newAdded.length; i < n; i++) {
let stateSet = newAdded[i];
let newMap = this._getNFASetTransitionMap(stateSet);
let currentDFAState = i + offset;
for (let letter in newMap) {
let toSet = newMap[letter];
let hashKey = hashNFAStates(toSet);
// find new state
let newItem = null;
if (epsilonNFASetCache[hashKey]) {
newItem = epsilonNFASetCache[hashKey];
} else {
newItem = this.epsilonClosure(newMap[letter]);
}
let newItemHashKey = hashNFAStates(newItem);
//
if (dfaStates[newItemHashKey] !== undefined) {
dfa.addTransition(currentDFAState, letter, dfaStates[newItemHashKey]);
} else {
// find new item
last++; // last + 1 as new DFA state
dfaStates[newItemHashKey] = last;
stateMap[last] = newItem;
newAddedTmp.push(newItem);
// build the connection from (index + offset) -> last
dfa.addTransition(currentDFAState, letter, last);
}
}
}
offset += newAdded.length;
newAdded = newAddedTmp;
}
return {
dfa,
stateMap
};
} | [
"function",
"(",
"startState",
")",
"{",
"let",
"dfa",
"=",
"new",
"DFA",
"(",
")",
";",
"let",
"stateMap",
"=",
"{",
"}",
";",
"let",
"epsilonNFASetCache",
"=",
"{",
"}",
";",
"// NFA-set -> NFA-set",
"let",
"startOrigin",
"=",
"{",
"[",
"startState",
"]",
":",
"1",
"}",
";",
"let",
"start",
"=",
"this",
".",
"epsilonClosure",
"(",
"startOrigin",
")",
";",
"epsilonNFASetCache",
"[",
"hashNFAStates",
"(",
"startOrigin",
")",
"]",
"=",
"start",
";",
"let",
"dfaStates",
"=",
"{",
"}",
",",
"newAdded",
"=",
"[",
"]",
";",
"let",
"last",
"=",
"0",
",",
"offset",
"=",
"0",
";",
"// distance between last state and current state",
"dfaStates",
"[",
"hashNFAStates",
"(",
"start",
")",
"]",
"=",
"0",
";",
"// default, the start state for DFA is 0",
"stateMap",
"[",
"0",
"]",
"=",
"start",
";",
"newAdded",
".",
"push",
"(",
"start",
")",
";",
"while",
"(",
"newAdded",
".",
"length",
")",
"{",
"let",
"newAddedTmp",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"n",
"=",
"newAdded",
".",
"length",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"let",
"stateSet",
"=",
"newAdded",
"[",
"i",
"]",
";",
"let",
"newMap",
"=",
"this",
".",
"_getNFASetTransitionMap",
"(",
"stateSet",
")",
";",
"let",
"currentDFAState",
"=",
"i",
"+",
"offset",
";",
"for",
"(",
"let",
"letter",
"in",
"newMap",
")",
"{",
"let",
"toSet",
"=",
"newMap",
"[",
"letter",
"]",
";",
"let",
"hashKey",
"=",
"hashNFAStates",
"(",
"toSet",
")",
";",
"// find new state",
"let",
"newItem",
"=",
"null",
";",
"if",
"(",
"epsilonNFASetCache",
"[",
"hashKey",
"]",
")",
"{",
"newItem",
"=",
"epsilonNFASetCache",
"[",
"hashKey",
"]",
";",
"}",
"else",
"{",
"newItem",
"=",
"this",
".",
"epsilonClosure",
"(",
"newMap",
"[",
"letter",
"]",
")",
";",
"}",
"let",
"newItemHashKey",
"=",
"hashNFAStates",
"(",
"newItem",
")",
";",
"//",
"if",
"(",
"dfaStates",
"[",
"newItemHashKey",
"]",
"!==",
"undefined",
")",
"{",
"dfa",
".",
"addTransition",
"(",
"currentDFAState",
",",
"letter",
",",
"dfaStates",
"[",
"newItemHashKey",
"]",
")",
";",
"}",
"else",
"{",
"// find new item",
"last",
"++",
";",
"// last + 1 as new DFA state",
"dfaStates",
"[",
"newItemHashKey",
"]",
"=",
"last",
";",
"stateMap",
"[",
"last",
"]",
"=",
"newItem",
";",
"newAddedTmp",
".",
"push",
"(",
"newItem",
")",
";",
"// build the connection from (index + offset) -> last",
"dfa",
".",
"addTransition",
"(",
"currentDFAState",
",",
"letter",
",",
"last",
")",
";",
"}",
"}",
"}",
"offset",
"+=",
"newAdded",
".",
"length",
";",
"newAdded",
"=",
"newAddedTmp",
";",
"}",
"return",
"{",
"dfa",
",",
"stateMap",
"}",
";",
"}"
] | generate a new DFA and record which nfa states composed to a new DFA state | [
"generate",
"a",
"new",
"DFA",
"and",
"record",
"which",
"nfa",
"states",
"composed",
"to",
"a",
"new",
"DFA",
"state"
] | db7e8d5a5df6d10f285049d8f154c3f3a3f34211 | https://github.com/LoveKino/cl-fsm/blob/db7e8d5a5df6d10f285049d8f154c3f3a3f34211/lib/nfa.js#L90-L153 |
|
56,305 | yoshuawuyts/virtual-form | index.js | virtualForm | function virtualForm (h, opts, arr) {
if (!arr) {
arr = opts
opts = {}
}
assert.equal(typeof h, 'function')
assert.equal(typeof opts, 'object')
assert.ok(Array.isArray(arr), 'is array')
return arr.map(function createInput (val) {
if (typeof val === 'string') {
val = { type: 'text', name: val }
}
if (!val.value) val.value = ''
assert.equal(typeof val, 'object')
if (opts.label) {
if (val.type === 'submit') return h('input', val)
return h('fieldset', [
h('label', [ val.name ]),
h('input', val)
])
}
if (val.type !== 'submit' && !val.placeholder) {
val.placeholder = val.name
}
return h('input', val)
})
} | javascript | function virtualForm (h, opts, arr) {
if (!arr) {
arr = opts
opts = {}
}
assert.equal(typeof h, 'function')
assert.equal(typeof opts, 'object')
assert.ok(Array.isArray(arr), 'is array')
return arr.map(function createInput (val) {
if (typeof val === 'string') {
val = { type: 'text', name: val }
}
if (!val.value) val.value = ''
assert.equal(typeof val, 'object')
if (opts.label) {
if (val.type === 'submit') return h('input', val)
return h('fieldset', [
h('label', [ val.name ]),
h('input', val)
])
}
if (val.type !== 'submit' && !val.placeholder) {
val.placeholder = val.name
}
return h('input', val)
})
} | [
"function",
"virtualForm",
"(",
"h",
",",
"opts",
",",
"arr",
")",
"{",
"if",
"(",
"!",
"arr",
")",
"{",
"arr",
"=",
"opts",
"opts",
"=",
"{",
"}",
"}",
"assert",
".",
"equal",
"(",
"typeof",
"h",
",",
"'function'",
")",
"assert",
".",
"equal",
"(",
"typeof",
"opts",
",",
"'object'",
")",
"assert",
".",
"ok",
"(",
"Array",
".",
"isArray",
"(",
"arr",
")",
",",
"'is array'",
")",
"return",
"arr",
".",
"map",
"(",
"function",
"createInput",
"(",
"val",
")",
"{",
"if",
"(",
"typeof",
"val",
"===",
"'string'",
")",
"{",
"val",
"=",
"{",
"type",
":",
"'text'",
",",
"name",
":",
"val",
"}",
"}",
"if",
"(",
"!",
"val",
".",
"value",
")",
"val",
".",
"value",
"=",
"''",
"assert",
".",
"equal",
"(",
"typeof",
"val",
",",
"'object'",
")",
"if",
"(",
"opts",
".",
"label",
")",
"{",
"if",
"(",
"val",
".",
"type",
"===",
"'submit'",
")",
"return",
"h",
"(",
"'input'",
",",
"val",
")",
"return",
"h",
"(",
"'fieldset'",
",",
"[",
"h",
"(",
"'label'",
",",
"[",
"val",
".",
"name",
"]",
")",
",",
"h",
"(",
"'input'",
",",
"val",
")",
"]",
")",
"}",
"if",
"(",
"val",
".",
"type",
"!==",
"'submit'",
"&&",
"!",
"val",
".",
"placeholder",
")",
"{",
"val",
".",
"placeholder",
"=",
"val",
".",
"name",
"}",
"return",
"h",
"(",
"'input'",
",",
"val",
")",
"}",
")",
"}"
] | Create a virtual-dom form null -> null | [
"Create",
"a",
"virtual",
"-",
"dom",
"form",
"null",
"-",
">",
"null"
] | acc64f437cccc8aa11681c2b8a042394b4844928 | https://github.com/yoshuawuyts/virtual-form/blob/acc64f437cccc8aa11681c2b8a042394b4844928/index.js#L7-L38 |
56,306 | Froguard/rgl-tplmin-loader | index.js | cleanRedundantCode | function cleanRedundantCode(str, opts){
opts = opts || {};
var minimize = def(opts.minimize, true);
var comments = opts.comments || {};
var htmlComments = comments.html,
rglComments = comments.rgl;
if(minimize && typeof str === 'string'){
var SINGLE_SPACE = ' ';
var EMPTY = '';
// remove html-comments <!-- xxx -->
str = !htmlComments ? str.replace(/<!-[\s\S]*?-->/g, EMPTY) : str;
// remove regular-comments {! xxx !}
str = !rglComments ? str.replace(/{![\s\S]*?!}/g, EMPTY) : str;
// 暴力全局替换\s,副作用:内容里面有带空格或回车的字符串会被替换截掉
// str = str.replace(/[\s]{2,}/g, SINGLE_SPACE);
str = str.replace(/[\f\t\v]{2,}/g, SINGLE_SPACE);
// // <abc>,<abc/> 左边
// str = str.replace(/[\s]{2,}(?=<\w+(\s[\s\S]*?)*?\/?>)/g, SINGLE_SPACE);
// // </abc> 左边
// str = str.replace(/[\s]{2,}(?=<\/\w+>)/g, SINGLE_SPACE);
//
// // js并不支持'后行断言'(?<=condition)这种写法,这里只能采用callback函数来弥补
//
// // <abc>,</abc>,<abc/>,/> 右边
// str = str.replace(/((?:<\/?\w+>)|(?:<\w+\/>)|(?:\/>))[\s]{2,}/g, function($0, $1){
// return ($1 ? ($ + SINGLE_SPACE) : $0);
// });
// // 花括号左右
// str = str.replace(/[\s]+(?=(}|\{))/g, SINGLE_SPACE); // 左空格
// str = str.replace(/(}|\{)(\s+)/g, function($0, $1){ // 右空格
// return $1 + SINGLE_SPACE;
// });
// // 大小于等号左右
// str = str.replace(/[\s]+(?=(>|<))/g, SINGLE_SPACE); // 左空格
// str = str.replace(/(>|<)(\s+)/g, function($0, $1){ // 右空格
// return $1 + SINGLE_SPACE;
// });
// Last, trim
str = str.trim();
}
return str;
} | javascript | function cleanRedundantCode(str, opts){
opts = opts || {};
var minimize = def(opts.minimize, true);
var comments = opts.comments || {};
var htmlComments = comments.html,
rglComments = comments.rgl;
if(minimize && typeof str === 'string'){
var SINGLE_SPACE = ' ';
var EMPTY = '';
// remove html-comments <!-- xxx -->
str = !htmlComments ? str.replace(/<!-[\s\S]*?-->/g, EMPTY) : str;
// remove regular-comments {! xxx !}
str = !rglComments ? str.replace(/{![\s\S]*?!}/g, EMPTY) : str;
// 暴力全局替换\s,副作用:内容里面有带空格或回车的字符串会被替换截掉
// str = str.replace(/[\s]{2,}/g, SINGLE_SPACE);
str = str.replace(/[\f\t\v]{2,}/g, SINGLE_SPACE);
// // <abc>,<abc/> 左边
// str = str.replace(/[\s]{2,}(?=<\w+(\s[\s\S]*?)*?\/?>)/g, SINGLE_SPACE);
// // </abc> 左边
// str = str.replace(/[\s]{2,}(?=<\/\w+>)/g, SINGLE_SPACE);
//
// // js并不支持'后行断言'(?<=condition)这种写法,这里只能采用callback函数来弥补
//
// // <abc>,</abc>,<abc/>,/> 右边
// str = str.replace(/((?:<\/?\w+>)|(?:<\w+\/>)|(?:\/>))[\s]{2,}/g, function($0, $1){
// return ($1 ? ($ + SINGLE_SPACE) : $0);
// });
// // 花括号左右
// str = str.replace(/[\s]+(?=(}|\{))/g, SINGLE_SPACE); // 左空格
// str = str.replace(/(}|\{)(\s+)/g, function($0, $1){ // 右空格
// return $1 + SINGLE_SPACE;
// });
// // 大小于等号左右
// str = str.replace(/[\s]+(?=(>|<))/g, SINGLE_SPACE); // 左空格
// str = str.replace(/(>|<)(\s+)/g, function($0, $1){ // 右空格
// return $1 + SINGLE_SPACE;
// });
// Last, trim
str = str.trim();
}
return str;
} | [
"function",
"cleanRedundantCode",
"(",
"str",
",",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"var",
"minimize",
"=",
"def",
"(",
"opts",
".",
"minimize",
",",
"true",
")",
";",
"var",
"comments",
"=",
"opts",
".",
"comments",
"||",
"{",
"}",
";",
"var",
"htmlComments",
"=",
"comments",
".",
"html",
",",
"rglComments",
"=",
"comments",
".",
"rgl",
";",
"if",
"(",
"minimize",
"&&",
"typeof",
"str",
"===",
"'string'",
")",
"{",
"var",
"SINGLE_SPACE",
"=",
"' '",
";",
"var",
"EMPTY",
"=",
"''",
";",
"// remove html-comments <!-- xxx -->",
"str",
"=",
"!",
"htmlComments",
"?",
"str",
".",
"replace",
"(",
"/",
"<!-[\\s\\S]*?-->",
"/",
"g",
",",
"EMPTY",
")",
":",
"str",
";",
"// remove regular-comments {! xxx !}",
"str",
"=",
"!",
"rglComments",
"?",
"str",
".",
"replace",
"(",
"/",
"{![\\s\\S]*?!}",
"/",
"g",
",",
"EMPTY",
")",
":",
"str",
";",
"// 暴力全局替换\\s,副作用:内容里面有带空格或回车的字符串会被替换截掉",
"// str = str.replace(/[\\s]{2,}/g, SINGLE_SPACE);",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"[\\f\\t\\v]{2,}",
"/",
"g",
",",
"SINGLE_SPACE",
")",
";",
"// // <abc>,<abc/> 左边",
"// str = str.replace(/[\\s]{2,}(?=<\\w+(\\s[\\s\\S]*?)*?\\/?>)/g, SINGLE_SPACE);",
"// // </abc> 左边",
"// str = str.replace(/[\\s]{2,}(?=<\\/\\w+>)/g, SINGLE_SPACE);",
"//",
"// // js并不支持'后行断言'(?<=condition)这种写法,这里只能采用callback函数来弥补",
"//",
"// // <abc>,</abc>,<abc/>,/> 右边",
"// str = str.replace(/((?:<\\/?\\w+>)|(?:<\\w+\\/>)|(?:\\/>))[\\s]{2,}/g, function($0, $1){",
"// return ($1 ? ($ + SINGLE_SPACE) : $0);",
"// });",
"// // 花括号左右",
"// str = str.replace(/[\\s]+(?=(}|\\{))/g, SINGLE_SPACE); // 左空格",
"// str = str.replace(/(}|\\{)(\\s+)/g, function($0, $1){ // 右空格",
"// return $1 + SINGLE_SPACE;",
"// });",
"// // 大小于等号左右",
"// str = str.replace(/[\\s]+(?=(>|<))/g, SINGLE_SPACE); // 左空格",
"// str = str.replace(/(>|<)(\\s+)/g, function($0, $1){ // 右空格",
"// return $1 + SINGLE_SPACE;",
"// });",
"// Last, trim",
"str",
"=",
"str",
".",
"trim",
"(",
")",
";",
"}",
"return",
"str",
";",
"}"
] | pure regEx to resolve it, not via a parser; | [
"pure",
"regEx",
"to",
"resolve",
"it",
"not",
"via",
"a",
"parser",
";"
] | 74a8af5373cffe3998606dd89975cb0737e5014d | https://github.com/Froguard/rgl-tplmin-loader/blob/74a8af5373cffe3998606dd89975cb0737e5014d/index.js#L15-L63 |
56,307 | dominictarr/npmd-unpack | index.js | getCache | function getCache (pkg, config) {
pkg = toPkg(pkg)
if(config && config.cacheHash)
return path.join(config.cache, pkg.shasum, 'package.tgz')
return path.join(
config.cache || path.join(process.env.HOME, '.npm'),
pkg.name, pkg.version, 'package.tgz'
)
} | javascript | function getCache (pkg, config) {
pkg = toPkg(pkg)
if(config && config.cacheHash)
return path.join(config.cache, pkg.shasum, 'package.tgz')
return path.join(
config.cache || path.join(process.env.HOME, '.npm'),
pkg.name, pkg.version, 'package.tgz'
)
} | [
"function",
"getCache",
"(",
"pkg",
",",
"config",
")",
"{",
"pkg",
"=",
"toPkg",
"(",
"pkg",
")",
"if",
"(",
"config",
"&&",
"config",
".",
"cacheHash",
")",
"return",
"path",
".",
"join",
"(",
"config",
".",
"cache",
",",
"pkg",
".",
"shasum",
",",
"'package.tgz'",
")",
"return",
"path",
".",
"join",
"(",
"config",
".",
"cache",
"||",
"path",
".",
"join",
"(",
"process",
".",
"env",
".",
"HOME",
",",
"'.npm'",
")",
",",
"pkg",
".",
"name",
",",
"pkg",
".",
"version",
",",
"'package.tgz'",
")",
"}"
] | Would be better to store the tarball as it's hash, not it's version. that would allow exact shrinkwraps. Probably want to fallback to getting the other cache, for speed. But to pull down new deps... Also... hashes would allow peer to peer module hosting, and multiple repos... | [
"Would",
"be",
"better",
"to",
"store",
"the",
"tarball",
"as",
"it",
"s",
"hash",
"not",
"it",
"s",
"version",
".",
"that",
"would",
"allow",
"exact",
"shrinkwraps",
".",
"Probably",
"want",
"to",
"fallback",
"to",
"getting",
"the",
"other",
"cache",
"for",
"speed",
".",
"But",
"to",
"pull",
"down",
"new",
"deps",
"...",
"Also",
"...",
"hashes",
"would",
"allow",
"peer",
"to",
"peer",
"module",
"hosting",
"and",
"multiple",
"repos",
"..."
] | 5d6057ebf3413d256a2b2fc7724b4d7fbc424c53 | https://github.com/dominictarr/npmd-unpack/blob/5d6057ebf3413d256a2b2fc7724b4d7fbc424c53/index.js#L44-L54 |
56,308 | dominictarr/npmd-unpack | index.js | get | function get (url, cb) {
var urls = [], end
_get(url, cb)
function _get (url) {
urls.push(url)
if(end) return
if(urls.length > 5)
cb(end = new Error('too many redirects\n'+JSON.stringify(urls)))
console.error('GET', url)
;(/^https/.test(url) ? https : http).get(url, function next (res) {
if(res.statusCode >= 300 && res.statusCode < 400)
_get(res.headers.location)
else {
end = true,
cb(null, res)
}
})
.on('error', function (err) {
if(!end)
cb(end = err)
})
}
} | javascript | function get (url, cb) {
var urls = [], end
_get(url, cb)
function _get (url) {
urls.push(url)
if(end) return
if(urls.length > 5)
cb(end = new Error('too many redirects\n'+JSON.stringify(urls)))
console.error('GET', url)
;(/^https/.test(url) ? https : http).get(url, function next (res) {
if(res.statusCode >= 300 && res.statusCode < 400)
_get(res.headers.location)
else {
end = true,
cb(null, res)
}
})
.on('error', function (err) {
if(!end)
cb(end = err)
})
}
} | [
"function",
"get",
"(",
"url",
",",
"cb",
")",
"{",
"var",
"urls",
"=",
"[",
"]",
",",
"end",
"_get",
"(",
"url",
",",
"cb",
")",
"function",
"_get",
"(",
"url",
")",
"{",
"urls",
".",
"push",
"(",
"url",
")",
"if",
"(",
"end",
")",
"return",
"if",
"(",
"urls",
".",
"length",
">",
"5",
")",
"cb",
"(",
"end",
"=",
"new",
"Error",
"(",
"'too many redirects\\n'",
"+",
"JSON",
".",
"stringify",
"(",
"urls",
")",
")",
")",
"console",
".",
"error",
"(",
"'GET'",
",",
"url",
")",
";",
"(",
"/",
"^https",
"/",
".",
"test",
"(",
"url",
")",
"?",
"https",
":",
"http",
")",
".",
"get",
"(",
"url",
",",
"function",
"next",
"(",
"res",
")",
"{",
"if",
"(",
"res",
".",
"statusCode",
">=",
"300",
"&&",
"res",
".",
"statusCode",
"<",
"400",
")",
"_get",
"(",
"res",
".",
"headers",
".",
"location",
")",
"else",
"{",
"end",
"=",
"true",
",",
"cb",
"(",
"null",
",",
"res",
")",
"}",
"}",
")",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"end",
")",
"cb",
"(",
"end",
"=",
"err",
")",
"}",
")",
"}",
"}"
] | pull a package from the registry | [
"pull",
"a",
"package",
"from",
"the",
"registry"
] | 5d6057ebf3413d256a2b2fc7724b4d7fbc424c53 | https://github.com/dominictarr/npmd-unpack/blob/5d6057ebf3413d256a2b2fc7724b4d7fbc424c53/index.js#L59-L83 |
56,309 | dominictarr/npmd-unpack | index.js | getTarballStream | function getTarballStream (pkg, config, cb) {
if(config.casDb && pkg.shasum) {
var db = config.casDb
db.has(pkg.shasum, function (err, stat) {
if(!err)
cb(null, db.getStream(pkg.shasum))
else //fallback to the old way...
tryCache()
})
}
else
tryCache()
function tryCache () {
var cache = getCache(pkg, config)
fs.stat(cache, function (err) {
if(!err)
cb(null, fs.createReadStream(cache))
else
getDownload(pkg, config, cb)
})
}
} | javascript | function getTarballStream (pkg, config, cb) {
if(config.casDb && pkg.shasum) {
var db = config.casDb
db.has(pkg.shasum, function (err, stat) {
if(!err)
cb(null, db.getStream(pkg.shasum))
else //fallback to the old way...
tryCache()
})
}
else
tryCache()
function tryCache () {
var cache = getCache(pkg, config)
fs.stat(cache, function (err) {
if(!err)
cb(null, fs.createReadStream(cache))
else
getDownload(pkg, config, cb)
})
}
} | [
"function",
"getTarballStream",
"(",
"pkg",
",",
"config",
",",
"cb",
")",
"{",
"if",
"(",
"config",
".",
"casDb",
"&&",
"pkg",
".",
"shasum",
")",
"{",
"var",
"db",
"=",
"config",
".",
"casDb",
"db",
".",
"has",
"(",
"pkg",
".",
"shasum",
",",
"function",
"(",
"err",
",",
"stat",
")",
"{",
"if",
"(",
"!",
"err",
")",
"cb",
"(",
"null",
",",
"db",
".",
"getStream",
"(",
"pkg",
".",
"shasum",
")",
")",
"else",
"//fallback to the old way...",
"tryCache",
"(",
")",
"}",
")",
"}",
"else",
"tryCache",
"(",
")",
"function",
"tryCache",
"(",
")",
"{",
"var",
"cache",
"=",
"getCache",
"(",
"pkg",
",",
"config",
")",
"fs",
".",
"stat",
"(",
"cache",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"!",
"err",
")",
"cb",
"(",
"null",
",",
"fs",
".",
"createReadStream",
"(",
"cache",
")",
")",
"else",
"getDownload",
"(",
"pkg",
",",
"config",
",",
"cb",
")",
"}",
")",
"}",
"}"
] | stream a tarball - either from cache or registry | [
"stream",
"a",
"tarball",
"-",
"either",
"from",
"cache",
"or",
"registry"
] | 5d6057ebf3413d256a2b2fc7724b4d7fbc424c53 | https://github.com/dominictarr/npmd-unpack/blob/5d6057ebf3413d256a2b2fc7724b4d7fbc424c53/index.js#L111-L133 |
56,310 | dominictarr/npmd-unpack | index.js | getTmp | function getTmp (config) {
return path.join(config.tmpdir || '/tmp', ''+Date.now() + Math.random())
} | javascript | function getTmp (config) {
return path.join(config.tmpdir || '/tmp', ''+Date.now() + Math.random())
} | [
"function",
"getTmp",
"(",
"config",
")",
"{",
"return",
"path",
".",
"join",
"(",
"config",
".",
"tmpdir",
"||",
"'/tmp'",
",",
"''",
"+",
"Date",
".",
"now",
"(",
")",
"+",
"Math",
".",
"random",
"(",
")",
")",
"}"
] | unpack a tarball to some target directory. recommend unpacking to tmpdir and then moving a following step. ALSO, should hash the file as we unpack it, and validate that we get the correct hash. | [
"unpack",
"a",
"tarball",
"to",
"some",
"target",
"directory",
".",
"recommend",
"unpacking",
"to",
"tmpdir",
"and",
"then",
"moving",
"a",
"following",
"step",
".",
"ALSO",
"should",
"hash",
"the",
"file",
"as",
"we",
"unpack",
"it",
"and",
"validate",
"that",
"we",
"get",
"the",
"correct",
"hash",
"."
] | 5d6057ebf3413d256a2b2fc7724b4d7fbc424c53 | https://github.com/dominictarr/npmd-unpack/blob/5d6057ebf3413d256a2b2fc7724b4d7fbc424c53/index.js#L140-L142 |
56,311 | Wiredcraft/mixable-object | lib/mixin.js | mixin | function mixin(source) {
var keys = [];
if (arguments.length > 1) {
for (var i = 1, len = arguments.length; i < len; i++) {
var key = arguments[i];
if (!source.hasOwnProperty(key)) {
throw new Error(util.format('Property not found: %s', key));
}
keys.push(key);
}
} else {
keys = Object.keys(source);
}
// Copy.
for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
defineProp(this, key, descriptor(source, key));
}
return this;
} | javascript | function mixin(source) {
var keys = [];
if (arguments.length > 1) {
for (var i = 1, len = arguments.length; i < len; i++) {
var key = arguments[i];
if (!source.hasOwnProperty(key)) {
throw new Error(util.format('Property not found: %s', key));
}
keys.push(key);
}
} else {
keys = Object.keys(source);
}
// Copy.
for (var i = 0, len = keys.length; i < len; i++) {
key = keys[i];
defineProp(this, key, descriptor(source, key));
}
return this;
} | [
"function",
"mixin",
"(",
"source",
")",
"{",
"var",
"keys",
"=",
"[",
"]",
";",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"1",
",",
"len",
"=",
"arguments",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"var",
"key",
"=",
"arguments",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"source",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"util",
".",
"format",
"(",
"'Property not found: %s'",
",",
"key",
")",
")",
";",
"}",
"keys",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
"else",
"{",
"keys",
"=",
"Object",
".",
"keys",
"(",
"source",
")",
";",
"}",
"// Copy.",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"keys",
".",
"length",
";",
"i",
"<",
"len",
";",
"i",
"++",
")",
"{",
"key",
"=",
"keys",
"[",
"i",
"]",
";",
"defineProp",
"(",
"this",
",",
"key",
",",
"descriptor",
"(",
"source",
",",
"key",
")",
")",
";",
"}",
"return",
"this",
";",
"}"
] | The common mixin, simply copies properties, by redefining the same properties
from the source.
@param {Object} source
@param {Mixed} ...keys if given only the attributes with the keys are copied
@return {this} | [
"The",
"common",
"mixin",
"simply",
"copies",
"properties",
"by",
"redefining",
"the",
"same",
"properties",
"from",
"the",
"source",
"."
] | 1ddb656ab11399b8cffbbf300b51bd334a1a77e1 | https://github.com/Wiredcraft/mixable-object/blob/1ddb656ab11399b8cffbbf300b51bd334a1a77e1/lib/mixin.js#L15-L34 |
56,312 | wigy/chronicles_of_grunt | tasks/build.js | subst | function subst(str, file, dst) {
if (dst !== undefined) {
str = str.replace(/\{\{DST\}\}/g, dst);
}
var dir = path.dirname(file);
str = str.replace(/\{\{SRC\}\}/g, file);
var name = path.basename(file);
str = str.replace(/\{\{NAME\}\}/g, name);
name = name.replace(/\.\w+$/, '');
str = str.replace(/\{\{BASENAME\}\}/g, name);
str = str.replace(/\{\{DIR\}\}/g, dir);
var parts = dir.split(path.sep);
parts.splice(0, 1);
str = str.replace(/\{\{SUBDIR\}\}/g, path.join.apply(null, parts));
parts.splice(0, 1);
str = str.replace(/\{\{SUBSUBDIR\}\}/g, path.join.apply(null, parts));
return str;
} | javascript | function subst(str, file, dst) {
if (dst !== undefined) {
str = str.replace(/\{\{DST\}\}/g, dst);
}
var dir = path.dirname(file);
str = str.replace(/\{\{SRC\}\}/g, file);
var name = path.basename(file);
str = str.replace(/\{\{NAME\}\}/g, name);
name = name.replace(/\.\w+$/, '');
str = str.replace(/\{\{BASENAME\}\}/g, name);
str = str.replace(/\{\{DIR\}\}/g, dir);
var parts = dir.split(path.sep);
parts.splice(0, 1);
str = str.replace(/\{\{SUBDIR\}\}/g, path.join.apply(null, parts));
parts.splice(0, 1);
str = str.replace(/\{\{SUBSUBDIR\}\}/g, path.join.apply(null, parts));
return str;
} | [
"function",
"subst",
"(",
"str",
",",
"file",
",",
"dst",
")",
"{",
"if",
"(",
"dst",
"!==",
"undefined",
")",
"{",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{DST\\}\\}",
"/",
"g",
",",
"dst",
")",
";",
"}",
"var",
"dir",
"=",
"path",
".",
"dirname",
"(",
"file",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{SRC\\}\\}",
"/",
"g",
",",
"file",
")",
";",
"var",
"name",
"=",
"path",
".",
"basename",
"(",
"file",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{NAME\\}\\}",
"/",
"g",
",",
"name",
")",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"/",
"\\.\\w+$",
"/",
",",
"''",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{BASENAME\\}\\}",
"/",
"g",
",",
"name",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{DIR\\}\\}",
"/",
"g",
",",
"dir",
")",
";",
"var",
"parts",
"=",
"dir",
".",
"split",
"(",
"path",
".",
"sep",
")",
";",
"parts",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{SUBDIR\\}\\}",
"/",
"g",
",",
"path",
".",
"join",
".",
"apply",
"(",
"null",
",",
"parts",
")",
")",
";",
"parts",
".",
"splice",
"(",
"0",
",",
"1",
")",
";",
"str",
"=",
"str",
".",
"replace",
"(",
"/",
"\\{\\{SUBSUBDIR\\}\\}",
"/",
"g",
",",
"path",
".",
"join",
".",
"apply",
"(",
"null",
",",
"parts",
")",
")",
";",
"return",
"str",
";",
"}"
] | Support function to substitute path variables. | [
"Support",
"function",
"to",
"substitute",
"path",
"variables",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/tasks/build.js#L57-L74 |
56,313 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
if (utils.Misc.isEmptyObject(request.query)) {
var errApp = new Error(errors['130']);
response.end(utils.Misc.createResponse(null, errApp, 130));
}
else {
next();
}
} | javascript | function(request, response, next){
if (utils.Misc.isEmptyObject(request.query)) {
var errApp = new Error(errors['130']);
response.end(utils.Misc.createResponse(null, errApp, 130));
}
else {
next();
}
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"if",
"(",
"utils",
".",
"Misc",
".",
"isEmptyObject",
"(",
"request",
".",
"query",
")",
")",
"{",
"var",
"errApp",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'130'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"errApp",
",",
"130",
")",
")",
";",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"}"
] | checks to be sure a criterion was specified for a bulk update operation | [
"checks",
"to",
"be",
"sure",
"a",
"criterion",
"was",
"specified",
"for",
"a",
"bulk",
"update",
"operation"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L81-L89 |
|
56,314 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.user)) {
next();
}
else {
var error = new Error(errors['213']);
response.end(utils.Misc.createResponse(null, error, 213));
}
} | javascript | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.user)) {
next();
}
else {
var error = new Error(errors['213']);
response.end(utils.Misc.createResponse(null, error, 213));
}
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"user",
")",
")",
"{",
"next",
"(",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'213'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"213",
")",
")",
";",
"}",
"}"
] | checks for logged-in user | [
"checks",
"for",
"logged",
"-",
"in",
"user"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L91-L99 |
|
56,315 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.user) || request.originalUrl == '/error' || request.originalUrl.indexOf('/error?') == 0) {
next();
}
else {
var success = encodeURIComponent(request.protocol + '://' + request.get('host') + request.originalUrl);
response.redirect('/login?success=' + success + '&no_query=true'); //we don't want it to add any query string
}
} | javascript | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.user) || request.originalUrl == '/error' || request.originalUrl.indexOf('/error?') == 0) {
next();
}
else {
var success = encodeURIComponent(request.protocol + '://' + request.get('host') + request.originalUrl);
response.redirect('/login?success=' + success + '&no_query=true'); //we don't want it to add any query string
}
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"user",
")",
"||",
"request",
".",
"originalUrl",
"==",
"'/error'",
"||",
"request",
".",
"originalUrl",
".",
"indexOf",
"(",
"'/error?'",
")",
"==",
"0",
")",
"{",
"next",
"(",
")",
";",
"}",
"else",
"{",
"var",
"success",
"=",
"encodeURIComponent",
"(",
"request",
".",
"protocol",
"+",
"'://'",
"+",
"request",
".",
"get",
"(",
"'host'",
")",
"+",
"request",
".",
"originalUrl",
")",
";",
"response",
".",
"redirect",
"(",
"'/login?success='",
"+",
"success",
"+",
"'&no_query=true'",
")",
";",
"//we don't want it to add any query string",
"}",
"}"
] | checks for logged-in UI user | [
"checks",
"for",
"logged",
"-",
"in",
"UI",
"user"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L101-L109 |
|
56,316 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
if (appnm == 'bolt') {
//native views
next();
}
else {
models.app.findOne({
name: appnm, system: true
}, function(appError, app){
if (!utils.Misc.isNullOrUndefined(appError)) {
response.end(utils.Misc.createResponse(null, appError));
}
else if(utils.Misc.isNullOrUndefined(app)){
var error = new Error(errors['504']);
response.end(utils.Misc.createResponse(null, error, 504));
}
else{
next();
}
});
}
} | javascript | function(request, response, next){
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
if (appnm == 'bolt') {
//native views
next();
}
else {
models.app.findOne({
name: appnm, system: true
}, function(appError, app){
if (!utils.Misc.isNullOrUndefined(appError)) {
response.end(utils.Misc.createResponse(null, appError));
}
else if(utils.Misc.isNullOrUndefined(app)){
var error = new Error(errors['504']);
response.end(utils.Misc.createResponse(null, error, 504));
}
else{
next();
}
});
}
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"var",
"apptkn",
";",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
")",
")",
"{",
"apptkn",
"=",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'110'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"110",
")",
")",
";",
"return",
";",
"}",
"var",
"name",
"=",
"__getAppFromAppToken",
"(",
"apptkn",
",",
"request",
")",
";",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"name",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'113'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"113",
")",
")",
";",
"return",
";",
"}",
"var",
"appnm",
"=",
"utils",
".",
"String",
".",
"trim",
"(",
"name",
".",
"toLowerCase",
"(",
")",
")",
";",
"if",
"(",
"appnm",
"==",
"'bolt'",
")",
"{",
"//native views",
"next",
"(",
")",
";",
"}",
"else",
"{",
"models",
".",
"app",
".",
"findOne",
"(",
"{",
"name",
":",
"appnm",
",",
"system",
":",
"true",
"}",
",",
"function",
"(",
"appError",
",",
"app",
")",
"{",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"appError",
")",
")",
"{",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"appError",
")",
")",
";",
"}",
"else",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"app",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'504'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"504",
")",
")",
";",
"}",
"else",
"{",
"next",
"(",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | checks to be sure the app making this request is a system app | [
"checks",
"to",
"be",
"sure",
"the",
"app",
"making",
"this",
"request",
"is",
"a",
"system",
"app"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L111-L150 |
|
56,317 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
request.appName = appnm;
next();
} | javascript | function(request, response, next){
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
request.appName = appnm;
next();
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"var",
"apptkn",
";",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
")",
")",
"{",
"apptkn",
"=",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'110'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"110",
")",
")",
";",
"return",
";",
"}",
"var",
"name",
"=",
"__getAppFromAppToken",
"(",
"apptkn",
",",
"request",
")",
";",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"name",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'113'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"113",
")",
")",
";",
"return",
";",
"}",
"var",
"appnm",
"=",
"utils",
".",
"String",
".",
"trim",
"(",
"name",
".",
"toLowerCase",
"(",
")",
")",
";",
"request",
".",
"appName",
"=",
"appnm",
";",
"next",
"(",
")",
";",
"}"
] | gets the app name from the request | [
"gets",
"the",
"app",
"name",
"from",
"the",
"request"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L153-L174 |
|
56,318 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.body.db)) {
request.db = request.body.db;
}
else if (!utils.Misc.isNullOrUndefined(request.body.app)) {
request.db = request.body.app;
}
else {
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
request.db = appnm;
}
if (request.db.indexOf('/') > -1 || request.db.indexOf('\\') > -1 || request.db.indexOf('?') > -1 || request.db.indexOf('&') > -1) {
//invalid characters in app name
var error = new Error(errors['405']);
response.end(utils.Misc.createResponse(null, error, 405));
return;
}
next();
} | javascript | function(request, response, next){
if (!utils.Misc.isNullOrUndefined(request.body.db)) {
request.db = request.body.db;
}
else if (!utils.Misc.isNullOrUndefined(request.body.app)) {
request.db = request.body.app;
}
else {
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
request.db = appnm;
}
if (request.db.indexOf('/') > -1 || request.db.indexOf('\\') > -1 || request.db.indexOf('?') > -1 || request.db.indexOf('&') > -1) {
//invalid characters in app name
var error = new Error(errors['405']);
response.end(utils.Misc.createResponse(null, error, 405));
return;
}
next();
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"body",
".",
"db",
")",
")",
"{",
"request",
".",
"db",
"=",
"request",
".",
"body",
".",
"db",
";",
"}",
"else",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"body",
".",
"app",
")",
")",
"{",
"request",
".",
"db",
"=",
"request",
".",
"body",
".",
"app",
";",
"}",
"else",
"{",
"var",
"apptkn",
";",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
")",
")",
"{",
"apptkn",
"=",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'110'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"110",
")",
")",
";",
"return",
";",
"}",
"var",
"name",
"=",
"__getAppFromAppToken",
"(",
"apptkn",
",",
"request",
")",
";",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"name",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'113'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"113",
")",
")",
";",
"return",
";",
"}",
"var",
"appnm",
"=",
"utils",
".",
"String",
".",
"trim",
"(",
"name",
".",
"toLowerCase",
"(",
")",
")",
";",
"request",
".",
"db",
"=",
"appnm",
";",
"}",
"if",
"(",
"request",
".",
"db",
".",
"indexOf",
"(",
"'/'",
")",
">",
"-",
"1",
"||",
"request",
".",
"db",
".",
"indexOf",
"(",
"'\\\\'",
")",
">",
"-",
"1",
"||",
"request",
".",
"db",
".",
"indexOf",
"(",
"'?'",
")",
">",
"-",
"1",
"||",
"request",
".",
"db",
".",
"indexOf",
"(",
"'&'",
")",
">",
"-",
"1",
")",
"{",
"//invalid characters in app name",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'405'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"405",
")",
")",
";",
"return",
";",
"}",
"next",
"(",
")",
";",
"}"
] | gets the DB name from the request, and creates the request.db field to hold the value | [
"gets",
"the",
"DB",
"name",
"from",
"the",
"request",
"and",
"creates",
"the",
"request",
".",
"db",
"field",
"to",
"hold",
"the",
"value"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L242-L278 |
|
56,319 | Chieze-Franklin/bolt-internal-checks | checks.js | function(request, response, next) {
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
var dbOwner = request.body.db || request.body.app || appnm;
models.collection.findOne({ name: request.params.collection, app: dbOwner }, function(collError, collection){
if (!utils.Misc.isNullOrUndefined(collError)){
response.end(utils.Misc.createResponse(null, collError));
}
else if(utils.Misc.isNullOrUndefined(collection)){
var errColl = new Error(errors['703']);
response.end(utils.Misc.createResponse(null, errColl, 703));
}
else {
//allow the owner to pass
if (appnm == collection.app.toLowerCase()) {
next();
return;
}
if (!utils.Misc.isNullOrUndefined(collection.tenants)) { //tenants allowed
if ("*" == collection.tenants) { //every body is allowed
next();
return;
}
//there is a tenant list; are u listed?
else if (collection.tenants.map(function(value){ return value.toLowerCase(); }).indexOf(appnm) > -1) {
next();
return;
}
}
//no guests allowed
var error = new Error(errors['704']);
response.end(utils.Misc.createResponse(null, error, 704));
}
});
} | javascript | function(request, response, next) {
var apptkn;
if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
apptkn = request.get(X_BOLT_APP_TOKEN);
}
else {
var error = new Error(errors['110']);
response.end(utils.Misc.createResponse(null, error, 110));
return;
}
var name = __getAppFromAppToken(apptkn, request);
if (utils.Misc.isNullOrUndefined(name)) {
var error = new Error(errors['113']);
response.end(utils.Misc.createResponse(null, error, 113));
return;
}
var appnm = utils.String.trim(name.toLowerCase());
var dbOwner = request.body.db || request.body.app || appnm;
models.collection.findOne({ name: request.params.collection, app: dbOwner }, function(collError, collection){
if (!utils.Misc.isNullOrUndefined(collError)){
response.end(utils.Misc.createResponse(null, collError));
}
else if(utils.Misc.isNullOrUndefined(collection)){
var errColl = new Error(errors['703']);
response.end(utils.Misc.createResponse(null, errColl, 703));
}
else {
//allow the owner to pass
if (appnm == collection.app.toLowerCase()) {
next();
return;
}
if (!utils.Misc.isNullOrUndefined(collection.tenants)) { //tenants allowed
if ("*" == collection.tenants) { //every body is allowed
next();
return;
}
//there is a tenant list; are u listed?
else if (collection.tenants.map(function(value){ return value.toLowerCase(); }).indexOf(appnm) > -1) {
next();
return;
}
}
//no guests allowed
var error = new Error(errors['704']);
response.end(utils.Misc.createResponse(null, error, 704));
}
});
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"var",
"apptkn",
";",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
")",
")",
"{",
"apptkn",
"=",
"request",
".",
"get",
"(",
"X_BOLT_APP_TOKEN",
")",
";",
"}",
"else",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'110'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"110",
")",
")",
";",
"return",
";",
"}",
"var",
"name",
"=",
"__getAppFromAppToken",
"(",
"apptkn",
",",
"request",
")",
";",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"name",
")",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'113'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"113",
")",
")",
";",
"return",
";",
"}",
"var",
"appnm",
"=",
"utils",
".",
"String",
".",
"trim",
"(",
"name",
".",
"toLowerCase",
"(",
")",
")",
";",
"var",
"dbOwner",
"=",
"request",
".",
"body",
".",
"db",
"||",
"request",
".",
"body",
".",
"app",
"||",
"appnm",
";",
"models",
".",
"collection",
".",
"findOne",
"(",
"{",
"name",
":",
"request",
".",
"params",
".",
"collection",
",",
"app",
":",
"dbOwner",
"}",
",",
"function",
"(",
"collError",
",",
"collection",
")",
"{",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"collError",
")",
")",
"{",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"collError",
")",
")",
";",
"}",
"else",
"if",
"(",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"collection",
")",
")",
"{",
"var",
"errColl",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'703'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"errColl",
",",
"703",
")",
")",
";",
"}",
"else",
"{",
"//allow the owner to pass",
"if",
"(",
"appnm",
"==",
"collection",
".",
"app",
".",
"toLowerCase",
"(",
")",
")",
"{",
"next",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"utils",
".",
"Misc",
".",
"isNullOrUndefined",
"(",
"collection",
".",
"tenants",
")",
")",
"{",
"//tenants allowed",
"if",
"(",
"\"*\"",
"==",
"collection",
".",
"tenants",
")",
"{",
"//every body is allowed",
"next",
"(",
")",
";",
"return",
";",
"}",
"//there is a tenant list; are u listed?",
"else",
"if",
"(",
"collection",
".",
"tenants",
".",
"map",
"(",
"function",
"(",
"value",
")",
"{",
"return",
"value",
".",
"toLowerCase",
"(",
")",
";",
"}",
")",
".",
"indexOf",
"(",
"appnm",
")",
">",
"-",
"1",
")",
"{",
"next",
"(",
")",
";",
"return",
";",
"}",
"}",
"//no guests allowed",
"var",
"error",
"=",
"new",
"Error",
"(",
"errors",
"[",
"'704'",
"]",
")",
";",
"response",
".",
"end",
"(",
"utils",
".",
"Misc",
".",
"createResponse",
"(",
"null",
",",
"error",
",",
"704",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] | checks if this app has the right to write to the collection in the database | [
"checks",
"if",
"this",
"app",
"has",
"the",
"right",
"to",
"write",
"to",
"the",
"collection",
"in",
"the",
"database"
] | f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225 | https://github.com/Chieze-Franklin/bolt-internal-checks/blob/f1a7ccea701ec3e69f9bad0e0d6cf2efa6ee2225/checks.js#L280-L333 |
|
56,320 | dignifiedquire/node-inotifyr | lib/bits.js | toBitMask | function toBitMask(event) {
if (!_.has(eventMap, event)) {
throw new Error('Unkown event: ' + event);
}
return eventMap[event];
} | javascript | function toBitMask(event) {
if (!_.has(eventMap, event)) {
throw new Error('Unkown event: ' + event);
}
return eventMap[event];
} | [
"function",
"toBitMask",
"(",
"event",
")",
"{",
"if",
"(",
"!",
"_",
".",
"has",
"(",
"eventMap",
",",
"event",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Unkown event: '",
"+",
"event",
")",
";",
"}",
"return",
"eventMap",
"[",
"event",
"]",
";",
"}"
] | Convert a string to the corresponding bit mask. event - String Returns a binary number. | [
"Convert",
"a",
"string",
"to",
"the",
"corresponding",
"bit",
"mask",
".",
"event",
"-",
"String",
"Returns",
"a",
"binary",
"number",
"."
] | 6d161fed38c6d30951c46055939a5a2915304a53 | https://github.com/dignifiedquire/node-inotifyr/blob/6d161fed38c6d30951c46055939a5a2915304a53/lib/bits.js#L37-L42 |
56,321 | dignifiedquire/node-inotifyr | lib/bits.js | addFlags | function addFlags(mask, flags) {
if (flags.onlydir) mask = mask | Inotify.IN_ONLYDIR;
if (flags.dont_follow) mask = mask | Inotify.IN_DONT_FOLLOW;
if (flags.oneshot) mask = mask | Inotify.IN_ONESHOT;
return mask;
} | javascript | function addFlags(mask, flags) {
if (flags.onlydir) mask = mask | Inotify.IN_ONLYDIR;
if (flags.dont_follow) mask = mask | Inotify.IN_DONT_FOLLOW;
if (flags.oneshot) mask = mask | Inotify.IN_ONESHOT;
return mask;
} | [
"function",
"addFlags",
"(",
"mask",
",",
"flags",
")",
"{",
"if",
"(",
"flags",
".",
"onlydir",
")",
"mask",
"=",
"mask",
"|",
"Inotify",
".",
"IN_ONLYDIR",
";",
"if",
"(",
"flags",
".",
"dont_follow",
")",
"mask",
"=",
"mask",
"|",
"Inotify",
".",
"IN_DONT_FOLLOW",
";",
"if",
"(",
"flags",
".",
"oneshot",
")",
"mask",
"=",
"mask",
"|",
"Inotify",
".",
"IN_ONESHOT",
";",
"return",
"mask",
";",
"}"
] | Add additional flags to a given mask. mask - Number flags - Object Returns a number. | [
"Add",
"additional",
"flags",
"to",
"a",
"given",
"mask",
".",
"mask",
"-",
"Number",
"flags",
"-",
"Object",
"Returns",
"a",
"number",
"."
] | 6d161fed38c6d30951c46055939a5a2915304a53 | https://github.com/dignifiedquire/node-inotifyr/blob/6d161fed38c6d30951c46055939a5a2915304a53/lib/bits.js#L108-L113 |
56,322 | 5long/roil | src/console/socket.io.js | FABridge__bridgeInitialized | function FABridge__bridgeInitialized(bridgeName) {
var objects = document.getElementsByTagName("object");
var ol = objects.length;
var activeObjects = [];
if (ol > 0) {
for (var i = 0; i < ol; i++) {
if (typeof objects[i].SetVariable != "undefined") {
activeObjects[activeObjects.length] = objects[i];
}
}
}
var embeds = document.getElementsByTagName("embed");
var el = embeds.length;
var activeEmbeds = [];
if (el > 0) {
for (var j = 0; j < el; j++) {
if (typeof embeds[j].SetVariable != "undefined") {
activeEmbeds[activeEmbeds.length] = embeds[j];
}
}
}
var aol = activeObjects.length;
var ael = activeEmbeds.length;
var searchStr = "bridgeName="+ bridgeName;
if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
FABridge.attachBridge(activeObjects[0], bridgeName);
}
else if (ael == 1 && !aol) {
FABridge.attachBridge(activeEmbeds[0], bridgeName);
}
else {
var flash_found = false;
if (aol > 1) {
for (var k = 0; k < aol; k++) {
var params = activeObjects[k].childNodes;
for (var l = 0; l < params.length; l++) {
var param = params[l];
if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
FABridge.attachBridge(activeObjects[k], bridgeName);
flash_found = true;
break;
}
}
if (flash_found) {
break;
}
}
}
if (!flash_found && ael > 1) {
for (var m = 0; m < ael; m++) {
var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
if (flashVars.indexOf(searchStr) >= 0) {
FABridge.attachBridge(activeEmbeds[m], bridgeName);
break;
}
}
}
}
return true;
} | javascript | function FABridge__bridgeInitialized(bridgeName) {
var objects = document.getElementsByTagName("object");
var ol = objects.length;
var activeObjects = [];
if (ol > 0) {
for (var i = 0; i < ol; i++) {
if (typeof objects[i].SetVariable != "undefined") {
activeObjects[activeObjects.length] = objects[i];
}
}
}
var embeds = document.getElementsByTagName("embed");
var el = embeds.length;
var activeEmbeds = [];
if (el > 0) {
for (var j = 0; j < el; j++) {
if (typeof embeds[j].SetVariable != "undefined") {
activeEmbeds[activeEmbeds.length] = embeds[j];
}
}
}
var aol = activeObjects.length;
var ael = activeEmbeds.length;
var searchStr = "bridgeName="+ bridgeName;
if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
FABridge.attachBridge(activeObjects[0], bridgeName);
}
else if (ael == 1 && !aol) {
FABridge.attachBridge(activeEmbeds[0], bridgeName);
}
else {
var flash_found = false;
if (aol > 1) {
for (var k = 0; k < aol; k++) {
var params = activeObjects[k].childNodes;
for (var l = 0; l < params.length; l++) {
var param = params[l];
if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
FABridge.attachBridge(activeObjects[k], bridgeName);
flash_found = true;
break;
}
}
if (flash_found) {
break;
}
}
}
if (!flash_found && ael > 1) {
for (var m = 0; m < ael; m++) {
var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
if (flashVars.indexOf(searchStr) >= 0) {
FABridge.attachBridge(activeEmbeds[m], bridgeName);
break;
}
}
}
}
return true;
} | [
"function",
"FABridge__bridgeInitialized",
"(",
"bridgeName",
")",
"{",
"var",
"objects",
"=",
"document",
".",
"getElementsByTagName",
"(",
"\"object\"",
")",
";",
"var",
"ol",
"=",
"objects",
".",
"length",
";",
"var",
"activeObjects",
"=",
"[",
"]",
";",
"if",
"(",
"ol",
">",
"0",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"ol",
";",
"i",
"++",
")",
"{",
"if",
"(",
"typeof",
"objects",
"[",
"i",
"]",
".",
"SetVariable",
"!=",
"\"undefined\"",
")",
"{",
"activeObjects",
"[",
"activeObjects",
".",
"length",
"]",
"=",
"objects",
"[",
"i",
"]",
";",
"}",
"}",
"}",
"var",
"embeds",
"=",
"document",
".",
"getElementsByTagName",
"(",
"\"embed\"",
")",
";",
"var",
"el",
"=",
"embeds",
".",
"length",
";",
"var",
"activeEmbeds",
"=",
"[",
"]",
";",
"if",
"(",
"el",
">",
"0",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"el",
";",
"j",
"++",
")",
"{",
"if",
"(",
"typeof",
"embeds",
"[",
"j",
"]",
".",
"SetVariable",
"!=",
"\"undefined\"",
")",
"{",
"activeEmbeds",
"[",
"activeEmbeds",
".",
"length",
"]",
"=",
"embeds",
"[",
"j",
"]",
";",
"}",
"}",
"}",
"var",
"aol",
"=",
"activeObjects",
".",
"length",
";",
"var",
"ael",
"=",
"activeEmbeds",
".",
"length",
";",
"var",
"searchStr",
"=",
"\"bridgeName=\"",
"+",
"bridgeName",
";",
"if",
"(",
"(",
"aol",
"==",
"1",
"&&",
"!",
"ael",
")",
"||",
"(",
"aol",
"==",
"1",
"&&",
"ael",
"==",
"1",
")",
")",
"{",
"FABridge",
".",
"attachBridge",
"(",
"activeObjects",
"[",
"0",
"]",
",",
"bridgeName",
")",
";",
"}",
"else",
"if",
"(",
"ael",
"==",
"1",
"&&",
"!",
"aol",
")",
"{",
"FABridge",
".",
"attachBridge",
"(",
"activeEmbeds",
"[",
"0",
"]",
",",
"bridgeName",
")",
";",
"}",
"else",
"{",
"var",
"flash_found",
"=",
"false",
";",
"if",
"(",
"aol",
">",
"1",
")",
"{",
"for",
"(",
"var",
"k",
"=",
"0",
";",
"k",
"<",
"aol",
";",
"k",
"++",
")",
"{",
"var",
"params",
"=",
"activeObjects",
"[",
"k",
"]",
".",
"childNodes",
";",
"for",
"(",
"var",
"l",
"=",
"0",
";",
"l",
"<",
"params",
".",
"length",
";",
"l",
"++",
")",
"{",
"var",
"param",
"=",
"params",
"[",
"l",
"]",
";",
"if",
"(",
"param",
".",
"nodeType",
"==",
"1",
"&&",
"param",
".",
"tagName",
".",
"toLowerCase",
"(",
")",
"==",
"\"param\"",
"&&",
"param",
"[",
"\"name\"",
"]",
".",
"toLowerCase",
"(",
")",
"==",
"\"flashvars\"",
"&&",
"param",
"[",
"\"value\"",
"]",
".",
"indexOf",
"(",
"searchStr",
")",
">=",
"0",
")",
"{",
"FABridge",
".",
"attachBridge",
"(",
"activeObjects",
"[",
"k",
"]",
",",
"bridgeName",
")",
";",
"flash_found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"flash_found",
")",
"{",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"flash_found",
"&&",
"ael",
">",
"1",
")",
"{",
"for",
"(",
"var",
"m",
"=",
"0",
";",
"m",
"<",
"ael",
";",
"m",
"++",
")",
"{",
"var",
"flashVars",
"=",
"activeEmbeds",
"[",
"m",
"]",
".",
"attributes",
".",
"getNamedItem",
"(",
"\"flashVars\"",
")",
".",
"nodeValue",
";",
"if",
"(",
"flashVars",
".",
"indexOf",
"(",
"searchStr",
")",
">=",
"0",
")",
"{",
"FABridge",
".",
"attachBridge",
"(",
"activeEmbeds",
"[",
"m",
"]",
",",
"bridgeName",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | updated for changes to SWFObject2 | [
"updated",
"for",
"changes",
"to",
"SWFObject2"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1029-L1088 |
56,323 | 5long/roil | src/console/socket.io.js | function(objRef, propName)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.getPropFromAS(objRef, propName);
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | javascript | function(objRef, propName)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.getPropFromAS(objRef, propName);
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | [
"function",
"(",
"objRef",
",",
"propName",
")",
"{",
"if",
"(",
"FABridge",
".",
"refCount",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.\"",
")",
";",
"}",
"else",
"{",
"FABridge",
".",
"refCount",
"++",
";",
"retVal",
"=",
"this",
".",
"target",
".",
"getPropFromAS",
"(",
"objRef",
",",
"propName",
")",
";",
"retVal",
"=",
"this",
".",
"handleError",
"(",
"retVal",
")",
";",
"FABridge",
".",
"refCount",
"--",
";",
"return",
"retVal",
";",
"}",
"}"
] | low level access to the flash object get a named property from an AS object | [
"low",
"level",
"access",
"to",
"the",
"flash",
"object",
"get",
"a",
"named",
"property",
"from",
"an",
"AS",
"object"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1181-L1195 |
|
56,324 | 5long/roil | src/console/socket.io.js | function(objRef,propName, value)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | javascript | function(objRef,propName, value)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | [
"function",
"(",
"objRef",
",",
"propName",
",",
"value",
")",
"{",
"if",
"(",
"FABridge",
".",
"refCount",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.\"",
")",
";",
"}",
"else",
"{",
"FABridge",
".",
"refCount",
"++",
";",
"retVal",
"=",
"this",
".",
"target",
".",
"setPropInAS",
"(",
"objRef",
",",
"propName",
",",
"this",
".",
"serialize",
"(",
"value",
")",
")",
";",
"retVal",
"=",
"this",
".",
"handleError",
"(",
"retVal",
")",
";",
"FABridge",
".",
"refCount",
"--",
";",
"return",
"retVal",
";",
"}",
"}"
] | set a named property on an AS object | [
"set",
"a",
"named",
"property",
"on",
"an",
"AS",
"object"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1197-L1211 |
|
56,325 | 5long/roil | src/console/socket.io.js | function(funcID, args)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.invokeASFunction(funcID, this.serialize(args));
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | javascript | function(funcID, args)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
retVal = this.target.invokeASFunction(funcID, this.serialize(args));
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | [
"function",
"(",
"funcID",
",",
"args",
")",
"{",
"if",
"(",
"FABridge",
".",
"refCount",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.\"",
")",
";",
"}",
"else",
"{",
"FABridge",
".",
"refCount",
"++",
";",
"retVal",
"=",
"this",
".",
"target",
".",
"invokeASFunction",
"(",
"funcID",
",",
"this",
".",
"serialize",
"(",
"args",
")",
")",
";",
"retVal",
"=",
"this",
".",
"handleError",
"(",
"retVal",
")",
";",
"FABridge",
".",
"refCount",
"--",
";",
"return",
"retVal",
";",
"}",
"}"
] | call an AS function | [
"call",
"an",
"AS",
"function"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1214-L1228 |
|
56,326 | 5long/roil | src/console/socket.io.js | function(objID, funcName, args)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
args = this.serialize(args);
retVal = this.target.invokeASMethod(objID, funcName, args);
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | javascript | function(objID, funcName, args)
{
if (FABridge.refCount > 0)
{
throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
}
else
{
FABridge.refCount++;
args = this.serialize(args);
retVal = this.target.invokeASMethod(objID, funcName, args);
retVal = this.handleError(retVal);
FABridge.refCount--;
return retVal;
}
} | [
"function",
"(",
"objID",
",",
"funcName",
",",
"args",
")",
"{",
"if",
"(",
"FABridge",
".",
"refCount",
">",
"0",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.\"",
")",
";",
"}",
"else",
"{",
"FABridge",
".",
"refCount",
"++",
";",
"args",
"=",
"this",
".",
"serialize",
"(",
"args",
")",
";",
"retVal",
"=",
"this",
".",
"target",
".",
"invokeASMethod",
"(",
"objID",
",",
"funcName",
",",
"args",
")",
";",
"retVal",
"=",
"this",
".",
"handleError",
"(",
"retVal",
")",
";",
"FABridge",
".",
"refCount",
"--",
";",
"return",
"retVal",
";",
"}",
"}"
] | call a method on an AS object | [
"call",
"a",
"method",
"on",
"an",
"AS",
"object"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1230-L1245 |
|
56,327 | 5long/roil | src/console/socket.io.js | function(funcID, args)
{
var result;
var func = this.localFunctionCache[funcID];
if(func != undefined)
{
result = this.serialize(func.apply(null, this.deserialize(args)));
}
return result;
} | javascript | function(funcID, args)
{
var result;
var func = this.localFunctionCache[funcID];
if(func != undefined)
{
result = this.serialize(func.apply(null, this.deserialize(args)));
}
return result;
} | [
"function",
"(",
"funcID",
",",
"args",
")",
"{",
"var",
"result",
";",
"var",
"func",
"=",
"this",
".",
"localFunctionCache",
"[",
"funcID",
"]",
";",
"if",
"(",
"func",
"!=",
"undefined",
")",
"{",
"result",
"=",
"this",
".",
"serialize",
"(",
"func",
".",
"apply",
"(",
"null",
",",
"this",
".",
"deserialize",
"(",
"args",
")",
")",
")",
";",
"}",
"return",
"result",
";",
"}"
] | callback from flash that executes a local JS function used mostly when setting js functions as callbacks on events | [
"callback",
"from",
"flash",
"that",
"executes",
"a",
"local",
"JS",
"function",
"used",
"mostly",
"when",
"setting",
"js",
"functions",
"as",
"callbacks",
"on",
"events"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1251-L1262 |
|
56,328 | 5long/roil | src/console/socket.io.js | function(objID, typeName)
{
var objType = this.getTypeFromName(typeName);
instanceFactory.prototype = objType;
var instance = new instanceFactory(objID);
this.remoteInstanceCache[objID] = instance;
return instance;
} | javascript | function(objID, typeName)
{
var objType = this.getTypeFromName(typeName);
instanceFactory.prototype = objType;
var instance = new instanceFactory(objID);
this.remoteInstanceCache[objID] = instance;
return instance;
} | [
"function",
"(",
"objID",
",",
"typeName",
")",
"{",
"var",
"objType",
"=",
"this",
".",
"getTypeFromName",
"(",
"typeName",
")",
";",
"instanceFactory",
".",
"prototype",
"=",
"objType",
";",
"var",
"instance",
"=",
"new",
"instanceFactory",
"(",
"objID",
")",
";",
"this",
".",
"remoteInstanceCache",
"[",
"objID",
"]",
"=",
"instance",
";",
"return",
"instance",
";",
"}"
] | create an AS proxy for the given object ID and type | [
"create",
"an",
"AS",
"proxy",
"for",
"the",
"given",
"object",
"ID",
"and",
"type"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1272-L1279 |
|
56,329 | 5long/roil | src/console/socket.io.js | function(typeData)
{
var newType = new ASProxy(this, typeData.name);
var accessors = typeData.accessors;
for (var i = 0; i < accessors.length; i++)
{
this.addPropertyToType(newType, accessors[i]);
}
var methods = typeData.methods;
for (var i = 0; i < methods.length; i++)
{
if (FABridge.blockedMethods[methods[i]] == undefined)
{
this.addMethodToType(newType, methods[i]);
}
}
this.remoteTypeCache[newType.typeName] = newType;
return newType;
} | javascript | function(typeData)
{
var newType = new ASProxy(this, typeData.name);
var accessors = typeData.accessors;
for (var i = 0; i < accessors.length; i++)
{
this.addPropertyToType(newType, accessors[i]);
}
var methods = typeData.methods;
for (var i = 0; i < methods.length; i++)
{
if (FABridge.blockedMethods[methods[i]] == undefined)
{
this.addMethodToType(newType, methods[i]);
}
}
this.remoteTypeCache[newType.typeName] = newType;
return newType;
} | [
"function",
"(",
"typeData",
")",
"{",
"var",
"newType",
"=",
"new",
"ASProxy",
"(",
"this",
",",
"typeData",
".",
"name",
")",
";",
"var",
"accessors",
"=",
"typeData",
".",
"accessors",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"accessors",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"addPropertyToType",
"(",
"newType",
",",
"accessors",
"[",
"i",
"]",
")",
";",
"}",
"var",
"methods",
"=",
"typeData",
".",
"methods",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"methods",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"FABridge",
".",
"blockedMethods",
"[",
"methods",
"[",
"i",
"]",
"]",
"==",
"undefined",
")",
"{",
"this",
".",
"addMethodToType",
"(",
"newType",
",",
"methods",
"[",
"i",
"]",
")",
";",
"}",
"}",
"this",
".",
"remoteTypeCache",
"[",
"newType",
".",
"typeName",
"]",
"=",
"newType",
";",
"return",
"newType",
";",
"}"
] | accepts a type structure, returns a constructed type | [
"accepts",
"a",
"type",
"structure",
"returns",
"a",
"constructed",
"type"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1287-L1308 |
|
56,330 | 5long/roil | src/console/socket.io.js | function(ty, propName)
{
var c = propName.charAt(0);
var setterName;
var getterName;
if(c >= "a" && c <= "z")
{
getterName = "get" + c.toUpperCase() + propName.substr(1);
setterName = "set" + c.toUpperCase() + propName.substr(1);
}
else
{
getterName = "get" + propName;
setterName = "set" + propName;
}
ty[setterName] = function(val)
{
this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
}
ty[getterName] = function()
{
return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
}
} | javascript | function(ty, propName)
{
var c = propName.charAt(0);
var setterName;
var getterName;
if(c >= "a" && c <= "z")
{
getterName = "get" + c.toUpperCase() + propName.substr(1);
setterName = "set" + c.toUpperCase() + propName.substr(1);
}
else
{
getterName = "get" + propName;
setterName = "set" + propName;
}
ty[setterName] = function(val)
{
this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
}
ty[getterName] = function()
{
return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
}
} | [
"function",
"(",
"ty",
",",
"propName",
")",
"{",
"var",
"c",
"=",
"propName",
".",
"charAt",
"(",
"0",
")",
";",
"var",
"setterName",
";",
"var",
"getterName",
";",
"if",
"(",
"c",
">=",
"\"a\"",
"&&",
"c",
"<=",
"\"z\"",
")",
"{",
"getterName",
"=",
"\"get\"",
"+",
"c",
".",
"toUpperCase",
"(",
")",
"+",
"propName",
".",
"substr",
"(",
"1",
")",
";",
"setterName",
"=",
"\"set\"",
"+",
"c",
".",
"toUpperCase",
"(",
")",
"+",
"propName",
".",
"substr",
"(",
"1",
")",
";",
"}",
"else",
"{",
"getterName",
"=",
"\"get\"",
"+",
"propName",
";",
"setterName",
"=",
"\"set\"",
"+",
"propName",
";",
"}",
"ty",
"[",
"setterName",
"]",
"=",
"function",
"(",
"val",
")",
"{",
"this",
".",
"bridge",
".",
"setPropertyInAS",
"(",
"this",
".",
"fb_instance_id",
",",
"propName",
",",
"val",
")",
";",
"}",
"ty",
"[",
"getterName",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"this",
".",
"bridge",
".",
"deserialize",
"(",
"this",
".",
"bridge",
".",
"getPropertyFromAS",
"(",
"this",
".",
"fb_instance_id",
",",
"propName",
")",
")",
";",
"}",
"}"
] | add a property to a typename; used to define the properties that can be called on an AS proxied object | [
"add",
"a",
"property",
"to",
"a",
"typename",
";",
"used",
"to",
"define",
"the",
"properties",
"that",
"can",
"be",
"called",
"on",
"an",
"AS",
"proxied",
"object"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1311-L1334 |
|
56,331 | 5long/roil | src/console/socket.io.js | function(ty, methodName)
{
ty[methodName] = function()
{
return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
}
} | javascript | function(ty, methodName)
{
ty[methodName] = function()
{
return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
}
} | [
"function",
"(",
"ty",
",",
"methodName",
")",
"{",
"ty",
"[",
"methodName",
"]",
"=",
"function",
"(",
")",
"{",
"return",
"this",
".",
"bridge",
".",
"deserialize",
"(",
"this",
".",
"bridge",
".",
"callASMethod",
"(",
"this",
".",
"fb_instance_id",
",",
"methodName",
",",
"FABridge",
".",
"argsToArray",
"(",
"arguments",
")",
")",
")",
";",
"}",
"}"
] | add a method to a typename; used to define the methods that can be callefd on an AS proxied object | [
"add",
"a",
"method",
"to",
"a",
"typename",
";",
"used",
"to",
"define",
"the",
"methods",
"that",
"can",
"be",
"callefd",
"on",
"an",
"AS",
"proxied",
"object"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1337-L1343 |
|
56,332 | 5long/roil | src/console/socket.io.js | function(funcID)
{
var bridge = this;
if (this.remoteFunctionCache[funcID] == null)
{
this.remoteFunctionCache[funcID] = function()
{
bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
}
}
return this.remoteFunctionCache[funcID];
} | javascript | function(funcID)
{
var bridge = this;
if (this.remoteFunctionCache[funcID] == null)
{
this.remoteFunctionCache[funcID] = function()
{
bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
}
}
return this.remoteFunctionCache[funcID];
} | [
"function",
"(",
"funcID",
")",
"{",
"var",
"bridge",
"=",
"this",
";",
"if",
"(",
"this",
".",
"remoteFunctionCache",
"[",
"funcID",
"]",
"==",
"null",
")",
"{",
"this",
".",
"remoteFunctionCache",
"[",
"funcID",
"]",
"=",
"function",
"(",
")",
"{",
"bridge",
".",
"callASFunction",
"(",
"funcID",
",",
"FABridge",
".",
"argsToArray",
"(",
"arguments",
")",
")",
";",
"}",
"}",
"return",
"this",
".",
"remoteFunctionCache",
"[",
"funcID",
"]",
";",
"}"
] | Function Proxies returns the AS proxy for the specified function ID | [
"Function",
"Proxies",
"returns",
"the",
"AS",
"proxy",
"for",
"the",
"specified",
"function",
"ID"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1348-L1359 |
|
56,333 | 5long/roil | src/console/socket.io.js | function(func)
{
if (func.__bridge_id__ == undefined)
{
func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
this.localFunctionCache[func.__bridge_id__] = func;
}
return func.__bridge_id__;
} | javascript | function(func)
{
if (func.__bridge_id__ == undefined)
{
func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
this.localFunctionCache[func.__bridge_id__] = func;
}
return func.__bridge_id__;
} | [
"function",
"(",
"func",
")",
"{",
"if",
"(",
"func",
".",
"__bridge_id__",
"==",
"undefined",
")",
"{",
"func",
".",
"__bridge_id__",
"=",
"this",
".",
"makeID",
"(",
"this",
".",
"nextLocalFuncID",
"++",
")",
";",
"this",
".",
"localFunctionCache",
"[",
"func",
".",
"__bridge_id__",
"]",
"=",
"func",
";",
"}",
"return",
"func",
".",
"__bridge_id__",
";",
"}"
] | reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache | [
"reutrns",
"the",
"ID",
"of",
"the",
"given",
"function",
";",
"if",
"it",
"doesnt",
"exist",
"it",
"is",
"created",
"and",
"added",
"to",
"the",
"local",
"cache"
] | 37b14072a7aea17accc7f4e5e04dedc90a1358de | https://github.com/5long/roil/blob/37b14072a7aea17accc7f4e5e04dedc90a1358de/src/console/socket.io.js#L1362-L1370 |
|
56,334 | tracker1/mssql-ng | src/connections/shadow-close.js | shadowClose | function shadowClose(connection) {
debug('shadowClose', 'start');
let close = connection.close;
connection.close = function() {
debug('connection.close','start');
//remove references
delete promises[connection._mssqlngKey];
delete connections[connection._mssqlngKey];
//close original connection
setImmediate(()=>{
try {
debug('connection.close','apply');
close.apply(connection);
debug('connection.close','applied');
//clear local references - allow GC
close = null;
connection - null;
}catch(err){}
});
debug('connection.close','end');
}
} | javascript | function shadowClose(connection) {
debug('shadowClose', 'start');
let close = connection.close;
connection.close = function() {
debug('connection.close','start');
//remove references
delete promises[connection._mssqlngKey];
delete connections[connection._mssqlngKey];
//close original connection
setImmediate(()=>{
try {
debug('connection.close','apply');
close.apply(connection);
debug('connection.close','applied');
//clear local references - allow GC
close = null;
connection - null;
}catch(err){}
});
debug('connection.close','end');
}
} | [
"function",
"shadowClose",
"(",
"connection",
")",
"{",
"debug",
"(",
"'shadowClose'",
",",
"'start'",
")",
";",
"let",
"close",
"=",
"connection",
".",
"close",
";",
"connection",
".",
"close",
"=",
"function",
"(",
")",
"{",
"debug",
"(",
"'connection.close'",
",",
"'start'",
")",
";",
"//remove references",
"delete",
"promises",
"[",
"connection",
".",
"_mssqlngKey",
"]",
";",
"delete",
"connections",
"[",
"connection",
".",
"_mssqlngKey",
"]",
";",
"//close original connection",
"setImmediate",
"(",
"(",
")",
"=>",
"{",
"try",
"{",
"debug",
"(",
"'connection.close'",
",",
"'apply'",
")",
";",
"close",
".",
"apply",
"(",
"connection",
")",
";",
"debug",
"(",
"'connection.close'",
",",
"'applied'",
")",
";",
"//clear local references - allow GC",
"close",
"=",
"null",
";",
"connection",
"-",
"null",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"}",
"}",
")",
";",
"debug",
"(",
"'connection.close'",
",",
"'end'",
")",
";",
"}",
"}"
] | shadow the close method, so that it will clear itself from the pool | [
"shadow",
"the",
"close",
"method",
"so",
"that",
"it",
"will",
"clear",
"itself",
"from",
"the",
"pool"
] | 7f32135d33f9b8324fdd94656136cae4087464ce | https://github.com/tracker1/mssql-ng/blob/7f32135d33f9b8324fdd94656136cae4087464ce/src/connections/shadow-close.js#L7-L31 |
56,335 | jl-/gulp-docy | jsdoc.js | function (infos, name) {
name = name || 'jsdoc.json';
var firstFile = null;
var readme = null;
var wp = new Parser(infos);
var bufferFiles = function(file, enc, next){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-jsdoc', 'Streaming not supported'));
// Store firstFile to get a base and cwd later on
if (!firstFile)
firstFile = file;
if (/[.]js$/i.test(file.path))
wp.parse(file);
else if(/readme(?:[.]md)?$/i.test(file.path))
readme = marked(file.contents.toString('utf8'));
next();
};
var endStream = function(conclude){
// Nothing? Exit right away
if (!firstFile){
conclude();
return;
}
var data;
try{
data = JSON.stringify(wp.complete(), null, 2);
// data = parser(options, filemap));
}catch(e){
return this.emit('error', new PluginError('gulp-jsdoc',
'Oooooh! Failed parsing with jsdoc. What did you do?! ' + e));
}
// Pump-up the generated output
var vinyl = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, name),
contents: new Buffer(data)
});
// Possibly stack-up the readme, if there was any in the first place
vinyl.readme = readme;
// Add that to the stream...
this.push(vinyl);
conclude();
};
// That's it for the parser
return through2.obj(bufferFiles, endStream);
} | javascript | function (infos, name) {
name = name || 'jsdoc.json';
var firstFile = null;
var readme = null;
var wp = new Parser(infos);
var bufferFiles = function(file, enc, next){
if (file.isNull()) return; // ignore
if (file.isStream()) return this.emit('error', new PluginError('gulp-jsdoc', 'Streaming not supported'));
// Store firstFile to get a base and cwd later on
if (!firstFile)
firstFile = file;
if (/[.]js$/i.test(file.path))
wp.parse(file);
else if(/readme(?:[.]md)?$/i.test(file.path))
readme = marked(file.contents.toString('utf8'));
next();
};
var endStream = function(conclude){
// Nothing? Exit right away
if (!firstFile){
conclude();
return;
}
var data;
try{
data = JSON.stringify(wp.complete(), null, 2);
// data = parser(options, filemap));
}catch(e){
return this.emit('error', new PluginError('gulp-jsdoc',
'Oooooh! Failed parsing with jsdoc. What did you do?! ' + e));
}
// Pump-up the generated output
var vinyl = new File({
cwd: firstFile.cwd,
base: firstFile.base,
path: path.join(firstFile.base, name),
contents: new Buffer(data)
});
// Possibly stack-up the readme, if there was any in the first place
vinyl.readme = readme;
// Add that to the stream...
this.push(vinyl);
conclude();
};
// That's it for the parser
return through2.obj(bufferFiles, endStream);
} | [
"function",
"(",
"infos",
",",
"name",
")",
"{",
"name",
"=",
"name",
"||",
"'jsdoc.json'",
";",
"var",
"firstFile",
"=",
"null",
";",
"var",
"readme",
"=",
"null",
";",
"var",
"wp",
"=",
"new",
"Parser",
"(",
"infos",
")",
";",
"var",
"bufferFiles",
"=",
"function",
"(",
"file",
",",
"enc",
",",
"next",
")",
"{",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"return",
";",
"// ignore\r",
"if",
"(",
"file",
".",
"isStream",
"(",
")",
")",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"'gulp-jsdoc'",
",",
"'Streaming not supported'",
")",
")",
";",
"// Store firstFile to get a base and cwd later on\r",
"if",
"(",
"!",
"firstFile",
")",
"firstFile",
"=",
"file",
";",
"if",
"(",
"/",
"[.]js$",
"/",
"i",
".",
"test",
"(",
"file",
".",
"path",
")",
")",
"wp",
".",
"parse",
"(",
"file",
")",
";",
"else",
"if",
"(",
"/",
"readme(?:[.]md)?$",
"/",
"i",
".",
"test",
"(",
"file",
".",
"path",
")",
")",
"readme",
"=",
"marked",
"(",
"file",
".",
"contents",
".",
"toString",
"(",
"'utf8'",
")",
")",
";",
"next",
"(",
")",
";",
"}",
";",
"var",
"endStream",
"=",
"function",
"(",
"conclude",
")",
"{",
"// Nothing? Exit right away\r",
"if",
"(",
"!",
"firstFile",
")",
"{",
"conclude",
"(",
")",
";",
"return",
";",
"}",
"var",
"data",
";",
"try",
"{",
"data",
"=",
"JSON",
".",
"stringify",
"(",
"wp",
".",
"complete",
"(",
")",
",",
"null",
",",
"2",
")",
";",
"// data = parser(options, filemap));\r",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"'gulp-jsdoc'",
",",
"'Oooooh! Failed parsing with jsdoc. What did you do?! '",
"+",
"e",
")",
")",
";",
"}",
"// Pump-up the generated output\r",
"var",
"vinyl",
"=",
"new",
"File",
"(",
"{",
"cwd",
":",
"firstFile",
".",
"cwd",
",",
"base",
":",
"firstFile",
".",
"base",
",",
"path",
":",
"path",
".",
"join",
"(",
"firstFile",
".",
"base",
",",
"name",
")",
",",
"contents",
":",
"new",
"Buffer",
"(",
"data",
")",
"}",
")",
";",
"// Possibly stack-up the readme, if there was any in the first place\r",
"vinyl",
".",
"readme",
"=",
"readme",
";",
"// Add that to the stream...\r",
"this",
".",
"push",
"(",
"vinyl",
")",
";",
"conclude",
"(",
")",
";",
"}",
";",
"// That's it for the parser\r",
"return",
"through2",
".",
"obj",
"(",
"bufferFiles",
",",
"endStream",
")",
";",
"}"
] | That's the plugin parser | [
"That",
"s",
"the",
"plugin",
"parser"
] | 40c2ba2da57c8ddb0a877340acc9a0604b1bafb4 | https://github.com/jl-/gulp-docy/blob/40c2ba2da57c8ddb0a877340acc9a0604b1bafb4/jsdoc.js#L29-L88 |
|
56,336 | RnbWd/parse-browserify | lib/collection.js | function(model, options) {
if (!(model instanceof Parse.Object)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
if (!model._validate(model.attributes, options)) {
model = false;
}
} else if (!model.collection) {
model.collection = this;
}
return model;
} | javascript | function(model, options) {
if (!(model instanceof Parse.Object)) {
var attrs = model;
options.collection = this;
model = new this.model(attrs, options);
if (!model._validate(model.attributes, options)) {
model = false;
}
} else if (!model.collection) {
model.collection = this;
}
return model;
} | [
"function",
"(",
"model",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"model",
"instanceof",
"Parse",
".",
"Object",
")",
")",
"{",
"var",
"attrs",
"=",
"model",
";",
"options",
".",
"collection",
"=",
"this",
";",
"model",
"=",
"new",
"this",
".",
"model",
"(",
"attrs",
",",
"options",
")",
";",
"if",
"(",
"!",
"model",
".",
"_validate",
"(",
"model",
".",
"attributes",
",",
"options",
")",
")",
"{",
"model",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"model",
".",
"collection",
")",
"{",
"model",
".",
"collection",
"=",
"this",
";",
"}",
"return",
"model",
";",
"}"
] | Prepare a model or hash of attributes to be added to this collection. | [
"Prepare",
"a",
"model",
"or",
"hash",
"of",
"attributes",
"to",
"be",
"added",
"to",
"this",
"collection",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/collection.js#L372-L384 |
|
56,337 | d08ble/livecomment | livecomment.js | _configGetExtLang | function _configGetExtLang(filext) {
var fileext1 = filext.indexOf('.') == 0 ? fileext.substring(1, filext.length) : fileext;
if (!config.extlangs.hasOwnProperty(fileext1))
return null;
return config.extlangs[fileext1];
} | javascript | function _configGetExtLang(filext) {
var fileext1 = filext.indexOf('.') == 0 ? fileext.substring(1, filext.length) : fileext;
if (!config.extlangs.hasOwnProperty(fileext1))
return null;
return config.extlangs[fileext1];
} | [
"function",
"_configGetExtLang",
"(",
"filext",
")",
"{",
"var",
"fileext1",
"=",
"filext",
".",
"indexOf",
"(",
"'.'",
")",
"==",
"0",
"?",
"fileext",
".",
"substring",
"(",
"1",
",",
"filext",
".",
"length",
")",
":",
"fileext",
";",
"if",
"(",
"!",
"config",
".",
"extlangs",
".",
"hasOwnProperty",
"(",
"fileext1",
")",
")",
"return",
"null",
";",
"return",
"config",
".",
"extlangs",
"[",
"fileext1",
"]",
";",
"}"
] | CHECK EXTLANG [ | [
"CHECK",
"EXTLANG",
"["
] | 9c4a00878101501411668070b4f6e7719e10d1fd | https://github.com/d08ble/livecomment/blob/9c4a00878101501411668070b4f6e7719e10d1fd/livecomment.js#L750-L756 |
56,338 | d08ble/livecomment | livecomment.js | extractCommentTagFromLine | function extractCommentTagFromLine(fileext, line) {
line = line.trim();
// CHECK FORMAT [
var b;
function chkfmt(b) {
if (line.indexOf(b) == 0 && line.indexOf('[') == line.length-1) // begin
return [line.substr(b.length, line.length-b.length-1).trim(), 0];
if (line.indexOf(b) == 0 && line.indexOf(']') == line.length-1 && line.indexOf('[') == -1) // end
return [line.substr(b.length, line.length-b.length-1).trim(), 1];
return null;
};
// CHECK FORMAT ]
// SUPPORT FORMATS [
switch (fileext) {
case '.js':
case '.java':
case '.c':
case '.h':
case '.cpp':
case '.hpp':
case '.less':
case '.m':
case '.mm':
return chkfmt('//') || false;
case '.css':
return chkfmt('/*') || false;
case '.acpul':
case '.sh':
case '.py':
case '.pro':
return chkfmt('#') || false;
case '.ejs':
case '.jade':
case '.sass':
case '.styl':
case '.coffee':
break;
default:
return null;
}
// SUPPORT FORMATS ]
return false;
} | javascript | function extractCommentTagFromLine(fileext, line) {
line = line.trim();
// CHECK FORMAT [
var b;
function chkfmt(b) {
if (line.indexOf(b) == 0 && line.indexOf('[') == line.length-1) // begin
return [line.substr(b.length, line.length-b.length-1).trim(), 0];
if (line.indexOf(b) == 0 && line.indexOf(']') == line.length-1 && line.indexOf('[') == -1) // end
return [line.substr(b.length, line.length-b.length-1).trim(), 1];
return null;
};
// CHECK FORMAT ]
// SUPPORT FORMATS [
switch (fileext) {
case '.js':
case '.java':
case '.c':
case '.h':
case '.cpp':
case '.hpp':
case '.less':
case '.m':
case '.mm':
return chkfmt('//') || false;
case '.css':
return chkfmt('/*') || false;
case '.acpul':
case '.sh':
case '.py':
case '.pro':
return chkfmt('#') || false;
case '.ejs':
case '.jade':
case '.sass':
case '.styl':
case '.coffee':
break;
default:
return null;
}
// SUPPORT FORMATS ]
return false;
} | [
"function",
"extractCommentTagFromLine",
"(",
"fileext",
",",
"line",
")",
"{",
"line",
"=",
"line",
".",
"trim",
"(",
")",
";",
"// CHECK FORMAT [",
"var",
"b",
";",
"function",
"chkfmt",
"(",
"b",
")",
"{",
"if",
"(",
"line",
".",
"indexOf",
"(",
"b",
")",
"==",
"0",
"&&",
"line",
".",
"indexOf",
"(",
"'['",
")",
"==",
"line",
".",
"length",
"-",
"1",
")",
"// begin",
"return",
"[",
"line",
".",
"substr",
"(",
"b",
".",
"length",
",",
"line",
".",
"length",
"-",
"b",
".",
"length",
"-",
"1",
")",
".",
"trim",
"(",
")",
",",
"0",
"]",
";",
"if",
"(",
"line",
".",
"indexOf",
"(",
"b",
")",
"==",
"0",
"&&",
"line",
".",
"indexOf",
"(",
"']'",
")",
"==",
"line",
".",
"length",
"-",
"1",
"&&",
"line",
".",
"indexOf",
"(",
"'['",
")",
"==",
"-",
"1",
")",
"// end",
"return",
"[",
"line",
".",
"substr",
"(",
"b",
".",
"length",
",",
"line",
".",
"length",
"-",
"b",
".",
"length",
"-",
"1",
")",
".",
"trim",
"(",
")",
",",
"1",
"]",
";",
"return",
"null",
";",
"}",
";",
"// CHECK FORMAT ]",
"// SUPPORT FORMATS [",
"switch",
"(",
"fileext",
")",
"{",
"case",
"'.js'",
":",
"case",
"'.java'",
":",
"case",
"'.c'",
":",
"case",
"'.h'",
":",
"case",
"'.cpp'",
":",
"case",
"'.hpp'",
":",
"case",
"'.less'",
":",
"case",
"'.m'",
":",
"case",
"'.mm'",
":",
"return",
"chkfmt",
"(",
"'//'",
")",
"||",
"false",
";",
"case",
"'.css'",
":",
"return",
"chkfmt",
"(",
"'/*'",
")",
"||",
"false",
";",
"case",
"'.acpul'",
":",
"case",
"'.sh'",
":",
"case",
"'.py'",
":",
"case",
"'.pro'",
":",
"return",
"chkfmt",
"(",
"'#'",
")",
"||",
"false",
";",
"case",
"'.ejs'",
":",
"case",
"'.jade'",
":",
"case",
"'.sass'",
":",
"case",
"'.styl'",
":",
"case",
"'.coffee'",
":",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"// SUPPORT FORMATS ]",
"return",
"false",
";",
"}"
] | custom comment format use config.extractCommentTagFromLine [ | [
"custom",
"comment",
"format",
"use",
"config",
".",
"extractCommentTagFromLine",
"["
] | 9c4a00878101501411668070b4f6e7719e10d1fd | https://github.com/d08ble/livecomment/blob/9c4a00878101501411668070b4f6e7719e10d1fd/livecomment.js#L778-L821 |
56,339 | RnbWd/parse-browserify | lib/analytics.js | function(name, dimensions) {
name = name || '';
name = name.replace(/^\s*/, '');
name = name.replace(/\s*$/, '');
if (name.length === 0) {
throw 'A name for the custom event must be provided';
}
_.each(dimensions, function(val, key) {
if (!_.isString(key) || !_.isString(val)) {
throw 'track() dimensions expects keys and values of type "string".';
}
});
return Parse._request({
route: 'events',
className: name,
method: 'POST',
data: { dimensions: dimensions }
});
} | javascript | function(name, dimensions) {
name = name || '';
name = name.replace(/^\s*/, '');
name = name.replace(/\s*$/, '');
if (name.length === 0) {
throw 'A name for the custom event must be provided';
}
_.each(dimensions, function(val, key) {
if (!_.isString(key) || !_.isString(val)) {
throw 'track() dimensions expects keys and values of type "string".';
}
});
return Parse._request({
route: 'events',
className: name,
method: 'POST',
data: { dimensions: dimensions }
});
} | [
"function",
"(",
"name",
",",
"dimensions",
")",
"{",
"name",
"=",
"name",
"||",
"''",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"/",
"^\\s*",
"/",
",",
"''",
")",
";",
"name",
"=",
"name",
".",
"replace",
"(",
"/",
"\\s*$",
"/",
",",
"''",
")",
";",
"if",
"(",
"name",
".",
"length",
"===",
"0",
")",
"{",
"throw",
"'A name for the custom event must be provided'",
";",
"}",
"_",
".",
"each",
"(",
"dimensions",
",",
"function",
"(",
"val",
",",
"key",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"key",
")",
"||",
"!",
"_",
".",
"isString",
"(",
"val",
")",
")",
"{",
"throw",
"'track() dimensions expects keys and values of type \"string\".'",
";",
"}",
"}",
")",
";",
"return",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"'events'",
",",
"className",
":",
"name",
",",
"method",
":",
"'POST'",
",",
"data",
":",
"{",
"dimensions",
":",
"dimensions",
"}",
"}",
")",
";",
"}"
] | Tracks the occurrence of a custom event with additional dimensions.
Parse will store a data point at the time of invocation with the given
event name.
Dimensions will allow segmentation of the occurrences of this custom
event. Keys and values should be {@code String}s, and will throw
otherwise.
To track a user signup along with additional metadata, consider the
following:
<pre>
var dimensions = {
gender: 'm',
source: 'web',
dayType: 'weekend'
};
Parse.Analytics.track('signup', dimensions);
</pre>
There is a default limit of 4 dimensions per event tracked.
@param {String} name The name of the custom event to report to Parse as
having happened.
@param {Object} dimensions The dictionary of information by which to
segment this event.
@return {Parse.Promise} A promise that is resolved when the round-trip
to the server completes. | [
"Tracks",
"the",
"occurrence",
"of",
"a",
"custom",
"event",
"with",
"additional",
"dimensions",
".",
"Parse",
"will",
"store",
"a",
"data",
"point",
"at",
"the",
"time",
"of",
"invocation",
"with",
"the",
"given",
"event",
"name",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/analytics.js#L40-L60 |
|
56,340 | relief-melone/limitpromises | src/services/service.retryPromiseTimeout.js | retryPromiseTimeout | function retryPromiseTimeout(PromiseFunc, Obj, Options){
let timeoutOpts = Options.Timeout;
limitpromises = limitpromises || require('../limitpromises');
setTimeout( () => {
if(Obj.isRunning && Obj.attempt <= timeoutOpts.retryAttempts){
// Put a new promise on the same stack as the current one is, so you dont call more promises of one
// group as specified. Input Value is just true as we dont need it and only make one promise
let newPromise = limitpromises( () =>{
return new Promise((resolve, reject) => {
PromiseFunc(Obj.inputValue).then(data => {
resolve(data);
}, err => {
reject(err);
});
});
},[true], Obj.maxAtOnce, Obj.TypeKey);
// Wait for the PromiseArray and either resolve the current promise or handle the rejects
Promise.all(newPromise.map(r => {return r.result})).then(data => {
if(Obj.isRunning){
Obj.resolveResult(data);
}
}, err => {
if(Obj.isRunning){
handleRejects(PromiseFunc, Obj, err, Options);
}
});
// Call the function again to check again after a given time
retryPromiseTimeout(PromiseFunc, Obj, Options);
// Count that an attempt has been made for that object
Obj.attempt++;
// If more retry attempts have been made than specified by the user, reject the result
} else if (Obj.isRunning && Obj.attempt > timeoutOpts.retryAttempts){
Obj.rejectResult(new Error.TimeoutError(Obj));
}
}, timeoutOpts.timeoutMillis);
} | javascript | function retryPromiseTimeout(PromiseFunc, Obj, Options){
let timeoutOpts = Options.Timeout;
limitpromises = limitpromises || require('../limitpromises');
setTimeout( () => {
if(Obj.isRunning && Obj.attempt <= timeoutOpts.retryAttempts){
// Put a new promise on the same stack as the current one is, so you dont call more promises of one
// group as specified. Input Value is just true as we dont need it and only make one promise
let newPromise = limitpromises( () =>{
return new Promise((resolve, reject) => {
PromiseFunc(Obj.inputValue).then(data => {
resolve(data);
}, err => {
reject(err);
});
});
},[true], Obj.maxAtOnce, Obj.TypeKey);
// Wait for the PromiseArray and either resolve the current promise or handle the rejects
Promise.all(newPromise.map(r => {return r.result})).then(data => {
if(Obj.isRunning){
Obj.resolveResult(data);
}
}, err => {
if(Obj.isRunning){
handleRejects(PromiseFunc, Obj, err, Options);
}
});
// Call the function again to check again after a given time
retryPromiseTimeout(PromiseFunc, Obj, Options);
// Count that an attempt has been made for that object
Obj.attempt++;
// If more retry attempts have been made than specified by the user, reject the result
} else if (Obj.isRunning && Obj.attempt > timeoutOpts.retryAttempts){
Obj.rejectResult(new Error.TimeoutError(Obj));
}
}, timeoutOpts.timeoutMillis);
} | [
"function",
"retryPromiseTimeout",
"(",
"PromiseFunc",
",",
"Obj",
",",
"Options",
")",
"{",
"let",
"timeoutOpts",
"=",
"Options",
".",
"Timeout",
";",
"limitpromises",
"=",
"limitpromises",
"||",
"require",
"(",
"'../limitpromises'",
")",
";",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"Obj",
".",
"isRunning",
"&&",
"Obj",
".",
"attempt",
"<=",
"timeoutOpts",
".",
"retryAttempts",
")",
"{",
"// Put a new promise on the same stack as the current one is, so you dont call more promises of one",
"// group as specified. Input Value is just true as we dont need it and only make one promise",
"let",
"newPromise",
"=",
"limitpromises",
"(",
"(",
")",
"=>",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"PromiseFunc",
"(",
"Obj",
".",
"inputValue",
")",
".",
"then",
"(",
"data",
"=>",
"{",
"resolve",
"(",
"data",
")",
";",
"}",
",",
"err",
"=>",
"{",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
",",
"[",
"true",
"]",
",",
"Obj",
".",
"maxAtOnce",
",",
"Obj",
".",
"TypeKey",
")",
";",
"// Wait for the PromiseArray and either resolve the current promise or handle the rejects",
"Promise",
".",
"all",
"(",
"newPromise",
".",
"map",
"(",
"r",
"=>",
"{",
"return",
"r",
".",
"result",
"}",
")",
")",
".",
"then",
"(",
"data",
"=>",
"{",
"if",
"(",
"Obj",
".",
"isRunning",
")",
"{",
"Obj",
".",
"resolveResult",
"(",
"data",
")",
";",
"}",
"}",
",",
"err",
"=>",
"{",
"if",
"(",
"Obj",
".",
"isRunning",
")",
"{",
"handleRejects",
"(",
"PromiseFunc",
",",
"Obj",
",",
"err",
",",
"Options",
")",
";",
"}",
"}",
")",
";",
"// Call the function again to check again after a given time",
"retryPromiseTimeout",
"(",
"PromiseFunc",
",",
"Obj",
",",
"Options",
")",
";",
"// Count that an attempt has been made for that object",
"Obj",
".",
"attempt",
"++",
";",
"// If more retry attempts have been made than specified by the user, reject the result",
"}",
"else",
"if",
"(",
"Obj",
".",
"isRunning",
"&&",
"Obj",
".",
"attempt",
">",
"timeoutOpts",
".",
"retryAttempts",
")",
"{",
"Obj",
".",
"rejectResult",
"(",
"new",
"Error",
".",
"TimeoutError",
"(",
"Obj",
")",
")",
";",
"}",
"}",
",",
"timeoutOpts",
".",
"timeoutMillis",
")",
";",
"}"
] | Handles Timeout of promises
@public
@param {Function} PromiseFunc Function that returns a Promise with one InputParameter that is used
@param {Object} Obj The Object holding the current Promise request
@param {Object} Options Options that have been specified by the user
@returns {void} | [
"Handles",
"Timeout",
"of",
"promises"
] | 1735b92749740204b597c1c6026257d54ade8200 | https://github.com/relief-melone/limitpromises/blob/1735b92749740204b597c1c6026257d54ade8200/src/services/service.retryPromiseTimeout.js#L17-L56 |
56,341 | Zingle/http-later-redis | index.js | queue | function queue(task, done) {
var storage = this,
key = this.keygen(task);
// store task as JSON serialized string
task = JSON.stringify(task);
// first add the key to the queue
this.redis().rpush(this.queueKey(), key, function(err) {
if (err) done(err);
// now store task data
else storage.redis().set(key, task, function(err) {
if (err) done(err);
else done(null, key);
});
});
} | javascript | function queue(task, done) {
var storage = this,
key = this.keygen(task);
// store task as JSON serialized string
task = JSON.stringify(task);
// first add the key to the queue
this.redis().rpush(this.queueKey(), key, function(err) {
if (err) done(err);
// now store task data
else storage.redis().set(key, task, function(err) {
if (err) done(err);
else done(null, key);
});
});
} | [
"function",
"queue",
"(",
"task",
",",
"done",
")",
"{",
"var",
"storage",
"=",
"this",
",",
"key",
"=",
"this",
".",
"keygen",
"(",
"task",
")",
";",
"// store task as JSON serialized string",
"task",
"=",
"JSON",
".",
"stringify",
"(",
"task",
")",
";",
"// first add the key to the queue",
"this",
".",
"redis",
"(",
")",
".",
"rpush",
"(",
"this",
".",
"queueKey",
"(",
")",
",",
"key",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"done",
"(",
"err",
")",
";",
"// now store task data",
"else",
"storage",
".",
"redis",
"(",
")",
".",
"set",
"(",
"key",
",",
"task",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"done",
"(",
"err",
")",
";",
"else",
"done",
"(",
"null",
",",
"key",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Queue a serialized request and pass the storage key to the callback.
@param {object} task
@param {function} done | [
"Queue",
"a",
"serialized",
"request",
"and",
"pass",
"the",
"storage",
"key",
"to",
"the",
"callback",
"."
] | 43008afabb2800400557a66857d41818e22b0623 | https://github.com/Zingle/http-later-redis/blob/43008afabb2800400557a66857d41818e22b0623/index.js#L10-L27 |
56,342 | Zingle/http-later-redis | index.js | unqueue | function unqueue(done) {
var storage = this;
this.redis().lpop(this.queueKey(), function(err, key) {
if (err) return done(err);
storage.redis().get(key, function(err, task) {
if (err) return done(err);
if (!task) return done();
storage.redis().del(key);
done(null, JSON.parse(task), key);
});
});
} | javascript | function unqueue(done) {
var storage = this;
this.redis().lpop(this.queueKey(), function(err, key) {
if (err) return done(err);
storage.redis().get(key, function(err, task) {
if (err) return done(err);
if (!task) return done();
storage.redis().del(key);
done(null, JSON.parse(task), key);
});
});
} | [
"function",
"unqueue",
"(",
"done",
")",
"{",
"var",
"storage",
"=",
"this",
";",
"this",
".",
"redis",
"(",
")",
".",
"lpop",
"(",
"this",
".",
"queueKey",
"(",
")",
",",
"function",
"(",
"err",
",",
"key",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"storage",
".",
"redis",
"(",
")",
".",
"get",
"(",
"key",
",",
"function",
"(",
"err",
",",
"task",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
";",
"if",
"(",
"!",
"task",
")",
"return",
"done",
"(",
")",
";",
"storage",
".",
"redis",
"(",
")",
".",
"del",
"(",
"key",
")",
";",
"done",
"(",
"null",
",",
"JSON",
".",
"parse",
"(",
"task",
")",
",",
"key",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Remove a task from the queue and pass it to the callback.
@param {function} done | [
"Remove",
"a",
"task",
"from",
"the",
"queue",
"and",
"pass",
"it",
"to",
"the",
"callback",
"."
] | 43008afabb2800400557a66857d41818e22b0623 | https://github.com/Zingle/http-later-redis/blob/43008afabb2800400557a66857d41818e22b0623/index.js#L33-L47 |
56,343 | Zingle/http-later-redis | index.js | log | function log(key, result, done) {
var storage = this;
// store result as JSON serialized string
result = JSON.stringify(result);
// generate result key from task key
key = key + "-result";
// first add the key to the log
this.redis().rpush(this.logKey(), key, function(err) {
if (err) done(err);
// now store result data
else storage.redis().set(key, result, done);
});
} | javascript | function log(key, result, done) {
var storage = this;
// store result as JSON serialized string
result = JSON.stringify(result);
// generate result key from task key
key = key + "-result";
// first add the key to the log
this.redis().rpush(this.logKey(), key, function(err) {
if (err) done(err);
// now store result data
else storage.redis().set(key, result, done);
});
} | [
"function",
"log",
"(",
"key",
",",
"result",
",",
"done",
")",
"{",
"var",
"storage",
"=",
"this",
";",
"// store result as JSON serialized string",
"result",
"=",
"JSON",
".",
"stringify",
"(",
"result",
")",
";",
"// generate result key from task key",
"key",
"=",
"key",
"+",
"\"-result\"",
";",
"// first add the key to the log",
"this",
".",
"redis",
"(",
")",
".",
"rpush",
"(",
"this",
".",
"logKey",
"(",
")",
",",
"key",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"done",
"(",
"err",
")",
";",
"// now store result data",
"else",
"storage",
".",
"redis",
"(",
")",
".",
"set",
"(",
"key",
",",
"result",
",",
"done",
")",
";",
"}",
")",
";",
"}"
] | Log task result.
@param {string} key
@param {object} result
@param {function} done | [
"Log",
"task",
"result",
"."
] | 43008afabb2800400557a66857d41818e22b0623 | https://github.com/Zingle/http-later-redis/blob/43008afabb2800400557a66857d41818e22b0623/index.js#L55-L71 |
56,344 | redisjs/jsr-log | lib/logger.js | Logger | function Logger() {
this._level = LEVELS.NOTICE;
this._out = process.stdout;
this._err = process.stderr;
/* istanbul ignore next: allow server to suppress logs */
if(process.env.NODE_ENV === Constants.TEST && !process.env.TEST_DEBUG) {
this.log = function noop(){};
}
} | javascript | function Logger() {
this._level = LEVELS.NOTICE;
this._out = process.stdout;
this._err = process.stderr;
/* istanbul ignore next: allow server to suppress logs */
if(process.env.NODE_ENV === Constants.TEST && !process.env.TEST_DEBUG) {
this.log = function noop(){};
}
} | [
"function",
"Logger",
"(",
")",
"{",
"this",
".",
"_level",
"=",
"LEVELS",
".",
"NOTICE",
";",
"this",
".",
"_out",
"=",
"process",
".",
"stdout",
";",
"this",
".",
"_err",
"=",
"process",
".",
"stderr",
";",
"/* istanbul ignore next: allow server to suppress logs */",
"if",
"(",
"process",
".",
"env",
".",
"NODE_ENV",
"===",
"Constants",
".",
"TEST",
"&&",
"!",
"process",
".",
"env",
".",
"TEST_DEBUG",
")",
"{",
"this",
".",
"log",
"=",
"function",
"noop",
"(",
")",
"{",
"}",
";",
"}",
"}"
] | Create a logger. | [
"Create",
"a",
"logger",
"."
] | a67a34285449b0d731493def58d8a5212aad5526 | https://github.com/redisjs/jsr-log/blob/a67a34285449b0d731493def58d8a5212aad5526/lib/logger.js#L60-L69 |
56,345 | redisjs/jsr-log | lib/logger.js | level | function level(lvl) {
if(!lvl) return this._level;
if(!~LEVELS.indexOf(lvl)) {
throw new Error('invalid log level: ' + lvl);
}
this._level = lvl;
return this._level;
} | javascript | function level(lvl) {
if(!lvl) return this._level;
if(!~LEVELS.indexOf(lvl)) {
throw new Error('invalid log level: ' + lvl);
}
this._level = lvl;
return this._level;
} | [
"function",
"level",
"(",
"lvl",
")",
"{",
"if",
"(",
"!",
"lvl",
")",
"return",
"this",
".",
"_level",
";",
"if",
"(",
"!",
"~",
"LEVELS",
".",
"indexOf",
"(",
"lvl",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'invalid log level: '",
"+",
"lvl",
")",
";",
"}",
"this",
".",
"_level",
"=",
"lvl",
";",
"return",
"this",
".",
"_level",
";",
"}"
] | Get or set the log level. | [
"Get",
"or",
"set",
"the",
"log",
"level",
"."
] | a67a34285449b0d731493def58d8a5212aad5526 | https://github.com/redisjs/jsr-log/blob/a67a34285449b0d731493def58d8a5212aad5526/lib/logger.js#L107-L114 |
56,346 | redisjs/jsr-log | lib/logger.js | warning | function warning() {
var args = [LEVELS.WARNING].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | javascript | function warning() {
var args = [LEVELS.WARNING].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | [
"function",
"warning",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"LEVELS",
".",
"WARNING",
"]",
".",
"concat",
"(",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"return",
"this",
".",
"log",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}"
] | Log a warning message. | [
"Log",
"a",
"warning",
"message",
"."
] | a67a34285449b0d731493def58d8a5212aad5526 | https://github.com/redisjs/jsr-log/blob/a67a34285449b0d731493def58d8a5212aad5526/lib/logger.js#L145-L148 |
56,347 | redisjs/jsr-log | lib/logger.js | notice | function notice() {
var args = [LEVELS.NOTICE].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | javascript | function notice() {
var args = [LEVELS.NOTICE].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | [
"function",
"notice",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"LEVELS",
".",
"NOTICE",
"]",
".",
"concat",
"(",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"return",
"this",
".",
"log",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}"
] | Log a notice message. | [
"Log",
"a",
"notice",
"message",
"."
] | a67a34285449b0d731493def58d8a5212aad5526 | https://github.com/redisjs/jsr-log/blob/a67a34285449b0d731493def58d8a5212aad5526/lib/logger.js#L153-L156 |
56,348 | redisjs/jsr-log | lib/logger.js | verbose | function verbose() {
var args = [LEVELS.VERBOSE].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | javascript | function verbose() {
var args = [LEVELS.VERBOSE].concat(slice.apply(arguments));
return this.log.apply(this, args);
} | [
"function",
"verbose",
"(",
")",
"{",
"var",
"args",
"=",
"[",
"LEVELS",
".",
"VERBOSE",
"]",
".",
"concat",
"(",
"slice",
".",
"apply",
"(",
"arguments",
")",
")",
";",
"return",
"this",
".",
"log",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}"
] | Log a verbose message. | [
"Log",
"a",
"verbose",
"message",
"."
] | a67a34285449b0d731493def58d8a5212aad5526 | https://github.com/redisjs/jsr-log/blob/a67a34285449b0d731493def58d8a5212aad5526/lib/logger.js#L161-L164 |
56,349 | ahwayakchih/serve-files | index.js | createConfiguration | function createConfiguration (options) {
const cfg = Object.assign({
followSymbolicLinks: false,
cacheTimeInSeconds : 0,
documentRoot : process.cwd(),
parsedURLName : 'urlParsed',
getFilePath : getFilePath,
getFileStats : getFileStats,
getResponseData : getResponseData,
standardResponses : null
}, options);
try {
let root = fs.realpathSync(cfg.documentRoot);
cfg.documentRootReal = root;
}
catch (e) {
return e;
}
return cfg;
} | javascript | function createConfiguration (options) {
const cfg = Object.assign({
followSymbolicLinks: false,
cacheTimeInSeconds : 0,
documentRoot : process.cwd(),
parsedURLName : 'urlParsed',
getFilePath : getFilePath,
getFileStats : getFileStats,
getResponseData : getResponseData,
standardResponses : null
}, options);
try {
let root = fs.realpathSync(cfg.documentRoot);
cfg.documentRootReal = root;
}
catch (e) {
return e;
}
return cfg;
} | [
"function",
"createConfiguration",
"(",
"options",
")",
"{",
"const",
"cfg",
"=",
"Object",
".",
"assign",
"(",
"{",
"followSymbolicLinks",
":",
"false",
",",
"cacheTimeInSeconds",
":",
"0",
",",
"documentRoot",
":",
"process",
".",
"cwd",
"(",
")",
",",
"parsedURLName",
":",
"'urlParsed'",
",",
"getFilePath",
":",
"getFilePath",
",",
"getFileStats",
":",
"getFileStats",
",",
"getResponseData",
":",
"getResponseData",
",",
"standardResponses",
":",
"null",
"}",
",",
"options",
")",
";",
"try",
"{",
"let",
"root",
"=",
"fs",
".",
"realpathSync",
"(",
"cfg",
".",
"documentRoot",
")",
";",
"cfg",
".",
"documentRootReal",
"=",
"root",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"e",
";",
"}",
"return",
"cfg",
";",
"}"
] | Configuration object.
@typedef {Object} configuration
@property {boolean} followSymbolicLinks=false
@property {number} cacheTimeInSeconds=0
@property {string} documentRoot=process.cwd()
@property {string} parsedURLName='urlParsed'
@property {Function} getFilePath
@property {Function} getFileStats
@property {Function} getResponseData
@property {Function[]} standardResponses=null
Prepare configuration object.
@param {Object} options Check properties of {@link module:serve-files~configuration}
@return {module:serve-files~configuration} | [
"Configuration",
"object",
"."
] | cd949252a37210bec229146ab519534ef641e942 | https://github.com/ahwayakchih/serve-files/blob/cd949252a37210bec229146ab519534ef641e942/index.js#L67-L88 |
56,350 | ahwayakchih/serve-files | index.js | getFileStats | function getFileStats (cfg, filePath, callback) {
fs.realpath(filePath, function (err, realpath) {
// On Windows we can get different cases for the same disk letter :/.
let checkPath = realpath;
if (os.platform() === 'win32' && realpath) {
checkPath = realpath.toLowerCase();
}
if (err || checkPath.indexOf(cfg.documentRootReal) !== 0) {
return callback(err || new Error('Access denied'));
}
fs[cfg.followSymbolicLinks ? 'stat' : 'lstat'](filePath, function (err, stats) {
if (err || !stats.isFile()) {
return callback(err || new Error('Access denied'));
}
stats.path = realpath;
callback(null, stats);
});
});
} | javascript | function getFileStats (cfg, filePath, callback) {
fs.realpath(filePath, function (err, realpath) {
// On Windows we can get different cases for the same disk letter :/.
let checkPath = realpath;
if (os.platform() === 'win32' && realpath) {
checkPath = realpath.toLowerCase();
}
if (err || checkPath.indexOf(cfg.documentRootReal) !== 0) {
return callback(err || new Error('Access denied'));
}
fs[cfg.followSymbolicLinks ? 'stat' : 'lstat'](filePath, function (err, stats) {
if (err || !stats.isFile()) {
return callback(err || new Error('Access denied'));
}
stats.path = realpath;
callback(null, stats);
});
});
} | [
"function",
"getFileStats",
"(",
"cfg",
",",
"filePath",
",",
"callback",
")",
"{",
"fs",
".",
"realpath",
"(",
"filePath",
",",
"function",
"(",
"err",
",",
"realpath",
")",
"{",
"// On Windows we can get different cases for the same disk letter :/.",
"let",
"checkPath",
"=",
"realpath",
";",
"if",
"(",
"os",
".",
"platform",
"(",
")",
"===",
"'win32'",
"&&",
"realpath",
")",
"{",
"checkPath",
"=",
"realpath",
".",
"toLowerCase",
"(",
")",
";",
"}",
"if",
"(",
"err",
"||",
"checkPath",
".",
"indexOf",
"(",
"cfg",
".",
"documentRootReal",
")",
"!==",
"0",
")",
"{",
"return",
"callback",
"(",
"err",
"||",
"new",
"Error",
"(",
"'Access denied'",
")",
")",
";",
"}",
"fs",
"[",
"cfg",
".",
"followSymbolicLinks",
"?",
"'stat'",
":",
"'lstat'",
"]",
"(",
"filePath",
",",
"function",
"(",
"err",
",",
"stats",
")",
"{",
"if",
"(",
"err",
"||",
"!",
"stats",
".",
"isFile",
"(",
")",
")",
"{",
"return",
"callback",
"(",
"err",
"||",
"new",
"Error",
"(",
"'Access denied'",
")",
")",
";",
"}",
"stats",
".",
"path",
"=",
"realpath",
";",
"callback",
"(",
"null",
",",
"stats",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Calls back with error or null and fs.Stats object as second parameter.
fs.Stats object is extended with `path` property.
@param {!module:serve-files~configuration} cfg
@param {!string} cfg.documentRootReal
@param {string} [cfg.followSymbolicLinks=false]
@param {!string} filePath
@param {@Function} callback | [
"Calls",
"back",
"with",
"error",
"or",
"null",
"and",
"fs",
".",
"Stats",
"object",
"as",
"second",
"parameter",
".",
"fs",
".",
"Stats",
"object",
"is",
"extended",
"with",
"path",
"property",
"."
] | cd949252a37210bec229146ab519534ef641e942 | https://github.com/ahwayakchih/serve-files/blob/cd949252a37210bec229146ab519534ef641e942/index.js#L118-L140 |
56,351 | ahwayakchih/serve-files | index.js | getResponseDataWhole | function getResponseDataWhole (fileStats/* , headers*/) {
return {
body : fs.createReadStream(fileStats.path),
statusCode: HTTP_CODES.OK,
headers : {
'Content-Type' : mime(fileStats.path),
'Content-Length': fileStats.size,
'Last-Modified' : fileStats.mtime.toUTCString()
}
};
} | javascript | function getResponseDataWhole (fileStats/* , headers*/) {
return {
body : fs.createReadStream(fileStats.path),
statusCode: HTTP_CODES.OK,
headers : {
'Content-Type' : mime(fileStats.path),
'Content-Length': fileStats.size,
'Last-Modified' : fileStats.mtime.toUTCString()
}
};
} | [
"function",
"getResponseDataWhole",
"(",
"fileStats",
"/* , headers*/",
")",
"{",
"return",
"{",
"body",
":",
"fs",
".",
"createReadStream",
"(",
"fileStats",
".",
"path",
")",
",",
"statusCode",
":",
"HTTP_CODES",
".",
"OK",
",",
"headers",
":",
"{",
"'Content-Type'",
":",
"mime",
"(",
"fileStats",
".",
"path",
")",
",",
"'Content-Length'",
":",
"fileStats",
".",
"size",
",",
"'Last-Modified'",
":",
"fileStats",
".",
"mtime",
".",
"toUTCString",
"(",
")",
"}",
"}",
";",
"}"
] | Creates responseData object with body set to readable stream of requested file.
@param {!external:"fs.Stats"} fileStats
@param {!string} fileStats.path path to the file in local filesystem
@param {!Date} fileStats.mtime date of last modification of file content
@param {!Number} fileStats.size number of bytes of data file contains
@param {!Object} headers
@return {module:serve-files~responseData} | [
"Creates",
"responseData",
"object",
"with",
"body",
"set",
"to",
"readable",
"stream",
"of",
"requested",
"file",
"."
] | cd949252a37210bec229146ab519534ef641e942 | https://github.com/ahwayakchih/serve-files/blob/cd949252a37210bec229146ab519534ef641e942/index.js#L286-L296 |
56,352 | ahwayakchih/serve-files | index.js | createFileResponseHandler | function createFileResponseHandler (options) {
const cfg = createConfiguration(options);
if (cfg instanceof Error) {
return cfg;
}
/**
* @private
* @param {!external:"http.IncomingMessage"} req
* @param {!external:"http.ServerResponse"} res
* @param {Function} [callback] called AFTER response is finished
*/
function serve (req, res, callback) {
if (callback && callback instanceof Function) {
res.once('finish', callback);
}
const filePath = cfg.getFilePath(cfg, req);
prepareFileResponse(cfg, filePath, req.headers, (err, data) => {
if (err) {
data = {
statusCode: HTTP_CODES.NOT_FOUND
};
}
serveFileResponse(cfg, data, res);
});
}
return serve;
} | javascript | function createFileResponseHandler (options) {
const cfg = createConfiguration(options);
if (cfg instanceof Error) {
return cfg;
}
/**
* @private
* @param {!external:"http.IncomingMessage"} req
* @param {!external:"http.ServerResponse"} res
* @param {Function} [callback] called AFTER response is finished
*/
function serve (req, res, callback) {
if (callback && callback instanceof Function) {
res.once('finish', callback);
}
const filePath = cfg.getFilePath(cfg, req);
prepareFileResponse(cfg, filePath, req.headers, (err, data) => {
if (err) {
data = {
statusCode: HTTP_CODES.NOT_FOUND
};
}
serveFileResponse(cfg, data, res);
});
}
return serve;
} | [
"function",
"createFileResponseHandler",
"(",
"options",
")",
"{",
"const",
"cfg",
"=",
"createConfiguration",
"(",
"options",
")",
";",
"if",
"(",
"cfg",
"instanceof",
"Error",
")",
"{",
"return",
"cfg",
";",
"}",
"/**\n\t * @private\n\t * @param {!external:\"http.IncomingMessage\"} req\n\t * @param {!external:\"http.ServerResponse\"} res\n\t * @param {Function} [callback] called AFTER response is finished\n\t */",
"function",
"serve",
"(",
"req",
",",
"res",
",",
"callback",
")",
"{",
"if",
"(",
"callback",
"&&",
"callback",
"instanceof",
"Function",
")",
"{",
"res",
".",
"once",
"(",
"'finish'",
",",
"callback",
")",
";",
"}",
"const",
"filePath",
"=",
"cfg",
".",
"getFilePath",
"(",
"cfg",
",",
"req",
")",
";",
"prepareFileResponse",
"(",
"cfg",
",",
"filePath",
",",
"req",
".",
"headers",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"data",
"=",
"{",
"statusCode",
":",
"HTTP_CODES",
".",
"NOT_FOUND",
"}",
";",
"}",
"serveFileResponse",
"(",
"cfg",
",",
"data",
",",
"res",
")",
";",
"}",
")",
";",
"}",
"return",
"serve",
";",
"}"
] | Create function that will handle serving files.
@example
var fileHandler = serveFiles();
var server = http.createServer(function (req, res) {
fileHandler(req, res, err => console.error(err));
});
@param {object} [options]
@param {boolean} [options.followSymbolicLinks=false] symbolic links will not be followed by default, i.e., they will not be served
@param {number} [options.cacheTimeInSeconds=0] HTTP cache will be disabled by default
@param {string} [options.documentRoot=process.cwd()] files outside of root path will not be served
@param {string} [options.parsedURLName='urlParsed'] name of an optional property of a request object, which contains result of `url.parse(req.url)`
@return {Function|Error} | [
"Create",
"function",
"that",
"will",
"handle",
"serving",
"files",
"."
] | cd949252a37210bec229146ab519534ef641e942 | https://github.com/ahwayakchih/serve-files/blob/cd949252a37210bec229146ab519534ef641e942/index.js#L389-L421 |
56,353 | mcgaryes/grunt-combine | tasks/combine.js | function(inputIndex) {
_.each(tokens, function(token, index) {
// determain whether or not this is a file reference or a string
if(token.file) {
// read the file and reset replacement to what was loaded
fs.readFile(token.file, 'utf8', function(e, data) {
if(e) {
grunt.fail.warn("There was an error processing the replacement '" + token.file + "' file.");
}
tokens[index].contents = data;
processTokenCompleteCallback();
});
} else if(token.string) {
// we didn't need to load a file
tokens[index].contents = token.string;
processTokenCompleteCallback();
} else {
processTokenCompleteCallback();
}
}, this);
} | javascript | function(inputIndex) {
_.each(tokens, function(token, index) {
// determain whether or not this is a file reference or a string
if(token.file) {
// read the file and reset replacement to what was loaded
fs.readFile(token.file, 'utf8', function(e, data) {
if(e) {
grunt.fail.warn("There was an error processing the replacement '" + token.file + "' file.");
}
tokens[index].contents = data;
processTokenCompleteCallback();
});
} else if(token.string) {
// we didn't need to load a file
tokens[index].contents = token.string;
processTokenCompleteCallback();
} else {
processTokenCompleteCallback();
}
}, this);
} | [
"function",
"(",
"inputIndex",
")",
"{",
"_",
".",
"each",
"(",
"tokens",
",",
"function",
"(",
"token",
",",
"index",
")",
"{",
"// determain whether or not this is a file reference or a string",
"if",
"(",
"token",
".",
"file",
")",
"{",
"// read the file and reset replacement to what was loaded",
"fs",
".",
"readFile",
"(",
"token",
".",
"file",
",",
"'utf8'",
",",
"function",
"(",
"e",
",",
"data",
")",
"{",
"if",
"(",
"e",
")",
"{",
"grunt",
".",
"fail",
".",
"warn",
"(",
"\"There was an error processing the replacement '\"",
"+",
"token",
".",
"file",
"+",
"\"' file.\"",
")",
";",
"}",
"tokens",
"[",
"index",
"]",
".",
"contents",
"=",
"data",
";",
"processTokenCompleteCallback",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"token",
".",
"string",
")",
"{",
"// we didn't need to load a file",
"tokens",
"[",
"index",
"]",
".",
"contents",
"=",
"token",
".",
"string",
";",
"processTokenCompleteCallback",
"(",
")",
";",
"}",
"else",
"{",
"processTokenCompleteCallback",
"(",
")",
";",
"}",
"}",
",",
"this",
")",
";",
"}"
] | Processes all of the passed replacements
@for grunt-combine
@method processReplacements | [
"Processes",
"all",
"of",
"the",
"passed",
"replacements"
] | 18a330b48f3eab4ec7af75f3c436294bf6f41319 | https://github.com/mcgaryes/grunt-combine/blob/18a330b48f3eab4ec7af75f3c436294bf6f41319/tasks/combine.js#L93-L117 |
|
56,354 | mcgaryes/grunt-combine | tasks/combine.js | function(inputIndex) {
var inputPath = input[inputIndex].split("/");
inputPath = inputPath[inputPath.length - 1];
var path = outputIsPath ? output + inputPath : output;
// write the input string to the output file name
grunt.log.writeln('Writing Output: ' + (path).cyan);
fs.writeFile(path, fileContents[inputIndex], 'utf8', function(err) {
//console.log(fileContents[inputIndex]);
if(err) {
clearTimeout(timer);
grunt.fail.warn("Could not write output '" + output + "' file.");
}
processedFiles++;
if(processedFiles === fileContents.length) {
processedFiles = 0;
fileContents = [];
var endtime = (new Date()).getTime();
grunt.log.writeln('Combine task completed in ' + ((endtime - starttime) / 1000) + ' seconds');
clearTimeout(timer);
done();
}
});
} | javascript | function(inputIndex) {
var inputPath = input[inputIndex].split("/");
inputPath = inputPath[inputPath.length - 1];
var path = outputIsPath ? output + inputPath : output;
// write the input string to the output file name
grunt.log.writeln('Writing Output: ' + (path).cyan);
fs.writeFile(path, fileContents[inputIndex], 'utf8', function(err) {
//console.log(fileContents[inputIndex]);
if(err) {
clearTimeout(timer);
grunt.fail.warn("Could not write output '" + output + "' file.");
}
processedFiles++;
if(processedFiles === fileContents.length) {
processedFiles = 0;
fileContents = [];
var endtime = (new Date()).getTime();
grunt.log.writeln('Combine task completed in ' + ((endtime - starttime) / 1000) + ' seconds');
clearTimeout(timer);
done();
}
});
} | [
"function",
"(",
"inputIndex",
")",
"{",
"var",
"inputPath",
"=",
"input",
"[",
"inputIndex",
"]",
".",
"split",
"(",
"\"/\"",
")",
";",
"inputPath",
"=",
"inputPath",
"[",
"inputPath",
".",
"length",
"-",
"1",
"]",
";",
"var",
"path",
"=",
"outputIsPath",
"?",
"output",
"+",
"inputPath",
":",
"output",
";",
"// write the input string to the output file name",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Writing Output: '",
"+",
"(",
"path",
")",
".",
"cyan",
")",
";",
"fs",
".",
"writeFile",
"(",
"path",
",",
"fileContents",
"[",
"inputIndex",
"]",
",",
"'utf8'",
",",
"function",
"(",
"err",
")",
"{",
"//console.log(fileContents[inputIndex]);",
"if",
"(",
"err",
")",
"{",
"clearTimeout",
"(",
"timer",
")",
";",
"grunt",
".",
"fail",
".",
"warn",
"(",
"\"Could not write output '\"",
"+",
"output",
"+",
"\"' file.\"",
")",
";",
"}",
"processedFiles",
"++",
";",
"if",
"(",
"processedFiles",
"===",
"fileContents",
".",
"length",
")",
"{",
"processedFiles",
"=",
"0",
";",
"fileContents",
"=",
"[",
"]",
";",
"var",
"endtime",
"=",
"(",
"new",
"Date",
"(",
")",
")",
".",
"getTime",
"(",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Combine task completed in '",
"+",
"(",
"(",
"endtime",
"-",
"starttime",
")",
"/",
"1000",
")",
"+",
"' seconds'",
")",
";",
"clearTimeout",
"(",
"timer",
")",
";",
"done",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Writes the processed input file to the specified output name.
@for grunt-combine
@method findAndReplaceTokens | [
"Writes",
"the",
"processed",
"input",
"file",
"to",
"the",
"specified",
"output",
"name",
"."
] | 18a330b48f3eab4ec7af75f3c436294bf6f41319 | https://github.com/mcgaryes/grunt-combine/blob/18a330b48f3eab4ec7af75f3c436294bf6f41319/tasks/combine.js#L164-L190 |
|
56,355 | posttool/currentcms | examples/store/public/js/$$.js | string_component | function string_component(self, message, component) {
eventify(self);
valuable(self, update, '');
var $c = $$().addClass('control');
var $l = $("<label>" + message + "</label>");
var $i = $(component);
$c.append($l, $i);
self.$el = $c;
function update() {
$i.val(self._data);
}
$i.on('change', function () {
self._data = $i.val();
self.emit('change');
})
} | javascript | function string_component(self, message, component) {
eventify(self);
valuable(self, update, '');
var $c = $$().addClass('control');
var $l = $("<label>" + message + "</label>");
var $i = $(component);
$c.append($l, $i);
self.$el = $c;
function update() {
$i.val(self._data);
}
$i.on('change', function () {
self._data = $i.val();
self.emit('change');
})
} | [
"function",
"string_component",
"(",
"self",
",",
"message",
",",
"component",
")",
"{",
"eventify",
"(",
"self",
")",
";",
"valuable",
"(",
"self",
",",
"update",
",",
"''",
")",
";",
"var",
"$c",
"=",
"$$",
"(",
")",
".",
"addClass",
"(",
"'control'",
")",
";",
"var",
"$l",
"=",
"$",
"(",
"\"<label>\"",
"+",
"message",
"+",
"\"</label>\"",
")",
";",
"var",
"$i",
"=",
"$",
"(",
"component",
")",
";",
"$c",
".",
"append",
"(",
"$l",
",",
"$i",
")",
";",
"self",
".",
"$el",
"=",
"$c",
";",
"function",
"update",
"(",
")",
"{",
"$i",
".",
"val",
"(",
"self",
".",
"_data",
")",
";",
"}",
"$i",
".",
"on",
"(",
"'change'",
",",
"function",
"(",
")",
"{",
"self",
".",
"_data",
"=",
"$i",
".",
"val",
"(",
")",
";",
"self",
".",
"emit",
"(",
"'change'",
")",
";",
"}",
")",
"}"
] | simple component ! | [
"simple",
"component",
"!"
] | 9afc9f907bad3b018d961af66c3abb33cd82b051 | https://github.com/posttool/currentcms/blob/9afc9f907bad3b018d961af66c3abb33cd82b051/examples/store/public/js/$$.js#L168-L184 |
56,356 | posttool/currentcms | examples/store/public/js/$$.js | attributable | function attributable(form, c, name) {
if (form._vals == null)
form._vals = {};
if (form._update == null)
form._update = function () {
for (var p in form._vals)
form._vals[p].data == form._data[p];
}
form._vals[name] = c;
c.on('change', function () {
form._data[name] = c.data;
form.emit('change');
});
} | javascript | function attributable(form, c, name) {
if (form._vals == null)
form._vals = {};
if (form._update == null)
form._update = function () {
for (var p in form._vals)
form._vals[p].data == form._data[p];
}
form._vals[name] = c;
c.on('change', function () {
form._data[name] = c.data;
form.emit('change');
});
} | [
"function",
"attributable",
"(",
"form",
",",
"c",
",",
"name",
")",
"{",
"if",
"(",
"form",
".",
"_vals",
"==",
"null",
")",
"form",
".",
"_vals",
"=",
"{",
"}",
";",
"if",
"(",
"form",
".",
"_update",
"==",
"null",
")",
"form",
".",
"_update",
"=",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"p",
"in",
"form",
".",
"_vals",
")",
"form",
".",
"_vals",
"[",
"p",
"]",
".",
"data",
"==",
"form",
".",
"_data",
"[",
"p",
"]",
";",
"}",
"form",
".",
"_vals",
"[",
"name",
"]",
"=",
"c",
";",
"c",
".",
"on",
"(",
"'change'",
",",
"function",
"(",
")",
"{",
"form",
".",
"_data",
"[",
"name",
"]",
"=",
"c",
".",
"data",
";",
"form",
".",
"emit",
"(",
"'change'",
")",
";",
"}",
")",
";",
"}"
] | form field utility | [
"form",
"field",
"utility"
] | 9afc9f907bad3b018d961af66c3abb33cd82b051 | https://github.com/posttool/currentcms/blob/9afc9f907bad3b018d961af66c3abb33cd82b051/examples/store/public/js/$$.js#L240-L253 |
56,357 | grydstedt/uservoice-sso | lib/index.js | UserVoiceSSO | function UserVoiceSSO(subdomain, ssoKey) {
// For UserVoice, the subdomain is used as password
// and the ssoKey is used as salt
this.subdomain = subdomain;
this.ssoKey = ssoKey;
if(!this.subdomain) {
throw new Error('No UserVoice subdomain given');
}
if(!this.ssoKey) {
throw new Error('No SSO key given. Find it ');
}
this.defaults = {};
} | javascript | function UserVoiceSSO(subdomain, ssoKey) {
// For UserVoice, the subdomain is used as password
// and the ssoKey is used as salt
this.subdomain = subdomain;
this.ssoKey = ssoKey;
if(!this.subdomain) {
throw new Error('No UserVoice subdomain given');
}
if(!this.ssoKey) {
throw new Error('No SSO key given. Find it ');
}
this.defaults = {};
} | [
"function",
"UserVoiceSSO",
"(",
"subdomain",
",",
"ssoKey",
")",
"{",
"// For UserVoice, the subdomain is used as password",
"// and the ssoKey is used as salt",
"this",
".",
"subdomain",
"=",
"subdomain",
";",
"this",
".",
"ssoKey",
"=",
"ssoKey",
";",
"if",
"(",
"!",
"this",
".",
"subdomain",
")",
"{",
"throw",
"new",
"Error",
"(",
"'No UserVoice subdomain given'",
")",
";",
"}",
"if",
"(",
"!",
"this",
".",
"ssoKey",
")",
"{",
"throw",
"new",
"Error",
"(",
"'No SSO key given. Find it '",
")",
";",
"}",
"this",
".",
"defaults",
"=",
"{",
"}",
";",
"}"
] | UserVoice SSO Contstructor
@param {String} subdomain Subdomain name
@param {String} ssoKey SSO key | [
"UserVoice",
"SSO",
"Contstructor"
] | 89a1e4dc0d72e964840c3e3e106cfeb12fc688cc | https://github.com/grydstedt/uservoice-sso/blob/89a1e4dc0d72e964840c3e3e106cfeb12fc688cc/lib/index.js#L24-L40 |
56,358 | stormpython/jubilee | build/jubilee.js | getDomain | function getDomain(data, accessor) {
return data
.map(function (item) {
return accessor.call(this, item);
})
.filter(function (item, index, array) {
return array.indexOf(item) === index;
});
} | javascript | function getDomain(data, accessor) {
return data
.map(function (item) {
return accessor.call(this, item);
})
.filter(function (item, index, array) {
return array.indexOf(item) === index;
});
} | [
"function",
"getDomain",
"(",
"data",
",",
"accessor",
")",
"{",
"return",
"data",
".",
"map",
"(",
"function",
"(",
"item",
")",
"{",
"return",
"accessor",
".",
"call",
"(",
"this",
",",
"item",
")",
";",
"}",
")",
".",
"filter",
"(",
"function",
"(",
"item",
",",
"index",
",",
"array",
")",
"{",
"return",
"array",
".",
"indexOf",
"(",
"item",
")",
"===",
"index",
";",
"}",
")",
";",
"}"
] | Creates a unique array of items | [
"Creates",
"a",
"unique",
"array",
"of",
"items"
] | 8263cec31ccfbef38e77229a5baaa7b337c6eefc | https://github.com/stormpython/jubilee/blob/8263cec31ccfbef38e77229a5baaa7b337c6eefc/build/jubilee.js#L11509-L11517 |
56,359 | brianshaler/kerplunk-server | assets/js/ba-routematcher.js | validateRule | function validateRule(rule, value) {
// For a given rule, get the first letter of the string name of its
// constructor function. "R" -> RegExp, "F" -> Function (these shouldn't
// conflict with any other types one might specify). Note: instead of
// getting .toString from a new object {} or Object.prototype, I'm assuming
// that exports will always be an object, and using its .toString method.
// Bad idea? Let me know by filing an issue
var type = exports.toString.call(rule).charAt(8);
// If regexp, match. If function, invoke. Otherwise, compare. Note that ==
// is used because type coercion is needed, as `value` will always be a
// string, but `rule` might not.
return type === "R" ? rule.test(value) : type === "F" ? rule(value) : rule == value;
} | javascript | function validateRule(rule, value) {
// For a given rule, get the first letter of the string name of its
// constructor function. "R" -> RegExp, "F" -> Function (these shouldn't
// conflict with any other types one might specify). Note: instead of
// getting .toString from a new object {} or Object.prototype, I'm assuming
// that exports will always be an object, and using its .toString method.
// Bad idea? Let me know by filing an issue
var type = exports.toString.call(rule).charAt(8);
// If regexp, match. If function, invoke. Otherwise, compare. Note that ==
// is used because type coercion is needed, as `value` will always be a
// string, but `rule` might not.
return type === "R" ? rule.test(value) : type === "F" ? rule(value) : rule == value;
} | [
"function",
"validateRule",
"(",
"rule",
",",
"value",
")",
"{",
"// For a given rule, get the first letter of the string name of its",
"// constructor function. \"R\" -> RegExp, \"F\" -> Function (these shouldn't",
"// conflict with any other types one might specify). Note: instead of",
"// getting .toString from a new object {} or Object.prototype, I'm assuming",
"// that exports will always be an object, and using its .toString method.",
"// Bad idea? Let me know by filing an issue",
"var",
"type",
"=",
"exports",
".",
"toString",
".",
"call",
"(",
"rule",
")",
".",
"charAt",
"(",
"8",
")",
";",
"// If regexp, match. If function, invoke. Otherwise, compare. Note that ==",
"// is used because type coercion is needed, as `value` will always be a",
"// string, but `rule` might not.",
"return",
"type",
"===",
"\"R\"",
"?",
"rule",
".",
"test",
"(",
"value",
")",
":",
"type",
"===",
"\"F\"",
"?",
"rule",
"(",
"value",
")",
":",
"rule",
"==",
"value",
";",
"}"
] | Test to see if a value matches the corresponding rule. | [
"Test",
"to",
"see",
"if",
"a",
"value",
"matches",
"the",
"corresponding",
"rule",
"."
] | f4ee71f2893a811b4968beace7a1ba0b8ea45182 | https://github.com/brianshaler/kerplunk-server/blob/f4ee71f2893a811b4968beace7a1ba0b8ea45182/assets/js/ba-routematcher.js#L13-L25 |
56,360 | emitdb/dotfile | index.js | Dotfile | function Dotfile(basename, options) {
this.basename = basename;
this.extname = '.json';
this.dirname = (options && typeof options.dirname === 'string') ? options.dirname : Dotfile._tilde;
this.filepath = path.join(this.dirname, '.' + this.basename + this.extname);
} | javascript | function Dotfile(basename, options) {
this.basename = basename;
this.extname = '.json';
this.dirname = (options && typeof options.dirname === 'string') ? options.dirname : Dotfile._tilde;
this.filepath = path.join(this.dirname, '.' + this.basename + this.extname);
} | [
"function",
"Dotfile",
"(",
"basename",
",",
"options",
")",
"{",
"this",
".",
"basename",
"=",
"basename",
";",
"this",
".",
"extname",
"=",
"'.json'",
";",
"this",
".",
"dirname",
"=",
"(",
"options",
"&&",
"typeof",
"options",
".",
"dirname",
"===",
"'string'",
")",
"?",
"options",
".",
"dirname",
":",
"Dotfile",
".",
"_tilde",
";",
"this",
".",
"filepath",
"=",
"path",
".",
"join",
"(",
"this",
".",
"dirname",
",",
"'.'",
"+",
"this",
".",
"basename",
"+",
"this",
".",
"extname",
")",
";",
"}"
] | Class to easily manage dot files
@param {String} basename What to name this dotfile
@author dscape | [
"Class",
"to",
"easily",
"manage",
"dot",
"files"
] | 1d1f226b5d64d1c10876ee7d37f55feee2b96aa4 | https://github.com/emitdb/dotfile/blob/1d1f226b5d64d1c10876ee7d37f55feee2b96aa4/index.js#L12-L17 |
56,361 | bredele/regurgitate | index.js | transform | function transform(value) {
if(typeof value === 'function') value = value()
if(value instanceof Array) {
var el = document.createDocumentFragment()
value.map(item => el.appendChild(transform(item)))
value = el
} else if(typeof value === 'object') {
if(typeof value.then === 'function') {
var tmp = document.createTextNode('')
value.then(function(data) {
tmp.parentElement.replaceChild(transform(data), tmp)
})
value = tmp
} else if(typeof value.on === 'function') {
var tmp = document.createTextNode('')
value.on('data', function(data) {
// need to transform? Streams are only text?
tmp.parentElement.insertBefore(document.createTextNode(data), tmp)
})
value = tmp
}
} else value = document.createTextNode(value)
return value
} | javascript | function transform(value) {
if(typeof value === 'function') value = value()
if(value instanceof Array) {
var el = document.createDocumentFragment()
value.map(item => el.appendChild(transform(item)))
value = el
} else if(typeof value === 'object') {
if(typeof value.then === 'function') {
var tmp = document.createTextNode('')
value.then(function(data) {
tmp.parentElement.replaceChild(transform(data), tmp)
})
value = tmp
} else if(typeof value.on === 'function') {
var tmp = document.createTextNode('')
value.on('data', function(data) {
// need to transform? Streams are only text?
tmp.parentElement.insertBefore(document.createTextNode(data), tmp)
})
value = tmp
}
} else value = document.createTextNode(value)
return value
} | [
"function",
"transform",
"(",
"value",
")",
"{",
"if",
"(",
"typeof",
"value",
"===",
"'function'",
")",
"value",
"=",
"value",
"(",
")",
"if",
"(",
"value",
"instanceof",
"Array",
")",
"{",
"var",
"el",
"=",
"document",
".",
"createDocumentFragment",
"(",
")",
"value",
".",
"map",
"(",
"item",
"=>",
"el",
".",
"appendChild",
"(",
"transform",
"(",
"item",
")",
")",
")",
"value",
"=",
"el",
"}",
"else",
"if",
"(",
"typeof",
"value",
"===",
"'object'",
")",
"{",
"if",
"(",
"typeof",
"value",
".",
"then",
"===",
"'function'",
")",
"{",
"var",
"tmp",
"=",
"document",
".",
"createTextNode",
"(",
"''",
")",
"value",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"tmp",
".",
"parentElement",
".",
"replaceChild",
"(",
"transform",
"(",
"data",
")",
",",
"tmp",
")",
"}",
")",
"value",
"=",
"tmp",
"}",
"else",
"if",
"(",
"typeof",
"value",
".",
"on",
"===",
"'function'",
")",
"{",
"var",
"tmp",
"=",
"document",
".",
"createTextNode",
"(",
"''",
")",
"value",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"data",
")",
"{",
"// need to transform? Streams are only text?",
"tmp",
".",
"parentElement",
".",
"insertBefore",
"(",
"document",
".",
"createTextNode",
"(",
"data",
")",
",",
"tmp",
")",
"}",
")",
"value",
"=",
"tmp",
"}",
"}",
"else",
"value",
"=",
"document",
".",
"createTextNode",
"(",
"value",
")",
"return",
"value",
"}"
] | Transform value.
@param {Any|Function|Promise} value
@return {Element}
@api private | [
"Transform",
"value",
"."
] | 313711f6871b083722a907353197f1ee27ad87c1 | https://github.com/bredele/regurgitate/blob/313711f6871b083722a907353197f1ee27ad87c1/index.js#L25-L48 |
56,362 | dinvio/dinvio-js-sdk | lib/Requests.js | Requests | function Requests(apiUrl, version, publicKey) {
this.apiUrl = stripSlashes(apiUrl);
this.version = version.toString();
this.publicKey = publicKey;
} | javascript | function Requests(apiUrl, version, publicKey) {
this.apiUrl = stripSlashes(apiUrl);
this.version = version.toString();
this.publicKey = publicKey;
} | [
"function",
"Requests",
"(",
"apiUrl",
",",
"version",
",",
"publicKey",
")",
"{",
"this",
".",
"apiUrl",
"=",
"stripSlashes",
"(",
"apiUrl",
")",
";",
"this",
".",
"version",
"=",
"version",
".",
"toString",
"(",
")",
";",
"this",
".",
"publicKey",
"=",
"publicKey",
";",
"}"
] | Dinvio API Requests module
@param {string} apiUrl
@param {string|number} version
@param {string} publicKey
@constructor | [
"Dinvio",
"API",
"Requests",
"module"
] | 24e960a3670841ff924d10e2a091b23c38a05dd4 | https://github.com/dinvio/dinvio-js-sdk/blob/24e960a3670841ff924d10e2a091b23c38a05dd4/lib/Requests.js#L15-L19 |
56,363 | hl198181/neptune | misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js | function(id) {
var file;
if (typeof id === 'number') {
file = this.uploader.files[id];
} else {
file = this.uploader.getFile(id);
}
return file;
} | javascript | function(id) {
var file;
if (typeof id === 'number') {
file = this.uploader.files[id];
} else {
file = this.uploader.getFile(id);
}
return file;
} | [
"function",
"(",
"id",
")",
"{",
"var",
"file",
";",
"if",
"(",
"typeof",
"id",
"===",
"'number'",
")",
"{",
"file",
"=",
"this",
".",
"uploader",
".",
"files",
"[",
"id",
"]",
";",
"}",
"else",
"{",
"file",
"=",
"this",
".",
"uploader",
".",
"getFile",
"(",
"id",
")",
";",
"}",
"return",
"file",
";",
"}"
] | Retrieve file by it's unique id.
@method getFile
@param {String} id Unique id of the file
@return {plupload.File} | [
"Retrieve",
"file",
"by",
"it",
"s",
"unique",
"id",
"."
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js#L700-L709 |
|
56,364 | hl198181/neptune | misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js | function(file) {
if (plupload.typeOf(file) === 'string') {
file = this.getFile(file);
}
this.uploader.removeFile(file);
} | javascript | function(file) {
if (plupload.typeOf(file) === 'string') {
file = this.getFile(file);
}
this.uploader.removeFile(file);
} | [
"function",
"(",
"file",
")",
"{",
"if",
"(",
"plupload",
".",
"typeOf",
"(",
"file",
")",
"===",
"'string'",
")",
"{",
"file",
"=",
"this",
".",
"getFile",
"(",
"file",
")",
";",
"}",
"this",
".",
"uploader",
".",
"removeFile",
"(",
"file",
")",
";",
"}"
] | Remove the file from the queue.
@method removeFile
@param {plupload.File|String} file File to remove, might be specified directly or by it's unique id | [
"Remove",
"the",
"file",
"from",
"the",
"queue",
"."
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js#L728-L733 |
|
56,365 | hl198181/neptune | misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js | function(type, message) {
var popup = $(
'<div class="plupload_message">' +
'<span class="plupload_message_close ui-icon ui-icon-circle-close" title="'+_('Close')+'"></span>' +
'<p><span class="ui-icon"></span>' + message + '</p>' +
'</div>'
);
popup
.addClass('ui-state-' + (type === 'error' ? 'error' : 'highlight'))
.find('p .ui-icon')
.addClass('ui-icon-' + (type === 'error' ? 'alert' : 'info'))
.end()
.find('.plupload_message_close')
.click(function() {
popup.remove();
})
.end();
$('.plupload_header', this.container).append(popup);
} | javascript | function(type, message) {
var popup = $(
'<div class="plupload_message">' +
'<span class="plupload_message_close ui-icon ui-icon-circle-close" title="'+_('Close')+'"></span>' +
'<p><span class="ui-icon"></span>' + message + '</p>' +
'</div>'
);
popup
.addClass('ui-state-' + (type === 'error' ? 'error' : 'highlight'))
.find('p .ui-icon')
.addClass('ui-icon-' + (type === 'error' ? 'alert' : 'info'))
.end()
.find('.plupload_message_close')
.click(function() {
popup.remove();
})
.end();
$('.plupload_header', this.container).append(popup);
} | [
"function",
"(",
"type",
",",
"message",
")",
"{",
"var",
"popup",
"=",
"$",
"(",
"'<div class=\"plupload_message\">'",
"+",
"'<span class=\"plupload_message_close ui-icon ui-icon-circle-close\" title=\"'",
"+",
"_",
"(",
"'Close'",
")",
"+",
"'\"></span>'",
"+",
"'<p><span class=\"ui-icon\"></span>'",
"+",
"message",
"+",
"'</p>'",
"+",
"'</div>'",
")",
";",
"popup",
".",
"addClass",
"(",
"'ui-state-'",
"+",
"(",
"type",
"===",
"'error'",
"?",
"'error'",
":",
"'highlight'",
")",
")",
".",
"find",
"(",
"'p .ui-icon'",
")",
".",
"addClass",
"(",
"'ui-icon-'",
"+",
"(",
"type",
"===",
"'error'",
"?",
"'alert'",
":",
"'info'",
")",
")",
".",
"end",
"(",
")",
".",
"find",
"(",
"'.plupload_message_close'",
")",
".",
"click",
"(",
"function",
"(",
")",
"{",
"popup",
".",
"remove",
"(",
")",
";",
"}",
")",
".",
"end",
"(",
")",
";",
"$",
"(",
"'.plupload_header'",
",",
"this",
".",
"container",
")",
".",
"append",
"(",
"popup",
")",
";",
"}"
] | Display a message in notification area.
@method notify
@param {Enum} type Type of the message, either `error` or `info`
@param {String} message The text message to display. | [
"Display",
"a",
"message",
"in",
"notification",
"area",
"."
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js#L777-L797 |
|
56,366 | hl198181/neptune | misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js | function() {
// destroy uploader instance
this.uploader.destroy();
// unbind all button events
$('.plupload_button', this.element).unbind();
// destroy buttons
if ($.ui.button) {
$('.plupload_add, .plupload_start, .plupload_stop', this.container)
.button('destroy');
}
// destroy progressbar
if ($.ui.progressbar) {
this.progressbar.progressbar('destroy');
}
// destroy sortable behavior
if ($.ui.sortable && this.options.sortable) {
$('tbody', this.filelist).sortable('destroy');
}
// restore the elements initial state
this.element
.empty()
.html(this.contents_bak);
this.contents_bak = '';
$.Widget.prototype.destroy.apply(this);
} | javascript | function() {
// destroy uploader instance
this.uploader.destroy();
// unbind all button events
$('.plupload_button', this.element).unbind();
// destroy buttons
if ($.ui.button) {
$('.plupload_add, .plupload_start, .plupload_stop', this.container)
.button('destroy');
}
// destroy progressbar
if ($.ui.progressbar) {
this.progressbar.progressbar('destroy');
}
// destroy sortable behavior
if ($.ui.sortable && this.options.sortable) {
$('tbody', this.filelist).sortable('destroy');
}
// restore the elements initial state
this.element
.empty()
.html(this.contents_bak);
this.contents_bak = '';
$.Widget.prototype.destroy.apply(this);
} | [
"function",
"(",
")",
"{",
"// destroy uploader instance",
"this",
".",
"uploader",
".",
"destroy",
"(",
")",
";",
"// unbind all button events",
"$",
"(",
"'.plupload_button'",
",",
"this",
".",
"element",
")",
".",
"unbind",
"(",
")",
";",
"// destroy buttons",
"if",
"(",
"$",
".",
"ui",
".",
"button",
")",
"{",
"$",
"(",
"'.plupload_add, .plupload_start, .plupload_stop'",
",",
"this",
".",
"container",
")",
".",
"button",
"(",
"'destroy'",
")",
";",
"}",
"// destroy progressbar",
"if",
"(",
"$",
".",
"ui",
".",
"progressbar",
")",
"{",
"this",
".",
"progressbar",
".",
"progressbar",
"(",
"'destroy'",
")",
";",
"}",
"// destroy sortable behavior",
"if",
"(",
"$",
".",
"ui",
".",
"sortable",
"&&",
"this",
".",
"options",
".",
"sortable",
")",
"{",
"$",
"(",
"'tbody'",
",",
"this",
".",
"filelist",
")",
".",
"sortable",
"(",
"'destroy'",
")",
";",
"}",
"// restore the elements initial state",
"this",
".",
"element",
".",
"empty",
"(",
")",
".",
"html",
"(",
"this",
".",
"contents_bak",
")",
";",
"this",
".",
"contents_bak",
"=",
"''",
";",
"$",
".",
"Widget",
".",
"prototype",
".",
"destroy",
".",
"apply",
"(",
"this",
")",
";",
"}"
] | Destroy the widget, the uploader, free associated resources and bring back original html.
@method destroy | [
"Destroy",
"the",
"widget",
"the",
"uploader",
"free",
"associated",
"resources",
"and",
"bring",
"back",
"original",
"html",
"."
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js#L805-L835 |
|
56,367 | hl198181/neptune | misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js | measure | function measure() {
if (!tw || !th) {
var wrapper = $('.plupload_file:eq(0)', self.filelist);
tw = wrapper.outerWidth(true);
th = wrapper.outerHeight(true);
}
var aw = self.content.width(), ah = self.content.height();
cols = Math.floor(aw / tw);
num = cols * (Math.ceil(ah / th) + 1);
} | javascript | function measure() {
if (!tw || !th) {
var wrapper = $('.plupload_file:eq(0)', self.filelist);
tw = wrapper.outerWidth(true);
th = wrapper.outerHeight(true);
}
var aw = self.content.width(), ah = self.content.height();
cols = Math.floor(aw / tw);
num = cols * (Math.ceil(ah / th) + 1);
} | [
"function",
"measure",
"(",
")",
"{",
"if",
"(",
"!",
"tw",
"||",
"!",
"th",
")",
"{",
"var",
"wrapper",
"=",
"$",
"(",
"'.plupload_file:eq(0)'",
",",
"self",
".",
"filelist",
")",
";",
"tw",
"=",
"wrapper",
".",
"outerWidth",
"(",
"true",
")",
";",
"th",
"=",
"wrapper",
".",
"outerHeight",
"(",
"true",
")",
";",
"}",
"var",
"aw",
"=",
"self",
".",
"content",
".",
"width",
"(",
")",
",",
"ah",
"=",
"self",
".",
"content",
".",
"height",
"(",
")",
";",
"cols",
"=",
"Math",
".",
"floor",
"(",
"aw",
"/",
"tw",
")",
";",
"num",
"=",
"cols",
"*",
"(",
"Math",
".",
"ceil",
"(",
"ah",
"/",
"th",
")",
"+",
"1",
")",
";",
"}"
] | calculate number of simultaneously visible thumbs | [
"calculate",
"number",
"of",
"simultaneously",
"visible",
"thumbs"
] | 88030bb4222945900e6a225469380cc43a016c13 | https://github.com/hl198181/neptune/blob/88030bb4222945900e6a225469380cc43a016c13/misc/demo/public/vendor/plupload-2.1.2/js/jquery.ui.plupload/jquery.ui.plupload.js#L1003-L1013 |
56,368 | dominictarr/pull-obv | index.js | obv | function obv (fn, immediate) {
if(!fn) return state
listeners.push(fn)
if(immediate !== false && fn(state) === true) obv.more()
return function () {
var i = listeners.indexOf(fn)
listeners.splice(i, 1)
}
} | javascript | function obv (fn, immediate) {
if(!fn) return state
listeners.push(fn)
if(immediate !== false && fn(state) === true) obv.more()
return function () {
var i = listeners.indexOf(fn)
listeners.splice(i, 1)
}
} | [
"function",
"obv",
"(",
"fn",
",",
"immediate",
")",
"{",
"if",
"(",
"!",
"fn",
")",
"return",
"state",
"listeners",
".",
"push",
"(",
"fn",
")",
"if",
"(",
"immediate",
"!==",
"false",
"&&",
"fn",
"(",
"state",
")",
"===",
"true",
")",
"obv",
".",
"more",
"(",
")",
"return",
"function",
"(",
")",
"{",
"var",
"i",
"=",
"listeners",
".",
"indexOf",
"(",
"fn",
")",
"listeners",
".",
"splice",
"(",
"i",
",",
"1",
")",
"}",
"}"
] | implement an observable | [
"implement",
"an",
"observable"
] | 414d8959624f0d9207bfe27c9ac8aa60513114fb | https://github.com/dominictarr/pull-obv/blob/414d8959624f0d9207bfe27c9ac8aa60513114fb/index.js#L10-L18 |
56,369 | sergiodxa/SukimaJS | index.js | isValid | function isValid (type, value) {
switch (type) {
case 'email':
return validator.isEmail(value);
break;
case 'url':
return validator.isURL(value);
break;
case 'domain':
return validator.isFQDN(value);
break;
case 'ip':
return validator.isIP(value);
break;
case 'alpha':
return validator.isAlpha(value);
break;
case 'number':
return validator.isNumeric(value);
break;
case 'alphanumeric':
return validator.isAlphanumeric(value);
break;
case 'base64':
return validator.isBase64(value);
break;
case 'hexadecimal':
return validator.isHexadecimal(value);
break;
case 'hexcolor':
return validator.isHexColor(value);
break;
case 'int':
return validator.isInt(value);
break;
case 'float':
return validator.isFloat(value);
break;
case 'null':
return validator.isNull(value);
break;
case 'uuid':
return validator.isUUID(value);
break;
case 'date':
return validator.isDate(value);
break;
case 'creditcard':
return validator.isCreditCard(value);
break;
case 'isbn':
return validator.isISBN(value);
break;
case 'mobilephone':
return validator.isMobilePhone(value);
break;
case 'json':
return validator.isJSON(value);
break;
case 'ascii':
return validator.isAscii(value);
break;
case 'mongoid':
return validator.isMongoId(value);
break;
default:
return false;
break;
}
} | javascript | function isValid (type, value) {
switch (type) {
case 'email':
return validator.isEmail(value);
break;
case 'url':
return validator.isURL(value);
break;
case 'domain':
return validator.isFQDN(value);
break;
case 'ip':
return validator.isIP(value);
break;
case 'alpha':
return validator.isAlpha(value);
break;
case 'number':
return validator.isNumeric(value);
break;
case 'alphanumeric':
return validator.isAlphanumeric(value);
break;
case 'base64':
return validator.isBase64(value);
break;
case 'hexadecimal':
return validator.isHexadecimal(value);
break;
case 'hexcolor':
return validator.isHexColor(value);
break;
case 'int':
return validator.isInt(value);
break;
case 'float':
return validator.isFloat(value);
break;
case 'null':
return validator.isNull(value);
break;
case 'uuid':
return validator.isUUID(value);
break;
case 'date':
return validator.isDate(value);
break;
case 'creditcard':
return validator.isCreditCard(value);
break;
case 'isbn':
return validator.isISBN(value);
break;
case 'mobilephone':
return validator.isMobilePhone(value);
break;
case 'json':
return validator.isJSON(value);
break;
case 'ascii':
return validator.isAscii(value);
break;
case 'mongoid':
return validator.isMongoId(value);
break;
default:
return false;
break;
}
} | [
"function",
"isValid",
"(",
"type",
",",
"value",
")",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"'email'",
":",
"return",
"validator",
".",
"isEmail",
"(",
"value",
")",
";",
"break",
";",
"case",
"'url'",
":",
"return",
"validator",
".",
"isURL",
"(",
"value",
")",
";",
"break",
";",
"case",
"'domain'",
":",
"return",
"validator",
".",
"isFQDN",
"(",
"value",
")",
";",
"break",
";",
"case",
"'ip'",
":",
"return",
"validator",
".",
"isIP",
"(",
"value",
")",
";",
"break",
";",
"case",
"'alpha'",
":",
"return",
"validator",
".",
"isAlpha",
"(",
"value",
")",
";",
"break",
";",
"case",
"'number'",
":",
"return",
"validator",
".",
"isNumeric",
"(",
"value",
")",
";",
"break",
";",
"case",
"'alphanumeric'",
":",
"return",
"validator",
".",
"isAlphanumeric",
"(",
"value",
")",
";",
"break",
";",
"case",
"'base64'",
":",
"return",
"validator",
".",
"isBase64",
"(",
"value",
")",
";",
"break",
";",
"case",
"'hexadecimal'",
":",
"return",
"validator",
".",
"isHexadecimal",
"(",
"value",
")",
";",
"break",
";",
"case",
"'hexcolor'",
":",
"return",
"validator",
".",
"isHexColor",
"(",
"value",
")",
";",
"break",
";",
"case",
"'int'",
":",
"return",
"validator",
".",
"isInt",
"(",
"value",
")",
";",
"break",
";",
"case",
"'float'",
":",
"return",
"validator",
".",
"isFloat",
"(",
"value",
")",
";",
"break",
";",
"case",
"'null'",
":",
"return",
"validator",
".",
"isNull",
"(",
"value",
")",
";",
"break",
";",
"case",
"'uuid'",
":",
"return",
"validator",
".",
"isUUID",
"(",
"value",
")",
";",
"break",
";",
"case",
"'date'",
":",
"return",
"validator",
".",
"isDate",
"(",
"value",
")",
";",
"break",
";",
"case",
"'creditcard'",
":",
"return",
"validator",
".",
"isCreditCard",
"(",
"value",
")",
";",
"break",
";",
"case",
"'isbn'",
":",
"return",
"validator",
".",
"isISBN",
"(",
"value",
")",
";",
"break",
";",
"case",
"'mobilephone'",
":",
"return",
"validator",
".",
"isMobilePhone",
"(",
"value",
")",
";",
"break",
";",
"case",
"'json'",
":",
"return",
"validator",
".",
"isJSON",
"(",
"value",
")",
";",
"break",
";",
"case",
"'ascii'",
":",
"return",
"validator",
".",
"isAscii",
"(",
"value",
")",
";",
"break",
";",
"case",
"'mongoid'",
":",
"return",
"validator",
".",
"isMongoId",
"(",
"value",
")",
";",
"break",
";",
"default",
":",
"return",
"false",
";",
"break",
";",
"}",
"}"
] | call a validator method depending on type | [
"call",
"a",
"validator",
"method",
"depending",
"on",
"type"
] | 9218a49ff2352a6d7ae989bf4150f70fed9e1b12 | https://github.com/sergiodxa/SukimaJS/blob/9218a49ff2352a6d7ae989bf4150f70fed9e1b12/index.js#L9-L78 |
56,370 | dylants/debug-caller | lib/debug-caller.js | _buildNamespace | function _buildNamespace(appName, depth) {
var callerFile;
// Our default depth needs to be 2, since 1 is this file. Add the user
// supplied depth to 1 (for this file) to make it 2.
callerFile = caller(depth + 1);
// if for some reason we're unable to determine the caller, use the appName only
if (!callerFile) {
return appName;
}
// TODO in later versions of Node (v0.12.+), there is simple `path.parse`
// which will provide us with the file name property. But until most have
// moved up to that version, find the caller file name in this way...
// find the filename from the path
callerFile = path.basename(callerFile);
// strip off the suffix (if any)
if (path.extname(callerFile)) {
callerFile = callerFile.slice(0, callerFile.indexOf(path.extname(callerFile)));
}
return appName + ":" + callerFile;
} | javascript | function _buildNamespace(appName, depth) {
var callerFile;
// Our default depth needs to be 2, since 1 is this file. Add the user
// supplied depth to 1 (for this file) to make it 2.
callerFile = caller(depth + 1);
// if for some reason we're unable to determine the caller, use the appName only
if (!callerFile) {
return appName;
}
// TODO in later versions of Node (v0.12.+), there is simple `path.parse`
// which will provide us with the file name property. But until most have
// moved up to that version, find the caller file name in this way...
// find the filename from the path
callerFile = path.basename(callerFile);
// strip off the suffix (if any)
if (path.extname(callerFile)) {
callerFile = callerFile.slice(0, callerFile.indexOf(path.extname(callerFile)));
}
return appName + ":" + callerFile;
} | [
"function",
"_buildNamespace",
"(",
"appName",
",",
"depth",
")",
"{",
"var",
"callerFile",
";",
"// Our default depth needs to be 2, since 1 is this file. Add the user",
"// supplied depth to 1 (for this file) to make it 2.",
"callerFile",
"=",
"caller",
"(",
"depth",
"+",
"1",
")",
";",
"// if for some reason we're unable to determine the caller, use the appName only",
"if",
"(",
"!",
"callerFile",
")",
"{",
"return",
"appName",
";",
"}",
"// TODO in later versions of Node (v0.12.+), there is simple `path.parse`",
"// which will provide us with the file name property. But until most have",
"// moved up to that version, find the caller file name in this way...",
"// find the filename from the path",
"callerFile",
"=",
"path",
".",
"basename",
"(",
"callerFile",
")",
";",
"// strip off the suffix (if any)",
"if",
"(",
"path",
".",
"extname",
"(",
"callerFile",
")",
")",
"{",
"callerFile",
"=",
"callerFile",
".",
"slice",
"(",
"0",
",",
"callerFile",
".",
"indexOf",
"(",
"path",
".",
"extname",
"(",
"callerFile",
")",
")",
")",
";",
"}",
"return",
"appName",
"+",
"\":\"",
"+",
"callerFile",
";",
"}"
] | Returns the descriptive text used in the debug instantiation, which at this
point is the app + calling filename. Allow the user to specify a depth for the
calling filename, in the case they have a wrapping function calling this.
@param {String} appName The application name, used in the namespace
@param {Number} depth Depth used to determine caller filename
@return {String} The app + calling filename | [
"Returns",
"the",
"descriptive",
"text",
"used",
"in",
"the",
"debug",
"instantiation",
"which",
"at",
"this",
"point",
"is",
"the",
"app",
"+",
"calling",
"filename",
".",
"Allow",
"the",
"user",
"to",
"specify",
"a",
"depth",
"for",
"the",
"calling",
"filename",
"in",
"the",
"case",
"they",
"have",
"a",
"wrapping",
"function",
"calling",
"this",
"."
] | b54c0f1d3825ef5015624f6f874ea6d955c08d92 | https://github.com/dylants/debug-caller/blob/b54c0f1d3825ef5015624f6f874ea6d955c08d92/lib/debug-caller.js#L18-L43 |
56,371 | dylants/debug-caller | lib/debug-caller.js | logger | function logger(appName, options) {
var namespace, log, error;
options = options ? options : {};
// merge our default options with the user supplied
options = xtend({
depth: 1,
randomColors: false,
logColor: 7,
errorColor: 1,
}, options);
// get the filename which is used as the namespace for the debug module.
namespace = _buildNamespace(appName, options.depth);
// setup two debug'ers, one for console.log and one for console.error
log = debug(namespace);
// bind the log to console.log
log.log = console.log.bind(console);
error = debug(namespace);
// this should happen by default, but just to be sure...
error.log = console.error.bind(console);
// if we don't want random colors, assign log to options.logColor (default: white (7))
// and error to options.errorColor (default: red (1))
if (!options.randomColors) {
log.color = options.logColor;
error.color = options.errorColor;
}
return {
// return the two debug'ers under the log and error functions
log: log,
error: error,
// include the namespace in case the client needs it
namespace: namespace
};
} | javascript | function logger(appName, options) {
var namespace, log, error;
options = options ? options : {};
// merge our default options with the user supplied
options = xtend({
depth: 1,
randomColors: false,
logColor: 7,
errorColor: 1,
}, options);
// get the filename which is used as the namespace for the debug module.
namespace = _buildNamespace(appName, options.depth);
// setup two debug'ers, one for console.log and one for console.error
log = debug(namespace);
// bind the log to console.log
log.log = console.log.bind(console);
error = debug(namespace);
// this should happen by default, but just to be sure...
error.log = console.error.bind(console);
// if we don't want random colors, assign log to options.logColor (default: white (7))
// and error to options.errorColor (default: red (1))
if (!options.randomColors) {
log.color = options.logColor;
error.color = options.errorColor;
}
return {
// return the two debug'ers under the log and error functions
log: log,
error: error,
// include the namespace in case the client needs it
namespace: namespace
};
} | [
"function",
"logger",
"(",
"appName",
",",
"options",
")",
"{",
"var",
"namespace",
",",
"log",
",",
"error",
";",
"options",
"=",
"options",
"?",
"options",
":",
"{",
"}",
";",
"// merge our default options with the user supplied",
"options",
"=",
"xtend",
"(",
"{",
"depth",
":",
"1",
",",
"randomColors",
":",
"false",
",",
"logColor",
":",
"7",
",",
"errorColor",
":",
"1",
",",
"}",
",",
"options",
")",
";",
"// get the filename which is used as the namespace for the debug module.",
"namespace",
"=",
"_buildNamespace",
"(",
"appName",
",",
"options",
".",
"depth",
")",
";",
"// setup two debug'ers, one for console.log and one for console.error",
"log",
"=",
"debug",
"(",
"namespace",
")",
";",
"// bind the log to console.log",
"log",
".",
"log",
"=",
"console",
".",
"log",
".",
"bind",
"(",
"console",
")",
";",
"error",
"=",
"debug",
"(",
"namespace",
")",
";",
"// this should happen by default, but just to be sure...",
"error",
".",
"log",
"=",
"console",
".",
"error",
".",
"bind",
"(",
"console",
")",
";",
"// if we don't want random colors, assign log to options.logColor (default: white (7))",
"// and error to options.errorColor (default: red (1))",
"if",
"(",
"!",
"options",
".",
"randomColors",
")",
"{",
"log",
".",
"color",
"=",
"options",
".",
"logColor",
";",
"error",
".",
"color",
"=",
"options",
".",
"errorColor",
";",
"}",
"return",
"{",
"// return the two debug'ers under the log and error functions",
"log",
":",
"log",
",",
"error",
":",
"error",
",",
"// include the namespace in case the client needs it",
"namespace",
":",
"namespace",
"}",
";",
"}"
] | Creates the `debug` object using the namespace built from the `appName`
and calling filename. Creates 2 loggers, one for log, one for error.
@param {String} appName The application name, used in the namespace
@param {Object} options Optional: The options to use for configuration
@return {Object} An object with two debug'ers: log and error,
alone with the namespace used for the logger | [
"Creates",
"the",
"debug",
"object",
"using",
"the",
"namespace",
"built",
"from",
"the",
"appName",
"and",
"calling",
"filename",
".",
"Creates",
"2",
"loggers",
"one",
"for",
"log",
"one",
"for",
"error",
"."
] | b54c0f1d3825ef5015624f6f874ea6d955c08d92 | https://github.com/dylants/debug-caller/blob/b54c0f1d3825ef5015624f6f874ea6d955c08d92/lib/debug-caller.js#L55-L94 |
56,372 | sendanor/nor-api-session | src/session.js | init_session | function init_session(req) {
debug.assert(req.session).is('object');
if(!is.obj(req.session.client)) {
req.session.client = {};
}
if( (!is.obj(req.session.client.messages)) || is.array(req.session.client.messages) ) {
req.session.client.messages = {};
}
} | javascript | function init_session(req) {
debug.assert(req.session).is('object');
if(!is.obj(req.session.client)) {
req.session.client = {};
}
if( (!is.obj(req.session.client.messages)) || is.array(req.session.client.messages) ) {
req.session.client.messages = {};
}
} | [
"function",
"init_session",
"(",
"req",
")",
"{",
"debug",
".",
"assert",
"(",
"req",
".",
"session",
")",
".",
"is",
"(",
"'object'",
")",
";",
"if",
"(",
"!",
"is",
".",
"obj",
"(",
"req",
".",
"session",
".",
"client",
")",
")",
"{",
"req",
".",
"session",
".",
"client",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"(",
"!",
"is",
".",
"obj",
"(",
"req",
".",
"session",
".",
"client",
".",
"messages",
")",
")",
"||",
"is",
".",
"array",
"(",
"req",
".",
"session",
".",
"client",
".",
"messages",
")",
")",
"{",
"req",
".",
"session",
".",
"client",
".",
"messages",
"=",
"{",
"}",
";",
"}",
"}"
] | Initialize the session | [
"Initialize",
"the",
"session"
] | be1aa653a12ecad2d10b69c3698ca0e30c3099f1 | https://github.com/sendanor/nor-api-session/blob/be1aa653a12ecad2d10b69c3698ca0e30c3099f1/src/session.js#L15-L23 |
56,373 | UXFoundry/hashdo-web | index.js | function (baseUrl, firebaseUrl, port, cardsDirectory) {
// Set environment variables.
process.env.BASE_URL = baseUrl || '';
process.env.FIREBASE_URL = firebaseUrl || 'https://hashdodemo.firebaseio.com/',
process.env.CARDS_DIRECTORY = cardsDirectory || process.cwd();
process.env.PORT = port || 4000;
var Path = require('path'),
Favicon = require('serve-favicon'),
Hpp = require('hpp');
App.use(Timeout('10s'));
App.use(Favicon(Path.join(__dirname, '/public/favicon.ico')));
App.use(Express.static('public'));
// Hacky, quick fix required for now.
// **********************************
App.use('/js', Express.static(Path.join(__dirname, '/node_modules/hashdo/public/js')));
App.use('/css', Express.static(Path.join(__dirname, '/node_modules/hashdo/public/css')));
// **********************************
App.use(BodyParser.urlencoded({extended: false, limit: '5mb'}));
App.use(Hpp());
App.use(Cors());
App.use(haltOnTimedout);
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
}
// Assume cards directory is based off root if a full path is not provided.
if (!Path.isAbsolute(process.env.CARDS_DIRECTORY)) {
process.env.CARDS_DIRECTORY = Path.join(process.cwd(), process.env.CARDS_DIRECTORY);
}
HashDo.packs.init(baseUrl, process.env.CARDS_DIRECTORY);
// Make public card directories static
HashDo.packs.cards().forEach(function (card) {
var packDirectory = Path.join(cardsDirectory, 'hashdo-' + card.pack);
App.use('/' + card.pack + '/' + card.card, Express.static(Path.join(packDirectory, 'public', card.card)));
});
} | javascript | function (baseUrl, firebaseUrl, port, cardsDirectory) {
// Set environment variables.
process.env.BASE_URL = baseUrl || '';
process.env.FIREBASE_URL = firebaseUrl || 'https://hashdodemo.firebaseio.com/',
process.env.CARDS_DIRECTORY = cardsDirectory || process.cwd();
process.env.PORT = port || 4000;
var Path = require('path'),
Favicon = require('serve-favicon'),
Hpp = require('hpp');
App.use(Timeout('10s'));
App.use(Favicon(Path.join(__dirname, '/public/favicon.ico')));
App.use(Express.static('public'));
// Hacky, quick fix required for now.
// **********************************
App.use('/js', Express.static(Path.join(__dirname, '/node_modules/hashdo/public/js')));
App.use('/css', Express.static(Path.join(__dirname, '/node_modules/hashdo/public/css')));
// **********************************
App.use(BodyParser.urlencoded({extended: false, limit: '5mb'}));
App.use(Hpp());
App.use(Cors());
App.use(haltOnTimedout);
function haltOnTimedout(req, res, next){
if (!req.timedout) next();
}
// Assume cards directory is based off root if a full path is not provided.
if (!Path.isAbsolute(process.env.CARDS_DIRECTORY)) {
process.env.CARDS_DIRECTORY = Path.join(process.cwd(), process.env.CARDS_DIRECTORY);
}
HashDo.packs.init(baseUrl, process.env.CARDS_DIRECTORY);
// Make public card directories static
HashDo.packs.cards().forEach(function (card) {
var packDirectory = Path.join(cardsDirectory, 'hashdo-' + card.pack);
App.use('/' + card.pack + '/' + card.card, Express.static(Path.join(packDirectory, 'public', card.card)));
});
} | [
"function",
"(",
"baseUrl",
",",
"firebaseUrl",
",",
"port",
",",
"cardsDirectory",
")",
"{",
"// Set environment variables.",
"process",
".",
"env",
".",
"BASE_URL",
"=",
"baseUrl",
"||",
"''",
";",
"process",
".",
"env",
".",
"FIREBASE_URL",
"=",
"firebaseUrl",
"||",
"'https://hashdodemo.firebaseio.com/'",
",",
"process",
".",
"env",
".",
"CARDS_DIRECTORY",
"=",
"cardsDirectory",
"||",
"process",
".",
"cwd",
"(",
")",
";",
"process",
".",
"env",
".",
"PORT",
"=",
"port",
"||",
"4000",
";",
"var",
"Path",
"=",
"require",
"(",
"'path'",
")",
",",
"Favicon",
"=",
"require",
"(",
"'serve-favicon'",
")",
",",
"Hpp",
"=",
"require",
"(",
"'hpp'",
")",
";",
"App",
".",
"use",
"(",
"Timeout",
"(",
"'10s'",
")",
")",
";",
"App",
".",
"use",
"(",
"Favicon",
"(",
"Path",
".",
"join",
"(",
"__dirname",
",",
"'/public/favicon.ico'",
")",
")",
")",
";",
"App",
".",
"use",
"(",
"Express",
".",
"static",
"(",
"'public'",
")",
")",
";",
"// Hacky, quick fix required for now.",
"// **********************************",
"App",
".",
"use",
"(",
"'/js'",
",",
"Express",
".",
"static",
"(",
"Path",
".",
"join",
"(",
"__dirname",
",",
"'/node_modules/hashdo/public/js'",
")",
")",
")",
";",
"App",
".",
"use",
"(",
"'/css'",
",",
"Express",
".",
"static",
"(",
"Path",
".",
"join",
"(",
"__dirname",
",",
"'/node_modules/hashdo/public/css'",
")",
")",
")",
";",
"// **********************************",
"App",
".",
"use",
"(",
"BodyParser",
".",
"urlencoded",
"(",
"{",
"extended",
":",
"false",
",",
"limit",
":",
"'5mb'",
"}",
")",
")",
";",
"App",
".",
"use",
"(",
"Hpp",
"(",
")",
")",
";",
"App",
".",
"use",
"(",
"Cors",
"(",
")",
")",
";",
"App",
".",
"use",
"(",
"haltOnTimedout",
")",
";",
"function",
"haltOnTimedout",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"if",
"(",
"!",
"req",
".",
"timedout",
")",
"next",
"(",
")",
";",
"}",
"// Assume cards directory is based off root if a full path is not provided.",
"if",
"(",
"!",
"Path",
".",
"isAbsolute",
"(",
"process",
".",
"env",
".",
"CARDS_DIRECTORY",
")",
")",
"{",
"process",
".",
"env",
".",
"CARDS_DIRECTORY",
"=",
"Path",
".",
"join",
"(",
"process",
".",
"cwd",
"(",
")",
",",
"process",
".",
"env",
".",
"CARDS_DIRECTORY",
")",
";",
"}",
"HashDo",
".",
"packs",
".",
"init",
"(",
"baseUrl",
",",
"process",
".",
"env",
".",
"CARDS_DIRECTORY",
")",
";",
"// Make public card directories static",
"HashDo",
".",
"packs",
".",
"cards",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"card",
")",
"{",
"var",
"packDirectory",
"=",
"Path",
".",
"join",
"(",
"cardsDirectory",
",",
"'hashdo-'",
"+",
"card",
".",
"pack",
")",
";",
"App",
".",
"use",
"(",
"'/'",
"+",
"card",
".",
"pack",
"+",
"'/'",
"+",
"card",
".",
"card",
",",
"Express",
".",
"static",
"(",
"Path",
".",
"join",
"(",
"packDirectory",
",",
"'public'",
",",
"card",
".",
"card",
")",
")",
")",
";",
"}",
")",
";",
"}"
] | Configured process events and middleware required to run the web application.
This function should always be called before starting the web server.
@method init
@param {String} baseUrl The URL that the web application will be accessible from.
@param {String} [firebaseUrl] Optional Firebase URL for real-time client updates. If not provided 'https://hashdodemo.firebaseio.com/' will be used.
@param {Number} [port] Optional port the web server will listen on. If not provided 4000 will be used.
@params {String} [cardsDirectory] Optional cards directory where your #Do cards will be loaded from. If not provided then cards will be searched for in the current working directory. | [
"Configured",
"process",
"events",
"and",
"middleware",
"required",
"to",
"run",
"the",
"web",
"application",
".",
"This",
"function",
"should",
"always",
"be",
"called",
"before",
"starting",
"the",
"web",
"server",
"."
] | ec69928cf4515a496f85d9af5926bfe8a4344465 | https://github.com/UXFoundry/hashdo-web/blob/ec69928cf4515a496f85d9af5926bfe8a4344465/index.js#L41-L81 |
|
56,374 | UXFoundry/hashdo-web | index.js | function (callback) {
var APIController = require('./controllers/api'),
DefaultController = require('./controllers/index'),
PackController = require('./controllers/pack'),
CardController = require('./controllers/card'),
WebHookController = require('./controllers/webhook'),
ProxyController = require('./controllers/proxy'),
JsonParser = BodyParser.json({strict: false});
// Disable caching middleware.
var nocache = function (req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
};
// Setup routes late to give implementers routes higher priority and allow middleware as well.
App.get('/api/count', nocache, APIController.count);
App.get('/api/cards', nocache, APIController.cards);
App.get('/api/card', nocache, APIController.card);
App.post('/api/card/state/save', APIController.saveState);
App.post('/api/card/state/clear', APIController.clearState);
App.post('/api/card/analytics', APIController.recordAnalyticEvents);
// Proxy
App.post('/proxy/:pack/:card', ProxyController.post);
// Web Hooks
App.post('/webhook/:pack/:card', WebHookController.process);
// Card Routes
App.post('/:pack/:card', JsonParser, CardController.post);
App.get('/:pack/:card', CardController.get);
App.get('/:pack', PackController);
App.get('/', DefaultController);
var exit = function () {
HashDo.db.disconnect(function () {
process.exit(0);
});
};
// Gracefully disconnect from the database on expected exit.
process.on('SIGINT', exit);
process.on('SIGTERM', exit);
// Global error handler (always exit for programmatic errors).
process.on('uncaughtException', function (err) {
console.error('FATAL: ', err.message);
console.error(err.stack);
process.exit(1);
});
// Connect to the database and start server on successful connection.
HashDo.db.connect(function (err) {
if (err) {
console.error('FATAL: Could not connect to database.', err);
process.exit(1);
}
else {
console.log('WEB: Starting web server on port %d...', process.env.PORT);
App.listen(process.env.PORT, function () {
console.log();
console.log('Let\'s #Do');
callback && callback();
});
}
});
} | javascript | function (callback) {
var APIController = require('./controllers/api'),
DefaultController = require('./controllers/index'),
PackController = require('./controllers/pack'),
CardController = require('./controllers/card'),
WebHookController = require('./controllers/webhook'),
ProxyController = require('./controllers/proxy'),
JsonParser = BodyParser.json({strict: false});
// Disable caching middleware.
var nocache = function (req, res, next) {
res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
res.header('Expires', '-1');
res.header('Pragma', 'no-cache');
next();
};
// Setup routes late to give implementers routes higher priority and allow middleware as well.
App.get('/api/count', nocache, APIController.count);
App.get('/api/cards', nocache, APIController.cards);
App.get('/api/card', nocache, APIController.card);
App.post('/api/card/state/save', APIController.saveState);
App.post('/api/card/state/clear', APIController.clearState);
App.post('/api/card/analytics', APIController.recordAnalyticEvents);
// Proxy
App.post('/proxy/:pack/:card', ProxyController.post);
// Web Hooks
App.post('/webhook/:pack/:card', WebHookController.process);
// Card Routes
App.post('/:pack/:card', JsonParser, CardController.post);
App.get('/:pack/:card', CardController.get);
App.get('/:pack', PackController);
App.get('/', DefaultController);
var exit = function () {
HashDo.db.disconnect(function () {
process.exit(0);
});
};
// Gracefully disconnect from the database on expected exit.
process.on('SIGINT', exit);
process.on('SIGTERM', exit);
// Global error handler (always exit for programmatic errors).
process.on('uncaughtException', function (err) {
console.error('FATAL: ', err.message);
console.error(err.stack);
process.exit(1);
});
// Connect to the database and start server on successful connection.
HashDo.db.connect(function (err) {
if (err) {
console.error('FATAL: Could not connect to database.', err);
process.exit(1);
}
else {
console.log('WEB: Starting web server on port %d...', process.env.PORT);
App.listen(process.env.PORT, function () {
console.log();
console.log('Let\'s #Do');
callback && callback();
});
}
});
} | [
"function",
"(",
"callback",
")",
"{",
"var",
"APIController",
"=",
"require",
"(",
"'./controllers/api'",
")",
",",
"DefaultController",
"=",
"require",
"(",
"'./controllers/index'",
")",
",",
"PackController",
"=",
"require",
"(",
"'./controllers/pack'",
")",
",",
"CardController",
"=",
"require",
"(",
"'./controllers/card'",
")",
",",
"WebHookController",
"=",
"require",
"(",
"'./controllers/webhook'",
")",
",",
"ProxyController",
"=",
"require",
"(",
"'./controllers/proxy'",
")",
",",
"JsonParser",
"=",
"BodyParser",
".",
"json",
"(",
"{",
"strict",
":",
"false",
"}",
")",
";",
"// Disable caching middleware. ",
"var",
"nocache",
"=",
"function",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"res",
".",
"header",
"(",
"'Cache-Control'",
",",
"'private, no-cache, no-store, must-revalidate'",
")",
";",
"res",
".",
"header",
"(",
"'Expires'",
",",
"'-1'",
")",
";",
"res",
".",
"header",
"(",
"'Pragma'",
",",
"'no-cache'",
")",
";",
"next",
"(",
")",
";",
"}",
";",
"// Setup routes late to give implementers routes higher priority and allow middleware as well.",
"App",
".",
"get",
"(",
"'/api/count'",
",",
"nocache",
",",
"APIController",
".",
"count",
")",
";",
"App",
".",
"get",
"(",
"'/api/cards'",
",",
"nocache",
",",
"APIController",
".",
"cards",
")",
";",
"App",
".",
"get",
"(",
"'/api/card'",
",",
"nocache",
",",
"APIController",
".",
"card",
")",
";",
"App",
".",
"post",
"(",
"'/api/card/state/save'",
",",
"APIController",
".",
"saveState",
")",
";",
"App",
".",
"post",
"(",
"'/api/card/state/clear'",
",",
"APIController",
".",
"clearState",
")",
";",
"App",
".",
"post",
"(",
"'/api/card/analytics'",
",",
"APIController",
".",
"recordAnalyticEvents",
")",
";",
"// Proxy",
"App",
".",
"post",
"(",
"'/proxy/:pack/:card'",
",",
"ProxyController",
".",
"post",
")",
";",
"// Web Hooks",
"App",
".",
"post",
"(",
"'/webhook/:pack/:card'",
",",
"WebHookController",
".",
"process",
")",
";",
"// Card Routes",
"App",
".",
"post",
"(",
"'/:pack/:card'",
",",
"JsonParser",
",",
"CardController",
".",
"post",
")",
";",
"App",
".",
"get",
"(",
"'/:pack/:card'",
",",
"CardController",
".",
"get",
")",
";",
"App",
".",
"get",
"(",
"'/:pack'",
",",
"PackController",
")",
";",
"App",
".",
"get",
"(",
"'/'",
",",
"DefaultController",
")",
";",
"var",
"exit",
"=",
"function",
"(",
")",
"{",
"HashDo",
".",
"db",
".",
"disconnect",
"(",
"function",
"(",
")",
"{",
"process",
".",
"exit",
"(",
"0",
")",
";",
"}",
")",
";",
"}",
";",
"// Gracefully disconnect from the database on expected exit.",
"process",
".",
"on",
"(",
"'SIGINT'",
",",
"exit",
")",
";",
"process",
".",
"on",
"(",
"'SIGTERM'",
",",
"exit",
")",
";",
"// Global error handler (always exit for programmatic errors).",
"process",
".",
"on",
"(",
"'uncaughtException'",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'FATAL: '",
",",
"err",
".",
"message",
")",
";",
"console",
".",
"error",
"(",
"err",
".",
"stack",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
")",
";",
"// Connect to the database and start server on successful connection.",
"HashDo",
".",
"db",
".",
"connect",
"(",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'FATAL: Could not connect to database.'",
",",
"err",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"'WEB: Starting web server on port %d...'",
",",
"process",
".",
"env",
".",
"PORT",
")",
";",
"App",
".",
"listen",
"(",
"process",
".",
"env",
".",
"PORT",
",",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
")",
";",
"console",
".",
"log",
"(",
"'Let\\'s #Do'",
")",
";",
"callback",
"&&",
"callback",
"(",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Sets up internal routes and starts the web server,
Ensure you call the init function before starting the web server.
@method start
@async
@param {Function} [callback] Optional callback to be nitified when the server has started and ready for requests. | [
"Sets",
"up",
"internal",
"routes",
"and",
"starts",
"the",
"web",
"server",
"Ensure",
"you",
"call",
"the",
"init",
"function",
"before",
"starting",
"the",
"web",
"server",
"."
] | ec69928cf4515a496f85d9af5926bfe8a4344465 | https://github.com/UXFoundry/hashdo-web/blob/ec69928cf4515a496f85d9af5926bfe8a4344465/index.js#L92-L165 |
|
56,375 | Tictrac/grunt-i18n-linter | tasks/lib/i18n_linter.js | run | function run(files, options) {
// If translations or templates are not supplied then error
if (options.translations.length === 0) {
grunt.fail.fatal('Please supply translations');
}
// If a missing translation regex has been supplied report the missing count
if (options.missingTranslationRegex !== null) {
linter.setMissingTranslationRegex(options.missingTranslationRegex);
}
// Add the translation keys to the linter
options.translations.forEach(function(file) {
var files = grunt.file.expand(file);
files.forEach(function(file) {
if (!grunt.file.exists(file)) {
grunt.fail.fatal('File ' + file + ' does not exist');
}
linter.addKeys(grunt.file.readJSON(file));
});
});
// Iterate through files and run them through the linter
files.forEach(function(file) {
if (!grunt.file.exists(file)) {
grunt.fail.fatal('File ' + file + ' does not exist');
}
linter.check(grunt.file.read(file));
});
} | javascript | function run(files, options) {
// If translations or templates are not supplied then error
if (options.translations.length === 0) {
grunt.fail.fatal('Please supply translations');
}
// If a missing translation regex has been supplied report the missing count
if (options.missingTranslationRegex !== null) {
linter.setMissingTranslationRegex(options.missingTranslationRegex);
}
// Add the translation keys to the linter
options.translations.forEach(function(file) {
var files = grunt.file.expand(file);
files.forEach(function(file) {
if (!grunt.file.exists(file)) {
grunt.fail.fatal('File ' + file + ' does not exist');
}
linter.addKeys(grunt.file.readJSON(file));
});
});
// Iterate through files and run them through the linter
files.forEach(function(file) {
if (!grunt.file.exists(file)) {
grunt.fail.fatal('File ' + file + ' does not exist');
}
linter.check(grunt.file.read(file));
});
} | [
"function",
"run",
"(",
"files",
",",
"options",
")",
"{",
"// If translations or templates are not supplied then error",
"if",
"(",
"options",
".",
"translations",
".",
"length",
"===",
"0",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'Please supply translations'",
")",
";",
"}",
"// If a missing translation regex has been supplied report the missing count",
"if",
"(",
"options",
".",
"missingTranslationRegex",
"!==",
"null",
")",
"{",
"linter",
".",
"setMissingTranslationRegex",
"(",
"options",
".",
"missingTranslationRegex",
")",
";",
"}",
"// Add the translation keys to the linter",
"options",
".",
"translations",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"files",
"=",
"grunt",
".",
"file",
".",
"expand",
"(",
"file",
")",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"grunt",
".",
"file",
".",
"exists",
"(",
"file",
")",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'File '",
"+",
"file",
"+",
"' does not exist'",
")",
";",
"}",
"linter",
".",
"addKeys",
"(",
"grunt",
".",
"file",
".",
"readJSON",
"(",
"file",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"// Iterate through files and run them through the linter",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"grunt",
".",
"file",
".",
"exists",
"(",
"file",
")",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'File '",
"+",
"file",
"+",
"' does not exist'",
")",
";",
"}",
"linter",
".",
"check",
"(",
"grunt",
".",
"file",
".",
"read",
"(",
"file",
")",
")",
";",
"}",
")",
";",
"}"
] | Run the linter against the given files and options
@param {Array} files List of files to check
@param {Object} options List of options | [
"Run",
"the",
"linter",
"against",
"the",
"given",
"files",
"and",
"options"
] | 7a64e19ece1cf974beb29f85ec15dec17a39c45f | https://github.com/Tictrac/grunt-i18n-linter/blob/7a64e19ece1cf974beb29f85ec15dec17a39c45f/tasks/lib/i18n_linter.js#L31-L61 |
56,376 | ugate/releasebot | lib/errors.js | logError | function logError(e) {
e = e instanceof Error ? e : e ? new Error(e) : null;
if (e) {
if (options && util.isRegExp(options.hideTokenRegExp)) {
e.message = e.message.replace(options.hideTokenRegExp, function(match, prefix, token, suffix) {
return prefix + '[SECURE]' + suffix;
});
}
errors.unshift(e);
rbot.log.error(e.stack || e.message);
}
} | javascript | function logError(e) {
e = e instanceof Error ? e : e ? new Error(e) : null;
if (e) {
if (options && util.isRegExp(options.hideTokenRegExp)) {
e.message = e.message.replace(options.hideTokenRegExp, function(match, prefix, token, suffix) {
return prefix + '[SECURE]' + suffix;
});
}
errors.unshift(e);
rbot.log.error(e.stack || e.message);
}
} | [
"function",
"logError",
"(",
"e",
")",
"{",
"e",
"=",
"e",
"instanceof",
"Error",
"?",
"e",
":",
"e",
"?",
"new",
"Error",
"(",
"e",
")",
":",
"null",
";",
"if",
"(",
"e",
")",
"{",
"if",
"(",
"options",
"&&",
"util",
".",
"isRegExp",
"(",
"options",
".",
"hideTokenRegExp",
")",
")",
"{",
"e",
".",
"message",
"=",
"e",
".",
"message",
".",
"replace",
"(",
"options",
".",
"hideTokenRegExp",
",",
"function",
"(",
"match",
",",
"prefix",
",",
"token",
",",
"suffix",
")",
"{",
"return",
"prefix",
"+",
"'[SECURE]'",
"+",
"suffix",
";",
"}",
")",
";",
"}",
"errors",
".",
"unshift",
"(",
"e",
")",
";",
"rbot",
".",
"log",
".",
"error",
"(",
"e",
".",
"stack",
"||",
"e",
".",
"message",
")",
";",
"}",
"}"
] | Logs an error
@param e
the {Error} object or string | [
"Logs",
"an",
"error"
] | 1a2ff42796e77f47f9590992c014fee461aad80b | https://github.com/ugate/releasebot/blob/1a2ff42796e77f47f9590992c014fee461aad80b/lib/errors.js#L44-L55 |
56,377 | ImHype/koa-sdf | lib/loadFile.js | loadFile | function loadFile(name, dir, options) {
var pathname = path.normalize(path.join(options.prefix, name));
var obj = {};
var filename = (obj.path = path.join(dir, name));
var stats = fs.statSync(filename);
var buffer = fs.readFileSync(filename);
obj.cacheControl = options.cacheControl;
obj.maxAge = obj.maxAge ? obj.maxAge : options.maxAge || 0;
obj.type = obj.mime = mime.lookup(pathname) || "application/octet-stream";
obj.mtime = stats.mtime;
obj.length = stats.size;
obj.md5 = crypto.createHash("md5").update(buffer).digest("base64");
debug("file: " + JSON.stringify(obj, null, 2));
if (options.buffer) obj.buffer = buffer;
buffer = null;
return obj;
} | javascript | function loadFile(name, dir, options) {
var pathname = path.normalize(path.join(options.prefix, name));
var obj = {};
var filename = (obj.path = path.join(dir, name));
var stats = fs.statSync(filename);
var buffer = fs.readFileSync(filename);
obj.cacheControl = options.cacheControl;
obj.maxAge = obj.maxAge ? obj.maxAge : options.maxAge || 0;
obj.type = obj.mime = mime.lookup(pathname) || "application/octet-stream";
obj.mtime = stats.mtime;
obj.length = stats.size;
obj.md5 = crypto.createHash("md5").update(buffer).digest("base64");
debug("file: " + JSON.stringify(obj, null, 2));
if (options.buffer) obj.buffer = buffer;
buffer = null;
return obj;
} | [
"function",
"loadFile",
"(",
"name",
",",
"dir",
",",
"options",
")",
"{",
"var",
"pathname",
"=",
"path",
".",
"normalize",
"(",
"path",
".",
"join",
"(",
"options",
".",
"prefix",
",",
"name",
")",
")",
";",
"var",
"obj",
"=",
"{",
"}",
";",
"var",
"filename",
"=",
"(",
"obj",
".",
"path",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"name",
")",
")",
";",
"var",
"stats",
"=",
"fs",
".",
"statSync",
"(",
"filename",
")",
";",
"var",
"buffer",
"=",
"fs",
".",
"readFileSync",
"(",
"filename",
")",
";",
"obj",
".",
"cacheControl",
"=",
"options",
".",
"cacheControl",
";",
"obj",
".",
"maxAge",
"=",
"obj",
".",
"maxAge",
"?",
"obj",
".",
"maxAge",
":",
"options",
".",
"maxAge",
"||",
"0",
";",
"obj",
".",
"type",
"=",
"obj",
".",
"mime",
"=",
"mime",
".",
"lookup",
"(",
"pathname",
")",
"||",
"\"application/octet-stream\"",
";",
"obj",
".",
"mtime",
"=",
"stats",
".",
"mtime",
";",
"obj",
".",
"length",
"=",
"stats",
".",
"size",
";",
"obj",
".",
"md5",
"=",
"crypto",
".",
"createHash",
"(",
"\"md5\"",
")",
".",
"update",
"(",
"buffer",
")",
".",
"digest",
"(",
"\"base64\"",
")",
";",
"debug",
"(",
"\"file: \"",
"+",
"JSON",
".",
"stringify",
"(",
"obj",
",",
"null",
",",
"2",
")",
")",
";",
"if",
"(",
"options",
".",
"buffer",
")",
"obj",
".",
"buffer",
"=",
"buffer",
";",
"buffer",
"=",
"null",
";",
"return",
"obj",
";",
"}"
] | load file and add file content to cache
@param {String} name
@param {String} dir
@param {Object} options
@return {Object}
@api private | [
"load",
"file",
"and",
"add",
"file",
"content",
"to",
"cache"
] | 7a88a6c4dfa99f34f6a8e4f5f9cf07a84015e53b | https://github.com/ImHype/koa-sdf/blob/7a88a6c4dfa99f34f6a8e4f5f9cf07a84015e53b/lib/loadFile.js#L16-L35 |
56,378 | duzun/onemit | dist/lightonemit.1.0.0.js | on | function on(name, hdl) {
var list = eventHandlers[name] || (eventHandlers[name] = []);
list.push(hdl);
return this;
} | javascript | function on(name, hdl) {
var list = eventHandlers[name] || (eventHandlers[name] = []);
list.push(hdl);
return this;
} | [
"function",
"on",
"(",
"name",
",",
"hdl",
")",
"{",
"var",
"list",
"=",
"eventHandlers",
"[",
"name",
"]",
"||",
"(",
"eventHandlers",
"[",
"name",
"]",
"=",
"[",
"]",
")",
";",
"list",
".",
"push",
"(",
"hdl",
")",
";",
"return",
"this",
";",
"}"
] | Bind an event listener to the model.
@param (string) name - event name
@param (function) hdl - event handler | [
"Bind",
"an",
"event",
"listener",
"to",
"the",
"model",
"."
] | 12360553cf36379e9fc91d36c40d519a822d4987 | https://github.com/duzun/onemit/blob/12360553cf36379e9fc91d36c40d519a822d4987/dist/lightonemit.1.0.0.js#L18-L22 |
56,379 | ayecue/node-klass | src/common/printf.js | function(string){
var pattern = /(^|\W)(\w)(\w*)/g,
result = [],
match;
while (pattern.exec(string)) {
result.push(RegExp.$1 + RegExp.$2.toUpperCase() + RegExp.$3);
}
return result.join('');
} | javascript | function(string){
var pattern = /(^|\W)(\w)(\w*)/g,
result = [],
match;
while (pattern.exec(string)) {
result.push(RegExp.$1 + RegExp.$2.toUpperCase() + RegExp.$3);
}
return result.join('');
} | [
"function",
"(",
"string",
")",
"{",
"var",
"pattern",
"=",
"/",
"(^|\\W)(\\w)(\\w*)",
"/",
"g",
",",
"result",
"=",
"[",
"]",
",",
"match",
";",
"while",
"(",
"pattern",
".",
"exec",
"(",
"string",
")",
")",
"{",
"result",
".",
"push",
"(",
"RegExp",
".",
"$1",
"+",
"RegExp",
".",
"$2",
".",
"toUpperCase",
"(",
")",
"+",
"RegExp",
".",
"$3",
")",
";",
"}",
"return",
"result",
".",
"join",
"(",
"''",
")",
";",
"}"
] | Upper first letter | [
"Upper",
"first",
"letter"
] | d0583db943bfc6186e45d205735bebd88828e117 | https://github.com/ayecue/node-klass/blob/d0583db943bfc6186e45d205735bebd88828e117/src/common/printf.js#L27-L37 |
|
56,380 | zestjs/zest-server | zest-server.js | function(module) {
for (var i = 0; i < module.include.length; i++) {
var curInclude = module.include[i];
if (curInclude.substr(0, 2) == '^!') {
module.include[i] = curInclude.substr(2);
attachBuildIds.push(curInclude.substr(2));
}
}
} | javascript | function(module) {
for (var i = 0; i < module.include.length; i++) {
var curInclude = module.include[i];
if (curInclude.substr(0, 2) == '^!') {
module.include[i] = curInclude.substr(2);
attachBuildIds.push(curInclude.substr(2));
}
}
} | [
"function",
"(",
"module",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"module",
".",
"include",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"curInclude",
"=",
"module",
".",
"include",
"[",
"i",
"]",
";",
"if",
"(",
"curInclude",
".",
"substr",
"(",
"0",
",",
"2",
")",
"==",
"'^!'",
")",
"{",
"module",
".",
"include",
"[",
"i",
"]",
"=",
"curInclude",
".",
"substr",
"(",
"2",
")",
";",
"attachBuildIds",
".",
"push",
"(",
"curInclude",
".",
"substr",
"(",
"2",
")",
")",
";",
"}",
"}",
"}"
] | remove the '^!' builds from the current module | [
"remove",
"the",
"^!",
"builds",
"from",
"the",
"current",
"module"
] | 83209d0209da3bce0e9c24034fb4b5016e7bdcc8 | https://github.com/zestjs/zest-server/blob/83209d0209da3bce0e9c24034fb4b5016e7bdcc8/zest-server.js#L234-L242 |
|
56,381 | itsa/itsa-event | event-base.js | function(customEvent, callback, context, filter, prepend) {
return this._addMultiSubs(false, customEvent, callback, context, filter, prepend);
} | javascript | function(customEvent, callback, context, filter, prepend) {
return this._addMultiSubs(false, customEvent, callback, context, filter, prepend);
} | [
"function",
"(",
"customEvent",
",",
"callback",
",",
"context",
",",
"filter",
",",
"prepend",
")",
"{",
"return",
"this",
".",
"_addMultiSubs",
"(",
"false",
",",
"customEvent",
",",
"callback",
",",
"context",
",",
"filter",
",",
"prepend",
")",
";",
"}"
] | Subscribes to a customEvent. The callback will be executed `after` the defaultFn.
@static
@method after
@param customEvent {String|Array} the custom-event (or Array of events) to subscribe to. CustomEvents should
have the syntax: `emitterName:eventName`. Wildcard `*` may be used for both `emitterName` as well as `eventName`.
If `emitterName` is not defined, `UI` is assumed.
@param callback {Function} subscriber:will be invoked when the event occurs. An `eventobject` will be passed
as its only argument.
@param [context] {Object} the instance that subscribes to the event.
any object can passed through, even those are not extended with event-listener methods.
Note: Objects who are extended with listener-methods should use instance.after() instead.
@param [filter] {String|Function} to filter the event.
Use a String if you want to filter DOM-events by a `selector`
Use a function if you want to filter by any other means. If the function returns a trully value, the
subscriber gets invoked. The function gets the `eventobject` as its only argument and the context is
the subscriber.
@param [prepend=false] {Boolean} whether the subscriber should be the first in the list of after-subscribers.
@return {Object} handler with a `detach()`-method which can be used to detach the subscriber
@since 0.0.1 | [
"Subscribes",
"to",
"a",
"customEvent",
".",
"The",
"callback",
"will",
"be",
"executed",
"after",
"the",
"defaultFn",
"."
] | fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa | https://github.com/itsa/itsa-event/blob/fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa/event-base.js#L83-L85 |
|
56,382 | itsa/itsa-event | event-base.js | function(customEvent, callback, context, filter, prepend) {
return this._addMultiSubs(true, customEvent, callback, context, filter, prepend);
} | javascript | function(customEvent, callback, context, filter, prepend) {
return this._addMultiSubs(true, customEvent, callback, context, filter, prepend);
} | [
"function",
"(",
"customEvent",
",",
"callback",
",",
"context",
",",
"filter",
",",
"prepend",
")",
"{",
"return",
"this",
".",
"_addMultiSubs",
"(",
"true",
",",
"customEvent",
",",
"callback",
",",
"context",
",",
"filter",
",",
"prepend",
")",
";",
"}"
] | Subscribes to a customEvent. The callback will be executed `before` the defaultFn.
@static
@method before
@param customEvent {String|Array} the custom-event (or Array of events) to subscribe to. CustomEvents should
have the syntax: `emitterName:eventName`. Wildcard `*` may be used for both `emitterName` as well as `eventName`.
If `emitterName` is not defined, `UI` is assumed.
@param callback {Function} subscriber:will be invoked when the event occurs. An `eventobject` will be passed
as its only argument.
@param [context] {Object} the instance that subscribes to the event.
any object can passed through, even those are not extended with event-listener methods.
Note: Objects who are extended with listener-methods should use instance.before() instead.
@param [filter] {String|Function} to filter the event.
Use a String if you want to filter DOM-events by a `selector`
Use a function if you want to filter by any other means. If the function returns a trully value, the
subscriber gets invoked. The function gets the `eventobject` as its only argument and the context is
the subscriber.
@param [prepend=false] {Boolean} whether the subscriber should be the first in the list of before-subscribers.
@return {Object} handler with a `detach()`-method which can be used to detach the subscriber
@since 0.0.1 | [
"Subscribes",
"to",
"a",
"customEvent",
".",
"The",
"callback",
"will",
"be",
"executed",
"before",
"the",
"defaultFn",
"."
] | fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa | https://github.com/itsa/itsa-event/blob/fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa/event-base.js#L109-L111 |
|
56,383 | itsa/itsa-event | event-base.js | function (emitterName) {
var instance = this,
pattern;
if (emitterName) {
pattern = new RegExp('^'+emitterName+':');
instance._ce.itsa_each(
function(value, key) {
key.match(pattern) && (delete instance._ce[key]);
}
);
}
else {
instance._ce.itsa_each(
function(value, key) {
delete instance._ce[key];
}
);
}
} | javascript | function (emitterName) {
var instance = this,
pattern;
if (emitterName) {
pattern = new RegExp('^'+emitterName+':');
instance._ce.itsa_each(
function(value, key) {
key.match(pattern) && (delete instance._ce[key]);
}
);
}
else {
instance._ce.itsa_each(
function(value, key) {
delete instance._ce[key];
}
);
}
} | [
"function",
"(",
"emitterName",
")",
"{",
"var",
"instance",
"=",
"this",
",",
"pattern",
";",
"if",
"(",
"emitterName",
")",
"{",
"pattern",
"=",
"new",
"RegExp",
"(",
"'^'",
"+",
"emitterName",
"+",
"':'",
")",
";",
"instance",
".",
"_ce",
".",
"itsa_each",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"key",
".",
"match",
"(",
"pattern",
")",
"&&",
"(",
"delete",
"instance",
".",
"_ce",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"instance",
".",
"_ce",
".",
"itsa_each",
"(",
"function",
"(",
"value",
",",
"key",
")",
"{",
"delete",
"instance",
".",
"_ce",
"[",
"key",
"]",
";",
"}",
")",
";",
"}",
"}"
] | Removes all event-definitions of an emitter, specified by its `emitterName`.
When `emitterName` is not set, ALL event-definitions will be removed.
@static
@method undefAllEvents
@param [emitterName] {String} name of the customEvent conform the syntax: `emitterName:eventName`
@since 0.0.1 | [
"Removes",
"all",
"event",
"-",
"definitions",
"of",
"an",
"emitter",
"specified",
"by",
"its",
"emitterName",
".",
"When",
"emitterName",
"is",
"not",
"set",
"ALL",
"event",
"-",
"definitions",
"will",
"be",
"removed",
"."
] | fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa | https://github.com/itsa/itsa-event/blob/fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa/event-base.js#L483-L501 |
|
56,384 | itsa/itsa-event | event-base.js | function (e, checkFilter, before, preProcessor, subscribers) { // subscribers, plural
var subs, passesThis, passesFilter;
if (subscribers && !e.status.halted && !e.silent) {
subs = before ? subscribers.b : subscribers.a;
subs && subs.some(function(subscriber) {
if (preProcessor && preProcessor(subscriber, e)) {
return true;
}
// check: does it need to be itself because of subscribing through 'this'
passesThis = (!subscriber.s || (subscriber.o===e.target));
// check: does it pass the filter
passesFilter = (!checkFilter || !subscriber.f || subscriber.f.call(subscriber.o, e));
if (passesThis && passesFilter) {
// finally: invoke subscriber
subscriber.cb.call(subscriber.o, e);
}
if (e.status.unSilencable && e.silent) {
console.warn(NAME, ' event '+e.emitter+':'+e.type+' cannot made silent: this customEvent is defined as unSilencable');
e.silent = false;
}
return e.silent || (before && e.status.halted); // remember to check whether it was halted for any reason
});
}
} | javascript | function (e, checkFilter, before, preProcessor, subscribers) { // subscribers, plural
var subs, passesThis, passesFilter;
if (subscribers && !e.status.halted && !e.silent) {
subs = before ? subscribers.b : subscribers.a;
subs && subs.some(function(subscriber) {
if (preProcessor && preProcessor(subscriber, e)) {
return true;
}
// check: does it need to be itself because of subscribing through 'this'
passesThis = (!subscriber.s || (subscriber.o===e.target));
// check: does it pass the filter
passesFilter = (!checkFilter || !subscriber.f || subscriber.f.call(subscriber.o, e));
if (passesThis && passesFilter) {
// finally: invoke subscriber
subscriber.cb.call(subscriber.o, e);
}
if (e.status.unSilencable && e.silent) {
console.warn(NAME, ' event '+e.emitter+':'+e.type+' cannot made silent: this customEvent is defined as unSilencable');
e.silent = false;
}
return e.silent || (before && e.status.halted); // remember to check whether it was halted for any reason
});
}
} | [
"function",
"(",
"e",
",",
"checkFilter",
",",
"before",
",",
"preProcessor",
",",
"subscribers",
")",
"{",
"// subscribers, plural",
"var",
"subs",
",",
"passesThis",
",",
"passesFilter",
";",
"if",
"(",
"subscribers",
"&&",
"!",
"e",
".",
"status",
".",
"halted",
"&&",
"!",
"e",
".",
"silent",
")",
"{",
"subs",
"=",
"before",
"?",
"subscribers",
".",
"b",
":",
"subscribers",
".",
"a",
";",
"subs",
"&&",
"subs",
".",
"some",
"(",
"function",
"(",
"subscriber",
")",
"{",
"if",
"(",
"preProcessor",
"&&",
"preProcessor",
"(",
"subscriber",
",",
"e",
")",
")",
"{",
"return",
"true",
";",
"}",
"// check: does it need to be itself because of subscribing through 'this'",
"passesThis",
"=",
"(",
"!",
"subscriber",
".",
"s",
"||",
"(",
"subscriber",
".",
"o",
"===",
"e",
".",
"target",
")",
")",
";",
"// check: does it pass the filter",
"passesFilter",
"=",
"(",
"!",
"checkFilter",
"||",
"!",
"subscriber",
".",
"f",
"||",
"subscriber",
".",
"f",
".",
"call",
"(",
"subscriber",
".",
"o",
",",
"e",
")",
")",
";",
"if",
"(",
"passesThis",
"&&",
"passesFilter",
")",
"{",
"// finally: invoke subscriber",
"subscriber",
".",
"cb",
".",
"call",
"(",
"subscriber",
".",
"o",
",",
"e",
")",
";",
"}",
"if",
"(",
"e",
".",
"status",
".",
"unSilencable",
"&&",
"e",
".",
"silent",
")",
"{",
"console",
".",
"warn",
"(",
"NAME",
",",
"' event '",
"+",
"e",
".",
"emitter",
"+",
"':'",
"+",
"e",
".",
"type",
"+",
"' cannot made silent: this customEvent is defined as unSilencable'",
")",
";",
"e",
".",
"silent",
"=",
"false",
";",
"}",
"return",
"e",
".",
"silent",
"||",
"(",
"before",
"&&",
"e",
".",
"status",
".",
"halted",
")",
";",
"// remember to check whether it was halted for any reason",
"}",
")",
";",
"}",
"}"
] | Does the actual invocation of a subscriber.
@method _invokeSubs
@param e {Object} event-object
@param [checkFilter] {Boolean}
@param [before] {Boolean} whether it concerns before subscribers
@param [checkFilter] {Boolean}
@param subscribers {Array} contains subscribers (objects) with these members:
<ul>
<li>subscriber.o {Object} context of the callback</li>
<li>subscriber.cb {Function} callback to be invoked</li>
<li>subscriber.f {Function} filter to be applied</li>
<li>subscriber.t {DOM-node} target for the specific selector, which will be set as e.target
only when event-dom is active and there are filter-selectors</li>
<li>subscriber.n {DOM-node} highest dom-node that acts as the container for delegation.
only when event-dom is active and there are filter-selectors</li>
<li>subscriber.s {Boolean} true when the subscription was set to itself by using "this:eventName"</li>
</ul>
@private
@since 0.0.1 | [
"Does",
"the",
"actual",
"invocation",
"of",
"a",
"subscriber",
"."
] | fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa | https://github.com/itsa/itsa-event/blob/fd7b5ede1a5e8b6a237f60bd8373f570d014f5fa/event-base.js#L916-L939 |
|
56,385 | doowb/ask-for-github-auth | index.js | askForGithubAuth | function askForGithubAuth (options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
options = options || {};
options.store = options.store || 'default';
if (typeof options.store === 'string') {
options.store = 'for-github-auth.' + options.store;
}
loadQuestions(options.store);
var creds = {};
ask.once('github-auth.type', options, function (err, type) {
if (err) return cb(err);
creds.type = type;
ask.once(['github-auth', type].join('.'), options, function (err, answer) {
if (err) return cb(err);
if (type === 'oauth') {
creds.token = answer;
} else {
creds.username = answer.username;
creds.password = answer.password;
}
cb(null, creds);
});
});
} | javascript | function askForGithubAuth (options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
options = options || {};
options.store = options.store || 'default';
if (typeof options.store === 'string') {
options.store = 'for-github-auth.' + options.store;
}
loadQuestions(options.store);
var creds = {};
ask.once('github-auth.type', options, function (err, type) {
if (err) return cb(err);
creds.type = type;
ask.once(['github-auth', type].join('.'), options, function (err, answer) {
if (err) return cb(err);
if (type === 'oauth') {
creds.token = answer;
} else {
creds.username = answer.username;
creds.password = answer.password;
}
cb(null, creds);
});
});
} | [
"function",
"askForGithubAuth",
"(",
"options",
",",
"cb",
")",
"{",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"cb",
"=",
"options",
";",
"options",
"=",
"{",
"}",
";",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"options",
".",
"store",
"=",
"options",
".",
"store",
"||",
"'default'",
";",
"if",
"(",
"typeof",
"options",
".",
"store",
"===",
"'string'",
")",
"{",
"options",
".",
"store",
"=",
"'for-github-auth.'",
"+",
"options",
".",
"store",
";",
"}",
"loadQuestions",
"(",
"options",
".",
"store",
")",
";",
"var",
"creds",
"=",
"{",
"}",
";",
"ask",
".",
"once",
"(",
"'github-auth.type'",
",",
"options",
",",
"function",
"(",
"err",
",",
"type",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"creds",
".",
"type",
"=",
"type",
";",
"ask",
".",
"once",
"(",
"[",
"'github-auth'",
",",
"type",
"]",
".",
"join",
"(",
"'.'",
")",
",",
"options",
",",
"function",
"(",
"err",
",",
"answer",
")",
"{",
"if",
"(",
"err",
")",
"return",
"cb",
"(",
"err",
")",
";",
"if",
"(",
"type",
"===",
"'oauth'",
")",
"{",
"creds",
".",
"token",
"=",
"answer",
";",
"}",
"else",
"{",
"creds",
".",
"username",
"=",
"answer",
".",
"username",
";",
"creds",
".",
"password",
"=",
"answer",
".",
"password",
";",
"}",
"cb",
"(",
"null",
",",
"creds",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Prompt a user for their github authentication credentials.
Save the answer so they're only asked once.
```js
ask(function (err, creds) {
console.log(creds);
//=> {type: 'oauth', token: '123456'}
//=> or {type: 'basic', username: 'doowb', password: 'password'}
});
```
@param {Object} `options` Options to pass to [ask-once][]
@param {String} `options.store` a [data-store][] instance or name that can be passed to [ask-once][]
@param {Function} `cb` Callback function returning either an error or authentication credentials
@api public | [
"Prompt",
"a",
"user",
"for",
"their",
"github",
"authentication",
"credentials",
".",
"Save",
"the",
"answer",
"so",
"they",
"re",
"only",
"asked",
"once",
"."
] | 1dc5763c911f44c1eb23247e698bf1142a42b111 | https://github.com/doowb/ask-for-github-auth/blob/1dc5763c911f44c1eb23247e698bf1142a42b111/index.js#L60-L89 |
56,386 | jkenlooper/stripmq | stripmq.js | StripMQ | function StripMQ(input, options, formatOptions) {
options || (options = {});
formatOptions || (formatOptions = {});
options = {
type: options.type || 'screen',
width: options.width || 1024,
'device-width': options['device-width'] || options.width || 1024,
height: options.height || 768,
'device-height': options['device-height'] || options.height || 768,
resolution: options.resolution || '1dppx',
orientation: options.orientation || 'landscape',
'aspect-ratio': options['aspect-ratio'] || options.width/options.height || 1024/768,
color: options.color || 3
};
var tree = css.parse(input);
tree = stripMediaQueries(tree, options);
return css.stringify(tree, formatOptions);
} | javascript | function StripMQ(input, options, formatOptions) {
options || (options = {});
formatOptions || (formatOptions = {});
options = {
type: options.type || 'screen',
width: options.width || 1024,
'device-width': options['device-width'] || options.width || 1024,
height: options.height || 768,
'device-height': options['device-height'] || options.height || 768,
resolution: options.resolution || '1dppx',
orientation: options.orientation || 'landscape',
'aspect-ratio': options['aspect-ratio'] || options.width/options.height || 1024/768,
color: options.color || 3
};
var tree = css.parse(input);
tree = stripMediaQueries(tree, options);
return css.stringify(tree, formatOptions);
} | [
"function",
"StripMQ",
"(",
"input",
",",
"options",
",",
"formatOptions",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"formatOptions",
"||",
"(",
"formatOptions",
"=",
"{",
"}",
")",
";",
"options",
"=",
"{",
"type",
":",
"options",
".",
"type",
"||",
"'screen'",
",",
"width",
":",
"options",
".",
"width",
"||",
"1024",
",",
"'device-width'",
":",
"options",
"[",
"'device-width'",
"]",
"||",
"options",
".",
"width",
"||",
"1024",
",",
"height",
":",
"options",
".",
"height",
"||",
"768",
",",
"'device-height'",
":",
"options",
"[",
"'device-height'",
"]",
"||",
"options",
".",
"height",
"||",
"768",
",",
"resolution",
":",
"options",
".",
"resolution",
"||",
"'1dppx'",
",",
"orientation",
":",
"options",
".",
"orientation",
"||",
"'landscape'",
",",
"'aspect-ratio'",
":",
"options",
"[",
"'aspect-ratio'",
"]",
"||",
"options",
".",
"width",
"/",
"options",
".",
"height",
"||",
"1024",
"/",
"768",
",",
"color",
":",
"options",
".",
"color",
"||",
"3",
"}",
";",
"var",
"tree",
"=",
"css",
".",
"parse",
"(",
"input",
")",
";",
"tree",
"=",
"stripMediaQueries",
"(",
"tree",
",",
"options",
")",
";",
"return",
"css",
".",
"stringify",
"(",
"tree",
",",
"formatOptions",
")",
";",
"}"
] | strip media queries
@param {string} input
@param {object} options
@param {object} formatOptions
@returns {string} output | [
"strip",
"media",
"queries"
] | 0fc9cfdc75e23271d8962d1c8c6365a05e91d67e | https://github.com/jkenlooper/stripmq/blob/0fc9cfdc75e23271d8962d1c8c6365a05e91d67e/stripmq.js#L29-L48 |
56,387 | el2iot2/linksoup | lib/linksoup.js | parseSpans | function parseSpans(text) {
var links = parseLinks(text);
/*Represented as
[{
href: "http://yada",
start: startIndex,
end: endIndex
}]*/
var spans = [];
var lastSpan = null;
function isPrefixedLinkSpan(span)
{
return span && "href" in span && span.prefix && "proposed" in span.prefix;
}
function isTextSpan(span)
{
return span && !("href" in span);
}
function addTextSpan(text) {
//if the last span was a candidate
if (isPrefixedLinkSpan(lastSpan)) {
//make sure there is a valid suffix
if (regexen.matchMarkdownLinkSuffix.test(text)) {
//is there any valid whitespace remaining?
text = RegExp.$3;
//use the title (if specified)
if (RegExp.$2) {
lastSpan.title = RegExp.$2;
}
//use the proposed link text for the verified link
lastSpan.text = lastSpan.prefix.proposed.linkText;
//if there was valid prefix text, use it
if (lastSpan.prefix.proposed.text) {
lastSpan.prefix.text = lastSpan.prefix.proposed.text;
delete lastSpan.prefix["proposed"]; //clean up proposal
}
else {
spans.splice(spans.length - 2, 1); //remove prefix
lastSpan = lastSpan.prefix;
}
}
else {
delete lastSpan.prefix["proposed"]; //clean up proposal...no match...no modification
}
delete lastSpan["prefix"]; //clean up prefix scratchwork
}
if (text) {
lastSpan = {
text : text
};
spans.push(lastSpan);
}
}
function addLinkSpan(linkSpan) {
var span = {
href : linkSpan.href
};
if (isTextSpan(lastSpan) && regexen.matchMarkdownLinkPrefix.test(lastSpan.text)) {
lastSpan.proposed = { text: RegExp.$1, linkText: RegExp.$2 };
span.prefix = lastSpan;
}
lastSpan = span;
spans.push(lastSpan);
}
//No links found, all text
if (links.length === 0) {
addTextSpan(text);
}
//One or more links found
else {
var firstLink = links[0],
lastLink = links[links.length - 1];
//Was there text before the first link?
if (firstLink.start > 0) {
addTextSpan(text.substring(0, firstLink.start));
}
//Handle single link
if (links.length === 1) {
addLinkSpan(firstLink);
} else {
//push the firstLink
addLinkSpan(firstLink);
var prevLink = firstLink;
//loop from the second
for (var i = 1; i < links.length; i++) {
//is there text between?
if (links[i].start - prevLink.end >= 1) {
addTextSpan(text.substring(prevLink.end, links[i].start));
}
//add link
addLinkSpan(prevLink = links[i]);
}
}
//Was there text after the links?
if (lastLink.end < (text.length)) {
addTextSpan(text.substring(lastLink.end));
}
}
return spans;
} | javascript | function parseSpans(text) {
var links = parseLinks(text);
/*Represented as
[{
href: "http://yada",
start: startIndex,
end: endIndex
}]*/
var spans = [];
var lastSpan = null;
function isPrefixedLinkSpan(span)
{
return span && "href" in span && span.prefix && "proposed" in span.prefix;
}
function isTextSpan(span)
{
return span && !("href" in span);
}
function addTextSpan(text) {
//if the last span was a candidate
if (isPrefixedLinkSpan(lastSpan)) {
//make sure there is a valid suffix
if (regexen.matchMarkdownLinkSuffix.test(text)) {
//is there any valid whitespace remaining?
text = RegExp.$3;
//use the title (if specified)
if (RegExp.$2) {
lastSpan.title = RegExp.$2;
}
//use the proposed link text for the verified link
lastSpan.text = lastSpan.prefix.proposed.linkText;
//if there was valid prefix text, use it
if (lastSpan.prefix.proposed.text) {
lastSpan.prefix.text = lastSpan.prefix.proposed.text;
delete lastSpan.prefix["proposed"]; //clean up proposal
}
else {
spans.splice(spans.length - 2, 1); //remove prefix
lastSpan = lastSpan.prefix;
}
}
else {
delete lastSpan.prefix["proposed"]; //clean up proposal...no match...no modification
}
delete lastSpan["prefix"]; //clean up prefix scratchwork
}
if (text) {
lastSpan = {
text : text
};
spans.push(lastSpan);
}
}
function addLinkSpan(linkSpan) {
var span = {
href : linkSpan.href
};
if (isTextSpan(lastSpan) && regexen.matchMarkdownLinkPrefix.test(lastSpan.text)) {
lastSpan.proposed = { text: RegExp.$1, linkText: RegExp.$2 };
span.prefix = lastSpan;
}
lastSpan = span;
spans.push(lastSpan);
}
//No links found, all text
if (links.length === 0) {
addTextSpan(text);
}
//One or more links found
else {
var firstLink = links[0],
lastLink = links[links.length - 1];
//Was there text before the first link?
if (firstLink.start > 0) {
addTextSpan(text.substring(0, firstLink.start));
}
//Handle single link
if (links.length === 1) {
addLinkSpan(firstLink);
} else {
//push the firstLink
addLinkSpan(firstLink);
var prevLink = firstLink;
//loop from the second
for (var i = 1; i < links.length; i++) {
//is there text between?
if (links[i].start - prevLink.end >= 1) {
addTextSpan(text.substring(prevLink.end, links[i].start));
}
//add link
addLinkSpan(prevLink = links[i]);
}
}
//Was there text after the links?
if (lastLink.end < (text.length)) {
addTextSpan(text.substring(lastLink.end));
}
}
return spans;
} | [
"function",
"parseSpans",
"(",
"text",
")",
"{",
"var",
"links",
"=",
"parseLinks",
"(",
"text",
")",
";",
"/*Represented as\r\n\t\t[{\r\n\t\thref: \"http://yada\",\r\n\t\tstart: startIndex,\r\n\t\tend: endIndex\r\n\t\t}]*/",
"var",
"spans",
"=",
"[",
"]",
";",
"var",
"lastSpan",
"=",
"null",
";",
"function",
"isPrefixedLinkSpan",
"(",
"span",
")",
"{",
"return",
"span",
"&&",
"\"href\"",
"in",
"span",
"&&",
"span",
".",
"prefix",
"&&",
"\"proposed\"",
"in",
"span",
".",
"prefix",
";",
"}",
"function",
"isTextSpan",
"(",
"span",
")",
"{",
"return",
"span",
"&&",
"!",
"(",
"\"href\"",
"in",
"span",
")",
";",
"}",
"function",
"addTextSpan",
"(",
"text",
")",
"{",
"//if the last span was a candidate\r",
"if",
"(",
"isPrefixedLinkSpan",
"(",
"lastSpan",
")",
")",
"{",
"//make sure there is a valid suffix\r",
"if",
"(",
"regexen",
".",
"matchMarkdownLinkSuffix",
".",
"test",
"(",
"text",
")",
")",
"{",
"//is there any valid whitespace remaining?\r",
"text",
"=",
"RegExp",
".",
"$3",
";",
"//use the title (if specified)\r",
"if",
"(",
"RegExp",
".",
"$2",
")",
"{",
"lastSpan",
".",
"title",
"=",
"RegExp",
".",
"$2",
";",
"}",
"//use the proposed link text for the verified link\r",
"lastSpan",
".",
"text",
"=",
"lastSpan",
".",
"prefix",
".",
"proposed",
".",
"linkText",
";",
"//if there was valid prefix text, use it\r",
"if",
"(",
"lastSpan",
".",
"prefix",
".",
"proposed",
".",
"text",
")",
"{",
"lastSpan",
".",
"prefix",
".",
"text",
"=",
"lastSpan",
".",
"prefix",
".",
"proposed",
".",
"text",
";",
"delete",
"lastSpan",
".",
"prefix",
"[",
"\"proposed\"",
"]",
";",
"//clean up proposal\t\r",
"}",
"else",
"{",
"spans",
".",
"splice",
"(",
"spans",
".",
"length",
"-",
"2",
",",
"1",
")",
";",
"//remove prefix\r",
"lastSpan",
"=",
"lastSpan",
".",
"prefix",
";",
"}",
"}",
"else",
"{",
"delete",
"lastSpan",
".",
"prefix",
"[",
"\"proposed\"",
"]",
";",
"//clean up proposal...no match...no modification\r",
"}",
"delete",
"lastSpan",
"[",
"\"prefix\"",
"]",
";",
"//clean up prefix scratchwork\r",
"}",
"if",
"(",
"text",
")",
"{",
"lastSpan",
"=",
"{",
"text",
":",
"text",
"}",
";",
"spans",
".",
"push",
"(",
"lastSpan",
")",
";",
"}",
"}",
"function",
"addLinkSpan",
"(",
"linkSpan",
")",
"{",
"var",
"span",
"=",
"{",
"href",
":",
"linkSpan",
".",
"href",
"}",
";",
"if",
"(",
"isTextSpan",
"(",
"lastSpan",
")",
"&&",
"regexen",
".",
"matchMarkdownLinkPrefix",
".",
"test",
"(",
"lastSpan",
".",
"text",
")",
")",
"{",
"lastSpan",
".",
"proposed",
"=",
"{",
"text",
":",
"RegExp",
".",
"$1",
",",
"linkText",
":",
"RegExp",
".",
"$2",
"}",
";",
"span",
".",
"prefix",
"=",
"lastSpan",
";",
"}",
"lastSpan",
"=",
"span",
";",
"spans",
".",
"push",
"(",
"lastSpan",
")",
";",
"}",
"//No links found, all text\r",
"if",
"(",
"links",
".",
"length",
"===",
"0",
")",
"{",
"addTextSpan",
"(",
"text",
")",
";",
"}",
"//One or more links found\r",
"else",
"{",
"var",
"firstLink",
"=",
"links",
"[",
"0",
"]",
",",
"lastLink",
"=",
"links",
"[",
"links",
".",
"length",
"-",
"1",
"]",
";",
"//Was there text before the first link?\r",
"if",
"(",
"firstLink",
".",
"start",
">",
"0",
")",
"{",
"addTextSpan",
"(",
"text",
".",
"substring",
"(",
"0",
",",
"firstLink",
".",
"start",
")",
")",
";",
"}",
"//Handle single link\r",
"if",
"(",
"links",
".",
"length",
"===",
"1",
")",
"{",
"addLinkSpan",
"(",
"firstLink",
")",
";",
"}",
"else",
"{",
"//push the firstLink\r",
"addLinkSpan",
"(",
"firstLink",
")",
";",
"var",
"prevLink",
"=",
"firstLink",
";",
"//loop from the second\r",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"links",
".",
"length",
";",
"i",
"++",
")",
"{",
"//is there text between?\r",
"if",
"(",
"links",
"[",
"i",
"]",
".",
"start",
"-",
"prevLink",
".",
"end",
">=",
"1",
")",
"{",
"addTextSpan",
"(",
"text",
".",
"substring",
"(",
"prevLink",
".",
"end",
",",
"links",
"[",
"i",
"]",
".",
"start",
")",
")",
";",
"}",
"//add link\r",
"addLinkSpan",
"(",
"prevLink",
"=",
"links",
"[",
"i",
"]",
")",
";",
"}",
"}",
"//Was there text after the links?\r",
"if",
"(",
"lastLink",
".",
"end",
"<",
"(",
"text",
".",
"length",
")",
")",
"{",
"addTextSpan",
"(",
"text",
".",
"substring",
"(",
"lastLink",
".",
"end",
")",
")",
";",
"}",
"}",
"return",
"spans",
";",
"}"
] | Parses the text into an array of spans | [
"Parses",
"the",
"text",
"into",
"an",
"array",
"of",
"spans"
] | 316ca49d6d6fd91c2ec9dc27f3585d718a7f5f60 | https://github.com/el2iot2/linksoup/blob/316ca49d6d6fd91c2ec9dc27f3585d718a7f5f60/lib/linksoup.js#L15-L124 |
56,388 | el2iot2/linksoup | lib/linksoup.js | makeFuncAsciiDomainReplace | function makeFuncAsciiDomainReplace(ctx) {
return function (asciiDomain) {
var asciiStartPosition = ctx.domain.indexOf(asciiDomain, ctx.asciiEndPosition);
ctx.asciiEndPosition = asciiStartPosition + asciiDomain.length;
ctx.lastLink = {
href : asciiDomain,
start: ctx.cursor.start + asciiStartPosition,
end: ctx.cursor.start + ctx.asciiEndPosition
};
ctx.lastLinkInvalidMatch = asciiDomain.match(regexen.invalidShortDomain);
if (!ctx.lastLinkInvalidMatch) {
ctx.links.push(ctx.lastLink);
}
};
} | javascript | function makeFuncAsciiDomainReplace(ctx) {
return function (asciiDomain) {
var asciiStartPosition = ctx.domain.indexOf(asciiDomain, ctx.asciiEndPosition);
ctx.asciiEndPosition = asciiStartPosition + asciiDomain.length;
ctx.lastLink = {
href : asciiDomain,
start: ctx.cursor.start + asciiStartPosition,
end: ctx.cursor.start + ctx.asciiEndPosition
};
ctx.lastLinkInvalidMatch = asciiDomain.match(regexen.invalidShortDomain);
if (!ctx.lastLinkInvalidMatch) {
ctx.links.push(ctx.lastLink);
}
};
} | [
"function",
"makeFuncAsciiDomainReplace",
"(",
"ctx",
")",
"{",
"return",
"function",
"(",
"asciiDomain",
")",
"{",
"var",
"asciiStartPosition",
"=",
"ctx",
".",
"domain",
".",
"indexOf",
"(",
"asciiDomain",
",",
"ctx",
".",
"asciiEndPosition",
")",
";",
"ctx",
".",
"asciiEndPosition",
"=",
"asciiStartPosition",
"+",
"asciiDomain",
".",
"length",
";",
"ctx",
".",
"lastLink",
"=",
"{",
"href",
":",
"asciiDomain",
",",
"start",
":",
"ctx",
".",
"cursor",
".",
"start",
"+",
"asciiStartPosition",
",",
"end",
":",
"ctx",
".",
"cursor",
".",
"start",
"+",
"ctx",
".",
"asciiEndPosition",
"}",
";",
"ctx",
".",
"lastLinkInvalidMatch",
"=",
"asciiDomain",
".",
"match",
"(",
"regexen",
".",
"invalidShortDomain",
")",
";",
"if",
"(",
"!",
"ctx",
".",
"lastLinkInvalidMatch",
")",
"{",
"ctx",
".",
"links",
".",
"push",
"(",
"ctx",
".",
"lastLink",
")",
";",
"}",
"}",
";",
"}"
] | return a closure to handle a custom ascii domain replace | [
"return",
"a",
"closure",
"to",
"handle",
"a",
"custom",
"ascii",
"domain",
"replace"
] | 316ca49d6d6fd91c2ec9dc27f3585d718a7f5f60 | https://github.com/el2iot2/linksoup/blob/316ca49d6d6fd91c2ec9dc27f3585d718a7f5f60/lib/linksoup.js#L198-L212 |
56,389 | HAKASHUN/gulp-git-staged | index.js | function(stdout, next) {
var lines = stdout.split("\n");
var filenames = _.transform(lines, function(result, line) {
var status = line.slice(0, 2);
if (regExp.test(status)) {
result.push(_.last(line.split(' ')));
}
});
next(null, filenames);
} | javascript | function(stdout, next) {
var lines = stdout.split("\n");
var filenames = _.transform(lines, function(result, line) {
var status = line.slice(0, 2);
if (regExp.test(status)) {
result.push(_.last(line.split(' ')));
}
});
next(null, filenames);
} | [
"function",
"(",
"stdout",
",",
"next",
")",
"{",
"var",
"lines",
"=",
"stdout",
".",
"split",
"(",
"\"\\n\"",
")",
";",
"var",
"filenames",
"=",
"_",
".",
"transform",
"(",
"lines",
",",
"function",
"(",
"result",
",",
"line",
")",
"{",
"var",
"status",
"=",
"line",
".",
"slice",
"(",
"0",
",",
"2",
")",
";",
"if",
"(",
"regExp",
".",
"test",
"(",
"status",
")",
")",
"{",
"result",
".",
"push",
"(",
"_",
".",
"last",
"(",
"line",
".",
"split",
"(",
"' '",
")",
")",
")",
";",
"}",
"}",
")",
";",
"next",
"(",
"null",
",",
"filenames",
")",
";",
"}"
] | collect filename by status stdout | [
"collect",
"filename",
"by",
"status",
"stdout"
] | 72862548634c27deae8c1a8a3062fcabb5bd307e | https://github.com/HAKASHUN/gulp-git-staged/blob/72862548634c27deae8c1a8a3062fcabb5bd307e/index.js#L50-L60 |
|
56,390 | HAKASHUN/gulp-git-staged | index.js | function(filenames) {
var isIn = _.some(filenames, function(line) {
return file.path.indexOf(line) !== -1;
});
if (isIn) {
self.push(file);
}
callback();
} | javascript | function(filenames) {
var isIn = _.some(filenames, function(line) {
return file.path.indexOf(line) !== -1;
});
if (isIn) {
self.push(file);
}
callback();
} | [
"function",
"(",
"filenames",
")",
"{",
"var",
"isIn",
"=",
"_",
".",
"some",
"(",
"filenames",
",",
"function",
"(",
"line",
")",
"{",
"return",
"file",
".",
"path",
".",
"indexOf",
"(",
"line",
")",
"!==",
"-",
"1",
";",
"}",
")",
";",
"if",
"(",
"isIn",
")",
"{",
"self",
".",
"push",
"(",
"file",
")",
";",
"}",
"callback",
"(",
")",
";",
"}"
] | filter file from stream | [
"filter",
"file",
"from",
"stream"
] | 72862548634c27deae8c1a8a3062fcabb5bd307e | https://github.com/HAKASHUN/gulp-git-staged/blob/72862548634c27deae8c1a8a3062fcabb5bd307e/index.js#L62-L70 |
|
56,391 | tualo/tualo-imap | lib/message.js | Message | function Message(rawText){
this.rawText = rawText;
this._parsed = false;
this._isFetch = false;
this._isNoop = false;
this._list = [];
this._search = [];
this._fetch = {
text: ''
};
this._parse();
} | javascript | function Message(rawText){
this.rawText = rawText;
this._parsed = false;
this._isFetch = false;
this._isNoop = false;
this._list = [];
this._search = [];
this._fetch = {
text: ''
};
this._parse();
} | [
"function",
"Message",
"(",
"rawText",
")",
"{",
"this",
".",
"rawText",
"=",
"rawText",
";",
"this",
".",
"_parsed",
"=",
"false",
";",
"this",
".",
"_isFetch",
"=",
"false",
";",
"this",
".",
"_isNoop",
"=",
"false",
";",
"this",
".",
"_list",
"=",
"[",
"]",
";",
"this",
".",
"_search",
"=",
"[",
"]",
";",
"this",
".",
"_fetch",
"=",
"{",
"text",
":",
"''",
"}",
";",
"this",
".",
"_parse",
"(",
")",
";",
"}"
] | Create a new instance of Message.
Message parses a messages of th IMAP server.
-rawText of the message recieved from th IMAP server.
@constructor
@this {Message}
@param {string} rawText | [
"Create",
"a",
"new",
"instance",
"of",
"Message",
".",
"Message",
"parses",
"a",
"messages",
"of",
"th",
"IMAP",
"server",
"."
] | 948d9cb4693eb0d0e82530365ece36c1d8dbecf3 | https://github.com/tualo/tualo-imap/blob/948d9cb4693eb0d0e82530365ece36c1d8dbecf3/lib/message.js#L14-L26 |
56,392 | commenthol/asyncc | src/NoPromise.js | function () {
if (this._lock) return
this._lock = true
let task = this._tasks.shift()
let tstType = this.error ? ['catch', 'end'] : ['then', 'end']
while (task && !~tstType.indexOf(task.type)) {
task = this._tasks.shift()
}
if (task) {
let cb = (err, res) => {
this.error = err
this.result = res || this.result
this._lock = false
this._run()
}
let fn = task.fn
if (task.type === 'end') { // .end
fn(this.error, this.result)
} else {
try {
if (task.type === 'catch') { // .catch
fn(this.error, this.result, cb)
} else { // .then
fn(this.result, cb)
}
} catch (e) {
cb(e)
}
}
} else {
this._lock = false
}
} | javascript | function () {
if (this._lock) return
this._lock = true
let task = this._tasks.shift()
let tstType = this.error ? ['catch', 'end'] : ['then', 'end']
while (task && !~tstType.indexOf(task.type)) {
task = this._tasks.shift()
}
if (task) {
let cb = (err, res) => {
this.error = err
this.result = res || this.result
this._lock = false
this._run()
}
let fn = task.fn
if (task.type === 'end') { // .end
fn(this.error, this.result)
} else {
try {
if (task.type === 'catch') { // .catch
fn(this.error, this.result, cb)
} else { // .then
fn(this.result, cb)
}
} catch (e) {
cb(e)
}
}
} else {
this._lock = false
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_lock",
")",
"return",
"this",
".",
"_lock",
"=",
"true",
"let",
"task",
"=",
"this",
".",
"_tasks",
".",
"shift",
"(",
")",
"let",
"tstType",
"=",
"this",
".",
"error",
"?",
"[",
"'catch'",
",",
"'end'",
"]",
":",
"[",
"'then'",
",",
"'end'",
"]",
"while",
"(",
"task",
"&&",
"!",
"~",
"tstType",
".",
"indexOf",
"(",
"task",
".",
"type",
")",
")",
"{",
"task",
"=",
"this",
".",
"_tasks",
".",
"shift",
"(",
")",
"}",
"if",
"(",
"task",
")",
"{",
"let",
"cb",
"=",
"(",
"err",
",",
"res",
")",
"=>",
"{",
"this",
".",
"error",
"=",
"err",
"this",
".",
"result",
"=",
"res",
"||",
"this",
".",
"result",
"this",
".",
"_lock",
"=",
"false",
"this",
".",
"_run",
"(",
")",
"}",
"let",
"fn",
"=",
"task",
".",
"fn",
"if",
"(",
"task",
".",
"type",
"===",
"'end'",
")",
"{",
"// .end",
"fn",
"(",
"this",
".",
"error",
",",
"this",
".",
"result",
")",
"}",
"else",
"{",
"try",
"{",
"if",
"(",
"task",
".",
"type",
"===",
"'catch'",
")",
"{",
"// .catch",
"fn",
"(",
"this",
".",
"error",
",",
"this",
".",
"result",
",",
"cb",
")",
"}",
"else",
"{",
"// .then",
"fn",
"(",
"this",
".",
"result",
",",
"cb",
")",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"cb",
"(",
"e",
")",
"}",
"}",
"}",
"else",
"{",
"this",
".",
"_lock",
"=",
"false",
"}",
"}"
] | runs the next function
@private | [
"runs",
"the",
"next",
"function"
] | a58e16e025d669403ad6c29e60c14f8215769bd4 | https://github.com/commenthol/asyncc/blob/a58e16e025d669403ad6c29e60c14f8215769bd4/src/NoPromise.js#L92-L124 |
|
56,393 | georgenorman/tessel-kit | lib/classes/button-mgr.js | function(time) {
var self = this;
self.eventDetection.recordRelease(time);
if (self.eventDetection.isLongPress()) {
// this is a "long-press" - reset detection states and notify the "long-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onLongPressCallbackRegistry);
} else {
if (self.eventDetection.onReleaseCount >= 2) {
// this is a double-press (or more) event, so notify the "double-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onDoublePressCallbackRegistry);
}
setTimeout(function(){
if (self.eventDetection.onReleaseCount == 1) {
// second press did not occur within the allotted time, so notify the "short-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onShortPressCallbackRegistry);
}
}, 300); // @-@:p0 make this configurable?
}
} | javascript | function(time) {
var self = this;
self.eventDetection.recordRelease(time);
if (self.eventDetection.isLongPress()) {
// this is a "long-press" - reset detection states and notify the "long-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onLongPressCallbackRegistry);
} else {
if (self.eventDetection.onReleaseCount >= 2) {
// this is a double-press (or more) event, so notify the "double-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onDoublePressCallbackRegistry);
}
setTimeout(function(){
if (self.eventDetection.onReleaseCount == 1) {
// second press did not occur within the allotted time, so notify the "short-press" observers
self.eventDetection.reset();
self._notifyObservers(self.onShortPressCallbackRegistry);
}
}, 300); // @-@:p0 make this configurable?
}
} | [
"function",
"(",
"time",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"eventDetection",
".",
"recordRelease",
"(",
"time",
")",
";",
"if",
"(",
"self",
".",
"eventDetection",
".",
"isLongPress",
"(",
")",
")",
"{",
"// this is a \"long-press\" - reset detection states and notify the \"long-press\" observers",
"self",
".",
"eventDetection",
".",
"reset",
"(",
")",
";",
"self",
".",
"_notifyObservers",
"(",
"self",
".",
"onLongPressCallbackRegistry",
")",
";",
"}",
"else",
"{",
"if",
"(",
"self",
".",
"eventDetection",
".",
"onReleaseCount",
">=",
"2",
")",
"{",
"// this is a double-press (or more) event, so notify the \"double-press\" observers",
"self",
".",
"eventDetection",
".",
"reset",
"(",
")",
";",
"self",
".",
"_notifyObservers",
"(",
"self",
".",
"onDoublePressCallbackRegistry",
")",
";",
"}",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"if",
"(",
"self",
".",
"eventDetection",
".",
"onReleaseCount",
"==",
"1",
")",
"{",
"// second press did not occur within the allotted time, so notify the \"short-press\" observers",
"self",
".",
"eventDetection",
".",
"reset",
"(",
")",
";",
"self",
".",
"_notifyObservers",
"(",
"self",
".",
"onShortPressCallbackRegistry",
")",
";",
"}",
"}",
",",
"300",
")",
";",
"// @-@:p0 make this configurable?",
"}",
"}"
] | Handle the button-release event generated by the button associated with this ButtonMgr instance.
@param time the time of the button-up event. | [
"Handle",
"the",
"button",
"-",
"release",
"event",
"generated",
"by",
"the",
"button",
"associated",
"with",
"this",
"ButtonMgr",
"instance",
"."
] | 487e91360f0ecf8500d24297228842e2c01ac762 | https://github.com/georgenorman/tessel-kit/blob/487e91360f0ecf8500d24297228842e2c01ac762/lib/classes/button-mgr.js#L172-L195 |
|
56,394 | crokita/functionite | examples/example4.js | longWait | function longWait (message, timer, cb) {
setTimeout(function () {
console.log(message);
cb("pang"); //always return "pang"
}, timer); //wait one second before logging
} | javascript | function longWait (message, timer, cb) {
setTimeout(function () {
console.log(message);
cb("pang"); //always return "pang"
}, timer); //wait one second before logging
} | [
"function",
"longWait",
"(",
"message",
",",
"timer",
",",
"cb",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"message",
")",
";",
"cb",
"(",
"\"pang\"",
")",
";",
"//always return \"pang\"",
"}",
",",
"timer",
")",
";",
"//wait one second before logging",
"}"
] | scenario 2 "skip" will call the next function as soon as the execution context leaves the function and will ignore anything passed in the callback | [
"scenario",
"2",
"skip",
"will",
"call",
"the",
"next",
"function",
"as",
"soon",
"as",
"the",
"execution",
"context",
"leaves",
"the",
"function",
"and",
"will",
"ignore",
"anything",
"passed",
"in",
"the",
"callback"
] | e5d52b3bded8eac6b42413208e1dc61e0741ae34 | https://github.com/crokita/functionite/blob/e5d52b3bded8eac6b42413208e1dc61e0741ae34/examples/example4.js#L43-L48 |
56,395 | treshugart/ubercod | index.js | resolveDeps | function resolveDeps (args) {
return deps.map(function (dep) {
if (args && args.length && typeof dep === 'number') {
return args[dep];
}
dep = that[dep];
if (dep) {
return dep;
}
});
} | javascript | function resolveDeps (args) {
return deps.map(function (dep) {
if (args && args.length && typeof dep === 'number') {
return args[dep];
}
dep = that[dep];
if (dep) {
return dep;
}
});
} | [
"function",
"resolveDeps",
"(",
"args",
")",
"{",
"return",
"deps",
".",
"map",
"(",
"function",
"(",
"dep",
")",
"{",
"if",
"(",
"args",
"&&",
"args",
".",
"length",
"&&",
"typeof",
"dep",
"===",
"'number'",
")",
"{",
"return",
"args",
"[",
"dep",
"]",
";",
"}",
"dep",
"=",
"that",
"[",
"dep",
"]",
";",
"if",
"(",
"dep",
")",
"{",
"return",
"dep",
";",
"}",
"}",
")",
";",
"}"
] | Returns the dependencies of the current dependency and merges in any supplied, named arguments. Arguments take precedence over dependencies in the container. | [
"Returns",
"the",
"dependencies",
"of",
"the",
"current",
"dependency",
"and",
"merges",
"in",
"any",
"supplied",
"named",
"arguments",
".",
"Arguments",
"take",
"precedence",
"over",
"dependencies",
"in",
"the",
"container",
"."
] | 772accd6957acf24b59ca56fb40253a1e1760e77 | https://github.com/treshugart/ubercod/blob/772accd6957acf24b59ca56fb40253a1e1760e77/index.js#L61-L73 |
56,396 | treshugart/ubercod | index.js | getInst | function getInst (bind, args) {
args = resolveDeps(args);
return isCtor ? applyCtor(func, args) : func.apply(bind, args);
} | javascript | function getInst (bind, args) {
args = resolveDeps(args);
return isCtor ? applyCtor(func, args) : func.apply(bind, args);
} | [
"function",
"getInst",
"(",
"bind",
",",
"args",
")",
"{",
"args",
"=",
"resolveDeps",
"(",
"args",
")",
";",
"return",
"isCtor",
"?",
"applyCtor",
"(",
"func",
",",
"args",
")",
":",
"func",
".",
"apply",
"(",
"bind",
",",
"args",
")",
";",
"}"
] | Returns a dependency. It checks to see if it's a constructor function or a regular function and calls it accordingly. | [
"Returns",
"a",
"dependency",
".",
"It",
"checks",
"to",
"see",
"if",
"it",
"s",
"a",
"constructor",
"function",
"or",
"a",
"regular",
"function",
"and",
"calls",
"it",
"accordingly",
"."
] | 772accd6957acf24b59ca56fb40253a1e1760e77 | https://github.com/treshugart/ubercod/blob/772accd6957acf24b59ca56fb40253a1e1760e77/index.js#L77-L80 |
56,397 | treshugart/ubercod | index.js | resolveInst | function resolveInst (bind, args) {
return isTransient ? getInst(bind, args) : cache || (cache = getInst(bind));
} | javascript | function resolveInst (bind, args) {
return isTransient ? getInst(bind, args) : cache || (cache = getInst(bind));
} | [
"function",
"resolveInst",
"(",
"bind",
",",
"args",
")",
"{",
"return",
"isTransient",
"?",
"getInst",
"(",
"bind",
",",
"args",
")",
":",
"cache",
"||",
"(",
"cache",
"=",
"getInst",
"(",
"bind",
")",
")",
";",
"}"
] | Resolves the dependency based on if it's a singleton or transient dependency. Both forms allow arguments. If it's a singleton, then no arguments are allowed. If it's transient, named arguments are allowed. | [
"Resolves",
"the",
"dependency",
"based",
"on",
"if",
"it",
"s",
"a",
"singleton",
"or",
"transient",
"dependency",
".",
"Both",
"forms",
"allow",
"arguments",
".",
"If",
"it",
"s",
"a",
"singleton",
"then",
"no",
"arguments",
"are",
"allowed",
".",
"If",
"it",
"s",
"transient",
"named",
"arguments",
"are",
"allowed",
"."
] | 772accd6957acf24b59ca56fb40253a1e1760e77 | https://github.com/treshugart/ubercod/blob/772accd6957acf24b59ca56fb40253a1e1760e77/index.js#L85-L87 |
56,398 | treshugart/ubercod | index.js | init | function init (func) {
func = ensureFunc(func);
cache = undefined;
deps = parseDepsFromFunc(func);
} | javascript | function init (func) {
func = ensureFunc(func);
cache = undefined;
deps = parseDepsFromFunc(func);
} | [
"function",
"init",
"(",
"func",
")",
"{",
"func",
"=",
"ensureFunc",
"(",
"func",
")",
";",
"cache",
"=",
"undefined",
";",
"deps",
"=",
"parseDepsFromFunc",
"(",
"func",
")",
";",
"}"
] | Initialises or re-initialises the state of the dependency. | [
"Initialises",
"or",
"re",
"-",
"initialises",
"the",
"state",
"of",
"the",
"dependency",
"."
] | 772accd6957acf24b59ca56fb40253a1e1760e77 | https://github.com/treshugart/ubercod/blob/772accd6957acf24b59ca56fb40253a1e1760e77/index.js#L90-L94 |
56,399 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/toolbar/plugin.js | getItemDefinedGroups | function getItemDefinedGroups() {
var groups = {},
itemName, item, itemToolbar, group, order;
for ( itemName in editor.ui.items ) {
item = editor.ui.items[ itemName ];
itemToolbar = item.toolbar || 'others';
if ( itemToolbar ) {
// Break the toolbar property into its parts: "group_name[,order]".
itemToolbar = itemToolbar.split( ',' );
group = itemToolbar[ 0 ];
order = parseInt( itemToolbar[ 1 ] || -1, 10 );
// Initialize the group, if necessary.
groups[ group ] || ( groups[ group ] = [] );
// Push the data used to build the toolbar later.
groups[ group ].push( { name: itemName, order: order } );
}
}
// Put the items in the right order.
for ( group in groups ) {
groups[ group ] = groups[ group ].sort( function( a, b ) {
return a.order == b.order ? 0 :
b.order < 0 ? -1 :
a.order < 0 ? 1 :
a.order < b.order ? -1 :
1;
} );
}
return groups;
} | javascript | function getItemDefinedGroups() {
var groups = {},
itemName, item, itemToolbar, group, order;
for ( itemName in editor.ui.items ) {
item = editor.ui.items[ itemName ];
itemToolbar = item.toolbar || 'others';
if ( itemToolbar ) {
// Break the toolbar property into its parts: "group_name[,order]".
itemToolbar = itemToolbar.split( ',' );
group = itemToolbar[ 0 ];
order = parseInt( itemToolbar[ 1 ] || -1, 10 );
// Initialize the group, if necessary.
groups[ group ] || ( groups[ group ] = [] );
// Push the data used to build the toolbar later.
groups[ group ].push( { name: itemName, order: order } );
}
}
// Put the items in the right order.
for ( group in groups ) {
groups[ group ] = groups[ group ].sort( function( a, b ) {
return a.order == b.order ? 0 :
b.order < 0 ? -1 :
a.order < 0 ? 1 :
a.order < b.order ? -1 :
1;
} );
}
return groups;
} | [
"function",
"getItemDefinedGroups",
"(",
")",
"{",
"var",
"groups",
"=",
"{",
"}",
",",
"itemName",
",",
"item",
",",
"itemToolbar",
",",
"group",
",",
"order",
";",
"for",
"(",
"itemName",
"in",
"editor",
".",
"ui",
".",
"items",
")",
"{",
"item",
"=",
"editor",
".",
"ui",
".",
"items",
"[",
"itemName",
"]",
";",
"itemToolbar",
"=",
"item",
".",
"toolbar",
"||",
"'others'",
";",
"if",
"(",
"itemToolbar",
")",
"{",
"// Break the toolbar property into its parts: \"group_name[,order]\".\r",
"itemToolbar",
"=",
"itemToolbar",
".",
"split",
"(",
"','",
")",
";",
"group",
"=",
"itemToolbar",
"[",
"0",
"]",
";",
"order",
"=",
"parseInt",
"(",
"itemToolbar",
"[",
"1",
"]",
"||",
"-",
"1",
",",
"10",
")",
";",
"// Initialize the group, if necessary.\r",
"groups",
"[",
"group",
"]",
"||",
"(",
"groups",
"[",
"group",
"]",
"=",
"[",
"]",
")",
";",
"// Push the data used to build the toolbar later.\r",
"groups",
"[",
"group",
"]",
".",
"push",
"(",
"{",
"name",
":",
"itemName",
",",
"order",
":",
"order",
"}",
")",
";",
"}",
"}",
"// Put the items in the right order.\r",
"for",
"(",
"group",
"in",
"groups",
")",
"{",
"groups",
"[",
"group",
"]",
"=",
"groups",
"[",
"group",
"]",
".",
"sort",
"(",
"function",
"(",
"a",
",",
"b",
")",
"{",
"return",
"a",
".",
"order",
"==",
"b",
".",
"order",
"?",
"0",
":",
"b",
".",
"order",
"<",
"0",
"?",
"-",
"1",
":",
"a",
".",
"order",
"<",
"0",
"?",
"1",
":",
"a",
".",
"order",
"<",
"b",
".",
"order",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}",
"return",
"groups",
";",
"}"
] | Returns an object containing all toolbar groups used by ui items. | [
"Returns",
"an",
"object",
"containing",
"all",
"toolbar",
"groups",
"used",
"by",
"ui",
"items",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/toolbar/plugin.js#L462-L495 |
Subsets and Splits