id
int32 0
58k
| repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
50,100 | Encapsule-Annex/onm-server-rest-routes | routes.js | function(req, res) {
if (!req._body || (req.body == null) || !req.body) {
res.send(400, "Invalid POST missing required request body.");
return;
}
if ((req.body.store == null) || !req.body.store) {
res.send(400, "Invalid POST mising 'store' property in request body.");
return;
}
if ((req.body.address == null) || !req.body.address) {
res.send(400, "Invalid POST missing 'address' property in request body.");
return;
}
if ((req.body.data == null) || !req.body.data) {
res.send(400, "Invalid POST missing 'data' property in request body.");
return;
}
var store = onmStoreDictionary[req.body.store];
if ((store == null) || !store) {
res.send(404, "The specified onm data store '" + req.body.store + "' does not exist on this server.");
return;
}
var address = undefined;
try {
address = store.model.createAddressFromHashString(req.body.address);
} catch (exception) {
console.error(exception);
res.send(403, "Invalid address '" + req.body.address + "' is outside of the data model's address space.");
return;
}
var namespace = undefined
try {
namespace = store.openNamespace(address);
} catch (exception) {
console.error(exception);
res.send(404, "Data component '" + req.body.address + "' does not exist in store '" + req.body.store + "'.");
return;
}
try {
namespace.fromJSON(req.body.data);
} catch (exception) {
console.error(exception);
res.send(400, "Unable to de-serialize JSON data in request.");
return;
}
res.send(204);
} | javascript | function(req, res) {
if (!req._body || (req.body == null) || !req.body) {
res.send(400, "Invalid POST missing required request body.");
return;
}
if ((req.body.store == null) || !req.body.store) {
res.send(400, "Invalid POST mising 'store' property in request body.");
return;
}
if ((req.body.address == null) || !req.body.address) {
res.send(400, "Invalid POST missing 'address' property in request body.");
return;
}
if ((req.body.data == null) || !req.body.data) {
res.send(400, "Invalid POST missing 'data' property in request body.");
return;
}
var store = onmStoreDictionary[req.body.store];
if ((store == null) || !store) {
res.send(404, "The specified onm data store '" + req.body.store + "' does not exist on this server.");
return;
}
var address = undefined;
try {
address = store.model.createAddressFromHashString(req.body.address);
} catch (exception) {
console.error(exception);
res.send(403, "Invalid address '" + req.body.address + "' is outside of the data model's address space.");
return;
}
var namespace = undefined
try {
namespace = store.openNamespace(address);
} catch (exception) {
console.error(exception);
res.send(404, "Data component '" + req.body.address + "' does not exist in store '" + req.body.store + "'.");
return;
}
try {
namespace.fromJSON(req.body.data);
} catch (exception) {
console.error(exception);
res.send(400, "Unable to de-serialize JSON data in request.");
return;
}
res.send(204);
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"!",
"req",
".",
"_body",
"||",
"(",
"req",
".",
"body",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST missing required request body.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"req",
".",
"body",
".",
"store",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
".",
"store",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST mising 'store' property in request body.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"req",
".",
"body",
".",
"address",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
".",
"address",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST missing 'address' property in request body.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"req",
".",
"body",
".",
"data",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
".",
"data",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST missing 'data' property in request body.\"",
")",
";",
"return",
";",
"}",
"var",
"store",
"=",
"onmStoreDictionary",
"[",
"req",
".",
"body",
".",
"store",
"]",
";",
"if",
"(",
"(",
"store",
"==",
"null",
")",
"||",
"!",
"store",
")",
"{",
"res",
".",
"send",
"(",
"404",
",",
"\"The specified onm data store '\"",
"+",
"req",
".",
"body",
".",
"store",
"+",
"\"' does not exist on this server.\"",
")",
";",
"return",
";",
"}",
"var",
"address",
"=",
"undefined",
";",
"try",
"{",
"address",
"=",
"store",
".",
"model",
".",
"createAddressFromHashString",
"(",
"req",
".",
"body",
".",
"address",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"console",
".",
"error",
"(",
"exception",
")",
";",
"res",
".",
"send",
"(",
"403",
",",
"\"Invalid address '\"",
"+",
"req",
".",
"body",
".",
"address",
"+",
"\"' is outside of the data model's address space.\"",
")",
";",
"return",
";",
"}",
"var",
"namespace",
"=",
"undefined",
"try",
"{",
"namespace",
"=",
"store",
".",
"openNamespace",
"(",
"address",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"console",
".",
"error",
"(",
"exception",
")",
";",
"res",
".",
"send",
"(",
"404",
",",
"\"Data component '\"",
"+",
"req",
".",
"body",
".",
"address",
"+",
"\"' does not exist in store '\"",
"+",
"req",
".",
"body",
".",
"store",
"+",
"\"'.\"",
")",
";",
"return",
";",
"}",
"try",
"{",
"namespace",
".",
"fromJSON",
"(",
"req",
".",
"body",
".",
"data",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"console",
".",
"error",
"(",
"exception",
")",
";",
"res",
".",
"send",
"(",
"400",
",",
"\"Unable to de-serialize JSON data in request.\"",
")",
";",
"return",
";",
"}",
"res",
".",
"send",
"(",
"204",
")",
";",
"}"
] | Overwrite a specific data component in a specific store. | [
"Overwrite",
"a",
"specific",
"data",
"component",
"in",
"a",
"specific",
"store",
"."
] | 2d831d46e13be0191c3562df20b61378bed49ee6 | https://github.com/Encapsule-Annex/onm-server-rest-routes/blob/2d831d46e13be0191c3562df20b61378bed49ee6/routes.js#L182-L228 |
|
50,101 | Encapsule-Annex/onm-server-rest-routes | routes.js | function(req, res) {
if (!req._body || (req.body == null) || !req.body) {
res.send(400, "Invalid POST missing required request body.");
return;
}
if ((req.body.store == null) || !req.body.store) {
res.send(400, "Invalid POST missing 'store' property in request body.");
return;
}
var store = onmStoreDictionary[req.body.store];
if ((store == null) || !store) {
res.send(404, "The specified onm data store '" + req.body.store + "' does not exist on this server.");
return;
}
// Delete the store if an address was not specified in the request body.
if ((req.body.address == null) || !req.body.address) {
console.log("deleting in-memory data store '" + req.body.store + "'.");
delete onmStoreDictionary[req.body.store];
res.send(204);
return;
}
// Attempt to delete the specified data component.
var addressHash = req.body.address
var address = undefined
try {
address = store.model.createAddressFromHashString(addressHash);
} catch (exception) {
console.error(exception);
res.send(403, "Invalid address '" + req.body.address + "' is outside of the data model's address space.");
return;
}
try {
store.removeComponent(address);
console.log("removed data component '" + addressHash + "' from in-memory store '" + req.body.store + "'.");
res.send(204);
} catch (exception) {
res.send(412, exception);
}
} | javascript | function(req, res) {
if (!req._body || (req.body == null) || !req.body) {
res.send(400, "Invalid POST missing required request body.");
return;
}
if ((req.body.store == null) || !req.body.store) {
res.send(400, "Invalid POST missing 'store' property in request body.");
return;
}
var store = onmStoreDictionary[req.body.store];
if ((store == null) || !store) {
res.send(404, "The specified onm data store '" + req.body.store + "' does not exist on this server.");
return;
}
// Delete the store if an address was not specified in the request body.
if ((req.body.address == null) || !req.body.address) {
console.log("deleting in-memory data store '" + req.body.store + "'.");
delete onmStoreDictionary[req.body.store];
res.send(204);
return;
}
// Attempt to delete the specified data component.
var addressHash = req.body.address
var address = undefined
try {
address = store.model.createAddressFromHashString(addressHash);
} catch (exception) {
console.error(exception);
res.send(403, "Invalid address '" + req.body.address + "' is outside of the data model's address space.");
return;
}
try {
store.removeComponent(address);
console.log("removed data component '" + addressHash + "' from in-memory store '" + req.body.store + "'.");
res.send(204);
} catch (exception) {
res.send(412, exception);
}
} | [
"function",
"(",
"req",
",",
"res",
")",
"{",
"if",
"(",
"!",
"req",
".",
"_body",
"||",
"(",
"req",
".",
"body",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST missing required request body.\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"(",
"req",
".",
"body",
".",
"store",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
".",
"store",
")",
"{",
"res",
".",
"send",
"(",
"400",
",",
"\"Invalid POST missing 'store' property in request body.\"",
")",
";",
"return",
";",
"}",
"var",
"store",
"=",
"onmStoreDictionary",
"[",
"req",
".",
"body",
".",
"store",
"]",
";",
"if",
"(",
"(",
"store",
"==",
"null",
")",
"||",
"!",
"store",
")",
"{",
"res",
".",
"send",
"(",
"404",
",",
"\"The specified onm data store '\"",
"+",
"req",
".",
"body",
".",
"store",
"+",
"\"' does not exist on this server.\"",
")",
";",
"return",
";",
"}",
"// Delete the store if an address was not specified in the request body.",
"if",
"(",
"(",
"req",
".",
"body",
".",
"address",
"==",
"null",
")",
"||",
"!",
"req",
".",
"body",
".",
"address",
")",
"{",
"console",
".",
"log",
"(",
"\"deleting in-memory data store '\"",
"+",
"req",
".",
"body",
".",
"store",
"+",
"\"'.\"",
")",
";",
"delete",
"onmStoreDictionary",
"[",
"req",
".",
"body",
".",
"store",
"]",
";",
"res",
".",
"send",
"(",
"204",
")",
";",
"return",
";",
"}",
"// Attempt to delete the specified data component.",
"var",
"addressHash",
"=",
"req",
".",
"body",
".",
"address",
"var",
"address",
"=",
"undefined",
"try",
"{",
"address",
"=",
"store",
".",
"model",
".",
"createAddressFromHashString",
"(",
"addressHash",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"console",
".",
"error",
"(",
"exception",
")",
";",
"res",
".",
"send",
"(",
"403",
",",
"\"Invalid address '\"",
"+",
"req",
".",
"body",
".",
"address",
"+",
"\"' is outside of the data model's address space.\"",
")",
";",
"return",
";",
"}",
"try",
"{",
"store",
".",
"removeComponent",
"(",
"address",
")",
";",
"console",
".",
"log",
"(",
"\"removed data component '\"",
"+",
"addressHash",
"+",
"\"' from in-memory store '\"",
"+",
"req",
".",
"body",
".",
"store",
"+",
"\"'.\"",
")",
";",
"res",
".",
"send",
"(",
"204",
")",
";",
"}",
"catch",
"(",
"exception",
")",
"{",
"res",
".",
"send",
"(",
"412",
",",
"exception",
")",
";",
"}",
"}"
] | Delete the named onm data store. Or, if an address is specified delete the addressed data component in the given store instead. | [
"Delete",
"the",
"named",
"onm",
"data",
"store",
".",
"Or",
"if",
"an",
"address",
"is",
"specified",
"delete",
"the",
"addressed",
"data",
"component",
"in",
"the",
"given",
"store",
"instead",
"."
] | 2d831d46e13be0191c3562df20b61378bed49ee6 | https://github.com/Encapsule-Annex/onm-server-rest-routes/blob/2d831d46e13be0191c3562df20b61378bed49ee6/routes.js#L243-L281 |
|
50,102 | vamship/wysknd-test | lib/object.js | function(target, expectedInterface, ignoreExtra) {
if (typeof target !== 'object' || target instanceof Array) {
throw new Error('target object not specified, or is not valid (arg #1)');
}
if (typeof expectedInterface !== 'object' || expectedInterface instanceof Array) {
throw new Error('expected interface not specified, or is not valid (arg #2)');
}
var errors = [];
var prop;
// Make sure that every expected member exists.
for (prop in expectedInterface) {
if (!target[prop]) {
errors.push('Expected member not defined: [' + prop + ']');
}
}
// Make sure that every member has the correct type. This second
// iteration will also ensure that no additional methods are
// defined in the target.
for (prop in target) {
if (target.hasOwnProperty(prop)) {
var expectedType = expectedInterface[prop] || 'undefined';
if (expectedType !== 'undefined' || !ignoreExtra) {
var propertyType = (typeof target[prop]);
if (expectedType !== 'ignore' && propertyType !== expectedType) {
errors.push('Expected member [' + prop +
'] to be of type [' + expectedType +
'], but was of type [' + propertyType +
'] instead');
}
}
}
}
return errors;
} | javascript | function(target, expectedInterface, ignoreExtra) {
if (typeof target !== 'object' || target instanceof Array) {
throw new Error('target object not specified, or is not valid (arg #1)');
}
if (typeof expectedInterface !== 'object' || expectedInterface instanceof Array) {
throw new Error('expected interface not specified, or is not valid (arg #2)');
}
var errors = [];
var prop;
// Make sure that every expected member exists.
for (prop in expectedInterface) {
if (!target[prop]) {
errors.push('Expected member not defined: [' + prop + ']');
}
}
// Make sure that every member has the correct type. This second
// iteration will also ensure that no additional methods are
// defined in the target.
for (prop in target) {
if (target.hasOwnProperty(prop)) {
var expectedType = expectedInterface[prop] || 'undefined';
if (expectedType !== 'undefined' || !ignoreExtra) {
var propertyType = (typeof target[prop]);
if (expectedType !== 'ignore' && propertyType !== expectedType) {
errors.push('Expected member [' + prop +
'] to be of type [' + expectedType +
'], but was of type [' + propertyType +
'] instead');
}
}
}
}
return errors;
} | [
"function",
"(",
"target",
",",
"expectedInterface",
",",
"ignoreExtra",
")",
"{",
"if",
"(",
"typeof",
"target",
"!==",
"'object'",
"||",
"target",
"instanceof",
"Array",
")",
"{",
"throw",
"new",
"Error",
"(",
"'target object not specified, or is not valid (arg #1)'",
")",
";",
"}",
"if",
"(",
"typeof",
"expectedInterface",
"!==",
"'object'",
"||",
"expectedInterface",
"instanceof",
"Array",
")",
"{",
"throw",
"new",
"Error",
"(",
"'expected interface not specified, or is not valid (arg #2)'",
")",
";",
"}",
"var",
"errors",
"=",
"[",
"]",
";",
"var",
"prop",
";",
"// Make sure that every expected member exists.",
"for",
"(",
"prop",
"in",
"expectedInterface",
")",
"{",
"if",
"(",
"!",
"target",
"[",
"prop",
"]",
")",
"{",
"errors",
".",
"push",
"(",
"'Expected member not defined: ['",
"+",
"prop",
"+",
"']'",
")",
";",
"}",
"}",
"// Make sure that every member has the correct type. This second",
"// iteration will also ensure that no additional methods are",
"// defined in the target.",
"for",
"(",
"prop",
"in",
"target",
")",
"{",
"if",
"(",
"target",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"var",
"expectedType",
"=",
"expectedInterface",
"[",
"prop",
"]",
"||",
"'undefined'",
";",
"if",
"(",
"expectedType",
"!==",
"'undefined'",
"||",
"!",
"ignoreExtra",
")",
"{",
"var",
"propertyType",
"=",
"(",
"typeof",
"target",
"[",
"prop",
"]",
")",
";",
"if",
"(",
"expectedType",
"!==",
"'ignore'",
"&&",
"propertyType",
"!==",
"expectedType",
")",
"{",
"errors",
".",
"push",
"(",
"'Expected member ['",
"+",
"prop",
"+",
"'] to be of type ['",
"+",
"expectedType",
"+",
"'], but was of type ['",
"+",
"propertyType",
"+",
"'] instead'",
")",
";",
"}",
"}",
"}",
"}",
"return",
"errors",
";",
"}"
] | Tests that the given object matches the specified interface.
NOTE: This functionality is also available via a few mocha assertions,
and those can be used instead. This method is being retained for
backwards compatibility purposes.
@param {Object} target The target object whose interface is being
verified.
@param {Object} expectedInterface An object that defines the expected
interface.
@param {boolean} [ignoreExtra = false] An optional parameter that
indicates whether or not extra methods in the
target will result in errors.
@return {Array} An array containing error messages (if any). | [
"Tests",
"that",
"the",
"given",
"object",
"matches",
"the",
"specified",
"interface",
"."
] | b7791c42f1c1b36be7738e2c6d24748360634003 | https://github.com/vamship/wysknd-test/blob/b7791c42f1c1b36be7738e2c6d24748360634003/lib/object.js#L21-L58 |
|
50,103 | lyfeyaj/ovt | lib/types/any.js | function(ref, condition) {
condition = condition || {};
utils.assert(
condition.then || condition.otherwise ,
'one of condition.then or condition.otherwise must be existed'
);
utils.assert(
!condition.then || (condition.then && condition.then.isOvt),
'condition.then must be a valid ovt schema'
);
utils.assert(
!condition.otherwise || (condition.otherwise && condition.otherwise.isOvt),
'condition.otherwise must be a valid ovt schema'
);
if (utils.isString(ref)) ref = utils.ref(ref);
utils.assert(utils.isRef(ref), 'ref must be a valid string or ref object');
// overwrite `then` and `otherwise` options to allow unknown and not stripped
let options = { allowUnknown: true, stripUnknown: false };
if (condition.then) condition.then = condition.then.options(options);
if (condition.otherwise) condition.otherwise = condition.otherwise.options(options);
return [ref, condition];
} | javascript | function(ref, condition) {
condition = condition || {};
utils.assert(
condition.then || condition.otherwise ,
'one of condition.then or condition.otherwise must be existed'
);
utils.assert(
!condition.then || (condition.then && condition.then.isOvt),
'condition.then must be a valid ovt schema'
);
utils.assert(
!condition.otherwise || (condition.otherwise && condition.otherwise.isOvt),
'condition.otherwise must be a valid ovt schema'
);
if (utils.isString(ref)) ref = utils.ref(ref);
utils.assert(utils.isRef(ref), 'ref must be a valid string or ref object');
// overwrite `then` and `otherwise` options to allow unknown and not stripped
let options = { allowUnknown: true, stripUnknown: false };
if (condition.then) condition.then = condition.then.options(options);
if (condition.otherwise) condition.otherwise = condition.otherwise.options(options);
return [ref, condition];
} | [
"function",
"(",
"ref",
",",
"condition",
")",
"{",
"condition",
"=",
"condition",
"||",
"{",
"}",
";",
"utils",
".",
"assert",
"(",
"condition",
".",
"then",
"||",
"condition",
".",
"otherwise",
",",
"'one of condition.then or condition.otherwise must be existed'",
")",
";",
"utils",
".",
"assert",
"(",
"!",
"condition",
".",
"then",
"||",
"(",
"condition",
".",
"then",
"&&",
"condition",
".",
"then",
".",
"isOvt",
")",
",",
"'condition.then must be a valid ovt schema'",
")",
";",
"utils",
".",
"assert",
"(",
"!",
"condition",
".",
"otherwise",
"||",
"(",
"condition",
".",
"otherwise",
"&&",
"condition",
".",
"otherwise",
".",
"isOvt",
")",
",",
"'condition.otherwise must be a valid ovt schema'",
")",
";",
"if",
"(",
"utils",
".",
"isString",
"(",
"ref",
")",
")",
"ref",
"=",
"utils",
".",
"ref",
"(",
"ref",
")",
";",
"utils",
".",
"assert",
"(",
"utils",
".",
"isRef",
"(",
"ref",
")",
",",
"'ref must be a valid string or ref object'",
")",
";",
"// overwrite `then` and `otherwise` options to allow unknown and not stripped",
"let",
"options",
"=",
"{",
"allowUnknown",
":",
"true",
",",
"stripUnknown",
":",
"false",
"}",
";",
"if",
"(",
"condition",
".",
"then",
")",
"condition",
".",
"then",
"=",
"condition",
".",
"then",
".",
"options",
"(",
"options",
")",
";",
"if",
"(",
"condition",
".",
"otherwise",
")",
"condition",
".",
"otherwise",
"=",
"condition",
".",
"otherwise",
".",
"options",
"(",
"options",
")",
";",
"return",
"[",
"ref",
",",
"condition",
"]",
";",
"}"
] | Check and parse ref and condition | [
"Check",
"and",
"parse",
"ref",
"and",
"condition"
] | ebd50a3531f1504cd356c869dda91200ad2f6539 | https://github.com/lyfeyaj/ovt/blob/ebd50a3531f1504cd356c869dda91200ad2f6539/lib/types/any.js#L92-L119 |
|
50,104 | unijs/bundle | build/web/c0.js | getHref | function getHref() {
return this.context.router.makeHref(this.props.to, this.props.params, this.props.query);
} | javascript | function getHref() {
return this.context.router.makeHref(this.props.to, this.props.params, this.props.query);
} | [
"function",
"getHref",
"(",
")",
"{",
"return",
"this",
".",
"context",
".",
"router",
".",
"makeHref",
"(",
"this",
".",
"props",
".",
"to",
",",
"this",
".",
"props",
".",
"params",
",",
"this",
".",
"props",
".",
"query",
")",
";",
"}"
] | Returns the value of the "href" attribute to use on the DOM element. | [
"Returns",
"the",
"value",
"of",
"the",
"href",
"attribute",
"to",
"use",
"on",
"the",
"DOM",
"element",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L217-L219 |
50,105 | unijs/bundle | build/web/c0.js | makePath | function makePath(to, params, query) {
return this.context.router.makePath(to, params, query);
} | javascript | function makePath(to, params, query) {
return this.context.router.makePath(to, params, query);
} | [
"function",
"makePath",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"return",
"this",
".",
"context",
".",
"router",
".",
"makePath",
"(",
"to",
",",
"params",
",",
"query",
")",
";",
"}"
] | Returns an absolute URL path created from the given route
name, URL parameters, and query values. | [
"Returns",
"an",
"absolute",
"URL",
"path",
"created",
"from",
"the",
"given",
"route",
"name",
"URL",
"parameters",
"and",
"query",
"values",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1073-L1075 |
50,106 | unijs/bundle | build/web/c0.js | makeHref | function makeHref(to, params, query) {
return this.context.router.makeHref(to, params, query);
} | javascript | function makeHref(to, params, query) {
return this.context.router.makeHref(to, params, query);
} | [
"function",
"makeHref",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"return",
"this",
".",
"context",
".",
"router",
".",
"makeHref",
"(",
"to",
",",
"params",
",",
"query",
")",
";",
"}"
] | Returns a string that may safely be used as the href of a
link to the route with the given name. | [
"Returns",
"a",
"string",
"that",
"may",
"safely",
"be",
"used",
"as",
"the",
"href",
"of",
"a",
"link",
"to",
"the",
"route",
"with",
"the",
"given",
"name",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1081-L1083 |
50,107 | unijs/bundle | build/web/c0.js | isActive | function isActive(to, params, query) {
return this.context.router.isActive(to, params, query);
} | javascript | function isActive(to, params, query) {
return this.context.router.isActive(to, params, query);
} | [
"function",
"isActive",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"return",
"this",
".",
"context",
".",
"router",
".",
"isActive",
"(",
"to",
",",
"params",
",",
"query",
")",
";",
"}"
] | A helper method to determine if a given route, params, and query
are active. | [
"A",
"helper",
"method",
"to",
"determine",
"if",
"a",
"given",
"route",
"params",
"and",
"query",
"are",
"active",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1180-L1182 |
50,108 | unijs/bundle | build/web/c0.js | appendChild | function appendChild(route) {
invariant(route instanceof Route, 'route.appendChild must use a valid Route');
if (!this.childRoutes) this.childRoutes = [];
this.childRoutes.push(route);
} | javascript | function appendChild(route) {
invariant(route instanceof Route, 'route.appendChild must use a valid Route');
if (!this.childRoutes) this.childRoutes = [];
this.childRoutes.push(route);
} | [
"function",
"appendChild",
"(",
"route",
")",
"{",
"invariant",
"(",
"route",
"instanceof",
"Route",
",",
"'route.appendChild must use a valid Route'",
")",
";",
"if",
"(",
"!",
"this",
".",
"childRoutes",
")",
"this",
".",
"childRoutes",
"=",
"[",
"]",
";",
"this",
".",
"childRoutes",
".",
"push",
"(",
"route",
")",
";",
"}"
] | Appends the given route to this route's child routes. | [
"Appends",
"the",
"given",
"route",
"to",
"this",
"route",
"s",
"child",
"routes",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1223-L1229 |
50,109 | unijs/bundle | build/web/c0.js | makePath | function makePath(to, params, query) {
var path;
if (PathUtils.isAbsolute(to)) {
path = to;
} else {
var route = to instanceof Route ? to : Router.namedRoutes[to];
invariant(route instanceof Route, 'Cannot find a route named "%s"', to);
path = route.path;
}
return PathUtils.withQuery(PathUtils.injectParams(path, params), query);
} | javascript | function makePath(to, params, query) {
var path;
if (PathUtils.isAbsolute(to)) {
path = to;
} else {
var route = to instanceof Route ? to : Router.namedRoutes[to];
invariant(route instanceof Route, 'Cannot find a route named "%s"', to);
path = route.path;
}
return PathUtils.withQuery(PathUtils.injectParams(path, params), query);
} | [
"function",
"makePath",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"var",
"path",
";",
"if",
"(",
"PathUtils",
".",
"isAbsolute",
"(",
"to",
")",
")",
"{",
"path",
"=",
"to",
";",
"}",
"else",
"{",
"var",
"route",
"=",
"to",
"instanceof",
"Route",
"?",
"to",
":",
"Router",
".",
"namedRoutes",
"[",
"to",
"]",
";",
"invariant",
"(",
"route",
"instanceof",
"Route",
",",
"'Cannot find a route named \"%s\"'",
",",
"to",
")",
";",
"path",
"=",
"route",
".",
"path",
";",
"}",
"return",
"PathUtils",
".",
"withQuery",
"(",
"PathUtils",
".",
"injectParams",
"(",
"path",
",",
"params",
")",
",",
"query",
")",
";",
"}"
] | Returns an absolute URL path created from the given route
name, URL parameters, and query. | [
"Returns",
"an",
"absolute",
"URL",
"path",
"created",
"from",
"the",
"given",
"route",
"name",
"URL",
"parameters",
"and",
"query",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1665-L1678 |
50,110 | unijs/bundle | build/web/c0.js | makeHref | function makeHref(to, params, query) {
var path = Router.makePath(to, params, query);
return location === HashLocation ? '#' + path : path;
} | javascript | function makeHref(to, params, query) {
var path = Router.makePath(to, params, query);
return location === HashLocation ? '#' + path : path;
} | [
"function",
"makeHref",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"var",
"path",
"=",
"Router",
".",
"makePath",
"(",
"to",
",",
"params",
",",
"query",
")",
";",
"return",
"location",
"===",
"HashLocation",
"?",
"'#'",
"+",
"path",
":",
"path",
";",
"}"
] | Returns a string that may safely be used as the href of a link
to the route with the given name, URL parameters, and query. | [
"Returns",
"a",
"string",
"that",
"may",
"safely",
"be",
"used",
"as",
"the",
"href",
"of",
"a",
"link",
"to",
"the",
"route",
"with",
"the",
"given",
"name",
"URL",
"parameters",
"and",
"query",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1684-L1687 |
50,111 | unijs/bundle | build/web/c0.js | goBack | function goBack() {
if (History.length > 1 || location === RefreshLocation) {
location.pop();
return true;
}
warning(false, 'goBack() was ignored because there is no router history');
return false;
} | javascript | function goBack() {
if (History.length > 1 || location === RefreshLocation) {
location.pop();
return true;
}
warning(false, 'goBack() was ignored because there is no router history');
return false;
} | [
"function",
"goBack",
"(",
")",
"{",
"if",
"(",
"History",
".",
"length",
">",
"1",
"||",
"location",
"===",
"RefreshLocation",
")",
"{",
"location",
".",
"pop",
"(",
")",
";",
"return",
"true",
";",
"}",
"warning",
"(",
"false",
",",
"'goBack() was ignored because there is no router history'",
")",
";",
"return",
"false",
";",
"}"
] | Transitions to the previous URL if one is available. Returns true if the
router was able to go back, false otherwise.
Note: The router only tracks history entries in your application, not the
current browser session, so you can safely call this function without guarding
against sending the user back to some other site. However, when using
RefreshLocation (which is the fallback for HistoryLocation in browsers that
don't support HTML5 history) this method will *always* send the client back
because we cannot reliably track history length. | [
"Transitions",
"to",
"the",
"previous",
"URL",
"if",
"one",
"is",
"available",
".",
"Returns",
"true",
"if",
"the",
"router",
"was",
"able",
"to",
"go",
"back",
"false",
"otherwise",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1723-L1732 |
50,112 | unijs/bundle | build/web/c0.js | isActive | function isActive(to, params, query) {
if (PathUtils.isAbsolute(to)) {
return to === state.path;
}return routeIsActive(state.routes, to) && paramsAreActive(state.params, params) && (query == null || queryIsActive(state.query, query));
} | javascript | function isActive(to, params, query) {
if (PathUtils.isAbsolute(to)) {
return to === state.path;
}return routeIsActive(state.routes, to) && paramsAreActive(state.params, params) && (query == null || queryIsActive(state.query, query));
} | [
"function",
"isActive",
"(",
"to",
",",
"params",
",",
"query",
")",
"{",
"if",
"(",
"PathUtils",
".",
"isAbsolute",
"(",
"to",
")",
")",
"{",
"return",
"to",
"===",
"state",
".",
"path",
";",
"}",
"return",
"routeIsActive",
"(",
"state",
".",
"routes",
",",
"to",
")",
"&&",
"paramsAreActive",
"(",
"state",
".",
"params",
",",
"params",
")",
"&&",
"(",
"query",
"==",
"null",
"||",
"queryIsActive",
"(",
"state",
".",
"query",
",",
"query",
")",
")",
";",
"}"
] | Returns true if the given route, params, and query are active. | [
"Returns",
"true",
"if",
"the",
"given",
"route",
"params",
"and",
"query",
"are",
"active",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L1935-L1939 |
50,113 | unijs/bundle | build/web/c0.js | extractParams | function extractParams(pattern, path) {
var _compilePattern = compilePattern(pattern);
var matcher = _compilePattern.matcher;
var paramNames = _compilePattern.paramNames;
var match = path.match(matcher);
if (!match) {
return null;
}var params = {};
paramNames.forEach(function (paramName, index) {
params[paramName] = match[index + 1];
});
return params;
} | javascript | function extractParams(pattern, path) {
var _compilePattern = compilePattern(pattern);
var matcher = _compilePattern.matcher;
var paramNames = _compilePattern.paramNames;
var match = path.match(matcher);
if (!match) {
return null;
}var params = {};
paramNames.forEach(function (paramName, index) {
params[paramName] = match[index + 1];
});
return params;
} | [
"function",
"extractParams",
"(",
"pattern",
",",
"path",
")",
"{",
"var",
"_compilePattern",
"=",
"compilePattern",
"(",
"pattern",
")",
";",
"var",
"matcher",
"=",
"_compilePattern",
".",
"matcher",
";",
"var",
"paramNames",
"=",
"_compilePattern",
".",
"paramNames",
";",
"var",
"match",
"=",
"path",
".",
"match",
"(",
"matcher",
")",
";",
"if",
"(",
"!",
"match",
")",
"{",
"return",
"null",
";",
"}",
"var",
"params",
"=",
"{",
"}",
";",
"paramNames",
".",
"forEach",
"(",
"function",
"(",
"paramName",
",",
"index",
")",
"{",
"params",
"[",
"paramName",
"]",
"=",
"match",
"[",
"index",
"+",
"1",
"]",
";",
"}",
")",
";",
"return",
"params",
";",
"}"
] | Extracts the portions of the given URL path that match the given pattern
and returns an object of param name => value pairs. Returns null if the
pattern does not match the given path. | [
"Extracts",
"the",
"portions",
"of",
"the",
"given",
"URL",
"path",
"that",
"match",
"the",
"given",
"pattern",
"and",
"returns",
"an",
"object",
"of",
"param",
"name",
"=",
">",
"value",
"pairs",
".",
"Returns",
"null",
"if",
"the",
"pattern",
"does",
"not",
"match",
"the",
"given",
"path",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L2727-L2744 |
50,114 | unijs/bundle | build/web/c0.js | injectParams | function injectParams(pattern, params) {
params = params || {};
var splatIndex = 0;
return pattern.replace(paramInjectMatcher, function (match, paramName) {
paramName = paramName || 'splat';
// If param is optional don't check for existence
if (paramName.slice(-1) === '?') {
paramName = paramName.slice(0, -1);
if (params[paramName] == null) return '';
} else {
invariant(params[paramName] != null, 'Missing "%s" parameter for path "%s"', paramName, pattern);
}
var segment;
if (paramName === 'splat' && Array.isArray(params[paramName])) {
segment = params[paramName][splatIndex++];
invariant(segment != null, 'Missing splat # %s for path "%s"', splatIndex, pattern);
} else {
segment = params[paramName];
}
return segment;
}).replace(paramInjectTrailingSlashMatcher, '/');
} | javascript | function injectParams(pattern, params) {
params = params || {};
var splatIndex = 0;
return pattern.replace(paramInjectMatcher, function (match, paramName) {
paramName = paramName || 'splat';
// If param is optional don't check for existence
if (paramName.slice(-1) === '?') {
paramName = paramName.slice(0, -1);
if (params[paramName] == null) return '';
} else {
invariant(params[paramName] != null, 'Missing "%s" parameter for path "%s"', paramName, pattern);
}
var segment;
if (paramName === 'splat' && Array.isArray(params[paramName])) {
segment = params[paramName][splatIndex++];
invariant(segment != null, 'Missing splat # %s for path "%s"', splatIndex, pattern);
} else {
segment = params[paramName];
}
return segment;
}).replace(paramInjectTrailingSlashMatcher, '/');
} | [
"function",
"injectParams",
"(",
"pattern",
",",
"params",
")",
"{",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"var",
"splatIndex",
"=",
"0",
";",
"return",
"pattern",
".",
"replace",
"(",
"paramInjectMatcher",
",",
"function",
"(",
"match",
",",
"paramName",
")",
"{",
"paramName",
"=",
"paramName",
"||",
"'splat'",
";",
"// If param is optional don't check for existence",
"if",
"(",
"paramName",
".",
"slice",
"(",
"-",
"1",
")",
"===",
"'?'",
")",
"{",
"paramName",
"=",
"paramName",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
";",
"if",
"(",
"params",
"[",
"paramName",
"]",
"==",
"null",
")",
"return",
"''",
";",
"}",
"else",
"{",
"invariant",
"(",
"params",
"[",
"paramName",
"]",
"!=",
"null",
",",
"'Missing \"%s\" parameter for path \"%s\"'",
",",
"paramName",
",",
"pattern",
")",
";",
"}",
"var",
"segment",
";",
"if",
"(",
"paramName",
"===",
"'splat'",
"&&",
"Array",
".",
"isArray",
"(",
"params",
"[",
"paramName",
"]",
")",
")",
"{",
"segment",
"=",
"params",
"[",
"paramName",
"]",
"[",
"splatIndex",
"++",
"]",
";",
"invariant",
"(",
"segment",
"!=",
"null",
",",
"'Missing splat # %s for path \"%s\"'",
",",
"splatIndex",
",",
"pattern",
")",
";",
"}",
"else",
"{",
"segment",
"=",
"params",
"[",
"paramName",
"]",
";",
"}",
"return",
"segment",
";",
"}",
")",
".",
"replace",
"(",
"paramInjectTrailingSlashMatcher",
",",
"'/'",
")",
";",
"}"
] | Returns a version of the given route path with params interpolated. Throws
if there is a dynamic segment of the route path for which there is no param. | [
"Returns",
"a",
"version",
"of",
"the",
"given",
"route",
"path",
"with",
"params",
"interpolated",
".",
"Throws",
"if",
"there",
"is",
"a",
"dynamic",
"segment",
"of",
"the",
"route",
"path",
"for",
"which",
"there",
"is",
"no",
"param",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L2750-L2778 |
50,115 | unijs/bundle | build/web/c0.js | extractQuery | function extractQuery(path) {
var match = path.match(queryMatcher);
return match && qs.parse(match[1]);
} | javascript | function extractQuery(path) {
var match = path.match(queryMatcher);
return match && qs.parse(match[1]);
} | [
"function",
"extractQuery",
"(",
"path",
")",
"{",
"var",
"match",
"=",
"path",
".",
"match",
"(",
"queryMatcher",
")",
";",
"return",
"match",
"&&",
"qs",
".",
"parse",
"(",
"match",
"[",
"1",
"]",
")",
";",
"}"
] | Returns an object that is the result of parsing any query string contained
in the given path, null if the path contains no query string. | [
"Returns",
"an",
"object",
"that",
"is",
"the",
"result",
"of",
"parsing",
"any",
"query",
"string",
"contained",
"in",
"the",
"given",
"path",
"null",
"if",
"the",
"path",
"contains",
"no",
"query",
"string",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L2784-L2787 |
50,116 | unijs/bundle | build/web/c0.js | withQuery | function withQuery(path, query) {
var existingQuery = PathUtils.extractQuery(path);
if (existingQuery) query = query ? assign(existingQuery, query) : existingQuery;
var queryString = qs.stringify(query, { arrayFormat: 'brackets' });
if (queryString) {
return PathUtils.withoutQuery(path) + '?' + queryString;
}return PathUtils.withoutQuery(path);
} | javascript | function withQuery(path, query) {
var existingQuery = PathUtils.extractQuery(path);
if (existingQuery) query = query ? assign(existingQuery, query) : existingQuery;
var queryString = qs.stringify(query, { arrayFormat: 'brackets' });
if (queryString) {
return PathUtils.withoutQuery(path) + '?' + queryString;
}return PathUtils.withoutQuery(path);
} | [
"function",
"withQuery",
"(",
"path",
",",
"query",
")",
"{",
"var",
"existingQuery",
"=",
"PathUtils",
".",
"extractQuery",
"(",
"path",
")",
";",
"if",
"(",
"existingQuery",
")",
"query",
"=",
"query",
"?",
"assign",
"(",
"existingQuery",
",",
"query",
")",
":",
"existingQuery",
";",
"var",
"queryString",
"=",
"qs",
".",
"stringify",
"(",
"query",
",",
"{",
"arrayFormat",
":",
"'brackets'",
"}",
")",
";",
"if",
"(",
"queryString",
")",
"{",
"return",
"PathUtils",
".",
"withoutQuery",
"(",
"path",
")",
"+",
"'?'",
"+",
"queryString",
";",
"}",
"return",
"PathUtils",
".",
"withoutQuery",
"(",
"path",
")",
";",
"}"
] | Returns a version of the given path with the parameters in the given
query merged into the query string. | [
"Returns",
"a",
"version",
"of",
"the",
"given",
"path",
"with",
"the",
"parameters",
"in",
"the",
"given",
"query",
"merged",
"into",
"the",
"query",
"string",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L2800-L2810 |
50,117 | unijs/bundle | build/web/c0.js | Transition | function Transition(path, retry) {
this.path = path;
this.abortReason = null;
// TODO: Change this to router.retryTransition(transition)
this.retry = retry.bind(this);
} | javascript | function Transition(path, retry) {
this.path = path;
this.abortReason = null;
// TODO: Change this to router.retryTransition(transition)
this.retry = retry.bind(this);
} | [
"function",
"Transition",
"(",
"path",
",",
"retry",
")",
"{",
"this",
".",
"path",
"=",
"path",
";",
"this",
".",
"abortReason",
"=",
"null",
";",
"// TODO: Change this to router.retryTransition(transition)",
"this",
".",
"retry",
"=",
"retry",
".",
"bind",
"(",
"this",
")",
";",
"}"
] | Encapsulates a transition to a given path.
The willTransitionTo and willTransitionFrom handlers receive
an instance of this class as their first argument. | [
"Encapsulates",
"a",
"transition",
"to",
"a",
"given",
"path",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L2922-L2927 |
50,118 | unijs/bundle | build/web/c0.js | findMatch | function findMatch(routes, path) {
var pathname = PathUtils.withoutQuery(path);
var query = PathUtils.extractQuery(path);
var match = null;
for (var i = 0, len = routes.length; match == null && i < len; ++i) match = deepSearch(routes[i], pathname, query);
return match;
} | javascript | function findMatch(routes, path) {
var pathname = PathUtils.withoutQuery(path);
var query = PathUtils.extractQuery(path);
var match = null;
for (var i = 0, len = routes.length; match == null && i < len; ++i) match = deepSearch(routes[i], pathname, query);
return match;
} | [
"function",
"findMatch",
"(",
"routes",
",",
"path",
")",
"{",
"var",
"pathname",
"=",
"PathUtils",
".",
"withoutQuery",
"(",
"path",
")",
";",
"var",
"query",
"=",
"PathUtils",
".",
"extractQuery",
"(",
"path",
")",
";",
"var",
"match",
"=",
"null",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"len",
"=",
"routes",
".",
"length",
";",
"match",
"==",
"null",
"&&",
"i",
"<",
"len",
";",
"++",
"i",
")",
"match",
"=",
"deepSearch",
"(",
"routes",
"[",
"i",
"]",
",",
"pathname",
",",
"query",
")",
";",
"return",
"match",
";",
"}"
] | Attempts to match depth-first a route in the given route's
subtree against the given path and returns the match if it
succeeds, null if no match can be made. | [
"Attempts",
"to",
"match",
"depth",
"-",
"first",
"a",
"route",
"in",
"the",
"given",
"route",
"s",
"subtree",
"against",
"the",
"given",
"path",
"and",
"returns",
"the",
"match",
"if",
"it",
"succeeds",
"null",
"if",
"no",
"match",
"can",
"be",
"made",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L3071-L3079 |
50,119 | unijs/bundle | build/web/c0.js | bindAutoBindMethod | function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
if ("production" !== process.env.NODE_ENV) {
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName;
var _bind = boundMethod.bind;
/* eslint-disable block-scoped-var, no-undef */
boundMethod.bind = function(newThis ) {for (var args=[],$__0=1,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]);
// User is trying to bind() an autobound method; we effectively will
// ignore the value of "this" that the user is trying to use, so
// let's warn.
if (newThis !== component && newThis !== null) {
("production" !== process.env.NODE_ENV ? warning(
false,
'bind(): React component methods may only be bound to the ' +
'component instance. See %s',
componentName
) : null);
} else if (!args.length) {
("production" !== process.env.NODE_ENV ? warning(
false,
'bind(): You are binding a component method to the component. ' +
'React does this for you automatically in a high-performance ' +
'way, so you can safely remove this call. See %s',
componentName
) : null);
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
/* eslint-enable */
};
}
return boundMethod;
} | javascript | function bindAutoBindMethod(component, method) {
var boundMethod = method.bind(component);
if ("production" !== process.env.NODE_ENV) {
boundMethod.__reactBoundContext = component;
boundMethod.__reactBoundMethod = method;
boundMethod.__reactBoundArguments = null;
var componentName = component.constructor.displayName;
var _bind = boundMethod.bind;
/* eslint-disable block-scoped-var, no-undef */
boundMethod.bind = function(newThis ) {for (var args=[],$__0=1,$__1=arguments.length;$__0<$__1;$__0++) args.push(arguments[$__0]);
// User is trying to bind() an autobound method; we effectively will
// ignore the value of "this" that the user is trying to use, so
// let's warn.
if (newThis !== component && newThis !== null) {
("production" !== process.env.NODE_ENV ? warning(
false,
'bind(): React component methods may only be bound to the ' +
'component instance. See %s',
componentName
) : null);
} else if (!args.length) {
("production" !== process.env.NODE_ENV ? warning(
false,
'bind(): You are binding a component method to the component. ' +
'React does this for you automatically in a high-performance ' +
'way, so you can safely remove this call. See %s',
componentName
) : null);
return boundMethod;
}
var reboundMethod = _bind.apply(boundMethod, arguments);
reboundMethod.__reactBoundContext = component;
reboundMethod.__reactBoundMethod = method;
reboundMethod.__reactBoundArguments = args;
return reboundMethod;
/* eslint-enable */
};
}
return boundMethod;
} | [
"function",
"bindAutoBindMethod",
"(",
"component",
",",
"method",
")",
"{",
"var",
"boundMethod",
"=",
"method",
".",
"bind",
"(",
"component",
")",
";",
"if",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
")",
"{",
"boundMethod",
".",
"__reactBoundContext",
"=",
"component",
";",
"boundMethod",
".",
"__reactBoundMethod",
"=",
"method",
";",
"boundMethod",
".",
"__reactBoundArguments",
"=",
"null",
";",
"var",
"componentName",
"=",
"component",
".",
"constructor",
".",
"displayName",
";",
"var",
"_bind",
"=",
"boundMethod",
".",
"bind",
";",
"/* eslint-disable block-scoped-var, no-undef */",
"boundMethod",
".",
"bind",
"=",
"function",
"(",
"newThis",
")",
"{",
"for",
"(",
"var",
"args",
"=",
"[",
"]",
",",
"$__0",
"=",
"1",
",",
"$__1",
"=",
"arguments",
".",
"length",
";",
"$__0",
"<",
"$__1",
";",
"$__0",
"++",
")",
"args",
".",
"push",
"(",
"arguments",
"[",
"$__0",
"]",
")",
";",
"// User is trying to bind() an autobound method; we effectively will",
"// ignore the value of \"this\" that the user is trying to use, so",
"// let's warn.",
"if",
"(",
"newThis",
"!==",
"component",
"&&",
"newThis",
"!==",
"null",
")",
"{",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"warning",
"(",
"false",
",",
"'bind(): React component methods may only be bound to the '",
"+",
"'component instance. See %s'",
",",
"componentName",
")",
":",
"null",
")",
";",
"}",
"else",
"if",
"(",
"!",
"args",
".",
"length",
")",
"{",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"warning",
"(",
"false",
",",
"'bind(): You are binding a component method to the component. '",
"+",
"'React does this for you automatically in a high-performance '",
"+",
"'way, so you can safely remove this call. See %s'",
",",
"componentName",
")",
":",
"null",
")",
";",
"return",
"boundMethod",
";",
"}",
"var",
"reboundMethod",
"=",
"_bind",
".",
"apply",
"(",
"boundMethod",
",",
"arguments",
")",
";",
"reboundMethod",
".",
"__reactBoundContext",
"=",
"component",
";",
"reboundMethod",
".",
"__reactBoundMethod",
"=",
"method",
";",
"reboundMethod",
".",
"__reactBoundArguments",
"=",
"args",
";",
"return",
"reboundMethod",
";",
"/* eslint-enable */",
"}",
";",
"}",
"return",
"boundMethod",
";",
"}"
] | Binds a method to the component.
@param {object} component Component whose method is going to be bound.
@param {function} method Method to be bound.
@return {function} The bound method. | [
"Binds",
"a",
"method",
"to",
"the",
"component",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L4280-L4319 |
50,120 | unijs/bundle | build/web/c0.js | function(type, key, ref, owner, context, props) {
// Built-in properties that belong on the element
this.type = type;
this.key = key;
this.ref = ref;
// Record the component responsible for creating this element.
this._owner = owner;
// TODO: Deprecate withContext, and then the context becomes accessible
// through the owner.
this._context = context;
if ("production" !== process.env.NODE_ENV) {
// The validation flag and props are currently mutative. We put them on
// an external backing store so that we can freeze the whole object.
// This can be replaced with a WeakMap once they are implemented in
// commonly used development environments.
this._store = {props: props, originalProps: assign({}, props)};
// To make comparing ReactElements easier for testing purposes, we make
// the validation flag non-enumerable (where possible, which should
// include every environment we run tests in), so the test framework
// ignores it.
try {
Object.defineProperty(this._store, 'validated', {
configurable: false,
enumerable: false,
writable: true
});
} catch (x) {
}
this._store.validated = false;
// We're not allowed to set props directly on the object so we early
// return and rely on the prototype membrane to forward to the backing
// store.
if (useMutationMembrane) {
Object.freeze(this);
return;
}
}
this.props = props;
} | javascript | function(type, key, ref, owner, context, props) {
// Built-in properties that belong on the element
this.type = type;
this.key = key;
this.ref = ref;
// Record the component responsible for creating this element.
this._owner = owner;
// TODO: Deprecate withContext, and then the context becomes accessible
// through the owner.
this._context = context;
if ("production" !== process.env.NODE_ENV) {
// The validation flag and props are currently mutative. We put them on
// an external backing store so that we can freeze the whole object.
// This can be replaced with a WeakMap once they are implemented in
// commonly used development environments.
this._store = {props: props, originalProps: assign({}, props)};
// To make comparing ReactElements easier for testing purposes, we make
// the validation flag non-enumerable (where possible, which should
// include every environment we run tests in), so the test framework
// ignores it.
try {
Object.defineProperty(this._store, 'validated', {
configurable: false,
enumerable: false,
writable: true
});
} catch (x) {
}
this._store.validated = false;
// We're not allowed to set props directly on the object so we early
// return and rely on the prototype membrane to forward to the backing
// store.
if (useMutationMembrane) {
Object.freeze(this);
return;
}
}
this.props = props;
} | [
"function",
"(",
"type",
",",
"key",
",",
"ref",
",",
"owner",
",",
"context",
",",
"props",
")",
"{",
"// Built-in properties that belong on the element",
"this",
".",
"type",
"=",
"type",
";",
"this",
".",
"key",
"=",
"key",
";",
"this",
".",
"ref",
"=",
"ref",
";",
"// Record the component responsible for creating this element.",
"this",
".",
"_owner",
"=",
"owner",
";",
"// TODO: Deprecate withContext, and then the context becomes accessible",
"// through the owner.",
"this",
".",
"_context",
"=",
"context",
";",
"if",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
")",
"{",
"// The validation flag and props are currently mutative. We put them on",
"// an external backing store so that we can freeze the whole object.",
"// This can be replaced with a WeakMap once they are implemented in",
"// commonly used development environments.",
"this",
".",
"_store",
"=",
"{",
"props",
":",
"props",
",",
"originalProps",
":",
"assign",
"(",
"{",
"}",
",",
"props",
")",
"}",
";",
"// To make comparing ReactElements easier for testing purposes, we make",
"// the validation flag non-enumerable (where possible, which should",
"// include every environment we run tests in), so the test framework",
"// ignores it.",
"try",
"{",
"Object",
".",
"defineProperty",
"(",
"this",
".",
"_store",
",",
"'validated'",
",",
"{",
"configurable",
":",
"false",
",",
"enumerable",
":",
"false",
",",
"writable",
":",
"true",
"}",
")",
";",
"}",
"catch",
"(",
"x",
")",
"{",
"}",
"this",
".",
"_store",
".",
"validated",
"=",
"false",
";",
"// We're not allowed to set props directly on the object so we early",
"// return and rely on the prototype membrane to forward to the backing",
"// store.",
"if",
"(",
"useMutationMembrane",
")",
"{",
"Object",
".",
"freeze",
"(",
"this",
")",
";",
"return",
";",
"}",
"}",
"this",
".",
"props",
"=",
"props",
";",
"}"
] | Base constructor for all React elements. This is only used to make this
work with a dynamic instanceof check. Nothing should live on this prototype.
@param {*} type
@param {string|object} ref
@param {*} key
@param {*} props
@internal | [
"Base",
"constructor",
"for",
"all",
"React",
"elements",
".",
"This",
"is",
"only",
"used",
"to",
"make",
"this",
"work",
"with",
"a",
"dynamic",
"instanceof",
"check",
".",
"Nothing",
"should",
"live",
"on",
"this",
"prototype",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L4780-L4824 |
|
50,121 | unijs/bundle | build/web/c0.js | getName | function getName(instance) {
var publicInstance = instance && instance.getPublicInstance();
if (!publicInstance) {
return undefined;
}
var constructor = publicInstance.constructor;
if (!constructor) {
return undefined;
}
return constructor.displayName || constructor.name || undefined;
} | javascript | function getName(instance) {
var publicInstance = instance && instance.getPublicInstance();
if (!publicInstance) {
return undefined;
}
var constructor = publicInstance.constructor;
if (!constructor) {
return undefined;
}
return constructor.displayName || constructor.name || undefined;
} | [
"function",
"getName",
"(",
"instance",
")",
"{",
"var",
"publicInstance",
"=",
"instance",
"&&",
"instance",
".",
"getPublicInstance",
"(",
")",
";",
"if",
"(",
"!",
"publicInstance",
")",
"{",
"return",
"undefined",
";",
"}",
"var",
"constructor",
"=",
"publicInstance",
".",
"constructor",
";",
"if",
"(",
"!",
"constructor",
")",
"{",
"return",
"undefined",
";",
"}",
"return",
"constructor",
".",
"displayName",
"||",
"constructor",
".",
"name",
"||",
"undefined",
";",
"}"
] | Gets the instance's name for use in warnings.
@internal
@return {?string} Display name or undefined | [
"Gets",
"the",
"instance",
"s",
"name",
"for",
"use",
"in",
"warnings",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5053-L5063 |
50,122 | unijs/bundle | build/web/c0.js | validateExplicitKey | function validateExplicitKey(element, parentType) {
if (element._store.validated || element.key != null) {
return;
}
element._store.validated = true;
warnAndMonitorForKeyUse(
'Each child in an array or iterator should have a unique "key" prop.',
element,
parentType
);
} | javascript | function validateExplicitKey(element, parentType) {
if (element._store.validated || element.key != null) {
return;
}
element._store.validated = true;
warnAndMonitorForKeyUse(
'Each child in an array or iterator should have a unique "key" prop.',
element,
parentType
);
} | [
"function",
"validateExplicitKey",
"(",
"element",
",",
"parentType",
")",
"{",
"if",
"(",
"element",
".",
"_store",
".",
"validated",
"||",
"element",
".",
"key",
"!=",
"null",
")",
"{",
"return",
";",
"}",
"element",
".",
"_store",
".",
"validated",
"=",
"true",
";",
"warnAndMonitorForKeyUse",
"(",
"'Each child in an array or iterator should have a unique \"key\" prop.'",
",",
"element",
",",
"parentType",
")",
";",
"}"
] | Warn if the element doesn't have an explicit key assigned to it.
This element is in an array. The array could grow and shrink or be
reordered. All children that haven't already been validated are required to
have a "key" property assigned to it.
@internal
@param {ReactElement} element Element that requires a key.
@param {*} parentType element's parent's type. | [
"Warn",
"if",
"the",
"element",
"doesn",
"t",
"have",
"an",
"explicit",
"key",
"assigned",
"to",
"it",
".",
"This",
"element",
"is",
"in",
"an",
"array",
".",
"The",
"array",
"could",
"grow",
"and",
"shrink",
"or",
"be",
"reordered",
".",
"All",
"children",
"that",
"haven",
"t",
"already",
"been",
"validated",
"are",
"required",
"to",
"have",
"a",
"key",
"property",
"assigned",
"to",
"it",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5088-L5099 |
50,123 | unijs/bundle | build/web/c0.js | validatePropertyKey | function validatePropertyKey(name, element, parentType) {
if (!NUMERIC_PROPERTY_REGEX.test(name)) {
return;
}
warnAndMonitorForKeyUse(
'Child objects should have non-numeric keys so ordering is preserved.',
element,
parentType
);
} | javascript | function validatePropertyKey(name, element, parentType) {
if (!NUMERIC_PROPERTY_REGEX.test(name)) {
return;
}
warnAndMonitorForKeyUse(
'Child objects should have non-numeric keys so ordering is preserved.',
element,
parentType
);
} | [
"function",
"validatePropertyKey",
"(",
"name",
",",
"element",
",",
"parentType",
")",
"{",
"if",
"(",
"!",
"NUMERIC_PROPERTY_REGEX",
".",
"test",
"(",
"name",
")",
")",
"{",
"return",
";",
"}",
"warnAndMonitorForKeyUse",
"(",
"'Child objects should have non-numeric keys so ordering is preserved.'",
",",
"element",
",",
"parentType",
")",
";",
"}"
] | Warn if the key is being defined as an object property but has an incorrect
value.
@internal
@param {string} name Property name of the key.
@param {ReactElement} element Component that requires a key.
@param {*} parentType element's parent's type. | [
"Warn",
"if",
"the",
"key",
"is",
"being",
"defined",
"as",
"an",
"object",
"property",
"but",
"has",
"an",
"incorrect",
"value",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5110-L5119 |
50,124 | unijs/bundle | build/web/c0.js | warnAndMonitorForKeyUse | function warnAndMonitorForKeyUse(message, element, parentType) {
var ownerName = getCurrentOwnerDisplayName();
var parentName = typeof parentType === 'string' ?
parentType : parentType.displayName || parentType.name;
var useName = ownerName || parentName;
var memoizer = ownerHasKeyUseWarning[message] || (
(ownerHasKeyUseWarning[message] = {})
);
if (memoizer.hasOwnProperty(useName)) {
return;
}
memoizer[useName] = true;
var parentOrOwnerAddendum =
ownerName ? (" Check the render method of " + ownerName + ".") :
parentName ? (" Check the React.render call using <" + parentName + ">.") :
'';
// Usually the current owner is the offender, but if it accepts children as a
// property, it may be the creator of the child that's responsible for
// assigning it a key.
var childOwnerAddendum = '';
if (element &&
element._owner &&
element._owner !== ReactCurrentOwner.current) {
// Name of the component that originally created this child.
var childOwnerName = getName(element._owner);
childOwnerAddendum = (" It was passed a child from " + childOwnerName + ".");
}
("production" !== process.env.NODE_ENV ? warning(
false,
message + '%s%s See https://fb.me/react-warning-keys for more information.',
parentOrOwnerAddendum,
childOwnerAddendum
) : null);
} | javascript | function warnAndMonitorForKeyUse(message, element, parentType) {
var ownerName = getCurrentOwnerDisplayName();
var parentName = typeof parentType === 'string' ?
parentType : parentType.displayName || parentType.name;
var useName = ownerName || parentName;
var memoizer = ownerHasKeyUseWarning[message] || (
(ownerHasKeyUseWarning[message] = {})
);
if (memoizer.hasOwnProperty(useName)) {
return;
}
memoizer[useName] = true;
var parentOrOwnerAddendum =
ownerName ? (" Check the render method of " + ownerName + ".") :
parentName ? (" Check the React.render call using <" + parentName + ">.") :
'';
// Usually the current owner is the offender, but if it accepts children as a
// property, it may be the creator of the child that's responsible for
// assigning it a key.
var childOwnerAddendum = '';
if (element &&
element._owner &&
element._owner !== ReactCurrentOwner.current) {
// Name of the component that originally created this child.
var childOwnerName = getName(element._owner);
childOwnerAddendum = (" It was passed a child from " + childOwnerName + ".");
}
("production" !== process.env.NODE_ENV ? warning(
false,
message + '%s%s See https://fb.me/react-warning-keys for more information.',
parentOrOwnerAddendum,
childOwnerAddendum
) : null);
} | [
"function",
"warnAndMonitorForKeyUse",
"(",
"message",
",",
"element",
",",
"parentType",
")",
"{",
"var",
"ownerName",
"=",
"getCurrentOwnerDisplayName",
"(",
")",
";",
"var",
"parentName",
"=",
"typeof",
"parentType",
"===",
"'string'",
"?",
"parentType",
":",
"parentType",
".",
"displayName",
"||",
"parentType",
".",
"name",
";",
"var",
"useName",
"=",
"ownerName",
"||",
"parentName",
";",
"var",
"memoizer",
"=",
"ownerHasKeyUseWarning",
"[",
"message",
"]",
"||",
"(",
"(",
"ownerHasKeyUseWarning",
"[",
"message",
"]",
"=",
"{",
"}",
")",
")",
";",
"if",
"(",
"memoizer",
".",
"hasOwnProperty",
"(",
"useName",
")",
")",
"{",
"return",
";",
"}",
"memoizer",
"[",
"useName",
"]",
"=",
"true",
";",
"var",
"parentOrOwnerAddendum",
"=",
"ownerName",
"?",
"(",
"\" Check the render method of \"",
"+",
"ownerName",
"+",
"\".\"",
")",
":",
"parentName",
"?",
"(",
"\" Check the React.render call using <\"",
"+",
"parentName",
"+",
"\">.\"",
")",
":",
"''",
";",
"// Usually the current owner is the offender, but if it accepts children as a",
"// property, it may be the creator of the child that's responsible for",
"// assigning it a key.",
"var",
"childOwnerAddendum",
"=",
"''",
";",
"if",
"(",
"element",
"&&",
"element",
".",
"_owner",
"&&",
"element",
".",
"_owner",
"!==",
"ReactCurrentOwner",
".",
"current",
")",
"{",
"// Name of the component that originally created this child.",
"var",
"childOwnerName",
"=",
"getName",
"(",
"element",
".",
"_owner",
")",
";",
"childOwnerAddendum",
"=",
"(",
"\" It was passed a child from \"",
"+",
"childOwnerName",
"+",
"\".\"",
")",
";",
"}",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"warning",
"(",
"false",
",",
"message",
"+",
"'%s%s See https://fb.me/react-warning-keys for more information.'",
",",
"parentOrOwnerAddendum",
",",
"childOwnerAddendum",
")",
":",
"null",
")",
";",
"}"
] | Shared warning and monitoring code for the key warnings.
@internal
@param {string} message The base warning that gets output.
@param {ReactElement} element Component that requires a key.
@param {*} parentType element's parent's type. | [
"Shared",
"warning",
"and",
"monitoring",
"code",
"for",
"the",
"key",
"warnings",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5129-L5167 |
50,125 | unijs/bundle | build/web/c0.js | validateChildKeys | function validateChildKeys(node, parentType) {
if (Array.isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
if (ReactElement.isValidElement(child)) {
validateExplicitKey(child, parentType);
}
}
} else if (ReactElement.isValidElement(node)) {
// This element was passed in a valid location.
node._store.validated = true;
} else if (node) {
var iteratorFn = getIteratorFn(node);
// Entry iterators provide implicit keys.
if (iteratorFn) {
if (iteratorFn !== node.entries) {
var iterator = iteratorFn.call(node);
var step;
while (!(step = iterator.next()).done) {
if (ReactElement.isValidElement(step.value)) {
validateExplicitKey(step.value, parentType);
}
}
}
} else if (typeof node === 'object') {
var fragment = ReactFragment.extractIfFragment(node);
for (var key in fragment) {
if (fragment.hasOwnProperty(key)) {
validatePropertyKey(key, fragment[key], parentType);
}
}
}
}
} | javascript | function validateChildKeys(node, parentType) {
if (Array.isArray(node)) {
for (var i = 0; i < node.length; i++) {
var child = node[i];
if (ReactElement.isValidElement(child)) {
validateExplicitKey(child, parentType);
}
}
} else if (ReactElement.isValidElement(node)) {
// This element was passed in a valid location.
node._store.validated = true;
} else if (node) {
var iteratorFn = getIteratorFn(node);
// Entry iterators provide implicit keys.
if (iteratorFn) {
if (iteratorFn !== node.entries) {
var iterator = iteratorFn.call(node);
var step;
while (!(step = iterator.next()).done) {
if (ReactElement.isValidElement(step.value)) {
validateExplicitKey(step.value, parentType);
}
}
}
} else if (typeof node === 'object') {
var fragment = ReactFragment.extractIfFragment(node);
for (var key in fragment) {
if (fragment.hasOwnProperty(key)) {
validatePropertyKey(key, fragment[key], parentType);
}
}
}
}
} | [
"function",
"validateChildKeys",
"(",
"node",
",",
"parentType",
")",
"{",
"if",
"(",
"Array",
".",
"isArray",
"(",
"node",
")",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"node",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"child",
"=",
"node",
"[",
"i",
"]",
";",
"if",
"(",
"ReactElement",
".",
"isValidElement",
"(",
"child",
")",
")",
"{",
"validateExplicitKey",
"(",
"child",
",",
"parentType",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"ReactElement",
".",
"isValidElement",
"(",
"node",
")",
")",
"{",
"// This element was passed in a valid location.",
"node",
".",
"_store",
".",
"validated",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"node",
")",
"{",
"var",
"iteratorFn",
"=",
"getIteratorFn",
"(",
"node",
")",
";",
"// Entry iterators provide implicit keys.",
"if",
"(",
"iteratorFn",
")",
"{",
"if",
"(",
"iteratorFn",
"!==",
"node",
".",
"entries",
")",
"{",
"var",
"iterator",
"=",
"iteratorFn",
".",
"call",
"(",
"node",
")",
";",
"var",
"step",
";",
"while",
"(",
"!",
"(",
"step",
"=",
"iterator",
".",
"next",
"(",
")",
")",
".",
"done",
")",
"{",
"if",
"(",
"ReactElement",
".",
"isValidElement",
"(",
"step",
".",
"value",
")",
")",
"{",
"validateExplicitKey",
"(",
"step",
".",
"value",
",",
"parentType",
")",
";",
"}",
"}",
"}",
"}",
"else",
"if",
"(",
"typeof",
"node",
"===",
"'object'",
")",
"{",
"var",
"fragment",
"=",
"ReactFragment",
".",
"extractIfFragment",
"(",
"node",
")",
";",
"for",
"(",
"var",
"key",
"in",
"fragment",
")",
"{",
"if",
"(",
"fragment",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"validatePropertyKey",
"(",
"key",
",",
"fragment",
"[",
"key",
"]",
",",
"parentType",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Ensure that every element either is passed in a static location, in an
array with an explicit keys property defined, or in an object literal
with valid key property.
@internal
@param {ReactNode} node Statically passed child of any type.
@param {*} parentType node's parent's type. | [
"Ensure",
"that",
"every",
"element",
"either",
"is",
"passed",
"in",
"a",
"static",
"location",
"in",
"an",
"array",
"with",
"an",
"explicit",
"keys",
"property",
"defined",
"or",
"in",
"an",
"object",
"literal",
"with",
"valid",
"key",
"property",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5178-L5211 |
50,126 | unijs/bundle | build/web/c0.js | is | function is(a, b) {
if (a !== a) {
// NaN
return b !== b;
}
if (a === 0 && b === 0) {
// +-0
return 1 / a === 1 / b;
}
return a === b;
} | javascript | function is(a, b) {
if (a !== a) {
// NaN
return b !== b;
}
if (a === 0 && b === 0) {
// +-0
return 1 / a === 1 / b;
}
return a === b;
} | [
"function",
"is",
"(",
"a",
",",
"b",
")",
"{",
"if",
"(",
"a",
"!==",
"a",
")",
"{",
"// NaN",
"return",
"b",
"!==",
"b",
";",
"}",
"if",
"(",
"a",
"===",
"0",
"&&",
"b",
"===",
"0",
")",
"{",
"// +-0",
"return",
"1",
"/",
"a",
"===",
"1",
"/",
"b",
";",
"}",
"return",
"a",
"===",
"b",
";",
"}"
] | Inline Object.is polyfill | [
"Inline",
"Object",
".",
"is",
"polyfill"
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5297-L5307 |
50,127 | unijs/bundle | build/web/c0.js | isValidID | function isValidID(id) {
return id === '' || (
id.charAt(0) === SEPARATOR && id.charAt(id.length - 1) !== SEPARATOR
);
} | javascript | function isValidID(id) {
return id === '' || (
id.charAt(0) === SEPARATOR && id.charAt(id.length - 1) !== SEPARATOR
);
} | [
"function",
"isValidID",
"(",
"id",
")",
"{",
"return",
"id",
"===",
"''",
"||",
"(",
"id",
".",
"charAt",
"(",
"0",
")",
"===",
"SEPARATOR",
"&&",
"id",
".",
"charAt",
"(",
"id",
".",
"length",
"-",
"1",
")",
"!==",
"SEPARATOR",
")",
";",
"}"
] | Checks if the supplied string is a valid React DOM ID.
@param {string} id A React DOM ID, maybe.
@return {boolean} True if the string is a valid React DOM ID.
@private | [
"Checks",
"if",
"the",
"supplied",
"string",
"is",
"a",
"valid",
"React",
"DOM",
"ID",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5969-L5973 |
50,128 | unijs/bundle | build/web/c0.js | isAncestorIDOf | function isAncestorIDOf(ancestorID, descendantID) {
return (
descendantID.indexOf(ancestorID) === 0 &&
isBoundary(descendantID, ancestorID.length)
);
} | javascript | function isAncestorIDOf(ancestorID, descendantID) {
return (
descendantID.indexOf(ancestorID) === 0 &&
isBoundary(descendantID, ancestorID.length)
);
} | [
"function",
"isAncestorIDOf",
"(",
"ancestorID",
",",
"descendantID",
")",
"{",
"return",
"(",
"descendantID",
".",
"indexOf",
"(",
"ancestorID",
")",
"===",
"0",
"&&",
"isBoundary",
"(",
"descendantID",
",",
"ancestorID",
".",
"length",
")",
")",
";",
"}"
] | Checks if the first ID is an ancestor of or equal to the second ID.
@param {string} ancestorID
@param {string} descendantID
@return {boolean} True if `ancestorID` is an ancestor of `descendantID`.
@internal | [
"Checks",
"if",
"the",
"first",
"ID",
"is",
"an",
"ancestor",
"of",
"or",
"equal",
"to",
"the",
"second",
"ID",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L5983-L5988 |
50,129 | unijs/bundle | build/web/c0.js | function(nextComponent, container) {
("production" !== process.env.NODE_ENV ? invariant(
container && (
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
),
'_registerComponent(...): Target container is not a DOM element.'
) : invariant(container && (
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
)));
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
var reactRootID = ReactMount.registerContainer(container);
instancesByReactRootID[reactRootID] = nextComponent;
return reactRootID;
} | javascript | function(nextComponent, container) {
("production" !== process.env.NODE_ENV ? invariant(
container && (
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
),
'_registerComponent(...): Target container is not a DOM element.'
) : invariant(container && (
(container.nodeType === ELEMENT_NODE_TYPE || container.nodeType === DOC_NODE_TYPE)
)));
ReactBrowserEventEmitter.ensureScrollValueMonitoring();
var reactRootID = ReactMount.registerContainer(container);
instancesByReactRootID[reactRootID] = nextComponent;
return reactRootID;
} | [
"function",
"(",
"nextComponent",
",",
"container",
")",
"{",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"invariant",
"(",
"container",
"&&",
"(",
"(",
"container",
".",
"nodeType",
"===",
"ELEMENT_NODE_TYPE",
"||",
"container",
".",
"nodeType",
"===",
"DOC_NODE_TYPE",
")",
")",
",",
"'_registerComponent(...): Target container is not a DOM element.'",
")",
":",
"invariant",
"(",
"container",
"&&",
"(",
"(",
"container",
".",
"nodeType",
"===",
"ELEMENT_NODE_TYPE",
"||",
"container",
".",
"nodeType",
"===",
"DOC_NODE_TYPE",
")",
")",
")",
")",
";",
"ReactBrowserEventEmitter",
".",
"ensureScrollValueMonitoring",
"(",
")",
";",
"var",
"reactRootID",
"=",
"ReactMount",
".",
"registerContainer",
"(",
"container",
")",
";",
"instancesByReactRootID",
"[",
"reactRootID",
"]",
"=",
"nextComponent",
";",
"return",
"reactRootID",
";",
"}"
] | Register a component into the instance map and starts scroll value
monitoring
@param {ReactComponent} nextComponent component instance to render
@param {DOMElement} container container to render into
@return {string} reactRoot ID prefix | [
"Register",
"a",
"component",
"into",
"the",
"instance",
"map",
"and",
"starts",
"scroll",
"value",
"monitoring"
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6601-L6616 |
|
50,130 | unijs/bundle | build/web/c0.js | function(
nextElement,
container,
shouldReuseMarkup
) {
// Various parts of our code (such as ReactCompositeComponent's
// _renderValidatedComponent) assume that calls to render aren't nested;
// verify that that's the case.
("production" !== process.env.NODE_ENV ? warning(
ReactCurrentOwner.current == null,
'_renderNewRootComponent(): Render methods should be a pure function ' +
'of props and state; triggering nested component updates from ' +
'render is not allowed. If necessary, trigger nested updates in ' +
'componentDidUpdate.'
) : null);
var componentInstance = instantiateReactComponent(nextElement, null);
var reactRootID = ReactMount._registerComponent(
componentInstance,
container
);
// The initial render is synchronous but any updates that happen during
// rendering, in componentWillMount or componentDidMount, will be batched
// according to the current batching strategy.
ReactUpdates.batchedUpdates(
batchedMountComponentIntoNode,
componentInstance,
reactRootID,
container,
shouldReuseMarkup
);
if ("production" !== process.env.NODE_ENV) {
// Record the root element in case it later gets transplanted.
rootElementsByReactRootID[reactRootID] =
getReactRootElementInContainer(container);
}
return componentInstance;
} | javascript | function(
nextElement,
container,
shouldReuseMarkup
) {
// Various parts of our code (such as ReactCompositeComponent's
// _renderValidatedComponent) assume that calls to render aren't nested;
// verify that that's the case.
("production" !== process.env.NODE_ENV ? warning(
ReactCurrentOwner.current == null,
'_renderNewRootComponent(): Render methods should be a pure function ' +
'of props and state; triggering nested component updates from ' +
'render is not allowed. If necessary, trigger nested updates in ' +
'componentDidUpdate.'
) : null);
var componentInstance = instantiateReactComponent(nextElement, null);
var reactRootID = ReactMount._registerComponent(
componentInstance,
container
);
// The initial render is synchronous but any updates that happen during
// rendering, in componentWillMount or componentDidMount, will be batched
// according to the current batching strategy.
ReactUpdates.batchedUpdates(
batchedMountComponentIntoNode,
componentInstance,
reactRootID,
container,
shouldReuseMarkup
);
if ("production" !== process.env.NODE_ENV) {
// Record the root element in case it later gets transplanted.
rootElementsByReactRootID[reactRootID] =
getReactRootElementInContainer(container);
}
return componentInstance;
} | [
"function",
"(",
"nextElement",
",",
"container",
",",
"shouldReuseMarkup",
")",
"{",
"// Various parts of our code (such as ReactCompositeComponent's",
"// _renderValidatedComponent) assume that calls to render aren't nested;",
"// verify that that's the case.",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"warning",
"(",
"ReactCurrentOwner",
".",
"current",
"==",
"null",
",",
"'_renderNewRootComponent(): Render methods should be a pure function '",
"+",
"'of props and state; triggering nested component updates from '",
"+",
"'render is not allowed. If necessary, trigger nested updates in '",
"+",
"'componentDidUpdate.'",
")",
":",
"null",
")",
";",
"var",
"componentInstance",
"=",
"instantiateReactComponent",
"(",
"nextElement",
",",
"null",
")",
";",
"var",
"reactRootID",
"=",
"ReactMount",
".",
"_registerComponent",
"(",
"componentInstance",
",",
"container",
")",
";",
"// The initial render is synchronous but any updates that happen during",
"// rendering, in componentWillMount or componentDidMount, will be batched",
"// according to the current batching strategy.",
"ReactUpdates",
".",
"batchedUpdates",
"(",
"batchedMountComponentIntoNode",
",",
"componentInstance",
",",
"reactRootID",
",",
"container",
",",
"shouldReuseMarkup",
")",
";",
"if",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
")",
"{",
"// Record the root element in case it later gets transplanted.",
"rootElementsByReactRootID",
"[",
"reactRootID",
"]",
"=",
"getReactRootElementInContainer",
"(",
"container",
")",
";",
"}",
"return",
"componentInstance",
";",
"}"
] | Render a new component into the DOM.
@param {ReactElement} nextElement element to render
@param {DOMElement} container container to render into
@param {boolean} shouldReuseMarkup if we should skip the markup insertion
@return {ReactComponent} nextComponent | [
"Render",
"a",
"new",
"component",
"into",
"the",
"DOM",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6625-L6666 |
|
50,131 | unijs/bundle | build/web/c0.js | function(constructor, props, container) {
var element = ReactElement.createElement(constructor, props);
return ReactMount.render(element, container);
} | javascript | function(constructor, props, container) {
var element = ReactElement.createElement(constructor, props);
return ReactMount.render(element, container);
} | [
"function",
"(",
"constructor",
",",
"props",
",",
"container",
")",
"{",
"var",
"element",
"=",
"ReactElement",
".",
"createElement",
"(",
"constructor",
",",
"props",
")",
";",
"return",
"ReactMount",
".",
"render",
"(",
"element",
",",
"container",
")",
";",
"}"
] | Constructs a component instance of `constructor` with `initialProps` and
renders it into the supplied `container`.
@param {function} constructor React component constructor.
@param {?object} props Initial props of the component instance.
@param {DOMElement} container DOM element to render into.
@return {ReactComponent} Component instance rendered in `container`. | [
"Constructs",
"a",
"component",
"instance",
"of",
"constructor",
"with",
"initialProps",
"and",
"renders",
"it",
"into",
"the",
"supplied",
"container",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6760-L6763 |
|
50,132 | unijs/bundle | build/web/c0.js | function(id) {
var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(id);
var container = containersByReactRootID[reactRootID];
if ("production" !== process.env.NODE_ENV) {
var rootElement = rootElementsByReactRootID[reactRootID];
if (rootElement && rootElement.parentNode !== container) {
("production" !== process.env.NODE_ENV ? invariant(
// Call internalGetID here because getID calls isValid which calls
// findReactContainerForID (this function).
internalGetID(rootElement) === reactRootID,
'ReactMount: Root element ID differed from reactRootID.'
) : invariant(// Call internalGetID here because getID calls isValid which calls
// findReactContainerForID (this function).
internalGetID(rootElement) === reactRootID));
var containerChild = container.firstChild;
if (containerChild &&
reactRootID === internalGetID(containerChild)) {
// If the container has a new child with the same ID as the old
// root element, then rootElementsByReactRootID[reactRootID] is
// just stale and needs to be updated. The case that deserves a
// warning is when the container is empty.
rootElementsByReactRootID[reactRootID] = containerChild;
} else {
("production" !== process.env.NODE_ENV ? warning(
false,
'ReactMount: Root element has been removed from its original ' +
'container. New container:', rootElement.parentNode
) : null);
}
}
}
return container;
} | javascript | function(id) {
var reactRootID = ReactInstanceHandles.getReactRootIDFromNodeID(id);
var container = containersByReactRootID[reactRootID];
if ("production" !== process.env.NODE_ENV) {
var rootElement = rootElementsByReactRootID[reactRootID];
if (rootElement && rootElement.parentNode !== container) {
("production" !== process.env.NODE_ENV ? invariant(
// Call internalGetID here because getID calls isValid which calls
// findReactContainerForID (this function).
internalGetID(rootElement) === reactRootID,
'ReactMount: Root element ID differed from reactRootID.'
) : invariant(// Call internalGetID here because getID calls isValid which calls
// findReactContainerForID (this function).
internalGetID(rootElement) === reactRootID));
var containerChild = container.firstChild;
if (containerChild &&
reactRootID === internalGetID(containerChild)) {
// If the container has a new child with the same ID as the old
// root element, then rootElementsByReactRootID[reactRootID] is
// just stale and needs to be updated. The case that deserves a
// warning is when the container is empty.
rootElementsByReactRootID[reactRootID] = containerChild;
} else {
("production" !== process.env.NODE_ENV ? warning(
false,
'ReactMount: Root element has been removed from its original ' +
'container. New container:', rootElement.parentNode
) : null);
}
}
}
return container;
} | [
"function",
"(",
"id",
")",
"{",
"var",
"reactRootID",
"=",
"ReactInstanceHandles",
".",
"getReactRootIDFromNodeID",
"(",
"id",
")",
";",
"var",
"container",
"=",
"containersByReactRootID",
"[",
"reactRootID",
"]",
";",
"if",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
")",
"{",
"var",
"rootElement",
"=",
"rootElementsByReactRootID",
"[",
"reactRootID",
"]",
";",
"if",
"(",
"rootElement",
"&&",
"rootElement",
".",
"parentNode",
"!==",
"container",
")",
"{",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"invariant",
"(",
"// Call internalGetID here because getID calls isValid which calls",
"// findReactContainerForID (this function).",
"internalGetID",
"(",
"rootElement",
")",
"===",
"reactRootID",
",",
"'ReactMount: Root element ID differed from reactRootID.'",
")",
":",
"invariant",
"(",
"// Call internalGetID here because getID calls isValid which calls",
"// findReactContainerForID (this function).",
"internalGetID",
"(",
"rootElement",
")",
"===",
"reactRootID",
")",
")",
";",
"var",
"containerChild",
"=",
"container",
".",
"firstChild",
";",
"if",
"(",
"containerChild",
"&&",
"reactRootID",
"===",
"internalGetID",
"(",
"containerChild",
")",
")",
"{",
"// If the container has a new child with the same ID as the old",
"// root element, then rootElementsByReactRootID[reactRootID] is",
"// just stale and needs to be updated. The case that deserves a",
"// warning is when the container is empty.",
"rootElementsByReactRootID",
"[",
"reactRootID",
"]",
"=",
"containerChild",
";",
"}",
"else",
"{",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"warning",
"(",
"false",
",",
"'ReactMount: Root element has been removed from its original '",
"+",
"'container. New container:'",
",",
"rootElement",
".",
"parentNode",
")",
":",
"null",
")",
";",
"}",
"}",
"}",
"return",
"container",
";",
"}"
] | Finds the container DOM element that contains React component to which the
supplied DOM `id` belongs.
@param {string} id The ID of an element rendered by a React component.
@return {?DOMElement} DOM element that contains the `id`. | [
"Finds",
"the",
"container",
"DOM",
"element",
"that",
"contains",
"React",
"component",
"to",
"which",
"the",
"supplied",
"DOM",
"id",
"belongs",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6878-L6913 |
|
50,133 | unijs/bundle | build/web/c0.js | function(node) {
if (node.nodeType !== 1) {
// Not a DOMElement, therefore not a React component
return false;
}
var id = ReactMount.getID(node);
return id ? id.charAt(0) === SEPARATOR : false;
} | javascript | function(node) {
if (node.nodeType !== 1) {
// Not a DOMElement, therefore not a React component
return false;
}
var id = ReactMount.getID(node);
return id ? id.charAt(0) === SEPARATOR : false;
} | [
"function",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"nodeType",
"!==",
"1",
")",
"{",
"// Not a DOMElement, therefore not a React component",
"return",
"false",
";",
"}",
"var",
"id",
"=",
"ReactMount",
".",
"getID",
"(",
"node",
")",
";",
"return",
"id",
"?",
"id",
".",
"charAt",
"(",
"0",
")",
"===",
"SEPARATOR",
":",
"false",
";",
"}"
] | True if the supplied `node` is rendered by React.
@param {*} node DOM Element to check.
@return {boolean} True if the DOM Element appears to be rendered by React.
@internal | [
"True",
"if",
"the",
"supplied",
"node",
"is",
"rendered",
"by",
"React",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6933-L6940 |
|
50,134 | unijs/bundle | build/web/c0.js | function(node) {
var current = node;
while (current && current.parentNode !== current) {
if (ReactMount.isRenderedByReact(current)) {
return current;
}
current = current.parentNode;
}
return null;
} | javascript | function(node) {
var current = node;
while (current && current.parentNode !== current) {
if (ReactMount.isRenderedByReact(current)) {
return current;
}
current = current.parentNode;
}
return null;
} | [
"function",
"(",
"node",
")",
"{",
"var",
"current",
"=",
"node",
";",
"while",
"(",
"current",
"&&",
"current",
".",
"parentNode",
"!==",
"current",
")",
"{",
"if",
"(",
"ReactMount",
".",
"isRenderedByReact",
"(",
"current",
")",
")",
"{",
"return",
"current",
";",
"}",
"current",
"=",
"current",
".",
"parentNode",
";",
"}",
"return",
"null",
";",
"}"
] | Traverses up the ancestors of the supplied node to find a node that is a
DOM representation of a React component.
@param {*} node
@return {?DOMEventTarget}
@internal | [
"Traverses",
"up",
"the",
"ancestors",
"of",
"the",
"supplied",
"node",
"to",
"find",
"a",
"node",
"that",
"is",
"a",
"DOM",
"representation",
"of",
"a",
"React",
"component",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L6950-L6959 |
|
50,135 | unijs/bundle | build/web/c0.js | function(publicInstance, partialProps) {
var internalInstance = getInternalInstanceReadyForUpdate(
publicInstance,
'setProps'
);
if (!internalInstance) {
return;
}
("production" !== process.env.NODE_ENV ? invariant(
internalInstance._isTopLevel,
'setProps(...): You called `setProps` on a ' +
'component with a parent. This is an anti-pattern since props will ' +
'get reactively updated when rendered. Instead, change the owner\'s ' +
'`render` method to pass the correct value as props to the component ' +
'where it is created.'
) : invariant(internalInstance._isTopLevel));
// Merge with the pending element if it exists, otherwise with existing
// element props.
var element = internalInstance._pendingElement ||
internalInstance._currentElement;
var props = assign({}, element.props, partialProps);
internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
element,
props
);
enqueueUpdate(internalInstance);
} | javascript | function(publicInstance, partialProps) {
var internalInstance = getInternalInstanceReadyForUpdate(
publicInstance,
'setProps'
);
if (!internalInstance) {
return;
}
("production" !== process.env.NODE_ENV ? invariant(
internalInstance._isTopLevel,
'setProps(...): You called `setProps` on a ' +
'component with a parent. This is an anti-pattern since props will ' +
'get reactively updated when rendered. Instead, change the owner\'s ' +
'`render` method to pass the correct value as props to the component ' +
'where it is created.'
) : invariant(internalInstance._isTopLevel));
// Merge with the pending element if it exists, otherwise with existing
// element props.
var element = internalInstance._pendingElement ||
internalInstance._currentElement;
var props = assign({}, element.props, partialProps);
internalInstance._pendingElement = ReactElement.cloneAndReplaceProps(
element,
props
);
enqueueUpdate(internalInstance);
} | [
"function",
"(",
"publicInstance",
",",
"partialProps",
")",
"{",
"var",
"internalInstance",
"=",
"getInternalInstanceReadyForUpdate",
"(",
"publicInstance",
",",
"'setProps'",
")",
";",
"if",
"(",
"!",
"internalInstance",
")",
"{",
"return",
";",
"}",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"invariant",
"(",
"internalInstance",
".",
"_isTopLevel",
",",
"'setProps(...): You called `setProps` on a '",
"+",
"'component with a parent. This is an anti-pattern since props will '",
"+",
"'get reactively updated when rendered. Instead, change the owner\\'s '",
"+",
"'`render` method to pass the correct value as props to the component '",
"+",
"'where it is created.'",
")",
":",
"invariant",
"(",
"internalInstance",
".",
"_isTopLevel",
")",
")",
";",
"// Merge with the pending element if it exists, otherwise with existing",
"// element props.",
"var",
"element",
"=",
"internalInstance",
".",
"_pendingElement",
"||",
"internalInstance",
".",
"_currentElement",
";",
"var",
"props",
"=",
"assign",
"(",
"{",
"}",
",",
"element",
".",
"props",
",",
"partialProps",
")",
";",
"internalInstance",
".",
"_pendingElement",
"=",
"ReactElement",
".",
"cloneAndReplaceProps",
"(",
"element",
",",
"props",
")",
";",
"enqueueUpdate",
"(",
"internalInstance",
")",
";",
"}"
] | Sets a subset of the props.
@param {ReactClass} publicInstance The instance that should rerender.
@param {object} partialProps Subset of the next props.
@internal | [
"Sets",
"a",
"subset",
"of",
"the",
"props",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L8973-L9003 |
|
50,136 | unijs/bundle | build/web/c0.js | function(transaction, prevElement, nextElement, context) {
assertValidProps(this._currentElement.props);
this._updateDOMProperties(prevElement.props, transaction);
this._updateDOMChildren(prevElement.props, transaction, context);
} | javascript | function(transaction, prevElement, nextElement, context) {
assertValidProps(this._currentElement.props);
this._updateDOMProperties(prevElement.props, transaction);
this._updateDOMChildren(prevElement.props, transaction, context);
} | [
"function",
"(",
"transaction",
",",
"prevElement",
",",
"nextElement",
",",
"context",
")",
"{",
"assertValidProps",
"(",
"this",
".",
"_currentElement",
".",
"props",
")",
";",
"this",
".",
"_updateDOMProperties",
"(",
"prevElement",
".",
"props",
",",
"transaction",
")",
";",
"this",
".",
"_updateDOMChildren",
"(",
"prevElement",
".",
"props",
",",
"transaction",
",",
"context",
")",
";",
"}"
] | Updates a native DOM component after it has already been allocated and
attached to the DOM. Reconciles the root DOM node, then recurses.
@param {ReactReconcileTransaction} transaction
@param {ReactElement} prevElement
@param {ReactElement} nextElement
@internal
@overridable | [
"Updates",
"a",
"native",
"DOM",
"component",
"after",
"it",
"has",
"already",
"been",
"allocated",
"and",
"attached",
"to",
"the",
"DOM",
".",
"Reconciles",
"the",
"root",
"DOM",
"node",
"then",
"recurses",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L9699-L9703 |
|
50,137 | unijs/bundle | build/web/c0.js | isNode | function isNode(object) {
return !!(object && (
((typeof Node === 'function' ? object instanceof Node : typeof object === 'object' &&
typeof object.nodeType === 'number' &&
typeof object.nodeName === 'string'))
));
} | javascript | function isNode(object) {
return !!(object && (
((typeof Node === 'function' ? object instanceof Node : typeof object === 'object' &&
typeof object.nodeType === 'number' &&
typeof object.nodeName === 'string'))
));
} | [
"function",
"isNode",
"(",
"object",
")",
"{",
"return",
"!",
"!",
"(",
"object",
"&&",
"(",
"(",
"(",
"typeof",
"Node",
"===",
"'function'",
"?",
"object",
"instanceof",
"Node",
":",
"typeof",
"object",
"===",
"'object'",
"&&",
"typeof",
"object",
".",
"nodeType",
"===",
"'number'",
"&&",
"typeof",
"object",
".",
"nodeName",
"===",
"'string'",
")",
")",
")",
")",
";",
"}"
] | Copyright 2013-2015, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
@providesModule isNode
@typechecks
@param {*} object The object to check.
@return {boolean} Whether or not the object is a DOM node. | [
"Copyright",
"2013",
"-",
"2015",
"Facebook",
"Inc",
".",
"All",
"rights",
"reserved",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L10205-L10211 |
50,138 | unijs/bundle | build/web/c0.js | function(id, name, value) {
var node = ReactMount.getNode(id);
("production" !== process.env.NODE_ENV ? invariant(
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
'updatePropertyByID(...): %s',
INVALID_PROPERTY_ERRORS[name]
) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
// If we're updating to null or undefined, we should remove the property
// from the DOM node instead of inadvertantly setting to a string. This
// brings us in line with the same behavior we have on initial render.
if (value != null) {
DOMPropertyOperations.setValueForProperty(node, name, value);
} else {
DOMPropertyOperations.deleteValueForProperty(node, name);
}
} | javascript | function(id, name, value) {
var node = ReactMount.getNode(id);
("production" !== process.env.NODE_ENV ? invariant(
!INVALID_PROPERTY_ERRORS.hasOwnProperty(name),
'updatePropertyByID(...): %s',
INVALID_PROPERTY_ERRORS[name]
) : invariant(!INVALID_PROPERTY_ERRORS.hasOwnProperty(name)));
// If we're updating to null or undefined, we should remove the property
// from the DOM node instead of inadvertantly setting to a string. This
// brings us in line with the same behavior we have on initial render.
if (value != null) {
DOMPropertyOperations.setValueForProperty(node, name, value);
} else {
DOMPropertyOperations.deleteValueForProperty(node, name);
}
} | [
"function",
"(",
"id",
",",
"name",
",",
"value",
")",
"{",
"var",
"node",
"=",
"ReactMount",
".",
"getNode",
"(",
"id",
")",
";",
"(",
"\"production\"",
"!==",
"process",
".",
"env",
".",
"NODE_ENV",
"?",
"invariant",
"(",
"!",
"INVALID_PROPERTY_ERRORS",
".",
"hasOwnProperty",
"(",
"name",
")",
",",
"'updatePropertyByID(...): %s'",
",",
"INVALID_PROPERTY_ERRORS",
"[",
"name",
"]",
")",
":",
"invariant",
"(",
"!",
"INVALID_PROPERTY_ERRORS",
".",
"hasOwnProperty",
"(",
"name",
")",
")",
")",
";",
"// If we're updating to null or undefined, we should remove the property",
"// from the DOM node instead of inadvertantly setting to a string. This",
"// brings us in line with the same behavior we have on initial render.",
"if",
"(",
"value",
"!=",
"null",
")",
"{",
"DOMPropertyOperations",
".",
"setValueForProperty",
"(",
"node",
",",
"name",
",",
"value",
")",
";",
"}",
"else",
"{",
"DOMPropertyOperations",
".",
"deleteValueForProperty",
"(",
"node",
",",
"name",
")",
";",
"}",
"}"
] | Updates a DOM node with new property values. This should only be used to
update DOM properties in `DOMProperty`.
@param {string} id ID of the node to update.
@param {string} name A valid property name, see `DOMProperty`.
@param {*} value New value of the property.
@internal | [
"Updates",
"a",
"DOM",
"node",
"with",
"new",
"property",
"values",
".",
"This",
"should",
"only",
"be",
"used",
"to",
"update",
"DOM",
"properties",
"in",
"DOMProperty",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L10895-L10911 |
|
50,139 | unijs/bundle | build/web/c0.js | function(id, styles) {
var node = ReactMount.getNode(id);
CSSPropertyOperations.setValueForStyles(node, styles);
} | javascript | function(id, styles) {
var node = ReactMount.getNode(id);
CSSPropertyOperations.setValueForStyles(node, styles);
} | [
"function",
"(",
"id",
",",
"styles",
")",
"{",
"var",
"node",
"=",
"ReactMount",
".",
"getNode",
"(",
"id",
")",
";",
"CSSPropertyOperations",
".",
"setValueForStyles",
"(",
"node",
",",
"styles",
")",
";",
"}"
] | Updates a DOM node with new style values. If a value is specified as '',
the corresponding style property will be unset.
@param {string} id ID of the node to update.
@param {object} styles Mapping from styles to values.
@internal | [
"Updates",
"a",
"DOM",
"node",
"with",
"new",
"style",
"values",
".",
"If",
"a",
"value",
"is",
"specified",
"as",
"the",
"corresponding",
"style",
"property",
"will",
"be",
"unset",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L10939-L10942 |
|
50,140 | unijs/bundle | build/web/c0.js | function(id, content) {
var node = ReactMount.getNode(id);
DOMChildrenOperations.updateTextContent(node, content);
} | javascript | function(id, content) {
var node = ReactMount.getNode(id);
DOMChildrenOperations.updateTextContent(node, content);
} | [
"function",
"(",
"id",
",",
"content",
")",
"{",
"var",
"node",
"=",
"ReactMount",
".",
"getNode",
"(",
"id",
")",
";",
"DOMChildrenOperations",
".",
"updateTextContent",
"(",
"node",
",",
"content",
")",
";",
"}"
] | Updates a DOM node's text content set by `props.content`.
@param {string} id ID of the node to update.
@param {string} content Text content.
@internal | [
"Updates",
"a",
"DOM",
"node",
"s",
"text",
"content",
"set",
"by",
"props",
".",
"content",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L10963-L10966 |
|
50,141 | unijs/bundle | build/web/c0.js | insertChildAt | function insertChildAt(parentNode, childNode, index) {
// By exploiting arrays returning `undefined` for an undefined index, we can
// rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. However, using `undefined` is not allowed by all
// browsers so we must replace it with `null`.
parentNode.insertBefore(
childNode,
parentNode.childNodes[index] || null
);
} | javascript | function insertChildAt(parentNode, childNode, index) {
// By exploiting arrays returning `undefined` for an undefined index, we can
// rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. However, using `undefined` is not allowed by all
// browsers so we must replace it with `null`.
parentNode.insertBefore(
childNode,
parentNode.childNodes[index] || null
);
} | [
"function",
"insertChildAt",
"(",
"parentNode",
",",
"childNode",
",",
"index",
")",
"{",
"// By exploiting arrays returning `undefined` for an undefined index, we can",
"// rely exclusively on `insertBefore(node, null)` instead of also using",
"// `appendChild(node)`. However, using `undefined` is not allowed by all",
"// browsers so we must replace it with `null`.",
"parentNode",
".",
"insertBefore",
"(",
"childNode",
",",
"parentNode",
".",
"childNodes",
"[",
"index",
"]",
"||",
"null",
")",
";",
"}"
] | Inserts `childNode` as a child of `parentNode` at the `index`.
@param {DOMElement} parentNode Parent node in which to insert.
@param {DOMElement} childNode Child node to insert.
@param {number} index Index at which to insert the child.
@internal | [
"Inserts",
"childNode",
"as",
"a",
"child",
"of",
"parentNode",
"at",
"the",
"index",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L11933-L11942 |
50,142 | unijs/bundle | build/web/c0.js | findParent | function findParent(node) {
// TODO: It may be a good idea to cache this to prevent unnecessary DOM
// traversal, but caching is difficult to do correctly without using a
// mutation observer to listen for all DOM changes.
var nodeID = ReactMount.getID(node);
var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
var container = ReactMount.findReactContainerForID(rootID);
var parent = ReactMount.getFirstReactDOM(container);
return parent;
} | javascript | function findParent(node) {
// TODO: It may be a good idea to cache this to prevent unnecessary DOM
// traversal, but caching is difficult to do correctly without using a
// mutation observer to listen for all DOM changes.
var nodeID = ReactMount.getID(node);
var rootID = ReactInstanceHandles.getReactRootIDFromNodeID(nodeID);
var container = ReactMount.findReactContainerForID(rootID);
var parent = ReactMount.getFirstReactDOM(container);
return parent;
} | [
"function",
"findParent",
"(",
"node",
")",
"{",
"// TODO: It may be a good idea to cache this to prevent unnecessary DOM",
"// traversal, but caching is difficult to do correctly without using a",
"// mutation observer to listen for all DOM changes.",
"var",
"nodeID",
"=",
"ReactMount",
".",
"getID",
"(",
"node",
")",
";",
"var",
"rootID",
"=",
"ReactInstanceHandles",
".",
"getReactRootIDFromNodeID",
"(",
"nodeID",
")",
";",
"var",
"container",
"=",
"ReactMount",
".",
"findReactContainerForID",
"(",
"rootID",
")",
";",
"var",
"parent",
"=",
"ReactMount",
".",
"getFirstReactDOM",
"(",
"container",
")",
";",
"return",
"parent",
";",
"}"
] | Finds the parent React component of `node`.
@param {*} node
@return {?DOMEventTarget} Parent container, or `null` if the specified node
is not nested. | [
"Finds",
"the",
"parent",
"React",
"component",
"of",
"node",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L15626-L15635 |
50,143 | unijs/bundle | build/web/c0.js | function() {
CallbackQueue.release(this.reactMountReady);
this.reactMountReady = null;
ReactPutListenerQueue.release(this.putListenerQueue);
this.putListenerQueue = null;
} | javascript | function() {
CallbackQueue.release(this.reactMountReady);
this.reactMountReady = null;
ReactPutListenerQueue.release(this.putListenerQueue);
this.putListenerQueue = null;
} | [
"function",
"(",
")",
"{",
"CallbackQueue",
".",
"release",
"(",
"this",
".",
"reactMountReady",
")",
";",
"this",
".",
"reactMountReady",
"=",
"null",
";",
"ReactPutListenerQueue",
".",
"release",
"(",
"this",
".",
"putListenerQueue",
")",
";",
"this",
".",
"putListenerQueue",
"=",
"null",
";",
"}"
] | `PooledClass` looks for this, and will invoke this before allowing this
instance to be resused. | [
"PooledClass",
"looks",
"for",
"this",
"and",
"will",
"invoke",
"this",
"before",
"allowing",
"this",
"instance",
"to",
"be",
"resused",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L15980-L15986 |
|
50,144 | unijs/bundle | build/web/c0.js | isInternalComponentType | function isInternalComponentType(type) {
return (
typeof type === 'function' &&
typeof type.prototype !== 'undefined' &&
typeof type.prototype.mountComponent === 'function' &&
typeof type.prototype.receiveComponent === 'function'
);
} | javascript | function isInternalComponentType(type) {
return (
typeof type === 'function' &&
typeof type.prototype !== 'undefined' &&
typeof type.prototype.mountComponent === 'function' &&
typeof type.prototype.receiveComponent === 'function'
);
} | [
"function",
"isInternalComponentType",
"(",
"type",
")",
"{",
"return",
"(",
"typeof",
"type",
"===",
"'function'",
"&&",
"typeof",
"type",
".",
"prototype",
"!==",
"'undefined'",
"&&",
"typeof",
"type",
".",
"prototype",
".",
"mountComponent",
"===",
"'function'",
"&&",
"typeof",
"type",
".",
"prototype",
".",
"receiveComponent",
"===",
"'function'",
")",
";",
"}"
] | Check if the type reference is a known internal type. I.e. not a user
provided composite type.
@param {function} type
@return {boolean} Returns true if this is a valid internal type. | [
"Check",
"if",
"the",
"type",
"reference",
"is",
"a",
"known",
"internal",
"type",
".",
"I",
".",
"e",
".",
"not",
"a",
"user",
"provided",
"composite",
"type",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L18573-L18580 |
50,145 | unijs/bundle | build/web/c0.js | enqueueMarkup | function enqueueMarkup(parentID, markup, toIndex) {
// NOTE: Null values reduce hidden classes.
updateQueue.push({
parentID: parentID,
parentNode: null,
type: ReactMultiChildUpdateTypes.INSERT_MARKUP,
markupIndex: markupQueue.push(markup) - 1,
textContent: null,
fromIndex: null,
toIndex: toIndex
});
} | javascript | function enqueueMarkup(parentID, markup, toIndex) {
// NOTE: Null values reduce hidden classes.
updateQueue.push({
parentID: parentID,
parentNode: null,
type: ReactMultiChildUpdateTypes.INSERT_MARKUP,
markupIndex: markupQueue.push(markup) - 1,
textContent: null,
fromIndex: null,
toIndex: toIndex
});
} | [
"function",
"enqueueMarkup",
"(",
"parentID",
",",
"markup",
",",
"toIndex",
")",
"{",
"// NOTE: Null values reduce hidden classes.",
"updateQueue",
".",
"push",
"(",
"{",
"parentID",
":",
"parentID",
",",
"parentNode",
":",
"null",
",",
"type",
":",
"ReactMultiChildUpdateTypes",
".",
"INSERT_MARKUP",
",",
"markupIndex",
":",
"markupQueue",
".",
"push",
"(",
"markup",
")",
"-",
"1",
",",
"textContent",
":",
"null",
",",
"fromIndex",
":",
"null",
",",
"toIndex",
":",
"toIndex",
"}",
")",
";",
"}"
] | Enqueues markup to be rendered and inserted at a supplied index.
@param {string} parentID ID of the parent component.
@param {string} markup Markup that renders into an element.
@param {number} toIndex Destination index.
@private | [
"Enqueues",
"markup",
"to",
"be",
"rendered",
"and",
"inserted",
"at",
"a",
"supplied",
"index",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L18943-L18954 |
50,146 | unijs/bundle | build/web/c0.js | function(nextNestedChildren, transaction, context) {
updateDepth++;
var errorThrown = true;
try {
this._updateChildren(nextNestedChildren, transaction, context);
errorThrown = false;
} finally {
updateDepth--;
if (!updateDepth) {
if (errorThrown) {
clearQueue();
} else {
processQueue();
}
}
}
} | javascript | function(nextNestedChildren, transaction, context) {
updateDepth++;
var errorThrown = true;
try {
this._updateChildren(nextNestedChildren, transaction, context);
errorThrown = false;
} finally {
updateDepth--;
if (!updateDepth) {
if (errorThrown) {
clearQueue();
} else {
processQueue();
}
}
}
} | [
"function",
"(",
"nextNestedChildren",
",",
"transaction",
",",
"context",
")",
"{",
"updateDepth",
"++",
";",
"var",
"errorThrown",
"=",
"true",
";",
"try",
"{",
"this",
".",
"_updateChildren",
"(",
"nextNestedChildren",
",",
"transaction",
",",
"context",
")",
";",
"errorThrown",
"=",
"false",
";",
"}",
"finally",
"{",
"updateDepth",
"--",
";",
"if",
"(",
"!",
"updateDepth",
")",
"{",
"if",
"(",
"errorThrown",
")",
"{",
"clearQueue",
"(",
")",
";",
"}",
"else",
"{",
"processQueue",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Updates the rendered children with new children.
@param {?object} nextNestedChildren Nested child maps.
@param {ReactReconcileTransaction} transaction
@internal | [
"Updates",
"the",
"rendered",
"children",
"with",
"new",
"children",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L19134-L19151 |
|
50,147 | unijs/bundle | build/web/c0.js | adler32 | function adler32(data) {
var a = 1;
var b = 0;
for (var i = 0; i < data.length; i++) {
a = (a + data.charCodeAt(i)) % MOD;
b = (b + a) % MOD;
}
return a | (b << 16);
} | javascript | function adler32(data) {
var a = 1;
var b = 0;
for (var i = 0; i < data.length; i++) {
a = (a + data.charCodeAt(i)) % MOD;
b = (b + a) % MOD;
}
return a | (b << 16);
} | [
"function",
"adler32",
"(",
"data",
")",
"{",
"var",
"a",
"=",
"1",
";",
"var",
"b",
"=",
"0",
";",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"data",
".",
"length",
";",
"i",
"++",
")",
"{",
"a",
"=",
"(",
"a",
"+",
"data",
".",
"charCodeAt",
"(",
"i",
")",
")",
"%",
"MOD",
";",
"b",
"=",
"(",
"b",
"+",
"a",
")",
"%",
"MOD",
";",
"}",
"return",
"a",
"|",
"(",
"b",
"<<",
"16",
")",
";",
"}"
] | This is a clean-room implementation of adler32 designed for detecting if markup is not what we expect it to be. It does not need to be cryptographically strong, only reasonably good at detecting if markup generated on the server is different than that on the client. | [
"This",
"is",
"a",
"clean",
"-",
"room",
"implementation",
"of",
"adler32",
"designed",
"for",
"detecting",
"if",
"markup",
"is",
"not",
"what",
"we",
"expect",
"it",
"to",
"be",
".",
"It",
"does",
"not",
"need",
"to",
"be",
"cryptographically",
"strong",
"only",
"reasonably",
"good",
"at",
"detecting",
"if",
"markup",
"generated",
"on",
"the",
"server",
"is",
"different",
"than",
"that",
"on",
"the",
"client",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L20963-L20971 |
50,148 | unijs/bundle | build/web/c0.js | function(partialProps, callback) {
// This is a deoptimized path. We optimize for always having an element.
// This creates an extra internal element.
var element = this._pendingElement || this._currentElement;
this._pendingElement = ReactElement.cloneAndReplaceProps(
element,
assign({}, element.props, partialProps)
);
ReactUpdates.enqueueUpdate(this, callback);
} | javascript | function(partialProps, callback) {
// This is a deoptimized path. We optimize for always having an element.
// This creates an extra internal element.
var element = this._pendingElement || this._currentElement;
this._pendingElement = ReactElement.cloneAndReplaceProps(
element,
assign({}, element.props, partialProps)
);
ReactUpdates.enqueueUpdate(this, callback);
} | [
"function",
"(",
"partialProps",
",",
"callback",
")",
"{",
"// This is a deoptimized path. We optimize for always having an element.",
"// This creates an extra internal element.",
"var",
"element",
"=",
"this",
".",
"_pendingElement",
"||",
"this",
".",
"_currentElement",
";",
"this",
".",
"_pendingElement",
"=",
"ReactElement",
".",
"cloneAndReplaceProps",
"(",
"element",
",",
"assign",
"(",
"{",
"}",
",",
"element",
".",
"props",
",",
"partialProps",
")",
")",
";",
"ReactUpdates",
".",
"enqueueUpdate",
"(",
"this",
",",
"callback",
")",
";",
"}"
] | Schedule a partial update to the props. Only used for internal testing.
@param {object} partialProps Subset of the next props.
@param {?function} callback Called after props are updated.
@final
@internal | [
"Schedule",
"a",
"partial",
"update",
"to",
"the",
"props",
".",
"Only",
"used",
"for",
"internal",
"testing",
"."
] | 15f627df9d8c83a59d3e613f68ef4769f15569fc | https://github.com/unijs/bundle/blob/15f627df9d8c83a59d3e613f68ef4769f15569fc/build/web/c0.js#L21595-L21604 |
|
50,149 | Nazariglez/perenquen | lib/pixi/src/core/graphics/Graphics.js | Graphics | function Graphics()
{
Container.call(this);
/**
* The alpha value used when filling the Graphics object.
*
* @member {number}
* @default 1
*/
this.fillAlpha = 1;
/**
* The width (thickness) of any lines drawn.
*
* @member {number}
* @default 0
*/
this.lineWidth = 0;
/**
* The color of any lines drawn.
*
* @member {string}
* @default 0
*/
this.lineColor = 0;
/**
* Graphics data
*
* @member {GraphicsData[]}
* @private
*/
this.graphicsData = [];
/**
* The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint.
*
* @member {number}
* @default 0xFFFFFF
*/
this.tint = 0xFFFFFF;
/**
* The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change.
*
* @member {number}
* @private
* @default 0xFFFFFF
*/
this._prevTint = 0xFFFFFF;
/**
* The blend mode to be applied to the graphic shape. Apply a value of blendModes.NORMAL to reset the blend mode.
*
* @member {number}
* @default CONST.BLEND_MODES.NORMAL;
*/
this.blendMode = CONST.BLEND_MODES.NORMAL;
/**
* Current path
*
* @member {GraphicsData}
* @private
*/
this.currentPath = null;
/**
* Array containing some WebGL-related properties used by the WebGL renderer.
*
* @member {object<number, object>}
* @private
*/
// TODO - _webgl should use a prototype object, not a random undocumented object...
this._webGL = {};
/**
* Whether this shape is being used as a mask.
*
* @member {boolean}
*/
this.isMask = false;
/**
* The bounds' padding used for bounds calculation.
*
* @member {number}
*/
this.boundsPadding = 0;
/**
* A cache of the local bounds to prevent recalculation.
*
* @member {Rectangle}
* @private
*/
this._localBounds = new math.Rectangle(0,0,1,1);
/**
* Used to detect if the graphics object has changed. If this is set to true then the graphics
* object will be recalculated.
*
* @member {boolean}
* @private
*/
this.dirty = true;
/**
* Used to detect if the WebGL graphics object has changed. If this is set to true then the
* graphics object will be recalculated.
*
* @member {boolean}
* @private
*/
this.glDirty = false;
this.boundsDirty = true;
/**
* Used to detect if the cached sprite object needs to be updated.
*
* @member {boolean}
* @private
*/
this.cachedSpriteDirty = false;
} | javascript | function Graphics()
{
Container.call(this);
/**
* The alpha value used when filling the Graphics object.
*
* @member {number}
* @default 1
*/
this.fillAlpha = 1;
/**
* The width (thickness) of any lines drawn.
*
* @member {number}
* @default 0
*/
this.lineWidth = 0;
/**
* The color of any lines drawn.
*
* @member {string}
* @default 0
*/
this.lineColor = 0;
/**
* Graphics data
*
* @member {GraphicsData[]}
* @private
*/
this.graphicsData = [];
/**
* The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint.
*
* @member {number}
* @default 0xFFFFFF
*/
this.tint = 0xFFFFFF;
/**
* The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change.
*
* @member {number}
* @private
* @default 0xFFFFFF
*/
this._prevTint = 0xFFFFFF;
/**
* The blend mode to be applied to the graphic shape. Apply a value of blendModes.NORMAL to reset the blend mode.
*
* @member {number}
* @default CONST.BLEND_MODES.NORMAL;
*/
this.blendMode = CONST.BLEND_MODES.NORMAL;
/**
* Current path
*
* @member {GraphicsData}
* @private
*/
this.currentPath = null;
/**
* Array containing some WebGL-related properties used by the WebGL renderer.
*
* @member {object<number, object>}
* @private
*/
// TODO - _webgl should use a prototype object, not a random undocumented object...
this._webGL = {};
/**
* Whether this shape is being used as a mask.
*
* @member {boolean}
*/
this.isMask = false;
/**
* The bounds' padding used for bounds calculation.
*
* @member {number}
*/
this.boundsPadding = 0;
/**
* A cache of the local bounds to prevent recalculation.
*
* @member {Rectangle}
* @private
*/
this._localBounds = new math.Rectangle(0,0,1,1);
/**
* Used to detect if the graphics object has changed. If this is set to true then the graphics
* object will be recalculated.
*
* @member {boolean}
* @private
*/
this.dirty = true;
/**
* Used to detect if the WebGL graphics object has changed. If this is set to true then the
* graphics object will be recalculated.
*
* @member {boolean}
* @private
*/
this.glDirty = false;
this.boundsDirty = true;
/**
* Used to detect if the cached sprite object needs to be updated.
*
* @member {boolean}
* @private
*/
this.cachedSpriteDirty = false;
} | [
"function",
"Graphics",
"(",
")",
"{",
"Container",
".",
"call",
"(",
"this",
")",
";",
"/**\n * The alpha value used when filling the Graphics object.\n *\n * @member {number}\n * @default 1\n */",
"this",
".",
"fillAlpha",
"=",
"1",
";",
"/**\n * The width (thickness) of any lines drawn.\n *\n * @member {number}\n * @default 0\n */",
"this",
".",
"lineWidth",
"=",
"0",
";",
"/**\n * The color of any lines drawn.\n *\n * @member {string}\n * @default 0\n */",
"this",
".",
"lineColor",
"=",
"0",
";",
"/**\n * Graphics data\n *\n * @member {GraphicsData[]}\n * @private\n */",
"this",
".",
"graphicsData",
"=",
"[",
"]",
";",
"/**\n * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint.\n *\n * @member {number}\n * @default 0xFFFFFF\n */",
"this",
".",
"tint",
"=",
"0xFFFFFF",
";",
"/**\n * The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change.\n *\n * @member {number}\n * @private\n * @default 0xFFFFFF\n */",
"this",
".",
"_prevTint",
"=",
"0xFFFFFF",
";",
"/**\n * The blend mode to be applied to the graphic shape. Apply a value of blendModes.NORMAL to reset the blend mode.\n *\n * @member {number}\n * @default CONST.BLEND_MODES.NORMAL;\n */",
"this",
".",
"blendMode",
"=",
"CONST",
".",
"BLEND_MODES",
".",
"NORMAL",
";",
"/**\n * Current path\n *\n * @member {GraphicsData}\n * @private\n */",
"this",
".",
"currentPath",
"=",
"null",
";",
"/**\n * Array containing some WebGL-related properties used by the WebGL renderer.\n *\n * @member {object<number, object>}\n * @private\n */",
"// TODO - _webgl should use a prototype object, not a random undocumented object...",
"this",
".",
"_webGL",
"=",
"{",
"}",
";",
"/**\n * Whether this shape is being used as a mask.\n *\n * @member {boolean}\n */",
"this",
".",
"isMask",
"=",
"false",
";",
"/**\n * The bounds' padding used for bounds calculation.\n *\n * @member {number}\n */",
"this",
".",
"boundsPadding",
"=",
"0",
";",
"/**\n * A cache of the local bounds to prevent recalculation.\n *\n * @member {Rectangle}\n * @private\n */",
"this",
".",
"_localBounds",
"=",
"new",
"math",
".",
"Rectangle",
"(",
"0",
",",
"0",
",",
"1",
",",
"1",
")",
";",
"/**\n * Used to detect if the graphics object has changed. If this is set to true then the graphics\n * object will be recalculated.\n *\n * @member {boolean}\n * @private\n */",
"this",
".",
"dirty",
"=",
"true",
";",
"/**\n * Used to detect if the WebGL graphics object has changed. If this is set to true then the\n * graphics object will be recalculated.\n *\n * @member {boolean}\n * @private\n */",
"this",
".",
"glDirty",
"=",
"false",
";",
"this",
".",
"boundsDirty",
"=",
"true",
";",
"/**\n * Used to detect if the cached sprite object needs to be updated.\n *\n * @member {boolean}\n * @private\n */",
"this",
".",
"cachedSpriteDirty",
"=",
"false",
";",
"}"
] | The Graphics class contains methods used to draw primitive shapes such as lines, circles and
rectangles to the display, and to color and fill them.
@class
@extends Container
@memberof PIXI | [
"The",
"Graphics",
"class",
"contains",
"methods",
"used",
"to",
"draw",
"primitive",
"shapes",
"such",
"as",
"lines",
"circles",
"and",
"rectangles",
"to",
"the",
"display",
"and",
"to",
"color",
"and",
"fill",
"them",
"."
] | e023964d05afeefebdcac4e2044819fdfa3899ae | https://github.com/Nazariglez/perenquen/blob/e023964d05afeefebdcac4e2044819fdfa3899ae/lib/pixi/src/core/graphics/Graphics.js#L19-L146 |
50,150 | linyngfly/omelo-rpc | lib/rpc-client/mailstation.js | function(opts) {
EventEmitter.call(this);
this.opts = opts;
this.servers = {}; // remote server info map, key: server id, value: info
this.serversMap = {}; // remote server info map, key: serverType, value: servers array
this.onlines = {}; // remote server online map, key: server id, value: 0/offline 1/online
this.mailboxFactory = opts.mailboxFactory || defaultMailboxFactory;
// filters
this.befores = [];
this.afters = [];
// pending request queues
this.pendings = {};
this.pendingSize = opts.pendingSize || constants.DEFAULT_PARAM.DEFAULT_PENDING_SIZE;
// connecting remote server mailbox map
this.connecting = {};
// working mailbox map
this.mailboxes = {};
this.state = STATE_INITED;
} | javascript | function(opts) {
EventEmitter.call(this);
this.opts = opts;
this.servers = {}; // remote server info map, key: server id, value: info
this.serversMap = {}; // remote server info map, key: serverType, value: servers array
this.onlines = {}; // remote server online map, key: server id, value: 0/offline 1/online
this.mailboxFactory = opts.mailboxFactory || defaultMailboxFactory;
// filters
this.befores = [];
this.afters = [];
// pending request queues
this.pendings = {};
this.pendingSize = opts.pendingSize || constants.DEFAULT_PARAM.DEFAULT_PENDING_SIZE;
// connecting remote server mailbox map
this.connecting = {};
// working mailbox map
this.mailboxes = {};
this.state = STATE_INITED;
} | [
"function",
"(",
"opts",
")",
"{",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"this",
".",
"opts",
"=",
"opts",
";",
"this",
".",
"servers",
"=",
"{",
"}",
";",
"// remote server info map, key: server id, value: info",
"this",
".",
"serversMap",
"=",
"{",
"}",
";",
"// remote server info map, key: serverType, value: servers array",
"this",
".",
"onlines",
"=",
"{",
"}",
";",
"// remote server online map, key: server id, value: 0/offline 1/online",
"this",
".",
"mailboxFactory",
"=",
"opts",
".",
"mailboxFactory",
"||",
"defaultMailboxFactory",
";",
"// filters",
"this",
".",
"befores",
"=",
"[",
"]",
";",
"this",
".",
"afters",
"=",
"[",
"]",
";",
"// pending request queues",
"this",
".",
"pendings",
"=",
"{",
"}",
";",
"this",
".",
"pendingSize",
"=",
"opts",
".",
"pendingSize",
"||",
"constants",
".",
"DEFAULT_PARAM",
".",
"DEFAULT_PENDING_SIZE",
";",
"// connecting remote server mailbox map",
"this",
".",
"connecting",
"=",
"{",
"}",
";",
"// working mailbox map",
"this",
".",
"mailboxes",
"=",
"{",
"}",
";",
"this",
".",
"state",
"=",
"STATE_INITED",
";",
"}"
] | station has closed
Mail station constructor.
@param {Object} opts construct parameters | [
"station",
"has",
"closed",
"Mail",
"station",
"constructor",
"."
] | a8d64a4f098f1d174550f0f648d5ccc7716624b8 | https://github.com/linyngfly/omelo-rpc/blob/a8d64a4f098f1d174550f0f648d5ccc7716624b8/lib/rpc-client/mailstation.js#L18-L41 |
|
50,151 | integreat-io/integreat-adapter-couchdb | lib/adapters/couchdb.js | couchdb | function couchdb (json) {
return {
prepareEndpoint (endpointOptions, sourceOptions) {
return prepareEndpoint(json, endpointOptions, sourceOptions)
},
async send (request) {
return send(json, request)
},
async serialize (data, request) {
const serializedData = await serializeData(data, request, json)
return json.serialize(serializedData, request)
},
async normalize (data, request) {
const normalizedData = await json.normalize(data, request)
return normalizeData(normalizedData)
}
}
} | javascript | function couchdb (json) {
return {
prepareEndpoint (endpointOptions, sourceOptions) {
return prepareEndpoint(json, endpointOptions, sourceOptions)
},
async send (request) {
return send(json, request)
},
async serialize (data, request) {
const serializedData = await serializeData(data, request, json)
return json.serialize(serializedData, request)
},
async normalize (data, request) {
const normalizedData = await json.normalize(data, request)
return normalizeData(normalizedData)
}
}
} | [
"function",
"couchdb",
"(",
"json",
")",
"{",
"return",
"{",
"prepareEndpoint",
"(",
"endpointOptions",
",",
"sourceOptions",
")",
"{",
"return",
"prepareEndpoint",
"(",
"json",
",",
"endpointOptions",
",",
"sourceOptions",
")",
"}",
",",
"async",
"send",
"(",
"request",
")",
"{",
"return",
"send",
"(",
"json",
",",
"request",
")",
"}",
",",
"async",
"serialize",
"(",
"data",
",",
"request",
")",
"{",
"const",
"serializedData",
"=",
"await",
"serializeData",
"(",
"data",
",",
"request",
",",
"json",
")",
"return",
"json",
".",
"serialize",
"(",
"serializedData",
",",
"request",
")",
"}",
",",
"async",
"normalize",
"(",
"data",
",",
"request",
")",
"{",
"const",
"normalizedData",
"=",
"await",
"json",
".",
"normalize",
"(",
"data",
",",
"request",
")",
"return",
"normalizeData",
"(",
"normalizedData",
")",
"}",
"}",
"}"
] | Wrap json adapter to provide adjustments for couchdb.
@param {Object} json - The json adapter
@returns {Object} The couchdb adapter | [
"Wrap",
"json",
"adapter",
"to",
"provide",
"adjustments",
"for",
"couchdb",
"."
] | e792aaa3e85c5dae41959bc449ed3b0e149f7ebf | https://github.com/integreat-io/integreat-adapter-couchdb/blob/e792aaa3e85c5dae41959bc449ed3b0e149f7ebf/lib/adapters/couchdb.js#L11-L31 |
50,152 | PropellerHealth/asthma-forecast-sdk-node | index.js | function(zip, callback) {
var queryString = "?postalCode="+zip;
httpGet(queryString, function(err, results) {
callback(err, results);
});
} | javascript | function(zip, callback) {
var queryString = "?postalCode="+zip;
httpGet(queryString, function(err, results) {
callback(err, results);
});
} | [
"function",
"(",
"zip",
",",
"callback",
")",
"{",
"var",
"queryString",
"=",
"\"?postalCode=\"",
"+",
"zip",
";",
"httpGet",
"(",
"queryString",
",",
"function",
"(",
"err",
",",
"results",
")",
"{",
"callback",
"(",
"err",
",",
"results",
")",
";",
"}",
")",
";",
"}"
] | callback for getForecastByZipCode
@callback module:asthma-forecast/client~getForecastByZipCodeCallback
@param {Object} [err] error calling Propeller API
@param {Object} [result] forecast
getForecastByZipCode
@param {String} options.zipCode Zip code
@param {module:asthma-forecast/client~getForecastByZipCodeCallback} [callback] callback | [
"callback",
"for",
"getForecastByZipCode"
] | 683611c2b1ea89d644afcc2ff0e2bbb0a4e4dd05 | https://github.com/PropellerHealth/asthma-forecast-sdk-node/blob/683611c2b1ea89d644afcc2ff0e2bbb0a4e4dd05/index.js#L69-L76 |
|
50,153 | PropellerHealth/asthma-forecast-sdk-node | index.js | function(lat, lon, callback) {
var queryString = "?latitude="+lat+"&longitude="+lon;
httpGet(queryString, function(err, results) {
callback(err, results);
});
} | javascript | function(lat, lon, callback) {
var queryString = "?latitude="+lat+"&longitude="+lon;
httpGet(queryString, function(err, results) {
callback(err, results);
});
} | [
"function",
"(",
"lat",
",",
"lon",
",",
"callback",
")",
"{",
"var",
"queryString",
"=",
"\"?latitude=\"",
"+",
"lat",
"+",
"\"&longitude=\"",
"+",
"lon",
";",
"httpGet",
"(",
"queryString",
",",
"function",
"(",
"err",
",",
"results",
")",
"{",
"callback",
"(",
"err",
",",
"results",
")",
";",
"}",
")",
";",
"}"
] | callback for getForecastByLatLong
@callback module:asthma-forecast/client~getForecastByLatLongCallback
@param {Object} [err] error calling asthma-forecast
@param {Object} [result] forecast
getForecastByLatLong
@param {Number} latitude Latitude in decimal degrees
@param {Number} longitude longitude in decimal degrees
@param {module:asthma-forecast/client~getForecastByLatLongCallback} [callback] callback | [
"callback",
"for",
"getForecastByLatLong"
] | 683611c2b1ea89d644afcc2ff0e2bbb0a4e4dd05 | https://github.com/PropellerHealth/asthma-forecast-sdk-node/blob/683611c2b1ea89d644afcc2ff0e2bbb0a4e4dd05/index.js#L89-L96 |
|
50,154 | emiljohansson/captn | captn.dom.hasclass/index.js | hasClass | function hasClass(element, className) {
if (!hasClassNameProperty(element)) {
return false;
}
return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
} | javascript | function hasClass(element, className) {
if (!hasClassNameProperty(element)) {
return false;
}
return (' ' + element.className + ' ').indexOf(' ' + className + ' ') > -1;
} | [
"function",
"hasClass",
"(",
"element",
",",
"className",
")",
"{",
"if",
"(",
"!",
"hasClassNameProperty",
"(",
"element",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"' '",
"+",
"element",
".",
"className",
"+",
"' '",
")",
".",
"indexOf",
"(",
"' '",
"+",
"className",
"+",
"' '",
")",
">",
"-",
"1",
";",
"}"
] | Returns true if the element's class name contains className.
@static
@param {DOMElement} element The DOM element to be checked.
@param {string} className The name to match.
@return {boolean} Returns `true` if `className` exist within the elements className.
@example
hasClass(el, 'container');
// => true | [
"Returns",
"true",
"if",
"the",
"element",
"s",
"class",
"name",
"contains",
"className",
"."
] | dae7520116dc2148b4de06af7e1d7a47a3a3ac37 | https://github.com/emiljohansson/captn/blob/dae7520116dc2148b4de06af7e1d7a47a3a3ac37/captn.dom.hasclass/index.js#L17-L22 |
50,155 | gethuman/pancakes-angular | lib/ngapp/state.helper.js | goToUrl | function goToUrl(url) {
if (!url) { return; }
if (_.isArray(url)) {
url = url.join('/');
}
var hasHttp = url.indexOf('http') === 0;
if (!hasHttp && url.indexOf('/') !== 0) {
url = '/' + url;
}
hasHttp ? $window.location.href = url : $location.path(url);
} | javascript | function goToUrl(url) {
if (!url) { return; }
if (_.isArray(url)) {
url = url.join('/');
}
var hasHttp = url.indexOf('http') === 0;
if (!hasHttp && url.indexOf('/') !== 0) {
url = '/' + url;
}
hasHttp ? $window.location.href = url : $location.path(url);
} | [
"function",
"goToUrl",
"(",
"url",
")",
"{",
"if",
"(",
"!",
"url",
")",
"{",
"return",
";",
"}",
"if",
"(",
"_",
".",
"isArray",
"(",
"url",
")",
")",
"{",
"url",
"=",
"url",
".",
"join",
"(",
"'/'",
")",
";",
"}",
"var",
"hasHttp",
"=",
"url",
".",
"indexOf",
"(",
"'http'",
")",
"===",
"0",
";",
"if",
"(",
"!",
"hasHttp",
"&&",
"url",
".",
"indexOf",
"(",
"'/'",
")",
"!==",
"0",
")",
"{",
"url",
"=",
"'/'",
"+",
"url",
";",
"}",
"hasHttp",
"?",
"$window",
".",
"location",
".",
"href",
"=",
"url",
":",
"$location",
".",
"path",
"(",
"url",
")",
";",
"}"
] | Simply go to the url and allow the state to change
@param url | [
"Simply",
"go",
"to",
"the",
"url",
"and",
"allow",
"the",
"state",
"to",
"change"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/state.helper.js#L15-L28 |
50,156 | gethuman/pancakes-angular | lib/ngapp/state.helper.js | getQueryParams | function getQueryParams(params) {
params = params || {};
var url = $location.url();
var idx = url.indexOf('?');
// if there is a query string
if (idx < 0) { return {}; }
// get the query string and split the keyvals
var query = url.substring(idx + 1);
var keyVals = query.split('&');
// put each key/val into the params object
_.each(keyVals, function (keyVal) {
var keyValArr = keyVal.split('=');
params[keyValArr[0]] = keyValArr[1];
});
return params;
} | javascript | function getQueryParams(params) {
params = params || {};
var url = $location.url();
var idx = url.indexOf('?');
// if there is a query string
if (idx < 0) { return {}; }
// get the query string and split the keyvals
var query = url.substring(idx + 1);
var keyVals = query.split('&');
// put each key/val into the params object
_.each(keyVals, function (keyVal) {
var keyValArr = keyVal.split('=');
params[keyValArr[0]] = keyValArr[1];
});
return params;
} | [
"function",
"getQueryParams",
"(",
"params",
")",
"{",
"params",
"=",
"params",
"||",
"{",
"}",
";",
"var",
"url",
"=",
"$location",
".",
"url",
"(",
")",
";",
"var",
"idx",
"=",
"url",
".",
"indexOf",
"(",
"'?'",
")",
";",
"// if there is a query string",
"if",
"(",
"idx",
"<",
"0",
")",
"{",
"return",
"{",
"}",
";",
"}",
"// get the query string and split the keyvals",
"var",
"query",
"=",
"url",
".",
"substring",
"(",
"idx",
"+",
"1",
")",
";",
"var",
"keyVals",
"=",
"query",
".",
"split",
"(",
"'&'",
")",
";",
"// put each key/val into the params object",
"_",
".",
"each",
"(",
"keyVals",
",",
"function",
"(",
"keyVal",
")",
"{",
"var",
"keyValArr",
"=",
"keyVal",
".",
"split",
"(",
"'='",
")",
";",
"params",
"[",
"keyValArr",
"[",
"0",
"]",
"]",
"=",
"keyValArr",
"[",
"1",
"]",
";",
"}",
")",
";",
"return",
"params",
";",
"}"
] | Get params from the URL | [
"Get",
"params",
"from",
"the",
"URL"
] | 9589b7ba09619843e271293088005c62ed23f355 | https://github.com/gethuman/pancakes-angular/blob/9589b7ba09619843e271293088005c62ed23f355/lib/ngapp/state.helper.js#L48-L67 |
50,157 | sendanor/nor-newrelic | src/cli.js | save_config | function save_config(path, config) {
debug.assert(path).is('string');
debug.assert(config).is('object');
return $Q.fcall(function stringify_json() {
return JSON.stringify(config, null, 2);
}).then(function write_to_file(data) {
return FS.writeFile(path, data, {'encoding':'utf8'});
});
} | javascript | function save_config(path, config) {
debug.assert(path).is('string');
debug.assert(config).is('object');
return $Q.fcall(function stringify_json() {
return JSON.stringify(config, null, 2);
}).then(function write_to_file(data) {
return FS.writeFile(path, data, {'encoding':'utf8'});
});
} | [
"function",
"save_config",
"(",
"path",
",",
"config",
")",
"{",
"debug",
".",
"assert",
"(",
"path",
")",
".",
"is",
"(",
"'string'",
")",
";",
"debug",
".",
"assert",
"(",
"config",
")",
".",
"is",
"(",
"'object'",
")",
";",
"return",
"$Q",
".",
"fcall",
"(",
"function",
"stringify_json",
"(",
")",
"{",
"return",
"JSON",
".",
"stringify",
"(",
"config",
",",
"null",
",",
"2",
")",
";",
"}",
")",
".",
"then",
"(",
"function",
"write_to_file",
"(",
"data",
")",
"{",
"return",
"FS",
".",
"writeFile",
"(",
"path",
",",
"data",
",",
"{",
"'encoding'",
":",
"'utf8'",
"}",
")",
";",
"}",
")",
";",
"}"
] | Save configurations to disk | [
"Save",
"configurations",
"to",
"disk"
] | 638c97036c9a1ff79ab2b114abb3c61ceacc81b7 | https://github.com/sendanor/nor-newrelic/blob/638c97036c9a1ff79ab2b114abb3c61ceacc81b7/src/cli.js#L50-L58 |
50,158 | toranb/gulp-ember-handlebarz | index.js | function (name) {
var n = path.extname(name).length;
return n === 0 ? name : name.slice(0, -n);
} | javascript | function (name) {
var n = path.extname(name).length;
return n === 0 ? name : name.slice(0, -n);
} | [
"function",
"(",
"name",
")",
"{",
"var",
"n",
"=",
"path",
".",
"extname",
"(",
"name",
")",
".",
"length",
";",
"return",
"n",
"===",
"0",
"?",
"name",
":",
"name",
".",
"slice",
"(",
"0",
",",
"-",
"n",
")",
";",
"}"
] | Default name function returns the template filename without extension. | [
"Default",
"name",
"function",
"returns",
"the",
"template",
"filename",
"without",
"extension",
"."
] | 2480533ccb6c3feb4a31373474038705c4d3aada | https://github.com/toranb/gulp-ember-handlebarz/blob/2480533ccb6c3feb4a31373474038705c4d3aada/index.js#L9-L12 |
|
50,159 | psalaets/grid-walk | lib/walker.js | walk | function walk(start, end, fn) {
this.start = new Vec2(start);
this.end = new Vec2(end);
this.direction = calcDirection(this.start, this.end);
// positive deltas go right and down
this.cellStepDelta = {
horizontal: 0,
vertical: 0
}
this.tMax = new Vec2();
this.tDelta = new Vec2();
this.currentCoord = positionToCoordinate(this.start, this.cellWidth, this.cellHeight);
this.endCoord = positionToCoordinate(this.end, this.cellWidth, this.cellHeight);
this.initStepMath();
while (!this.isPastEnd()) {
fn(coord(this.currentCoord));
if (this.shouldMoveHorizontally()) {
this.moveHorizontally();
} else {
this.moveVertically();
}
}
} | javascript | function walk(start, end, fn) {
this.start = new Vec2(start);
this.end = new Vec2(end);
this.direction = calcDirection(this.start, this.end);
// positive deltas go right and down
this.cellStepDelta = {
horizontal: 0,
vertical: 0
}
this.tMax = new Vec2();
this.tDelta = new Vec2();
this.currentCoord = positionToCoordinate(this.start, this.cellWidth, this.cellHeight);
this.endCoord = positionToCoordinate(this.end, this.cellWidth, this.cellHeight);
this.initStepMath();
while (!this.isPastEnd()) {
fn(coord(this.currentCoord));
if (this.shouldMoveHorizontally()) {
this.moveHorizontally();
} else {
this.moveVertically();
}
}
} | [
"function",
"walk",
"(",
"start",
",",
"end",
",",
"fn",
")",
"{",
"this",
".",
"start",
"=",
"new",
"Vec2",
"(",
"start",
")",
";",
"this",
".",
"end",
"=",
"new",
"Vec2",
"(",
"end",
")",
";",
"this",
".",
"direction",
"=",
"calcDirection",
"(",
"this",
".",
"start",
",",
"this",
".",
"end",
")",
";",
"// positive deltas go right and down",
"this",
".",
"cellStepDelta",
"=",
"{",
"horizontal",
":",
"0",
",",
"vertical",
":",
"0",
"}",
"this",
".",
"tMax",
"=",
"new",
"Vec2",
"(",
")",
";",
"this",
".",
"tDelta",
"=",
"new",
"Vec2",
"(",
")",
";",
"this",
".",
"currentCoord",
"=",
"positionToCoordinate",
"(",
"this",
".",
"start",
",",
"this",
".",
"cellWidth",
",",
"this",
".",
"cellHeight",
")",
";",
"this",
".",
"endCoord",
"=",
"positionToCoordinate",
"(",
"this",
".",
"end",
",",
"this",
".",
"cellWidth",
",",
"this",
".",
"cellHeight",
")",
";",
"this",
".",
"initStepMath",
"(",
")",
";",
"while",
"(",
"!",
"this",
".",
"isPastEnd",
"(",
")",
")",
"{",
"fn",
"(",
"coord",
"(",
"this",
".",
"currentCoord",
")",
")",
";",
"if",
"(",
"this",
".",
"shouldMoveHorizontally",
"(",
")",
")",
"{",
"this",
".",
"moveHorizontally",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"moveVertically",
"(",
")",
";",
"}",
"}",
"}"
] | Walk along a line through the grid.
@param {object} start - Start point of line, object with x/y properties.
@param {object} end - End point of line, object with x/y properties.
@param {function} fn - Callback to be invoked *synchronously* for each cell
visited with grid coordinate
{column: number, row: number} as the lone param. | [
"Walk",
"along",
"a",
"line",
"through",
"the",
"grid",
"."
] | 6969e4c9aa0a18289dd3af7da136f7966bcb022d | https://github.com/psalaets/grid-walk/blob/6969e4c9aa0a18289dd3af7da136f7966bcb022d/lib/walker.js#L34-L62 |
50,160 | psalaets/grid-walk | lib/walker.js | coord | function coord(coordOrColumn, row) {
if (arguments.length == 1) { // copy incoming coord object
return {
column: coordOrColumn.column,
row: coordOrColumn.row
};
} else if (arguments.length == 2) { // create coord object
return {
column: coordOrColumn,
row: row
};
}
} | javascript | function coord(coordOrColumn, row) {
if (arguments.length == 1) { // copy incoming coord object
return {
column: coordOrColumn.column,
row: coordOrColumn.row
};
} else if (arguments.length == 2) { // create coord object
return {
column: coordOrColumn,
row: row
};
}
} | [
"function",
"coord",
"(",
"coordOrColumn",
",",
"row",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"==",
"1",
")",
"{",
"// copy incoming coord object",
"return",
"{",
"column",
":",
"coordOrColumn",
".",
"column",
",",
"row",
":",
"coordOrColumn",
".",
"row",
"}",
";",
"}",
"else",
"if",
"(",
"arguments",
".",
"length",
"==",
"2",
")",
"{",
"// create coord object",
"return",
"{",
"column",
":",
"coordOrColumn",
",",
"row",
":",
"row",
"}",
";",
"}",
"}"
] | Creates a coordinate object which is an object with column and row properties.
@param {object|number} coordOrColumn - Coordinate object to copy or column
number to create coordinate object with.
@param {number} [row] - Required when first argument is column number.
@param {object} object with column and row properties | [
"Creates",
"a",
"coordinate",
"object",
"which",
"is",
"an",
"object",
"with",
"column",
"and",
"row",
"properties",
"."
] | 6969e4c9aa0a18289dd3af7da136f7966bcb022d | https://github.com/psalaets/grid-walk/blob/6969e4c9aa0a18289dd3af7da136f7966bcb022d/lib/walker.js#L154-L166 |
50,161 | psalaets/grid-walk | lib/walker.js | calcDirection | function calcDirection(start, end) {
var direction = new Vec2(end);
direction.subtract(start);
direction.normalize();
return direction;
} | javascript | function calcDirection(start, end) {
var direction = new Vec2(end);
direction.subtract(start);
direction.normalize();
return direction;
} | [
"function",
"calcDirection",
"(",
"start",
",",
"end",
")",
"{",
"var",
"direction",
"=",
"new",
"Vec2",
"(",
"end",
")",
";",
"direction",
".",
"subtract",
"(",
"start",
")",
";",
"direction",
".",
"normalize",
"(",
")",
";",
"return",
"direction",
";",
"}"
] | Figure out direction vector of line connecting two points.
@param {Vec2} start
@param {Vec2} end
@return {Vec2} normalized direction vector | [
"Figure",
"out",
"direction",
"vector",
"of",
"line",
"connecting",
"two",
"points",
"."
] | 6969e4c9aa0a18289dd3af7da136f7966bcb022d | https://github.com/psalaets/grid-walk/blob/6969e4c9aa0a18289dd3af7da136f7966bcb022d/lib/walker.js#L193-L198 |
50,162 | acos-server/acos-jsparsons | static/js-parsons/ui-extension/parsons-site-ui.js | function(newAction) {
// ignore init and feedback actions
if (newAction.type === "init" || newAction.type === "feedback") { return; }
var action = parson.whatWeDidPreviously();
// if we have been here before (action not undefined) and more than one line in solution...
if (action && action.output && newAction.output.split('-').length > 1 && action.output.split('-').length > 1 && action.stepsToLast > 2) {
var html = "<div class='currentState'><p>Your current code is identical to one you had " +
"previously. You might want to stop going in circles and think carefully about " +
"the feedback shown here.</p>" +
"<div class='sortable-code' id='currFeedback'></div>";
html += "</div><div class='prevAction'><p>Last time you went on to move the line " +
"highlighted with a blue right margin. Think carefully about the feedback for " +
"this code and your current code.</p>" +
"<div class='sortable-code' id='prevFeedback'></div>";
html += "</div>";
// .. set the content of the tab ...
RevisitFeedback.html(html)
.label("Hint")
.available(true); // .. and make the "feedback" available
// create the parsons feedback
createParsonFeedbackForElement("currFeedback", newAction.output);
createParsonFeedbackForElement("prevFeedback", action.output);
// .. and higlight modified lines
RevisitFeedback.highlightLine("currFeedbackcodeline" + action.target)
.highlightLine("prevFeedbackcodeline" + action.target);
} else if (previousFeedbackState) {
RevisitFeedback.available(false);
setLastFeedback();
} else {
RevisitFeedback.available(false); // make the feedback unavailable
}
} | javascript | function(newAction) {
// ignore init and feedback actions
if (newAction.type === "init" || newAction.type === "feedback") { return; }
var action = parson.whatWeDidPreviously();
// if we have been here before (action not undefined) and more than one line in solution...
if (action && action.output && newAction.output.split('-').length > 1 && action.output.split('-').length > 1 && action.stepsToLast > 2) {
var html = "<div class='currentState'><p>Your current code is identical to one you had " +
"previously. You might want to stop going in circles and think carefully about " +
"the feedback shown here.</p>" +
"<div class='sortable-code' id='currFeedback'></div>";
html += "</div><div class='prevAction'><p>Last time you went on to move the line " +
"highlighted with a blue right margin. Think carefully about the feedback for " +
"this code and your current code.</p>" +
"<div class='sortable-code' id='prevFeedback'></div>";
html += "</div>";
// .. set the content of the tab ...
RevisitFeedback.html(html)
.label("Hint")
.available(true); // .. and make the "feedback" available
// create the parsons feedback
createParsonFeedbackForElement("currFeedback", newAction.output);
createParsonFeedbackForElement("prevFeedback", action.output);
// .. and higlight modified lines
RevisitFeedback.highlightLine("currFeedbackcodeline" + action.target)
.highlightLine("prevFeedbackcodeline" + action.target);
} else if (previousFeedbackState) {
RevisitFeedback.available(false);
setLastFeedback();
} else {
RevisitFeedback.available(false); // make the feedback unavailable
}
} | [
"function",
"(",
"newAction",
")",
"{",
"// ignore init and feedback actions",
"if",
"(",
"newAction",
".",
"type",
"===",
"\"init\"",
"||",
"newAction",
".",
"type",
"===",
"\"feedback\"",
")",
"{",
"return",
";",
"}",
"var",
"action",
"=",
"parson",
".",
"whatWeDidPreviously",
"(",
")",
";",
"// if we have been here before (action not undefined) and more than one line in solution...",
"if",
"(",
"action",
"&&",
"action",
".",
"output",
"&&",
"newAction",
".",
"output",
".",
"split",
"(",
"'-'",
")",
".",
"length",
">",
"1",
"&&",
"action",
".",
"output",
".",
"split",
"(",
"'-'",
")",
".",
"length",
">",
"1",
"&&",
"action",
".",
"stepsToLast",
">",
"2",
")",
"{",
"var",
"html",
"=",
"\"<div class='currentState'><p>Your current code is identical to one you had \"",
"+",
"\"previously. You might want to stop going in circles and think carefully about \"",
"+",
"\"the feedback shown here.</p>\"",
"+",
"\"<div class='sortable-code' id='currFeedback'></div>\"",
";",
"html",
"+=",
"\"</div><div class='prevAction'><p>Last time you went on to move the line \"",
"+",
"\"highlighted with a blue right margin. Think carefully about the feedback for \"",
"+",
"\"this code and your current code.</p>\"",
"+",
"\"<div class='sortable-code' id='prevFeedback'></div>\"",
";",
"html",
"+=",
"\"</div>\"",
";",
"// .. set the content of the tab ...",
"RevisitFeedback",
".",
"html",
"(",
"html",
")",
".",
"label",
"(",
"\"Hint\"",
")",
".",
"available",
"(",
"true",
")",
";",
"// .. and make the \"feedback\" available",
"// create the parsons feedback",
"createParsonFeedbackForElement",
"(",
"\"currFeedback\"",
",",
"newAction",
".",
"output",
")",
";",
"createParsonFeedbackForElement",
"(",
"\"prevFeedback\"",
",",
"action",
".",
"output",
")",
";",
"// .. and higlight modified lines",
"RevisitFeedback",
".",
"highlightLine",
"(",
"\"currFeedbackcodeline\"",
"+",
"action",
".",
"target",
")",
".",
"highlightLine",
"(",
"\"prevFeedbackcodeline\"",
"+",
"action",
".",
"target",
")",
";",
"}",
"else",
"if",
"(",
"previousFeedbackState",
")",
"{",
"RevisitFeedback",
".",
"available",
"(",
"false",
")",
";",
"setLastFeedback",
"(",
")",
";",
"}",
"else",
"{",
"RevisitFeedback",
".",
"available",
"(",
"false",
")",
";",
"// make the feedback unavailable",
"}",
"}"
] | callback function called when user action is done on codelines | [
"callback",
"function",
"called",
"when",
"user",
"action",
"is",
"done",
"on",
"codelines"
] | 8c504c261137b0bedf1939a60dd76cfe21d01d7f | https://github.com/acos-server/acos-jsparsons/blob/8c504c261137b0bedf1939a60dd76cfe21d01d7f/static/js-parsons/ui-extension/parsons-site-ui.js#L141-L173 |
|
50,163 | acos-server/acos-jsparsons | static/js-parsons/ui-extension/parsons-site-ui.js | function(title, message, callback, options) {
var buttons = {};
buttons[options?(options.buttonTitle || "OK"):"OK"] = function() {
$(this).dialog( "close" );
};
var opts = $.extend(true,
{ buttons: buttons,
modal: true,
title: title,
draggable: false,
close: function() {
// if there is a callback, call it
if ($.isFunction(callback)) {
callback();
}
return true;
}
},
options);
$("#feedbackDialog") // find the dialog element
.find("p") // find the p element inside
.text(message) // set the feedback text
.end() // go back to the #feedbackDialog element
.dialog(opts);
} | javascript | function(title, message, callback, options) {
var buttons = {};
buttons[options?(options.buttonTitle || "OK"):"OK"] = function() {
$(this).dialog( "close" );
};
var opts = $.extend(true,
{ buttons: buttons,
modal: true,
title: title,
draggable: false,
close: function() {
// if there is a callback, call it
if ($.isFunction(callback)) {
callback();
}
return true;
}
},
options);
$("#feedbackDialog") // find the dialog element
.find("p") // find the p element inside
.text(message) // set the feedback text
.end() // go back to the #feedbackDialog element
.dialog(opts);
} | [
"function",
"(",
"title",
",",
"message",
",",
"callback",
",",
"options",
")",
"{",
"var",
"buttons",
"=",
"{",
"}",
";",
"buttons",
"[",
"options",
"?",
"(",
"options",
".",
"buttonTitle",
"||",
"\"OK\"",
")",
":",
"\"OK\"",
"]",
"=",
"function",
"(",
")",
"{",
"$",
"(",
"this",
")",
".",
"dialog",
"(",
"\"close\"",
")",
";",
"}",
";",
"var",
"opts",
"=",
"$",
".",
"extend",
"(",
"true",
",",
"{",
"buttons",
":",
"buttons",
",",
"modal",
":",
"true",
",",
"title",
":",
"title",
",",
"draggable",
":",
"false",
",",
"close",
":",
"function",
"(",
")",
"{",
"// if there is a callback, call it",
"if",
"(",
"$",
".",
"isFunction",
"(",
"callback",
")",
")",
"{",
"callback",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"}",
",",
"options",
")",
";",
"$",
"(",
"\"#feedbackDialog\"",
")",
"// find the dialog element",
".",
"find",
"(",
"\"p\"",
")",
"// find the p element inside",
".",
"text",
"(",
"message",
")",
"// set the feedback text",
".",
"end",
"(",
")",
"// go back to the #feedbackDialog element",
".",
"dialog",
"(",
"opts",
")",
";",
"}"
] | function used to show a UI message dialog | [
"function",
"used",
"to",
"show",
"a",
"UI",
"message",
"dialog"
] | 8c504c261137b0bedf1939a60dd76cfe21d01d7f | https://github.com/acos-server/acos-jsparsons/blob/8c504c261137b0bedf1939a60dd76cfe21d01d7f/static/js-parsons/ui-extension/parsons-site-ui.js#L176-L200 |
|
50,164 | acos-server/acos-jsparsons | static/js-parsons/ui-extension/parsons-site-ui.js | function(duration) {
$("#header").addClass("timer");
$("#timer").show().animate({width: "100%"}, duration, function() {
$("#header").removeClass("timer");
$("#timer").hide().css({width: "0"});
});
} | javascript | function(duration) {
$("#header").addClass("timer");
$("#timer").show().animate({width: "100%"}, duration, function() {
$("#header").removeClass("timer");
$("#timer").hide().css({width: "0"});
});
} | [
"function",
"(",
"duration",
")",
"{",
"$",
"(",
"\"#header\"",
")",
".",
"addClass",
"(",
"\"timer\"",
")",
";",
"$",
"(",
"\"#timer\"",
")",
".",
"show",
"(",
")",
".",
"animate",
"(",
"{",
"width",
":",
"\"100%\"",
"}",
",",
"duration",
",",
"function",
"(",
")",
"{",
"$",
"(",
"\"#header\"",
")",
".",
"removeClass",
"(",
"\"timer\"",
")",
";",
"$",
"(",
"\"#timer\"",
")",
".",
"hide",
"(",
")",
".",
"css",
"(",
"{",
"width",
":",
"\"0\"",
"}",
")",
";",
"}",
")",
";",
"}"
] | function to disable feedback for duration milliseconds | [
"function",
"to",
"disable",
"feedback",
"for",
"duration",
"milliseconds"
] | 8c504c261137b0bedf1939a60dd76cfe21d01d7f | https://github.com/acos-server/acos-jsparsons/blob/8c504c261137b0bedf1939a60dd76cfe21d01d7f/static/js-parsons/ui-extension/parsons-site-ui.js#L203-L209 |
|
50,165 | acos-server/acos-jsparsons | static/js-parsons/ui-extension/parsons-site-ui.js | function(feedback) {
var isCorrect = ($.isArray(feedback) && feedback.length === 0) ||
('feedback' in feedback && feedback.success);
// correctly solved but collection has more exercises
if (isCorrect && $.isFunction(PARSONS_SETTINGS.next)) {
$("#ul-sortable").sortable("destroy");
$("#ul-sortableTrash").sortable("destroy");
showDialog("Good Job!", "Click OK to go to the next question.", function() {
PARSONS_SETTINGS.next();
});
} else if (isCorrect) { // correct and last question
showDialog("Good Job!", "That was the last question. Click OK to go back to main page.", function() {
window.location = "./index.html";
});
} else { // not correct, show feedback
var now = new Date(),
penaltyTime = 0,
feedbackText;
if ($.isArray(feedback)) { // line-based feedback
feedbackText = feedback.join('\n');
} else if ('feedback' in feedback) { // execution based feedback
feedbackText = "Some tests failed for your solution. See the Last Feedback tab for details.";
}
if (feedbackTimeHistory.length > 1) { // 1st and 2nd feedback can't be too fast
// we'll go through all the times in the feedback time history
for (var i = 0; i < feedbackTimeHistory.length; i++) {
// check if the corresponding feedbackwindow is bigger than time between now
// and the i:th feedback time
if (FEEDBACK_WINDOWS[i] > now - feedbackTimeHistory[i]) {
penaltyTime += FEEDBACK_PENALTIES[i]; // add to penalty time
}
}
// if there is penalty time, disable feedback and show a message to student
if (penaltyTime > 0) {
disableFeedback(penaltyTime);
feedbackText += "\n\nDue to frequent use, feedback has been disabled for a while. It will be" +
"available once the button turns orange again. You can still continue solving the problem.";
}
}
// add the current time to the feedbak history
feedbackTimeHistory.unshift(now);
// make sure we have at most as many feedback times in history as we have windows
feedbackTimeHistory = feedbackTimeHistory.slice(0, FEEDBACK_WINDOWS.length);
showDialog("Feedback", feedbackText);
}
} | javascript | function(feedback) {
var isCorrect = ($.isArray(feedback) && feedback.length === 0) ||
('feedback' in feedback && feedback.success);
// correctly solved but collection has more exercises
if (isCorrect && $.isFunction(PARSONS_SETTINGS.next)) {
$("#ul-sortable").sortable("destroy");
$("#ul-sortableTrash").sortable("destroy");
showDialog("Good Job!", "Click OK to go to the next question.", function() {
PARSONS_SETTINGS.next();
});
} else if (isCorrect) { // correct and last question
showDialog("Good Job!", "That was the last question. Click OK to go back to main page.", function() {
window.location = "./index.html";
});
} else { // not correct, show feedback
var now = new Date(),
penaltyTime = 0,
feedbackText;
if ($.isArray(feedback)) { // line-based feedback
feedbackText = feedback.join('\n');
} else if ('feedback' in feedback) { // execution based feedback
feedbackText = "Some tests failed for your solution. See the Last Feedback tab for details.";
}
if (feedbackTimeHistory.length > 1) { // 1st and 2nd feedback can't be too fast
// we'll go through all the times in the feedback time history
for (var i = 0; i < feedbackTimeHistory.length; i++) {
// check if the corresponding feedbackwindow is bigger than time between now
// and the i:th feedback time
if (FEEDBACK_WINDOWS[i] > now - feedbackTimeHistory[i]) {
penaltyTime += FEEDBACK_PENALTIES[i]; // add to penalty time
}
}
// if there is penalty time, disable feedback and show a message to student
if (penaltyTime > 0) {
disableFeedback(penaltyTime);
feedbackText += "\n\nDue to frequent use, feedback has been disabled for a while. It will be" +
"available once the button turns orange again. You can still continue solving the problem.";
}
}
// add the current time to the feedbak history
feedbackTimeHistory.unshift(now);
// make sure we have at most as many feedback times in history as we have windows
feedbackTimeHistory = feedbackTimeHistory.slice(0, FEEDBACK_WINDOWS.length);
showDialog("Feedback", feedbackText);
}
} | [
"function",
"(",
"feedback",
")",
"{",
"var",
"isCorrect",
"=",
"(",
"$",
".",
"isArray",
"(",
"feedback",
")",
"&&",
"feedback",
".",
"length",
"===",
"0",
")",
"||",
"(",
"'feedback'",
"in",
"feedback",
"&&",
"feedback",
".",
"success",
")",
";",
"// correctly solved but collection has more exercises",
"if",
"(",
"isCorrect",
"&&",
"$",
".",
"isFunction",
"(",
"PARSONS_SETTINGS",
".",
"next",
")",
")",
"{",
"$",
"(",
"\"#ul-sortable\"",
")",
".",
"sortable",
"(",
"\"destroy\"",
")",
";",
"$",
"(",
"\"#ul-sortableTrash\"",
")",
".",
"sortable",
"(",
"\"destroy\"",
")",
";",
"showDialog",
"(",
"\"Good Job!\"",
",",
"\"Click OK to go to the next question.\"",
",",
"function",
"(",
")",
"{",
"PARSONS_SETTINGS",
".",
"next",
"(",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"isCorrect",
")",
"{",
"// correct and last question",
"showDialog",
"(",
"\"Good Job!\"",
",",
"\"That was the last question. Click OK to go back to main page.\"",
",",
"function",
"(",
")",
"{",
"window",
".",
"location",
"=",
"\"./index.html\"",
";",
"}",
")",
";",
"}",
"else",
"{",
"// not correct, show feedback",
"var",
"now",
"=",
"new",
"Date",
"(",
")",
",",
"penaltyTime",
"=",
"0",
",",
"feedbackText",
";",
"if",
"(",
"$",
".",
"isArray",
"(",
"feedback",
")",
")",
"{",
"// line-based feedback",
"feedbackText",
"=",
"feedback",
".",
"join",
"(",
"'\\n'",
")",
";",
"}",
"else",
"if",
"(",
"'feedback'",
"in",
"feedback",
")",
"{",
"// execution based feedback",
"feedbackText",
"=",
"\"Some tests failed for your solution. See the Last Feedback tab for details.\"",
";",
"}",
"if",
"(",
"feedbackTimeHistory",
".",
"length",
">",
"1",
")",
"{",
"// 1st and 2nd feedback can't be too fast",
"// we'll go through all the times in the feedback time history",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"feedbackTimeHistory",
".",
"length",
";",
"i",
"++",
")",
"{",
"// check if the corresponding feedbackwindow is bigger than time between now",
"// and the i:th feedback time",
"if",
"(",
"FEEDBACK_WINDOWS",
"[",
"i",
"]",
">",
"now",
"-",
"feedbackTimeHistory",
"[",
"i",
"]",
")",
"{",
"penaltyTime",
"+=",
"FEEDBACK_PENALTIES",
"[",
"i",
"]",
";",
"// add to penalty time",
"}",
"}",
"// if there is penalty time, disable feedback and show a message to student",
"if",
"(",
"penaltyTime",
">",
"0",
")",
"{",
"disableFeedback",
"(",
"penaltyTime",
")",
";",
"feedbackText",
"+=",
"\"\\n\\nDue to frequent use, feedback has been disabled for a while. It will be\"",
"+",
"\"available once the button turns orange again. You can still continue solving the problem.\"",
";",
"}",
"}",
"// add the current time to the feedbak history",
"feedbackTimeHistory",
".",
"unshift",
"(",
"now",
")",
";",
"// make sure we have at most as many feedback times in history as we have windows",
"feedbackTimeHistory",
"=",
"feedbackTimeHistory",
".",
"slice",
"(",
"0",
",",
"FEEDBACK_WINDOWS",
".",
"length",
")",
";",
"showDialog",
"(",
"\"Feedback\"",
",",
"feedbackText",
")",
";",
"}",
"}"
] | default feedback callback handler | [
"default",
"feedback",
"callback",
"handler"
] | 8c504c261137b0bedf1939a60dd76cfe21d01d7f | https://github.com/acos-server/acos-jsparsons/blob/8c504c261137b0bedf1939a60dd76cfe21d01d7f/static/js-parsons/ui-extension/parsons-site-ui.js#L213-L259 |
|
50,166 | toddbluhm/bluebird-events | index.js | function (events, func) {
for (var i = 0; i < events.length; i++) {
obj.once(events[i], func)
listeners[events[i]] = func
}
} | javascript | function (events, func) {
for (var i = 0; i < events.length; i++) {
obj.once(events[i], func)
listeners[events[i]] = func
}
} | [
"function",
"(",
"events",
",",
"func",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"events",
".",
"length",
";",
"i",
"++",
")",
"{",
"obj",
".",
"once",
"(",
"events",
"[",
"i",
"]",
",",
"func",
")",
"listeners",
"[",
"events",
"[",
"i",
"]",
"]",
"=",
"func",
"}",
"}"
] | Adds an array of events to the object with the given func | [
"Adds",
"an",
"array",
"of",
"events",
"to",
"the",
"object",
"with",
"the",
"given",
"func"
] | 3f9045c73c35ad28e6c285feca4a740bfec6ff91 | https://github.com/toddbluhm/bluebird-events/blob/3f9045c73c35ad28e6c285feca4a740bfec6ff91/index.js#L45-L50 |
|
50,167 | yefremov/aggregatejs | max.js | max | function max(array) {
var length = array.length;
if (length === 0) {
return 0;
}
var index = -1;
var result = array[++index];
while (++index < length) {
if (array[index] > result) {
result = array[index];
}
}
return result;
} | javascript | function max(array) {
var length = array.length;
if (length === 0) {
return 0;
}
var index = -1;
var result = array[++index];
while (++index < length) {
if (array[index] > result) {
result = array[index];
}
}
return result;
} | [
"function",
"max",
"(",
"array",
")",
"{",
"var",
"length",
"=",
"array",
".",
"length",
";",
"if",
"(",
"length",
"===",
"0",
")",
"{",
"return",
"0",
";",
"}",
"var",
"index",
"=",
"-",
"1",
";",
"var",
"result",
"=",
"array",
"[",
"++",
"index",
"]",
";",
"while",
"(",
"++",
"index",
"<",
"length",
")",
"{",
"if",
"(",
"array",
"[",
"index",
"]",
">",
"result",
")",
"{",
"result",
"=",
"array",
"[",
"index",
"]",
";",
"}",
"}",
"return",
"result",
";",
"}"
] | Returns the largest number in `array`.
@param {Array} array Range of numbers to get maximum.
@return {number}
@example
max([100, -100, 150, -50, 250, 100]);
// => 250 | [
"Returns",
"the",
"largest",
"number",
"in",
"array",
"."
] | 932b28a15a5707135e7095950000a838db409511 | https://github.com/yefremov/aggregatejs/blob/932b28a15a5707135e7095950000a838db409511/max.js#L19-L36 |
50,168 | taoyuan/sira-express-rest | lib/rest.js | buildRoutes | function buildRoutes(obj) {
var routes = obj.http;
if (routes && !Array.isArray(routes)) {
routes = [routes];
}
// overidden
if (routes) {
// patch missing verbs / routes
routes.forEach(function (r) {
r.verb = String(r.verb || 'all').toLowerCase();
r.path = r.path || ('/' + obj.name);
});
} else {
if (obj.name === 'sharedCtor') {
routes = [
{
verb: 'all',
path: '/prototype'
}
];
} else {
// build default route
routes = [
{
verb: 'all',
path: obj.name ? ('/' + obj.name) : ''
}
];
}
}
return routes;
} | javascript | function buildRoutes(obj) {
var routes = obj.http;
if (routes && !Array.isArray(routes)) {
routes = [routes];
}
// overidden
if (routes) {
// patch missing verbs / routes
routes.forEach(function (r) {
r.verb = String(r.verb || 'all').toLowerCase();
r.path = r.path || ('/' + obj.name);
});
} else {
if (obj.name === 'sharedCtor') {
routes = [
{
verb: 'all',
path: '/prototype'
}
];
} else {
// build default route
routes = [
{
verb: 'all',
path: obj.name ? ('/' + obj.name) : ''
}
];
}
}
return routes;
} | [
"function",
"buildRoutes",
"(",
"obj",
")",
"{",
"var",
"routes",
"=",
"obj",
".",
"http",
";",
"if",
"(",
"routes",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"routes",
")",
")",
"{",
"routes",
"=",
"[",
"routes",
"]",
";",
"}",
"// overidden",
"if",
"(",
"routes",
")",
"{",
"// patch missing verbs / routes",
"routes",
".",
"forEach",
"(",
"function",
"(",
"r",
")",
"{",
"r",
".",
"verb",
"=",
"String",
"(",
"r",
".",
"verb",
"||",
"'all'",
")",
".",
"toLowerCase",
"(",
")",
";",
"r",
".",
"path",
"=",
"r",
".",
"path",
"||",
"(",
"'/'",
"+",
"obj",
".",
"name",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"if",
"(",
"obj",
".",
"name",
"===",
"'sharedCtor'",
")",
"{",
"routes",
"=",
"[",
"{",
"verb",
":",
"'all'",
",",
"path",
":",
"'/prototype'",
"}",
"]",
";",
"}",
"else",
"{",
"// build default route",
"routes",
"=",
"[",
"{",
"verb",
":",
"'all'",
",",
"path",
":",
"obj",
".",
"name",
"?",
"(",
"'/'",
"+",
"obj",
".",
"name",
")",
":",
"''",
"}",
"]",
";",
"}",
"}",
"return",
"routes",
";",
"}"
] | Get the path for the given method.
Rest.prototype.buildRoutes = buildRoutes; | [
"Get",
"the",
"path",
"for",
"the",
"given",
"method",
".",
"Rest",
".",
"prototype",
".",
"buildRoutes",
"=",
"buildRoutes",
";"
] | 84b06a3cb127cf68f194a1b1ec115db0e560078c | https://github.com/taoyuan/sira-express-rest/blob/84b06a3cb127cf68f194a1b1ec115db0e560078c/lib/rest.js#L341-L375 |
50,169 | benmosheron/ben-loves-vectors | vector.js | create2x2 | function create2x2(a, b, c, d){
if (undef(a)) throw new Error("At least one argument must be provided.");
if (undef(b)){
// Everything = a
b = a;
c = a;
d = a;
}
else{
// we have a and b
if(undef(c)){
c = a;
d = b;
}
else{
if(undef(d)) throw new Error("Argument 'd' must be provided if 'c' is.");
}
}
return new Vector([[a, b],[c, d]]);
} | javascript | function create2x2(a, b, c, d){
if (undef(a)) throw new Error("At least one argument must be provided.");
if (undef(b)){
// Everything = a
b = a;
c = a;
d = a;
}
else{
// we have a and b
if(undef(c)){
c = a;
d = b;
}
else{
if(undef(d)) throw new Error("Argument 'd' must be provided if 'c' is.");
}
}
return new Vector([[a, b],[c, d]]);
} | [
"function",
"create2x2",
"(",
"a",
",",
"b",
",",
"c",
",",
"d",
")",
"{",
"if",
"(",
"undef",
"(",
"a",
")",
")",
"throw",
"new",
"Error",
"(",
"\"At least one argument must be provided.\"",
")",
";",
"if",
"(",
"undef",
"(",
"b",
")",
")",
"{",
"// Everything = a",
"b",
"=",
"a",
";",
"c",
"=",
"a",
";",
"d",
"=",
"a",
";",
"}",
"else",
"{",
"// we have a and b",
"if",
"(",
"undef",
"(",
"c",
")",
")",
"{",
"c",
"=",
"a",
";",
"d",
"=",
"b",
";",
"}",
"else",
"{",
"if",
"(",
"undef",
"(",
"d",
")",
")",
"throw",
"new",
"Error",
"(",
"\"Argument 'd' must be provided if 'c' is.\"",
")",
";",
"}",
"}",
"return",
"new",
"Vector",
"(",
"[",
"[",
"a",
",",
"b",
"]",
",",
"[",
"c",
",",
"d",
"]",
"]",
")",
";",
"}"
] | Create a 2D vector by providing one, two, or four values | [
"Create",
"a",
"2D",
"vector",
"by",
"providing",
"one",
"two",
"or",
"four",
"values"
] | 8af737655f6a0fc4a585b3281f516129bb5bc8d3 | https://github.com/benmosheron/ben-loves-vectors/blob/8af737655f6a0fc4a585b3281f516129bb5bc8d3/vector.js#L130-L151 |
50,170 | benmosheron/ben-loves-vectors | vector.js | drillRec | function drillRec(v){
const next = v.get(0);
if(v.length > 1 || !isAVector(next)) return v;
return drillRec(next);
} | javascript | function drillRec(v){
const next = v.get(0);
if(v.length > 1 || !isAVector(next)) return v;
return drillRec(next);
} | [
"function",
"drillRec",
"(",
"v",
")",
"{",
"const",
"next",
"=",
"v",
".",
"get",
"(",
"0",
")",
";",
"if",
"(",
"v",
".",
"length",
">",
"1",
"||",
"!",
"isAVector",
"(",
"next",
")",
")",
"return",
"v",
";",
"return",
"drillRec",
"(",
"next",
")",
";",
"}"
] | drill to first level with >1 value | [
"drill",
"to",
"first",
"level",
"with",
">",
"1",
"value"
] | 8af737655f6a0fc4a585b3281f516129bb5bc8d3 | https://github.com/benmosheron/ben-loves-vectors/blob/8af737655f6a0fc4a585b3281f516129bb5bc8d3/vector.js#L350-L354 |
50,171 | benmosheron/ben-loves-vectors | vector.js | mapToValues | function mapToValues(v){
function mapRec(e){
if(!isAVector(e)) return e;
return mapRec(e.get(0));
}
return v.map(mapRec);
} | javascript | function mapToValues(v){
function mapRec(e){
if(!isAVector(e)) return e;
return mapRec(e.get(0));
}
return v.map(mapRec);
} | [
"function",
"mapToValues",
"(",
"v",
")",
"{",
"function",
"mapRec",
"(",
"e",
")",
"{",
"if",
"(",
"!",
"isAVector",
"(",
"e",
")",
")",
"return",
"e",
";",
"return",
"mapRec",
"(",
"e",
".",
"get",
"(",
"0",
")",
")",
";",
"}",
"return",
"v",
".",
"map",
"(",
"mapRec",
")",
";",
"}"
] | map to elementary values | [
"map",
"to",
"elementary",
"values"
] | 8af737655f6a0fc4a585b3281f516129bb5bc8d3 | https://github.com/benmosheron/ben-loves-vectors/blob/8af737655f6a0fc4a585b3281f516129bb5bc8d3/vector.js#L357-L363 |
50,172 | cli-kit/cli-mid-command | index.js | lazy | function lazy(arg) {
var conf = this.configure();
var action = arg.action();
if(!conf.command.dir || action !== undefined) return false;
var file = path.join(conf.command.dir, getModulePath.call(this, arg))
try{
action = require(file);
if(typeof action !== 'function') {
return this.raise(this.errors.ECMD_TYPE, [file]);
}
arg.action(action);
}catch(e) {
return this.raise(this.errors.ECMD_REQUIRE, [file, e.message], e);
}
} | javascript | function lazy(arg) {
var conf = this.configure();
var action = arg.action();
if(!conf.command.dir || action !== undefined) return false;
var file = path.join(conf.command.dir, getModulePath.call(this, arg))
try{
action = require(file);
if(typeof action !== 'function') {
return this.raise(this.errors.ECMD_TYPE, [file]);
}
arg.action(action);
}catch(e) {
return this.raise(this.errors.ECMD_REQUIRE, [file, e.message], e);
}
} | [
"function",
"lazy",
"(",
"arg",
")",
"{",
"var",
"conf",
"=",
"this",
".",
"configure",
"(",
")",
";",
"var",
"action",
"=",
"arg",
".",
"action",
"(",
")",
";",
"if",
"(",
"!",
"conf",
".",
"command",
".",
"dir",
"||",
"action",
"!==",
"undefined",
")",
"return",
"false",
";",
"var",
"file",
"=",
"path",
".",
"join",
"(",
"conf",
".",
"command",
".",
"dir",
",",
"getModulePath",
".",
"call",
"(",
"this",
",",
"arg",
")",
")",
"try",
"{",
"action",
"=",
"require",
"(",
"file",
")",
";",
"if",
"(",
"typeof",
"action",
"!==",
"'function'",
")",
"{",
"return",
"this",
".",
"raise",
"(",
"this",
".",
"errors",
".",
"ECMD_TYPE",
",",
"[",
"file",
"]",
")",
";",
"}",
"arg",
".",
"action",
"(",
"action",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"return",
"this",
".",
"raise",
"(",
"this",
".",
"errors",
".",
"ECMD_REQUIRE",
",",
"[",
"file",
",",
"e",
".",
"message",
"]",
",",
"e",
")",
";",
"}",
"}"
] | lazily load a command action definition from a module | [
"lazily",
"load",
"a",
"command",
"action",
"definition",
"from",
"a",
"module"
] | fd2c3d758886e2833df7dcf84b0e14cd40649671 | https://github.com/cli-kit/cli-mid-command/blob/fd2c3d758886e2833df7dcf84b0e14cd40649671/index.js#L23-L37 |
50,173 | jwoudenberg/require-compiled | index.js | rewriteRequires | function rewriteRequires (filename) {
var basedir = path.dirname(filename)
return wrapListener(
function (nodePath) {
if (nodePath.isLiteral() && !path.isAbsolute(nodePath.node.value)) {
var match = nodePath.node.value.match(/^compile!(.+)$/)
nodePath.node.value = match
? nodePath.node.value = requireCompiledResolve(filename, match[1])
: nodePath.node.value = resolve.sync(nodePath.node.value, { basedir: basedir })
}
},
'rewrite-require',
{
generated: true,
require: true,
import: true
}
)
} | javascript | function rewriteRequires (filename) {
var basedir = path.dirname(filename)
return wrapListener(
function (nodePath) {
if (nodePath.isLiteral() && !path.isAbsolute(nodePath.node.value)) {
var match = nodePath.node.value.match(/^compile!(.+)$/)
nodePath.node.value = match
? nodePath.node.value = requireCompiledResolve(filename, match[1])
: nodePath.node.value = resolve.sync(nodePath.node.value, { basedir: basedir })
}
},
'rewrite-require',
{
generated: true,
require: true,
import: true
}
)
} | [
"function",
"rewriteRequires",
"(",
"filename",
")",
"{",
"var",
"basedir",
"=",
"path",
".",
"dirname",
"(",
"filename",
")",
"return",
"wrapListener",
"(",
"function",
"(",
"nodePath",
")",
"{",
"if",
"(",
"nodePath",
".",
"isLiteral",
"(",
")",
"&&",
"!",
"path",
".",
"isAbsolute",
"(",
"nodePath",
".",
"node",
".",
"value",
")",
")",
"{",
"var",
"match",
"=",
"nodePath",
".",
"node",
".",
"value",
".",
"match",
"(",
"/",
"^compile!(.+)$",
"/",
")",
"nodePath",
".",
"node",
".",
"value",
"=",
"match",
"?",
"nodePath",
".",
"node",
".",
"value",
"=",
"requireCompiledResolve",
"(",
"filename",
",",
"match",
"[",
"1",
"]",
")",
":",
"nodePath",
".",
"node",
".",
"value",
"=",
"resolve",
".",
"sync",
"(",
"nodePath",
".",
"node",
".",
"value",
",",
"{",
"basedir",
":",
"basedir",
"}",
")",
"}",
"}",
",",
"'rewrite-require'",
",",
"{",
"generated",
":",
"true",
",",
"require",
":",
"true",
",",
"import",
":",
"true",
"}",
")",
"}"
] | Rewrite requires to use absolute paths. This way tests the compiled tests can still be ran from a different directory. | [
"Rewrite",
"requires",
"to",
"use",
"absolute",
"paths",
".",
"This",
"way",
"tests",
"the",
"compiled",
"tests",
"can",
"still",
"be",
"ran",
"from",
"a",
"different",
"directory",
"."
] | 99f45ad1f286ba346313d23e6d42d78adff68d42 | https://github.com/jwoudenberg/require-compiled/blob/99f45ad1f286ba346313d23e6d42d78adff68d42/index.js#L84-L102 |
50,174 | meltmedia/node-usher | lib/activity/poller.js | ActivityPoller | function ActivityPoller(name, domain, options) {
if (!(this instanceof ActivityPoller)) {
return new ActivityPoller(name, domain, options);
}
events.EventEmitter.call(this);
if (!_.isString(name)) {
throw new Error('A `name` is required');
}
if (!_.isString(domain)) {
throw new Error('A `domain` is required');
}
this.name = name;
this.domain = domain;
this.options = options || {};
// Make sure taskList is an object of { name: '' }
if (this.options.taskList && _.isString(this.options.taskList)) {
this.options.taskList = { name: this.options.taskList };
}
// Set default taskList if not defined
if (!this.options.taskList) {
this.options.taskList = { name: this.name + '-tasklist' };
}
/** @private */
this._registrations = [];
this._activities = {};
this._poller = undefined;
} | javascript | function ActivityPoller(name, domain, options) {
if (!(this instanceof ActivityPoller)) {
return new ActivityPoller(name, domain, options);
}
events.EventEmitter.call(this);
if (!_.isString(name)) {
throw new Error('A `name` is required');
}
if (!_.isString(domain)) {
throw new Error('A `domain` is required');
}
this.name = name;
this.domain = domain;
this.options = options || {};
// Make sure taskList is an object of { name: '' }
if (this.options.taskList && _.isString(this.options.taskList)) {
this.options.taskList = { name: this.options.taskList };
}
// Set default taskList if not defined
if (!this.options.taskList) {
this.options.taskList = { name: this.name + '-tasklist' };
}
/** @private */
this._registrations = [];
this._activities = {};
this._poller = undefined;
} | [
"function",
"ActivityPoller",
"(",
"name",
",",
"domain",
",",
"options",
")",
"{",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ActivityPoller",
")",
")",
"{",
"return",
"new",
"ActivityPoller",
"(",
"name",
",",
"domain",
",",
"options",
")",
";",
"}",
"events",
".",
"EventEmitter",
".",
"call",
"(",
"this",
")",
";",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"name",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A `name` is required'",
")",
";",
"}",
"if",
"(",
"!",
"_",
".",
"isString",
"(",
"domain",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'A `domain` is required'",
")",
";",
"}",
"this",
".",
"name",
"=",
"name",
";",
"this",
".",
"domain",
"=",
"domain",
";",
"this",
".",
"options",
"=",
"options",
"||",
"{",
"}",
";",
"// Make sure taskList is an object of { name: '' }",
"if",
"(",
"this",
".",
"options",
".",
"taskList",
"&&",
"_",
".",
"isString",
"(",
"this",
".",
"options",
".",
"taskList",
")",
")",
"{",
"this",
".",
"options",
".",
"taskList",
"=",
"{",
"name",
":",
"this",
".",
"options",
".",
"taskList",
"}",
";",
"}",
"// Set default taskList if not defined",
"if",
"(",
"!",
"this",
".",
"options",
".",
"taskList",
")",
"{",
"this",
".",
"options",
".",
"taskList",
"=",
"{",
"name",
":",
"this",
".",
"name",
"+",
"'-tasklist'",
"}",
";",
"}",
"/** @private */",
"this",
".",
"_registrations",
"=",
"[",
"]",
";",
"this",
".",
"_activities",
"=",
"{",
"}",
";",
"this",
".",
"_poller",
"=",
"undefined",
";",
"}"
] | Represents a single, named poller, where all activities are defined.
@constructor
@param {string} name - The name of the poller. This is arbitrary and has no bering on SWF.
@param {string} domain - The AWS SWF domain name to execute this pollers activities in.
@param {object} [options] - Additional options used when polling for new activities
(taskList) | [
"Represents",
"a",
"single",
"named",
"poller",
"where",
"all",
"activities",
"are",
"defined",
"."
] | fe6183bf7097f84bef935e8d9c19463accc08ad6 | https://github.com/meltmedia/node-usher/blob/fe6183bf7097f84bef935e8d9c19463accc08ad6/lib/activity/poller.js#L33-L67 |
50,175 | docLoop/core | manage-calls.js | function(obj, method_name, force_call_after = 1000){
if(typeof obj[method_name] != 'function') throw new TypeError("collateCalls(): Not a method '"+method_name+ "' on "+obj.toString())
var original_fn = obj[method_name],
scheduled_runs = {}
function requestRun(...args){
var str = JSON.stringify(args)
if(!scheduled_runs[str] || !scheduled_runs[str].isPending()){
scheduled_runs[str] = Promise.resolve( original_fn.apply(obj, args) )
setTimeout( () => scheduled_runs[str] = undefined, force_call_after)
}
return scheduled_runs[str]
}
function restore(){
obj[method_name] = original_fn
}
obj[method_name] = requestRun
obj[method_name].restore = restore
} | javascript | function(obj, method_name, force_call_after = 1000){
if(typeof obj[method_name] != 'function') throw new TypeError("collateCalls(): Not a method '"+method_name+ "' on "+obj.toString())
var original_fn = obj[method_name],
scheduled_runs = {}
function requestRun(...args){
var str = JSON.stringify(args)
if(!scheduled_runs[str] || !scheduled_runs[str].isPending()){
scheduled_runs[str] = Promise.resolve( original_fn.apply(obj, args) )
setTimeout( () => scheduled_runs[str] = undefined, force_call_after)
}
return scheduled_runs[str]
}
function restore(){
obj[method_name] = original_fn
}
obj[method_name] = requestRun
obj[method_name].restore = restore
} | [
"function",
"(",
"obj",
",",
"method_name",
",",
"force_call_after",
"=",
"1000",
")",
"{",
"if",
"(",
"typeof",
"obj",
"[",
"method_name",
"]",
"!=",
"'function'",
")",
"throw",
"new",
"TypeError",
"(",
"\"collateCalls(): Not a method '\"",
"+",
"method_name",
"+",
"\"' on \"",
"+",
"obj",
".",
"toString",
"(",
")",
")",
"var",
"original_fn",
"=",
"obj",
"[",
"method_name",
"]",
",",
"scheduled_runs",
"=",
"{",
"}",
"function",
"requestRun",
"(",
"...",
"args",
")",
"{",
"var",
"str",
"=",
"JSON",
".",
"stringify",
"(",
"args",
")",
"if",
"(",
"!",
"scheduled_runs",
"[",
"str",
"]",
"||",
"!",
"scheduled_runs",
"[",
"str",
"]",
".",
"isPending",
"(",
")",
")",
"{",
"scheduled_runs",
"[",
"str",
"]",
"=",
"Promise",
".",
"resolve",
"(",
"original_fn",
".",
"apply",
"(",
"obj",
",",
"args",
")",
")",
"setTimeout",
"(",
"(",
")",
"=>",
"scheduled_runs",
"[",
"str",
"]",
"=",
"undefined",
",",
"force_call_after",
")",
"}",
"return",
"scheduled_runs",
"[",
"str",
"]",
"}",
"function",
"restore",
"(",
")",
"{",
"obj",
"[",
"method_name",
"]",
"=",
"original_fn",
"}",
"obj",
"[",
"method_name",
"]",
"=",
"requestRun",
"obj",
"[",
"method_name",
"]",
".",
"restore",
"=",
"restore",
"}"
] | Replaces a method of provided object with a proxy,
that will prevent multiple calls to the original method with the same arguments
while waiting for a response.
The proxy method will allways wrap the original method in a Promise.
If a previous call with the same arguments is still pending the proxy will return the corresponding promise.
This may help to prevent multiple redudant API calls.
(e.g. when you dont expect the result of an API call to change while it's pending)
Two sets of arguments are considered equal if their JSON representaions are equal.
The orginial method can be restored with obj[method_name].restore().
@memberof module:docloop
@param {Object} obj Target object
@param {string} method_name Name of the method whose calls should be callated
@param {Number} [force_call_after=1000] After this time (in milliseconds) the proxy will call the original method, regardless of previous calls still pending.
@throws {TypeError} If method_name does not point to a function.
@return {} undefined | [
"Replaces",
"a",
"method",
"of",
"provided",
"object",
"with",
"a",
"proxy",
"that",
"will",
"prevent",
"multiple",
"calls",
"to",
"the",
"original",
"method",
"with",
"the",
"same",
"arguments",
"while",
"waiting",
"for",
"a",
"response",
"."
] | 111870e3dcc537997fa31dee485e355e487af794 | https://github.com/docLoop/core/blob/111870e3dcc537997fa31dee485e355e487af794/manage-calls.js#L96-L121 |
|
50,176 | billysbilling/inflectors | index.js | function() {
singulars = {};
for (var k in plurals) {
if (!plurals.hasOwnProperty(k)) continue;
singulars[plurals[k]] = k;
}
} | javascript | function() {
singulars = {};
for (var k in plurals) {
if (!plurals.hasOwnProperty(k)) continue;
singulars[plurals[k]] = k;
}
} | [
"function",
"(",
")",
"{",
"singulars",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"k",
"in",
"plurals",
")",
"{",
"if",
"(",
"!",
"plurals",
".",
"hasOwnProperty",
"(",
"k",
")",
")",
"continue",
";",
"singulars",
"[",
"plurals",
"[",
"k",
"]",
"]",
"=",
"k",
";",
"}",
"}"
] | Clears singular rules and recreates from opposites of plural rules | [
"Clears",
"singular",
"rules",
"and",
"recreates",
"from",
"opposites",
"of",
"plural",
"rules"
] | 092d024e9e883aef911354e2af1c669a463d448f | https://github.com/billysbilling/inflectors/blob/092d024e9e883aef911354e2af1c669a463d448f/index.js#L74-L80 |
|
50,177 | redisjs/jsr-server | lib/command/script/evalsha.js | execute | function execute(req, res) {
ScriptManager.evalsha(req, res, '' + req.args[0], req.args.slice(1));
} | javascript | function execute(req, res) {
ScriptManager.evalsha(req, res, '' + req.args[0], req.args.slice(1));
} | [
"function",
"execute",
"(",
"req",
",",
"res",
")",
"{",
"ScriptManager",
".",
"evalsha",
"(",
"req",
",",
"res",
",",
"''",
"+",
"req",
".",
"args",
"[",
"0",
"]",
",",
"req",
".",
"args",
".",
"slice",
"(",
"1",
")",
")",
";",
"}"
] | Respond to the EVALSHA command. | [
"Respond",
"to",
"the",
"EVALSHA",
"command",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/command/script/evalsha.js#L18-L20 |
50,178 | feedhenry/fh-statsc | lib/stats.js | send | function send(data, cb) {
if (enabled) {
var send_data = new Buffer(data);
try {
socket.send(send_data, 0, send_data.length, port, host, function(err, bytes) {
if (cb) {
return cb(err, bytes);
}
});
} catch (x) {
// Purposely ignored..
cb();
}
} else {
cb();
}
} | javascript | function send(data, cb) {
if (enabled) {
var send_data = new Buffer(data);
try {
socket.send(send_data, 0, send_data.length, port, host, function(err, bytes) {
if (cb) {
return cb(err, bytes);
}
});
} catch (x) {
// Purposely ignored..
cb();
}
} else {
cb();
}
} | [
"function",
"send",
"(",
"data",
",",
"cb",
")",
"{",
"if",
"(",
"enabled",
")",
"{",
"var",
"send_data",
"=",
"new",
"Buffer",
"(",
"data",
")",
";",
"try",
"{",
"socket",
".",
"send",
"(",
"send_data",
",",
"0",
",",
"send_data",
".",
"length",
",",
"port",
",",
"host",
",",
"function",
"(",
"err",
",",
"bytes",
")",
"{",
"if",
"(",
"cb",
")",
"{",
"return",
"cb",
"(",
"err",
",",
"bytes",
")",
";",
"}",
"}",
")",
";",
"}",
"catch",
"(",
"x",
")",
"{",
"// Purposely ignored..",
"cb",
"(",
")",
";",
"}",
"}",
"else",
"{",
"cb",
"(",
")",
";",
"}",
"}"
] | needs to send in batches every second or so | [
"needs",
"to",
"send",
"in",
"batches",
"every",
"second",
"or",
"so"
] | 6a320a3dfa5d6baabc6ea4d5d7280bdb60e6757d | https://github.com/feedhenry/fh-statsc/blob/6a320a3dfa5d6baabc6ea4d5d7280bdb60e6757d/lib/stats.js#L23-L39 |
50,179 | nfroidure/common-services | src/codeGenerator.js | codeGenerator | async function codeGenerator(length = 6) {
const code = new Array(length)
.fill('0')
.map(() => CHARS_SET[Math.floor(random() * (charsSetLength - 1))])
.join('');
log('debug', `Generated a new code:`, code);
return code;
} | javascript | async function codeGenerator(length = 6) {
const code = new Array(length)
.fill('0')
.map(() => CHARS_SET[Math.floor(random() * (charsSetLength - 1))])
.join('');
log('debug', `Generated a new code:`, code);
return code;
} | [
"async",
"function",
"codeGenerator",
"(",
"length",
"=",
"6",
")",
"{",
"const",
"code",
"=",
"new",
"Array",
"(",
"length",
")",
".",
"fill",
"(",
"'0'",
")",
".",
"map",
"(",
"(",
")",
"=>",
"CHARS_SET",
"[",
"Math",
".",
"floor",
"(",
"random",
"(",
")",
"*",
"(",
"charsSetLength",
"-",
"1",
")",
")",
"]",
")",
".",
"join",
"(",
"''",
")",
";",
"log",
"(",
"'debug'",
",",
"`",
"`",
",",
"code",
")",
";",
"return",
"code",
";",
"}"
] | Returns a random code
@param {Number} [length]
An optional custon code length (defaults to 6)
@return {Promise<String>}
A promise of the generated code
@example
console.log([
codeGenerator(),
codeGenerator(),
codeGenerator(),
]);
// Prints: ABCDEF,GHJKMN,PRSTUV | [
"Returns",
"a",
"random",
"code"
] | 09df32597fe798777abec0ef1f3a994e91046085 | https://github.com/nfroidure/common-services/blob/09df32597fe798777abec0ef1f3a994e91046085/src/codeGenerator.js#L62-L69 |
50,180 | gethuman/pancakes-mongo | lib/pancakes.mongo.adapter.js | getModel | function getModel(resource) {
var name = resource.name;
// if not already in the model cache, get it
if (!cache.models[name]) {
var schema = new mongoose.Schema(resource.fields, { collection: name });
// loop through indexes and add them to the schema
_.each(resource.indexes, function (idx) {
schema.index(idx.fields, idx.options);
});
cache.models[name] = mongoose.model(name, schema);
}
return cache.models[name];
} | javascript | function getModel(resource) {
var name = resource.name;
// if not already in the model cache, get it
if (!cache.models[name]) {
var schema = new mongoose.Schema(resource.fields, { collection: name });
// loop through indexes and add them to the schema
_.each(resource.indexes, function (idx) {
schema.index(idx.fields, idx.options);
});
cache.models[name] = mongoose.model(name, schema);
}
return cache.models[name];
} | [
"function",
"getModel",
"(",
"resource",
")",
"{",
"var",
"name",
"=",
"resource",
".",
"name",
";",
"// if not already in the model cache, get it",
"if",
"(",
"!",
"cache",
".",
"models",
"[",
"name",
"]",
")",
"{",
"var",
"schema",
"=",
"new",
"mongoose",
".",
"Schema",
"(",
"resource",
".",
"fields",
",",
"{",
"collection",
":",
"name",
"}",
")",
";",
"// loop through indexes and add them to the schema",
"_",
".",
"each",
"(",
"resource",
".",
"indexes",
",",
"function",
"(",
"idx",
")",
"{",
"schema",
".",
"index",
"(",
"idx",
".",
"fields",
",",
"idx",
".",
"options",
")",
";",
"}",
")",
";",
"cache",
".",
"models",
"[",
"name",
"]",
"=",
"mongoose",
".",
"model",
"(",
"name",
",",
"schema",
")",
";",
"}",
"return",
"cache",
".",
"models",
"[",
"name",
"]",
";",
"}"
] | Create a mongoose model object from a set of fields, fieldsets and indexes
@param resource
@returns {Model} | [
"Create",
"a",
"mongoose",
"model",
"object",
"from",
"a",
"set",
"of",
"fields",
"fieldsets",
"and",
"indexes"
] | e10d2ca61643607008fdcb14b55d8a383284463b | https://github.com/gethuman/pancakes-mongo/blob/e10d2ca61643607008fdcb14b55d8a383284463b/lib/pancakes.mongo.adapter.js#L114-L130 |
50,181 | gethuman/pancakes-mongo | lib/pancakes.mongo.adapter.js | saveIndexInfo | function saveIndexInfo() {
// reset the cache
var tmpCache = cache.idxInfo;
cache.idxInfo = {};
var promises = [];
// add promise for each things being saved/updated
_.each(tmpCache, function (idxInfo, key) {
var where = { str: key };
var select = '_id count';
var promise = IdxInfoModel.findOne(where, select).exec()
.then(function (savedItem) {
if (savedItem) {
return IdxInfoModel.findOneAndUpdate(where, { $inc: { count: idxInfo.count }});
}
else {
var model = new IdxInfoModel(idxInfo);
var deferred = Q.defer();
model.save(function (modelErr) {
modelErr ? deferred.reject(modelErr) : deferred.resolve(model.toObject());
});
return deferred.promise;
}
});
promises.push(promise);
});
return Q.all(promises);
} | javascript | function saveIndexInfo() {
// reset the cache
var tmpCache = cache.idxInfo;
cache.idxInfo = {};
var promises = [];
// add promise for each things being saved/updated
_.each(tmpCache, function (idxInfo, key) {
var where = { str: key };
var select = '_id count';
var promise = IdxInfoModel.findOne(where, select).exec()
.then(function (savedItem) {
if (savedItem) {
return IdxInfoModel.findOneAndUpdate(where, { $inc: { count: idxInfo.count }});
}
else {
var model = new IdxInfoModel(idxInfo);
var deferred = Q.defer();
model.save(function (modelErr) {
modelErr ? deferred.reject(modelErr) : deferred.resolve(model.toObject());
});
return deferred.promise;
}
});
promises.push(promise);
});
return Q.all(promises);
} | [
"function",
"saveIndexInfo",
"(",
")",
"{",
"// reset the cache",
"var",
"tmpCache",
"=",
"cache",
".",
"idxInfo",
";",
"cache",
".",
"idxInfo",
"=",
"{",
"}",
";",
"var",
"promises",
"=",
"[",
"]",
";",
"// add promise for each things being saved/updated",
"_",
".",
"each",
"(",
"tmpCache",
",",
"function",
"(",
"idxInfo",
",",
"key",
")",
"{",
"var",
"where",
"=",
"{",
"str",
":",
"key",
"}",
";",
"var",
"select",
"=",
"'_id count'",
";",
"var",
"promise",
"=",
"IdxInfoModel",
".",
"findOne",
"(",
"where",
",",
"select",
")",
".",
"exec",
"(",
")",
".",
"then",
"(",
"function",
"(",
"savedItem",
")",
"{",
"if",
"(",
"savedItem",
")",
"{",
"return",
"IdxInfoModel",
".",
"findOneAndUpdate",
"(",
"where",
",",
"{",
"$inc",
":",
"{",
"count",
":",
"idxInfo",
".",
"count",
"}",
"}",
")",
";",
"}",
"else",
"{",
"var",
"model",
"=",
"new",
"IdxInfoModel",
"(",
"idxInfo",
")",
";",
"var",
"deferred",
"=",
"Q",
".",
"defer",
"(",
")",
";",
"model",
".",
"save",
"(",
"function",
"(",
"modelErr",
")",
"{",
"modelErr",
"?",
"deferred",
".",
"reject",
"(",
"modelErr",
")",
":",
"deferred",
".",
"resolve",
"(",
"model",
".",
"toObject",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"deferred",
".",
"promise",
";",
"}",
"}",
")",
";",
"promises",
".",
"push",
"(",
"promise",
")",
";",
"}",
")",
";",
"return",
"Q",
".",
"all",
"(",
"promises",
")",
";",
"}"
] | Save a query to the idxInfo table | [
"Save",
"a",
"query",
"to",
"the",
"idxInfo",
"table"
] | e10d2ca61643607008fdcb14b55d8a383284463b | https://github.com/gethuman/pancakes-mongo/blob/e10d2ca61643607008fdcb14b55d8a383284463b/lib/pancakes.mongo.adapter.js#L135-L167 |
50,182 | tomiberes/batoh | src/batoh.js | function(cb) {
var self = this;
var request;
try {
request = IndexedDB.open(self.setup.database, self.setup.version);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
self.idb = event.target.result;
if (isFunction(cb)) return cb(null);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
request.onblocked = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
request.onupgradeneeded = function(event) {
try {
var idb = event.target.result;
for (var storeName in self.setup.stores) {
var store = self.setup.stores[storeName];
var objectStore = idb.createObjectStore(storeName,
{ keyPath: store.keyPath, autoIncrement: store.autoIncrement });
for (var indexNo in store.indexes) {
var index = store.indexes[indexNo];
objectStore.createIndex(index.name, index.keyPath,
{ unique: index.unique, multiEntry: index.multiEntry });
}
}
} catch (err) {
if (isFunction(cb)) return cb(err);
}
};
} | javascript | function(cb) {
var self = this;
var request;
try {
request = IndexedDB.open(self.setup.database, self.setup.version);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
self.idb = event.target.result;
if (isFunction(cb)) return cb(null);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
request.onblocked = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
request.onupgradeneeded = function(event) {
try {
var idb = event.target.result;
for (var storeName in self.setup.stores) {
var store = self.setup.stores[storeName];
var objectStore = idb.createObjectStore(storeName,
{ keyPath: store.keyPath, autoIncrement: store.autoIncrement });
for (var indexNo in store.indexes) {
var index = store.indexes[indexNo];
objectStore.createIndex(index.name, index.keyPath,
{ unique: index.unique, multiEntry: index.multiEntry });
}
}
} catch (err) {
if (isFunction(cb)) return cb(err);
}
};
} | [
"function",
"(",
"cb",
")",
"{",
"var",
"self",
"=",
"this",
";",
"var",
"request",
";",
"try",
"{",
"request",
"=",
"IndexedDB",
".",
"open",
"(",
"self",
".",
"setup",
".",
"database",
",",
"self",
".",
"setup",
".",
"version",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"self",
".",
"idb",
"=",
"event",
".",
"target",
".",
"result",
";",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"null",
")",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"request",
".",
"onblocked",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"request",
".",
"onupgradeneeded",
"=",
"function",
"(",
"event",
")",
"{",
"try",
"{",
"var",
"idb",
"=",
"event",
".",
"target",
".",
"result",
";",
"for",
"(",
"var",
"storeName",
"in",
"self",
".",
"setup",
".",
"stores",
")",
"{",
"var",
"store",
"=",
"self",
".",
"setup",
".",
"stores",
"[",
"storeName",
"]",
";",
"var",
"objectStore",
"=",
"idb",
".",
"createObjectStore",
"(",
"storeName",
",",
"{",
"keyPath",
":",
"store",
".",
"keyPath",
",",
"autoIncrement",
":",
"store",
".",
"autoIncrement",
"}",
")",
";",
"for",
"(",
"var",
"indexNo",
"in",
"store",
".",
"indexes",
")",
"{",
"var",
"index",
"=",
"store",
".",
"indexes",
"[",
"indexNo",
"]",
";",
"objectStore",
".",
"createIndex",
"(",
"index",
".",
"name",
",",
"index",
".",
"keyPath",
",",
"{",
"unique",
":",
"index",
".",
"unique",
",",
"multiEntry",
":",
"index",
".",
"multiEntry",
"}",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"}",
";",
"}"
] | Open or create the database using the `setup` passed to the constructor.
@param {Function} callback - gets one argument `(err)`,
if there is no error `err` is null. | [
"Open",
"or",
"create",
"the",
"database",
"using",
"the",
"setup",
"passed",
"to",
"the",
"constructor",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L66-L101 |
|
50,183 | tomiberes/batoh | src/batoh.js | function(cb) {
if (IndexedDB.deleteDatabase) {
var request = IndexedDB.deleteDatabase(this.setup.database);
// It's always in an order of onblocked -> onsuccess,
// ignoring other handlers, for now.
request.onsuccess = function(event) {
if (isFunction(cb)) return cb(null, event.target.result);
};
request.onerror = function(event) {
};
request.onblocked = function(event) {
};
request.onversionchange = function(event) {
};
}
} | javascript | function(cb) {
if (IndexedDB.deleteDatabase) {
var request = IndexedDB.deleteDatabase(this.setup.database);
// It's always in an order of onblocked -> onsuccess,
// ignoring other handlers, for now.
request.onsuccess = function(event) {
if (isFunction(cb)) return cb(null, event.target.result);
};
request.onerror = function(event) {
};
request.onblocked = function(event) {
};
request.onversionchange = function(event) {
};
}
} | [
"function",
"(",
"cb",
")",
"{",
"if",
"(",
"IndexedDB",
".",
"deleteDatabase",
")",
"{",
"var",
"request",
"=",
"IndexedDB",
".",
"deleteDatabase",
"(",
"this",
".",
"setup",
".",
"database",
")",
";",
"// It's always in an order of onblocked -> onsuccess,",
"// ignoring other handlers, for now.",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"null",
",",
"event",
".",
"target",
".",
"result",
")",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"}",
";",
"request",
".",
"onblocked",
"=",
"function",
"(",
"event",
")",
"{",
"}",
";",
"request",
".",
"onversionchange",
"=",
"function",
"(",
"event",
")",
"{",
"}",
";",
"}",
"}"
] | If deleting database is provided by implementation,
delete the database used with current setup.
@param {Function} callback - gets one argument `(err)`,
if there is no error `err` is null.
TODO: correct success, blocked, versionchange handling,
current spec is unclear and outcome is not usable,
thus using only the `onsuccess` handler. | [
"If",
"deleting",
"database",
"is",
"provided",
"by",
"implementation",
"delete",
"the",
"database",
"used",
"with",
"current",
"setup",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L125-L140 |
|
50,184 | tomiberes/batoh | src/batoh.js | function(storeNames, mode, result, cb) {
var transaction;
try {
transaction = this.idb.transaction(storeNames, mode);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
transaction.onabort = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
transaction.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
transaction.oncomplete = function(event) {
if (isFunction(cb)) return cb(null, result);
};
return transaction;
} | javascript | function(storeNames, mode, result, cb) {
var transaction;
try {
transaction = this.idb.transaction(storeNames, mode);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
transaction.onabort = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
transaction.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
transaction.oncomplete = function(event) {
if (isFunction(cb)) return cb(null, result);
};
return transaction;
} | [
"function",
"(",
"storeNames",
",",
"mode",
",",
"result",
",",
"cb",
")",
"{",
"var",
"transaction",
";",
"try",
"{",
"transaction",
"=",
"this",
".",
"idb",
".",
"transaction",
"(",
"storeNames",
",",
"mode",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"transaction",
".",
"onabort",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"transaction",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"transaction",
".",
"oncomplete",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"null",
",",
"result",
")",
";",
"}",
";",
"return",
"transaction",
";",
"}"
] | Wrap IDBDatabase.transaction
@param {String} storeNames - names of the object stores to use.
@param {String} mode - transaction mode to use.
@param {Function} callback - gets two arguments `(err, result)`,
if there is no Error `err` is `null`.
@param {Object} result - Object that will be returned as a result of
the transaction. | [
"Wrap",
"IDBDatabase",
".",
"transaction"
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L152-L169 |
|
50,185 | tomiberes/batoh | src/batoh.js | function(storeName, transaction, cb) {
try {
return transaction.objectStore(storeName);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
} | javascript | function(storeName, transaction, cb) {
try {
return transaction.objectStore(storeName);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
} | [
"function",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
"{",
"try",
"{",
"return",
"transaction",
".",
"objectStore",
"(",
"storeName",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"}"
] | Wrap IDBTransation.objectStore
@param {String} storeName - name of the object store to use.
@param {IDBTransaction} transaction - to use.
@param {Function} callback - gets one argument `(err)`,
if there is no error, it won't be called. | [
"Wrap",
"IDBTransation",
".",
"objectStore"
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L179-L185 |
|
50,186 | tomiberes/batoh | src/batoh.js | function(storeName, value, key, cb) {
// For usage of out-of-line keys a `key` argument have to be specified,
// otherwise the `request` will be made assuming in-line key or key generator.
// For detailed possibilities see what you can't do in `DataError` section here:
// `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions`
var data = {};
if (arguments.length === 4) {
if (!Array.isArray(key)) {
data.key = [key];
} else {
data.key = key;
}
}
if (arguments.length === 3) {
cb = key;
key = null;
}
if (!Array.isArray(value)) {
data.value = [value];
} else {
data.value = value;
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var _add = function(value, key) {
var request;
try {
request = store.add(value, key);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result.push(event.target.result);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
};
for (var i = 0, l = data.value.length; i < l ; i++) {
// In-line key
if (!data.key) {
_add(data.value[i]);
// Out-of-line key
} else {
_add(data.value[i], data.key[i]);
}
}
} | javascript | function(storeName, value, key, cb) {
// For usage of out-of-line keys a `key` argument have to be specified,
// otherwise the `request` will be made assuming in-line key or key generator.
// For detailed possibilities see what you can't do in `DataError` section here:
// `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions`
var data = {};
if (arguments.length === 4) {
if (!Array.isArray(key)) {
data.key = [key];
} else {
data.key = key;
}
}
if (arguments.length === 3) {
cb = key;
key = null;
}
if (!Array.isArray(value)) {
data.value = [value];
} else {
data.value = value;
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var _add = function(value, key) {
var request;
try {
request = store.add(value, key);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result.push(event.target.result);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
};
for (var i = 0, l = data.value.length; i < l ; i++) {
// In-line key
if (!data.key) {
_add(data.value[i]);
// Out-of-line key
} else {
_add(data.value[i], data.key[i]);
}
}
} | [
"function",
"(",
"storeName",
",",
"value",
",",
"key",
",",
"cb",
")",
"{",
"// For usage of out-of-line keys a `key` argument have to be specified,",
"// otherwise the `request` will be made assuming in-line key or key generator.",
"// For detailed possibilities see what you can't do in `DataError` section here:",
"// `https://developer.mozilla.org/en-US/docs/Web/API/IDBObjectStore.add#Exceptions`",
"var",
"data",
"=",
"{",
"}",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"4",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"data",
".",
"key",
"=",
"[",
"key",
"]",
";",
"}",
"else",
"{",
"data",
".",
"key",
"=",
"key",
";",
"}",
"}",
"if",
"(",
"arguments",
".",
"length",
"===",
"3",
")",
"{",
"cb",
"=",
"key",
";",
"key",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"data",
".",
"value",
"=",
"[",
"value",
"]",
";",
"}",
"else",
"{",
"data",
".",
"value",
"=",
"value",
";",
"}",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"transaction",
"=",
"this",
".",
"transaction",
"(",
"storeName",
",",
"MODE",
".",
"READ_WRITE",
",",
"result",
",",
"cb",
")",
";",
"var",
"store",
"=",
"this",
".",
"store",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
";",
"var",
"_add",
"=",
"function",
"(",
"value",
",",
"key",
")",
"{",
"var",
"request",
";",
"try",
"{",
"request",
"=",
"store",
".",
"add",
"(",
"value",
",",
"key",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"result",
".",
"push",
"(",
"event",
".",
"target",
".",
"result",
")",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"data",
".",
"value",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"// In-line key",
"if",
"(",
"!",
"data",
".",
"key",
")",
"{",
"_add",
"(",
"data",
".",
"value",
"[",
"i",
"]",
")",
";",
"// Out-of-line key",
"}",
"else",
"{",
"_add",
"(",
"data",
".",
"value",
"[",
"i",
"]",
",",
"data",
".",
"key",
"[",
"i",
"]",
")",
";",
"}",
"}",
"}"
] | Add one or more records. If record already exist in object store,
returns an Error.
@param {String} storeName - name of the object store to use.
@param {Object|Object[]} value - Object or Array of objects to store.
@param {String|String[]} [key] - String or an Array of strings,
as a keys for the values.
If an Array is passed indexes have to be corresponding to the
indexes in values Array.
@param {Function} callback - gets two arguments `(err, result)`,
if there is no Error `err` is `null`. `result` is always an Array of keys
for the values added. | [
"Add",
"one",
"or",
"more",
"records",
".",
"If",
"record",
"already",
"exist",
"in",
"object",
"store",
"returns",
"an",
"Error",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L201-L250 |
|
50,187 | tomiberes/batoh | src/batoh.js | function(storeName, key, cb) {
if (!Array.isArray(key)) {
key = [key];
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var _del = function(key) {
var request;
try {
request = store.delete(key);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result.push(event.target.result);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
};
for (var i = 0, l = key.length; i < l; i++) {
_del(key[i]);
}
} | javascript | function(storeName, key, cb) {
if (!Array.isArray(key)) {
key = [key];
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var _del = function(key) {
var request;
try {
request = store.delete(key);
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result.push(event.target.result);
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
};
for (var i = 0, l = key.length; i < l; i++) {
_del(key[i]);
}
} | [
"function",
"(",
"storeName",
",",
"key",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"key",
")",
")",
"{",
"key",
"=",
"[",
"key",
"]",
";",
"}",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"transaction",
"=",
"this",
".",
"transaction",
"(",
"storeName",
",",
"MODE",
".",
"READ_WRITE",
",",
"result",
",",
"cb",
")",
";",
"var",
"store",
"=",
"this",
".",
"store",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
";",
"var",
"_del",
"=",
"function",
"(",
"key",
")",
"{",
"var",
"request",
";",
"try",
"{",
"request",
"=",
"store",
".",
"delete",
"(",
"key",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"result",
".",
"push",
"(",
"event",
".",
"target",
".",
"result",
")",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"}",
";",
"for",
"(",
"var",
"i",
"=",
"0",
",",
"l",
"=",
"key",
".",
"length",
";",
"i",
"<",
"l",
";",
"i",
"++",
")",
"{",
"_del",
"(",
"key",
"[",
"i",
"]",
")",
";",
"}",
"}"
] | Delete one or more records specified by the key.
@param {String} storeName - name of the object store to use
@param {String} key - key that identifies the record to be deleted.
@param {Function} callback - gets two arguments `(err, result)`,
if there is no Error `err` is `null`. `result` is always an Array of the
results of delete operations (undefined). | [
"Delete",
"one",
"or",
"more",
"records",
"specified",
"by",
"the",
"key",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L360-L385 |
|
50,188 | tomiberes/batoh | src/batoh.js | function(storeName, query, each, cb) {
if (arguments.length === 3) {
cb = each;
each = null;
}
if (arguments.length === 2) {
cb = query;
query = null;
each = null;
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_ONLY, result, cb);
var store = this.store(storeName, transaction, cb);
var target = store;
var request;
try {
// Change the target of the cursor, if defined
if (query !== null && query.index) {
target = store.index(query.index);
}
// Set a limit, if defined
if (query !== null && query.limit) {
var limit = query.limit;
}
if (query === null) {
// Retrieve all records from object store
request = target.openCursor();
} else {
request = target.openCursor(query.range, query.direction);
}
} catch(err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
// Execute specified operation on each value
if (isFunction(each)) {
result.push(each(cursor.value));
// Gather all results according to query
} else {
result.push(cursor.value);
}
// Limit the number of results
if (limit) {
limit--;
if (limit === 0) {
return;
}
}
try {
cursor.continue();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
} else {
// No more matching records
}
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | javascript | function(storeName, query, each, cb) {
if (arguments.length === 3) {
cb = each;
each = null;
}
if (arguments.length === 2) {
cb = query;
query = null;
each = null;
}
var result = [];
var transaction = this.transaction(storeName, MODE.READ_ONLY, result, cb);
var store = this.store(storeName, transaction, cb);
var target = store;
var request;
try {
// Change the target of the cursor, if defined
if (query !== null && query.index) {
target = store.index(query.index);
}
// Set a limit, if defined
if (query !== null && query.limit) {
var limit = query.limit;
}
if (query === null) {
// Retrieve all records from object store
request = target.openCursor();
} else {
request = target.openCursor(query.range, query.direction);
}
} catch(err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
var cursor = event.target.result;
if (cursor) {
// Execute specified operation on each value
if (isFunction(each)) {
result.push(each(cursor.value));
// Gather all results according to query
} else {
result.push(cursor.value);
}
// Limit the number of results
if (limit) {
limit--;
if (limit === 0) {
return;
}
}
try {
cursor.continue();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
} else {
// No more matching records
}
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | [
"function",
"(",
"storeName",
",",
"query",
",",
"each",
",",
"cb",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"===",
"3",
")",
"{",
"cb",
"=",
"each",
";",
"each",
"=",
"null",
";",
"}",
"if",
"(",
"arguments",
".",
"length",
"===",
"2",
")",
"{",
"cb",
"=",
"query",
";",
"query",
"=",
"null",
";",
"each",
"=",
"null",
";",
"}",
"var",
"result",
"=",
"[",
"]",
";",
"var",
"transaction",
"=",
"this",
".",
"transaction",
"(",
"storeName",
",",
"MODE",
".",
"READ_ONLY",
",",
"result",
",",
"cb",
")",
";",
"var",
"store",
"=",
"this",
".",
"store",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
";",
"var",
"target",
"=",
"store",
";",
"var",
"request",
";",
"try",
"{",
"// Change the target of the cursor, if defined",
"if",
"(",
"query",
"!==",
"null",
"&&",
"query",
".",
"index",
")",
"{",
"target",
"=",
"store",
".",
"index",
"(",
"query",
".",
"index",
")",
";",
"}",
"// Set a limit, if defined",
"if",
"(",
"query",
"!==",
"null",
"&&",
"query",
".",
"limit",
")",
"{",
"var",
"limit",
"=",
"query",
".",
"limit",
";",
"}",
"if",
"(",
"query",
"===",
"null",
")",
"{",
"// Retrieve all records from object store",
"request",
"=",
"target",
".",
"openCursor",
"(",
")",
";",
"}",
"else",
"{",
"request",
"=",
"target",
".",
"openCursor",
"(",
"query",
".",
"range",
",",
"query",
".",
"direction",
")",
";",
"}",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"var",
"cursor",
"=",
"event",
".",
"target",
".",
"result",
";",
"if",
"(",
"cursor",
")",
"{",
"// Execute specified operation on each value",
"if",
"(",
"isFunction",
"(",
"each",
")",
")",
"{",
"result",
".",
"push",
"(",
"each",
"(",
"cursor",
".",
"value",
")",
")",
";",
"// Gather all results according to query",
"}",
"else",
"{",
"result",
".",
"push",
"(",
"cursor",
".",
"value",
")",
";",
"}",
"// Limit the number of results",
"if",
"(",
"limit",
")",
"{",
"limit",
"--",
";",
"if",
"(",
"limit",
"===",
"0",
")",
"{",
"return",
";",
"}",
"}",
"try",
"{",
"cursor",
".",
"continue",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"}",
"else",
"{",
"// No more matching records",
"}",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"}"
] | Open cursor and query the object store.
@param {string} storeName - name of the object store to use
@param {Object} query - configuration Object defining the query
@param {String} [query.index] - index to use, if omitted cursor is
opened on the keyPath of the store
@param {Object} [query.range] - IDBKeyRange object defining the range
@param {String} [query.direction] - direction to move the cursor,
`next`, `prev`, `nextunique`, `prevunique`
@param {Number} [query.limit] - number of records to retrieve
@param {Boolean} [query.unique] - TODO?
@param {Boolean} [query.multiEntry] - TODO?
@param {Function} [each] - operation to be called on each cursor value
@param {Function} callback - gets two arguments `(err, result)`,
if there is no Error `err` is `null`. `result` is an Array of records,
returned by the query. | [
"Open",
"cursor",
"and",
"query",
"the",
"object",
"store",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L405-L468 |
|
50,189 | tomiberes/batoh | src/batoh.js | function(storeName, cb) {
var result;
var transaction = this.transaction(storeName, MODE.READ_ONLY, result, cb);
var store = this.store(storeName, transaction, cb);
var request;
try {
request = store.count();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result = event.target.result;
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | javascript | function(storeName, cb) {
var result;
var transaction = this.transaction(storeName, MODE.READ_ONLY, result, cb);
var store = this.store(storeName, transaction, cb);
var request;
try {
request = store.count();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result = event.target.result;
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | [
"function",
"(",
"storeName",
",",
"cb",
")",
"{",
"var",
"result",
";",
"var",
"transaction",
"=",
"this",
".",
"transaction",
"(",
"storeName",
",",
"MODE",
".",
"READ_ONLY",
",",
"result",
",",
"cb",
")",
";",
"var",
"store",
"=",
"this",
".",
"store",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
";",
"var",
"request",
";",
"try",
"{",
"request",
"=",
"store",
".",
"count",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"result",
"=",
"event",
".",
"target",
".",
"result",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"}"
] | Count the objects in the store.
@param {String} storeName - name of the object store to count.
@param {Function} callback - gets one argument `(err)`,
if there is no error `err` is null. | [
"Count",
"the",
"objects",
"in",
"the",
"store",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L477-L493 |
|
50,190 | tomiberes/batoh | src/batoh.js | function(storeName, cb) {
var result;
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var request;
try {
request = store.clear();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result = event.target.result;
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | javascript | function(storeName, cb) {
var result;
var transaction = this.transaction(storeName, MODE.READ_WRITE, result, cb);
var store = this.store(storeName, transaction, cb);
var request;
try {
request = store.clear();
} catch (err) {
if (isFunction(cb)) return cb(err);
}
request.onsuccess = function(event) {
result = event.target.result;
};
request.onerror = function(event) {
if (isFunction(cb)) return cb(event.target.error);
};
} | [
"function",
"(",
"storeName",
",",
"cb",
")",
"{",
"var",
"result",
";",
"var",
"transaction",
"=",
"this",
".",
"transaction",
"(",
"storeName",
",",
"MODE",
".",
"READ_WRITE",
",",
"result",
",",
"cb",
")",
";",
"var",
"store",
"=",
"this",
".",
"store",
"(",
"storeName",
",",
"transaction",
",",
"cb",
")",
";",
"var",
"request",
";",
"try",
"{",
"request",
"=",
"store",
".",
"clear",
"(",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"request",
".",
"onsuccess",
"=",
"function",
"(",
"event",
")",
"{",
"result",
"=",
"event",
".",
"target",
".",
"result",
";",
"}",
";",
"request",
".",
"onerror",
"=",
"function",
"(",
"event",
")",
"{",
"if",
"(",
"isFunction",
"(",
"cb",
")",
")",
"return",
"cb",
"(",
"event",
".",
"target",
".",
"error",
")",
";",
"}",
";",
"}"
] | Clear the object store of all records.
@param {String} storeName - name of the object store to clear
@param {Function} callback - gets one argument `(err)`,
if there is no error `err` is null. | [
"Clear",
"the",
"object",
"store",
"of",
"all",
"records",
"."
] | 2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d | https://github.com/tomiberes/batoh/blob/2bc5d0bb5d5fa8d7fdb6998298ca51c50e4ee54d/src/batoh.js#L502-L518 |
|
50,191 | gardr/validator | lib/rule/validate/codeUsage.js | validate | function validate(harvested, report, next, options) {
report.setChecklist('CodeUsage', 'Static code analysis');
var illegalIdentifiers = ['geolocation'];
function analyze(content, sourceURL, origin) {
var ast;
var trace = {
'trace': {
'sourceURL': sourceURL
}
};
try {
ast = esprima.parse(content.toString(), {
'loc': true,
'tolerant': true
});
} catch (e) {
report.error('Possible javascript malformed / SyntaxError in content from ' + origin, {
trace: [
{
'line': e.lineNumber,
'column': e.column,
'index': e.index,
'sourceURL': sourceURL
}
]
});
return;
}
estraverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'Identifier' && parent.type === 'MemberExpression' && illegalIdentifiers.indexOf(node.name) > -1) {
report.error('Please do not "use" the geolocation api', trace);
} else if (node.type === 'Literal' && illegalIdentifiers.indexOf(node.value) > -1) {
report.error('Please do not "use" the geolocation api', trace);
}
}
});
}
if (harvested.script.tags) {
harvested.script.tags.forEach(function (tag) {
analyze(tag, options.scriptUrl, 'tag');
});
}
if (harvested.script.attributes) {
harvested.script.attributes.forEach(function (data) {
data.matches.forEach(function (match) {
analyze(match.value, '(' + data.tag + ') ' + match.key + '-attribute', 'attribute');
});
});
}
if (harvested.har.rawFileData) {
Object.keys(harvested.har.rawFileData).forEach(function (key) {
var v = harvested.har.rawFileData[key];
if (v && !v.requestError && v.contentType && v.contentType.indexOf('javascript') > -1 && v.base64Content) {
analyze(new Buffer(v.base64Content, 'base64').toString('utf8'), v.url, 'file');
}
});
}
report.exitChecklist();
next();
} | javascript | function validate(harvested, report, next, options) {
report.setChecklist('CodeUsage', 'Static code analysis');
var illegalIdentifiers = ['geolocation'];
function analyze(content, sourceURL, origin) {
var ast;
var trace = {
'trace': {
'sourceURL': sourceURL
}
};
try {
ast = esprima.parse(content.toString(), {
'loc': true,
'tolerant': true
});
} catch (e) {
report.error('Possible javascript malformed / SyntaxError in content from ' + origin, {
trace: [
{
'line': e.lineNumber,
'column': e.column,
'index': e.index,
'sourceURL': sourceURL
}
]
});
return;
}
estraverse.traverse(ast, {
enter: function (node, parent) {
if (node.type === 'Identifier' && parent.type === 'MemberExpression' && illegalIdentifiers.indexOf(node.name) > -1) {
report.error('Please do not "use" the geolocation api', trace);
} else if (node.type === 'Literal' && illegalIdentifiers.indexOf(node.value) > -1) {
report.error('Please do not "use" the geolocation api', trace);
}
}
});
}
if (harvested.script.tags) {
harvested.script.tags.forEach(function (tag) {
analyze(tag, options.scriptUrl, 'tag');
});
}
if (harvested.script.attributes) {
harvested.script.attributes.forEach(function (data) {
data.matches.forEach(function (match) {
analyze(match.value, '(' + data.tag + ') ' + match.key + '-attribute', 'attribute');
});
});
}
if (harvested.har.rawFileData) {
Object.keys(harvested.har.rawFileData).forEach(function (key) {
var v = harvested.har.rawFileData[key];
if (v && !v.requestError && v.contentType && v.contentType.indexOf('javascript') > -1 && v.base64Content) {
analyze(new Buffer(v.base64Content, 'base64').toString('utf8'), v.url, 'file');
}
});
}
report.exitChecklist();
next();
} | [
"function",
"validate",
"(",
"harvested",
",",
"report",
",",
"next",
",",
"options",
")",
"{",
"report",
".",
"setChecklist",
"(",
"'CodeUsage'",
",",
"'Static code analysis'",
")",
";",
"var",
"illegalIdentifiers",
"=",
"[",
"'geolocation'",
"]",
";",
"function",
"analyze",
"(",
"content",
",",
"sourceURL",
",",
"origin",
")",
"{",
"var",
"ast",
";",
"var",
"trace",
"=",
"{",
"'trace'",
":",
"{",
"'sourceURL'",
":",
"sourceURL",
"}",
"}",
";",
"try",
"{",
"ast",
"=",
"esprima",
".",
"parse",
"(",
"content",
".",
"toString",
"(",
")",
",",
"{",
"'loc'",
":",
"true",
",",
"'tolerant'",
":",
"true",
"}",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"report",
".",
"error",
"(",
"'Possible javascript malformed / SyntaxError in content from '",
"+",
"origin",
",",
"{",
"trace",
":",
"[",
"{",
"'line'",
":",
"e",
".",
"lineNumber",
",",
"'column'",
":",
"e",
".",
"column",
",",
"'index'",
":",
"e",
".",
"index",
",",
"'sourceURL'",
":",
"sourceURL",
"}",
"]",
"}",
")",
";",
"return",
";",
"}",
"estraverse",
".",
"traverse",
"(",
"ast",
",",
"{",
"enter",
":",
"function",
"(",
"node",
",",
"parent",
")",
"{",
"if",
"(",
"node",
".",
"type",
"===",
"'Identifier'",
"&&",
"parent",
".",
"type",
"===",
"'MemberExpression'",
"&&",
"illegalIdentifiers",
".",
"indexOf",
"(",
"node",
".",
"name",
")",
">",
"-",
"1",
")",
"{",
"report",
".",
"error",
"(",
"'Please do not \"use\" the geolocation api'",
",",
"trace",
")",
";",
"}",
"else",
"if",
"(",
"node",
".",
"type",
"===",
"'Literal'",
"&&",
"illegalIdentifiers",
".",
"indexOf",
"(",
"node",
".",
"value",
")",
">",
"-",
"1",
")",
"{",
"report",
".",
"error",
"(",
"'Please do not \"use\" the geolocation api'",
",",
"trace",
")",
";",
"}",
"}",
"}",
")",
";",
"}",
"if",
"(",
"harvested",
".",
"script",
".",
"tags",
")",
"{",
"harvested",
".",
"script",
".",
"tags",
".",
"forEach",
"(",
"function",
"(",
"tag",
")",
"{",
"analyze",
"(",
"tag",
",",
"options",
".",
"scriptUrl",
",",
"'tag'",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"harvested",
".",
"script",
".",
"attributes",
")",
"{",
"harvested",
".",
"script",
".",
"attributes",
".",
"forEach",
"(",
"function",
"(",
"data",
")",
"{",
"data",
".",
"matches",
".",
"forEach",
"(",
"function",
"(",
"match",
")",
"{",
"analyze",
"(",
"match",
".",
"value",
",",
"'('",
"+",
"data",
".",
"tag",
"+",
"') '",
"+",
"match",
".",
"key",
"+",
"'-attribute'",
",",
"'attribute'",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"if",
"(",
"harvested",
".",
"har",
".",
"rawFileData",
")",
"{",
"Object",
".",
"keys",
"(",
"harvested",
".",
"har",
".",
"rawFileData",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"var",
"v",
"=",
"harvested",
".",
"har",
".",
"rawFileData",
"[",
"key",
"]",
";",
"if",
"(",
"v",
"&&",
"!",
"v",
".",
"requestError",
"&&",
"v",
".",
"contentType",
"&&",
"v",
".",
"contentType",
".",
"indexOf",
"(",
"'javascript'",
")",
">",
"-",
"1",
"&&",
"v",
".",
"base64Content",
")",
"{",
"analyze",
"(",
"new",
"Buffer",
"(",
"v",
".",
"base64Content",
",",
"'base64'",
")",
".",
"toString",
"(",
"'utf8'",
")",
",",
"v",
".",
"url",
",",
"'file'",
")",
";",
"}",
"}",
")",
";",
"}",
"report",
".",
"exitChecklist",
"(",
")",
";",
"next",
"(",
")",
";",
"}"
] | navigator.geolocation | [
"navigator",
".",
"geolocation"
] | 8ff6acc9e312d3a33f35422110397cd83b035036 | https://github.com/gardr/validator/blob/8ff6acc9e312d3a33f35422110397cd83b035036/lib/rule/validate/codeUsage.js#L5-L75 |
50,192 | inception-soa/inception.primitives | lib/error.js | PrimitiveError | function PrimitiveError(code, metadata, cause) {
if (code === undefined || code === null) {
throw new TypeError('`code` is a required argument!');
}
PrimitiveError.super_.call(this, this.constructor.ERRORS[code]);
if (metadata instanceof Error) {
cause = metadata;
metadata = undefined;
}
/**
* Backing field to store an object's state
*
* @type {Object}
* @private
*/
this._properties = {
code: code,
metadata: metadata,
cause: cause
};
} | javascript | function PrimitiveError(code, metadata, cause) {
if (code === undefined || code === null) {
throw new TypeError('`code` is a required argument!');
}
PrimitiveError.super_.call(this, this.constructor.ERRORS[code]);
if (metadata instanceof Error) {
cause = metadata;
metadata = undefined;
}
/**
* Backing field to store an object's state
*
* @type {Object}
* @private
*/
this._properties = {
code: code,
metadata: metadata,
cause: cause
};
} | [
"function",
"PrimitiveError",
"(",
"code",
",",
"metadata",
",",
"cause",
")",
"{",
"if",
"(",
"code",
"===",
"undefined",
"||",
"code",
"===",
"null",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"'`code` is a required argument!'",
")",
";",
"}",
"PrimitiveError",
".",
"super_",
".",
"call",
"(",
"this",
",",
"this",
".",
"constructor",
".",
"ERRORS",
"[",
"code",
"]",
")",
";",
"if",
"(",
"metadata",
"instanceof",
"Error",
")",
"{",
"cause",
"=",
"metadata",
";",
"metadata",
"=",
"undefined",
";",
"}",
"/**\n * Backing field to store an object's state\n *\n * @type {Object}\n * @private\n */",
"this",
".",
"_properties",
"=",
"{",
"code",
":",
"code",
",",
"metadata",
":",
"metadata",
",",
"cause",
":",
"cause",
"}",
";",
"}"
] | A base class for all errors
This class inherits from the JavaScript Error class, and then parasitically
inherits from PrimitiveObject. Multiple inheritance isn't pretty!
@param {String} code A unique code identifying the error
@param {Object} [metadata] Metadata related to the error
@param {Error} [cause] The original error, if any, to be wrapped | [
"A",
"base",
"class",
"for",
"all",
"errors"
] | fc9fa777248050eefe3e62f73b9f15494bdc0bbc | https://github.com/inception-soa/inception.primitives/blob/fc9fa777248050eefe3e62f73b9f15494bdc0bbc/lib/error.js#L41-L64 |
50,193 | redisjs/jsr-server | lib/client.js | Client | function Client(socket) {
// flag whether an external or internal client socket
this._tcp = (socket instanceof Socket);
// index into the connections array
this._index = -1;
// file descriptor
this._fd = socket._handle.fd;
// remote ip address
this._remoteAddress = socket.remoteAddress;
// remote port
this._remotePort = socket.remotePort;
// full remote address
this._addr =
(this._remoteAddress && this._remotePort)
? this._remoteAddress + ':' + this._remotePort : null;
// connection id (2^53)
this._id = ++id;
// connection name used by setname/getname
this._name = null;
// flag used to mark clients as authenticated
this._authenticated = false;
// current db for this connection
this.db = 0;
// transaction reference for multi blocks
this._transaction = null;
// map of keys being watched by this connection
this._watched = {};
// monitor slave mode
this._monitor = false;
// the timestamp (ms) when this connection was established
this._connected = Date.now();
// last command played
this._cmd = null;
// buffer for queries
this._qbuf = new Buffer(0);
// time when the last command was received, used
// to get idle time
this._last = Date.now();
// encapsulates pubsub state for this client
this._pubsub = null;
} | javascript | function Client(socket) {
// flag whether an external or internal client socket
this._tcp = (socket instanceof Socket);
// index into the connections array
this._index = -1;
// file descriptor
this._fd = socket._handle.fd;
// remote ip address
this._remoteAddress = socket.remoteAddress;
// remote port
this._remotePort = socket.remotePort;
// full remote address
this._addr =
(this._remoteAddress && this._remotePort)
? this._remoteAddress + ':' + this._remotePort : null;
// connection id (2^53)
this._id = ++id;
// connection name used by setname/getname
this._name = null;
// flag used to mark clients as authenticated
this._authenticated = false;
// current db for this connection
this.db = 0;
// transaction reference for multi blocks
this._transaction = null;
// map of keys being watched by this connection
this._watched = {};
// monitor slave mode
this._monitor = false;
// the timestamp (ms) when this connection was established
this._connected = Date.now();
// last command played
this._cmd = null;
// buffer for queries
this._qbuf = new Buffer(0);
// time when the last command was received, used
// to get idle time
this._last = Date.now();
// encapsulates pubsub state for this client
this._pubsub = null;
} | [
"function",
"Client",
"(",
"socket",
")",
"{",
"// flag whether an external or internal client socket",
"this",
".",
"_tcp",
"=",
"(",
"socket",
"instanceof",
"Socket",
")",
";",
"// index into the connections array",
"this",
".",
"_index",
"=",
"-",
"1",
";",
"// file descriptor",
"this",
".",
"_fd",
"=",
"socket",
".",
"_handle",
".",
"fd",
";",
"// remote ip address",
"this",
".",
"_remoteAddress",
"=",
"socket",
".",
"remoteAddress",
";",
"// remote port",
"this",
".",
"_remotePort",
"=",
"socket",
".",
"remotePort",
";",
"// full remote address",
"this",
".",
"_addr",
"=",
"(",
"this",
".",
"_remoteAddress",
"&&",
"this",
".",
"_remotePort",
")",
"?",
"this",
".",
"_remoteAddress",
"+",
"':'",
"+",
"this",
".",
"_remotePort",
":",
"null",
";",
"// connection id (2^53)",
"this",
".",
"_id",
"=",
"++",
"id",
";",
"// connection name used by setname/getname",
"this",
".",
"_name",
"=",
"null",
";",
"// flag used to mark clients as authenticated",
"this",
".",
"_authenticated",
"=",
"false",
";",
"// current db for this connection",
"this",
".",
"db",
"=",
"0",
";",
"// transaction reference for multi blocks",
"this",
".",
"_transaction",
"=",
"null",
";",
"// map of keys being watched by this connection",
"this",
".",
"_watched",
"=",
"{",
"}",
";",
"// monitor slave mode",
"this",
".",
"_monitor",
"=",
"false",
";",
"// the timestamp (ms) when this connection was established",
"this",
".",
"_connected",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// last command played",
"this",
".",
"_cmd",
"=",
"null",
";",
"// buffer for queries",
"this",
".",
"_qbuf",
"=",
"new",
"Buffer",
"(",
"0",
")",
";",
"// time when the last command was received, used",
"// to get idle time",
"this",
".",
"_last",
"=",
"Date",
".",
"now",
"(",
")",
";",
"// encapsulates pubsub state for this client",
"this",
".",
"_pubsub",
"=",
"null",
";",
"}"
] | Encapsulates client connection state. | [
"Encapsulates",
"client",
"connection",
"state",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/client.js#L25-L83 |
50,194 | redisjs/jsr-server | lib/client.js | getObject | function getObject() {
var o = {}
, i
, fields = arguments.length
? Array.prototype.slice.call(arguments, 0) : keys;
for(i = 0;i < fields.length;i++) {
o[fields[i]] = this[fields[i]];
}
return o;
} | javascript | function getObject() {
var o = {}
, i
, fields = arguments.length
? Array.prototype.slice.call(arguments, 0) : keys;
for(i = 0;i < fields.length;i++) {
o[fields[i]] = this[fields[i]];
}
return o;
} | [
"function",
"getObject",
"(",
")",
"{",
"var",
"o",
"=",
"{",
"}",
",",
"i",
",",
"fields",
"=",
"arguments",
".",
"length",
"?",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
":",
"keys",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"fields",
".",
"length",
";",
"i",
"++",
")",
"{",
"o",
"[",
"fields",
"[",
"i",
"]",
"]",
"=",
"this",
"[",
"fields",
"[",
"i",
"]",
"]",
";",
"}",
"return",
"o",
";",
"}"
] | Get an object of information about this client. | [
"Get",
"an",
"object",
"of",
"information",
"about",
"this",
"client",
"."
] | 49413052d3039524fbdd2ade0ef9bae26cb4d647 | https://github.com/redisjs/jsr-server/blob/49413052d3039524fbdd2ade0ef9bae26cb4d647/lib/client.js#L88-L97 |
50,195 | SebastianOsuna/configure.js | lib/configure.js | _configFilter | function _configFilter ( f ) {
var parts = f.split("."),
ext = parts[ parts.length - 1 ],
pre = parts[ parts.length - 2 ],
name = parts[ parts.length - 3];
return !!(ext === "dist" && pre === "json" &&
exports.__ignores.indexOf( name ) === -1 && exports.__ignores.indexOf( f ) === -1 );
} | javascript | function _configFilter ( f ) {
var parts = f.split("."),
ext = parts[ parts.length - 1 ],
pre = parts[ parts.length - 2 ],
name = parts[ parts.length - 3];
return !!(ext === "dist" && pre === "json" &&
exports.__ignores.indexOf( name ) === -1 && exports.__ignores.indexOf( f ) === -1 );
} | [
"function",
"_configFilter",
"(",
"f",
")",
"{",
"var",
"parts",
"=",
"f",
".",
"split",
"(",
"\".\"",
")",
",",
"ext",
"=",
"parts",
"[",
"parts",
".",
"length",
"-",
"1",
"]",
",",
"pre",
"=",
"parts",
"[",
"parts",
".",
"length",
"-",
"2",
"]",
",",
"name",
"=",
"parts",
"[",
"parts",
".",
"length",
"-",
"3",
"]",
";",
"return",
"!",
"!",
"(",
"ext",
"===",
"\"dist\"",
"&&",
"pre",
"===",
"\"json\"",
"&&",
"exports",
".",
"__ignores",
".",
"indexOf",
"(",
"name",
")",
"===",
"-",
"1",
"&&",
"exports",
".",
"__ignores",
".",
"indexOf",
"(",
"f",
")",
"===",
"-",
"1",
")",
";",
"}"
] | filename filter function | [
"filename",
"filter",
"function"
] | 39551c58d92a4ce065df25e6b9999b8495ca4833 | https://github.com/SebastianOsuna/configure.js/blob/39551c58d92a4ce065df25e6b9999b8495ca4833/lib/configure.js#L90-L98 |
50,196 | foru17/gulp-rev-custom-tag | tool.js | function (directory, filename) {
return Path.join(directory, filename).replace(/^[a-z]:\\/i, '/').replace(/\\/g, '/');
} | javascript | function (directory, filename) {
return Path.join(directory, filename).replace(/^[a-z]:\\/i, '/').replace(/\\/g, '/');
} | [
"function",
"(",
"directory",
",",
"filename",
")",
"{",
"return",
"Path",
".",
"join",
"(",
"directory",
",",
"filename",
")",
".",
"replace",
"(",
"/",
"^[a-z]:\\\\",
"/",
"i",
",",
"'/'",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"}"
] | Joins a directory and a filename, replaces Windows forward-slash with a backslash. | [
"Joins",
"a",
"directory",
"and",
"a",
"filename",
"replaces",
"Windows",
"forward",
"-",
"slash",
"with",
"a",
"backslash",
"."
] | 96ef47647629f49b15d3f8fca024fc567bcb358e | https://github.com/foru17/gulp-rev-custom-tag/blob/96ef47647629f49b15d3f8fca024fc567bcb358e/tool.js#L27-L31 |
|
50,197 | foru17/gulp-rev-custom-tag | tool.js | function (base, path, noStartingSlash) {
if (base === path) {
return '';
}
// Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base
base = base.replace(/^[a-z]:/i, '').replace(/\\/g, '/').replace(/\/$/g, '') + '/';
path = path.replace(/^[a-z]:/i, '').replace(/\\/g, '/');
// console.log(' ==== '+path);
// Only truncate paths that overap with the base
if (base === path.substr(0, base.length)) {
path = '/' + path.substr(base.length);
}
var modifyStartingSlash = noStartingSlash !== undefined;
if(modifyStartingSlash) {
if (path[0] === '/' && noStartingSlash) {
path = path.substr(1);
} else if (path[0] !== '/' && !noStartingSlash){
path = '/' + path;
}
}
return path;
} | javascript | function (base, path, noStartingSlash) {
if (base === path) {
return '';
}
// Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base
base = base.replace(/^[a-z]:/i, '').replace(/\\/g, '/').replace(/\/$/g, '') + '/';
path = path.replace(/^[a-z]:/i, '').replace(/\\/g, '/');
// console.log(' ==== '+path);
// Only truncate paths that overap with the base
if (base === path.substr(0, base.length)) {
path = '/' + path.substr(base.length);
}
var modifyStartingSlash = noStartingSlash !== undefined;
if(modifyStartingSlash) {
if (path[0] === '/' && noStartingSlash) {
path = path.substr(1);
} else if (path[0] !== '/' && !noStartingSlash){
path = '/' + path;
}
}
return path;
} | [
"function",
"(",
"base",
",",
"path",
",",
"noStartingSlash",
")",
"{",
"if",
"(",
"base",
"===",
"path",
")",
"{",
"return",
"''",
";",
"}",
"// Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base",
"base",
"=",
"base",
".",
"replace",
"(",
"/",
"^[a-z]:",
"/",
"i",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
".",
"replace",
"(",
"/",
"\\/$",
"/",
"g",
",",
"''",
")",
"+",
"'/'",
";",
"path",
"=",
"path",
".",
"replace",
"(",
"/",
"^[a-z]:",
"/",
"i",
",",
"''",
")",
".",
"replace",
"(",
"/",
"\\\\",
"/",
"g",
",",
"'/'",
")",
";",
"// console.log(' ==== '+path);",
"// Only truncate paths that overap with the base",
"if",
"(",
"base",
"===",
"path",
".",
"substr",
"(",
"0",
",",
"base",
".",
"length",
")",
")",
"{",
"path",
"=",
"'/'",
"+",
"path",
".",
"substr",
"(",
"base",
".",
"length",
")",
";",
"}",
"var",
"modifyStartingSlash",
"=",
"noStartingSlash",
"!==",
"undefined",
";",
"if",
"(",
"modifyStartingSlash",
")",
"{",
"if",
"(",
"path",
"[",
"0",
"]",
"===",
"'/'",
"&&",
"noStartingSlash",
")",
"{",
"path",
"=",
"path",
".",
"substr",
"(",
"1",
")",
";",
"}",
"else",
"if",
"(",
"path",
"[",
"0",
"]",
"!==",
"'/'",
"&&",
"!",
"noStartingSlash",
")",
"{",
"path",
"=",
"'/'",
"+",
"path",
";",
"}",
"}",
"return",
"path",
";",
"}"
] | Given a base path and resource path, will return resource path relative to the base.
Also replaces Windows forward-slash with a backslash. | [
"Given",
"a",
"base",
"path",
"and",
"resource",
"path",
"will",
"return",
"resource",
"path",
"relative",
"to",
"the",
"base",
".",
"Also",
"replaces",
"Windows",
"forward",
"-",
"slash",
"with",
"a",
"backslash",
"."
] | 96ef47647629f49b15d3f8fca024fc567bcb358e | https://github.com/foru17/gulp-rev-custom-tag/blob/96ef47647629f49b15d3f8fca024fc567bcb358e/tool.js#L37-L64 |
|
50,198 | ksmithut/logget | index.js | Log | function Log(namespace) {
// If it's called without new, still return a new instance.
if (!(this instanceof Log)) { return new Log(namespace); }
// Configure Log if it hasn't already
if (!logger) { Log.configure(); }
// This gets all of the log levels and applies them to this
Object.keys(logger.levels).forEach(function (level) {
if (!namespace) {
this[level] = logger[level].bind(logger);
return;
}
this[level] = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift('[' + namespace + ']');
logger[level].apply(logger, args);
};
}, this);
} | javascript | function Log(namespace) {
// If it's called without new, still return a new instance.
if (!(this instanceof Log)) { return new Log(namespace); }
// Configure Log if it hasn't already
if (!logger) { Log.configure(); }
// This gets all of the log levels and applies them to this
Object.keys(logger.levels).forEach(function (level) {
if (!namespace) {
this[level] = logger[level].bind(logger);
return;
}
this[level] = function () {
var args = Array.prototype.slice.call(arguments);
args.unshift('[' + namespace + ']');
logger[level].apply(logger, args);
};
}, this);
} | [
"function",
"Log",
"(",
"namespace",
")",
"{",
"// If it's called without new, still return a new instance.",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"Log",
")",
")",
"{",
"return",
"new",
"Log",
"(",
"namespace",
")",
";",
"}",
"// Configure Log if it hasn't already",
"if",
"(",
"!",
"logger",
")",
"{",
"Log",
".",
"configure",
"(",
")",
";",
"}",
"// This gets all of the log levels and applies them to this",
"Object",
".",
"keys",
"(",
"logger",
".",
"levels",
")",
".",
"forEach",
"(",
"function",
"(",
"level",
")",
"{",
"if",
"(",
"!",
"namespace",
")",
"{",
"this",
"[",
"level",
"]",
"=",
"logger",
"[",
"level",
"]",
".",
"bind",
"(",
"logger",
")",
";",
"return",
";",
"}",
"this",
"[",
"level",
"]",
"=",
"function",
"(",
")",
"{",
"var",
"args",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
")",
";",
"args",
".",
"unshift",
"(",
"'['",
"+",
"namespace",
"+",
"']'",
")",
";",
"logger",
"[",
"level",
"]",
".",
"apply",
"(",
"logger",
",",
"args",
")",
";",
"}",
";",
"}",
",",
"this",
")",
";",
"}"
] | Log You create a new log by specifying a namespace. This basically only keeps track of the namepace prefix that goes into each log. If nothing is passed, then it doesn't prefix it with anything. | [
"Log",
"You",
"create",
"a",
"new",
"log",
"by",
"specifying",
"a",
"namespace",
".",
"This",
"basically",
"only",
"keeps",
"track",
"of",
"the",
"namepace",
"prefix",
"that",
"goes",
"into",
"each",
"log",
".",
"If",
"nothing",
"is",
"passed",
"then",
"it",
"doesn",
"t",
"prefix",
"it",
"with",
"anything",
"."
] | b04ea84cb573fb2aef8e7d46589c94d5a0c085d4 | https://github.com/ksmithut/logget/blob/b04ea84cb573fb2aef8e7d46589c94d5a0c085d4/index.js#L31-L52 |
50,199 | trekjs/utils | lib/pbkdf2.js | genSalt | function genSalt() {
var len = arguments[0] === undefined ? 16 : arguments[0];
var encoding = arguments[1] === undefined ? 'hex' : arguments[1];
return (0, _token2['default'])(len, encoding);
} | javascript | function genSalt() {
var len = arguments[0] === undefined ? 16 : arguments[0];
var encoding = arguments[1] === undefined ? 'hex' : arguments[1];
return (0, _token2['default'])(len, encoding);
} | [
"function",
"genSalt",
"(",
")",
"{",
"var",
"len",
"=",
"arguments",
"[",
"0",
"]",
"===",
"undefined",
"?",
"16",
":",
"arguments",
"[",
"0",
"]",
";",
"var",
"encoding",
"=",
"arguments",
"[",
"1",
"]",
"===",
"undefined",
"?",
"'hex'",
":",
"arguments",
"[",
"1",
"]",
";",
"return",
"(",
"0",
",",
"_token2",
"[",
"'default'",
"]",
")",
"(",
"len",
",",
"encoding",
")",
";",
"}"
] | Generate a salt.
@method
@param {Number} len
@param {String} encoding
@return {Promise} by default 32 of slat length. | [
"Generate",
"a",
"salt",
"."
] | a6c7138ec7f7ccdff95df85c6662e7cefcd94eb0 | https://github.com/trekjs/utils/blob/a6c7138ec7f7ccdff95df85c6662e7cefcd94eb0/lib/pbkdf2.js#L29-L34 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.