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
|
---|---|---|---|---|---|---|---|---|---|---|---|
54,700 | RnbWd/parse-browserify | lib/query.js | function(options) {
var self = this;
options = options || {};
var request = Parse._request({
route: "classes",
className: this.className,
method: "GET",
useMasterKey: options.useMasterKey,
data: this.toJSON()
});
return request.then(function(response) {
return _.map(response.results, function(json) {
var obj;
if (response.className) {
obj = new Parse.Object(response.className);
} else {
obj = new self.objectClass();
}
obj._finishFetch(json, true);
return obj;
});
})._thenRunCallbacks(options);
} | javascript | function(options) {
var self = this;
options = options || {};
var request = Parse._request({
route: "classes",
className: this.className,
method: "GET",
useMasterKey: options.useMasterKey,
data: this.toJSON()
});
return request.then(function(response) {
return _.map(response.results, function(json) {
var obj;
if (response.className) {
obj = new Parse.Object(response.className);
} else {
obj = new self.objectClass();
}
obj._finishFetch(json, true);
return obj;
});
})._thenRunCallbacks(options);
} | [
"function",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"request",
"=",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"\"classes\"",
",",
"className",
":",
"this",
".",
"className",
",",
"method",
":",
"\"GET\"",
",",
"useMasterKey",
":",
"options",
".",
"useMasterKey",
",",
"data",
":",
"this",
".",
"toJSON",
"(",
")",
"}",
")",
";",
"return",
"request",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"_",
".",
"map",
"(",
"response",
".",
"results",
",",
"function",
"(",
"json",
")",
"{",
"var",
"obj",
";",
"if",
"(",
"response",
".",
"className",
")",
"{",
"obj",
"=",
"new",
"Parse",
".",
"Object",
"(",
"response",
".",
"className",
")",
";",
"}",
"else",
"{",
"obj",
"=",
"new",
"self",
".",
"objectClass",
"(",
")",
";",
"}",
"obj",
".",
"_finishFetch",
"(",
"json",
",",
"true",
")",
";",
"return",
"obj",
";",
"}",
")",
";",
"}",
")",
".",
"_thenRunCallbacks",
"(",
"options",
")",
";",
"}"
] | Retrieves a list of ParseObjects that satisfy this query.
Either options.success or options.error is called when the find
completes.
@param {Object} options A Backbone-style options object. Valid options
are:<ul>
<li>success: Function to call when the find completes successfully.
<li>error: Function to call when the find fails.
<li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
be used for this request.
</ul>
@return {Parse.Promise} A promise that is resolved with the results when
the query completes. | [
"Retrieves",
"a",
"list",
"of",
"ParseObjects",
"that",
"satisfy",
"this",
"query",
".",
"Either",
"options",
".",
"success",
"or",
"options",
".",
"error",
"is",
"called",
"when",
"the",
"find",
"completes",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L189-L213 |
|
54,701 | RnbWd/parse-browserify | lib/query.js | function(options) {
var self = this;
options = options || {};
var params = this.toJSON();
params.limit = 0;
params.count = 1;
var request = Parse._request({
route: "classes",
className: self.className,
method: "GET",
useMasterKey: options.useMasterKey,
data: params
});
return request.then(function(response) {
return response.count;
})._thenRunCallbacks(options);
} | javascript | function(options) {
var self = this;
options = options || {};
var params = this.toJSON();
params.limit = 0;
params.count = 1;
var request = Parse._request({
route: "classes",
className: self.className,
method: "GET",
useMasterKey: options.useMasterKey,
data: params
});
return request.then(function(response) {
return response.count;
})._thenRunCallbacks(options);
} | [
"function",
"(",
"options",
")",
"{",
"var",
"self",
"=",
"this",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"var",
"params",
"=",
"this",
".",
"toJSON",
"(",
")",
";",
"params",
".",
"limit",
"=",
"0",
";",
"params",
".",
"count",
"=",
"1",
";",
"var",
"request",
"=",
"Parse",
".",
"_request",
"(",
"{",
"route",
":",
"\"classes\"",
",",
"className",
":",
"self",
".",
"className",
",",
"method",
":",
"\"GET\"",
",",
"useMasterKey",
":",
"options",
".",
"useMasterKey",
",",
"data",
":",
"params",
"}",
")",
";",
"return",
"request",
".",
"then",
"(",
"function",
"(",
"response",
")",
"{",
"return",
"response",
".",
"count",
";",
"}",
")",
".",
"_thenRunCallbacks",
"(",
"options",
")",
";",
"}"
] | Counts the number of objects that match this query.
Either options.success or options.error is called when the count
completes.
@param {Object} options A Backbone-style options object. Valid options
are:<ul>
<li>success: Function to call when the count completes successfully.
<li>error: Function to call when the find fails.
<li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
be used for this request.
</ul>
@return {Parse.Promise} A promise that is resolved with the count when
the query completes. | [
"Counts",
"the",
"number",
"of",
"objects",
"that",
"match",
"this",
"query",
".",
"Either",
"options",
".",
"success",
"or",
"options",
".",
"error",
"is",
"called",
"when",
"the",
"count",
"completes",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L231-L249 |
|
54,702 | RnbWd/parse-browserify | lib/query.js | function(items, options) {
options = options || {};
return new Parse.Collection(items, _.extend(options, {
model: this.objectClass,
query: this
}));
} | javascript | function(items, options) {
options = options || {};
return new Parse.Collection(items, _.extend(options, {
model: this.objectClass,
query: this
}));
} | [
"function",
"(",
"items",
",",
"options",
")",
"{",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"return",
"new",
"Parse",
".",
"Collection",
"(",
"items",
",",
"_",
".",
"extend",
"(",
"options",
",",
"{",
"model",
":",
"this",
".",
"objectClass",
",",
"query",
":",
"this",
"}",
")",
")",
";",
"}"
] | Returns a new instance of Parse.Collection backed by this query.
@param {Array} items An array of instances of <code>Parse.Object</code>
with which to start this Collection.
@param {Object} options An optional object with Backbone-style options.
Valid options are:<ul>
<li>model: The Parse.Object subclass that this collection contains.
<li>query: An instance of Parse.Query to use when fetching items.
<li>comparator: A string property name or function to sort by.
</ul>
@return {Parse.Collection} | [
"Returns",
"a",
"new",
"instance",
"of",
"Parse",
".",
"Collection",
"backed",
"by",
"this",
"query",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L303-L309 |
|
54,703 | RnbWd/parse-browserify | lib/query.js | function(key) {
var self = this;
if (!this._order) {
this._order = [];
}
Parse._arrayEach(arguments, function(key) {
if (Array.isArray(key)) {
key = key.join();
}
self._order = self._order.concat(key.replace(/\s/g, "").split(","));
});
return this;
} | javascript | function(key) {
var self = this;
if (!this._order) {
this._order = [];
}
Parse._arrayEach(arguments, function(key) {
if (Array.isArray(key)) {
key = key.join();
}
self._order = self._order.concat(key.replace(/\s/g, "").split(","));
});
return this;
} | [
"function",
"(",
"key",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"this",
".",
"_order",
")",
"{",
"this",
".",
"_order",
"=",
"[",
"]",
";",
"}",
"Parse",
".",
"_arrayEach",
"(",
"arguments",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"key",
"=",
"key",
".",
"join",
"(",
")",
";",
"}",
"self",
".",
"_order",
"=",
"self",
".",
"_order",
".",
"concat",
"(",
"key",
".",
"replace",
"(",
"/",
"\\s",
"/",
"g",
",",
"\"\"",
")",
".",
"split",
"(",
"\",\"",
")",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Sorts the results in ascending order by the given key,
but can also add secondary sort descriptors without overwriting _order.
@param {(String|String[]|...String} key The key to order by, which is a
string of comma separated values, or an Array of keys, or multiple keys.
@return {Parse.Query} Returns the query, so you can chain this call. | [
"Sorts",
"the",
"results",
"in",
"ascending",
"order",
"by",
"the",
"given",
"key",
"but",
"can",
"also",
"add",
"secondary",
"sort",
"descriptors",
"without",
"overwriting",
"_order",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L649-L661 |
|
54,704 | RnbWd/parse-browserify | lib/query.js | function() {
var self = this;
Parse._arrayEach(arguments, function(key) {
if (_.isArray(key)) {
self._include = self._include.concat(key);
} else {
self._include.push(key);
}
});
return this;
} | javascript | function() {
var self = this;
Parse._arrayEach(arguments, function(key) {
if (_.isArray(key)) {
self._include = self._include.concat(key);
} else {
self._include.push(key);
}
});
return this;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"Parse",
".",
"_arrayEach",
"(",
"arguments",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"self",
".",
"_include",
"=",
"self",
".",
"_include",
".",
"concat",
"(",
"key",
")",
";",
"}",
"else",
"{",
"self",
".",
"_include",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Include nested Parse.Objects for the provided key. You can use dot
notation to specify which fields in the included object are also fetch.
@param {String} key The name of the key to include.
@return {Parse.Query} Returns the query, so you can chain this call. | [
"Include",
"nested",
"Parse",
".",
"Objects",
"for",
"the",
"provided",
"key",
".",
"You",
"can",
"use",
"dot",
"notation",
"to",
"specify",
"which",
"fields",
"in",
"the",
"included",
"object",
"are",
"also",
"fetch",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L786-L796 |
|
54,705 | RnbWd/parse-browserify | lib/query.js | function() {
var self = this;
this._select = this._select || [];
Parse._arrayEach(arguments, function(key) {
if (_.isArray(key)) {
self._select = self._select.concat(key);
} else {
self._select.push(key);
}
});
return this;
} | javascript | function() {
var self = this;
this._select = this._select || [];
Parse._arrayEach(arguments, function(key) {
if (_.isArray(key)) {
self._select = self._select.concat(key);
} else {
self._select.push(key);
}
});
return this;
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"this",
".",
"_select",
"=",
"this",
".",
"_select",
"||",
"[",
"]",
";",
"Parse",
".",
"_arrayEach",
"(",
"arguments",
",",
"function",
"(",
"key",
")",
"{",
"if",
"(",
"_",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"self",
".",
"_select",
"=",
"self",
".",
"_select",
".",
"concat",
"(",
"key",
")",
";",
"}",
"else",
"{",
"self",
".",
"_select",
".",
"push",
"(",
"key",
")",
";",
"}",
"}",
")",
";",
"return",
"this",
";",
"}"
] | Restrict the fields of the returned Parse.Objects to include only the
provided keys. If this is called multiple times, then all of the keys
specified in each of the calls will be included.
@param {Array} keys The names of the keys to include.
@return {Parse.Query} Returns the query, so you can chain this call. | [
"Restrict",
"the",
"fields",
"of",
"the",
"returned",
"Parse",
".",
"Objects",
"to",
"include",
"only",
"the",
"provided",
"keys",
".",
"If",
"this",
"is",
"called",
"multiple",
"times",
"then",
"all",
"of",
"the",
"keys",
"specified",
"in",
"each",
"of",
"the",
"calls",
"will",
"be",
"included",
"."
] | c19c1b798e4010a552e130b1a9ce3b5d084dc101 | https://github.com/RnbWd/parse-browserify/blob/c19c1b798e4010a552e130b1a9ce3b5d084dc101/lib/query.js#L805-L816 |
|
54,706 | maidol/cw-logger | logstash/tcp-bunyan.js | LogstashStream | function LogstashStream(options) {
EventEmitter.call(this);
options = options || {};
this.name = 'bunyan';
this.level = options.level || 'info';
this.server = options.server || os.hostname();
this.host = options.host || '127.0.0.1';
this.port = options.port || 9999;
this.application = options.appName || process.title;
this.pid = options.pid || process.pid;
this.tags = options.tags || ['bunyan'];
this.type = options.type;
this.client = null;
// ssl
this.ssl_enable = options.ssl_enable || false;
this.ssl_key = options.ssl_key || '';
this.ssl_cert = options.ssl_cert || '';
this.ca = options.ca || '';
this.ssl_passphrase = options.ssl_passphrase || '';
this.cbuffer_size = options.cbuffer_size || 10;
// Connection state
this.log_queue = new CBuffer(this.cbuffer_size);
this.connected = false;
this.socket = null;
this.retries = -1;
this.max_connect_retries = (typeof options.max_connect_retries === 'number') ? options.max_connect_retries : 4;
this.retry_interval = options.retry_interval || 100;
this.connect();
} | javascript | function LogstashStream(options) {
EventEmitter.call(this);
options = options || {};
this.name = 'bunyan';
this.level = options.level || 'info';
this.server = options.server || os.hostname();
this.host = options.host || '127.0.0.1';
this.port = options.port || 9999;
this.application = options.appName || process.title;
this.pid = options.pid || process.pid;
this.tags = options.tags || ['bunyan'];
this.type = options.type;
this.client = null;
// ssl
this.ssl_enable = options.ssl_enable || false;
this.ssl_key = options.ssl_key || '';
this.ssl_cert = options.ssl_cert || '';
this.ca = options.ca || '';
this.ssl_passphrase = options.ssl_passphrase || '';
this.cbuffer_size = options.cbuffer_size || 10;
// Connection state
this.log_queue = new CBuffer(this.cbuffer_size);
this.connected = false;
this.socket = null;
this.retries = -1;
this.max_connect_retries = (typeof options.max_connect_retries === 'number') ? options.max_connect_retries : 4;
this.retry_interval = options.retry_interval || 100;
this.connect();
} | [
"function",
"LogstashStream",
"(",
"options",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"this",
".",
"name",
"=",
"'bunyan'",
";",
"this",
".",
"level",
"=",
"options",
".",
"level",
"||",
"'info'",
";",
"this",
".",
"server",
"=",
"options",
".",
"server",
"||",
"os",
".",
"hostname",
"(",
")",
";",
"this",
".",
"host",
"=",
"options",
".",
"host",
"||",
"'127.0.0.1'",
";",
"this",
".",
"port",
"=",
"options",
".",
"port",
"||",
"9999",
";",
"this",
".",
"application",
"=",
"options",
".",
"appName",
"||",
"process",
".",
"title",
";",
"this",
".",
"pid",
"=",
"options",
".",
"pid",
"||",
"process",
".",
"pid",
";",
"this",
".",
"tags",
"=",
"options",
".",
"tags",
"||",
"[",
"'bunyan'",
"]",
";",
"this",
".",
"type",
"=",
"options",
".",
"type",
";",
"this",
".",
"client",
"=",
"null",
";",
"// ssl\r",
"this",
".",
"ssl_enable",
"=",
"options",
".",
"ssl_enable",
"||",
"false",
";",
"this",
".",
"ssl_key",
"=",
"options",
".",
"ssl_key",
"||",
"''",
";",
"this",
".",
"ssl_cert",
"=",
"options",
".",
"ssl_cert",
"||",
"''",
";",
"this",
".",
"ca",
"=",
"options",
".",
"ca",
"||",
"''",
";",
"this",
".",
"ssl_passphrase",
"=",
"options",
".",
"ssl_passphrase",
"||",
"''",
";",
"this",
".",
"cbuffer_size",
"=",
"options",
".",
"cbuffer_size",
"||",
"10",
";",
"// Connection state\r",
"this",
".",
"log_queue",
"=",
"new",
"CBuffer",
"(",
"this",
".",
"cbuffer_size",
")",
";",
"this",
".",
"connected",
"=",
"false",
";",
"this",
".",
"socket",
"=",
"null",
";",
"this",
".",
"retries",
"=",
"-",
"1",
";",
"this",
".",
"max_connect_retries",
"=",
"(",
"typeof",
"options",
".",
"max_connect_retries",
"===",
"'number'",
")",
"?",
"options",
".",
"max_connect_retries",
":",
"4",
";",
"this",
".",
"retry_interval",
"=",
"options",
".",
"retry_interval",
"||",
"100",
";",
"this",
".",
"connect",
"(",
")",
";",
"}"
] | This class implements the bunyan stream contract with a stream that
sends data to logstash.
@param {objects} options The constructions options. See the constructor for details.
TODO: Improve this doc.
@constructor | [
"This",
"class",
"implements",
"the",
"bunyan",
"stream",
"contract",
"with",
"a",
"stream",
"that",
"sends",
"data",
"to",
"logstash",
"."
] | 5bdc950113df6306ebfa7a7916a450915422f0ac | https://github.com/maidol/cw-logger/blob/5bdc950113df6306ebfa7a7916a450915422f0ac/logstash/tcp-bunyan.js#L40-L75 |
54,707 | docvy/plugin-installer | lib/installer.js | npmInstall | function npmInstall(packages, callback) {
callback = utils.defineCallback(callback);
if (_.isString(packages)) {
packages = [ packages ];
}
return npm.load({
loglevel: "silent",
prefix: tmpDir,
}, function(loadErr) {
if (loadErr) {
return callback(new errors.NpmLoadError(loadErr));
}
npm.commands.install(packages, function(installErr) {
if (installErr) {
return callback(new errors.NpmInstallError(installErr));
}
ncp(tmpDir + "/node_modules/", pluginsDir, function(copyError) {
if (copyError) {
return callback(new errors.PluginsMoveFromTempError(copyError));
}
return callback(null);
}); // ncp
}); // npm.commands.install
}); // npm.load
} | javascript | function npmInstall(packages, callback) {
callback = utils.defineCallback(callback);
if (_.isString(packages)) {
packages = [ packages ];
}
return npm.load({
loglevel: "silent",
prefix: tmpDir,
}, function(loadErr) {
if (loadErr) {
return callback(new errors.NpmLoadError(loadErr));
}
npm.commands.install(packages, function(installErr) {
if (installErr) {
return callback(new errors.NpmInstallError(installErr));
}
ncp(tmpDir + "/node_modules/", pluginsDir, function(copyError) {
if (copyError) {
return callback(new errors.PluginsMoveFromTempError(copyError));
}
return callback(null);
}); // ncp
}); // npm.commands.install
}); // npm.load
} | [
"function",
"npmInstall",
"(",
"packages",
",",
"callback",
")",
"{",
"callback",
"=",
"utils",
".",
"defineCallback",
"(",
"callback",
")",
";",
"if",
"(",
"_",
".",
"isString",
"(",
"packages",
")",
")",
"{",
"packages",
"=",
"[",
"packages",
"]",
";",
"}",
"return",
"npm",
".",
"load",
"(",
"{",
"loglevel",
":",
"\"silent\"",
",",
"prefix",
":",
"tmpDir",
",",
"}",
",",
"function",
"(",
"loadErr",
")",
"{",
"if",
"(",
"loadErr",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"NpmLoadError",
"(",
"loadErr",
")",
")",
";",
"}",
"npm",
".",
"commands",
".",
"install",
"(",
"packages",
",",
"function",
"(",
"installErr",
")",
"{",
"if",
"(",
"installErr",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"NpmInstallError",
"(",
"installErr",
")",
")",
";",
"}",
"ncp",
"(",
"tmpDir",
"+",
"\"/node_modules/\"",
",",
"pluginsDir",
",",
"function",
"(",
"copyError",
")",
"{",
"if",
"(",
"copyError",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"PluginsMoveFromTempError",
"(",
"copyError",
")",
")",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"// ncp",
"}",
")",
";",
"// npm.commands.install",
"}",
")",
";",
"// npm.load",
"}"
] | Install plugins using NPM
@param {String|String[]} packages - name of packages
@param {Function} [callback] | [
"Install",
"plugins",
"using",
"NPM"
] | eb645eb21f350a0fbbf783d83b25ab18feeee684 | https://github.com/docvy/plugin-installer/blob/eb645eb21f350a0fbbf783d83b25ab18feeee684/lib/installer.js#L50-L74 |
54,708 | docvy/plugin-installer | lib/installer.js | dirInstall | function dirInstall(dirpath, callback) {
callback = utils.defineCallback(callback);
return fs.exists(dirpath, function(exists) {
if (!exists) {
return callback(new errors.DirectoryNotExistingError());
}
var pluginName = path.basename(dirpath);
var destPath = path.join(pluginsDir, pluginName);
return ncp(dirpath, destPath, function(copyError) {
if (copyError) {
return callback(new errors.PluginsMoveFromTempError(copyError));
}
return callback(null);
});
});
} | javascript | function dirInstall(dirpath, callback) {
callback = utils.defineCallback(callback);
return fs.exists(dirpath, function(exists) {
if (!exists) {
return callback(new errors.DirectoryNotExistingError());
}
var pluginName = path.basename(dirpath);
var destPath = path.join(pluginsDir, pluginName);
return ncp(dirpath, destPath, function(copyError) {
if (copyError) {
return callback(new errors.PluginsMoveFromTempError(copyError));
}
return callback(null);
});
});
} | [
"function",
"dirInstall",
"(",
"dirpath",
",",
"callback",
")",
"{",
"callback",
"=",
"utils",
".",
"defineCallback",
"(",
"callback",
")",
";",
"return",
"fs",
".",
"exists",
"(",
"dirpath",
",",
"function",
"(",
"exists",
")",
"{",
"if",
"(",
"!",
"exists",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"DirectoryNotExistingError",
"(",
")",
")",
";",
"}",
"var",
"pluginName",
"=",
"path",
".",
"basename",
"(",
"dirpath",
")",
";",
"var",
"destPath",
"=",
"path",
".",
"join",
"(",
"pluginsDir",
",",
"pluginName",
")",
";",
"return",
"ncp",
"(",
"dirpath",
",",
"destPath",
",",
"function",
"(",
"copyError",
")",
"{",
"if",
"(",
"copyError",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"PluginsMoveFromTempError",
"(",
"copyError",
")",
")",
";",
"}",
"return",
"callback",
"(",
"null",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Install plugins from Directory
@param {String} dirpath - path to directory
@param {Function} [callback] | [
"Install",
"plugins",
"from",
"Directory"
] | eb645eb21f350a0fbbf783d83b25ab18feeee684 | https://github.com/docvy/plugin-installer/blob/eb645eb21f350a0fbbf783d83b25ab18feeee684/lib/installer.js#L83-L98 |
54,709 | docvy/plugin-installer | lib/installer.js | listPlugins | function listPlugins(callback) {
callback = utils.defineCallback(callback);
return fs.readdir(pluginsDir, function(readdirErr, files) {
if (readdirErr) {
return callback(new errors.PluginsListingError(readdirErr));
}
var fullpath, pkg;
var descriptors = [ ];
files.forEach(function (file) {
fullpath = path.join(pluginsDir, file, "package.json");
try {
pkg = require(fullpath);
descriptors.push({
name: pkg.name,
version: pkg.version || "",
description: pkg.description || "",
author: pkg.author || "",
icon: pkg.icon || "",
homepage: pkg.homepage || "",
});
} catch (requireErr) {
/*
* we shall ignore this error and only list those plugins
* we can load
*/
}
});
return callback(null, descriptors);
});
} | javascript | function listPlugins(callback) {
callback = utils.defineCallback(callback);
return fs.readdir(pluginsDir, function(readdirErr, files) {
if (readdirErr) {
return callback(new errors.PluginsListingError(readdirErr));
}
var fullpath, pkg;
var descriptors = [ ];
files.forEach(function (file) {
fullpath = path.join(pluginsDir, file, "package.json");
try {
pkg = require(fullpath);
descriptors.push({
name: pkg.name,
version: pkg.version || "",
description: pkg.description || "",
author: pkg.author || "",
icon: pkg.icon || "",
homepage: pkg.homepage || "",
});
} catch (requireErr) {
/*
* we shall ignore this error and only list those plugins
* we can load
*/
}
});
return callback(null, descriptors);
});
} | [
"function",
"listPlugins",
"(",
"callback",
")",
"{",
"callback",
"=",
"utils",
".",
"defineCallback",
"(",
"callback",
")",
";",
"return",
"fs",
".",
"readdir",
"(",
"pluginsDir",
",",
"function",
"(",
"readdirErr",
",",
"files",
")",
"{",
"if",
"(",
"readdirErr",
")",
"{",
"return",
"callback",
"(",
"new",
"errors",
".",
"PluginsListingError",
"(",
"readdirErr",
")",
")",
";",
"}",
"var",
"fullpath",
",",
"pkg",
";",
"var",
"descriptors",
"=",
"[",
"]",
";",
"files",
".",
"forEach",
"(",
"function",
"(",
"file",
")",
"{",
"fullpath",
"=",
"path",
".",
"join",
"(",
"pluginsDir",
",",
"file",
",",
"\"package.json\"",
")",
";",
"try",
"{",
"pkg",
"=",
"require",
"(",
"fullpath",
")",
";",
"descriptors",
".",
"push",
"(",
"{",
"name",
":",
"pkg",
".",
"name",
",",
"version",
":",
"pkg",
".",
"version",
"||",
"\"\"",
",",
"description",
":",
"pkg",
".",
"description",
"||",
"\"\"",
",",
"author",
":",
"pkg",
".",
"author",
"||",
"\"\"",
",",
"icon",
":",
"pkg",
".",
"icon",
"||",
"\"\"",
",",
"homepage",
":",
"pkg",
".",
"homepage",
"||",
"\"\"",
",",
"}",
")",
";",
"}",
"catch",
"(",
"requireErr",
")",
"{",
"/*\n * we shall ignore this error and only list those plugins\n * we can load\n */",
"}",
"}",
")",
";",
"return",
"callback",
"(",
"null",
",",
"descriptors",
")",
";",
"}",
")",
";",
"}"
] | Listing installed plugins
@param {Function} [callback] - callback(err, descriptors) | [
"Listing",
"installed",
"plugins"
] | eb645eb21f350a0fbbf783d83b25ab18feeee684 | https://github.com/docvy/plugin-installer/blob/eb645eb21f350a0fbbf783d83b25ab18feeee684/lib/installer.js#L106-L135 |
54,710 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/list/plugin.js | inheirtInlineStyles | function inheirtInlineStyles( parent, el ) {
var style = parent.getAttribute( 'style' );
// Put parent styles before child styles.
style && el.setAttribute( 'style', style.replace( /([^;])$/, '$1;' ) + ( el.getAttribute( 'style' ) || '' ) );
} | javascript | function inheirtInlineStyles( parent, el ) {
var style = parent.getAttribute( 'style' );
// Put parent styles before child styles.
style && el.setAttribute( 'style', style.replace( /([^;])$/, '$1;' ) + ( el.getAttribute( 'style' ) || '' ) );
} | [
"function",
"inheirtInlineStyles",
"(",
"parent",
",",
"el",
")",
"{",
"var",
"style",
"=",
"parent",
".",
"getAttribute",
"(",
"'style'",
")",
";",
"// Put parent styles before child styles.\r",
"style",
"&&",
"el",
".",
"setAttribute",
"(",
"'style'",
",",
"style",
".",
"replace",
"(",
"/",
"([^;])$",
"/",
",",
"'$1;'",
")",
"+",
"(",
"el",
".",
"getAttribute",
"(",
"'style'",
")",
"||",
"''",
")",
")",
";",
"}"
] | Inheirt inline styles from another element. | [
"Inheirt",
"inline",
"styles",
"from",
"another",
"element",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/list/plugin.js#L34-L39 |
54,711 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/list/plugin.js | mergeListSiblings | function mergeListSiblings( listNode )
{
var mergeSibling;
( mergeSibling = function( rtl )
{
var sibling = listNode[ rtl ? 'getPrevious' : 'getNext' ]( nonEmpty );
if ( sibling &&
sibling.type == CKEDITOR.NODE_ELEMENT &&
sibling.is( listNode.getName() ) )
{
// Move children order by merge direction.(#3820)
mergeChildren( listNode, sibling, null, !rtl );
listNode.remove();
listNode = sibling;
}
} )();
mergeSibling( 1 );
} | javascript | function mergeListSiblings( listNode )
{
var mergeSibling;
( mergeSibling = function( rtl )
{
var sibling = listNode[ rtl ? 'getPrevious' : 'getNext' ]( nonEmpty );
if ( sibling &&
sibling.type == CKEDITOR.NODE_ELEMENT &&
sibling.is( listNode.getName() ) )
{
// Move children order by merge direction.(#3820)
mergeChildren( listNode, sibling, null, !rtl );
listNode.remove();
listNode = sibling;
}
} )();
mergeSibling( 1 );
} | [
"function",
"mergeListSiblings",
"(",
"listNode",
")",
"{",
"var",
"mergeSibling",
";",
"(",
"mergeSibling",
"=",
"function",
"(",
"rtl",
")",
"{",
"var",
"sibling",
"=",
"listNode",
"[",
"rtl",
"?",
"'getPrevious'",
":",
"'getNext'",
"]",
"(",
"nonEmpty",
")",
";",
"if",
"(",
"sibling",
"&&",
"sibling",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
"&&",
"sibling",
".",
"is",
"(",
"listNode",
".",
"getName",
"(",
")",
")",
")",
"{",
"// Move children order by merge direction.(#3820)\r",
"mergeChildren",
"(",
"listNode",
",",
"sibling",
",",
"null",
",",
"!",
"rtl",
")",
";",
"listNode",
".",
"remove",
"(",
")",
";",
"listNode",
"=",
"sibling",
";",
"}",
"}",
")",
"(",
")",
";",
"mergeSibling",
"(",
"1",
")",
";",
"}"
] | Merge list adjacent, of same type lists. | [
"Merge",
"list",
"adjacent",
"of",
"same",
"type",
"lists",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/list/plugin.js#L680-L698 |
54,712 | skerit/alchemy-styleboost | public/ckeditor/4.4dev/plugins/list/plugin.js | isTextBlock | function isTextBlock( node ) {
return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in CKEDITOR.dtd.$block || node.getName() in CKEDITOR.dtd.$listItem ) && CKEDITOR.dtd[ node.getName() ][ '#' ];
} | javascript | function isTextBlock( node ) {
return node.type == CKEDITOR.NODE_ELEMENT && ( node.getName() in CKEDITOR.dtd.$block || node.getName() in CKEDITOR.dtd.$listItem ) && CKEDITOR.dtd[ node.getName() ][ '#' ];
} | [
"function",
"isTextBlock",
"(",
"node",
")",
"{",
"return",
"node",
".",
"type",
"==",
"CKEDITOR",
".",
"NODE_ELEMENT",
"&&",
"(",
"node",
".",
"getName",
"(",
")",
"in",
"CKEDITOR",
".",
"dtd",
".",
"$block",
"||",
"node",
".",
"getName",
"(",
")",
"in",
"CKEDITOR",
".",
"dtd",
".",
"$listItem",
")",
"&&",
"CKEDITOR",
".",
"dtd",
"[",
"node",
".",
"getName",
"(",
")",
"]",
"[",
"'#'",
"]",
";",
"}"
] | Check if node is block element that recieves text. | [
"Check",
"if",
"node",
"is",
"block",
"element",
"that",
"recieves",
"text",
"."
] | 2b90b8a6afc9f065f785651292fb193940021d90 | https://github.com/skerit/alchemy-styleboost/blob/2b90b8a6afc9f065f785651292fb193940021d90/public/ckeditor/4.4dev/plugins/list/plugin.js#L715-L717 |
54,713 | activethread/vulpejs | lib/routes/index.js | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'SAVE';
options.res = res;
if (req.params.model) {
options.model = req.params.model;
}
if (req.body) {
options.item = req.body;
}
if (req.params.data) {
options.data = req.params.data;
}
exports.save.before(req, res, options);
var userId = req.session['user-id'];
vulpejs.models.save({
model: options.model,
item: options.item,
data: options.data,
validate: options.validate || false,
userId: userId,
callback: {
success: function (item) {
if (!vulpejs.utils.execute(options.callback, {
item: item,
postedItem: options.item,
res: res,
})) {
exports.save.after(req, res, item);
res.json({
item: item,
postedItem: options.item,
});
}
},
error: function (error) {
exports.response.error(options, error);
},
validate: function (validate) {
exports.response.validate(options, validate);
},
},
});
} | javascript | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'SAVE';
options.res = res;
if (req.params.model) {
options.model = req.params.model;
}
if (req.body) {
options.item = req.body;
}
if (req.params.data) {
options.data = req.params.data;
}
exports.save.before(req, res, options);
var userId = req.session['user-id'];
vulpejs.models.save({
model: options.model,
item: options.item,
data: options.data,
validate: options.validate || false,
userId: userId,
callback: {
success: function (item) {
if (!vulpejs.utils.execute(options.callback, {
item: item,
postedItem: options.item,
res: res,
})) {
exports.save.after(req, res, item);
res.json({
item: item,
postedItem: options.item,
});
}
},
error: function (error) {
exports.response.error(options, error);
},
validate: function (validate) {
exports.response.validate(options, validate);
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"operation",
"=",
"'SAVE'",
";",
"options",
".",
"res",
"=",
"res",
";",
"if",
"(",
"req",
".",
"params",
".",
"model",
")",
"{",
"options",
".",
"model",
"=",
"req",
".",
"params",
".",
"model",
";",
"}",
"if",
"(",
"req",
".",
"body",
")",
"{",
"options",
".",
"item",
"=",
"req",
".",
"body",
";",
"}",
"if",
"(",
"req",
".",
"params",
".",
"data",
")",
"{",
"options",
".",
"data",
"=",
"req",
".",
"params",
".",
"data",
";",
"}",
"exports",
".",
"save",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"var",
"userId",
"=",
"req",
".",
"session",
"[",
"'user-id'",
"]",
";",
"vulpejs",
".",
"models",
".",
"save",
"(",
"{",
"model",
":",
"options",
".",
"model",
",",
"item",
":",
"options",
".",
"item",
",",
"data",
":",
"options",
".",
"data",
",",
"validate",
":",
"options",
".",
"validate",
"||",
"false",
",",
"userId",
":",
"userId",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"vulpejs",
".",
"utils",
".",
"execute",
"(",
"options",
".",
"callback",
",",
"{",
"item",
":",
"item",
",",
"postedItem",
":",
"options",
".",
"item",
",",
"res",
":",
"res",
",",
"}",
")",
")",
"{",
"exports",
".",
"save",
".",
"after",
"(",
"req",
",",
"res",
",",
"item",
")",
";",
"res",
".",
"json",
"(",
"{",
"item",
":",
"item",
",",
"postedItem",
":",
"options",
".",
"item",
",",
"}",
")",
";",
"}",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"validate",
":",
"function",
"(",
"validate",
")",
"{",
"exports",
".",
"response",
".",
"validate",
"(",
"options",
",",
"validate",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | Save object in database.
@param {Object} req Request
@param {Object} res Response
@param {Object} options {model, data, callback} | [
"Save",
"object",
"in",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L212-L257 |
|
54,714 | activethread/vulpejs | lib/routes/index.js | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'REMOVE';
options.res = res;
if (!options) {
options = {};
}
if (req.params.model) {
options.model = req.params.model;
}
if (req.params.query) {
options.query = req.params.query;
}
if (req.params.id) {
options.query = {
_id: req.params.id,
};
}
exports.remove.before(req, res, options);
var userId = req.session['user-id'];
vulpejs.models.remove({
model: options.model,
item: {
_id: req.params.id,
},
query: options.query,
validate: options.validate || false,
userId: userId,
callback: {
success: function (item) {
if (!vulpejs.utils.execute(options.callback, {
item: item,
res: res,
})) {
exports.remove.after(req, res, item);
res.json({
item: item,
});
}
},
error: function (error) {
exports.response.error(options, error);
},
validate: function (validate) {
exports.response.validate(options, validate);
},
},
});
} | javascript | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'REMOVE';
options.res = res;
if (!options) {
options = {};
}
if (req.params.model) {
options.model = req.params.model;
}
if (req.params.query) {
options.query = req.params.query;
}
if (req.params.id) {
options.query = {
_id: req.params.id,
};
}
exports.remove.before(req, res, options);
var userId = req.session['user-id'];
vulpejs.models.remove({
model: options.model,
item: {
_id: req.params.id,
},
query: options.query,
validate: options.validate || false,
userId: userId,
callback: {
success: function (item) {
if (!vulpejs.utils.execute(options.callback, {
item: item,
res: res,
})) {
exports.remove.after(req, res, item);
res.json({
item: item,
});
}
},
error: function (error) {
exports.response.error(options, error);
},
validate: function (validate) {
exports.response.validate(options, validate);
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"operation",
"=",
"'REMOVE'",
";",
"options",
".",
"res",
"=",
"res",
";",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"if",
"(",
"req",
".",
"params",
".",
"model",
")",
"{",
"options",
".",
"model",
"=",
"req",
".",
"params",
".",
"model",
";",
"}",
"if",
"(",
"req",
".",
"params",
".",
"query",
")",
"{",
"options",
".",
"query",
"=",
"req",
".",
"params",
".",
"query",
";",
"}",
"if",
"(",
"req",
".",
"params",
".",
"id",
")",
"{",
"options",
".",
"query",
"=",
"{",
"_id",
":",
"req",
".",
"params",
".",
"id",
",",
"}",
";",
"}",
"exports",
".",
"remove",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"var",
"userId",
"=",
"req",
".",
"session",
"[",
"'user-id'",
"]",
";",
"vulpejs",
".",
"models",
".",
"remove",
"(",
"{",
"model",
":",
"options",
".",
"model",
",",
"item",
":",
"{",
"_id",
":",
"req",
".",
"params",
".",
"id",
",",
"}",
",",
"query",
":",
"options",
".",
"query",
",",
"validate",
":",
"options",
".",
"validate",
"||",
"false",
",",
"userId",
":",
"userId",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"item",
")",
"{",
"if",
"(",
"!",
"vulpejs",
".",
"utils",
".",
"execute",
"(",
"options",
".",
"callback",
",",
"{",
"item",
":",
"item",
",",
"res",
":",
"res",
",",
"}",
")",
")",
"{",
"exports",
".",
"remove",
".",
"after",
"(",
"req",
",",
"res",
",",
"item",
")",
";",
"res",
".",
"json",
"(",
"{",
"item",
":",
"item",
",",
"}",
")",
";",
"}",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"validate",
":",
"function",
"(",
"validate",
")",
"{",
"exports",
".",
"response",
".",
"validate",
"(",
"options",
",",
"validate",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | Remove object from database by id and callback if success.
@param {Object} req Request
@param {Object} res Response
@param {Object} options {model, id, callback} | [
"Remove",
"object",
"from",
"database",
"by",
"id",
"and",
"callback",
"if",
"success",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L269-L319 |
|
54,715 | activethread/vulpejs | lib/routes/index.js | function (req, res) {
var options = {
operation: 'LIST',
res: res,
};
exports.list.before(req, res, options);
vulpejs.models.list({
model: req.params.model,
query: req.params.query || {},
populate: req.params.populate || '',
sort: req.params.sort || {},
userId: req.session['user-id'],
callback: {
success: function (items) {
exports.list.after(req, res, items);
res.json({
items: items,
});
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | javascript | function (req, res) {
var options = {
operation: 'LIST',
res: res,
};
exports.list.before(req, res, options);
vulpejs.models.list({
model: req.params.model,
query: req.params.query || {},
populate: req.params.populate || '',
sort: req.params.sort || {},
userId: req.session['user-id'],
callback: {
success: function (items) {
exports.list.after(req, res, items);
res.json({
items: items,
});
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"var",
"options",
"=",
"{",
"operation",
":",
"'LIST'",
",",
"res",
":",
"res",
",",
"}",
";",
"exports",
".",
"list",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"vulpejs",
".",
"models",
".",
"list",
"(",
"{",
"model",
":",
"req",
".",
"params",
".",
"model",
",",
"query",
":",
"req",
".",
"params",
".",
"query",
"||",
"{",
"}",
",",
"populate",
":",
"req",
".",
"params",
".",
"populate",
"||",
"''",
",",
"sort",
":",
"req",
".",
"params",
".",
"sort",
"||",
"{",
"}",
",",
"userId",
":",
"req",
".",
"session",
"[",
"'user-id'",
"]",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"items",
")",
"{",
"exports",
".",
"list",
".",
"after",
"(",
"req",
",",
"res",
",",
"items",
")",
";",
"res",
".",
"json",
"(",
"{",
"items",
":",
"items",
",",
"}",
")",
";",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | List from database.
@param {Object} req Request
@param {Object} res Response | [
"List",
"from",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L330-L354 |
|
54,716 | activethread/vulpejs | lib/routes/index.js | function (req, res) {
var options = {
operation: 'PAGINATE',
res: res,
};
exports.paginate.before(req, res, options);
vulpejs.models.paginate({
model: req.params.model,
query: req.params.query || {},
populate: req.params.populate || '',
sort: req.params.sort || {},
page: req.params.page || 1,
userId: req.session['user-id'],
callback: {
success: function (data) {
exports.paginate.after(req, res, data);
res.json({
items: data.items,
pageCount: data.pageCount,
itemCount: data.itemCount,
});
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | javascript | function (req, res) {
var options = {
operation: 'PAGINATE',
res: res,
};
exports.paginate.before(req, res, options);
vulpejs.models.paginate({
model: req.params.model,
query: req.params.query || {},
populate: req.params.populate || '',
sort: req.params.sort || {},
page: req.params.page || 1,
userId: req.session['user-id'],
callback: {
success: function (data) {
exports.paginate.after(req, res, data);
res.json({
items: data.items,
pageCount: data.pageCount,
itemCount: data.itemCount,
});
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"var",
"options",
"=",
"{",
"operation",
":",
"'PAGINATE'",
",",
"res",
":",
"res",
",",
"}",
";",
"exports",
".",
"paginate",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"vulpejs",
".",
"models",
".",
"paginate",
"(",
"{",
"model",
":",
"req",
".",
"params",
".",
"model",
",",
"query",
":",
"req",
".",
"params",
".",
"query",
"||",
"{",
"}",
",",
"populate",
":",
"req",
".",
"params",
".",
"populate",
"||",
"''",
",",
"sort",
":",
"req",
".",
"params",
".",
"sort",
"||",
"{",
"}",
",",
"page",
":",
"req",
".",
"params",
".",
"page",
"||",
"1",
",",
"userId",
":",
"req",
".",
"session",
"[",
"'user-id'",
"]",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"data",
")",
"{",
"exports",
".",
"paginate",
".",
"after",
"(",
"req",
",",
"res",
",",
"data",
")",
";",
"res",
".",
"json",
"(",
"{",
"items",
":",
"data",
".",
"items",
",",
"pageCount",
":",
"data",
".",
"pageCount",
",",
"itemCount",
":",
"data",
".",
"itemCount",
",",
"}",
")",
";",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | Paginate list from database.
@param {Object} req Request
@param {Object} res Response | [
"Paginate",
"list",
"from",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L365-L392 |
|
54,717 | activethread/vulpejs | lib/routes/index.js | function (req, res) {
var options = {
operation: 'DISTINCT',
res: res,
};
exports.distinct.before(req, res, options);
vulpejs.models.distinct({
model: req.params.model,
query: req.params.query || {},
sort: req.params.sort || false,
array: req.params.array || false,
callback: {
success: function (items) {
exports.distinct.after(req, res, items);
res.json(items);
},
error: function (error) {
vulpejs.log.error('DISTINCT', error);
res.status(500).end();
},
},
});
} | javascript | function (req, res) {
var options = {
operation: 'DISTINCT',
res: res,
};
exports.distinct.before(req, res, options);
vulpejs.models.distinct({
model: req.params.model,
query: req.params.query || {},
sort: req.params.sort || false,
array: req.params.array || false,
callback: {
success: function (items) {
exports.distinct.after(req, res, items);
res.json(items);
},
error: function (error) {
vulpejs.log.error('DISTINCT', error);
res.status(500).end();
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"var",
"options",
"=",
"{",
"operation",
":",
"'DISTINCT'",
",",
"res",
":",
"res",
",",
"}",
";",
"exports",
".",
"distinct",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"vulpejs",
".",
"models",
".",
"distinct",
"(",
"{",
"model",
":",
"req",
".",
"params",
".",
"model",
",",
"query",
":",
"req",
".",
"params",
".",
"query",
"||",
"{",
"}",
",",
"sort",
":",
"req",
".",
"params",
".",
"sort",
"||",
"false",
",",
"array",
":",
"req",
".",
"params",
".",
"array",
"||",
"false",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"items",
")",
"{",
"exports",
".",
"distinct",
".",
"after",
"(",
"req",
",",
"res",
",",
"items",
")",
";",
"res",
".",
"json",
"(",
"items",
")",
";",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"vulpejs",
".",
"log",
".",
"error",
"(",
"'DISTINCT'",
",",
"error",
")",
";",
"res",
".",
"status",
"(",
"500",
")",
".",
"end",
"(",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | Retrive distinct list of objects from database.
@param {Object} req Request
@param {Object} res Response | [
"Retrive",
"distinct",
"list",
"of",
"objects",
"from",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L403-L425 |
|
54,718 | activethread/vulpejs | lib/routes/index.js | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'FIND';
options.res = res;
exports.find.before(req, res, options);
vulpejs.models.find({
model: req.params.model,
populate: req.params.populate,
history: true,
id: req.params.id || false,
query: req.params.query || {
_id: req.params.id,
},
callback: {
success: function (data) {
exports.find.after(req, res, data);
if (options && options.callback) {
vulpejs.utils.execute(options.callback, {
item: data.item,
history: data.history,
res: res,
});
} else {
res.json(data);
}
},
error: function (error) {
exports.response.error(options, error);
},
},
})
} | javascript | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'FIND';
options.res = res;
exports.find.before(req, res, options);
vulpejs.models.find({
model: req.params.model,
populate: req.params.populate,
history: true,
id: req.params.id || false,
query: req.params.query || {
_id: req.params.id,
},
callback: {
success: function (data) {
exports.find.after(req, res, data);
if (options && options.callback) {
vulpejs.utils.execute(options.callback, {
item: data.item,
history: data.history,
res: res,
});
} else {
res.json(data);
}
},
error: function (error) {
exports.response.error(options, error);
},
},
})
} | [
"function",
"(",
"req",
",",
"res",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"operation",
"=",
"'FIND'",
";",
"options",
".",
"res",
"=",
"res",
";",
"exports",
".",
"find",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"vulpejs",
".",
"models",
".",
"find",
"(",
"{",
"model",
":",
"req",
".",
"params",
".",
"model",
",",
"populate",
":",
"req",
".",
"params",
".",
"populate",
",",
"history",
":",
"true",
",",
"id",
":",
"req",
".",
"params",
".",
"id",
"||",
"false",
",",
"query",
":",
"req",
".",
"params",
".",
"query",
"||",
"{",
"_id",
":",
"req",
".",
"params",
".",
"id",
",",
"}",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"data",
")",
"{",
"exports",
".",
"find",
".",
"after",
"(",
"req",
",",
"res",
",",
"data",
")",
";",
"if",
"(",
"options",
"&&",
"options",
".",
"callback",
")",
"{",
"vulpejs",
".",
"utils",
".",
"execute",
"(",
"options",
".",
"callback",
",",
"{",
"item",
":",
"data",
".",
"item",
",",
"history",
":",
"data",
".",
"history",
",",
"res",
":",
"res",
",",
"}",
")",
";",
"}",
"else",
"{",
"res",
".",
"json",
"(",
"data",
")",
";",
"}",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"}",
",",
"}",
")",
"}"
] | Find object in database.
@param {Object} req Request
@param {Object} res Response
@param {Object} options {model, populate, callback} | [
"Find",
"object",
"in",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L437-L470 |
|
54,719 | activethread/vulpejs | lib/routes/index.js | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'STATUS';
options.res = res;
exports.status.before(req, res, options);
vulpejs.models.status({
model: req.params.model,
data: req.body,
callback: {
success: function (item) {
exports.status.after(req, res, item);
if (options && options.callback) {
vulpejs.utils.execute(options.callback, item);
} else {
exports.response.success(options);
}
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | javascript | function (req, res, options) {
if (!options) {
options = {};
}
options.operation = 'STATUS';
options.res = res;
exports.status.before(req, res, options);
vulpejs.models.status({
model: req.params.model,
data: req.body,
callback: {
success: function (item) {
exports.status.after(req, res, item);
if (options && options.callback) {
vulpejs.utils.execute(options.callback, item);
} else {
exports.response.success(options);
}
},
error: function (error) {
exports.response.error(options, error);
},
},
});
} | [
"function",
"(",
"req",
",",
"res",
",",
"options",
")",
"{",
"if",
"(",
"!",
"options",
")",
"{",
"options",
"=",
"{",
"}",
";",
"}",
"options",
".",
"operation",
"=",
"'STATUS'",
";",
"options",
".",
"res",
"=",
"res",
";",
"exports",
".",
"status",
".",
"before",
"(",
"req",
",",
"res",
",",
"options",
")",
";",
"vulpejs",
".",
"models",
".",
"status",
"(",
"{",
"model",
":",
"req",
".",
"params",
".",
"model",
",",
"data",
":",
"req",
".",
"body",
",",
"callback",
":",
"{",
"success",
":",
"function",
"(",
"item",
")",
"{",
"exports",
".",
"status",
".",
"after",
"(",
"req",
",",
"res",
",",
"item",
")",
";",
"if",
"(",
"options",
"&&",
"options",
".",
"callback",
")",
"{",
"vulpejs",
".",
"utils",
".",
"execute",
"(",
"options",
".",
"callback",
",",
"item",
")",
";",
"}",
"else",
"{",
"exports",
".",
"response",
".",
"success",
"(",
"options",
")",
";",
"}",
"}",
",",
"error",
":",
"function",
"(",
"error",
")",
"{",
"exports",
".",
"response",
".",
"error",
"(",
"options",
",",
"error",
")",
";",
"}",
",",
"}",
",",
"}",
")",
";",
"}"
] | Change status of object in database.
@param {Object} req Request
@param {Object} res Response
@param {Object} options {model, callback} | [
"Change",
"status",
"of",
"object",
"in",
"database",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L550-L574 |
|
54,720 | activethread/vulpejs | lib/routes/index.js | function (configObject) {
if (typeof configObject !== 'undefined') {
configuration.directory = configObject.directory || configuration.directory;
configuration.extension = configObject.extension || configuration.extension;
configuration.objectNotation = configObject.objectNotation || configuration.objectNotation;
}
// Register routes
var uri = vulpejs.app.root.context + '/i18n/:locale';
vulpejs.express.app.get(uri, i18nRoutes.i18n);
vulpejs.express.app.get(uri + '/:phrase', i18nRoutes.translate);
} | javascript | function (configObject) {
if (typeof configObject !== 'undefined') {
configuration.directory = configObject.directory || configuration.directory;
configuration.extension = configObject.extension || configuration.extension;
configuration.objectNotation = configObject.objectNotation || configuration.objectNotation;
}
// Register routes
var uri = vulpejs.app.root.context + '/i18n/:locale';
vulpejs.express.app.get(uri, i18nRoutes.i18n);
vulpejs.express.app.get(uri + '/:phrase', i18nRoutes.translate);
} | [
"function",
"(",
"configObject",
")",
"{",
"if",
"(",
"typeof",
"configObject",
"!==",
"'undefined'",
")",
"{",
"configuration",
".",
"directory",
"=",
"configObject",
".",
"directory",
"||",
"configuration",
".",
"directory",
";",
"configuration",
".",
"extension",
"=",
"configObject",
".",
"extension",
"||",
"configuration",
".",
"extension",
";",
"configuration",
".",
"objectNotation",
"=",
"configObject",
".",
"objectNotation",
"||",
"configuration",
".",
"objectNotation",
";",
"}",
"// Register routes",
"var",
"uri",
"=",
"vulpejs",
".",
"app",
".",
"root",
".",
"context",
"+",
"'/i18n/:locale'",
";",
"vulpejs",
".",
"express",
".",
"app",
".",
"get",
"(",
"uri",
",",
"i18nRoutes",
".",
"i18n",
")",
";",
"vulpejs",
".",
"express",
".",
"app",
".",
"get",
"(",
"uri",
"+",
"'/:phrase'",
",",
"i18nRoutes",
".",
"translate",
")",
";",
"}"
] | Configure the express routes through which translations are served.
@param app
@param {Object} [configObject] | [
"Configure",
"the",
"express",
"routes",
"through",
"which",
"translations",
"are",
"served",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L1117-L1128 |
|
54,721 | activethread/vulpejs | lib/routes/index.js | function (request, response, next) {
response.locals.i18n = {
getLocale: function () {
return request.cookies.appLanguage || vulpejs.i18n.getLocale.apply(request, arguments);
},
};
// For backwards compatibility, also define 'acceptedLanguage'.
response.locals.acceptedLanguage = response.locals.i18n.getLocale;
if (typeof next !== 'undefined') {
next();
}
} | javascript | function (request, response, next) {
response.locals.i18n = {
getLocale: function () {
return request.cookies.appLanguage || vulpejs.i18n.getLocale.apply(request, arguments);
},
};
// For backwards compatibility, also define 'acceptedLanguage'.
response.locals.acceptedLanguage = response.locals.i18n.getLocale;
if (typeof next !== 'undefined') {
next();
}
} | [
"function",
"(",
"request",
",",
"response",
",",
"next",
")",
"{",
"response",
".",
"locals",
".",
"i18n",
"=",
"{",
"getLocale",
":",
"function",
"(",
")",
"{",
"return",
"request",
".",
"cookies",
".",
"appLanguage",
"||",
"vulpejs",
".",
"i18n",
".",
"getLocale",
".",
"apply",
"(",
"request",
",",
"arguments",
")",
";",
"}",
",",
"}",
";",
"// For backwards compatibility, also define 'acceptedLanguage'.",
"response",
".",
"locals",
".",
"acceptedLanguage",
"=",
"response",
".",
"locals",
".",
"i18n",
".",
"getLocale",
";",
"if",
"(",
"typeof",
"next",
"!==",
"'undefined'",
")",
"{",
"next",
"(",
")",
";",
"}",
"}"
] | Middleware to allow retrieval of users locale in the template engine.
@param {Object} request
@param {Object} response
@param {Function} [next] | [
"Middleware",
"to",
"allow",
"retrieval",
"of",
"users",
"locale",
"in",
"the",
"template",
"engine",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L1136-L1149 |
|
54,722 | activethread/vulpejs | lib/routes/index.js | function (request, response) {
var locale = request.params.locale;
var sendFile = response.sendFile || response.sendfile;
sendFile.apply(response, [path.join(configuration.directory, locale + configuration.extension)]);
} | javascript | function (request, response) {
var locale = request.params.locale;
var sendFile = response.sendFile || response.sendfile;
sendFile.apply(response, [path.join(configuration.directory, locale + configuration.extension)]);
} | [
"function",
"(",
"request",
",",
"response",
")",
"{",
"var",
"locale",
"=",
"request",
".",
"params",
".",
"locale",
";",
"var",
"sendFile",
"=",
"response",
".",
"sendFile",
"||",
"response",
".",
"sendfile",
";",
"sendFile",
".",
"apply",
"(",
"response",
",",
"[",
"path",
".",
"join",
"(",
"configuration",
".",
"directory",
",",
"locale",
"+",
"configuration",
".",
"extension",
")",
"]",
")",
";",
"}"
] | Sends a translation file to the client.
@param request
@param response | [
"Sends",
"a",
"translation",
"file",
"to",
"the",
"client",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L1157-L1161 |
|
54,723 | activethread/vulpejs | lib/routes/index.js | function (request, response) {
var locale = request.params.locale;
var phrase = request.params.phrase;
var result;
if (request.query.plural) {
var singular = phrase;
var plural = request.query.plural;
// Make sure the information is added to the catalog if it doesn't exist yet.
var translated = vulpejs.i18n.__n({
singular: singular,
plural: plural,
count: request.query.count,
locale: locale,
});
// Retrieve the translation object from the catalog and return it.
var catalog = vulpejs.i18n.getCatalog(locale);
result = singular.split(configuration.objectNotation).reduce(function (object, index) {
return object[index];
}, catalog);
} else {
result = vulpejs.i18n.__({
phrase: phrase,
locale: locale,
});
}
response.send(result);
} | javascript | function (request, response) {
var locale = request.params.locale;
var phrase = request.params.phrase;
var result;
if (request.query.plural) {
var singular = phrase;
var plural = request.query.plural;
// Make sure the information is added to the catalog if it doesn't exist yet.
var translated = vulpejs.i18n.__n({
singular: singular,
plural: plural,
count: request.query.count,
locale: locale,
});
// Retrieve the translation object from the catalog and return it.
var catalog = vulpejs.i18n.getCatalog(locale);
result = singular.split(configuration.objectNotation).reduce(function (object, index) {
return object[index];
}, catalog);
} else {
result = vulpejs.i18n.__({
phrase: phrase,
locale: locale,
});
}
response.send(result);
} | [
"function",
"(",
"request",
",",
"response",
")",
"{",
"var",
"locale",
"=",
"request",
".",
"params",
".",
"locale",
";",
"var",
"phrase",
"=",
"request",
".",
"params",
".",
"phrase",
";",
"var",
"result",
";",
"if",
"(",
"request",
".",
"query",
".",
"plural",
")",
"{",
"var",
"singular",
"=",
"phrase",
";",
"var",
"plural",
"=",
"request",
".",
"query",
".",
"plural",
";",
"// Make sure the information is added to the catalog if it doesn't exist yet.",
"var",
"translated",
"=",
"vulpejs",
".",
"i18n",
".",
"__n",
"(",
"{",
"singular",
":",
"singular",
",",
"plural",
":",
"plural",
",",
"count",
":",
"request",
".",
"query",
".",
"count",
",",
"locale",
":",
"locale",
",",
"}",
")",
";",
"// Retrieve the translation object from the catalog and return it.",
"var",
"catalog",
"=",
"vulpejs",
".",
"i18n",
".",
"getCatalog",
"(",
"locale",
")",
";",
"result",
"=",
"singular",
".",
"split",
"(",
"configuration",
".",
"objectNotation",
")",
".",
"reduce",
"(",
"function",
"(",
"object",
",",
"index",
")",
"{",
"return",
"object",
"[",
"index",
"]",
";",
"}",
",",
"catalog",
")",
";",
"}",
"else",
"{",
"result",
"=",
"vulpejs",
".",
"i18n",
".",
"__",
"(",
"{",
"phrase",
":",
"phrase",
",",
"locale",
":",
"locale",
",",
"}",
")",
";",
"}",
"response",
".",
"send",
"(",
"result",
")",
";",
"}"
] | Translate a given string and provide the result.
@param request
@param response | [
"Translate",
"a",
"given",
"string",
"and",
"provide",
"the",
"result",
"."
] | cba9529ebb13892b2c7d07219c7fa69137151fbd | https://github.com/activethread/vulpejs/blob/cba9529ebb13892b2c7d07219c7fa69137151fbd/lib/routes/index.js#L1168-L1195 |
|
54,724 | byu-oit/aws-scatter-gather | bin/middleware.js | subscribe | function subscribe(topicArn) {
// validate the topic arn
if (!rxTopicArn.test(topicArn)) throw Error('Cannot subscribe to an invalid AWS Topic Arn: ' + topicArn);
// if already subscribed then return now
if (subscriptions[topicArn]) return subscriptions[topicArn].promise;
// create and store the deferred promise
const deferred = defer();
subscriptions[topicArn] = deferred;
// make the sns subscribe request
const params = {
Protocol: /^(https?):/.exec(config.endpoint)[1],
TopicArn: topicArn,
Endpoint: config.endpoint
};
config.sns.subscribe(params, function(err) {
debug('Subscription request for ' + topicArn + (err ? ' failed : ' + err.message : ' sent.'));
if (err) return deferred.reject(err);
});
return deferred.promise;
} | javascript | function subscribe(topicArn) {
// validate the topic arn
if (!rxTopicArn.test(topicArn)) throw Error('Cannot subscribe to an invalid AWS Topic Arn: ' + topicArn);
// if already subscribed then return now
if (subscriptions[topicArn]) return subscriptions[topicArn].promise;
// create and store the deferred promise
const deferred = defer();
subscriptions[topicArn] = deferred;
// make the sns subscribe request
const params = {
Protocol: /^(https?):/.exec(config.endpoint)[1],
TopicArn: topicArn,
Endpoint: config.endpoint
};
config.sns.subscribe(params, function(err) {
debug('Subscription request for ' + topicArn + (err ? ' failed : ' + err.message : ' sent.'));
if (err) return deferred.reject(err);
});
return deferred.promise;
} | [
"function",
"subscribe",
"(",
"topicArn",
")",
"{",
"// validate the topic arn",
"if",
"(",
"!",
"rxTopicArn",
".",
"test",
"(",
"topicArn",
")",
")",
"throw",
"Error",
"(",
"'Cannot subscribe to an invalid AWS Topic Arn: '",
"+",
"topicArn",
")",
";",
"// if already subscribed then return now",
"if",
"(",
"subscriptions",
"[",
"topicArn",
"]",
")",
"return",
"subscriptions",
"[",
"topicArn",
"]",
".",
"promise",
";",
"// create and store the deferred promise",
"const",
"deferred",
"=",
"defer",
"(",
")",
";",
"subscriptions",
"[",
"topicArn",
"]",
"=",
"deferred",
";",
"// make the sns subscribe request",
"const",
"params",
"=",
"{",
"Protocol",
":",
"/",
"^(https?):",
"/",
".",
"exec",
"(",
"config",
".",
"endpoint",
")",
"[",
"1",
"]",
",",
"TopicArn",
":",
"topicArn",
",",
"Endpoint",
":",
"config",
".",
"endpoint",
"}",
";",
"config",
".",
"sns",
".",
"subscribe",
"(",
"params",
",",
"function",
"(",
"err",
")",
"{",
"debug",
"(",
"'Subscription request for '",
"+",
"topicArn",
"+",
"(",
"err",
"?",
"' failed : '",
"+",
"err",
".",
"message",
":",
"' sent.'",
")",
")",
";",
"if",
"(",
"err",
")",
"return",
"deferred",
".",
"reject",
"(",
"err",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}"
] | Subscribe to an SNS Topic.
@param {string} topicArn
@returns {Promise} | [
"Subscribe",
"to",
"an",
"SNS",
"Topic",
"."
] | 708e7caa6bea706276d55b3678d8468438d6d163 | https://github.com/byu-oit/aws-scatter-gather/blob/708e7caa6bea706276d55b3678d8468438d6d163/bin/middleware.js#L150-L174 |
54,725 | byu-oit/aws-scatter-gather | bin/middleware.js | unsubscribe | function unsubscribe(topicArn) {
// if not subscribed then return now
if (!subscriptions[topicArn]) {
debug('Not subscribed to ' + topicArn);
return Promise.resolve();
}
return new Promise(function(resolve, reject) {
const params = { SubscriptionArn: topicArn };
config.sns.unsubscribe(params, function (err) {
debug('Unsubscribe from ' + topicArn + (err ? ' failed: ' + err.message : 'succeeded'));
if (err) return reject(err);
delete subscriptions[topicArn];
resolve();
});
});
} | javascript | function unsubscribe(topicArn) {
// if not subscribed then return now
if (!subscriptions[topicArn]) {
debug('Not subscribed to ' + topicArn);
return Promise.resolve();
}
return new Promise(function(resolve, reject) {
const params = { SubscriptionArn: topicArn };
config.sns.unsubscribe(params, function (err) {
debug('Unsubscribe from ' + topicArn + (err ? ' failed: ' + err.message : 'succeeded'));
if (err) return reject(err);
delete subscriptions[topicArn];
resolve();
});
});
} | [
"function",
"unsubscribe",
"(",
"topicArn",
")",
"{",
"// if not subscribed then return now",
"if",
"(",
"!",
"subscriptions",
"[",
"topicArn",
"]",
")",
"{",
"debug",
"(",
"'Not subscribed to '",
"+",
"topicArn",
")",
";",
"return",
"Promise",
".",
"resolve",
"(",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"function",
"(",
"resolve",
",",
"reject",
")",
"{",
"const",
"params",
"=",
"{",
"SubscriptionArn",
":",
"topicArn",
"}",
";",
"config",
".",
"sns",
".",
"unsubscribe",
"(",
"params",
",",
"function",
"(",
"err",
")",
"{",
"debug",
"(",
"'Unsubscribe from '",
"+",
"topicArn",
"+",
"(",
"err",
"?",
"' failed: '",
"+",
"err",
".",
"message",
":",
"'succeeded'",
")",
")",
";",
"if",
"(",
"err",
")",
"return",
"reject",
"(",
"err",
")",
";",
"delete",
"subscriptions",
"[",
"topicArn",
"]",
";",
"resolve",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Unsubscribe from an SNS Topic
@param {string} topicArn
@returns {Promise} | [
"Unsubscribe",
"from",
"an",
"SNS",
"Topic"
] | 708e7caa6bea706276d55b3678d8468438d6d163 | https://github.com/byu-oit/aws-scatter-gather/blob/708e7caa6bea706276d55b3678d8468438d6d163/bin/middleware.js#L181-L198 |
54,726 | byu-oit/aws-scatter-gather | bin/middleware.js | parseBody | function parseBody(req) {
return extractBody(req)
.then(() => {
if (req.body && typeof req.body === 'object') return req.body;
try {
return JSON.parse(req.body);
} catch (err) {
throw Error('Unexpected body format received. Expected application/json, received: ' + req.body);
}
});
} | javascript | function parseBody(req) {
return extractBody(req)
.then(() => {
if (req.body && typeof req.body === 'object') return req.body;
try {
return JSON.parse(req.body);
} catch (err) {
throw Error('Unexpected body format received. Expected application/json, received: ' + req.body);
}
});
} | [
"function",
"parseBody",
"(",
"req",
")",
"{",
"return",
"extractBody",
"(",
"req",
")",
".",
"then",
"(",
"(",
")",
"=>",
"{",
"if",
"(",
"req",
".",
"body",
"&&",
"typeof",
"req",
".",
"body",
"===",
"'object'",
")",
"return",
"req",
".",
"body",
";",
"try",
"{",
"return",
"JSON",
".",
"parse",
"(",
"req",
".",
"body",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"throw",
"Error",
"(",
"'Unexpected body format received. Expected application/json, received: '",
"+",
"req",
".",
"body",
")",
";",
"}",
"}",
")",
";",
"}"
] | Parse the response body.
@param {Object} req
@returns {Promise} | [
"Parse",
"the",
"response",
"body",
"."
] | 708e7caa6bea706276d55b3678d8468438d6d163 | https://github.com/byu-oit/aws-scatter-gather/blob/708e7caa6bea706276d55b3678d8468438d6d163/bin/middleware.js#L225-L235 |
54,727 | zouloux/semver-increment | index.js | function (version, semverIndex)
{
const splittedVersion = version.split('.');
splittedVersion[ semverIndex ] = parseInt(splittedVersion[ semverIndex ], 10) + 1;
while (semverIndex < 2)
{
splittedVersion[ ++semverIndex ] = '0';
}
return splittedVersion.join('.');
} | javascript | function (version, semverIndex)
{
const splittedVersion = version.split('.');
splittedVersion[ semverIndex ] = parseInt(splittedVersion[ semverIndex ], 10) + 1;
while (semverIndex < 2)
{
splittedVersion[ ++semverIndex ] = '0';
}
return splittedVersion.join('.');
} | [
"function",
"(",
"version",
",",
"semverIndex",
")",
"{",
"const",
"splittedVersion",
"=",
"version",
".",
"split",
"(",
"'.'",
")",
";",
"splittedVersion",
"[",
"semverIndex",
"]",
"=",
"parseInt",
"(",
"splittedVersion",
"[",
"semverIndex",
"]",
",",
"10",
")",
"+",
"1",
";",
"while",
"(",
"semverIndex",
"<",
"2",
")",
"{",
"splittedVersion",
"[",
"++",
"semverIndex",
"]",
"=",
"'0'",
";",
"}",
"return",
"splittedVersion",
".",
"join",
"(",
"'.'",
")",
";",
"}"
] | Increment a version which is as a string. | [
"Increment",
"a",
"version",
"which",
"is",
"as",
"a",
"string",
"."
] | 4c65abeb42a17ad05d147108d595cd490eaafc4d | https://github.com/zouloux/semver-increment/blob/4c65abeb42a17ad05d147108d595cd490eaafc4d/index.js#L25-L34 |
|
54,728 | zouloux/semver-increment | index.js | function (packagePath, semverIndex)
{
// Check if package file exists
if ( !fs.existsSync(packagePath) )
{
throw new Error(`Package file ${packagePath} is not found.`, 1);
}
// Read package file content
const packageData = JSON.parse( fs.readFileSync( packagePath ) );
// Increment version according to semver increment index
packageData.version = module.exports.semverIncrement(packageData.version, semverIndex);
// Write new package.json
fs.writeFileSync(packagePath, JSON.stringify( packageData, null, 2));
// Return incremented version
return packageData.version;
} | javascript | function (packagePath, semverIndex)
{
// Check if package file exists
if ( !fs.existsSync(packagePath) )
{
throw new Error(`Package file ${packagePath} is not found.`, 1);
}
// Read package file content
const packageData = JSON.parse( fs.readFileSync( packagePath ) );
// Increment version according to semver increment index
packageData.version = module.exports.semverIncrement(packageData.version, semverIndex);
// Write new package.json
fs.writeFileSync(packagePath, JSON.stringify( packageData, null, 2));
// Return incremented version
return packageData.version;
} | [
"function",
"(",
"packagePath",
",",
"semverIndex",
")",
"{",
"// Check if package file exists",
"if",
"(",
"!",
"fs",
".",
"existsSync",
"(",
"packagePath",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"`",
"${",
"packagePath",
"}",
"`",
",",
"1",
")",
";",
"}",
"// Read package file content",
"const",
"packageData",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"packagePath",
")",
")",
";",
"// Increment version according to semver increment index",
"packageData",
".",
"version",
"=",
"module",
".",
"exports",
".",
"semverIncrement",
"(",
"packageData",
".",
"version",
",",
"semverIndex",
")",
";",
"// Write new package.json",
"fs",
".",
"writeFileSync",
"(",
"packagePath",
",",
"JSON",
".",
"stringify",
"(",
"packageData",
",",
"null",
",",
"2",
")",
")",
";",
"// Return incremented version",
"return",
"packageData",
".",
"version",
";",
"}"
] | Increment any package.json version. | [
"Increment",
"any",
"package",
".",
"json",
"version",
"."
] | 4c65abeb42a17ad05d147108d595cd490eaafc4d | https://github.com/zouloux/semver-increment/blob/4c65abeb42a17ad05d147108d595cd490eaafc4d/index.js#L39-L58 |
|
54,729 | shenanigans/node-fauxmongo | lib/Project.js | multiproject | function multiproject (pointer, target, path) {
var pointerType = getTypeStr (pointer);
var mainTarget;
if (target)
mainTarget = target;
else
if (pointerType == 'object')
target = {};
else if (pointerType == 'array') {
target = [];
var remainingPath = path.slice (i);
for (var i in pointer) {
var found = multiproject (pointer[i], target[i], remainingPath);
if (found !== undefined)
target[i] = found;
}
return target;
} else
return;
for (var i=0,j=path.length-1; i<j; i++) {
var pathStep = path[i];
if (pathStep == '$')
throw new Error (
'cannot use the positional operator inside another Array'
);
if (pointerType == 'array') {
if (!mainTarget) mainTarget = target;
var remainingPath = path.slice (i);
for (var k in pointer) {
var found = multiproject (pointer[k], target[k], remainingPath);
if (found !== undefined)
target[k] = found;
}
return mainTarget;
} else if (pointerType != 'object')
return mainTarget; // if there's path left, we must be a container type
if (!Object.hasOwnProperty.call (pointer, pathStep))
return mainTarget; // not found
if (!mainTarget) mainTarget = target;
pointer = pointer[pathStep];
pointerType = getTypeStr (pointer);
if (Object.hasOwnProperty.call (target, pathStep))
target = target[pathStep];
else
if (pointerType == 'object')
target = target[pathStep] = {};
else
target = target[pathStep] = [];
}
var finalStep = path[path.length-1];
if (!mainTarget) mainTarget = target;
if (pointerType == 'array') {
for (var k in pointer) {
var found = multiproject (pointer[k], target[k], [ finalStep ]);
if (found !== undefined)
target[k] = found;
}
return mainTarget;
} else if (pointerType != 'object')
return mainTarget;
if (Object.hasOwnProperty.call (pointer, finalStep)) {
target[finalStep] = pointer[finalStep];
if (!mainTarget) mainTarget = target;
}
return mainTarget;
} | javascript | function multiproject (pointer, target, path) {
var pointerType = getTypeStr (pointer);
var mainTarget;
if (target)
mainTarget = target;
else
if (pointerType == 'object')
target = {};
else if (pointerType == 'array') {
target = [];
var remainingPath = path.slice (i);
for (var i in pointer) {
var found = multiproject (pointer[i], target[i], remainingPath);
if (found !== undefined)
target[i] = found;
}
return target;
} else
return;
for (var i=0,j=path.length-1; i<j; i++) {
var pathStep = path[i];
if (pathStep == '$')
throw new Error (
'cannot use the positional operator inside another Array'
);
if (pointerType == 'array') {
if (!mainTarget) mainTarget = target;
var remainingPath = path.slice (i);
for (var k in pointer) {
var found = multiproject (pointer[k], target[k], remainingPath);
if (found !== undefined)
target[k] = found;
}
return mainTarget;
} else if (pointerType != 'object')
return mainTarget; // if there's path left, we must be a container type
if (!Object.hasOwnProperty.call (pointer, pathStep))
return mainTarget; // not found
if (!mainTarget) mainTarget = target;
pointer = pointer[pathStep];
pointerType = getTypeStr (pointer);
if (Object.hasOwnProperty.call (target, pathStep))
target = target[pathStep];
else
if (pointerType == 'object')
target = target[pathStep] = {};
else
target = target[pathStep] = [];
}
var finalStep = path[path.length-1];
if (!mainTarget) mainTarget = target;
if (pointerType == 'array') {
for (var k in pointer) {
var found = multiproject (pointer[k], target[k], [ finalStep ]);
if (found !== undefined)
target[k] = found;
}
return mainTarget;
} else if (pointerType != 'object')
return mainTarget;
if (Object.hasOwnProperty.call (pointer, finalStep)) {
target[finalStep] = pointer[finalStep];
if (!mainTarget) mainTarget = target;
}
return mainTarget;
} | [
"function",
"multiproject",
"(",
"pointer",
",",
"target",
",",
"path",
")",
"{",
"var",
"pointerType",
"=",
"getTypeStr",
"(",
"pointer",
")",
";",
"var",
"mainTarget",
";",
"if",
"(",
"target",
")",
"mainTarget",
"=",
"target",
";",
"else",
"if",
"(",
"pointerType",
"==",
"'object'",
")",
"target",
"=",
"{",
"}",
";",
"else",
"if",
"(",
"pointerType",
"==",
"'array'",
")",
"{",
"target",
"=",
"[",
"]",
";",
"var",
"remainingPath",
"=",
"path",
".",
"slice",
"(",
"i",
")",
";",
"for",
"(",
"var",
"i",
"in",
"pointer",
")",
"{",
"var",
"found",
"=",
"multiproject",
"(",
"pointer",
"[",
"i",
"]",
",",
"target",
"[",
"i",
"]",
",",
"remainingPath",
")",
";",
"if",
"(",
"found",
"!==",
"undefined",
")",
"target",
"[",
"i",
"]",
"=",
"found",
";",
"}",
"return",
"target",
";",
"}",
"else",
"return",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"j",
"=",
"path",
".",
"length",
"-",
"1",
";",
"i",
"<",
"j",
";",
"i",
"++",
")",
"{",
"var",
"pathStep",
"=",
"path",
"[",
"i",
"]",
";",
"if",
"(",
"pathStep",
"==",
"'$'",
")",
"throw",
"new",
"Error",
"(",
"'cannot use the positional operator inside another Array'",
")",
";",
"if",
"(",
"pointerType",
"==",
"'array'",
")",
"{",
"if",
"(",
"!",
"mainTarget",
")",
"mainTarget",
"=",
"target",
";",
"var",
"remainingPath",
"=",
"path",
".",
"slice",
"(",
"i",
")",
";",
"for",
"(",
"var",
"k",
"in",
"pointer",
")",
"{",
"var",
"found",
"=",
"multiproject",
"(",
"pointer",
"[",
"k",
"]",
",",
"target",
"[",
"k",
"]",
",",
"remainingPath",
")",
";",
"if",
"(",
"found",
"!==",
"undefined",
")",
"target",
"[",
"k",
"]",
"=",
"found",
";",
"}",
"return",
"mainTarget",
";",
"}",
"else",
"if",
"(",
"pointerType",
"!=",
"'object'",
")",
"return",
"mainTarget",
";",
"// if there's path left, we must be a container type",
"if",
"(",
"!",
"Object",
".",
"hasOwnProperty",
".",
"call",
"(",
"pointer",
",",
"pathStep",
")",
")",
"return",
"mainTarget",
";",
"// not found",
"if",
"(",
"!",
"mainTarget",
")",
"mainTarget",
"=",
"target",
";",
"pointer",
"=",
"pointer",
"[",
"pathStep",
"]",
";",
"pointerType",
"=",
"getTypeStr",
"(",
"pointer",
")",
";",
"if",
"(",
"Object",
".",
"hasOwnProperty",
".",
"call",
"(",
"target",
",",
"pathStep",
")",
")",
"target",
"=",
"target",
"[",
"pathStep",
"]",
";",
"else",
"if",
"(",
"pointerType",
"==",
"'object'",
")",
"target",
"=",
"target",
"[",
"pathStep",
"]",
"=",
"{",
"}",
";",
"else",
"target",
"=",
"target",
"[",
"pathStep",
"]",
"=",
"[",
"]",
";",
"}",
"var",
"finalStep",
"=",
"path",
"[",
"path",
".",
"length",
"-",
"1",
"]",
";",
"if",
"(",
"!",
"mainTarget",
")",
"mainTarget",
"=",
"target",
";",
"if",
"(",
"pointerType",
"==",
"'array'",
")",
"{",
"for",
"(",
"var",
"k",
"in",
"pointer",
")",
"{",
"var",
"found",
"=",
"multiproject",
"(",
"pointer",
"[",
"k",
"]",
",",
"target",
"[",
"k",
"]",
",",
"[",
"finalStep",
"]",
")",
";",
"if",
"(",
"found",
"!==",
"undefined",
")",
"target",
"[",
"k",
"]",
"=",
"found",
";",
"}",
"return",
"mainTarget",
";",
"}",
"else",
"if",
"(",
"pointerType",
"!=",
"'object'",
")",
"return",
"mainTarget",
";",
"if",
"(",
"Object",
".",
"hasOwnProperty",
".",
"call",
"(",
"pointer",
",",
"finalStep",
")",
")",
"{",
"target",
"[",
"finalStep",
"]",
"=",
"pointer",
"[",
"finalStep",
"]",
";",
"if",
"(",
"!",
"mainTarget",
")",
"mainTarget",
"=",
"target",
";",
"}",
"return",
"mainTarget",
";",
"}"
] | in case we traverse any Arrays during this projection | [
"in",
"case",
"we",
"traverse",
"any",
"Arrays",
"during",
"this",
"projection"
] | 8aa4806f0f1da5dacc59c4fe2c1c7cd48904ce20 | https://github.com/shenanigans/node-fauxmongo/blob/8aa4806f0f1da5dacc59c4fe2c1c7cd48904ce20/lib/Project.js#L29-L101 |
54,730 | wilmoore/node-git-origin-url | index.js | origin | function origin(fn) {
'use strict';
exec('git config --local --get remote.origin.url', function (errors, stdout, stderr) {
var url = "";
if (errors) return fn(errors.stack, url);
if (stderr) return fn(stderr, url);
url = trim.call(stdout);
if (!url) return fn('Unable to find remote origin URL!', url);
fn(null, url);
});
} | javascript | function origin(fn) {
'use strict';
exec('git config --local --get remote.origin.url', function (errors, stdout, stderr) {
var url = "";
if (errors) return fn(errors.stack, url);
if (stderr) return fn(stderr, url);
url = trim.call(stdout);
if (!url) return fn('Unable to find remote origin URL!', url);
fn(null, url);
});
} | [
"function",
"origin",
"(",
"fn",
")",
"{",
"'use strict'",
";",
"exec",
"(",
"'git config --local --get remote.origin.url'",
",",
"function",
"(",
"errors",
",",
"stdout",
",",
"stderr",
")",
"{",
"var",
"url",
"=",
"\"\"",
";",
"if",
"(",
"errors",
")",
"return",
"fn",
"(",
"errors",
".",
"stack",
",",
"url",
")",
";",
"if",
"(",
"stderr",
")",
"return",
"fn",
"(",
"stderr",
",",
"url",
")",
";",
"url",
"=",
"trim",
".",
"call",
"(",
"stdout",
")",
";",
"if",
"(",
"!",
"url",
")",
"return",
"fn",
"(",
"'Unable to find remote origin URL!'",
",",
"url",
")",
";",
"fn",
"(",
"null",
",",
"url",
")",
";",
"}",
")",
";",
"}"
] | Retrieve the git remote origin URL of the current repo.
@param {Function} fn
Callback to receive the result. | [
"Retrieve",
"the",
"git",
"remote",
"origin",
"URL",
"of",
"the",
"current",
"repo",
"."
] | 881e3c9c7a22c1482b5ca3a7293eb45f8b350223 | https://github.com/wilmoore/node-git-origin-url/blob/881e3c9c7a22c1482b5ca3a7293eb45f8b350223/index.js#L15-L29 |
54,731 | doowb/src-stream | index.js | srcStream | function srcStream(stream) {
var pass = through.obj();
pass.setMaxListeners(0);
var outputstream = duplexify.obj(pass, ms(stream, pass));
outputstream.setMaxListeners(0);
var isReading = false;
outputstream.on('pipe', function (src) {
isReading = true;
src.on('end', function () {
isReading = false;
outputstream.end();
});
});
stream.on('end', function () {
if (!isReading) {
outputstream.end();
}
});
return outputstream;
} | javascript | function srcStream(stream) {
var pass = through.obj();
pass.setMaxListeners(0);
var outputstream = duplexify.obj(pass, ms(stream, pass));
outputstream.setMaxListeners(0);
var isReading = false;
outputstream.on('pipe', function (src) {
isReading = true;
src.on('end', function () {
isReading = false;
outputstream.end();
});
});
stream.on('end', function () {
if (!isReading) {
outputstream.end();
}
});
return outputstream;
} | [
"function",
"srcStream",
"(",
"stream",
")",
"{",
"var",
"pass",
"=",
"through",
".",
"obj",
"(",
")",
";",
"pass",
".",
"setMaxListeners",
"(",
"0",
")",
";",
"var",
"outputstream",
"=",
"duplexify",
".",
"obj",
"(",
"pass",
",",
"ms",
"(",
"stream",
",",
"pass",
")",
")",
";",
"outputstream",
".",
"setMaxListeners",
"(",
"0",
")",
";",
"var",
"isReading",
"=",
"false",
";",
"outputstream",
".",
"on",
"(",
"'pipe'",
",",
"function",
"(",
"src",
")",
"{",
"isReading",
"=",
"true",
";",
"src",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"isReading",
"=",
"false",
";",
"outputstream",
".",
"end",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"stream",
".",
"on",
"(",
"'end'",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"isReading",
")",
"{",
"outputstream",
".",
"end",
"(",
")",
";",
"}",
"}",
")",
";",
"return",
"outputstream",
";",
"}"
] | Wrap a source stream to passthrough any data
that's being written to it.
```js
var src = require('src-stream');
// wrap something that returns a readable stream
var stream = src(plugin());
fs.createReadStream('./package.json')
.pipe(stream)
.on('data', console.log)
.on('end', function () {
console.log();
console.log('Finished');
console.log();
});
```
@param {Stream} `stream` Readable stream to be wrapped.
@return {Stream} Duplex stream to handle reading and writing.
@api public | [
"Wrap",
"a",
"source",
"stream",
"to",
"passthrough",
"any",
"data",
"that",
"s",
"being",
"written",
"to",
"it",
"."
] | 943a7222b1f7a72455a4a3f74cb0b8245f90ad81 | https://github.com/doowb/src-stream/blob/943a7222b1f7a72455a4a3f74cb0b8245f90ad81/index.js#L39-L62 |
54,732 | llamadeus/data-to-png | cjs/index.js | createIHDRChunk | function createIHDRChunk(width, height) {
const data = buffer.Buffer.alloc(13);
// Width
data.writeUInt32BE(width);
// Height
data.writeUInt32BE(height, 4);
// Bit depth
data.writeUInt8(8, 8);
// RGBA mode
data.writeUInt8(6, 9);
// No compression
data.writeUInt8(0, 10);
// No filter
data.writeUInt8(0, 11);
// No interlacing
data.writeUInt8(0, 12);
return createChunk('IHDR', data);
} | javascript | function createIHDRChunk(width, height) {
const data = buffer.Buffer.alloc(13);
// Width
data.writeUInt32BE(width);
// Height
data.writeUInt32BE(height, 4);
// Bit depth
data.writeUInt8(8, 8);
// RGBA mode
data.writeUInt8(6, 9);
// No compression
data.writeUInt8(0, 10);
// No filter
data.writeUInt8(0, 11);
// No interlacing
data.writeUInt8(0, 12);
return createChunk('IHDR', data);
} | [
"function",
"createIHDRChunk",
"(",
"width",
",",
"height",
")",
"{",
"const",
"data",
"=",
"buffer",
".",
"Buffer",
".",
"alloc",
"(",
"13",
")",
";",
"// Width",
"data",
".",
"writeUInt32BE",
"(",
"width",
")",
";",
"// Height",
"data",
".",
"writeUInt32BE",
"(",
"height",
",",
"4",
")",
";",
"// Bit depth",
"data",
".",
"writeUInt8",
"(",
"8",
",",
"8",
")",
";",
"// RGBA mode",
"data",
".",
"writeUInt8",
"(",
"6",
",",
"9",
")",
";",
"// No compression",
"data",
".",
"writeUInt8",
"(",
"0",
",",
"10",
")",
";",
"// No filter",
"data",
".",
"writeUInt8",
"(",
"0",
",",
"11",
")",
";",
"// No interlacing",
"data",
".",
"writeUInt8",
"(",
"0",
",",
"12",
")",
";",
"return",
"createChunk",
"(",
"'IHDR'",
",",
"data",
")",
";",
"}"
] | Create the IHDR chunk.
@param width
@param height
@returns {Buffer} | [
"Create",
"the",
"IHDR",
"chunk",
"."
] | 8170197b4213d86a56c7b0cc4952f80a1e840766 | https://github.com/llamadeus/data-to-png/blob/8170197b4213d86a56c7b0cc4952f80a1e840766/cjs/index.js#L53-L72 |
54,733 | llamadeus/data-to-png | cjs/index.js | createPng | function createPng(pixelData) {
const length = pixelData.length + 4 - (pixelData.length % 4);
const pixels = Math.ceil(length / 4);
const width = Math.min(pixels, MAX_WIDTH);
const height = Math.ceil(pixels / MAX_WIDTH);
const bytesPerRow = width * 4;
const buffer$$1 = buffer.Buffer.alloc((bytesPerRow + 1) * height);
// Write pixel data to buffer
for (let y = 0; y < height; y += 1) {
const offset = y * bytesPerRow;
const rowData = pixelData.slice(offset, offset + bytesPerRow);
const rowStartX = offset + y + 1;
const rowEndX = rowStartX + bytesPerRow;
buffer$$1.writeUInt8(0, offset + y);
buffer$$1.fill(rowData, rowStartX, rowEndX);
}
return new Promise((resolve, reject) => {
zlib.deflate(buffer$$1, (error, deflated) => {
if (error) {
reject(error);
return;
}
resolve(buffer.Buffer.concat([
PNG_HEADER,
createIHDRChunk(width, height),
createIDATChunk(deflated),
createIENDChunk(),
]));
});
});
} | javascript | function createPng(pixelData) {
const length = pixelData.length + 4 - (pixelData.length % 4);
const pixels = Math.ceil(length / 4);
const width = Math.min(pixels, MAX_WIDTH);
const height = Math.ceil(pixels / MAX_WIDTH);
const bytesPerRow = width * 4;
const buffer$$1 = buffer.Buffer.alloc((bytesPerRow + 1) * height);
// Write pixel data to buffer
for (let y = 0; y < height; y += 1) {
const offset = y * bytesPerRow;
const rowData = pixelData.slice(offset, offset + bytesPerRow);
const rowStartX = offset + y + 1;
const rowEndX = rowStartX + bytesPerRow;
buffer$$1.writeUInt8(0, offset + y);
buffer$$1.fill(rowData, rowStartX, rowEndX);
}
return new Promise((resolve, reject) => {
zlib.deflate(buffer$$1, (error, deflated) => {
if (error) {
reject(error);
return;
}
resolve(buffer.Buffer.concat([
PNG_HEADER,
createIHDRChunk(width, height),
createIDATChunk(deflated),
createIENDChunk(),
]));
});
});
} | [
"function",
"createPng",
"(",
"pixelData",
")",
"{",
"const",
"length",
"=",
"pixelData",
".",
"length",
"+",
"4",
"-",
"(",
"pixelData",
".",
"length",
"%",
"4",
")",
";",
"const",
"pixels",
"=",
"Math",
".",
"ceil",
"(",
"length",
"/",
"4",
")",
";",
"const",
"width",
"=",
"Math",
".",
"min",
"(",
"pixels",
",",
"MAX_WIDTH",
")",
";",
"const",
"height",
"=",
"Math",
".",
"ceil",
"(",
"pixels",
"/",
"MAX_WIDTH",
")",
";",
"const",
"bytesPerRow",
"=",
"width",
"*",
"4",
";",
"const",
"buffer$$1",
"=",
"buffer",
".",
"Buffer",
".",
"alloc",
"(",
"(",
"bytesPerRow",
"+",
"1",
")",
"*",
"height",
")",
";",
"// Write pixel data to buffer",
"for",
"(",
"let",
"y",
"=",
"0",
";",
"y",
"<",
"height",
";",
"y",
"+=",
"1",
")",
"{",
"const",
"offset",
"=",
"y",
"*",
"bytesPerRow",
";",
"const",
"rowData",
"=",
"pixelData",
".",
"slice",
"(",
"offset",
",",
"offset",
"+",
"bytesPerRow",
")",
";",
"const",
"rowStartX",
"=",
"offset",
"+",
"y",
"+",
"1",
";",
"const",
"rowEndX",
"=",
"rowStartX",
"+",
"bytesPerRow",
";",
"buffer$$1",
".",
"writeUInt8",
"(",
"0",
",",
"offset",
"+",
"y",
")",
";",
"buffer$$1",
".",
"fill",
"(",
"rowData",
",",
"rowStartX",
",",
"rowEndX",
")",
";",
"}",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"zlib",
".",
"deflate",
"(",
"buffer$$1",
",",
"(",
"error",
",",
"deflated",
")",
"=>",
"{",
"if",
"(",
"error",
")",
"{",
"reject",
"(",
"error",
")",
";",
"return",
";",
"}",
"resolve",
"(",
"buffer",
".",
"Buffer",
".",
"concat",
"(",
"[",
"PNG_HEADER",
",",
"createIHDRChunk",
"(",
"width",
",",
"height",
")",
",",
"createIDATChunk",
"(",
"deflated",
")",
",",
"createIENDChunk",
"(",
")",
",",
"]",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Create a png from the given pixel data.
@param pixelData
@returns {Promise<Buffer>} | [
"Create",
"a",
"png",
"from",
"the",
"given",
"pixel",
"data",
"."
] | 8170197b4213d86a56c7b0cc4952f80a1e840766 | https://github.com/llamadeus/data-to-png/blob/8170197b4213d86a56c7b0cc4952f80a1e840766/cjs/index.js#L99-L133 |
54,734 | llamadeus/data-to-png | cjs/index.js | prependLength | function prependLength(data) {
const lengthAsBytes = buffer.Buffer.alloc(4);
lengthAsBytes.writeUInt32BE(data.length);
return buffer.Buffer.concat([lengthAsBytes, data]);
} | javascript | function prependLength(data) {
const lengthAsBytes = buffer.Buffer.alloc(4);
lengthAsBytes.writeUInt32BE(data.length);
return buffer.Buffer.concat([lengthAsBytes, data]);
} | [
"function",
"prependLength",
"(",
"data",
")",
"{",
"const",
"lengthAsBytes",
"=",
"buffer",
".",
"Buffer",
".",
"alloc",
"(",
"4",
")",
";",
"lengthAsBytes",
".",
"writeUInt32BE",
"(",
"data",
".",
"length",
")",
";",
"return",
"buffer",
".",
"Buffer",
".",
"concat",
"(",
"[",
"lengthAsBytes",
",",
"data",
"]",
")",
";",
"}"
] | Prepend length to the data.
@param data
@returns {Buffer} | [
"Prepend",
"length",
"to",
"the",
"data",
"."
] | 8170197b4213d86a56c7b0cc4952f80a1e840766 | https://github.com/llamadeus/data-to-png/blob/8170197b4213d86a56c7b0cc4952f80a1e840766/cjs/index.js#L141-L147 |
54,735 | llamadeus/data-to-png | cjs/index.js | encode | function encode(data) {
const bytes = buffer.Buffer.from(data, 'utf8');
const pixelData = prependLength(bytes);
return createPng(pixelData);
} | javascript | function encode(data) {
const bytes = buffer.Buffer.from(data, 'utf8');
const pixelData = prependLength(bytes);
return createPng(pixelData);
} | [
"function",
"encode",
"(",
"data",
")",
"{",
"const",
"bytes",
"=",
"buffer",
".",
"Buffer",
".",
"from",
"(",
"data",
",",
"'utf8'",
")",
";",
"const",
"pixelData",
"=",
"prependLength",
"(",
"bytes",
")",
";",
"return",
"createPng",
"(",
"pixelData",
")",
";",
"}"
] | Encode the given data to png.
@param {string} data
@returns {Promise<Buffer>} | [
"Encode",
"the",
"given",
"data",
"to",
"png",
"."
] | 8170197b4213d86a56c7b0cc4952f80a1e840766 | https://github.com/llamadeus/data-to-png/blob/8170197b4213d86a56c7b0cc4952f80a1e840766/cjs/index.js#L155-L160 |
54,736 | jkorona/grunt-release-bower | lib/semver-utils.js | function (increment) {
increment = increment || Semver.PATCH; // default is patch
switch (increment) {
/* jshint indent: false */
case Semver.MAJOR:
this.major++;
this.minor = this.patch = 0;
break;
case Semver.MINOR:
this.minor++;
this.patch = 0;
break;
case Semver.PATCH:
this.patch++;
break;
}
return this;
} | javascript | function (increment) {
increment = increment || Semver.PATCH; // default is patch
switch (increment) {
/* jshint indent: false */
case Semver.MAJOR:
this.major++;
this.minor = this.patch = 0;
break;
case Semver.MINOR:
this.minor++;
this.patch = 0;
break;
case Semver.PATCH:
this.patch++;
break;
}
return this;
} | [
"function",
"(",
"increment",
")",
"{",
"increment",
"=",
"increment",
"||",
"Semver",
".",
"PATCH",
";",
"// default is patch",
"switch",
"(",
"increment",
")",
"{",
"/* jshint indent: false */",
"case",
"Semver",
".",
"MAJOR",
":",
"this",
".",
"major",
"++",
";",
"this",
".",
"minor",
"=",
"this",
".",
"patch",
"=",
"0",
";",
"break",
";",
"case",
"Semver",
".",
"MINOR",
":",
"this",
".",
"minor",
"++",
";",
"this",
".",
"patch",
"=",
"0",
";",
"break",
";",
"case",
"Semver",
".",
"PATCH",
":",
"this",
".",
"patch",
"++",
";",
"break",
";",
"}",
"return",
"this",
";",
"}"
] | Increases version number using increment factor.
@param increment indicates which part of version should be pumped (major, minor, patch).
@returns {*} current Semver instance for method chaining. | [
"Increases",
"version",
"number",
"using",
"increment",
"factor",
"."
] | a1b0e0b4aa85eced889f75ee88f45e187af9ae24 | https://github.com/jkorona/grunt-release-bower/blob/a1b0e0b4aa85eced889f75ee88f45e187af9ae24/lib/semver-utils.js#L22-L39 |
|
54,737 | angeloocana/joj-core | dist-esnext/Game.js | isMyTurn | function isMyTurn(game, from) {
if (game.score.ended)
return false;
from = Board.getPositionFromBoard(game.board, from);
return isWhiteTurn(game) ? Position.hasWhitePiece(from) : Position.hasBlackPiece(from);
} | javascript | function isMyTurn(game, from) {
if (game.score.ended)
return false;
from = Board.getPositionFromBoard(game.board, from);
return isWhiteTurn(game) ? Position.hasWhitePiece(from) : Position.hasBlackPiece(from);
} | [
"function",
"isMyTurn",
"(",
"game",
",",
"from",
")",
"{",
"if",
"(",
"game",
".",
"score",
".",
"ended",
")",
"return",
"false",
";",
"from",
"=",
"Board",
".",
"getPositionFromBoard",
"(",
"game",
".",
"board",
",",
"from",
")",
";",
"return",
"isWhiteTurn",
"(",
"game",
")",
"?",
"Position",
".",
"hasWhitePiece",
"(",
"from",
")",
":",
"Position",
".",
"hasBlackPiece",
"(",
"from",
")",
";",
"}"
] | Returns true if from piece can be played. | [
"Returns",
"true",
"if",
"from",
"piece",
"can",
"be",
"played",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist-esnext/Game.js#L22-L27 |
54,738 | angeloocana/joj-core | dist-esnext/Game.js | getTurnPieces | function getTurnPieces(game) {
const isBlack = isBlackTurn(game);
return game.board.reduce((piecesRow, row) => {
return piecesRow.concat(row.reduce((pieces, position) => (isBlack !== position.isBlack)
? pieces
: pieces.concat({ x: position.x, y: position.y, isBlack }), []));
}, []);
} | javascript | function getTurnPieces(game) {
const isBlack = isBlackTurn(game);
return game.board.reduce((piecesRow, row) => {
return piecesRow.concat(row.reduce((pieces, position) => (isBlack !== position.isBlack)
? pieces
: pieces.concat({ x: position.x, y: position.y, isBlack }), []));
}, []);
} | [
"function",
"getTurnPieces",
"(",
"game",
")",
"{",
"const",
"isBlack",
"=",
"isBlackTurn",
"(",
"game",
")",
";",
"return",
"game",
".",
"board",
".",
"reduce",
"(",
"(",
"piecesRow",
",",
"row",
")",
"=>",
"{",
"return",
"piecesRow",
".",
"concat",
"(",
"row",
".",
"reduce",
"(",
"(",
"pieces",
",",
"position",
")",
"=>",
"(",
"isBlack",
"!==",
"position",
".",
"isBlack",
")",
"?",
"pieces",
":",
"pieces",
".",
"concat",
"(",
"{",
"x",
":",
"position",
".",
"x",
",",
"y",
":",
"position",
".",
"y",
",",
"isBlack",
"}",
")",
",",
"[",
"]",
")",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Gets all positions from current player turn. | [
"Gets",
"all",
"positions",
"from",
"current",
"player",
"turn",
"."
] | 14bc7801c004271cefafff6cc0abb0c3173c805a | https://github.com/angeloocana/joj-core/blob/14bc7801c004271cefafff6cc0abb0c3173c805a/dist-esnext/Game.js#L32-L39 |
54,739 | wigy/chronicles_of_grunt | lib/cog.js | prefix | function prefix(pattern) {
if (!pattern) {
pattern = 'grunt-available-tasks';
}
pattern = pattern.replace(/^node_modules\//, '');
var ret;
if (grunt.file.expand('node_modules/' + pattern).length) {
ret = 'node_modules/';
} else if (grunt.file.expand('../../node_modules/' + pattern).length) {
ret = '../../node_modules/';
} else if (grunt.file.expand('node_modules/chronicles_of_grunt/node_modules/' + pattern).length) {
ret = 'node_modules/chronicles_of_grunt/node_modules/';
} else {
grunt.fail.fatal("Cannot find module path for " + pattern);
}
return ret;
} | javascript | function prefix(pattern) {
if (!pattern) {
pattern = 'grunt-available-tasks';
}
pattern = pattern.replace(/^node_modules\//, '');
var ret;
if (grunt.file.expand('node_modules/' + pattern).length) {
ret = 'node_modules/';
} else if (grunt.file.expand('../../node_modules/' + pattern).length) {
ret = '../../node_modules/';
} else if (grunt.file.expand('node_modules/chronicles_of_grunt/node_modules/' + pattern).length) {
ret = 'node_modules/chronicles_of_grunt/node_modules/';
} else {
grunt.fail.fatal("Cannot find module path for " + pattern);
}
return ret;
} | [
"function",
"prefix",
"(",
"pattern",
")",
"{",
"if",
"(",
"!",
"pattern",
")",
"{",
"pattern",
"=",
"'grunt-available-tasks'",
";",
"}",
"pattern",
"=",
"pattern",
".",
"replace",
"(",
"/",
"^node_modules\\/",
"/",
",",
"''",
")",
";",
"var",
"ret",
";",
"if",
"(",
"grunt",
".",
"file",
".",
"expand",
"(",
"'node_modules/'",
"+",
"pattern",
")",
".",
"length",
")",
"{",
"ret",
"=",
"'node_modules/'",
";",
"}",
"else",
"if",
"(",
"grunt",
".",
"file",
".",
"expand",
"(",
"'../../node_modules/'",
"+",
"pattern",
")",
".",
"length",
")",
"{",
"ret",
"=",
"'../../node_modules/'",
";",
"}",
"else",
"if",
"(",
"grunt",
".",
"file",
".",
"expand",
"(",
"'node_modules/chronicles_of_grunt/node_modules/'",
"+",
"pattern",
")",
".",
"length",
")",
"{",
"ret",
"=",
"'node_modules/chronicles_of_grunt/node_modules/'",
";",
"}",
"else",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"\"Cannot find module path for \"",
"+",
"pattern",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Find the path prefix to the node_modules containing needed utilities. | [
"Find",
"the",
"path",
"prefix",
"to",
"the",
"node_modules",
"containing",
"needed",
"utilities",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/cog.js#L45-L61 |
54,740 | wigy/chronicles_of_grunt | lib/cog.js | getConfig | function getConfig(name, def) {
var i, j;
// Load initital config.
if (!config) {
var external;
config = grunt.config.get('cog') || {options: {}};
// Expand general external definitions to category specific definitions.
if (config.options.external instanceof Array) {
external = config.options.external;
config.options.external = {lib: [], css: [], fonts: []};
for (i=0; i < external.length; i++) {
if (!db.categories[external[i]]) {
grunt.fail.fatal("Cannot figure out applicaple categories for external dependency: " + external[i]);
}
for(j = 0; j < db.categories[external[i]].length; j++) {
config.options.external[db.categories[external[i]][j]].push(external[i]);
}
}
}
// Expand also for unit tests.
if (config.options.test && config.options.test.unit && config.options.test.unit.external instanceof Array) {
external = config.options.test.unit.external;
config.options.test.unit.lib = [];
config.options.test.unit.css = [];
for (i=0; i < external.length; i++) {
if (!db.categories[external[i]]) {
grunt.fail.fatal("Cannot figure out applicaple categories for external dependency: " + external[i]);
continue;
}
for(j = 0; j < db.categories[external[i]].length; j++) {
config.options.test.unit[db.categories[external[i]][j]].push(external[i]);
}
}
}
}
var ret = config.options;
if (!name) {
return ret;
}
var parts = name.split('.');
for (i=0; i < parts.length; i++) {
if (!ret) {
return def;
}
ret = ret[parts[i]];
}
return ret || def;
} | javascript | function getConfig(name, def) {
var i, j;
// Load initital config.
if (!config) {
var external;
config = grunt.config.get('cog') || {options: {}};
// Expand general external definitions to category specific definitions.
if (config.options.external instanceof Array) {
external = config.options.external;
config.options.external = {lib: [], css: [], fonts: []};
for (i=0; i < external.length; i++) {
if (!db.categories[external[i]]) {
grunt.fail.fatal("Cannot figure out applicaple categories for external dependency: " + external[i]);
}
for(j = 0; j < db.categories[external[i]].length; j++) {
config.options.external[db.categories[external[i]][j]].push(external[i]);
}
}
}
// Expand also for unit tests.
if (config.options.test && config.options.test.unit && config.options.test.unit.external instanceof Array) {
external = config.options.test.unit.external;
config.options.test.unit.lib = [];
config.options.test.unit.css = [];
for (i=0; i < external.length; i++) {
if (!db.categories[external[i]]) {
grunt.fail.fatal("Cannot figure out applicaple categories for external dependency: " + external[i]);
continue;
}
for(j = 0; j < db.categories[external[i]].length; j++) {
config.options.test.unit[db.categories[external[i]][j]].push(external[i]);
}
}
}
}
var ret = config.options;
if (!name) {
return ret;
}
var parts = name.split('.');
for (i=0; i < parts.length; i++) {
if (!ret) {
return def;
}
ret = ret[parts[i]];
}
return ret || def;
} | [
"function",
"getConfig",
"(",
"name",
",",
"def",
")",
"{",
"var",
"i",
",",
"j",
";",
"// Load initital config.",
"if",
"(",
"!",
"config",
")",
"{",
"var",
"external",
";",
"config",
"=",
"grunt",
".",
"config",
".",
"get",
"(",
"'cog'",
")",
"||",
"{",
"options",
":",
"{",
"}",
"}",
";",
"// Expand general external definitions to category specific definitions.",
"if",
"(",
"config",
".",
"options",
".",
"external",
"instanceof",
"Array",
")",
"{",
"external",
"=",
"config",
".",
"options",
".",
"external",
";",
"config",
".",
"options",
".",
"external",
"=",
"{",
"lib",
":",
"[",
"]",
",",
"css",
":",
"[",
"]",
",",
"fonts",
":",
"[",
"]",
"}",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"external",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"\"Cannot figure out applicaple categories for external dependency: \"",
"+",
"external",
"[",
"i",
"]",
")",
";",
"}",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
".",
"length",
";",
"j",
"++",
")",
"{",
"config",
".",
"options",
".",
"external",
"[",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
"[",
"j",
"]",
"]",
".",
"push",
"(",
"external",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"// Expand also for unit tests.",
"if",
"(",
"config",
".",
"options",
".",
"test",
"&&",
"config",
".",
"options",
".",
"test",
".",
"unit",
"&&",
"config",
".",
"options",
".",
"test",
".",
"unit",
".",
"external",
"instanceof",
"Array",
")",
"{",
"external",
"=",
"config",
".",
"options",
".",
"test",
".",
"unit",
".",
"external",
";",
"config",
".",
"options",
".",
"test",
".",
"unit",
".",
"lib",
"=",
"[",
"]",
";",
"config",
".",
"options",
".",
"test",
".",
"unit",
".",
"css",
"=",
"[",
"]",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"external",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
")",
"{",
"grunt",
".",
"fail",
".",
"fatal",
"(",
"\"Cannot figure out applicaple categories for external dependency: \"",
"+",
"external",
"[",
"i",
"]",
")",
";",
"continue",
";",
"}",
"for",
"(",
"j",
"=",
"0",
";",
"j",
"<",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
".",
"length",
";",
"j",
"++",
")",
"{",
"config",
".",
"options",
".",
"test",
".",
"unit",
"[",
"db",
".",
"categories",
"[",
"external",
"[",
"i",
"]",
"]",
"[",
"j",
"]",
"]",
".",
"push",
"(",
"external",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"}",
"var",
"ret",
"=",
"config",
".",
"options",
";",
"if",
"(",
"!",
"name",
")",
"{",
"return",
"ret",
";",
"}",
"var",
"parts",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"parts",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"ret",
")",
"{",
"return",
"def",
";",
"}",
"ret",
"=",
"ret",
"[",
"parts",
"[",
"i",
"]",
"]",
";",
"}",
"return",
"ret",
"||",
"def",
";",
"}"
] | Safe fetch of configuration variable. | [
"Safe",
"fetch",
"of",
"configuration",
"variable",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/cog.js#L76-L133 |
54,741 | wigy/chronicles_of_grunt | lib/cog.js | configuredFramework | function configuredFramework() {
var lib = getConfig('external.lib');
if (!lib) {
return null;
}
if (typeof(lib) === 'string') {
lib = [lib];
}
if (lib.indexOf('ember') >= 0) {
return 'ember';
}
if (lib.indexOf('angular') >= 0 || lib.indexOf('coa') >= 0) {
return 'angular';
}
return null;
} | javascript | function configuredFramework() {
var lib = getConfig('external.lib');
if (!lib) {
return null;
}
if (typeof(lib) === 'string') {
lib = [lib];
}
if (lib.indexOf('ember') >= 0) {
return 'ember';
}
if (lib.indexOf('angular') >= 0 || lib.indexOf('coa') >= 0) {
return 'angular';
}
return null;
} | [
"function",
"configuredFramework",
"(",
")",
"{",
"var",
"lib",
"=",
"getConfig",
"(",
"'external.lib'",
")",
";",
"if",
"(",
"!",
"lib",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"typeof",
"(",
"lib",
")",
"===",
"'string'",
")",
"{",
"lib",
"=",
"[",
"lib",
"]",
";",
"}",
"if",
"(",
"lib",
".",
"indexOf",
"(",
"'ember'",
")",
">=",
"0",
")",
"{",
"return",
"'ember'",
";",
"}",
"if",
"(",
"lib",
".",
"indexOf",
"(",
"'angular'",
")",
">=",
"0",
"||",
"ib.",
"i",
"ndexOf(",
"'",
"coa')",
" ",
"= ",
")",
" ",
"",
"return",
"'angular'",
";",
"}",
"return",
"null",
";",
"}"
] | Check the frameworks defined. | [
"Check",
"the",
"frameworks",
"defined",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/cog.js#L138-L153 |
54,742 | wigy/chronicles_of_grunt | lib/cog.js | getOption | function getOption(name) {
var ret = getConfig('options.' + name);
if (ret === undefined) {
var framework = configuredFramework();
if (db.frameworks.options[framework] && (name in db.frameworks.options[framework])) {
ret = db.frameworks.options[framework][name];
} else if (name in db.frameworks.options.all) {
ret = db.frameworks.options.all[name];
}
}
if (typeof(ret) === 'function') {
ret = ret();
}
return ret;
} | javascript | function getOption(name) {
var ret = getConfig('options.' + name);
if (ret === undefined) {
var framework = configuredFramework();
if (db.frameworks.options[framework] && (name in db.frameworks.options[framework])) {
ret = db.frameworks.options[framework][name];
} else if (name in db.frameworks.options.all) {
ret = db.frameworks.options.all[name];
}
}
if (typeof(ret) === 'function') {
ret = ret();
}
return ret;
} | [
"function",
"getOption",
"(",
"name",
")",
"{",
"var",
"ret",
"=",
"getConfig",
"(",
"'options.'",
"+",
"name",
")",
";",
"if",
"(",
"ret",
"===",
"undefined",
")",
"{",
"var",
"framework",
"=",
"configuredFramework",
"(",
")",
";",
"if",
"(",
"db",
".",
"frameworks",
".",
"options",
"[",
"framework",
"]",
"&&",
"(",
"name",
"in",
"db",
".",
"frameworks",
".",
"options",
"[",
"framework",
"]",
")",
")",
"{",
"ret",
"=",
"db",
".",
"frameworks",
".",
"options",
"[",
"framework",
"]",
"[",
"name",
"]",
";",
"}",
"else",
"if",
"(",
"name",
"in",
"db",
".",
"frameworks",
".",
"options",
".",
"all",
")",
"{",
"ret",
"=",
"db",
".",
"frameworks",
".",
"options",
".",
"all",
"[",
"name",
"]",
";",
"}",
"}",
"if",
"(",
"typeof",
"(",
"ret",
")",
"===",
"'function'",
")",
"{",
"ret",
"=",
"ret",
"(",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Get the value of a configuration flag. | [
"Get",
"the",
"value",
"of",
"a",
"configuration",
"flag",
"."
] | c5f089a6f391a0ca625fcb81ef51907713471bb3 | https://github.com/wigy/chronicles_of_grunt/blob/c5f089a6f391a0ca625fcb81ef51907713471bb3/lib/cog.js#L180-L196 |
54,743 | flitbit/oops | examples/browser/vendor/angular-ui.js | function (inst) {
if (inst.isDirty()) {
inst.save();
ngModel.$setViewValue(elm.val());
if (!scope.$$phase)
scope.$apply();
}
} | javascript | function (inst) {
if (inst.isDirty()) {
inst.save();
ngModel.$setViewValue(elm.val());
if (!scope.$$phase)
scope.$apply();
}
} | [
"function",
"(",
"inst",
")",
"{",
"if",
"(",
"inst",
".",
"isDirty",
"(",
")",
")",
"{",
"inst",
".",
"save",
"(",
")",
";",
"ngModel",
".",
"$setViewValue",
"(",
"elm",
".",
"val",
"(",
")",
")",
";",
"if",
"(",
"!",
"scope",
".",
"$$phase",
")",
"scope",
".",
"$apply",
"(",
")",
";",
"}",
"}"
] | Update model on button click | [
"Update",
"model",
"on",
"button",
"click"
] | 73c36d459b98d1ac9485327ab3d6bf180c78d254 | https://github.com/flitbit/oops/blob/73c36d459b98d1ac9485327ab3d6bf180c78d254/examples/browser/vendor/angular-ui.js#L758-L765 |
|
54,744 | flitbit/oops | examples/browser/vendor/angular-ui.js | function(event, jsEvent, view) {
if (view.name !== 'agendaDay') {
$(jsEvent.target).attr('title', event.title);
}
} | javascript | function(event, jsEvent, view) {
if (view.name !== 'agendaDay') {
$(jsEvent.target).attr('title', event.title);
}
} | [
"function",
"(",
"event",
",",
"jsEvent",
",",
"view",
")",
"{",
"if",
"(",
"view",
".",
"name",
"!==",
"'agendaDay'",
")",
"{",
"$",
"(",
"jsEvent",
".",
"target",
")",
".",
"attr",
"(",
"'title'",
",",
"event",
".",
"title",
")",
";",
"}",
"}"
] | add event name to title attribute on mouseover. | [
"add",
"event",
"name",
"to",
"title",
"attribute",
"on",
"mouseover",
"."
] | 73c36d459b98d1ac9485327ab3d6bf180c78d254 | https://github.com/flitbit/oops/blob/73c36d459b98d1ac9485327ab3d6bf180c78d254/examples/browser/vendor/angular-ui.js#L913-L917 |
|
54,745 | patgrasso/parsey | lib/cfg.js | CFG | function CFG(rules) {
let arr = [];
arr.__proto__ = CFG.prototype;
if (Array.isArray(rules)) {
rules.forEach(arr.rule.bind(arr));
}
return arr;
} | javascript | function CFG(rules) {
let arr = [];
arr.__proto__ = CFG.prototype;
if (Array.isArray(rules)) {
rules.forEach(arr.rule.bind(arr));
}
return arr;
} | [
"function",
"CFG",
"(",
"rules",
")",
"{",
"let",
"arr",
"=",
"[",
"]",
";",
"arr",
".",
"__proto__",
"=",
"CFG",
".",
"prototype",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"rules",
")",
")",
"{",
"rules",
".",
"forEach",
"(",
"arr",
".",
"rule",
".",
"bind",
"(",
"arr",
")",
")",
";",
"}",
"return",
"arr",
";",
"}"
] | Constructs a new context-free grammar, which is just a container for
production rules
@class CFG
@extends Array
@constructor
@param {rules=} - Optional array of {@link Rule}s to initialize the grammar
with | [
"Constructs",
"a",
"new",
"context",
"-",
"free",
"grammar",
"which",
"is",
"just",
"a",
"container",
"for",
"production",
"rules"
] | d28b3f330ee03b5c273f1ce5871a5b86dac79fb0 | https://github.com/patgrasso/parsey/blob/d28b3f330ee03b5c273f1ce5871a5b86dac79fb0/lib/cfg.js#L27-L36 |
54,746 | wilmoore/reapply.js | index.js | reapply | function reapply (parameters) {
return (arguments.length > 1)
? reapplyer(parameters, arguments[1])
: reapplyer.bind(null, parameters)
} | javascript | function reapply (parameters) {
return (arguments.length > 1)
? reapplyer(parameters, arguments[1])
: reapplyer.bind(null, parameters)
} | [
"function",
"reapply",
"(",
"parameters",
")",
"{",
"return",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"?",
"reapplyer",
"(",
"parameters",
",",
"arguments",
"[",
"1",
"]",
")",
":",
"reapplyer",
".",
"bind",
"(",
"null",
",",
"parameters",
")",
"}"
] | Curried wrapper.
@param {String} parameters
parameters to pass to applied function.
@return {Function|*}
result of partial or full function application. | [
"Curried",
"wrapper",
"."
] | 77b558bb4a1d9d623bc32a0280e2de5f43a144b7 | https://github.com/wilmoore/reapply.js/blob/77b558bb4a1d9d623bc32a0280e2de5f43a144b7/index.js#L25-L29 |
54,747 | grappler-ci/grappler-hook-github | index.js | handlePush | function handlePush(key, req, log, fn) {
var body = req.body;
var repo = body.repository;
if (!body || !repo) return fn(new Error('missing body'));
var url = repo.url;
var name = repo.name;
var ref = body.ref;
var branch = ref.replace('refs/heads/', '');
var sha = body.after;
var info = {
repo: repo.organization + '/' + repo.name,
url: repo.url,
name: repo.name,
ref: ref,
branch: branch,
sha: sha,
body: body
};
var event = body.deleted ? 'branch-deleted' : 'gh:parsed';
fn(null, info, event);
} | javascript | function handlePush(key, req, log, fn) {
var body = req.body;
var repo = body.repository;
if (!body || !repo) return fn(new Error('missing body'));
var url = repo.url;
var name = repo.name;
var ref = body.ref;
var branch = ref.replace('refs/heads/', '');
var sha = body.after;
var info = {
repo: repo.organization + '/' + repo.name,
url: repo.url,
name: repo.name,
ref: ref,
branch: branch,
sha: sha,
body: body
};
var event = body.deleted ? 'branch-deleted' : 'gh:parsed';
fn(null, info, event);
} | [
"function",
"handlePush",
"(",
"key",
",",
"req",
",",
"log",
",",
"fn",
")",
"{",
"var",
"body",
"=",
"req",
".",
"body",
";",
"var",
"repo",
"=",
"body",
".",
"repository",
";",
"if",
"(",
"!",
"body",
"||",
"!",
"repo",
")",
"return",
"fn",
"(",
"new",
"Error",
"(",
"'missing body'",
")",
")",
";",
"var",
"url",
"=",
"repo",
".",
"url",
";",
"var",
"name",
"=",
"repo",
".",
"name",
";",
"var",
"ref",
"=",
"body",
".",
"ref",
";",
"var",
"branch",
"=",
"ref",
".",
"replace",
"(",
"'refs/heads/'",
",",
"''",
")",
";",
"var",
"sha",
"=",
"body",
".",
"after",
";",
"var",
"info",
"=",
"{",
"repo",
":",
"repo",
".",
"organization",
"+",
"'/'",
"+",
"repo",
".",
"name",
",",
"url",
":",
"repo",
".",
"url",
",",
"name",
":",
"repo",
".",
"name",
",",
"ref",
":",
"ref",
",",
"branch",
":",
"branch",
",",
"sha",
":",
"sha",
",",
"body",
":",
"body",
"}",
";",
"var",
"event",
"=",
"body",
".",
"deleted",
"?",
"'branch-deleted'",
":",
"'gh:parsed'",
";",
"fn",
"(",
"null",
",",
"info",
",",
"event",
")",
";",
"}"
] | Handle a push event
steps:
* git clone sha
* deploy the sha
* listen for success/failure and update the repo status (https://developer.github.com/v3/repos/statuses/)
* create a deployment (https://developer.github.com/v3/repos/deployments/#create-a-deployment) | [
"Handle",
"a",
"push",
"event"
] | acb9a268ee51fd3575739a682ef2ec0ac8403e27 | https://github.com/grappler-ci/grappler-hook-github/blob/acb9a268ee51fd3575739a682ef2ec0ac8403e27/index.js#L75-L98 |
54,748 | grappler-ci/grappler-hook-github | index.js | clone | function clone(url, target, ref, key, log, fn) {
var urlObj = parseurl(url);
urlObj.auth = key + ':x-oauth-basic';
var authurl = formaturl(urlObj) + '.git';
var dir = target + '/.git';
log('creating dir ' + dir);
mkdirp(dir, function(err) {
if (err) return fn(err);
var remote = git.remote(authurl);
var repo = git.repo(dir);
var opts = {};
opts.want = ref;
log('fetching ' + url);
repo.fetch(remote, opts, function(err) {
if (err) return fn(err);
log('checking out ' + ref);
repo.resolveHashish(ref, function(err, hash) {
if (err) return fn(err);
log('updating head to ' + hash);
repo.updateHead(hash, function(err) {
if (err) return fn(err);
exec('git checkout ' + hash, {cwd: target}, function(err, stdout, stderr) {
fn(err);
});
});
});
});
});
} | javascript | function clone(url, target, ref, key, log, fn) {
var urlObj = parseurl(url);
urlObj.auth = key + ':x-oauth-basic';
var authurl = formaturl(urlObj) + '.git';
var dir = target + '/.git';
log('creating dir ' + dir);
mkdirp(dir, function(err) {
if (err) return fn(err);
var remote = git.remote(authurl);
var repo = git.repo(dir);
var opts = {};
opts.want = ref;
log('fetching ' + url);
repo.fetch(remote, opts, function(err) {
if (err) return fn(err);
log('checking out ' + ref);
repo.resolveHashish(ref, function(err, hash) {
if (err) return fn(err);
log('updating head to ' + hash);
repo.updateHead(hash, function(err) {
if (err) return fn(err);
exec('git checkout ' + hash, {cwd: target}, function(err, stdout, stderr) {
fn(err);
});
});
});
});
});
} | [
"function",
"clone",
"(",
"url",
",",
"target",
",",
"ref",
",",
"key",
",",
"log",
",",
"fn",
")",
"{",
"var",
"urlObj",
"=",
"parseurl",
"(",
"url",
")",
";",
"urlObj",
".",
"auth",
"=",
"key",
"+",
"':x-oauth-basic'",
";",
"var",
"authurl",
"=",
"formaturl",
"(",
"urlObj",
")",
"+",
"'.git'",
";",
"var",
"dir",
"=",
"target",
"+",
"'/.git'",
";",
"log",
"(",
"'creating dir '",
"+",
"dir",
")",
";",
"mkdirp",
"(",
"dir",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"fn",
"(",
"err",
")",
";",
"var",
"remote",
"=",
"git",
".",
"remote",
"(",
"authurl",
")",
";",
"var",
"repo",
"=",
"git",
".",
"repo",
"(",
"dir",
")",
";",
"var",
"opts",
"=",
"{",
"}",
";",
"opts",
".",
"want",
"=",
"ref",
";",
"log",
"(",
"'fetching '",
"+",
"url",
")",
";",
"repo",
".",
"fetch",
"(",
"remote",
",",
"opts",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"fn",
"(",
"err",
")",
";",
"log",
"(",
"'checking out '",
"+",
"ref",
")",
";",
"repo",
".",
"resolveHashish",
"(",
"ref",
",",
"function",
"(",
"err",
",",
"hash",
")",
"{",
"if",
"(",
"err",
")",
"return",
"fn",
"(",
"err",
")",
";",
"log",
"(",
"'updating head to '",
"+",
"hash",
")",
";",
"repo",
".",
"updateHead",
"(",
"hash",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"fn",
"(",
"err",
")",
";",
"exec",
"(",
"'git checkout '",
"+",
"hash",
",",
"{",
"cwd",
":",
"target",
"}",
",",
"function",
"(",
"err",
",",
"stdout",
",",
"stderr",
")",
"{",
"fn",
"(",
"err",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Clone a repo
@param {String} url
@param {String} target
@param {String} ref
@param {String} key
@param {Function} log
@param {Function} fn | [
"Clone",
"a",
"repo"
] | acb9a268ee51fd3575739a682ef2ec0ac8403e27 | https://github.com/grappler-ci/grappler-hook-github/blob/acb9a268ee51fd3575739a682ef2ec0ac8403e27/index.js#L149-L180 |
54,749 | yoshuawuyts/base-package-json | index.js | basePackageJson | function basePackageJson (opts) {
opts = opts || {}
const _name = opts.name || '<name>'
const _version = opts.version || '1.0.0'
const _private = opts.private || false
var called = false
return from({ objectMode: true }, function (size, next) {
if (called) return next(null, null)
const res = { name: _name, version: _version }
if (_private) res.private = true
res.scripts = {}
res.dependencies = {}
res.devDependencies = {}
called = true
next(null, res)
})
} | javascript | function basePackageJson (opts) {
opts = opts || {}
const _name = opts.name || '<name>'
const _version = opts.version || '1.0.0'
const _private = opts.private || false
var called = false
return from({ objectMode: true }, function (size, next) {
if (called) return next(null, null)
const res = { name: _name, version: _version }
if (_private) res.private = true
res.scripts = {}
res.dependencies = {}
res.devDependencies = {}
called = true
next(null, res)
})
} | [
"function",
"basePackageJson",
"(",
"opts",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
"const",
"_name",
"=",
"opts",
".",
"name",
"||",
"'<name>'",
"const",
"_version",
"=",
"opts",
".",
"version",
"||",
"'1.0.0'",
"const",
"_private",
"=",
"opts",
".",
"private",
"||",
"false",
"var",
"called",
"=",
"false",
"return",
"from",
"(",
"{",
"objectMode",
":",
"true",
"}",
",",
"function",
"(",
"size",
",",
"next",
")",
"{",
"if",
"(",
"called",
")",
"return",
"next",
"(",
"null",
",",
"null",
")",
"const",
"res",
"=",
"{",
"name",
":",
"_name",
",",
"version",
":",
"_version",
"}",
"if",
"(",
"_private",
")",
"res",
".",
"private",
"=",
"true",
"res",
".",
"scripts",
"=",
"{",
"}",
"res",
".",
"dependencies",
"=",
"{",
"}",
"res",
".",
"devDependencies",
"=",
"{",
"}",
"called",
"=",
"true",
"next",
"(",
"null",
",",
"res",
")",
"}",
")",
"}"
] | Basic package.json readable stream obj -> stream | [
"Basic",
"package",
".",
"json",
"readable",
"stream",
"obj",
"-",
">",
"stream"
] | 314a6c830880fd63347775ff4daf33d0eff972e5 | https://github.com/yoshuawuyts/base-package-json/blob/314a6c830880fd63347775ff4daf33d0eff972e5/index.js#L7-L27 |
54,750 | garyns/OneLineLogger | onelinelogger.js | padLeft | function padLeft(width, string, padding) {
return (width <= string.length) ? string : padLeft(width, string + padding, padding);
} | javascript | function padLeft(width, string, padding) {
return (width <= string.length) ? string : padLeft(width, string + padding, padding);
} | [
"function",
"padLeft",
"(",
"width",
",",
"string",
",",
"padding",
")",
"{",
"return",
"(",
"width",
"<=",
"string",
".",
"length",
")",
"?",
"string",
":",
"padLeft",
"(",
"width",
",",
"string",
"+",
"padding",
",",
"padding",
")",
";",
"}"
] | Pad a string. | [
"Pad",
"a",
"string",
"."
] | 92965144fcc87fa54b15b82843b651af4b980c0d | https://github.com/garyns/OneLineLogger/blob/92965144fcc87fa54b15b82843b651af4b980c0d/onelinelogger.js#L227-L229 |
54,751 | garyns/OneLineLogger | onelinelogger.js | writeLogFile | function writeLogFile(file, line) {
if (file === undefined || file === null) {
return;
}
fs.appendFile(file, line + os.EOL, {}, function() {
//
});
} | javascript | function writeLogFile(file, line) {
if (file === undefined || file === null) {
return;
}
fs.appendFile(file, line + os.EOL, {}, function() {
//
});
} | [
"function",
"writeLogFile",
"(",
"file",
",",
"line",
")",
"{",
"if",
"(",
"file",
"===",
"undefined",
"||",
"file",
"===",
"null",
")",
"{",
"return",
";",
"}",
"fs",
".",
"appendFile",
"(",
"file",
",",
"line",
"+",
"os",
".",
"EOL",
",",
"{",
"}",
",",
"function",
"(",
")",
"{",
"//",
"}",
")",
";",
"}"
] | Appends line to a file if Logger.file is specified. | [
"Appends",
"line",
"to",
"a",
"file",
"if",
"Logger",
".",
"file",
"is",
"specified",
"."
] | 92965144fcc87fa54b15b82843b651af4b980c0d | https://github.com/garyns/OneLineLogger/blob/92965144fcc87fa54b15b82843b651af4b980c0d/onelinelogger.js#L234-L243 |
54,752 | yoshuawuyts/linkstash | index.js | Stash | function Stash(nlz) {
if (!(this instanceof Stash)) return new Stash(nlz);
nlz = nlz || function(val) {return val};
assert.equal(typeof nlz, 'function', 'linkstash: nlz should be a function');
this._prev = null;
this._next = null;
this._nlz = nlz;
return this;
} | javascript | function Stash(nlz) {
if (!(this instanceof Stash)) return new Stash(nlz);
nlz = nlz || function(val) {return val};
assert.equal(typeof nlz, 'function', 'linkstash: nlz should be a function');
this._prev = null;
this._next = null;
this._nlz = nlz;
return this;
} | [
"function",
"Stash",
"(",
"nlz",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Stash",
")",
")",
"return",
"new",
"Stash",
"(",
"nlz",
")",
";",
"nlz",
"=",
"nlz",
"||",
"function",
"(",
"val",
")",
"{",
"return",
"val",
"}",
";",
"assert",
".",
"equal",
"(",
"typeof",
"nlz",
",",
"'function'",
",",
"'linkstash: nlz should be a function'",
")",
";",
"this",
".",
"_prev",
"=",
"null",
";",
"this",
".",
"_next",
"=",
"null",
";",
"this",
".",
"_nlz",
"=",
"nlz",
";",
"return",
"this",
";",
"}"
] | Update the API links object. Diffs the prev
timestamp in links and updates if
it exceeds the timestamp threshold.
@param {String} prev
@param {String} next
@api private | [
"Update",
"the",
"API",
"links",
"object",
".",
"Diffs",
"the",
"prev",
"timestamp",
"in",
"links",
"and",
"updates",
"if",
"it",
"exceeds",
"the",
"timestamp",
"threshold",
"."
] | 232f576893f7311e2541c5aa5e7d1d5b78eed500 | https://github.com/yoshuawuyts/linkstash/blob/232f576893f7311e2541c5aa5e7d1d5b78eed500/index.js#L29-L40 |
54,753 | raincatcher-beta/raincatcher-sync | lib/client/mediator-subscribers/create-spec.js | checkMocksCalled | function checkMocksCalled(createResult) {
expect(createResult).to.deep.equal(createResult);
sinon.assert.calledOnce(mockDatasetManager.create);
sinon.assert.calledWith(mockDatasetManager.create, sinon.match(mockDataToCreate));
} | javascript | function checkMocksCalled(createResult) {
expect(createResult).to.deep.equal(createResult);
sinon.assert.calledOnce(mockDatasetManager.create);
sinon.assert.calledWith(mockDatasetManager.create, sinon.match(mockDataToCreate));
} | [
"function",
"checkMocksCalled",
"(",
"createResult",
")",
"{",
"expect",
"(",
"createResult",
")",
".",
"to",
".",
"deep",
".",
"equal",
"(",
"createResult",
")",
";",
"sinon",
".",
"assert",
".",
"calledOnce",
"(",
"mockDatasetManager",
".",
"create",
")",
";",
"sinon",
".",
"assert",
".",
"calledWith",
"(",
"mockDatasetManager",
".",
"create",
",",
"sinon",
".",
"match",
"(",
"mockDataToCreate",
")",
")",
";",
"}"
] | Verifying the mocks were called with the correct parameters. | [
"Verifying",
"the",
"mocks",
"were",
"called",
"with",
"the",
"correct",
"parameters",
"."
] | a51eeb8fdea30a6afdcd0587019bd1148bf30468 | https://github.com/raincatcher-beta/raincatcher-sync/blob/a51eeb8fdea30a6afdcd0587019bd1148bf30468/lib/client/mediator-subscribers/create-spec.js#L52-L57 |
54,754 | jldec/pub-preview | jqueryview.js | nav | function nav(path, query, hash, forceReload) {
var reload = forceReload || !path;
path = path || location.pathname;
query = query || (reload && location.search) || '';
hash = hash || (reload && location.hash) || '';
var newpage = generator.findPage(path);
if (!newpage) return generator.emit('notify', 'Oops, jqueryview cannot find new page object ' + path);
var oldpath = u.unPrefix(location.pathname, opts.staticRoot);
var oldpage = generator.findPage(oldpath);
if (!oldpage) return generator.emit('notify', 'Oops, jqueryview cannot find current page object ' + oldpath);
if (!reload && newpage === oldpage) return; // hash navigation doesn't require repaint
// simulate server-side request
generator.req = { query: query ? require('querystring').parse(query.slice(1)) : {} };
if ($layout.length && (reload || layoutChanged(oldpage, newpage))) {
updateLayout();
return;
}
// else just update page
updatePage();
///// helper functions /////
function updateLayout() {
var layout = generator.layoutTemplate(newpage);
$layout.html(generator.renderLayout(newpage));
$layout.attr('data-render-layout', layout);
log('jqueryview updateLayout', path, query, hash);
generator.emit('update-view', path, query, hash, window, $layout);
}
function updatePage() {
var $page = $('[data-render-page]');
if (!$page.length) return generator.emit('notify', 'Oops, jqueryview cannot update page ' + path);
$page.html(generator.renderPage(newpage));
$page.attr('data-render-page', newpage._href);
log('jqueryview updatePage:', path, query, hash)
generator.emit('update-view', path, query, hash, window, $page);
}
// return true if newpage layout is different from current layout
function layoutChanged(oldpage, newpage) {
if (oldpage && oldpage.fixlayout) return true;
if (lang(oldpage) !== lang(newpage)) return true;
var currentlayout = $layout.attr('data-render-layout') || 'main-layout';
var newlayout = generator.layoutTemplate(newpage);
return (newlayout !== currentlayout);
}
} | javascript | function nav(path, query, hash, forceReload) {
var reload = forceReload || !path;
path = path || location.pathname;
query = query || (reload && location.search) || '';
hash = hash || (reload && location.hash) || '';
var newpage = generator.findPage(path);
if (!newpage) return generator.emit('notify', 'Oops, jqueryview cannot find new page object ' + path);
var oldpath = u.unPrefix(location.pathname, opts.staticRoot);
var oldpage = generator.findPage(oldpath);
if (!oldpage) return generator.emit('notify', 'Oops, jqueryview cannot find current page object ' + oldpath);
if (!reload && newpage === oldpage) return; // hash navigation doesn't require repaint
// simulate server-side request
generator.req = { query: query ? require('querystring').parse(query.slice(1)) : {} };
if ($layout.length && (reload || layoutChanged(oldpage, newpage))) {
updateLayout();
return;
}
// else just update page
updatePage();
///// helper functions /////
function updateLayout() {
var layout = generator.layoutTemplate(newpage);
$layout.html(generator.renderLayout(newpage));
$layout.attr('data-render-layout', layout);
log('jqueryview updateLayout', path, query, hash);
generator.emit('update-view', path, query, hash, window, $layout);
}
function updatePage() {
var $page = $('[data-render-page]');
if (!$page.length) return generator.emit('notify', 'Oops, jqueryview cannot update page ' + path);
$page.html(generator.renderPage(newpage));
$page.attr('data-render-page', newpage._href);
log('jqueryview updatePage:', path, query, hash)
generator.emit('update-view', path, query, hash, window, $page);
}
// return true if newpage layout is different from current layout
function layoutChanged(oldpage, newpage) {
if (oldpage && oldpage.fixlayout) return true;
if (lang(oldpage) !== lang(newpage)) return true;
var currentlayout = $layout.attr('data-render-layout') || 'main-layout';
var newlayout = generator.layoutTemplate(newpage);
return (newlayout !== currentlayout);
}
} | [
"function",
"nav",
"(",
"path",
",",
"query",
",",
"hash",
",",
"forceReload",
")",
"{",
"var",
"reload",
"=",
"forceReload",
"||",
"!",
"path",
";",
"path",
"=",
"path",
"||",
"location",
".",
"pathname",
";",
"query",
"=",
"query",
"||",
"(",
"reload",
"&&",
"location",
".",
"search",
")",
"||",
"''",
";",
"hash",
"=",
"hash",
"||",
"(",
"reload",
"&&",
"location",
".",
"hash",
")",
"||",
"''",
";",
"var",
"newpage",
"=",
"generator",
".",
"findPage",
"(",
"path",
")",
";",
"if",
"(",
"!",
"newpage",
")",
"return",
"generator",
".",
"emit",
"(",
"'notify'",
",",
"'Oops, jqueryview cannot find new page object '",
"+",
"path",
")",
";",
"var",
"oldpath",
"=",
"u",
".",
"unPrefix",
"(",
"location",
".",
"pathname",
",",
"opts",
".",
"staticRoot",
")",
";",
"var",
"oldpage",
"=",
"generator",
".",
"findPage",
"(",
"oldpath",
")",
";",
"if",
"(",
"!",
"oldpage",
")",
"return",
"generator",
".",
"emit",
"(",
"'notify'",
",",
"'Oops, jqueryview cannot find current page object '",
"+",
"oldpath",
")",
";",
"if",
"(",
"!",
"reload",
"&&",
"newpage",
"===",
"oldpage",
")",
"return",
";",
"// hash navigation doesn't require repaint",
"// simulate server-side request",
"generator",
".",
"req",
"=",
"{",
"query",
":",
"query",
"?",
"require",
"(",
"'querystring'",
")",
".",
"parse",
"(",
"query",
".",
"slice",
"(",
"1",
")",
")",
":",
"{",
"}",
"}",
";",
"if",
"(",
"$layout",
".",
"length",
"&&",
"(",
"reload",
"||",
"layoutChanged",
"(",
"oldpage",
",",
"newpage",
")",
")",
")",
"{",
"updateLayout",
"(",
")",
";",
"return",
";",
"}",
"// else just update page",
"updatePage",
"(",
")",
";",
"///// helper functions /////",
"function",
"updateLayout",
"(",
")",
"{",
"var",
"layout",
"=",
"generator",
".",
"layoutTemplate",
"(",
"newpage",
")",
";",
"$layout",
".",
"html",
"(",
"generator",
".",
"renderLayout",
"(",
"newpage",
")",
")",
";",
"$layout",
".",
"attr",
"(",
"'data-render-layout'",
",",
"layout",
")",
";",
"log",
"(",
"'jqueryview updateLayout'",
",",
"path",
",",
"query",
",",
"hash",
")",
";",
"generator",
".",
"emit",
"(",
"'update-view'",
",",
"path",
",",
"query",
",",
"hash",
",",
"window",
",",
"$layout",
")",
";",
"}",
"function",
"updatePage",
"(",
")",
"{",
"var",
"$page",
"=",
"$",
"(",
"'[data-render-page]'",
")",
";",
"if",
"(",
"!",
"$page",
".",
"length",
")",
"return",
"generator",
".",
"emit",
"(",
"'notify'",
",",
"'Oops, jqueryview cannot update page '",
"+",
"path",
")",
";",
"$page",
".",
"html",
"(",
"generator",
".",
"renderPage",
"(",
"newpage",
")",
")",
";",
"$page",
".",
"attr",
"(",
"'data-render-page'",
",",
"newpage",
".",
"_href",
")",
";",
"log",
"(",
"'jqueryview updatePage:'",
",",
"path",
",",
"query",
",",
"hash",
")",
"generator",
".",
"emit",
"(",
"'update-view'",
",",
"path",
",",
"query",
",",
"hash",
",",
"window",
",",
"$page",
")",
";",
"}",
"// return true if newpage layout is different from current layout",
"function",
"layoutChanged",
"(",
"oldpage",
",",
"newpage",
")",
"{",
"if",
"(",
"oldpage",
"&&",
"oldpage",
".",
"fixlayout",
")",
"return",
"true",
";",
"if",
"(",
"lang",
"(",
"oldpage",
")",
"!==",
"lang",
"(",
"newpage",
")",
")",
"return",
"true",
";",
"var",
"currentlayout",
"=",
"$layout",
".",
"attr",
"(",
"'data-render-layout'",
")",
"||",
"'main-layout'",
";",
"var",
"newlayout",
"=",
"generator",
".",
"layoutTemplate",
"(",
"newpage",
")",
";",
"return",
"(",
"newlayout",
"!==",
"currentlayout",
")",
";",
"}",
"}"
] | navigate or reload by regenerating just the page or the whole layout | [
"navigate",
"or",
"reload",
"by",
"regenerating",
"just",
"the",
"page",
"or",
"the",
"whole",
"layout"
] | 55df6500200cbad4a4a03d8da86fef5b3ea9342c | https://github.com/jldec/pub-preview/blob/55df6500200cbad4a4a03d8da86fef5b3ea9342c/jqueryview.js#L49-L106 |
54,755 | jldec/pub-preview | jqueryview.js | layoutChanged | function layoutChanged(oldpage, newpage) {
if (oldpage && oldpage.fixlayout) return true;
if (lang(oldpage) !== lang(newpage)) return true;
var currentlayout = $layout.attr('data-render-layout') || 'main-layout';
var newlayout = generator.layoutTemplate(newpage);
return (newlayout !== currentlayout);
} | javascript | function layoutChanged(oldpage, newpage) {
if (oldpage && oldpage.fixlayout) return true;
if (lang(oldpage) !== lang(newpage)) return true;
var currentlayout = $layout.attr('data-render-layout') || 'main-layout';
var newlayout = generator.layoutTemplate(newpage);
return (newlayout !== currentlayout);
} | [
"function",
"layoutChanged",
"(",
"oldpage",
",",
"newpage",
")",
"{",
"if",
"(",
"oldpage",
"&&",
"oldpage",
".",
"fixlayout",
")",
"return",
"true",
";",
"if",
"(",
"lang",
"(",
"oldpage",
")",
"!==",
"lang",
"(",
"newpage",
")",
")",
"return",
"true",
";",
"var",
"currentlayout",
"=",
"$layout",
".",
"attr",
"(",
"'data-render-layout'",
")",
"||",
"'main-layout'",
";",
"var",
"newlayout",
"=",
"generator",
".",
"layoutTemplate",
"(",
"newpage",
")",
";",
"return",
"(",
"newlayout",
"!==",
"currentlayout",
")",
";",
"}"
] | return true if newpage layout is different from current layout | [
"return",
"true",
"if",
"newpage",
"layout",
"is",
"different",
"from",
"current",
"layout"
] | 55df6500200cbad4a4a03d8da86fef5b3ea9342c | https://github.com/jldec/pub-preview/blob/55df6500200cbad4a4a03d8da86fef5b3ea9342c/jqueryview.js#L98-L104 |
54,756 | jldec/pub-preview | jqueryview.js | updateHtml | function updateHtml(href) {
var fragment = generator.fragment$[href];
if (!fragment) return generator.emit('notify', 'Oops, jqueryview cannot find fragment: ' + href);
var $html = $('[data-render-html="' + href + '"]');
if (!$html.length) return generator.emit('notify', 'Oops, jqueryview cannot update html for fragment: ' + href);
$html.html(generator.renderHtml(fragment));
log('jqueryview updateHtml', location.pathname, location.search, location.hash);
generator.emit('update-view', location.pathname, location.search, location.hash, window, $html);
} | javascript | function updateHtml(href) {
var fragment = generator.fragment$[href];
if (!fragment) return generator.emit('notify', 'Oops, jqueryview cannot find fragment: ' + href);
var $html = $('[data-render-html="' + href + '"]');
if (!$html.length) return generator.emit('notify', 'Oops, jqueryview cannot update html for fragment: ' + href);
$html.html(generator.renderHtml(fragment));
log('jqueryview updateHtml', location.pathname, location.search, location.hash);
generator.emit('update-view', location.pathname, location.search, location.hash, window, $html);
} | [
"function",
"updateHtml",
"(",
"href",
")",
"{",
"var",
"fragment",
"=",
"generator",
".",
"fragment$",
"[",
"href",
"]",
";",
"if",
"(",
"!",
"fragment",
")",
"return",
"generator",
".",
"emit",
"(",
"'notify'",
",",
"'Oops, jqueryview cannot find fragment: '",
"+",
"href",
")",
";",
"var",
"$html",
"=",
"$",
"(",
"'[data-render-html=\"'",
"+",
"href",
"+",
"'\"]'",
")",
";",
"if",
"(",
"!",
"$html",
".",
"length",
")",
"return",
"generator",
".",
"emit",
"(",
"'notify'",
",",
"'Oops, jqueryview cannot update html for fragment: '",
"+",
"href",
")",
";",
"$html",
".",
"html",
"(",
"generator",
".",
"renderHtml",
"(",
"fragment",
")",
")",
";",
"log",
"(",
"'jqueryview updateHtml'",
",",
"location",
".",
"pathname",
",",
"location",
".",
"search",
",",
"location",
".",
"hash",
")",
";",
"generator",
".",
"emit",
"(",
"'update-view'",
",",
"location",
".",
"pathname",
",",
"location",
".",
"search",
",",
"location",
".",
"hash",
",",
"window",
",",
"$html",
")",
";",
"}"
] | this won't work if the href of a fragment is edited | [
"this",
"won",
"t",
"work",
"if",
"the",
"href",
"of",
"a",
"fragment",
"is",
"edited"
] | 55df6500200cbad4a4a03d8da86fef5b3ea9342c | https://github.com/jldec/pub-preview/blob/55df6500200cbad4a4a03d8da86fef5b3ea9342c/jqueryview.js#L109-L119 |
54,757 | diggerio/digger-level | db/append.js | appendModel | function appendModel(url, model, done){
var list = utils.flatten_tree(JSON.parse(JSON.stringify(model)))
var errormodel = null
list = list.filter(function(model){
if(!model._digger.path || !model._digger.inode){
errormodel = model;
return false;
}
return true
})
if(errormodel){
return done('no path or inode in level-append: ' + JSON.stringify(model))
}
var batch = list.map(function(model){
return {
type:'put',
key:model._digger.path + '/' + model._digger.inode,
value:model
}
})
tree.batch(batch, function(err){
if(err) return done(err)
done(null, model)
})
} | javascript | function appendModel(url, model, done){
var list = utils.flatten_tree(JSON.parse(JSON.stringify(model)))
var errormodel = null
list = list.filter(function(model){
if(!model._digger.path || !model._digger.inode){
errormodel = model;
return false;
}
return true
})
if(errormodel){
return done('no path or inode in level-append: ' + JSON.stringify(model))
}
var batch = list.map(function(model){
return {
type:'put',
key:model._digger.path + '/' + model._digger.inode,
value:model
}
})
tree.batch(batch, function(err){
if(err) return done(err)
done(null, model)
})
} | [
"function",
"appendModel",
"(",
"url",
",",
"model",
",",
"done",
")",
"{",
"var",
"list",
"=",
"utils",
".",
"flatten_tree",
"(",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"model",
")",
")",
")",
"var",
"errormodel",
"=",
"null",
"list",
"=",
"list",
".",
"filter",
"(",
"function",
"(",
"model",
")",
"{",
"if",
"(",
"!",
"model",
".",
"_digger",
".",
"path",
"||",
"!",
"model",
".",
"_digger",
".",
"inode",
")",
"{",
"errormodel",
"=",
"model",
";",
"return",
"false",
";",
"}",
"return",
"true",
"}",
")",
"if",
"(",
"errormodel",
")",
"{",
"return",
"done",
"(",
"'no path or inode in level-append: '",
"+",
"JSON",
".",
"stringify",
"(",
"model",
")",
")",
"}",
"var",
"batch",
"=",
"list",
".",
"map",
"(",
"function",
"(",
"model",
")",
"{",
"return",
"{",
"type",
":",
"'put'",
",",
"key",
":",
"model",
".",
"_digger",
".",
"path",
"+",
"'/'",
"+",
"model",
".",
"_digger",
".",
"inode",
",",
"value",
":",
"model",
"}",
"}",
")",
"tree",
".",
"batch",
"(",
"batch",
",",
"function",
"(",
"err",
")",
"{",
"if",
"(",
"err",
")",
"return",
"done",
"(",
"err",
")",
"done",
"(",
"null",
",",
"model",
")",
"}",
")",
"}"
] | append a single model | [
"append",
"a",
"single",
"model"
] | 5ec947f28dd781171aa9db3fe457aee6b7b8c27d | https://github.com/diggerio/digger-level/blob/5ec947f28dd781171aa9db3fe457aee6b7b8c27d/db/append.js#L13-L42 |
54,758 | wilmoore/string-prepend.js | index.js | prepend | function prepend(pre) {
function prepender(string) { return pre + string; }
return arguments.length > 1
? prepender(arguments[1])
: prepender;
} | javascript | function prepend(pre) {
function prepender(string) { return pre + string; }
return arguments.length > 1
? prepender(arguments[1])
: prepender;
} | [
"function",
"prepend",
"(",
"pre",
")",
"{",
"function",
"prepender",
"(",
"string",
")",
"{",
"return",
"pre",
"+",
"string",
";",
"}",
"return",
"arguments",
".",
"length",
">",
"1",
"?",
"prepender",
"(",
"arguments",
"[",
"1",
"]",
")",
":",
"prepender",
";",
"}"
] | Curried `String.prototype.prepend`.
@param {String} pre
String to prepend to original string.
@param {String} string
Original string.
@return {String}
String consisting of prepended and original string. | [
"Curried",
"String",
".",
"prototype",
".",
"prepend",
"."
] | 00089b79d75edb76db27a5750682c418b86218c0 | https://github.com/wilmoore/string-prepend.js/blob/00089b79d75edb76db27a5750682c418b86218c0/index.js#L22-L28 |
54,759 | nwoltman/pro-array | pro-array.js | function(value, compareFunction) {
var low = 0;
var high = this.length;
var mid;
if (compareFunction) {
while (low < high) {
mid = low + high >>> 1;
var direction = compareFunction(this[mid], value);
if (!direction) {
return mid;
}
if (direction < 0) {
low = mid + 1;
} else {
high = mid;
}
}
} else {
while (low < high) {
mid = low + high >>> 1;
if (this[mid] === value) {
return mid;
}
if (this[mid] < value) {
low = mid + 1;
} else {
high = mid;
}
}
}
return -1;
} | javascript | function(value, compareFunction) {
var low = 0;
var high = this.length;
var mid;
if (compareFunction) {
while (low < high) {
mid = low + high >>> 1;
var direction = compareFunction(this[mid], value);
if (!direction) {
return mid;
}
if (direction < 0) {
low = mid + 1;
} else {
high = mid;
}
}
} else {
while (low < high) {
mid = low + high >>> 1;
if (this[mid] === value) {
return mid;
}
if (this[mid] < value) {
low = mid + 1;
} else {
high = mid;
}
}
}
return -1;
} | [
"function",
"(",
"value",
",",
"compareFunction",
")",
"{",
"var",
"low",
"=",
"0",
";",
"var",
"high",
"=",
"this",
".",
"length",
";",
"var",
"mid",
";",
"if",
"(",
"compareFunction",
")",
"{",
"while",
"(",
"low",
"<",
"high",
")",
"{",
"mid",
"=",
"low",
"+",
"high",
">>>",
"1",
";",
"var",
"direction",
"=",
"compareFunction",
"(",
"this",
"[",
"mid",
"]",
",",
"value",
")",
";",
"if",
"(",
"!",
"direction",
")",
"{",
"return",
"mid",
";",
"}",
"if",
"(",
"direction",
"<",
"0",
")",
"{",
"low",
"=",
"mid",
"+",
"1",
";",
"}",
"else",
"{",
"high",
"=",
"mid",
";",
"}",
"}",
"}",
"else",
"{",
"while",
"(",
"low",
"<",
"high",
")",
"{",
"mid",
"=",
"low",
"+",
"high",
">>>",
"1",
";",
"if",
"(",
"this",
"[",
"mid",
"]",
"===",
"value",
")",
"{",
"return",
"mid",
";",
"}",
"if",
"(",
"this",
"[",
"mid",
"]",
"<",
"value",
")",
"{",
"low",
"=",
"mid",
"+",
"1",
";",
"}",
"else",
"{",
"high",
"=",
"mid",
";",
"}",
"}",
"}",
"return",
"-",
"1",
";",
"}"
] | Finds the index of a value in a sorted array using a binary search algorithm.
If no `compareFunction` is supplied, the `>` and `<` relational operators are used to compare values,
which provides optimal performance for arrays of numbers and simple strings.
@function Array#bsearch
@param {*} value - The value to search for.
@param {Function} [compareFunction] - The same type of comparing function you would pass to
[`.sort()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort).
@returns {number} The index of the value if it is in the array, or `-1` if it cannot be found.
If the search value can be found at multiple indexes in the array, it is unknown which of
those indexes will be returned.
@example
['a', 'b', 'c', 'd'].bsearch('c');
// -> 2
[1, 1, 2, 2].bsearch(2);
// -> 2 or 3
[1, 2, 3, 4].bsearch(10);
// -> -1
// Search an array of people sorted by age
var finn = {name: 'Finn', age: 12};
var jake = {name: 'Jake', age: 28};
[finn, jake].bsearch(finn, function(a, b) {
return a.age - b.age;
});
// -> 0
['img1', 'img2', 'img10', 'img13'].bsearch('img2', naturalCompare);
// -> 1
// `naturalCompare` is provided by the string-natural-compare npm module:
// https://www.npmjs.com/package/string-natural-compare | [
"Finds",
"the",
"index",
"of",
"a",
"value",
"in",
"a",
"sorted",
"array",
"using",
"a",
"binary",
"search",
"algorithm",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L136-L169 |
|
54,760 | nwoltman/pro-array | pro-array.js | function(size) {
size = size || 1;
var numChunks = Math.ceil(this.length / size);
var result = new Array(numChunks);
for (var i = 0, index = 0; i < numChunks; i++) {
result[i] = chunkSlice(this, index, index += size);
}
return result;
} | javascript | function(size) {
size = size || 1;
var numChunks = Math.ceil(this.length / size);
var result = new Array(numChunks);
for (var i = 0, index = 0; i < numChunks; i++) {
result[i] = chunkSlice(this, index, index += size);
}
return result;
} | [
"function",
"(",
"size",
")",
"{",
"size",
"=",
"size",
"||",
"1",
";",
"var",
"numChunks",
"=",
"Math",
".",
"ceil",
"(",
"this",
".",
"length",
"/",
"size",
")",
";",
"var",
"result",
"=",
"new",
"Array",
"(",
"numChunks",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"index",
"=",
"0",
";",
"i",
"<",
"numChunks",
";",
"i",
"++",
")",
"{",
"result",
"[",
"i",
"]",
"=",
"chunkSlice",
"(",
"this",
",",
"index",
",",
"index",
"+=",
"size",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Creates an array of elements split into groups the length of `size`. If the array
can't be split evenly, the final chunk will be the remaining elements.
@function Array#chunk
@param {number} [size=1] - The length of each chunk.
@returns {Array} An array containing the chunks.
@throws {RangeError} Throws when `size` is a negative number.
@example
[1, 2, 3, 4].chunk(2);
// -> [[1, 2], [3, 4]]
[1, 2, 3, 4].chunk(3);
// -> [[1, 2, 3], [4]] | [
"Creates",
"an",
"array",
"of",
"elements",
"split",
"into",
"groups",
"the",
"length",
"of",
"size",
".",
"If",
"the",
"array",
"can",
"t",
"be",
"split",
"evenly",
"the",
"final",
"chunk",
"will",
"be",
"the",
"remaining",
"elements",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L187-L198 |
|
54,761 | nwoltman/pro-array | pro-array.js | function() {
var result = [];
for (var i = 0; i < this.length; i++) {
var value = this[i];
if (Array.isArray(value)) {
for (var j = 0; j < value.length; j++) {
result.push(value[j]);
}
} else {
result.push(value);
}
}
return result;
} | javascript | function() {
var result = [];
for (var i = 0; i < this.length; i++) {
var value = this[i];
if (Array.isArray(value)) {
for (var j = 0; j < value.length; j++) {
result.push(value[j]);
}
} else {
result.push(value);
}
}
return result;
} | [
"function",
"(",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"value",
"=",
"this",
"[",
"i",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"value",
".",
"length",
";",
"j",
"++",
")",
"{",
"result",
".",
"push",
"(",
"value",
"[",
"j",
"]",
")",
";",
"}",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"value",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Flattens a nested array a single level.
@function Array#flatten
@returns {Array} The new flattened array.
@example
[1, [2, 3, [4]], 5].flatten();
// -> [1, 2, 3, [4], 5] | [
"Flattens",
"a",
"nested",
"array",
"a",
"single",
"level",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L402-L417 |
|
54,762 | nwoltman/pro-array | pro-array.js | function() {
var remStartIndex = 0;
var numToRemove = 0;
for (var i = 0; i < this.length; i++) {
var removeCurrentIndex = false;
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
removeCurrentIndex = true;
break;
}
}
if (removeCurrentIndex) {
if (!numToRemove) {
remStartIndex = i;
}
++numToRemove;
} else if (numToRemove) {
this.splice(remStartIndex, numToRemove);
i -= numToRemove;
numToRemove = 0;
}
}
if (numToRemove) {
this.splice(remStartIndex, numToRemove);
}
return this;
} | javascript | function() {
var remStartIndex = 0;
var numToRemove = 0;
for (var i = 0; i < this.length; i++) {
var removeCurrentIndex = false;
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
removeCurrentIndex = true;
break;
}
}
if (removeCurrentIndex) {
if (!numToRemove) {
remStartIndex = i;
}
++numToRemove;
} else if (numToRemove) {
this.splice(remStartIndex, numToRemove);
i -= numToRemove;
numToRemove = 0;
}
}
if (numToRemove) {
this.splice(remStartIndex, numToRemove);
}
return this;
} | [
"function",
"(",
")",
"{",
"var",
"remStartIndex",
"=",
"0",
";",
"var",
"numToRemove",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"removeCurrentIndex",
"=",
"false",
";",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"arguments",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"this",
"[",
"i",
"]",
"===",
"arguments",
"[",
"j",
"]",
")",
"{",
"removeCurrentIndex",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"removeCurrentIndex",
")",
"{",
"if",
"(",
"!",
"numToRemove",
")",
"{",
"remStartIndex",
"=",
"i",
";",
"}",
"++",
"numToRemove",
";",
"}",
"else",
"if",
"(",
"numToRemove",
")",
"{",
"this",
".",
"splice",
"(",
"remStartIndex",
",",
"numToRemove",
")",
";",
"i",
"-=",
"numToRemove",
";",
"numToRemove",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"numToRemove",
")",
"{",
"this",
".",
"splice",
"(",
"remStartIndex",
",",
"numToRemove",
")",
";",
"}",
"return",
"this",
";",
"}"
] | Removes all occurrences of the passed in items from the array and returns the array.
__Note:__ Unlike {@link Array#without|`.without()`}, this method mutates the array.
@function Array#remove
@param {...*} items - Items to remove from the array.
@returns {Array} The array this method was called on.
@example
var array = [1, 2, 3, 3, 4, 3, 5];
array.remove(1);
// -> [2, 3, 3, 4, 3, 5]
array.remove(3);
// -> [2, 4, 5]
array.remove(2, 5);
// -> [4] | [
"Removes",
"all",
"occurrences",
"of",
"the",
"passed",
"in",
"items",
"from",
"the",
"array",
"and",
"returns",
"the",
"array",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L601-L632 |
|
54,763 | nwoltman/pro-array | pro-array.js | function(isSorted) {
var result = [];
var length = this.length;
if (!length) {
return result;
}
result[0] = this[0];
var i = 1;
if (isSorted) {
for (; i < length; i++) {
if (this[i] !== this[i - 1]) {
result.push(this[i]);
}
}
} else {
for (; i < length; i++) {
if (result.indexOf(this[i]) < 0) {
result.push(this[i]);
}
}
}
return result;
} | javascript | function(isSorted) {
var result = [];
var length = this.length;
if (!length) {
return result;
}
result[0] = this[0];
var i = 1;
if (isSorted) {
for (; i < length; i++) {
if (this[i] !== this[i - 1]) {
result.push(this[i]);
}
}
} else {
for (; i < length; i++) {
if (result.indexOf(this[i]) < 0) {
result.push(this[i]);
}
}
}
return result;
} | [
"function",
"(",
"isSorted",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"length",
"=",
"this",
".",
"length",
";",
"if",
"(",
"!",
"length",
")",
"{",
"return",
"result",
";",
"}",
"result",
"[",
"0",
"]",
"=",
"this",
"[",
"0",
"]",
";",
"var",
"i",
"=",
"1",
";",
"if",
"(",
"isSorted",
")",
"{",
"for",
"(",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
"[",
"i",
"]",
"!==",
"this",
"[",
"i",
"-",
"1",
"]",
")",
"{",
"result",
".",
"push",
"(",
"this",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"result",
".",
"indexOf",
"(",
"this",
"[",
"i",
"]",
")",
"<",
"0",
")",
"{",
"result",
".",
"push",
"(",
"this",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}",
"return",
"result",
";",
"}"
] | Returns a duplicate-free clone of the array.
@function Array#unique
@param {boolean} [isSorted=false] - If the array's contents are sorted and this is set to `true`,
a faster algorithm will be used to create the unique array.
@returns {Array} The new, duplicate-free array.
@example
// Unsorted
[4, 2, 3, 2, 1, 4].unique();
// -> [4, 2, 3, 1]
// Sorted
[1, 2, 2, 3, 4, 4].unique();
// -> [1, 2, 3, 4]
[1, 2, 2, 3, 4, 4].unique(true);
// -> [1, 2, 3, 4] (but faster than the previous example) | [
"Returns",
"a",
"duplicate",
"-",
"free",
"clone",
"of",
"the",
"array",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L684-L710 |
|
54,764 | nwoltman/pro-array | pro-array.js | function() {
var result = [];
next: for (var i = 0; i < this.length; i++) {
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
continue next;
}
}
result.push(this[i]);
}
return result;
} | javascript | function() {
var result = [];
next: for (var i = 0; i < this.length; i++) {
for (var j = 0; j < arguments.length; j++) {
if (this[i] === arguments[j]) {
continue next;
}
}
result.push(this[i]);
}
return result;
} | [
"function",
"(",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"next",
":",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"length",
";",
"i",
"++",
")",
"{",
"for",
"(",
"var",
"j",
"=",
"0",
";",
"j",
"<",
"arguments",
".",
"length",
";",
"j",
"++",
")",
"{",
"if",
"(",
"this",
"[",
"i",
"]",
"===",
"arguments",
"[",
"j",
"]",
")",
"{",
"continue",
"next",
";",
"}",
"}",
"result",
".",
"push",
"(",
"this",
"[",
"i",
"]",
")",
";",
"}",
"return",
"result",
";",
"}"
] | Returns a copy of the array without any elements from the input parameters.
@function Array#without
@param {...*} items - Items to leave out of the returned array.
@returns {Array} The new array of filtered values.
@example
[1, 2, 3, 4].without(2, 4);
// -> [1, 3]
[1, 1].without(1);
// -> [] | [
"Returns",
"a",
"copy",
"of",
"the",
"array",
"without",
"any",
"elements",
"from",
"the",
"input",
"parameters",
"."
] | c61a7be99e932912f95e553b57bf1bca16e3c709 | https://github.com/nwoltman/pro-array/blob/c61a7be99e932912f95e553b57bf1bca16e3c709/pro-array.js#L726-L739 |
|
54,765 | Cereceres/flatten-array | index.js | flattenArray | function flattenArray(arrayToFlatten, arrayFlatten) {
// check if the arg is a array, if not a error is thrown
if(!Array.isArray(arrayToFlatten)) throw new Error('Only can flat arrays and you pass a ' + typeof arrayToFlatten)
// set the default value of arrayFlatten, this validation is used only in the first call of
// recursive function
arrayFlatten = arrayFlatten || []
// loop over the array to get flatten the array
for (let i = 0; i < arrayToFlatten.length; ++i) {
// if the item in the arrray is a array then the flattenArray function is callen again
if (Array.isArray(arrayToFlatten[i])) {
// the function is called with the element what is a array and pass the arrayFlatten as second arg
flattenArray(arrayToFlatten[i], arrayFlatten)
// break the loop
continue
}
// if the element is not a array only push the element
arrayFlatten.push(arrayToFlatten[i]);
}
// return the array flatten
return arrayFlatten
} | javascript | function flattenArray(arrayToFlatten, arrayFlatten) {
// check if the arg is a array, if not a error is thrown
if(!Array.isArray(arrayToFlatten)) throw new Error('Only can flat arrays and you pass a ' + typeof arrayToFlatten)
// set the default value of arrayFlatten, this validation is used only in the first call of
// recursive function
arrayFlatten = arrayFlatten || []
// loop over the array to get flatten the array
for (let i = 0; i < arrayToFlatten.length; ++i) {
// if the item in the arrray is a array then the flattenArray function is callen again
if (Array.isArray(arrayToFlatten[i])) {
// the function is called with the element what is a array and pass the arrayFlatten as second arg
flattenArray(arrayToFlatten[i], arrayFlatten)
// break the loop
continue
}
// if the element is not a array only push the element
arrayFlatten.push(arrayToFlatten[i]);
}
// return the array flatten
return arrayFlatten
} | [
"function",
"flattenArray",
"(",
"arrayToFlatten",
",",
"arrayFlatten",
")",
"{",
"// check if the arg is a array, if not a error is thrown",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"arrayToFlatten",
")",
")",
"throw",
"new",
"Error",
"(",
"'Only can flat arrays and you pass a '",
"+",
"typeof",
"arrayToFlatten",
")",
"// set the default value of arrayFlatten, this validation is used only in the first call of",
"// recursive function",
"arrayFlatten",
"=",
"arrayFlatten",
"||",
"[",
"]",
"// loop over the array to get flatten the array ",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"arrayToFlatten",
".",
"length",
";",
"++",
"i",
")",
"{",
"// if the item in the arrray is a array then the flattenArray function is callen again",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arrayToFlatten",
"[",
"i",
"]",
")",
")",
"{",
"// the function is called with the element what is a array and pass the arrayFlatten as second arg",
"flattenArray",
"(",
"arrayToFlatten",
"[",
"i",
"]",
",",
"arrayFlatten",
")",
"// break the loop",
"continue",
"}",
"// if the element is not a array only push the element",
"arrayFlatten",
".",
"push",
"(",
"arrayToFlatten",
"[",
"i",
"]",
")",
";",
"}",
"// return the array flatten",
"return",
"arrayFlatten",
"}"
] | recursive function to flatten a array of integers given
@func
@param {Array} - arrayToFlatten of integers | [
"recursive",
"function",
"to",
"flatten",
"a",
"array",
"of",
"integers",
"given"
] | 1ce0612a34ef235126384951c4abdef9a81c2099 | https://github.com/Cereceres/flatten-array/blob/1ce0612a34ef235126384951c4abdef9a81c2099/index.js#L7-L27 |
54,766 | RetailMeNotSandbox/grunt-hooks | tasks/grunt-hooks.js | nextQuestion | function nextQuestion() {
if ( !hooks.length ) {
if ( !!options.onDone ) {
grunt.log.writeln( '' );
grunt.log.writeln( options.onDone.blue );
}
done();
} else {
var hookConfig = hooks.shift();
promptHook( hookConfig );
}
} | javascript | function nextQuestion() {
if ( !hooks.length ) {
if ( !!options.onDone ) {
grunt.log.writeln( '' );
grunt.log.writeln( options.onDone.blue );
}
done();
} else {
var hookConfig = hooks.shift();
promptHook( hookConfig );
}
} | [
"function",
"nextQuestion",
"(",
")",
"{",
"if",
"(",
"!",
"hooks",
".",
"length",
")",
"{",
"if",
"(",
"!",
"!",
"options",
".",
"onDone",
")",
"{",
"grunt",
".",
"log",
".",
"writeln",
"(",
"''",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"options",
".",
"onDone",
".",
"blue",
")",
";",
"}",
"done",
"(",
")",
";",
"}",
"else",
"{",
"var",
"hookConfig",
"=",
"hooks",
".",
"shift",
"(",
")",
";",
"promptHook",
"(",
"hookConfig",
")",
";",
"}",
"}"
] | option passed to task via flag | [
"option",
"passed",
"to",
"task",
"via",
"flag"
] | 22611771304fb8a49552d25a10629f47bb415670 | https://github.com/RetailMeNotSandbox/grunt-hooks/blob/22611771304fb8a49552d25a10629f47bb415670/tasks/grunt-hooks.js#L20-L31 |
54,767 | RetailMeNotSandbox/grunt-hooks | tasks/grunt-hooks.js | actuallyInstallHook | function actuallyInstallHook(
hookToCopy,
whereToPutIt,
sourceCanonicalName
) {
mkpath.sync( path.join( './', path.dirname( whereToPutIt ) ) );
exec( 'cp ' + hookToCopy + ' ' + whereToPutIt );
grunt.log.writeln( [
'Installed ', sourceCanonicalName, ' hook in ', whereToPutIt
].join( '' ).green );
} | javascript | function actuallyInstallHook(
hookToCopy,
whereToPutIt,
sourceCanonicalName
) {
mkpath.sync( path.join( './', path.dirname( whereToPutIt ) ) );
exec( 'cp ' + hookToCopy + ' ' + whereToPutIt );
grunt.log.writeln( [
'Installed ', sourceCanonicalName, ' hook in ', whereToPutIt
].join( '' ).green );
} | [
"function",
"actuallyInstallHook",
"(",
"hookToCopy",
",",
"whereToPutIt",
",",
"sourceCanonicalName",
")",
"{",
"mkpath",
".",
"sync",
"(",
"path",
".",
"join",
"(",
"'./'",
",",
"path",
".",
"dirname",
"(",
"whereToPutIt",
")",
")",
")",
";",
"exec",
"(",
"'cp '",
"+",
"hookToCopy",
"+",
"' '",
"+",
"whereToPutIt",
")",
";",
"grunt",
".",
"log",
".",
"writeln",
"(",
"[",
"'Installed '",
",",
"sourceCanonicalName",
",",
"' hook in '",
",",
"whereToPutIt",
"]",
".",
"join",
"(",
"''",
")",
".",
"green",
")",
";",
"}"
] | Installs the hook without checking if it already exists | [
"Installs",
"the",
"hook",
"without",
"checking",
"if",
"it",
"already",
"exists"
] | 22611771304fb8a49552d25a10629f47bb415670 | https://github.com/RetailMeNotSandbox/grunt-hooks/blob/22611771304fb8a49552d25a10629f47bb415670/tasks/grunt-hooks.js#L109-L119 |
54,768 | gregtatum/npm-on-tap | on-tap.js | function(e) {
var touch = e.touches[0]
// Make sure click doesn't fire
touchClientX = touch.clientX
touchClientY = touch.clientY
timestamp = Date.now()
} | javascript | function(e) {
var touch = e.touches[0]
// Make sure click doesn't fire
touchClientX = touch.clientX
touchClientY = touch.clientY
timestamp = Date.now()
} | [
"function",
"(",
"e",
")",
"{",
"var",
"touch",
"=",
"e",
".",
"touches",
"[",
"0",
"]",
"// Make sure click doesn't fire",
"touchClientX",
"=",
"touch",
".",
"clientX",
"touchClientY",
"=",
"touch",
".",
"clientY",
"timestamp",
"=",
"Date",
".",
"now",
"(",
")",
"}"
] | Disable click if touch is fired | [
"Disable",
"click",
"if",
"touch",
"is",
"fired"
] | c0aecdea1edb0ce2b3c50b8e5ae6d09db92f3c78 | https://github.com/gregtatum/npm-on-tap/blob/c0aecdea1edb0ce2b3c50b8e5ae6d09db92f3c78/on-tap.js#L41-L49 |
|
54,769 | KyperTech/grout | examples/browser/app.js | login | function login(){
console.log('Login called');
var username = document.getElementById('login-username').value;
var password = document.getElementById('login-password').value;
// {username:username, password:password}
grout.login('google').then(function (loginInfo){
console.log('successful login:', loginInfo);
setStatus();
}, function (err){
console.error('login() : Error logging in:', err);
});
} | javascript | function login(){
console.log('Login called');
var username = document.getElementById('login-username').value;
var password = document.getElementById('login-password').value;
// {username:username, password:password}
grout.login('google').then(function (loginInfo){
console.log('successful login:', loginInfo);
setStatus();
}, function (err){
console.error('login() : Error logging in:', err);
});
} | [
"function",
"login",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Login called'",
")",
";",
"var",
"username",
"=",
"document",
".",
"getElementById",
"(",
"'login-username'",
")",
".",
"value",
";",
"var",
"password",
"=",
"document",
".",
"getElementById",
"(",
"'login-password'",
")",
".",
"value",
";",
"// {username:username, password:password}",
"grout",
".",
"login",
"(",
"'google'",
")",
".",
"then",
"(",
"function",
"(",
"loginInfo",
")",
"{",
"console",
".",
"log",
"(",
"'successful login:'",
",",
"loginInfo",
")",
";",
"setStatus",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'login() : Error logging in:'",
",",
"err",
")",
";",
"}",
")",
";",
"}"
] | Login user based on entered credentials | [
"Login",
"user",
"based",
"on",
"entered",
"credentials"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L25-L36 |
54,770 | KyperTech/grout | examples/browser/app.js | logout | function logout(){
console.log('Logout called');
grout.logout().then(function(){
console.log('successful logout');
setStatus();
}, function (err){
console.error('logout() : Error logging out:', err);
});
} | javascript | function logout(){
console.log('Logout called');
grout.logout().then(function(){
console.log('successful logout');
setStatus();
}, function (err){
console.error('logout() : Error logging out:', err);
});
} | [
"function",
"logout",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'Logout called'",
")",
";",
"grout",
".",
"logout",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'successful logout'",
")",
";",
"setStatus",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'logout() : Error logging out:'",
",",
"err",
")",
";",
"}",
")",
";",
"}"
] | Log currently logged in user out | [
"Log",
"currently",
"logged",
"in",
"user",
"out"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L38-L46 |
54,771 | KyperTech/grout | examples/browser/app.js | signup | function signup(){
console.log('signup called');
var name = document.getElementById('signup-name').value;
var username = document.getElementById('signup-username').value;
var email = document.getElementById('signup-email').value;
var password = document.getElementById('signup-password').value;
grout.signup().then(function(){
console.log('successful logout');
setStatus();
}, function(err){
console.error('logout() : Error logging out:', err);
});
} | javascript | function signup(){
console.log('signup called');
var name = document.getElementById('signup-name').value;
var username = document.getElementById('signup-username').value;
var email = document.getElementById('signup-email').value;
var password = document.getElementById('signup-password').value;
grout.signup().then(function(){
console.log('successful logout');
setStatus();
}, function(err){
console.error('logout() : Error logging out:', err);
});
} | [
"function",
"signup",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'signup called'",
")",
";",
"var",
"name",
"=",
"document",
".",
"getElementById",
"(",
"'signup-name'",
")",
".",
"value",
";",
"var",
"username",
"=",
"document",
".",
"getElementById",
"(",
"'signup-username'",
")",
".",
"value",
";",
"var",
"email",
"=",
"document",
".",
"getElementById",
"(",
"'signup-email'",
")",
".",
"value",
";",
"var",
"password",
"=",
"document",
".",
"getElementById",
"(",
"'signup-password'",
")",
".",
"value",
";",
"grout",
".",
"signup",
"(",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'successful logout'",
")",
";",
"setStatus",
"(",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'logout() : Error logging out:'",
",",
"err",
")",
";",
"}",
")",
";",
"}"
] | Signup and login as a new user | [
"Signup",
"and",
"login",
"as",
"a",
"new",
"user"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L48-L62 |
54,772 | KyperTech/grout | examples/browser/app.js | getProjects | function getProjects(){
console.log('getProjects called');
grout.Projects.get().then(function(appsList){
console.log('apps list loaded:', appsList);
var outHtml = '<h2>No app data</h2>';
if (appsList) {
outHtml = '<ul>';
appsList.forEach(function(app){
outHtml += '<li>' + app.name + '</li></br>'
});
outHtml += '</ul>';
}
document.getElementById("output").innerHTML = outHtml;
});
} | javascript | function getProjects(){
console.log('getProjects called');
grout.Projects.get().then(function(appsList){
console.log('apps list loaded:', appsList);
var outHtml = '<h2>No app data</h2>';
if (appsList) {
outHtml = '<ul>';
appsList.forEach(function(app){
outHtml += '<li>' + app.name + '</li></br>'
});
outHtml += '</ul>';
}
document.getElementById("output").innerHTML = outHtml;
});
} | [
"function",
"getProjects",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'getProjects called'",
")",
";",
"grout",
".",
"Projects",
".",
"get",
"(",
")",
".",
"then",
"(",
"function",
"(",
"appsList",
")",
"{",
"console",
".",
"log",
"(",
"'apps list loaded:'",
",",
"appsList",
")",
";",
"var",
"outHtml",
"=",
"'<h2>No app data</h2>'",
";",
"if",
"(",
"appsList",
")",
"{",
"outHtml",
"=",
"'<ul>'",
";",
"appsList",
".",
"forEach",
"(",
"function",
"(",
"app",
")",
"{",
"outHtml",
"+=",
"'<li>'",
"+",
"app",
".",
"name",
"+",
"'</li></br>'",
"}",
")",
";",
"outHtml",
"+=",
"'</ul>'",
";",
"}",
"document",
".",
"getElementById",
"(",
"\"output\"",
")",
".",
"innerHTML",
"=",
"outHtml",
";",
"}",
")",
";",
"}"
] | Get list of applications | [
"Get",
"list",
"of",
"applications"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L64-L78 |
54,773 | KyperTech/grout | examples/browser/app.js | getFile | function getFile() {
var file = grout.Project('test', 'scott').File({key: 'index.html', path: 'index.html'});
console.log('fbUrl', file.fbUrl);
console.log('fbRef', file.fbRef);
file.get().then(function(app){
console.log('file loaded:', app);
document.getElementById("output").innerHTML = JSON.stringify(app);
});
} | javascript | function getFile() {
var file = grout.Project('test', 'scott').File({key: 'index.html', path: 'index.html'});
console.log('fbUrl', file.fbUrl);
console.log('fbRef', file.fbRef);
file.get().then(function(app){
console.log('file loaded:', app);
document.getElementById("output").innerHTML = JSON.stringify(app);
});
} | [
"function",
"getFile",
"(",
")",
"{",
"var",
"file",
"=",
"grout",
".",
"Project",
"(",
"'test'",
",",
"'scott'",
")",
".",
"File",
"(",
"{",
"key",
":",
"'index.html'",
",",
"path",
":",
"'index.html'",
"}",
")",
";",
"console",
".",
"log",
"(",
"'fbUrl'",
",",
"file",
".",
"fbUrl",
")",
";",
"console",
".",
"log",
"(",
"'fbRef'",
",",
"file",
".",
"fbRef",
")",
";",
"file",
".",
"get",
"(",
")",
".",
"then",
"(",
"function",
"(",
"app",
")",
"{",
"console",
".",
"log",
"(",
"'file loaded:'",
",",
"app",
")",
";",
"document",
".",
"getElementById",
"(",
"\"output\"",
")",
".",
"innerHTML",
"=",
"JSON",
".",
"stringify",
"(",
"app",
")",
";",
"}",
")",
";",
"}"
] | Get single file content | [
"Get",
"single",
"file",
"content"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L81-L89 |
54,774 | KyperTech/grout | examples/browser/app.js | getUsers | function getUsers(){
console.log('getUsers called');
grout.Users.get().then(function(app){
console.log('apps list loaded:', app);
document.getElementById("output").innerHTML = JSON.stringify(app);
}, function(err){
console.error('Error getting users:', err);
});
} | javascript | function getUsers(){
console.log('getUsers called');
grout.Users.get().then(function(app){
console.log('apps list loaded:', app);
document.getElementById("output").innerHTML = JSON.stringify(app);
}, function(err){
console.error('Error getting users:', err);
});
} | [
"function",
"getUsers",
"(",
")",
"{",
"console",
".",
"log",
"(",
"'getUsers called'",
")",
";",
"grout",
".",
"Users",
".",
"get",
"(",
")",
".",
"then",
"(",
"function",
"(",
"app",
")",
"{",
"console",
".",
"log",
"(",
"'apps list loaded:'",
",",
"app",
")",
";",
"document",
".",
"getElementById",
"(",
"\"output\"",
")",
".",
"innerHTML",
"=",
"JSON",
".",
"stringify",
"(",
"app",
")",
";",
"}",
",",
"function",
"(",
"err",
")",
"{",
"console",
".",
"error",
"(",
"'Error getting users:'",
",",
"err",
")",
";",
"}",
")",
";",
"}"
] | Get list of users | [
"Get",
"list",
"of",
"users"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L134-L142 |
54,775 | KyperTech/grout | examples/browser/app.js | searchUsers | function searchUsers(searchStr){
console.log('getUsers called');
if(!searchStr){
searchStr = document.getElementById('search').value;
}
grout.Users.search(searchStr).then(function(users){
console.log('search users loaded:', users);
document.getElementById("search-output").innerHTML = JSON.stringify(users);
});
} | javascript | function searchUsers(searchStr){
console.log('getUsers called');
if(!searchStr){
searchStr = document.getElementById('search').value;
}
grout.Users.search(searchStr).then(function(users){
console.log('search users loaded:', users);
document.getElementById("search-output").innerHTML = JSON.stringify(users);
});
} | [
"function",
"searchUsers",
"(",
"searchStr",
")",
"{",
"console",
".",
"log",
"(",
"'getUsers called'",
")",
";",
"if",
"(",
"!",
"searchStr",
")",
"{",
"searchStr",
"=",
"document",
".",
"getElementById",
"(",
"'search'",
")",
".",
"value",
";",
"}",
"grout",
".",
"Users",
".",
"search",
"(",
"searchStr",
")",
".",
"then",
"(",
"function",
"(",
"users",
")",
"{",
"console",
".",
"log",
"(",
"'search users loaded:'",
",",
"users",
")",
";",
"document",
".",
"getElementById",
"(",
"\"search-output\"",
")",
".",
"innerHTML",
"=",
"JSON",
".",
"stringify",
"(",
"users",
")",
";",
"}",
")",
";",
"}"
] | Search users based on a provided string | [
"Search",
"users",
"based",
"on",
"a",
"provided",
"string"
] | 54e6d7118ce03edc2cf671b28e235be664162a77 | https://github.com/KyperTech/grout/blob/54e6d7118ce03edc2cf671b28e235be664162a77/examples/browser/app.js#L144-L153 |
54,776 | wronex/node-conquer | bin/logger.js | write | function write(msg, color, prefix) {
if (!prefix)
prefix = clc.cyan('[conquer]');
// Print each line of the message on its own line.
var messages = msg.split('\n');
for (var i = 0; i < messages.length; i++) {
var message = messages[i].replace(/(\s?$)|(\n?$)/gm, '');
if (message && message.length > 0)
console.log(prefix, color ? color(message) : message);
}
} | javascript | function write(msg, color, prefix) {
if (!prefix)
prefix = clc.cyan('[conquer]');
// Print each line of the message on its own line.
var messages = msg.split('\n');
for (var i = 0; i < messages.length; i++) {
var message = messages[i].replace(/(\s?$)|(\n?$)/gm, '');
if (message && message.length > 0)
console.log(prefix, color ? color(message) : message);
}
} | [
"function",
"write",
"(",
"msg",
",",
"color",
",",
"prefix",
")",
"{",
"if",
"(",
"!",
"prefix",
")",
"prefix",
"=",
"clc",
".",
"cyan",
"(",
"'[conquer]'",
")",
";",
"// Print each line of the message on its own line.",
"var",
"messages",
"=",
"msg",
".",
"split",
"(",
"'\\n'",
")",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"messages",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"message",
"=",
"messages",
"[",
"i",
"]",
".",
"replace",
"(",
"/",
"(\\s?$)|(\\n?$)",
"/",
"gm",
",",
"''",
")",
";",
"if",
"(",
"message",
"&&",
"message",
".",
"length",
">",
"0",
")",
"console",
".",
"log",
"(",
"prefix",
",",
"color",
"?",
"color",
"(",
"message",
")",
":",
"message",
")",
";",
"}",
"}"
] | Writes the supplied message to the log.
@param {String} msg - the message.
@param {Function} [color] - the clc coloring function to use on each message.
@param {String} [prefix] - a message prefix. Defaults to '[conquer]'. | [
"Writes",
"the",
"supplied",
"message",
"to",
"the",
"log",
"."
] | 48fa586d1fad15ad544d143d1ba4b97172fed0f1 | https://github.com/wronex/node-conquer/blob/48fa586d1fad15ad544d143d1ba4b97172fed0f1/bin/logger.js#L12-L23 |
54,777 | wronex/node-conquer | bin/logger.js | log | function log() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg);
} | javascript | function log() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg);
} | [
"function",
"log",
"(",
")",
"{",
"var",
"msg",
"=",
"util",
".",
"format",
".",
"apply",
"(",
"null",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
")",
";",
"write",
"(",
"msg",
")",
";",
"}"
] | Writes the supplied parameters to the log. | [
"Writes",
"the",
"supplied",
"parameters",
"to",
"the",
"log",
"."
] | 48fa586d1fad15ad544d143d1ba4b97172fed0f1 | https://github.com/wronex/node-conquer/blob/48fa586d1fad15ad544d143d1ba4b97172fed0f1/bin/logger.js#L26-L29 |
54,778 | wronex/node-conquer | bin/logger.js | warn | function warn() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg, clc.yellow);
} | javascript | function warn() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg, clc.yellow);
} | [
"function",
"warn",
"(",
")",
"{",
"var",
"msg",
"=",
"util",
".",
"format",
".",
"apply",
"(",
"null",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
")",
";",
"write",
"(",
"msg",
",",
"clc",
".",
"yellow",
")",
";",
"}"
] | Writes the supplied parameters to the log as a warning. | [
"Writes",
"the",
"supplied",
"parameters",
"to",
"the",
"log",
"as",
"a",
"warning",
"."
] | 48fa586d1fad15ad544d143d1ba4b97172fed0f1 | https://github.com/wronex/node-conquer/blob/48fa586d1fad15ad544d143d1ba4b97172fed0f1/bin/logger.js#L32-L35 |
54,779 | wronex/node-conquer | bin/logger.js | error | function error() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg, clc.red);
} | javascript | function error() {
var msg = util.format.apply(null, Array.prototype.slice.call(arguments, 0));
write(msg, clc.red);
} | [
"function",
"error",
"(",
")",
"{",
"var",
"msg",
"=",
"util",
".",
"format",
".",
"apply",
"(",
"null",
",",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
")",
";",
"write",
"(",
"msg",
",",
"clc",
".",
"red",
")",
";",
"}"
] | Writes the supplied parameters to the log as an error. | [
"Writes",
"the",
"supplied",
"parameters",
"to",
"the",
"log",
"as",
"an",
"error",
"."
] | 48fa586d1fad15ad544d143d1ba4b97172fed0f1 | https://github.com/wronex/node-conquer/blob/48fa586d1fad15ad544d143d1ba4b97172fed0f1/bin/logger.js#L38-L41 |
54,780 | wronex/node-conquer | bin/logger.js | scriptLog | function scriptLog(script, msg, isError) {
write(msg,
isError ? clc.red : null,
clc.yellow('[' + script + ']'));
} | javascript | function scriptLog(script, msg, isError) {
write(msg,
isError ? clc.red : null,
clc.yellow('[' + script + ']'));
} | [
"function",
"scriptLog",
"(",
"script",
",",
"msg",
",",
"isError",
")",
"{",
"write",
"(",
"msg",
",",
"isError",
"?",
"clc",
".",
"red",
":",
"null",
",",
"clc",
".",
"yellow",
"(",
"'['",
"+",
"script",
"+",
"']'",
")",
")",
";",
"}"
] | Writes the supplied message from the running script to the log.
@param {String} script - the name of the running script.
@param {String} msg - the message.
@param {Boolean} isError - indicates if the message is an error message. | [
"Writes",
"the",
"supplied",
"message",
"from",
"the",
"running",
"script",
"to",
"the",
"log",
"."
] | 48fa586d1fad15ad544d143d1ba4b97172fed0f1 | https://github.com/wronex/node-conquer/blob/48fa586d1fad15ad544d143d1ba4b97172fed0f1/bin/logger.js#L49-L53 |
54,781 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | Plugin | function Plugin(element, options, jsonData) {
// same the DOM element.
this.element = element;
this.jsonData = jsonData;
// merge the options.
// the jQuery extend function, the later object will
// overwrite the former object.
this.options = $.extend({}, defaultOptions, options);
// set the plugin name.
this._name = pluginName;
// call the initialize function.
this.init();
} | javascript | function Plugin(element, options, jsonData) {
// same the DOM element.
this.element = element;
this.jsonData = jsonData;
// merge the options.
// the jQuery extend function, the later object will
// overwrite the former object.
this.options = $.extend({}, defaultOptions, options);
// set the plugin name.
this._name = pluginName;
// call the initialize function.
this.init();
} | [
"function",
"Plugin",
"(",
"element",
",",
"options",
",",
"jsonData",
")",
"{",
"// same the DOM element.",
"this",
".",
"element",
"=",
"element",
";",
"this",
".",
"jsonData",
"=",
"jsonData",
";",
"// merge the options.",
"// the jQuery extend function, the later object will",
"// overwrite the former object.",
"this",
".",
"options",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"defaultOptions",
",",
"options",
")",
";",
"// set the plugin name.",
"this",
".",
"_name",
"=",
"pluginName",
";",
"// call the initialize function.",
"this",
".",
"init",
"(",
")",
";",
"}"
] | the constructor for bilevelSunburst plugin. | [
"the",
"constructor",
"for",
"bilevelSunburst",
"plugin",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L35-L47 |
54,782 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function(options, jsonData) {
//console.log(jsonData);
var self = this;
// remove the existing one.
$('#' + self.attrId).empty();
// need merge the options with default options.
self.options = $.extend({}, defaultOptions, options);
self.jsonData = jsonData;
self.init();
} | javascript | function(options, jsonData) {
//console.log(jsonData);
var self = this;
// remove the existing one.
$('#' + self.attrId).empty();
// need merge the options with default options.
self.options = $.extend({}, defaultOptions, options);
self.jsonData = jsonData;
self.init();
} | [
"function",
"(",
"options",
",",
"jsonData",
")",
"{",
"//console.log(jsonData);",
"var",
"self",
"=",
"this",
";",
"// remove the existing one.",
"$",
"(",
"'#'",
"+",
"self",
".",
"attrId",
")",
".",
"empty",
"(",
")",
";",
"// need merge the options with default options.",
"self",
".",
"options",
"=",
"$",
".",
"extend",
"(",
"{",
"}",
",",
"defaultOptions",
",",
"options",
")",
";",
"self",
".",
"jsonData",
"=",
"jsonData",
";",
"self",
".",
"init",
"(",
")",
";",
"}"
] | reload the plugin. | [
"reload",
"the",
"plugin",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L128-L139 |
|
54,783 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function() {
var self = this;
var bsExplanation = '';
if(self.options.explanationBuilder) {
// call customized explanation builder.
bsExplanation =
self.options.explanationBuilder(self.attrId);
} else {
bsExplanation =
self.buildDefaultExplanation(self.attrId);
}
$('body').append(bsExplanation);
} | javascript | function() {
var self = this;
var bsExplanation = '';
if(self.options.explanationBuilder) {
// call customized explanation builder.
bsExplanation =
self.options.explanationBuilder(self.attrId);
} else {
bsExplanation =
self.buildDefaultExplanation(self.attrId);
}
$('body').append(bsExplanation);
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"bsExplanation",
"=",
"''",
";",
"if",
"(",
"self",
".",
"options",
".",
"explanationBuilder",
")",
"{",
"// call customized explanation builder.",
"bsExplanation",
"=",
"self",
".",
"options",
".",
"explanationBuilder",
"(",
"self",
".",
"attrId",
")",
";",
"}",
"else",
"{",
"bsExplanation",
"=",
"self",
".",
"buildDefaultExplanation",
"(",
"self",
".",
"attrId",
")",
";",
"}",
"$",
"(",
"'body'",
")",
".",
"append",
"(",
"bsExplanation",
")",
";",
"}"
] | append the explanation div and the inline styles for it.
the option explanationBuilder will be checked to
allow developer to customize the explanation div
self.options.explanationBuilder(prefix); | [
"append",
"the",
"explanation",
"div",
"and",
"the",
"inline",
"styles",
"for",
"it",
".",
"the",
"option",
"explanationBuilder",
"will",
"be",
"checked",
"to",
"allow",
"developer",
"to",
"customize",
"the",
"explanation",
"div"
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L148-L163 |
|
54,784 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function() {
var self = this;
// calculate the location and offset.
// the largest rectangle that can be inscribed in a
// circle is a square.
// calculate the offset for the center of the chart.
var offset = $('#' + self.getGenericId('svg')).offset();
var top = offset['top'] + self.options.diameter / 2;
var left = offset['left'] + self.options.diameter / 2;
// the center circle's the diameter is a third of the
// self.options.diameter.
var centerRadius = self.options.diameter / 6;
var squareX = Math.sqrt(centerRadius * centerRadius / 2);
// top and left for the explanation div.
top = top - squareX;
left = left - squareX - 25;
// the main explanation div.
$('#' + self.getGenericId('explanation'))
.css('position', 'absolute')
.css('text-align', 'center')
// The z-index property specifies the z-order of a
// positioned element and its descendants.
// When elements overlap, z-order determines
// which one covers the other.
// An element with a larger z-index
// generally covers an element with a lower one.
// FIXME: seems we need use class to utilize the
// -1 z-index, which will help position
// the explanation div under the circle.
.css('z-index', '-1')
// it turns out the bootstrap panel has something
// to do with the z-index.
// In general the z-index should work fine.
//.attr('class', 'bs-explanation')
// set the border, most time is for debugging..
.css('border', '0px solid black')
.css('width', '180px')
.css('top', top + 'px')
.css('left', left + 'px');
$('#' + self.getGenericId('pageviews'))
.css('font-size', '2.5em')
.css('color', '#316395');
$('#' + self.getGenericId('percentage'))
.css('font-size', '1.5em')
.css('color', '#316395');
$('#' + self.getGenericId('date'))
.css('font-weight', 'bold');
$('#' + self.getGenericId('group'))
.css('font-weight', 'bold');
} | javascript | function() {
var self = this;
// calculate the location and offset.
// the largest rectangle that can be inscribed in a
// circle is a square.
// calculate the offset for the center of the chart.
var offset = $('#' + self.getGenericId('svg')).offset();
var top = offset['top'] + self.options.diameter / 2;
var left = offset['left'] + self.options.diameter / 2;
// the center circle's the diameter is a third of the
// self.options.diameter.
var centerRadius = self.options.diameter / 6;
var squareX = Math.sqrt(centerRadius * centerRadius / 2);
// top and left for the explanation div.
top = top - squareX;
left = left - squareX - 25;
// the main explanation div.
$('#' + self.getGenericId('explanation'))
.css('position', 'absolute')
.css('text-align', 'center')
// The z-index property specifies the z-order of a
// positioned element and its descendants.
// When elements overlap, z-order determines
// which one covers the other.
// An element with a larger z-index
// generally covers an element with a lower one.
// FIXME: seems we need use class to utilize the
// -1 z-index, which will help position
// the explanation div under the circle.
.css('z-index', '-1')
// it turns out the bootstrap panel has something
// to do with the z-index.
// In general the z-index should work fine.
//.attr('class', 'bs-explanation')
// set the border, most time is for debugging..
.css('border', '0px solid black')
.css('width', '180px')
.css('top', top + 'px')
.css('left', left + 'px');
$('#' + self.getGenericId('pageviews'))
.css('font-size', '2.5em')
.css('color', '#316395');
$('#' + self.getGenericId('percentage'))
.css('font-size', '1.5em')
.css('color', '#316395');
$('#' + self.getGenericId('date'))
.css('font-weight', 'bold');
$('#' + self.getGenericId('group'))
.css('font-weight', 'bold');
} | [
"function",
"(",
")",
"{",
"var",
"self",
"=",
"this",
";",
"// calculate the location and offset.",
"// the largest rectangle that can be inscribed in a ",
"// circle is a square.",
"// calculate the offset for the center of the chart.",
"var",
"offset",
"=",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'svg'",
")",
")",
".",
"offset",
"(",
")",
";",
"var",
"top",
"=",
"offset",
"[",
"'top'",
"]",
"+",
"self",
".",
"options",
".",
"diameter",
"/",
"2",
";",
"var",
"left",
"=",
"offset",
"[",
"'left'",
"]",
"+",
"self",
".",
"options",
".",
"diameter",
"/",
"2",
";",
"// the center circle's the diameter is a third of the ",
"// self.options.diameter.",
"var",
"centerRadius",
"=",
"self",
".",
"options",
".",
"diameter",
"/",
"6",
";",
"var",
"squareX",
"=",
"Math",
".",
"sqrt",
"(",
"centerRadius",
"*",
"centerRadius",
"/",
"2",
")",
";",
"// top and left for the explanation div.",
"top",
"=",
"top",
"-",
"squareX",
";",
"left",
"=",
"left",
"-",
"squareX",
"-",
"25",
";",
"// the main explanation div.",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'explanation'",
")",
")",
".",
"css",
"(",
"'position'",
",",
"'absolute'",
")",
".",
"css",
"(",
"'text-align'",
",",
"'center'",
")",
"// The z-index property specifies the z-order of a ",
"// positioned element and its descendants. ",
"// When elements overlap, z-order determines ",
"// which one covers the other. ",
"// An element with a larger z-index ",
"// generally covers an element with a lower one.",
"// FIXME: seems we need use class to utilize the ",
"// -1 z-index, which will help position ",
"// the explanation div under the circle.",
".",
"css",
"(",
"'z-index'",
",",
"'-1'",
")",
"// it turns out the bootstrap panel has something",
"// to do with the z-index.",
"// In general the z-index should work fine.",
"//.attr('class', 'bs-explanation')",
"// set the border, most time is for debugging..",
".",
"css",
"(",
"'border'",
",",
"'0px solid black'",
")",
".",
"css",
"(",
"'width'",
",",
"'180px'",
")",
".",
"css",
"(",
"'top'",
",",
"top",
"+",
"'px'",
")",
".",
"css",
"(",
"'left'",
",",
"left",
"+",
"'px'",
")",
";",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'pageviews'",
")",
")",
".",
"css",
"(",
"'font-size'",
",",
"'2.5em'",
")",
".",
"css",
"(",
"'color'",
",",
"'#316395'",
")",
";",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'percentage'",
")",
")",
".",
"css",
"(",
"'font-size'",
",",
"'1.5em'",
")",
".",
"css",
"(",
"'color'",
",",
"'#316395'",
")",
";",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'date'",
")",
")",
".",
"css",
"(",
"'font-weight'",
",",
"'bold'",
")",
";",
"$",
"(",
"'#'",
"+",
"self",
".",
"getGenericId",
"(",
"'group'",
")",
")",
".",
"css",
"(",
"'font-weight'",
",",
"'bold'",
")",
";",
"}"
] | apply styles for the explanation div.
this should happen after we have the location and offset
of the svg. | [
"apply",
"styles",
"for",
"the",
"explanation",
"div",
".",
"this",
"should",
"happen",
"after",
"we",
"have",
"the",
"location",
"and",
"offset",
"of",
"the",
"svg",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L170-L230 |
|
54,785 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function(p) {
var self = this;
if (p.depth > 1) p = p.parent;
// no children
if (!p.children) return;
//console.log("zoom in p.value = " + p.value);
//console.log("zoom in p.name = " + p.name);
self.updateExplanation(p.value, p.name);
self.zoom(p, p);
} | javascript | function(p) {
var self = this;
if (p.depth > 1) p = p.parent;
// no children
if (!p.children) return;
//console.log("zoom in p.value = " + p.value);
//console.log("zoom in p.name = " + p.name);
self.updateExplanation(p.value, p.name);
self.zoom(p, p);
} | [
"function",
"(",
"p",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"p",
".",
"depth",
">",
"1",
")",
"p",
"=",
"p",
".",
"parent",
";",
"// no children",
"if",
"(",
"!",
"p",
".",
"children",
")",
"return",
";",
"//console.log(\"zoom in p.value = \" + p.value);",
"//console.log(\"zoom in p.name = \" + p.name);",
"self",
".",
"updateExplanation",
"(",
"p",
".",
"value",
",",
"p",
".",
"name",
")",
";",
"self",
".",
"zoom",
"(",
"p",
",",
"p",
")",
";",
"}"
] | handle zoomin, it happen on arcs. | [
"handle",
"zoomin",
"it",
"happen",
"on",
"arcs",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L357-L370 |
|
54,786 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function(pageviews, name) {
var self = this;
$("#" + self.getGenericId('pageviews'))
.text(self.formatNumber(pageviews));
$("#" + self.getGenericId("group")).text(name);
var percentage = pageviews / self.totalValue;
$("#" + self.getGenericId("percentage"))
.text(self.formatPercentage(percentage));
} | javascript | function(pageviews, name) {
var self = this;
$("#" + self.getGenericId('pageviews'))
.text(self.formatNumber(pageviews));
$("#" + self.getGenericId("group")).text(name);
var percentage = pageviews / self.totalValue;
$("#" + self.getGenericId("percentage"))
.text(self.formatPercentage(percentage));
} | [
"function",
"(",
"pageviews",
",",
"name",
")",
"{",
"var",
"self",
"=",
"this",
";",
"$",
"(",
"\"#\"",
"+",
"self",
".",
"getGenericId",
"(",
"'pageviews'",
")",
")",
".",
"text",
"(",
"self",
".",
"formatNumber",
"(",
"pageviews",
")",
")",
";",
"$",
"(",
"\"#\"",
"+",
"self",
".",
"getGenericId",
"(",
"\"group\"",
")",
")",
".",
"text",
"(",
"name",
")",
";",
"var",
"percentage",
"=",
"pageviews",
"/",
"self",
".",
"totalValue",
";",
"$",
"(",
"\"#\"",
"+",
"self",
".",
"getGenericId",
"(",
"\"percentage\"",
")",
")",
".",
"text",
"(",
"self",
".",
"formatPercentage",
"(",
"percentage",
")",
")",
";",
"}"
] | update the explanation div.
TODO: Should allow user to update through the
self.options.explanationUpdater. | [
"update",
"the",
"explanation",
"div",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L378-L388 |
|
54,787 | leocornus/leocornus-visualdata | src/bilevel-sunburst.js | function(p) {
var self = this;
if (!p) return;
if (!p.parent) return;
//console.log("zoom out p.value = " + p.parent.value);
//console.log("zoom out p.name = " + p.parent.name);
//console.log(p.parent);
self.updateExplanation(p.parent.sum, p.parent.name);
self.zoom(p.parent, p);
} | javascript | function(p) {
var self = this;
if (!p) return;
if (!p.parent) return;
//console.log("zoom out p.value = " + p.parent.value);
//console.log("zoom out p.name = " + p.parent.name);
//console.log(p.parent);
self.updateExplanation(p.parent.sum, p.parent.name);
self.zoom(p.parent, p);
} | [
"function",
"(",
"p",
")",
"{",
"var",
"self",
"=",
"this",
";",
"if",
"(",
"!",
"p",
")",
"return",
";",
"if",
"(",
"!",
"p",
".",
"parent",
")",
"return",
";",
"//console.log(\"zoom out p.value = \" + p.parent.value);",
"//console.log(\"zoom out p.name = \" + p.parent.name);",
"//console.log(p.parent);",
"self",
".",
"updateExplanation",
"(",
"p",
".",
"parent",
".",
"sum",
",",
"p",
".",
"parent",
".",
"name",
")",
";",
"self",
".",
"zoom",
"(",
"p",
".",
"parent",
",",
"p",
")",
";",
"}"
] | handle zoomout, for center circle. | [
"handle",
"zoomout",
"for",
"center",
"circle",
"."
] | 9d9714ca11c126f0250e650f3c1c4086709af3ab | https://github.com/leocornus/leocornus-visualdata/blob/9d9714ca11c126f0250e650f3c1c4086709af3ab/src/bilevel-sunburst.js#L393-L406 |
|
54,788 | isaacsimmons/cache-manifest-generator | index.js | onFile | function onFile(filePath, stat) {
if (filePath.match(ignore) || filePath.match(globalIgnore)) { return; }
var newTimestamp = updateTimestamp(stat.mtime);
if (manifest['CACHE'].insert(toUrl(cleanPath(filePath))) || newTimestamp) {
updateListener(manifest);
}
} | javascript | function onFile(filePath, stat) {
if (filePath.match(ignore) || filePath.match(globalIgnore)) { return; }
var newTimestamp = updateTimestamp(stat.mtime);
if (manifest['CACHE'].insert(toUrl(cleanPath(filePath))) || newTimestamp) {
updateListener(manifest);
}
} | [
"function",
"onFile",
"(",
"filePath",
",",
"stat",
")",
"{",
"if",
"(",
"filePath",
".",
"match",
"(",
"ignore",
")",
"||",
"filePath",
".",
"match",
"(",
"globalIgnore",
")",
")",
"{",
"return",
";",
"}",
"var",
"newTimestamp",
"=",
"updateTimestamp",
"(",
"stat",
".",
"mtime",
")",
";",
"if",
"(",
"manifest",
"[",
"'CACHE'",
"]",
".",
"insert",
"(",
"toUrl",
"(",
"cleanPath",
"(",
"filePath",
")",
")",
")",
"||",
"newTimestamp",
")",
"{",
"updateListener",
"(",
"manifest",
")",
";",
"}",
"}"
] | If no ignore pattern is given, use one that matches nothing | [
"If",
"no",
"ignore",
"pattern",
"is",
"given",
"use",
"one",
"that",
"matches",
"nothing"
] | 9746c47e33d1febae7639b56383a757d2a138bfe | https://github.com/isaacsimmons/cache-manifest-generator/blob/9746c47e33d1febae7639b56383a757d2a138bfe/index.js#L152-L158 |
54,789 | dan-nl/yeoman-prompting-helpers | src/filter-prompts.js | filterPrompts | function filterPrompts( PromptAnswers, generator_prompts ) {
return filter(
generator_prompts,
function iteratee( prompt ) {
return typeof PromptAnswers.get( prompt.name ) === 'undefined';
}
);
} | javascript | function filterPrompts( PromptAnswers, generator_prompts ) {
return filter(
generator_prompts,
function iteratee( prompt ) {
return typeof PromptAnswers.get( prompt.name ) === 'undefined';
}
);
} | [
"function",
"filterPrompts",
"(",
"PromptAnswers",
",",
"generator_prompts",
")",
"{",
"return",
"filter",
"(",
"generator_prompts",
",",
"function",
"iteratee",
"(",
"prompt",
")",
"{",
"return",
"typeof",
"PromptAnswers",
".",
"get",
"(",
"prompt",
".",
"name",
")",
"===",
"'undefined'",
";",
"}",
")",
";",
"}"
] | if a prompt.name already exists in PromptAnswers.answers that prompt will not be returned in
the resulting Array
@param {PromptAnswers} PromptAnswers
@param {Array} generator_prompts
@returns {Array} | [
"if",
"a",
"prompt",
".",
"name",
"already",
"exists",
"in",
"PromptAnswers",
".",
"answers",
"that",
"prompt",
"will",
"not",
"be",
"returned",
"in",
"the",
"resulting",
"Array"
] | 6b698989f7350f736705bae66d8481d01512612c | https://github.com/dan-nl/yeoman-prompting-helpers/blob/6b698989f7350f736705bae66d8481d01512612c/src/filter-prompts.js#L16-L23 |
54,790 | commenthol/streamss-through | index.js | Through | function Through (options, transform, flush) {
var self = this
if (!(this instanceof Through)) {
return new Through(options, transform, flush)
}
if (typeof options === 'function') {
flush = transform
transform = options
options = {}
}
options = options || {}
Transform.call(this, options)
if (typeof transform !== 'function') {
transform = function (data) {
this.push(data)
}
}
if (typeof flush !== 'function') {
flush = null
}
this._transform = transform
this._flush = flush
self.on('pipe', function (src) {
if (options.passError !== false) {
src.on('error', function (err) {
self.emit('error', err)
})
}
})
if (this._transform.length < 3) {
this._transform = wrap.transform.call(this, transform)
}
if (this._flush && this._flush.length < 1) {
this._flush = wrap.flush.call(this, flush)
}
return this
} | javascript | function Through (options, transform, flush) {
var self = this
if (!(this instanceof Through)) {
return new Through(options, transform, flush)
}
if (typeof options === 'function') {
flush = transform
transform = options
options = {}
}
options = options || {}
Transform.call(this, options)
if (typeof transform !== 'function') {
transform = function (data) {
this.push(data)
}
}
if (typeof flush !== 'function') {
flush = null
}
this._transform = transform
this._flush = flush
self.on('pipe', function (src) {
if (options.passError !== false) {
src.on('error', function (err) {
self.emit('error', err)
})
}
})
if (this._transform.length < 3) {
this._transform = wrap.transform.call(this, transform)
}
if (this._flush && this._flush.length < 1) {
this._flush = wrap.flush.call(this, flush)
}
return this
} | [
"function",
"Through",
"(",
"options",
",",
"transform",
",",
"flush",
")",
"{",
"var",
"self",
"=",
"this",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Through",
")",
")",
"{",
"return",
"new",
"Through",
"(",
"options",
",",
"transform",
",",
"flush",
")",
"}",
"if",
"(",
"typeof",
"options",
"===",
"'function'",
")",
"{",
"flush",
"=",
"transform",
"transform",
"=",
"options",
"options",
"=",
"{",
"}",
"}",
"options",
"=",
"options",
"||",
"{",
"}",
"Transform",
".",
"call",
"(",
"this",
",",
"options",
")",
"if",
"(",
"typeof",
"transform",
"!==",
"'function'",
")",
"{",
"transform",
"=",
"function",
"(",
"data",
")",
"{",
"this",
".",
"push",
"(",
"data",
")",
"}",
"}",
"if",
"(",
"typeof",
"flush",
"!==",
"'function'",
")",
"{",
"flush",
"=",
"null",
"}",
"this",
".",
"_transform",
"=",
"transform",
"this",
".",
"_flush",
"=",
"flush",
"self",
".",
"on",
"(",
"'pipe'",
",",
"function",
"(",
"src",
")",
"{",
"if",
"(",
"options",
".",
"passError",
"!==",
"false",
")",
"{",
"src",
".",
"on",
"(",
"'error'",
",",
"function",
"(",
"err",
")",
"{",
"self",
".",
"emit",
"(",
"'error'",
",",
"err",
")",
"}",
")",
"}",
"}",
")",
"if",
"(",
"this",
".",
"_transform",
".",
"length",
"<",
"3",
")",
"{",
"this",
".",
"_transform",
"=",
"wrap",
".",
"transform",
".",
"call",
"(",
"this",
",",
"transform",
")",
"}",
"if",
"(",
"this",
".",
"_flush",
"&&",
"this",
".",
"_flush",
".",
"length",
"<",
"1",
")",
"{",
"this",
".",
"_flush",
"=",
"wrap",
".",
"flush",
".",
"call",
"(",
"this",
",",
"flush",
")",
"}",
"return",
"this",
"}"
] | Stream transformer with functional API
@constructor
@param {Object} [options] - Stream options
@param {Boolean} options.objectMode - Whether this stream should behave as a stream of objects. Default=false
@param {Number} options.highWaterMark - The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying resource. Default=16kb
@param {String} options.encoding - Set encoding for string-decoder
@param {Boolean} options.decodeStrings - Do not decode strings if set to `false`. Default=true
@param {Boolean} options.passError - Pass error to next pipe. Default=true
@param {Function} [transform] - Function called on transform
@param {Function} [flush] - Function called on flush | [
"Stream",
"transformer",
"with",
"functional",
"API"
] | 713b5256db6b0f4d4a3efe2ed4256ef626c753cb | https://github.com/commenthol/streamss-through/blob/713b5256db6b0f4d4a3efe2ed4256ef626c753cb/index.js#L41-L85 |
54,791 | brianloveswords/gogo | lib/field.mysql.js | finishSpec | function finishSpec(spec, opts, field) {
if (opts.unique) {
var keylength = parseInt(opts.unique, 10) ? opts.unique : undefined;
if (opts.unique === true && spec.sql.match(/^(text|blob)/i)) {
var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }';
throw new Error(msg);
}
spec.keysql = _.strjoin(
_.upcase('unique key'),
_.backtick(field),
_.paren(_.strjoin(
_.backtick(field),
_.paren(keylength)
))
);
}
if (opts['null'] === false || opts.required === true) {
spec.sql = _.strjoin(spec.sql, 'NOT NULL');
spec.validators.unshift(Validators.Require);
}
if (opts['default'] !== undefined) {
var defval = opts['default'];
var textType = opts.type.match(/blob|text|char|enum|binary/i);
spec.sql = _.strjoin(
spec.sql,
'DEFAULT',
(textType ? _.quote(defval) : defval)
);
}
return spec;
} | javascript | function finishSpec(spec, opts, field) {
if (opts.unique) {
var keylength = parseInt(opts.unique, 10) ? opts.unique : undefined;
if (opts.unique === true && spec.sql.match(/^(text|blob)/i)) {
var msg = 'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }';
throw new Error(msg);
}
spec.keysql = _.strjoin(
_.upcase('unique key'),
_.backtick(field),
_.paren(_.strjoin(
_.backtick(field),
_.paren(keylength)
))
);
}
if (opts['null'] === false || opts.required === true) {
spec.sql = _.strjoin(spec.sql, 'NOT NULL');
spec.validators.unshift(Validators.Require);
}
if (opts['default'] !== undefined) {
var defval = opts['default'];
var textType = opts.type.match(/blob|text|char|enum|binary/i);
spec.sql = _.strjoin(
spec.sql,
'DEFAULT',
(textType ? _.quote(defval) : defval)
);
}
return spec;
} | [
"function",
"finishSpec",
"(",
"spec",
",",
"opts",
",",
"field",
")",
"{",
"if",
"(",
"opts",
".",
"unique",
")",
"{",
"var",
"keylength",
"=",
"parseInt",
"(",
"opts",
".",
"unique",
",",
"10",
")",
"?",
"opts",
".",
"unique",
":",
"undefined",
";",
"if",
"(",
"opts",
".",
"unique",
"===",
"true",
"&&",
"spec",
".",
"sql",
".",
"match",
"(",
"/",
"^(text|blob)",
"/",
"i",
")",
")",
"{",
"var",
"msg",
"=",
"'When adding a unique key to an unsized type (text or blob), unique must be set with a length e.g. { unique: 128 }'",
";",
"throw",
"new",
"Error",
"(",
"msg",
")",
";",
"}",
"spec",
".",
"keysql",
"=",
"_",
".",
"strjoin",
"(",
"_",
".",
"upcase",
"(",
"'unique key'",
")",
",",
"_",
".",
"backtick",
"(",
"field",
")",
",",
"_",
".",
"paren",
"(",
"_",
".",
"strjoin",
"(",
"_",
".",
"backtick",
"(",
"field",
")",
",",
"_",
".",
"paren",
"(",
"keylength",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"opts",
"[",
"'null'",
"]",
"===",
"false",
"||",
"opts",
".",
"required",
"===",
"true",
")",
"{",
"spec",
".",
"sql",
"=",
"_",
".",
"strjoin",
"(",
"spec",
".",
"sql",
",",
"'NOT NULL'",
")",
";",
"spec",
".",
"validators",
".",
"unshift",
"(",
"Validators",
".",
"Require",
")",
";",
"}",
"if",
"(",
"opts",
"[",
"'default'",
"]",
"!==",
"undefined",
")",
"{",
"var",
"defval",
"=",
"opts",
"[",
"'default'",
"]",
";",
"var",
"textType",
"=",
"opts",
".",
"type",
".",
"match",
"(",
"/",
"blob|text|char|enum|binary",
"/",
"i",
")",
";",
"spec",
".",
"sql",
"=",
"_",
".",
"strjoin",
"(",
"spec",
".",
"sql",
",",
"'DEFAULT'",
",",
"(",
"textType",
"?",
"_",
".",
"quote",
"(",
"defval",
")",
":",
"defval",
")",
")",
";",
"}",
"return",
"spec",
";",
"}"
] | Helper for handling generic options for field generators.
@param {Object} spec
@param {Object} opts see below
@param {String} field
@param {Boolean} opts.null when false, adds `required` validator,
`not null` to field
@param {Boolean} opts.required opposite of `opts.null`
@param {Boolean|Integer} opts.unique integer specifies length of key
@param {String|Number} opts.default the default value for the field | [
"Helper",
"for",
"handling",
"generic",
"options",
"for",
"field",
"generators",
"."
] | f17ee794e0439ed961907f52b91bcb74dcca351a | https://github.com/brianloveswords/gogo/blob/f17ee794e0439ed961907f52b91bcb74dcca351a/lib/field.mysql.js#L22-L57 |
54,792 | darrencruse/sugarlisp-core | sl-types.js | pprintSEXP | function pprintSEXP(formJson, opts, indentLevel, priorNodeStr) {
opts = opts || {};
opts.lbracket = "(";
opts.rbracket = ")";
opts.separator = " ";
opts.bareSymbols = true;
return pprintJSON(formJson, opts, indentLevel, priorNodeStr);
} | javascript | function pprintSEXP(formJson, opts, indentLevel, priorNodeStr) {
opts = opts || {};
opts.lbracket = "(";
opts.rbracket = ")";
opts.separator = " ";
opts.bareSymbols = true;
return pprintJSON(formJson, opts, indentLevel, priorNodeStr);
} | [
"function",
"pprintSEXP",
"(",
"formJson",
",",
"opts",
",",
"indentLevel",
",",
"priorNodeStr",
")",
"{",
"opts",
"=",
"opts",
"||",
"{",
"}",
";",
"opts",
".",
"lbracket",
"=",
"\"(\"",
";",
"opts",
".",
"rbracket",
"=",
"\")\"",
";",
"opts",
".",
"separator",
"=",
"\" \"",
";",
"opts",
".",
"bareSymbols",
"=",
"true",
";",
"return",
"pprintJSON",
"(",
"formJson",
",",
"opts",
",",
"indentLevel",
",",
"priorNodeStr",
")",
";",
"}"
] | "pretty print" lisp s-expressions from the form tree to a string | [
"pretty",
"print",
"lisp",
"s",
"-",
"expressions",
"from",
"the",
"form",
"tree",
"to",
"a",
"string"
] | c6ff983ebc3d60268054d6fe046db4aff6c5f78c | https://github.com/darrencruse/sugarlisp-core/blob/c6ff983ebc3d60268054d6fe046db4aff6c5f78c/sl-types.js#L639-L646 |
54,793 | darrencruse/sugarlisp-core | sl-types.js | isQuotedString | function isQuotedString(str) {
var is = false;
if(typeof str === 'string') {
var firstChar = str.charAt(0);
is = (['"', "'", '`'].indexOf(firstChar) !== -1);
}
return is;
} | javascript | function isQuotedString(str) {
var is = false;
if(typeof str === 'string') {
var firstChar = str.charAt(0);
is = (['"', "'", '`'].indexOf(firstChar) !== -1);
}
return is;
} | [
"function",
"isQuotedString",
"(",
"str",
")",
"{",
"var",
"is",
"=",
"false",
";",
"if",
"(",
"typeof",
"str",
"===",
"'string'",
")",
"{",
"var",
"firstChar",
"=",
"str",
".",
"charAt",
"(",
"0",
")",
";",
"is",
"=",
"(",
"[",
"'\"'",
",",
"\"'\"",
",",
"'`'",
"]",
".",
"indexOf",
"(",
"firstChar",
")",
"!==",
"-",
"1",
")",
";",
"}",
"return",
"is",
";",
"}"
] | Is the text a quoted string? | [
"Is",
"the",
"text",
"a",
"quoted",
"string?"
] | c6ff983ebc3d60268054d6fe046db4aff6c5f78c | https://github.com/darrencruse/sugarlisp-core/blob/c6ff983ebc3d60268054d6fe046db4aff6c5f78c/sl-types.js#L848-L855 |
54,794 | darrencruse/sugarlisp-core | sl-types.js | stripQuotes | function stripQuotes(text) {
var sansquotes = text;
if(isQuotedString(text)) {
if(text.length === 2) {
sanquotes = ""; // empty string
}
else {
sansquotes = text.substring(1, text.length-1);
// DELETE? sansquotes = unescapeQuotes(sansquotes);
}
}
return sansquotes;
} | javascript | function stripQuotes(text) {
var sansquotes = text;
if(isQuotedString(text)) {
if(text.length === 2) {
sanquotes = ""; // empty string
}
else {
sansquotes = text.substring(1, text.length-1);
// DELETE? sansquotes = unescapeQuotes(sansquotes);
}
}
return sansquotes;
} | [
"function",
"stripQuotes",
"(",
"text",
")",
"{",
"var",
"sansquotes",
"=",
"text",
";",
"if",
"(",
"isQuotedString",
"(",
"text",
")",
")",
"{",
"if",
"(",
"text",
".",
"length",
"===",
"2",
")",
"{",
"sanquotes",
"=",
"\"\"",
";",
"// empty string",
"}",
"else",
"{",
"sansquotes",
"=",
"text",
".",
"substring",
"(",
"1",
",",
"text",
".",
"length",
"-",
"1",
")",
";",
"// DELETE? sansquotes = unescapeQuotes(sansquotes);",
"}",
"}",
"return",
"sansquotes",
";",
"}"
] | strip the quotes from around a string if there are any
otherwise return the string as given.
since we are removing the quotes we also unescape quotes
within the string. | [
"strip",
"the",
"quotes",
"from",
"around",
"a",
"string",
"if",
"there",
"are",
"any",
"otherwise",
"return",
"the",
"string",
"as",
"given",
".",
"since",
"we",
"are",
"removing",
"the",
"quotes",
"we",
"also",
"unescape",
"quotes",
"within",
"the",
"string",
"."
] | c6ff983ebc3d60268054d6fe046db4aff6c5f78c | https://github.com/darrencruse/sugarlisp-core/blob/c6ff983ebc3d60268054d6fe046db4aff6c5f78c/sl-types.js#L877-L889 |
54,795 | darrencruse/sugarlisp-core | sl-types.js | addQuotes | function addQuotes(text, quoteChar) {
var withquotes = text;
if(!isQuotedString(text)) {
var delim = quoteChar && quoteChar.length === 1 ? quoteChar : '"';
withquotes = delim + text + delim;
}
return withquotes;
} | javascript | function addQuotes(text, quoteChar) {
var withquotes = text;
if(!isQuotedString(text)) {
var delim = quoteChar && quoteChar.length === 1 ? quoteChar : '"';
withquotes = delim + text + delim;
}
return withquotes;
} | [
"function",
"addQuotes",
"(",
"text",
",",
"quoteChar",
")",
"{",
"var",
"withquotes",
"=",
"text",
";",
"if",
"(",
"!",
"isQuotedString",
"(",
"text",
")",
")",
"{",
"var",
"delim",
"=",
"quoteChar",
"&&",
"quoteChar",
".",
"length",
"===",
"1",
"?",
"quoteChar",
":",
"'\"'",
";",
"withquotes",
"=",
"delim",
"+",
"text",
"+",
"delim",
";",
"}",
"return",
"withquotes",
";",
"}"
] | add quotes around a string if there aren't any
otherwise return the string as given.
since we're adding the quotes we also escape quotes
within the string. | [
"add",
"quotes",
"around",
"a",
"string",
"if",
"there",
"aren",
"t",
"any",
"otherwise",
"return",
"the",
"string",
"as",
"given",
".",
"since",
"we",
"re",
"adding",
"the",
"quotes",
"we",
"also",
"escape",
"quotes",
"within",
"the",
"string",
"."
] | c6ff983ebc3d60268054d6fe046db4aff6c5f78c | https://github.com/darrencruse/sugarlisp-core/blob/c6ff983ebc3d60268054d6fe046db4aff6c5f78c/sl-types.js#L897-L904 |
54,796 | mattdesl/gl-texture2d-pixels | index.js | getPixels | function getPixels(texture, opts) {
var gl = texture.gl
if (!gl)
throw new Error("must provide gl-texture2d object with a valid 'gl' context")
if (!fbo) {
var handle = gl.createFramebuffer()
fbo = {
handle: handle,
dispose: dispose,
gl: gl
}
}
// make this the current frame buffer
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.handle)
// attach the texture to the framebuffer.
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, texture.handle, 0)
// check if you can read from this type of texture.
var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)
if (status !== gl.FRAMEBUFFER_COMPLETE)
throw new Error("cannot read GL framebuffer: " + status)
opts = opts||{}
opts.x = opts.x|0
opts.y = opts.y|0
opts.width = typeof opts.width === 'number' ? opts.width : (texture.shape[0]|0)
opts.height = typeof opts.height === 'number' ? opts.height : (texture.shape[1]|0)
var array = new Uint8Array(opts.width * opts.height * 4)
gl.readPixels(opts.x, opts.y, opts.width, opts.height, gl.RGBA, gl.UNSIGNED_BYTE, array)
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
return array
} | javascript | function getPixels(texture, opts) {
var gl = texture.gl
if (!gl)
throw new Error("must provide gl-texture2d object with a valid 'gl' context")
if (!fbo) {
var handle = gl.createFramebuffer()
fbo = {
handle: handle,
dispose: dispose,
gl: gl
}
}
// make this the current frame buffer
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo.handle)
// attach the texture to the framebuffer.
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D, texture.handle, 0)
// check if you can read from this type of texture.
var status = gl.checkFramebufferStatus(gl.FRAMEBUFFER)
if (status !== gl.FRAMEBUFFER_COMPLETE)
throw new Error("cannot read GL framebuffer: " + status)
opts = opts||{}
opts.x = opts.x|0
opts.y = opts.y|0
opts.width = typeof opts.width === 'number' ? opts.width : (texture.shape[0]|0)
opts.height = typeof opts.height === 'number' ? opts.height : (texture.shape[1]|0)
var array = new Uint8Array(opts.width * opts.height * 4)
gl.readPixels(opts.x, opts.y, opts.width, opts.height, gl.RGBA, gl.UNSIGNED_BYTE, array)
gl.bindFramebuffer(gl.FRAMEBUFFER, null)
return array
} | [
"function",
"getPixels",
"(",
"texture",
",",
"opts",
")",
"{",
"var",
"gl",
"=",
"texture",
".",
"gl",
"if",
"(",
"!",
"gl",
")",
"throw",
"new",
"Error",
"(",
"\"must provide gl-texture2d object with a valid 'gl' context\"",
")",
"if",
"(",
"!",
"fbo",
")",
"{",
"var",
"handle",
"=",
"gl",
".",
"createFramebuffer",
"(",
")",
"fbo",
"=",
"{",
"handle",
":",
"handle",
",",
"dispose",
":",
"dispose",
",",
"gl",
":",
"gl",
"}",
"}",
"// make this the current frame buffer",
"gl",
".",
"bindFramebuffer",
"(",
"gl",
".",
"FRAMEBUFFER",
",",
"fbo",
".",
"handle",
")",
"// attach the texture to the framebuffer.",
"gl",
".",
"framebufferTexture2D",
"(",
"gl",
".",
"FRAMEBUFFER",
",",
"gl",
".",
"COLOR_ATTACHMENT0",
",",
"gl",
".",
"TEXTURE_2D",
",",
"texture",
".",
"handle",
",",
"0",
")",
"// check if you can read from this type of texture.",
"var",
"status",
"=",
"gl",
".",
"checkFramebufferStatus",
"(",
"gl",
".",
"FRAMEBUFFER",
")",
"if",
"(",
"status",
"!==",
"gl",
".",
"FRAMEBUFFER_COMPLETE",
")",
"throw",
"new",
"Error",
"(",
"\"cannot read GL framebuffer: \"",
"+",
"status",
")",
"opts",
"=",
"opts",
"||",
"{",
"}",
"opts",
".",
"x",
"=",
"opts",
".",
"x",
"|",
"0",
"opts",
".",
"y",
"=",
"opts",
".",
"y",
"|",
"0",
"opts",
".",
"width",
"=",
"typeof",
"opts",
".",
"width",
"===",
"'number'",
"?",
"opts",
".",
"width",
":",
"(",
"texture",
".",
"shape",
"[",
"0",
"]",
"|",
"0",
")",
"opts",
".",
"height",
"=",
"typeof",
"opts",
".",
"height",
"===",
"'number'",
"?",
"opts",
".",
"height",
":",
"(",
"texture",
".",
"shape",
"[",
"1",
"]",
"|",
"0",
")",
"var",
"array",
"=",
"new",
"Uint8Array",
"(",
"opts",
".",
"width",
"*",
"opts",
".",
"height",
"*",
"4",
")",
"gl",
".",
"readPixels",
"(",
"opts",
".",
"x",
",",
"opts",
".",
"y",
",",
"opts",
".",
"width",
",",
"opts",
".",
"height",
",",
"gl",
".",
"RGBA",
",",
"gl",
".",
"UNSIGNED_BYTE",
",",
"array",
")",
"gl",
".",
"bindFramebuffer",
"(",
"gl",
".",
"FRAMEBUFFER",
",",
"null",
")",
"return",
"array",
"}"
] | Split into another module or use gl-fbo somehow | [
"Split",
"into",
"another",
"module",
"or",
"use",
"gl",
"-",
"fbo",
"somehow"
] | 06bdd8a71635414642db025b09b47da05c8953d9 | https://github.com/mattdesl/gl-texture2d-pixels/blob/06bdd8a71635414642db025b09b47da05c8953d9/index.js#L8-L45 |
54,797 | stefanmintert/ep_xmlexport | Line.js | function(listsEnabled, lineAttributesEnabled) {
if ((!hasList() && !hasLineAttributes) || (!listsEnabled && !lineAttributesEnabled)) {
return {
lineAttributes: [],
inlineAttributeString: rawAttributeString,
inlinePlaintext: rawText
};
}
if (listsEnabled && !lineAttributesEnabled) {
if (hasList() && _hasNonlistLineAttributes()) {
return {
lineAttributes: [],
inlineAttributeString: _attributeStringWithoutListAttributes(rawAttributeString),
inlinePlaintext: rawText
};
} else if (hasList() && !_hasNonlistLineAttributes()){
return {
lineAttributes: [],
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else if (!hasList() && hasLineAttributes){
return {
lineAttributes: [],
inlineAttributeString: rawAttributeString,
inlinePlaintext: rawText
};
} else {
console.error("Plugin error: it seems the developer missed a case here.");
}
} else if (listsEnabled && lineAttributesEnabled) {
if (_hasNonlistLineAttributes()) {
return {
lineAttributes: _withoutListAttributes(lineAttributes),
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else {
return {
lineAttributes: [],
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
}
} else if (!listsEnabled && lineAttributesEnabled) {
return {
lineAttributes: lineAttributes,
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else {
console.error("Plugin error: it seems the developer missed a case here.");
}
} | javascript | function(listsEnabled, lineAttributesEnabled) {
if ((!hasList() && !hasLineAttributes) || (!listsEnabled && !lineAttributesEnabled)) {
return {
lineAttributes: [],
inlineAttributeString: rawAttributeString,
inlinePlaintext: rawText
};
}
if (listsEnabled && !lineAttributesEnabled) {
if (hasList() && _hasNonlistLineAttributes()) {
return {
lineAttributes: [],
inlineAttributeString: _attributeStringWithoutListAttributes(rawAttributeString),
inlinePlaintext: rawText
};
} else if (hasList() && !_hasNonlistLineAttributes()){
return {
lineAttributes: [],
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else if (!hasList() && hasLineAttributes){
return {
lineAttributes: [],
inlineAttributeString: rawAttributeString,
inlinePlaintext: rawText
};
} else {
console.error("Plugin error: it seems the developer missed a case here.");
}
} else if (listsEnabled && lineAttributesEnabled) {
if (_hasNonlistLineAttributes()) {
return {
lineAttributes: _withoutListAttributes(lineAttributes),
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else {
return {
lineAttributes: [],
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
}
} else if (!listsEnabled && lineAttributesEnabled) {
return {
lineAttributes: lineAttributes,
inlineAttributeString: inlineAttributeString,
inlinePlaintext: extractedText
};
} else {
console.error("Plugin error: it seems the developer missed a case here.");
}
} | [
"function",
"(",
"listsEnabled",
",",
"lineAttributesEnabled",
")",
"{",
"if",
"(",
"(",
"!",
"hasList",
"(",
")",
"&&",
"!",
"hasLineAttributes",
")",
"||",
"(",
"!",
"listsEnabled",
"&&",
"!",
"lineAttributesEnabled",
")",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"[",
"]",
",",
"inlineAttributeString",
":",
"rawAttributeString",
",",
"inlinePlaintext",
":",
"rawText",
"}",
";",
"}",
"if",
"(",
"listsEnabled",
"&&",
"!",
"lineAttributesEnabled",
")",
"{",
"if",
"(",
"hasList",
"(",
")",
"&&",
"_hasNonlistLineAttributes",
"(",
")",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"[",
"]",
",",
"inlineAttributeString",
":",
"_attributeStringWithoutListAttributes",
"(",
"rawAttributeString",
")",
",",
"inlinePlaintext",
":",
"rawText",
"}",
";",
"}",
"else",
"if",
"(",
"hasList",
"(",
")",
"&&",
"!",
"_hasNonlistLineAttributes",
"(",
")",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"[",
"]",
",",
"inlineAttributeString",
":",
"inlineAttributeString",
",",
"inlinePlaintext",
":",
"extractedText",
"}",
";",
"}",
"else",
"if",
"(",
"!",
"hasList",
"(",
")",
"&&",
"hasLineAttributes",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"[",
"]",
",",
"inlineAttributeString",
":",
"rawAttributeString",
",",
"inlinePlaintext",
":",
"rawText",
"}",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"Plugin error: it seems the developer missed a case here.\"",
")",
";",
"}",
"}",
"else",
"if",
"(",
"listsEnabled",
"&&",
"lineAttributesEnabled",
")",
"{",
"if",
"(",
"_hasNonlistLineAttributes",
"(",
")",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"_withoutListAttributes",
"(",
"lineAttributes",
")",
",",
"inlineAttributeString",
":",
"inlineAttributeString",
",",
"inlinePlaintext",
":",
"extractedText",
"}",
";",
"}",
"else",
"{",
"return",
"{",
"lineAttributes",
":",
"[",
"]",
",",
"inlineAttributeString",
":",
"inlineAttributeString",
",",
"inlinePlaintext",
":",
"extractedText",
"}",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"listsEnabled",
"&&",
"lineAttributesEnabled",
")",
"{",
"return",
"{",
"lineAttributes",
":",
"lineAttributes",
",",
"inlineAttributeString",
":",
"inlineAttributeString",
",",
"inlinePlaintext",
":",
"extractedText",
"}",
";",
"}",
"else",
"{",
"console",
".",
"error",
"(",
"\"Plugin error: it seems the developer missed a case here.\"",
")",
";",
"}",
"}"
] | splits the line into line attributes and the remaining plain text and inline attributes
depending on the given parameters
@param {Boolean} listsEnabled if the client sent the parameter lists=true
@param {Boolean} lineAttributesEnabled if the client sent the parameter lineattribs=true
@return {lineAttributes: Array, inlineAttributeString: String, inlinePlaintext: String} | [
"splits",
"the",
"line",
"into",
"line",
"attributes",
"and",
"the",
"remaining",
"plain",
"text",
"and",
"inline",
"attributes",
"depending",
"on",
"the",
"given",
"parameters"
] | c46a742b66bc048453ebe26c7b3fbd710ae8f7c4 | https://github.com/stefanmintert/ep_xmlexport/blob/c46a742b66bc048453ebe26c7b3fbd710ae8f7c4/Line.js#L128-L182 |
|
54,798 | Jam3/innkeeper | lib/storeRedis.js | function( userID ) {
var id = curId;
curId++;
if( curId == Number.MAX_VALUE )
curId = Number.MIN_VALUE;
roomUsers[ id ] = [];
return this.setRoomData( id, {} )
.then( this.joinRoom.bind( this, userID, id ) )
.then( function() {
return id;
});
} | javascript | function( userID ) {
var id = curId;
curId++;
if( curId == Number.MAX_VALUE )
curId = Number.MIN_VALUE;
roomUsers[ id ] = [];
return this.setRoomData( id, {} )
.then( this.joinRoom.bind( this, userID, id ) )
.then( function() {
return id;
});
} | [
"function",
"(",
"userID",
")",
"{",
"var",
"id",
"=",
"curId",
";",
"curId",
"++",
";",
"if",
"(",
"curId",
"==",
"Number",
".",
"MAX_VALUE",
")",
"curId",
"=",
"Number",
".",
"MIN_VALUE",
";",
"roomUsers",
"[",
"id",
"]",
"=",
"[",
"]",
";",
"return",
"this",
".",
"setRoomData",
"(",
"id",
",",
"{",
"}",
")",
".",
"then",
"(",
"this",
".",
"joinRoom",
".",
"bind",
"(",
"this",
",",
"userID",
",",
"id",
")",
")",
".",
"then",
"(",
"function",
"(",
")",
"{",
"return",
"id",
";",
"}",
")",
";",
"}"
] | This will create a roomID, roomDataObject, and users array for the room
@return {Promise} This promise will return a room id once the room is created | [
"This",
"will",
"create",
"a",
"roomID",
"roomDataObject",
"and",
"users",
"array",
"for",
"the",
"room"
] | 95182271c62cf4416442c825189f025234b6ef1e | https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/lib/storeRedis.js#L36-L53 |
|
54,799 | Jam3/innkeeper | lib/storeRedis.js | function( userID, roomID ) {
var userCount;
if( roomUsers[ roomID ] === undefined ) {
return promise.reject( 'No room with the id: ' + roomID );
} else {
var userIDX = roomUsers[ roomID ].indexOf( userID );
if( userIDX != -1 ) {
roomUsers[ roomID ].splice( userIDX, 1 );
userCount = roomUsers[ roomID ].length;
if( userCount == 0 ) {
delete roomUsers[ roomID ];
}
return promise.resolve( userCount );
} else {
return promise.reject( 'User ' + userID + ' is not in the room: ' + roomID );
}
}
} | javascript | function( userID, roomID ) {
var userCount;
if( roomUsers[ roomID ] === undefined ) {
return promise.reject( 'No room with the id: ' + roomID );
} else {
var userIDX = roomUsers[ roomID ].indexOf( userID );
if( userIDX != -1 ) {
roomUsers[ roomID ].splice( userIDX, 1 );
userCount = roomUsers[ roomID ].length;
if( userCount == 0 ) {
delete roomUsers[ roomID ];
}
return promise.resolve( userCount );
} else {
return promise.reject( 'User ' + userID + ' is not in the room: ' + roomID );
}
}
} | [
"function",
"(",
"userID",
",",
"roomID",
")",
"{",
"var",
"userCount",
";",
"if",
"(",
"roomUsers",
"[",
"roomID",
"]",
"===",
"undefined",
")",
"{",
"return",
"promise",
".",
"reject",
"(",
"'No room with the id: '",
"+",
"roomID",
")",
";",
"}",
"else",
"{",
"var",
"userIDX",
"=",
"roomUsers",
"[",
"roomID",
"]",
".",
"indexOf",
"(",
"userID",
")",
";",
"if",
"(",
"userIDX",
"!=",
"-",
"1",
")",
"{",
"roomUsers",
"[",
"roomID",
"]",
".",
"splice",
"(",
"userIDX",
",",
"1",
")",
";",
"userCount",
"=",
"roomUsers",
"[",
"roomID",
"]",
".",
"length",
";",
"if",
"(",
"userCount",
"==",
"0",
")",
"{",
"delete",
"roomUsers",
"[",
"roomID",
"]",
";",
"}",
"return",
"promise",
".",
"resolve",
"(",
"userCount",
")",
";",
"}",
"else",
"{",
"return",
"promise",
".",
"reject",
"(",
"'User '",
"+",
"userID",
"+",
"' is not in the room: '",
"+",
"roomID",
")",
";",
"}",
"}",
"}"
] | Remove a user from a room
@param {String} userID an id for the user whose leaving
@param {String} roomID an id for the room the user is leaving
@return {Promise} When this promise resolves it will send the number of users in the room | [
"Remove",
"a",
"user",
"from",
"a",
"room"
] | 95182271c62cf4416442c825189f025234b6ef1e | https://github.com/Jam3/innkeeper/blob/95182271c62cf4416442c825189f025234b6ef1e/lib/storeRedis.js#L81-L109 |
Subsets and Splits