id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
56,200 | el-fuego/grunt-concat-properties | tasks/lib/reader.js | addProperty | function addProperty(sourceData, propertiesGroups, filePath) {
var group = propertiesUtils.getGroup(sourceData[2], propertiesGroups),
propertyName,
data,
propertyDefinitionWithoutObjectName;
if (!group) {
grunt.log.error('Object ' + sourceData[2] + ' without init file');
return;
}
grunt.verbose.ok(sourceData[2]);
// generate property data
propertyDefinitionWithoutObjectName = sourceData[2].replace(group.pattern, '').replace(/^\./, '');
propertyName = propertyDefinitionWithoutObjectName.replace(/^prototype\./i, '');
data = {
name: propertyName,
source: sourceData[3].replace(/(^[\r\n\s]+|[\r\n\s;]+$)/g, ''),
comment: sourceData[1] || '',
type: propertiesUtils.isFunction(sourceData[3]) ? 'function' : 'object',
isPublic: propertiesUtils.isPublic(propertyName),
isFromPrototype: propertiesUtils.isFromPrototype(propertyDefinitionWithoutObjectName),
filePath: filePath
};
// add property data to prototype or inline array
group[(data.isFromPrototype ? 'prototypeProperties' : 'inlineProperties')].push(data);
} | javascript | function addProperty(sourceData, propertiesGroups, filePath) {
var group = propertiesUtils.getGroup(sourceData[2], propertiesGroups),
propertyName,
data,
propertyDefinitionWithoutObjectName;
if (!group) {
grunt.log.error('Object ' + sourceData[2] + ' without init file');
return;
}
grunt.verbose.ok(sourceData[2]);
// generate property data
propertyDefinitionWithoutObjectName = sourceData[2].replace(group.pattern, '').replace(/^\./, '');
propertyName = propertyDefinitionWithoutObjectName.replace(/^prototype\./i, '');
data = {
name: propertyName,
source: sourceData[3].replace(/(^[\r\n\s]+|[\r\n\s;]+$)/g, ''),
comment: sourceData[1] || '',
type: propertiesUtils.isFunction(sourceData[3]) ? 'function' : 'object',
isPublic: propertiesUtils.isPublic(propertyName),
isFromPrototype: propertiesUtils.isFromPrototype(propertyDefinitionWithoutObjectName),
filePath: filePath
};
// add property data to prototype or inline array
group[(data.isFromPrototype ? 'prototypeProperties' : 'inlineProperties')].push(data);
} | [
"function",
"addProperty",
"(",
"sourceData",
",",
"propertiesGroups",
",",
"filePath",
")",
"{",
"var",
"group",
"=",
"propertiesUtils",
".",
"getGroup",
"(",
"sourceData",
"[",
"2",
"]",
",",
"propertiesGroups",
")",
",",
"propertyName",
",",
"data",
",",
"propertyDefinitionWithoutObjectName",
";",
"if",
"(",
"!",
"group",
")",
"{",
"grunt",
".",
"log",
".",
"error",
"(",
"'Object '",
"+",
"sourceData",
"[",
"2",
"]",
"+",
"' without init file'",
")",
";",
"return",
";",
"}",
"grunt",
".",
"verbose",
".",
"ok",
"(",
"sourceData",
"[",
"2",
"]",
")",
";",
"// generate property data",
"propertyDefinitionWithoutObjectName",
"=",
"sourceData",
"[",
"2",
"]",
".",
"replace",
"(",
"group",
".",
"pattern",
",",
"''",
")",
".",
"replace",
"(",
"/",
"^\\.",
"/",
",",
"''",
")",
";",
"propertyName",
"=",
"propertyDefinitionWithoutObjectName",
".",
"replace",
"(",
"/",
"^prototype\\.",
"/",
"i",
",",
"''",
")",
";",
"data",
"=",
"{",
"name",
":",
"propertyName",
",",
"source",
":",
"sourceData",
"[",
"3",
"]",
".",
"replace",
"(",
"/",
"(^[\\r\\n\\s]+|[\\r\\n\\s;]+$)",
"/",
"g",
",",
"''",
")",
",",
"comment",
":",
"sourceData",
"[",
"1",
"]",
"||",
"''",
",",
"type",
":",
"propertiesUtils",
".",
"isFunction",
"(",
"sourceData",
"[",
"3",
"]",
")",
"?",
"'function'",
":",
"'object'",
",",
"isPublic",
":",
"propertiesUtils",
".",
"isPublic",
"(",
"propertyName",
")",
",",
"isFromPrototype",
":",
"propertiesUtils",
".",
"isFromPrototype",
"(",
"propertyDefinitionWithoutObjectName",
")",
",",
"filePath",
":",
"filePath",
"}",
";",
"// add property data to prototype or inline array",
"group",
"[",
"(",
"data",
".",
"isFromPrototype",
"?",
"'prototypeProperties'",
":",
"'inlineProperties'",
")",
"]",
".",
"push",
"(",
"data",
")",
";",
"}"
] | Add property data to their properties group
@param sourceData {String}
@param propertiesGroups [{Object}]
@param filePath {String}
@returns {Object} | [
"Add",
"property",
"data",
"to",
"their",
"properties",
"group"
] | a7efad68106d81aec262deee12190c75952f09b3 | https://github.com/el-fuego/grunt-concat-properties/blob/a7efad68106d81aec262deee12190c75952f09b3/tasks/lib/reader.js#L64-L93 |
56,201 | el-fuego/grunt-concat-properties | tasks/lib/reader.js | addJSONProperties | function addJSONProperties(jsonData, propertiesGroups, filePath, currentNamesPath) {
var i,
group,
propertyDefinition,
propertyDefinitionWithoutObjectName,
propertyName,
data;
if (currentNamesPath === undefined) {
currentNamesPath = '';
}
// get all values
for (i in jsonData) {
// add to group if is a simply object
if (jsonData[i] instanceof Array || jsonData[i] == null || typeof jsonData[i] !== 'object' || grunt.util._.isEmpty(jsonData[i])) {
// find group
propertyDefinition = (currentNamesPath ? currentNamesPath + '.' + i : i)
.replace(/^[^.]+\./, '');
group = propertiesUtils.getGroup(propertyDefinition, propertiesGroups);
if (!group) {
grunt.log.error('Object ' + propertyDefinition + ' without init file');
return;
}
grunt.verbose.ok(propertyDefinition);
// generate property data
propertyDefinitionWithoutObjectName = propertyDefinition
.replace(group.pattern, '')
.replace(/^\./, '');
propertyName = propertyDefinitionWithoutObjectName
.replace(/^prototype\./i, '');
data = {
name: propertyName,
comment: '',
type: 'object',
isPublic: propertiesUtils.isPublic(propertyName),
isFromPrototype: propertiesUtils.isFromPrototype(propertyDefinitionWithoutObjectName),
filePath: filePath
};
// string -> "string"
// true -> true
switch (typeof jsonData[i]) {
case 'object':
if (jsonData[i] != null) {
data.source = JSON.stringify(jsonData[i]);
}
break;
case 'string':
data.source = '"' + jsonData[i].split('"').join('\\"') + '"';
break;
}
if (data.source === undefined) {
data.source = '' + jsonData[i];
}
// add property data to prototype or inline array
group[(data.isFromPrototype ? 'prototypeProperties' : 'inlineProperties')].push(data);
} else {
// is object
// add attributeName to path and try to add
addJSONProperties(jsonData[i], propertiesGroups, filePath, currentNamesPath ? currentNamesPath + '.' + i : i);
}
}
} | javascript | function addJSONProperties(jsonData, propertiesGroups, filePath, currentNamesPath) {
var i,
group,
propertyDefinition,
propertyDefinitionWithoutObjectName,
propertyName,
data;
if (currentNamesPath === undefined) {
currentNamesPath = '';
}
// get all values
for (i in jsonData) {
// add to group if is a simply object
if (jsonData[i] instanceof Array || jsonData[i] == null || typeof jsonData[i] !== 'object' || grunt.util._.isEmpty(jsonData[i])) {
// find group
propertyDefinition = (currentNamesPath ? currentNamesPath + '.' + i : i)
.replace(/^[^.]+\./, '');
group = propertiesUtils.getGroup(propertyDefinition, propertiesGroups);
if (!group) {
grunt.log.error('Object ' + propertyDefinition + ' without init file');
return;
}
grunt.verbose.ok(propertyDefinition);
// generate property data
propertyDefinitionWithoutObjectName = propertyDefinition
.replace(group.pattern, '')
.replace(/^\./, '');
propertyName = propertyDefinitionWithoutObjectName
.replace(/^prototype\./i, '');
data = {
name: propertyName,
comment: '',
type: 'object',
isPublic: propertiesUtils.isPublic(propertyName),
isFromPrototype: propertiesUtils.isFromPrototype(propertyDefinitionWithoutObjectName),
filePath: filePath
};
// string -> "string"
// true -> true
switch (typeof jsonData[i]) {
case 'object':
if (jsonData[i] != null) {
data.source = JSON.stringify(jsonData[i]);
}
break;
case 'string':
data.source = '"' + jsonData[i].split('"').join('\\"') + '"';
break;
}
if (data.source === undefined) {
data.source = '' + jsonData[i];
}
// add property data to prototype or inline array
group[(data.isFromPrototype ? 'prototypeProperties' : 'inlineProperties')].push(data);
} else {
// is object
// add attributeName to path and try to add
addJSONProperties(jsonData[i], propertiesGroups, filePath, currentNamesPath ? currentNamesPath + '.' + i : i);
}
}
} | [
"function",
"addJSONProperties",
"(",
"jsonData",
",",
"propertiesGroups",
",",
"filePath",
",",
"currentNamesPath",
")",
"{",
"var",
"i",
",",
"group",
",",
"propertyDefinition",
",",
"propertyDefinitionWithoutObjectName",
",",
"propertyName",
",",
"data",
";",
"if",
"(",
"currentNamesPath",
"===",
"undefined",
")",
"{",
"currentNamesPath",
"=",
"''",
";",
"}",
"// get all values",
"for",
"(",
"i",
"in",
"jsonData",
")",
"{",
"// add to group if is a simply object",
"if",
"(",
"jsonData",
"[",
"i",
"]",
"instanceof",
"Array",
"||",
"jsonData",
"[",
"i",
"]",
"==",
"null",
"||",
"typeof",
"jsonData",
"[",
"i",
"]",
"!==",
"'object'",
"||",
"grunt",
".",
"util",
".",
"_",
".",
"isEmpty",
"(",
"jsonData",
"[",
"i",
"]",
")",
")",
"{",
"// find group",
"propertyDefinition",
"=",
"(",
"currentNamesPath",
"?",
"currentNamesPath",
"+",
"'.'",
"+",
"i",
":",
"i",
")",
".",
"replace",
"(",
"/",
"^[^.]+\\.",
"/",
",",
"''",
")",
";",
"group",
"=",
"propertiesUtils",
".",
"getGroup",
"(",
"propertyDefinition",
",",
"propertiesGroups",
")",
";",
"if",
"(",
"!",
"group",
")",
"{",
"grunt",
".",
"log",
".",
"error",
"(",
"'Object '",
"+",
"propertyDefinition",
"+",
"' without init file'",
")",
";",
"return",
";",
"}",
"grunt",
".",
"verbose",
".",
"ok",
"(",
"propertyDefinition",
")",
";",
"// generate property data",
"propertyDefinitionWithoutObjectName",
"=",
"propertyDefinition",
".",
"replace",
"(",
"group",
".",
"pattern",
",",
"''",
")",
".",
"replace",
"(",
"/",
"^\\.",
"/",
",",
"''",
")",
";",
"propertyName",
"=",
"propertyDefinitionWithoutObjectName",
".",
"replace",
"(",
"/",
"^prototype\\.",
"/",
"i",
",",
"''",
")",
";",
"data",
"=",
"{",
"name",
":",
"propertyName",
",",
"comment",
":",
"''",
",",
"type",
":",
"'object'",
",",
"isPublic",
":",
"propertiesUtils",
".",
"isPublic",
"(",
"propertyName",
")",
",",
"isFromPrototype",
":",
"propertiesUtils",
".",
"isFromPrototype",
"(",
"propertyDefinitionWithoutObjectName",
")",
",",
"filePath",
":",
"filePath",
"}",
";",
"// string -> \"string\"",
"// true -> true",
"switch",
"(",
"typeof",
"jsonData",
"[",
"i",
"]",
")",
"{",
"case",
"'object'",
":",
"if",
"(",
"jsonData",
"[",
"i",
"]",
"!=",
"null",
")",
"{",
"data",
".",
"source",
"=",
"JSON",
".",
"stringify",
"(",
"jsonData",
"[",
"i",
"]",
")",
";",
"}",
"break",
";",
"case",
"'string'",
":",
"data",
".",
"source",
"=",
"'\"'",
"+",
"jsonData",
"[",
"i",
"]",
".",
"split",
"(",
"'\"'",
")",
".",
"join",
"(",
"'\\\\\"'",
")",
"+",
"'\"'",
";",
"break",
";",
"}",
"if",
"(",
"data",
".",
"source",
"===",
"undefined",
")",
"{",
"data",
".",
"source",
"=",
"''",
"+",
"jsonData",
"[",
"i",
"]",
";",
"}",
"// add property data to prototype or inline array",
"group",
"[",
"(",
"data",
".",
"isFromPrototype",
"?",
"'prototypeProperties'",
":",
"'inlineProperties'",
")",
"]",
".",
"push",
"(",
"data",
")",
";",
"}",
"else",
"{",
"// is object",
"// add attributeName to path and try to add",
"addJSONProperties",
"(",
"jsonData",
"[",
"i",
"]",
",",
"propertiesGroups",
",",
"filePath",
",",
"currentNamesPath",
"?",
"currentNamesPath",
"+",
"'.'",
"+",
"i",
":",
"i",
")",
";",
"}",
"}",
"}"
] | Add JSON properties values to their properties group
@param jsonData {String}
@param propertiesGroups [{Object}]
@param filePath {String}
@param currentNamesPath {String}
@returns {Object} | [
"Add",
"JSON",
"properties",
"values",
"to",
"their",
"properties",
"group"
] | a7efad68106d81aec262deee12190c75952f09b3 | https://github.com/el-fuego/grunt-concat-properties/blob/a7efad68106d81aec262deee12190c75952f09b3/tasks/lib/reader.js#L104-L177 |
56,202 | Gozala/fs-reduce | reader.js | onChunk | function onChunk(count) {
// If chunk read has no bytes than there is nothing left, so end a
// collection.
if (count === 0) return next(end)
// Move a offset `position` with `count` towards the end unless
// position was a `null` in which case we just keep it (`null` means
// from a current position).
position = position === null ? position : position + count
// Read chunk is forwarded to a consumer that will return
// a promise which is delivered once write is complete.
// In a future we may switch to an approach similar to new
// streams in node, where buffering watermarks are specified
// via options and reads can buffer up up to that point in
// parallel to write.
when(next(buffer.slice(0, count), state), onDrain, onError)
} | javascript | function onChunk(count) {
// If chunk read has no bytes than there is nothing left, so end a
// collection.
if (count === 0) return next(end)
// Move a offset `position` with `count` towards the end unless
// position was a `null` in which case we just keep it (`null` means
// from a current position).
position = position === null ? position : position + count
// Read chunk is forwarded to a consumer that will return
// a promise which is delivered once write is complete.
// In a future we may switch to an approach similar to new
// streams in node, where buffering watermarks are specified
// via options and reads can buffer up up to that point in
// parallel to write.
when(next(buffer.slice(0, count), state), onDrain, onError)
} | [
"function",
"onChunk",
"(",
"count",
")",
"{",
"// If chunk read has no bytes than there is nothing left, so end a",
"// collection.",
"if",
"(",
"count",
"===",
"0",
")",
"return",
"next",
"(",
"end",
")",
"// Move a offset `position` with `count` towards the end unless",
"// position was a `null` in which case we just keep it (`null` means",
"// from a current position).",
"position",
"=",
"position",
"===",
"null",
"?",
"position",
":",
"position",
"+",
"count",
"// Read chunk is forwarded to a consumer that will return",
"// a promise which is delivered once write is complete.",
"// In a future we may switch to an approach similar to new",
"// streams in node, where buffering watermarks are specified",
"// via options and reads can buffer up up to that point in",
"// parallel to write.",
"when",
"(",
"next",
"(",
"buffer",
".",
"slice",
"(",
"0",
",",
"count",
")",
",",
"state",
")",
",",
"onDrain",
",",
"onError",
")",
"}"
] | Function is used to read out given `count` bytes from the file starting from the current position. Note that `position` is captured. `onChunk` handler is invoked after reading a chunk of a file. | [
"Function",
"is",
"used",
"to",
"read",
"out",
"given",
"count",
"bytes",
"from",
"the",
"file",
"starting",
"from",
"the",
"current",
"position",
".",
"Note",
"that",
"position",
"is",
"captured",
".",
"onChunk",
"handler",
"is",
"invoked",
"after",
"reading",
"a",
"chunk",
"of",
"a",
"file",
"."
] | 4b59070f0ccba17ce35ce419c27e83a2ec152d98 | https://github.com/Gozala/fs-reduce/blob/4b59070f0ccba17ce35ce419c27e83a2ec152d98/reader.js#L49-L65 |
56,203 | Gozala/fs-reduce | reader.js | onDrain | function onDrain(value) {
state = value
// If value is marked as `reduced` no further reads should take place,
// as consumer has finished consumption.
if (isReduced(value)) return next(end)
// If current `position` has reached or passed `finish` mark end a
// collection.
else if (position >= finish) return next(end, state)
// Otherwise read another chunk from the current position & execute
// `onChunk` handler or `onError` if fails. Note that `readChunk`
// reads chunk and returns either number of bytes read or a promise
// for that or an error if failed. Errors will invoke onError handler
// causing collection error and end. `onChunk` will propagate data
// further likely to the writer on the other end.
when(readChunk(fd, buffer, position, size), onChunk, onError)
} | javascript | function onDrain(value) {
state = value
// If value is marked as `reduced` no further reads should take place,
// as consumer has finished consumption.
if (isReduced(value)) return next(end)
// If current `position` has reached or passed `finish` mark end a
// collection.
else if (position >= finish) return next(end, state)
// Otherwise read another chunk from the current position & execute
// `onChunk` handler or `onError` if fails. Note that `readChunk`
// reads chunk and returns either number of bytes read or a promise
// for that or an error if failed. Errors will invoke onError handler
// causing collection error and end. `onChunk` will propagate data
// further likely to the writer on the other end.
when(readChunk(fd, buffer, position, size), onChunk, onError)
} | [
"function",
"onDrain",
"(",
"value",
")",
"{",
"state",
"=",
"value",
"// If value is marked as `reduced` no further reads should take place,",
"// as consumer has finished consumption.",
"if",
"(",
"isReduced",
"(",
"value",
")",
")",
"return",
"next",
"(",
"end",
")",
"// If current `position` has reached or passed `finish` mark end a",
"// collection.",
"else",
"if",
"(",
"position",
">=",
"finish",
")",
"return",
"next",
"(",
"end",
",",
"state",
")",
"// Otherwise read another chunk from the current position & execute",
"// `onChunk` handler or `onError` if fails. Note that `readChunk`",
"// reads chunk and returns either number of bytes read or a promise",
"// for that or an error if failed. Errors will invoke onError handler",
"// causing collection error and end. `onChunk` will propagate data",
"// further likely to the writer on the other end.",
"when",
"(",
"readChunk",
"(",
"fd",
",",
"buffer",
",",
"position",
",",
"size",
")",
",",
"onChunk",
",",
"onError",
")",
"}"
] | Handler is invoked whenever consumer of the collection finished consumption of the previous chunk and can accept more data. It's also passed a new state value that is being accumulated. | [
"Handler",
"is",
"invoked",
"whenever",
"consumer",
"of",
"the",
"collection",
"finished",
"consumption",
"of",
"the",
"previous",
"chunk",
"and",
"can",
"accept",
"more",
"data",
".",
"It",
"s",
"also",
"passed",
"a",
"new",
"state",
"value",
"that",
"is",
"being",
"accumulated",
"."
] | 4b59070f0ccba17ce35ce419c27e83a2ec152d98 | https://github.com/Gozala/fs-reduce/blob/4b59070f0ccba17ce35ce419c27e83a2ec152d98/reader.js#L70-L86 |
56,204 | RnbWd/parse-browserify | lib/relation.js | function(objects) {
if (!_.isArray(objects)) {
objects = [objects];
}
var change = new Parse.Op.Relation(objects, []);
this.parent.set(this.key, change);
this.targetClassName = change._targetClassName;
} | javascript | function(objects) {
if (!_.isArray(objects)) {
objects = [objects];
}
var change = new Parse.Op.Relation(objects, []);
this.parent.set(this.key, change);
this.targetClassName = change._targetClassName;
} | [
"function",
"(",
"objects",
")",
"{",
"if",
"(",
"!",
"_",
".",
"isArray",
"(",
"objects",
")",
")",
"{",
"objects",
"=",
"[",
"objects",
"]",
";",
"}",
"var",
"change",
"=",
"new",
"Parse",
".",
"Op",
".",
"Relation",
"(",
"objects",
",",
"[",
"]",
")",
";",
"this",
".",
"parent",
".",
"set",
"(",
"this",
".",
"key",
",",
"change",
")",
";",
"this",
".",
"targetClassName",
"=",
"change",
".",
"_targetClassName",
";",
"}"
] | Adds a Parse.Object or an array of Parse.Objects to the relation.
@param {} objects The item or items to add. | [
"Adds",
"a",
"Parse",
".",
"Object",
"or",
"an",
"array",
"of",
"Parse",
".",
"Objects",
"to",
"the",
"relation",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/relation.js#L45-L53 |
|
56,205 | RnbWd/parse-browserify | lib/relation.js | function() {
var targetClass;
var query;
if (!this.targetClassName) {
targetClass = Parse.Object._getSubclass(this.parent.className);
query = new Parse.Query(targetClass);
query._extraOptions.redirectClassNameForKey = this.key;
} else {
targetClass = Parse.Object._getSubclass(this.targetClassName);
query = new Parse.Query(targetClass);
}
query._addCondition("$relatedTo", "object", this.parent._toPointer());
query._addCondition("$relatedTo", "key", this.key);
return query;
} | javascript | function() {
var targetClass;
var query;
if (!this.targetClassName) {
targetClass = Parse.Object._getSubclass(this.parent.className);
query = new Parse.Query(targetClass);
query._extraOptions.redirectClassNameForKey = this.key;
} else {
targetClass = Parse.Object._getSubclass(this.targetClassName);
query = new Parse.Query(targetClass);
}
query._addCondition("$relatedTo", "object", this.parent._toPointer());
query._addCondition("$relatedTo", "key", this.key);
return query;
} | [
"function",
"(",
")",
"{",
"var",
"targetClass",
";",
"var",
"query",
";",
"if",
"(",
"!",
"this",
".",
"targetClassName",
")",
"{",
"targetClass",
"=",
"Parse",
".",
"Object",
".",
"_getSubclass",
"(",
"this",
".",
"parent",
".",
"className",
")",
";",
"query",
"=",
"new",
"Parse",
".",
"Query",
"(",
"targetClass",
")",
";",
"query",
".",
"_extraOptions",
".",
"redirectClassNameForKey",
"=",
"this",
".",
"key",
";",
"}",
"else",
"{",
"targetClass",
"=",
"Parse",
".",
"Object",
".",
"_getSubclass",
"(",
"this",
".",
"targetClassName",
")",
";",
"query",
"=",
"new",
"Parse",
".",
"Query",
"(",
"targetClass",
")",
";",
"}",
"query",
".",
"_addCondition",
"(",
"\"$relatedTo\"",
",",
"\"object\"",
",",
"this",
".",
"parent",
".",
"_toPointer",
"(",
")",
")",
";",
"query",
".",
"_addCondition",
"(",
"\"$relatedTo\"",
",",
"\"key\"",
",",
"this",
".",
"key",
")",
";",
"return",
"query",
";",
"}"
] | Returns a Parse.Query that is limited to objects in this
relation.
@return {Parse.Query} | [
"Returns",
"a",
"Parse",
".",
"Query",
"that",
"is",
"limited",
"to",
"objects",
"in",
"this",
"relation",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/relation.js#L82-L97 |
|
56,206 | blake-regalia/rapunzel.js | lib/main/index.js | function(s_line, s_close_delim, z_merge_delim) {
// open block
add(
s_line || '',
z_merge_delim,
true
);
// set close delim
s_close = ('string' === typeof s_close_delim)? s_close_delim: a_closers.slice(-1)[0];
a_closers.push(s_close);
// increase indentation
add.tabs += 1;
} | javascript | function(s_line, s_close_delim, z_merge_delim) {
// open block
add(
s_line || '',
z_merge_delim,
true
);
// set close delim
s_close = ('string' === typeof s_close_delim)? s_close_delim: a_closers.slice(-1)[0];
a_closers.push(s_close);
// increase indentation
add.tabs += 1;
} | [
"function",
"(",
"s_line",
",",
"s_close_delim",
",",
"z_merge_delim",
")",
"{",
"// open block",
"add",
"(",
"s_line",
"||",
"''",
",",
"z_merge_delim",
",",
"true",
")",
";",
"// set close delim",
"s_close",
"=",
"(",
"'string'",
"===",
"typeof",
"s_close_delim",
")",
"?",
"s_close_delim",
":",
"a_closers",
".",
"slice",
"(",
"-",
"1",
")",
"[",
"0",
"]",
";",
"a_closers",
".",
"push",
"(",
"s_close",
")",
";",
"// increase indentation",
"add",
".",
"tabs",
"+=",
"1",
";",
"}"
] | block open helper | [
"block",
"open",
"helper"
] | bc8e231bf248eeaec6aa86f5c9f073d1fe615c1c | https://github.com/blake-regalia/rapunzel.js/blob/bc8e231bf248eeaec6aa86f5c9f073d1fe615c1c/lib/main/index.js#L176-L191 |
|
56,207 | adiwidjaja/frontend-pagebuilder | js/tinymce/plugins/paste/plugin.js | trimHtml | function trimHtml(html) {
function trimSpaces(all, s1, s2) {
// WebKit meant to preserve multiple spaces but instead inserted around all inline tags,
// including the spans with inline styles created on paste
if (!s1 && !s2) {
return ' ';
}
return '\u00a0';
}
html = filter(html, [
/^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig, // Remove anything but the contents within the BODY element
/<!--StartFragment-->|<!--EndFragment-->/g, // Inner fragments (tables from excel on mac)
[/( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g, trimSpaces],
/<br class="Apple-interchange-newline">/g,
/<br>$/i // Trailing BR elements
]);
return html;
} | javascript | function trimHtml(html) {
function trimSpaces(all, s1, s2) {
// WebKit meant to preserve multiple spaces but instead inserted around all inline tags,
// including the spans with inline styles created on paste
if (!s1 && !s2) {
return ' ';
}
return '\u00a0';
}
html = filter(html, [
/^[\s\S]*<body[^>]*>\s*|\s*<\/body[^>]*>[\s\S]*$/ig, // Remove anything but the contents within the BODY element
/<!--StartFragment-->|<!--EndFragment-->/g, // Inner fragments (tables from excel on mac)
[/( ?)<span class="Apple-converted-space">\u00a0<\/span>( ?)/g, trimSpaces],
/<br class="Apple-interchange-newline">/g,
/<br>$/i // Trailing BR elements
]);
return html;
} | [
"function",
"trimHtml",
"(",
"html",
")",
"{",
"function",
"trimSpaces",
"(",
"all",
",",
"s1",
",",
"s2",
")",
"{",
"// WebKit meant to preserve multiple spaces but instead inserted around all inline tags,",
"// including the spans with inline styles created on paste",
"if",
"(",
"!",
"s1",
"&&",
"!",
"s2",
")",
"{",
"return",
"' '",
";",
"}",
"return",
"'\\u00a0'",
";",
"}",
"html",
"=",
"filter",
"(",
"html",
",",
"[",
"/",
"^[\\s\\S]*<body[^>]*>\\s*|\\s*<\\/body[^>]*>[\\s\\S]*$",
"/",
"ig",
",",
"// Remove anything but the contents within the BODY element",
"/",
"<!--StartFragment-->|<!--EndFragment-->",
"/",
"g",
",",
"// Inner fragments (tables from excel on mac)",
"[",
"/",
"( ?)<span class=\"Apple-converted-space\">\\u00a0<\\/span>( ?)",
"/",
"g",
",",
"trimSpaces",
"]",
",",
"/",
"<br class=\"Apple-interchange-newline\">",
"/",
"g",
",",
"/",
"<br>$",
"/",
"i",
"// Trailing BR elements",
"]",
")",
";",
"return",
"html",
";",
"}"
] | Trims the specified HTML by removing all WebKit fragments, all elements wrapping the body trailing BR elements etc.
@param {String} html Html string to trim contents on.
@return {String} Html contents that got trimmed. | [
"Trims",
"the",
"specified",
"HTML",
"by",
"removing",
"all",
"WebKit",
"fragments",
"all",
"elements",
"wrapping",
"the",
"body",
"trailing",
"BR",
"elements",
"etc",
"."
] | a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f | https://github.com/adiwidjaja/frontend-pagebuilder/blob/a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f/js/tinymce/plugins/paste/plugin.js#L392-L412 |
56,208 | adiwidjaja/frontend-pagebuilder | js/tinymce/plugins/paste/plugin.js | getDataTransferItems | function getDataTransferItems(dataTransfer) {
var items = {};
if (dataTransfer) {
// Use old WebKit/IE API
if (dataTransfer.getData) {
var legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
if (legacyText.indexOf(mceInternalUrlPrefix) == -1) {
items['text/plain'] = legacyText;
}
}
}
if (dataTransfer.types) {
for (var i = 0; i < dataTransfer.types.length; i++) {
var contentType = dataTransfer.types[i];
try { // IE11 throws exception when contentType is Files (type is present but data cannot be retrieved via getData())
items[contentType] = dataTransfer.getData(contentType);
} catch (ex) {
items[contentType] = ""; // useless in general, but for consistency across browsers
}
}
}
}
return items;
} | javascript | function getDataTransferItems(dataTransfer) {
var items = {};
if (dataTransfer) {
// Use old WebKit/IE API
if (dataTransfer.getData) {
var legacyText = dataTransfer.getData('Text');
if (legacyText && legacyText.length > 0) {
if (legacyText.indexOf(mceInternalUrlPrefix) == -1) {
items['text/plain'] = legacyText;
}
}
}
if (dataTransfer.types) {
for (var i = 0; i < dataTransfer.types.length; i++) {
var contentType = dataTransfer.types[i];
try { // IE11 throws exception when contentType is Files (type is present but data cannot be retrieved via getData())
items[contentType] = dataTransfer.getData(contentType);
} catch (ex) {
items[contentType] = ""; // useless in general, but for consistency across browsers
}
}
}
}
return items;
} | [
"function",
"getDataTransferItems",
"(",
"dataTransfer",
")",
"{",
"var",
"items",
"=",
"{",
"}",
";",
"if",
"(",
"dataTransfer",
")",
"{",
"// Use old WebKit/IE API",
"if",
"(",
"dataTransfer",
".",
"getData",
")",
"{",
"var",
"legacyText",
"=",
"dataTransfer",
".",
"getData",
"(",
"'Text'",
")",
";",
"if",
"(",
"legacyText",
"&&",
"legacyText",
".",
"length",
">",
"0",
")",
"{",
"if",
"(",
"legacyText",
".",
"indexOf",
"(",
"mceInternalUrlPrefix",
")",
"==",
"-",
"1",
")",
"{",
"items",
"[",
"'text/plain'",
"]",
"=",
"legacyText",
";",
"}",
"}",
"}",
"if",
"(",
"dataTransfer",
".",
"types",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"dataTransfer",
".",
"types",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"contentType",
"=",
"dataTransfer",
".",
"types",
"[",
"i",
"]",
";",
"try",
"{",
"// IE11 throws exception when contentType is Files (type is present but data cannot be retrieved via getData())",
"items",
"[",
"contentType",
"]",
"=",
"dataTransfer",
".",
"getData",
"(",
"contentType",
")",
";",
"}",
"catch",
"(",
"ex",
")",
"{",
"items",
"[",
"contentType",
"]",
"=",
"\"\"",
";",
"// useless in general, but for consistency across browsers",
"}",
"}",
"}",
"}",
"return",
"items",
";",
"}"
] | Gets various content types out of a datatransfer object.
@param {DataTransfer} dataTransfer Event fired on paste.
@return {Object} Object with mime types and data for those mime types. | [
"Gets",
"various",
"content",
"types",
"out",
"of",
"a",
"datatransfer",
"object",
"."
] | a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f | https://github.com/adiwidjaja/frontend-pagebuilder/blob/a08caa06cd9f919d575eb68f0d6b56fdedfb7d0f/js/tinymce/plugins/paste/plugin.js#L1033-L1060 |
56,209 | floriancargoet/jasmine-async-errors | index.js | function (originalIt) {
return function it(desc, cb) {
if (cb.length === 0) {
originalIt(desc, cb);
} else {
originalIt(desc, wrapInTryCatch(cb));
}
};
} | javascript | function (originalIt) {
return function it(desc, cb) {
if (cb.length === 0) {
originalIt(desc, cb);
} else {
originalIt(desc, wrapInTryCatch(cb));
}
};
} | [
"function",
"(",
"originalIt",
")",
"{",
"return",
"function",
"it",
"(",
"desc",
",",
"cb",
")",
"{",
"if",
"(",
"cb",
".",
"length",
"===",
"0",
")",
"{",
"originalIt",
"(",
"desc",
",",
"cb",
")",
";",
"}",
"else",
"{",
"originalIt",
"(",
"desc",
",",
"wrapInTryCatch",
"(",
"cb",
")",
")",
";",
"}",
"}",
";",
"}"
] | wrap jasmine's "it" function so that each
test is wrapped in a trycatch handler | [
"wrap",
"jasmine",
"s",
"it",
"function",
"so",
"that",
"each",
"test",
"is",
"wrapped",
"in",
"a",
"trycatch",
"handler"
] | 496bccb0f6c7feb803bf2767cf7762d3cb0c5198 | https://github.com/floriancargoet/jasmine-async-errors/blob/496bccb0f6c7feb803bf2767cf7762d3cb0c5198/index.js#L28-L36 |
|
56,210 | michaelpb/elmoed | lib/adaptors/riotjs.js | mount | function mount(mountLocation, tagname, props) {
// return riot.mount(mountLocation, tagname, props)[0];
const id = makeUID(`riotjs_mount_${tagname}`);
const fauxTag = `<${tagname} data-elmoed-editor="${tagname}" id="${id}">
</${tagname}>`;
// Loop through all sub-mounted editors that might already exist in the
// mount location and properly unmount them for clean up
const selector = '[data-elmoed-editor]';
const subEditors = mountLocation.querySelectorAll(selector);
for (const submountedEditor of subEditors) {
// _tag learned from: https://github.com/riot/riot/issues/934
// Might not be maintained, hence the check for its existence
if (!submountedEditor._tag) {
console.error('Unsuccessful unmount tag: Bad Riot.js version?');
continue;
}
submountedEditor._tag.unmount();
}
/* eslint-disable no-param-reassign */
// Clear any initial HTML
mountLocation.innerHTML = '';
// Add in the HTML in the right location for riot to find
mountLocation.innerHTML = fauxTag;
// Finally, mount the element where it belongs
const tagInstance = riot.mount(`#${id}`, props)[0];
tagInstance.on('before-unmount', () => {
props.clearAll(); // ensure everything gets cleared
});
return tagInstance;
} | javascript | function mount(mountLocation, tagname, props) {
// return riot.mount(mountLocation, tagname, props)[0];
const id = makeUID(`riotjs_mount_${tagname}`);
const fauxTag = `<${tagname} data-elmoed-editor="${tagname}" id="${id}">
</${tagname}>`;
// Loop through all sub-mounted editors that might already exist in the
// mount location and properly unmount them for clean up
const selector = '[data-elmoed-editor]';
const subEditors = mountLocation.querySelectorAll(selector);
for (const submountedEditor of subEditors) {
// _tag learned from: https://github.com/riot/riot/issues/934
// Might not be maintained, hence the check for its existence
if (!submountedEditor._tag) {
console.error('Unsuccessful unmount tag: Bad Riot.js version?');
continue;
}
submountedEditor._tag.unmount();
}
/* eslint-disable no-param-reassign */
// Clear any initial HTML
mountLocation.innerHTML = '';
// Add in the HTML in the right location for riot to find
mountLocation.innerHTML = fauxTag;
// Finally, mount the element where it belongs
const tagInstance = riot.mount(`#${id}`, props)[0];
tagInstance.on('before-unmount', () => {
props.clearAll(); // ensure everything gets cleared
});
return tagInstance;
} | [
"function",
"mount",
"(",
"mountLocation",
",",
"tagname",
",",
"props",
")",
"{",
"// return riot.mount(mountLocation, tagname, props)[0];",
"const",
"id",
"=",
"makeUID",
"(",
"`",
"${",
"tagname",
"}",
"`",
")",
";",
"const",
"fauxTag",
"=",
"`",
"${",
"tagname",
"}",
"${",
"tagname",
"}",
"${",
"id",
"}",
"${",
"tagname",
"}",
"`",
";",
"// Loop through all sub-mounted editors that might already exist in the",
"// mount location and properly unmount them for clean up",
"const",
"selector",
"=",
"'[data-elmoed-editor]'",
";",
"const",
"subEditors",
"=",
"mountLocation",
".",
"querySelectorAll",
"(",
"selector",
")",
";",
"for",
"(",
"const",
"submountedEditor",
"of",
"subEditors",
")",
"{",
"// _tag learned from: https://github.com/riot/riot/issues/934",
"// Might not be maintained, hence the check for its existence",
"if",
"(",
"!",
"submountedEditor",
".",
"_tag",
")",
"{",
"console",
".",
"error",
"(",
"'Unsuccessful unmount tag: Bad Riot.js version?'",
")",
";",
"continue",
";",
"}",
"submountedEditor",
".",
"_tag",
".",
"unmount",
"(",
")",
";",
"}",
"/* eslint-disable no-param-reassign */",
"// Clear any initial HTML",
"mountLocation",
".",
"innerHTML",
"=",
"''",
";",
"// Add in the HTML in the right location for riot to find",
"mountLocation",
".",
"innerHTML",
"=",
"fauxTag",
";",
"// Finally, mount the element where it belongs",
"const",
"tagInstance",
"=",
"riot",
".",
"mount",
"(",
"`",
"${",
"id",
"}",
"`",
",",
"props",
")",
"[",
"0",
"]",
";",
"tagInstance",
".",
"on",
"(",
"'before-unmount'",
",",
"(",
")",
"=>",
"{",
"props",
".",
"clearAll",
"(",
")",
";",
"// ensure everything gets cleared",
"}",
")",
";",
"return",
"tagInstance",
";",
"}"
] | riot.js adaptor | [
"riot",
".",
"js",
"adaptor"
] | f1f51a06fb5c9703dcd36e320472572b311e2649 | https://github.com/michaelpb/elmoed/blob/f1f51a06fb5c9703dcd36e320472572b311e2649/lib/adaptors/riotjs.js#L25-L58 |
56,211 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/indent/plugin.js | function( editor, name, isIndent ) {
this.name = name;
this.editor = editor;
/**
* An object of jobs handled by the command. Each job consists
* of two functions: `refresh` and `exec` as well as the execution priority.
*
* * The `refresh` function determines whether a job is doable for
* a particular context. These functions are executed in the
* order of priorities, one by one, for all plugins that registered
* jobs. As jobs are related to generic commands, refreshing
* occurs when the global command is firing the `refresh` event.
*
* **Note**: This function must return either {@link CKEDITOR#TRISTATE_DISABLED}
* or {@link CKEDITOR#TRISTATE_OFF}.
*
* * The `exec` function modifies the DOM if possible. Just like
* `refresh`, `exec` functions are executed in the order of priorities
* while the generic command is executed. This function is not executed
* if `refresh` for this job returned {@link CKEDITOR#TRISTATE_DISABLED}.
*
* **Note**: This function must return a Boolean value, indicating whether it
* was successful. If a job was successful, then no other jobs are being executed.
*
* Sample definition:
*
* command.jobs = {
* // Priority = 20.
* '20': {
* refresh( editor, path ) {
* if ( condition )
* return CKEDITOR.TRISTATE_OFF;
* else
* return CKEDITOR.TRISTATE_DISABLED;
* },
* exec( editor ) {
* // DOM modified! This was OK.
* return true;
* }
* },
* // Priority = 60. This job is done later.
* '60': {
* // Another job.
* }
* };
*
* For additional information, please check comments for
* the `setupGenericListeners` function.
*
* @readonly
* @property {Object} [={}]
*/
this.jobs = {};
/**
* Determines whether the editor that the command belongs to has
* {@link CKEDITOR.config#enterMode config.enterMode} set to {@link CKEDITOR#ENTER_BR}.
*
* @readonly
* @see CKEDITOR.config#enterMode
* @property {Boolean} [=false]
*/
this.enterBr = editor.config.enterMode == CKEDITOR.ENTER_BR;
/**
* Determines whether the command belongs to the indentation family.
* Otherwise it is assumed to be an outdenting command.
*
* @readonly
* @property {Boolean} [=false]
*/
this.isIndent = !!isIndent;
/**
* The name of the global command related to this one.
*
* @readonly
*/
this.relatedGlobal = isIndent ? 'indent' : 'outdent';
/**
* A keystroke associated with this command (*Tab* or *Shift+Tab*).
*
* @readonly
*/
this.indentKey = isIndent ? 9 : CKEDITOR.SHIFT + 9;
/**
* Stores created markers for the command so they can eventually be
* purged after the `exec` function is run.
*/
this.database = {};
} | javascript | function( editor, name, isIndent ) {
this.name = name;
this.editor = editor;
/**
* An object of jobs handled by the command. Each job consists
* of two functions: `refresh` and `exec` as well as the execution priority.
*
* * The `refresh` function determines whether a job is doable for
* a particular context. These functions are executed in the
* order of priorities, one by one, for all plugins that registered
* jobs. As jobs are related to generic commands, refreshing
* occurs when the global command is firing the `refresh` event.
*
* **Note**: This function must return either {@link CKEDITOR#TRISTATE_DISABLED}
* or {@link CKEDITOR#TRISTATE_OFF}.
*
* * The `exec` function modifies the DOM if possible. Just like
* `refresh`, `exec` functions are executed in the order of priorities
* while the generic command is executed. This function is not executed
* if `refresh` for this job returned {@link CKEDITOR#TRISTATE_DISABLED}.
*
* **Note**: This function must return a Boolean value, indicating whether it
* was successful. If a job was successful, then no other jobs are being executed.
*
* Sample definition:
*
* command.jobs = {
* // Priority = 20.
* '20': {
* refresh( editor, path ) {
* if ( condition )
* return CKEDITOR.TRISTATE_OFF;
* else
* return CKEDITOR.TRISTATE_DISABLED;
* },
* exec( editor ) {
* // DOM modified! This was OK.
* return true;
* }
* },
* // Priority = 60. This job is done later.
* '60': {
* // Another job.
* }
* };
*
* For additional information, please check comments for
* the `setupGenericListeners` function.
*
* @readonly
* @property {Object} [={}]
*/
this.jobs = {};
/**
* Determines whether the editor that the command belongs to has
* {@link CKEDITOR.config#enterMode config.enterMode} set to {@link CKEDITOR#ENTER_BR}.
*
* @readonly
* @see CKEDITOR.config#enterMode
* @property {Boolean} [=false]
*/
this.enterBr = editor.config.enterMode == CKEDITOR.ENTER_BR;
/**
* Determines whether the command belongs to the indentation family.
* Otherwise it is assumed to be an outdenting command.
*
* @readonly
* @property {Boolean} [=false]
*/
this.isIndent = !!isIndent;
/**
* The name of the global command related to this one.
*
* @readonly
*/
this.relatedGlobal = isIndent ? 'indent' : 'outdent';
/**
* A keystroke associated with this command (*Tab* or *Shift+Tab*).
*
* @readonly
*/
this.indentKey = isIndent ? 9 : CKEDITOR.SHIFT + 9;
/**
* Stores created markers for the command so they can eventually be
* purged after the `exec` function is run.
*/
this.database = {};
} | [
"function",
"(",
"editor",
",",
"name",
",",
"isIndent",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"editor",
"=",
"editor",
";",
"/**\r\n\t\t\t * An object of jobs handled by the command. Each job consists\r\n\t\t\t * of two functions: `refresh` and `exec` as well as the execution priority.\r\n\t\t\t *\r\n\t\t\t *\t* The `refresh` function determines whether a job is doable for\r\n\t\t\t *\t a particular context. These functions are executed in the\r\n\t\t\t *\t order of priorities, one by one, for all plugins that registered\r\n\t\t\t *\t jobs. As jobs are related to generic commands, refreshing\r\n\t\t\t *\t occurs when the global command is firing the `refresh` event.\r\n\t\t\t *\r\n\t\t\t *\t **Note**: This function must return either {@link CKEDITOR#TRISTATE_DISABLED}\r\n\t\t\t *\t or {@link CKEDITOR#TRISTATE_OFF}.\r\n\t\t\t *\r\n\t\t\t *\t* The `exec` function modifies the DOM if possible. Just like\r\n\t\t\t *\t `refresh`, `exec` functions are executed in the order of priorities\r\n\t\t\t *\t while the generic command is executed. This function is not executed\r\n\t\t\t *\t if `refresh` for this job returned {@link CKEDITOR#TRISTATE_DISABLED}.\r\n\t\t\t *\r\n\t\t\t *\t **Note**: This function must return a Boolean value, indicating whether it\r\n\t\t\t *\t was successful. If a job was successful, then no other jobs are being executed.\r\n\t\t\t *\r\n\t\t\t * Sample definition:\r\n\t\t\t *\r\n\t\t\t *\t\tcommand.jobs = {\r\n\t\t\t *\t\t\t// Priority = 20.\r\n\t\t\t *\t\t\t'20': {\r\n\t\t\t *\t\t\t\trefresh( editor, path ) {\r\n\t\t\t *\t\t\t\t\tif ( condition )\r\n\t\t\t *\t\t\t\t\t\treturn CKEDITOR.TRISTATE_OFF;\r\n\t\t\t *\t\t\t\t\telse\r\n\t\t\t *\t\t\t\t\t\treturn CKEDITOR.TRISTATE_DISABLED;\r\n\t\t\t *\t\t\t\t},\r\n\t\t\t *\t\t\t\texec( editor ) {\r\n\t\t\t *\t\t\t\t\t// DOM modified! This was OK.\r\n\t\t\t *\t\t\t\t\treturn true;\r\n\t\t\t *\t\t\t\t}\r\n\t\t\t *\t\t\t},\r\n\t\t\t *\t\t\t// Priority = 60. This job is done later.\r\n\t\t\t *\t\t\t'60': {\r\n\t\t\t *\t\t\t\t// Another job.\r\n\t\t\t *\t\t\t}\r\n\t\t\t *\t\t};\r\n\t\t\t *\r\n\t\t\t * For additional information, please check comments for\r\n\t\t\t * the `setupGenericListeners` function.\r\n\t\t\t *\r\n\t\t\t * @readonly\r\n\t\t\t * @property {Object} [={}]\r\n\t\t\t */",
"this",
".",
"jobs",
"=",
"{",
"}",
";",
"/**\r\n\t\t\t * Determines whether the editor that the command belongs to has\r\n\t\t\t * {@link CKEDITOR.config#enterMode config.enterMode} set to {@link CKEDITOR#ENTER_BR}.\r\n\t\t\t *\r\n\t\t\t * @readonly\r\n\t\t\t * @see CKEDITOR.config#enterMode\r\n\t\t\t * @property {Boolean} [=false]\r\n\t\t\t */",
"this",
".",
"enterBr",
"=",
"editor",
".",
"config",
".",
"enterMode",
"==",
"CKEDITOR",
".",
"ENTER_BR",
";",
"/**\r\n\t\t\t * Determines whether the command belongs to the indentation family.\r\n\t\t\t * Otherwise it is assumed to be an outdenting command.\r\n\t\t\t *\r\n\t\t\t * @readonly\r\n\t\t\t * @property {Boolean} [=false]\r\n\t\t\t */",
"this",
".",
"isIndent",
"=",
"!",
"!",
"isIndent",
";",
"/**\r\n\t\t\t * The name of the global command related to this one.\r\n\t\t\t *\r\n\t\t\t * @readonly\r\n\t\t\t */",
"this",
".",
"relatedGlobal",
"=",
"isIndent",
"?",
"'indent'",
":",
"'outdent'",
";",
"/**\r\n\t\t\t * A keystroke associated with this command (*Tab* or *Shift+Tab*).\r\n\t\t\t *\r\n\t\t\t * @readonly\r\n\t\t\t */",
"this",
".",
"indentKey",
"=",
"isIndent",
"?",
"9",
":",
"CKEDITOR",
".",
"SHIFT",
"+",
"9",
";",
"/**\r\n\t\t\t * Stores created markers for the command so they can eventually be\r\n\t\t\t * purged after the `exec` function is run.\r\n\t\t\t */",
"this",
".",
"database",
"=",
"{",
"}",
";",
"}"
] | A base class for specific indentation command definitions responsible for
handling a pre-defined set of elements i.e. indentlist for lists or
indentblock for text block elements.
Commands of this class perform indentation operations and modify the DOM structure.
They listen for events fired by {@link CKEDITOR.plugins.indent.genericDefinition}
and execute defined actions.
**NOTE**: This is not an {@link CKEDITOR.command editor command}.
Context-specific commands are internal, for indentation system only.
@class CKEDITOR.plugins.indent.specificDefinition
@param {CKEDITOR.editor} editor The editor instance this command will be
applied to.
@param {String} name The name of the command.
@param {Boolean} [isIndent] Defines the command as indenting or outdenting. | [
"A",
"base",
"class",
"for",
"specific",
"indentation",
"command",
"definitions",
"responsible",
"for",
"handling",
"a",
"pre",
"-",
"defined",
"set",
"of",
"elements",
"i",
".",
"e",
".",
"indentlist",
"for",
"lists",
"or",
"indentblock",
"for",
"text",
"block",
"elements",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/indent/plugin.js#L143-L236 |
|
56,212 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/indent/plugin.js | function( editor, commands ) {
editor.on( 'pluginsLoaded', function() {
for ( var name in commands ) {
( function( editor, command ) {
var relatedGlobal = editor.getCommand( command.relatedGlobal );
for ( var priority in command.jobs ) {
// Observe generic exec event and execute command when necessary.
// If the command was successfully handled by the command and
// DOM has been modified, stop event propagation so no other plugin
// will bother. Job is done.
relatedGlobal.on( 'exec', function( evt ) {
if ( evt.data.done )
return;
// Make sure that anything this command will do is invisible
// for undoManager. What undoManager only can see and
// remember is the execution of the global command (relatedGlobal).
editor.fire( 'lockSnapshot' );
if ( command.execJob( editor, priority ) )
evt.data.done = true;
editor.fire( 'unlockSnapshot' );
// Clean up the markers.
CKEDITOR.dom.element.clearAllMarkers( command.database );
}, this, null, priority );
// Observe generic refresh event and force command refresh.
// Once refreshed, save command state in event data
// so generic command plugin can update its own state and UI.
relatedGlobal.on( 'refresh', function( evt ) {
if ( !evt.data.states )
evt.data.states = {};
evt.data.states[ command.name + '@' + priority ] =
command.refreshJob( editor, priority, evt.data.path );
}, this, null, priority );
}
// Since specific indent commands have no UI elements,
// they need to be manually registered as a editor feature.
editor.addFeature( command );
} )( this, commands[ name ] );
}
} );
} | javascript | function( editor, commands ) {
editor.on( 'pluginsLoaded', function() {
for ( var name in commands ) {
( function( editor, command ) {
var relatedGlobal = editor.getCommand( command.relatedGlobal );
for ( var priority in command.jobs ) {
// Observe generic exec event and execute command when necessary.
// If the command was successfully handled by the command and
// DOM has been modified, stop event propagation so no other plugin
// will bother. Job is done.
relatedGlobal.on( 'exec', function( evt ) {
if ( evt.data.done )
return;
// Make sure that anything this command will do is invisible
// for undoManager. What undoManager only can see and
// remember is the execution of the global command (relatedGlobal).
editor.fire( 'lockSnapshot' );
if ( command.execJob( editor, priority ) )
evt.data.done = true;
editor.fire( 'unlockSnapshot' );
// Clean up the markers.
CKEDITOR.dom.element.clearAllMarkers( command.database );
}, this, null, priority );
// Observe generic refresh event and force command refresh.
// Once refreshed, save command state in event data
// so generic command plugin can update its own state and UI.
relatedGlobal.on( 'refresh', function( evt ) {
if ( !evt.data.states )
evt.data.states = {};
evt.data.states[ command.name + '@' + priority ] =
command.refreshJob( editor, priority, evt.data.path );
}, this, null, priority );
}
// Since specific indent commands have no UI elements,
// they need to be manually registered as a editor feature.
editor.addFeature( command );
} )( this, commands[ name ] );
}
} );
} | [
"function",
"(",
"editor",
",",
"commands",
")",
"{",
"editor",
".",
"on",
"(",
"'pluginsLoaded'",
",",
"function",
"(",
")",
"{",
"for",
"(",
"var",
"name",
"in",
"commands",
")",
"{",
"(",
"function",
"(",
"editor",
",",
"command",
")",
"{",
"var",
"relatedGlobal",
"=",
"editor",
".",
"getCommand",
"(",
"command",
".",
"relatedGlobal",
")",
";",
"for",
"(",
"var",
"priority",
"in",
"command",
".",
"jobs",
")",
"{",
"// Observe generic exec event and execute command when necessary.\r",
"// If the command was successfully handled by the command and\r",
"// DOM has been modified, stop event propagation so no other plugin\r",
"// will bother. Job is done.\r",
"relatedGlobal",
".",
"on",
"(",
"'exec'",
",",
"function",
"(",
"evt",
")",
"{",
"if",
"(",
"evt",
".",
"data",
".",
"done",
")",
"return",
";",
"// Make sure that anything this command will do is invisible\r",
"// for undoManager. What undoManager only can see and\r",
"// remember is the execution of the global command (relatedGlobal).\r",
"editor",
".",
"fire",
"(",
"'lockSnapshot'",
")",
";",
"if",
"(",
"command",
".",
"execJob",
"(",
"editor",
",",
"priority",
")",
")",
"evt",
".",
"data",
".",
"done",
"=",
"true",
";",
"editor",
".",
"fire",
"(",
"'unlockSnapshot'",
")",
";",
"// Clean up the markers.\r",
"CKEDITOR",
".",
"dom",
".",
"element",
".",
"clearAllMarkers",
"(",
"command",
".",
"database",
")",
";",
"}",
",",
"this",
",",
"null",
",",
"priority",
")",
";",
"// Observe generic refresh event and force command refresh.\r",
"// Once refreshed, save command state in event data\r",
"// so generic command plugin can update its own state and UI.\r",
"relatedGlobal",
".",
"on",
"(",
"'refresh'",
",",
"function",
"(",
"evt",
")",
"{",
"if",
"(",
"!",
"evt",
".",
"data",
".",
"states",
")",
"evt",
".",
"data",
".",
"states",
"=",
"{",
"}",
";",
"evt",
".",
"data",
".",
"states",
"[",
"command",
".",
"name",
"+",
"'@'",
"+",
"priority",
"]",
"=",
"command",
".",
"refreshJob",
"(",
"editor",
",",
"priority",
",",
"evt",
".",
"data",
".",
"path",
")",
";",
"}",
",",
"this",
",",
"null",
",",
"priority",
")",
";",
"}",
"// Since specific indent commands have no UI elements,\r",
"// they need to be manually registered as a editor feature.\r",
"editor",
".",
"addFeature",
"(",
"command",
")",
";",
"}",
")",
"(",
"this",
",",
"commands",
"[",
"name",
"]",
")",
";",
"}",
"}",
")",
";",
"}"
] | Registers content-specific commands as a part of the indentation system
directed by generic commands. Once a command is registered,
it listens for events of a related generic command.
CKEDITOR.plugins.indent.registerCommands( editor, {
'indentlist': new indentListCommand( editor, 'indentlist' ),
'outdentlist': new indentListCommand( editor, 'outdentlist' )
} );
Content-specific commands listen for the generic command's `exec` and
try to execute their own jobs, one after another. If some execution is
successful, `evt.data.done` is set so no more jobs (commands) are involved.
Content-specific commands also listen for the generic command's `refresh`
and fill the `evt.data.states` object with states of jobs. A generic command
uses this data to determine its own state and to update the UI.
@member CKEDITOR.plugins.indent
@param {CKEDITOR.editor} editor The editor instance this command is
applied to.
@param {Object} commands An object of {@link CKEDITOR.command}. | [
"Registers",
"content",
"-",
"specific",
"commands",
"as",
"a",
"part",
"of",
"the",
"indentation",
"system",
"directed",
"by",
"generic",
"commands",
".",
"Once",
"a",
"command",
"is",
"registered",
"it",
"listens",
"for",
"events",
"of",
"a",
"related",
"generic",
"command",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/indent/plugin.js#L261-L308 |
|
56,213 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/indent/plugin.js | function( editor, priority ) {
var job = this.jobs[ priority ];
if ( job.state != TRISTATE_DISABLED )
return job.exec.call( this, editor );
} | javascript | function( editor, priority ) {
var job = this.jobs[ priority ];
if ( job.state != TRISTATE_DISABLED )
return job.exec.call( this, editor );
} | [
"function",
"(",
"editor",
",",
"priority",
")",
"{",
"var",
"job",
"=",
"this",
".",
"jobs",
"[",
"priority",
"]",
";",
"if",
"(",
"job",
".",
"state",
"!=",
"TRISTATE_DISABLED",
")",
"return",
"job",
".",
"exec",
".",
"call",
"(",
"this",
",",
"editor",
")",
";",
"}"
] | Executes the content-specific procedure if the context is correct.
It calls the `exec` function of a job of the given `priority`
that modifies the DOM.
@param {CKEDITOR.editor} editor The editor instance this command
will be applied to.
@param {Number} priority The priority of the job to be executed.
@returns {Boolean} Indicates whether the job was successful. | [
"Executes",
"the",
"content",
"-",
"specific",
"procedure",
"if",
"the",
"context",
"is",
"correct",
".",
"It",
"calls",
"the",
"exec",
"function",
"of",
"a",
"job",
"of",
"the",
"given",
"priority",
"that",
"modifies",
"the",
"DOM",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/indent/plugin.js#L328-L333 |
|
56,214 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/indent/plugin.js | setupGenericListeners | function setupGenericListeners( editor, command ) {
var selection, bookmarks;
// Set the command state according to content-specific
// command states.
command.on( 'refresh', function( evt ) {
// If no state comes with event data, disable command.
var states = [ TRISTATE_DISABLED ];
for ( var s in evt.data.states )
states.push( evt.data.states[ s ] );
this.setState( CKEDITOR.tools.search( states, TRISTATE_OFF ) ?
TRISTATE_OFF
:
TRISTATE_DISABLED );
}, command, null, 100 );
// Initialization. Save bookmarks and mark event as not handled
// by any plugin (command) yet.
command.on( 'exec', function( evt ) {
selection = editor.getSelection();
bookmarks = selection.createBookmarks( 1 );
// Mark execution as not handled yet.
if ( !evt.data )
evt.data = {};
evt.data.done = false;
}, command, null, 0 );
// Housekeeping. Make sure selectionChange will be called.
// Also re-select previously saved bookmarks.
command.on( 'exec', function( evt ) {
editor.forceNextSelectionCheck();
selection.selectBookmarks( bookmarks );
}, command, null, 100 );
} | javascript | function setupGenericListeners( editor, command ) {
var selection, bookmarks;
// Set the command state according to content-specific
// command states.
command.on( 'refresh', function( evt ) {
// If no state comes with event data, disable command.
var states = [ TRISTATE_DISABLED ];
for ( var s in evt.data.states )
states.push( evt.data.states[ s ] );
this.setState( CKEDITOR.tools.search( states, TRISTATE_OFF ) ?
TRISTATE_OFF
:
TRISTATE_DISABLED );
}, command, null, 100 );
// Initialization. Save bookmarks and mark event as not handled
// by any plugin (command) yet.
command.on( 'exec', function( evt ) {
selection = editor.getSelection();
bookmarks = selection.createBookmarks( 1 );
// Mark execution as not handled yet.
if ( !evt.data )
evt.data = {};
evt.data.done = false;
}, command, null, 0 );
// Housekeeping. Make sure selectionChange will be called.
// Also re-select previously saved bookmarks.
command.on( 'exec', function( evt ) {
editor.forceNextSelectionCheck();
selection.selectBookmarks( bookmarks );
}, command, null, 100 );
} | [
"function",
"setupGenericListeners",
"(",
"editor",
",",
"command",
")",
"{",
"var",
"selection",
",",
"bookmarks",
";",
"// Set the command state according to content-specific\r",
"// command states.\r",
"command",
".",
"on",
"(",
"'refresh'",
",",
"function",
"(",
"evt",
")",
"{",
"// If no state comes with event data, disable command.\r",
"var",
"states",
"=",
"[",
"TRISTATE_DISABLED",
"]",
";",
"for",
"(",
"var",
"s",
"in",
"evt",
".",
"data",
".",
"states",
")",
"states",
".",
"push",
"(",
"evt",
".",
"data",
".",
"states",
"[",
"s",
"]",
")",
";",
"this",
".",
"setState",
"(",
"CKEDITOR",
".",
"tools",
".",
"search",
"(",
"states",
",",
"TRISTATE_OFF",
")",
"?",
"TRISTATE_OFF",
":",
"TRISTATE_DISABLED",
")",
";",
"}",
",",
"command",
",",
"null",
",",
"100",
")",
";",
"// Initialization. Save bookmarks and mark event as not handled\r",
"// by any plugin (command) yet.\r",
"command",
".",
"on",
"(",
"'exec'",
",",
"function",
"(",
"evt",
")",
"{",
"selection",
"=",
"editor",
".",
"getSelection",
"(",
")",
";",
"bookmarks",
"=",
"selection",
".",
"createBookmarks",
"(",
"1",
")",
";",
"// Mark execution as not handled yet.\r",
"if",
"(",
"!",
"evt",
".",
"data",
")",
"evt",
".",
"data",
"=",
"{",
"}",
";",
"evt",
".",
"data",
".",
"done",
"=",
"false",
";",
"}",
",",
"command",
",",
"null",
",",
"0",
")",
";",
"// Housekeeping. Make sure selectionChange will be called.\r",
"// Also re-select previously saved bookmarks.\r",
"command",
".",
"on",
"(",
"'exec'",
",",
"function",
"(",
"evt",
")",
"{",
"editor",
".",
"forceNextSelectionCheck",
"(",
")",
";",
"selection",
".",
"selectBookmarks",
"(",
"bookmarks",
")",
";",
"}",
",",
"command",
",",
"null",
",",
"100",
")",
";",
"}"
] | Attaches event listeners for this generic command. Since the indentation
system is event-oriented, generic commands communicate with
content-specific commands using the `exec` and `refresh` events.
Listener priorities are crucial. Different indentation phases
are executed with different priorities.
For the `exec` event:
* 0: Selection and bookmarks are saved by the generic command.
* 1-99: Content-specific commands try to indent the code by executing
their own jobs ({@link CKEDITOR.plugins.indent.specificDefinition#jobs}).
* 100: Bookmarks are re-selected by the generic command.
The visual interpretation looks as follows:
+------------------+
| Exec event fired |
+------ + ---------+
|
0 -<----------+ Selection and bookmarks saved.
|
|
25 -<---+ Exec 1st job of plugin#1 (return false, continuing...).
|
|
50 -<---+ Exec 1st job of plugin#2 (return false, continuing...).
|
|
75 -<---+ Exec 2nd job of plugin#1 (only if plugin#2 failed).
|
|
100 -<-----------+ Re-select bookmarks, clean-up.
|
+-------- v ----------+
| Exec event finished |
+---------------------+
For the `refresh` event:
* <100: Content-specific commands refresh their job states according
to the given path. Jobs save their states in the `evt.data.states` object
passed along with the event. This can be either {@link CKEDITOR#TRISTATE_DISABLED}
or {@link CKEDITOR#TRISTATE_OFF}.
* 100: Command state is determined according to what states
have been returned by content-specific jobs (`evt.data.states`).
UI elements are updated at this stage.
**Note**: If there is at least one job with the {@link CKEDITOR#TRISTATE_OFF} state,
then the generic command state is also {@link CKEDITOR#TRISTATE_OFF}. Otherwise,
the command state is {@link CKEDITOR#TRISTATE_DISABLED}.
@param {CKEDITOR.command} command The command to be set up.
@private | [
"Attaches",
"event",
"listeners",
"for",
"this",
"generic",
"command",
".",
"Since",
"the",
"indentation",
"system",
"is",
"event",
"-",
"oriented",
"generic",
"commands",
"communicate",
"with",
"content",
"-",
"specific",
"commands",
"using",
"the",
"exec",
"and",
"refresh",
"events",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/indent/plugin.js#L424-L461 |
56,215 | j-/ok | ok.js | function (event, fn, context) {
this._events = this._events || {};
var e = this._events[event] || (this._events[event] = []);
e.push([fn, context]);
} | javascript | function (event, fn, context) {
this._events = this._events || {};
var e = this._events[event] || (this._events[event] = []);
e.push([fn, context]);
} | [
"function",
"(",
"event",
",",
"fn",
",",
"context",
")",
"{",
"this",
".",
"_events",
"=",
"this",
".",
"_events",
"||",
"{",
"}",
";",
"var",
"e",
"=",
"this",
".",
"_events",
"[",
"event",
"]",
"||",
"(",
"this",
".",
"_events",
"[",
"event",
"]",
"=",
"[",
"]",
")",
";",
"e",
".",
"push",
"(",
"[",
"fn",
",",
"context",
"]",
")",
";",
"}"
] | Adds a callback to the event queue which is executed when an event fires
@param {string} event Event name
@param {Function} fn Callback function. Executed when event fires.
@param {*=} context Optional context to apply to callback | [
"Adds",
"a",
"callback",
"to",
"the",
"event",
"queue",
"which",
"is",
"executed",
"when",
"an",
"event",
"fires"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L442-L446 |
|
56,216 | j-/ok | ok.js | function (obj, event, fn, context) {
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = eventIndex++);
listeningTo[id] = obj;
if (!fn && typeof event === 'object') {
fn = this;
}
if (!context) {
context = this;
}
obj.on(event, fn, context);
} | javascript | function (obj, event, fn, context) {
var listeningTo = this._listeningTo || (this._listeningTo = {});
var id = obj._listenId || (obj._listenId = eventIndex++);
listeningTo[id] = obj;
if (!fn && typeof event === 'object') {
fn = this;
}
if (!context) {
context = this;
}
obj.on(event, fn, context);
} | [
"function",
"(",
"obj",
",",
"event",
",",
"fn",
",",
"context",
")",
"{",
"var",
"listeningTo",
"=",
"this",
".",
"_listeningTo",
"||",
"(",
"this",
".",
"_listeningTo",
"=",
"{",
"}",
")",
";",
"var",
"id",
"=",
"obj",
".",
"_listenId",
"||",
"(",
"obj",
".",
"_listenId",
"=",
"eventIndex",
"++",
")",
";",
"listeningTo",
"[",
"id",
"]",
"=",
"obj",
";",
"if",
"(",
"!",
"fn",
"&&",
"typeof",
"event",
"===",
"'object'",
")",
"{",
"fn",
"=",
"this",
";",
"}",
"if",
"(",
"!",
"context",
")",
"{",
"context",
"=",
"this",
";",
"}",
"obj",
".",
"on",
"(",
"event",
",",
"fn",
",",
"context",
")",
";",
"}"
] | Observe another object by adding a callback to its event queue which is
executed when an event fires
@param {Events} obj Object to listen to
@param {string} event Event name
@param {Function} fn Callback function. Executed when event fires.
@param {*=} context Optional context to apply to callback | [
"Observe",
"another",
"object",
"by",
"adding",
"a",
"callback",
"to",
"its",
"event",
"queue",
"which",
"is",
"executed",
"when",
"an",
"event",
"fires"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L455-L466 |
|
56,217 | j-/ok | ok.js | function (event, fn) {
this._events = this._events || {};
var e = this._events[event];
if (e) {
for (var i = 0, l = e.length; i < l; i++) {
if (e[i][0] === fn) {
e.splice(i, 1);
i--;
l--;
}
}
}
} | javascript | function (event, fn) {
this._events = this._events || {};
var e = this._events[event];
if (e) {
for (var i = 0, l = e.length; i < l; i++) {
if (e[i][0] === fn) {
e.splice(i, 1);
i--;
l--;
}
}
}
} | [
"function",
"(",
"event",
",",
"fn",
")",
"{",
"this",
".",
"_events",
"=",
"this",
".",
"_events",
"||",
"{",
"}",
";",
"var",
"e",
"=",
"this",
".",
"_events",
"[",
"event",
"]",
";",
"if",
"(",
"e",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"e",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"e",
"[",
"i",
"]",
"[",
"0",
"]",
"===",
"fn",
")",
"{",
"e",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"i",
"--",
";",
"l",
"--",
";",
"}",
"}",
"}",
"}"
] | Removes a callback from the event queue
@param {string} event Event name
@param {Function} fn Callback function. No longer executed when event
fires. | [
"Removes",
"a",
"callback",
"from",
"the",
"event",
"queue"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L473-L485 |
|
56,218 | j-/ok | ok.js | function (obj, event, fn) {
var listeningTo = this._listeningTo;
if (!listeningTo) {
return;
}
var remove = !event && !fn;
if (!fn && typeof event === 'object') {
fn = this;
}
if (obj) {
(listeningTo = {})[obj._listenId] = obj;
}
for (var id in listeningTo) {
obj = listeningTo[id];
obj.off(event, fn, this);
if (remove) {
delete this._listeningTo[id];
}
}
} | javascript | function (obj, event, fn) {
var listeningTo = this._listeningTo;
if (!listeningTo) {
return;
}
var remove = !event && !fn;
if (!fn && typeof event === 'object') {
fn = this;
}
if (obj) {
(listeningTo = {})[obj._listenId] = obj;
}
for (var id in listeningTo) {
obj = listeningTo[id];
obj.off(event, fn, this);
if (remove) {
delete this._listeningTo[id];
}
}
} | [
"function",
"(",
"obj",
",",
"event",
",",
"fn",
")",
"{",
"var",
"listeningTo",
"=",
"this",
".",
"_listeningTo",
";",
"if",
"(",
"!",
"listeningTo",
")",
"{",
"return",
";",
"}",
"var",
"remove",
"=",
"!",
"event",
"&&",
"!",
"fn",
";",
"if",
"(",
"!",
"fn",
"&&",
"typeof",
"event",
"===",
"'object'",
")",
"{",
"fn",
"=",
"this",
";",
"}",
"if",
"(",
"obj",
")",
"{",
"(",
"listeningTo",
"=",
"{",
"}",
")",
"[",
"obj",
".",
"_listenId",
"]",
"=",
"obj",
";",
"}",
"for",
"(",
"var",
"id",
"in",
"listeningTo",
")",
"{",
"obj",
"=",
"listeningTo",
"[",
"id",
"]",
";",
"obj",
".",
"off",
"(",
"event",
",",
"fn",
",",
"this",
")",
";",
"if",
"(",
"remove",
")",
"{",
"delete",
"this",
".",
"_listeningTo",
"[",
"id",
"]",
";",
"}",
"}",
"}"
] | Stop observing another object
@param {Events=} obj Object to stop observing. Omit to stop observing all
objects.
@param {string=} event Event name. Omit to stop observing all events on
this object.
@param {Function} fn Callback function. Stops this function executing
when `event` is triggered. | [
"Stop",
"observing",
"another",
"object"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L495-L514 |
|
56,219 | j-/ok | ok.js | function (event/*, args... */) {
this._events = this._events || {};
var e = this._events[event];
if (e) {
for (var i = 0, l = e.length; i < l; i++){
e[i][0].apply(e[i][1] || this, slice(arguments, 1));
}
}
} | javascript | function (event/*, args... */) {
this._events = this._events || {};
var e = this._events[event];
if (e) {
for (var i = 0, l = e.length; i < l; i++){
e[i][0].apply(e[i][1] || this, slice(arguments, 1));
}
}
} | [
"function",
"(",
"event",
"/*, args... */",
")",
"{",
"this",
".",
"_events",
"=",
"this",
".",
"_events",
"||",
"{",
"}",
";",
"var",
"e",
"=",
"this",
".",
"_events",
"[",
"event",
"]",
";",
"if",
"(",
"e",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"e",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"e",
"[",
"i",
"]",
"[",
"0",
"]",
".",
"apply",
"(",
"e",
"[",
"i",
"]",
"[",
"1",
"]",
"||",
"this",
",",
"slice",
"(",
"arguments",
",",
"1",
")",
")",
";",
"}",
"}",
"}"
] | Trigger an event and execute all callbacks in the event queue
@param {string} event Event name
@param {...*} args Event arguments passed through to all callbacks | [
"Trigger",
"an",
"event",
"and",
"execute",
"all",
"callbacks",
"in",
"the",
"event",
"queue"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L520-L528 |
|
56,220 | j-/ok | ok.js | Property | function Property (initValue) {
if (arguments.length) {
this.set(initValue);
}
else {
this.set(this.defaultValue);
}
ok.Data.apply(this, arguments);
} | javascript | function Property (initValue) {
if (arguments.length) {
this.set(initValue);
}
else {
this.set(this.defaultValue);
}
ok.Data.apply(this, arguments);
} | [
"function",
"Property",
"(",
"initValue",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
")",
"{",
"this",
".",
"set",
"(",
"initValue",
")",
";",
"}",
"else",
"{",
"this",
".",
"set",
"(",
"this",
".",
"defaultValue",
")",
";",
"}",
"ok",
".",
"Data",
".",
"apply",
"(",
"this",
",",
"arguments",
")",
";",
"}"
] | Optionally initialize this property with a value
@param {*=} initValue Initial value for this property | [
"Optionally",
"initialize",
"this",
"property",
"with",
"a",
"value"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L701-L709 |
56,221 | j-/ok | ok.js | function (newValue) {
var oldValue = this._value;
if (oldValue !== newValue) {
this._value = newValue;
this.trigger(EVENT_CHANGE, this, newValue, oldValue);
}
} | javascript | function (newValue) {
var oldValue = this._value;
if (oldValue !== newValue) {
this._value = newValue;
this.trigger(EVENT_CHANGE, this, newValue, oldValue);
}
} | [
"function",
"(",
"newValue",
")",
"{",
"var",
"oldValue",
"=",
"this",
".",
"_value",
";",
"if",
"(",
"oldValue",
"!==",
"newValue",
")",
"{",
"this",
".",
"_value",
"=",
"newValue",
";",
"this",
".",
"trigger",
"(",
"EVENT_CHANGE",
",",
"this",
",",
"newValue",
",",
"oldValue",
")",
";",
"}",
"}"
] | Replace the internal property with a new value and trigger a 'change'
@param {*} newValue New property value
@fires change | [
"Replace",
"the",
"internal",
"property",
"with",
"a",
"new",
"value",
"and",
"trigger",
"a",
"change"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L722-L728 |
|
56,222 | j-/ok | ok.js | function () {
var properties = this.properties;
_.forEach(properties, function (prop, name) {
prop = this.getProperty(name);
this.stopListening(prop, EVENT_CHANGE);
}, this);
} | javascript | function () {
var properties = this.properties;
_.forEach(properties, function (prop, name) {
prop = this.getProperty(name);
this.stopListening(prop, EVENT_CHANGE);
}, this);
} | [
"function",
"(",
")",
"{",
"var",
"properties",
"=",
"this",
".",
"properties",
";",
"_",
".",
"forEach",
"(",
"properties",
",",
"function",
"(",
"prop",
",",
"name",
")",
"{",
"prop",
"=",
"this",
".",
"getProperty",
"(",
"name",
")",
";",
"this",
".",
"stopListening",
"(",
"prop",
",",
"EVENT_CHANGE",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Remove all events listeners
@deprecated Use {@link #stopListening} (with no arguments) instead | [
"Remove",
"all",
"events",
"listeners"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L796-L802 |
|
56,223 | j-/ok | ok.js | function (properties) {
properties = properties || {};
_.forEach(properties, function (property, name) {
this.initProperty(name, property);
}, this);
} | javascript | function (properties) {
properties = properties || {};
_.forEach(properties, function (property, name) {
this.initProperty(name, property);
}, this);
} | [
"function",
"(",
"properties",
")",
"{",
"properties",
"=",
"properties",
"||",
"{",
"}",
";",
"_",
".",
"forEach",
"(",
"properties",
",",
"function",
"(",
"property",
",",
"name",
")",
"{",
"this",
".",
"initProperty",
"(",
"name",
",",
"property",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Declare the values of a hash of properties
@param {Object} properties Hash of properties and values | [
"Declare",
"the",
"values",
"of",
"a",
"hash",
"of",
"properties"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L820-L825 |
|
56,224 | j-/ok | ok.js | function (name, value) {
var prop = this.getProperty(name);
var Constructor;
if (!prop) {
Constructor = this.getConstructor(name, value);
prop = new Constructor();
prop = this.setProperty(name, prop);
}
if (typeof value !== 'undefined') {
prop.set(value);
}
return prop;
} | javascript | function (name, value) {
var prop = this.getProperty(name);
var Constructor;
if (!prop) {
Constructor = this.getConstructor(name, value);
prop = new Constructor();
prop = this.setProperty(name, prop);
}
if (typeof value !== 'undefined') {
prop.set(value);
}
return prop;
} | [
"function",
"(",
"name",
",",
"value",
")",
"{",
"var",
"prop",
"=",
"this",
".",
"getProperty",
"(",
"name",
")",
";",
"var",
"Constructor",
";",
"if",
"(",
"!",
"prop",
")",
"{",
"Constructor",
"=",
"this",
".",
"getConstructor",
"(",
"name",
",",
"value",
")",
";",
"prop",
"=",
"new",
"Constructor",
"(",
")",
";",
"prop",
"=",
"this",
".",
"setProperty",
"(",
"name",
",",
"prop",
")",
";",
"}",
"if",
"(",
"typeof",
"value",
"!==",
"'undefined'",
")",
"{",
"prop",
".",
"set",
"(",
"value",
")",
";",
"}",
"return",
"prop",
";",
"}"
] | Declare the value of a single property
@param {string} name Property name
@param {*} value Property value
@return {module:ok.Property} New property instance | [
"Declare",
"the",
"value",
"of",
"a",
"single",
"property"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L832-L844 |
|
56,225 | j-/ok | ok.js | function (name) {
var args = arguments;
var len = args.length;
if (len === 0) {
return this.getMap();
}
else if (len === 1) {
return this.getValue(name);
}
else {
return this.getValues.apply(this, args);
}
} | javascript | function (name) {
var args = arguments;
var len = args.length;
if (len === 0) {
return this.getMap();
}
else if (len === 1) {
return this.getValue(name);
}
else {
return this.getValues.apply(this, args);
}
} | [
"function",
"(",
"name",
")",
"{",
"var",
"args",
"=",
"arguments",
";",
"var",
"len",
"=",
"args",
".",
"length",
";",
"if",
"(",
"len",
"===",
"0",
")",
"{",
"return",
"this",
".",
"getMap",
"(",
")",
";",
"}",
"else",
"if",
"(",
"len",
"===",
"1",
")",
"{",
"return",
"this",
".",
"getValue",
"(",
"name",
")",
";",
"}",
"else",
"{",
"return",
"this",
".",
"getValues",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"}",
"}"
] | Get the values of one or more properties
@param {...string=} name Optional property names. If omitted, a map of
all properties will be returned. If one property name is given then the
value of that property will be returned. Otherwise, if more than one
property name is given, the values of those properties will be returned
as an array.
@return {Object|Array|*} Result of the get operation depending on the
number of property names given. | [
"Get",
"the",
"values",
"of",
"one",
"or",
"more",
"properties"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L875-L887 |
|
56,226 | j-/ok | ok.js | function () {
var map = this.properties;
var pairs = _.map(map, function (prop, name) {
return [name, prop.get()];
});
var result = _.object(pairs);
return result;
} | javascript | function () {
var map = this.properties;
var pairs = _.map(map, function (prop, name) {
return [name, prop.get()];
});
var result = _.object(pairs);
return result;
} | [
"function",
"(",
")",
"{",
"var",
"map",
"=",
"this",
".",
"properties",
";",
"var",
"pairs",
"=",
"_",
".",
"map",
"(",
"map",
",",
"function",
"(",
"prop",
",",
"name",
")",
"{",
"return",
"[",
"name",
",",
"prop",
".",
"get",
"(",
")",
"]",
";",
"}",
")",
";",
"var",
"result",
"=",
"_",
".",
"object",
"(",
"pairs",
")",
";",
"return",
"result",
";",
"}"
] | Get the values of all properties
@return {Object} Map of all properties. Each property has had its `get`
function invoked. | [
"Get",
"the",
"values",
"of",
"all",
"properties"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L893-L900 |
|
56,227 | j-/ok | ok.js | function () {
var result = [];
var args = arguments;
var l = args.length;
var name, value;
for (var i = 0; i < l; i++) {
name = args[i];
value = this.getValue(name);
result.push(value);
}
return result;
} | javascript | function () {
var result = [];
var args = arguments;
var l = args.length;
var name, value;
for (var i = 0; i < l; i++) {
name = args[i];
value = this.getValue(name);
result.push(value);
}
return result;
} | [
"function",
"(",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"args",
"=",
"arguments",
";",
"var",
"l",
"=",
"args",
".",
"length",
";",
"var",
"name",
",",
"value",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"name",
"=",
"args",
"[",
"i",
"]",
";",
"value",
"=",
"this",
".",
"getValue",
"(",
"name",
")",
";",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Get the value of multiple properties
@param {...string} names Property names
@return {Array} Array of values from each property's `get` function | [
"Get",
"the",
"value",
"of",
"multiple",
"properties"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L915-L926 |
|
56,228 | j-/ok | ok.js | function (name, newValue) {
if (arguments.length > 1) {
this.setValue(name, newValue);
}
else {
var attrs = name;
this.setMap(attrs);
}
} | javascript | function (name, newValue) {
if (arguments.length > 1) {
this.setValue(name, newValue);
}
else {
var attrs = name;
this.setMap(attrs);
}
} | [
"function",
"(",
"name",
",",
"newValue",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"{",
"this",
".",
"setValue",
"(",
"name",
",",
"newValue",
")",
";",
"}",
"else",
"{",
"var",
"attrs",
"=",
"name",
";",
"this",
".",
"setMap",
"(",
"attrs",
")",
";",
"}",
"}"
] | Set the value of one or more properties
@method module:ok.Map#set
@param {Object} attrs Hash of property names and values to set
Set the value of a single property
@param {string} name Property name
@param {*} newValue Property value | [
"Set",
"the",
"value",
"of",
"one",
"or",
"more",
"properties"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L953-L961 |
|
56,229 | j-/ok | ok.js | function (attrs) {
attrs = attrs || {};
_.forEach(attrs, function (val, name) {
this.setValue(name, val);
}, this);
} | javascript | function (attrs) {
attrs = attrs || {};
_.forEach(attrs, function (val, name) {
this.setValue(name, val);
}, this);
} | [
"function",
"(",
"attrs",
")",
"{",
"attrs",
"=",
"attrs",
"||",
"{",
"}",
";",
"_",
".",
"forEach",
"(",
"attrs",
",",
"function",
"(",
"val",
",",
"name",
")",
"{",
"this",
".",
"setValue",
"(",
"name",
",",
"val",
")",
";",
"}",
",",
"this",
")",
";",
"}"
] | Set values of properties using an object
@param {Object} attrs Hash of property names and values to set | [
"Set",
"values",
"of",
"properties",
"using",
"an",
"object"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L966-L971 |
|
56,230 | j-/ok | ok.js | function (name, newValue) {
var property = this.getProperty(name);
if (!property) {
this.initProperty(name, newValue);
}
else {
property.set(newValue);
}
} | javascript | function (name, newValue) {
var property = this.getProperty(name);
if (!property) {
this.initProperty(name, newValue);
}
else {
property.set(newValue);
}
} | [
"function",
"(",
"name",
",",
"newValue",
")",
"{",
"var",
"property",
"=",
"this",
".",
"getProperty",
"(",
"name",
")",
";",
"if",
"(",
"!",
"property",
")",
"{",
"this",
".",
"initProperty",
"(",
"name",
",",
"newValue",
")",
";",
"}",
"else",
"{",
"property",
".",
"set",
"(",
"newValue",
")",
";",
"}",
"}"
] | Set the value of a single property
@param {string} name Property name
@param {*} newValue Property value | [
"Set",
"the",
"value",
"of",
"a",
"single",
"property"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L977-L985 |
|
56,231 | j-/ok | ok.js | function (name, prop) {
this.unsetProperty(name);
this.properties[name] = prop;
this.listenTo(prop, EVENT_CHANGE, this.change);
return prop;
} | javascript | function (name, prop) {
this.unsetProperty(name);
this.properties[name] = prop;
this.listenTo(prop, EVENT_CHANGE, this.change);
return prop;
} | [
"function",
"(",
"name",
",",
"prop",
")",
"{",
"this",
".",
"unsetProperty",
"(",
"name",
")",
";",
"this",
".",
"properties",
"[",
"name",
"]",
"=",
"prop",
";",
"this",
".",
"listenTo",
"(",
"prop",
",",
"EVENT_CHANGE",
",",
"this",
".",
"change",
")",
";",
"return",
"prop",
";",
"}"
] | Set a single property to a new value
@param {string} name Property name
@param {module:ok.Property} prop Property object
@return {module:ok.Property} The new property | [
"Set",
"a",
"single",
"property",
"to",
"a",
"new",
"value"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L992-L997 |
|
56,232 | j-/ok | ok.js | function (name) {
var prop = this.properties[name];
if (prop) {
this.stopListening(prop, EVENT_CHANGE, this.change);
delete this.properties[name];
return prop;
}
return null;
} | javascript | function (name) {
var prop = this.properties[name];
if (prop) {
this.stopListening(prop, EVENT_CHANGE, this.change);
delete this.properties[name];
return prop;
}
return null;
} | [
"function",
"(",
"name",
")",
"{",
"var",
"prop",
"=",
"this",
".",
"properties",
"[",
"name",
"]",
";",
"if",
"(",
"prop",
")",
"{",
"this",
".",
"stopListening",
"(",
"prop",
",",
"EVENT_CHANGE",
",",
"this",
".",
"change",
")",
";",
"delete",
"this",
".",
"properties",
"[",
"name",
"]",
";",
"return",
"prop",
";",
"}",
"return",
"null",
";",
"}"
] | Remove a single property from the map
@param {String} name Property name
@return {?module:ok.Property} Removed property or `null` | [
"Remove",
"a",
"single",
"property",
"from",
"the",
"map"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1003-L1011 |
|
56,233 | j-/ok | ok.js | function (/* items... */) {
var items = slice(arguments);
var item;
for (var i = 0, l = items.length; i < l; i++) {
item = items[i];
$Array.push.call(this, item);
this.trigger(EVENT_ADD, item, this.length);
}
return this.length;
} | javascript | function (/* items... */) {
var items = slice(arguments);
var item;
for (var i = 0, l = items.length; i < l; i++) {
item = items[i];
$Array.push.call(this, item);
this.trigger(EVENT_ADD, item, this.length);
}
return this.length;
} | [
"function",
"(",
"/* items... */",
")",
"{",
"var",
"items",
"=",
"slice",
"(",
"arguments",
")",
";",
"var",
"item",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"items",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"$Array",
".",
"push",
".",
"call",
"(",
"this",
",",
"item",
")",
";",
"this",
".",
"trigger",
"(",
"EVENT_ADD",
",",
"item",
",",
"this",
".",
"length",
")",
";",
"}",
"return",
"this",
".",
"length",
";",
"}"
] | Push new items to the top of the stack
@param {...*} New items to push
@return {int} New length after items have been pushed
@fires add | [
"Push",
"new",
"items",
"to",
"the",
"top",
"of",
"the",
"stack"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1046-L1055 |
|
56,234 | j-/ok | ok.js | function (start, length) {
var removed, item;
if (arguments.length < 1) {
start = 0;
}
if (arguments.length < 2) {
length = this.length - start;
}
removed = [];
while (start < this.length && length-- > 0) {
item = this[start];
$Array.splice.call(this, start, 1);
this.trigger(EVENT_REMOVE, item);
removed.push(item);
}
return removed;
} | javascript | function (start, length) {
var removed, item;
if (arguments.length < 1) {
start = 0;
}
if (arguments.length < 2) {
length = this.length - start;
}
removed = [];
while (start < this.length && length-- > 0) {
item = this[start];
$Array.splice.call(this, start, 1);
this.trigger(EVENT_REMOVE, item);
removed.push(item);
}
return removed;
} | [
"function",
"(",
"start",
",",
"length",
")",
"{",
"var",
"removed",
",",
"item",
";",
"if",
"(",
"arguments",
".",
"length",
"<",
"1",
")",
"{",
"start",
"=",
"0",
";",
"}",
"if",
"(",
"arguments",
".",
"length",
"<",
"2",
")",
"{",
"length",
"=",
"this",
".",
"length",
"-",
"start",
";",
"}",
"removed",
"=",
"[",
"]",
";",
"while",
"(",
"start",
"<",
"this",
".",
"length",
"&&",
"length",
"--",
">",
"0",
")",
"{",
"item",
"=",
"this",
"[",
"start",
"]",
";",
"$Array",
".",
"splice",
".",
"call",
"(",
"this",
",",
"start",
",",
"1",
")",
";",
"this",
".",
"trigger",
"(",
"EVENT_REMOVE",
",",
"item",
")",
";",
"removed",
".",
"push",
"(",
"item",
")",
";",
"}",
"return",
"removed",
";",
"}"
] | Remove items from the array
@param {int=} start Start index. If omitted, will start at 0.
@param {int=} length Number of items to remove. If omitted, will remove
all items until the end of the array.
@return {Array} Collection of removed items
@fires remove | [
"Remove",
"items",
"from",
"the",
"array"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1122-L1138 |
|
56,235 | j-/ok | ok.js | function (start/*, items... */) {
var items = slice(arguments, 1);
var item, index;
for (var i = 0, l = items.length; i < l; i++) {
item = items[i];
index = start + i;
$Array.splice.call(this, index, 0, item);
this.trigger(EVENT_ADD, item, index);
}
return this.length;
} | javascript | function (start/*, items... */) {
var items = slice(arguments, 1);
var item, index;
for (var i = 0, l = items.length; i < l; i++) {
item = items[i];
index = start + i;
$Array.splice.call(this, index, 0, item);
this.trigger(EVENT_ADD, item, index);
}
return this.length;
} | [
"function",
"(",
"start",
"/*, items... */",
")",
"{",
"var",
"items",
"=",
"slice",
"(",
"arguments",
",",
"1",
")",
";",
"var",
"item",
",",
"index",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"items",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"item",
"=",
"items",
"[",
"i",
"]",
";",
"index",
"=",
"start",
"+",
"i",
";",
"$Array",
".",
"splice",
".",
"call",
"(",
"this",
",",
"index",
",",
"0",
",",
"item",
")",
";",
"this",
".",
"trigger",
"(",
"EVENT_ADD",
",",
"item",
",",
"index",
")",
";",
"}",
"return",
"this",
".",
"length",
";",
"}"
] | Insert items into the array
@param {int} start Starting index
@param {...*} items New items to insert
@return {int} New length after items have been added
@fires add | [
"Insert",
"items",
"into",
"the",
"array"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1155-L1165 |
|
56,236 | j-/ok | ok.js | function (items) {
var args = slice(items);
args.unshift(0);
this.empty();
this.insert.apply(this, args);
return this.length;
} | javascript | function (items) {
var args = slice(items);
args.unshift(0);
this.empty();
this.insert.apply(this, args);
return this.length;
} | [
"function",
"(",
"items",
")",
"{",
"var",
"args",
"=",
"slice",
"(",
"items",
")",
";",
"args",
".",
"unshift",
"(",
"0",
")",
";",
"this",
".",
"empty",
"(",
")",
";",
"this",
".",
"insert",
".",
"apply",
"(",
"this",
",",
"args",
")",
";",
"return",
"this",
".",
"length",
";",
"}"
] | Set the contents of this array. Empties it first.
@param {Array} items New contents of array
@return {int} New length after items have been added
@fires remove
@fires add | [
"Set",
"the",
"contents",
"of",
"this",
"array",
".",
"Empties",
"it",
"first",
"."
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1173-L1179 |
|
56,237 | j-/ok | ok.js | function (index) {
if (arguments.length < 1) {
return this;
}
if (index < 0) {
index = this.length + index;
}
if (hasProperty(this, index)) {
return this[index];
}
return null;
} | javascript | function (index) {
if (arguments.length < 1) {
return this;
}
if (index < 0) {
index = this.length + index;
}
if (hasProperty(this, index)) {
return this[index];
}
return null;
} | [
"function",
"(",
"index",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"<",
"1",
")",
"{",
"return",
"this",
";",
"}",
"if",
"(",
"index",
"<",
"0",
")",
"{",
"index",
"=",
"this",
".",
"length",
"+",
"index",
";",
"}",
"if",
"(",
"hasProperty",
"(",
"this",
",",
"index",
")",
")",
"{",
"return",
"this",
"[",
"index",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Get the item at a given index. Can be negative. If no index is given, a
reference to the array will be returned.
@param {int=} Index of item to get
@return {?ok.Items|*} Item at given index or whole array | [
"Get",
"the",
"item",
"at",
"a",
"given",
"index",
".",
"Can",
"be",
"negative",
".",
"If",
"no",
"index",
"is",
"given",
"a",
"reference",
"to",
"the",
"array",
"will",
"be",
"returned",
"."
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1186-L1197 |
|
56,238 | j-/ok | ok.js | Collection | function Collection (items) {
this.items = new ok.Items();
this.start();
if (items) {
this.add(items);
}
this.init();
} | javascript | function Collection (items) {
this.items = new ok.Items();
this.start();
if (items) {
this.add(items);
}
this.init();
} | [
"function",
"Collection",
"(",
"items",
")",
"{",
"this",
".",
"items",
"=",
"new",
"ok",
".",
"Items",
"(",
")",
";",
"this",
".",
"start",
"(",
")",
";",
"if",
"(",
"items",
")",
"{",
"this",
".",
"add",
"(",
"items",
")",
";",
"}",
"this",
".",
"init",
"(",
")",
";",
"}"
] | Initialize with items | [
"Initialize",
"with",
"items"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1280-L1287 |
56,239 | j-/ok | ok.js | function () {
this.stop();
this.listenTo(this.items, EVENT_ADD, this.triggerAdd);
this.listenTo(this.items, EVENT_REMOVE, this.triggerRemove);
this.listenTo(this.items, EVENT_SORT, this.triggerSort);
this.listenTo(this.items, EVENT_ADD, this.updateLength);
this.listenTo(this.items, EVENT_REMOVE, this.updateLength);
this.listenTo(this.items, EVENT_ADD, this.watchItem);
this.listenTo(this.items, EVENT_REMOVE, this.unwatchItem);
} | javascript | function () {
this.stop();
this.listenTo(this.items, EVENT_ADD, this.triggerAdd);
this.listenTo(this.items, EVENT_REMOVE, this.triggerRemove);
this.listenTo(this.items, EVENT_SORT, this.triggerSort);
this.listenTo(this.items, EVENT_ADD, this.updateLength);
this.listenTo(this.items, EVENT_REMOVE, this.updateLength);
this.listenTo(this.items, EVENT_ADD, this.watchItem);
this.listenTo(this.items, EVENT_REMOVE, this.unwatchItem);
} | [
"function",
"(",
")",
"{",
"this",
".",
"stop",
"(",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_ADD",
",",
"this",
".",
"triggerAdd",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_REMOVE",
",",
"this",
".",
"triggerRemove",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_SORT",
",",
"this",
".",
"triggerSort",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_ADD",
",",
"this",
".",
"updateLength",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_REMOVE",
",",
"this",
".",
"updateLength",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_ADD",
",",
"this",
".",
"watchItem",
")",
";",
"this",
".",
"listenTo",
"(",
"this",
".",
"items",
",",
"EVENT_REMOVE",
",",
"this",
".",
"unwatchItem",
")",
";",
"}"
] | Begin listening to changes on the internal items storage array | [
"Begin",
"listening",
"to",
"changes",
"on",
"the",
"internal",
"items",
"storage",
"array"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1291-L1300 |
|
56,240 | j-/ok | ok.js | function () {
var items = _.flatten(arguments);
for (var i = 0, l = items.length; i < l; i++) {
this.addItem(items[i], this.items.length);
}
} | javascript | function () {
var items = _.flatten(arguments);
for (var i = 0, l = items.length; i < l; i++) {
this.addItem(items[i], this.items.length);
}
} | [
"function",
"(",
")",
"{",
"var",
"items",
"=",
"_",
".",
"flatten",
"(",
"arguments",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"items",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"this",
".",
"addItem",
"(",
"items",
"[",
"i",
"]",
",",
"this",
".",
"items",
".",
"length",
")",
";",
"}",
"}"
] | Add one or more items
@param {*|Array.<*>} items A single item or array of items which will be
added to this collection
@fires add | [
"Add",
"one",
"or",
"more",
"items"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1357-L1362 |
|
56,241 | j-/ok | ok.js | function (item/*, index*/) {
var old = item;
var Constructor;
if (!(item instanceof ok.Base)) {
Constructor = this.getConstructor(item);
item = new Constructor(item);
}
var identified = this.identify(item);
if (identified) {
identified.set(old);
}
else {
var index = this.findInsertIndex(item);
this.items.insert(index + 1, item);
}
} | javascript | function (item/*, index*/) {
var old = item;
var Constructor;
if (!(item instanceof ok.Base)) {
Constructor = this.getConstructor(item);
item = new Constructor(item);
}
var identified = this.identify(item);
if (identified) {
identified.set(old);
}
else {
var index = this.findInsertIndex(item);
this.items.insert(index + 1, item);
}
} | [
"function",
"(",
"item",
"/*, index*/",
")",
"{",
"var",
"old",
"=",
"item",
";",
"var",
"Constructor",
";",
"if",
"(",
"!",
"(",
"item",
"instanceof",
"ok",
".",
"Base",
")",
")",
"{",
"Constructor",
"=",
"this",
".",
"getConstructor",
"(",
"item",
")",
";",
"item",
"=",
"new",
"Constructor",
"(",
"item",
")",
";",
"}",
"var",
"identified",
"=",
"this",
".",
"identify",
"(",
"item",
")",
";",
"if",
"(",
"identified",
")",
"{",
"identified",
".",
"set",
"(",
"old",
")",
";",
"}",
"else",
"{",
"var",
"index",
"=",
"this",
".",
"findInsertIndex",
"(",
"item",
")",
";",
"this",
".",
"items",
".",
"insert",
"(",
"index",
"+",
"1",
",",
"item",
")",
";",
"}",
"}"
] | Add a single item to this collection
@param {*} item Item to add to collection
@param {int} index Position to add the item
@fires add | [
"Add",
"a",
"single",
"item",
"to",
"this",
"collection"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1369-L1384 |
|
56,242 | j-/ok | ok.js | function (item) {
var index = -1;
this.items.forEach(function (comparedTo, newIndex) {
if (this.comparator(comparedTo, item) <= 0) {
index = newIndex;
return false;
}
}, this);
return index;
} | javascript | function (item) {
var index = -1;
this.items.forEach(function (comparedTo, newIndex) {
if (this.comparator(comparedTo, item) <= 0) {
index = newIndex;
return false;
}
}, this);
return index;
} | [
"function",
"(",
"item",
")",
"{",
"var",
"index",
"=",
"-",
"1",
";",
"this",
".",
"items",
".",
"forEach",
"(",
"function",
"(",
"comparedTo",
",",
"newIndex",
")",
"{",
"if",
"(",
"this",
".",
"comparator",
"(",
"comparedTo",
",",
"item",
")",
"<=",
"0",
")",
"{",
"index",
"=",
"newIndex",
";",
"return",
"false",
";",
"}",
"}",
",",
"this",
")",
";",
"return",
"index",
";",
"}"
] | Determine where a newly inserted item would fit in this collection. Find
the index of the item to insert after, or -1 to insert at the first
index.
@param {*} item Item to be added to collection
@return {int} Index of the item to insert after
@todo Rephrase | [
"Determine",
"where",
"a",
"newly",
"inserted",
"item",
"would",
"fit",
"in",
"this",
"collection",
".",
"Find",
"the",
"index",
"of",
"the",
"item",
"to",
"insert",
"after",
"or",
"-",
"1",
"to",
"insert",
"at",
"the",
"first",
"index",
"."
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1407-L1416 |
|
56,243 | j-/ok | ok.js | function (item) {
var items = this.items;
var removed = 0;
for (var i = 0, l = items.length; i < l; i++) {
if (items[i] === item) {
items.splice(i, 1);
i--;
removed++;
}
}
return removed;
} | javascript | function (item) {
var items = this.items;
var removed = 0;
for (var i = 0, l = items.length; i < l; i++) {
if (items[i] === item) {
items.splice(i, 1);
i--;
removed++;
}
}
return removed;
} | [
"function",
"(",
"item",
")",
"{",
"var",
"items",
"=",
"this",
".",
"items",
";",
"var",
"removed",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"items",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"if",
"(",
"items",
"[",
"i",
"]",
"===",
"item",
")",
"{",
"items",
".",
"splice",
"(",
"i",
",",
"1",
")",
";",
"i",
"--",
";",
"removed",
"++",
";",
"}",
"}",
"return",
"removed",
";",
"}"
] | Remove a specific item from the collection
@param {*} item Item to remove
@return {int} Number of items which have been removed
@fires remove | [
"Remove",
"a",
"specific",
"item",
"from",
"the",
"collection"
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1431-L1442 |
|
56,244 | j-/ok | ok.js | function () {
var message = this.message;
var name = this.name;
var url = this.url;
var result = name;
if (message) {
result += ': ' + message;
}
if (url) {
result += ' (' + url + ')';
}
return result;
} | javascript | function () {
var message = this.message;
var name = this.name;
var url = this.url;
var result = name;
if (message) {
result += ': ' + message;
}
if (url) {
result += ' (' + url + ')';
}
return result;
} | [
"function",
"(",
")",
"{",
"var",
"message",
"=",
"this",
".",
"message",
";",
"var",
"name",
"=",
"this",
".",
"name",
";",
"var",
"url",
"=",
"this",
".",
"url",
";",
"var",
"result",
"=",
"name",
";",
"if",
"(",
"message",
")",
"{",
"result",
"+=",
"': '",
"+",
"message",
";",
"}",
"if",
"(",
"url",
")",
"{",
"result",
"+=",
"' ('",
"+",
"url",
"+",
"')'",
";",
"}",
"return",
"result",
";",
"}"
] | Display the contents of this error. Always shows the name. If the message
exists it is also displayed. A URL to, for example, help documentation
can be displayed as well.
@return {String} Contents of this error | [
"Display",
"the",
"contents",
"of",
"this",
"error",
".",
"Always",
"shows",
"the",
"name",
".",
"If",
"the",
"message",
"exists",
"it",
"is",
"also",
"displayed",
".",
"A",
"URL",
"to",
"for",
"example",
"help",
"documentation",
"can",
"be",
"displayed",
"as",
"well",
"."
] | f1e4d9af3565574c5fdeccf4313972f2428cf3f8 | https://github.com/j-/ok/blob/f1e4d9af3565574c5fdeccf4313972f2428cf3f8/ok.js#L1591-L1603 |
|
56,245 | cubbles/cubx-grunt-webpackage-upload | tasks/cubx_webpackage_bulk_upload.js | function (err, files) {
if (err) {
grunt.fail.fatal(err);
}
files.forEach(function (file) {
var pathName = path.join(workspacePath, file);
if (fs.statSync(pathName).isDirectory()) {
if (file === activeWebpackage && choices.length > 0) {
choices.splice(0, 0, file);
} else {
choices.push(file);
}
}
});
// get list of webpackages to upload from config
var uploadWebpackages = grunt.config.get('workspaceConfig.uploadWebpackages');
var i = 0;
if (uploadWebpackages && uploadWebpackages.length) {
// create upload list from config
grunt.log.writeln('Webpackages to upload:');
for (i = 0; i < uploadWebpackages.length; i++) {
if (choices.indexOf(uploadWebpackages[i]) >= 0) {
webpackages.push(uploadWebpackages[i]);
grunt.log.writeln((i + 1) + ') ' + uploadWebpackages[i]);
}
}
startUploads();
} else {
// get user decision
choices.push('CANCEL');
grunt.log.writeln('Please select all webpackages to upload ' +
'or to CANCEL: ');
for (i = 0; i < choices.length; i++) {
grunt.log.writeln((i + 1) + ') ' + choices[i]);
}
var options = {
questions: [
{
name: 'selectedWebpackages',
type: 'input',
message: 'Answer:'
}
]
};
inquirer.prompt(options.questions).then(webpackagesSelected);
}
} | javascript | function (err, files) {
if (err) {
grunt.fail.fatal(err);
}
files.forEach(function (file) {
var pathName = path.join(workspacePath, file);
if (fs.statSync(pathName).isDirectory()) {
if (file === activeWebpackage && choices.length > 0) {
choices.splice(0, 0, file);
} else {
choices.push(file);
}
}
});
// get list of webpackages to upload from config
var uploadWebpackages = grunt.config.get('workspaceConfig.uploadWebpackages');
var i = 0;
if (uploadWebpackages && uploadWebpackages.length) {
// create upload list from config
grunt.log.writeln('Webpackages to upload:');
for (i = 0; i < uploadWebpackages.length; i++) {
if (choices.indexOf(uploadWebpackages[i]) >= 0) {
webpackages.push(uploadWebpackages[i]);
grunt.log.writeln((i + 1) + ') ' + uploadWebpackages[i]);
}
}
startUploads();
} else {
// get user decision
choices.push('CANCEL');
grunt.log.writeln('Please select all webpackages to upload ' +
'or to CANCEL: ');
for (i = 0; i < choices.length; i++) {
grunt.log.writeln((i + 1) + ') ' + choices[i]);
}
var options = {
questions: [
{
name: 'selectedWebpackages',
type: 'input',
message: 'Answer:'
}
]
};
inquirer.prompt(options.questions).then(webpackagesSelected);
}
} | [
"function",
"(",
"err",
",",
"files",
")",
"{",
"if",
"(",
"err",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"err",
")",
";",
"}",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"var",
"pathName",
"=",
"path",
".",
"join",
"(",
"workspacePath",
",",
"file",
")",
";",
"if",
"(",
"fs",
".",
"statSync",
"(",
"pathName",
")",
".",
"isDirectory",
"(",
")",
")",
"{",
"if",
"(",
"file",
"===",
"activeWebpackage",
"&&",
"choices",
".",
"length",
">",
"0",
")",
"{",
"choices",
".",
"splice",
"(",
"0",
",",
"0",
",",
"file",
")",
";",
"}",
"else",
"{",
"choices",
".",
"push",
"(",
"file",
")",
";",
"}",
"}",
"}",
")",
";",
"// get list of webpackages to upload from config",
"var",
"uploadWebpackages",
"=",
"grunt",
".",
"config",
".",
"get",
"(",
"'workspaceConfig.uploadWebpackages'",
")",
";",
"var",
"i",
"=",
"0",
";",
"if",
"(",
"uploadWebpackages",
"&&",
"uploadWebpackages",
".",
"length",
")",
"{",
"// create upload list from config",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Webpackages to upload:'",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"uploadWebpackages",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"choices",
".",
"indexOf",
"(",
"uploadWebpackages",
"[",
"i",
"]",
")",
">=",
"0",
")",
"{",
"webpackages",
".",
"push",
"(",
"uploadWebpackages",
"[",
"i",
"]",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"(",
"i",
"+",
"1",
")",
"+",
"') '",
"+",
"uploadWebpackages",
"[",
"i",
"]",
")",
";",
"}",
"}",
"startUploads",
"(",
")",
";",
"}",
"else",
"{",
"// get user decision",
"choices",
".",
"push",
"(",
"'CANCEL'",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"'Please select all webpackages to upload '",
"+",
"'or to CANCEL: '",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"choices",
".",
"length",
";",
"i",
"++",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"(",
"i",
"+",
"1",
")",
"+",
"') '",
"+",
"choices",
"[",
"i",
"]",
")",
";",
"}",
"var",
"options",
"=",
"{",
"questions",
":",
"[",
"{",
"name",
":",
"'selectedWebpackages'",
",",
"type",
":",
"'input'",
",",
"message",
":",
"'Answer:'",
"}",
"]",
"}",
";",
"inquirer",
".",
"prompt",
"(",
"options",
".",
"questions",
")",
".",
"then",
"(",
"webpackagesSelected",
")",
";",
"}",
"}"
] | get all webpackages | [
"get",
"all",
"webpackages"
] | 3fb7075fc9de2185475ade21c3be8d31f0f56e1d | https://github.com/cubbles/cubx-grunt-webpackage-upload/blob/3fb7075fc9de2185475ade21c3be8d31f0f56e1d/tasks/cubx_webpackage_bulk_upload.js#L33-L82 |
|
56,246 | duzun/onemit | onemit.js | EmitEvent | function EmitEvent(props) {
const event = this;
if ( !(event instanceof EmitEvent) ) {
return new EmitEvent(props);
}
if ( props == undefined ) {
props = '';
}
if ( typeof props == 'string' ) {
props = { type: props };
}
_extend(event, props);
event.timeStamp = Date.now();
} | javascript | function EmitEvent(props) {
const event = this;
if ( !(event instanceof EmitEvent) ) {
return new EmitEvent(props);
}
if ( props == undefined ) {
props = '';
}
if ( typeof props == 'string' ) {
props = { type: props };
}
_extend(event, props);
event.timeStamp = Date.now();
} | [
"function",
"EmitEvent",
"(",
"props",
")",
"{",
"const",
"event",
"=",
"this",
";",
"if",
"(",
"!",
"(",
"event",
"instanceof",
"EmitEvent",
")",
")",
"{",
"return",
"new",
"EmitEvent",
"(",
"props",
")",
";",
"}",
"if",
"(",
"props",
"==",
"undefined",
")",
"{",
"props",
"=",
"''",
";",
"}",
"if",
"(",
"typeof",
"props",
"==",
"'string'",
")",
"{",
"props",
"=",
"{",
"type",
":",
"props",
"}",
";",
"}",
"_extend",
"(",
"event",
",",
"props",
")",
";",
"event",
".",
"timeStamp",
"=",
"Date",
".",
"now",
"(",
")",
";",
"}"
] | Event constructor.
@param (Object) props - { type: "eventName", ... } or just "eventName" | [
"Event",
"constructor",
"."
] | 12360553cf36379e9fc91d36c40d519a822d4987 | https://github.com/duzun/onemit/blob/12360553cf36379e9fc91d36c40d519a822d4987/onemit.js#L112-L125 |
56,247 | duzun/onemit | onemit.js | _extend | function _extend(obj, from) {
for ( let key in from ) if ( hop.call(from, key) ) {
obj[key] = from[key];
}
return obj;
} | javascript | function _extend(obj, from) {
for ( let key in from ) if ( hop.call(from, key) ) {
obj[key] = from[key];
}
return obj;
} | [
"function",
"_extend",
"(",
"obj",
",",
"from",
")",
"{",
"for",
"(",
"let",
"key",
"in",
"from",
")",
"if",
"(",
"hop",
".",
"call",
"(",
"from",
",",
"key",
")",
")",
"{",
"obj",
"[",
"key",
"]",
"=",
"from",
"[",
"key",
"]",
";",
"}",
"return",
"obj",
";",
"}"
] | Copy properties to `obj` from `from`
@param (Object) obj
@param (Object) from - source object
@return (Object) obj
@api private | [
"Copy",
"properties",
"to",
"obj",
"from",
"from"
] | 12360553cf36379e9fc91d36c40d519a822d4987 | https://github.com/duzun/onemit/blob/12360553cf36379e9fc91d36c40d519a822d4987/onemit.js#L522-L527 |
56,248 | duzun/onemit | onemit.js | _append | function _append(array, args/*, ...*/) {
var i = array.length
, j
, k = 1
, l
, m = arguments.length
, a
;
for(; k < m; ++k) {
a = arguments[k];
array.length =
l = i + a.length;
for(j = 0; i < l; ++i, ++j) {
array[i] = a[j];
}
}
return array;
} | javascript | function _append(array, args/*, ...*/) {
var i = array.length
, j
, k = 1
, l
, m = arguments.length
, a
;
for(; k < m; ++k) {
a = arguments[k];
array.length =
l = i + a.length;
for(j = 0; i < l; ++i, ++j) {
array[i] = a[j];
}
}
return array;
} | [
"function",
"_append",
"(",
"array",
",",
"args",
"/*, ...*/",
")",
"{",
"var",
"i",
"=",
"array",
".",
"length",
",",
"j",
",",
"k",
"=",
"1",
",",
"l",
",",
"m",
"=",
"arguments",
".",
"length",
",",
"a",
";",
"for",
"(",
";",
"k",
"<",
"m",
";",
"++",
"k",
")",
"{",
"a",
"=",
"arguments",
"[",
"k",
"]",
";",
"array",
".",
"length",
"=",
"l",
"=",
"i",
"+",
"a",
".",
"length",
";",
"for",
"(",
"j",
"=",
"0",
";",
"i",
"<",
"l",
";",
"++",
"i",
",",
"++",
"j",
")",
"{",
"array",
"[",
"i",
"]",
"=",
"a",
"[",
"j",
"]",
";",
"}",
"}",
"return",
"array",
";",
"}"
] | Append elements of `args` to `array`.
This function is similar to `array.concat(args)`,
but also works on non-Array `args` as if it where an Array,
and it modifies the original `array`.
@param (Array) array - an array or array-like object
@param (Array) args - an array or array-like object to append to `array`
@return (Array) array | [
"Append",
"elements",
"of",
"args",
"to",
"array",
"."
] | 12360553cf36379e9fc91d36c40d519a822d4987 | https://github.com/duzun/onemit/blob/12360553cf36379e9fc91d36c40d519a822d4987/onemit.js#L541-L558 |
56,249 | byu-oit/aws-scatter-gather | bin/response.js | function (data, circuitbreakerState, callback) {
const responder = (circuitbreakerState===CB.OPEN) ? config.bypass : config.handler;
// call the handler using its expected paradigm
const promise = responder.length > 1
? new Promise(function(resolve, reject) {
responder(data, function(err, result) {
if (err) return reject(err);
resolve(result);
});
})
: Promise.resolve(responder(data));
// provide an asynchronous response in the expected paradigm
if (typeof callback !== 'function') return promise;
promise.then(
function (data) { callback(null, data); },
function (err) { callback(err, null); }
);
} | javascript | function (data, circuitbreakerState, callback) {
const responder = (circuitbreakerState===CB.OPEN) ? config.bypass : config.handler;
// call the handler using its expected paradigm
const promise = responder.length > 1
? new Promise(function(resolve, reject) {
responder(data, function(err, result) {
if (err) return reject(err);
resolve(result);
});
})
: Promise.resolve(responder(data));
// provide an asynchronous response in the expected paradigm
if (typeof callback !== 'function') return promise;
promise.then(
function (data) { callback(null, data); },
function (err) { callback(err, null); }
);
} | [
"function",
"(",
"data",
",",
"circuitbreakerState",
",",
"callback",
")",
"{",
"const",
"responder",
"=",
"(",
"circuitbreakerState",
"===",
"CB",
".",
"OPEN",
")",
"?",
"config",
".",
"bypass",
":",
"config",
".",
"handler",
";",
"// call the handler using its expected paradigm",
"const",
"promise",
"=",
"responder",
".",
"length",
">",
"1",
"?",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"responder",
"(",
"data",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"return",
"reject",
"(",
"err",
")",
";",
"resolve",
"(",
"result",
")",
";",
"}",
")",
";",
"}",
")",
":",
"Promise",
".",
"resolve",
"(",
"responder",
"(",
"data",
")",
")",
";",
"// provide an asynchronous response in the expected paradigm",
"if",
"(",
"typeof",
"callback",
"!==",
"'function'",
")",
"return",
"promise",
";",
"promise",
".",
"then",
"(",
"function",
"(",
"data",
")",
"{",
"callback",
"(",
"null",
",",
"data",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
",",
"null",
")",
";",
"}",
")",
";",
"}"
] | define the response function wrapper | [
"define",
"the",
"response",
"function",
"wrapper"
] | 708e7caa6bea706276d55b3678d8468438d6d163 | https://github.com/byu-oit/aws-scatter-gather/blob/708e7caa6bea706276d55b3678d8468438d6d163/bin/response.js#L48-L68 |
|
56,250 | paukan-org/core | common/index.js | serviceConfig | function serviceConfig() {
var arg = ld.values(arguments), cfg = {};
// try to load file from global directory
if(typeof arg[0] === 'string') {
var path = arg.shift();
try {
cfg = require('/etc/paukan/'+path+'.json');
} catch (err) { // try to load file directly if global fails
try {
cfg = require(path);
} catch (err) {}
}
}
// append default settings
var localCfg = arg.shift();
if(!ld.isPlainObject(localCfg)) {
throw new Error('at least local config should be specified');
}
ld.defaults(cfg, localCfg);
// load specific field from package.json
var packageCfg = arg.shift();
if(ld.isPlainObject(packageCfg)) {
ld.defaults(cfg, ld.pick(packageCfg, ['version', 'description', 'homepage', 'author']));
}
return cfg;
} | javascript | function serviceConfig() {
var arg = ld.values(arguments), cfg = {};
// try to load file from global directory
if(typeof arg[0] === 'string') {
var path = arg.shift();
try {
cfg = require('/etc/paukan/'+path+'.json');
} catch (err) { // try to load file directly if global fails
try {
cfg = require(path);
} catch (err) {}
}
}
// append default settings
var localCfg = arg.shift();
if(!ld.isPlainObject(localCfg)) {
throw new Error('at least local config should be specified');
}
ld.defaults(cfg, localCfg);
// load specific field from package.json
var packageCfg = arg.shift();
if(ld.isPlainObject(packageCfg)) {
ld.defaults(cfg, ld.pick(packageCfg, ['version', 'description', 'homepage', 'author']));
}
return cfg;
} | [
"function",
"serviceConfig",
"(",
")",
"{",
"var",
"arg",
"=",
"ld",
".",
"values",
"(",
"arguments",
")",
",",
"cfg",
"=",
"{",
"}",
";",
"// try to load file from global directory",
"if",
"(",
"typeof",
"arg",
"[",
"0",
"]",
"===",
"'string'",
")",
"{",
"var",
"path",
"=",
"arg",
".",
"shift",
"(",
")",
";",
"try",
"{",
"cfg",
"=",
"require",
"(",
"'/etc/paukan/'",
"+",
"path",
"+",
"'.json'",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"// try to load file directly if global fails",
"try",
"{",
"cfg",
"=",
"require",
"(",
"path",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"}",
"}",
"}",
"// append default settings",
"var",
"localCfg",
"=",
"arg",
".",
"shift",
"(",
")",
";",
"if",
"(",
"!",
"ld",
".",
"isPlainObject",
"(",
"localCfg",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'at least local config should be specified'",
")",
";",
"}",
"ld",
".",
"defaults",
"(",
"cfg",
",",
"localCfg",
")",
";",
"// load specific field from package.json",
"var",
"packageCfg",
"=",
"arg",
".",
"shift",
"(",
")",
";",
"if",
"(",
"ld",
".",
"isPlainObject",
"(",
"packageCfg",
")",
")",
"{",
"ld",
".",
"defaults",
"(",
"cfg",
",",
"ld",
".",
"pick",
"(",
"packageCfg",
",",
"[",
"'version'",
",",
"'description'",
",",
"'homepage'",
",",
"'author'",
"]",
")",
")",
";",
"}",
"return",
"cfg",
";",
"}"
] | Take configuration files and service specific info from package.json
@params {string|object}
- if first parameter is string - will be added config from /etc/paukan/<name>.json
- second parameter is confguration object with default settings
- last (third, or second if name is not specified - object from package.json where service-specific info will be taken) | [
"Take",
"configuration",
"files",
"and",
"service",
"specific",
"info",
"from",
"package",
".",
"json"
] | e6ff0667d50bc9b25ab5678852316e89521942ad | https://github.com/paukan-org/core/blob/e6ff0667d50bc9b25ab5678852316e89521942ad/common/index.js#L15-L45 |
56,251 | paukan-org/core | common/index.js | StreamConsole | function StreamConsole(cfg) {
cfg = cfg || {};
this.color = cfg.color || true;
this.timestamp = (typeof cfg.timestamp === 'undefined') ? 'HH:mm:ss ' : cfg.timestamp;
} | javascript | function StreamConsole(cfg) {
cfg = cfg || {};
this.color = cfg.color || true;
this.timestamp = (typeof cfg.timestamp === 'undefined') ? 'HH:mm:ss ' : cfg.timestamp;
} | [
"function",
"StreamConsole",
"(",
"cfg",
")",
"{",
"cfg",
"=",
"cfg",
"||",
"{",
"}",
";",
"this",
".",
"color",
"=",
"cfg",
".",
"color",
"||",
"true",
";",
"this",
".",
"timestamp",
"=",
"(",
"typeof",
"cfg",
".",
"timestamp",
"===",
"'undefined'",
")",
"?",
"'HH:mm:ss '",
":",
"cfg",
".",
"timestamp",
";",
"}"
] | Stream to console for bunyan logger | [
"Stream",
"to",
"console",
"for",
"bunyan",
"logger"
] | e6ff0667d50bc9b25ab5678852316e89521942ad | https://github.com/paukan-org/core/blob/e6ff0667d50bc9b25ab5678852316e89521942ad/common/index.js#L50-L54 |
56,252 | JGAntunes/ampersand-infinite-scroll | ampersand-infinite-scroll.js | InfiniteScrollSetup | function InfiniteScrollSetup (options) {
options || (options = {});
var self = this;
var gap = (options.gap || 20); // defaults to 20
self.events = self.events || {};
assign(self.events, {scroll: 'infiniteScroll'});
self.infiniteScroll = function () {
if (this.el.scrollHeight - this.el.scrollTop <= this.el.clientHeight + gap) {
this.collection.fetchPage(options);
}
};
} | javascript | function InfiniteScrollSetup (options) {
options || (options = {});
var self = this;
var gap = (options.gap || 20); // defaults to 20
self.events = self.events || {};
assign(self.events, {scroll: 'infiniteScroll'});
self.infiniteScroll = function () {
if (this.el.scrollHeight - this.el.scrollTop <= this.el.clientHeight + gap) {
this.collection.fetchPage(options);
}
};
} | [
"function",
"InfiniteScrollSetup",
"(",
"options",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"var",
"self",
"=",
"this",
";",
"var",
"gap",
"=",
"(",
"options",
".",
"gap",
"||",
"20",
")",
";",
"// defaults to 20",
"self",
".",
"events",
"=",
"self",
".",
"events",
"||",
"{",
"}",
";",
"assign",
"(",
"self",
".",
"events",
",",
"{",
"scroll",
":",
"'infiniteScroll'",
"}",
")",
";",
"self",
".",
"infiniteScroll",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"this",
".",
"el",
".",
"scrollHeight",
"-",
"this",
".",
"el",
".",
"scrollTop",
"<=",
"this",
".",
"el",
".",
"clientHeight",
"+",
"gap",
")",
"{",
"this",
".",
"collection",
".",
"fetchPage",
"(",
"options",
")",
";",
"}",
"}",
";",
"}"
] | Setup the closure function for the Infinite Scroll callback
@param {Object} options - the valid options are:
.gap - the pixel margin to fire the request | [
"Setup",
"the",
"closure",
"function",
"for",
"the",
"Infinite",
"Scroll",
"callback"
] | 6d3906eb1905fb2087199ba7daa64e93b06f7d5f | https://github.com/JGAntunes/ampersand-infinite-scroll/blob/6d3906eb1905fb2087199ba7daa64e93b06f7d5f/ampersand-infinite-scroll.js#L11-L24 |
56,253 | JGAntunes/ampersand-infinite-scroll | ampersand-infinite-scroll.js | InfiniteScrollView | function InfiniteScrollView (options) {
options || (options = {});
BaseView.call(this, options);
InfiniteScrollSetup.call(this, options);
} | javascript | function InfiniteScrollView (options) {
options || (options = {});
BaseView.call(this, options);
InfiniteScrollSetup.call(this, options);
} | [
"function",
"InfiniteScrollView",
"(",
"options",
")",
"{",
"options",
"||",
"(",
"options",
"=",
"{",
"}",
")",
";",
"BaseView",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"InfiniteScrollSetup",
".",
"call",
"(",
"this",
",",
"options",
")",
";",
"}"
] | Infinite Scroll View constructor
@param {Object} options - the valid options according to the `ampersand-view`
and this module | [
"Infinite",
"Scroll",
"View",
"constructor"
] | 6d3906eb1905fb2087199ba7daa64e93b06f7d5f | https://github.com/JGAntunes/ampersand-infinite-scroll/blob/6d3906eb1905fb2087199ba7daa64e93b06f7d5f/ampersand-infinite-scroll.js#L37-L41 |
56,254 | directiv/data-hyper-repeat | index.js | hyperRepeat | function hyperRepeat(store) {
this.compile = compile;
this.state = function(config, state) {
var res = store.get(config.path, state);
if (!res.completed) return false;
return state.set(config.source, res.value);
};
this.children = function(config, state, children) {
var items = state.get(config.source);
var arr = [];
if (!items) return arr;
var target = config.target;
var i, c, child;
var path = ['state', target];
for (i = 0; i < items.length; i++) {
function update() {return items[i]};
for (c = 0; c < children.length; c++) {
child = children[c];
if (!child) continue;
// TODO set the key prop
child = child.updateIn(path, update);
arr.push(child);
}
}
return arr;
};
} | javascript | function hyperRepeat(store) {
this.compile = compile;
this.state = function(config, state) {
var res = store.get(config.path, state);
if (!res.completed) return false;
return state.set(config.source, res.value);
};
this.children = function(config, state, children) {
var items = state.get(config.source);
var arr = [];
if (!items) return arr;
var target = config.target;
var i, c, child;
var path = ['state', target];
for (i = 0; i < items.length; i++) {
function update() {return items[i]};
for (c = 0; c < children.length; c++) {
child = children[c];
if (!child) continue;
// TODO set the key prop
child = child.updateIn(path, update);
arr.push(child);
}
}
return arr;
};
} | [
"function",
"hyperRepeat",
"(",
"store",
")",
"{",
"this",
".",
"compile",
"=",
"compile",
";",
"this",
".",
"state",
"=",
"function",
"(",
"config",
",",
"state",
")",
"{",
"var",
"res",
"=",
"store",
".",
"get",
"(",
"config",
".",
"path",
",",
"state",
")",
";",
"if",
"(",
"!",
"res",
".",
"completed",
")",
"return",
"false",
";",
"return",
"state",
".",
"set",
"(",
"config",
".",
"source",
",",
"res",
".",
"value",
")",
";",
"}",
";",
"this",
".",
"children",
"=",
"function",
"(",
"config",
",",
"state",
",",
"children",
")",
"{",
"var",
"items",
"=",
"state",
".",
"get",
"(",
"config",
".",
"source",
")",
";",
"var",
"arr",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"items",
")",
"return",
"arr",
";",
"var",
"target",
"=",
"config",
".",
"target",
";",
"var",
"i",
",",
"c",
",",
"child",
";",
"var",
"path",
"=",
"[",
"'state'",
",",
"target",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"items",
".",
"length",
";",
"i",
"++",
")",
"{",
"function",
"update",
"(",
")",
"{",
"return",
"items",
"[",
"i",
"]",
"}",
";",
"for",
"(",
"c",
"=",
"0",
";",
"c",
"<",
"children",
".",
"length",
";",
"c",
"++",
")",
"{",
"child",
"=",
"children",
"[",
"c",
"]",
";",
"if",
"(",
"!",
"child",
")",
"continue",
";",
"// TODO set the key prop",
"child",
"=",
"child",
".",
"updateIn",
"(",
"path",
",",
"update",
")",
";",
"arr",
".",
"push",
"(",
"child",
")",
";",
"}",
"}",
"return",
"arr",
";",
"}",
";",
"}"
] | Initialize the 'hyper-repeat' directive
Examples:
user <- users
user <- users[0,2..8]
user <- [.featured[0..2] .famous[0..2] .others[0..2]]
@param {StoreHyper} | [
"Initialize",
"the",
"hyper",
"-",
"repeat",
"directive"
] | 2f2aab31d2f9db4ca83765a793ad6f0c795c3f58 | https://github.com/directiv/data-hyper-repeat/blob/2f2aab31d2f9db4ca83765a793ad6f0c795c3f58/index.js#L28-L60 |
56,255 | directiv/data-hyper-repeat | index.js | compile | function compile(input) {
var res = input.match(REGEX);
if (!res) throw new Error('Invalid expression: "' + input + '"');
var range = res[3];
var parsedRange;
if (range) {
parsedRange = parser(range);
if (parsedRange === null) throw new Error('Invalid range expression: "' + range + '" in "' + input + '"');
}
var path = res[2];
var source = path.split('.');
// TODO support ranges
if (parsedRange) console.warn('data-hyper-repeat ranges are not supported at this time');
return {
target: res[1],
path: path,
source: source[source.length - 1],
range: parsedRange
};
} | javascript | function compile(input) {
var res = input.match(REGEX);
if (!res) throw new Error('Invalid expression: "' + input + '"');
var range = res[3];
var parsedRange;
if (range) {
parsedRange = parser(range);
if (parsedRange === null) throw new Error('Invalid range expression: "' + range + '" in "' + input + '"');
}
var path = res[2];
var source = path.split('.');
// TODO support ranges
if (parsedRange) console.warn('data-hyper-repeat ranges are not supported at this time');
return {
target: res[1],
path: path,
source: source[source.length - 1],
range: parsedRange
};
} | [
"function",
"compile",
"(",
"input",
")",
"{",
"var",
"res",
"=",
"input",
".",
"match",
"(",
"REGEX",
")",
";",
"if",
"(",
"!",
"res",
")",
"throw",
"new",
"Error",
"(",
"'Invalid expression: \"'",
"+",
"input",
"+",
"'\"'",
")",
";",
"var",
"range",
"=",
"res",
"[",
"3",
"]",
";",
"var",
"parsedRange",
";",
"if",
"(",
"range",
")",
"{",
"parsedRange",
"=",
"parser",
"(",
"range",
")",
";",
"if",
"(",
"parsedRange",
"===",
"null",
")",
"throw",
"new",
"Error",
"(",
"'Invalid range expression: \"'",
"+",
"range",
"+",
"'\" in \"'",
"+",
"input",
"+",
"'\"'",
")",
";",
"}",
"var",
"path",
"=",
"res",
"[",
"2",
"]",
";",
"var",
"source",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
";",
"// TODO support ranges",
"if",
"(",
"parsedRange",
")",
"console",
".",
"warn",
"(",
"'data-hyper-repeat ranges are not supported at this time'",
")",
";",
"return",
"{",
"target",
":",
"res",
"[",
"1",
"]",
",",
"path",
":",
"path",
",",
"source",
":",
"source",
"[",
"source",
".",
"length",
"-",
"1",
"]",
",",
"range",
":",
"parsedRange",
"}",
";",
"}"
] | Compile a 'hyper-repeat' expression | [
"Compile",
"a",
"hyper",
"-",
"repeat",
"expression"
] | 2f2aab31d2f9db4ca83765a793ad6f0c795c3f58 | https://github.com/directiv/data-hyper-repeat/blob/2f2aab31d2f9db4ca83765a793ad6f0c795c3f58/index.js#L72-L95 |
56,256 | RnbWd/parse-browserify | lib/file.js | function(file, type) {
var promise = new Parse.Promise();
if (typeof(FileReader) === "undefined") {
return Parse.Promise.error(new Parse.Error(
Parse.Error.FILE_READ_ERROR,
"Attempted to use a FileReader on an unsupported browser."));
}
var reader = new FileReader();
reader.onloadend = function() {
if (reader.readyState !== 2) {
promise.reject(new Parse.Error(
Parse.Error.FILE_READ_ERROR,
"Error reading file."));
return;
}
var dataURL = reader.result;
var matches = /^data:([^;]*);base64,(.*)$/.exec(dataURL);
if (!matches) {
promise.reject(new Parse.Error(
Parse.ERROR.FILE_READ_ERROR,
"Unable to interpret data URL: " + dataURL));
return;
}
promise.resolve(matches[2], type || matches[1]);
};
reader.readAsDataURL(file);
return promise;
} | javascript | function(file, type) {
var promise = new Parse.Promise();
if (typeof(FileReader) === "undefined") {
return Parse.Promise.error(new Parse.Error(
Parse.Error.FILE_READ_ERROR,
"Attempted to use a FileReader on an unsupported browser."));
}
var reader = new FileReader();
reader.onloadend = function() {
if (reader.readyState !== 2) {
promise.reject(new Parse.Error(
Parse.Error.FILE_READ_ERROR,
"Error reading file."));
return;
}
var dataURL = reader.result;
var matches = /^data:([^;]*);base64,(.*)$/.exec(dataURL);
if (!matches) {
promise.reject(new Parse.Error(
Parse.ERROR.FILE_READ_ERROR,
"Unable to interpret data URL: " + dataURL));
return;
}
promise.resolve(matches[2], type || matches[1]);
};
reader.readAsDataURL(file);
return promise;
} | [
"function",
"(",
"file",
",",
"type",
")",
"{",
"var",
"promise",
"=",
"new",
"Parse",
".",
"Promise",
"(",
")",
";",
"if",
"(",
"typeof",
"(",
"FileReader",
")",
"===",
"\"undefined\"",
")",
"{",
"return",
"Parse",
".",
"Promise",
".",
"error",
"(",
"new",
"Parse",
".",
"Error",
"(",
"Parse",
".",
"Error",
".",
"FILE_READ_ERROR",
",",
"\"Attempted to use a FileReader on an unsupported browser.\"",
")",
")",
";",
"}",
"var",
"reader",
"=",
"new",
"FileReader",
"(",
")",
";",
"reader",
".",
"onloadend",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"reader",
".",
"readyState",
"!==",
"2",
")",
"{",
"promise",
".",
"reject",
"(",
"new",
"Parse",
".",
"Error",
"(",
"Parse",
".",
"Error",
".",
"FILE_READ_ERROR",
",",
"\"Error reading file.\"",
")",
")",
";",
"return",
";",
"}",
"var",
"dataURL",
"=",
"reader",
".",
"result",
";",
"var",
"matches",
"=",
"/",
"^data:([^;]*);base64,(.*)$",
"/",
".",
"exec",
"(",
"dataURL",
")",
";",
"if",
"(",
"!",
"matches",
")",
"{",
"promise",
".",
"reject",
"(",
"new",
"Parse",
".",
"Error",
"(",
"Parse",
".",
"ERROR",
".",
"FILE_READ_ERROR",
",",
"\"Unable to interpret data URL: \"",
"+",
"dataURL",
")",
")",
";",
"return",
";",
"}",
"promise",
".",
"resolve",
"(",
"matches",
"[",
"2",
"]",
",",
"type",
"||",
"matches",
"[",
"1",
"]",
")",
";",
"}",
";",
"reader",
".",
"readAsDataURL",
"(",
"file",
")",
";",
"return",
"promise",
";",
"}"
] | Reads a File using a FileReader.
@param file {File} the File to read.
@param type {String} (optional) the mimetype to override with.
@return {Parse.Promise} A Promise that will be fulfilled with a
base64-encoded string of the data and its mime type. | [
"Reads",
"a",
"File",
"using",
"a",
"FileReader",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/file.js#L253-L284 |
|
56,257 | RnbWd/parse-browserify | lib/file.js | function(options) {
options= options || {};
var self = this;
if (!self._previousSave) {
self._previousSave = self._source.then(function(base64, type) {
var data = {
base64: base64,
_ContentType: type
};
return Parse._request({
route: "files",
className: self._name,
method: 'POST',
data: data,
useMasterKey: options.useMasterKey
});
}).then(function(response) {
self._name = response.name;
self._url = response.url;
return self;
});
}
return self._previousSave._thenRunCallbacks(options);
} | javascript | function(options) {
options= options || {};
var self = this;
if (!self._previousSave) {
self._previousSave = self._source.then(function(base64, type) {
var data = {
base64: base64,
_ContentType: type
};
return Parse._request({
route: "files",
className: self._name,
method: 'POST',
data: data,
useMasterKey: options.useMasterKey
});
}).then(function(response) {
self._name = response.name;
self._url = response.url;
return self;
});
}
return self._previousSave._thenRunCallbacks(options);
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"self",
".",
"_previousSave",
")",
"{",
"self",
".",
"_previousSave",
"=",
"self",
".",
"_source",
".",
"then",
"(",
"function",
"(",
"base64",
",",
"type",
")",
"{",
"var",
"data",
"=",
"{",
"base64",
":",
"base64",
",",
"_ContentType",
":",
"type",
"}",
";",
"return",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"\"files\"",
",",
"className",
":",
"self",
".",
"_name",
",",
"method",
":",
"'POST'",
",",
"data",
":",
"data",
",",
"useMasterKey",
":",
"options",
".",
"useMasterKey",
"}",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"self",
".",
"_name",
"=",
"response",
".",
"name",
";",
"self",
".",
"_url",
"=",
"response",
".",
"url",
";",
"return",
"self",
";",
"}",
")",
";",
"}",
"return",
"self",
".",
"_previousSave",
".",
"_thenRunCallbacks",
"(",
"options",
")",
";",
"}"
] | Saves the file to the Parse cloud.
@param {Object} options A Backbone-style options object.
@return {Parse.Promise} Promise that is resolved when the save finishes. | [
"Saves",
"the",
"file",
"to",
"the",
"Parse",
"cloud",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/file.js#L374-L399 |
|
56,258 | Zenedith/npm-my-restify-api | lib/public/swagger/swagger-ui.js | function (operation, parameter) {
// TODO the reference to operation.api is not available
if (operation.api && operation.api.parameterMacro) {
return operation.api.parameterMacro(operation, parameter);
} else {
return parameter.defaultValue;
}
} | javascript | function (operation, parameter) {
// TODO the reference to operation.api is not available
if (operation.api && operation.api.parameterMacro) {
return operation.api.parameterMacro(operation, parameter);
} else {
return parameter.defaultValue;
}
} | [
"function",
"(",
"operation",
",",
"parameter",
")",
"{",
"// TODO the reference to operation.api is not available",
"if",
"(",
"operation",
".",
"api",
"&&",
"operation",
".",
"api",
".",
"parameterMacro",
")",
"{",
"return",
"operation",
".",
"api",
".",
"parameterMacro",
"(",
"operation",
",",
"parameter",
")",
";",
"}",
"else",
"{",
"return",
"parameter",
".",
"defaultValue",
";",
"}",
"}"
] | allows override of the default value based on the parameter being
supplied | [
"allows",
"override",
"of",
"the",
"default",
"value",
"based",
"on",
"the",
"parameter",
"being",
"supplied"
] | 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/public/swagger/swagger-ui.js#L2650-L2657 |
|
56,259 | Zenedith/npm-my-restify-api | lib/public/swagger/swagger-ui.js | function (model, property) {
// TODO the reference to model.api is not available
if (model.api && model.api.modelPropertyMacro) {
return model.api.modelPropertyMacro(model, property);
} else {
return property.default;
}
} | javascript | function (model, property) {
// TODO the reference to model.api is not available
if (model.api && model.api.modelPropertyMacro) {
return model.api.modelPropertyMacro(model, property);
} else {
return property.default;
}
} | [
"function",
"(",
"model",
",",
"property",
")",
"{",
"// TODO the reference to model.api is not available",
"if",
"(",
"model",
".",
"api",
"&&",
"model",
".",
"api",
".",
"modelPropertyMacro",
")",
"{",
"return",
"model",
".",
"api",
".",
"modelPropertyMacro",
"(",
"model",
",",
"property",
")",
";",
"}",
"else",
"{",
"return",
"property",
".",
"default",
";",
"}",
"}"
] | allows overriding the default value of an model property | [
"allows",
"overriding",
"the",
"default",
"value",
"of",
"an",
"model",
"property"
] | 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/public/swagger/swagger-ui.js#L2662-L2669 |
|
56,260 | Zenedith/npm-my-restify-api | lib/public/swagger/swagger-ui.js | baseIsEqual | function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other);
}
var valType = typeof value,
othType = typeof other;
// Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
value == null || other == null) {
// Return `false` unless both values are `NaN`.
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
} | javascript | function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
// Exit early for identical values.
if (value === other) {
// Treat `+0` vs. `-0` as not equal.
return value !== 0 || (1 / value == 1 / other);
}
var valType = typeof value,
othType = typeof other;
// Exit early for unlike primitive values.
if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') ||
value == null || other == null) {
// Return `false` unless both values are `NaN`.
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
} | [
"function",
"baseIsEqual",
"(",
"value",
",",
"other",
",",
"customizer",
",",
"isLoose",
",",
"stackA",
",",
"stackB",
")",
"{",
"// Exit early for identical values.",
"if",
"(",
"value",
"===",
"other",
")",
"{",
"// Treat `+0` vs. `-0` as not equal.",
"return",
"value",
"!==",
"0",
"||",
"(",
"1",
"/",
"value",
"==",
"1",
"/",
"other",
")",
";",
"}",
"var",
"valType",
"=",
"typeof",
"value",
",",
"othType",
"=",
"typeof",
"other",
";",
"// Exit early for unlike primitive values.",
"if",
"(",
"(",
"valType",
"!=",
"'function'",
"&&",
"valType",
"!=",
"'object'",
"&&",
"othType",
"!=",
"'function'",
"&&",
"othType",
"!=",
"'object'",
")",
"||",
"value",
"==",
"null",
"||",
"other",
"==",
"null",
")",
"{",
"// Return `false` unless both values are `NaN`.",
"return",
"value",
"!==",
"value",
"&&",
"other",
"!==",
"other",
";",
"}",
"return",
"baseIsEqualDeep",
"(",
"value",
",",
"other",
",",
"baseIsEqual",
",",
"customizer",
",",
"isLoose",
",",
"stackA",
",",
"stackB",
")",
";",
"}"
] | The base implementation of `_.isEqual` without support for `this` binding
`customizer` functions.
@private
@param {*} value The value to compare.
@param {*} other The other value to compare.
@param {Function} [customizer] The function to customize comparing values.
@param {boolean} [isLoose] Specify performing partial comparisons.
@param {Array} [stackA] Tracks traversed `value` objects.
@param {Array} [stackB] Tracks traversed `other` objects.
@returns {boolean} Returns `true` if the values are equivalent, else `false`. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"isEqual",
"without",
"support",
"for",
"this",
"binding",
"customizer",
"functions",
"."
] | 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/public/swagger/swagger-ui.js#L16021-L16037 |
56,261 | Zenedith/npm-my-restify-api | lib/public/swagger/swagger-ui.js | baseMatchesProperty | function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
return function(object) {
return object != null && baseIsEqual(value, object[key], null, true);
};
} | javascript | function baseMatchesProperty(key, value) {
if (isStrictComparable(value)) {
return function(object) {
return object != null && object[key] === value &&
(typeof value != 'undefined' || (key in toObject(object)));
};
}
return function(object) {
return object != null && baseIsEqual(value, object[key], null, true);
};
} | [
"function",
"baseMatchesProperty",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"isStrictComparable",
"(",
"value",
")",
")",
"{",
"return",
"function",
"(",
"object",
")",
"{",
"return",
"object",
"!=",
"null",
"&&",
"object",
"[",
"key",
"]",
"===",
"value",
"&&",
"(",
"typeof",
"value",
"!=",
"'undefined'",
"||",
"(",
"key",
"in",
"toObject",
"(",
"object",
")",
")",
")",
";",
"}",
";",
"}",
"return",
"function",
"(",
"object",
")",
"{",
"return",
"object",
"!=",
"null",
"&&",
"baseIsEqual",
"(",
"value",
",",
"object",
"[",
"key",
"]",
",",
"null",
",",
"true",
")",
";",
"}",
";",
"}"
] | The base implementation of `_.matchesProperty` which does not coerce `key`
to a string.
@private
@param {string} key The key of the property to get.
@param {*} value The value to compare.
@returns {Function} Returns the new function. | [
"The",
"base",
"implementation",
"of",
"_",
".",
"matchesProperty",
"which",
"does",
"not",
"coerce",
"key",
"to",
"a",
"string",
"."
] | 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/public/swagger/swagger-ui.js#L16314-L16324 |
56,262 | Zenedith/npm-my-restify-api | lib/public/swagger/swagger-ui.js | createBaseEach | function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}
var index = fromRight ? length : -1,
iterable = toObject(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
} | javascript | function createBaseEach(eachFunc, fromRight) {
return function(collection, iteratee) {
var length = collection ? collection.length : 0;
if (!isLength(length)) {
return eachFunc(collection, iteratee);
}
var index = fromRight ? length : -1,
iterable = toObject(collection);
while ((fromRight ? index-- : ++index < length)) {
if (iteratee(iterable[index], index, iterable) === false) {
break;
}
}
return collection;
};
} | [
"function",
"createBaseEach",
"(",
"eachFunc",
",",
"fromRight",
")",
"{",
"return",
"function",
"(",
"collection",
",",
"iteratee",
")",
"{",
"var",
"length",
"=",
"collection",
"?",
"collection",
".",
"length",
":",
"0",
";",
"if",
"(",
"!",
"isLength",
"(",
"length",
")",
")",
"{",
"return",
"eachFunc",
"(",
"collection",
",",
"iteratee",
")",
";",
"}",
"var",
"index",
"=",
"fromRight",
"?",
"length",
":",
"-",
"1",
",",
"iterable",
"=",
"toObject",
"(",
"collection",
")",
";",
"while",
"(",
"(",
"fromRight",
"?",
"index",
"--",
":",
"++",
"index",
"<",
"length",
")",
")",
"{",
"if",
"(",
"iteratee",
"(",
"iterable",
"[",
"index",
"]",
",",
"index",
",",
"iterable",
")",
"===",
"false",
")",
"{",
"break",
";",
"}",
"}",
"return",
"collection",
";",
"}",
";",
"}"
] | Creates a `baseEach` or `baseEachRight` function.
@private
@param {Function} eachFunc The function to iterate over a collection.
@param {boolean} [fromRight] Specify iterating from right to left.
@returns {Function} Returns the new base function. | [
"Creates",
"a",
"baseEach",
"or",
"baseEachRight",
"function",
"."
] | 946e40ede37124f6f4acaea19d73ab3c9d5074d9 | https://github.com/Zenedith/npm-my-restify-api/blob/946e40ede37124f6f4acaea19d73ab3c9d5074d9/lib/public/swagger/swagger-ui.js#L16664-L16680 |
56,263 | phun-ky/patsy | lib/config.js | function(config,callback,patsy){
patsy = typeof config === 'function' && typeof callback === 'object' ? callback : patsy;
callback = typeof config === 'function' ? config : callback;
config = typeof config === 'function' ? undefined : config;
if(typeof config !== 'undefined' && typeof callback !== 'undefined' && typeof callback === 'function'){
try{
config = this.bake(config);
fs.writeFileSync( "patsy.json", JSON.stringify( config, null, 2 ) );
callback(patsy);
} catch(e){
console.log('config.create',e);
return false;
}
} else {
patsy.config.generateDefaultConfiguration();
callback(patsy);
}
} | javascript | function(config,callback,patsy){
patsy = typeof config === 'function' && typeof callback === 'object' ? callback : patsy;
callback = typeof config === 'function' ? config : callback;
config = typeof config === 'function' ? undefined : config;
if(typeof config !== 'undefined' && typeof callback !== 'undefined' && typeof callback === 'function'){
try{
config = this.bake(config);
fs.writeFileSync( "patsy.json", JSON.stringify( config, null, 2 ) );
callback(patsy);
} catch(e){
console.log('config.create',e);
return false;
}
} else {
patsy.config.generateDefaultConfiguration();
callback(patsy);
}
} | [
"function",
"(",
"config",
",",
"callback",
",",
"patsy",
")",
"{",
"patsy",
"=",
"typeof",
"config",
"===",
"'function'",
"&&",
"typeof",
"callback",
"===",
"'object'",
"?",
"callback",
":",
"patsy",
";",
"callback",
"=",
"typeof",
"config",
"===",
"'function'",
"?",
"config",
":",
"callback",
";",
"config",
"=",
"typeof",
"config",
"===",
"'function'",
"?",
"undefined",
":",
"config",
";",
"if",
"(",
"typeof",
"config",
"!==",
"'undefined'",
"&&",
"typeof",
"callback",
"!==",
"'undefined'",
"&&",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"try",
"{",
"config",
"=",
"this",
".",
"bake",
"(",
"config",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"\"patsy.json\"",
",",
"JSON",
".",
"stringify",
"(",
"config",
",",
"null",
",",
"2",
")",
")",
";",
"callback",
"(",
"patsy",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"console",
".",
"log",
"(",
"'config.create'",
",",
"e",
")",
";",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"patsy",
".",
"config",
".",
"generateDefaultConfiguration",
"(",
")",
";",
"callback",
"(",
"patsy",
")",
";",
"}",
"}"
] | Function to create a config file with given configuration object
@param Object config
@param Funciton callback | [
"Function",
"to",
"create",
"a",
"config",
"file",
"with",
"given",
"configuration",
"object"
] | b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5 | https://github.com/phun-ky/patsy/blob/b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5/lib/config.js#L75-L110 |
|
56,264 | phun-ky/patsy | lib/config.js | function(patsy, project_path){
if(opts.verbose){
util.print('>>'.cyan + ' Loading project configuration...');
}
if(typeof project_path === 'undefined'){
if(opts.verbose){
patsy.utils.notice();
patsy.utils.notice('No project path set, declaring path to CWD: '.white + String(process.cwd() + path.sep).inverse.cyan + '');
}
project_path = opts.project_path || process.cwd() + path.sep;
} else {
if(opts.verbose){
patsy.utils.ok();
}
}
var _path_to_config = project_path + 'patsy.json';
if(opts.verbose){
util.print('>>'.cyan + ' Reading project configuration file: ' + _path_to_config.inverse.cyan + '...\n');
}
if(!fs.existsSync(_path_to_config)){
patsy.utils.notice();
if(opts.verbose){
patsy.utils.notice('Configuration file not found here, looking elsewhere: ' + _path_to_config.inverse.cyan + '...\n');
}
patsy.scripture.print('[Patsy]'.yellow + ': <stumbling forward>\n');
_path_to_config = this.searchForConfigFile(patsy);
}
if(fs.existsSync(_path_to_config)){
if(opts.verbose){
patsy.utils.ok('File found here: ' + _path_to_config.inverse.cyan);
util.print('>>'.cyan + ' Loading project configuration...');
}
// Read file synchroneously, parse contents as JSON and return config
var _config_json;
try{
_config_json = require(_path_to_config);
} catch (e){
patsy.utils.fail();
}
if(this.validate(_config_json)){
if(opts.verbose){
patsy.utils.ok();
}
} else {
if(opts.verbose){
patsy.utils.fail('Configuration file is not valid!');
}
patsy.scripture.print('[Patsy]'.yellow + ': Sire! The configuration script is not valid! We have to turn around!\n');
process.exit(1);
}
_config_json.project.environment.rel_path = path.relative(_config_json.appPath || '', _config_json.project.environment.abs_path) + path.sep;
return _config_json;
} else {
if(opts.verbose){
util.print('>> FAIL'.red + ': Loading project configuration: Could not find configuration file!'.white + '\n');
}
return undefined;
}
} | javascript | function(patsy, project_path){
if(opts.verbose){
util.print('>>'.cyan + ' Loading project configuration...');
}
if(typeof project_path === 'undefined'){
if(opts.verbose){
patsy.utils.notice();
patsy.utils.notice('No project path set, declaring path to CWD: '.white + String(process.cwd() + path.sep).inverse.cyan + '');
}
project_path = opts.project_path || process.cwd() + path.sep;
} else {
if(opts.verbose){
patsy.utils.ok();
}
}
var _path_to_config = project_path + 'patsy.json';
if(opts.verbose){
util.print('>>'.cyan + ' Reading project configuration file: ' + _path_to_config.inverse.cyan + '...\n');
}
if(!fs.existsSync(_path_to_config)){
patsy.utils.notice();
if(opts.verbose){
patsy.utils.notice('Configuration file not found here, looking elsewhere: ' + _path_to_config.inverse.cyan + '...\n');
}
patsy.scripture.print('[Patsy]'.yellow + ': <stumbling forward>\n');
_path_to_config = this.searchForConfigFile(patsy);
}
if(fs.existsSync(_path_to_config)){
if(opts.verbose){
patsy.utils.ok('File found here: ' + _path_to_config.inverse.cyan);
util.print('>>'.cyan + ' Loading project configuration...');
}
// Read file synchroneously, parse contents as JSON and return config
var _config_json;
try{
_config_json = require(_path_to_config);
} catch (e){
patsy.utils.fail();
}
if(this.validate(_config_json)){
if(opts.verbose){
patsy.utils.ok();
}
} else {
if(opts.verbose){
patsy.utils.fail('Configuration file is not valid!');
}
patsy.scripture.print('[Patsy]'.yellow + ': Sire! The configuration script is not valid! We have to turn around!\n');
process.exit(1);
}
_config_json.project.environment.rel_path = path.relative(_config_json.appPath || '', _config_json.project.environment.abs_path) + path.sep;
return _config_json;
} else {
if(opts.verbose){
util.print('>> FAIL'.red + ': Loading project configuration: Could not find configuration file!'.white + '\n');
}
return undefined;
}
} | [
"function",
"(",
"patsy",
",",
"project_path",
")",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"util",
".",
"print",
"(",
"'>>'",
".",
"cyan",
"+",
"' Loading project configuration...'",
")",
";",
"}",
"if",
"(",
"typeof",
"project_path",
"===",
"'undefined'",
")",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"notice",
"(",
")",
";",
"patsy",
".",
"utils",
".",
"notice",
"(",
"'No project path set, declaring path to CWD: '",
".",
"white",
"+",
"String",
"(",
"process",
".",
"cwd",
"(",
")",
"+",
"path",
".",
"sep",
")",
".",
"inverse",
".",
"cyan",
"+",
"''",
")",
";",
"}",
"project_path",
"=",
"opts",
".",
"project_path",
"||",
"process",
".",
"cwd",
"(",
")",
"+",
"path",
".",
"sep",
";",
"}",
"else",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"ok",
"(",
")",
";",
"}",
"}",
"var",
"_path_to_config",
"=",
"project_path",
"+",
"'patsy.json'",
";",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"util",
".",
"print",
"(",
"'>>'",
".",
"cyan",
"+",
"' Reading project configuration file: '",
"+",
"_path_to_config",
".",
"inverse",
".",
"cyan",
"+",
"'...\\n'",
")",
";",
"}",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"_path_to_config",
")",
")",
"{",
"patsy",
".",
"utils",
".",
"notice",
"(",
")",
";",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"notice",
"(",
"'Configuration file not found here, looking elsewhere: '",
"+",
"_path_to_config",
".",
"inverse",
".",
"cyan",
"+",
"'...\\n'",
")",
";",
"}",
"patsy",
".",
"scripture",
".",
"print",
"(",
"'[Patsy]'",
".",
"yellow",
"+",
"': <stumbling forward>\\n'",
")",
";",
"_path_to_config",
"=",
"this",
".",
"searchForConfigFile",
"(",
"patsy",
")",
";",
"}",
"if",
"(",
"fs",
".",
"existsSync",
"(",
"_path_to_config",
")",
")",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"ok",
"(",
"'File found here: '",
"+",
"_path_to_config",
".",
"inverse",
".",
"cyan",
")",
";",
"util",
".",
"print",
"(",
"'>>'",
".",
"cyan",
"+",
"' Loading project configuration...'",
")",
";",
"}",
"// Read file synchroneously, parse contents as JSON and return config",
"var",
"_config_json",
";",
"try",
"{",
"_config_json",
"=",
"require",
"(",
"_path_to_config",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"patsy",
".",
"utils",
".",
"fail",
"(",
")",
";",
"}",
"if",
"(",
"this",
".",
"validate",
"(",
"_config_json",
")",
")",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"ok",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"patsy",
".",
"utils",
".",
"fail",
"(",
"'Configuration file is not valid!'",
")",
";",
"}",
"patsy",
".",
"scripture",
".",
"print",
"(",
"'[Patsy]'",
".",
"yellow",
"+",
"': Sire! The configuration script is not valid! We have to turn around!\\n'",
")",
";",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"_config_json",
".",
"project",
".",
"environment",
".",
"rel_path",
"=",
"path",
".",
"relative",
"(",
"_config_json",
".",
"appPath",
"||",
"''",
",",
"_config_json",
".",
"project",
".",
"environment",
".",
"abs_path",
")",
"+",
"path",
".",
"sep",
";",
"return",
"_config_json",
";",
"}",
"else",
"{",
"if",
"(",
"opts",
".",
"verbose",
")",
"{",
"util",
".",
"print",
"(",
"'>> FAIL'",
".",
"red",
"+",
"': Loading project configuration: Could not find configuration file!'",
".",
"white",
"+",
"'\\n'",
")",
";",
"}",
"return",
"undefined",
";",
"}",
"}"
] | Function to load patsy configuration
@param Object patsy
@param String projectPath
@return Object | [
"Function",
"to",
"load",
"patsy",
"configuration"
] | b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5 | https://github.com/phun-ky/patsy/blob/b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5/lib/config.js#L265-L374 |
|
56,265 | phun-ky/patsy | lib/config.js | function () {
var defaultConfig = JSON.parse(fs.readFileSync(__dirname + '/../patsy.default.json', 'utf8'));
var projectSpecificSettings = {
"project": {
"details" : {
"name" : path.basename(process.cwd())
},
"environment": {
"root" : path.basename(process.cwd()),
"abs_path": process.cwd() + path.sep
}
}
};
var almostDefaultConfig = require('./utils').deepExtend(defaultConfig, projectSpecificSettings);
almostDefaultConfig = JSON.stringify(almostDefaultConfig, null, 2);
fs.writeFileSync("patsy.json", almostDefaultConfig);
} | javascript | function () {
var defaultConfig = JSON.parse(fs.readFileSync(__dirname + '/../patsy.default.json', 'utf8'));
var projectSpecificSettings = {
"project": {
"details" : {
"name" : path.basename(process.cwd())
},
"environment": {
"root" : path.basename(process.cwd()),
"abs_path": process.cwd() + path.sep
}
}
};
var almostDefaultConfig = require('./utils').deepExtend(defaultConfig, projectSpecificSettings);
almostDefaultConfig = JSON.stringify(almostDefaultConfig, null, 2);
fs.writeFileSync("patsy.json", almostDefaultConfig);
} | [
"function",
"(",
")",
"{",
"var",
"defaultConfig",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"__dirname",
"+",
"'/../patsy.default.json'",
",",
"'utf8'",
")",
")",
";",
"var",
"projectSpecificSettings",
"=",
"{",
"\"project\"",
":",
"{",
"\"details\"",
":",
"{",
"\"name\"",
":",
"path",
".",
"basename",
"(",
"process",
".",
"cwd",
"(",
")",
")",
"}",
",",
"\"environment\"",
":",
"{",
"\"root\"",
":",
"path",
".",
"basename",
"(",
"process",
".",
"cwd",
"(",
")",
")",
",",
"\"abs_path\"",
":",
"process",
".",
"cwd",
"(",
")",
"+",
"path",
".",
"sep",
"}",
"}",
"}",
";",
"var",
"almostDefaultConfig",
"=",
"require",
"(",
"'./utils'",
")",
".",
"deepExtend",
"(",
"defaultConfig",
",",
"projectSpecificSettings",
")",
";",
"almostDefaultConfig",
"=",
"JSON",
".",
"stringify",
"(",
"almostDefaultConfig",
",",
"null",
",",
"2",
")",
";",
"fs",
".",
"writeFileSync",
"(",
"\"patsy.json\"",
",",
"almostDefaultConfig",
")",
";",
"}"
] | Generates a default patsy.json configuration file in the root of the current project.
@var Object | [
"Generates",
"a",
"default",
"patsy",
".",
"json",
"configuration",
"file",
"in",
"the",
"root",
"of",
"the",
"current",
"project",
"."
] | b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5 | https://github.com/phun-ky/patsy/blob/b2bf3e6c72e17c38d9b2cf2fa4306478fc3858a5/lib/config.js#L380-L401 |
|
56,266 | ltoussaint/node-bootstrap-core | application.js | dispatch | function dispatch(request, response) {
return Promise.resolve()
.then(resolveRouters.bind(this, request))
.then(callAction.bind(this, request, response));
} | javascript | function dispatch(request, response) {
return Promise.resolve()
.then(resolveRouters.bind(this, request))
.then(callAction.bind(this, request, response));
} | [
"function",
"dispatch",
"(",
"request",
",",
"response",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
")",
".",
"then",
"(",
"resolveRouters",
".",
"bind",
"(",
"this",
",",
"request",
")",
")",
".",
"then",
"(",
"callAction",
".",
"bind",
"(",
"this",
",",
"request",
",",
"response",
")",
")",
";",
"}"
] | Dispatch request in good action using routers
@param request
@param response
@returns {Promise} | [
"Dispatch",
"request",
"in",
"good",
"action",
"using",
"routers"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/application.js#L105-L109 |
56,267 | ltoussaint/node-bootstrap-core | application.js | resolveRouters | function resolveRouters(request) {
for (var i = 0, l = routers.length; i < l; i++) {
var callback = routers[i].resolve(request);
if (null != callback) {
return Promise.resolve(callback);
}
}
return Promise.reject('Route not defined for "' + request.url + '"');
} | javascript | function resolveRouters(request) {
for (var i = 0, l = routers.length; i < l; i++) {
var callback = routers[i].resolve(request);
if (null != callback) {
return Promise.resolve(callback);
}
}
return Promise.reject('Route not defined for "' + request.url + '"');
} | [
"function",
"resolveRouters",
"(",
"request",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"routers",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"var",
"callback",
"=",
"routers",
"[",
"i",
"]",
".",
"resolve",
"(",
"request",
")",
";",
"if",
"(",
"null",
"!=",
"callback",
")",
"{",
"return",
"Promise",
".",
"resolve",
"(",
"callback",
")",
";",
"}",
"}",
"return",
"Promise",
".",
"reject",
"(",
"'Route not defined for \"'",
"+",
"request",
".",
"url",
"+",
"'\"'",
")",
";",
"}"
] | Resolve uri using routers
@param request
@returns {Promise} | [
"Resolve",
"uri",
"using",
"routers"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/application.js#L116-L124 |
56,268 | ltoussaint/node-bootstrap-core | application.js | callAction | function callAction(request, response, callback) {
if (typeof callback == 'function') {
return Promive.resolve()
.then(callback.bind(null, request, response));
}
try {
var Action = require(ACTION_PATH + '/' + callback.action + '.js');
} catch (error) {
if (error.message == 'Cannot find module \'' + ACTION_PATH + '/' + callback.action + '.js\'') {
return Promise.reject('Action ' + callback.action + ' does not exist.')
.catch(this.onPageNotFound.bind(this, request, response));
}
return Promise.reject(error)
.catch(this.onError.bind(this, request, response));
}
var instance = new Action(request, response);
// Test if method exists
if (!instance[callback.method]) {
return Promise.reject(new Error('Method "' + callback.method + '" not found in action "' + callback.action + '"'));
}
var promise = Promise.resolve();
if (instance.init && 'function' == typeof instance.init) {
promise = promise.then(function () {
return instance.init();
});
}
promise = promise.then(function () {
return instance[callback.method].apply(instance, callback.arguments);
});
if (instance.onError && 'function' == typeof instance.onError) {
promise = promise.catch(function (error) {
return instance.onError.call(instance, error)
});
}
promise = promise.catch(this.onError.bind(this, request, response));
return promise;
} | javascript | function callAction(request, response, callback) {
if (typeof callback == 'function') {
return Promive.resolve()
.then(callback.bind(null, request, response));
}
try {
var Action = require(ACTION_PATH + '/' + callback.action + '.js');
} catch (error) {
if (error.message == 'Cannot find module \'' + ACTION_PATH + '/' + callback.action + '.js\'') {
return Promise.reject('Action ' + callback.action + ' does not exist.')
.catch(this.onPageNotFound.bind(this, request, response));
}
return Promise.reject(error)
.catch(this.onError.bind(this, request, response));
}
var instance = new Action(request, response);
// Test if method exists
if (!instance[callback.method]) {
return Promise.reject(new Error('Method "' + callback.method + '" not found in action "' + callback.action + '"'));
}
var promise = Promise.resolve();
if (instance.init && 'function' == typeof instance.init) {
promise = promise.then(function () {
return instance.init();
});
}
promise = promise.then(function () {
return instance[callback.method].apply(instance, callback.arguments);
});
if (instance.onError && 'function' == typeof instance.onError) {
promise = promise.catch(function (error) {
return instance.onError.call(instance, error)
});
}
promise = promise.catch(this.onError.bind(this, request, response));
return promise;
} | [
"function",
"callAction",
"(",
"request",
",",
"response",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"callback",
"==",
"'function'",
")",
"{",
"return",
"Promive",
".",
"resolve",
"(",
")",
".",
"then",
"(",
"callback",
".",
"bind",
"(",
"null",
",",
"request",
",",
"response",
")",
")",
";",
"}",
"try",
"{",
"var",
"Action",
"=",
"require",
"(",
"ACTION_PATH",
"+",
"'/'",
"+",
"callback",
".",
"action",
"+",
"'.js'",
")",
";",
"}",
"catch",
"(",
"error",
")",
"{",
"if",
"(",
"error",
".",
"message",
"==",
"'Cannot find module \\''",
"+",
"ACTION_PATH",
"+",
"'/'",
"+",
"callback",
".",
"action",
"+",
"'.js\\''",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"'Action '",
"+",
"callback",
".",
"action",
"+",
"' does not exist.'",
")",
".",
"catch",
"(",
"this",
".",
"onPageNotFound",
".",
"bind",
"(",
"this",
",",
"request",
",",
"response",
")",
")",
";",
"}",
"return",
"Promise",
".",
"reject",
"(",
"error",
")",
".",
"catch",
"(",
"this",
".",
"onError",
".",
"bind",
"(",
"this",
",",
"request",
",",
"response",
")",
")",
";",
"}",
"var",
"instance",
"=",
"new",
"Action",
"(",
"request",
",",
"response",
")",
";",
"// Test if method exists",
"if",
"(",
"!",
"instance",
"[",
"callback",
".",
"method",
"]",
")",
"{",
"return",
"Promise",
".",
"reject",
"(",
"new",
"Error",
"(",
"'Method \"'",
"+",
"callback",
".",
"method",
"+",
"'\" not found in action \"'",
"+",
"callback",
".",
"action",
"+",
"'\"'",
")",
")",
";",
"}",
"var",
"promise",
"=",
"Promise",
".",
"resolve",
"(",
")",
";",
"if",
"(",
"instance",
".",
"init",
"&&",
"'function'",
"==",
"typeof",
"instance",
".",
"init",
")",
"{",
"promise",
"=",
"promise",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"instance",
".",
"init",
"(",
")",
";",
"}",
")",
";",
"}",
"promise",
"=",
"promise",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"instance",
"[",
"callback",
".",
"method",
"]",
".",
"apply",
"(",
"instance",
",",
"callback",
".",
"arguments",
")",
";",
"}",
")",
";",
"if",
"(",
"instance",
".",
"onError",
"&&",
"'function'",
"==",
"typeof",
"instance",
".",
"onError",
")",
"{",
"promise",
"=",
"promise",
".",
"catch",
"(",
"function",
"(",
"error",
")",
"{",
"return",
"instance",
".",
"onError",
".",
"call",
"(",
"instance",
",",
"error",
")",
"}",
")",
";",
"}",
"promise",
"=",
"promise",
".",
"catch",
"(",
"this",
".",
"onError",
".",
"bind",
"(",
"this",
",",
"request",
",",
"response",
")",
")",
";",
"return",
"promise",
";",
"}"
] | Call action and method form resolved route
@param request
@param response
@param callback
@returns {*} | [
"Call",
"action",
"and",
"method",
"form",
"resolved",
"route"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/application.js#L133-L176 |
56,269 | ltoussaint/node-bootstrap-core | application.js | postDecode | function postDecode(request) {
return new Promise(function promisePostDecode(resolve) {
var postData = '';
if (request.method === 'POST') {
request.on('data', function (chunk) {
// append the current chunk of data to the fullBody variable
postData += chunk.toString();
});
request.on('end', function () {
request.body = qs.parse(postData);
resolve();
});
} else {
resolve();
}
});
} | javascript | function postDecode(request) {
return new Promise(function promisePostDecode(resolve) {
var postData = '';
if (request.method === 'POST') {
request.on('data', function (chunk) {
// append the current chunk of data to the fullBody variable
postData += chunk.toString();
});
request.on('end', function () {
request.body = qs.parse(postData);
resolve();
});
} else {
resolve();
}
});
} | [
"function",
"postDecode",
"(",
"request",
")",
"{",
"return",
"new",
"Promise",
"(",
"function",
"promisePostDecode",
"(",
"resolve",
")",
"{",
"var",
"postData",
"=",
"''",
";",
"if",
"(",
"request",
".",
"method",
"===",
"'POST'",
")",
"{",
"request",
".",
"on",
"(",
"'data'",
",",
"function",
"(",
"chunk",
")",
"{",
"// append the current chunk of data to the fullBody variable",
"postData",
"+=",
"chunk",
".",
"toString",
"(",
")",
";",
"}",
")",
";",
"request",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"request",
".",
"body",
"=",
"qs",
".",
"parse",
"(",
"postData",
")",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"resolve",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Decode post data and add input into request
@param request
@returns {Promise} | [
"Decode",
"post",
"data",
"and",
"add",
"input",
"into",
"request"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/application.js#L183-L201 |
56,270 | ltoussaint/node-bootstrap-core | application.js | runHooks | function runHooks(request, response, hooks) {
var promise = Promise.resolve();
for (var i = 0; i < hooks.length; i++) {
promise = promise.then(hooks[i].bind(this, request, response));
}
return promise;
} | javascript | function runHooks(request, response, hooks) {
var promise = Promise.resolve();
for (var i = 0; i < hooks.length; i++) {
promise = promise.then(hooks[i].bind(this, request, response));
}
return promise;
} | [
"function",
"runHooks",
"(",
"request",
",",
"response",
",",
"hooks",
")",
"{",
"var",
"promise",
"=",
"Promise",
".",
"resolve",
"(",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"hooks",
".",
"length",
";",
"i",
"++",
")",
"{",
"promise",
"=",
"promise",
".",
"then",
"(",
"hooks",
"[",
"i",
"]",
".",
"bind",
"(",
"this",
",",
"request",
",",
"response",
")",
")",
";",
"}",
"return",
"promise",
";",
"}"
] | Run given hooks
@param request
@param response
@param hooks
@returns {Promise} | [
"Run",
"given",
"hooks"
] | b083b320900ed068007e58af2249825b8da24c79 | https://github.com/ltoussaint/node-bootstrap-core/blob/b083b320900ed068007e58af2249825b8da24c79/application.js#L210-L216 |
56,271 | forfuturellc/node-simple-argparse | index.js | pad | function pad(text, width) {
var space = (width - text.length) + 5;
return text + Array(space).join(" ");
} | javascript | function pad(text, width) {
var space = (width - text.length) + 5;
return text + Array(space).join(" ");
} | [
"function",
"pad",
"(",
"text",
",",
"width",
")",
"{",
"var",
"space",
"=",
"(",
"width",
"-",
"text",
".",
"length",
")",
"+",
"5",
";",
"return",
"text",
"+",
"Array",
"(",
"space",
")",
".",
"join",
"(",
"\" \"",
")",
";",
"}"
] | Appends padding space to some text.
@param {String} text
@param {Number} width - width of column
@return {String} padded text | [
"Appends",
"padding",
"space",
"to",
"some",
"text",
"."
] | 11f5d49cec5c891fb344c8a6a1e413b535dad331 | https://github.com/forfuturellc/node-simple-argparse/blob/11f5d49cec5c891fb344c8a6a1e413b535dad331/index.js#L37-L40 |
56,272 | hillscottc/nostra | dist/index.js | generate | function generate() {
var rnum = Math.floor(Math.random() * 10);
var mood = rnum <= 8 ? "good" : "bad";
var sentences = [_sentence_mgr2.default.feeling(mood), _word_library2.default.warning(), nu.chooseFrom([_sentence_mgr2.default.relationship(mood), _sentence_mgr2.default.encounter(mood)])];
// randomize (shuffle) the array
sentences = nu.shuffle(sentences);
// Select 2 or 3 sentences, to add to the random feel
var num_s = Math.floor(Math.random() * 2) + 2;
sentences = sentences.slice(0, num_s);
sentences = sentences.join(" ");
sentences += " " + _sentence_mgr2.default.datePredict();
debug(sentences);
return sentences;
} | javascript | function generate() {
var rnum = Math.floor(Math.random() * 10);
var mood = rnum <= 8 ? "good" : "bad";
var sentences = [_sentence_mgr2.default.feeling(mood), _word_library2.default.warning(), nu.chooseFrom([_sentence_mgr2.default.relationship(mood), _sentence_mgr2.default.encounter(mood)])];
// randomize (shuffle) the array
sentences = nu.shuffle(sentences);
// Select 2 or 3 sentences, to add to the random feel
var num_s = Math.floor(Math.random() * 2) + 2;
sentences = sentences.slice(0, num_s);
sentences = sentences.join(" ");
sentences += " " + _sentence_mgr2.default.datePredict();
debug(sentences);
return sentences;
} | [
"function",
"generate",
"(",
")",
"{",
"var",
"rnum",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"10",
")",
";",
"var",
"mood",
"=",
"rnum",
"<=",
"8",
"?",
"\"good\"",
":",
"\"bad\"",
";",
"var",
"sentences",
"=",
"[",
"_sentence_mgr2",
".",
"default",
".",
"feeling",
"(",
"mood",
")",
",",
"_word_library2",
".",
"default",
".",
"warning",
"(",
")",
",",
"nu",
".",
"chooseFrom",
"(",
"[",
"_sentence_mgr2",
".",
"default",
".",
"relationship",
"(",
"mood",
")",
",",
"_sentence_mgr2",
".",
"default",
".",
"encounter",
"(",
"mood",
")",
"]",
")",
"]",
";",
"// randomize (shuffle) the array",
"sentences",
"=",
"nu",
".",
"shuffle",
"(",
"sentences",
")",
";",
"// Select 2 or 3 sentences, to add to the random feel",
"var",
"num_s",
"=",
"Math",
".",
"floor",
"(",
"Math",
".",
"random",
"(",
")",
"*",
"2",
")",
"+",
"2",
";",
"sentences",
"=",
"sentences",
".",
"slice",
"(",
"0",
",",
"num_s",
")",
";",
"sentences",
"=",
"sentences",
".",
"join",
"(",
"\" \"",
")",
";",
"sentences",
"+=",
"\" \"",
"+",
"_sentence_mgr2",
".",
"default",
".",
"datePredict",
"(",
")",
";",
"debug",
"(",
"sentences",
")",
";",
"return",
"sentences",
";",
"}"
] | Generate a three to four sentence horoscope.
@returns {*[]} | [
"Generate",
"a",
"three",
"to",
"four",
"sentence",
"horoscope",
"."
] | 1801c8e19f7fab91dd29fea07195789d41624915 | https://github.com/hillscottc/nostra/blob/1801c8e19f7fab91dd29fea07195789d41624915/dist/index.js#L28-L47 |
56,273 | raincatcher-beta/raincatcher-file-angular | lib/file-list/file-list-controller.js | FileListController | function FileListController($scope, mediator, $stateParams, $window, userClient, fileMediatorService, $timeout, mobileCamera, desktopCamera, FILE_CONFIG) {
var self = this;
self.files = null;
var _files;
self.uploadEnabled = FILE_CONFIG.uploadEnabled;
userClient.getProfile().then(function(profileData){
var userFilter;
if(FILE_CONFIG.userMode){
userFilter = profileData.id;
}
function refreshFiles(){
fileMediatorService.listFiles(userFilter).then(function(files){
$timeout(function(){
_files = files;
self.files = files;
});
});
}
refreshFiles();
fileMediatorService.subscribeToFileCRUDDoneTopics($scope, refreshFiles);
self.selectFile = function(event, file){
self.selectedFileId = file.id;
mediator.publish(fileMediatorService.fileUITopics.getTopic(CONSTANTS.TOPICS.SELECTED), file);
};
//TODO: Move to service
self.applyFilter = function(term){
term = term.toLowerCase();
self.files = _files.filter(function(file){
return String(file.name).toLowerCase().indexOf(term) !== -1
|| String(file.id).indexOf(term) !== -1;
});
};
$scope.$parent.selected = {id: null};
var captureThenUpload = function(){
if($window.cordova){
return mobileCamera.capture()
.then(function(capture){
var fileData = {
userId: profileData.id,
fileURI: capture.fileURI,
options: {fileName: capture.fileName}
};
fileMediatorService.createFile(fileData);
});
}else{
return desktopCamera.capture()
.then(function(dataUrl){
return fileMediatorService.createFile({userId: profileData.id, dataUrl: dataUrl});
});
}
};
self.capturePhoto = function(){
captureThenUpload().then(function(){
}, function(error){
console.error(error);
});
};
});
} | javascript | function FileListController($scope, mediator, $stateParams, $window, userClient, fileMediatorService, $timeout, mobileCamera, desktopCamera, FILE_CONFIG) {
var self = this;
self.files = null;
var _files;
self.uploadEnabled = FILE_CONFIG.uploadEnabled;
userClient.getProfile().then(function(profileData){
var userFilter;
if(FILE_CONFIG.userMode){
userFilter = profileData.id;
}
function refreshFiles(){
fileMediatorService.listFiles(userFilter).then(function(files){
$timeout(function(){
_files = files;
self.files = files;
});
});
}
refreshFiles();
fileMediatorService.subscribeToFileCRUDDoneTopics($scope, refreshFiles);
self.selectFile = function(event, file){
self.selectedFileId = file.id;
mediator.publish(fileMediatorService.fileUITopics.getTopic(CONSTANTS.TOPICS.SELECTED), file);
};
//TODO: Move to service
self.applyFilter = function(term){
term = term.toLowerCase();
self.files = _files.filter(function(file){
return String(file.name).toLowerCase().indexOf(term) !== -1
|| String(file.id).indexOf(term) !== -1;
});
};
$scope.$parent.selected = {id: null};
var captureThenUpload = function(){
if($window.cordova){
return mobileCamera.capture()
.then(function(capture){
var fileData = {
userId: profileData.id,
fileURI: capture.fileURI,
options: {fileName: capture.fileName}
};
fileMediatorService.createFile(fileData);
});
}else{
return desktopCamera.capture()
.then(function(dataUrl){
return fileMediatorService.createFile({userId: profileData.id, dataUrl: dataUrl});
});
}
};
self.capturePhoto = function(){
captureThenUpload().then(function(){
}, function(error){
console.error(error);
});
};
});
} | [
"function",
"FileListController",
"(",
"$scope",
",",
"mediator",
",",
"$stateParams",
",",
"$window",
",",
"userClient",
",",
"fileMediatorService",
",",
"$timeout",
",",
"mobileCamera",
",",
"desktopCamera",
",",
"FILE_CONFIG",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"files",
"=",
"null",
";",
"var",
"_files",
";",
"self",
".",
"uploadEnabled",
"=",
"FILE_CONFIG",
".",
"uploadEnabled",
";",
"userClient",
".",
"getProfile",
"(",
")",
".",
"then",
"(",
"function",
"(",
"profileData",
")",
"{",
"var",
"userFilter",
";",
"if",
"(",
"FILE_CONFIG",
".",
"userMode",
")",
"{",
"userFilter",
"=",
"profileData",
".",
"id",
";",
"}",
"function",
"refreshFiles",
"(",
")",
"{",
"fileMediatorService",
".",
"listFiles",
"(",
"userFilter",
")",
".",
"then",
"(",
"function",
"(",
"files",
")",
"{",
"$timeout",
"(",
"function",
"(",
")",
"{",
"_files",
"=",
"files",
";",
"self",
".",
"files",
"=",
"files",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"refreshFiles",
"(",
")",
";",
"fileMediatorService",
".",
"subscribeToFileCRUDDoneTopics",
"(",
"$scope",
",",
"refreshFiles",
")",
";",
"self",
".",
"selectFile",
"=",
"function",
"(",
"event",
",",
"file",
")",
"{",
"self",
".",
"selectedFileId",
"=",
"file",
".",
"id",
";",
"mediator",
".",
"publish",
"(",
"fileMediatorService",
".",
"fileUITopics",
".",
"getTopic",
"(",
"CONSTANTS",
".",
"TOPICS",
".",
"SELECTED",
")",
",",
"file",
")",
";",
"}",
";",
"//TODO: Move to service",
"self",
".",
"applyFilter",
"=",
"function",
"(",
"term",
")",
"{",
"term",
"=",
"term",
".",
"toLowerCase",
"(",
")",
";",
"self",
".",
"files",
"=",
"_files",
".",
"filter",
"(",
"function",
"(",
"file",
")",
"{",
"return",
"String",
"(",
"file",
".",
"name",
")",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"term",
")",
"!==",
"-",
"1",
"||",
"String",
"(",
"file",
".",
"id",
")",
".",
"indexOf",
"(",
"term",
")",
"!==",
"-",
"1",
";",
"}",
")",
";",
"}",
";",
"$scope",
".",
"$parent",
".",
"selected",
"=",
"{",
"id",
":",
"null",
"}",
";",
"var",
"captureThenUpload",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"$window",
".",
"cordova",
")",
"{",
"return",
"mobileCamera",
".",
"capture",
"(",
")",
".",
"then",
"(",
"function",
"(",
"capture",
")",
"{",
"var",
"fileData",
"=",
"{",
"userId",
":",
"profileData",
".",
"id",
",",
"fileURI",
":",
"capture",
".",
"fileURI",
",",
"options",
":",
"{",
"fileName",
":",
"capture",
".",
"fileName",
"}",
"}",
";",
"fileMediatorService",
".",
"createFile",
"(",
"fileData",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"return",
"desktopCamera",
".",
"capture",
"(",
")",
".",
"then",
"(",
"function",
"(",
"dataUrl",
")",
"{",
"return",
"fileMediatorService",
".",
"createFile",
"(",
"{",
"userId",
":",
"profileData",
".",
"id",
",",
"dataUrl",
":",
"dataUrl",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
";",
"self",
".",
"capturePhoto",
"=",
"function",
"(",
")",
"{",
"captureThenUpload",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"}",
",",
"function",
"(",
"error",
")",
"{",
"console",
".",
"error",
"(",
"error",
")",
";",
"}",
")",
";",
"}",
";",
"}",
")",
";",
"}"
] | Controller for listing Files | [
"Controller",
"for",
"listing",
"Files"
] | a76d406ca62d6c29da3caf94cc9db75f343ec797 | https://github.com/raincatcher-beta/raincatcher-file-angular/blob/a76d406ca62d6c29da3caf94cc9db75f343ec797/lib/file-list/file-list-controller.js#L8-L72 |
56,274 | JimmyRobz/grunt-mokuai-coffee | tasks/mokuai-coffee.js | optionResult | function optionResult(options, option){
var result = options[option];
// If the returned value is a function, call it with the dest option parameter
if(_.isFunction(result)){
result = result(options.dest);
}
return result;
} | javascript | function optionResult(options, option){
var result = options[option];
// If the returned value is a function, call it with the dest option parameter
if(_.isFunction(result)){
result = result(options.dest);
}
return result;
} | [
"function",
"optionResult",
"(",
"options",
",",
"option",
")",
"{",
"var",
"result",
"=",
"options",
"[",
"option",
"]",
";",
"// If the returned value is a function, call it with the dest option parameter",
"if",
"(",
"_",
".",
"isFunction",
"(",
"result",
")",
")",
"{",
"result",
"=",
"result",
"(",
"options",
".",
"dest",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Get option result from options | [
"Get",
"option",
"result",
"from",
"options"
] | 163a4cdea0a5451832444dfd1570e9b5daf3d2f8 | https://github.com/JimmyRobz/grunt-mokuai-coffee/blob/163a4cdea0a5451832444dfd1570e9b5daf3d2f8/tasks/mokuai-coffee.js#L19-L26 |
56,275 | reklatsmasters/win-ps | index.js | build_shell | function build_shell(fields) {
var $fields = Array.isArray(fields) ? normalizeFields(fields) : ['ProcessId','Name','Path','ParentProcessId','Priority'];
var args = command.shell_arg.split(' ');
args.push(`${command.ps} | ${command.select} ${ $fields.join(',') } | ${command.convert}`);
return shell(command.shell, args);
} | javascript | function build_shell(fields) {
var $fields = Array.isArray(fields) ? normalizeFields(fields) : ['ProcessId','Name','Path','ParentProcessId','Priority'];
var args = command.shell_arg.split(' ');
args.push(`${command.ps} | ${command.select} ${ $fields.join(',') } | ${command.convert}`);
return shell(command.shell, args);
} | [
"function",
"build_shell",
"(",
"fields",
")",
"{",
"var",
"$fields",
"=",
"Array",
".",
"isArray",
"(",
"fields",
")",
"?",
"normalizeFields",
"(",
"fields",
")",
":",
"[",
"'ProcessId'",
",",
"'Name'",
",",
"'Path'",
",",
"'ParentProcessId'",
",",
"'Priority'",
"]",
";",
"var",
"args",
"=",
"command",
".",
"shell_arg",
".",
"split",
"(",
"' '",
")",
";",
"args",
".",
"push",
"(",
"`",
"${",
"command",
".",
"ps",
"}",
"${",
"command",
".",
"select",
"}",
"${",
"$fields",
".",
"join",
"(",
"','",
")",
"}",
"${",
"command",
".",
"convert",
"}",
"`",
")",
";",
"return",
"shell",
"(",
"command",
".",
"shell",
",",
"args",
")",
";",
"}"
] | Build shell command
@param {Array} fields
@return {Object} child_process instance | [
"Build",
"shell",
"command"
] | ea5f7e5978b3a8620556a0d898000429e5baeb4f | https://github.com/reklatsmasters/win-ps/blob/ea5f7e5978b3a8620556a0d898000429e5baeb4f/index.js#L45-L52 |
56,276 | MCluck90/clairvoyant | src/main.js | function(options) {
options = extend({
src: '',
output: '',
is3d: false,
failOnWarn: false,
overwrite: false,
reporter: 'default'
}, options);
if (!options.src || !options.output) {
throw new Error('Must specify source file and output directory');
}
var reporterConstructor;
if (options.reporter === 'default') {
reporterConstructor = require('./reporter.js').Reporter;
} else {
reporterConstructor = require('./reporters/' + options.reporter + '.js');
}
if (reporterConstructor === undefined) {
throw new Error('Invalid reporter given');
}
this.reporter = new reporterConstructor(options.failOnWarn);
this.sourceCode = fs.readFileSync(options.src, 'utf-8');
this.psykickVersion = (options.is3d) ? '3d' : '2d';
this.sourcePath = options.src;
this.outputPath = options.output;
this.overwrite = options.overwrite;
this.ast = null;
this.compiler = null;
this.writer = null;
} | javascript | function(options) {
options = extend({
src: '',
output: '',
is3d: false,
failOnWarn: false,
overwrite: false,
reporter: 'default'
}, options);
if (!options.src || !options.output) {
throw new Error('Must specify source file and output directory');
}
var reporterConstructor;
if (options.reporter === 'default') {
reporterConstructor = require('./reporter.js').Reporter;
} else {
reporterConstructor = require('./reporters/' + options.reporter + '.js');
}
if (reporterConstructor === undefined) {
throw new Error('Invalid reporter given');
}
this.reporter = new reporterConstructor(options.failOnWarn);
this.sourceCode = fs.readFileSync(options.src, 'utf-8');
this.psykickVersion = (options.is3d) ? '3d' : '2d';
this.sourcePath = options.src;
this.outputPath = options.output;
this.overwrite = options.overwrite;
this.ast = null;
this.compiler = null;
this.writer = null;
} | [
"function",
"(",
"options",
")",
"{",
"options",
"=",
"extend",
"(",
"{",
"src",
":",
"''",
",",
"output",
":",
"''",
",",
"is3d",
":",
"false",
",",
"failOnWarn",
":",
"false",
",",
"overwrite",
":",
"false",
",",
"reporter",
":",
"'default'",
"}",
",",
"options",
")",
";",
"if",
"(",
"!",
"options",
".",
"src",
"||",
"!",
"options",
".",
"output",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Must specify source file and output directory'",
")",
";",
"}",
"var",
"reporterConstructor",
";",
"if",
"(",
"options",
".",
"reporter",
"===",
"'default'",
")",
"{",
"reporterConstructor",
"=",
"require",
"(",
"'./reporter.js'",
")",
".",
"Reporter",
";",
"}",
"else",
"{",
"reporterConstructor",
"=",
"require",
"(",
"'./reporters/'",
"+",
"options",
".",
"reporter",
"+",
"'.js'",
")",
";",
"}",
"if",
"(",
"reporterConstructor",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Invalid reporter given'",
")",
";",
"}",
"this",
".",
"reporter",
"=",
"new",
"reporterConstructor",
"(",
"options",
".",
"failOnWarn",
")",
";",
"this",
".",
"sourceCode",
"=",
"fs",
".",
"readFileSync",
"(",
"options",
".",
"src",
",",
"'utf-8'",
")",
";",
"this",
".",
"psykickVersion",
"=",
"(",
"options",
".",
"is3d",
")",
"?",
"'3d'",
":",
"'2d'",
";",
"this",
".",
"sourcePath",
"=",
"options",
".",
"src",
";",
"this",
".",
"outputPath",
"=",
"options",
".",
"output",
";",
"this",
".",
"overwrite",
"=",
"options",
".",
"overwrite",
";",
"this",
".",
"ast",
"=",
"null",
";",
"this",
".",
"compiler",
"=",
"null",
";",
"this",
".",
"writer",
"=",
"null",
";",
"}"
] | Exposes Clairvoyant as a module to use programatically
@param {object} options
@param {string} options.src - Source file
@param {string} options.output - Path to the file to place the project in
@param {boolean} [options.is3d=false] - If true, will compile for Psykick3D
@param {boolean} [options.failOnWarn=false] - If true, will fail when a warning is issued
@param {boolean} [options.overwrite=false] - If true, will overwrite existing files
@param {string} [options.reporter='default'] - Specify which reporter to load
@constructor | [
"Exposes",
"Clairvoyant",
"as",
"a",
"module",
"to",
"use",
"programatically"
] | 4c347499c5fe0f561a53e180d141884b1fa8c21b | https://github.com/MCluck90/clairvoyant/blob/4c347499c5fe0f561a53e180d141884b1fa8c21b/src/main.js#L24-L58 |
|
56,277 | relief-melone/limitpromises | src/services/service.handleRejects.js | handleRejects | function handleRejects(PromiseFunc, Obj, Err, Options){
var rejectOpts = Options.Reject || rejectConfig;
switch(rejectOpts.rejectBehaviour){
case "reject":
// Every time a promise finishes start the first one from the currentPromiseArrays[typeKey]Array that hasnt been started yet;
if(Obj.isRunning) return Obj.rejectResult(Err);
break;
case "resolve":
if(Obj.isRunning) return Obj.resolveResult(rejectOpts.returnOnReject);
break;
case "retry":
if(Obj.isRunning) return retryPromiseRejected(PromiseFunc, Obj, Options, Err);
break;
case "none":
break;
}
} | javascript | function handleRejects(PromiseFunc, Obj, Err, Options){
var rejectOpts = Options.Reject || rejectConfig;
switch(rejectOpts.rejectBehaviour){
case "reject":
// Every time a promise finishes start the first one from the currentPromiseArrays[typeKey]Array that hasnt been started yet;
if(Obj.isRunning) return Obj.rejectResult(Err);
break;
case "resolve":
if(Obj.isRunning) return Obj.resolveResult(rejectOpts.returnOnReject);
break;
case "retry":
if(Obj.isRunning) return retryPromiseRejected(PromiseFunc, Obj, Options, Err);
break;
case "none":
break;
}
} | [
"function",
"handleRejects",
"(",
"PromiseFunc",
",",
"Obj",
",",
"Err",
",",
"Options",
")",
"{",
"var",
"rejectOpts",
"=",
"Options",
".",
"Reject",
"||",
"rejectConfig",
";",
"switch",
"(",
"rejectOpts",
".",
"rejectBehaviour",
")",
"{",
"case",
"\"reject\"",
":",
"// Every time a promise finishes start the first one from the currentPromiseArrays[typeKey]Array that hasnt been started yet; ",
"if",
"(",
"Obj",
".",
"isRunning",
")",
"return",
"Obj",
".",
"rejectResult",
"(",
"Err",
")",
";",
"break",
";",
"case",
"\"resolve\"",
":",
"if",
"(",
"Obj",
".",
"isRunning",
")",
"return",
"Obj",
".",
"resolveResult",
"(",
"rejectOpts",
".",
"returnOnReject",
")",
";",
"break",
";",
"case",
"\"retry\"",
":",
"if",
"(",
"Obj",
".",
"isRunning",
")",
"return",
"retryPromiseRejected",
"(",
"PromiseFunc",
",",
"Obj",
",",
"Options",
",",
"Err",
")",
";",
"break",
";",
"case",
"\"none\"",
":",
"break",
";",
"}",
"}"
] | Handle rejects will determine how a promise is beeing handled after it the PromiseFunc has been rejected
@param {Function} PromiseFunc Function that returns a Promise with one InputParameter that is used
@param {Object} Obj Current Object to be treated
@param {Error} Err The error returned by the PromiseFunction
@param {Object} Options Options that contain information about how the Reject is handelt under Object.Reject
@returns {void} | [
"Handle",
"rejects",
"will",
"determine",
"how",
"a",
"promise",
"is",
"beeing",
"handled",
"after",
"it",
"the",
"PromiseFunc",
"has",
"been",
"rejected"
] | 1735b92749740204b597c1c6026257d54ade8200 | https://github.com/relief-melone/limitpromises/blob/1735b92749740204b597c1c6026257d54ade8200/src/services/service.handleRejects.js#L13-L29 |
56,278 | imlucas/node-stor | adapters/backbone.js | getHandler | function getHandler(method){
var taxonomy = {
create: store.set,
read: store.get,
update: store.set,
'delete': store.remove,
patch: store.set,
findAll: store.all,
findById: store.get
};
return store[method] || taxonomy[method];
} | javascript | function getHandler(method){
var taxonomy = {
create: store.set,
read: store.get,
update: store.set,
'delete': store.remove,
patch: store.set,
findAll: store.all,
findById: store.get
};
return store[method] || taxonomy[method];
} | [
"function",
"getHandler",
"(",
"method",
")",
"{",
"var",
"taxonomy",
"=",
"{",
"create",
":",
"store",
".",
"set",
",",
"read",
":",
"store",
".",
"get",
",",
"update",
":",
"store",
".",
"set",
",",
"'delete'",
":",
"store",
".",
"remove",
",",
"patch",
":",
"store",
".",
"set",
",",
"findAll",
":",
"store",
".",
"all",
",",
"findById",
":",
"store",
".",
"get",
"}",
";",
"return",
"store",
"[",
"method",
"]",
"||",
"taxonomy",
"[",
"method",
"]",
";",
"}"
] | normalize the api taxonomy with a convenience that returns the correct function for a store. | [
"normalize",
"the",
"api",
"taxonomy",
"with",
"a",
"convenience",
"that",
"returns",
"the",
"correct",
"function",
"for",
"a",
"store",
"."
] | 6b74af52bf160873658bc3570db716d44c33f335 | https://github.com/imlucas/node-stor/blob/6b74af52bf160873658bc3570db716d44c33f335/adapters/backbone.js#L5-L16 |
56,279 | weisjohn/tessel-apple-remote | index.js | valid_leader | function valid_leader(durations) {
var on = durations[0];
var off = durations[1];
return (8900 < on && on < 9200) && (-4600 < off && off < -4350);
} | javascript | function valid_leader(durations) {
var on = durations[0];
var off = durations[1];
return (8900 < on && on < 9200) && (-4600 < off && off < -4350);
} | [
"function",
"valid_leader",
"(",
"durations",
")",
"{",
"var",
"on",
"=",
"durations",
"[",
"0",
"]",
";",
"var",
"off",
"=",
"durations",
"[",
"1",
"]",
";",
"return",
"(",
"8900",
"<",
"on",
"&&",
"on",
"<",
"9200",
")",
"&&",
"(",
"-",
"4600",
"<",
"off",
"&&",
"off",
"<",
"-",
"4350",
")",
";",
"}"
] | validate the leader bit | [
"validate",
"the",
"leader",
"bit"
] | 0b29abe595f53059eebd021c70b13c9d8720ac8d | https://github.com/weisjohn/tessel-apple-remote/blob/0b29abe595f53059eebd021c70b13c9d8720ac8d/index.js#L35-L39 |
56,280 | weisjohn/tessel-apple-remote | index.js | command_id_from_buffer | function command_id_from_buffer(data) {
var durations = command_durations_from_hex_buffer(data);
if (!valid_leader(durations)) return;
var binary = binary_from_durations(durations);
if (!valid_binary(binary)) return;
var bytes = bytes_from_binary(binary);
if (!valid_bytes(bytes)) return;
if (!valid_codes(bytes)) return;
return command_id_from_bytes(bytes);
} | javascript | function command_id_from_buffer(data) {
var durations = command_durations_from_hex_buffer(data);
if (!valid_leader(durations)) return;
var binary = binary_from_durations(durations);
if (!valid_binary(binary)) return;
var bytes = bytes_from_binary(binary);
if (!valid_bytes(bytes)) return;
if (!valid_codes(bytes)) return;
return command_id_from_bytes(bytes);
} | [
"function",
"command_id_from_buffer",
"(",
"data",
")",
"{",
"var",
"durations",
"=",
"command_durations_from_hex_buffer",
"(",
"data",
")",
";",
"if",
"(",
"!",
"valid_leader",
"(",
"durations",
")",
")",
"return",
";",
"var",
"binary",
"=",
"binary_from_durations",
"(",
"durations",
")",
";",
"if",
"(",
"!",
"valid_binary",
"(",
"binary",
")",
")",
"return",
";",
"var",
"bytes",
"=",
"bytes_from_binary",
"(",
"binary",
")",
";",
"if",
"(",
"!",
"valid_bytes",
"(",
"bytes",
")",
")",
"return",
";",
"if",
"(",
"!",
"valid_codes",
"(",
"bytes",
")",
")",
"return",
";",
"return",
"command_id_from_bytes",
"(",
"bytes",
")",
";",
"}"
] | a small implementation of the whole flow | [
"a",
"small",
"implementation",
"of",
"the",
"whole",
"flow"
] | 0b29abe595f53059eebd021c70b13c9d8720ac8d | https://github.com/weisjohn/tessel-apple-remote/blob/0b29abe595f53059eebd021c70b13c9d8720ac8d/index.js#L111-L125 |
56,281 | weisjohn/tessel-apple-remote | index.js | continue_from_buffer | function continue_from_buffer(data) {
var durations = continue_durations_from_hex_buffer(data);
var on = durations[0];
var off = durations[1];
var stop = durations[2];
return (8900 < on && on < 9200) &&
(-2350 < off && off < -2100) &&
(500 < stop && stop < 650);
} | javascript | function continue_from_buffer(data) {
var durations = continue_durations_from_hex_buffer(data);
var on = durations[0];
var off = durations[1];
var stop = durations[2];
return (8900 < on && on < 9200) &&
(-2350 < off && off < -2100) &&
(500 < stop && stop < 650);
} | [
"function",
"continue_from_buffer",
"(",
"data",
")",
"{",
"var",
"durations",
"=",
"continue_durations_from_hex_buffer",
"(",
"data",
")",
";",
"var",
"on",
"=",
"durations",
"[",
"0",
"]",
";",
"var",
"off",
"=",
"durations",
"[",
"1",
"]",
";",
"var",
"stop",
"=",
"durations",
"[",
"2",
"]",
";",
"return",
"(",
"8900",
"<",
"on",
"&&",
"on",
"<",
"9200",
")",
"&&",
"(",
"-",
"2350",
"<",
"off",
"&&",
"off",
"<",
"-",
"2100",
")",
"&&",
"(",
"500",
"<",
"stop",
"&&",
"stop",
"<",
"650",
")",
";",
"}"
] | determine whether or not the buffer is a valid continuation code | [
"determine",
"whether",
"or",
"not",
"the",
"buffer",
"is",
"a",
"valid",
"continuation",
"code"
] | 0b29abe595f53059eebd021c70b13c9d8720ac8d | https://github.com/weisjohn/tessel-apple-remote/blob/0b29abe595f53059eebd021c70b13c9d8720ac8d/index.js#L129-L140 |
56,282 | Swaagie/npm-probe | probes/delta.js | versions | function versions(a, b) {
if (!a || !b) return false;
a = Array.isArray(a) ? a : Object.keys(a);
b = Array.isArray(a) ? a : Object.keys(a);
return a.length === b.length && a.reduce(function has(memo, item) {
return memo && ~b.indexOf(item);
}, true);
} | javascript | function versions(a, b) {
if (!a || !b) return false;
a = Array.isArray(a) ? a : Object.keys(a);
b = Array.isArray(a) ? a : Object.keys(a);
return a.length === b.length && a.reduce(function has(memo, item) {
return memo && ~b.indexOf(item);
}, true);
} | [
"function",
"versions",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"!",
"a",
"||",
"!",
"b",
")",
"return",
"false",
";",
"a",
"=",
"Array",
".",
"isArray",
"(",
"a",
")",
"?",
"a",
":",
"Object",
".",
"keys",
"(",
"a",
")",
";",
"b",
"=",
"Array",
".",
"isArray",
"(",
"a",
")",
"?",
"a",
":",
"Object",
".",
"keys",
"(",
"a",
")",
";",
"return",
"a",
".",
"length",
"===",
"b",
".",
"length",
"&&",
"a",
".",
"reduce",
"(",
"function",
"has",
"(",
"memo",
",",
"item",
")",
"{",
"return",
"memo",
"&&",
"~",
"b",
".",
"indexOf",
"(",
"item",
")",
";",
"}",
",",
"true",
")",
";",
"}"
] | Unpublished modules will have no versions, modified time should be equal. | [
"Unpublished",
"modules",
"will",
"have",
"no",
"versions",
"modified",
"time",
"should",
"be",
"equal",
"."
] | e9b717934ff3e3eb4f7c7a15f39728c380f1925e | https://github.com/Swaagie/npm-probe/blob/e9b717934ff3e3eb4f7c7a15f39728c380f1925e/probes/delta.js#L48-L57 |
56,283 | oori/gulp-jsonschema-deref | index.js | dereference | function dereference(file, opts, cb) {
parser.dereference(file.path, opts, (err, schema) => {
if (err) {
this.emit('error', new gutil.PluginError('gulp-jsonschema-deref', err, {fileName: file.path}));
} else {
file.contents = Buffer.from(JSON.stringify(schema));
this.push(file);
}
cb();
});
} | javascript | function dereference(file, opts, cb) {
parser.dereference(file.path, opts, (err, schema) => {
if (err) {
this.emit('error', new gutil.PluginError('gulp-jsonschema-deref', err, {fileName: file.path}));
} else {
file.contents = Buffer.from(JSON.stringify(schema));
this.push(file);
}
cb();
});
} | [
"function",
"dereference",
"(",
"file",
",",
"opts",
",",
"cb",
")",
"{",
"parser",
".",
"dereference",
"(",
"file",
".",
"path",
",",
"opts",
",",
"(",
"err",
",",
"schema",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"this",
".",
"emit",
"(",
"'error'",
",",
"new",
"gutil",
".",
"PluginError",
"(",
"'gulp-jsonschema-deref'",
",",
"err",
",",
"{",
"fileName",
":",
"file",
".",
"path",
"}",
")",
")",
";",
"}",
"else",
"{",
"file",
".",
"contents",
"=",
"Buffer",
".",
"from",
"(",
"JSON",
".",
"stringify",
"(",
"schema",
")",
")",
";",
"this",
".",
"push",
"(",
"file",
")",
";",
"}",
"cb",
"(",
")",
";",
"}",
")",
";",
"}"
] | Dereference a jsonschema | [
"Dereference",
"a",
"jsonschema"
] | 51b6a8af2039fe3bac9af0d10b61320fc57ae122 | https://github.com/oori/gulp-jsonschema-deref/blob/51b6a8af2039fe3bac9af0d10b61320fc57ae122/index.js#L9-L19 |
56,284 | rumkin/keyget | index.js | breadcrumbs | function breadcrumbs(target, path) {
path = pathToArray(path);
const result = [target];
let part;
let value = target;
if (! isObject(value)) {
return result;
}
for (let i = 0, l = path.length; i < l; i++) {
part = path[i];
if (! value.hasOwnProperty(part)) {
break;
}
result.push(value[part]);
value = value[part];
}
return result;
} | javascript | function breadcrumbs(target, path) {
path = pathToArray(path);
const result = [target];
let part;
let value = target;
if (! isObject(value)) {
return result;
}
for (let i = 0, l = path.length; i < l; i++) {
part = path[i];
if (! value.hasOwnProperty(part)) {
break;
}
result.push(value[part]);
value = value[part];
}
return result;
} | [
"function",
"breadcrumbs",
"(",
"target",
",",
"path",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"const",
"result",
"=",
"[",
"target",
"]",
";",
"let",
"part",
";",
"let",
"value",
"=",
"target",
";",
"if",
"(",
"!",
"isObject",
"(",
"value",
")",
")",
"{",
"return",
"result",
";",
"}",
"for",
"(",
"let",
"i",
"=",
"0",
",",
"l",
"=",
"path",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"part",
"=",
"path",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"value",
".",
"hasOwnProperty",
"(",
"part",
")",
")",
"{",
"break",
";",
"}",
"result",
".",
"push",
"(",
"value",
"[",
"part",
"]",
")",
";",
"value",
"=",
"value",
"[",
"part",
"]",
";",
"}",
"return",
"result",
";",
"}"
] | breadcrumbs - Extract nested value by path and return as array. If target is not an object
or path is empty returns empty array.
@param {*} target Value.
@param {Path} path Path to value.
@return {*[]} Values for path components.
@example
breadcrumbs({a: b: {1}}, ['a', 'b']); // -> [{b:1}, 1]; | [
"breadcrumbs",
"-",
"Extract",
"nested",
"value",
"by",
"path",
"and",
"return",
"as",
"array",
".",
"If",
"target",
"is",
"not",
"an",
"object",
"or",
"path",
"is",
"empty",
"returns",
"empty",
"array",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L39-L63 |
56,285 | rumkin/keyget | index.js | hasPath | function hasPath(target, path) {
path = pathToArray(path);
const result = breadcrumbs(target, path);
return result.length === path.length + 1;
} | javascript | function hasPath(target, path) {
path = pathToArray(path);
const result = breadcrumbs(target, path);
return result.length === path.length + 1;
} | [
"function",
"hasPath",
"(",
"target",
",",
"path",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"const",
"result",
"=",
"breadcrumbs",
"(",
"target",
",",
"path",
")",
";",
"return",
"result",
".",
"length",
"===",
"path",
".",
"length",
"+",
"1",
";",
"}"
] | hasPath - Set deeply nested value into target object. If nested properties
are not an objects or not exists creates them.
@param {Object} target Parent object.
@param {Path} path Array of path segments.
@return {Boolean} Returns true if object contains `path`. | [
"hasPath",
"-",
"Set",
"deeply",
"nested",
"value",
"into",
"target",
"object",
".",
"If",
"nested",
"properties",
"are",
"not",
"an",
"objects",
"or",
"not",
"exists",
"creates",
"them",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L73-L79 |
56,286 | rumkin/keyget | index.js | setByPath | function setByPath(target, path, value) {
path = pathToArray(path);
if (! path.length) {
return value;
}
const key = path[0];
if (isNumber(key)) {
if (! Array.isArray(target)) {
target = [];
}
}
else if (! isObject(target)) {
target = {};
}
if (path.length > 1) {
target[key] = setByPath(target[key], path.slice(1), value);
}
else {
target[key] = value;
}
return target;
} | javascript | function setByPath(target, path, value) {
path = pathToArray(path);
if (! path.length) {
return value;
}
const key = path[0];
if (isNumber(key)) {
if (! Array.isArray(target)) {
target = [];
}
}
else if (! isObject(target)) {
target = {};
}
if (path.length > 1) {
target[key] = setByPath(target[key], path.slice(1), value);
}
else {
target[key] = value;
}
return target;
} | [
"function",
"setByPath",
"(",
"target",
",",
"path",
",",
"value",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"if",
"(",
"!",
"path",
".",
"length",
")",
"{",
"return",
"value",
";",
"}",
"const",
"key",
"=",
"path",
"[",
"0",
"]",
";",
"if",
"(",
"isNumber",
"(",
"key",
")",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"target",
")",
")",
"{",
"target",
"=",
"[",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"isObject",
"(",
"target",
")",
")",
"{",
"target",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"path",
".",
"length",
">",
"1",
")",
"{",
"target",
"[",
"key",
"]",
"=",
"setByPath",
"(",
"target",
"[",
"key",
"]",
",",
"path",
".",
"slice",
"(",
"1",
")",
",",
"value",
")",
";",
"}",
"else",
"{",
"target",
"[",
"key",
"]",
"=",
"value",
";",
"}",
"return",
"target",
";",
"}"
] | setByPath - Set deeply nested value into target object. If nested properties
are not an objects or not exists creates them.
@param {Object} target Parent object.
@param {Path} path Array of path segments.
@param {*} value Value to set.
@return {void} | [
"setByPath",
"-",
"Set",
"deeply",
"nested",
"value",
"into",
"target",
"object",
".",
"If",
"nested",
"properties",
"are",
"not",
"an",
"objects",
"or",
"not",
"exists",
"creates",
"them",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L90-L115 |
56,287 | rumkin/keyget | index.js | pushByPath | function pushByPath(target, path, value) {
path = pathToArray(path);
if (! path.length) {
if (! Array.isArray(target)) {
return [value];
}
else {
target.push(value);
return target;
}
}
if (! isObject(target)) {
target = {};
}
return at(target, path, function(finalTarget, key) {
if (Array.isArray(finalTarget[key])) {
finalTarget[key].push(value);
}
else {
finalTarget[key] = [value];
}
return finalTarget;
});
} | javascript | function pushByPath(target, path, value) {
path = pathToArray(path);
if (! path.length) {
if (! Array.isArray(target)) {
return [value];
}
else {
target.push(value);
return target;
}
}
if (! isObject(target)) {
target = {};
}
return at(target, path, function(finalTarget, key) {
if (Array.isArray(finalTarget[key])) {
finalTarget[key].push(value);
}
else {
finalTarget[key] = [value];
}
return finalTarget;
});
} | [
"function",
"pushByPath",
"(",
"target",
",",
"path",
",",
"value",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"if",
"(",
"!",
"path",
".",
"length",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"target",
")",
")",
"{",
"return",
"[",
"value",
"]",
";",
"}",
"else",
"{",
"target",
".",
"push",
"(",
"value",
")",
";",
"return",
"target",
";",
"}",
"}",
"if",
"(",
"!",
"isObject",
"(",
"target",
")",
")",
"{",
"target",
"=",
"{",
"}",
";",
"}",
"return",
"at",
"(",
"target",
",",
"path",
",",
"function",
"(",
"finalTarget",
",",
"key",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"finalTarget",
"[",
"key",
"]",
")",
")",
"{",
"finalTarget",
"[",
"key",
"]",
".",
"push",
"(",
"value",
")",
";",
"}",
"else",
"{",
"finalTarget",
"[",
"key",
"]",
"=",
"[",
"value",
"]",
";",
"}",
"return",
"finalTarget",
";",
"}",
")",
";",
"}"
] | Push deeply nested value into target object. If nested properties are not an
objects or not exists creates them.
@param {*} target Parent object.
@param {Path} path Array of path segments.
@param {*} value Value to set.
@return {Object|Array} Returns updated `target`. | [
"Push",
"deeply",
"nested",
"value",
"into",
"target",
"object",
".",
"If",
"nested",
"properties",
"are",
"not",
"an",
"objects",
"or",
"not",
"exists",
"creates",
"them",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L126-L153 |
56,288 | rumkin/keyget | index.js | getByPath | function getByPath(target, path) {
path = pathToArray(path);
const values = breadcrumbs(target, path);
return values[values.length - 1];
} | javascript | function getByPath(target, path) {
path = pathToArray(path);
const values = breadcrumbs(target, path);
return values[values.length - 1];
} | [
"function",
"getByPath",
"(",
"target",
",",
"path",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"const",
"values",
"=",
"breadcrumbs",
"(",
"target",
",",
"path",
")",
";",
"return",
"values",
"[",
"values",
".",
"length",
"-",
"1",
"]",
";",
"}"
] | getByPath - Get value from `target` by `path`.
@param {*} target Nested object or anything else.
@param {Path} path Path to nested property.
@return {*} Returns value or undefined. | [
"getByPath",
"-",
"Get",
"value",
"from",
"target",
"by",
"path",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L204-L210 |
56,289 | rumkin/keyget | index.js | methodByPath | function methodByPath(target, path) {
path = pathToArray(path);
const values = breadcrumbs(target, path);
if (values.length < path.length) {
return noop;
}
if (typeof values[values.length - 1] !== 'function') {
return noop;
}
if (values.length > 1) {
return values[values.length - 1].bind(values[values.length - 2]);
}
else {
return values[0].bind(target);
}
} | javascript | function methodByPath(target, path) {
path = pathToArray(path);
const values = breadcrumbs(target, path);
if (values.length < path.length) {
return noop;
}
if (typeof values[values.length - 1] !== 'function') {
return noop;
}
if (values.length > 1) {
return values[values.length - 1].bind(values[values.length - 2]);
}
else {
return values[0].bind(target);
}
} | [
"function",
"methodByPath",
"(",
"target",
",",
"path",
")",
"{",
"path",
"=",
"pathToArray",
"(",
"path",
")",
";",
"const",
"values",
"=",
"breadcrumbs",
"(",
"target",
",",
"path",
")",
";",
"if",
"(",
"values",
".",
"length",
"<",
"path",
".",
"length",
")",
"{",
"return",
"noop",
";",
"}",
"if",
"(",
"typeof",
"values",
"[",
"values",
".",
"length",
"-",
"1",
"]",
"!==",
"'function'",
")",
"{",
"return",
"noop",
";",
"}",
"if",
"(",
"values",
".",
"length",
">",
"1",
")",
"{",
"return",
"values",
"[",
"values",
".",
"length",
"-",
"1",
"]",
".",
"bind",
"(",
"values",
"[",
"values",
".",
"length",
"-",
"2",
"]",
")",
";",
"}",
"else",
"{",
"return",
"values",
"[",
"0",
"]",
".",
"bind",
"(",
"target",
")",
";",
"}",
"}"
] | methodByPath - Receive method from deeply nested object as function with
captured context as the method's owner object.
@param {*} target Deeply nested object or anything else.
@param {Path} path Path to the method.
@return {Function} Returns function. | [
"methodByPath",
"-",
"Receive",
"method",
"from",
"deeply",
"nested",
"object",
"as",
"function",
"with",
"captured",
"context",
"as",
"the",
"method",
"s",
"owner",
"object",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L220-L239 |
56,290 | rumkin/keyget | index.js | callByPath | function callByPath(target, path, args) {
var fn = methodByPath(target, path);
if (! fn) {
return;
}
return fn.apply(null, args);
} | javascript | function callByPath(target, path, args) {
var fn = methodByPath(target, path);
if (! fn) {
return;
}
return fn.apply(null, args);
} | [
"function",
"callByPath",
"(",
"target",
",",
"path",
",",
"args",
")",
"{",
"var",
"fn",
"=",
"methodByPath",
"(",
"target",
",",
"path",
")",
";",
"if",
"(",
"!",
"fn",
")",
"{",
"return",
";",
"}",
"return",
"fn",
".",
"apply",
"(",
"null",
",",
"args",
")",
";",
"}"
] | callByPath - Call method by it's path in nested object.
@param {*} target Nested object or anything else.
@param {Path} path Path to nested property.
@param {*[]} args Arguments of function call.
@return {*} Result of function call or undefined if method not exists. | [
"callByPath",
"-",
"Call",
"method",
"by",
"it",
"s",
"path",
"in",
"nested",
"object",
"."
] | 3198d6cfb22d10f98552b7cee0be6b1dab79b5fd | https://github.com/rumkin/keyget/blob/3198d6cfb22d10f98552b7cee0be6b1dab79b5fd/index.js#L249-L256 |
56,291 | RnbWd/parse-browserify | lib/geopoint.js | function(point) {
var d2r = Math.PI / 180.0;
var lat1rad = this.latitude * d2r;
var long1rad = this.longitude * d2r;
var lat2rad = point.latitude * d2r;
var long2rad = point.longitude * d2r;
var deltaLat = lat1rad - lat2rad;
var deltaLong = long1rad - long2rad;
var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);
var sinDeltaLongDiv2 = Math.sin(deltaLong / 2);
// Square of half the straight line chord distance between both points.
var a = ((sinDeltaLatDiv2 * sinDeltaLatDiv2) +
(Math.cos(lat1rad) * Math.cos(lat2rad) *
sinDeltaLongDiv2 * sinDeltaLongDiv2));
a = Math.min(1.0, a);
return 2 * Math.asin(Math.sqrt(a));
} | javascript | function(point) {
var d2r = Math.PI / 180.0;
var lat1rad = this.latitude * d2r;
var long1rad = this.longitude * d2r;
var lat2rad = point.latitude * d2r;
var long2rad = point.longitude * d2r;
var deltaLat = lat1rad - lat2rad;
var deltaLong = long1rad - long2rad;
var sinDeltaLatDiv2 = Math.sin(deltaLat / 2);
var sinDeltaLongDiv2 = Math.sin(deltaLong / 2);
// Square of half the straight line chord distance between both points.
var a = ((sinDeltaLatDiv2 * sinDeltaLatDiv2) +
(Math.cos(lat1rad) * Math.cos(lat2rad) *
sinDeltaLongDiv2 * sinDeltaLongDiv2));
a = Math.min(1.0, a);
return 2 * Math.asin(Math.sqrt(a));
} | [
"function",
"(",
"point",
")",
"{",
"var",
"d2r",
"=",
"Math",
".",
"PI",
"/",
"180.0",
";",
"var",
"lat1rad",
"=",
"this",
".",
"latitude",
"*",
"d2r",
";",
"var",
"long1rad",
"=",
"this",
".",
"longitude",
"*",
"d2r",
";",
"var",
"lat2rad",
"=",
"point",
".",
"latitude",
"*",
"d2r",
";",
"var",
"long2rad",
"=",
"point",
".",
"longitude",
"*",
"d2r",
";",
"var",
"deltaLat",
"=",
"lat1rad",
"-",
"lat2rad",
";",
"var",
"deltaLong",
"=",
"long1rad",
"-",
"long2rad",
";",
"var",
"sinDeltaLatDiv2",
"=",
"Math",
".",
"sin",
"(",
"deltaLat",
"/",
"2",
")",
";",
"var",
"sinDeltaLongDiv2",
"=",
"Math",
".",
"sin",
"(",
"deltaLong",
"/",
"2",
")",
";",
"// Square of half the straight line chord distance between both points.",
"var",
"a",
"=",
"(",
"(",
"sinDeltaLatDiv2",
"*",
"sinDeltaLatDiv2",
")",
"+",
"(",
"Math",
".",
"cos",
"(",
"lat1rad",
")",
"*",
"Math",
".",
"cos",
"(",
"lat2rad",
")",
"*",
"sinDeltaLongDiv2",
"*",
"sinDeltaLongDiv2",
")",
")",
";",
"a",
"=",
"Math",
".",
"min",
"(",
"1.0",
",",
"a",
")",
";",
"return",
"2",
"*",
"Math",
".",
"asin",
"(",
"Math",
".",
"sqrt",
"(",
"a",
")",
")",
";",
"}"
] | Returns the distance from this GeoPoint to another in radians.
@param {Parse.GeoPoint} point the other Parse.GeoPoint.
@return {Number} | [
"Returns",
"the",
"distance",
"from",
"this",
"GeoPoint",
"to",
"another",
"in",
"radians",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/geopoint.js#L136-L152 |
|
56,292 | allanmboyd/exceptions | lib/exceptions.js | throwError | function throwError(name, message) {
var error = new Error(message);
error.name = name;
error.stack = formaterrors.stackFilter(error.stack, ["exceptions.js"], false);
throw error;
} | javascript | function throwError(name, message) {
var error = new Error(message);
error.name = name;
error.stack = formaterrors.stackFilter(error.stack, ["exceptions.js"], false);
throw error;
} | [
"function",
"throwError",
"(",
"name",
",",
"message",
")",
"{",
"var",
"error",
"=",
"new",
"Error",
"(",
"message",
")",
";",
"error",
".",
"name",
"=",
"name",
";",
"error",
".",
"stack",
"=",
"formaterrors",
".",
"stackFilter",
"(",
"error",
".",
"stack",
",",
"[",
"\"exceptions.js\"",
"]",
",",
"false",
")",
";",
"throw",
"error",
";",
"}"
] | Throw an error. This method ensures that no exceptions.js lines are included in the stack trace of the thrown
error.
@private
@param {String} name the name of the Error to throw.
@param {String} message the message part of the error to throw. | [
"Throw",
"an",
"error",
".",
"This",
"method",
"ensures",
"that",
"no",
"exceptions",
".",
"js",
"lines",
"are",
"included",
"in",
"the",
"stack",
"trace",
"of",
"the",
"thrown",
"error",
"."
] | ea093be65aba73ededd98fccbf24e16e38f9629b | https://github.com/allanmboyd/exceptions/blob/ea093be65aba73ededd98fccbf24e16e38f9629b/lib/exceptions.js#L56-L63 |
56,293 | imlucas/node-regret | index.js | regret | function regret(name, input){
var matchers, res = null, re, matches, matcher;
if(typeof name.exec === 'function'){
matchers = Object.keys(regret.matchers).filter(function(m){
return name.test(m);
}).map(function(m){
return regret.matchers[m];
});
}
else {
matchers = regret.matchers[name] ? [regret.matchers[name]] : [];
}
if(matchers.length === 0){
return undefined;
}
while(matchers.length > 0){
matcher = matchers.shift();
matches = matcher.pattern.exec(input);
if(!matches){
continue;
}
res = {};
// pop off the input string
matches.shift();
matches.map(function(p, i){
res[matcher.captures[i]] = p;
});
break;
}
return res;
} | javascript | function regret(name, input){
var matchers, res = null, re, matches, matcher;
if(typeof name.exec === 'function'){
matchers = Object.keys(regret.matchers).filter(function(m){
return name.test(m);
}).map(function(m){
return regret.matchers[m];
});
}
else {
matchers = regret.matchers[name] ? [regret.matchers[name]] : [];
}
if(matchers.length === 0){
return undefined;
}
while(matchers.length > 0){
matcher = matchers.shift();
matches = matcher.pattern.exec(input);
if(!matches){
continue;
}
res = {};
// pop off the input string
matches.shift();
matches.map(function(p, i){
res[matcher.captures[i]] = p;
});
break;
}
return res;
} | [
"function",
"regret",
"(",
"name",
",",
"input",
")",
"{",
"var",
"matchers",
",",
"res",
"=",
"null",
",",
"re",
",",
"matches",
",",
"matcher",
";",
"if",
"(",
"typeof",
"name",
".",
"exec",
"===",
"'function'",
")",
"{",
"matchers",
"=",
"Object",
".",
"keys",
"(",
"regret",
".",
"matchers",
")",
".",
"filter",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"name",
".",
"test",
"(",
"m",
")",
";",
"}",
")",
".",
"map",
"(",
"function",
"(",
"m",
")",
"{",
"return",
"regret",
".",
"matchers",
"[",
"m",
"]",
";",
"}",
")",
";",
"}",
"else",
"{",
"matchers",
"=",
"regret",
".",
"matchers",
"[",
"name",
"]",
"?",
"[",
"regret",
".",
"matchers",
"[",
"name",
"]",
"]",
":",
"[",
"]",
";",
"}",
"if",
"(",
"matchers",
".",
"length",
"===",
"0",
")",
"{",
"return",
"undefined",
";",
"}",
"while",
"(",
"matchers",
".",
"length",
">",
"0",
")",
"{",
"matcher",
"=",
"matchers",
".",
"shift",
"(",
")",
";",
"matches",
"=",
"matcher",
".",
"pattern",
".",
"exec",
"(",
"input",
")",
";",
"if",
"(",
"!",
"matches",
")",
"{",
"continue",
";",
"}",
"res",
"=",
"{",
"}",
";",
"// pop off the input string",
"matches",
".",
"shift",
"(",
")",
";",
"matches",
".",
"map",
"(",
"function",
"(",
"p",
",",
"i",
")",
"{",
"res",
"[",
"matcher",
".",
"captures",
"[",
"i",
"]",
"]",
"=",
"p",
";",
"}",
")",
";",
"break",
";",
"}",
"return",
"res",
";",
"}"
] | Don't let the regex party get out of control. | [
"Don",
"t",
"let",
"the",
"regex",
"party",
"get",
"out",
"of",
"control",
"."
] | 7e304af8575a9480028fc75fe62a3e1c5d893551 | https://github.com/imlucas/node-regret/blob/7e304af8575a9480028fc75fe62a3e1c5d893551/index.js#L4-L38 |
56,294 | antonycourtney/tabli-core | lib/js/utils.js | seqActions | function seqActions(actions, seed, onCompleted) {
var index = 0;
function invokeNext(v) {
var action = actions[index];
action(v, function (res) {
index = index + 1;
if (index < actions.length) {
invokeNext(res);
} else {
onCompleted(res);
}
});
}
invokeNext(seed);
} | javascript | function seqActions(actions, seed, onCompleted) {
var index = 0;
function invokeNext(v) {
var action = actions[index];
action(v, function (res) {
index = index + 1;
if (index < actions.length) {
invokeNext(res);
} else {
onCompleted(res);
}
});
}
invokeNext(seed);
} | [
"function",
"seqActions",
"(",
"actions",
",",
"seed",
",",
"onCompleted",
")",
"{",
"var",
"index",
"=",
"0",
";",
"function",
"invokeNext",
"(",
"v",
")",
"{",
"var",
"action",
"=",
"actions",
"[",
"index",
"]",
";",
"action",
"(",
"v",
",",
"function",
"(",
"res",
")",
"{",
"index",
"=",
"index",
"+",
"1",
";",
"if",
"(",
"index",
"<",
"actions",
".",
"length",
")",
"{",
"invokeNext",
"(",
"res",
")",
";",
"}",
"else",
"{",
"onCompleted",
"(",
"res",
")",
";",
"}",
"}",
")",
";",
"}",
"invokeNext",
"(",
"seed",
")",
";",
"}"
] | chain a sequence of asynchronous actions | [
"chain",
"a",
"sequence",
"of",
"asynchronous",
"actions"
] | 76cc540891421bc6c8bdcf00f277ebb6e716fdd9 | https://github.com/antonycourtney/tabli-core/blob/76cc540891421bc6c8bdcf00f277ebb6e716fdd9/lib/js/utils.js#L56-L72 |
56,295 | stdarg/json-rest-api | index.js | RestApi | function RestApi(config, cb) {
var self = this;
self.routes = {};
self.bindTo = (config && config.bindTo) ? config.bindTo : undefined;
self.port = (config && config.port) ? config.port : DEFAULT_PORT;
// create the HTTP server object and on every request, try to match the
// request with a known route. If there is no match, return a 404 error.
self.HttpServer = http.createServer(function(req, res) {
var uriPath;
var queryStr;
var urlParts = url.parse(req.url, true);
if (is.obj(urlParts)) {
uriPath = urlParts.pathname || undefined;
queryStr = urlParts.query || undefined;
debug('queryStr: '+inspect(queryStr));
} else {
// no match was found, return a 404 error.
res.writeHead(400, {'Content-Type': 'application/json; charset=utf-8'});
res.end('{status:400, message:"Bad URI path."}', 'utf8');
return;
}
// try to match the request & method with a handler
for (var path in self.routes[req.method]) {
if (path === uriPath) {
self.routes[req.method][path](req, res, queryStr);
return;
}
}
// no match was found, return a 404 error.
res.writeHead(404, {'Content-Type': 'application/json; charset=utf-8'});
res.end('{status:404, message:"Content not found."}', 'utf8');
});
if (cb) self.listen(cb);
} | javascript | function RestApi(config, cb) {
var self = this;
self.routes = {};
self.bindTo = (config && config.bindTo) ? config.bindTo : undefined;
self.port = (config && config.port) ? config.port : DEFAULT_PORT;
// create the HTTP server object and on every request, try to match the
// request with a known route. If there is no match, return a 404 error.
self.HttpServer = http.createServer(function(req, res) {
var uriPath;
var queryStr;
var urlParts = url.parse(req.url, true);
if (is.obj(urlParts)) {
uriPath = urlParts.pathname || undefined;
queryStr = urlParts.query || undefined;
debug('queryStr: '+inspect(queryStr));
} else {
// no match was found, return a 404 error.
res.writeHead(400, {'Content-Type': 'application/json; charset=utf-8'});
res.end('{status:400, message:"Bad URI path."}', 'utf8');
return;
}
// try to match the request & method with a handler
for (var path in self.routes[req.method]) {
if (path === uriPath) {
self.routes[req.method][path](req, res, queryStr);
return;
}
}
// no match was found, return a 404 error.
res.writeHead(404, {'Content-Type': 'application/json; charset=utf-8'});
res.end('{status:404, message:"Content not found."}', 'utf8');
});
if (cb) self.listen(cb);
} | [
"function",
"RestApi",
"(",
"config",
",",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"self",
".",
"routes",
"=",
"{",
"}",
";",
"self",
".",
"bindTo",
"=",
"(",
"config",
"&&",
"config",
".",
"bindTo",
")",
"?",
"config",
".",
"bindTo",
":",
"undefined",
";",
"self",
".",
"port",
"=",
"(",
"config",
"&&",
"config",
".",
"port",
")",
"?",
"config",
".",
"port",
":",
"DEFAULT_PORT",
";",
"// create the HTTP server object and on every request, try to match the",
"// request with a known route. If there is no match, return a 404 error.",
"self",
".",
"HttpServer",
"=",
"http",
".",
"createServer",
"(",
"function",
"(",
"req",
",",
"res",
")",
"{",
"var",
"uriPath",
";",
"var",
"queryStr",
";",
"var",
"urlParts",
"=",
"url",
".",
"parse",
"(",
"req",
".",
"url",
",",
"true",
")",
";",
"if",
"(",
"is",
".",
"obj",
"(",
"urlParts",
")",
")",
"{",
"uriPath",
"=",
"urlParts",
".",
"pathname",
"||",
"undefined",
";",
"queryStr",
"=",
"urlParts",
".",
"query",
"||",
"undefined",
";",
"debug",
"(",
"'queryStr: '",
"+",
"inspect",
"(",
"queryStr",
")",
")",
";",
"}",
"else",
"{",
"// no match was found, return a 404 error.",
"res",
".",
"writeHead",
"(",
"400",
",",
"{",
"'Content-Type'",
":",
"'application/json; charset=utf-8'",
"}",
")",
";",
"res",
".",
"end",
"(",
"'{status:400, message:\"Bad URI path.\"}'",
",",
"'utf8'",
")",
";",
"return",
";",
"}",
"// try to match the request & method with a handler",
"for",
"(",
"var",
"path",
"in",
"self",
".",
"routes",
"[",
"req",
".",
"method",
"]",
")",
"{",
"if",
"(",
"path",
"===",
"uriPath",
")",
"{",
"self",
".",
"routes",
"[",
"req",
".",
"method",
"]",
"[",
"path",
"]",
"(",
"req",
",",
"res",
",",
"queryStr",
")",
";",
"return",
";",
"}",
"}",
"// no match was found, return a 404 error.",
"res",
".",
"writeHead",
"(",
"404",
",",
"{",
"'Content-Type'",
":",
"'application/json; charset=utf-8'",
"}",
")",
";",
"res",
".",
"end",
"(",
"'{status:404, message:\"Content not found.\"}'",
",",
"'utf8'",
")",
";",
"}",
")",
";",
"if",
"(",
"cb",
")",
"self",
".",
"listen",
"(",
"cb",
")",
";",
"}"
] | RestApi constructor. Creates the HTTP server objects and starts listening on
the socket.
@param {Object} [config] An optional configuration object to configure the
RestApi. Possible properties are: port and bindTo to specify the listening
port and the address to bind to. If no port is specified the default is 44401
and the default address is INADDR_ANY.
@param {Function} [cb] An optional callback. If there is a callback, the
process will be begin listening on the socket for HTTP requests.
@constructor | [
"RestApi",
"constructor",
".",
"Creates",
"the",
"HTTP",
"server",
"objects",
"and",
"starts",
"listening",
"on",
"the",
"socket",
"."
] | 25e47f4d26d9391f6a8a3de37545029130e39d45 | https://github.com/stdarg/json-rest-api/blob/25e47f4d26d9391f6a8a3de37545029130e39d45/index.js#L31-L69 |
56,296 | pierrec/node-atok | lib/rule.js | Rule | function Rule (subrules, type, handler, props, groupProps, encoding) {
var self = this
var n = subrules.length
this.props = props
this.debug = false
// Used for cloning
this.subrules = subrules
// Required by Atok#_resolveRules
for (var p in groupProps)
this[p] = groupProps[p]
// Runtime values for continue props
this.continue = this.props.continue[0]
this.continueOnFail = this.props.continue[1]
this.type = type
this.handler = handler
// For debug
this.prevHandler = null
this.id = this.type !== null ? this.type : handler
// Id for debug
this._id = (handler !== null ? (handler.name || '#emit()') : this.type)
// Subrule pattern index that matched (-1 if only 1 pattern)
this.idx = -1
// Single subrule: special case for trimRight
this.single = (n === 1)
// First subrule
var subrule = this.first = n > 0
? SubRule.firstSubRule( subrules[0], this.props, encoding, this.single )
// Special case: no rule given -> passthrough
: SubRule.emptySubRule
// Special case: one empty rule -> tokenize whole buffer
if (n === 1 && subrule.length === 0) {
subrule = this.first = SubRule.allSubRule
// Make infinite loop detection ignore this
this.length = -1
} else {
// First subrule pattern length (max of all patterns if many)
// - used in infinite loop detection
this.length = this.first.length
}
// Instantiate and link the subrules
// { test: {Function}
// , next: {SubRule|undefined}
// }
var prev = subrule
// Many subrules or none
for (var i = 1; i < n; i++) {
subrule = SubRule.SubRule( subrules[i], this.props, encoding )
prev.next = subrule
subrule.prev = prev // Useful in some edge cases
prev = subrule
if (this.length < subrule.length) this.length = subrule.length
}
// Last subrule (used for trimRight and matched idx)
this.last = subrule
// Set the first and last subrules length based on trim properties
if (!this.props.trimLeft) this.first.length = 0
if (!this.single && !this.props.trimRight) this.last.length = 0
this.next = null
this.nextFail = null
this.currentRule = null
} | javascript | function Rule (subrules, type, handler, props, groupProps, encoding) {
var self = this
var n = subrules.length
this.props = props
this.debug = false
// Used for cloning
this.subrules = subrules
// Required by Atok#_resolveRules
for (var p in groupProps)
this[p] = groupProps[p]
// Runtime values for continue props
this.continue = this.props.continue[0]
this.continueOnFail = this.props.continue[1]
this.type = type
this.handler = handler
// For debug
this.prevHandler = null
this.id = this.type !== null ? this.type : handler
// Id for debug
this._id = (handler !== null ? (handler.name || '#emit()') : this.type)
// Subrule pattern index that matched (-1 if only 1 pattern)
this.idx = -1
// Single subrule: special case for trimRight
this.single = (n === 1)
// First subrule
var subrule = this.first = n > 0
? SubRule.firstSubRule( subrules[0], this.props, encoding, this.single )
// Special case: no rule given -> passthrough
: SubRule.emptySubRule
// Special case: one empty rule -> tokenize whole buffer
if (n === 1 && subrule.length === 0) {
subrule = this.first = SubRule.allSubRule
// Make infinite loop detection ignore this
this.length = -1
} else {
// First subrule pattern length (max of all patterns if many)
// - used in infinite loop detection
this.length = this.first.length
}
// Instantiate and link the subrules
// { test: {Function}
// , next: {SubRule|undefined}
// }
var prev = subrule
// Many subrules or none
for (var i = 1; i < n; i++) {
subrule = SubRule.SubRule( subrules[i], this.props, encoding )
prev.next = subrule
subrule.prev = prev // Useful in some edge cases
prev = subrule
if (this.length < subrule.length) this.length = subrule.length
}
// Last subrule (used for trimRight and matched idx)
this.last = subrule
// Set the first and last subrules length based on trim properties
if (!this.props.trimLeft) this.first.length = 0
if (!this.single && !this.props.trimRight) this.last.length = 0
this.next = null
this.nextFail = null
this.currentRule = null
} | [
"function",
"Rule",
"(",
"subrules",
",",
"type",
",",
"handler",
",",
"props",
",",
"groupProps",
",",
"encoding",
")",
"{",
"var",
"self",
"=",
"this",
"var",
"n",
"=",
"subrules",
".",
"length",
"this",
".",
"props",
"=",
"props",
"this",
".",
"debug",
"=",
"false",
"// Used for cloning",
"this",
".",
"subrules",
"=",
"subrules",
"// Required by Atok#_resolveRules",
"for",
"(",
"var",
"p",
"in",
"groupProps",
")",
"this",
"[",
"p",
"]",
"=",
"groupProps",
"[",
"p",
"]",
"// Runtime values for continue props",
"this",
".",
"continue",
"=",
"this",
".",
"props",
".",
"continue",
"[",
"0",
"]",
"this",
".",
"continueOnFail",
"=",
"this",
".",
"props",
".",
"continue",
"[",
"1",
"]",
"this",
".",
"type",
"=",
"type",
"this",
".",
"handler",
"=",
"handler",
"// For debug",
"this",
".",
"prevHandler",
"=",
"null",
"this",
".",
"id",
"=",
"this",
".",
"type",
"!==",
"null",
"?",
"this",
".",
"type",
":",
"handler",
"// Id for debug",
"this",
".",
"_id",
"=",
"(",
"handler",
"!==",
"null",
"?",
"(",
"handler",
".",
"name",
"||",
"'#emit()'",
")",
":",
"this",
".",
"type",
")",
"// Subrule pattern index that matched (-1 if only 1 pattern)",
"this",
".",
"idx",
"=",
"-",
"1",
"// Single subrule: special case for trimRight",
"this",
".",
"single",
"=",
"(",
"n",
"===",
"1",
")",
"// First subrule",
"var",
"subrule",
"=",
"this",
".",
"first",
"=",
"n",
">",
"0",
"?",
"SubRule",
".",
"firstSubRule",
"(",
"subrules",
"[",
"0",
"]",
",",
"this",
".",
"props",
",",
"encoding",
",",
"this",
".",
"single",
")",
"// Special case: no rule given -> passthrough",
":",
"SubRule",
".",
"emptySubRule",
"// Special case: one empty rule -> tokenize whole buffer",
"if",
"(",
"n",
"===",
"1",
"&&",
"subrule",
".",
"length",
"===",
"0",
")",
"{",
"subrule",
"=",
"this",
".",
"first",
"=",
"SubRule",
".",
"allSubRule",
"// Make infinite loop detection ignore this",
"this",
".",
"length",
"=",
"-",
"1",
"}",
"else",
"{",
"// First subrule pattern length (max of all patterns if many)",
"// - used in infinite loop detection",
"this",
".",
"length",
"=",
"this",
".",
"first",
".",
"length",
"}",
"// Instantiate and link the subrules",
"// { test: {Function}",
"// , next: {SubRule|undefined}",
"// }",
"var",
"prev",
"=",
"subrule",
"// Many subrules or none",
"for",
"(",
"var",
"i",
"=",
"1",
";",
"i",
"<",
"n",
";",
"i",
"++",
")",
"{",
"subrule",
"=",
"SubRule",
".",
"SubRule",
"(",
"subrules",
"[",
"i",
"]",
",",
"this",
".",
"props",
",",
"encoding",
")",
"prev",
".",
"next",
"=",
"subrule",
"subrule",
".",
"prev",
"=",
"prev",
"// Useful in some edge cases",
"prev",
"=",
"subrule",
"if",
"(",
"this",
".",
"length",
"<",
"subrule",
".",
"length",
")",
"this",
".",
"length",
"=",
"subrule",
".",
"length",
"}",
"// Last subrule (used for trimRight and matched idx)",
"this",
".",
"last",
"=",
"subrule",
"// Set the first and last subrules length based on trim properties",
"if",
"(",
"!",
"this",
".",
"props",
".",
"trimLeft",
")",
"this",
".",
"first",
".",
"length",
"=",
"0",
"if",
"(",
"!",
"this",
".",
"single",
"&&",
"!",
"this",
".",
"props",
".",
"trimRight",
")",
"this",
".",
"last",
".",
"length",
"=",
"0",
"this",
".",
"next",
"=",
"null",
"this",
".",
"nextFail",
"=",
"null",
"this",
".",
"currentRule",
"=",
"null",
"}"
] | Atok Rule constructor
@param {array} list of subrules
@param {string|number|null} rule type (set if handler is not)
@param {function} rule handler (set if type is not)
@param {Object} atok instance
@constructor
@api private | [
"Atok",
"Rule",
"constructor"
] | abe139e7fa8c092d87e528289b6abd9083df2323 | https://github.com/pierrec/node-atok/blob/abe139e7fa8c092d87e528289b6abd9083df2323/lib/rule.js#L23-L98 |
56,297 | donavon/storeit | lib/Storeit.js | initializeItemSerializer | function initializeItemSerializer(hasItems) {
// Is there is a itemSerializer specified, we MUST use it.
// If existing data and no itemSerializer specified, this is an old JSON database,
// so "fake" the compatible JSON serializer
var providerInfo = storageProvider.getMetadata(namespace); // TODO I hate this!
var itemSerializerName = providerInfo ? providerInfo.itemSerializer :
hasItems ? "JSONSerializer" : null;
storageProvider.itemSerializer = itemSerializerName;
} | javascript | function initializeItemSerializer(hasItems) {
// Is there is a itemSerializer specified, we MUST use it.
// If existing data and no itemSerializer specified, this is an old JSON database,
// so "fake" the compatible JSON serializer
var providerInfo = storageProvider.getMetadata(namespace); // TODO I hate this!
var itemSerializerName = providerInfo ? providerInfo.itemSerializer :
hasItems ? "JSONSerializer" : null;
storageProvider.itemSerializer = itemSerializerName;
} | [
"function",
"initializeItemSerializer",
"(",
"hasItems",
")",
"{",
"// Is there is a itemSerializer specified, we MUST use it.",
"// If existing data and no itemSerializer specified, this is an old JSON database,",
"// so \"fake\" the compatible JSON serializer",
"var",
"providerInfo",
"=",
"storageProvider",
".",
"getMetadata",
"(",
"namespace",
")",
";",
"// TODO I hate this!",
"var",
"itemSerializerName",
"=",
"providerInfo",
"?",
"providerInfo",
".",
"itemSerializer",
":",
"hasItems",
"?",
"\"JSONSerializer\"",
":",
"null",
";",
"storageProvider",
".",
"itemSerializer",
"=",
"itemSerializerName",
";",
"}"
] | Read in the base namespace key. | [
"Read",
"in",
"the",
"base",
"namespace",
"key",
"."
] | f896ddd81394626073494c800076272b694d7ec8 | https://github.com/donavon/storeit/blob/f896ddd81394626073494c800076272b694d7ec8/lib/Storeit.js#L211-L219 |
56,298 | react-components/onus | index.js | _yield | function _yield(name, context) {
var prop = this.props[name || 'children'];
if (typeof prop !== 'function') return prop;
var args = Array.prototype.slice.call(arguments, 2);
return prop.apply(context, args);
} | javascript | function _yield(name, context) {
var prop = this.props[name || 'children'];
if (typeof prop !== 'function') return prop;
var args = Array.prototype.slice.call(arguments, 2);
return prop.apply(context, args);
} | [
"function",
"_yield",
"(",
"name",
",",
"context",
")",
"{",
"var",
"prop",
"=",
"this",
".",
"props",
"[",
"name",
"||",
"'children'",
"]",
";",
"if",
"(",
"typeof",
"prop",
"!==",
"'function'",
")",
"return",
"prop",
";",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"return",
"prop",
".",
"apply",
"(",
"context",
",",
"args",
")",
";",
"}"
] | Wrap the yield function | [
"Wrap",
"the",
"yield",
"function"
] | ebe1884a8e70b3ca9d1e95e05c373525f7f5d71b | https://github.com/react-components/onus/blob/ebe1884a8e70b3ca9d1e95e05c373525f7f5d71b/index.js#L238-L244 |
56,299 | ruifortes/json-deref | src/index.js | getJsonResource | function getJsonResource(url) {
var protocol = url.match(/^(.*?):/)
protocol = (protocol && protocol[1]) || 'file'
const defaultLoader = defaultOptions.loaders[protocol]
const loader = options.loaders[protocol]
return Promise.resolve(cache[url])
.then(cached => {
if(cached) {
return cached
} else {
return loader(url, defaultOptions.loaders)
.then(json => cache[url] = {raw: json, parsed: Array.isArray(json) ? [] : {} })
}
})
} | javascript | function getJsonResource(url) {
var protocol = url.match(/^(.*?):/)
protocol = (protocol && protocol[1]) || 'file'
const defaultLoader = defaultOptions.loaders[protocol]
const loader = options.loaders[protocol]
return Promise.resolve(cache[url])
.then(cached => {
if(cached) {
return cached
} else {
return loader(url, defaultOptions.loaders)
.then(json => cache[url] = {raw: json, parsed: Array.isArray(json) ? [] : {} })
}
})
} | [
"function",
"getJsonResource",
"(",
"url",
")",
"{",
"var",
"protocol",
"=",
"url",
".",
"match",
"(",
"/",
"^(.*?):",
"/",
")",
"protocol",
"=",
"(",
"protocol",
"&&",
"protocol",
"[",
"1",
"]",
")",
"||",
"'file'",
"const",
"defaultLoader",
"=",
"defaultOptions",
".",
"loaders",
"[",
"protocol",
"]",
"const",
"loader",
"=",
"options",
".",
"loaders",
"[",
"protocol",
"]",
"return",
"Promise",
".",
"resolve",
"(",
"cache",
"[",
"url",
"]",
")",
".",
"then",
"(",
"cached",
"=>",
"{",
"if",
"(",
"cached",
")",
"{",
"return",
"cached",
"}",
"else",
"{",
"return",
"loader",
"(",
"url",
",",
"defaultOptions",
".",
"loaders",
")",
".",
"then",
"(",
"json",
"=>",
"cache",
"[",
"url",
"]",
"=",
"{",
"raw",
":",
"json",
",",
"parsed",
":",
"Array",
".",
"isArray",
"(",
"json",
")",
"?",
"[",
"]",
":",
"{",
"}",
"}",
")",
"}",
"}",
")",
"}"
] | Gets raw and parsed json from cache
@param {object} url - uri-js object
@param {object} params - ...rest of the json-reference object
@returns {Object}
Returns an object containing raw, parsed and id | [
"Gets",
"raw",
"and",
"parsed",
"json",
"from",
"cache"
] | 1d534d68e5067b3de4bc98080f6e989187a684ca | https://github.com/ruifortes/json-deref/blob/1d534d68e5067b3de4bc98080f6e989187a684ca/src/index.js#L87-L104 |
Subsets and Splits