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
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
47,700 | slideme/rorschach | index.js | initZooKeeper | function initZooKeeper(rorschach, connectionString, options) {
var error;
var zk = zookeeper.createClient(connectionString, options);
rorschach.zk = zk;
zk.connect();
zk.on('connected', onconnected);
zk.on('expired', setError);
zk.on('authenticationFailed', setError);
zk.on('disconnected', ondisconnected);
zk.on('state', handleStateChange);
function onconnected() {
error = false;
}
function setError() {
error = true;
}
function ondisconnected() {
if (rorschach.closed) {
return;
}
if (error) {
zk.removeListener('connected', onconnected);
zk.removeListener('disconnected', ondisconnected);
zk.removeListener('expired', setError);
zk.removeListener('authenticationFailed', setError);
zk.removeListener('state', handleStateChange);
zk.close();
initZooKeeper(rorschach, connectionString, options);
}
}
function handleStateChange(state) {
var newState;
if (state === State.SYNC_CONNECTED) {
if (!rorschach.ready) {
rorschach.ready = true;
rorschach.emit('connected');
newState = ConnectionState.CONNECTED;
}
else {
newState = ConnectionState.RECONNECTED;
}
}
else if (state === State.CONNECTED_READ_ONLY) {
newState = ConnectionState.READ_ONLY;
}
else if (state === State.EXPIRED) {
newState = ConnectionState.LOST;
}
else if (state === State.DISCONNECTED) {
newState = ConnectionState.SUSPENDED;
}
else {
// AUTH_FAILED and SASL_AUTHENTICATED are not handled, yep.
return;
}
rorschach.state = newState;
rorschach.emit('connectionStateChanged', newState);
}
} | javascript | function initZooKeeper(rorschach, connectionString, options) {
var error;
var zk = zookeeper.createClient(connectionString, options);
rorschach.zk = zk;
zk.connect();
zk.on('connected', onconnected);
zk.on('expired', setError);
zk.on('authenticationFailed', setError);
zk.on('disconnected', ondisconnected);
zk.on('state', handleStateChange);
function onconnected() {
error = false;
}
function setError() {
error = true;
}
function ondisconnected() {
if (rorschach.closed) {
return;
}
if (error) {
zk.removeListener('connected', onconnected);
zk.removeListener('disconnected', ondisconnected);
zk.removeListener('expired', setError);
zk.removeListener('authenticationFailed', setError);
zk.removeListener('state', handleStateChange);
zk.close();
initZooKeeper(rorschach, connectionString, options);
}
}
function handleStateChange(state) {
var newState;
if (state === State.SYNC_CONNECTED) {
if (!rorschach.ready) {
rorschach.ready = true;
rorschach.emit('connected');
newState = ConnectionState.CONNECTED;
}
else {
newState = ConnectionState.RECONNECTED;
}
}
else if (state === State.CONNECTED_READ_ONLY) {
newState = ConnectionState.READ_ONLY;
}
else if (state === State.EXPIRED) {
newState = ConnectionState.LOST;
}
else if (state === State.DISCONNECTED) {
newState = ConnectionState.SUSPENDED;
}
else {
// AUTH_FAILED and SASL_AUTHENTICATED are not handled, yep.
return;
}
rorschach.state = newState;
rorschach.emit('connectionStateChanged', newState);
}
} | [
"function",
"initZooKeeper",
"(",
"rorschach",
",",
"connectionString",
",",
"options",
")",
"{",
"var",
"error",
";",
"var",
"zk",
"=",
"zookeeper",
".",
"createClient",
"(",
"connectionString",
",",
"options",
")",
";",
"rorschach",
".",
"zk",
"=",
"zk",
";",
"zk",
".",
"connect",
"(",
")",
";",
"zk",
".",
"on",
"(",
"'connected'",
",",
"onconnected",
")",
";",
"zk",
".",
"on",
"(",
"'expired'",
",",
"setError",
")",
";",
"zk",
".",
"on",
"(",
"'authenticationFailed'",
",",
"setError",
")",
";",
"zk",
".",
"on",
"(",
"'disconnected'",
",",
"ondisconnected",
")",
";",
"zk",
".",
"on",
"(",
"'state'",
",",
"handleStateChange",
")",
";",
"function",
"onconnected",
"(",
")",
"{",
"error",
"=",
"false",
";",
"}",
"function",
"setError",
"(",
")",
"{",
"error",
"=",
"true",
";",
"}",
"function",
"ondisconnected",
"(",
")",
"{",
"if",
"(",
"rorschach",
".",
"closed",
")",
"{",
"return",
";",
"}",
"if",
"(",
"error",
")",
"{",
"zk",
".",
"removeListener",
"(",
"'connected'",
",",
"onconnected",
")",
";",
"zk",
".",
"removeListener",
"(",
"'disconnected'",
",",
"ondisconnected",
")",
";",
"zk",
".",
"removeListener",
"(",
"'expired'",
",",
"setError",
")",
";",
"zk",
".",
"removeListener",
"(",
"'authenticationFailed'",
",",
"setError",
")",
";",
"zk",
".",
"removeListener",
"(",
"'state'",
",",
"handleStateChange",
")",
";",
"zk",
".",
"close",
"(",
")",
";",
"initZooKeeper",
"(",
"rorschach",
",",
"connectionString",
",",
"options",
")",
";",
"}",
"}",
"function",
"handleStateChange",
"(",
"state",
")",
"{",
"var",
"newState",
";",
"if",
"(",
"state",
"===",
"State",
".",
"SYNC_CONNECTED",
")",
"{",
"if",
"(",
"!",
"rorschach",
".",
"ready",
")",
"{",
"rorschach",
".",
"ready",
"=",
"true",
";",
"rorschach",
".",
"emit",
"(",
"'connected'",
")",
";",
"newState",
"=",
"ConnectionState",
".",
"CONNECTED",
";",
"}",
"else",
"{",
"newState",
"=",
"ConnectionState",
".",
"RECONNECTED",
";",
"}",
"}",
"else",
"if",
"(",
"state",
"===",
"State",
".",
"CONNECTED_READ_ONLY",
")",
"{",
"newState",
"=",
"ConnectionState",
".",
"READ_ONLY",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"State",
".",
"EXPIRED",
")",
"{",
"newState",
"=",
"ConnectionState",
".",
"LOST",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"State",
".",
"DISCONNECTED",
")",
"{",
"newState",
"=",
"ConnectionState",
".",
"SUSPENDED",
";",
"}",
"else",
"{",
"// AUTH_FAILED and SASL_AUTHENTICATED are not handled, yep.",
"return",
";",
"}",
"rorschach",
".",
"state",
"=",
"newState",
";",
"rorschach",
".",
"emit",
"(",
"'connectionStateChanged'",
",",
"newState",
")",
";",
"}",
"}"
]
| Initialize connection with ZooKeeper.
@param {Rorschach} rorschach Rorschach instance
@param {String} connectionString Connection string
@param {Object} options ZooKeeper options. | [
"Initialize",
"connection",
"with",
"ZooKeeper",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/index.js#L183-L251 |
47,701 | zakandrewking/tinier | src/tinier.js | updateComponents | function updateComponents (address, node, state, diff, bindings, renderResult,
relativeAddress, stateCallers, opts) {
// TODO pull these out to top level
const updateRecurse = ([ d, s ], k) => {
// TODO in updateRecurse functions where k can be null, there must be a
// nicer way to organize things with fewer null checks
const component = k !== null ? node.component : node
const newAddress = k !== null ? addressWith(address, k) : address
const newRelativeAddress = k !== null
? addressWith(relativeAddress, k)
: relativeAddress
const b = k !== null ? get(bindings, k) : bindings
// Get binding el
const lastRenderedEl = get(b, 'data')
const el = renderResult !== null
? renderResult[makeBindingKey(newRelativeAddress)]
: lastRenderedEl
// Update the component. If DESTROY, then there will not be a binding.
const res = updateEl(newAddress, component, s, d.data, lastRenderedEl, el,
stateCallers, opts)
// Fall back on old bindings.
const nextRenderResult = res.renderResult !== null
? res.renderResult
: null
// Update children
const children = updateComponents(newAddress, component.model, s,
d.children, get(b, 'children'),
nextRenderResult, [], stateCallers, opts)
return tagType(NODE, { data: el, children })
}
// TODO pull these out to top level
const recurse = (n, k) => {
return updateComponents(addressWith(address, k), n, get(state, k), diff[k],
get(bindings, k), renderResult,
addressWith(relativeAddress, k), stateCallers, opts)
}
return match(node, match_updateComponents, null, diff, state, updateRecurse,
recurse)
} | javascript | function updateComponents (address, node, state, diff, bindings, renderResult,
relativeAddress, stateCallers, opts) {
// TODO pull these out to top level
const updateRecurse = ([ d, s ], k) => {
// TODO in updateRecurse functions where k can be null, there must be a
// nicer way to organize things with fewer null checks
const component = k !== null ? node.component : node
const newAddress = k !== null ? addressWith(address, k) : address
const newRelativeAddress = k !== null
? addressWith(relativeAddress, k)
: relativeAddress
const b = k !== null ? get(bindings, k) : bindings
// Get binding el
const lastRenderedEl = get(b, 'data')
const el = renderResult !== null
? renderResult[makeBindingKey(newRelativeAddress)]
: lastRenderedEl
// Update the component. If DESTROY, then there will not be a binding.
const res = updateEl(newAddress, component, s, d.data, lastRenderedEl, el,
stateCallers, opts)
// Fall back on old bindings.
const nextRenderResult = res.renderResult !== null
? res.renderResult
: null
// Update children
const children = updateComponents(newAddress, component.model, s,
d.children, get(b, 'children'),
nextRenderResult, [], stateCallers, opts)
return tagType(NODE, { data: el, children })
}
// TODO pull these out to top level
const recurse = (n, k) => {
return updateComponents(addressWith(address, k), n, get(state, k), diff[k],
get(bindings, k), renderResult,
addressWith(relativeAddress, k), stateCallers, opts)
}
return match(node, match_updateComponents, null, diff, state, updateRecurse,
recurse)
} | [
"function",
"updateComponents",
"(",
"address",
",",
"node",
",",
"state",
",",
"diff",
",",
"bindings",
",",
"renderResult",
",",
"relativeAddress",
",",
"stateCallers",
",",
"opts",
")",
"{",
"// TODO pull these out to top level",
"const",
"updateRecurse",
"=",
"(",
"[",
"d",
",",
"s",
"]",
",",
"k",
")",
"=>",
"{",
"// TODO in updateRecurse functions where k can be null, there must be a",
"// nicer way to organize things with fewer null checks",
"const",
"component",
"=",
"k",
"!==",
"null",
"?",
"node",
".",
"component",
":",
"node",
"const",
"newAddress",
"=",
"k",
"!==",
"null",
"?",
"addressWith",
"(",
"address",
",",
"k",
")",
":",
"address",
"const",
"newRelativeAddress",
"=",
"k",
"!==",
"null",
"?",
"addressWith",
"(",
"relativeAddress",
",",
"k",
")",
":",
"relativeAddress",
"const",
"b",
"=",
"k",
"!==",
"null",
"?",
"get",
"(",
"bindings",
",",
"k",
")",
":",
"bindings",
"// Get binding el",
"const",
"lastRenderedEl",
"=",
"get",
"(",
"b",
",",
"'data'",
")",
"const",
"el",
"=",
"renderResult",
"!==",
"null",
"?",
"renderResult",
"[",
"makeBindingKey",
"(",
"newRelativeAddress",
")",
"]",
":",
"lastRenderedEl",
"// Update the component. If DESTROY, then there will not be a binding.",
"const",
"res",
"=",
"updateEl",
"(",
"newAddress",
",",
"component",
",",
"s",
",",
"d",
".",
"data",
",",
"lastRenderedEl",
",",
"el",
",",
"stateCallers",
",",
"opts",
")",
"// Fall back on old bindings.",
"const",
"nextRenderResult",
"=",
"res",
".",
"renderResult",
"!==",
"null",
"?",
"res",
".",
"renderResult",
":",
"null",
"// Update children",
"const",
"children",
"=",
"updateComponents",
"(",
"newAddress",
",",
"component",
".",
"model",
",",
"s",
",",
"d",
".",
"children",
",",
"get",
"(",
"b",
",",
"'children'",
")",
",",
"nextRenderResult",
",",
"[",
"]",
",",
"stateCallers",
",",
"opts",
")",
"return",
"tagType",
"(",
"NODE",
",",
"{",
"data",
":",
"el",
",",
"children",
"}",
")",
"}",
"// TODO pull these out to top level",
"const",
"recurse",
"=",
"(",
"n",
",",
"k",
")",
"=>",
"{",
"return",
"updateComponents",
"(",
"addressWith",
"(",
"address",
",",
"k",
")",
",",
"n",
",",
"get",
"(",
"state",
",",
"k",
")",
",",
"diff",
"[",
"k",
"]",
",",
"get",
"(",
"bindings",
",",
"k",
")",
",",
"renderResult",
",",
"addressWith",
"(",
"relativeAddress",
",",
"k",
")",
",",
"stateCallers",
",",
"opts",
")",
"}",
"return",
"match",
"(",
"node",
",",
"match_updateComponents",
",",
"null",
",",
"diff",
",",
"state",
",",
"updateRecurse",
",",
"recurse",
")",
"}"
]
| Run create, update, and destroy for component.
@param {Array} address - The location of the component in the state.
@param {Object} node - A model or a node within a model.
@param {Object} diff - The diff object for this component.
@param {Object|null} bindings -
@param {Object|null} renderResult -
@param {Object} stateCallers -
@return {Object} | [
"Run",
"create",
"update",
"and",
"destroy",
"for",
"component",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L444-L486 |
47,702 | zakandrewking/tinier | src/tinier.js | treeGet | function treeGet (address, tree) {
return address.reduce((accum, val) => {
return checkType(NODE, accum) ? accum.children[val] : accum[val]
}, tree)
} | javascript | function treeGet (address, tree) {
return address.reduce((accum, val) => {
return checkType(NODE, accum) ? accum.children[val] : accum[val]
}, tree)
} | [
"function",
"treeGet",
"(",
"address",
",",
"tree",
")",
"{",
"return",
"address",
".",
"reduce",
"(",
"(",
"accum",
",",
"val",
")",
"=>",
"{",
"return",
"checkType",
"(",
"NODE",
",",
"accum",
")",
"?",
"accum",
".",
"children",
"[",
"val",
"]",
":",
"accum",
"[",
"val",
"]",
"}",
",",
"tree",
")",
"}"
]
| Get the value in a tree.
@param {Array} address -
@param {Object} tree -
@return {*} - The value at the given address. | [
"Get",
"the",
"value",
"in",
"a",
"tree",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L513-L517 |
47,703 | zakandrewking/tinier | src/tinier.js | treeSet | function treeSet (address, tree, value) {
if (address.length === 0) {
return value
} else {
const [ k, rest ] = head(address)
return (typeof k === 'string' ?
{ ...tree, [k]: treeSet(rest, treeGet([ k ], tree), value) } :
[ ...tree.slice(0, k), treeSet(rest, treeGet([ k ], tree), value),
...tree.slice(k + 1) ])
}
} | javascript | function treeSet (address, tree, value) {
if (address.length === 0) {
return value
} else {
const [ k, rest ] = head(address)
return (typeof k === 'string' ?
{ ...tree, [k]: treeSet(rest, treeGet([ k ], tree), value) } :
[ ...tree.slice(0, k), treeSet(rest, treeGet([ k ], tree), value),
...tree.slice(k + 1) ])
}
} | [
"function",
"treeSet",
"(",
"address",
",",
"tree",
",",
"value",
")",
"{",
"if",
"(",
"address",
".",
"length",
"===",
"0",
")",
"{",
"return",
"value",
"}",
"else",
"{",
"const",
"[",
"k",
",",
"rest",
"]",
"=",
"head",
"(",
"address",
")",
"return",
"(",
"typeof",
"k",
"===",
"'string'",
"?",
"{",
"...",
"tree",
",",
"[",
"k",
"]",
":",
"treeSet",
"(",
"rest",
",",
"treeGet",
"(",
"[",
"k",
"]",
",",
"tree",
")",
",",
"value",
")",
"}",
":",
"[",
"...",
"tree",
".",
"slice",
"(",
"0",
",",
"k",
")",
",",
"treeSet",
"(",
"rest",
",",
"treeGet",
"(",
"[",
"k",
"]",
",",
"tree",
")",
",",
"value",
")",
",",
"...",
"tree",
".",
"slice",
"(",
"k",
"+",
"1",
")",
"]",
")",
"}",
"}"
]
| Set the value in a tree; immutable.
@param {Array} address -
@param {Object} tree -
@param {*} value - The new value to set at address.
@return (*) The new tree. | [
"Set",
"the",
"value",
"in",
"a",
"tree",
";",
"immutable",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L526-L536 |
47,704 | zakandrewking/tinier | src/tinier.js | treeSetMutable | function treeSetMutable (address, tree, value) {
if (address.length === 0) {
return value
} else {
const [ rest, last ] = tail(address)
const parent = treeGet(rest, tree)
if (checkType(NODE, parent)) {
parent.children[last] = value
} else {
parent[last] = value
}
return tree
}
} | javascript | function treeSetMutable (address, tree, value) {
if (address.length === 0) {
return value
} else {
const [ rest, last ] = tail(address)
const parent = treeGet(rest, tree)
if (checkType(NODE, parent)) {
parent.children[last] = value
} else {
parent[last] = value
}
return tree
}
} | [
"function",
"treeSetMutable",
"(",
"address",
",",
"tree",
",",
"value",
")",
"{",
"if",
"(",
"address",
".",
"length",
"===",
"0",
")",
"{",
"return",
"value",
"}",
"else",
"{",
"const",
"[",
"rest",
",",
"last",
"]",
"=",
"tail",
"(",
"address",
")",
"const",
"parent",
"=",
"treeGet",
"(",
"rest",
",",
"tree",
")",
"if",
"(",
"checkType",
"(",
"NODE",
",",
"parent",
")",
")",
"{",
"parent",
".",
"children",
"[",
"last",
"]",
"=",
"value",
"}",
"else",
"{",
"parent",
"[",
"last",
"]",
"=",
"value",
"}",
"return",
"tree",
"}",
"}"
]
| Set the value in a tree; mutable.
@param {Array} address -
@param {Object} tree -
@param {*} value - The new value to set at address.
@return (*) The tree. | [
"Set",
"the",
"value",
"in",
"a",
"tree",
";",
"mutable",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L545-L558 |
47,705 | zakandrewking/tinier | src/tinier.js | diffWithModel | function diffWithModel (modelNode, state, lastState, address,
triggeringAddress) {
return match(modelNode, match_diffWithModel, null, modelNode, state,
lastState, address, triggeringAddress)
} | javascript | function diffWithModel (modelNode, state, lastState, address,
triggeringAddress) {
return match(modelNode, match_diffWithModel, null, modelNode, state,
lastState, address, triggeringAddress)
} | [
"function",
"diffWithModel",
"(",
"modelNode",
",",
"state",
",",
"lastState",
",",
"address",
",",
"triggeringAddress",
")",
"{",
"return",
"match",
"(",
"modelNode",
",",
"match_diffWithModel",
",",
"null",
",",
"modelNode",
",",
"state",
",",
"lastState",
",",
"address",
",",
"triggeringAddress",
")",
"}"
]
| Compute the full diff tree for the model node. Calls shouldUpdate. | [
"Compute",
"the",
"full",
"diff",
"tree",
"for",
"the",
"model",
"node",
".",
"Calls",
"shouldUpdate",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L711-L715 |
47,706 | zakandrewking/tinier | src/tinier.js | singleOrAll | function singleOrAll (modelNode, address, minTreeAr) {
const getMin = indices => {
if (indices.length === 0) {
// If all elements in the array are null, return null.
return null
} else if (nonNullIndices.signals.length === 1) {
// If there is a single value, return that tree, with an updated address.
return {
minSignals: {
diff: minTreeAr.map(a => a.minSignals.diff),
address,
modelNode,
},
minUpdate: {
diff: minTreeAr.map(a => a.minUpdate.diff),
address,
modelNode,
},
}
} else {
// Otherwise, return full trees from this level.
return {
minSignals: {
diff: minTreeAr.map(a => a.minSignals.diff),
address,
modelNode,
},
minUpdate: {
diff: minTreeAr.map(a => a.minUpdate.diff),
address,
modelNode,
},
}
}
}
// Get the indices where the signal and update trees are not null.
const nonNullIndices = minTreeAr.reduce((accum, val, i) => {
return {
signals: val.minSignals !== null ? [ ...accum.signals, i ]: accum.signals,
update: val.minUpdate !== null ? [ ...accum.update, i ]: accum.update,
}
}, { signals: [], update: [] })
// For each set of indices, test the diffs with these tests to get a minimum
// tree.
const minSignals = getMin(nonNullIndices.signals)
const minUpdate = getMin(nonNullIndices.update)
return { minSignals, minUpdate }
} | javascript | function singleOrAll (modelNode, address, minTreeAr) {
const getMin = indices => {
if (indices.length === 0) {
// If all elements in the array are null, return null.
return null
} else if (nonNullIndices.signals.length === 1) {
// If there is a single value, return that tree, with an updated address.
return {
minSignals: {
diff: minTreeAr.map(a => a.minSignals.diff),
address,
modelNode,
},
minUpdate: {
diff: minTreeAr.map(a => a.minUpdate.diff),
address,
modelNode,
},
}
} else {
// Otherwise, return full trees from this level.
return {
minSignals: {
diff: minTreeAr.map(a => a.minSignals.diff),
address,
modelNode,
},
minUpdate: {
diff: minTreeAr.map(a => a.minUpdate.diff),
address,
modelNode,
},
}
}
}
// Get the indices where the signal and update trees are not null.
const nonNullIndices = minTreeAr.reduce((accum, val, i) => {
return {
signals: val.minSignals !== null ? [ ...accum.signals, i ]: accum.signals,
update: val.minUpdate !== null ? [ ...accum.update, i ]: accum.update,
}
}, { signals: [], update: [] })
// For each set of indices, test the diffs with these tests to get a minimum
// tree.
const minSignals = getMin(nonNullIndices.signals)
const minUpdate = getMin(nonNullIndices.update)
return { minSignals, minUpdate }
} | [
"function",
"singleOrAll",
"(",
"modelNode",
",",
"address",
",",
"minTreeAr",
")",
"{",
"const",
"getMin",
"=",
"indices",
"=>",
"{",
"if",
"(",
"indices",
".",
"length",
"===",
"0",
")",
"{",
"// If all elements in the array are null, return null.",
"return",
"null",
"}",
"else",
"if",
"(",
"nonNullIndices",
".",
"signals",
".",
"length",
"===",
"1",
")",
"{",
"// If there is a single value, return that tree, with an updated address.",
"return",
"{",
"minSignals",
":",
"{",
"diff",
":",
"minTreeAr",
".",
"map",
"(",
"a",
"=>",
"a",
".",
"minSignals",
".",
"diff",
")",
",",
"address",
",",
"modelNode",
",",
"}",
",",
"minUpdate",
":",
"{",
"diff",
":",
"minTreeAr",
".",
"map",
"(",
"a",
"=>",
"a",
".",
"minUpdate",
".",
"diff",
")",
",",
"address",
",",
"modelNode",
",",
"}",
",",
"}",
"}",
"else",
"{",
"// Otherwise, return full trees from this level.",
"return",
"{",
"minSignals",
":",
"{",
"diff",
":",
"minTreeAr",
".",
"map",
"(",
"a",
"=>",
"a",
".",
"minSignals",
".",
"diff",
")",
",",
"address",
",",
"modelNode",
",",
"}",
",",
"minUpdate",
":",
"{",
"diff",
":",
"minTreeAr",
".",
"map",
"(",
"a",
"=>",
"a",
".",
"minUpdate",
".",
"diff",
")",
",",
"address",
",",
"modelNode",
",",
"}",
",",
"}",
"}",
"}",
"// Get the indices where the signal and update trees are not null.",
"const",
"nonNullIndices",
"=",
"minTreeAr",
".",
"reduce",
"(",
"(",
"accum",
",",
"val",
",",
"i",
")",
"=>",
"{",
"return",
"{",
"signals",
":",
"val",
".",
"minSignals",
"!==",
"null",
"?",
"[",
"...",
"accum",
".",
"signals",
",",
"i",
"]",
":",
"accum",
".",
"signals",
",",
"update",
":",
"val",
".",
"minUpdate",
"!==",
"null",
"?",
"[",
"...",
"accum",
".",
"update",
",",
"i",
"]",
":",
"accum",
".",
"update",
",",
"}",
"}",
",",
"{",
"signals",
":",
"[",
"]",
",",
"update",
":",
"[",
"]",
"}",
")",
"// For each set of indices, test the diffs with these tests to get a minimum",
"// tree.",
"const",
"minSignals",
"=",
"getMin",
"(",
"nonNullIndices",
".",
"signals",
")",
"const",
"minUpdate",
"=",
"getMin",
"(",
"nonNullIndices",
".",
"update",
")",
"return",
"{",
"minSignals",
",",
"minUpdate",
"}",
"}"
]
| For an array of minSignals and minUpdate trees, return the minimal trees that
represent the whole array. | [
"For",
"an",
"array",
"of",
"minSignals",
"and",
"minUpdate",
"trees",
"return",
"the",
"minimal",
"trees",
"that",
"represent",
"the",
"whole",
"array",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L721-L768 |
47,707 | zakandrewking/tinier | src/tinier.js | makeSignalsAPI | function makeSignalsAPI (signalNames, isCollection) {
return fromPairs(signalNames.map(name => {
return [ name, makeOneSignalAPI(isCollection) ]
}))
} | javascript | function makeSignalsAPI (signalNames, isCollection) {
return fromPairs(signalNames.map(name => {
return [ name, makeOneSignalAPI(isCollection) ]
}))
} | [
"function",
"makeSignalsAPI",
"(",
"signalNames",
",",
"isCollection",
")",
"{",
"return",
"fromPairs",
"(",
"signalNames",
".",
"map",
"(",
"name",
"=>",
"{",
"return",
"[",
"name",
",",
"makeOneSignalAPI",
"(",
"isCollection",
")",
"]",
"}",
")",
")",
"}"
]
| Implement the signals API. | [
"Implement",
"the",
"signals",
"API",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L867-L871 |
47,708 | zakandrewking/tinier | src/tinier.js | runSignalSetup | function runSignalSetup (component, address, stateCallers) {
const signalsAPI = makeSignalsAPI(component.signalNames, false)
const childSignalsAPI = makeChildSignalsAPI(component.model)
const reducers = patchReducersWithState(address, component, stateCallers.callReducer)
const signals = patchSignals(address, component, stateCallers.callSignal)
const methods = patchMethods(address, component, stateCallers.callMethod,
reducers, signals)
// cannot call signalSetup any earlier because it needs a reference to
// `methods`, which must know the address
component.signalSetup({
methods,
reducers,
signals: signalsAPI,
childSignals: childSignalsAPI,
})
return { signalsAPI, childSignalsAPI }
} | javascript | function runSignalSetup (component, address, stateCallers) {
const signalsAPI = makeSignalsAPI(component.signalNames, false)
const childSignalsAPI = makeChildSignalsAPI(component.model)
const reducers = patchReducersWithState(address, component, stateCallers.callReducer)
const signals = patchSignals(address, component, stateCallers.callSignal)
const methods = patchMethods(address, component, stateCallers.callMethod,
reducers, signals)
// cannot call signalSetup any earlier because it needs a reference to
// `methods`, which must know the address
component.signalSetup({
methods,
reducers,
signals: signalsAPI,
childSignals: childSignalsAPI,
})
return { signalsAPI, childSignalsAPI }
} | [
"function",
"runSignalSetup",
"(",
"component",
",",
"address",
",",
"stateCallers",
")",
"{",
"const",
"signalsAPI",
"=",
"makeSignalsAPI",
"(",
"component",
".",
"signalNames",
",",
"false",
")",
"const",
"childSignalsAPI",
"=",
"makeChildSignalsAPI",
"(",
"component",
".",
"model",
")",
"const",
"reducers",
"=",
"patchReducersWithState",
"(",
"address",
",",
"component",
",",
"stateCallers",
".",
"callReducer",
")",
"const",
"signals",
"=",
"patchSignals",
"(",
"address",
",",
"component",
",",
"stateCallers",
".",
"callSignal",
")",
"const",
"methods",
"=",
"patchMethods",
"(",
"address",
",",
"component",
",",
"stateCallers",
".",
"callMethod",
",",
"reducers",
",",
"signals",
")",
"// cannot call signalSetup any earlier because it needs a reference to",
"// `methods`, which must know the address",
"component",
".",
"signalSetup",
"(",
"{",
"methods",
",",
"reducers",
",",
"signals",
":",
"signalsAPI",
",",
"childSignals",
":",
"childSignalsAPI",
",",
"}",
")",
"return",
"{",
"signalsAPI",
",",
"childSignalsAPI",
"}",
"}"
]
| Run signalSetup with the component.
@param {Object} component -
@param {Array} address -
@param {Object} stateCallers -
@return {Object} Object with keys signalsAPI and childSignalsAPI. | [
"Run",
"signalSetup",
"with",
"the",
"component",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L921-L937 |
47,709 | zakandrewking/tinier | src/tinier.js | makeCallSignal | function makeCallSignal (signals, opts) {
return (address, signalName, arg) => {
if (opts.verbose) {
console.log('Called signal ' + signalName + ' at [' + address.join(', ') +
'].')
}
signals.get(address).data.signals[signalName].call(arg)
}
} | javascript | function makeCallSignal (signals, opts) {
return (address, signalName, arg) => {
if (opts.verbose) {
console.log('Called signal ' + signalName + ' at [' + address.join(', ') +
'].')
}
signals.get(address).data.signals[signalName].call(arg)
}
} | [
"function",
"makeCallSignal",
"(",
"signals",
",",
"opts",
")",
"{",
"return",
"(",
"address",
",",
"signalName",
",",
"arg",
")",
"=>",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"console",
".",
"log",
"(",
"'Called signal '",
"+",
"signalName",
"+",
"' at ['",
"+",
"address",
".",
"join",
"(",
"', '",
")",
"+",
"'].'",
")",
"}",
"signals",
".",
"get",
"(",
"address",
")",
".",
"data",
".",
"signals",
"[",
"signalName",
"]",
".",
"call",
"(",
"arg",
")",
"}",
"}"
]
| Return a callSignal function. | [
"Return",
"a",
"callSignal",
"function",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L1269-L1277 |
47,710 | zakandrewking/tinier | src/tinier.js | keyBy | function keyBy (arr, key) {
var obj = {}
arr.map(x => obj[x[key]] = x)
return obj
} | javascript | function keyBy (arr, key) {
var obj = {}
arr.map(x => obj[x[key]] = x)
return obj
} | [
"function",
"keyBy",
"(",
"arr",
",",
"key",
")",
"{",
"var",
"obj",
"=",
"{",
"}",
"arr",
".",
"map",
"(",
"x",
"=>",
"obj",
"[",
"x",
"[",
"key",
"]",
"]",
"=",
"x",
")",
"return",
"obj",
"}"
]
| Turn an array of objects into a new object of objects where the keys are
given by the value of `key` in each child object.
@param {[Object]} arr - The array of objects.
@param {String} key - The key to look for. | [
"Turn",
"an",
"array",
"of",
"objects",
"into",
"a",
"new",
"object",
"of",
"objects",
"where",
"the",
"keys",
"are",
"given",
"by",
"the",
"value",
"of",
"key",
"in",
"each",
"child",
"object",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L1470-L1474 |
47,711 | zakandrewking/tinier | src/tinier.js | isText | function isText (o) {
return (o && typeof o === 'object' && o !== null &&
o.nodeType === 3 && typeof o.nodeName === 'string')
} | javascript | function isText (o) {
return (o && typeof o === 'object' && o !== null &&
o.nodeType === 3 && typeof o.nodeName === 'string')
} | [
"function",
"isText",
"(",
"o",
")",
"{",
"return",
"(",
"o",
"&&",
"typeof",
"o",
"===",
"'object'",
"&&",
"o",
"!==",
"null",
"&&",
"o",
".",
"nodeType",
"===",
"3",
"&&",
"typeof",
"o",
".",
"nodeName",
"===",
"'string'",
")",
"}"
]
| Returns true if it is a DOM text element. | [
"Returns",
"true",
"if",
"it",
"is",
"a",
"DOM",
"text",
"element",
"."
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L1492-L1495 |
47,712 | zakandrewking/tinier | src/tinier.js | flattenElementsAr | function flattenElementsAr (ar) {
return ar.reduce((acc, el) => {
return isArray(el) ? [ ...acc, ...el ] : [ ...acc, el ]
}, []).filter(notNull) // null means ignore
} | javascript | function flattenElementsAr (ar) {
return ar.reduce((acc, el) => {
return isArray(el) ? [ ...acc, ...el ] : [ ...acc, el ]
}, []).filter(notNull) // null means ignore
} | [
"function",
"flattenElementsAr",
"(",
"ar",
")",
"{",
"return",
"ar",
".",
"reduce",
"(",
"(",
"acc",
",",
"el",
")",
"=>",
"{",
"return",
"isArray",
"(",
"el",
")",
"?",
"[",
"...",
"acc",
",",
"...",
"el",
"]",
":",
"[",
"...",
"acc",
",",
"el",
"]",
"}",
",",
"[",
"]",
")",
".",
"filter",
"(",
"notNull",
")",
"// null means ignore",
"}"
]
| flatten the elements array | [
"flatten",
"the",
"elements",
"array"
]
| 05ee87bc6a52d9f411b45d145e0a62f543039a07 | https://github.com/zakandrewking/tinier/blob/05ee87bc6a52d9f411b45d145e0a62f543039a07/src/tinier.js#L1689-L1693 |
47,713 | nodejitsu/npm-search-pagelet | client.js | redirect | function redirect(e) {
if (e && e.preventDefault) e.preventDefault();
//
// Assume that the value in the $control_input is uptodate. If not get the
// value directly through the constructor. When the selectize is still
// loading results the `getValue()` will return an empty value. This is why
// we do a double value check.
//
var selectize = select[0].selectize
, value = selectize.$control_input.val() || selectize.getValue();
if (!value) return;
window.location = '/package/'+ value;
} | javascript | function redirect(e) {
if (e && e.preventDefault) e.preventDefault();
//
// Assume that the value in the $control_input is uptodate. If not get the
// value directly through the constructor. When the selectize is still
// loading results the `getValue()` will return an empty value. This is why
// we do a double value check.
//
var selectize = select[0].selectize
, value = selectize.$control_input.val() || selectize.getValue();
if (!value) return;
window.location = '/package/'+ value;
} | [
"function",
"redirect",
"(",
"e",
")",
"{",
"if",
"(",
"e",
"&&",
"e",
".",
"preventDefault",
")",
"e",
".",
"preventDefault",
"(",
")",
";",
"//",
"// Assume that the value in the $control_input is uptodate. If not get the",
"// value directly through the constructor. When the selectize is still",
"// loading results the `getValue()` will return an empty value. This is why",
"// we do a double value check.",
"//",
"var",
"selectize",
"=",
"select",
"[",
"0",
"]",
".",
"selectize",
",",
"value",
"=",
"selectize",
".",
"$control_input",
".",
"val",
"(",
")",
"||",
"selectize",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"!",
"value",
")",
"return",
";",
"window",
".",
"location",
"=",
"'/package/'",
"+",
"value",
";",
"}"
]
| Bypass the submit functionality and just redirect manually so we don't have
to do a server callback.
@param {Event} e Optional event
@api private | [
"Bypass",
"the",
"submit",
"functionality",
"and",
"just",
"redirect",
"manually",
"so",
"we",
"don",
"t",
"have",
"to",
"do",
"a",
"server",
"callback",
"."
]
| a6086c627b69c36c0cf638dc994c25f3d9d5df72 | https://github.com/nodejitsu/npm-search-pagelet/blob/a6086c627b69c36c0cf638dc994c25f3d9d5df72/client.js#L13-L28 |
47,714 | nodejitsu/npm-search-pagelet | client.js | load | function load(query, callback) {
if (!query.length) return callback();
pagelet.complete(query, function complete(err, results) {
if (err) return callback();
callback(results);
});
} | javascript | function load(query, callback) {
if (!query.length) return callback();
pagelet.complete(query, function complete(err, results) {
if (err) return callback();
callback(results);
});
} | [
"function",
"load",
"(",
"query",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"query",
".",
"length",
")",
"return",
"callback",
"(",
")",
";",
"pagelet",
".",
"complete",
"(",
"query",
",",
"function",
"complete",
"(",
"err",
",",
"results",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
")",
";",
"callback",
"(",
"results",
")",
";",
"}",
")",
";",
"}"
]
| Load the autocomplete results through the Pagelet's RPC methods.
@param {String} query Thing that we search for
@param {Function} callback Callback
@api private | [
"Load",
"the",
"autocomplete",
"results",
"through",
"the",
"Pagelet",
"s",
"RPC",
"methods",
"."
]
| a6086c627b69c36c0cf638dc994c25f3d9d5df72 | https://github.com/nodejitsu/npm-search-pagelet/blob/a6086c627b69c36c0cf638dc994c25f3d9d5df72/client.js#L46-L54 |
47,715 | nodejitsu/npm-search-pagelet | client.js | render | function render(item, escape) {
return [
'<div class="completed">',
'<strong class="name">'+ escape(item.name) +'</strong>',
'string' === typeof item.desc ? '<span class="description">'+ escape(item.desc) +'</span>' : '',
'</div>'
].join('');
} | javascript | function render(item, escape) {
return [
'<div class="completed">',
'<strong class="name">'+ escape(item.name) +'</strong>',
'string' === typeof item.desc ? '<span class="description">'+ escape(item.desc) +'</span>' : '',
'</div>'
].join('');
} | [
"function",
"render",
"(",
"item",
",",
"escape",
")",
"{",
"return",
"[",
"'<div class=\"completed\">'",
",",
"'<strong class=\"name\">'",
"+",
"escape",
"(",
"item",
".",
"name",
")",
"+",
"'</strong>'",
",",
"'string'",
"===",
"typeof",
"item",
".",
"desc",
"?",
"'<span class=\"description\">'",
"+",
"escape",
"(",
"item",
".",
"desc",
")",
"+",
"'</span>'",
":",
"''",
",",
"'</div>'",
"]",
".",
"join",
"(",
"''",
")",
";",
"}"
]
| Custom layout renderer for items.
@param {Object} item The thing returned from the server.
@param {Function} escape Custom HTML escaper.
@returns {String}
@api private | [
"Custom",
"layout",
"renderer",
"for",
"items",
"."
]
| a6086c627b69c36c0cf638dc994c25f3d9d5df72 | https://github.com/nodejitsu/npm-search-pagelet/blob/a6086c627b69c36c0cf638dc994c25f3d9d5df72/client.js#L65-L72 |
47,716 | fvsch/gulp-task-maker | helpers.js | customLog | function customLog(message) {
const trimmed = message.trim()
const limit = trimmed.indexOf('\n')
if (limit === -1) {
fancyLog(trimmed)
} else {
const title = trimmed.slice(0, limit).trim()
const details = trimmed.slice(limit).trim()
fancyLog(`${title}${('\n' + details).replace(/\n/g, '\n ')}`)
}
} | javascript | function customLog(message) {
const trimmed = message.trim()
const limit = trimmed.indexOf('\n')
if (limit === -1) {
fancyLog(trimmed)
} else {
const title = trimmed.slice(0, limit).trim()
const details = trimmed.slice(limit).trim()
fancyLog(`${title}${('\n' + details).replace(/\n/g, '\n ')}`)
}
} | [
"function",
"customLog",
"(",
"message",
")",
"{",
"const",
"trimmed",
"=",
"message",
".",
"trim",
"(",
")",
"const",
"limit",
"=",
"trimmed",
".",
"indexOf",
"(",
"'\\n'",
")",
"if",
"(",
"limit",
"===",
"-",
"1",
")",
"{",
"fancyLog",
"(",
"trimmed",
")",
"}",
"else",
"{",
"const",
"title",
"=",
"trimmed",
".",
"slice",
"(",
"0",
",",
"limit",
")",
".",
"trim",
"(",
")",
"const",
"details",
"=",
"trimmed",
".",
"slice",
"(",
"limit",
")",
".",
"trim",
"(",
")",
"fancyLog",
"(",
"`",
"${",
"title",
"}",
"${",
"(",
"'\\n'",
"+",
"details",
")",
".",
"replace",
"(",
"/",
"\\n",
"/",
"g",
",",
"'\\n '",
")",
"}",
"`",
")",
"}",
"}"
]
| Custom long log format using fancy-log
@param {string} message | [
"Custom",
"long",
"log",
"format",
"using",
"fancy",
"-",
"log"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/helpers.js#L7-L17 |
47,717 | fvsch/gulp-task-maker | helpers.js | toUniqueStrings | function toUniqueStrings(input) {
const list = (Array.isArray(input) ? input : [input])
.map(el => (typeof el === 'string' ? el.trim() : null))
.filter(Boolean)
return list.length > 1 ? Array.from(new Set(list)) : list
} | javascript | function toUniqueStrings(input) {
const list = (Array.isArray(input) ? input : [input])
.map(el => (typeof el === 'string' ? el.trim() : null))
.filter(Boolean)
return list.length > 1 ? Array.from(new Set(list)) : list
} | [
"function",
"toUniqueStrings",
"(",
"input",
")",
"{",
"const",
"list",
"=",
"(",
"Array",
".",
"isArray",
"(",
"input",
")",
"?",
"input",
":",
"[",
"input",
"]",
")",
".",
"map",
"(",
"el",
"=>",
"(",
"typeof",
"el",
"===",
"'string'",
"?",
"el",
".",
"trim",
"(",
")",
":",
"null",
")",
")",
".",
"filter",
"(",
"Boolean",
")",
"return",
"list",
".",
"length",
">",
"1",
"?",
"Array",
".",
"from",
"(",
"new",
"Set",
"(",
"list",
")",
")",
":",
"list",
"}"
]
| Return an array of unique trimmed strings,
from input which can be a string or an array of strings
@param {Array|string} input
@return {string[]} | [
"Return",
"an",
"array",
"of",
"unique",
"trimmed",
"strings",
"from",
"input",
"which",
"can",
"be",
"a",
"string",
"or",
"an",
"array",
"of",
"strings"
]
| 20ab4245f2d75174786ad140793e9438c025d546 | https://github.com/fvsch/gulp-task-maker/blob/20ab4245f2d75174786ad140793e9438c025d546/helpers.js#L74-L79 |
47,718 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/forms/dialogs/select.js | removeSelectedOptions | function removeSelectedOptions( combo )
{
combo = getSelect( combo );
// Save the selected index
var iSelectedIndex = getSelectedIndex( combo );
// Remove all selected options.
for ( var i = combo.getChildren().count() - 1 ; i >= 0 ; i-- )
{
if ( combo.getChild( i ).$.selected )
combo.getChild( i ).remove();
}
// Reset the selection based on the original selected index.
setSelectedIndex( combo, iSelectedIndex );
} | javascript | function removeSelectedOptions( combo )
{
combo = getSelect( combo );
// Save the selected index
var iSelectedIndex = getSelectedIndex( combo );
// Remove all selected options.
for ( var i = combo.getChildren().count() - 1 ; i >= 0 ; i-- )
{
if ( combo.getChild( i ).$.selected )
combo.getChild( i ).remove();
}
// Reset the selection based on the original selected index.
setSelectedIndex( combo, iSelectedIndex );
} | [
"function",
"removeSelectedOptions",
"(",
"combo",
")",
"{",
"combo",
"=",
"getSelect",
"(",
"combo",
")",
";",
"// Save the selected index\r",
"var",
"iSelectedIndex",
"=",
"getSelectedIndex",
"(",
"combo",
")",
";",
"// Remove all selected options.\r",
"for",
"(",
"var",
"i",
"=",
"combo",
".",
"getChildren",
"(",
")",
".",
"count",
"(",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"combo",
".",
"getChild",
"(",
"i",
")",
".",
"$",
".",
"selected",
")",
"combo",
".",
"getChild",
"(",
"i",
")",
".",
"remove",
"(",
")",
";",
"}",
"// Reset the selection based on the original selected index.\r",
"setSelectedIndex",
"(",
"combo",
",",
"iSelectedIndex",
")",
";",
"}"
]
| Remove all selected options from a SELECT object. | [
"Remove",
"all",
"selected",
"options",
"from",
"a",
"SELECT",
"object",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/forms/dialogs/select.js#L45-L61 |
47,719 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/forms/dialogs/select.js | modifyOption | function modifyOption( combo, index, title, value )
{
combo = getSelect( combo );
if ( index < 0 )
return false;
var child = combo.getChild( index );
child.setText( title );
child.setValue( value );
return child;
} | javascript | function modifyOption( combo, index, title, value )
{
combo = getSelect( combo );
if ( index < 0 )
return false;
var child = combo.getChild( index );
child.setText( title );
child.setValue( value );
return child;
} | [
"function",
"modifyOption",
"(",
"combo",
",",
"index",
",",
"title",
",",
"value",
")",
"{",
"combo",
"=",
"getSelect",
"(",
"combo",
")",
";",
"if",
"(",
"index",
"<",
"0",
")",
"return",
"false",
";",
"var",
"child",
"=",
"combo",
".",
"getChild",
"(",
"index",
")",
";",
"child",
".",
"setText",
"(",
"title",
")",
";",
"child",
".",
"setValue",
"(",
"value",
")",
";",
"return",
"child",
";",
"}"
]
| Modify option from a SELECT object. | [
"Modify",
"option",
"from",
"a",
"SELECT",
"object",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/forms/dialogs/select.js#L63-L72 |
47,720 | Froguard/json-toy | bin/main.js | dir2TreeStr | function dir2TreeStr(){
argD = Type.isBoolean(argD) ? "./" : trimAndDelQuotes(argD);
let dirJson,djOpt;
try{
djOpt = {
// preChars:{
// directory: ":open_file_folder: ",
// file:":page_facing_up: "
// },
exclude:{
outExcludeDir: true //将过滤掉的文件夹输出
},
extChars:{
directory: " /"
},
maxDepth: argM
};
dirJson = dir2Json(argD, djOpt);
}catch(e3){
errorOut("Gen Json via dir failed: " + e3.toString());
dirJson = false;
}
if(!dirJson){
if(dirJson===null){
warningOut("The directory '" + argD + "' is empty! (exclude-filter: .git|.svn|.idea|node_modules|bower_components )");
}
}else if(Type.isString(dirJson)){
warningOut("The directory '" + argD + "' is '" + dirJson + "'");
}else{
// 间距配置和上面不一样
s = Type.isNaN(s) ? 2 : s;
v = Type.isNaN(v) ? 0 : v;
jsonName = (djOpt.preChars && djOpt.preChars.directory || "") + argD.replace(/\\/g,"/");
outputVal = false;
_doMain(dirJson,true);
}
} | javascript | function dir2TreeStr(){
argD = Type.isBoolean(argD) ? "./" : trimAndDelQuotes(argD);
let dirJson,djOpt;
try{
djOpt = {
// preChars:{
// directory: ":open_file_folder: ",
// file:":page_facing_up: "
// },
exclude:{
outExcludeDir: true //将过滤掉的文件夹输出
},
extChars:{
directory: " /"
},
maxDepth: argM
};
dirJson = dir2Json(argD, djOpt);
}catch(e3){
errorOut("Gen Json via dir failed: " + e3.toString());
dirJson = false;
}
if(!dirJson){
if(dirJson===null){
warningOut("The directory '" + argD + "' is empty! (exclude-filter: .git|.svn|.idea|node_modules|bower_components )");
}
}else if(Type.isString(dirJson)){
warningOut("The directory '" + argD + "' is '" + dirJson + "'");
}else{
// 间距配置和上面不一样
s = Type.isNaN(s) ? 2 : s;
v = Type.isNaN(v) ? 0 : v;
jsonName = (djOpt.preChars && djOpt.preChars.directory || "") + argD.replace(/\\/g,"/");
outputVal = false;
_doMain(dirJson,true);
}
} | [
"function",
"dir2TreeStr",
"(",
")",
"{",
"argD",
"=",
"Type",
".",
"isBoolean",
"(",
"argD",
")",
"?",
"\"./\"",
":",
"trimAndDelQuotes",
"(",
"argD",
")",
";",
"let",
"dirJson",
",",
"djOpt",
";",
"try",
"{",
"djOpt",
"=",
"{",
"// preChars:{",
"// directory: \":open_file_folder: \",",
"// file:\":page_facing_up: \"",
"// },",
"exclude",
":",
"{",
"outExcludeDir",
":",
"true",
"//将过滤掉的文件夹输出",
"}",
",",
"extChars",
":",
"{",
"directory",
":",
"\" /\"",
"}",
",",
"maxDepth",
":",
"argM",
"}",
";",
"dirJson",
"=",
"dir2Json",
"(",
"argD",
",",
"djOpt",
")",
";",
"}",
"catch",
"(",
"e3",
")",
"{",
"errorOut",
"(",
"\"Gen Json via dir failed: \"",
"+",
"e3",
".",
"toString",
"(",
")",
")",
";",
"dirJson",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"dirJson",
")",
"{",
"if",
"(",
"dirJson",
"===",
"null",
")",
"{",
"warningOut",
"(",
"\"The directory '\"",
"+",
"argD",
"+",
"\"' is empty! (exclude-filter: .git|.svn|.idea|node_modules|bower_components )\"",
")",
";",
"}",
"}",
"else",
"if",
"(",
"Type",
".",
"isString",
"(",
"dirJson",
")",
")",
"{",
"warningOut",
"(",
"\"The directory '\"",
"+",
"argD",
"+",
"\"' is '\"",
"+",
"dirJson",
"+",
"\"'\"",
")",
";",
"}",
"else",
"{",
"// 间距配置和上面不一样",
"s",
"=",
"Type",
".",
"isNaN",
"(",
"s",
")",
"?",
"2",
":",
"s",
";",
"v",
"=",
"Type",
".",
"isNaN",
"(",
"v",
")",
"?",
"0",
":",
"v",
";",
"jsonName",
"=",
"(",
"djOpt",
".",
"preChars",
"&&",
"djOpt",
".",
"preChars",
".",
"directory",
"||",
"\"\"",
")",
"+",
"argD",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"\"/\"",
")",
";",
"outputVal",
"=",
"false",
";",
"_doMain",
"(",
"dirJson",
",",
"true",
")",
";",
"}",
"}"
]
| convert directory to tree-string | [
"convert",
"directory",
"to",
"tree",
"-",
"string"
]
| cc0549794c2200adfa2c5adce4050b8ba2012000 | https://github.com/Froguard/json-toy/blob/cc0549794c2200adfa2c5adce4050b8ba2012000/bin/main.js#L120-L156 |
47,721 | anvaka/ngraph.shremlin | lib/iterators/vertexIterator.js | VertexIterator | function VertexIterator(graph, startFrom) {
if (graph === undefined) {
throw new Error('Graph is required by VertexIterator');
}
this._graph = graph;
this._startFrom = startFrom;
this._currentIndex = 0;
this._allNodes = [];
this._initialized = false;
this._current = undefined;
} | javascript | function VertexIterator(graph, startFrom) {
if (graph === undefined) {
throw new Error('Graph is required by VertexIterator');
}
this._graph = graph;
this._startFrom = startFrom;
this._currentIndex = 0;
this._allNodes = [];
this._initialized = false;
this._current = undefined;
} | [
"function",
"VertexIterator",
"(",
"graph",
",",
"startFrom",
")",
"{",
"if",
"(",
"graph",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Graph is required by VertexIterator'",
")",
";",
"}",
"this",
".",
"_graph",
"=",
"graph",
";",
"this",
".",
"_startFrom",
"=",
"startFrom",
";",
"this",
".",
"_currentIndex",
"=",
"0",
";",
"this",
".",
"_allNodes",
"=",
"[",
"]",
";",
"this",
".",
"_initialized",
"=",
"false",
";",
"this",
".",
"_current",
"=",
"undefined",
";",
"}"
]
| Vertex Iterator provides a simple wrapper over `graph.forEachNode`
to perform lazy iteration.
`startFrom` argument is optional and has the following meaning:
_Not passed_ - Iterate over all vertices of a `graph`:
```
var iterator = new VertexIterator(graph);
while (iterator.moveNext()) {
// prints all vertices:
console.log(iterator.current());
}
```
_Array_ - Iterate over all vertices with matching identifiers from array:
```
var iterator = new VertexIterator(graph, [0, 1]);
while (iterator.moveNext()) {
// prints two vertices with identifier 0 or 1:
console.log(iterator.current());
}
```
_Function_ - Iterate over all vertices which match function predicate:
```
var filter = function (vertex) { return false; },
iterator = new VertexIterator(graph, filter);
while (iterator.moveNext()) {
console.log('This will never be shown');
}
```
_Anything else_ - Consider it as starting vertex id:
```
var iterator = new VertexIterator(graph, 42);
while (iterator.moveNext()) {
// this will print single node with id == 42;
console.log(iterator.current());
}
``` | [
"Vertex",
"Iterator",
"provides",
"a",
"simple",
"wrapper",
"over",
"graph",
".",
"forEachNode",
"to",
"perform",
"lazy",
"iteration",
"."
]
| 98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7 | https://github.com/anvaka/ngraph.shremlin/blob/98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7/lib/iterators/vertexIterator.js#L58-L69 |
47,722 | saggiyogesh/nodeportal | lib/CacheStore/index.js | CacheStore | function CacheStore(options) {
if (!options.id) {
throw new IdNotDefinedError();
}
var storeType, _cache;
function parseKey(key) {
return key.replace(/[^a-z0-9]/gi, '_').replace(/^-+/, '').replace(/-+$/, '').toLowerCase();
}
/**
* Returns Cache Store object
* @returns {Object}
*/
this.getCacheStore = function () {
return _cache;
};
/**
* Method initiates cache store depends on type
* @param type {String} cache store type
* @returns {CacheStore}
*/
this._setStoreType = function (type) {
storeType = type;
var ttl = options.expires || DEFAULT_EXPIRATION_TIME;
options.max = options.max || 0; //makes lru cache to store infinite no of items
switch (type) {
case STORE_TYPE_MEMORY:
_cache = CacheManager.caching({store: STORE_TYPE_MEMORY, max: options.max, ttl: ttl});
break;
case STORE_TYPE_REDIS:
_cache = CacheManager.caching({store: RedisStore, db: options.db, ttl: ttl, host: options.host,
port: options.port, id: options.id
});
break;
default :
throw new InvalidCacheStoreTypeError(type);
}
//exposing delete method alias of _del
_cache.delete = _cache.del;
return this;
};
//setting public functions
/**
* Gets cache item
* @param key {String} Key to retrieve cache item
* @param next {Function} callback. parameters are err, value
*/
this.get = function (key, next) {
_cache.get(parseKey(key), next);
};
/**
* Sets cache item in cache.
* @param key {String} Key to retrieve cache item
* @param value {String} Value to save cache item
* @param next {Function} callback. parameters are err
*/
this.set = function (key, value, next) {
_cache.set(parseKey(key), value, next);
};
/**
* Delete from cache
* @param key {String} Key to retrieve cache item
* @param next {Function} callback. parameters are err
*/
this.delete = function (key, next) {
_cache.del(parseKey(key), next);
};
/**
* Wraps a function in cache, the first time the function is run,
* its results are stored in cache so subsequent calls retrieve from cache
* instead of calling the function.
*
* @example
*
* var key = 'user_' + user_id;
* cache.wrap(key, function(cb) {
* User.get(user_id, cb);
* }, function(err, user) {
* console.log(user);
* });
*
* @param key {String} Key to retrieve cache item
* @param wrapFn
* @param next {Function} callback. parameters are err, value
*/
this.wrap = function (key, wrapFn, next) {
_cache.wrap(parseKey(key), wrapFn, next);
};
/**
* Flushes the current cache store
* @param next {Function} callback. parameters are err, success
*/
this.reset = function (next) {
_cache.reset(next);
};
/**
* Gets all keys associated with this cache store
* @param next {Function} callback. parameters are err, keys
*/
this.keys = function (next) {
_cache.keys(next);
};
} | javascript | function CacheStore(options) {
if (!options.id) {
throw new IdNotDefinedError();
}
var storeType, _cache;
function parseKey(key) {
return key.replace(/[^a-z0-9]/gi, '_').replace(/^-+/, '').replace(/-+$/, '').toLowerCase();
}
/**
* Returns Cache Store object
* @returns {Object}
*/
this.getCacheStore = function () {
return _cache;
};
/**
* Method initiates cache store depends on type
* @param type {String} cache store type
* @returns {CacheStore}
*/
this._setStoreType = function (type) {
storeType = type;
var ttl = options.expires || DEFAULT_EXPIRATION_TIME;
options.max = options.max || 0; //makes lru cache to store infinite no of items
switch (type) {
case STORE_TYPE_MEMORY:
_cache = CacheManager.caching({store: STORE_TYPE_MEMORY, max: options.max, ttl: ttl});
break;
case STORE_TYPE_REDIS:
_cache = CacheManager.caching({store: RedisStore, db: options.db, ttl: ttl, host: options.host,
port: options.port, id: options.id
});
break;
default :
throw new InvalidCacheStoreTypeError(type);
}
//exposing delete method alias of _del
_cache.delete = _cache.del;
return this;
};
//setting public functions
/**
* Gets cache item
* @param key {String} Key to retrieve cache item
* @param next {Function} callback. parameters are err, value
*/
this.get = function (key, next) {
_cache.get(parseKey(key), next);
};
/**
* Sets cache item in cache.
* @param key {String} Key to retrieve cache item
* @param value {String} Value to save cache item
* @param next {Function} callback. parameters are err
*/
this.set = function (key, value, next) {
_cache.set(parseKey(key), value, next);
};
/**
* Delete from cache
* @param key {String} Key to retrieve cache item
* @param next {Function} callback. parameters are err
*/
this.delete = function (key, next) {
_cache.del(parseKey(key), next);
};
/**
* Wraps a function in cache, the first time the function is run,
* its results are stored in cache so subsequent calls retrieve from cache
* instead of calling the function.
*
* @example
*
* var key = 'user_' + user_id;
* cache.wrap(key, function(cb) {
* User.get(user_id, cb);
* }, function(err, user) {
* console.log(user);
* });
*
* @param key {String} Key to retrieve cache item
* @param wrapFn
* @param next {Function} callback. parameters are err, value
*/
this.wrap = function (key, wrapFn, next) {
_cache.wrap(parseKey(key), wrapFn, next);
};
/**
* Flushes the current cache store
* @param next {Function} callback. parameters are err, success
*/
this.reset = function (next) {
_cache.reset(next);
};
/**
* Gets all keys associated with this cache store
* @param next {Function} callback. parameters are err, keys
*/
this.keys = function (next) {
_cache.keys(next);
};
} | [
"function",
"CacheStore",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"options",
".",
"id",
")",
"{",
"throw",
"new",
"IdNotDefinedError",
"(",
")",
";",
"}",
"var",
"storeType",
",",
"_cache",
";",
"function",
"parseKey",
"(",
"key",
")",
"{",
"return",
"key",
".",
"replace",
"(",
"/",
"[^a-z0-9]",
"/",
"gi",
",",
"'_'",
")",
".",
"replace",
"(",
"/",
"^-+",
"/",
",",
"''",
")",
".",
"replace",
"(",
"/",
"-+$",
"/",
",",
"''",
")",
".",
"toLowerCase",
"(",
")",
";",
"}",
"/**\n * Returns Cache Store object\n * @returns {Object}\n */",
"this",
".",
"getCacheStore",
"=",
"function",
"(",
")",
"{",
"return",
"_cache",
";",
"}",
";",
"/**\n * Method initiates cache store depends on type\n * @param type {String} cache store type\n * @returns {CacheStore}\n */",
"this",
".",
"_setStoreType",
"=",
"function",
"(",
"type",
")",
"{",
"storeType",
"=",
"type",
";",
"var",
"ttl",
"=",
"options",
".",
"expires",
"||",
"DEFAULT_EXPIRATION_TIME",
";",
"options",
".",
"max",
"=",
"options",
".",
"max",
"||",
"0",
";",
"//makes lru cache to store infinite no of items",
"switch",
"(",
"type",
")",
"{",
"case",
"STORE_TYPE_MEMORY",
":",
"_cache",
"=",
"CacheManager",
".",
"caching",
"(",
"{",
"store",
":",
"STORE_TYPE_MEMORY",
",",
"max",
":",
"options",
".",
"max",
",",
"ttl",
":",
"ttl",
"}",
")",
";",
"break",
";",
"case",
"STORE_TYPE_REDIS",
":",
"_cache",
"=",
"CacheManager",
".",
"caching",
"(",
"{",
"store",
":",
"RedisStore",
",",
"db",
":",
"options",
".",
"db",
",",
"ttl",
":",
"ttl",
",",
"host",
":",
"options",
".",
"host",
",",
"port",
":",
"options",
".",
"port",
",",
"id",
":",
"options",
".",
"id",
"}",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"InvalidCacheStoreTypeError",
"(",
"type",
")",
";",
"}",
"//exposing delete method alias of _del",
"_cache",
".",
"delete",
"=",
"_cache",
".",
"del",
";",
"return",
"this",
";",
"}",
";",
"//setting public functions",
"/**\n * Gets cache item\n * @param key {String} Key to retrieve cache item\n * @param next {Function} callback. parameters are err, value\n */",
"this",
".",
"get",
"=",
"function",
"(",
"key",
",",
"next",
")",
"{",
"_cache",
".",
"get",
"(",
"parseKey",
"(",
"key",
")",
",",
"next",
")",
";",
"}",
";",
"/**\n * Sets cache item in cache.\n * @param key {String} Key to retrieve cache item\n * @param value {String} Value to save cache item\n * @param next {Function} callback. parameters are err\n */",
"this",
".",
"set",
"=",
"function",
"(",
"key",
",",
"value",
",",
"next",
")",
"{",
"_cache",
".",
"set",
"(",
"parseKey",
"(",
"key",
")",
",",
"value",
",",
"next",
")",
";",
"}",
";",
"/**\n * Delete from cache\n * @param key {String} Key to retrieve cache item\n * @param next {Function} callback. parameters are err\n */",
"this",
".",
"delete",
"=",
"function",
"(",
"key",
",",
"next",
")",
"{",
"_cache",
".",
"del",
"(",
"parseKey",
"(",
"key",
")",
",",
"next",
")",
";",
"}",
";",
"/**\n * Wraps a function in cache, the first time the function is run,\n * its results are stored in cache so subsequent calls retrieve from cache\n * instead of calling the function.\n *\n * @example\n *\n * var key = 'user_' + user_id;\n * cache.wrap(key, function(cb) {\n * User.get(user_id, cb);\n * }, function(err, user) {\n * console.log(user);\n * });\n *\n * @param key {String} Key to retrieve cache item\n * @param wrapFn\n * @param next {Function} callback. parameters are err, value\n */",
"this",
".",
"wrap",
"=",
"function",
"(",
"key",
",",
"wrapFn",
",",
"next",
")",
"{",
"_cache",
".",
"wrap",
"(",
"parseKey",
"(",
"key",
")",
",",
"wrapFn",
",",
"next",
")",
";",
"}",
";",
"/**\n * Flushes the current cache store\n * @param next {Function} callback. parameters are err, success\n */",
"this",
".",
"reset",
"=",
"function",
"(",
"next",
")",
"{",
"_cache",
".",
"reset",
"(",
"next",
")",
";",
"}",
";",
"/**\n * Gets all keys associated with this cache store\n * @param next {Function} callback. parameters are err, keys\n */",
"this",
".",
"keys",
"=",
"function",
"(",
"next",
")",
"{",
"_cache",
".",
"keys",
"(",
"next",
")",
";",
"}",
";",
"}"
]
| Abstract function to create cache store
@param [options]
@constructor | [
"Abstract",
"function",
"to",
"create",
"cache",
"store"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/CacheStore/index.js#L41-L154 |
47,723 | kchapelier/node-glitch | index.js | function(options) {
"use strict";
stream.Transform.call(this, options);
options = options || {};
this.probability = options.probability || 0;
this.deviation = Math.abs(options.deviation || 0);
this.whiteList = options.whiteList || [];
this.blackList = options.blackList || [];
this.func = options.func;
} | javascript | function(options) {
"use strict";
stream.Transform.call(this, options);
options = options || {};
this.probability = options.probability || 0;
this.deviation = Math.abs(options.deviation || 0);
this.whiteList = options.whiteList || [];
this.blackList = options.blackList || [];
this.func = options.func;
} | [
"function",
"(",
"options",
")",
"{",
"\"use strict\"",
";",
"stream",
".",
"Transform",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"probability",
"=",
"options",
".",
"probability",
"||",
"0",
";",
"this",
".",
"deviation",
"=",
"Math",
".",
"abs",
"(",
"options",
".",
"deviation",
"||",
"0",
")",
";",
"this",
".",
"whiteList",
"=",
"options",
".",
"whiteList",
"||",
"[",
"]",
";",
"this",
".",
"blackList",
"=",
"options",
".",
"blackList",
"||",
"[",
"]",
";",
"this",
".",
"func",
"=",
"options",
".",
"func",
";",
"}"
]
| GlitchedStream, a Transform stream to intentionally corrupt data
@param {Object} options
@constructor | [
"GlitchedStream",
"a",
"Transform",
"stream",
"to",
"intentionally",
"corrupt",
"data"
]
| 28681c573df3864d32177252523e7ca0d59c5992 | https://github.com/kchapelier/node-glitch/blob/28681c573df3864d32177252523e7ca0d59c5992/index.js#L11-L23 |
|
47,724 | kchapelier/node-glitch | index.js | function(fileSrc, fileDst, probability, deviation, mode) {
"use strict";
var rstream = fs.createReadStream(fileSrc);
var woptions = mode ? { 'mode' : mode } : {};
var wstream = fs.createWriteStream(fileDst, woptions);
var gstream = new GlitchedStream({
'probability' : probability,
'deviation' : deviation
});
rstream.pipe(gstream).pipe(wstream);
} | javascript | function(fileSrc, fileDst, probability, deviation, mode) {
"use strict";
var rstream = fs.createReadStream(fileSrc);
var woptions = mode ? { 'mode' : mode } : {};
var wstream = fs.createWriteStream(fileDst, woptions);
var gstream = new GlitchedStream({
'probability' : probability,
'deviation' : deviation
});
rstream.pipe(gstream).pipe(wstream);
} | [
"function",
"(",
"fileSrc",
",",
"fileDst",
",",
"probability",
",",
"deviation",
",",
"mode",
")",
"{",
"\"use strict\"",
";",
"var",
"rstream",
"=",
"fs",
".",
"createReadStream",
"(",
"fileSrc",
")",
";",
"var",
"woptions",
"=",
"mode",
"?",
"{",
"'mode'",
":",
"mode",
"}",
":",
"{",
"}",
";",
"var",
"wstream",
"=",
"fs",
".",
"createWriteStream",
"(",
"fileDst",
",",
"woptions",
")",
";",
"var",
"gstream",
"=",
"new",
"GlitchedStream",
"(",
"{",
"'probability'",
":",
"probability",
",",
"'deviation'",
":",
"deviation",
"}",
")",
";",
"rstream",
".",
"pipe",
"(",
"gstream",
")",
".",
"pipe",
"(",
"wstream",
")",
";",
"}"
]
| Read the content of a file, corrupt it and write it into another file
@param {String} fileSrc - Path of the source file
@param {String} fileDst - Path of the destination file
@param {Number} probability - Probability of deviation per byte (between 0 and 1)
@param {Number} deviation - Maximum value difference between each byte of the source and of the destination
@param {Number} mode | [
"Read",
"the",
"content",
"of",
"a",
"file",
"corrupt",
"it",
"and",
"write",
"it",
"into",
"another",
"file"
]
| 28681c573df3864d32177252523e7ca0d59c5992 | https://github.com/kchapelier/node-glitch/blob/28681c573df3864d32177252523e7ca0d59c5992/index.js#L87-L98 |
|
47,725 | ticup/CloudTypes-paper | shared/CInt.js | CInt | function CInt(base, offset, isSet) {
this.base = base || 0;
this.offset = offset || 0;
this.isSet = isSet || false;
} | javascript | function CInt(base, offset, isSet) {
this.base = base || 0;
this.offset = offset || 0;
this.isSet = isSet || false;
} | [
"function",
"CInt",
"(",
"base",
",",
"offset",
",",
"isSet",
")",
"{",
"this",
".",
"base",
"=",
"base",
"||",
"0",
";",
"this",
".",
"offset",
"=",
"offset",
"||",
"0",
";",
"this",
".",
"isSet",
"=",
"isSet",
"||",
"false",
";",
"}"
]
| Actual CInt object of which an instance represents a variable of which the property is defined with CIntDeclaration | [
"Actual",
"CInt",
"object",
"of",
"which",
"an",
"instance",
"represents",
"a",
"variable",
"of",
"which",
"the",
"property",
"is",
"defined",
"with",
"CIntDeclaration"
]
| f3b6adcd60bd66a28eb0e22edfcdcd9500ef7dda | https://github.com/ticup/CloudTypes-paper/blob/f3b6adcd60bd66a28eb0e22edfcdcd9500ef7dda/shared/CInt.js#L26-L30 |
47,726 | jchook/virtual-dom-handlebars | lib/VText.js | VText | function VText(text, config) {
this.virtual = true;
extend(this, config);
// Non-overridable
this.text = [].concat(text);
this.textOnly = true;
this.simple = true;
} | javascript | function VText(text, config) {
this.virtual = true;
extend(this, config);
// Non-overridable
this.text = [].concat(text);
this.textOnly = true;
this.simple = true;
} | [
"function",
"VText",
"(",
"text",
",",
"config",
")",
"{",
"this",
".",
"virtual",
"=",
"true",
";",
"extend",
"(",
"this",
",",
"config",
")",
";",
"// Non-overridable",
"this",
".",
"text",
"=",
"[",
"]",
".",
"concat",
"(",
"text",
")",
";",
"this",
".",
"textOnly",
"=",
"true",
";",
"this",
".",
"simple",
"=",
"true",
";",
"}"
]
| Simplest node, only text | [
"Simplest",
"node",
"only",
"text"
]
| d1c2015449bad8489572114fe3d8facef2cce367 | https://github.com/jchook/virtual-dom-handlebars/blob/d1c2015449bad8489572114fe3d8facef2cce367/lib/VText.js#L6-L14 |
47,727 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/colordialog/dialogs/colordialog.js | appendColorRow | function appendColorRow( rangeA, rangeB )
{
for ( var i = rangeA ; i < rangeA + 3 ; i++ )
{
var row = table.$.insertRow( -1 );
for ( var j = rangeB ; j < rangeB + 3 ; j++ )
{
for ( var n = 0 ; n < 6 ; n++ )
{
appendColorCell( row, '#' + aColors[j] + aColors[n] + aColors[i] );
}
}
}
} | javascript | function appendColorRow( rangeA, rangeB )
{
for ( var i = rangeA ; i < rangeA + 3 ; i++ )
{
var row = table.$.insertRow( -1 );
for ( var j = rangeB ; j < rangeB + 3 ; j++ )
{
for ( var n = 0 ; n < 6 ; n++ )
{
appendColorCell( row, '#' + aColors[j] + aColors[n] + aColors[i] );
}
}
}
} | [
"function",
"appendColorRow",
"(",
"rangeA",
",",
"rangeB",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"rangeA",
";",
"i",
"<",
"rangeA",
"+",
"3",
";",
"i",
"++",
")",
"{",
"var",
"row",
"=",
"table",
".",
"$",
".",
"insertRow",
"(",
"-",
"1",
")",
";",
"for",
"(",
"var",
"j",
"=",
"rangeB",
";",
"j",
"<",
"rangeB",
"+",
"3",
";",
"j",
"++",
")",
"{",
"for",
"(",
"var",
"n",
"=",
"0",
";",
"n",
"<",
"6",
";",
"n",
"++",
")",
"{",
"appendColorCell",
"(",
"row",
",",
"'#'",
"+",
"aColors",
"[",
"j",
"]",
"+",
"aColors",
"[",
"n",
"]",
"+",
"aColors",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"}"
]
| This function combines two ranges of three values from the color array into a row. | [
"This",
"function",
"combines",
"two",
"ranges",
"of",
"three",
"values",
"from",
"the",
"color",
"array",
"into",
"a",
"row",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/colordialog/dialogs/colordialog.js#L179-L193 |
47,728 | ticup/CloudTypes-paper | shared/CEntity.js | CEntity | function CEntity(indexes, properties, states) {
CArray.call(this, indexes, properties);
this.states = {} || states;
this.uid = 0;
} | javascript | function CEntity(indexes, properties, states) {
CArray.call(this, indexes, properties);
this.states = {} || states;
this.uid = 0;
} | [
"function",
"CEntity",
"(",
"indexes",
",",
"properties",
",",
"states",
")",
"{",
"CArray",
".",
"call",
"(",
"this",
",",
"indexes",
",",
"properties",
")",
";",
"this",
".",
"states",
"=",
"{",
"}",
"||",
"states",
";",
"this",
".",
"uid",
"=",
"0",
";",
"}"
]
| when declared in a State, the state will add itself and the declared name for this CArray as properties to the CEntity object. | [
"when",
"declared",
"in",
"a",
"State",
"the",
"state",
"will",
"add",
"itself",
"and",
"the",
"declared",
"name",
"for",
"this",
"CArray",
"as",
"properties",
"to",
"the",
"CEntity",
"object",
"."
]
| f3b6adcd60bd66a28eb0e22edfcdcd9500ef7dda | https://github.com/ticup/CloudTypes-paper/blob/f3b6adcd60bd66a28eb0e22edfcdcd9500ef7dda/shared/CEntity.js#L15-L19 |
47,729 | saggiyogesh/nodeportal | plugins/manageResource/client/manageResource.js | attachMenu | function attachMenu(item) {
var menuType = item.find('a').hasClass(FOLDER_TYPE) ? "folderMenu" : "itemMenu";
item.contextMenu({
menu:menuType
},
function (action, el, pos) {
switch (action) {
case ADD_SUBFOLDER_MENU_COMMAND:
var parentFolderId = el.find('a').attr('id');
addFolder(parentFolderId);
break;
case DOWNLOAD_MENU_COMMAND:
download(el.find('a').attr('id'));
break;
case RENAME_MENU_COMMAND:
rename(el.find('a').attr('id'), true);
break;
case DELETE_MENU_COMMAND:
var link = el.find('a');
remove(link.attr('id'), link.hasClass(FOLDER_TYPE) ? FOLDER_TYPE : "");
break;
default:
alert("Todo: apply action '" + action + "' to node " + el);
}
});
} | javascript | function attachMenu(item) {
var menuType = item.find('a').hasClass(FOLDER_TYPE) ? "folderMenu" : "itemMenu";
item.contextMenu({
menu:menuType
},
function (action, el, pos) {
switch (action) {
case ADD_SUBFOLDER_MENU_COMMAND:
var parentFolderId = el.find('a').attr('id');
addFolder(parentFolderId);
break;
case DOWNLOAD_MENU_COMMAND:
download(el.find('a').attr('id'));
break;
case RENAME_MENU_COMMAND:
rename(el.find('a').attr('id'), true);
break;
case DELETE_MENU_COMMAND:
var link = el.find('a');
remove(link.attr('id'), link.hasClass(FOLDER_TYPE) ? FOLDER_TYPE : "");
break;
default:
alert("Todo: apply action '" + action + "' to node " + el);
}
});
} | [
"function",
"attachMenu",
"(",
"item",
")",
"{",
"var",
"menuType",
"=",
"item",
".",
"find",
"(",
"'a'",
")",
".",
"hasClass",
"(",
"FOLDER_TYPE",
")",
"?",
"\"folderMenu\"",
":",
"\"itemMenu\"",
";",
"item",
".",
"contextMenu",
"(",
"{",
"menu",
":",
"menuType",
"}",
",",
"function",
"(",
"action",
",",
"el",
",",
"pos",
")",
"{",
"switch",
"(",
"action",
")",
"{",
"case",
"ADD_SUBFOLDER_MENU_COMMAND",
":",
"var",
"parentFolderId",
"=",
"el",
".",
"find",
"(",
"'a'",
")",
".",
"attr",
"(",
"'id'",
")",
";",
"addFolder",
"(",
"parentFolderId",
")",
";",
"break",
";",
"case",
"DOWNLOAD_MENU_COMMAND",
":",
"download",
"(",
"el",
".",
"find",
"(",
"'a'",
")",
".",
"attr",
"(",
"'id'",
")",
")",
";",
"break",
";",
"case",
"RENAME_MENU_COMMAND",
":",
"rename",
"(",
"el",
".",
"find",
"(",
"'a'",
")",
".",
"attr",
"(",
"'id'",
")",
",",
"true",
")",
";",
"break",
";",
"case",
"DELETE_MENU_COMMAND",
":",
"var",
"link",
"=",
"el",
".",
"find",
"(",
"'a'",
")",
";",
"remove",
"(",
"link",
".",
"attr",
"(",
"'id'",
")",
",",
"link",
".",
"hasClass",
"(",
"FOLDER_TYPE",
")",
"?",
"FOLDER_TYPE",
":",
"\"\"",
")",
";",
"break",
";",
"default",
":",
"alert",
"(",
"\"Todo: apply action '\"",
"+",
"action",
"+",
"\"' to node \"",
"+",
"el",
")",
";",
"}",
"}",
")",
";",
"}"
]
| attach menu as per type | [
"attach",
"menu",
"as",
"per",
"type"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/manageResource/client/manageResource.js#L272-L298 |
47,730 | gummesson/inject-inline-style | index.js | injectStyle | function injectStyle(obj) {
if (!obj) return ''
var selectors = Object.keys(obj)
var styles = selectors.map(function(key) {
var selector = obj[key]
var style = inlineStyle(selector)
var inline = key.concat('{').concat(style).concat('}')
return inline
})
var results = styles.join('')
insertCss(results)
return results
} | javascript | function injectStyle(obj) {
if (!obj) return ''
var selectors = Object.keys(obj)
var styles = selectors.map(function(key) {
var selector = obj[key]
var style = inlineStyle(selector)
var inline = key.concat('{').concat(style).concat('}')
return inline
})
var results = styles.join('')
insertCss(results)
return results
} | [
"function",
"injectStyle",
"(",
"obj",
")",
"{",
"if",
"(",
"!",
"obj",
")",
"return",
"''",
"var",
"selectors",
"=",
"Object",
".",
"keys",
"(",
"obj",
")",
"var",
"styles",
"=",
"selectors",
".",
"map",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"selector",
"=",
"obj",
"[",
"key",
"]",
"var",
"style",
"=",
"inlineStyle",
"(",
"selector",
")",
"var",
"inline",
"=",
"key",
".",
"concat",
"(",
"'{'",
")",
".",
"concat",
"(",
"style",
")",
".",
"concat",
"(",
"'}'",
")",
"return",
"inline",
"}",
")",
"var",
"results",
"=",
"styles",
".",
"join",
"(",
"''",
")",
"insertCss",
"(",
"results",
")",
"return",
"results",
"}"
]
| Inject `obj` as an inline CSS string.
@param {Object} obj
@return {String} | [
"Inject",
"obj",
"as",
"an",
"inline",
"CSS",
"string",
"."
]
| 9e8aa759ac240390b3404c0b508d02d52e699e6b | https://github.com/gummesson/inject-inline-style/blob/9e8aa759ac240390b3404c0b508d02d52e699e6b/index.js#L21-L37 |
47,731 | BadgeUp/badgeup-browser-client | dist/src/http.js | fetchWithRetry | function fetchWithRetry(url, options) {
async function fetchWrapper() {
const response = await fetch(url, options);
// don't retry if status is 4xx
if (response.status >= 400 && response.status < 500) {
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
const body = await response.json();
throw new p_retry_1.default.AbortError(body.message);
}
else {
throw new p_retry_1.default.AbortError(response.statusText);
}
}
return response;
}
return p_retry_1.default(fetchWrapper, { retries: RETRY_COUNT });
} | javascript | function fetchWithRetry(url, options) {
async function fetchWrapper() {
const response = await fetch(url, options);
// don't retry if status is 4xx
if (response.status >= 400 && response.status < 500) {
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
const body = await response.json();
throw new p_retry_1.default.AbortError(body.message);
}
else {
throw new p_retry_1.default.AbortError(response.statusText);
}
}
return response;
}
return p_retry_1.default(fetchWrapper, { retries: RETRY_COUNT });
} | [
"function",
"fetchWithRetry",
"(",
"url",
",",
"options",
")",
"{",
"async",
"function",
"fetchWrapper",
"(",
")",
"{",
"const",
"response",
"=",
"await",
"fetch",
"(",
"url",
",",
"options",
")",
";",
"// don't retry if status is 4xx",
"if",
"(",
"response",
".",
"status",
">=",
"400",
"&&",
"response",
".",
"status",
"<",
"500",
")",
"{",
"const",
"contentType",
"=",
"response",
".",
"headers",
".",
"get",
"(",
"'content-type'",
")",
";",
"if",
"(",
"contentType",
"&&",
"contentType",
".",
"includes",
"(",
"'application/json'",
")",
")",
"{",
"const",
"body",
"=",
"await",
"response",
".",
"json",
"(",
")",
";",
"throw",
"new",
"p_retry_1",
".",
"default",
".",
"AbortError",
"(",
"body",
".",
"message",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"p_retry_1",
".",
"default",
".",
"AbortError",
"(",
"response",
".",
"statusText",
")",
";",
"}",
"}",
"return",
"response",
";",
"}",
"return",
"p_retry_1",
".",
"default",
"(",
"fetchWrapper",
",",
"{",
"retries",
":",
"RETRY_COUNT",
"}",
")",
";",
"}"
]
| Performs fetch with retries in case of HTTP errors
@param url request url
@param options request options
@returns Returns a Promise that resolves with the response object | [
"Performs",
"fetch",
"with",
"retries",
"in",
"case",
"of",
"HTTP",
"errors"
]
| a9ab5051b445f139a83c6ac1499e7a31c85a79f4 | https://github.com/BadgeUp/badgeup-browser-client/blob/a9ab5051b445f139a83c6ac1499e7a31c85a79f4/dist/src/http.js#L78-L95 |
47,732 | BadgeUp/badgeup-browser-client | dist/src/http.js | hydrateDates | function hydrateDates(body) {
/**
* Hydrates a string date to a Date object. Mutates input.
* @param item object potentially containing a meta object
*/
function hydrateMeta(item) {
const meta = item.meta;
if (meta && meta.created) {
// parse ISO-8601 string to Date
meta.created = new Date(meta.created);
}
}
if (Array.isArray(body.data)) {
// paginated response
for (const item of body.data) {
hydrateMeta(item);
}
}
else {
// object response
hydrateMeta(body);
}
return body;
} | javascript | function hydrateDates(body) {
/**
* Hydrates a string date to a Date object. Mutates input.
* @param item object potentially containing a meta object
*/
function hydrateMeta(item) {
const meta = item.meta;
if (meta && meta.created) {
// parse ISO-8601 string to Date
meta.created = new Date(meta.created);
}
}
if (Array.isArray(body.data)) {
// paginated response
for (const item of body.data) {
hydrateMeta(item);
}
}
else {
// object response
hydrateMeta(body);
}
return body;
} | [
"function",
"hydrateDates",
"(",
"body",
")",
"{",
"/**\n * Hydrates a string date to a Date object. Mutates input.\n * @param item object potentially containing a meta object\n */",
"function",
"hydrateMeta",
"(",
"item",
")",
"{",
"const",
"meta",
"=",
"item",
".",
"meta",
";",
"if",
"(",
"meta",
"&&",
"meta",
".",
"created",
")",
"{",
"// parse ISO-8601 string to Date",
"meta",
".",
"created",
"=",
"new",
"Date",
"(",
"meta",
".",
"created",
")",
";",
"}",
"}",
"if",
"(",
"Array",
".",
"isArray",
"(",
"body",
".",
"data",
")",
")",
"{",
"// paginated response",
"for",
"(",
"const",
"item",
"of",
"body",
".",
"data",
")",
"{",
"hydrateMeta",
"(",
"item",
")",
";",
"}",
"}",
"else",
"{",
"// object response",
"hydrateMeta",
"(",
"body",
")",
";",
"}",
"return",
"body",
";",
"}"
]
| Hydrates dates in response bodies. Handles paginated responses and object responses.
Mutates input.
@param body HTTP response body | [
"Hydrates",
"dates",
"in",
"response",
"bodies",
".",
"Handles",
"paginated",
"responses",
"and",
"object",
"responses",
".",
"Mutates",
"input",
"."
]
| a9ab5051b445f139a83c6ac1499e7a31c85a79f4 | https://github.com/BadgeUp/badgeup-browser-client/blob/a9ab5051b445f139a83c6ac1499e7a31c85a79f4/dist/src/http.js#L101-L124 |
47,733 | BadgeUp/badgeup-browser-client | dist/src/http.js | hydrateMeta | function hydrateMeta(item) {
const meta = item.meta;
if (meta && meta.created) {
// parse ISO-8601 string to Date
meta.created = new Date(meta.created);
}
} | javascript | function hydrateMeta(item) {
const meta = item.meta;
if (meta && meta.created) {
// parse ISO-8601 string to Date
meta.created = new Date(meta.created);
}
} | [
"function",
"hydrateMeta",
"(",
"item",
")",
"{",
"const",
"meta",
"=",
"item",
".",
"meta",
";",
"if",
"(",
"meta",
"&&",
"meta",
".",
"created",
")",
"{",
"// parse ISO-8601 string to Date",
"meta",
".",
"created",
"=",
"new",
"Date",
"(",
"meta",
".",
"created",
")",
";",
"}",
"}"
]
| Hydrates a string date to a Date object. Mutates input.
@param item object potentially containing a meta object | [
"Hydrates",
"a",
"string",
"date",
"to",
"a",
"Date",
"object",
".",
"Mutates",
"input",
"."
]
| a9ab5051b445f139a83c6ac1499e7a31c85a79f4 | https://github.com/BadgeUp/badgeup-browser-client/blob/a9ab5051b445f139a83c6ac1499e7a31c85a79f4/dist/src/http.js#L106-L112 |
47,734 | slideme/rorschach | lib/LeaderElection.js | LeaderElection | function LeaderElection(client, path, id) {
EventEmitter.call(this);
/**
* Ref. to client.
*
* @type {Rorschach}
*/
this.client = client;
/**
* ZooKeeper path where participants' nodes exist.
*
* @type {String}
*/
this.path = path;
/**
* Id of participant. It's kept in node.
*
* @type {String}
*/
this.id = id;
/**
* Leadership state
*
* @type {Boolean}
*/
this.isLeader = false;
/**
* Initial state.
*
* @type {State}
*/
this.state = State.LATENT;
} | javascript | function LeaderElection(client, path, id) {
EventEmitter.call(this);
/**
* Ref. to client.
*
* @type {Rorschach}
*/
this.client = client;
/**
* ZooKeeper path where participants' nodes exist.
*
* @type {String}
*/
this.path = path;
/**
* Id of participant. It's kept in node.
*
* @type {String}
*/
this.id = id;
/**
* Leadership state
*
* @type {Boolean}
*/
this.isLeader = false;
/**
* Initial state.
*
* @type {State}
*/
this.state = State.LATENT;
} | [
"function",
"LeaderElection",
"(",
"client",
",",
"path",
",",
"id",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"/**\n * Ref. to client.\n *\n * @type {Rorschach}\n */",
"this",
".",
"client",
"=",
"client",
";",
"/**\n * ZooKeeper path where participants' nodes exist.\n *\n * @type {String}\n */",
"this",
".",
"path",
"=",
"path",
";",
"/**\n * Id of participant. It's kept in node.\n *\n * @type {String}\n */",
"this",
".",
"id",
"=",
"id",
";",
"/**\n * Leadership state\n *\n * @type {Boolean}\n */",
"this",
".",
"isLeader",
"=",
"false",
";",
"/**\n * Initial state.\n *\n * @type {State}\n */",
"this",
".",
"state",
"=",
"State",
".",
"LATENT",
";",
"}"
]
| Leader election participant.
@constructor
@extends {EventEmitter}
@param {Rorschach} client Rorschach instance
@param {String} path Election path
@param {String} id Participant id | [
"Leader",
"election",
"participant",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/LeaderElection.js#L44-L85 |
47,735 | slideme/rorschach | lib/LeaderElection.js | handleStateChange | function handleStateChange(election, state) {
if (state === ConnectionState.RECONNECTED) {
reset(election, afterReset);
}
else if (state === ConnectionState.SUSPENDED ||
state === ConnectionState.LOST) {
setLeadership(election, false);
}
function afterReset(err) {
if (err) {
election.emit('error', err);
setLeadership(election, false);
}
}
} | javascript | function handleStateChange(election, state) {
if (state === ConnectionState.RECONNECTED) {
reset(election, afterReset);
}
else if (state === ConnectionState.SUSPENDED ||
state === ConnectionState.LOST) {
setLeadership(election, false);
}
function afterReset(err) {
if (err) {
election.emit('error', err);
setLeadership(election, false);
}
}
} | [
"function",
"handleStateChange",
"(",
"election",
",",
"state",
")",
"{",
"if",
"(",
"state",
"===",
"ConnectionState",
".",
"RECONNECTED",
")",
"{",
"reset",
"(",
"election",
",",
"afterReset",
")",
";",
"}",
"else",
"if",
"(",
"state",
"===",
"ConnectionState",
".",
"SUSPENDED",
"||",
"state",
"===",
"ConnectionState",
".",
"LOST",
")",
"{",
"setLeadership",
"(",
"election",
",",
"false",
")",
";",
"}",
"function",
"afterReset",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"{",
"election",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
";",
"setLeadership",
"(",
"election",
",",
"false",
")",
";",
"}",
"}",
"}"
]
| Handle connection state change.
@param {LeaderElection} election
@param {ConnectionState} state | [
"Handle",
"connection",
"state",
"change",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/LeaderElection.js#L154-L169 |
47,736 | UsabilityDynamics/node-wordpress-client | examples/upload.js | fileUploaded | function fileUploaded( error, response ) {
this.debug( 'File Uploaded' );
console.log( require( 'util' ).inspect( error || response, { showHidden: false, colors: true, depth: 4 } ) );
} | javascript | function fileUploaded( error, response ) {
this.debug( 'File Uploaded' );
console.log( require( 'util' ).inspect( error || response, { showHidden: false, colors: true, depth: 4 } ) );
} | [
"function",
"fileUploaded",
"(",
"error",
",",
"response",
")",
"{",
"this",
".",
"debug",
"(",
"'File Uploaded'",
")",
";",
"console",
".",
"log",
"(",
"require",
"(",
"'util'",
")",
".",
"inspect",
"(",
"error",
"||",
"response",
",",
"{",
"showHidden",
":",
"false",
",",
"colors",
":",
"true",
",",
"depth",
":",
"4",
"}",
")",
")",
";",
"}"
]
| File Uploaded Callback
@param error
@param response | [
"File",
"Uploaded",
"Callback"
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/examples/upload.js#L22-L25 |
47,737 | saggiyogesh/nodeportal | public/ckeditor/_source/core/htmlparser/text.js | function( writer, filter )
{
var text = this.value;
if ( filter && !( text = filter.onText( text, this ) ) )
return;
writer.text( text );
} | javascript | function( writer, filter )
{
var text = this.value;
if ( filter && !( text = filter.onText( text, this ) ) )
return;
writer.text( text );
} | [
"function",
"(",
"writer",
",",
"filter",
")",
"{",
"var",
"text",
"=",
"this",
".",
"value",
";",
"if",
"(",
"filter",
"&&",
"!",
"(",
"text",
"=",
"filter",
".",
"onText",
"(",
"text",
",",
"this",
")",
")",
")",
"return",
";",
"writer",
".",
"text",
"(",
"text",
")",
";",
"}"
]
| Writes the HTML representation of this text to a CKEDITOR.htmlWriter.
@param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
@example | [
"Writes",
"the",
"HTML",
"representation",
"of",
"this",
"text",
"to",
"a",
"CKEDITOR",
".",
"htmlWriter",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/htmlparser/text.js#L43-L51 |
|
47,738 | Froguard/json-toy | lib/json-check-circular.js | checkCircular | function checkCircular(obj){
let isCcl = false;
let cclKeysArr = [];
travelJson(obj,function(k,v,kp,ts,cpl,cd,isCircular){
if(isCircular){
isCcl = true;
cclKeysArr.push({
keyPath: kp,
circularTo: v.slice(11,-1),
key: k,
value: v
});
}
},"ROOT",true);
return {
isCircular: isCcl,
circularProps: cclKeysArr
};
} | javascript | function checkCircular(obj){
let isCcl = false;
let cclKeysArr = [];
travelJson(obj,function(k,v,kp,ts,cpl,cd,isCircular){
if(isCircular){
isCcl = true;
cclKeysArr.push({
keyPath: kp,
circularTo: v.slice(11,-1),
key: k,
value: v
});
}
},"ROOT",true);
return {
isCircular: isCcl,
circularProps: cclKeysArr
};
} | [
"function",
"checkCircular",
"(",
"obj",
")",
"{",
"let",
"isCcl",
"=",
"false",
";",
"let",
"cclKeysArr",
"=",
"[",
"]",
";",
"travelJson",
"(",
"obj",
",",
"function",
"(",
"k",
",",
"v",
",",
"kp",
",",
"ts",
",",
"cpl",
",",
"cd",
",",
"isCircular",
")",
"{",
"if",
"(",
"isCircular",
")",
"{",
"isCcl",
"=",
"true",
";",
"cclKeysArr",
".",
"push",
"(",
"{",
"keyPath",
":",
"kp",
",",
"circularTo",
":",
"v",
".",
"slice",
"(",
"11",
",",
"-",
"1",
")",
",",
"key",
":",
"k",
",",
"value",
":",
"v",
"}",
")",
";",
"}",
"}",
",",
"\"ROOT\"",
",",
"true",
")",
";",
"return",
"{",
"isCircular",
":",
"isCcl",
",",
"circularProps",
":",
"cclKeysArr",
"}",
";",
"}"
]
| check circular obj
@param obj
@returns {{isCircular: boolean, circularProps: Array}} | [
"check",
"circular",
"obj"
]
| cc0549794c2200adfa2c5adce4050b8ba2012000 | https://github.com/Froguard/json-toy/blob/cc0549794c2200adfa2c5adce4050b8ba2012000/lib/json-check-circular.js#L7-L25 |
47,739 | dcodeIO/node-BufferView | index.js | BufferView | function BufferView(buffer, byteOffset, byteLength) {
if (typeof byteOffset === "undefined") byteOffset = 0;
if (typeof byteLength === "undefined") byteLength = buffer.length;
this._buffer = byteOffset === 0 && byteLength === buffer.length
? buffer
: buffer.slice(byteOffset, byteLength);
} | javascript | function BufferView(buffer, byteOffset, byteLength) {
if (typeof byteOffset === "undefined") byteOffset = 0;
if (typeof byteLength === "undefined") byteLength = buffer.length;
this._buffer = byteOffset === 0 && byteLength === buffer.length
? buffer
: buffer.slice(byteOffset, byteLength);
} | [
"function",
"BufferView",
"(",
"buffer",
",",
"byteOffset",
",",
"byteLength",
")",
"{",
"if",
"(",
"typeof",
"byteOffset",
"===",
"\"undefined\"",
")",
"byteOffset",
"=",
"0",
";",
"if",
"(",
"typeof",
"byteLength",
"===",
"\"undefined\"",
")",
"byteLength",
"=",
"buffer",
".",
"length",
";",
"this",
".",
"_buffer",
"=",
"byteOffset",
"===",
"0",
"&&",
"byteLength",
"===",
"buffer",
".",
"length",
"?",
"buffer",
":",
"buffer",
".",
"slice",
"(",
"byteOffset",
",",
"byteLength",
")",
";",
"}"
]
| Constructs a new BufferView.
@exports BufferView
@class An optimized DataView-compatible BufferView for node Buffers.
@param {!Buffer} buffer An existing Buffer to use as the storage for the new BufferView object.
@param {number=} byteOffset The offset, in bytes, to the first byte in the specified buffer for the new view to
reference. If not specified, the view of the buffer will start with the first byte.
@param {number=} byteLength The number of elements in the byte array. If unspecified, length of the view will match
the buffer's length.
@constructor
@extends DataView | [
"Constructs",
"a",
"new",
"BufferView",
"."
]
| 4e025d6f0ebd089f0408d3c1d3f47684aac8c965 | https://github.com/dcodeIO/node-BufferView/blob/4e025d6f0ebd089f0408d3c1d3f47684aac8c965/index.js#L16-L22 |
47,740 | Havvy/mock-net-socket | socket.js | function (message, data) {
var datastr = data === undefined ? "no-data" : inspect(data);
logfn(format(" [EMIT] %s %s", pad(message), datastr));
EEProto.emit.apply(this, arguments);
} | javascript | function (message, data) {
var datastr = data === undefined ? "no-data" : inspect(data);
logfn(format(" [EMIT] %s %s", pad(message), datastr));
EEProto.emit.apply(this, arguments);
} | [
"function",
"(",
"message",
",",
"data",
")",
"{",
"var",
"datastr",
"=",
"data",
"===",
"undefined",
"?",
"\"no-data\"",
":",
"inspect",
"(",
"data",
")",
";",
"logfn",
"(",
"format",
"(",
"\" [EMIT] %s %s\"",
",",
"pad",
"(",
"message",
")",
",",
"datastr",
")",
")",
";",
"EEProto",
".",
"emit",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
]
| Spying on Event Emitter methods. | [
"Spying",
"on",
"Event",
"Emitter",
"methods",
"."
]
| b27404b2be835536829f1391fcd6cba4f0de3d9e | https://github.com/Havvy/mock-net-socket/blob/b27404b2be835536829f1391fcd6cba4f0de3d9e/socket.js#L86-L90 |
|
47,741 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/node.js | function( evaluator )
{
var next = this.$, retval;
do
{
next = next.nextSibling;
retval = next && new CKEDITOR.dom.node( next );
}
while ( retval && evaluator && !evaluator( retval ) )
return retval;
} | javascript | function( evaluator )
{
var next = this.$, retval;
do
{
next = next.nextSibling;
retval = next && new CKEDITOR.dom.node( next );
}
while ( retval && evaluator && !evaluator( retval ) )
return retval;
} | [
"function",
"(",
"evaluator",
")",
"{",
"var",
"next",
"=",
"this",
".",
"$",
",",
"retval",
";",
"do",
"{",
"next",
"=",
"next",
".",
"nextSibling",
";",
"retval",
"=",
"next",
"&&",
"new",
"CKEDITOR",
".",
"dom",
".",
"node",
"(",
"next",
")",
";",
"}",
"while",
"(",
"retval",
"&&",
"evaluator",
"&&",
"!",
"evaluator",
"(",
"retval",
")",
")",
"return",
"retval",
";",
"}"
]
| Gets the node that follows this element in its parent's child list.
@param {Function} evaluator Filtering the result node.
@returns {CKEDITOR.dom.node} The next node or null if not available.
@example
var element = CKEDITOR.dom.element.createFromHtml( '<div><b>Example</b> <i>next</i></div>' );
var first = <strong>element.getFirst().getNext()</strong>;
alert( first.getName() ); // "i" | [
"Gets",
"the",
"node",
"that",
"follows",
"this",
"element",
"in",
"its",
"parent",
"s",
"child",
"list",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/node.js#L370-L380 |
|
47,742 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/node.js | function( reference, includeSelf )
{
var $ = this.$,
name;
if ( !includeSelf )
$ = $.parentNode;
while ( $ )
{
if ( $.nodeName && ( name = $.nodeName.toLowerCase(), ( typeof reference == 'string' ? name == reference : name in reference ) ) )
return new CKEDITOR.dom.node( $ );
$ = $.parentNode;
}
return null;
} | javascript | function( reference, includeSelf )
{
var $ = this.$,
name;
if ( !includeSelf )
$ = $.parentNode;
while ( $ )
{
if ( $.nodeName && ( name = $.nodeName.toLowerCase(), ( typeof reference == 'string' ? name == reference : name in reference ) ) )
return new CKEDITOR.dom.node( $ );
$ = $.parentNode;
}
return null;
} | [
"function",
"(",
"reference",
",",
"includeSelf",
")",
"{",
"var",
"$",
"=",
"this",
".",
"$",
",",
"name",
";",
"if",
"(",
"!",
"includeSelf",
")",
"$",
"=",
"$",
".",
"parentNode",
";",
"while",
"(",
"$",
")",
"{",
"if",
"(",
"$",
".",
"nodeName",
"&&",
"(",
"name",
"=",
"$",
".",
"nodeName",
".",
"toLowerCase",
"(",
")",
",",
"(",
"typeof",
"reference",
"==",
"'string'",
"?",
"name",
"==",
"reference",
":",
"name",
"in",
"reference",
")",
")",
")",
"return",
"new",
"CKEDITOR",
".",
"dom",
".",
"node",
"(",
"$",
")",
";",
"$",
"=",
"$",
".",
"parentNode",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets the closest ancestor node of this node, specified by its name.
@param {String} reference The name of the ancestor node to search or
an object with the node names to search for.
@param {Boolean} [includeSelf] Whether to include the current
node in the search.
@returns {CKEDITOR.dom.node} The located ancestor node or null if not found.
@since 3.6.1
@example
// Suppose we have the following HTML structure:
// <div id="outer"><div id="inner"><p><b>Some text</b></p></div></div>
// If node == <b>
ascendant = node.getAscendant( 'div' ); // ascendant == <div id="inner">
ascendant = node.getAscendant( 'b' ); // ascendant == null
ascendant = node.getAscendant( 'b', true ); // ascendant == <b>
ascendant = node.getAscendant( { div: 1, p: 1} ); // Searches for the first 'div' or 'p': ascendant == <div id="inner"> | [
"Gets",
"the",
"closest",
"ancestor",
"node",
"of",
"this",
"node",
"specified",
"by",
"its",
"name",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/node.js#L507-L523 |
|
47,743 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/node.js | function( preserveChildren )
{
var $ = this.$;
var parent = $.parentNode;
if ( parent )
{
if ( preserveChildren )
{
// Move all children before the node.
for ( var child ; ( child = $.firstChild ) ; )
{
parent.insertBefore( $.removeChild( child ), $ );
}
}
parent.removeChild( $ );
}
return this;
} | javascript | function( preserveChildren )
{
var $ = this.$;
var parent = $.parentNode;
if ( parent )
{
if ( preserveChildren )
{
// Move all children before the node.
for ( var child ; ( child = $.firstChild ) ; )
{
parent.insertBefore( $.removeChild( child ), $ );
}
}
parent.removeChild( $ );
}
return this;
} | [
"function",
"(",
"preserveChildren",
")",
"{",
"var",
"$",
"=",
"this",
".",
"$",
";",
"var",
"parent",
"=",
"$",
".",
"parentNode",
";",
"if",
"(",
"parent",
")",
"{",
"if",
"(",
"preserveChildren",
")",
"{",
"// Move all children before the node.\r",
"for",
"(",
"var",
"child",
";",
"(",
"child",
"=",
"$",
".",
"firstChild",
")",
";",
")",
"{",
"parent",
".",
"insertBefore",
"(",
"$",
".",
"removeChild",
"(",
"child",
")",
",",
"$",
")",
";",
"}",
"}",
"parent",
".",
"removeChild",
"(",
"$",
")",
";",
"}",
"return",
"this",
";",
"}"
]
| Removes this node from the document DOM.
@param {Boolean} [preserveChildren] Indicates that the children
elements must remain in the document, removing only the outer
tags.
@example
var element = CKEDITOR.dom.element.getById( 'MyElement' );
<strong>element.remove()</strong>; | [
"Removes",
"this",
"node",
"from",
"the",
"document",
"DOM",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/node.js#L556-L576 |
|
47,744 | saggiyogesh/nodeportal | public/ckeditor/_source/core/skins.js | function()
{
if ( cssIsLoaded && jsIsLoaded )
{
// Mark the part as loaded.
part._isLoaded = 1;
// Call all pending callbacks.
for ( var i = 0 ; i < pending.length ; i++ )
{
if ( pending[ i ] )
pending[ i ]();
}
}
} | javascript | function()
{
if ( cssIsLoaded && jsIsLoaded )
{
// Mark the part as loaded.
part._isLoaded = 1;
// Call all pending callbacks.
for ( var i = 0 ; i < pending.length ; i++ )
{
if ( pending[ i ] )
pending[ i ]();
}
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"cssIsLoaded",
"&&",
"jsIsLoaded",
")",
"{",
"// Mark the part as loaded.\r",
"part",
".",
"_isLoaded",
"=",
"1",
";",
"// Call all pending callbacks.\r",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"pending",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"pending",
"[",
"i",
"]",
")",
"pending",
"[",
"i",
"]",
"(",
")",
";",
"}",
"}",
"}"
]
| This is the function that will trigger the callback calls on load. | [
"This",
"is",
"the",
"function",
"that",
"will",
"trigger",
"the",
"callback",
"calls",
"on",
"load",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/skins.js#L81-L95 |
|
47,745 | saggiyogesh/nodeportal | public/ckeditor/_source/core/skins.js | function( skinName, skinDefinition )
{
loaded[ skinName ] = skinDefinition;
skinDefinition.skinPath = paths[ skinName ]
|| ( paths[ skinName ] =
CKEDITOR.getUrl(
'_source/' + // @Packager.RemoveLine
'skins/' + skinName + '/' ) );
} | javascript | function( skinName, skinDefinition )
{
loaded[ skinName ] = skinDefinition;
skinDefinition.skinPath = paths[ skinName ]
|| ( paths[ skinName ] =
CKEDITOR.getUrl(
'_source/' + // @Packager.RemoveLine
'skins/' + skinName + '/' ) );
} | [
"function",
"(",
"skinName",
",",
"skinDefinition",
")",
"{",
"loaded",
"[",
"skinName",
"]",
"=",
"skinDefinition",
";",
"skinDefinition",
".",
"skinPath",
"=",
"paths",
"[",
"skinName",
"]",
"||",
"(",
"paths",
"[",
"skinName",
"]",
"=",
"CKEDITOR",
".",
"getUrl",
"(",
"'_source/'",
"+",
"// @Packager.RemoveLine\r",
"'skins/'",
"+",
"skinName",
"+",
"'/'",
")",
")",
";",
"}"
]
| Registers a skin definition.
@param {String} skinName The skin name.
@param {Object} skinDefinition The skin definition.
@example | [
"Registers",
"a",
"skin",
"definition",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/skins.js#L145-L154 |
|
47,746 | saggiyogesh/nodeportal | public/ckeditor/_source/core/skins.js | function( editor, skinPart, callback )
{
var skinName = editor.skinName,
skinPath = editor.skinPath;
if ( loaded[ skinName ] )
loadPart( editor, skinName, skinPart, callback );
else
{
paths[ skinName ] = skinPath;
CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( skinPath + 'skin.js' ), function()
{
loadPart( editor, skinName, skinPart, callback );
});
}
} | javascript | function( editor, skinPart, callback )
{
var skinName = editor.skinName,
skinPath = editor.skinPath;
if ( loaded[ skinName ] )
loadPart( editor, skinName, skinPart, callback );
else
{
paths[ skinName ] = skinPath;
CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( skinPath + 'skin.js' ), function()
{
loadPart( editor, skinName, skinPart, callback );
});
}
} | [
"function",
"(",
"editor",
",",
"skinPart",
",",
"callback",
")",
"{",
"var",
"skinName",
"=",
"editor",
".",
"skinName",
",",
"skinPath",
"=",
"editor",
".",
"skinPath",
";",
"if",
"(",
"loaded",
"[",
"skinName",
"]",
")",
"loadPart",
"(",
"editor",
",",
"skinName",
",",
"skinPart",
",",
"callback",
")",
";",
"else",
"{",
"paths",
"[",
"skinName",
"]",
"=",
"skinPath",
";",
"CKEDITOR",
".",
"scriptLoader",
".",
"load",
"(",
"CKEDITOR",
".",
"getUrl",
"(",
"skinPath",
"+",
"'skin.js'",
")",
",",
"function",
"(",
")",
"{",
"loadPart",
"(",
"editor",
",",
"skinName",
",",
"skinPart",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
"}"
]
| Loads a skin part. Skins are defined in parts, which are basically
separated CSS files. This function is mainly used by the core code and
should not have much use out of it.
@param {String} skinName The name of the skin to be loaded.
@param {String} skinPart The skin part to be loaded. Common skin parts
are "editor" and "dialog".
@param {Function} [callback] A function to be called once the skin
part files are loaded.
@example | [
"Loads",
"a",
"skin",
"part",
".",
"Skins",
"are",
"defined",
"in",
"parts",
"which",
"are",
"basically",
"separated",
"CSS",
"files",
".",
"This",
"function",
"is",
"mainly",
"used",
"by",
"the",
"core",
"code",
"and",
"should",
"not",
"have",
"much",
"use",
"out",
"of",
"it",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/skins.js#L167-L182 |
|
47,747 | Testlio/lambda-foundation | lib/util.js | forOwnDeep | function forOwnDeep(object, callback, prefix) {
prefix = prefix ? prefix + '.' : '';
_.forOwn(object, function(value, key) {
if (_.isString(value)) {
callback(value, prefix + key);
} else {
forOwnDeep(value, callback, prefix + key);
}
});
} | javascript | function forOwnDeep(object, callback, prefix) {
prefix = prefix ? prefix + '.' : '';
_.forOwn(object, function(value, key) {
if (_.isString(value)) {
callback(value, prefix + key);
} else {
forOwnDeep(value, callback, prefix + key);
}
});
} | [
"function",
"forOwnDeep",
"(",
"object",
",",
"callback",
",",
"prefix",
")",
"{",
"prefix",
"=",
"prefix",
"?",
"prefix",
"+",
"'.'",
":",
"''",
";",
"_",
".",
"forOwn",
"(",
"object",
",",
"function",
"(",
"value",
",",
"key",
")",
"{",
"if",
"(",
"_",
".",
"isString",
"(",
"value",
")",
")",
"{",
"callback",
"(",
"value",
",",
"prefix",
"+",
"key",
")",
";",
"}",
"else",
"{",
"forOwnDeep",
"(",
"value",
",",
"callback",
",",
"prefix",
"+",
"key",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Utility function for looping deeply over an object's properties
@param object - object to loop over
@param callback - callback to call for every key-value pair found
@param prefix - prefix to use for the keys that are returned in the callback | [
"Utility",
"function",
"for",
"looping",
"deeply",
"over",
"an",
"object",
"s",
"properties"
]
| d6db22ab7974b9279f17466f36f77af4d53fde01 | https://github.com/Testlio/lambda-foundation/blob/d6db22ab7974b9279f17466f36f77af4d53fde01/lib/util.js#L14-L24 |
47,748 | slideme/rorschach | lib/Lock.js | Lock | function Lock(client, basePath, lockName, lockDriver) {
if (lockName instanceof LockDriver) {
lockDriver = lockName;
lockName = null;
}
if (!lockName) {
lockName = Lock.LOCK_NAME;
}
if (!lockDriver) {
lockDriver = new LockDriver();
}
/**
* Keep ref to client as all the low-level operations are done through it.
*
* @type {Rorschach}
*/
this.client = client;
/**
* Base path should be valid ZooKeeper path.
*
* @type {String}
*/
this.basePath = basePath;
/**
* Node name.
*
* @type {String}
*/
this.lockName = lockName;
/**
* Lock driver.
*
* @type {LockDriver}
*/
this.driver = lockDriver;
/**
* Sequence node name (set when acquired).
*
* @type {String}
*/
this.lockPath;
/**
* Number of max leases.
*
* @type {Number}
*/
this.maxLeases = 1;
/**
* Number of acquires.
*
* @type {Number}
*/
this.acquires = 0;
} | javascript | function Lock(client, basePath, lockName, lockDriver) {
if (lockName instanceof LockDriver) {
lockDriver = lockName;
lockName = null;
}
if (!lockName) {
lockName = Lock.LOCK_NAME;
}
if (!lockDriver) {
lockDriver = new LockDriver();
}
/**
* Keep ref to client as all the low-level operations are done through it.
*
* @type {Rorschach}
*/
this.client = client;
/**
* Base path should be valid ZooKeeper path.
*
* @type {String}
*/
this.basePath = basePath;
/**
* Node name.
*
* @type {String}
*/
this.lockName = lockName;
/**
* Lock driver.
*
* @type {LockDriver}
*/
this.driver = lockDriver;
/**
* Sequence node name (set when acquired).
*
* @type {String}
*/
this.lockPath;
/**
* Number of max leases.
*
* @type {Number}
*/
this.maxLeases = 1;
/**
* Number of acquires.
*
* @type {Number}
*/
this.acquires = 0;
} | [
"function",
"Lock",
"(",
"client",
",",
"basePath",
",",
"lockName",
",",
"lockDriver",
")",
"{",
"if",
"(",
"lockName",
"instanceof",
"LockDriver",
")",
"{",
"lockDriver",
"=",
"lockName",
";",
"lockName",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"lockName",
")",
"{",
"lockName",
"=",
"Lock",
".",
"LOCK_NAME",
";",
"}",
"if",
"(",
"!",
"lockDriver",
")",
"{",
"lockDriver",
"=",
"new",
"LockDriver",
"(",
")",
";",
"}",
"/**\n * Keep ref to client as all the low-level operations are done through it.\n *\n * @type {Rorschach}\n */",
"this",
".",
"client",
"=",
"client",
";",
"/**\n * Base path should be valid ZooKeeper path.\n *\n * @type {String}\n */",
"this",
".",
"basePath",
"=",
"basePath",
";",
"/**\n * Node name.\n *\n * @type {String}\n */",
"this",
".",
"lockName",
"=",
"lockName",
";",
"/**\n * Lock driver.\n *\n * @type {LockDriver}\n */",
"this",
".",
"driver",
"=",
"lockDriver",
";",
"/**\n * Sequence node name (set when acquired).\n *\n * @type {String}\n */",
"this",
".",
"lockPath",
";",
"/**\n * Number of max leases.\n *\n * @type {Number}\n */",
"this",
".",
"maxLeases",
"=",
"1",
";",
"/**\n * Number of acquires.\n *\n * @type {Number}\n */",
"this",
".",
"acquires",
"=",
"0",
";",
"}"
]
| Distributed lock implementation
@constructor
@param {Rorschach} client Rorschach instance
@param {String} basePath Base lock path
@param {String} [lockName] Ephemeral node name
@param {LockDriver} [lockDriver=new LockDriver()] Lock utilities | [
"Distributed",
"lock",
"implementation"
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/Lock.js#L29-L96 |
47,749 | slideme/rorschach | lib/Lock.js | attemptLock | function attemptLock(lock, timeout, callback) {
var lockPath;
var sequenceNodeName;
var timerId = null;
var start = Date.now();
createNode(lock, afterCreate);
function afterCreate(err, nodePath) {
if (err) {
return exit(err);
}
lockPath = nodePath;
sequenceNodeName = nodePath.substring(lock.basePath.length + 1);
getSortedChildren(lock, afterGetChildren);
}
function afterGetChildren(err, list) {
if (exited()) {
return;
}
if (err) {
return exit(err);
}
var result = lock.driver.getsTheLock(list, sequenceNodeName,
lock.maxLeases);
if (result.error) {
return exit(result.error);
}
else if (result.hasLock) {
return exit(null, lockPath);
}
var watchPath = utils.join(lock.basePath, result.watchPath);
lock.client
.getData()
.usingWatcher(watcher)
.forPath(watchPath, afterGetData);
setTimer();
}
function afterGetData(err) {
if (exited() || !err) {
return;
}
if (err.getCode() === Exception.NO_NODE) {
getSortedChildren(lock, afterGetChildren);
}
else {
exit(err);
}
}
function watcher(event) {
if (!exited() && event.getType() === Event.NODE_DELETED) {
getSortedChildren(lock, afterGetChildren);
}
}
function setTimer() {
if (timerId) {
return;
}
if (timeout >= 0) {
timeout -= Date.now() - start;
if (timeout <= 0) {
return sayBye();
}
timerId = setTimeout(sayBye, timeout);
}
}
function sayBye() {
exit(new TimeoutError('Could not acquire lock %s', lock.basePath));
}
function exit(err, path) {
if (timerId) {
clearTimeout(timerId);
timerId = -1;
}
var cb = callback;
callback = null;
if (!err) {
cb(null, path);
}
else if (lockPath) {
deleteNode(lock, lockPath, proceed);
}
else {
cb(err);
}
function proceed(deleteError) {
if (deleteError) {
cb(deleteError);
}
else {
cb(err);
}
}
}
function exited() {
return !callback;
}
} | javascript | function attemptLock(lock, timeout, callback) {
var lockPath;
var sequenceNodeName;
var timerId = null;
var start = Date.now();
createNode(lock, afterCreate);
function afterCreate(err, nodePath) {
if (err) {
return exit(err);
}
lockPath = nodePath;
sequenceNodeName = nodePath.substring(lock.basePath.length + 1);
getSortedChildren(lock, afterGetChildren);
}
function afterGetChildren(err, list) {
if (exited()) {
return;
}
if (err) {
return exit(err);
}
var result = lock.driver.getsTheLock(list, sequenceNodeName,
lock.maxLeases);
if (result.error) {
return exit(result.error);
}
else if (result.hasLock) {
return exit(null, lockPath);
}
var watchPath = utils.join(lock.basePath, result.watchPath);
lock.client
.getData()
.usingWatcher(watcher)
.forPath(watchPath, afterGetData);
setTimer();
}
function afterGetData(err) {
if (exited() || !err) {
return;
}
if (err.getCode() === Exception.NO_NODE) {
getSortedChildren(lock, afterGetChildren);
}
else {
exit(err);
}
}
function watcher(event) {
if (!exited() && event.getType() === Event.NODE_DELETED) {
getSortedChildren(lock, afterGetChildren);
}
}
function setTimer() {
if (timerId) {
return;
}
if (timeout >= 0) {
timeout -= Date.now() - start;
if (timeout <= 0) {
return sayBye();
}
timerId = setTimeout(sayBye, timeout);
}
}
function sayBye() {
exit(new TimeoutError('Could not acquire lock %s', lock.basePath));
}
function exit(err, path) {
if (timerId) {
clearTimeout(timerId);
timerId = -1;
}
var cb = callback;
callback = null;
if (!err) {
cb(null, path);
}
else if (lockPath) {
deleteNode(lock, lockPath, proceed);
}
else {
cb(err);
}
function proceed(deleteError) {
if (deleteError) {
cb(deleteError);
}
else {
cb(err);
}
}
}
function exited() {
return !callback;
}
} | [
"function",
"attemptLock",
"(",
"lock",
",",
"timeout",
",",
"callback",
")",
"{",
"var",
"lockPath",
";",
"var",
"sequenceNodeName",
";",
"var",
"timerId",
"=",
"null",
";",
"var",
"start",
"=",
"Date",
".",
"now",
"(",
")",
";",
"createNode",
"(",
"lock",
",",
"afterCreate",
")",
";",
"function",
"afterCreate",
"(",
"err",
",",
"nodePath",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"exit",
"(",
"err",
")",
";",
"}",
"lockPath",
"=",
"nodePath",
";",
"sequenceNodeName",
"=",
"nodePath",
".",
"substring",
"(",
"lock",
".",
"basePath",
".",
"length",
"+",
"1",
")",
";",
"getSortedChildren",
"(",
"lock",
",",
"afterGetChildren",
")",
";",
"}",
"function",
"afterGetChildren",
"(",
"err",
",",
"list",
")",
"{",
"if",
"(",
"exited",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"err",
")",
"{",
"return",
"exit",
"(",
"err",
")",
";",
"}",
"var",
"result",
"=",
"lock",
".",
"driver",
".",
"getsTheLock",
"(",
"list",
",",
"sequenceNodeName",
",",
"lock",
".",
"maxLeases",
")",
";",
"if",
"(",
"result",
".",
"error",
")",
"{",
"return",
"exit",
"(",
"result",
".",
"error",
")",
";",
"}",
"else",
"if",
"(",
"result",
".",
"hasLock",
")",
"{",
"return",
"exit",
"(",
"null",
",",
"lockPath",
")",
";",
"}",
"var",
"watchPath",
"=",
"utils",
".",
"join",
"(",
"lock",
".",
"basePath",
",",
"result",
".",
"watchPath",
")",
";",
"lock",
".",
"client",
".",
"getData",
"(",
")",
".",
"usingWatcher",
"(",
"watcher",
")",
".",
"forPath",
"(",
"watchPath",
",",
"afterGetData",
")",
";",
"setTimer",
"(",
")",
";",
"}",
"function",
"afterGetData",
"(",
"err",
")",
"{",
"if",
"(",
"exited",
"(",
")",
"||",
"!",
"err",
")",
"{",
"return",
";",
"}",
"if",
"(",
"err",
".",
"getCode",
"(",
")",
"===",
"Exception",
".",
"NO_NODE",
")",
"{",
"getSortedChildren",
"(",
"lock",
",",
"afterGetChildren",
")",
";",
"}",
"else",
"{",
"exit",
"(",
"err",
")",
";",
"}",
"}",
"function",
"watcher",
"(",
"event",
")",
"{",
"if",
"(",
"!",
"exited",
"(",
")",
"&&",
"event",
".",
"getType",
"(",
")",
"===",
"Event",
".",
"NODE_DELETED",
")",
"{",
"getSortedChildren",
"(",
"lock",
",",
"afterGetChildren",
")",
";",
"}",
"}",
"function",
"setTimer",
"(",
")",
"{",
"if",
"(",
"timerId",
")",
"{",
"return",
";",
"}",
"if",
"(",
"timeout",
">=",
"0",
")",
"{",
"timeout",
"-=",
"Date",
".",
"now",
"(",
")",
"-",
"start",
";",
"if",
"(",
"timeout",
"<=",
"0",
")",
"{",
"return",
"sayBye",
"(",
")",
";",
"}",
"timerId",
"=",
"setTimeout",
"(",
"sayBye",
",",
"timeout",
")",
";",
"}",
"}",
"function",
"sayBye",
"(",
")",
"{",
"exit",
"(",
"new",
"TimeoutError",
"(",
"'Could not acquire lock %s'",
",",
"lock",
".",
"basePath",
")",
")",
";",
"}",
"function",
"exit",
"(",
"err",
",",
"path",
")",
"{",
"if",
"(",
"timerId",
")",
"{",
"clearTimeout",
"(",
"timerId",
")",
";",
"timerId",
"=",
"-",
"1",
";",
"}",
"var",
"cb",
"=",
"callback",
";",
"callback",
"=",
"null",
";",
"if",
"(",
"!",
"err",
")",
"{",
"cb",
"(",
"null",
",",
"path",
")",
";",
"}",
"else",
"if",
"(",
"lockPath",
")",
"{",
"deleteNode",
"(",
"lock",
",",
"lockPath",
",",
"proceed",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"function",
"proceed",
"(",
"deleteError",
")",
"{",
"if",
"(",
"deleteError",
")",
"{",
"cb",
"(",
"deleteError",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"err",
")",
";",
"}",
"}",
"}",
"function",
"exited",
"(",
")",
"{",
"return",
"!",
"callback",
";",
"}",
"}"
]
| Attempt to acquire a lock.
@private
@param {Lock} lock Instance
@param {Number} timeout Timeout
@param {Function} callback Callback function: <code>(err, lockPath)</code> | [
"Attempt",
"to",
"acquire",
"a",
"lock",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/Lock.js#L158-L277 |
47,750 | slideme/rorschach | lib/Lock.js | createNode | function createNode(lock, callback) {
var nodePath = utils.join(lock.basePath, lock.lockName);
var client = lock.client;
client
.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
.forPath(nodePath, callback);
} | javascript | function createNode(lock, callback) {
var nodePath = utils.join(lock.basePath, lock.lockName);
var client = lock.client;
client
.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.EPHEMERAL_SEQUENTIAL)
.forPath(nodePath, callback);
} | [
"function",
"createNode",
"(",
"lock",
",",
"callback",
")",
"{",
"var",
"nodePath",
"=",
"utils",
".",
"join",
"(",
"lock",
".",
"basePath",
",",
"lock",
".",
"lockName",
")",
";",
"var",
"client",
"=",
"lock",
".",
"client",
";",
"client",
".",
"create",
"(",
")",
".",
"creatingParentsIfNeeded",
"(",
")",
".",
"withMode",
"(",
"CreateMode",
".",
"EPHEMERAL_SEQUENTIAL",
")",
".",
"forPath",
"(",
"nodePath",
",",
"callback",
")",
";",
"}"
]
| Create lock node.
@private
@param {Lock} lock Lock instance
@param {Function} callback Callback function: `(err, nodePath)` | [
"Create",
"lock",
"node",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/Lock.js#L289-L298 |
47,751 | slideme/rorschach | lib/Lock.js | deleteNode | function deleteNode(lock, lockPath, callback) {
lock.client
.delete()
.guaranteed()
.forPath(lockPath, callback);
} | javascript | function deleteNode(lock, lockPath, callback) {
lock.client
.delete()
.guaranteed()
.forPath(lockPath, callback);
} | [
"function",
"deleteNode",
"(",
"lock",
",",
"lockPath",
",",
"callback",
")",
"{",
"lock",
".",
"client",
".",
"delete",
"(",
")",
".",
"guaranteed",
"(",
")",
".",
"forPath",
"(",
"lockPath",
",",
"callback",
")",
";",
"}"
]
| Guaranteed node deletion.
@private
@param {Lock} lock Lock instance
@param {String} lockPath
@param {Function} [callback] Callback function: `(err)` | [
"Guaranteed",
"node",
"deletion",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/Lock.js#L311-L316 |
47,752 | lucastan/node-buffer-utils | lib/utils.js | dupBuffer | function dupBuffer(buf){
var cloned = new Buffer(buf.length);
buf.copy(cloned);
return cloned;
} | javascript | function dupBuffer(buf){
var cloned = new Buffer(buf.length);
buf.copy(cloned);
return cloned;
} | [
"function",
"dupBuffer",
"(",
"buf",
")",
"{",
"var",
"cloned",
"=",
"new",
"Buffer",
"(",
"buf",
".",
"length",
")",
";",
"buf",
".",
"copy",
"(",
"cloned",
")",
";",
"return",
"cloned",
";",
"}"
]
| Duplicates a buffer.
@param {Buffer} buf To be duplicated.
@return {Buffer} A new buffer with the exact same size and contents.
Modifying this will NOT modify the original instance. | [
"Duplicates",
"a",
"buffer",
"."
]
| 8c7d7c498c2c9ada3c217f1faf08874c3e1644ed | https://github.com/lucastan/node-buffer-utils/blob/8c7d7c498c2c9ada3c217f1faf08874c3e1644ed/lib/utils.js#L9-L13 |
47,753 | lucastan/node-buffer-utils | lib/utils.js | compare | function compare(buf1, buf2){
if (buf1.length !== buf2.length)
return buf1.length - buf2.length;
for (var i = 0; i < buf1.length; i++)
if (buf1[i] !== buf2[i])
return buf1[i] - buf2[i];
return 0;
} | javascript | function compare(buf1, buf2){
if (buf1.length !== buf2.length)
return buf1.length - buf2.length;
for (var i = 0; i < buf1.length; i++)
if (buf1[i] !== buf2[i])
return buf1[i] - buf2[i];
return 0;
} | [
"function",
"compare",
"(",
"buf1",
",",
"buf2",
")",
"{",
"if",
"(",
"buf1",
".",
"length",
"!==",
"buf2",
".",
"length",
")",
"return",
"buf1",
".",
"length",
"-",
"buf2",
".",
"length",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"buf1",
".",
"length",
";",
"i",
"++",
")",
"if",
"(",
"buf1",
"[",
"i",
"]",
"!==",
"buf2",
"[",
"i",
"]",
")",
"return",
"buf1",
"[",
"i",
"]",
"-",
"buf2",
"[",
"i",
"]",
";",
"return",
"0",
";",
"}"
]
| Compares 2 buffers, works like C's memcmp.
@return {integer} -1 if buf1 is "smaller", 0 if both are equal,
1 if buf1 is "greater". | [
"Compares",
"2",
"buffers",
"works",
"like",
"C",
"s",
"memcmp",
"."
]
| 8c7d7c498c2c9ada3c217f1faf08874c3e1644ed | https://github.com/lucastan/node-buffer-utils/blob/8c7d7c498c2c9ada3c217f1faf08874c3e1644ed/lib/utils.js#L20-L29 |
47,754 | xpepermint/koa-strong-params | lib/index.js | strongify | function strongify(o) {
/**
* Cloning object.
*/
var params = _.clone(o);
/**
* Returns all object data.
*
* @return {object}
* @api public
*/
params.all = function() {
return params = _.omit(params, ['all', 'only', 'except', 'require', 'merge']);
}
/**
* Returns only listed object keys.
*
* @return {object}
* @api public
*/
params.only = function() {
return params = _.pick(params, _.flatten(arguments));
}
/**
* Returns all object keys except those listed.
*
* @return {object}
* @api public
*/
params.except = function() {
params = _.omit(params, _.flatten(arguments));
return params = params.all(params);
}
/**
* Returns a sub-object or throws an error if the requested key does not
* exist. This is usefull when working with nested data (e.g. user[name]).
*
* @return {object}
* @api public
*/
params.require = function(key) {
if (Object.keys(params).indexOf(key) == -1) throw new Error('param `'+key+'` required');
if (typeof params[key] != 'object') throw new Error('param `'+key+'` is not an object');
return params = strongify(params[key]);
}
/**
* Returns params with merged data.
*
* @return {object}
* @api public
*/
params.merge = function(data) {
return params = _.merge(params, data);
}
/**
* Return object.
*/
return params;
} | javascript | function strongify(o) {
/**
* Cloning object.
*/
var params = _.clone(o);
/**
* Returns all object data.
*
* @return {object}
* @api public
*/
params.all = function() {
return params = _.omit(params, ['all', 'only', 'except', 'require', 'merge']);
}
/**
* Returns only listed object keys.
*
* @return {object}
* @api public
*/
params.only = function() {
return params = _.pick(params, _.flatten(arguments));
}
/**
* Returns all object keys except those listed.
*
* @return {object}
* @api public
*/
params.except = function() {
params = _.omit(params, _.flatten(arguments));
return params = params.all(params);
}
/**
* Returns a sub-object or throws an error if the requested key does not
* exist. This is usefull when working with nested data (e.g. user[name]).
*
* @return {object}
* @api public
*/
params.require = function(key) {
if (Object.keys(params).indexOf(key) == -1) throw new Error('param `'+key+'` required');
if (typeof params[key] != 'object') throw new Error('param `'+key+'` is not an object');
return params = strongify(params[key]);
}
/**
* Returns params with merged data.
*
* @return {object}
* @api public
*/
params.merge = function(data) {
return params = _.merge(params, data);
}
/**
* Return object.
*/
return params;
} | [
"function",
"strongify",
"(",
"o",
")",
"{",
"/**\n * Cloning object.\n */",
"var",
"params",
"=",
"_",
".",
"clone",
"(",
"o",
")",
";",
"/**\n * Returns all object data.\n *\n * @return {object}\n * @api public\n */",
"params",
".",
"all",
"=",
"function",
"(",
")",
"{",
"return",
"params",
"=",
"_",
".",
"omit",
"(",
"params",
",",
"[",
"'all'",
",",
"'only'",
",",
"'except'",
",",
"'require'",
",",
"'merge'",
"]",
")",
";",
"}",
"/**\n * Returns only listed object keys.\n *\n * @return {object}\n * @api public\n */",
"params",
".",
"only",
"=",
"function",
"(",
")",
"{",
"return",
"params",
"=",
"_",
".",
"pick",
"(",
"params",
",",
"_",
".",
"flatten",
"(",
"arguments",
")",
")",
";",
"}",
"/**\n * Returns all object keys except those listed.\n *\n * @return {object}\n * @api public\n */",
"params",
".",
"except",
"=",
"function",
"(",
")",
"{",
"params",
"=",
"_",
".",
"omit",
"(",
"params",
",",
"_",
".",
"flatten",
"(",
"arguments",
")",
")",
";",
"return",
"params",
"=",
"params",
".",
"all",
"(",
"params",
")",
";",
"}",
"/**\n * Returns a sub-object or throws an error if the requested key does not\n * exist. This is usefull when working with nested data (e.g. user[name]).\n *\n * @return {object}\n * @api public\n */",
"params",
".",
"require",
"=",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"Object",
".",
"keys",
"(",
"params",
")",
".",
"indexOf",
"(",
"key",
")",
"==",
"-",
"1",
")",
"throw",
"new",
"Error",
"(",
"'param `'",
"+",
"key",
"+",
"'` required'",
")",
";",
"if",
"(",
"typeof",
"params",
"[",
"key",
"]",
"!=",
"'object'",
")",
"throw",
"new",
"Error",
"(",
"'param `'",
"+",
"key",
"+",
"'` is not an object'",
")",
";",
"return",
"params",
"=",
"strongify",
"(",
"params",
"[",
"key",
"]",
")",
";",
"}",
"/**\n * Returns params with merged data.\n *\n * @return {object}\n * @api public\n */",
"params",
".",
"merge",
"=",
"function",
"(",
"data",
")",
"{",
"return",
"params",
"=",
"_",
".",
"merge",
"(",
"params",
",",
"data",
")",
";",
"}",
"/**\n * Return object.\n */",
"return",
"params",
";",
"}"
]
| Returns cloned object with extends functionality.
@param {object}
@return {object}
@api private | [
"Returns",
"cloned",
"object",
"with",
"extends",
"functionality",
"."
]
| 2a81065064b2a5096dc57545fc611607f122f047 | https://github.com/xpepermint/koa-strong-params/blob/2a81065064b2a5096dc57545fc611607f122f047/lib/index.js#L17-L89 |
47,755 | saggiyogesh/nodeportal | plugins/themeBuilder/client/themeBuilder.js | saveFileChanges | function saveFileChanges(themeId, folderName, fileName, text) {
io({
url:getURL("save") + "/" + themeId + "/" + folderName + "/" + fileName,
data:{
content:encodeURI(text)
},
callback:function (isSuccess, message, response) {
if (!isSuccess) {
showErrorMsg(message);
}
}
});
} | javascript | function saveFileChanges(themeId, folderName, fileName, text) {
io({
url:getURL("save") + "/" + themeId + "/" + folderName + "/" + fileName,
data:{
content:encodeURI(text)
},
callback:function (isSuccess, message, response) {
if (!isSuccess) {
showErrorMsg(message);
}
}
});
} | [
"function",
"saveFileChanges",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
",",
"text",
")",
"{",
"io",
"(",
"{",
"url",
":",
"getURL",
"(",
"\"save\"",
")",
"+",
"\"/\"",
"+",
"themeId",
"+",
"\"/\"",
"+",
"folderName",
"+",
"\"/\"",
"+",
"fileName",
",",
"data",
":",
"{",
"content",
":",
"encodeURI",
"(",
"text",
")",
"}",
",",
"callback",
":",
"function",
"(",
"isSuccess",
",",
"message",
",",
"response",
")",
"{",
"if",
"(",
"!",
"isSuccess",
")",
"{",
"showErrorMsg",
"(",
"message",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
]
| Handler for save file changes
@param {String} themeId
@param {String} folderName
@param {String} fileName
@param {String} text | [
"Handler",
"for",
"save",
"file",
"changes"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/themeBuilder/client/themeBuilder.js#L55-L67 |
47,756 | saggiyogesh/nodeportal | plugins/themeBuilder/client/themeBuilder.js | initAceEditor | function initAceEditor(themeId, folderName, fileName, text, mode) {
hideImageHolder();
$("#" + editorId).show();
var doc = new Document(text);
var session = new EditSession(doc, "ace/mode/" + mode);
session.setUndoManager(new UndoManager());
editor.setSession(session);
//bind change event for text changes in opened file and save them.
doc.on('change', function (e) {
// e.type, etc
console.log(e);
saveFileChanges(themeId, folderName, fileName, doc.getValue());
});
} | javascript | function initAceEditor(themeId, folderName, fileName, text, mode) {
hideImageHolder();
$("#" + editorId).show();
var doc = new Document(text);
var session = new EditSession(doc, "ace/mode/" + mode);
session.setUndoManager(new UndoManager());
editor.setSession(session);
//bind change event for text changes in opened file and save them.
doc.on('change', function (e) {
// e.type, etc
console.log(e);
saveFileChanges(themeId, folderName, fileName, doc.getValue());
});
} | [
"function",
"initAceEditor",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
",",
"text",
",",
"mode",
")",
"{",
"hideImageHolder",
"(",
")",
";",
"$",
"(",
"\"#\"",
"+",
"editorId",
")",
".",
"show",
"(",
")",
";",
"var",
"doc",
"=",
"new",
"Document",
"(",
"text",
")",
";",
"var",
"session",
"=",
"new",
"EditSession",
"(",
"doc",
",",
"\"ace/mode/\"",
"+",
"mode",
")",
";",
"session",
".",
"setUndoManager",
"(",
"new",
"UndoManager",
"(",
")",
")",
";",
"editor",
".",
"setSession",
"(",
"session",
")",
";",
"//bind change event for text changes in opened file and save them.",
"doc",
".",
"on",
"(",
"'change'",
",",
"function",
"(",
"e",
")",
"{",
"// e.type, etc",
"console",
".",
"log",
"(",
"e",
")",
";",
"saveFileChanges",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
",",
"doc",
".",
"getValue",
"(",
")",
")",
";",
"}",
")",
";",
"}"
]
| Initialize editor for each file opened
@param {String} themeId
@param {String} folderName
@param {String} fileName
@param {String} text
@param {String} mode | [
"Initialize",
"editor",
"for",
"each",
"file",
"opened"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/themeBuilder/client/themeBuilder.js#L77-L91 |
47,757 | saggiyogesh/nodeportal | plugins/themeBuilder/client/themeBuilder.js | openFile | function openFile(themeId, folderName, fileName) {
if (themeId && folderName && fileName) {
//if image then display it
if (folderName === "images") {
showImage(themeId, folderName, fileName);
return;
}
var options = {
url:getURL("show") + "/" + themeId + "/" + folderName + "/" + fileName,
success:function (response) {
if (response.status === "error") {
util.showErrorFlash(response.message);
}
else {
// if js, css or jade file then show in editor
var mode = "scss";
if (fileName.indexOf(".js") > -1) {
mode = "javascript";
}
else if (fileName.indexOf(".css") > -1) {
mode = "css";
}
initAceEditor(themeId, folderName, fileName, response, mode);
}
}
};
Rocket.ajax(options);
}
} | javascript | function openFile(themeId, folderName, fileName) {
if (themeId && folderName && fileName) {
//if image then display it
if (folderName === "images") {
showImage(themeId, folderName, fileName);
return;
}
var options = {
url:getURL("show") + "/" + themeId + "/" + folderName + "/" + fileName,
success:function (response) {
if (response.status === "error") {
util.showErrorFlash(response.message);
}
else {
// if js, css or jade file then show in editor
var mode = "scss";
if (fileName.indexOf(".js") > -1) {
mode = "javascript";
}
else if (fileName.indexOf(".css") > -1) {
mode = "css";
}
initAceEditor(themeId, folderName, fileName, response, mode);
}
}
};
Rocket.ajax(options);
}
} | [
"function",
"openFile",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
")",
"{",
"if",
"(",
"themeId",
"&&",
"folderName",
"&&",
"fileName",
")",
"{",
"//if image then display it",
"if",
"(",
"folderName",
"===",
"\"images\"",
")",
"{",
"showImage",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
")",
";",
"return",
";",
"}",
"var",
"options",
"=",
"{",
"url",
":",
"getURL",
"(",
"\"show\"",
")",
"+",
"\"/\"",
"+",
"themeId",
"+",
"\"/\"",
"+",
"folderName",
"+",
"\"/\"",
"+",
"fileName",
",",
"success",
":",
"function",
"(",
"response",
")",
"{",
"if",
"(",
"response",
".",
"status",
"===",
"\"error\"",
")",
"{",
"util",
".",
"showErrorFlash",
"(",
"response",
".",
"message",
")",
";",
"}",
"else",
"{",
"// if js, css or jade file then show in editor",
"var",
"mode",
"=",
"\"scss\"",
";",
"if",
"(",
"fileName",
".",
"indexOf",
"(",
"\".js\"",
")",
">",
"-",
"1",
")",
"{",
"mode",
"=",
"\"javascript\"",
";",
"}",
"else",
"if",
"(",
"fileName",
".",
"indexOf",
"(",
"\".css\"",
")",
">",
"-",
"1",
")",
"{",
"mode",
"=",
"\"css\"",
";",
"}",
"initAceEditor",
"(",
"themeId",
",",
"folderName",
",",
"fileName",
",",
"response",
",",
"mode",
")",
";",
"}",
"}",
"}",
";",
"Rocket",
".",
"ajax",
"(",
"options",
")",
";",
"}",
"}"
]
| Handler when theme file is activated in tree, calls io to show file content
@param {Number} themeId
@param {String} folderName
@param {String} fileName | [
"Handler",
"when",
"theme",
"file",
"is",
"activated",
"in",
"tree",
"calls",
"io",
"to",
"show",
"file",
"content"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/themeBuilder/client/themeBuilder.js#L100-L130 |
47,758 | saggiyogesh/nodeportal | plugins/themeBuilder/client/themeBuilder.js | renderThemeTree | function renderThemeTree(themeId, fileList, themeName) {
var getTreeNodes = function (arr) {
var ret = [];
_.each(arr, function (fileName) {
ret.push({title:fileName});
});
return ret;
};
var css = {title:validTitleName[0], isFolder:true, children:getTreeNodes(fileList["css"])},
js = {title:validTitleName[1], isFolder:true, children:getTreeNodes(fileList["js"])},
images = {title:validTitleName[2], isFolder:true, children:getTreeNodes(fileList["images"])},
tmpl = {title:validTitleName[3], isFolder:true, children:getTreeNodes(fileList["tmpl"])},
children = [css, images, js, tmpl];
tree = treeObj.dynatree({
onActivate:function (node) {
var data = node.data;
if (!data.isFolder) {
openFile(themeId, node.parent.data.title, data.title);
}
else {
hideEditor();
hideImageHolder();
}
},
children:{title:themeName, children:children, isFolder:true, expand:true}
}
);
$(tree).dynatree("getTree").reload();
} | javascript | function renderThemeTree(themeId, fileList, themeName) {
var getTreeNodes = function (arr) {
var ret = [];
_.each(arr, function (fileName) {
ret.push({title:fileName});
});
return ret;
};
var css = {title:validTitleName[0], isFolder:true, children:getTreeNodes(fileList["css"])},
js = {title:validTitleName[1], isFolder:true, children:getTreeNodes(fileList["js"])},
images = {title:validTitleName[2], isFolder:true, children:getTreeNodes(fileList["images"])},
tmpl = {title:validTitleName[3], isFolder:true, children:getTreeNodes(fileList["tmpl"])},
children = [css, images, js, tmpl];
tree = treeObj.dynatree({
onActivate:function (node) {
var data = node.data;
if (!data.isFolder) {
openFile(themeId, node.parent.data.title, data.title);
}
else {
hideEditor();
hideImageHolder();
}
},
children:{title:themeName, children:children, isFolder:true, expand:true}
}
);
$(tree).dynatree("getTree").reload();
} | [
"function",
"renderThemeTree",
"(",
"themeId",
",",
"fileList",
",",
"themeName",
")",
"{",
"var",
"getTreeNodes",
"=",
"function",
"(",
"arr",
")",
"{",
"var",
"ret",
"=",
"[",
"]",
";",
"_",
".",
"each",
"(",
"arr",
",",
"function",
"(",
"fileName",
")",
"{",
"ret",
".",
"push",
"(",
"{",
"title",
":",
"fileName",
"}",
")",
";",
"}",
")",
";",
"return",
"ret",
";",
"}",
";",
"var",
"css",
"=",
"{",
"title",
":",
"validTitleName",
"[",
"0",
"]",
",",
"isFolder",
":",
"true",
",",
"children",
":",
"getTreeNodes",
"(",
"fileList",
"[",
"\"css\"",
"]",
")",
"}",
",",
"js",
"=",
"{",
"title",
":",
"validTitleName",
"[",
"1",
"]",
",",
"isFolder",
":",
"true",
",",
"children",
":",
"getTreeNodes",
"(",
"fileList",
"[",
"\"js\"",
"]",
")",
"}",
",",
"images",
"=",
"{",
"title",
":",
"validTitleName",
"[",
"2",
"]",
",",
"isFolder",
":",
"true",
",",
"children",
":",
"getTreeNodes",
"(",
"fileList",
"[",
"\"images\"",
"]",
")",
"}",
",",
"tmpl",
"=",
"{",
"title",
":",
"validTitleName",
"[",
"3",
"]",
",",
"isFolder",
":",
"true",
",",
"children",
":",
"getTreeNodes",
"(",
"fileList",
"[",
"\"tmpl\"",
"]",
")",
"}",
",",
"children",
"=",
"[",
"css",
",",
"images",
",",
"js",
",",
"tmpl",
"]",
";",
"tree",
"=",
"treeObj",
".",
"dynatree",
"(",
"{",
"onActivate",
":",
"function",
"(",
"node",
")",
"{",
"var",
"data",
"=",
"node",
".",
"data",
";",
"if",
"(",
"!",
"data",
".",
"isFolder",
")",
"{",
"openFile",
"(",
"themeId",
",",
"node",
".",
"parent",
".",
"data",
".",
"title",
",",
"data",
".",
"title",
")",
";",
"}",
"else",
"{",
"hideEditor",
"(",
")",
";",
"hideImageHolder",
"(",
")",
";",
"}",
"}",
",",
"children",
":",
"{",
"title",
":",
"themeName",
",",
"children",
":",
"children",
",",
"isFolder",
":",
"true",
",",
"expand",
":",
"true",
"}",
"}",
")",
";",
"$",
"(",
"tree",
")",
".",
"dynatree",
"(",
"\"getTree\"",
")",
".",
"reload",
"(",
")",
";",
"}"
]
| Renders theme's folders as tree in left side and attach handlers on each file
@param {String} themeId
@param {Object} fileList | [
"Renders",
"theme",
"s",
"folders",
"as",
"tree",
"in",
"left",
"side",
"and",
"attach",
"handlers",
"on",
"each",
"file"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/themeBuilder/client/themeBuilder.js#L137-L165 |
47,759 | jlewczyk/git-hooks-js-win | lib/git-hooks-debug.js | function (workingDirectory) {
var gitPath = getClosestGitPath(workingDirectory);
if (!gitPath) {
throw new Error('git-hooks must be run inside a git repository');
}
var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
var pathToGitHooks = path.join(path.relative(hooksPath, __dirname), 'git-hooks');
if (isWin32) {
pathToGitHooks = pathToGitHooks.replace(/\\/g, '\\\\');
}
if (fsHelpers.exists(hooksOldPath)) {
throw new Error('git-hooks already installed');
}
if (fsHelpers.exists(hooksPath)) {
fs.renameSync(hooksPath, hooksOldPath);
}
var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME);
var pathToGitHooks = path.relative(hooksPath, __dirname);
// Fix non-POSIX (Windows) separators
pathToGitHooks = pathToGitHooks.replace(new RegExp(path.sep.replace(/\\/g, '\\$&'), 'g'), '/');
var hook = util.format(hookTemplate.toString(), pathToGitHooks);
fsHelpers.makeDir(hooksPath);
HOOKS.forEach(function (hookName) {
var hookPath = path.resolve(hooksPath, hookName);
try {
fs.writeFileSync(hookPath, hook, {mode: '0777'});
} catch (e) {
// node 0.8 fallback
fs.writeFileSync(hookPath, hook, 'utf8');
fs.chmodSync(hookPath, '0777');
}
});
} | javascript | function (workingDirectory) {
var gitPath = getClosestGitPath(workingDirectory);
if (!gitPath) {
throw new Error('git-hooks must be run inside a git repository');
}
var hooksPath = path.resolve(gitPath, HOOKS_DIRNAME);
var pathToGitHooks = path.join(path.relative(hooksPath, __dirname), 'git-hooks');
if (isWin32) {
pathToGitHooks = pathToGitHooks.replace(/\\/g, '\\\\');
}
if (fsHelpers.exists(hooksOldPath)) {
throw new Error('git-hooks already installed');
}
if (fsHelpers.exists(hooksPath)) {
fs.renameSync(hooksPath, hooksOldPath);
}
var hookTemplate = fs.readFileSync(__dirname + '/' + HOOKS_TEMPLATE_FILE_NAME);
var pathToGitHooks = path.relative(hooksPath, __dirname);
// Fix non-POSIX (Windows) separators
pathToGitHooks = pathToGitHooks.replace(new RegExp(path.sep.replace(/\\/g, '\\$&'), 'g'), '/');
var hook = util.format(hookTemplate.toString(), pathToGitHooks);
fsHelpers.makeDir(hooksPath);
HOOKS.forEach(function (hookName) {
var hookPath = path.resolve(hooksPath, hookName);
try {
fs.writeFileSync(hookPath, hook, {mode: '0777'});
} catch (e) {
// node 0.8 fallback
fs.writeFileSync(hookPath, hook, 'utf8');
fs.chmodSync(hookPath, '0777');
}
});
} | [
"function",
"(",
"workingDirectory",
")",
"{",
"var",
"gitPath",
"=",
"getClosestGitPath",
"(",
"workingDirectory",
")",
";",
"if",
"(",
"!",
"gitPath",
")",
"{",
"throw",
"new",
"Error",
"(",
"'git-hooks must be run inside a git repository'",
")",
";",
"}",
"var",
"hooksPath",
"=",
"path",
".",
"resolve",
"(",
"gitPath",
",",
"HOOKS_DIRNAME",
")",
";",
"var",
"pathToGitHooks",
"=",
"path",
".",
"join",
"(",
"path",
".",
"relative",
"(",
"hooksPath",
",",
"__dirname",
")",
",",
"'git-hooks'",
")",
";",
"if",
"(",
"isWin32",
")",
"{",
"pathToGitHooks",
"=",
"pathToGitHooks",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'\\\\\\\\'",
")",
";",
"}",
"if",
"(",
"fsHelpers",
".",
"exists",
"(",
"hooksOldPath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'git-hooks already installed'",
")",
";",
"}",
"if",
"(",
"fsHelpers",
".",
"exists",
"(",
"hooksPath",
")",
")",
"{",
"fs",
".",
"renameSync",
"(",
"hooksPath",
",",
"hooksOldPath",
")",
";",
"}",
"var",
"hookTemplate",
"=",
"fs",
".",
"readFileSync",
"(",
"__dirname",
"+",
"'/'",
"+",
"HOOKS_TEMPLATE_FILE_NAME",
")",
";",
"var",
"pathToGitHooks",
"=",
"path",
".",
"relative",
"(",
"hooksPath",
",",
"__dirname",
")",
";",
"// Fix non-POSIX (Windows) separators",
"pathToGitHooks",
"=",
"pathToGitHooks",
".",
"replace",
"(",
"new",
"RegExp",
"(",
"path",
".",
"sep",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'\\\\$&'",
")",
",",
"'g'",
")",
",",
"'/'",
")",
";",
"var",
"hook",
"=",
"util",
".",
"format",
"(",
"hookTemplate",
".",
"toString",
"(",
")",
",",
"pathToGitHooks",
")",
";",
"fsHelpers",
".",
"makeDir",
"(",
"hooksPath",
")",
";",
"HOOKS",
".",
"forEach",
"(",
"function",
"(",
"hookName",
")",
"{",
"var",
"hookPath",
"=",
"path",
".",
"resolve",
"(",
"hooksPath",
",",
"hookName",
")",
";",
"try",
"{",
"fs",
".",
"writeFileSync",
"(",
"hookPath",
",",
"hook",
",",
"{",
"mode",
":",
"'0777'",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// node 0.8 fallback",
"fs",
".",
"writeFileSync",
"(",
"hookPath",
",",
"hook",
",",
"'utf8'",
")",
";",
"fs",
".",
"chmodSync",
"(",
"hookPath",
",",
"'0777'",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Installs git hooks.
@param {String} [workingDirectory]
@throws {Error} | [
"Installs",
"git",
"hooks",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks-debug.js#L51-L90 |
|
47,760 | jlewczyk/git-hooks-js-win | lib/git-hooks-debug.js | function (filename, arg, callback) {
console.log('*** git-hooks.js run', filename, arg);
var hookName = path.basename(filename);
var hooksDirname = path.resolve(path.dirname(filename), '../../.githooks', hookName);
if (fsHelpers.exists(hooksDirname)) {
var list = fs.readdirSync(hooksDirname);
var hooks = list.map(function (hookName) {
return path.resolve(hooksDirname, hookName);
});
excludeIgnoredPaths(hooks, function (filteredHooks) {
runHooks(filteredHooks, [arg], callback);
});
} else {
callback(0);
}
} | javascript | function (filename, arg, callback) {
console.log('*** git-hooks.js run', filename, arg);
var hookName = path.basename(filename);
var hooksDirname = path.resolve(path.dirname(filename), '../../.githooks', hookName);
if (fsHelpers.exists(hooksDirname)) {
var list = fs.readdirSync(hooksDirname);
var hooks = list.map(function (hookName) {
return path.resolve(hooksDirname, hookName);
});
excludeIgnoredPaths(hooks, function (filteredHooks) {
runHooks(filteredHooks, [arg], callback);
});
} else {
callback(0);
}
} | [
"function",
"(",
"filename",
",",
"arg",
",",
"callback",
")",
"{",
"console",
".",
"log",
"(",
"'*** git-hooks.js run'",
",",
"filename",
",",
"arg",
")",
";",
"var",
"hookName",
"=",
"path",
".",
"basename",
"(",
"filename",
")",
";",
"var",
"hooksDirname",
"=",
"path",
".",
"resolve",
"(",
"path",
".",
"dirname",
"(",
"filename",
")",
",",
"'../../.githooks'",
",",
"hookName",
")",
";",
"if",
"(",
"fsHelpers",
".",
"exists",
"(",
"hooksDirname",
")",
")",
"{",
"var",
"list",
"=",
"fs",
".",
"readdirSync",
"(",
"hooksDirname",
")",
";",
"var",
"hooks",
"=",
"list",
".",
"map",
"(",
"function",
"(",
"hookName",
")",
"{",
"return",
"path",
".",
"resolve",
"(",
"hooksDirname",
",",
"hookName",
")",
";",
"}",
")",
";",
"excludeIgnoredPaths",
"(",
"hooks",
",",
"function",
"(",
"filteredHooks",
")",
"{",
"runHooks",
"(",
"filteredHooks",
",",
"[",
"arg",
"]",
",",
"callback",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"0",
")",
";",
"}",
"}"
]
| Runs a git hook.
@param {String} filename Path to git hook.
@param {String} [arg] Git hook argument.
@param {Function} callback | [
"Runs",
"a",
"git",
"hook",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks-debug.js#L126-L142 |
|
47,761 | jlewczyk/git-hooks-js-win | lib/git-hooks-debug.js | runHooks | function runHooks(hooks, args, callback) {
console.log('*** git-hooks.js runHooks', hooks, args);
if (!hooks.length) {
callback(0);
return;
}
try {
var hook = spawnHook(hooks.shift(), args);
hook.on('close', function (code) {
if (code === 0) {
runHooks(hooks, args, callback);
} else {
callback(code);
}
});
} catch (e) {
callback(1, e);
}
} | javascript | function runHooks(hooks, args, callback) {
console.log('*** git-hooks.js runHooks', hooks, args);
if (!hooks.length) {
callback(0);
return;
}
try {
var hook = spawnHook(hooks.shift(), args);
hook.on('close', function (code) {
if (code === 0) {
runHooks(hooks, args, callback);
} else {
callback(code);
}
});
} catch (e) {
callback(1, e);
}
} | [
"function",
"runHooks",
"(",
"hooks",
",",
"args",
",",
"callback",
")",
"{",
"console",
".",
"log",
"(",
"'*** git-hooks.js runHooks'",
",",
"hooks",
",",
"args",
")",
";",
"if",
"(",
"!",
"hooks",
".",
"length",
")",
"{",
"callback",
"(",
"0",
")",
";",
"return",
";",
"}",
"try",
"{",
"var",
"hook",
"=",
"spawnHook",
"(",
"hooks",
".",
"shift",
"(",
")",
",",
"args",
")",
";",
"hook",
".",
"on",
"(",
"'close'",
",",
"function",
"(",
"code",
")",
"{",
"if",
"(",
"code",
"===",
"0",
")",
"{",
"runHooks",
"(",
"hooks",
",",
"args",
",",
"callback",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"code",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"callback",
"(",
"1",
",",
"e",
")",
";",
"}",
"}"
]
| Runs hooks.
@param {String[]} hooks List of hook names to execute.
@param {String[]} args
@param {Function} callback | [
"Runs",
"hooks",
"."
]
| e156f88ad7aec76c9180c70656c5568ad89f9de7 | https://github.com/jlewczyk/git-hooks-js-win/blob/e156f88ad7aec76c9180c70656c5568ad89f9de7/lib/git-hooks-debug.js#L152-L170 |
47,762 | enriched/repeating-interval | interval.js | function () {
if (this._duration) {
return this._duration;
}
if (this._start && this._end) {
return moment.duration(this._end - this._start);
}
else {
return moment.duration(0);
}
} | javascript | function () {
if (this._duration) {
return this._duration;
}
if (this._start && this._end) {
return moment.duration(this._end - this._start);
}
else {
return moment.duration(0);
}
} | [
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"_duration",
")",
"{",
"return",
"this",
".",
"_duration",
";",
"}",
"if",
"(",
"this",
".",
"_start",
"&&",
"this",
".",
"_end",
")",
"{",
"return",
"moment",
".",
"duration",
"(",
"this",
".",
"_end",
"-",
"this",
".",
"_start",
")",
";",
"}",
"else",
"{",
"return",
"moment",
".",
"duration",
"(",
"0",
")",
";",
"}",
"}"
]
| The duration of a single repition of the interval | [
"The",
"duration",
"of",
"a",
"single",
"repition",
"of",
"the",
"interval"
]
| 059173390aabbd84615fe7bc98ecca695d5d2c47 | https://github.com/enriched/repeating-interval/blob/059173390aabbd84615fe7bc98ecca695d5d2c47/interval.js#L225-L235 |
|
47,763 | anvaka/ngraph.shremlin | lib/utils/filterExpression.js | createFilter | function createFilter(filterExpression) {
if (typeof filterExpression === 'undefined') {
throw new Error('Filter expression should be defined');
}
if (isSimpleType(filterExpression)) {
return simpleTypeFilter(filterExpression);
} else if (isCustomPredicate(filterExpression)) {
return customPredicateFilter(filterExpression);
} else if (isArray(filterExpression)) {
return arrayFilter(filterExpression);
}
return customObjectFilter(filterExpression);
} | javascript | function createFilter(filterExpression) {
if (typeof filterExpression === 'undefined') {
throw new Error('Filter expression should be defined');
}
if (isSimpleType(filterExpression)) {
return simpleTypeFilter(filterExpression);
} else if (isCustomPredicate(filterExpression)) {
return customPredicateFilter(filterExpression);
} else if (isArray(filterExpression)) {
return arrayFilter(filterExpression);
}
return customObjectFilter(filterExpression);
} | [
"function",
"createFilter",
"(",
"filterExpression",
")",
"{",
"if",
"(",
"typeof",
"filterExpression",
"===",
"'undefined'",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Filter expression should be defined'",
")",
";",
"}",
"if",
"(",
"isSimpleType",
"(",
"filterExpression",
")",
")",
"{",
"return",
"simpleTypeFilter",
"(",
"filterExpression",
")",
";",
"}",
"else",
"if",
"(",
"isCustomPredicate",
"(",
"filterExpression",
")",
")",
"{",
"return",
"customPredicateFilter",
"(",
"filterExpression",
")",
";",
"}",
"else",
"if",
"(",
"isArray",
"(",
"filterExpression",
")",
")",
"{",
"return",
"arrayFilter",
"(",
"filterExpression",
")",
";",
"}",
"return",
"customObjectFilter",
"(",
"filterExpression",
")",
";",
"}"
]
| This method creates custom filter predicate based on `filterExpression`
value.
When `filterExpression` is a simple type (Number, String or Boolean), then
returned predicate compares `data` property directly with that value:
```
var match42 = createFilter(42);
// this will print true:
console.log(match42({data: 42}));
```
You might be wondering why it compares against `data` property, not object
directly (`match42(42)`)? It is thank to the fact, that data for each vertex or
edge of [VivaGraph](https://github.com/anvaka/VivaGraphJS)/[ngraph](https://github.com/anvaka/ngraph.graph)
is stored within `xxx.data` property.
If you want to filter against direct object attributes, you can pass custom
`filterExpression` as a `function`:
```
var match42 = createFiliter(function (obj) {
return obj === 42;
});
// Now this will print true:
console.log(match42(42));
```
When `filterExpression` is an array, then `data` property should also be
an array (or array-like) object, with the same elements:
```
var matchArray = createFilter([40, 2]);
// prints true:
console.log(matchArray({ data: [40, 2] });
```
Finally you can pass `filterExpression` as an `object`, in which case
`data` attribute should have all properties of `filterExpression`
and they all should be equal to values of your `filterExpression`:
```
var matchJohnSmith = createFilter({
firstName: 'John',
lastName: 'Smith'
});
// true:
matchJohnSmith({
data: { firstName: 'John', lastName: 'Smith' }
});
// false (missing lastName):
matchJohnSmith({
data: { firstName: 'John' }
});
``` | [
"This",
"method",
"creates",
"custom",
"filter",
"predicate",
"based",
"on",
"filterExpression",
"value",
"."
]
| 98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7 | https://github.com/anvaka/ngraph.shremlin/blob/98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7/lib/utils/filterExpression.js#L81-L95 |
47,764 | rksm/ace.improved | lib/ace.ext.keys.js | toUnicode | function toUnicode(charCode) {
var result = charCode.toString(16).toUpperCase();
while (result.length < 4) result = '0' + result;
return '\\u' + result;
} | javascript | function toUnicode(charCode) {
var result = charCode.toString(16).toUpperCase();
while (result.length < 4) result = '0' + result;
return '\\u' + result;
} | [
"function",
"toUnicode",
"(",
"charCode",
")",
"{",
"var",
"result",
"=",
"charCode",
".",
"toString",
"(",
"16",
")",
".",
"toUpperCase",
"(",
")",
";",
"while",
"(",
"result",
".",
"length",
"<",
"4",
")",
"result",
"=",
"'0'",
"+",
"result",
";",
"return",
"'\\\\u'",
"+",
"result",
";",
"}"
]
| -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- eventing stuff -=-=-=-=-=-=-=- | [
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"eventing",
"stuff",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-",
"=",
"-"
]
| b0b5014d9e31046608a10714c850a2441223a8f3 | https://github.com/rksm/ace.improved/blob/b0b5014d9e31046608a10714c850a2441223a8f3/lib/ace.ext.keys.js#L514-L518 |
47,765 | saggiyogesh/nodeportal | lib/permissions/PermissionError.js | PermissionError | function PermissionError(message, userName, actionKey) {
this.name = "PermissionError";
this.message = message || (userName && actionKey) ? "Permission Error. User " + userName + " is not authorized to " + actionKey : "Permission Error";
this.localizedMessageKey = "permission-error";
} | javascript | function PermissionError(message, userName, actionKey) {
this.name = "PermissionError";
this.message = message || (userName && actionKey) ? "Permission Error. User " + userName + " is not authorized to " + actionKey : "Permission Error";
this.localizedMessageKey = "permission-error";
} | [
"function",
"PermissionError",
"(",
"message",
",",
"userName",
",",
"actionKey",
")",
"{",
"this",
".",
"name",
"=",
"\"PermissionError\"",
";",
"this",
".",
"message",
"=",
"message",
"||",
"(",
"userName",
"&&",
"actionKey",
")",
"?",
"\"Permission Error. User \"",
"+",
"userName",
"+",
"\" is not authorized to \"",
"+",
"actionKey",
":",
"\"Permission Error\"",
";",
"this",
".",
"localizedMessageKey",
"=",
"\"permission-error\"",
";",
"}"
]
| This error is thrown when user role is not having permission to perform any action | [
"This",
"error",
"is",
"thrown",
"when",
"user",
"role",
"is",
"not",
"having",
"permission",
"to",
"perform",
"any",
"action"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/permissions/PermissionError.js#L5-L9 |
47,766 | garanj/amphtml-autoscript | index.js | create | function create(opt_options) {
function runInclude(file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME,
'Streams not supported!'));
}
if (file.isBuffer()) {
addIncludesToFile(file, opt_options).then((file) => {
return callback(null, file);
})
.catch(() => {
return callback(null, file);
});
}
}
var rv = function() {
return through.obj(runInclude);
};
return rv;
} | javascript | function create(opt_options) {
function runInclude(file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
if (file.isStream()) {
this.emit('error', new PluginError(PLUGIN_NAME,
'Streams not supported!'));
}
if (file.isBuffer()) {
addIncludesToFile(file, opt_options).then((file) => {
return callback(null, file);
})
.catch(() => {
return callback(null, file);
});
}
}
var rv = function() {
return through.obj(runInclude);
};
return rv;
} | [
"function",
"create",
"(",
"opt_options",
")",
"{",
"function",
"runInclude",
"(",
"file",
",",
"encoding",
",",
"callback",
")",
"{",
"if",
"(",
"file",
".",
"isNull",
"(",
")",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"file",
")",
";",
"}",
"if",
"(",
"file",
".",
"isStream",
"(",
")",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"PluginError",
"(",
"PLUGIN_NAME",
",",
"'Streams not supported!'",
")",
")",
";",
"}",
"if",
"(",
"file",
".",
"isBuffer",
"(",
")",
")",
"{",
"addIncludesToFile",
"(",
"file",
",",
"opt_options",
")",
".",
"then",
"(",
"(",
"file",
")",
"=>",
"{",
"return",
"callback",
"(",
"null",
",",
"file",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
")",
"=>",
"{",
"return",
"callback",
"(",
"null",
",",
"file",
")",
";",
"}",
")",
";",
"}",
"}",
"var",
"rv",
"=",
"function",
"(",
")",
"{",
"return",
"through",
".",
"obj",
"(",
"runInclude",
")",
";",
"}",
";",
"return",
"rv",
";",
"}"
]
| Imports the required AMP custom-element script tags into an AMP document.
@param {Object} opt_options Configurations options, currently:
placeholder: Overrides the default placeholder.
mode: Overrides the default mode (MODES.PLACEHOLDER);
@return {!Transform} The created stream.Transform object. | [
"Imports",
"the",
"required",
"AMP",
"custom",
"-",
"element",
"script",
"tags",
"into",
"an",
"AMP",
"document",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L50-L72 |
47,767 | garanj/amphtml-autoscript | index.js | addIncludesToFile | async function addIncludesToFile(file,
opt_options) {
const overrideMap = await readComponentsMap('./amp-versions.json');
const html = file.contents.toString();
const newHtml = await addIncludesToHtml(html, overrideMap, opt_options);
file.contents = new Buffer(newHtml);
return file;
} | javascript | async function addIncludesToFile(file,
opt_options) {
const overrideMap = await readComponentsMap('./amp-versions.json');
const html = file.contents.toString();
const newHtml = await addIncludesToHtml(html, overrideMap, opt_options);
file.contents = new Buffer(newHtml);
return file;
} | [
"async",
"function",
"addIncludesToFile",
"(",
"file",
",",
"opt_options",
")",
"{",
"const",
"overrideMap",
"=",
"await",
"readComponentsMap",
"(",
"'./amp-versions.json'",
")",
";",
"const",
"html",
"=",
"file",
".",
"contents",
".",
"toString",
"(",
")",
";",
"const",
"newHtml",
"=",
"await",
"addIncludesToHtml",
"(",
"html",
",",
"overrideMap",
",",
"opt_options",
")",
";",
"file",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"newHtml",
")",
";",
"return",
"file",
";",
"}"
]
| Identifies missing AMP custom-elementscript tags in an AMP HTML file and
adds them.
@param {!Vinyl} file The file to add script tags to.
@param {Object} opt_options See {@code create}.
@return {!Vinyl} The modified file. | [
"Identifies",
"missing",
"AMP",
"custom",
"-",
"elementscript",
"tags",
"in",
"an",
"AMP",
"HTML",
"file",
"and",
"adds",
"them",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L82-L89 |
47,768 | garanj/amphtml-autoscript | index.js | addIncludesToHtml | async function addIncludesToHtml(html, overrideMap,
opt_options) {
let instance = await amphtmlValidator.getInstance();
const options = opt_options || {};
if (options.updateComponentsMap) {
await updateComponentMap();
}
const versionMap = await readComponentsMap(COMPONENTS_MAP_PATH);
const result = instance.validateString(html);
const placeholder = options.placeholder || DEFAULT_AMP_PLACEHOLDER;
const mode = options.mode || DEFAULT_INSERTION_MODE;
// It is necessary to escape the placeholder as it is used in a RegExp object
// for example ${ampjs} -> \\$\\{ampjs\\}.
// Furthermore, the regular expression is defined to also match any
// preceding whitespace too, so that inserted tags can be indented to match.
const escapedPlaceholder = new RegExp('([^\\S\\r\\n]*)'
+ escapeRegex(placeholder));
var missingScriptUrls = new Set();
if (result.status === 'FAIL') {
// Determine whether the base AMP script element is missing.
for (err of result.errors) {
if (err.category === 'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'
&& err.code === 'MANDATORY_TAG_MISSING'
&& err.params && err.params[0] === 'amphtml engine v0.js script') {
missingScriptUrls.add(AMP_BASE_URL_ELEMENT);
break;
}
}
// Filter for only those errors indicating a missing script tag.
const tagErrors = result.errors
.filter(err => {
return err.category === 'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'
&& (err.code === 'MISSING_REQUIRED_EXTENSION'
|| err.code === 'ATTR_MISSING_REQUIRED_EXTENSION')});
for (let tagError of tagErrors) {
const tagName = tagError.params[1];
if (overrideMap[tagName]) {
var tagVersion = overrideMap[tagName];
} else if (options.forceLatest) {
var tagVersion = 'latest';
} else if (versionMap[tagName]) {
var tagVersion = versionMap[tagName];
}
if (!tagVersion) {
throw Error('Unknown AMP Component ' + tagName);
}
missingScriptUrls.add(createAmpCustomElementTag(tagName, tagVersion));
}
}
if (missingScriptUrls.size) {
if (mode === MODES.PLACEHOLDER) {
return addScriptUrlsByPlaceHolder(html, missingScriptUrls,
escapedPlaceholder);
} else {
return addScriptUrlsByHeaderInsertion(html, missingScriptUrls);
}
}
return html;
} | javascript | async function addIncludesToHtml(html, overrideMap,
opt_options) {
let instance = await amphtmlValidator.getInstance();
const options = opt_options || {};
if (options.updateComponentsMap) {
await updateComponentMap();
}
const versionMap = await readComponentsMap(COMPONENTS_MAP_PATH);
const result = instance.validateString(html);
const placeholder = options.placeholder || DEFAULT_AMP_PLACEHOLDER;
const mode = options.mode || DEFAULT_INSERTION_MODE;
// It is necessary to escape the placeholder as it is used in a RegExp object
// for example ${ampjs} -> \\$\\{ampjs\\}.
// Furthermore, the regular expression is defined to also match any
// preceding whitespace too, so that inserted tags can be indented to match.
const escapedPlaceholder = new RegExp('([^\\S\\r\\n]*)'
+ escapeRegex(placeholder));
var missingScriptUrls = new Set();
if (result.status === 'FAIL') {
// Determine whether the base AMP script element is missing.
for (err of result.errors) {
if (err.category === 'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'
&& err.code === 'MANDATORY_TAG_MISSING'
&& err.params && err.params[0] === 'amphtml engine v0.js script') {
missingScriptUrls.add(AMP_BASE_URL_ELEMENT);
break;
}
}
// Filter for only those errors indicating a missing script tag.
const tagErrors = result.errors
.filter(err => {
return err.category === 'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'
&& (err.code === 'MISSING_REQUIRED_EXTENSION'
|| err.code === 'ATTR_MISSING_REQUIRED_EXTENSION')});
for (let tagError of tagErrors) {
const tagName = tagError.params[1];
if (overrideMap[tagName]) {
var tagVersion = overrideMap[tagName];
} else if (options.forceLatest) {
var tagVersion = 'latest';
} else if (versionMap[tagName]) {
var tagVersion = versionMap[tagName];
}
if (!tagVersion) {
throw Error('Unknown AMP Component ' + tagName);
}
missingScriptUrls.add(createAmpCustomElementTag(tagName, tagVersion));
}
}
if (missingScriptUrls.size) {
if (mode === MODES.PLACEHOLDER) {
return addScriptUrlsByPlaceHolder(html, missingScriptUrls,
escapedPlaceholder);
} else {
return addScriptUrlsByHeaderInsertion(html, missingScriptUrls);
}
}
return html;
} | [
"async",
"function",
"addIncludesToHtml",
"(",
"html",
",",
"overrideMap",
",",
"opt_options",
")",
"{",
"let",
"instance",
"=",
"await",
"amphtmlValidator",
".",
"getInstance",
"(",
")",
";",
"const",
"options",
"=",
"opt_options",
"||",
"{",
"}",
";",
"if",
"(",
"options",
".",
"updateComponentsMap",
")",
"{",
"await",
"updateComponentMap",
"(",
")",
";",
"}",
"const",
"versionMap",
"=",
"await",
"readComponentsMap",
"(",
"COMPONENTS_MAP_PATH",
")",
";",
"const",
"result",
"=",
"instance",
".",
"validateString",
"(",
"html",
")",
";",
"const",
"placeholder",
"=",
"options",
".",
"placeholder",
"||",
"DEFAULT_AMP_PLACEHOLDER",
";",
"const",
"mode",
"=",
"options",
".",
"mode",
"||",
"DEFAULT_INSERTION_MODE",
";",
"// It is necessary to escape the placeholder as it is used in a RegExp object",
"// for example ${ampjs} -> \\\\$\\\\{ampjs\\\\}.",
"// Furthermore, the regular expression is defined to also match any",
"// preceding whitespace too, so that inserted tags can be indented to match.",
"const",
"escapedPlaceholder",
"=",
"new",
"RegExp",
"(",
"'([^\\\\S\\\\r\\\\n]*)'",
"+",
"escapeRegex",
"(",
"placeholder",
")",
")",
";",
"var",
"missingScriptUrls",
"=",
"new",
"Set",
"(",
")",
";",
"if",
"(",
"result",
".",
"status",
"===",
"'FAIL'",
")",
"{",
"// Determine whether the base AMP script element is missing.",
"for",
"(",
"err",
"of",
"result",
".",
"errors",
")",
"{",
"if",
"(",
"err",
".",
"category",
"===",
"'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'",
"&&",
"err",
".",
"code",
"===",
"'MANDATORY_TAG_MISSING'",
"&&",
"err",
".",
"params",
"&&",
"err",
".",
"params",
"[",
"0",
"]",
"===",
"'amphtml engine v0.js script'",
")",
"{",
"missingScriptUrls",
".",
"add",
"(",
"AMP_BASE_URL_ELEMENT",
")",
";",
"break",
";",
"}",
"}",
"// Filter for only those errors indicating a missing script tag.",
"const",
"tagErrors",
"=",
"result",
".",
"errors",
".",
"filter",
"(",
"err",
"=>",
"{",
"return",
"err",
".",
"category",
"===",
"'MANDATORY_AMP_TAG_MISSING_OR_INCORRECT'",
"&&",
"(",
"err",
".",
"code",
"===",
"'MISSING_REQUIRED_EXTENSION'",
"||",
"err",
".",
"code",
"===",
"'ATTR_MISSING_REQUIRED_EXTENSION'",
")",
"}",
")",
";",
"for",
"(",
"let",
"tagError",
"of",
"tagErrors",
")",
"{",
"const",
"tagName",
"=",
"tagError",
".",
"params",
"[",
"1",
"]",
";",
"if",
"(",
"overrideMap",
"[",
"tagName",
"]",
")",
"{",
"var",
"tagVersion",
"=",
"overrideMap",
"[",
"tagName",
"]",
";",
"}",
"else",
"if",
"(",
"options",
".",
"forceLatest",
")",
"{",
"var",
"tagVersion",
"=",
"'latest'",
";",
"}",
"else",
"if",
"(",
"versionMap",
"[",
"tagName",
"]",
")",
"{",
"var",
"tagVersion",
"=",
"versionMap",
"[",
"tagName",
"]",
";",
"}",
"if",
"(",
"!",
"tagVersion",
")",
"{",
"throw",
"Error",
"(",
"'Unknown AMP Component '",
"+",
"tagName",
")",
";",
"}",
"missingScriptUrls",
".",
"add",
"(",
"createAmpCustomElementTag",
"(",
"tagName",
",",
"tagVersion",
")",
")",
";",
"}",
"}",
"if",
"(",
"missingScriptUrls",
".",
"size",
")",
"{",
"if",
"(",
"mode",
"===",
"MODES",
".",
"PLACEHOLDER",
")",
"{",
"return",
"addScriptUrlsByPlaceHolder",
"(",
"html",
",",
"missingScriptUrls",
",",
"escapedPlaceholder",
")",
";",
"}",
"else",
"{",
"return",
"addScriptUrlsByHeaderInsertion",
"(",
"html",
",",
"missingScriptUrls",
")",
";",
"}",
"}",
"return",
"html",
";",
"}"
]
| Identifies missing AMP custom-element script tags in an AMP HTML test and
adds them.
This is achieved by:
1. Running the AMP validator and filtering for errors for missing extensions.
2. Creating <script> elements using versions taken from GitHub directory
listings.
@param {!Vinyl} file The file to add script tags to.
@param {Object} overrideMap Lookup of component versions for this project.
@param {Object} opt_options See {@code create}.
@return {!Vinyl} The modified file. | [
"Identifies",
"missing",
"AMP",
"custom",
"-",
"element",
"script",
"tags",
"in",
"an",
"AMP",
"HTML",
"test",
"and",
"adds",
"them",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L105-L168 |
47,769 | garanj/amphtml-autoscript | index.js | updateComponentMap | async function updateComponentMap() {
const response = await fetch(GITHUB_AMPHTML_TREE_URL);
const data = await response.json();
const pairs = data.tree.map((item) => item.path.match(REGEX_EXTENSION_DIR))
.filter((match) => match && !match[1].endsWith('impl'))
.map((match) => [match[1], match[2]]);
const versionMap = {};
pairs.forEach((pair) => {
if (!versionMap[pair[0]] || versionMap[pair[0]] < pair[1]) {
versionMap[pair[0]] = pair[1];
}
});
writeComponentsMap(COMPONENTS_MAP_PATH, versionMap);
} | javascript | async function updateComponentMap() {
const response = await fetch(GITHUB_AMPHTML_TREE_URL);
const data = await response.json();
const pairs = data.tree.map((item) => item.path.match(REGEX_EXTENSION_DIR))
.filter((match) => match && !match[1].endsWith('impl'))
.map((match) => [match[1], match[2]]);
const versionMap = {};
pairs.forEach((pair) => {
if (!versionMap[pair[0]] || versionMap[pair[0]] < pair[1]) {
versionMap[pair[0]] = pair[1];
}
});
writeComponentsMap(COMPONENTS_MAP_PATH, versionMap);
} | [
"async",
"function",
"updateComponentMap",
"(",
")",
"{",
"const",
"response",
"=",
"await",
"fetch",
"(",
"GITHUB_AMPHTML_TREE_URL",
")",
";",
"const",
"data",
"=",
"await",
"response",
".",
"json",
"(",
")",
";",
"const",
"pairs",
"=",
"data",
".",
"tree",
".",
"map",
"(",
"(",
"item",
")",
"=>",
"item",
".",
"path",
".",
"match",
"(",
"REGEX_EXTENSION_DIR",
")",
")",
".",
"filter",
"(",
"(",
"match",
")",
"=>",
"match",
"&&",
"!",
"match",
"[",
"1",
"]",
".",
"endsWith",
"(",
"'impl'",
")",
")",
".",
"map",
"(",
"(",
"match",
")",
"=>",
"[",
"match",
"[",
"1",
"]",
",",
"match",
"[",
"2",
"]",
"]",
")",
";",
"const",
"versionMap",
"=",
"{",
"}",
";",
"pairs",
".",
"forEach",
"(",
"(",
"pair",
")",
"=>",
"{",
"if",
"(",
"!",
"versionMap",
"[",
"pair",
"[",
"0",
"]",
"]",
"||",
"versionMap",
"[",
"pair",
"[",
"0",
"]",
"]",
"<",
"pair",
"[",
"1",
"]",
")",
"{",
"versionMap",
"[",
"pair",
"[",
"0",
"]",
"]",
"=",
"pair",
"[",
"1",
"]",
";",
"}",
"}",
")",
";",
"writeComponentsMap",
"(",
"COMPONENTS_MAP_PATH",
",",
"versionMap",
")",
";",
"}"
]
| Create a map from component to version number, based on GitHub directory
structure. | [
"Create",
"a",
"map",
"from",
"component",
"to",
"version",
"number",
"based",
"on",
"GitHub",
"directory",
"structure",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L206-L219 |
47,770 | garanj/amphtml-autoscript | index.js | writeComponentsMap | function writeComponentsMap(path, componentsMap) {
return new Promise((resolve, reject) => {
const data = JSON.stringify(componentsMap);
fs.writeFile(path, data, (err) => {
if (err) {
return reject(err);
}
resolve(data.length);
});
});
} | javascript | function writeComponentsMap(path, componentsMap) {
return new Promise((resolve, reject) => {
const data = JSON.stringify(componentsMap);
fs.writeFile(path, data, (err) => {
if (err) {
return reject(err);
}
resolve(data.length);
});
});
} | [
"function",
"writeComponentsMap",
"(",
"path",
",",
"componentsMap",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"data",
"=",
"JSON",
".",
"stringify",
"(",
"componentsMap",
")",
";",
"fs",
".",
"writeFile",
"(",
"path",
",",
"data",
",",
"(",
"err",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"resolve",
"(",
"data",
".",
"length",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Writes a component map to the file system.
@param {string} path The path to the file to write to.
@param {Object} componentsMap The map of components to versions.
@return {number} The length of data written. | [
"Writes",
"a",
"component",
"map",
"to",
"the",
"file",
"system",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L228-L238 |
47,771 | garanj/amphtml-autoscript | index.js | readComponentsMap | async function readComponentsMap(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, (err, data) => {
if (err) {
return resolve({});
}
resolve(JSON.parse(data));
});
});
} | javascript | async function readComponentsMap(path) {
return new Promise((resolve, reject) => {
fs.readFile(path, (err, data) => {
if (err) {
return resolve({});
}
resolve(JSON.parse(data));
});
});
} | [
"async",
"function",
"readComponentsMap",
"(",
"path",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"fs",
".",
"readFile",
"(",
"path",
",",
"(",
"err",
",",
"data",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"resolve",
"(",
"{",
"}",
")",
";",
"}",
"resolve",
"(",
"JSON",
".",
"parse",
"(",
"data",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| Reads a component map from the file system.
@param {string} path The path to the file to write to.
@return {Object} The map of components to versions. | [
"Reads",
"a",
"component",
"map",
"from",
"the",
"file",
"system",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L246-L255 |
47,772 | garanj/amphtml-autoscript | index.js | createAmpCustomElementTag | function createAmpCustomElementTag(tagName, version) {
const scriptType = AMP_SCRIPT_TYPE_MAP[tagName] || 'custom-element';
return `<script async ${scriptType}="${tagName}" ` +
`src="https://cdn.ampproject.org/v0/${tagName}-${version}.js"></script>`;
} | javascript | function createAmpCustomElementTag(tagName, version) {
const scriptType = AMP_SCRIPT_TYPE_MAP[tagName] || 'custom-element';
return `<script async ${scriptType}="${tagName}" ` +
`src="https://cdn.ampproject.org/v0/${tagName}-${version}.js"></script>`;
} | [
"function",
"createAmpCustomElementTag",
"(",
"tagName",
",",
"version",
")",
"{",
"const",
"scriptType",
"=",
"AMP_SCRIPT_TYPE_MAP",
"[",
"tagName",
"]",
"||",
"'custom-element'",
";",
"return",
"`",
"${",
"scriptType",
"}",
"${",
"tagName",
"}",
"`",
"+",
"`",
"${",
"tagName",
"}",
"${",
"version",
"}",
"`",
";",
"}"
]
| Builds a script tag for a custom element.
@param {string} tagName The custom element to include.
@param {number} version The version number to include.
@return {string} The <script> tag. | [
"Builds",
"a",
"script",
"tag",
"for",
"a",
"custom",
"element",
"."
]
| 7361a39c9d47406e04bbc4077477fe1f84bf5e7a | https://github.com/garanj/amphtml-autoscript/blob/7361a39c9d47406e04bbc4077477fe1f84bf5e7a/index.js#L274-L278 |
47,773 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/document.js | function( cssFileUrl )
{
if ( this.$.createStyleSheet )
this.$.createStyleSheet( cssFileUrl );
else
{
var link = new CKEDITOR.dom.element( 'link' );
link.setAttributes(
{
rel :'stylesheet',
type : 'text/css',
href : cssFileUrl
});
this.getHead().append( link );
}
} | javascript | function( cssFileUrl )
{
if ( this.$.createStyleSheet )
this.$.createStyleSheet( cssFileUrl );
else
{
var link = new CKEDITOR.dom.element( 'link' );
link.setAttributes(
{
rel :'stylesheet',
type : 'text/css',
href : cssFileUrl
});
this.getHead().append( link );
}
} | [
"function",
"(",
"cssFileUrl",
")",
"{",
"if",
"(",
"this",
".",
"$",
".",
"createStyleSheet",
")",
"this",
".",
"$",
".",
"createStyleSheet",
"(",
"cssFileUrl",
")",
";",
"else",
"{",
"var",
"link",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"element",
"(",
"'link'",
")",
";",
"link",
".",
"setAttributes",
"(",
"{",
"rel",
":",
"'stylesheet'",
",",
"type",
":",
"'text/css'",
",",
"href",
":",
"cssFileUrl",
"}",
")",
";",
"this",
".",
"getHead",
"(",
")",
".",
"append",
"(",
"link",
")",
";",
"}",
"}"
]
| Appends a CSS file to the document.
@param {String} cssFileUrl The CSS file URL.
@example
<b>CKEDITOR.document.appendStyleSheet( '/mystyles.css' )</b>; | [
"Appends",
"a",
"CSS",
"file",
"to",
"the",
"document",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/document.js#L37-L53 |
|
47,774 | saggiyogesh/nodeportal | public/ckeditor/_source/core/dom/document.js | function()
{
var head = this.$.getElementsByTagName( 'head' )[0];
if ( !head )
head = this.getDocumentElement().append( new CKEDITOR.dom.element( 'head' ), true );
else
head = new CKEDITOR.dom.element( head );
return (
this.getHead = function()
{
return head;
})();
} | javascript | function()
{
var head = this.$.getElementsByTagName( 'head' )[0];
if ( !head )
head = this.getDocumentElement().append( new CKEDITOR.dom.element( 'head' ), true );
else
head = new CKEDITOR.dom.element( head );
return (
this.getHead = function()
{
return head;
})();
} | [
"function",
"(",
")",
"{",
"var",
"head",
"=",
"this",
".",
"$",
".",
"getElementsByTagName",
"(",
"'head'",
")",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"head",
")",
"head",
"=",
"this",
".",
"getDocumentElement",
"(",
")",
".",
"append",
"(",
"new",
"CKEDITOR",
".",
"dom",
".",
"element",
"(",
"'head'",
")",
",",
"true",
")",
";",
"else",
"head",
"=",
"new",
"CKEDITOR",
".",
"dom",
".",
"element",
"(",
"head",
")",
";",
"return",
"(",
"this",
".",
"getHead",
"=",
"function",
"(",
")",
"{",
"return",
"head",
";",
"}",
")",
"(",
")",
";",
"}"
]
| Gets the <head> element for this document.
@returns {CKEDITOR.dom.element} The <head> element.
@example
var element = <b>CKEDITOR.document.getHead()</b>;
alert( element.getName() ); // "head" | [
"Gets",
"the",
"<",
";",
"head>",
";",
"element",
"for",
"this",
"document",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/dom/document.js#L165-L178 |
|
47,775 | saggiyogesh/nodeportal | lib/permissions/PermissionDefinitionProcessor.js | isActionsExistsInPermissionActions | function isActionsExistsInPermissionActions(allActions, schemaActions) {
return utils.contains(allActions.sort().join(), schemaActions.sort().join());
} | javascript | function isActionsExistsInPermissionActions(allActions, schemaActions) {
return utils.contains(allActions.sort().join(), schemaActions.sort().join());
} | [
"function",
"isActionsExistsInPermissionActions",
"(",
"allActions",
",",
"schemaActions",
")",
"{",
"return",
"utils",
".",
"contains",
"(",
"allActions",
".",
"sort",
"(",
")",
".",
"join",
"(",
")",
",",
"schemaActions",
".",
"sort",
"(",
")",
".",
"join",
"(",
")",
")",
";",
"}"
]
| Returns true if schemaActions exists in allActions
@param allActions {Array} all actions in defined in permission definition file
@param schemaActions {Array} actions allowed in particular schema entry in definition file | [
"Returns",
"true",
"if",
"schemaActions",
"exists",
"in",
"allActions"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/permissions/PermissionDefinitionProcessor.js#L35-L37 |
47,776 | saggiyogesh/nodeportal | lib/permissions/PermissionDefinitionProcessor.js | insertSettingsPluginsPermission | function insertSettingsPluginsPermission(app, next) {
var pluginsHome = utils.getRootPath() + "/plugins",
settingsPlugins = Object.keys(plugins.getSettingsPlugins());
var dbActionInstance = DBActions.getSimpleInstance(app, "SchemaPermissions");
var pluginInstanceHandler = require(utils.getLibPath() + "/PluginInstanceHandler"),
Roles = require(utils.getLibPath() + "/permissions/Roles"),
guestRoleId = Roles.getGuestRole().roleId,
userRoleId = Roles.getUserRole().roleId;
var mapFunction = function (pluginId, next) {
var permissions = pluginInstanceHandler.Permissions;
var model = {
actionsValue: permissions.actionsValue,
permissionSchemaKey: utils.getSettingsPluginPermissionSchemaKey(pluginId)
};
var rolePermissions = _.clone(permissions.rolePermissions);
//guest has nothing to do with settings plugin as its a non logged in user
delete rolePermissions[guestRoleId];
//user role only have permission to show user manage plugin, to modify his profile
if(pluginId != "userManage"){
rolePermissions[userRoleId] = [];
}
model.rolePermissions = rolePermissions;
Cache.store(model);
dbActionInstance.save(model, next);
};
async.eachSeries(settingsPlugins, mapFunction, function (err, results) {
next(err, true);
});
} | javascript | function insertSettingsPluginsPermission(app, next) {
var pluginsHome = utils.getRootPath() + "/plugins",
settingsPlugins = Object.keys(plugins.getSettingsPlugins());
var dbActionInstance = DBActions.getSimpleInstance(app, "SchemaPermissions");
var pluginInstanceHandler = require(utils.getLibPath() + "/PluginInstanceHandler"),
Roles = require(utils.getLibPath() + "/permissions/Roles"),
guestRoleId = Roles.getGuestRole().roleId,
userRoleId = Roles.getUserRole().roleId;
var mapFunction = function (pluginId, next) {
var permissions = pluginInstanceHandler.Permissions;
var model = {
actionsValue: permissions.actionsValue,
permissionSchemaKey: utils.getSettingsPluginPermissionSchemaKey(pluginId)
};
var rolePermissions = _.clone(permissions.rolePermissions);
//guest has nothing to do with settings plugin as its a non logged in user
delete rolePermissions[guestRoleId];
//user role only have permission to show user manage plugin, to modify his profile
if(pluginId != "userManage"){
rolePermissions[userRoleId] = [];
}
model.rolePermissions = rolePermissions;
Cache.store(model);
dbActionInstance.save(model, next);
};
async.eachSeries(settingsPlugins, mapFunction, function (err, results) {
next(err, true);
});
} | [
"function",
"insertSettingsPluginsPermission",
"(",
"app",
",",
"next",
")",
"{",
"var",
"pluginsHome",
"=",
"utils",
".",
"getRootPath",
"(",
")",
"+",
"\"/plugins\"",
",",
"settingsPlugins",
"=",
"Object",
".",
"keys",
"(",
"plugins",
".",
"getSettingsPlugins",
"(",
")",
")",
";",
"var",
"dbActionInstance",
"=",
"DBActions",
".",
"getSimpleInstance",
"(",
"app",
",",
"\"SchemaPermissions\"",
")",
";",
"var",
"pluginInstanceHandler",
"=",
"require",
"(",
"utils",
".",
"getLibPath",
"(",
")",
"+",
"\"/PluginInstanceHandler\"",
")",
",",
"Roles",
"=",
"require",
"(",
"utils",
".",
"getLibPath",
"(",
")",
"+",
"\"/permissions/Roles\"",
")",
",",
"guestRoleId",
"=",
"Roles",
".",
"getGuestRole",
"(",
")",
".",
"roleId",
",",
"userRoleId",
"=",
"Roles",
".",
"getUserRole",
"(",
")",
".",
"roleId",
";",
"var",
"mapFunction",
"=",
"function",
"(",
"pluginId",
",",
"next",
")",
"{",
"var",
"permissions",
"=",
"pluginInstanceHandler",
".",
"Permissions",
";",
"var",
"model",
"=",
"{",
"actionsValue",
":",
"permissions",
".",
"actionsValue",
",",
"permissionSchemaKey",
":",
"utils",
".",
"getSettingsPluginPermissionSchemaKey",
"(",
"pluginId",
")",
"}",
";",
"var",
"rolePermissions",
"=",
"_",
".",
"clone",
"(",
"permissions",
".",
"rolePermissions",
")",
";",
"//guest has nothing to do with settings plugin as its a non logged in user",
"delete",
"rolePermissions",
"[",
"guestRoleId",
"]",
";",
"//user role only have permission to show user manage plugin, to modify his profile",
"if",
"(",
"pluginId",
"!=",
"\"userManage\"",
")",
"{",
"rolePermissions",
"[",
"userRoleId",
"]",
"=",
"[",
"]",
";",
"}",
"model",
".",
"rolePermissions",
"=",
"rolePermissions",
";",
"Cache",
".",
"store",
"(",
"model",
")",
";",
"dbActionInstance",
".",
"save",
"(",
"model",
",",
"next",
")",
";",
"}",
";",
"async",
".",
"eachSeries",
"(",
"settingsPlugins",
",",
"mapFunction",
",",
"function",
"(",
"err",
",",
"results",
")",
"{",
"next",
"(",
"err",
",",
"true",
")",
";",
"}",
")",
";",
"}"
]
| Function used to insert settings plugin schema permissions
@param app
@param next | [
"Function",
"used",
"to",
"insert",
"settings",
"plugin",
"schema",
"permissions"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/permissions/PermissionDefinitionProcessor.js#L110-L144 |
47,777 | saggiyogesh/nodeportal | public/ckeditor/_source/core/editor.js | function()
{
this.fire( 'beforeGetData' );
var eventData = this._.data;
if ( typeof eventData != 'string' )
{
var element = this.element;
if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
else
eventData = '';
}
eventData = { dataValue : eventData };
// Fire "getData" so data manipulation may happen.
this.fire( 'getData', eventData );
return eventData.dataValue;
} | javascript | function()
{
this.fire( 'beforeGetData' );
var eventData = this._.data;
if ( typeof eventData != 'string' )
{
var element = this.element;
if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
eventData = element.is( 'textarea' ) ? element.getValue() : element.getHtml();
else
eventData = '';
}
eventData = { dataValue : eventData };
// Fire "getData" so data manipulation may happen.
this.fire( 'getData', eventData );
return eventData.dataValue;
} | [
"function",
"(",
")",
"{",
"this",
".",
"fire",
"(",
"'beforeGetData'",
")",
";",
"var",
"eventData",
"=",
"this",
".",
"_",
".",
"data",
";",
"if",
"(",
"typeof",
"eventData",
"!=",
"'string'",
")",
"{",
"var",
"element",
"=",
"this",
".",
"element",
";",
"if",
"(",
"element",
"&&",
"this",
".",
"elementMode",
"==",
"CKEDITOR",
".",
"ELEMENT_MODE_REPLACE",
")",
"eventData",
"=",
"element",
".",
"is",
"(",
"'textarea'",
")",
"?",
"element",
".",
"getValue",
"(",
")",
":",
"element",
".",
"getHtml",
"(",
")",
";",
"else",
"eventData",
"=",
"''",
";",
"}",
"eventData",
"=",
"{",
"dataValue",
":",
"eventData",
"}",
";",
"// Fire \"getData\" so data manipulation may happen.\r",
"this",
".",
"fire",
"(",
"'getData'",
",",
"eventData",
")",
";",
"return",
"eventData",
".",
"dataValue",
";",
"}"
]
| Gets the editor data. The data will be in raw format. It is the same
data that is posted by the editor.
@type String
@returns (String) The editor data.
@example
if ( CKEDITOR.instances.editor1.<strong>getData()</strong> == '' )
alert( 'There is no data available' ); | [
"Gets",
"the",
"editor",
"data",
".",
"The",
"data",
"will",
"be",
"in",
"raw",
"format",
".",
"It",
"is",
"the",
"same",
"data",
"that",
"is",
"posted",
"by",
"the",
"editor",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/editor.js#L638-L659 |
|
47,778 | saggiyogesh/nodeportal | public/ckeditor/_source/core/htmlparser/comment.js | function( writer, filter )
{
var comment = this.value;
if ( filter )
{
if ( !( comment = filter.onComment( comment, this ) ) )
return;
if ( typeof comment != 'string' )
{
comment.parent = this.parent;
comment.writeHtml( writer, filter );
return;
}
}
writer.comment( comment );
} | javascript | function( writer, filter )
{
var comment = this.value;
if ( filter )
{
if ( !( comment = filter.onComment( comment, this ) ) )
return;
if ( typeof comment != 'string' )
{
comment.parent = this.parent;
comment.writeHtml( writer, filter );
return;
}
}
writer.comment( comment );
} | [
"function",
"(",
"writer",
",",
"filter",
")",
"{",
"var",
"comment",
"=",
"this",
".",
"value",
";",
"if",
"(",
"filter",
")",
"{",
"if",
"(",
"!",
"(",
"comment",
"=",
"filter",
".",
"onComment",
"(",
"comment",
",",
"this",
")",
")",
")",
"return",
";",
"if",
"(",
"typeof",
"comment",
"!=",
"'string'",
")",
"{",
"comment",
".",
"parent",
"=",
"this",
".",
"parent",
";",
"comment",
".",
"writeHtml",
"(",
"writer",
",",
"filter",
")",
";",
"return",
";",
"}",
"}",
"writer",
".",
"comment",
"(",
"comment",
")",
";",
"}"
]
| Writes the HTML representation of this comment to a CKEDITOR.htmlWriter.
@param {CKEDITOR.htmlWriter} writer The writer to which write the HTML.
@example | [
"Writes",
"the",
"HTML",
"representation",
"of",
"this",
"comment",
"to",
"a",
"CKEDITOR",
".",
"htmlWriter",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/htmlparser/comment.js#L41-L59 |
|
47,779 | slideme/rorschach | lib/RetryPolicy.js | RetryPolicy | function RetryPolicy(options) {
options = options || {};
if (typeof options.maxAttempts === 'number') {
this.maxAttempts = options.maxAttempts;
}
else {
this.maxAttempts = RetryPolicy.DEFAULT_MAX_ATTEMPTS;
}
if (typeof options.codes === 'function') {
this.isRetryable = options.codes;
}
else {
this.codes = options.codes || RetryPolicy.DEFAULT_RETRYABLE_ERRORS;
}
} | javascript | function RetryPolicy(options) {
options = options || {};
if (typeof options.maxAttempts === 'number') {
this.maxAttempts = options.maxAttempts;
}
else {
this.maxAttempts = RetryPolicy.DEFAULT_MAX_ATTEMPTS;
}
if (typeof options.codes === 'function') {
this.isRetryable = options.codes;
}
else {
this.codes = options.codes || RetryPolicy.DEFAULT_RETRYABLE_ERRORS;
}
} | [
"function",
"RetryPolicy",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"if",
"(",
"typeof",
"options",
".",
"maxAttempts",
"===",
"'number'",
")",
"{",
"this",
".",
"maxAttempts",
"=",
"options",
".",
"maxAttempts",
";",
"}",
"else",
"{",
"this",
".",
"maxAttempts",
"=",
"RetryPolicy",
".",
"DEFAULT_MAX_ATTEMPTS",
";",
"}",
"if",
"(",
"typeof",
"options",
".",
"codes",
"===",
"'function'",
")",
"{",
"this",
".",
"isRetryable",
"=",
"options",
".",
"codes",
";",
"}",
"else",
"{",
"this",
".",
"codes",
"=",
"options",
".",
"codes",
"||",
"RetryPolicy",
".",
"DEFAULT_RETRYABLE_ERRORS",
";",
"}",
"}"
]
| Retry policy controls behavior of Rorschach in case of errors.
@constructor
@param {Object} [options] Options:
@param {Number} options.maxAttempts Max number of attempts
@param {Array.<String>|Function} options.codes Error codes or error validation function | [
"Retry",
"policy",
"controls",
"behavior",
"of",
"Rorschach",
"in",
"case",
"of",
"errors",
"."
]
| 899339baf31682f8a62b2960cdd26fbb58a9e3a1 | https://github.com/slideme/rorschach/blob/899339baf31682f8a62b2960cdd26fbb58a9e3a1/lib/RetryPolicy.js#L22-L38 |
47,780 | JoTrdl/grunt-dock | tasks/dock.js | function(command, arg) {
if (!arg) {
arg = 'default';
}
if (!commands[command]) {
grunt.fail.fatal('Command [' + command + '] not found.');
}
// Check arg
if (typeof (commands[command]) !== 'function') {
if (!commands[command][arg]) {
grunt.fail.fatal('Argument [' + arg + '] for [' + command
+ '] not found.');
}
}
var func = (arg) ? commands[command][arg] : commands[command];
if (!func) {
func = commands[command]; // fallback to the main function
}
var options = this.options();
var docker = (options.docker) ? new Docker(options.docker) : null;
var done = this.async();
var callback = function(e) {
if (e) {
grunt.fail.warn(e);
}
done();
};
func.apply(this, [ grunt, docker, options, callback, arg ]);
} | javascript | function(command, arg) {
if (!arg) {
arg = 'default';
}
if (!commands[command]) {
grunt.fail.fatal('Command [' + command + '] not found.');
}
// Check arg
if (typeof (commands[command]) !== 'function') {
if (!commands[command][arg]) {
grunt.fail.fatal('Argument [' + arg + '] for [' + command
+ '] not found.');
}
}
var func = (arg) ? commands[command][arg] : commands[command];
if (!func) {
func = commands[command]; // fallback to the main function
}
var options = this.options();
var docker = (options.docker) ? new Docker(options.docker) : null;
var done = this.async();
var callback = function(e) {
if (e) {
grunt.fail.warn(e);
}
done();
};
func.apply(this, [ grunt, docker, options, callback, arg ]);
} | [
"function",
"(",
"command",
",",
"arg",
")",
"{",
"if",
"(",
"!",
"arg",
")",
"{",
"arg",
"=",
"'default'",
";",
"}",
"if",
"(",
"!",
"commands",
"[",
"command",
"]",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'Command ['",
"+",
"command",
"+",
"'] not found.'",
")",
";",
"}",
"// Check arg",
"if",
"(",
"typeof",
"(",
"commands",
"[",
"command",
"]",
")",
"!==",
"'function'",
")",
"{",
"if",
"(",
"!",
"commands",
"[",
"command",
"]",
"[",
"arg",
"]",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"'Argument ['",
"+",
"arg",
"+",
"'] for ['",
"+",
"command",
"+",
"'] not found.'",
")",
";",
"}",
"}",
"var",
"func",
"=",
"(",
"arg",
")",
"?",
"commands",
"[",
"command",
"]",
"[",
"arg",
"]",
":",
"commands",
"[",
"command",
"]",
";",
"if",
"(",
"!",
"func",
")",
"{",
"func",
"=",
"commands",
"[",
"command",
"]",
";",
"// fallback to the main function",
"}",
"var",
"options",
"=",
"this",
".",
"options",
"(",
")",
";",
"var",
"docker",
"=",
"(",
"options",
".",
"docker",
")",
"?",
"new",
"Docker",
"(",
"options",
".",
"docker",
")",
":",
"null",
";",
"var",
"done",
"=",
"this",
".",
"async",
"(",
")",
";",
"var",
"callback",
"=",
"function",
"(",
"e",
")",
"{",
"if",
"(",
"e",
")",
"{",
"grunt",
".",
"fail",
".",
"warn",
"(",
"e",
")",
";",
"}",
"done",
"(",
")",
";",
"}",
";",
"func",
".",
"apply",
"(",
"this",
",",
"[",
"grunt",
",",
"docker",
",",
"options",
",",
"callback",
",",
"arg",
"]",
")",
";",
"}"
]
| Process the given command with arg. | [
"Process",
"the",
"given",
"command",
"with",
"arg",
"."
]
| ea731dd4679c88cb7c6ae812affd1214c7eb43a9 | https://github.com/JoTrdl/grunt-dock/blob/ea731dd4679c88cb7c6ae812affd1214c7eb43a9/tasks/dock.js#L23-L57 |
|
47,781 | levilindsey/physx | src/integrator/src/rk4-integrator.js | _calculateDerivative | function _calculateDerivative(out, state, job, t, dt, d) {
vec3.scaleAndAdd(state.position, state.position, d.velocity, dt);
vec3.scaleAndAdd(state.momentum, state.momentum, d.force, dt);
_geometry.scaleAndAddQuat(state.orientation, state.orientation, d.spin, dt);
vec3.scaleAndAdd(state.angularMomentum, state.angularMomentum, d.torque, dt);
state.updateDependentFields();
out.velocity = state.velocity;
out.spin = state.spin;
vec3.set(out.force, 0, 0, 0);
vec3.set(out.torque, 0, 0, 0);
_forceApplierOutput.force = out.force;
_forceApplierOutput.torque = out.torque;
_forceApplierInput.state = state;
_forceApplierInput.t = t + dt;
_forceApplierInput.dt = dt;
job.applyForces(_forceApplierOutput, _forceApplierInput);
} | javascript | function _calculateDerivative(out, state, job, t, dt, d) {
vec3.scaleAndAdd(state.position, state.position, d.velocity, dt);
vec3.scaleAndAdd(state.momentum, state.momentum, d.force, dt);
_geometry.scaleAndAddQuat(state.orientation, state.orientation, d.spin, dt);
vec3.scaleAndAdd(state.angularMomentum, state.angularMomentum, d.torque, dt);
state.updateDependentFields();
out.velocity = state.velocity;
out.spin = state.spin;
vec3.set(out.force, 0, 0, 0);
vec3.set(out.torque, 0, 0, 0);
_forceApplierOutput.force = out.force;
_forceApplierOutput.torque = out.torque;
_forceApplierInput.state = state;
_forceApplierInput.t = t + dt;
_forceApplierInput.dt = dt;
job.applyForces(_forceApplierOutput, _forceApplierInput);
} | [
"function",
"_calculateDerivative",
"(",
"out",
",",
"state",
",",
"job",
",",
"t",
",",
"dt",
",",
"d",
")",
"{",
"vec3",
".",
"scaleAndAdd",
"(",
"state",
".",
"position",
",",
"state",
".",
"position",
",",
"d",
".",
"velocity",
",",
"dt",
")",
";",
"vec3",
".",
"scaleAndAdd",
"(",
"state",
".",
"momentum",
",",
"state",
".",
"momentum",
",",
"d",
".",
"force",
",",
"dt",
")",
";",
"_geometry",
".",
"scaleAndAddQuat",
"(",
"state",
".",
"orientation",
",",
"state",
".",
"orientation",
",",
"d",
".",
"spin",
",",
"dt",
")",
";",
"vec3",
".",
"scaleAndAdd",
"(",
"state",
".",
"angularMomentum",
",",
"state",
".",
"angularMomentum",
",",
"d",
".",
"torque",
",",
"dt",
")",
";",
"state",
".",
"updateDependentFields",
"(",
")",
";",
"out",
".",
"velocity",
"=",
"state",
".",
"velocity",
";",
"out",
".",
"spin",
"=",
"state",
".",
"spin",
";",
"vec3",
".",
"set",
"(",
"out",
".",
"force",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"vec3",
".",
"set",
"(",
"out",
".",
"torque",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"_forceApplierOutput",
".",
"force",
"=",
"out",
".",
"force",
";",
"_forceApplierOutput",
".",
"torque",
"=",
"out",
".",
"torque",
";",
"_forceApplierInput",
".",
"state",
"=",
"state",
";",
"_forceApplierInput",
".",
"t",
"=",
"t",
"+",
"dt",
";",
"_forceApplierInput",
".",
"dt",
"=",
"dt",
";",
"job",
".",
"applyForces",
"(",
"_forceApplierOutput",
",",
"_forceApplierInput",
")",
";",
"}"
]
| Calculate the derivative from the given state with the given time step.
@param {PhysicsDerivative} out
@param {PhysicsState} state
@param {PhysicsJob} job
@param {number} t
@param {number} dt
@param {PhysicsDerivative} d
@private | [
"Calculate",
"the",
"derivative",
"from",
"the",
"given",
"state",
"with",
"the",
"given",
"time",
"step",
"."
]
| 62df9f6968082ed34aa784a23f3db6c8feca6f3a | https://github.com/levilindsey/physx/blob/62df9f6968082ed34aa784a23f3db6c8feca6f3a/src/integrator/src/rk4-integrator.js#L83-L103 |
47,782 | backbeam/backbeamjs | cache.js | Cache | function Cache(maxSize, debug, storage) {
this.maxSize_ = maxSize || -1;
this.debug_ = debug || false;
this.storage_ = storage || new Cache.BasicCacheStorage();
this.fillFactor_ = .75;
this.stats_ = {};
this.stats_['hits'] = 0;
this.stats_['misses'] = 0;
this.log_('Initialized cache with size ' + maxSize);
} | javascript | function Cache(maxSize, debug, storage) {
this.maxSize_ = maxSize || -1;
this.debug_ = debug || false;
this.storage_ = storage || new Cache.BasicCacheStorage();
this.fillFactor_ = .75;
this.stats_ = {};
this.stats_['hits'] = 0;
this.stats_['misses'] = 0;
this.log_('Initialized cache with size ' + maxSize);
} | [
"function",
"Cache",
"(",
"maxSize",
",",
"debug",
",",
"storage",
")",
"{",
"this",
".",
"maxSize_",
"=",
"maxSize",
"||",
"-",
"1",
";",
"this",
".",
"debug_",
"=",
"debug",
"||",
"false",
";",
"this",
".",
"storage_",
"=",
"storage",
"||",
"new",
"Cache",
".",
"BasicCacheStorage",
"(",
")",
";",
"this",
".",
"fillFactor_",
"=",
".75",
";",
"this",
".",
"stats_",
"=",
"{",
"}",
";",
"this",
".",
"stats_",
"[",
"'hits'",
"]",
"=",
"0",
";",
"this",
".",
"stats_",
"[",
"'misses'",
"]",
"=",
"0",
";",
"this",
".",
"log_",
"(",
"'Initialized cache with size '",
"+",
"maxSize",
")",
";",
"}"
]
| Creates a new Cache object.
@param {number} maxSize The maximum size of the cache (or -1 for no max).
@param {boolean} debug Whether to log events to the console.log.
@constructor | [
"Creates",
"a",
"new",
"Cache",
"object",
"."
]
| 3d664a2edcb680da076a0f3b3afa717290f6c215 | https://github.com/backbeam/backbeamjs/blob/3d664a2edcb680da076a0f3b3afa717290f6c215/cache.js#L36-L47 |
47,783 | enquirer/prompt-autocompletion | index.js | Prompt | function Prompt() {
BasePrompt.apply(this, arguments);
if (typeof this.question.source !== 'function') {
throw new TypeError('expected source to be defined');
}
this.currentChoices = [];
this.firstRender = true;
this.selected = 0;
// Make sure no default is set (so it won't be printed)
this.question.default = undefined;
this.paginator = new Paginator();
} | javascript | function Prompt() {
BasePrompt.apply(this, arguments);
if (typeof this.question.source !== 'function') {
throw new TypeError('expected source to be defined');
}
this.currentChoices = [];
this.firstRender = true;
this.selected = 0;
// Make sure no default is set (so it won't be printed)
this.question.default = undefined;
this.paginator = new Paginator();
} | [
"function",
"Prompt",
"(",
")",
"{",
"BasePrompt",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"if",
"(",
"typeof",
"this",
".",
"question",
".",
"source",
"!==",
"'function'",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'expected source to be defined'",
")",
";",
"}",
"this",
".",
"currentChoices",
"=",
"[",
"]",
";",
"this",
".",
"firstRender",
"=",
"true",
";",
"this",
".",
"selected",
"=",
"0",
";",
"// Make sure no default is set (so it won't be printed)",
"this",
".",
"question",
".",
"default",
"=",
"undefined",
";",
"this",
".",
"paginator",
"=",
"new",
"Paginator",
"(",
")",
";",
"}"
]
| Create a new autocomplete `Prompt` | [
"Create",
"a",
"new",
"autocomplete",
"Prompt"
]
| ea9daf347b0129e22a235de82bdc71038d34b341 | https://github.com/enquirer/prompt-autocompletion/blob/ea9daf347b0129e22a235de82bdc71038d34b341/index.js#L21-L34 |
47,784 | UsabilityDynamics/node-wordpress-client | examples/create.js | insertCallback | function insertCallback(error, data) {
console.log(require('util').inspect(error ? error.message : data, { showHidden: true, colors: true, depth: 2 }));
} | javascript | function insertCallback(error, data) {
console.log(require('util').inspect(error ? error.message : data, { showHidden: true, colors: true, depth: 2 }));
} | [
"function",
"insertCallback",
"(",
"error",
",",
"data",
")",
"{",
"console",
".",
"log",
"(",
"require",
"(",
"'util'",
")",
".",
"inspect",
"(",
"error",
"?",
"error",
".",
"message",
":",
"data",
",",
"{",
"showHidden",
":",
"true",
",",
"colors",
":",
"true",
",",
"depth",
":",
"2",
"}",
")",
")",
";",
"}"
]
| Insertion Callback.
@param error
@param data | [
"Insertion",
"Callback",
"."
]
| 2b47a7c5cadd3d8f2cfd255f997f36af14a5d843 | https://github.com/UsabilityDynamics/node-wordpress-client/blob/2b47a7c5cadd3d8f2cfd255f997f36af14a5d843/examples/create.js#L13-L15 |
47,785 | JoTrdl/grunt-dock | lib/container.js | function(tag, confImage, callback) {
grunt.log.subhead(actioning[action] + ' image [' + tag + ']');
async.waterfall([
// Step 1: search for a running container with the same image
function(cb) {
docker.listContainers({
all : 1,
// filters: (action !== 'unpause') ? '{"status":["running"]}' : null
}, function(err, containers) {
if (err) {
return cb(err);
}
var container = null;
for (var c = 0; c < containers.length; c++) {
if (containers[c].Image.indexOf(utils.qualifiedImageName(tag,
options.registry, null)) === 0) {
container = containers[c];
break;
}
}
cb(null, container);
});
},
// Step 2: stop it
function(container, cb) {
if (container) {
grunt.log.writeln("Found a matched container, " + action + " it.");
var dockcontainer = docker.getContainer(container.Id);
var opts = confImage.options && confImage.options[action] || {};
dockcontainer[action](opts, function(e, stream) {
if (stream && stream.readable) {
stream.setEncoding('utf8');
stream.on('error', cb);
stream.on('end', cb);
stream.on('data', grunt.log.write);
} else {
cb(e);
}
});
} else {
grunt.log.writeln("No matched container with this image.");
cb(null);
}
}, ], callback);
} | javascript | function(tag, confImage, callback) {
grunt.log.subhead(actioning[action] + ' image [' + tag + ']');
async.waterfall([
// Step 1: search for a running container with the same image
function(cb) {
docker.listContainers({
all : 1,
// filters: (action !== 'unpause') ? '{"status":["running"]}' : null
}, function(err, containers) {
if (err) {
return cb(err);
}
var container = null;
for (var c = 0; c < containers.length; c++) {
if (containers[c].Image.indexOf(utils.qualifiedImageName(tag,
options.registry, null)) === 0) {
container = containers[c];
break;
}
}
cb(null, container);
});
},
// Step 2: stop it
function(container, cb) {
if (container) {
grunt.log.writeln("Found a matched container, " + action + " it.");
var dockcontainer = docker.getContainer(container.Id);
var opts = confImage.options && confImage.options[action] || {};
dockcontainer[action](opts, function(e, stream) {
if (stream && stream.readable) {
stream.setEncoding('utf8');
stream.on('error', cb);
stream.on('end', cb);
stream.on('data', grunt.log.write);
} else {
cb(e);
}
});
} else {
grunt.log.writeln("No matched container with this image.");
cb(null);
}
}, ], callback);
} | [
"function",
"(",
"tag",
",",
"confImage",
",",
"callback",
")",
"{",
"grunt",
".",
"log",
".",
"subhead",
"(",
"actioning",
"[",
"action",
"]",
"+",
"' image ['",
"+",
"tag",
"+",
"']'",
")",
";",
"async",
".",
"waterfall",
"(",
"[",
"// Step 1: search for a running container with the same image",
"function",
"(",
"cb",
")",
"{",
"docker",
".",
"listContainers",
"(",
"{",
"all",
":",
"1",
",",
"// filters: (action !== 'unpause') ? '{\"status\":[\"running\"]}' : null",
"}",
",",
"function",
"(",
"err",
",",
"containers",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"var",
"container",
"=",
"null",
";",
"for",
"(",
"var",
"c",
"=",
"0",
";",
"c",
"<",
"containers",
".",
"length",
";",
"c",
"++",
")",
"{",
"if",
"(",
"containers",
"[",
"c",
"]",
".",
"Image",
".",
"indexOf",
"(",
"utils",
".",
"qualifiedImageName",
"(",
"tag",
",",
"options",
".",
"registry",
",",
"null",
")",
")",
"===",
"0",
")",
"{",
"container",
"=",
"containers",
"[",
"c",
"]",
";",
"break",
";",
"}",
"}",
"cb",
"(",
"null",
",",
"container",
")",
";",
"}",
")",
";",
"}",
",",
"// Step 2: stop it",
"function",
"(",
"container",
",",
"cb",
")",
"{",
"if",
"(",
"container",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"Found a matched container, \"",
"+",
"action",
"+",
"\" it.\"",
")",
";",
"var",
"dockcontainer",
"=",
"docker",
".",
"getContainer",
"(",
"container",
".",
"Id",
")",
";",
"var",
"opts",
"=",
"confImage",
".",
"options",
"&&",
"confImage",
".",
"options",
"[",
"action",
"]",
"||",
"{",
"}",
";",
"dockcontainer",
"[",
"action",
"]",
"(",
"opts",
",",
"function",
"(",
"e",
",",
"stream",
")",
"{",
"if",
"(",
"stream",
"&&",
"stream",
".",
"readable",
")",
"{",
"stream",
".",
"setEncoding",
"(",
"'utf8'",
")",
";",
"stream",
".",
"on",
"(",
"'error'",
",",
"cb",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"cb",
")",
";",
"stream",
".",
"on",
"(",
"'data'",
",",
"grunt",
".",
"log",
".",
"write",
")",
";",
"}",
"else",
"{",
"cb",
"(",
"e",
")",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"\"No matched container with this image.\"",
")",
";",
"cb",
"(",
"null",
")",
";",
"}",
"}",
",",
"]",
",",
"callback",
")",
";",
"}"
]
| process 1 container with image tag | [
"process",
"1",
"container",
"with",
"image",
"tag"
]
| ea731dd4679c88cb7c6ae812affd1214c7eb43a9 | https://github.com/JoTrdl/grunt-dock/blob/ea731dd4679c88cb7c6ae812affd1214c7eb43a9/lib/container.js#L159-L215 |
|
47,786 | saggiyogesh/nodeportal | lib/Renderer/PluginRender.js | PluginRender | function PluginRender(pluginInstance, rendererInstance) {
this._view = "index.jade";
this._locals = {};
var ns = pluginInstance.pluginNamespace, obj = PluginHelper.getPluginIdAndIId(ns), pluginId = obj.pluginId,
req = PluginHelper.cloneRequest(rendererInstance.req, pluginId), res = rendererInstance.res;
Object.defineProperties(req.params, {
plugin: {
value: obj.pluginId
},
iId: {
value: obj.iId
},
namespace: {
value: ns
}
});
Object.defineProperties(req, {
pluginRender: {
value: this
}
});
Object.defineProperties(this, {
req: {
value: req
},
res: {
value: res
},
pluginId: {
value: req.params.plugin
},
iId: {
value: req.params.iId
},
plugin: {
value: Plugins.get(req.params.plugin)
},
namespace: {
value: req.params.namespace
},
pluginInstance: {
value: pluginInstance
},
theme: {
value: rendererInstance.theme
},
page: {
value: rendererInstance.page
},
pluginPermissionValidator: {
value: rendererInstance.pluginPermissionValidator
},
pagePermissionValidator: {
value: rendererInstance.pagePermissionValidator
},
pluginInstanceDBAction: {
value: rendererInstance.pluginInstanceDBAction
},
isExclusive: {
value: rendererInstance.isExclusive
}
});
} | javascript | function PluginRender(pluginInstance, rendererInstance) {
this._view = "index.jade";
this._locals = {};
var ns = pluginInstance.pluginNamespace, obj = PluginHelper.getPluginIdAndIId(ns), pluginId = obj.pluginId,
req = PluginHelper.cloneRequest(rendererInstance.req, pluginId), res = rendererInstance.res;
Object.defineProperties(req.params, {
plugin: {
value: obj.pluginId
},
iId: {
value: obj.iId
},
namespace: {
value: ns
}
});
Object.defineProperties(req, {
pluginRender: {
value: this
}
});
Object.defineProperties(this, {
req: {
value: req
},
res: {
value: res
},
pluginId: {
value: req.params.plugin
},
iId: {
value: req.params.iId
},
plugin: {
value: Plugins.get(req.params.plugin)
},
namespace: {
value: req.params.namespace
},
pluginInstance: {
value: pluginInstance
},
theme: {
value: rendererInstance.theme
},
page: {
value: rendererInstance.page
},
pluginPermissionValidator: {
value: rendererInstance.pluginPermissionValidator
},
pagePermissionValidator: {
value: rendererInstance.pagePermissionValidator
},
pluginInstanceDBAction: {
value: rendererInstance.pluginInstanceDBAction
},
isExclusive: {
value: rendererInstance.isExclusive
}
});
} | [
"function",
"PluginRender",
"(",
"pluginInstance",
",",
"rendererInstance",
")",
"{",
"this",
".",
"_view",
"=",
"\"index.jade\"",
";",
"this",
".",
"_locals",
"=",
"{",
"}",
";",
"var",
"ns",
"=",
"pluginInstance",
".",
"pluginNamespace",
",",
"obj",
"=",
"PluginHelper",
".",
"getPluginIdAndIId",
"(",
"ns",
")",
",",
"pluginId",
"=",
"obj",
".",
"pluginId",
",",
"req",
"=",
"PluginHelper",
".",
"cloneRequest",
"(",
"rendererInstance",
".",
"req",
",",
"pluginId",
")",
",",
"res",
"=",
"rendererInstance",
".",
"res",
";",
"Object",
".",
"defineProperties",
"(",
"req",
".",
"params",
",",
"{",
"plugin",
":",
"{",
"value",
":",
"obj",
".",
"pluginId",
"}",
",",
"iId",
":",
"{",
"value",
":",
"obj",
".",
"iId",
"}",
",",
"namespace",
":",
"{",
"value",
":",
"ns",
"}",
"}",
")",
";",
"Object",
".",
"defineProperties",
"(",
"req",
",",
"{",
"pluginRender",
":",
"{",
"value",
":",
"this",
"}",
"}",
")",
";",
"Object",
".",
"defineProperties",
"(",
"this",
",",
"{",
"req",
":",
"{",
"value",
":",
"req",
"}",
",",
"res",
":",
"{",
"value",
":",
"res",
"}",
",",
"pluginId",
":",
"{",
"value",
":",
"req",
".",
"params",
".",
"plugin",
"}",
",",
"iId",
":",
"{",
"value",
":",
"req",
".",
"params",
".",
"iId",
"}",
",",
"plugin",
":",
"{",
"value",
":",
"Plugins",
".",
"get",
"(",
"req",
".",
"params",
".",
"plugin",
")",
"}",
",",
"namespace",
":",
"{",
"value",
":",
"req",
".",
"params",
".",
"namespace",
"}",
",",
"pluginInstance",
":",
"{",
"value",
":",
"pluginInstance",
"}",
",",
"theme",
":",
"{",
"value",
":",
"rendererInstance",
".",
"theme",
"}",
",",
"page",
":",
"{",
"value",
":",
"rendererInstance",
".",
"page",
"}",
",",
"pluginPermissionValidator",
":",
"{",
"value",
":",
"rendererInstance",
".",
"pluginPermissionValidator",
"}",
",",
"pagePermissionValidator",
":",
"{",
"value",
":",
"rendererInstance",
".",
"pagePermissionValidator",
"}",
",",
"pluginInstanceDBAction",
":",
"{",
"value",
":",
"rendererInstance",
".",
"pluginInstanceDBAction",
"}",
",",
"isExclusive",
":",
"{",
"value",
":",
"rendererInstance",
".",
"isExclusive",
"}",
"}",
")",
";",
"}"
]
| Constructor to create Plugin render, which will render the plugin's html
@param pluginInstance {Object} Plugin Instance model
@param rendererInstance {PageRenderer} instance of PageRenderer
@constructor | [
"Constructor",
"to",
"create",
"Plugin",
"render",
"which",
"will",
"render",
"the",
"plugin",
"s",
"html"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/lib/Renderer/PluginRender.js#L21-L88 |
47,787 | reklatsmasters/unicast | lib/socket.js | filter | function filter(socket, message, rinfo) {
const isAllowedAddress = socket.remoteAddress === rinfo.address;
const isAllowedPort = socket.remotePort === rinfo.port;
return isAllowedAddress && isAllowedPort;
} | javascript | function filter(socket, message, rinfo) {
const isAllowedAddress = socket.remoteAddress === rinfo.address;
const isAllowedPort = socket.remotePort === rinfo.port;
return isAllowedAddress && isAllowedPort;
} | [
"function",
"filter",
"(",
"socket",
",",
"message",
",",
"rinfo",
")",
"{",
"const",
"isAllowedAddress",
"=",
"socket",
".",
"remoteAddress",
"===",
"rinfo",
".",
"address",
";",
"const",
"isAllowedPort",
"=",
"socket",
".",
"remotePort",
"===",
"rinfo",
".",
"port",
";",
"return",
"isAllowedAddress",
"&&",
"isAllowedPort",
";",
"}"
]
| Default filter for incoming messages.
@param {Socket} socket
@param {Buffer} message
@param {{address: string, port: number}} rinfo
@returns {bool} | [
"Default",
"filter",
"for",
"incoming",
"messages",
"."
]
| fe83eb884bcd8687e50a4b5163a5af584d32444b | https://github.com/reklatsmasters/unicast/blob/fe83eb884bcd8687e50a4b5163a5af584d32444b/lib/socket.js#L231-L236 |
47,788 | mdreizin/webpack-config-stream | lib/propsStream.js | propsStream | function propsStream(options) {
if (!_.isObject(options)) {
options = {};
}
return through.obj(function(chunk, enc, cb) {
var webpackOptions = chunk[FIELD_NAME] || {};
webpackOptions = _.merge(webpackOptions, options);
chunk[FIELD_NAME] = webpackOptions;
cb(null, chunk);
});
} | javascript | function propsStream(options) {
if (!_.isObject(options)) {
options = {};
}
return through.obj(function(chunk, enc, cb) {
var webpackOptions = chunk[FIELD_NAME] || {};
webpackOptions = _.merge(webpackOptions, options);
chunk[FIELD_NAME] = webpackOptions;
cb(null, chunk);
});
} | [
"function",
"propsStream",
"(",
"options",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isObject",
"(",
"options",
")",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"return",
"through",
".",
"obj",
"(",
"function",
"(",
"chunk",
",",
"enc",
",",
"cb",
")",
"{",
"var",
"webpackOptions",
"=",
"chunk",
"[",
"FIELD_NAME",
"]",
"||",
"{",
"}",
";",
"webpackOptions",
"=",
"_",
".",
"merge",
"(",
"webpackOptions",
",",
"options",
")",
";",
"chunk",
"[",
"FIELD_NAME",
"]",
"=",
"webpackOptions",
";",
"cb",
"(",
"null",
",",
"chunk",
")",
";",
"}",
")",
";",
"}"
]
| Overrides existing properties of each `webpack.config.js` file. Can be piped.
@function
@alias propsStream
@param {Configuration=} options
@returns {Stream} | [
"Overrides",
"existing",
"properties",
"of",
"each",
"webpack",
".",
"config",
".",
"js",
"file",
".",
"Can",
"be",
"piped",
"."
]
| f8424f97837a224bc07cc18a03ecf649d708e924 | https://github.com/mdreizin/webpack-config-stream/blob/f8424f97837a224bc07cc18a03ecf649d708e924/lib/propsStream.js#L20-L34 |
47,789 | alekzonder/maf | src/Service/Config/getConfigFromConsul.js | function (logger, key, options) {
return new Promise((resolve, reject) => {
var url = `http://${options.host}:${options.port}/v1/kv/${key}`;
logger.trace(`GET ${url}`);
request.get(url)
.timeout(options.timeout)
.then((res) => {
logger.trace(`GET ${url} - 200`);
resolve(res.body);
})
.catch((error) => {
logger.trace(`GET ${url} - ${error.status}`);
if (error.status === 404) {
return resolve(null);
}
var code = ConfigError.CODES.UNKNOWN_ERROR;
if (error.code === 'ECONNREFUSED') {
code = ConfigError.CODES.CONSUL_ECONNREFUSED;
} else if (
error.code === 'ECONNABORTED' &&
typeof error.timeout === 'number'
) {
code = ConfigError.CODES.CONSUL_TIMEOUT;
}
var exception = ConfigError.createError(code, error);
exception.bind({method: 'GET', url: url});
reject(exception);
});
});
} | javascript | function (logger, key, options) {
return new Promise((resolve, reject) => {
var url = `http://${options.host}:${options.port}/v1/kv/${key}`;
logger.trace(`GET ${url}`);
request.get(url)
.timeout(options.timeout)
.then((res) => {
logger.trace(`GET ${url} - 200`);
resolve(res.body);
})
.catch((error) => {
logger.trace(`GET ${url} - ${error.status}`);
if (error.status === 404) {
return resolve(null);
}
var code = ConfigError.CODES.UNKNOWN_ERROR;
if (error.code === 'ECONNREFUSED') {
code = ConfigError.CODES.CONSUL_ECONNREFUSED;
} else if (
error.code === 'ECONNABORTED' &&
typeof error.timeout === 'number'
) {
code = ConfigError.CODES.CONSUL_TIMEOUT;
}
var exception = ConfigError.createError(code, error);
exception.bind({method: 'GET', url: url});
reject(exception);
});
});
} | [
"function",
"(",
"logger",
",",
"key",
",",
"options",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"var",
"url",
"=",
"`",
"${",
"options",
".",
"host",
"}",
"${",
"options",
".",
"port",
"}",
"${",
"key",
"}",
"`",
";",
"logger",
".",
"trace",
"(",
"`",
"${",
"url",
"}",
"`",
")",
";",
"request",
".",
"get",
"(",
"url",
")",
".",
"timeout",
"(",
"options",
".",
"timeout",
")",
".",
"then",
"(",
"(",
"res",
")",
"=>",
"{",
"logger",
".",
"trace",
"(",
"`",
"${",
"url",
"}",
"`",
")",
";",
"resolve",
"(",
"res",
".",
"body",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"error",
")",
"=>",
"{",
"logger",
".",
"trace",
"(",
"`",
"${",
"url",
"}",
"${",
"error",
".",
"status",
"}",
"`",
")",
";",
"if",
"(",
"error",
".",
"status",
"===",
"404",
")",
"{",
"return",
"resolve",
"(",
"null",
")",
";",
"}",
"var",
"code",
"=",
"ConfigError",
".",
"CODES",
".",
"UNKNOWN_ERROR",
";",
"if",
"(",
"error",
".",
"code",
"===",
"'ECONNREFUSED'",
")",
"{",
"code",
"=",
"ConfigError",
".",
"CODES",
".",
"CONSUL_ECONNREFUSED",
";",
"}",
"else",
"if",
"(",
"error",
".",
"code",
"===",
"'ECONNABORTED'",
"&&",
"typeof",
"error",
".",
"timeout",
"===",
"'number'",
")",
"{",
"code",
"=",
"ConfigError",
".",
"CODES",
".",
"CONSUL_TIMEOUT",
";",
"}",
"var",
"exception",
"=",
"ConfigError",
".",
"createError",
"(",
"code",
",",
"error",
")",
";",
"exception",
".",
"bind",
"(",
"{",
"method",
":",
"'GET'",
",",
"url",
":",
"url",
"}",
")",
";",
"reject",
"(",
"exception",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| get key form consul kv api
@param {logger} logger
@param {String} key
@param {Object} options
@private
@return {Promise} | [
"get",
"key",
"form",
"consul",
"kv",
"api"
]
| 1c88ef1f8618080fa4bfd467220c938ac74c4164 | https://github.com/alekzonder/maf/blob/1c88ef1f8618080fa4bfd467220c938ac74c4164/src/Service/Config/getConfigFromConsul.js#L18-L58 |
|
47,790 | saggiyogesh/nodeportal | public/ckeditor/_source/plugins/tabletools/dialogs/tableCell.js | function()
{
var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),
labelElement = heightType.getElement(),
inputElement = this.getInputElement(),
ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
} | javascript | function()
{
var heightType = this.getDialog().getContentElement( 'info', 'htmlHeightType' ),
labelElement = heightType.getElement(),
inputElement = this.getInputElement(),
ariaLabelledByAttr = inputElement.getAttribute( 'aria-labelledby' );
inputElement.setAttribute( 'aria-labelledby', [ ariaLabelledByAttr, labelElement.$.id ].join( ' ' ) );
} | [
"function",
"(",
")",
"{",
"var",
"heightType",
"=",
"this",
".",
"getDialog",
"(",
")",
".",
"getContentElement",
"(",
"'info'",
",",
"'htmlHeightType'",
")",
",",
"labelElement",
"=",
"heightType",
".",
"getElement",
"(",
")",
",",
"inputElement",
"=",
"this",
".",
"getInputElement",
"(",
")",
",",
"ariaLabelledByAttr",
"=",
"inputElement",
".",
"getAttribute",
"(",
"'aria-labelledby'",
")",
";",
"inputElement",
".",
"setAttribute",
"(",
"'aria-labelledby'",
",",
"[",
"ariaLabelledByAttr",
",",
"labelElement",
".",
"$",
".",
"id",
"]",
".",
"join",
"(",
"' '",
")",
")",
";",
"}"
]
| Extra labelling of height unit type. | [
"Extra",
"labelling",
"of",
"height",
"unit",
"type",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/plugins/tabletools/dialogs/tableCell.js#L173-L181 |
|
47,791 | anvaka/ngraph.shremlin | index.js | createGraphIterators | function createGraphIterators(graph) {
return {
/**
* Creates a vertex iterator stream. This is an entry point for all traversal
* starting with a node.
*
* @param {string|number} [startFrom] vertex id to start iteration from.
* If this argument is omitted, then all graph nodes are iterated
*
* @returns {VertexPipe}
*/
V: function createVertexStream(startFrom) {
var VertexPipe = require('./lib/pipes/vertexPipe');
var VertexIterator = require('./lib/iterators/vertexIterator');
var vertexPipe = new VertexPipe(graph);
vertexPipe.setSourcePipe(new VertexIterator(graph, startFrom));
return vertexPipe;
}
};
} | javascript | function createGraphIterators(graph) {
return {
/**
* Creates a vertex iterator stream. This is an entry point for all traversal
* starting with a node.
*
* @param {string|number} [startFrom] vertex id to start iteration from.
* If this argument is omitted, then all graph nodes are iterated
*
* @returns {VertexPipe}
*/
V: function createVertexStream(startFrom) {
var VertexPipe = require('./lib/pipes/vertexPipe');
var VertexIterator = require('./lib/iterators/vertexIterator');
var vertexPipe = new VertexPipe(graph);
vertexPipe.setSourcePipe(new VertexIterator(graph, startFrom));
return vertexPipe;
}
};
} | [
"function",
"createGraphIterators",
"(",
"graph",
")",
"{",
"return",
"{",
"/**\n * Creates a vertex iterator stream. This is an entry point for all traversal\n * starting with a node.\n *\n * @param {string|number} [startFrom] vertex id to start iteration from.\n * If this argument is omitted, then all graph nodes are iterated\n *\n * @returns {VertexPipe}\n */",
"V",
":",
"function",
"createVertexStream",
"(",
"startFrom",
")",
"{",
"var",
"VertexPipe",
"=",
"require",
"(",
"'./lib/pipes/vertexPipe'",
")",
";",
"var",
"VertexIterator",
"=",
"require",
"(",
"'./lib/iterators/vertexIterator'",
")",
";",
"var",
"vertexPipe",
"=",
"new",
"VertexPipe",
"(",
"graph",
")",
";",
"vertexPipe",
".",
"setSourcePipe",
"(",
"new",
"VertexIterator",
"(",
"graph",
",",
"startFrom",
")",
")",
";",
"return",
"vertexPipe",
";",
"}",
"}",
";",
"}"
]
| Creates a wrapper to iterate over graph. A wrapper contains methods which
allows you to begin iteration. Currently we support only vertices as iterator
starters, but in future we can easily extend this and add edges
@param {ngraph.graph|Viva.Graph.graph} graph source graph we want to iterate over | [
"Creates",
"a",
"wrapper",
"to",
"iterate",
"over",
"graph",
".",
"A",
"wrapper",
"contains",
"methods",
"which",
"allows",
"you",
"to",
"begin",
"iteration",
".",
"Currently",
"we",
"support",
"only",
"vertices",
"as",
"iterator",
"starters",
"but",
"in",
"future",
"we",
"can",
"easily",
"extend",
"this",
"and",
"add",
"edges"
]
| 98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7 | https://github.com/anvaka/ngraph.shremlin/blob/98f1f7892e0b1ccc4511cf664b74e7c0276f2ce7/index.js#L61-L81 |
47,792 | adriantoine/preact-enroute | index.js | normalizeRoute | function normalizeRoute(path, parent) {
if (path[0] === '/' || path[0] === '') {
return path; // absolute route
}
if (!parent) {
return path; // no need for a join
}
return `${parent.route}/${path}`; // join
} | javascript | function normalizeRoute(path, parent) {
if (path[0] === '/' || path[0] === '') {
return path; // absolute route
}
if (!parent) {
return path; // no need for a join
}
return `${parent.route}/${path}`; // join
} | [
"function",
"normalizeRoute",
"(",
"path",
",",
"parent",
")",
"{",
"if",
"(",
"path",
"[",
"0",
"]",
"===",
"'/'",
"||",
"path",
"[",
"0",
"]",
"===",
"''",
")",
"{",
"return",
"path",
";",
"// absolute route",
"}",
"if",
"(",
"!",
"parent",
")",
"{",
"return",
"path",
";",
"// no need for a join",
"}",
"return",
"`",
"${",
"parent",
".",
"route",
"}",
"${",
"path",
"}",
"`",
";",
"// join",
"}"
]
| Normalize route based on the parent. | [
"Normalize",
"route",
"based",
"on",
"the",
"parent",
"."
]
| c7923d05df4b4b6b36a7ea2014d2dfa9ad963383 | https://github.com/adriantoine/preact-enroute/blob/c7923d05df4b4b6b36a7ea2014d2dfa9ad963383/index.js#L97-L105 |
47,793 | lambtron/metalsmith-hover | lib/index.js | plugin | function plugin() {
return function(files, metalsmith, done) {
Object.keys(files).forEach(function(file) {
if (!~file.indexOf('.html')) return;
var $ = cheerio.load(files[file].contents);
var links = $('a');
for (var i = links.length - 1; i >= 0; i--) {
var url = links[i].attribs.href;
if (image(url)) $(links[i]).append(img(url));
}
$.root().prepend(css());
files[file].contents = new Buffer($.html());
});
done();
};
} | javascript | function plugin() {
return function(files, metalsmith, done) {
Object.keys(files).forEach(function(file) {
if (!~file.indexOf('.html')) return;
var $ = cheerio.load(files[file].contents);
var links = $('a');
for (var i = links.length - 1; i >= 0; i--) {
var url = links[i].attribs.href;
if (image(url)) $(links[i]).append(img(url));
}
$.root().prepend(css());
files[file].contents = new Buffer($.html());
});
done();
};
} | [
"function",
"plugin",
"(",
")",
"{",
"return",
"function",
"(",
"files",
",",
"metalsmith",
",",
"done",
")",
"{",
"Object",
".",
"keys",
"(",
"files",
")",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"if",
"(",
"!",
"~",
"file",
".",
"indexOf",
"(",
"'.html'",
")",
")",
"return",
";",
"var",
"$",
"=",
"cheerio",
".",
"load",
"(",
"files",
"[",
"file",
"]",
".",
"contents",
")",
";",
"var",
"links",
"=",
"$",
"(",
"'a'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"links",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"var",
"url",
"=",
"links",
"[",
"i",
"]",
".",
"attribs",
".",
"href",
";",
"if",
"(",
"image",
"(",
"url",
")",
")",
"$",
"(",
"links",
"[",
"i",
"]",
")",
".",
"append",
"(",
"img",
"(",
"url",
")",
")",
";",
"}",
"$",
".",
"root",
"(",
")",
".",
"prepend",
"(",
"css",
"(",
")",
")",
";",
"files",
"[",
"file",
"]",
".",
"contents",
"=",
"new",
"Buffer",
"(",
"$",
".",
"html",
"(",
")",
")",
";",
"}",
")",
";",
"done",
"(",
")",
";",
"}",
";",
"}"
]
| Plugin to show images or gifs from anchor elements on hover.
@return {Function} | [
"Plugin",
"to",
"show",
"images",
"or",
"gifs",
"from",
"anchor",
"elements",
"on",
"hover",
"."
]
| a147b8d109d88eaab8e93d20cfaac764de260b59 | https://github.com/lambtron/metalsmith-hover/blob/a147b8d109d88eaab8e93d20cfaac764de260b59/lib/index.js#L32-L47 |
47,794 | lambtron/metalsmith-hover | lib/index.js | image | function image(filename) {
if (!filename) return;
var ext = filename.split('.')[filename.split('.').length - 1];
return ~extensions.join().indexOf(ext);
} | javascript | function image(filename) {
if (!filename) return;
var ext = filename.split('.')[filename.split('.').length - 1];
return ~extensions.join().indexOf(ext);
} | [
"function",
"image",
"(",
"filename",
")",
"{",
"if",
"(",
"!",
"filename",
")",
"return",
";",
"var",
"ext",
"=",
"filename",
".",
"split",
"(",
"'.'",
")",
"[",
"filename",
".",
"split",
"(",
"'.'",
")",
".",
"length",
"-",
"1",
"]",
";",
"return",
"~",
"extensions",
".",
"join",
"(",
")",
".",
"indexOf",
"(",
"ext",
")",
";",
"}"
]
| See if filename is image. | [
"See",
"if",
"filename",
"is",
"image",
"."
]
| a147b8d109d88eaab8e93d20cfaac764de260b59 | https://github.com/lambtron/metalsmith-hover/blob/a147b8d109d88eaab8e93d20cfaac764de260b59/lib/index.js#L53-L57 |
47,795 | saggiyogesh/nodeportal | public/ckeditor/_source/core/htmlparser/filter.js | callItems | function callItems( currentEntry )
{
var isNode = currentEntry.type
|| currentEntry instanceof CKEDITOR.htmlParser.fragment;
for ( var i = 0 ; i < this.length ; i++ )
{
// Backup the node info before filtering.
if ( isNode )
{
var orgType = currentEntry.type,
orgName = currentEntry.name;
}
var item = this[ i ],
ret = item.apply( window, arguments );
if ( ret === false )
return ret;
// We're filtering node (element/fragment).
if ( isNode )
{
// No further filtering if it's not anymore
// fitable for the subsequent filters.
if ( ret && ( ret.name != orgName
|| ret.type != orgType ) )
{
return ret;
}
}
// Filtering value (nodeName/textValue/attrValue).
else
{
// No further filtering if it's not
// any more values.
if ( typeof ret != 'string' )
return ret;
}
ret != undefined && ( currentEntry = ret );
}
return currentEntry;
} | javascript | function callItems( currentEntry )
{
var isNode = currentEntry.type
|| currentEntry instanceof CKEDITOR.htmlParser.fragment;
for ( var i = 0 ; i < this.length ; i++ )
{
// Backup the node info before filtering.
if ( isNode )
{
var orgType = currentEntry.type,
orgName = currentEntry.name;
}
var item = this[ i ],
ret = item.apply( window, arguments );
if ( ret === false )
return ret;
// We're filtering node (element/fragment).
if ( isNode )
{
// No further filtering if it's not anymore
// fitable for the subsequent filters.
if ( ret && ( ret.name != orgName
|| ret.type != orgType ) )
{
return ret;
}
}
// Filtering value (nodeName/textValue/attrValue).
else
{
// No further filtering if it's not
// any more values.
if ( typeof ret != 'string' )
return ret;
}
ret != undefined && ( currentEntry = ret );
}
return currentEntry;
} | [
"function",
"callItems",
"(",
"currentEntry",
")",
"{",
"var",
"isNode",
"=",
"currentEntry",
".",
"type",
"||",
"currentEntry",
"instanceof",
"CKEDITOR",
".",
"htmlParser",
".",
"fragment",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"// Backup the node info before filtering.\r",
"if",
"(",
"isNode",
")",
"{",
"var",
"orgType",
"=",
"currentEntry",
".",
"type",
",",
"orgName",
"=",
"currentEntry",
".",
"name",
";",
"}",
"var",
"item",
"=",
"this",
"[",
"i",
"]",
",",
"ret",
"=",
"item",
".",
"apply",
"(",
"window",
",",
"arguments",
")",
";",
"if",
"(",
"ret",
"===",
"false",
")",
"return",
"ret",
";",
"// We're filtering node (element/fragment).\r",
"if",
"(",
"isNode",
")",
"{",
"// No further filtering if it's not anymore\r",
"// fitable for the subsequent filters.\r",
"if",
"(",
"ret",
"&&",
"(",
"ret",
".",
"name",
"!=",
"orgName",
"||",
"ret",
".",
"type",
"!=",
"orgType",
")",
")",
"{",
"return",
"ret",
";",
"}",
"}",
"// Filtering value (nodeName/textValue/attrValue).\r",
"else",
"{",
"// No further filtering if it's not\r",
"// any more values.\r",
"if",
"(",
"typeof",
"ret",
"!=",
"'string'",
")",
"return",
"ret",
";",
"}",
"ret",
"!=",
"undefined",
"&&",
"(",
"currentEntry",
"=",
"ret",
")",
";",
"}",
"return",
"currentEntry",
";",
"}"
]
| Invoke filters sequentially on the array, break the iteration when it doesn't make sense to continue anymore. | [
"Invoke",
"filters",
"sequentially",
"on",
"the",
"array",
"break",
"the",
"iteration",
"when",
"it",
"doesn",
"t",
"make",
"sense",
"to",
"continue",
"anymore",
"."
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/public/ckeditor/_source/core/htmlparser/filter.js#L232-L276 |
47,796 | building5/appdirsjs | index.js | function (dir, appname, version) {
if (appname) {
dir = path.join(dir, appname);
if (version) {
dir = path.join(dir, version);
}
}
return dir;
} | javascript | function (dir, appname, version) {
if (appname) {
dir = path.join(dir, appname);
if (version) {
dir = path.join(dir, version);
}
}
return dir;
} | [
"function",
"(",
"dir",
",",
"appname",
",",
"version",
")",
"{",
"if",
"(",
"appname",
")",
"{",
"dir",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"appname",
")",
";",
"if",
"(",
"version",
")",
"{",
"dir",
"=",
"path",
".",
"join",
"(",
"dir",
",",
"version",
")",
";",
"}",
"}",
"return",
"dir",
";",
"}"
]
| Append the name and and version to a path.
Both the appname and version are optional. The version is only appended if
the appname.
@param {string} dir Base directory.
@param {string} [appname] Optional name to append.
@param {string} [version] Optional version to append.
@returns {string} Resulting path
@private | [
"Append",
"the",
"name",
"and",
"and",
"version",
"to",
"a",
"path",
"."
]
| 0c1a98efea2db40923b92e45725adb44c36f5a18 | https://github.com/building5/appdirsjs/blob/0c1a98efea2db40923b92e45725adb44c36f5a18/index.js#L40-L48 |
|
47,797 | saggiyogesh/nodeportal | plugins/managePage/PageManageController.js | deletePage | function deletePage(req, res, next) {
var that = this, db = that.getDB(), DBActions = that.getDBActionsLib(),
dbAction = DBActions.getAuthInstance(req, PAGE_SCHEMA, PAGE_PERMISSION_SCHEMA_ENTRY);
var params = req.params;
var pageId = params.id;
if (!pageId) {
that.setErrorMessage(req, "No page is selected");
return next(null);
}
var redirect = req.params.page + "/" + req.params.plugin;
dbAction.get("findByPageId", pageId, function (err, page) {
if (err) {
return next(err);
}
page && (page = page.toObject());
if (page && (that.getAppProperty("DEFAULT_INDEX_PAGE") == page.friendlyURL)) {
that.setErrorMessage(req, "Cannot delete index page.");
that.setRedirect(req, redirect);
return next(null);
}
PageManager.hasChildren(dbAction, pageId, function (err, pages) {
if (pages.length > 0) {
that.setRedirect(req, redirect);
that.setErrorMessage(req, "Delete all child pages.");
next(err);
} else {
var aboveSiblings;
async.series([
function (n) {
dbAction.authorizedRemove(pageId, n);
},
function (n) {
PageManager.getAboveSiblings(dbAction, page, function (err, pages) {
if (pages) {
aboveSiblings = pages;
}
n(err, pages);
});
},
function (n) {
if (!aboveSiblings || aboveSiblings.length == 0) {
return n(null, true);
}
var dbAction1 = DBActions.getInstance(req, PAGE_SCHEMA);
var decrementPageOrder = function (page, n) {
var order = page.order;
--order;
dbAction1.update({
pageId: page.pageId,
order: order
}, n);
};
async.each(aboveSiblings, decrementPageOrder, n);
}
], function (err, result) {
if (!err) {
that.setRedirect(req, redirect);
that.setSuccessMessage(req, "Page deleted successfully.");
}
next(err);
});
}
});
})
} | javascript | function deletePage(req, res, next) {
var that = this, db = that.getDB(), DBActions = that.getDBActionsLib(),
dbAction = DBActions.getAuthInstance(req, PAGE_SCHEMA, PAGE_PERMISSION_SCHEMA_ENTRY);
var params = req.params;
var pageId = params.id;
if (!pageId) {
that.setErrorMessage(req, "No page is selected");
return next(null);
}
var redirect = req.params.page + "/" + req.params.plugin;
dbAction.get("findByPageId", pageId, function (err, page) {
if (err) {
return next(err);
}
page && (page = page.toObject());
if (page && (that.getAppProperty("DEFAULT_INDEX_PAGE") == page.friendlyURL)) {
that.setErrorMessage(req, "Cannot delete index page.");
that.setRedirect(req, redirect);
return next(null);
}
PageManager.hasChildren(dbAction, pageId, function (err, pages) {
if (pages.length > 0) {
that.setRedirect(req, redirect);
that.setErrorMessage(req, "Delete all child pages.");
next(err);
} else {
var aboveSiblings;
async.series([
function (n) {
dbAction.authorizedRemove(pageId, n);
},
function (n) {
PageManager.getAboveSiblings(dbAction, page, function (err, pages) {
if (pages) {
aboveSiblings = pages;
}
n(err, pages);
});
},
function (n) {
if (!aboveSiblings || aboveSiblings.length == 0) {
return n(null, true);
}
var dbAction1 = DBActions.getInstance(req, PAGE_SCHEMA);
var decrementPageOrder = function (page, n) {
var order = page.order;
--order;
dbAction1.update({
pageId: page.pageId,
order: order
}, n);
};
async.each(aboveSiblings, decrementPageOrder, n);
}
], function (err, result) {
if (!err) {
that.setRedirect(req, redirect);
that.setSuccessMessage(req, "Page deleted successfully.");
}
next(err);
});
}
});
})
} | [
"function",
"deletePage",
"(",
"req",
",",
"res",
",",
"next",
")",
"{",
"var",
"that",
"=",
"this",
",",
"db",
"=",
"that",
".",
"getDB",
"(",
")",
",",
"DBActions",
"=",
"that",
".",
"getDBActionsLib",
"(",
")",
",",
"dbAction",
"=",
"DBActions",
".",
"getAuthInstance",
"(",
"req",
",",
"PAGE_SCHEMA",
",",
"PAGE_PERMISSION_SCHEMA_ENTRY",
")",
";",
"var",
"params",
"=",
"req",
".",
"params",
";",
"var",
"pageId",
"=",
"params",
".",
"id",
";",
"if",
"(",
"!",
"pageId",
")",
"{",
"that",
".",
"setErrorMessage",
"(",
"req",
",",
"\"No page is selected\"",
")",
";",
"return",
"next",
"(",
"null",
")",
";",
"}",
"var",
"redirect",
"=",
"req",
".",
"params",
".",
"page",
"+",
"\"/\"",
"+",
"req",
".",
"params",
".",
"plugin",
";",
"dbAction",
".",
"get",
"(",
"\"findByPageId\"",
",",
"pageId",
",",
"function",
"(",
"err",
",",
"page",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"next",
"(",
"err",
")",
";",
"}",
"page",
"&&",
"(",
"page",
"=",
"page",
".",
"toObject",
"(",
")",
")",
";",
"if",
"(",
"page",
"&&",
"(",
"that",
".",
"getAppProperty",
"(",
"\"DEFAULT_INDEX_PAGE\"",
")",
"==",
"page",
".",
"friendlyURL",
")",
")",
"{",
"that",
".",
"setErrorMessage",
"(",
"req",
",",
"\"Cannot delete index page.\"",
")",
";",
"that",
".",
"setRedirect",
"(",
"req",
",",
"redirect",
")",
";",
"return",
"next",
"(",
"null",
")",
";",
"}",
"PageManager",
".",
"hasChildren",
"(",
"dbAction",
",",
"pageId",
",",
"function",
"(",
"err",
",",
"pages",
")",
"{",
"if",
"(",
"pages",
".",
"length",
">",
"0",
")",
"{",
"that",
".",
"setRedirect",
"(",
"req",
",",
"redirect",
")",
";",
"that",
".",
"setErrorMessage",
"(",
"req",
",",
"\"Delete all child pages.\"",
")",
";",
"next",
"(",
"err",
")",
";",
"}",
"else",
"{",
"var",
"aboveSiblings",
";",
"async",
".",
"series",
"(",
"[",
"function",
"(",
"n",
")",
"{",
"dbAction",
".",
"authorizedRemove",
"(",
"pageId",
",",
"n",
")",
";",
"}",
",",
"function",
"(",
"n",
")",
"{",
"PageManager",
".",
"getAboveSiblings",
"(",
"dbAction",
",",
"page",
",",
"function",
"(",
"err",
",",
"pages",
")",
"{",
"if",
"(",
"pages",
")",
"{",
"aboveSiblings",
"=",
"pages",
";",
"}",
"n",
"(",
"err",
",",
"pages",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"n",
")",
"{",
"if",
"(",
"!",
"aboveSiblings",
"||",
"aboveSiblings",
".",
"length",
"==",
"0",
")",
"{",
"return",
"n",
"(",
"null",
",",
"true",
")",
";",
"}",
"var",
"dbAction1",
"=",
"DBActions",
".",
"getInstance",
"(",
"req",
",",
"PAGE_SCHEMA",
")",
";",
"var",
"decrementPageOrder",
"=",
"function",
"(",
"page",
",",
"n",
")",
"{",
"var",
"order",
"=",
"page",
".",
"order",
";",
"--",
"order",
";",
"dbAction1",
".",
"update",
"(",
"{",
"pageId",
":",
"page",
".",
"pageId",
",",
"order",
":",
"order",
"}",
",",
"n",
")",
";",
"}",
";",
"async",
".",
"each",
"(",
"aboveSiblings",
",",
"decrementPageOrder",
",",
"n",
")",
";",
"}",
"]",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"!",
"err",
")",
"{",
"that",
".",
"setRedirect",
"(",
"req",
",",
"redirect",
")",
";",
"that",
".",
"setSuccessMessage",
"(",
"req",
",",
"\"Page deleted successfully.\"",
")",
";",
"}",
"next",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}",
")",
"}"
]
| only single page is deleted at a time, ie if a page doesn't have any children
@param req
@param res
@param next | [
"only",
"single",
"page",
"is",
"deleted",
"at",
"a",
"time",
"ie",
"if",
"a",
"page",
"doesn",
"t",
"have",
"any",
"children"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/managePage/PageManageController.js#L177-L243 |
47,798 | saggiyogesh/nodeportal | plugins/themeBuilder/ThemeBuilderPluginController.js | setupWatcher | function setupWatcher(app, dbAction, name) {
dbAction.get("findByName", name, function (err, theme) {
if (!err && theme) {
require(utils.getLibPath() + "/static/ThemesWatcher").cacheAndWatchTheme(app, theme);
}
});
} | javascript | function setupWatcher(app, dbAction, name) {
dbAction.get("findByName", name, function (err, theme) {
if (!err && theme) {
require(utils.getLibPath() + "/static/ThemesWatcher").cacheAndWatchTheme(app, theme);
}
});
} | [
"function",
"setupWatcher",
"(",
"app",
",",
"dbAction",
",",
"name",
")",
"{",
"dbAction",
".",
"get",
"(",
"\"findByName\"",
",",
"name",
",",
"function",
"(",
"err",
",",
"theme",
")",
"{",
"if",
"(",
"!",
"err",
"&&",
"theme",
")",
"{",
"require",
"(",
"utils",
".",
"getLibPath",
"(",
")",
"+",
"\"/static/ThemesWatcher\"",
")",
".",
"cacheAndWatchTheme",
"(",
"app",
",",
"theme",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Setup watcher for newly created theme for changes
@param app
@param dbAction
@param name | [
"Setup",
"watcher",
"for",
"newly",
"created",
"theme",
"for",
"changes"
]
| cfd5b340f259d3a57c20892a1e2c95b133fe99ee | https://github.com/saggiyogesh/nodeportal/blob/cfd5b340f259d3a57c20892a1e2c95b133fe99ee/plugins/themeBuilder/ThemeBuilderPluginController.js#L250-L256 |
47,799 | nicktindall/cyclon.p2p-rtc-client | lib/SignallingServerSelector.js | filterAndSortAvailableServers | function filterAndSortAvailableServers (serverArray) {
var copyOfServerArray = JSON.parse(JSON.stringify(serverArray));
copyOfServerArray.sort(function (itemOne, itemTwo) {
return sortValue(itemOne) - sortValue(itemTwo);
});
// Filter servers we've too-recently disconnected from
return copyOfServerArray.filter(haveNotDisconnectedFromRecently);
} | javascript | function filterAndSortAvailableServers (serverArray) {
var copyOfServerArray = JSON.parse(JSON.stringify(serverArray));
copyOfServerArray.sort(function (itemOne, itemTwo) {
return sortValue(itemOne) - sortValue(itemTwo);
});
// Filter servers we've too-recently disconnected from
return copyOfServerArray.filter(haveNotDisconnectedFromRecently);
} | [
"function",
"filterAndSortAvailableServers",
"(",
"serverArray",
")",
"{",
"var",
"copyOfServerArray",
"=",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"serverArray",
")",
")",
";",
"copyOfServerArray",
".",
"sort",
"(",
"function",
"(",
"itemOne",
",",
"itemTwo",
")",
"{",
"return",
"sortValue",
"(",
"itemOne",
")",
"-",
"sortValue",
"(",
"itemTwo",
")",
";",
"}",
")",
";",
"// Filter servers we've too-recently disconnected from",
"return",
"copyOfServerArray",
".",
"filter",
"(",
"haveNotDisconnectedFromRecently",
")",
";",
"}"
]
| Return a copy of the known server array sorted in the order of
their last-disconnect-time. Due to the fact a failed connect is
considered a disconnect, this will cause servers to be tried in
a round robin pattern. | [
"Return",
"a",
"copy",
"of",
"the",
"known",
"server",
"array",
"sorted",
"in",
"the",
"order",
"of",
"their",
"last",
"-",
"disconnect",
"-",
"time",
".",
"Due",
"to",
"the",
"fact",
"a",
"failed",
"connect",
"is",
"considered",
"a",
"disconnect",
"this",
"will",
"cause",
"servers",
"to",
"be",
"tried",
"in",
"a",
"round",
"robin",
"pattern",
"."
]
| eb586ce288a6ad7e1b221280825037e855b03904 | https://github.com/nicktindall/cyclon.p2p-rtc-client/blob/eb586ce288a6ad7e1b221280825037e855b03904/lib/SignallingServerSelector.js#L24-L32 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.